create-pmos 0.416.0 → 0.418.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/board-programs-test.js +68 -1
  7. package/workspace/briefing-premium-board-test.js +21 -19
  8. package/workspace/changelog.json +24 -0
  9. package/workspace/guide/workflows.md +3 -2
  10. package/workspace/lib/engine/boards.js +7 -2
  11. package/workspace/lib/initiative-chat.js +1 -1
  12. package/workspace/lib/initiative-premium.js +7 -4
  13. package/workspace/lib/routes-boards.js +73 -4
  14. package/workspace/lib/task-cli.js +27 -3
  15. package/workspace/lib/task-items.js +5 -1
  16. package/workspace/lib/workflow-cli.js +9 -3
  17. package/workspace/package-lock.json +2 -2
  18. package/workspace/package.json +1 -1
  19. package/workspace/premium-board-actions-test.js +9 -5
  20. package/workspace/public/pm/bd-acts.js +3 -2
  21. package/workspace/public/pm/bd-scroll.js +164 -0
  22. package/workspace/public/pm/bd-span.js +151 -188
  23. package/workspace/public/pm/bd-stages.js +3 -25
  24. package/workspace/public/pm/cozy-board.css +92 -71
  25. package/workspace/public/pm/home-app.js +2 -0
  26. package/workspace/public/pm/home-data.js +17 -4
  27. package/workspace/public/pm/home-ini-model.js +5 -1
  28. package/workspace/public/pm/home-ini.js +4 -2
  29. package/workspace/public/pm/home-list.js +3 -3
  30. package/workspace/public/pm/home-task.js +4 -1
  31. package/workspace/public/pm/ini-view-model.js +4 -2
  32. package/workspace/public/pm/premium-board.js +49 -38
  33. package/workspace/public/pm/premium-vw-item.js +5 -2
  34. package/workspace/public/pm/task-card.js +12 -0
  35. package/workspace/public/premium-board.html +3 -2
  36. package/workspace/server.js +3 -0
  37. package/workspace/task-card-test.js +7 -0
@@ -27,14 +27,17 @@ const B = require(repoScript('boards.js'));
27
27
  const TI = require('./task-items.js');
28
28
  const rowsLib = require('./initiative-rows.js');
29
29
 
30
- const COMMANDS = { task: ['add', 'list', 'state', 'set'] };
30
+ const COMMANDS = { task: ['add', 'list', 'state', 'set', 'remove'] };
31
31
  const USAGE = [
32
- 'usage: pmos task add|list|state|set — an initiative\'s tasks, the ones the PM sees in its Tasks section',
32
+ 'usage: pmos task add|list|state|set|remove — an initiative\'s tasks, the ones the PM sees in its Tasks section',
33
33
  ' pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]',
34
34
  ' Add a task. Every new task goes here; pmos item add is the older breakdown record.',
35
35
  ' pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>]',
36
36
  ' Group tasks under a stage of the initiative\'s workflow (key or name; none takes it out), or change dates, owner or notes.',
37
37
  ' pmos task list <initiative> [--all] its open tasks; --all adds Done, Won\'t do and Archived',
38
+ ' pmos task remove <task> [<task> …] [--why <text>]',
39
+ ' Delete a task added by mistake (a placeholder, a duplicate) when the PM asks. It goes from every list; the page\'s Undo brings',
40
+ ' it back. Work that stopped is Archived or Won\'t do instead. A breakdown item is not deleted: set it to Won\'t do.',
38
41
  ' pmos task state <task> [<task> …] --to <state> [--why <text>]',
39
42
  ' Set each task\'s state when the PM asks: To do, In progress, Done, Won\'t do or Archived. The page shows it at once.',
40
43
  ' Give --why with Done: it is the evidence the PM reads.',
@@ -45,7 +48,7 @@ const USAGE = [
45
48
  ];
46
49
  const BOOL = new Set(['json', 'help', 'all']);
47
50
  const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes', 'stage']);
48
- const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage'], list: ['all'], state: ['to', 'why'], set: ['due', 'start', 'owner', 'notes', 'stage'] };
51
+ const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage'], list: ['all'], state: ['to', 'why'], remove: ['why'], set: ['due', 'start', 'owner', 'notes', 'stage'] };
49
52
  const OPEN = new Set(['To do', 'In progress']);
50
53
  /** The PM's words for a state: any case, with or without the apostrophe or the space. */
51
54
  function stateOf(s) {
@@ -206,6 +209,27 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
206
209
  return refused.length ? 1 : 0;
207
210
  }
208
211
 
212
+ if (verb === 'remove') {
213
+ // batch 7 item 5: a task added by mistake goes from every list (POST /api/boards/tasks/delete, the page's ⋯ Delete)
214
+ if (!pos.length) { say('usage: pmos task remove <task> [<task> …] [--why <text>]'); return 2; }
215
+ const folded = boards.foldOf(ctx, w);
216
+ const done = [], refused = [];
217
+ for (const id of pos) {
218
+ const t = findTask(folded, id);
219
+ if (!t) { refused.push({ task: id, error: `no task ${id}; pmos task list <initiative> --all names them` }); continue; }
220
+ const r = boards.taskDelete(ctx, { ws: w.id, board: t.board, task: id, ...(flags.why ? { why: flags.why } : {}) }, g);
221
+ if (!r.body || r.body.ok !== true) refused.push({ task: id, error: (r.body && r.body.error) || 'the write was refused' });
222
+ else done.push({ task: id, title: t.title });
223
+ }
224
+ if (json) say(JSON.stringify({ ok: !refused.length, done, refused }));
225
+ else {
226
+ for (const d of done) say(`✓ ${d.task} deleted: ${d.title}`);
227
+ for (const x of refused) say(`✗ ${x.task}: ${x.error}`);
228
+ if (done.length) say(' It is gone from the page. Nothing was sent.');
229
+ }
230
+ return refused.length ? 1 : 0;
231
+ }
232
+
209
233
  // state
210
234
  if (!pos.length || !flags.to) { say('usage: pmos task state <task> [<task> …] --to <state> [--why <text>]'); return 2; }
211
235
  const to = stateOf(flags.to);
@@ -37,6 +37,10 @@ function ownerOf(text) {
37
37
  return 'person:' + t.slice(0, 60);
38
38
  }
39
39
 
40
+ /** Every breakdown item by id, read once (a Jira ticket drafted from an item takes its plan dates: batch 7 item 6). */
41
+ function itemsById(root) {
42
+ try { return planItems.readFold(root).items || {}; } catch { return {}; }
43
+ }
40
44
  function itemOf(root, id) {
41
45
  try { return planItems.readFold(root).items[id] || null; } catch { return null; }
42
46
  }
@@ -85,4 +89,4 @@ function write(root, events, actor, cli) {
85
89
  return planItems.appendFromUi(root, events, { actor: actor && actor.by ? { by: actor.by, via: 'ui' } : undefined });
86
90
  }
87
91
 
88
- module.exports = { STATE_OF, isItemId, ownerName, ownerOf, itemOf, rowsOf, stateEvents, editEvents, write };
92
+ module.exports = { STATE_OF, isItemId, ownerName, ownerOf, itemOf, itemsById, rowsOf, stateEvents, editEvents, write };
@@ -11,7 +11,7 @@
11
11
  * pmos workflow judge --board <id> --id <initiative> --stage <key> --undo
12
12
  * records PMOS's reading of an Only-when stage (one stage-judge line in boards.jsonl): yes runs it, no skips it, unsure asks the PM.
13
13
  * pmos workflow of <initiative> the workflow the initiative runs, its current stage, and every stage numbered (done, current, skipped)
14
- * pmos workflow move <initiative> --stage <key|name> [--why <text>]
14
+ * pmos workflow move <initiative> --stage <key|name|number> [--why <text>]
15
15
  * pmos workflow switch <initiative> --to <workflow id> [--stage <key|name>] [--why <text>]
16
16
  * move the initiative along its workflow, or put it on another workflow, as the PM asked (bug 2026-10-25). These run the Board's own
17
17
  * write routes (lib/routes-boards.js move, switchWorkflow) outside HTTP, so the checks, the warnings and the boards.jsonl line are the
@@ -45,7 +45,7 @@ const USAGE = [
45
45
  ' pmos workflow judge --board <id> --id <initiative> --stage <key> --undo',
46
46
  ' Record PMOS\'s reading of an Only-when stage: yes runs it, no skips it, unsure asks the PM. Give the reason and where you read it.',
47
47
  ' pmos workflow of <initiative> the workflow it runs and its current stage, every stage numbered',
48
- ' pmos workflow move <initiative> --stage <key|name> [--why <text>]',
48
+ ' pmos workflow move <initiative> --stage <key|name|number> [--why <text>]',
49
49
  ' Move the initiative to a stage of its own workflow, when the PM asks. The stage card and the Board show it at once.',
50
50
  ' pmos workflow switch <initiative> --to <workflow id> [--stage <key|name>] [--why <text>]',
51
51
  ' Put the initiative on another workflow, when the PM asks. Without --stage it lands where the Board\'s switch puts it.',
@@ -186,7 +186,7 @@ const ofJson = (r) => ({ initiative: { id: r.row.id, title: r.row.title }, board
186
186
 
187
187
  function onInitiative(verb, { pos, flags, json, say, fail, root, stateDir, actor }) {
188
188
  const id = pos[0];
189
- const usage = { of: 'pmos workflow of <initiative>', move: 'pmos workflow move <initiative> --stage <key|name> [--why <text>]', switch: 'pmos workflow switch <initiative> --to <workflow id> [--stage <key|name>] [--why <text>]' }[verb];
189
+ const usage = { of: 'pmos workflow of <initiative>', move: 'pmos workflow move <initiative> --stage <key|name|number> [--why <text>]', switch: 'pmos workflow switch <initiative> --to <workflow id> [--stage <key|name>] [--why <text>]' }[verb];
190
190
  if (!id) { say('usage: ' + usage); return 2; }
191
191
  if (verb === 'move' && !flags.stage) { say('usage: ' + usage); return 2; }
192
192
  if (verb === 'switch' && !flags.to) { say('usage: ' + usage); return 2; }
@@ -205,6 +205,12 @@ function onInitiative(verb, { pos, flags, json, say, fail, root, stateDir, actor
205
205
  const g = { ok: true, actor };
206
206
  const base = { ws: w.id, board: before.board.id, id, ...(flags.why ? { why: flags.why } : {}) };
207
207
  let to = flags.stage;
208
+ // a stage by its number, as pmos workflow of numbers them (batch 7 item 2: "--stage 5" was refused)
209
+ if (/^\d+$/.test(String(to || '').trim()) && verb === 'move') {
210
+ const st = (before.row.wfStages || [])[Number(to) - 1];
211
+ if (!st) return fail(`there is no stage ${to}: ${before.row.wf.name} has ${(before.row.wfStages || []).length} stages`);
212
+ to = st.key;
213
+ }
208
214
  let r;
209
215
  if (verb === 'move') {
210
216
  // Product feature: the Board's move names the stage; a key of Product feature reads as its name
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.416.0",
3
+ "version": "0.418.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.416.0",
9
+ "version": "0.418.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.416.0",
3
+ "version": "0.418.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -38,6 +38,10 @@ const finish = async (code) => {
38
38
  process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
39
39
 
40
40
  /** Every line of a ledger the routes append to, wherever the repository keeps it. */
41
+ // a stage move is a move line, or (batch 7 item 4) the ini-wf line that pins a Product feature initiative to a stage the board has no column for
42
+ const isMove = (l) => l.kind === 'move' || (l.kind === 'ini-wf' && !!l.moved);
43
+ const toOf = (l) => (l.kind === 'ini-wf' ? l.moved.to : l.to);
44
+ const sameStage = (a, b) => String(a).toLowerCase() === String(b).toLowerCase(); // a stored Product feature key against its name
41
45
  const lines = (name) => {
42
46
  const out = [];
43
47
  const walk = (d) => { for (const e of fs.readdirSync(d, { withFileTypes: true })) { if (e.name === '.git') continue; const p = path.join(d, e.name); if (e.isDirectory()) walk(p); else if (e.name === name) out.push(...fs.readFileSync(p, 'utf8').split('\n').filter(Boolean).map((x) => JSON.parse(x))); } };
@@ -195,10 +199,10 @@ const ALLOWED = /^\/api\/(?:boards\/(?:asks\/(?:add|accept|decline)|move|archive
195
199
  await (async (pg) => { if (await pg.$('#czViewer [data-hi-view="stage"]')) await pg.click('#czViewer [data-hi-view="stage"]'); else await viaMore(pg, 'Stage'); })(ip);
196
200
  const bar = await until(() => ip.evaluate(() => { const v = document.querySelector('#czViewer:not([hidden])'); if (!v || !v.querySelector('[data-ov-move]')) return null; const cur = v.querySelector('[data-ov-move][aria-pressed="true"]'); return { moves: [...v.querySelectorAll('[data-ov-move]')].map((x) => x.dataset.ovMove), cur: cur ? cur.dataset.ovMove : '', life: [...v.querySelectorAll('[data-ov-life]')].map((x) => x.dataset.ovLife) }; }), 60000);
197
201
  ok('I1 the Overview offers the stages, the current one pressed, and the lifecycle presses', !!bar && bar.moves.length > 1 && !!bar.cur && bar.moves.indexOf(bar.cur) < bar.moves.length - 1 && bar.life.join() === 'on-hold,cancelled', JSON.stringify(bar) + ' ' + (await ip.evaluate(() => (document.querySelector('#czViewer .cz-vw-body') || {}).innerText || 'no Viewer')).slice(0, 400));
198
- const n0 = lines('boards.jsonl').filter((l) => l.kind === 'move').length;
202
+ const n0 = lines('boards.jsonl').filter(isMove).length;
199
203
  const next = bar ? bar.moves[bar.moves.indexOf(bar.cur) + 1] : '';
200
204
  await ip.click(`#czViewer [data-ov-move="${next}"]`);
201
- ok('I2 a stage press records one move line', await until(() => { const L = lines('boards.jsonl').filter((l) => l.kind === 'move'); return L.length === n0 + 1 && L[L.length - 1].id === 'pa-one' && L[L.length - 1].to === next; }), JSON.stringify(lines('boards.jsonl').filter((l) => l.kind === 'move').slice(-1)));
205
+ ok('I2 a stage press records one move line', await until(() => { const L = lines('boards.jsonl').filter(isMove); return L.length === n0 + 1 && L[L.length - 1].id === 'pa-one' && sameStage(toOf(L[L.length - 1]), next); }), JSON.stringify(lines('boards.jsonl').filter(isMove).slice(-1)));
202
206
  ok('I2 the Overview then shows the new stage pressed', await until(() => ip.evaluate((n) => !!document.querySelector(`#czViewer [data-ov-move="${n}"][aria-pressed="true"]`), next)));
203
207
  const lif0 = lines('lifecycle.jsonl').length;
204
208
  await ip.click('#czViewer [data-ov-life="on-hold"]');
@@ -212,13 +216,13 @@ const ALLOWED = /^\/api\/(?:boards\/(?:asks\/(?:add|accept|decline)|move|archive
212
216
  const back = await openNext();
213
217
  ok('I4 the card\'s next stage opens Move to the next stage now and Back', back && await ip.evaluate(() => /^Move to .+ now$/.test(((document.querySelector('.hi-pop [data-hi-go]') || {}).textContent || '').trim())));
214
218
  if (back) {
215
- const m0 = lines('boards.jsonl').filter((l) => l.kind === 'move').length;
219
+ const m0 = lines('boards.jsonl').filter(isMove).length;
216
220
  await ip.click('.hi-pop [data-hi-goback]');
217
221
  const asked = await until(() => ip.evaluate(() => { const d = document.querySelector('.hi-pop[role="dialog"]'); return d ? { go: d.querySelector('[data-hi-go]').disabled, chips: d.querySelectorAll('[data-hi-why]').length } : null; }));
218
- ok('I4 Back asks why first: Move back waits for a reason and records nothing yet', !!asked && asked.go === true && asked.chips === 4 && lines('boards.jsonl').filter((l) => l.kind === 'move').length === m0, JSON.stringify(asked));
222
+ ok('I4 Back asks why first: Move back waits for a reason and records nothing yet', !!asked && asked.go === true && asked.chips === 4 && lines('boards.jsonl').filter(isMove).length === m0, JSON.stringify(asked));
219
223
  await ip.click('.hi-pop [data-hi-why="New research"]'); await ip.fill('.hi-pop #hiWhy', 'Interviews changed the scope');
220
224
  await ip.click('.hi-pop [data-hi-go]');
221
- ok('I4 Move back records one move line with the reason as its why', await until(() => { const L = lines('boards.jsonl').filter((l) => l.kind === 'move'); const x = L[L.length - 1]; return L.length === m0 + 1 && x.id === 'pa-one' && x.to === bar.cur && x.why === 'Back: New research. Interviews changed the scope'; }), JSON.stringify(lines('boards.jsonl').filter((l) => l.kind === 'move').slice(-1)));
225
+ ok('I4 Move back records one move line with the reason as its why', await until(() => { const L = lines('boards.jsonl').filter(isMove); const x = L[L.length - 1]; return L.length === m0 + 1 && x.id === 'pa-one' && sameStage(toOf(x), bar.cur) && x.why === 'Back: New research. Interviews changed the scope'; }), JSON.stringify(lines('boards.jsonl').filter((l) => l.kind === 'move').slice(-1)));
222
226
  ok('I4 the Undo toast shows after the move', await until(() => ip.evaluate(() => { const t = document.querySelector('#hiToast'); return !!t && !t.hidden && /moved to/.test(t.textContent) && !!t.querySelector('[data-hi-undo]'); })));
223
227
  await openNext();
224
228
  await ip.click('.hi-pop [data-hi-auto]');
@@ -185,7 +185,8 @@ function openFind(from) {
185
185
  function pickFind() {
186
186
  const b = $$('#bdQr .bd-mi')[findAt]; if (b) b.click();
187
187
  }
188
- /** The Filter's groups: owner, workflow and category (WfAElse: Kind became Workflow), sprint (from the Jira reading, and the backlog).
188
+ /** The Filter's groups: owner, workflow and category (WfAElse: Kind became Workflow), sprint (from the Jira reading, and the backlog; on the
189
+ * timeline only on the Sprint span, TsSprintFilter).
189
190
  * The workflow is one choice, the same one the chip row picks (pm/bd-wf.js); it shows only with more than one workflow on the board. */
190
191
  function filterHtml() {
191
192
  const rows = M().initiatives.list.rows, F = A.F;
@@ -200,7 +201,7 @@ function filterHtml() {
200
201
  return grp + `<p class="bd-mlbl">Owner</p><div class="bd-fg">${owners.map((o) => chip('owners', o, (o === 'No owner' ? '' : V.avatar(o, 'xs')) + esc(o))).join('')}</div>`
201
202
  + (W.list.length > 1 ? `<p class="bd-mlbl">Workflow</p><div class="bd-fg" role="radiogroup" aria-label="Workflow">${W.list.map((w) => { const on = WF.narrowed(W.list) && W.cur.id === w.id; return `<button type="button" class="bd-chip${on ? ' on' : ''}" role="radio" aria-checked="${on}" data-fwf="${esc(w.id)}">${WF.wfIcon(w, 16)}${esc(w.name)}</button>`; }).join('')}</div>` : '')
202
203
  + (cats.length ? `<p class="bd-mlbl">Category</p><div class="bd-fg">${cats.map((k) => chip('cats', k, esc(WF.catLabel(k)))).join('')}</div>` : '')
203
- + (sprints.length ? `<p class="bd-mlbl">Sprint</p><div class="bd-fg">${sprints.map((s) => chip('sprints', s.name, esc(s.name + (s.now ? ' · now' : '')))).join('')}${chip('sprints', 'Backlog')}</div>` : '')
204
+ + (sprints.length && (!A.sprintFilter || A.sprintFilter()) ? `<p class="bd-mlbl">Sprint</p><div class="bd-fg">${sprints.map((s) => chip('sprints', s.name, esc(s.name + (s.now ? ' · now' : '')))).join('')}${chip('sprints', 'Backlog')}</div>` : '')
204
205
  + `<div class="bd-arow bd-ffoot"><button type="button" class="bd-btn sm ghost" data-fclear>Clear</button><span class="bd-amut bd-push">Applies as you pick</span></div>`;
205
206
  }
206
207
  function openFilter(from) { Pop.open(filterHtml(), from, { label: 'Filter', width: 340, align: 'right', cls: 'bd-filter' }); }
@@ -0,0 +1,164 @@
1
+ /* pm/bd-scroll.js — the timeline's sideways scroll (feedback batch 7, timeline spans C: TsCOpen, TsCDesk, TsCPhone, TsCPhoneBack, TsCEdges,
2
+ * TsCGrill). pm/bd-span.js draws a track wider than the screen from Quarter on; this module moves it and keeps what sits at its edges true.
3
+ * · open: today sits 25% of the way in, on every span. Switching span keeps the date in the middle in the middle, or keeps today in place
4
+ * when it is in view. A redraw (a filter, the panel) keeps the place the same way. The scroll position is not remembered across visits.
5
+ * · scroll: trackpad, Shift + wheel, a drag on empty track (a drag that starts on a bar or a name still opens it), ← → by half a screen,
6
+ * T for today, a swipe on a phone. The name column stays pinned (CSS: position sticky).
7
+ * · Today: in view, the pill on the today line. Off screen, the back button beside "Initiative" (on the axis edge on a phone) with its arrow
8
+ * pointing the way back; a press scrolls back to today.
9
+ * · edge tabs: a row whose marks are all behind the view shows its left tab, all ahead its right tab; a program's next milestone past the
10
+ * view waits on the right. A press scrolls the bar into view.
11
+ * · the first column on screen carries the year; the fades show only on the side where there is more; the scroller names its range for
12
+ * a screen reader ("Timeline, Jan 2027 to Dec 2027").
13
+ * · reveal(key): Find scrolls an off-screen bar into view and tints its row for a moment.
14
+ * Sprint does not scroll (data-fixed). */
15
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
16
+ const monthYear = (d) => MON[d.getMonth()] + ' ' + d.getFullYear();
17
+
18
+ let cur = null; // the timeline on screen: { el, sc, from, to, tw, nw, span }
19
+ let keep = null; // its place before a redraw: { span, mid, todayAt }
20
+ let ro = null;
21
+
22
+ /** The place of the timeline on screen, kept for the next draw. */
23
+ function capture() {
24
+ if (!cur || !cur.el.isConnected || cur.fixed) return null;
25
+ const v = view(), now = +cur.el.dataset.now, tx = xOf(now);
26
+ return { span: cur.span, mid: dateAt(v.l + v.w / 2), todayAt: tx >= v.l && tx <= v.l + v.w ? (tx - v.l) / v.w : null };
27
+ }
28
+ /** Leaving the timeline: the next visit opens at today again. */
29
+ export function forget() { keep = null; cur = null; }
30
+
31
+ const xOf = (ms) => ((ms - cur.from) / (cur.to - cur.from)) * cur.tw;
32
+ const dateAt = (x) => cur.from + (x / cur.tw) * (cur.to - cur.from);
33
+ function view() { return { l: cur.sc.scrollLeft, w: Math.max(1, cur.sc.clientWidth - cur.nw) }; }
34
+ function scrollToX(x, smooth) { cur.sc.scrollTo({ left: Math.max(0, x), behavior: smooth ? 'smooth' : 'auto' }); }
35
+ /** Today 25% of the way in (TsCOpen). */
36
+ function toToday(smooth) { const v = view(); scrollToX(xOf(+cur.el.dataset.now) - v.w * 0.25, smooth); }
37
+
38
+ /** The track's width for the screen it is on: one screen holds the span's columns. */
39
+ function size() {
40
+ const ratio = +cur.el.dataset.ratio || 1, w = Math.max(1, cur.sc.clientWidth - cur.nw);
41
+ cur.tw = Math.round(w * ratio);
42
+ cur.sc.style.setProperty('--tw', cur.tw + 'px');
43
+ cur.sc.style.setProperty('--vw', cur.sc.clientWidth + 'px');
44
+ }
45
+
46
+ /** Wire the timeline just drawn in `host`. A different span than before opens where the rules say (see the head of this file). */
47
+ export function mount(host) {
48
+ const before = keep || capture();
49
+ keep = null;
50
+ if (ro) { ro.disconnect(); ro = null; }
51
+ const el = host && host.querySelector('.tg-s');
52
+ if (!el) { cur = null; return; }
53
+ const sc = el.querySelector('.tg-sc'), nameCell = el.querySelector('.tg-h > .tg-n');
54
+ cur = { el, sc, from: +el.dataset.from, to: +el.dataset.to, span: el.dataset.span, fixed: el.hasAttribute('data-fixed'), nw: nameCell ? nameCell.getBoundingClientRect().width : 0, tw: 0 };
55
+ size();
56
+ if (!cur.fixed) {
57
+ if (!before || before.span === 'sprint') toToday(false);
58
+ else if (before.todayAt != null) { const v = view(); scrollToX(xOf(+el.dataset.now) - v.w * before.todayAt); }
59
+ else { const v = view(); scrollToX(xOf(before.mid) - v.w / 2); }
60
+ }
61
+ sc.addEventListener('scroll', schedule, { passive: true });
62
+ sc.addEventListener('keydown', onKey);
63
+ sc.addEventListener('pointerdown', onDown);
64
+ el.addEventListener('click', onClick, true);
65
+ ro = new ResizeObserver(() => { if (!cur || cur.el !== el) return; const v = view(), mid = dateAt(v.l + v.w / 2); cur.nw = nameCell ? nameCell.getBoundingClientRect().width : 0; size(); scrollToX(xOf(mid) - view().w / 2); update(); });
66
+ ro.observe(sc);
67
+ update();
68
+ }
69
+ /** Before the page redraws the board: keep the timeline's place (a span switch, a filter, the panel). */
70
+ export function hold() { keep = capture(); }
71
+
72
+ let raf = 0;
73
+ function schedule() { if (!raf) raf = requestAnimationFrame(() => { raf = 0; if (cur && cur.el.isConnected) update(); }); }
74
+
75
+ function update() {
76
+ const v = view(), el = cur.el, max = cur.sc.scrollWidth - cur.sc.clientWidth;
77
+ el.classList.toggle('more-l', !cur.fixed && v.l > 1);
78
+ el.classList.toggle('more-r', !cur.fixed && v.l < max - 1);
79
+ cur.sc.setAttribute('aria-label', 'Timeline, ' + monthYear(new Date(dateAt(v.l))) + ' to ' + monthYear(new Date(dateAt(v.l + v.w))) + (cur.fixed ? '' : '. Left and right arrows move half a screen, T goes to today'));
80
+ // Today: the pill on the line in view, else the back button with its arrow pointing the way
81
+ const tx = xOf(+el.dataset.now), back = el.querySelector('.tg-tback'), off = tx < v.l ? 'l' : tx > v.l + v.w ? 'r' : '';
82
+ if (back) { back.hidden = !off || cur.fixed; back.classList.toggle('l', off === 'l'); back.classList.toggle('r', off === 'r'); }
83
+ // the first column on screen carries the year (TsCGrill 10)
84
+ const ticks = [...el.querySelectorAll('.tg-h .tg-p > span[data-y], .tgq-h .tg-p > span[data-y]')];
85
+ let first = null;
86
+ for (const t of ticks) { if (t.offsetLeft <= v.l + 2) first = t; else break; }
87
+ if (!first) first = ticks[0] || null;
88
+ for (const t of ticks) {
89
+ const pin = t === first && !cur.fixed, s = t.querySelector('small');
90
+ if (t.classList.contains('pin') !== pin || pin) {
91
+ t.classList.toggle('pin', pin);
92
+ if (s && !t.hasAttribute('data-plain')) { if (!('sub' in t.dataset)) t.dataset.sub = s.textContent; s.textContent = pin ? [t.dataset.base, t.dataset.y].filter(Boolean).join(' · ') : t.dataset.sub; }
93
+ const next = ticks[ticks.indexOf(t) + 1], room = (next ? next.offsetLeft : cur.tw) - t.offsetLeft - t.offsetWidth;
94
+ t.style.transform = pin && v.l > t.offsetLeft ? `translateX(${Math.max(0, Math.min(v.l - t.offsetLeft, room))}px)` : '';
95
+ }
96
+ }
97
+ // edge tabs (TsCDesk, TsCEdges 1): one per side at most, at the edge of the view
98
+ for (const b of el.querySelectorAll('.tg-edge')) {
99
+ let show = false;
100
+ if (b.dataset.edge === 'm') {
101
+ const ms = JSON.parse(b.dataset.ms || '[]'), next = ms.find(([p]) => (p / 100) * cur.tw > v.l + v.w);
102
+ show = !!next; if (next) { b.querySelector('span').textContent = next[1]; b.dataset.go = next[0]; b.setAttribute('aria-label', 'Next program milestone: ' + next[1] + '. Scroll to it'); }
103
+ } else {
104
+ const a = (+b.dataset.a / 100) * cur.tw, z = (+b.dataset.b / 100) * cur.tw;
105
+ show = b.dataset.edge === 'l' ? z < v.l - 4 : a > v.l + v.w + 4;
106
+ }
107
+ b.hidden = !show || cur.fixed; b.tabIndex = show ? 0 : -1;
108
+ if (show) b.style.left = b.dataset.edge === 'l' ? v.l + 6 + 'px' : v.l + v.w - 6 + 'px';
109
+ }
110
+ }
111
+
112
+ /** Scroll a stretch of the track into view: centred, or its near end in view when it is wider than the screen. */
113
+ function bring(a, b, side) {
114
+ const v = view();
115
+ if (b - a < v.w * 0.9) scrollToX((a + b) / 2 - v.w / 2, true);
116
+ else scrollToX(side === 'l' ? b - v.w * 0.85 : a - v.w * 0.15, true);
117
+ }
118
+
119
+ function onClick(e) {
120
+ if (dragged) { e.preventDefault(); e.stopPropagation(); dragged = false; return; }
121
+ const t = e.target.closest('.tg-tback, .tg-edge'); if (!t || !cur) return;
122
+ e.preventDefault(); e.stopPropagation();
123
+ if (t.classList.contains('tg-tback')) { toToday(true); return; }
124
+ if (t.dataset.edge === 'm') { const x = (+t.dataset.go / 100) * cur.tw; bring(x, x, 'r'); return; }
125
+ bring((+t.dataset.a / 100) * cur.tw, (+t.dataset.b / 100) * cur.tw, t.dataset.edge);
126
+ }
127
+
128
+ function onKey(e) {
129
+ if (!cur || cur.fixed || e.altKey || e.ctrlKey || e.metaKey || /^(INPUT|TEXTAREA|SELECT)$/.test(e.target.tagName)) return;
130
+ const v = view();
131
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') { e.preventDefault(); scrollToX(v.l + (e.key === 'ArrowLeft' ? -1 : 1) * v.w / 2, true); }
132
+ else if (e.key === 't' || e.key === 'T') { e.preventDefault(); toToday(true); }
133
+ }
134
+
135
+ // a drag on empty track scrolls (a mouse; touch and a trackpad scroll natively). A drag that starts on a bar, a name or a button does not.
136
+ let drag = null, dragged = false;
137
+ function onDown(e) {
138
+ if (!cur || cur.fixed || e.button !== 0 || e.pointerType !== 'mouse' || e.target.closest('button, a, .tg-bar, .tg-n, .tgq-n, .bd-prdb, .tg-psb')) return;
139
+ drag = { x: e.clientX, l: cur.sc.scrollLeft, id: e.pointerId }; dragged = false;
140
+ window.addEventListener('pointermove', onMove);
141
+ window.addEventListener('pointerup', onUp, { once: true });
142
+ }
143
+ function onMove(e) {
144
+ if (!drag || !cur) return;
145
+ const dx = e.clientX - drag.x;
146
+ if (!dragged && Math.abs(dx) < 4) return;
147
+ if (!dragged) { dragged = true; cur.el.classList.add('dragging'); }
148
+ cur.sc.scrollLeft = drag.l - dx;
149
+ }
150
+ function onUp() { window.removeEventListener('pointermove', onMove); drag = null; if (cur) cur.el.classList.remove('dragging'); setTimeout(() => { dragged = false; }, 0); }
151
+
152
+ /** Find (TsCEdges 4): scroll the row's bar into view when it is off screen, and tint the row for a moment. */
153
+ export function reveal(key) {
154
+ if (!cur || !cur.el.isConnected) return;
155
+ const row = [...cur.el.querySelectorAll('[data-row]')].find((r) => r.dataset.row === key); if (!row) return;
156
+ const p = row.querySelector('.tg-p[data-a]');
157
+ if (p && !cur.fixed) {
158
+ const a = (+p.dataset.a / 100) * cur.tw, b = (+p.dataset.b / 100) * cur.tw, v = view();
159
+ if (b < v.l || a > v.l + v.w) bring(a, b, b < v.l ? 'l' : 'r');
160
+ }
161
+ row.scrollIntoView({ block: 'nearest' });
162
+ row.classList.remove('tint'); void row.offsetWidth; row.classList.add('tint');
163
+ setTimeout(() => row.classList.remove('tint'), 1600);
164
+ }