In this section
- Pilot Ticker interaction · cosmic / tools/explore/theme/pilot-ticker.js lines 1–413
- Pilot Vicinity render · cosmic / tools/explore/theme/pilot-vicinity.css lines 1–32
Pilot Ticker
A JavaScript file in the theme folder of Cosmic that draws pipeline headlines snapshot and uses data from the GlobalGrid2050 and data-GB-electricity repositories.
interactioncosmic / tools/explore/theme/pilot-ticker.js · lines 1–413 of 413 · Entry point · pattern publicationStamp (shared by 2 files)
- What it does
- It draws pipeline headlines snapshot, the REPD register, solar and wind. Defines 34 functions or classes, including publicationStamp, publicHttpsUrl, fmtDay, fmtStamp, age. Side effects: changes the web page (DOM); uses storage (browser storage, DuckDB or Parquet).
- Why it exists in the grid workflow
- Domain terms in the code: the REPD register, solar, wind.
- Inputs & outputs
- In: data source: globalgrid2050 data; data source: data-gb-electricity data; JSON file pipeline_headlines.json; JSON file pipeline_headlines.snapshot.json; JSON file index.json; browser storage (getItem). Out: browser storage (setItem).
- Downstream impact
- Used directly by 1 file: Pilot (cosmic, https://ventusltd.github.io/cosmic/tools/explore/theme/pilot.html).
- What it achieves
- It loads feed (`loadFeed`), loads price (`loadPrice`) and sets hidden (`setHidden`). Pilot module: Pipeline News ticker (MARQUEE-53, optional). It responds to click, focusin and focusout events.
- Why it matters
- Loaded by the Pilot page at https://ventusltd.github.io/cosmic/tools/explore/theme/pilot.html.
- Application
- cosmic · tools/explore/theme · script
- Uses
- none found
- Used by
- loaded by Pilot (script src)
- Produces
- publicationStamp, publicHttpsUrl, fmtDay, fmtStamp, age, shortAge, dateOf, hasTime, dateText, feedLabel, rowsOf, norm
- Defines here
- publicationStamp, publicHttpsUrl, fmtDay, fmtStamp, age, shortAge, dateOf, hasTime, dateText, feedLabel, rowsOf, norm, distinctive, relevance, km, askContext, ctxKey, reduced, loadFeed, loadPrice, status, entries, itemHTML, render, sync, measure, wire, firstRow, setHidden, linkBtn
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/theme/pilot-ticker.js:1-413 · blob 0d477b23e8cbff3ebc51612a5f1ff4a5ee28241c · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom, storage · domain stage: unknown · users: none · canonical: unknown
/* Pilot module: Pipeline News ticker (MARQUEE-53, optional). Contract: /tmp/vk/pilot200/CONTRACT.md v1.
A thin headline strip in the top HUD slot, streamed at run time from the same published feeds Pipeline News reads.
Nothing is copied into cosmic (photon rule).
Sources (pinned to Pipeline News V9.78, edition 202611280922, Ventusltd/globalgrid2050):
- Live headlines: globalgrid2050 branch pipeline-news-data, dist/pipeline_headlines.json. Written by the workflow
.github/workflows/pipeline-headlines.yml at 04:41, 10:41 and 16:41 UTC. Schema globalgrid2050.news.pipeline-headlines.v1.
Fetched by uk_renewables_pipeline/202611280922/scripts/plugins/live-news.js (LIVE).
- Saved snapshot, used only when the live file fails: that edition's news/pipeline_headlines.snapshot.json at
globalgrid2050@27fe29a7b4e07352ec7fff2a648ffa1a7ae9600b (71 items, collected 2026-11-16T18:08:01Z).
- Market item: the Elexon system sell price, daily historical, from data-gb-electricity
derived/price-daily-browser @ cf48c8d6fdd9ab686c4af7261149d81a0129f7fc. This is the source the edition's
automation/price_daily_ui/78d5360.../model.mjs pins. It is not a live quote.
Licence: Apache-2.0 for this file. The ported rules are originally CERN-OHL-S-2.0 (Ventusltd/globalgrid2050@27fe29a7b4e07352ec7fff2a648ffa1a7ae9600b
uk_renewables_pipeline/202611280922/scripts/...). Ventus Ltd additionally licenses this material under Apache-2.0 to the
extent it holds the rights, effective 2026-12-05. Third-party material is excluded. See theme/LICENSE-MANIFEST.md.
Rules ported from that edition:
- Strict publication dates: scripts/layers/model.mjs publicationStamp().
- Publisher date first, then "First collected" (first_seen), and per-item filtering: latestHeadlines().
- Public HTTPS links only: scripts/layers/url-policy.mjs publicHttpsUrl().
- Feed freshness labels and the 36 h overdue rule: scripts/plugins/live-news.js label() and STALE_MS.
One deliberate difference, from satnav issue #7: a headline whose dates are malformed is not dropped, and it
never interrupts rendering. It is kept at the end of the list and labelled "Date unavailable".
Local relevance: a headline moves to the front only when its own feed entry names the place. That means the
collector's possible_match REPD ref, or the distinctive part of a nearby REPD site name in the title, or the
feed's own technology label matching nearby REPD sites. Nearby sites come from 'repd:query' (W06). The query
never forces the register to load. Nothing is inferred from location alone. */
(function () {
'use strict';
var W = window, P = W.PILOT;
if (!P) return;
var D = W.document;
P.module('ticker', { version: '1', owner: 'MARQUEE-53' });
// ---- sources
var PN_EDITION = '202611280922', PN_VERSION = 'V9.78';
var PN_URL = 'https://globalgrid2050.com/uk_renewables_pipeline/' + PN_EDITION + '/';
var PN_NEWS = PN_URL + '#headlinesHeading';
var LIVE = 'https://raw.githubusercontent.com/Ventusltd/globalgrid2050/pipeline-news-data/dist/pipeline_headlines.json';
var SNAPSHOT = 'https://raw.githubusercontent.com/Ventusltd/globalgrid2050/27fe29a7b4e07352ec7fff2a648ffa1a7ae9600b/uk_renewables_pipeline/' + PN_EDITION + '/news/pipeline_headlines.snapshot.json';
var PRICE = 'https://raw.githubusercontent.com/Ventusltd/data-gb-electricity/cf48c8d6fdd9ab686c4af7261149d81a0129f7fc/derived/price-daily-browser/';
var SCHEMA = 'globalgrid2050.news.pipeline-headlines.v1', PRICE_SCHEMA = 'data-gb-electricity.system-sell-daily.v1';
var STALE_MS = 36 * 3600 * 1000, FUTURE_MS = 300000, REFRESH_MS = 30 * 60 * 1000, LIMIT = 60;
var CREDIT_NEWS = 'Headlines: Pipeline News ' + PN_VERSION + ' collector (globalgrid2050), public RSS/Atom titles and links only, © the original publishers';
var CREDIT_PRICE = 'GB system sell price: Elexon via data-gb-electricity (daily, historical)';
var CATEGORY = { planning_decision: 'PLANNING DECISION', consent: 'CONSENTED', refusal: 'REFUSED', dco: 'DCO', finance: 'FINANCE',
construction: 'CONSTRUCTION', energisation: 'ENERGISED', grid: 'GRID', policy: 'POLICY', datacentre: 'DATA CENTRES', other: '' };
var TECHNOLOGY = { solar: 'SOLAR', wind: 'WIND', offshore_wind: 'OFFSHORE WIND', battery: 'BATTERY', hydro: 'HYDRO', tidal: 'TIDAL' };
// REPD registry technology code (W06 TECH keys) -> the headline feed's technology label
var REPD_TO_FEED = { solar: 'solar', solar_roof: 'solar', wind_onshore: 'wind', wind_offshore: 'offshore_wind', bess: 'battery', hydro: 'hydro', tidal: 'tidal' };
var esc = P.esc || function (s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return '&#' + c.charCodeAt(0) + ';'; }); };
// ---- pure rules (ported; see header)
function publicationStamp(value) {
if (typeof value !== 'string') return NaN;
var m = /^(\d{4})-(\d{2})-(\d{2})(?:T(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d{1,9})?(?:Z|[+-](?:[01]\d|2[0-3]):[0-5]\d))?$/.exec(value);
if (!m) return NaN;
var y = +m[1], mo = +m[2], d = +m[3], leap = y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0);
var days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if (y < 1900 || mo < 1 || mo > 12 || d < 1 || d > days[mo - 1]) return NaN;
return Date.parse(value);
}
function publicHttpsUrl(value) {
if (typeof value !== 'string') return null;
try {
var u = new URL(value), h = u.hostname.toLowerCase();
if (u.protocol !== 'https:' || u.username || u.password || h.indexOf('.') < 0 || h.indexOf(':') >= 0 || /\.$/.test(h) ||
/^[\d.]+$/.test(h) || /(^|\.)(localhost|local|internal)$/.test(h) || (u.port && u.port !== '443')) return null;
return u.href;
} catch (e) { return null; }
}
var MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
function fmtDay(ms) { var d = new Date(ms); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()] + ' ' + d.getUTCFullYear(); }
function fmtStamp(ms, withTime) {
var d = new Date(ms);
return fmtDay(ms) + (withTime ? ' ' + ('0' + d.getUTCHours()).slice(-2) + ':' + ('0' + d.getUTCMinutes()).slice(-2) + ' UTC' : '');
}
function age(ms, now) {
var a = now - ms;
if (a < 0) return 'just now';
if (a < 3600000) return Math.max(1, Math.round(a / 60000)) + ' min ago';
if (a < 48 * 3600000) return Math.round(a / 3600000) + ' h ago';
return Math.floor(a / 86400000) + ' days ago';
}
function shortAge(ms, now) { var a = Math.max(0, now - ms); return a < 3600000 ? Math.round(a / 60000) + 'm' : a < 48 * 3600000 ? Math.round(a / 3600000) + 'h' : Math.round(a / 86400000) + 'd'; }
/* Date of one headline: Publisher date, else First collected, else unknown. Never throws on any input type. */
function dateOf(item, now) {
var hasTime = function (s) { return typeof s === 'string' && s.indexOf('T') > 0; };
var p = publicationStamp(item.date);
if (isFinite(p) && p - now <= FUTURE_MS) return { ms: p, kind: 'Publisher date', time: hasTime(item.date) };
var f = publicationStamp(item.first_seen);
if (isFinite(f) && f - now <= FUTURE_MS) return { ms: f, kind: 'First collected', time: hasTime(item.first_seen) };
var ahead = (isFinite(p) && p - now > FUTURE_MS) || (isFinite(f) && f - now > FUTURE_MS);
return { ms: NaN, kind: null, time: false, note: ahead ? 'Date unavailable (ahead of this clock)' : 'Date unavailable' };
}
function dateText(dt, now) { return dt.kind ? fmtStamp(dt.ms, false) + ' · ' + age(dt.ms, now) : dt.note; }
/* Feed status, after live-news.js label(): a pure function of the file's date, its status, the clock and the source. */
function feedLabel(doc, source, now) {
if (source === 'offline') return { state: 'offline', chip: 'OFFLINE', text: 'Offline mode: the ticker does not fetch. Headlines unknown, not zero.' };
if (source === 'loading') return { state: 'loading', chip: '…', text: 'Loading the Pipeline News headline feed…' };
var when = doc ? publicationStamp(doc.generated_at) : NaN;
if (source === 'none' || !isFinite(when)) return { state: 'unavailable', chip: 'NO FEED', text: 'Headline feed failed to load (live and saved snapshot). Headlines unknown, not zero.' };
var at = fmtStamp(when, true);
if (source === 'snapshot') return { state: 'snapshot', chip: 'SAVED ' + shortAge(when, now), text: 'Live source unavailable. Showing a saved snapshot collected ' + at + '; its articles may be older.' };
if (doc.status === 'failed') return { state: 'failed', chip: 'FAILED', text: 'Source collection failed at ' + at + '. Any displayed headlines were retained from earlier collections.' };
if (when - now > FUTURE_MS) return { state: 'future', chip: 'CLOCK?', text: 'Feed timestamp is ahead of this clock. Collection time needs review: ' + at + '.' };
var overdue = now - when > STALE_MS;
if (doc.status === 'partial') {
var c = doc.counts || {}, ok = Number.isInteger(c.feeds_ok) ? c.feeds_ok : null, bad = Number.isInteger(c.feeds_failed) ? c.feeds_failed : null;
var cov = ok !== null && bad !== null ? ' (' + ok + ' sources succeeded, ' + bad + ' failed)' : '';
return { state: overdue ? 'overdue-partial' : 'partial', chip: (overdue ? 'STALE ' : 'PARTIAL ') + shortAge(when, now),
text: 'Partial source collection' + cov + '. Feed checked ' + at + (overdue ? '; refresh is overdue.' : '. Displaying available headlines.') };
}
if (doc.status !== 'ok') return { state: 'unknown', chip: '? ' + shortAge(when, now), text: 'Feed checked ' + at + '; collection status unknown.' };
if (overdue) return { state: 'overdue', chip: 'STALE ' + shortAge(when, now), text: 'Feed last checked ' + at + '; refresh is overdue. Article dates may be older.' };
return { state: 'live', chip: 'LIVE ' + shortAge(when, now), text: 'Feed checked ' + at + '. Article dates are shown separately.' };
}
/* Whole-document checks fail closed; single bad items are skipped and never stop the rest. */
function rowsOf(doc, now) {
if (!doc || doc.schema !== SCHEMA || !Array.isArray(doc.items) || doc.items.length > 10000 || !isFinite(publicationStamp(doc.generated_at))) return null;
var seen = {}, rows = [];
for (var i = 0; i < doc.items.length; i++) {
var it = doc.items[i];
if (!it || typeof it !== 'object' || typeof it.title !== 'string' || !it.title.trim() || it.title.length > 1000) continue;
var link = publicHttpsUrl(it.link); if (!link) continue;
var dt = dateOf(it, now);
var pm = it.possible_match && typeof it.possible_match === 'object' && /^\d+$/.test(String(it.possible_match.repd_ref || '')) && typeof it.possible_match.site_name === 'string'
? { ref: String(it.possible_match.repd_ref), name: it.possible_match.site_name } : null;
var row = { title: it.title.trim(), link: link, source: typeof it.source === 'string' && it.source.trim() ? it.source.trim() : 'Publisher not supplied',
dt: dt, category: CATEGORY[it.category] || '', tech: typeof it.technology === 'string' && TECHNOLOGY[it.technology] ? it.technology : null, match: pm };
var old = seen[link];
if (old) { // same link twice: keep the newer dated copy
if (isFinite(dt.ms) && !(old.dt.ms >= dt.ms)) { rows[rows.indexOf(old)] = row; seen[link] = row; }
continue;
}
seen[link] = row; rows.push(row);
}
rows.sort(function (a, b) {
var ad = isFinite(a.dt.ms), bd = isFinite(b.dt.ms);
if (ad !== bd) return ad ? -1 : 1;
return (ad ? b.dt.ms - a.dt.ms : 0) || (a.link < b.link ? -1 : a.link > b.link ? 1 : 0);
});
return rows.slice(0, LIMIT);
}
// ---- local relevance (only what the feed entry itself names)
var GENERIC = {}; ('solar farm park wind windfarm battery batteries storage energy project bess the and of limited ltd extension phase site power station ' +
'offshore onshore hybrid scheme plant pv array generating centre center facility grid hub east west north south land at near').split(' ').forEach(function (w) { GENERIC[w] = 1; });
function norm(v) { return ' ' + String(v || '').normalize('NFKD').replace(/[̀-ͯ]/g, '').toLowerCase().replace(/&/g, ' and ').replace(/[^a-z0-9]+/g, ' ').trim() + ' '; }
function distinctive(name) {
var first = String(name || '').split(/\s+-\s+|,/)[0];
var all = norm(first).trim().split(' ').filter(Boolean);
var keep = all.filter(function (t) { return !GENERIC[t]; });
if (!keep.length) return null;
// keep the name as written, e.g. "botley west", minus trailing generic words only
var end = all.length; while (end > 0 && GENERIC[all[end - 1]]) end--;
var s = all.slice(0, end).join(' ');
return s.replace(/\s/g, '').length >= 5 ? ' ' + s + ' ' : null;
}
var ctx = { state: 'none', at: null, sites: [], techs: {}, selected: null, asked: 0 };
function relevance(row) {
var why = [], score = 0, t = norm(row.title), i, s;
if (ctx.selected && row.match && row.match.ref === ctx.selected.ref) { score += 100; why.push('its feed entry names REPD ' + row.match.ref + ' (' + row.match.name + '), the site you selected'); }
for (i = 0; i < ctx.sites.length; i++) {
s = ctx.sites[i];
if (row.match && row.match.ref === s.ref && !(ctx.selected && ctx.selected.ref === s.ref)) { score += 60; why.push('its feed entry names REPD ' + s.ref + ' (' + row.match.name + '), ' + km(s.d) + ' from you'); break; }
}
for (i = 0; i < ctx.sites.length; i++) {
s = ctx.sites[i];
if (s.key && t.indexOf(s.key) >= 0) { score += 40; why.push('the headline names "' + s.key.trim() + '", REPD ' + s.ref + ' ' + km(s.d) + ' from you'); break; }
}
if (row.tech && ctx.techs[row.tech]) { score += 10; why.push('the feed labels it ' + TECHNOLOGY[row.tech] + ', and ' + ctx.techs[row.tech] + ' nearby REPD site' + (ctx.techs[row.tech] === 1 ? ' is' : 's are') + ' ' + TECHNOLOGY[row.tech]); }
return { score: score, why: why };
}
function km(m) { return m < 1000 ? Math.round(m) + ' m' : (m / 1000).toFixed(m < 10000 ? 1 : 0) + ' km'; }
var CTX_RADIUS = 25000, CTX_MOVE = 1500, CTX_EVERY = 60000;
function askContext(force) {
var c = P.camLL ? P.camLL() : null; if (!c || !isFinite(c.lat) || !isFinite(c.lon)) return;
var now = Date.now();
if (!force && ctx.at && P.dist(ctx.at[0], ctx.at[1], c.lat, c.lon) < CTX_MOVE && now - ctx.asked < CTX_EVERY) return;
ctx.asked = now; ctx.at = [c.lat, c.lon];
var answered = false;
try {
P.emit('repd:query', { lat: c.lat, lon: c.lon, n: 25, radiusM: CTX_RADIUS, all: true, reply: function (list, meta) {
answered = true;
var before = ctxKey();
if (!meta || !meta.loaded || !Array.isArray(list)) { ctx.state = meta && meta.state === 'error' ? 'error' : 'notloaded'; ctx.sites = []; ctx.techs = {}; }
else {
ctx.state = 'ok';
ctx.sites = list.filter(function (r) { return r && r.ref != null && isFinite(r.d); }).map(function (r) { return { ref: String(r.ref), name: String(r.name || ''), tech: r.tech, d: +r.d, key: distinctive(r.name) }; });
ctx.techs = {};
ctx.sites.forEach(function (s) { var f = REPD_TO_FEED[s.tech]; if (f && s.d <= 10000) ctx.techs[f] = (ctx.techs[f] || 0) + 1; });
}
if (ctxKey() !== before) render();
} });
} catch (e) { /* another module's handler failed; keep the plain order */ }
if (!answered && ctx.state === 'none') ctx.state = 'nomodule';
}
function ctxKey() { return ctx.state + '|' + (ctx.selected ? ctx.selected.ref : '') + '|' + ctx.sites.map(function (s) { return s.ref; }).join(','); }
// ---- state
var S = { doc: null, source: P.offline ? 'offline' : 'loading', rows: [], price: null, priceErr: '', shown: [], key: '', paused: false, hidden: false, fetchedAt: 0 };
try { S.hidden = W.localStorage.getItem('p-ticker-hidden') === '1'; } catch (e) { /* none */ }
var reducedMQ = W.matchMedia ? W.matchMedia('(prefers-reduced-motion: reduce)') : null;
function reduced() { return !!(P.reduced || (reducedMQ && reducedMQ.matches)); }
// ---- loading
function loadFeed() {
if (P.offline) { S.source = 'offline'; render(); return Promise.resolve(); }
var now = Date.now();
return P.data.fetchJSON(LIVE, { cache: false, timeout: 12000 }).then(function (doc) {
var rows = rowsOf(doc, Date.now()); if (!rows) throw new Error('invalid headline feed');
S.doc = doc; S.rows = rows; S.source = 'live';
}).catch(function () {
if (S.source === 'live' && S.doc) return; // keep the last good live copy; its label still ages honestly
return P.data.fetchJSON(SNAPSHOT, { cache: true, timeout: 12000 }).then(function (doc) {
var rows = rowsOf(doc, Date.now()); if (!rows) throw new Error('invalid snapshot');
S.doc = doc; S.rows = rows; S.source = 'snapshot';
}).catch(function () { S.doc = null; S.rows = []; S.source = 'none'; });
}).then(function () { S.fetchedAt = now; render(); P.emit('ticker:status', status()); });
}
function loadPrice() {
if (P.offline) return;
P.data.fetchJSON(PRICE + 'index.json', { timeout: 15000 }).then(function (idx) {
if (!idx || idx.schema !== PRICE_SCHEMA + '.index' || idx.unit !== 'GBP/MWh' || !/^\d{4}-\d{2}-\d{2}$/.test(idx.last_date || '') || !Array.isArray(idx.parts)) throw new Error('price index contract');
var y = +idx.last_date.slice(0, 4), part = idx.parts.filter(function (p) { return p && p.year === y && p.path === y + '.json'; })[0];
if (!part) throw new Error('price year part missing');
return P.data.fetchJSON(PRICE + part.path, { timeout: 15000 }).then(function (data) {
if (!data || data.schema !== PRICE_SCHEMA || data.unit !== 'GBP/MWh' || !Array.isArray(data.rows)) throw new Error('price year contract');
for (var i = data.rows.length - 1; i >= 0; i--) {
var r = data.rows[i];
if (r && r.priced_periods > 0 && isFinite(r.mean_available_gbp_per_mwh) && isFinite(publicationStamp(r.date))) {
S.price = { date: r.date, ms: publicationStamp(r.date), mean: +r.mean_available_gbp_per_mwh, min: r.minimum_observed_gbp_per_mwh, max: r.maximum_observed_gbp_per_mwh,
coverage: r.coverage_status, priced: r.priced_periods, expected: r.expected_periods, last: idx.last_date };
break;
}
}
if (!S.price) throw new Error('no priced day');
render();
});
}).catch(function (e) { S.priceErr = (e && e.message) || 'price unavailable'; S.price = null; render(); });
}
// ---- view
var host = null, panelBody = null;
function status() {
var lab = feedLabel(S.doc, S.source, Date.now());
return { state: lab.state, chip: lab.chip, text: lab.text, source: S.source, items: S.rows.length, generated_at: S.doc ? S.doc.generated_at : null,
context: ctx.state, near: S.shown.filter(function (x) { return x.rel && x.rel.score > 0; }).length, hidden: S.hidden, paused: S.paused, reduced: reduced(),
price: S.price ? { date: S.price.date, mean: S.price.mean } : null, order: S.shown.map(function (x) { return x.kind === 'price' ? 'price' : x.row.link; }) };
}
function entries() {
var now = Date.now(), list = S.rows.map(function (row, i) { return { kind: 'news', row: row, rel: relevance(row), i: i }; });
list.sort(function (a, b) { return b.rel.score - a.rel.score || a.i - b.i; });
if (S.price) {
var at = 0; while (at < list.length && list[at].rel.score > 0) at++;
list.splice(at, 0, { kind: 'price', p: S.price, rel: { score: 0, why: [] } });
}
return list;
}
function itemHTML(e, k, now) {
if (e.kind === 'price') {
return '<span class="p-ticker-tag">MARKET</span><span class="p-ticker-t">GB system sell price £' + e.p.mean.toFixed(2) + '/MWh daily mean — Elexon</span>' +
'<span class="p-ticker-d">' + esc(fmtDay(e.p.ms) + ' · ' + age(e.p.ms, now) + ' · historical') + '</span>';
}
var r = e.row;
return (e.rel.score > 0 ? '<span class="p-ticker-tag p-ticker-near">NEAR</span>' : (r.category ? '<span class="p-ticker-tag">' + esc(r.category) + '</span>' : '')) +
'<span class="p-ticker-t">' + esc(r.title + ' — ' + r.source) + '</span><span class="p-ticker-d' + (r.dt.kind ? '' : ' p-ticker-unk') + '">' + esc(dateText(r.dt, now)) + '</span>';
}
function render() {
if (!P.hud) return;
if (S.hidden) { P.hud('top:ticker', null); host = null; P.credit('ticker', null); P.credit('ticker-price', null); renderPanel(); return; }
var now = Date.now(), lab = feedLabel(S.doc, S.source, now), list = entries();
S.shown = list;
var key = JSON.stringify([lab.chip, lab.state, list.map(function (e) { return e.kind === 'price' ? 'p' + e.p.date : e.row.link + (e.rel.score > 0 ? '*' : '') + dateText(e.row.dt, now); })]);
if (host && key === S.key && host.parentNode) { sync(); renderPanel(); return; }
S.key = key;
var items = list.map(function (e, k) { return '<li><button type="button" class="p-ticker-item" data-p-ticker-i="' + k + '">' + itemHTML(e, k, now) + '</button></li>'; }).join('');
var copy = list.map(function (e, k) { return '<span class="p-ticker-item">' + itemHTML(e, k, now) + '</span>'; }).join('');
var empty = '<li class="p-ticker-msg">' + esc(lab.state === 'loading' ? 'Loading headlines…' : lab.state === 'offline' ? 'Offline: headlines unknown, not zero.' :
'Headlines unavailable: ' + lab.text) + '</li>';
var html = '<div class="p-ticker" data-state="' + esc(lab.state) + '" role="group" aria-label="Pipeline News ticker">' +
'<button type="button" class="p-ticker-chip" data-p-ticker-chip="1" aria-label="Feed status: ' + esc(lab.text) + '" title="' + esc(lab.text) + '">' + esc(lab.chip) + '</button>' +
'<div class="p-ticker-vp" tabindex="0" role="region" aria-label="Headlines from Pipeline News; focus or tap to pause">' +
'<div class="p-ticker-track"><ul class="p-ticker-list" aria-label="Headlines with publisher and date">' + (list.length ? items : empty) + '</ul>' +
(list.length > 1 ? '<div class="p-ticker-list p-ticker-copy" aria-hidden="true" inert>' + copy + '</div>' : '') + '</div></div>' +
'<button type="button" class="p-ticker-btn" data-p-ticker-pause="1" aria-pressed="false" aria-label="Pause ticker">❚❚</button>' +
'<button type="button" class="p-ticker-btn" data-p-ticker-hide="1" aria-label="Hide ticker (show again from the NEWS tab)">✕</button></div>';
host = P.hud('top:ticker', html);
if (host) { host.classList.add('p-ticker-host'); firstRow(host); if (!host.hasAttribute('data-p-ticker-wired')) { host.setAttribute('data-p-ticker-wired', '1'); wire(host); } }
P.credit('ticker', S.source === 'live' || S.source === 'snapshot' ? CREDIT_NEWS : null);
P.credit('ticker-price', S.price ? CREDIT_PRICE : null);
sync(); measure(); renderPanel();
}
var focused = false, cardOpen = false;
function sync() {
if (!host) return;
var box = host.querySelector('.p-ticker'); if (!box) return;
var still = reduced() || S.paused || focused || cardOpen || S.shown.length < 2;
box.setAttribute('data-motion', still ? 'static' : 'flowing');
box.setAttribute('data-reduced', reduced() ? 'true' : 'false');
var b = host.querySelector('[data-p-ticker-pause]');
if (b) { b.setAttribute('aria-pressed', S.paused ? 'true' : 'false'); b.textContent = S.paused ? '▶' : '❚❚'; b.setAttribute('aria-label', S.paused ? 'Resume ticker' : 'Pause ticker'); b.hidden = reduced() || S.shown.length < 2; }
}
function measure() {
if (!host) return;
var box = host.querySelector('.p-ticker'), list = host.querySelector('ul.p-ticker-list'); if (!box || !list) return;
var w = list.getBoundingClientRect().width;
box.style.setProperty('--p-ticker-w', w + 'px');
box.style.setProperty('--p-ticker-dur', Math.max(20, w / 45) + 's');
}
function wire(el) {
el.addEventListener('click', function (e) {
var t = e.target && e.target.closest ? e.target : null; if (!t) return;
var it = t.closest('[data-p-ticker-i]');
if (it) { openItem(+it.getAttribute('data-p-ticker-i')); return; }
if (t.closest('[data-p-ticker-pause]')) { S.paused = !S.paused; sync(); return; }
if (t.closest('[data-p-ticker-hide]')) { setHidden(true); return; }
if (t.closest('[data-p-ticker-chip]')) { openStatus(); }
});
// keyboard focus on a headline holds the strip still (as in Pipeline News); focus on the chip or buttons does not
el.addEventListener('focusin', function (e) { focused = !!(e.target.closest && e.target.closest('.p-ticker-vp')); sync(); });
el.addEventListener('focusout', function (e) { var vp = el.querySelector('.p-ticker-vp'); if (!vp || !vp.contains(e.relatedTarget)) { focused = false; sync(); } });
}
/* Keep the strip as the first row of the top slot, straight under the core HUD. Lower rows reach the phone's stick
and FAST button at 390x844, and a full-width strip there would cover them. Moving our own sub-slot does not
change any slot heights. */
function firstRow(el) { var par = el.parentNode; if (par && par.firstChild !== el) par.insertBefore(el, par.firstChild); }
function setHidden(on) {
S.hidden = !!on; try { W.localStorage.setItem('p-ticker-hidden', on ? '1' : '0'); } catch (e) { /* none */ }
focused = false; S.key = ''; render();
if (on && P.note) P.note('Ticker hidden. Show it again from the NEWS tab.', 3500);
}
function linkBtn(href, text, rel) { return '<a class="pbtn p-ticker-link" href="' + esc(href) + '" target="_blank" rel="' + (rel || 'noopener') + '">' + esc(text) + '</a>'; }
function openItem(k) {
var e = S.shown[k]; if (!e) return;
var now = Date.now(), lab = feedLabel(S.doc, S.source, now), h = '';
if (e.kind === 'price') {
var p = e.p;
h = '<p>£' + esc(p.mean.toFixed(2)) + '/MWh daily mean of available half-hours (observed range £' + esc(String(p.min)) + ' to £' + esc(String(p.max)) + ').</p>' +
'<p class="p-ticker-cmeta">Settlement date ' + esc(fmtDay(p.ms)) + ' · ' + esc(age(p.ms, now)) + ' · ' + esc(String(p.priced)) + ' of ' + esc(String(p.expected)) + ' periods priced · ' + esc(String(p.coverage || 'coverage unknown')) + '</p>' +
'<p class="p-ticker-cnote">Historical Elexon system sell price from the pinned data-gb-electricity edition that Pipeline News reads (last date ' + esc(p.last) + '). It is not a live quote or forecast.</p>' +
'<p class="p-ticker-acts">' + linkBtn(PN_URL, 'Open Pipeline News') + linkBtn(PRICE + 'index.json', 'Source index') + '</p>';
P.card({ title: 'GB system sell price', cap: 'MARKET · PIPELINE NEWS SOURCE', html: h });
} else {
var r = e.row;
h = '<p class="p-ticker-cmeta">' + esc(r.source) + ' · ' + (r.dt.kind ? esc(r.dt.kind + ' ' + fmtStamp(r.dt.ms, r.dt.time) + ' · ' + age(r.dt.ms, now)) : '<span class="p-ticker-unk">' + esc(r.dt.note) + '</span>') + '</p>' +
((r.category || r.tech) ? '<p class="p-ticker-cmeta">' + esc([r.category, r.tech ? TECHNOLOGY[r.tech] : ''].filter(Boolean).join(' · ')) + ' (labels read from the headline)</p>' : '') +
(r.match ? '<p>Possible match: ' + esc(r.match.name) + ' (REPD ' + esc(r.match.ref) + '). The collector found a name coincidence for review. It is not a confirmed link.</p>' : '') +
(e.rel.score > 0 ? '<p class="p-ticker-cnear">Shown first because ' + esc(e.rel.why.join('; ')) + '.</p>' : '') +
'<p class="p-ticker-cnote">Feed: ' + esc(lab.text) + '</p>' +
'<p class="p-ticker-acts">' + linkBtn(PN_NEWS, 'Open in Pipeline News') + linkBtn(r.link, 'Original · ' + r.source, 'noopener noreferrer') +
(r.match ? '<button type="button" class="pbtn" data-p-ticker-repd="' + esc(r.match.ref) + '">REPD ' + esc(r.match.ref) + '</button>' : '') + '</p>';
P.card({ title: r.title, cap: 'PIPELINE NEWS HEADLINE', html: h });
}
cardOpen = true; sync();
}
function openStatus() {
var lab = feedLabel(S.doc, S.source, Date.now());
P.card({ title: 'Ticker feed status', cap: 'PIPELINE NEWS TICKER', html: '<p>' + esc(lab.text) + '</p>' +
'<p class="p-ticker-cnote">' + esc(S.rows.length + ' headlines shown, newest first. Refresh is overdue after 36 h. The collector runs at 04:41, 10:41 and 16:41 UTC. ' +
(S.price ? 'Market item: settlement date ' + S.price.date + '.' : S.priceErr ? 'Market item unavailable (' + S.priceErr + ').' : '') + ' Local ranking: ' + ctxText()) + '</p>' +
'<p class="p-ticker-acts">' + linkBtn(PN_NEWS, 'Open Pipeline News') + '</p>' });
cardOpen = true; sync();
}
function ctxText() {
return ctx.state === 'ok' ? ctx.sites.length + ' REPD sites within 25 km; headlines go first only when their own feed entry names one of them.' :
ctx.state === 'notloaded' ? 'off until the REPD layer has loaded.' : ctx.state === 'error' ? 'off (REPD register failed to load).' : 'off (no REPD module).';
}
D.addEventListener('click', function (e) {
var b = e.target && e.target.closest && e.target.closest('[data-p-ticker-repd]'); if (!b) return;
e.preventDefault(); P.emit('repd:show', { ref: b.getAttribute('data-p-ticker-repd') });
});
function renderPanel() {
if (!P.panel) return;
var now = Date.now(), lab = feedLabel(S.doc, S.source, now);
var rows = (S.shown.length ? S.shown : entries()).map(function (e, k) {
if (e.kind === 'price') return '<li><b>MARKET</b> GB system sell price £' + e.p.mean.toFixed(2) + '/MWh · ' + esc(fmtDay(e.p.ms)) + ' (historical)</li>';
var r = e.row;
return '<li>' + (e.rel.score > 0 ? '<b class="p-ticker-near">NEAR</b> ' : '') + '<a href="' + esc(r.link) + '" target="_blank" rel="noopener noreferrer">' + esc(r.title) + '</a> — ' + esc(r.source) +
' · <span class="' + (r.dt.kind ? '' : 'p-ticker-unk') + '">' + esc(r.dt.kind ? r.dt.kind + ' ' + dateText(r.dt, now) : r.dt.note) + '</span></li>';
}).join('');
var html = '<div class="p-ticker-panel"><p class="p-ticker-pstat" data-state="' + esc(lab.state) + '">' + esc(lab.text) + '</p>' +
'<p><button type="button" class="pbtn" data-p-ticker-toggle="1" aria-pressed="' + (S.hidden ? 'false' : 'true') + '">' + (S.hidden ? 'Show ticker strip' : 'Hide ticker strip') + '</button> ' +
linkBtn(PN_NEWS, 'Open Pipeline News') + '</p>' +
(rows ? '<ol class="p-ticker-plist">' + rows + '</ol>' : '<p>No headlines to show. Headlines unknown, not zero.</p>') +
'<p class="p-ticker-cnote">Pipeline News ' + PN_VERSION + ' (edition ' + PN_EDITION + ') feeds, streamed at run time. Headlines and links only, from public RSS/Atom feeds. Local ranking: ' + esc(ctxText()) + '</p></div>';
if (!panelBody) {
panelBody = P.panel('ticker', html, { title: 'Pipeline News', icon: 'NEWS', open: false });
if (panelBody) panelBody.addEventListener('click', function (e) { if (e.target.closest && e.target.closest('[data-p-ticker-toggle]')) setHidden(!S.hidden); });
} else panelBody.innerHTML = html;
}
// ---- wiring
if (!S.hidden && P.hud) { host = P.hud('top:ticker', '<div class="p-ticker" data-state="loading"><span class="p-ticker-msg">Loading headlines…</span></div>'); if (host) host.classList.add('p-ticker-host'); }
P.on('repd:select', function (d) { if (d && d.ref != null) { ctx.selected = { ref: String(d.ref), at: Date.now() }; render(); } });
P.on('repd:ready', function () { askContext(true); });
P.on('arrive', function () { askContext(true); });
P.on('resize', measure);
P.on('ticker:query', function (q) { if (q && typeof q.reply === 'function') q.reply(status()); });
P.on('ticker:show', function (q) { setHidden(q && q.hidden === true); });
if (reducedMQ && reducedMQ.addEventListener) reducedMQ.addEventListener('change', function () { sync(); });
// The shared card has no close event; a tap on the canvas or another card ends "reading".
D.addEventListener('pointerdown', function (e) { if (cardOpen && !(e.target.closest && (e.target.closest('#card') || e.target.closest('.p-ticker')))) { cardOpen = false; sync(); } }, true);
P.ready(function () {
render();
loadFeed().then(loadPrice);
askContext(true);
setInterval(function () { askContext(false); }, 15000);
setInterval(function () { if (!P.offline) loadFeed(); else render(); }, REFRESH_MS);
setInterval(function () { if (!S.hidden) render(); }, 60000); // ages and the overdue label move with the clock
});
})();Pilot Vicinity
A style sheet in the theme folder of Cosmic.
rendercosmic / tools/explore/theme/pilot-vicinity.css · lines 1–32 of 32 · Entry point
- What it does
- Side effects: changes the web page (DOM).
- Downstream impact
- Used directly by 1 file: Pilot (cosmic, https://ventusltd.github.io/cosmic/tools/explore/theme/pilot.html).
- What it achieves
- Pilot vicinity panel (W07). Every selector prefixed p-vicinity-.
- Why it matters
- Loaded by the Pilot page at https://ventusltd.github.io/cosmic/tools/explore/theme/pilot.html.
- Application
- cosmic · tools/explore/theme · style sheet
- Uses
- none found
- Used by
- loaded by Pilot (stylesheet)
- Produces
- none declared
- Defines here
- none
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/theme/pilot-vicinity.css:1-32 · blob 9c6d3c22c28239d714450e3e3003422c40abd94e · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: unknown · users: none · canonical: unknown
/* Pilot vicinity panel (W07). Every selector prefixed p-vicinity-. Mobile first: 44 px taps, no sideways scroll. */
.p-vicinity { font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: #bfe9ee; max-width: 100%; overflow-wrap: anywhere; }
.p-vicinity * { box-sizing: border-box; }
.p-vicinity-lede, .p-vicinity-cap { margin: 6px 0; color: #9ab8be; }
.p-vicinity-cap { color: #ffd84d; font-size: 11px; }
.p-vicinity-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.p-vicinity-actions .p-vicinity-btn { flex: 1 1 120px; }
.p-vicinity-btn { min-height: 44px; min-width: 44px; padding: 8px 10px; font: inherit; color: #0ff; background: #061216; border: 1px solid #367078; border-radius: 6px; cursor: pointer; }
.p-vicinity-btn:disabled { opacity: .45; cursor: default; }
.p-vicinity button:focus-visible, .p-vicinity input:focus-visible { outline: 3px solid #ffd84d; outline-offset: 2px; }
.p-vicinity-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0; }
.p-vicinity-form label { flex: 0 0 auto; }
.p-vicinity-input { flex: 1 1 140px; min-width: 0; min-height: 44px; padding: 8px; font: inherit; color: #bfe9ee; background: #071013; border: 1px solid #367078; border-radius: 6px; color-scheme: dark; }
.p-vicinity-range { display: block; margin-top: 6px; }
.p-vicinity-slider { display: block; width: 100%; height: 44px; margin: 0; accent-color: #0ff; }
.p-vicinity-check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.p-vicinity-check input { width: 22px; height: 22px; accent-color: #0ff; flex: none; }
.p-vicinity-status { min-height: 1.4em; margin: 4px 0; color: #0ff; }
.p-vicinity-tabs { display: flex; gap: 4px; margin: 6px 0 2px; }
.p-vicinity-tab { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 6px 4px; font: inherit; font-size: 12px; color: #9ab8be; background: #020809; border: 1px solid #315057; border-radius: 6px 6px 0 0; cursor: pointer; }
.p-vicinity-tab[aria-selected="true"] { color: #0ff; border-color: #0ff; background: #103039; }
.p-vicinity-list { list-style: none; margin: 0; padding: 0; }
.p-vicinity-list li { display: flex; gap: 6px; align-items: stretch; border-bottom: 1px solid #18333a; padding: 3px 0; }
.p-vicinity-row { flex: 1 1 auto; min-width: 0; min-height: 44px; display: grid; grid-template-columns: 12px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center; text-align: left; padding: 6px 4px; font: inherit; color: #bfe9ee; background: none; border: 0; cursor: pointer; }
.p-vicinity-row b { grid-column: 2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e6f7f9; font-weight: 600; }
.p-vicinity-meta { grid-column: 2; grid-row: 2; font-size: 11px; color: #9ab8be; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-vicinity-km { grid-column: 3; grid-row: 1 / span 2; color: #0ff; white-space: nowrap; }
.p-vicinity-dot { grid-row: 1 / span 2; width: 10px; height: 10px; border-radius: 50%; }
.p-vicinity-route { flex: none; }
.p-vicinity-empty { color: #9ab8be; padding: 10px 0 !important; }
.p-vicinity-hud { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: inline-block; vertical-align: bottom; }
@media (prefers-reduced-motion: reduce) { .p-vicinity * { transition: none !important; animation: none !important; } }