@kolkrabbi/kol-component 0.313.1 → 0.314.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.313.1",
3
+ "version": "0.314.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,8 +26,8 @@
26
26
  "embla-carousel-react": "^8.6.0",
27
27
  "pdfjs-dist": "^6.3.289",
28
28
  "react-syntax-highlighter": "^16.1.1",
29
- "@kolkrabbi/kol-search": "^0.3.0",
30
- "@kolkrabbi/kol-markdown": "^0.2.0"
29
+ "@kolkrabbi/kol-markdown": "^0.2.0",
30
+ "@kolkrabbi/kol-search": "^0.3.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@kolkrabbi/kol-icons": ">=0.22.0",
@@ -0,0 +1,33 @@
1
+ import { useEffect } from 'react'
2
+
3
+ /**
4
+ * useScrollFade — the scroll state a `.kol-scroll-fade` box fades by (TimeSetAndSiteRailFade, kol-website 2026-10-29 —
5
+ * user: *"FADE WHAT VERTICALLY SCROLLS into clipping!!!"*). On the element `ref` points at it sets `data-fade-top` once the
6
+ * box is scrolled, and `data-fade-bottom` while more lies below; kol-theme's `.kol-scroll-fade` draws the two fades from
7
+ * them. Re-read on scroll and whenever the box or its content changes size. One rule for every vertically scrolling rail
8
+ * or list that clips: the site rail, the app rail, the workshop's rails.
9
+ */
10
+ export default function useScrollFade(ref, enabled = true) {
11
+ useEffect(() => {
12
+ const el = ref.current
13
+ if (!el || !enabled) return undefined
14
+ const read = () => {
15
+ el.toggleAttribute('data-fade-top', el.scrollTop > 1)
16
+ el.toggleAttribute('data-fade-bottom', el.scrollTop + el.clientHeight < el.scrollHeight - 1)
17
+ }
18
+ read()
19
+ el.addEventListener('scroll', read, { passive: true })
20
+ const ro = new ResizeObserver(read)
21
+ ro.observe(el)
22
+ for (const c of el.children) ro.observe(c)
23
+ const mo = new MutationObserver(() => { for (const c of el.children) ro.observe(c); read() })
24
+ mo.observe(el, { childList: true })
25
+ return () => {
26
+ el.removeEventListener('scroll', read)
27
+ ro.disconnect()
28
+ mo.disconnect()
29
+ el.removeAttribute('data-fade-top')
30
+ el.removeAttribute('data-fade-bottom')
31
+ }
32
+ }, [ref, enabled])
33
+ }
package/src/index.js CHANGED
@@ -268,6 +268,11 @@ export { SOLO, ADJACENT, INDICATOR, glyphSize, indicatorSize } from './hooks/gly
268
268
  export { default as usePrefersReducedMotion } from './hooks/usePrefersReducedMotion.js'
269
269
  export { default as useReveal } from './hooks/useReveal.js'
270
270
  export { default as useScrollSpy } from './hooks/useScrollSpy.js'
271
+ export { default as useScrollFade } from './hooks/useScrollFade.js'
272
+ /* the time set — Timeline · Month · Week · Day over one model (TimeSetAndSiteRailFade, 2026-10-29; kol-atlas's views) */
273
+ export { default as TimeSet } from './organisms/TimeSet.jsx'
274
+ export { timelineModel } from './organisms/time/model.js'
275
+ export { renderTimeline, mountTimeline, printTimeline } from './organisms/time/view.js'
271
276
  export { default as useTilt } from './hooks/useTilt.js'
272
277
  export { default as usePlayback } from './hooks/usePlayback.js'
273
278
  export { default as useCoarsePointer } from './hooks/useCoarsePointer.js'
@@ -5,6 +5,7 @@ import gsap from 'gsap'
5
5
  * app rail and the site rail are one component, and a site must not install the app shell
6
6
  * for its sidebar — the PageHeader precedent. kol-shell re-exports it. */
7
7
  import Button from '../atoms/Button.jsx'
8
+ import useScrollFade from '../hooks/useScrollFade.js'
8
9
  import { Tooltip } from '../utilities/Popover.jsx'
9
10
  import { GRAB } from '../utilities/motion.js'
10
11
  /* the grab pill's proximity wake, travel and dwell — ONE implementation, shared
@@ -339,6 +340,9 @@ function AppRail({
339
340
  const snapOpenRef = useRef(null)
340
341
  const slotRef = useRef(null)
341
342
  const ctx = useRailSlot()
343
+ /* the list fades where it clips — the head once scrolled, the foot while more lies below (kol-theme `.kol-scroll-fade`) */
344
+ const listRef = useRef(null)
345
+ useScrollFade(listRef, fade)
342
346
  const setSlot = ctx?.setSlot
343
347
  const setCtxOpen = ctx?.setRailOpen
344
348
  const slotOpen = drawer || railOpen
@@ -416,7 +420,7 @@ function AppRail({
416
420
  {/* THE LIST IS ITS OWN REGION (2026-10-02): it takes the room between the mark and the pinned
417
421
  * bottom rows — what the bare spacer used to hold — scrolls when the rows outrun the window,
418
422
  * and fades at its foot unless `fade={false}`. Same column, same gap, as the rail's own. */}
419
- <div style={ctx && slotOpen ? { flex: '0 1 auto' } : undefined} className={`kol-shell-rail-list flex min-h-0 w-full flex-1 flex-col items-start gap-2 overflow-y-auto overflow-x-hidden ${fade ? 'kol-shell-rail-list--fade' : ''}`.trim()}>
423
+ <div ref={listRef} style={ctx && slotOpen ? { flex: '0 1 auto' } : undefined} className={`kol-shell-rail-list flex min-h-0 w-full flex-1 flex-col items-start gap-2 overflow-y-auto overflow-x-hidden ${fade ? 'kol-shell-rail-list--fade kol-scroll-fade' : ''}`.trim()}>
420
424
  {section ? (
421
425
  <>
422
426
  <RailItem icon="arrow-left" path={section.path} label={section.label} currentPath="" onNavigate={() => setEntered(trail.slice(0, -1).map((t) => t.path))} iconComponent={iconComponent} railOpen={drawer || railOpen} />
@@ -3,6 +3,7 @@ import { createPortal } from 'react-dom'
3
3
  import { Icon } from '@kolkrabbi/kol-icons'
4
4
  import { Tooltip } from '../utilities/Popover.jsx'
5
5
  import useDragResize from '../hooks/useDragResize.js'
6
+ import useScrollFade from '../hooks/useScrollFade.js'
6
7
 
7
8
  /* taxonomy-ok: organism — NavRail's site variant; nests Tooltip (utility) + kol-icons' Icon.
8
9
  * Carried class-for-class from kol-framework's SideNav.jsx (2026-10-22, the one nav rail):
@@ -212,6 +213,10 @@ export default function NavRailSite({
212
213
  defaultOpen = [],
213
214
  openOnRoute = false,
214
215
  }) {
216
+ /* the tree fades where it clips — the head once scrolled, the foot while more lies below (kol-theme `.kol-scroll-fade`;
217
+ * TimeSetAndSiteRailFade, 2026-10-29) */
218
+ const scrollRef = useRef(null)
219
+ useScrollFade(scrollRef, fade)
215
220
  const Glyph = iconComponent ?? Icon
216
221
  const isPageActive = (to) => (isActive ? isActive(to) : pathname === to)
217
222
  /* a leaf is lit by its route, or — an action leaf — by its own `active` */
@@ -491,7 +496,7 @@ export default function NavRailSite({
491
496
  * collapsed tree they scrolled off below the footer — "pinned" only
492
497
  * held while the tree was shorter than the rail. They are the block
493
498
  * after it now, above the footer, the tree scrolling underneath. */}
494
- <div className={`kol-sidenav-scroll flex-1 overflow-y-auto pt-4 [scrollbar-width:thin] ${fade ? 'pb-12 kol-sidenav-scroll--fade' : 'pb-4'}`}>
499
+ <div ref={scrollRef} className={`kol-sidenav-scroll flex-1 overflow-y-auto pt-4 [scrollbar-width:thin] ${fade ? 'pb-12 kol-scroll-fade' : 'pb-4'}`}>
495
500
  <nav aria-label="Sections">
496
501
  <ul className="kol-sidenav-tree flex flex-col gap-[2px]">
497
502
  {navTree.map(renderCat)}
@@ -0,0 +1,25 @@
1
+ import { useEffect, useMemo, useRef } from 'react'
2
+ import { timelineModel } from './time/model.js'
3
+ import { mountTimeline } from './time/view.js'
4
+
5
+ /**
6
+ * TimeSet — a project in time, four ways: Timeline (phases across the whole project, dated checkpoints, breaks, the Today
7
+ * line) · Month · Week · Day, one switch, one legend, a phase's detail on click. kol-atlas's timeline views carried
8
+ * verbatim (TimeSetAndSiteRailFade, kol-website 2026-10-29 — user: *"in kol-atlas there are date components … we might
9
+ * just need day? and then we have a full 'time' set?"*), Day added. The views are plain HTML from `time/view.js`; this
10
+ * mounts them. Styles: kol-theme's `kol-components-time.css` (`--tl-*`, mapped to KOL's tokens).
11
+ *
12
+ * @param {Array} milestones parseProject's milestones (kol-atlas's shape) — `{ id, title, when, phases: [{ id, title, when,
13
+ * dw?, reason?, marks, items: [{ num, text, kind, date?, time? }] }] }`; or pass `model`
14
+ * @param {Object} model a `timelineModel(milestones)` already built
15
+ * @param {string} today ISO day the Today line marks (default: the real today)
16
+ * @param {Date|string} now the moment Day's Today line marks (default: now)
17
+ * @param {string} view 'timeline' | 'month' | 'week' | 'day' — the view to open on (else the viewer's last)
18
+ * @param {string} storageKey where the viewer's view is remembered (default `kol-time-view`)
19
+ */
20
+ export default function TimeSet({ milestones, model, today, now, view, storageKey, className = '' }) {
21
+ const ref = useRef(null)
22
+ const m = useMemo(() => model ?? timelineModel(milestones ?? []), [model, milestones])
23
+ useEffect(() => mountTimeline(ref.current, m, { today, now, view, storageKey }), [m, today, now, view, storageKey])
24
+ return <div ref={ref} className={className} />
25
+ }
@@ -0,0 +1,56 @@
1
+ /* The timeline's data, from parseProject's milestones: every date resolved to an ISO day, nothing typed here.
2
+ * Pure and JSON-safe, so the dev page and the artifact build (scripts/timeline-artifact.mjs) read the same model.
3
+ *
4
+ * kol-atlas's apps/workspace/src/timeline/model.js, carried verbatim into kol-component (TimeSetAndSiteRailFade, kol-website
5
+ * 2026-10-29). Two changes: atlas's `isOptional` is inlined (it lived in its render engine), and an item may carry a `time`
6
+ * ("14:00") — the Day view places it on its hour. A milestone is `{ id, title, when, phases }`, a phase `{ id, title, when,
7
+ * dw?, reason?, marks: [[mark, kind]], items: [{ num, text, kind: 'c' | …, date?, time? }] }` — parseProject's shape. */
8
+ /* a milestone is optional when every phase is parked (atlas's engine/render.js `isOptional`) */
9
+ const isOptional = (m) => m.phases.length > 0 && m.phases.every((p) => p.marks.some((k) => k[1] === 'park'))
10
+
11
+ const MONTHS = { jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5, jul: 6, aug: 7, sep: 8, oct: 9, nov: 10, dec: 11 }
12
+ const iso = (y, m, d) => new Date(Date.UTC(y, m, d)).toISOString().slice(0, 10)
13
+ const addDays = (s, n) => { const d = new Date(s + 'T00:00:00Z'); d.setUTCDate(d.getUTCDate() + n); return d.toISOString().slice(0, 10) }
14
+ const dayDiff = (a, b) => Math.round((new Date(b + 'T00:00:00Z') - new Date(a + 'T00:00:00Z')) / 864e5)
15
+
16
+ /* "26 – 30 Oct" · "26 Oct – 6 Nov" · "26 Oct – 16 Dec 2026" · "27 Oct" → [start, end]. A missing month takes the
17
+ * end's; a missing year takes `year`, minus one when the day would land after `before` (a range crossing New Year). */
18
+ function parseRange(s, year, before) {
19
+ const parts = s.replace(/\s+/g, ' ').trim().split(/\s*[–-]\s*/)
20
+ const read = (p) => { const m = /^(\d{1,2})(?: ([A-Za-z]{3})[a-z]*)?(?: (\d{4}))?$/.exec(p.trim()); return m ? { d: +m[1], m: m[2] ? MONTHS[m[2].toLowerCase()] : undefined, y: m[3] ? +m[3] : undefined } : null }
21
+ const a = read(parts[0]), b = read(parts[parts.length - 1])
22
+ if (!a || !b) return null
23
+ const y = b.y || year
24
+ if (a.m === undefined) a.m = b.m
25
+ const end = iso(y, b.m, b.d)
26
+ let start = iso(a.y || y, a.m, a.d)
27
+ if (start > end) start = iso((a.y || y) - 1, a.m, a.d)
28
+ if (before && end > before) return [iso((a.y || y) - 1, a.m, a.d), iso(y - 1, b.m, b.d)]
29
+ return [start, end]
30
+ }
31
+
32
+ const num = (t) => (/^((?:M)?\d+(?:\.\d+)?)\s+/.exec(t) || [])[1] || ''
33
+ const name = (t) => t.replace(/^(?:M?\d+(?:\.\d+)?)\s+/, '')
34
+
35
+ export function timelineModel(ms) {
36
+ const milestones = ms.map((m) => {
37
+ const yearOf = +(/(\d{4})\s*$/.exec(m.when) || [])[1]
38
+ const [mStart, mEnd] = parseRange(m.when, yearOf)
39
+ const slack = addDays(mEnd, 7)
40
+ const phases = m.phases.map((p) => {
41
+ const [start, end] = parseRange(p.when, yearOf, slack) || [mStart, mEnd]
42
+ return {
43
+ id: p.id, num: num(p.title), name: name(p.title), start, end, acceptance: p.dw || '',
44
+ confirm: p.marks.some((k) => k[1] !== 'park') ? p.reason : '', optional: p.marks.some((k) => k[1] === 'park'),
45
+ items: p.items.map((it) => ({ num: it.num, text: it.text, checkpoint: it.kind === 'c', date: it.date ? parseRange(it.date, yearOf, slack)[0] : '', time: it.time || '' })),
46
+ }
47
+ })
48
+ return { id: m.id, num: num(m.title), name: name(m.title), start: mStart, end: mEnd, optional: isOptional(m), phases }
49
+ })
50
+ const checkpoints = milestones.flatMap((m) => m.phases.flatMap((p) => p.items.filter((i) => i.checkpoint && i.date).map((i) => ({ date: i.date, time: i.time, label: i.text, num: i.num, phase: p.id, ms: m.num }))))
51
+ /* breaks: gaps of more than a weekend between one milestone's end and the next one's start */
52
+ const breaks = milestones.slice(1).map((m, i) => [addDays(milestones[i].end, 1), addDays(m.start, -1)]).filter(([a, b]) => dayDiff(a, b) > 3)
53
+ const first = milestones[0].start, last = milestones[milestones.length - 1].end
54
+ const mon = (s) => addDays(s, -((new Date(s + 'T00:00:00Z').getUTCDay() + 6) % 7))
55
+ return { start: mon(first), end: addDays(mon(last), 6), first, last, milestones, checkpoints, breaks }
56
+ }
@@ -0,0 +1,201 @@
1
+ /* The timeline views: model (model.js) in, HTML out — Timeline (Gantt) · Month · Week · Day, a phase's detail on click.
2
+ * No imports and no framework, so the timeline on Plan (/plan) and the artifact (scripts/timeline-artifact.mjs) run
3
+ * this same file. Styles: timeline.css, every colour a --tl-* variable each host sets.
4
+ *
5
+ * kol-atlas's apps/workspace/src/timeline/view.js, carried verbatim into kol-component (TimeSetAndSiteRailFade, kol-website
6
+ * 2026-10-29 — *"we might just need day? and then we have a full 'time' set?"*). Added: DAY — one day by hour, the phases
7
+ * running that day and its untimed checkpoints in an all-day lane, timed ones on their hour, the Today line at the hour
8
+ * now; the view is remembered under `kol-time-view`. The styles are kol-theme's kol-components-time.css. */
9
+
10
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
11
+ const MONTH = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
12
+ const WD = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
13
+ const VIEWS = [['timeline', 'Timeline'], ['month', 'Month'], ['week', 'Week'], ['day', 'Day']]
14
+
15
+ const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' })[c])
16
+ const D = (s) => new Date(s + 'T00:00:00Z')
17
+ const add = (s, n) => { const d = D(s); d.setUTCDate(d.getUTCDate() + n); return d.toISOString().slice(0, 10) }
18
+ const diff = (a, b) => Math.round((D(b) - D(a)) / 864e5)
19
+ const wd = (s) => (D(s).getUTCDay() + 6) % 7 // 0 = Monday
20
+ const monday = (s) => add(s, -wd(s))
21
+ const day = (s) => D(s).getUTCDate() + ' ' + MON[D(s).getUTCMonth()]
22
+ const dayY = (s) => day(s) + ' ' + D(s).getUTCFullYear()
23
+ const range = (a, b) => (a === b ? day(a) : D(a).getUTCMonth() === D(b).getUTCMonth() ? D(a).getUTCDate() + ' – ' + day(b) : day(a) + ' – ' + day(b))
24
+ const weekNo = (s) => { const d = D(s); d.setUTCDate(d.getUTCDate() + 3 - wd(s)); const y = new Date(Date.UTC(d.getUTCFullYear(), 0, 4)); return 1 + Math.round((d - y) / 864e5 / 7) }
25
+ const workdays = (a, b) => { let n = 0; for (let d = a; d <= b; d = add(d, 1)) if (wd(d) < 5) n++; return n }
26
+ const clamp = (s, a, b) => (s < a ? a : s > b ? b : s)
27
+ const inBreak = (m, s) => m.breaks.some(([a, b]) => s >= a && s <= b)
28
+
29
+ const phases = (m) => m.milestones.flatMap((ms, i) => ms.phases.map((p) => ({ ...p, msi: i, ms })))
30
+ const msClass = (i, ms) => 'tl-m' + (i + 1) + (ms.optional ? ' tl-opt' : '')
31
+ const marks = (p) => (p.confirm ? '<span class="tl-confirm" title="To confirm: ' + esc(p.confirm) + '"><i></i>To confirm</span>' : '')
32
+
33
+ function legend(m) {
34
+ return '<div class="tl-legend">' + m.milestones.map((ms, i) => '<span><b class="tl-sw ' + msClass(i, ms) + '"></b>' + esc(ms.num + ' ' + ms.name) + (ms.optional ? ' (optional)' : '') + '</span>').join('') +
35
+ '<span><b class="tl-dia"></b>Checkpoint</span><span class="tl-confirm"><i></i>To confirm</span><span><b class="tl-sw tl-sw-break"></b>Break</span><span><b class="tl-sw tl-sw-today"></b>Today</span></div>'
36
+ }
37
+
38
+ /* ---------- Timeline: one row per milestone and phase across the whole project ---------- */
39
+ function timeline(m, st) {
40
+ const total = diff(m.start, m.end) + 1
41
+ const x = (s) => (diff(m.start, s) / total) * 100
42
+ const w = (a, b) => ((diff(a, b) + 1) / total) * 100
43
+ const rows = []
44
+ m.milestones.forEach((ms, i) => {
45
+ rows.push({ kind: 'ms', ms, i })
46
+ ms.phases.forEach((p) => rows.push({ kind: 'ph', ms, i, p }))
47
+ })
48
+ const H = 34
49
+ let scale = '', bg = '', firstLab = true
50
+ for (let d = m.start; d <= m.end; d = add(d, 1)) {
51
+ /* a month label on each 1st, and on the range's first day only when its month has room before the next 1st; the year on the first label and on January */
52
+ if (D(d).getUTCDate() === 1 || (d === m.start && D(d).getUTCDate() < 20)) { scale += '<span class="tl-mo" style="left:' + x(d) + '%">' + MONTH[D(d).getUTCMonth()] + (D(d).getUTCMonth() === 0 || firstLab ? ' ' + D(d).getUTCFullYear() : '') + '</span>'; firstLab = false }
53
+ if (wd(d) === 0) scale += '<span class="tl-wk" style="left:' + x(d) + '%">' + D(d).getUTCDate() + '</span>', bg += '<i class="tl-vline" style="left:' + x(d) + '%"></i>'
54
+ if (wd(d) === 5) bg += '<i class="tl-weekend" style="left:' + x(d) + '%;width:' + w(d, add(d, 1)) + '%"></i>'
55
+ }
56
+ m.breaks.forEach(([a, b]) => { bg += '<i class="tl-break" style="left:' + x(a) + '%;width:' + w(a, b) + '%"><span>Break</span></i>' })
57
+ if (st.today >= m.start && st.today <= m.end) bg += '<i class="tl-today" style="left:' + (x(st.today) + 50 / total) + '%"><span>Today</span></i>'
58
+ const labels = rows.map((r) => r.kind === 'ms'
59
+ ? '<div class="tl-lab tl-lab-ms" style="height:' + H + 'px"><b>' + esc(r.ms.num) + '</b> ' + esc(r.ms.name) + (r.ms.optional ? ' <span class="tl-tag">Optional</span>' : '') + '</div>'
60
+ : '<button class="tl-lab' + (st.sel === r.p.id ? ' is-sel' : '') + '" data-phase="' + r.p.id + '" style="height:' + H + 'px"><span class="tl-num">' + esc(r.p.num) + '</span>' + esc(r.p.name) + marks(r.p) + '</button>').join('')
61
+ const bars = rows.map((r, k) => {
62
+ const top = k * H + 7
63
+ if (r.kind === 'ms') return '<div class="tl-band ' + msClass(r.i, r.ms) + '" style="top:' + top + 'px;left:' + x(r.ms.start) + '%;width:' + w(r.ms.start, r.ms.end) + '%" title="' + esc(r.ms.num + ' ' + r.ms.name + ' · ' + range(r.ms.start, r.ms.end)) + '"></div>'
64
+ const p = r.p
65
+ const cps = p.items.filter((it) => it.checkpoint && it.date).map((it) => '<span class="tl-cp' + (x(it.date) > 82 ? ' is-left' : '') + '" style="top:' + (top + 2) + 'px;left:' + (x(it.date) + 50 / total) + '%" title="' + esc(day(it.date) + ' · ' + it.text) + '"><b class="tl-dia"></b><em>' + esc(it.text.replace(/^[^:]+:\s*/, '')) + '</em></span>').join('')
66
+ return '<button class="tl-barp ' + msClass(r.i, r.ms) + (st.sel === p.id ? ' is-sel' : '') + '" data-phase="' + p.id + '" style="top:' + top + 'px;left:' + x(p.start) + '%;width:' + w(p.start, p.end) + '%" title="' + esc(p.num + ' ' + p.name + ' · ' + range(p.start, p.end)) + '"></button>' + cps
67
+ }).join('')
68
+ return '<div class="tl-gantt"><div class="tl-ggrid"><div class="tl-gl"><div class="tl-gh">Phase</div>' + labels + '</div>' +
69
+ '<div class="tl-gr"><div class="tl-gh tl-scale">' + scale + '</div><div class="tl-plot" style="height:' + rows.length * H + 'px">' + bg + bars + '</div></div></div></div>'
70
+ }
71
+
72
+ /* ---------- Month: weeks as rows, phases as bars across the days, checkpoints on their day ---------- */
73
+ function month(m, st) {
74
+ const c = D(st.cursor), y = c.getUTCFullYear(), mo = c.getUTCMonth()
75
+ const first = new Date(Date.UTC(y, mo, 1)).toISOString().slice(0, 10)
76
+ const last = new Date(Date.UTC(y, mo + 1, 0)).toISOString().slice(0, 10)
77
+ const all = phases(m)
78
+ let out = '<div class="tl-month"><div class="tl-wdays">' + WD.map((d) => '<span>' + d + '</span>').join('') + '</div>'
79
+ for (let ws = monday(first); ws <= last; ws = add(ws, 7)) {
80
+ const we = add(ws, 6)
81
+ const segs = all.filter((p) => p.start <= we && p.end >= ws).map((p) => ({ p, s: p.start < ws ? ws : p.start, e: p.end > we ? we : p.end }))
82
+ const lanes = []
83
+ segs.forEach((g) => { let l = lanes.findIndex((end) => end < g.s); if (l < 0) { l = lanes.length; lanes.push('') } lanes[l] = g.e; g.lane = l })
84
+ const span = 3 + lanes.length // day row, checkpoint row, the lanes, a closing gap
85
+ let cells = '', cps = ''
86
+ for (let i = 0; i < 7; i++) {
87
+ const d = add(ws, i)
88
+ const cls = ['tl-day', d < first || d > last ? 'is-out' : '', i > 4 ? 'is-we' : '', inBreak(m, d) ? 'is-break' : '', d === st.today ? 'is-today' : ''].filter(Boolean).join(' ')
89
+ cells += '<div class="' + cls + '" style="grid-column:' + (i + 1) + ';grid-row:1 / span ' + span + '"><span class="tl-dn">' + D(d).getUTCDate() + '</span></div>'
90
+ const here = m.checkpoints.filter((k) => k.date === d)
91
+ if (here.length) cps += '<div class="tl-mcp" style="grid-column:' + (i + 1) + ';grid-row:2">' + here.map((k) => '<button data-phase="' + k.phase + '" title="' + esc(k.label) + '"><b class="tl-dia"></b>' + esc(k.label.replace(/^[^:]+:\s*/, '')) + '</button>').join('') + '</div>'
92
+ }
93
+ const bars = segs.map((g) => '<button class="tl-seg ' + msClass(g.p.msi, g.p.ms) + (g.s === g.p.start ? ' is-start' : '') + (g.e === g.p.end ? ' is-end' : '') + (st.sel === g.p.id ? ' is-sel' : '') + '" data-phase="' + g.p.id + '" style="grid-column:' + (wd(g.s) + 1) + ' / ' + (wd(g.e) + 2) + ';grid-row:' + (g.lane + 3) + '" title="' + esc(g.p.num + ' ' + g.p.name + ' · ' + range(g.p.start, g.p.end)) + '"><span>' + esc(g.p.num + ' ' + g.p.name) + '</span></button>').join('')
94
+ out += '<div class="tl-week" style="grid-template-rows:30px auto' + ' auto'.repeat(lanes.length) + ' 8px">' + cells + cps + bars + '</div>'
95
+ }
96
+ return out + '</div>'
97
+ }
98
+
99
+ /* ---------- Week: the seven days with their checkpoints, then what is running ---------- */
100
+ function week(m, st) {
101
+ const ws = monday(st.cursor), we = add(ws, 6)
102
+ let strip = ''
103
+ for (let i = 0; i < 7; i++) {
104
+ const d = add(ws, i)
105
+ const here = m.checkpoints.filter((k) => k.date === d)
106
+ strip += '<div class="tl-wday' + (i > 4 ? ' is-we' : '') + (inBreak(m, d) ? ' is-break' : '') + (d === st.today ? ' is-today' : '') + '"><span class="tl-wdh">' + WD[i] + ' <b>' + D(d).getUTCDate() + '</b></span>' +
107
+ here.map((k) => '<button class="tl-wcp" data-phase="' + k.phase + '"><b class="tl-dia"></b><span>' + esc(k.label) + '</span><em>' + esc(k.num) + '</em></button>').join('') + '</div>'
108
+ }
109
+ const act = phases(m).filter((p) => p.start <= we && p.end >= ws)
110
+ const state = (p) => p.start >= ws ? 'Starts ' + WD[wd(p.start)] + ' ' + day(p.start) : p.end <= we ? 'Ends ' + WD[wd(p.end)] + ' ' + day(p.end) : 'Day ' + workdays(p.start, ws < p.start ? p.start : ws) + ' of ' + workdays(p.start, p.end)
111
+ const list = act.length
112
+ ? act.map((p) => '<button class="tl-act' + (st.sel === p.id ? ' is-sel' : '') + '" data-phase="' + p.id + '"><b class="tl-sw ' + msClass(p.msi, p.ms) + '"></b><span class="tl-act-t"><span class="tl-num">' + esc(p.num) + '</span>' + esc(p.name) + marks(p) + '</span><span class="tl-act-d">' + esc(range(p.start, p.end)) + '</span><span class="tl-act-s">' + esc(state(p)) + '</span>' + (p.acceptance ? '<span class="tl-act-a"><b>Acceptance:</b> ' + esc(p.acceptance) + '</span>' : '') + '</button>').join('')
113
+ : '<p class="tl-empty">' + (inBreak(m, ws) || inBreak(m, we) ? 'Break: no phase runs this week.' : 'No phase runs this week.') + '</p>'
114
+ return '<div class="tl-weekv"><div class="tl-wstrip">' + strip + '</div><h3 class="tl-h">Running this week</h3>' + list + '</div>'
115
+ }
116
+
117
+ /* ---------- Day: one day by hour — what runs all day, then each hour with its timed checkpoints, the Today line at now ---------- */
118
+ const H0 = 7, H1 = 20 // the hours a working day shows; a timed item outside them widens the range
119
+ const hourOf = (t) => (/^(\d{1,2})(?::(\d{2}))?/.exec(t || '') || []).slice(1).map((n) => +(n || 0))
120
+ function dayView(m, st) {
121
+ const d = st.cursor
122
+ const run = phases(m).filter((p) => p.start <= d && p.end >= d)
123
+ const here = m.checkpoints.filter((k) => k.date === d)
124
+ const timed = here.filter((k) => k.time), untimed = here.filter((k) => !k.time)
125
+ const hs = timed.map((k) => hourOf(k.time)[0])
126
+ /* on today the range also reaches the hour now, so the Today line always has a place */
127
+ const nowH = d === st.today && st.now != null ? Math.floor(st.now / 60) : null
128
+ const from = Math.min(H0, ...hs, ...(nowH != null ? [nowH] : [])), to = Math.max(H1, ...hs.map((h) => h + 1), ...(nowH != null ? [nowH + 1] : []))
129
+ const all = '<div class="tl-dall"><span class="tl-dlab">All day</span><div class="tl-dall-b">' +
130
+ (run.length || untimed.length
131
+ ? run.map((p) => '<button class="tl-dseg ' + msClass(p.msi, p.ms) + (st.sel === p.id ? ' is-sel' : '') + '" data-phase="' + p.id + '" title="' + esc(p.num + ' ' + p.name + ' · ' + range(p.start, p.end)) + '"><span>' + esc(p.num + ' ' + p.name) + '</span></button>').join('') +
132
+ untimed.map((k) => '<button class="tl-wcp" data-phase="' + k.phase + '"><b class="tl-dia"></b><span>' + esc(k.label) + '</span><em>' + esc(k.num) + '</em></button>').join('')
133
+ : '<p class="tl-empty">' + (inBreak(m, d) ? 'Break: no phase runs today.' : 'No phase runs this day.') + '</p>') + '</div></div>'
134
+ let rows = ''
135
+ for (let h = from; h < to; h++) {
136
+ const at = timed.filter((k) => hourOf(k.time)[0] === h)
137
+ rows += '<div class="tl-hour"><span class="tl-hl">' + String(h).padStart(2, '0') + ':00</span><div class="tl-hb">' +
138
+ at.map((k) => '<button class="tl-wcp" data-phase="' + k.phase + '"><b class="tl-dia"></b><span>' + esc(k.time + ' · ' + k.label) + '</span><em>' + esc(k.num) + '</em></button>').join('') + '</div></div>'
139
+ }
140
+ const now = d === st.today && st.now != null && st.now >= from * 60 && st.now < to * 60
141
+ ? '<i class="tl-dnow" style="top:calc(' + ((st.now - from * 60) / ((to - from) * 60)) * 100 + '% )"><span>Today</span></i>' : ''
142
+ return '<div class="tl-dayv' + (inBreak(m, d) ? ' is-break' : '') + '">' + all + '<div class="tl-hours">' + rows + now + '</div></div>'
143
+ }
144
+
145
+ function detail(m, st) {
146
+ const p = phases(m).find((q) => q.id === st.sel)
147
+ if (!p) return ''
148
+ return '<aside class="tl-detail"><button class="tl-x" data-close aria-label="Close">×</button>' +
149
+ '<p class="tl-eyebrow">' + esc(p.ms.num + ' ' + p.ms.name) + (p.ms.optional ? ' · Optional' : '') + '</p>' +
150
+ '<h3><span class="tl-num">' + esc(p.num) + '</span>' + esc(p.name) + '</h3>' +
151
+ '<p class="tl-meta"><b>Dates:</b> ' + esc(range(p.start, p.end)) + ' · ' + workdays(p.start, p.end) + ' working days</p>' +
152
+ (p.confirm ? '<p class="tl-meta"><span class="tl-confirm"><i></i>To confirm</span> ' + esc(p.confirm) + '</p>' : '') +
153
+ (p.acceptance ? '<p class="tl-meta"><b>Acceptance:</b> ' + esc(p.acceptance) + '</p>' : '') +
154
+ '<ol class="tl-items">' + p.items.map((it) => '<li><span class="tl-num">' + esc(it.num) + '</span>' + (it.checkpoint ? '<b class="tl-dia"></b>' : '') + esc(it.text) + (it.date ? ' <em>' + esc(WD[wd(it.date)] + ' ' + day(it.date)) + '</em>' : '') + '</li>').join('') + '</ol></aside>'
155
+ }
156
+
157
+ export function renderTimeline(m, st) {
158
+ const nav = st.view === 'timeline' ? '<span class="tl-title">' + esc(dayY(m.first) + ' – ' + dayY(m.last)) + '</span>'
159
+ : '<span class="tl-nav"><button data-nav="-1" aria-label="Previous">‹</button><span class="tl-title">' +
160
+ (st.view === 'month' ? MONTH[D(st.cursor).getUTCMonth()] + ' ' + D(st.cursor).getUTCFullYear() : st.view === 'day' ? WD[wd(st.cursor)] + ' ' + dayY(st.cursor) : 'Week ' + weekNo(st.cursor) + ' · ' + range(monday(st.cursor), add(monday(st.cursor), 6)) + ' ' + D(add(monday(st.cursor), 6)).getUTCFullYear()) +
161
+ '</span><button data-nav="1" aria-label="Next">›</button><button class="tl-todayb" data-nav="0">Today</button></span>'
162
+ const body = st.view === 'month' ? month(m, st) : st.view === 'week' ? week(m, st) : st.view === 'day' ? dayView(m, st) : timeline(m, st)
163
+ return '<div class="tl-bar"><div class="tl-switch" role="group" aria-label="View">' + VIEWS.map(([k, l]) => '<button data-view="' + k + '" aria-pressed="' + (st.view === k) + '">' + l + '</button>').join('') + '</div>' + nav + '</div>' +
164
+ legend(m) + '<div class="tl-body is-' + st.view + (st.sel ? ' has-detail' : '') + '">' + body + detail(m, st) + '</div>'
165
+ }
166
+
167
+ /* the Timeline view alone, static, for print (scripts/timeline-print.mjs): legend and chart, no controls */
168
+ export function printTimeline(m, today) {
169
+ return legend(m) + timeline(m, { today, sel: null })
170
+ }
171
+
172
+ /* the controller: one delegated click handler, state in a closure, the view remembered per viewer */
173
+ export function mountTimeline(root, m, opts = {}) {
174
+ const today = opts.today || new Date().toISOString().slice(0, 10)
175
+ const home = clamp(today, m.first, m.last)
176
+ let saved = null
177
+ try { saved = localStorage.getItem(opts.storageKey ?? 'kol-time-view') } catch { /* storage blocked: start on Timeline */ }
178
+ /* `now` — minutes since midnight, for the Day view's Today line */
179
+ const at = opts.now ? new Date(opts.now) : new Date()
180
+ const st = { view: VIEWS.some(([k]) => k === (opts.view ?? saved)) ? (opts.view ?? saved) : 'timeline', cursor: home, sel: null, today, now: at.getHours() * 60 + at.getMinutes() }
181
+ const draw = () => { root.innerHTML = renderTimeline(m, st) }
182
+ const onClick = (e) => {
183
+ const t = e.target.closest('[data-view],[data-nav],[data-phase],[data-close]')
184
+ if (!t || !root.contains(t)) return
185
+ if (t.dataset.view) { st.view = t.dataset.view; try { localStorage.setItem(opts.storageKey ?? 'kol-time-view', st.view) } catch { /* not remembered */ } }
186
+ else if (t.dataset.nav !== undefined) {
187
+ const n = +t.dataset.nav
188
+ if (n === 0) st.cursor = home
189
+ else if (st.view === 'month') { const d = D(st.cursor); d.setUTCDate(1); d.setUTCMonth(d.getUTCMonth() + n); st.cursor = clamp(d.toISOString().slice(0, 10), m.first.slice(0, 8) + '01', m.last) }
190
+ else if (st.view === 'day') st.cursor = clamp(add(st.cursor, n), m.start, m.end)
191
+ else st.cursor = clamp(add(st.cursor, 7 * n), monday(m.first), m.last)
192
+ }
193
+ else if (t.dataset.phase) st.sel = st.sel === t.dataset.phase ? null : t.dataset.phase
194
+ else if (t.dataset.close !== undefined) st.sel = null
195
+ draw()
196
+ }
197
+ root.classList.add('tl')
198
+ root.addEventListener('click', onClick)
199
+ draw()
200
+ return () => root.removeEventListener('click', onClick)
201
+ }