@tempoxyz/ds 0.3.15 → 0.3.17

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 (130) hide show
  1. package/dist/docs/AGENTS.md +10 -6
  2. package/dist/docs/arsenal.md +44 -0
  3. package/dist/docs/marketing.md +703 -4
  4. package/dist/docs/product/components/actions.md +53 -1
  5. package/dist/docs/product/components/blockchain.md +147 -3
  6. package/dist/docs/product/components/feedback-and-status.md +137 -7
  7. package/dist/docs/product/components/navigation.md +1 -1
  8. package/dist/docs/product/documents.md +225 -0
  9. package/dist/docs/product/foundations.md +2 -1
  10. package/dist/docs/product/patterns.md +3 -22
  11. package/dist/document/Document.d.ts +46 -0
  12. package/dist/document/Document.d.ts.map +1 -0
  13. package/dist/document/Document.js +190 -0
  14. package/dist/document/Document.js.map +1 -0
  15. package/dist/document/Enhance.d.ts +13 -0
  16. package/dist/document/Enhance.d.ts.map +1 -0
  17. package/dist/document/Enhance.js +421 -0
  18. package/dist/document/Enhance.js.map +1 -0
  19. package/dist/document/bin.d.ts +3 -0
  20. package/dist/document/bin.d.ts.map +1 -0
  21. package/dist/document/bin.js +38 -0
  22. package/dist/document/bin.js.map +1 -0
  23. package/dist/document/document.css +373 -0
  24. package/dist/document/index.d.ts +3 -0
  25. package/dist/document/index.d.ts.map +1 -0
  26. package/dist/document/index.js +3 -0
  27. package/dist/document/index.js.map +1 -0
  28. package/dist/document/internal/Cli.d.ts +43 -0
  29. package/dist/document/internal/Cli.d.ts.map +1 -0
  30. package/dist/document/internal/Cli.js +87 -0
  31. package/dist/document/internal/Cli.js.map +1 -0
  32. package/dist/document/internal/Template.d.ts +21 -0
  33. package/dist/document/internal/Template.d.ts.map +1 -0
  34. package/dist/document/internal/Template.js +15 -0
  35. package/dist/document/internal/Template.js.map +1 -0
  36. package/dist/document/script.d.ts +2 -0
  37. package/dist/document/script.d.ts.map +1 -0
  38. package/dist/document/script.js +379 -0
  39. package/dist/document/templates/brief.html +96 -0
  40. package/dist/document/templates/essay.html +70 -0
  41. package/dist/document/templates/post.html +69 -0
  42. package/dist/marketing/index.js.zyzz.json +1 -1
  43. package/dist/marketing/vars.d.ts +618 -758
  44. package/dist/marketing/vars.d.ts.map +1 -1
  45. package/dist/marketing/vars.js +8 -5
  46. package/dist/marketing/vars.js.map +1 -1
  47. package/dist/marketing/vars.js.zyzz.json +1 -1
  48. package/dist/marketing/zyzz.config.d.ts +3042 -3757
  49. package/dist/marketing/zyzz.config.d.ts.map +1 -1
  50. package/dist/marketing/zyzz.config.js +1 -1
  51. package/dist/marketing/zyzz.config.js.map +1 -1
  52. package/dist/marketing/zyzz.config.js.zyzz.json +1 -1
  53. package/dist/mobile/components/Button.d.ts +115 -15
  54. package/dist/mobile/components/Button.d.ts.map +1 -1
  55. package/dist/mobile/components/Button.js +85 -14
  56. package/dist/mobile/components/Button.js.map +1 -1
  57. package/dist/mobile/components/IconButton.d.ts +129 -40
  58. package/dist/mobile/components/IconButton.d.ts.map +1 -1
  59. package/dist/mobile/components/IconButton.js +97 -28
  60. package/dist/mobile/components/IconButton.js.map +1 -1
  61. package/dist/mobile/components/TextInput.d.ts +132 -11
  62. package/dist/mobile/components/TextInput.d.ts.map +1 -1
  63. package/dist/mobile/components/TextInput.js +115 -14
  64. package/dist/mobile/components/TextInput.js.map +1 -1
  65. package/dist/mobile/index.d.ts +1 -0
  66. package/dist/mobile/index.d.ts.map +1 -1
  67. package/dist/mobile/index.js +1 -0
  68. package/dist/mobile/index.js.map +1 -1
  69. package/dist/mobile/vars.d.ts +103 -0
  70. package/dist/mobile/vars.d.ts.map +1 -1
  71. package/dist/mobile/vars.js +74 -0
  72. package/dist/mobile/vars.js.map +1 -1
  73. package/dist/mobile/zyzz.config.d.ts +408 -0
  74. package/dist/mobile/zyzz.config.d.ts.map +1 -1
  75. package/dist/web/components/AddressCard.js.zyzz.json +1 -1
  76. package/dist/web/components/Amount.css +1 -1
  77. package/dist/web/components/Amount.d.ts +9 -0
  78. package/dist/web/components/Amount.d.ts.map +1 -1
  79. package/dist/web/components/Amount.js +8 -5
  80. package/dist/web/components/Amount.js.map +1 -1
  81. package/dist/web/components/Amount.js.zyzz.json +1 -1
  82. package/dist/web/components/CopyButton.d.ts +6 -0
  83. package/dist/web/components/CopyButton.d.ts.map +1 -1
  84. package/dist/web/components/CopyButton.js +4 -1
  85. package/dist/web/components/CopyButton.js.map +1 -1
  86. package/dist/web/components/CopyButton.js.zyzz.json +1 -1
  87. package/dist/web/components/Hex.css +1 -1
  88. package/dist/web/components/Hex.d.ts +84 -3
  89. package/dist/web/components/Hex.d.ts.map +1 -1
  90. package/dist/web/components/Hex.js +20 -13
  91. package/dist/web/components/Hex.js.map +1 -1
  92. package/dist/web/components/Hex.js.zyzz.json +1 -1
  93. package/dist/web/components/Progress.css +1 -1
  94. package/dist/web/components/Progress.d.ts +12 -2
  95. package/dist/web/components/Progress.d.ts.map +1 -1
  96. package/dist/web/components/Progress.js +9 -5
  97. package/dist/web/components/Progress.js.map +1 -1
  98. package/dist/web/components/Progress.js.zyzz.json +1 -1
  99. package/dist/web/components/SecretValue.js.zyzz.json +1 -1
  100. package/dist/web/components/SidebarMenu.d.ts +4 -4
  101. package/dist/web/components/SidebarMenu.js +6 -6
  102. package/dist/web/components/SidebarMenu.js.map +1 -1
  103. package/dist/web/components/Snippet.js.zyzz.json +1 -1
  104. package/dist/web/index.js.zyzz.json +1 -1
  105. package/package.json +19 -1
  106. package/src/document/Document.ts +277 -0
  107. package/src/document/Enhance.ts +434 -0
  108. package/src/document/bin.ts +38 -0
  109. package/src/document/document.css +373 -0
  110. package/src/document/index.ts +2 -0
  111. package/src/document/internal/Cli.ts +132 -0
  112. package/src/document/internal/Template.ts +25 -0
  113. package/src/document/script.ts +8 -0
  114. package/src/document/templates/brief.html +96 -0
  115. package/src/document/templates/essay.html +70 -0
  116. package/src/document/templates/post.html +69 -0
  117. package/src/marketing/README.md +1 -1
  118. package/src/marketing/vars.ts +526 -604
  119. package/src/marketing/zyzz.config.ts +5 -4
  120. package/src/mobile/README.md +19 -6
  121. package/src/mobile/components/Button.tsx +94 -17
  122. package/src/mobile/components/IconButton.tsx +122 -30
  123. package/src/mobile/components/TextInput.tsx +139 -24
  124. package/src/mobile/index.ts +1 -0
  125. package/src/mobile/vars.ts +74 -0
  126. package/src/web/components/Amount.tsx +37 -3
  127. package/src/web/components/CopyButton.tsx +8 -0
  128. package/src/web/components/Hex.tsx +79 -13
  129. package/src/web/components/Progress.tsx +8 -2
  130. package/src/web/components/SidebarMenu.tsx +6 -6
@@ -0,0 +1,434 @@
1
+ /**
2
+ * Progressive enhancement for document mode: footnote popovers and the list of notes, heading
3
+ * copy-link anchors, copy buttons on code blocks, Essay's reading rail, Brief's contents highlight,
4
+ * and Axis placement. A document reads in full without it. @module
5
+ */
6
+
7
+ // The Link icon from src/web/icons/svg/Link.svg, filled with currentColor as the React icon is. Inlined
8
+ // so the script has no imports to resolve.
9
+ const link =
10
+ '<svg viewBox="0 0 16 16" fill="none" aria-hidden="true">' +
11
+ '<path d="M3.81309 6.81315C4.00834 6.61819 4.32494 6.61809 4.52012 6.81315C4.71529 7.00833 4.71513 7.32491 4.52012 7.52018L2.77501 9.26628C2.63738 9.40389 2.55452 9.48662 2.49864 9.55241C2.44691 9.61342 2.44701 9.62653 2.45079 9.61491C2.43994 9.64829 2.43997 9.68504 2.45079 9.71843C2.45504 9.72574 2.46795 9.74473 2.49864 9.78093C2.55453 9.84677 2.63719 9.92925 2.77501 10.0671L5.93321 13.2253C6.07102 13.3631 6.15351 13.4448 6.21934 13.5007C6.25519 13.5311 6.27422 13.5441 6.28184 13.5485C6.31522 13.5593 6.35199 13.5603 6.38536 13.5495C6.39329 13.5448 6.41267 13.5305 6.44786 13.5007C6.51365 13.4448 6.5964 13.3629 6.73399 13.2253L8.48008 11.4801C8.67537 11.2851 8.99194 11.285 9.18712 11.4801C9.38206 11.6753 9.38205 11.992 9.18712 12.1872L7.44102 13.9323C7.31499 14.0583 7.19946 14.1749 7.09532 14.2633C7.01381 14.3325 6.92065 14.4014 6.81016 14.4538L6.69395 14.4997C6.45972 14.5758 6.2075 14.5757 5.97325 14.4997C5.80931 14.4465 5.68052 14.3556 5.57188 14.2633C5.4677 14.1749 5.35229 14.0584 5.22618 13.9323L2.06798 10.7741C1.94181 10.6479 1.82539 10.5326 1.73692 10.4284C1.64466 10.3197 1.55286 10.1909 1.49962 10.027C1.42365 9.79294 1.42362 9.54039 1.49962 9.30632C1.55287 9.14262 1.64472 9.01358 1.73692 8.90495C1.82537 8.8008 1.94192 8.6853 2.06798 8.55925L3.81309 6.81315Z" fill="currentColor"/>' +
12
+ '<path d="M9.6461 5.64616C9.84126 5.451 10.1578 5.4512 10.3531 5.64616C10.5484 5.84142 10.5484 6.15793 10.3531 6.35319L6.35313 10.3532C6.15787 10.5485 5.84136 10.5485 5.6461 10.3532C5.45114 10.1579 5.45094 9.84132 5.6461 9.64616L9.6461 5.64616Z" fill="currentColor"/>' +
13
+ '<path d="M9.30626 1.49968C9.54033 1.42368 9.79288 1.42371 10.027 1.49968C10.1908 1.55292 10.3196 1.64472 10.4283 1.73698C10.5325 1.82546 10.6479 1.94187 10.774 2.06804L13.9322 5.22624C14.0583 5.35235 14.1748 5.46776 14.2633 5.57194C14.3555 5.68058 14.4464 5.80937 14.4996 5.97331C14.5566 6.14891 14.5711 6.33463 14.5426 6.5153L14.4996 6.69401C14.4464 6.85774 14.3554 6.98682 14.2633 7.09538C14.1748 7.19952 14.0583 7.31506 13.9322 7.44108L12.1871 9.18718C11.9919 9.38211 11.6753 9.38213 11.4801 9.18718C11.2849 8.992 11.2851 8.67543 11.4801 8.48015L13.2252 6.73405C13.3628 6.59646 13.4447 6.51371 13.5006 6.44792C13.5305 6.41273 13.5438 6.39335 13.5484 6.38542C13.5593 6.35205 13.5602 6.31528 13.5494 6.2819C13.5451 6.27428 13.531 6.25525 13.5006 6.2194C13.4447 6.15357 13.363 6.07108 13.2252 5.93327L10.067 2.77507C9.92919 2.63725 9.84671 2.55459 9.78087 2.4987C9.74467 2.46801 9.72568 2.45511 9.71837 2.45085C9.68498 2.44003 9.64823 2.44 9.61485 2.45085C9.62646 2.44707 9.61336 2.44697 9.55235 2.4987C9.48656 2.55458 9.40383 2.63744 9.26622 2.77507L7.52012 4.52018C7.32485 4.71519 7.00827 4.71535 6.81309 4.52018C6.61803 4.325 6.61813 4.0084 6.81309 3.81315L8.55919 2.06804C8.68524 1.94198 8.80074 1.82543 8.90489 1.73698C9.01352 1.64478 9.14256 1.55293 9.30626 1.49968Z" fill="currentColor"/>' +
14
+ '</svg>'
15
+
16
+ /** How long a copied state shows before it reverts, in milliseconds. */
17
+ const settle = 1500
18
+
19
+ /**
20
+ * Enhances every document on a page. Safe to call once per page, after the document is parsed.
21
+ *
22
+ * @example
23
+ * Enhance.run(document)
24
+ */
25
+ export function run(page: Document): void {
26
+ const view = page.defaultView
27
+ if (!view) return
28
+
29
+ page.documentElement.classList.add('js')
30
+ const live = page.createElement('div')
31
+ live.className = 'sr-only'
32
+ live.setAttribute('aria-live', 'polite')
33
+ page.body.append(live)
34
+ const announce = (message: string) => {
35
+ live.textContent = message
36
+ }
37
+
38
+ for (const doc of page.querySelectorAll<HTMLElement>('.doc')) {
39
+ notes(doc, view)
40
+ anchors(doc, view, announce)
41
+ code(doc, view, announce)
42
+ if (doc.hasAttribute('data-rail')) rail(doc, view)
43
+ }
44
+ for (const nav of page.querySelectorAll<HTMLElement>('.summary nav')) contents(nav, view)
45
+ for (const axis of page.querySelectorAll<HTMLOListElement>('ol.axis')) place(axis, view)
46
+ }
47
+
48
+ /** Adds a copy-link anchor to each H2 and H3 that has an id, or gets one from its text. */
49
+ function anchors(doc: HTMLElement, view: Window, announce: (message: string) => void) {
50
+ const page = doc.ownerDocument
51
+
52
+ for (const heading of doc.querySelectorAll<HTMLHeadingElement>(':scope > h2, :scope > h3')) {
53
+ if (heading.querySelector('.h-anchor')) continue
54
+ const name = (heading.textContent ?? '').trim()
55
+ heading.dataset['name'] = name
56
+ if (!heading.id) {
57
+ const base = slug(name) || 'section'
58
+ let id = base
59
+ for (let n = 2; page.getElementById(id); n++) id = `${base}-${n}`
60
+ heading.id = id
61
+ }
62
+
63
+ const anchor = page.createElement('a')
64
+ anchor.className = 'h-anchor'
65
+ anchor.href = '#' + heading.id
66
+ anchor.setAttribute('aria-label', 'Copy link to ' + name)
67
+ anchor.innerHTML = link + '<span class="tip" aria-hidden="true">Copy link</span>'
68
+
69
+ // The last word and the anchor never wrap apart.
70
+ const last = heading.lastChild
71
+ const match = last?.nodeType === 3 ? /^([\s\S]*?)(\S+)\s*$/.exec(last.textContent ?? '') : null
72
+ if (last && match) {
73
+ last.textContent = match[1] ?? ''
74
+ const tail = page.createElement('span')
75
+ tail.className = 'h-tail'
76
+ tail.append(match[2] ?? '', anchor)
77
+ heading.append(tail)
78
+ } else heading.append(anchor)
79
+
80
+ let timer: ReturnType<typeof setTimeout> | undefined
81
+ const tip = anchor.querySelector<HTMLElement>('.tip')
82
+ anchor.addEventListener('click', (event) => {
83
+ const clipboard = view.navigator.clipboard
84
+ if (!clipboard) return
85
+ event.preventDefault()
86
+ const url = view.location.href.split('#')[0] + '#' + heading.id
87
+ clipboard.writeText(url).then(
88
+ () => {
89
+ view.history.replaceState(null, '', '#' + heading.id)
90
+ anchor.dataset['copied'] = ''
91
+ if (tip) tip.textContent = 'Link copied'
92
+ announce('Link to ' + name + ' copied')
93
+ clearTimeout(timer)
94
+ timer = setTimeout(() => {
95
+ delete anchor.dataset['copied']
96
+ if (tip) tip.textContent = 'Copy link'
97
+ announce('')
98
+ }, settle)
99
+ },
100
+ () => {
101
+ view.location.hash = heading.id
102
+ },
103
+ )
104
+ })
105
+ }
106
+ }
107
+
108
+ /** Wraps each code block with a copy button. */
109
+ function code(doc: HTMLElement, view: Window, announce: (message: string) => void) {
110
+ const page = doc.ownerDocument
111
+
112
+ for (const pre of doc.querySelectorAll<HTMLPreElement>(':scope > pre')) {
113
+ const wrap = page.createElement('div')
114
+ wrap.className = [
115
+ 'code-block',
116
+ ...[...pre.classList].filter((name) => name.startsWith('l-')),
117
+ ].join(' ')
118
+ pre.replaceWith(wrap)
119
+ wrap.append(pre)
120
+
121
+ const button = page.createElement('button')
122
+ button.type = 'button'
123
+ button.className = 'copy'
124
+ button.textContent = 'Copy'
125
+ button.setAttribute('aria-label', 'Copy code')
126
+ wrap.append(button)
127
+
128
+ let timer: ReturnType<typeof setTimeout> | undefined
129
+ button.addEventListener('click', async () => {
130
+ const text = (pre.querySelector('code') ?? pre).textContent ?? ''
131
+ try {
132
+ await view.navigator.clipboard.writeText(text)
133
+ } catch {
134
+ return
135
+ }
136
+ button.textContent = 'Copied'
137
+ button.dataset['copied'] = ''
138
+ announce('Copied')
139
+ clearTimeout(timer)
140
+ timer = setTimeout(() => {
141
+ button.textContent = 'Copy'
142
+ delete button.dataset['copied']
143
+ announce('')
144
+ }, settle)
145
+ })
146
+ }
147
+ }
148
+
149
+ /** Marks the Brief contents link of the section in view. */
150
+ function contents(nav: HTMLElement, view: Window) {
151
+ const page = nav.ownerDocument
152
+ const links = [...nav.querySelectorAll<HTMLAnchorElement>('a[href^="#"]')]
153
+ const targets = links.flatMap((anchor) => {
154
+ const target = page.getElementById((anchor.getAttribute('href') ?? '').slice(1))
155
+ return target ? [target] : []
156
+ })
157
+ if (targets.length === 0) return
158
+
159
+ const mark = () => {
160
+ let current = targets[0]
161
+ for (const target of targets)
162
+ if (target.getBoundingClientRect().top < view.innerHeight * 0.3) current = target
163
+ for (const anchor of links)
164
+ anchor.setAttribute('aria-current', String(anchor.getAttribute('href') === '#' + current?.id))
165
+ }
166
+ mark()
167
+ view.addEventListener('scroll', () => view.requestAnimationFrame(mark), { passive: true })
168
+ }
169
+
170
+ /**
171
+ * Turns each `span.sn > small` into a numbered button with a popover, and lists the notes at the
172
+ * end. Escape closes the open note and returns focus to its button.
173
+ */
174
+ function notes(doc: HTMLElement, view: Window) {
175
+ const page = doc.ownerDocument
176
+ const items = [...doc.querySelectorAll<HTMLElement>('.sn')].flatMap((note) => {
177
+ const small = note.querySelector<HTMLElement>(':scope > small')
178
+ return small ? [{ note, small }] : []
179
+ })
180
+ if (items.length === 0) return
181
+
182
+ let open: { button: HTMLButtonElement; note: HTMLElement } | undefined
183
+ const close = () => {
184
+ if (!open) return
185
+ open.note.classList.remove('open')
186
+ open.button.setAttribute('aria-expanded', 'false')
187
+ open = undefined
188
+ }
189
+ const show = (note: HTMLElement, button: HTMLButtonElement, small: HTMLElement) => {
190
+ if (open && open.note !== note) close()
191
+ note.classList.add('open')
192
+ button.setAttribute('aria-expanded', 'true')
193
+ open = { button, note }
194
+ // The open note is positioned against its containing block, which is the nearest positioned
195
+ // ancestor (the article.doc), so measure from that box.
196
+ const frame = (small.offsetParent ?? doc).getBoundingClientRect()
197
+ const anchor = button.getBoundingClientRect()
198
+ const width = Math.min(320, view.innerWidth - 40)
199
+ const x = Math.max(
200
+ 20 - frame.left,
201
+ Math.min(anchor.left - frame.left - 16, view.innerWidth - 20 - width - frame.left),
202
+ )
203
+ note.style.setProperty('--pop-x', x + 'px')
204
+ note.style.setProperty('--pop-y', anchor.bottom - frame.top + 8 + 'px')
205
+ }
206
+
207
+ const list = page.createElement('ol')
208
+ items.forEach((item, index) => {
209
+ const { note, small } = item
210
+ const number = String(index + 1)
211
+ small.id ||= 'note-' + number
212
+ small.setAttribute('role', 'note')
213
+
214
+ const button = page.createElement('button')
215
+ button.type = 'button'
216
+ button.className = 'sn-ref'
217
+ button.textContent = number
218
+ button.setAttribute('aria-label', 'Note ' + number)
219
+ button.setAttribute('aria-controls', small.id)
220
+ button.setAttribute('aria-expanded', 'false')
221
+ note.insertBefore(button, small)
222
+ button.addEventListener('click', (event) => {
223
+ event.stopPropagation()
224
+ if (note.classList.contains('open')) close()
225
+ else show(note, button, small)
226
+ })
227
+
228
+ let timer: ReturnType<typeof setTimeout> | undefined
229
+ note.addEventListener('pointerenter', (event) => {
230
+ if (event.pointerType !== 'mouse') return
231
+ clearTimeout(timer)
232
+ timer = setTimeout(() => show(note, button, small), 300)
233
+ })
234
+ note.addEventListener('pointerleave', (event) => {
235
+ if (event.pointerType !== 'mouse') return
236
+ clearTimeout(timer)
237
+ timer = setTimeout(() => open?.note === note && close(), 160)
238
+ })
239
+
240
+ const listed = page.createElement('li')
241
+ listed.innerHTML = small.innerHTML
242
+ list.append(listed)
243
+ })
244
+
245
+ page.addEventListener('click', (event) => {
246
+ if (open && !open.note.contains(event.target as Node)) close()
247
+ })
248
+ page.addEventListener('keydown', (event) => {
249
+ if (event.key !== 'Escape' || !open) return
250
+ const { button, note } = open
251
+ const inside = note.contains(page.activeElement)
252
+ close()
253
+ if (inside) button.focus()
254
+ })
255
+
256
+ const section = page.createElement('section')
257
+ section.className = 'footnotes'
258
+ section.setAttribute('aria-label', 'Notes')
259
+ const heading = page.createElement('h2')
260
+ heading.textContent = 'Notes'
261
+ section.append(heading, list)
262
+ doc.append(section)
263
+ }
264
+
265
+ /**
266
+ * Lays an Axis timeline out horizontally at 768px and wider, in lanes so labels never overlap.
267
+ * Narrower, it stays a vertical list in date order.
268
+ */
269
+ function place(axis: HTMLOListElement, view: Window) {
270
+ const page = axis.ownerDocument
271
+ const items = [...axis.children] as HTMLElement[]
272
+ const day = 864e5
273
+ const start = Date.parse(axis.dataset['start'] ?? '')
274
+ const end = Date.parse(axis.dataset['end'] ?? '')
275
+ if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return
276
+ const at = (time: number) => (time - start) / (end - start)
277
+
278
+ for (const item of items) {
279
+ const times = [...item.querySelectorAll('time')].map((time) =>
280
+ Date.parse(time.getAttribute('datetime') ?? ''),
281
+ )
282
+ const first = times[0] ?? start
283
+ item.style.setProperty('--x', at(first).toFixed(4))
284
+ if (item.classList.contains('phase'))
285
+ item.style.setProperty('--w', (at(times[1] ?? first) - at(first)).toFixed(4))
286
+ }
287
+ // As a list, read in date order with each phase ahead of the events inside it.
288
+ items
289
+ .map((item, index) => ({
290
+ index,
291
+ item,
292
+ kind: item.classList.contains('phase') ? 0 : 1,
293
+ x: Number(item.style.getPropertyValue('--x')),
294
+ }))
295
+ .sort((a, b) => a.x - b.x || a.kind - b.kind || a.index - b.index)
296
+ .forEach((entry, order) => {
297
+ entry.item.style.order = String(order)
298
+ })
299
+ axis.style.display = 'flex'
300
+ axis.style.flexDirection = 'column'
301
+
302
+ const scale = page.createElement('div')
303
+ scale.className = 'axis-scale'
304
+ scale.setAttribute('aria-hidden', 'true')
305
+ const marks = [start]
306
+ for (let time = start + 7 * day; time < end - 3 * day; time += 7 * day) marks.push(time)
307
+ marks.push(end)
308
+ for (const mark of marks) {
309
+ const span = page.createElement('span')
310
+ span.style.left = (at(mark) * 100).toFixed(2) + '%'
311
+ span.textContent = new Date(mark).toLocaleDateString('en-US', {
312
+ day: 'numeric',
313
+ month: 'short',
314
+ timeZone: 'UTC',
315
+ })
316
+ scale.append(span)
317
+ }
318
+ axis.after(scale)
319
+
320
+ const wide = view.matchMedia('(min-width: 768px)')
321
+ const lanes = () => {
322
+ if (!wide.matches) {
323
+ delete axis.dataset['placed']
324
+ axis.style.display = 'flex'
325
+ return
326
+ }
327
+ axis.dataset['placed'] = ''
328
+ axis.style.removeProperty('display')
329
+ const width = axis.clientWidth
330
+ const fill = (list: HTMLElement[], phase: boolean) => {
331
+ const ends: number[] = []
332
+ const placed: { lane: number; x: number }[] = []
333
+ for (const item of list) {
334
+ delete item.dataset['flip']
335
+ item.style.setProperty('--lane', '0')
336
+ const x = Number(item.style.getPropertyValue('--x')) * width
337
+ const size = phase
338
+ ? Math.max(item.scrollWidth, Number(item.style.getPropertyValue('--w')) * width)
339
+ : item.scrollWidth
340
+ let left = x
341
+ let right = x + size
342
+ if (!phase && right > width) {
343
+ item.dataset['flip'] = ''
344
+ left = x - size
345
+ right = x
346
+ }
347
+ let lane: number
348
+ if (phase) {
349
+ lane = ends.findIndex((edge) => edge < left - 12)
350
+ if (lane < 0) lane = ends.push(0) - 1
351
+ ends[lane] = right
352
+ } else {
353
+ const crossed = (depth: number) =>
354
+ placed.some(
355
+ (other) => other.lane > depth && other.x >= left - 4 && other.x <= right + 4,
356
+ )
357
+ lane = ends.findIndex((edge, depth) => edge > right + 12 && !crossed(depth))
358
+ if (lane < 0) lane = ends.push(0) - 1
359
+ ends[lane] = left
360
+ placed.push({ lane, x: 'flip' in item.dataset ? right : left })
361
+ }
362
+ item.style.setProperty('--lane', String(lane))
363
+ }
364
+ return Math.max(1, ends.length)
365
+ }
366
+ const phases = items.filter((item) => item.classList.contains('phase'))
367
+ // Events right to left, so a leader line never crosses a label in a shallower lane.
368
+ const events = items
369
+ .filter((item) => !item.classList.contains('phase') && !item.classList.contains('minor'))
370
+ .reverse()
371
+ axis.style.setProperty('--phase-lanes', String(fill(phases, true)))
372
+ axis.style.setProperty('--event-lanes', String(fill(events, false)))
373
+ }
374
+ lanes()
375
+ wide.addEventListener('change', lanes)
376
+ view.addEventListener('resize', lanes)
377
+ void page.fonts?.ready.then(lanes)
378
+ }
379
+
380
+ /** Adds Essay's reading rail: progress through the page, with a tick for each section. */
381
+ function rail(doc: HTMLElement, view: Window) {
382
+ const page = doc.ownerDocument
383
+ const headings = [...doc.querySelectorAll<HTMLHeadingElement>(':scope > h2[id]')]
384
+ const nav = page.createElement('nav')
385
+ nav.className = 'rail'
386
+ nav.setAttribute('aria-label', 'Reading progress')
387
+ nav.innerHTML = '<div class="rail-track"></div><div class="rail-fill"></div>'
388
+ const ticks = headings.map((heading) => {
389
+ const anchor = page.createElement('a')
390
+ const name = heading.dataset['name'] ?? heading.textContent ?? ''
391
+ anchor.href = '#' + heading.id
392
+ anchor.setAttribute('aria-label', 'Go to ' + name)
393
+ const label = page.createElement('span')
394
+ label.textContent = name
395
+ anchor.append(label)
396
+ nav.append(anchor)
397
+ return anchor
398
+ })
399
+ page.body.append(nav)
400
+
401
+ const header = doc.querySelector('header')
402
+ let span = 1
403
+ const measure = () => {
404
+ span = Math.max(1, page.documentElement.scrollHeight - view.innerHeight)
405
+ headings.forEach((heading, index) => {
406
+ const y = heading.getBoundingClientRect().top + view.scrollY - view.innerHeight * 0.25
407
+ ticks[index]?.style.setProperty('--at', Math.min(1, Math.max(0, y / span)).toFixed(4))
408
+ })
409
+ }
410
+ const update = () => {
411
+ nav.style.setProperty('--p', Math.min(1, Math.max(0, view.scrollY / span)).toFixed(4))
412
+ const started = header ? header.getBoundingClientRect().bottom < 80 : view.scrollY > 200
413
+ nav.toggleAttribute('data-on', started)
414
+ }
415
+ measure()
416
+ update()
417
+ view.addEventListener('scroll', () => view.requestAnimationFrame(update), { passive: true })
418
+ view.addEventListener('resize', () => {
419
+ measure()
420
+ update()
421
+ })
422
+ void page.fonts?.ready.then(() => {
423
+ measure()
424
+ update()
425
+ })
426
+ }
427
+
428
+ /** Returns a URL fragment for a heading's text. */
429
+ function slug(text: string) {
430
+ return text
431
+ .toLowerCase()
432
+ .replace(/[^a-z0-9]+/g, '-')
433
+ .replace(/^-|-$/g, '')
434
+ }
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ /** The `tempo-document` executable, which runs the document command line on the filesystem. @module */
3
+ import * as Fs from 'node:fs/promises'
4
+ import * as Cli from './internal/Cli.ts'
5
+
6
+ // The bin sits at `dist/document` when installed and at `src/document` when linked for development.
7
+ const manifest = JSON.parse(
8
+ await Fs.readFile(new URL('../../package.json', import.meta.url), 'utf8'),
9
+ ) as { version: string }
10
+
11
+ const result = await Cli.run({
12
+ args: process.argv.slice(2),
13
+ files: {
14
+ async create(path, text) {
15
+ try {
16
+ await Fs.writeFile(path, text, { flag: 'wx' })
17
+ return true
18
+ } catch (error) {
19
+ if ((error as NodeJS.ErrnoException).code === 'EEXIST') return false
20
+ throw error
21
+ }
22
+ },
23
+ async read(path) {
24
+ try {
25
+ return await Fs.readFile(path, 'utf8')
26
+ } catch (error) {
27
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
28
+ throw error
29
+ }
30
+ },
31
+ template: (name) => Fs.readFile(new URL(`./templates/${name}.html`, import.meta.url), 'utf8'),
32
+ },
33
+ version: manifest.version,
34
+ })
35
+
36
+ process.stdout.write(result.stdout)
37
+ process.stderr.write(result.stderr)
38
+ process.exitCode = result.code