deictic 0.0.1 → 0.1.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 (173) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/dist/annotations/client.d.ts +4 -0
  4. package/dist/annotations/client.d.ts.map +1 -0
  5. package/dist/annotations/client.js +497 -0
  6. package/dist/annotations/client.js.map +1 -0
  7. package/dist/annotations/index.d.ts +110 -0
  8. package/dist/annotations/index.d.ts.map +1 -0
  9. package/dist/annotations/index.js +22 -0
  10. package/dist/annotations/index.js.map +1 -0
  11. package/dist/astro.d.ts +29 -0
  12. package/dist/astro.d.ts.map +1 -0
  13. package/dist/astro.js +24 -0
  14. package/dist/astro.js.map +1 -0
  15. package/dist/bun.d.ts +12 -0
  16. package/dist/bun.d.ts.map +1 -0
  17. package/dist/bun.js +67 -0
  18. package/dist/bun.js.map +1 -0
  19. package/dist/client/index.d.ts +93 -0
  20. package/dist/client/index.d.ts.map +1 -0
  21. package/dist/client/index.js +1329 -0
  22. package/dist/client/index.js.map +1 -0
  23. package/dist/endpoints.js +354 -0
  24. package/dist/endpoints.js.map +1 -0
  25. package/dist/index.d.ts +220 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +10 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/index2.d.ts +23 -0
  30. package/dist/index3.d.ts +98 -0
  31. package/dist/index3.d.ts.map +1 -0
  32. package/dist/index4.d.ts +74 -0
  33. package/dist/index4.d.ts.map +1 -0
  34. package/dist/index5.d.ts +70 -0
  35. package/dist/index5.d.ts.map +1 -0
  36. package/dist/integration.d.ts +19 -0
  37. package/dist/integration.d.ts.map +1 -0
  38. package/dist/integration.js +277 -0
  39. package/dist/integration.js.map +1 -0
  40. package/dist/kept.js +23 -0
  41. package/dist/kept.js.map +1 -0
  42. package/dist/loader.d.ts +15 -0
  43. package/dist/loader.d.ts.map +1 -0
  44. package/dist/loader.js +17 -0
  45. package/dist/loader.js.map +1 -0
  46. package/dist/marks.js +14 -0
  47. package/dist/marks.js.map +1 -0
  48. package/dist/next.d.ts +17 -0
  49. package/dist/next.d.ts.map +1 -0
  50. package/dist/next.js +150 -0
  51. package/dist/next.js.map +1 -0
  52. package/dist/playwright.js +105 -0
  53. package/dist/playwright.js.map +1 -0
  54. package/dist/recommended/index.d.ts +25 -0
  55. package/dist/recommended/index.d.ts.map +1 -0
  56. package/dist/recommended/index.js +19 -0
  57. package/dist/recommended/index.js.map +1 -0
  58. package/dist/recordings/client.d.ts +4 -0
  59. package/dist/recordings/client.d.ts.map +1 -0
  60. package/dist/recordings/client.js +376 -0
  61. package/dist/recordings/client.js.map +1 -0
  62. package/dist/recordings/index.d.ts +2 -0
  63. package/dist/recordings/index.js +3 -0
  64. package/dist/recordings.js +235 -0
  65. package/dist/recordings.js.map +1 -0
  66. package/dist/screenshots/client.d.ts +23 -0
  67. package/dist/screenshots/client.d.ts.map +1 -0
  68. package/dist/screenshots/client.js +76 -0
  69. package/dist/screenshots/client.js.map +1 -0
  70. package/dist/screenshots/dom.d.ts +4 -0
  71. package/dist/screenshots/dom.d.ts.map +1 -0
  72. package/dist/screenshots/dom.js +92 -0
  73. package/dist/screenshots/dom.js.map +1 -0
  74. package/dist/screenshots/index.d.ts +2 -0
  75. package/dist/screenshots/index.js +98 -0
  76. package/dist/screenshots/index.js.map +1 -0
  77. package/dist/screenshots/rrweb.d.ts +9 -0
  78. package/dist/screenshots/rrweb.d.ts.map +1 -0
  79. package/dist/screenshots/rrweb.js +60 -0
  80. package/dist/screenshots/rrweb.js.map +1 -0
  81. package/dist/shortcut.js +63 -0
  82. package/dist/shortcut.js.map +1 -0
  83. package/dist/tailwind/client.d.ts +4 -0
  84. package/dist/tailwind/client.d.ts.map +1 -0
  85. package/dist/tailwind/client.js +613 -0
  86. package/dist/tailwind/client.js.map +1 -0
  87. package/dist/tailwind/index.d.ts +2 -0
  88. package/dist/tailwind/index.js +557 -0
  89. package/dist/tailwind/index.js.map +1 -0
  90. package/dist/tasks/client.d.ts +6 -0
  91. package/dist/tasks/client.d.ts.map +1 -0
  92. package/dist/tasks/client.js +642 -0
  93. package/dist/tasks/client.js.map +1 -0
  94. package/dist/tasks/index.d.ts +159 -0
  95. package/dist/tasks/index.d.ts.map +1 -0
  96. package/dist/tasks/index.js +348 -0
  97. package/dist/tasks/index.js.map +1 -0
  98. package/dist/vite.d.ts +17 -0
  99. package/dist/vite.d.ts.map +1 -0
  100. package/dist/vite.js +44 -0
  101. package/dist/vite.js.map +1 -0
  102. package/dist/voice/client.d.ts +4 -0
  103. package/dist/voice/client.d.ts.map +1 -0
  104. package/dist/voice/client.js +66 -0
  105. package/dist/voice/client.js.map +1 -0
  106. package/dist/voice/index.d.ts +47 -0
  107. package/dist/voice/index.d.ts.map +1 -0
  108. package/dist/voice/index.js +74 -0
  109. package/dist/voice/index.js.map +1 -0
  110. package/dist/waveform.js +93 -0
  111. package/dist/waveform.js.map +1 -0
  112. package/dist/webpack.d.ts +50 -0
  113. package/dist/webpack.d.ts.map +1 -0
  114. package/dist/webpack.js +78 -0
  115. package/dist/webpack.js.map +1 -0
  116. package/package.json +307 -7
  117. package/skills/deictic/SKILL.md +47 -0
  118. package/skills/deictic/references/install.md +81 -0
  119. package/skills/deictic/references/recordings.md +83 -0
  120. package/skills/deictic/references/tasks.md +79 -0
  121. package/skills/deictic/references/watch.md +43 -0
  122. package/skills/deictic/scripts/frame.mjs +62 -0
  123. package/skills/deictic/scripts/lib.mjs +193 -0
  124. package/skills/deictic/scripts/recording.mjs +186 -0
  125. package/skills/deictic/scripts/task.mjs +84 -0
  126. package/skills/deictic/scripts/transcribe.mjs +93 -0
  127. package/skills/deictic/scripts/voice.mjs +50 -0
  128. package/skills/deictic/scripts/watch.mjs +51 -0
  129. package/src/astro.ts +34 -0
  130. package/src/bun.ts +79 -0
  131. package/src/client/index.ts +833 -0
  132. package/src/client/lightbox.ts +256 -0
  133. package/src/client/style.ts +243 -0
  134. package/src/client/tooltip.ts +78 -0
  135. package/src/client/waveform.ts +98 -0
  136. package/src/index.ts +240 -0
  137. package/src/loader.ts +28 -0
  138. package/src/next.ts +133 -0
  139. package/src/plugins/annotations/client.ts +301 -0
  140. package/src/plugins/annotations/draw.ts +169 -0
  141. package/src/plugins/annotations/index.ts +105 -0
  142. package/src/plugins/annotations/svg.ts +61 -0
  143. package/src/plugins/recommended/index.ts +35 -0
  144. package/src/plugins/recordings/client.ts +315 -0
  145. package/src/plugins/recordings/index.ts +174 -0
  146. package/src/plugins/recordings/marks.ts +11 -0
  147. package/src/plugins/recordings/ours.ts +70 -0
  148. package/src/plugins/recordings/replay.ts +139 -0
  149. package/src/plugins/screenshots/client.ts +63 -0
  150. package/src/plugins/screenshots/dom.ts +79 -0
  151. package/src/plugins/screenshots/index.ts +194 -0
  152. package/src/plugins/screenshots/playwright.ts +119 -0
  153. package/src/plugins/screenshots/rrweb.ts +45 -0
  154. package/src/plugins/tailwind/catalog.ts +396 -0
  155. package/src/plugins/tailwind/client.ts +669 -0
  156. package/src/plugins/tailwind/index.ts +267 -0
  157. package/src/plugins/tasks/client.ts +622 -0
  158. package/src/plugins/tasks/index.ts +513 -0
  159. package/src/plugins/voice/client.ts +57 -0
  160. package/src/plugins/voice/index.ts +114 -0
  161. package/src/shortcut.ts +83 -0
  162. package/src/tools/astro.ts +81 -0
  163. package/src/tools/editor.ts +22 -0
  164. package/src/tools/endpoints.ts +163 -0
  165. package/src/tools/history.ts +203 -0
  166. package/src/tools/integration.ts +106 -0
  167. package/src/tools/kept.ts +21 -0
  168. package/src/tools/locate.ts +94 -0
  169. package/src/tools/plugins.ts +41 -0
  170. package/src/tools/source.ts +72 -0
  171. package/src/vite.ts +62 -0
  172. package/src/webpack.ts +107 -0
  173. package/index.js +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["div","button"],"sources":["../../src/client/lightbox.ts","../../src/client/style.ts","../../src/client/tooltip.ts","../../src/client/index.ts"],"sourcesContent":["/**\n * The lightbox: what a panel has attached (a capture, a recording's replay, a voice clip), big, over everything,\n * one at a time, ← and → between them. It grows out of the element that opened it and shrinks back into it, or\n * fades where motion is reduced. A sound plays in a player of its own: play, its waveform with what's played\n * lit (click or drag it to seek), and the time. It's a modal (`data-deictic-modal`): Esc closes it, not the popup.\n */\nimport type { LightboxItem, LightboxOptions } from '#src/index.ts';\n\nimport { type Colors, drawBars, peaksOf } from './waveform.ts';\n\nconst EASE = 'cubic-bezier(0.2, 0.8, 0.2, 1)';\nconst PLAY = '<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M7 4v16l13-8z\" fill=\"currentColor\"/></svg>';\nconst PAUSE = '<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M6 4h4v16H6zM14 4h4v16h-4z\" fill=\"currentColor\"/></svg>';\n\nconst reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;\nconst clock = (s: number) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}`;\n\n/**\n * Opens it in `root`. `pinned` draws it where `root` is in the page instead, with no backdrop, motion or keys, and\n * actions that don't close it: for a page of deictic's own states (`lightboxIn`).\n */\nexport function openLightbox(\n root: ShadowRoot,\n items: LightboxItem[],\n { at = 0, from, pinned = false }: LightboxOptions & { pinned?: boolean } = {},\n): { close: () => void } {\n const box = div(pinned ? 'lightbox pinned' : 'lightbox');\n if (!pinned) {\n box.dataset.deicticModal = '';\n box.setAttribute('role', 'dialog');\n box.setAttribute('aria-modal', 'true');\n }\n const backdrop = div('lb-backdrop');\n const stage = div('lb-stage');\n const head = div('lb-head');\n const title = div('lb-title');\n const count = div('lb-count');\n const actions = div('lb-actions');\n const close = button('×', 'Close (Esc)', 'lb-close');\n head.append(title, count, actions, close);\n const body = div('lb-body');\n stage.append(head, body);\n const prev = button('‹', 'Previous (←)', 'lb-prev');\n const next = button('›', 'Next (→)', 'lb-next');\n box.append(backdrop, stage, ...(items.length > 1 ? [prev, next] : []));\n root.append(box);\n\n let index = Math.min(Math.max(0, at), items.length - 1);\n let leave: (() => void) | undefined;\n let closing = false;\n\n const show = (i: number, animate: boolean) => {\n leave?.();\n leave = undefined;\n index = (i + items.length) % items.length;\n const item = items[index]!;\n box.setAttribute('aria-label', item.title);\n title.textContent = item.title;\n count.textContent = items.length > 1 ? `${index + 1} / ${items.length}` : '';\n actions.replaceChildren(\n ...(item.actions ?? []).map((a) => {\n const b = button(a.label, a.title ?? '', '');\n b.addEventListener('click', () => {\n if (!pinned) done();\n a.run();\n });\n return b;\n }),\n );\n // A sound plays as it opens, but not on a page that only shows the lightbox.\n const content = contentOf(item, !pinned);\n body.replaceChildren(content.element);\n leave = content.leave;\n if (animate && !reduced()) body.animate({ opacity: [0, 1] }, { duration: 160, easing: 'ease-out' });\n };\n\n /** The transform that puts the stage where `from` is: what it grows from and shrinks back to. */\n const fromRect = () => {\n if (from === undefined || !from.isConnected) return undefined;\n const f = from.getBoundingClientRect();\n const s = stage.getBoundingClientRect();\n if (f.width === 0 || s.width === 0) return undefined;\n return `translate(${f.left - s.left}px, ${f.top - s.top}px) scale(${f.width / s.width}, ${f.height / s.height})`;\n };\n\n const onKey = (e: KeyboardEvent) => {\n if (e.key === 'Escape') done();\n else if (e.key === 'ArrowLeft' && items.length > 1) show(index - 1, true);\n else if (e.key === 'ArrowRight' && items.length > 1) show(index + 1, true);\n else return;\n // The popup, under it, waits for its own Esc.\n e.preventDefault();\n e.stopImmediatePropagation();\n };\n if (!pinned) addEventListener('keydown', onKey, true);\n\n function done() {\n if (closing) return;\n closing = true;\n removeEventListener('keydown', onKey, true);\n leave?.();\n if (pinned) return box.remove();\n const gone = () => {\n box.remove();\n if (from instanceof HTMLElement && from.isConnected) from.focus({ preventScroll: true });\n };\n if (reduced()) return gone();\n const to = fromRect();\n backdrop.animate({ opacity: [1, 0] }, { duration: 200, easing: 'ease-in', fill: 'forwards' });\n stage\n .animate(\n to === undefined\n ? { opacity: [1, 0], transform: ['none', 'scale(0.96)'] }\n : { transform: ['none', to], opacity: [1, 1, 0], offset: [0, 0.8, 1] },\n { duration: 220, easing: EASE, fill: 'forwards' },\n )\n .finished.then(gone, gone);\n }\n\n backdrop.addEventListener('click', done);\n close.addEventListener('click', done);\n prev.addEventListener('click', () => show(index - 1, true));\n next.addEventListener('click', () => show(index + 1, true));\n\n show(index, false);\n if (pinned) {\n close.hidden = true;\n return { close: done };\n }\n close.focus({ preventScroll: true });\n if (reduced()) {\n box.animate({ opacity: [0, 1] }, { duration: 150 });\n } else {\n backdrop.animate({ opacity: [0, 1] }, { duration: 240, easing: 'ease-out' });\n const grow = fromRect();\n stage.animate(\n grow === undefined\n ? { opacity: [0, 1], transform: ['scale(0.96)', 'none'] }\n : { transform: [grow, 'none'], opacity: [0, 1, 1], offset: [0, 0.2, 1] },\n { duration: 280, easing: EASE },\n );\n }\n return { close: done };\n}\n\n/** An item, drawn: what goes in the body, and what to stop when it's left (a sound playing). */\nfunction contentOf(item: LightboxItem, autoplay: boolean): { element: HTMLElement; leave?: () => void } {\n switch (item.kind) {\n case 'image': {\n const img = Object.assign(document.createElement('img'), { src: item.url, alt: item.title, className: 'lb-image', draggable: false });\n return { element: img };\n }\n case 'page': {\n const frame = Object.assign(document.createElement('iframe'), { src: item.url, title: item.title, className: 'lb-page' });\n frame.allow = 'autoplay; fullscreen';\n return { element: frame };\n }\n case 'audio':\n return player(item.url, autoplay);\n }\n}\n\n/** A sound: play and pause, its waveform with what's played lit, and the time. With `autoplay`, it starts playing. */\nfunction player(url: string, autoplay: boolean): { element: HTMLElement; leave: () => void } {\n const el = div('lb-audio');\n const play = button('', 'Play (Space)', 'lb-play');\n const wave = Object.assign(document.createElement('canvas'), { className: 'lb-wave' });\n wave.setAttribute('role', 'slider');\n wave.setAttribute('aria-label', 'Where in the clip');\n wave.tabIndex = 0;\n const time = div('lb-time');\n el.append(play, wave, time);\n const audio = new Audio(url);\n const colors: Colors = { played: '#3ddc7c', rest: '#52525b' };\n // Flat until the clip's read: the bars rise when its peaks are in.\n let peaks: number[] = Array<number>(120).fill(0.05);\n let frame = 0;\n // MediaRecorder's webm says no length until it's played through; reading the peaks gives it sooner.\n let length = 0;\n const lengthOf = () => (Number.isFinite(audio.duration) && audio.duration > 0 ? audio.duration : length);\n const draw = () => {\n const total = lengthOf();\n drawBars(wave, peaks, total > 0 ? audio.currentTime / total : 0, colors);\n time.textContent = `${clock(audio.currentTime)} / ${total > 0 ? clock(total) : '–:––'}`;\n wave.setAttribute('aria-valuenow', String(Math.round(audio.currentTime)));\n };\n const loop = () => {\n draw();\n frame = audio.paused ? 0 : requestAnimationFrame(loop);\n };\n const state = () => {\n play.innerHTML = audio.paused ? PLAY : PAUSE;\n play.title = audio.paused ? 'Play (Space)' : 'Pause (Space)';\n if (!audio.paused && frame === 0) frame = requestAnimationFrame(loop);\n draw();\n };\n audio.addEventListener('play', state);\n audio.addEventListener('pause', state);\n audio.addEventListener('ended', state);\n audio.addEventListener('loadedmetadata', draw);\n const toggle = () => void (audio.paused ? audio.play().catch(() => {}) : audio.pause());\n play.addEventListener('click', toggle);\n const seek = (e: PointerEvent) => {\n const r = wave.getBoundingClientRect();\n const total = lengthOf();\n if (total > 0) audio.currentTime = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width)) * total;\n draw();\n };\n wave.addEventListener('pointerdown', (e) => {\n wave.setPointerCapture(e.pointerId);\n seek(e);\n });\n wave.addEventListener('pointermove', (e) => {\n if (wave.hasPointerCapture(e.pointerId)) seek(e);\n });\n el.addEventListener('keydown', (e) => {\n if (e.key !== ' ') return;\n e.preventDefault();\n toggle();\n });\n void peaksOf(url, 120).then(\n (read) => {\n peaks = read.peaks;\n length = read.duration;\n draw();\n },\n // Undecodable here: the player still plays it, over flat bars.\n () => {},\n );\n state();\n if (autoplay) void audio.play().catch(() => state());\n // The canvas has its size once it's in the page.\n requestAnimationFrame(draw);\n return {\n element: el,\n leave: () => {\n audio.pause();\n cancelAnimationFrame(frame);\n },\n };\n}\n\nfunction div(className: string): HTMLDivElement {\n const el = document.createElement('div');\n el.className = className;\n return el;\n}\n\nfunction button(text: string, title: string, className: string): HTMLButtonElement {\n const el = document.createElement('button');\n el.type = 'button';\n el.textContent = text;\n el.title = title;\n el.className = className;\n return el;\n}\n","/**\n * The overlay's styles, in its shadow root. Panels style their bodies with the same custom\n * properties, so a plugin's panel looks like the rest without styles of its own for the basics.\n */\nexport const STYLE = `\n:host {\n --deictic-accent: #12b358;\n --deictic-on-accent: #04130b;\n --deictic-bg: #18181b;\n --deictic-fg: #f4f4f5;\n --deictic-muted: #a1a1aa;\n --deictic-line: #3f3f46;\n --deictic-problem: #f87171;\n all: initial;\n /* Inherited by everything in the root: a thumb and no track, on whatever the panel's background is. */\n scrollbar-color: var(--deictic-line) transparent;\n}\n/* The host takes no room in the page: everything in it is fixed, so nothing of deictic's moves or scrolls it. */\n:host(deictic-overlay) { display: contents; }\n.box {\n position: fixed;\n display: none;\n z-index: 2147483646;\n pointer-events: none;\n box-sizing: border-box;\n outline: 2px solid var(--deictic-accent);\n background: rgb(18 179 88 / 0.1);\n}\n.box.shown { display: block; }\n.box.inner { outline: 1px dashed var(--deictic-accent); background: none; }\n/* The element the popup is open on: dashed and off it a little, with no fill, so what's tried on it shows as it is. */\n.box.on { outline: 1px dashed var(--deictic-accent); border-radius: 4px; background: none; }\n.label {\n position: absolute;\n left: -2px;\n bottom: 100%;\n padding: 1px 6px;\n font: 12px/1.5 ui-monospace, monospace;\n white-space: nowrap;\n color: var(--deictic-on-accent);\n background: var(--deictic-accent);\n}\n.label.below { top: 100%; bottom: auto; }\n.panel {\n position: fixed;\n z-index: 2147483647;\n width: min(360px, calc(100vw - 16px));\n max-height: 60vh;\n display: flex;\n flex-direction: column;\n box-sizing: border-box;\n border: 1px solid var(--deictic-line);\n border-radius: 8px;\n box-shadow: 0 12px 32px rgb(0 0 0 / 0.35);\n font: 13px/1.4 system-ui, sans-serif;\n color: var(--deictic-fg);\n background: var(--deictic-bg);\n}\n.panel.pinned { position: relative; z-index: auto; max-height: none; }\n@media (prefers-reduced-motion: no-preference) {\n .panel:not(.pinned) { animation: deictic-in 0.12s ease-out; }\n}\n@keyframes deictic-in {\n from { opacity: 0; translate: 0 4px; }\n}\n.head {\n display: flex;\n align-items: flex-end;\n gap: 2px;\n padding: 4px 8px 0;\n}\n/* Over the page the head is what the popup is dragged by; no touch scrolling starts there. */\n.panel:not(.pinned) .head { cursor: grab; touch-action: none; user-select: none; }\n.panel.dragging .head, .panel.dragging .head button { cursor: grabbing; }\n.head .tab {\n border: 0;\n border-bottom: 2px solid transparent;\n border-radius: 0;\n padding: 4px 8px;\n font-weight: 600;\n color: var(--deictic-muted);\n}\n.head .tab:hover { color: var(--deictic-fg); }\n.head .tab[aria-selected='true'] { color: var(--deictic-fg); border-bottom-color: var(--deictic-accent); }\n.head .close { margin: 0 0 3px auto; }\n.bar {\n display: flex;\n align-items: center;\n gap: 2px;\n padding: 4px 8px;\n border-top: 1px solid var(--deictic-line);\n border-bottom: 1px solid var(--deictic-line);\n}\n.bar .where {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n min-width: 0;\n margin-right: auto;\n font: 12px ui-monospace, monospace;\n color: var(--deictic-muted);\n text-decoration: none;\n}\n.bar .where span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.bar .where svg { flex: none; }\n.bar .where:hover, .bar .where:focus-visible { color: var(--deictic-fg); }\n.bar .where:hover span { text-decoration: underline; }\n.lightbox {\n position: fixed;\n inset: 0;\n z-index: 2147483647;\n display: flex;\n align-items: center;\n justify-content: center;\n font: 13px/1.4 system-ui, sans-serif;\n color: var(--deictic-fg);\n}\n.lb-backdrop { position: absolute; inset: 0; background: rgb(9 9 11 / 0.72); backdrop-filter: blur(2px); }\n.lb-stage {\n position: relative;\n display: flex;\n flex-direction: column;\n max-width: 92vw;\n max-height: 90vh;\n border: 1px solid var(--deictic-line);\n border-radius: 10px;\n background: var(--deictic-bg);\n box-shadow: 0 24px 64px rgb(0 0 0 / 0.5);\n transform-origin: 0 0;\n overflow: hidden;\n}\n.lb-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--deictic-line); }\n.lb-title { font-weight: 600; }\n.lb-count { color: var(--deictic-muted); font-size: 12px; font-variant-numeric: tabular-nums; }\n.lb-actions { display: flex; gap: 6px; margin-left: auto; }\n.lb-body { display: flex; justify-content: center; min-height: 0; background: #09090b; }\n.lb-image { display: block; max-width: 92vw; max-height: calc(90vh - 48px); object-fit: contain; }\n.lb-page { display: block; width: min(1280px, 92vw); height: min(860px, calc(90vh - 48px)); border: 0; background: #18181b; }\n.lb-audio { display: flex; align-items: center; gap: 12px; width: min(640px, 86vw); padding: 20px 16px; }\n.lb-play {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 40px;\n height: 40px;\n padding: 0;\n border: 0;\n border-radius: 50%;\n color: var(--deictic-on-accent);\n background: var(--deictic-accent);\n}\n.lb-play svg { width: 16px; height: 16px; }\n.lb-wave { flex: 1; min-width: 0; height: 56px; cursor: pointer; border-radius: 4px; }\n.lb-wave:focus-visible { outline: 1px solid var(--deictic-accent); outline-offset: 2px; }\n.lb-time { flex: none; min-width: 9ch; text-align: right; font: 12px ui-monospace, monospace; color: var(--deictic-muted); }\n.lb-prev, .lb-next {\n position: absolute;\n top: 50%;\n translate: 0 -50%;\n width: 40px;\n height: 40px;\n padding: 0;\n border: 1px solid var(--deictic-line);\n border-radius: 50%;\n font-size: 22px;\n line-height: 1;\n background: var(--deictic-bg);\n}\n.lb-prev { left: 16px; }\n.lb-next { right: 16px; }\n.lightbox.pinned { position: relative; inset: auto; z-index: auto; display: block; padding: 0 64px; }\n.lightbox.pinned .lb-stage { max-width: 100%; max-height: none; }\n.lightbox.pinned .lb-page { width: 100%; height: 420px; }\n.lightbox.pinned .lb-image { max-width: 100%; max-height: 420px; }\n.lightbox.pinned .lb-backdrop { display: none; }\n.lightbox.pinned .lb-audio { width: 100%; box-sizing: border-box; }\n.lightbox.pinned .lb-close { display: none; }\n.tip {\n position: fixed;\n left: 0;\n top: 0;\n z-index: 2147483647;\n max-width: 280px;\n padding: 3px 6px;\n border: 1px solid var(--deictic-line);\n border-radius: 4px;\n font: 12px/1.4 system-ui, sans-serif;\n color: var(--deictic-fg);\n background: #09090b;\n box-shadow: 0 4px 12px rgb(0 0 0 / 0.3);\n pointer-events: none;\n visibility: hidden;\n opacity: 0;\n transition: opacity 0.12s;\n}\n.tip.shown { visibility: visible; opacity: 1; }\nbutton {\n font: inherit;\n color: inherit;\n background: transparent;\n border: 1px solid var(--deictic-line);\n border-radius: 4px;\n padding: 1px 7px;\n cursor: pointer;\n}\nbutton:hover { border-color: var(--deictic-muted); }\nbutton:disabled { opacity: 0.5; cursor: default; }\nbutton:disabled:hover { border-color: var(--deictic-line); }\n/* One ring for whatever the keyboard lands on, in place of each browser's own. */\nbutton:focus-visible, a:focus-visible { outline: 1px solid var(--deictic-accent); outline-offset: 1px; }\nbutton.icon {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 22px;\n height: 22px;\n padding: 0;\n border: 0;\n color: var(--deictic-muted);\n}\nbutton.icon svg { width: 14px; height: 14px; }\nbutton.icon:hover:not(:disabled) { color: var(--deictic-fg); background: rgb(255 255 255 / 0.08); }\nbutton.primary { background: var(--deictic-accent); border-color: var(--deictic-accent); color: var(--deictic-on-accent); }\ninput, textarea {\n box-sizing: border-box;\n width: 100%;\n font: 12px ui-monospace, monospace;\n color: inherit;\n background: #09090b;\n border: 1px solid var(--deictic-line);\n border-radius: 4px;\n padding: 4px 6px;\n}\ninput:focus, textarea:focus { outline: 1px solid var(--deictic-accent); }\ncode { font: 12px ui-monospace, monospace; }\n/* Border-box, as the popup holds the body's height by its whole box while a tab reads. */\n.body { box-sizing: border-box; padding: 8px; overflow: auto; }\n.status { padding: 0 8px 6px; font-size: 12px; color: var(--deictic-muted); }\n.status:empty { display: none; }\n.status.problem { color: var(--deictic-problem); }\n`;\n","/**\n * One tooltip for everything deictic draws in a shadow root: whatever has a `title` (or `data-tip`) shows it\n * in a box of ours, soon after the pointer rests or focus lands, instead of the browser's, which comes late\n * and looks like nothing else here. Plugins only set `title`, as they would anywhere; the first hover moves\n * it to `data-tip`, so the browser's own stays away, and gives a textless control the title as its name.\n * The box is fixed in the root, so no panel's scrolling clips it.\n */\nconst DELAY = 300;\n\nexport function tooltips(root: ShadowRoot): void {\n const tip = document.createElement('div');\n tip.className = 'tip';\n tip.setAttribute('role', 'tooltip');\n root.append(tip);\n let timer = 0;\n let over: Element | undefined;\n\n const hide = () => {\n clearTimeout(timer);\n over = undefined;\n tip.classList.remove('shown');\n };\n const show = (el: Element) => {\n const text = el.getAttribute('data-tip');\n if (text === null || text === '' || !el.isConnected) return hide();\n tip.textContent = text;\n // Last in the root, over a modal or toolbar added since at the same z-index.\n if (tip !== root.lastElementChild) root.append(tip);\n tip.classList.add('shown');\n // Centred below it, kept on screen; above it where there's no room below.\n const r = el.getBoundingClientRect();\n const t = tip.getBoundingClientRect();\n const left = Math.max(8, Math.min(r.left + r.width / 2 - t.width / 2, innerWidth - t.width - 8));\n const top = r.bottom + 6 + t.height > innerHeight - 8 ? r.top - 6 - t.height : r.bottom + 6;\n Object.assign(tip.style, { left: `${left}px`, top: `${top}px` });\n };\n /** The element with a tip around where the event happened, its `title` taken over the first time. */\n const tipped = (e: Event) => {\n for (const node of e.composedPath()) {\n if (!(node instanceof Element)) continue;\n if (node === tip) return undefined;\n // A frame's title is its name for assistive tech, not a tip; what's in it has tips of its own.\n if (node.localName === 'iframe') return undefined;\n const title = node.getAttribute('title');\n if (title !== null) {\n node.removeAttribute('title');\n if (title === '') continue;\n node.setAttribute('data-tip', title);\n // A control with no text of its own (an icon, ×, ↶) is known by its tip; one with text keeps its name.\n if (!node.hasAttribute('aria-label') && (node.textContent ?? '').trim().length <= 1) node.setAttribute('aria-label', title);\n else node.setAttribute('aria-description', title);\n }\n if (node.hasAttribute('data-tip')) return node;\n }\n return undefined;\n };\n const enter = (e: Event) => {\n const el = tipped(e);\n if (el === over) return;\n hide();\n if (el === undefined) return;\n over = el;\n timer = window.setTimeout(() => show(el), e.type === 'focusin' ? 0 : DELAY);\n };\n root.addEventListener('pointerover', enter);\n root.addEventListener('focusin', (e) => {\n // Focus from the keyboard only: a click focuses too, and its tip is the pointer's.\n if ((e.target as Element).matches(':focus-visible')) enter(e);\n });\n root.addEventListener('pointerout', (e) => {\n const to = (e as PointerEvent).relatedTarget;\n if (over !== undefined && !(to instanceof Node && over.contains(to))) hide();\n });\n root.addEventListener('focusout', hide);\n // A press acts, and what it changes (a mic turned on) may change the tip: the next hover shows the new one.\n root.addEventListener('pointerdown', hide);\n addEventListener('scroll', hide, { capture: true, passive: true });\n}\n","/**\n * `deictic/client`: the overlay the page loads in dev. Hold a shortcut's keys (Alt, deictic's own,\n * by default) and point: the element under the pointer that the source marked (`tools/locate.ts`) is\n * outlined, with its tag, its place and how many elements share it. Press the shortcut's button to open\n * the popup there: a tab for each plugin with a panel, at the one used last, or at a plugin's own where\n * its shortcut was pressed.\n *\n * Everything drawn sits in one shadow root, so neither the page's styles nor ours cross over. A\n * panel's undo and redo are its tab's on its element: the latest change that plugin made there.\n */\nimport type { ClientContext, ClientPlugin, LightboxItem, PanelContext, Resumed, Target } from '#src/index.ts';\nimport { gestureOf, type Shortcut } from '#src/shortcut.ts';\n\nimport { openLightbox } from './lightbox.ts';\nimport { STYLE } from './style.ts';\nimport { tooltips } from './tooltip.ts';\n\n// For a plugin's page half that records the mic, or shows a clip: the waveforms the lightbox draws.\nexport { drawBars, liveWaveform, peaksOf, type Colors } from './waveform.ts';\n\nexport interface StartOptions {\n /** The dev server's base URL, ending in `/`. */\n base: string;\n /** deictic's own shortcut, checked: it opens the popup at the tab used last. None where it's turned off. */\n shortcut?: Required<Shortcut>;\n /** Each plugin with a half in the page, and its own shortcut as the bundler's plugin checked it, where it has one. */\n plugins: { plugin: ClientPlugin; shortcut?: Required<Shortcut>; options?: unknown }[];\n}\n\ntype Mount = (panel: HTMLElement, context: PanelContext<unknown, unknown>) => (() => void) | void;\n\n/** A plugin with a panel: a tab in the popup. */\ninterface Tab {\n plugin: ClientPlugin;\n mount: Mount;\n}\n\nconst ATTRIBUTE = 'data-deictic';\n/** An arrow pointing up and out: the link leaves the page for the editor. */\nconst OUT = icon('M7 17 17 7M8 7h9v9', 2.25);\n// Drawn, as the arrows and the cross of a system's font differ in size and weight from one to the next.\nconst UNDO = icon('M9 14 4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11');\nconst REDO = icon('m15 14 5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13');\nconst CLOSE = icon('M18 6 6 18M6 6l12 12');\n/** Where the tab used last is kept, for deictic's own shortcut to open it again. */\nconst LAST = 'deictic:tab';\n/** How long a read may take, in milliseconds, before the popup says it's reading. */\nconst SLOW = 200;\nconst STARTED = Symbol.for('deictic');\n\nexport function targetOf(el: Element): Target | undefined {\n const at = el.getAttribute(ATTRIBUTE);\n const match = at === null ? null : /^(.*):(\\d+):(\\d+)$/.exec(at);\n if (match === null) return undefined;\n return { loc: { file: match[1]!, line: Number(match[2]), column: Number(match[3]) }, tag: el.localName };\n}\n\nconst sameAs = (el: Element) => [...document.querySelectorAll(`[${ATTRIBUTE}=\"${CSS.escape(el.getAttribute(ATTRIBUTE) ?? '')}\"]`)];\n\n/** The nearest marked element around `el`, out through shadow roots to their hosts. */\nfunction markedAround(el: Element): Element | undefined {\n for (let at: Element | undefined = el; at !== undefined;) {\n const marked = at.closest(`[${ATTRIBUTE}]`);\n if (marked !== null) return marked;\n const root = at.getRootNode();\n at = root instanceof ShadowRoot ? root.host : undefined;\n }\n return undefined;\n}\n\n/** `div.panel > button.tab`: the element as a selector, the deepest classes only, for a person to tell it by. */\nfunction icon(path: string, width = 2): string {\n return `<svg viewBox=\"0 0 24 24\" width=\"12\" height=\"12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"${width}\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"${path}\"/></svg>`;\n}\n\nconst nameOf = (el: Element) => `${el.localName}${[...el.classList].map((c) => `.${c}`).join('')}`;\n\n/** What the overlay keeps once started, for `popupIn` to show the popup with. */\ninterface Started {\n base: string;\n contextOf: (name: string) => ClientContext;\n tabs: Tab[];\n /** Opens the popup over the page on an element, at a tab or the one used last: `openPopup`. */\n open: (element: Element, tab?: string) => boolean;\n}\n\nlet started: Started | undefined;\n\n/**\n * What the page hears on `window` as the popup opens over it on an element (its `detail` a `PopupOpened`) and as\n * it closes: for a page that moves on its own to hold still meanwhile, as deictic's site does. Not for one pinned.\n */\nexport const POPUP_OPENED = 'deictic:open';\nexport const POPUP_CLOSED = 'deictic:close';\n\nexport interface PopupOpened {\n /** The element it's open on. */\n element: Element;\n /** The plugin whose tab it opened at. */\n tab: string;\n}\n\n/**\n * Opens the popup over the page on `element`, as deictic's own shortcut does: at `tab` (a plugin's name), or at the\n * tab used last. For a page that opens it from a gesture of its own, as deictic's site does on a plain click.\n * Answers whether it opened: not where no plugin has a tab, or `element` has no mark. The overlay must have started.\n */\nexport function openPopup(element: Element, { tab }: { tab?: string } = {}): boolean {\n if (started === undefined) throw new Error('deictic: the overlay has not started, so there is no popup to open');\n return started.open(element, tab);\n}\n\n/**\n * Shows the popup in `container`, open at a tab (`tab`, a plugin's name, or the first) on `element`, where\n * the page puts it rather than over the page: a page of the popup's states, to point at and fix, as deictic's\n * own site does. It's the real popup, its tabs and plugins working. Closing it, or a tab's `away`, opens it\n * again in place. It draws in `container`'s shadow root, made if there isn't one. Answers what removes it.\n * The overlay must have started (the dev server's client module starts it), and `element` be marked.\n */\nexport function popupIn(container: Element, { tab: name, element }: { tab?: string; element: Element }): () => void {\n if (started === undefined) throw new Error('deictic: the overlay has not started, so there is no popup to show');\n const target = targetOf(element);\n if (target === undefined) throw new Error(`deictic: ${nameOf(element)} has no ${ATTRIBUTE} mark to open the popup on`);\n const { base, contextOf, tabs } = started;\n // A tab shown here isn't one a person chose: the popup over the page keeps opening at theirs.\n const remember = () => {};\n const tab = tabs.find((t) => t.plugin.name === name) ?? tabs[0];\n if (tab === undefined) throw new Error('deictic: no plugin has a tab to show');\n const root = container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = `${STYLE}:host { display: block; }`;\n root.replaceChildren(style);\n tooltips(root);\n let panel: { close: () => void } | undefined;\n let gone = false;\n const open = (at: Tab, resumed?: Resumed) => {\n panel = openPanel({\n base,\n root,\n contextOf,\n tabs,\n tab: at,\n remember,\n element,\n target,\n pinned: true,\n onClose: (shown, leaving) => {\n panel = undefined;\n // Closed by its own × or Esc: open again, as the page is there to show it. Leaving for `away` comes back by `reopen`.\n if (!gone && !leaving) open(shown);\n },\n ...(resumed === undefined ? {} : { resumed }),\n reopen: (again, _, kept) => open(again, kept),\n });\n };\n open(tab);\n return () => {\n gone = true;\n panel?.close();\n style.remove();\n };\n}\n\n/**\n * Shows the lightbox in `container`, at `at`, where the page puts it rather than over everything: as `popupIn`\n * does the popup, for a page of deictic's own states. Its items step with its arrows; there's no backdrop, close\n * or keys, and an item's actions run without closing it. Answers what removes it.\n */\nexport function lightboxIn(container: Element, items: LightboxItem[], { at }: { at?: number } = {}): () => void {\n const root = container.shadowRoot ?? container.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = `${STYLE}:host { display: block; }`;\n root.replaceChildren(style);\n tooltips(root);\n const { close } = openLightbox(root, items, { ...(at === undefined ? {} : { at }), pinned: true });\n return () => {\n close();\n style.remove();\n };\n}\n\n/** Starts the overlay, once per page: the client module runs again when a module importing it is replaced. */\nexport function start({ base, shortcut: own, plugins: given }: StartOptions): void {\n const page = globalThis as { [STARTED]?: true };\n if (page[STARTED] === true) return;\n page[STARTED] = true;\n\n const host = document.createElement('deictic-overlay');\n const root = host.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = STYLE;\n const box = div('box');\n const label = div('label');\n box.append(label);\n // What's under the pointer, outlined inside the marked element around it when they differ.\n const inner = div('box inner');\n root.append(style, box, inner);\n tooltips(root);\n // What's typed in the popup is the popup's: the page hears a key from in here as one on the host, not in a field,\n // so its own shortcuts (a \"/\" to search, a \"j\" to step) would run on a task's words. Ours listen while capturing.\n for (const type of ['keydown', 'keypress', 'keyup'] as const) host.addEventListener(type, (e) => e.stopPropagation());\n document.documentElement.append(host);\n\n // Each plugin's API, set up before any panel opens. `use` reads it when asked, so a setup may keep\n // `use` for later, not call it: the plugin it asks for may not be set up yet.\n const apis = new Map<string, unknown>();\n const optionsOf = new Map(given.map(({ plugin, options }) => [plugin.name, options]));\n const contextOf = (name: string): ClientContext => ({\n base,\n root,\n options: optionsOf.get(name),\n use: (other) => apis.get(other) as never,\n request: (route, init) => fetch(`${base}__deictic/plugins/${name}/${route}`, init),\n open: (plugin, element) => openAt(plugin, element),\n lightbox: (items, options) => openLightbox(root, items, options),\n });\n for (const { plugin } of given) {\n if (plugin.setup === undefined) continue;\n try {\n apis.set(plugin.name, plugin.setup(contextOf(plugin.name)));\n } catch (e) {\n // One plugin's failure is no reason to take the others down with it.\n console.error(`deictic: ${plugin.name} failed to set up`, e);\n }\n }\n const tabs: Tab[] = given.flatMap(({ plugin }) => (plugin.mount === undefined ? [] : [{ plugin, mount: plugin.mount }]));\n started = {\n base,\n contextOf,\n tabs,\n // Not over a popup holding something unsaved: the press that asked shook its button (`openPanel`).\n open: (element, tab) => tabs.length > 0 && panel?.unsaved() !== true && openAt(tab ?? last().plugin.name, element),\n };\n const last = () => {\n let name: string | null = null;\n try {\n name = localStorage.getItem(LAST);\n } catch {\n // Storage can be off: the first tab, then.\n }\n return tabs.find((t) => t.plugin.name === name) ?? tabs[0]!;\n };\n const remember = (tab: Tab) => {\n try {\n localStorage.setItem(LAST, tab.plugin.name);\n } catch {\n // Not kept, then: the next open starts at the first tab.\n }\n };\n // What opens the popup, and at which tab: deictic's own shortcut at the one used last, each\n // plugin's at its own.\n const plugins = [\n ...(own === undefined || tabs.length === 0 ? [] : [{ shortcut: own, gesture: gestureOf(own), tab: last }]),\n ...given.flatMap(({ plugin, shortcut }) => {\n if (shortcut === undefined) return [];\n const tab = tabs.find((t) => t.plugin === plugin);\n if (tab !== undefined) return [{ shortcut, gesture: gestureOf(shortcut), tab: () => tab }];\n console.error(`deictic: ${plugin.name} has a shortcut, but its page half has no \\`mount\\` to draw a tab with`);\n return [];\n }),\n ];\n\n let pointer: { x: number; y: number } | undefined;\n let frame = 0;\n let panel: { close: () => void; unsaved: () => boolean } | undefined;\n\n /** The plugins whose keys are held: several, where they share keys and differ by button. */\n const heldBy = (e: MouseEvent | KeyboardEvent) => plugins.filter((p) => p.gesture.held(e));\n /** The plugin a press opens. */\n const pressedBy = (e: MouseEvent) => plugins.find((p) => p.gesture.held(e) && e.button === p.gesture.button);\n /**\n * The marked element at a point, and what's under the pointer inside it where that differs: down through\n * open shadow roots but the overlay's own, as a page showing the popup (`popupIn`) has it in one.\n */\n const hitAt = (x: number, y: number) => {\n let under = document.elementFromPoint(x, y) ?? undefined;\n while (under !== undefined && under !== host && under.shadowRoot !== null) {\n const inside = under.shadowRoot.elementFromPoint(x, y);\n if (inside === null || inside === under) break;\n under = inside;\n }\n const el = under === undefined || under === host ? undefined : markedAround(under);\n return el === undefined ? undefined : { el, pointed: under === el ? undefined : under };\n };\n const hide = () => {\n box.classList.remove('shown');\n inner.classList.remove('shown');\n };\n const show = (held: typeof plugins) => {\n frame = 0;\n const hit = pointer === undefined ? undefined : hitAt(pointer.x, pointer.y);\n const el = hit?.el;\n const target = el === undefined ? undefined : targetOf(el);\n if (el === undefined || target === undefined) return hide();\n place(box, el.getBoundingClientRect());\n if (hit?.pointed === undefined) {\n inner.classList.remove('shown');\n } else {\n place(inner, hit.pointed.getBoundingClientRect());\n inner.classList.add('shown');\n }\n const count = sameAs(el).length;\n // The button, where it isn't the left: what the keys alone don't tell apart.\n const names = held.map(({ tab, shortcut }) => {\n const { plugin } = tab();\n const name = plugin.label ?? plugin.name;\n return shortcut.button === 'left' ? name : `${name} (${shortcut.button})`;\n });\n const within = hit?.pointed === undefined ? '' : ` › ${nameOf(hit.pointed)}`;\n label.textContent = `${names.join(' / ')} · <${target.tag}> ${target.loc.file}:${target.loc.line}${count > 1 ? ` · ×${count}` : ''}${within}`;\n label.classList.toggle('below', el.getBoundingClientRect().top < 24);\n box.classList.add('shown');\n };\n const update = (e: MouseEvent | KeyboardEvent) => {\n const held = heldBy(e);\n if (held.length === 0) return hide();\n if (frame === 0) frame = requestAnimationFrame(() => show(held));\n };\n\n window.addEventListener(\n 'mousemove',\n (e) => {\n pointer = { x: e.clientX, y: e.clientY };\n update(e);\n },\n { capture: true, passive: true },\n );\n window.addEventListener('keydown', update, true);\n window.addEventListener('keyup', update, true);\n window.addEventListener('blur', hide);\n let press = {};\n let opened: object | undefined;\n // Alt-click on a link would otherwise download it, and on a field focus it.\n window.addEventListener(\n 'mousedown',\n (e) => {\n press = {};\n if (e.composedPath().includes(host)) return;\n if (pressedBy(e) !== undefined && hitAt(e.clientX, e.clientY) !== undefined) e.preventDefault();\n },\n true,\n );\n // A press ends in `click`, `auxclick` or `contextmenu` by its button, and a right one in two of\n // them, in an order that varies by platform; on macOS Control-click is a left `contextmenu`. Each\n // is kept from the page, and the first opens the panel.\n const pressed = (e: MouseEvent) => {\n if (e.composedPath().includes(host)) return;\n const found = pressedBy(e);\n const hit = found === undefined ? undefined : hitAt(e.clientX, e.clientY);\n const target = hit === undefined ? undefined : targetOf(hit.el);\n if (found === undefined || hit === undefined || target === undefined) return;\n e.preventDefault();\n e.stopPropagation();\n if (opened === press) return;\n opened = press;\n // Still open after this press's pointerdown, outside it: it holds something unsaved, and shook its button.\n if (panel?.unsaved() === true) return;\n openTab(found.tab(), hit.el, target, undefined, hit.pointed);\n };\n const openTab = (tab: Tab, el: Element, target: Target, resumed?: Resumed, pointed?: Element) => {\n hide();\n panel?.close();\n panel = openPanel({\n base,\n root,\n contextOf,\n tabs,\n tab,\n remember,\n element: el,\n ...(pointed === undefined ? {} : { pointed }),\n target,\n onClose: () => (panel = undefined),\n ...(resumed === undefined ? {} : { resumed }),\n reopen: (again, element, kept) => {\n const found = element.isConnected ? element : sameAs(element)[0];\n const at = found === undefined ? undefined : targetOf(found);\n // Gone from the page while away: there's nothing to come back to.\n if (found === undefined || at === undefined)\n return console.warn('deictic: the element is no longer on the page, so the popup stays closed');\n openTab(again, found, at, kept, pointed?.isConnected === true && found === element ? pointed : undefined);\n },\n });\n };\n function openAt(name: string, given: Element): boolean {\n const tab = tabs.find((t) => t.plugin.name === name);\n const el = given.isConnected ? given : (sameAs(given)[0] ?? undefined);\n const target = el === undefined ? undefined : targetOf(el);\n if (tab === undefined || el === undefined || target === undefined) return false;\n openTab(tab, el, target);\n return true;\n }\n for (const type of ['click', 'auxclick', 'contextmenu'] as const) window.addEventListener(type, pressed, true);\n}\n\ninterface PanelOptions {\n base: string;\n root: ShadowRoot;\n contextOf: (name: string) => ClientContext;\n tabs: Tab[];\n /** The tab it opens at. */\n tab: Tab;\n /** Keeps the tab shown, for deictic's own shortcut to open at next. */\n remember: (tab: Tab) => void;\n element: Element;\n /** What was under the pointer inside `element`, where that differs. */\n pointed?: Element;\n target: Target;\n /** Shown where the page put it (`popupIn`), not over the page beside the element; Esc leaves it alone. */\n pinned?: boolean;\n /** Called as it closes: the tab it showed, and whether it's leaving for a tab's `away`, to come back by `reopen`. */\n onClose: (shown: Tab, leaving: boolean) => void;\n /** What the first tab's mount gets, coming back from `away`. */\n resumed?: Resumed;\n /** Opens the popup again, at a tab on an element, coming back from `away`. */\n reopen: (tab: Tab, element: Element, resumed: Resumed) => void;\n}\n\nfunction openPanel({\n base,\n root,\n contextOf,\n tabs,\n tab: first,\n remember,\n element,\n pointed,\n target,\n pinned = false,\n onClose,\n resumed: coming,\n reopen,\n}: PanelOptions): { close: () => void; unsaved: () => boolean } {\n // Given to the first tab's first mount only: another tab, or a remount after an undo, starts afresh.\n let resumed = coming;\n const panel = div('panel');\n // The tabs, then the element's place and undo and redo, which are the shown tab's on this element.\n const head = div('head');\n head.setAttribute('role', 'tablist');\n const bar = div('bar');\n const where = document.createElement('a');\n where.className = 'where';\n const file = document.createElement('span');\n file.textContent = `${target.loc.file}:${target.loc.line}`;\n // An arrow out, as it leaves the page for the editor; its title is the overlay's tooltip (`tooltip.ts`).\n where.append(file);\n where.insertAdjacentHTML('beforeend', OUT);\n where.title = 'Open in editor';\n where.setAttribute('aria-label', `Open ${file.textContent} in the editor`);\n // The element's place, as a request's query names it.\n const at = { file: target.loc.file, line: String(target.loc.line), column: String(target.loc.column) };\n where.href = `${base}__deictic/open?${new URLSearchParams(at)}`;\n where.addEventListener('click', (e) => {\n e.preventDefault();\n void fetch(where.href);\n });\n // Off until the tab's history is read: there's nothing to take back on most elements.\n const undo = iconButton(UNDO, 'Undo', 'Nothing to undo');\n const redo = iconButton(REDO, 'Redo', 'Nothing to redo');\n undo.disabled = redo.disabled = true;\n const close = iconButton(CLOSE, 'Close', pinned ? 'Close' : 'Close (Esc)');\n const buttons = tabs.map((tab) => {\n const el = button(tab.plugin.label ?? tab.plugin.name, '');\n el.className = 'tab';\n el.setAttribute('role', 'tab');\n el.addEventListener('click', () => show(tab));\n return { tab, el };\n });\n close.classList.add('close');\n head.append(...buttons.map((b) => b.el), close);\n bar.append(where, undo, redo);\n const body = div('body');\n body.setAttribute('role', 'tabpanel');\n const status = div('status');\n panel.append(head, bar, body, status);\n root.append(panel);\n if (pinned) panel.classList.add('pinned');\n const release = pinned ? undefined : keepInView(panel, body, head, element);\n const unmark = pinned ? undefined : outline(root, element);\n if (!pinned) window.dispatchEvent(new CustomEvent<PopupOpened>(POPUP_OPENED, { detail: { element, tab: first.plugin.name } }));\n\n let cleanup: (() => void) | void;\n // The button that keeps what the shown tab would lose, while there's something: `unsaved`, from the panel.\n let holding: HTMLElement | undefined;\n const say = (text: string, problem = false) => {\n status.textContent = text;\n status.classList.toggle('problem', problem);\n };\n const post = async <T>(route: string, body?: unknown): Promise<T> => {\n const res = await fetch(`${base}__deictic/${route}`, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify(body ?? {}),\n });\n const json = (await res.json()) as T & { problem?: string };\n if (!res.ok) throw new Error(json.problem ?? res.statusText);\n return json;\n };\n const unmount = () => {\n cleanup?.();\n cleanup = undefined;\n holding = undefined;\n body.replaceChildren();\n };\n // The change undone may be this tab's from before the panel opened: the panel reads its model again.\n const step = (route: 'undo' | 'redo') =>\n post<{ change: { label: string } }>(route, { plugin: current.plugin.name, target })\n .then(\n async ({ change }) => {\n await load();\n say(`${route === 'undo' ? 'Undid' : 'Redid'} ${change.label}`);\n },\n (e: unknown) => say(messageOf(e), true),\n )\n .finally(() => void steps());\n // Undo and redo as the tab's history on this element stands: off with nothing to take back or do again, else\n // saying what they would. Read as a tab shows, after each change made here, and as the pointer comes back, for a\n // change made elsewhere. One a later read overtook (another tab's) sets nothing.\n let asked = 0;\n const steps = async () => {\n const ask = ++asked;\n let history: { done: { label: string }[]; undone: { label: string }[] };\n try {\n const res = await fetch(`${base}__deictic/history?${new URLSearchParams({ plugin: current.plugin.name, ...at })}`);\n if (!res.ok || ask !== asked) return;\n history = (await res.json()) as typeof history;\n } catch {\n return;\n }\n const last = history.done.at(-1);\n const next = history.undone.at(-1);\n undo.disabled = last === undefined;\n undo.title = last === undefined ? 'Nothing to undo' : `Undo ${last.label}`;\n redo.disabled = next === undefined;\n redo.title = next === undefined ? 'Nothing to redo' : `Redo ${next.label}`;\n };\n panel.addEventListener('pointerenter', () => void steps());\n\n const done = (leaving = false) => {\n unmount();\n release?.();\n unmark?.();\n panel.remove();\n window.removeEventListener('keydown', onKey, true);\n window.removeEventListener('pointerdown', onOutside, true);\n if (!pinned) window.dispatchEvent(new CustomEvent(POPUP_CLOSED));\n onClose(current, leaving);\n };\n const onKey = (e: KeyboardEvent) => {\n // A plugin's modal over the popup (one marked `data-deictic-modal`) takes Esc for itself.\n if (e.key !== 'Escape' || root.querySelector('[data-deictic-modal]') !== null) return;\n // Esc is the popup's while it's open: a dialog of the page's that it's open in stays open.\n e.preventDefault();\n e.stopPropagation();\n done();\n };\n // A press on the page closes the popup, as it would a menu, unless that loses something: then the button that\n // keeps it shakes. Anything in the overlay is the popup's own: a modal, the lightbox, the surface marks are drawn on.\n const onOutside = (e: PointerEvent) => {\n if (e.composedPath().includes(root.host)) return;\n if (holding === undefined) return done();\n shake(holding);\n };\n if (!pinned) {\n window.addEventListener('keydown', onKey, true);\n window.addEventListener('pointerdown', onOutside, true);\n }\n undo.addEventListener('click', () => void step('undo'));\n redo.addEventListener('click', () => void step('redo'));\n close.addEventListener('click', () => done());\n\n let current = first;\n // A read that a later one overtook (another tab, or the same after an undo) mounts nothing.\n let reads = 0;\n const load = async () => {\n const { plugin, mount } = current;\n const read = ++reads;\n // The body keeps its height while it's empty, and \"Reading…\" waits for a read that takes long: one answered\n // at once, as most are, would otherwise fold the popup and open it again in a blink.\n body.style.minHeight = `${body.offsetHeight}px`;\n unmount();\n say('');\n const slow = setTimeout(() => read === reads && say('Reading…'), SLOW);\n let model: unknown;\n try {\n ({ model } = await post<{ model: unknown }>('read', { plugin: plugin.name, target }));\n } catch (e) {\n if (read !== reads) return;\n body.style.minHeight = '';\n say(messageOf(e), true);\n return;\n } finally {\n clearTimeout(slow);\n }\n if (read !== reads) return;\n body.style.minHeight = '';\n say('');\n const back = current === first ? resumed : undefined;\n resumed = undefined;\n cleanup = mount(body, {\n ...contextOf(plugin.name),\n ...(back === undefined ? {} : { resumed: back }),\n away: (state, task) => {\n const tab = current;\n done(true);\n void task().then(\n (result) => reopen(tab, element, { state, result }),\n (e: unknown) => reopen(tab, element, { state, problem: messageOf(e) }),\n );\n },\n element,\n ...(pointed === undefined ? {} : { pointed }),\n elements: sameAs(element),\n target,\n model,\n apply: async (op) => {\n say('Writing…');\n try {\n const result = await post<{ model: unknown }>('apply', { plugin: plugin.name, target, op });\n say('');\n void steps();\n return result.model;\n } catch (e) {\n say(messageOf(e), true);\n throw e;\n }\n },\n close: () => done(),\n unsaved: (action) => {\n if (read === reads) holding = action;\n },\n });\n };\n const show = (tab: Tab) => {\n current = tab;\n for (const b of buttons) b.el.setAttribute('aria-selected', String(b.tab === tab));\n remember(tab);\n void steps();\n void load();\n };\n show(first);\n return { close: done, unsaved: () => holding !== undefined };\n}\n\n/** Shakes a panel's button, in view: what a press outside does where closing would lose something. A blink where motion is reduced. */\nfunction shake(el: HTMLElement): void {\n el.scrollIntoView({ block: 'nearest' });\n if (matchMedia('(prefers-reduced-motion: reduce)').matches) return void el.animate({ opacity: [1, 0.3, 1, 0.3, 1] }, 400);\n el.animate({ translate: ['0', '-5px', '5px', '-4px', '4px', '-2px', '0'] }, { duration: 360, easing: 'ease-out' });\n}\n\n/** Puts an outline over `r`. */\nfunction place(el: HTMLElement, r: DOMRect): void {\n Object.assign(el.style, { left: `${r.left}px`, top: `${r.top}px`, width: `${r.width}px`, height: `${r.height}px` });\n}\n\n/** How far from the element the popup's outline is drawn, in pixels. */\nconst ROOM = 4;\n\n/**\n * Outlines the element the popup is open on, for as long as it is: which one it's about, where several look alike\n * or the popup covers it. Dashed, with no fill and a little room around the element, so nothing of it is drawn on:\n * a border, a ring or a colour tried on it shows as it is. Read each frame, as the element moves with the page's\n * scrolling, its layout and what a panel previews on it. Answers what removes it.\n */\nfunction outline(root: ShadowRoot, element: Element): () => void {\n const box = div('box on');\n root.append(box);\n let frame = 0;\n let was = '';\n const follow = () => {\n frame = requestAnimationFrame(follow);\n const r = element.getBoundingClientRect();\n const now = element.isConnected ? `${r.left},${r.top},${r.width},${r.height}` : '';\n if (now === was) return;\n was = now;\n box.classList.toggle('shown', now !== '');\n place(box, new DOMRect(r.left - ROOM, r.top - ROOM, r.width + 2 * ROOM, r.height + 2 * ROOM));\n };\n follow();\n return () => {\n cancelAnimationFrame(frame);\n box.remove();\n };\n}\n\nconst MARGIN = 8;\n// Under this much room on either side, the panel overlaps the element rather than shrink to a sliver beside it.\nconst LEAST = 160;\n\n/** How far a press on the head moves, in pixels, before it's a drag: a click there leaves the popup following. */\nconst SLACK = 3;\n\n/**\n * Keeps a panel beside `element` and inside the viewport, as its tabs fill it, the window resizes and the element\n * moves with the page: below, or above where it fits better, its height capped to the room there, so the body\n * scrolls rather than the panel leaving the window. Dragged by `handle`, it stays where it's put, in the window,\n * and follows the element no more. Fixed, so it never changes the page's own scrolling. Answers a release.\n */\nfunction keepInView(panel: HTMLElement, body: HTMLElement, handle: HTMLElement, element: Element): () => void {\n let frame = 0;\n let timer: ReturnType<typeof setTimeout> | undefined;\n // Where the element was last seen: one gone from the page leaves the popup where it was.\n let r = element.getBoundingClientRect();\n let moved: { left: number; top: number } | undefined;\n const fit = () => {\n cancelAnimationFrame(frame);\n clearTimeout(timer);\n frame = 0;\n timer = undefined;\n // The viewport without the page's scrollbars.\n const width = document.documentElement.clientWidth;\n const height = document.documentElement.clientHeight;\n // What the panel would take with no cap: its frame, and all of its body.\n const wanted = panel.offsetHeight - body.clientHeight + body.scrollHeight;\n if (moved !== undefined) {\n const room = Math.max(0, height - 2 * MARGIN);\n Object.assign(panel.style, {\n left: `${Math.max(MARGIN, Math.min(moved.left, width - MARGIN - panel.offsetWidth))}px`,\n top: `${Math.max(MARGIN, Math.min(moved.top, height - MARGIN - Math.min(wanted, room)))}px`,\n maxHeight: `${room}px`,\n });\n return;\n }\n const top = Math.min(Math.max(r.top, 0), height);\n const bottom = Math.min(Math.max(r.bottom, 0), height);\n const below = height - bottom - 2 * MARGIN;\n const above = top - 2 * MARGIN;\n const cap = Math.max(0, Math.min(height * 0.6, height - 2 * MARGIN));\n let at: number;\n let room: number;\n if (Math.max(below, above) < LEAST) {\n room = height - 2 * MARGIN;\n at = Math.min(Math.max(bottom + MARGIN, MARGIN), height - MARGIN - Math.min(wanted, room));\n } else if (wanted <= below || below >= above) {\n room = Math.min(below, cap);\n at = bottom + MARGIN;\n } else {\n room = Math.min(above, cap);\n at = top - MARGIN - Math.min(wanted, room);\n }\n Object.assign(panel.style, {\n left: `${Math.max(MARGIN, Math.min(r.left, width - MARGIN - panel.offsetWidth))}px`,\n top: `${at}px`,\n bottom: '',\n maxHeight: `${room}px`,\n });\n };\n // Not in the observers' callbacks, where a change of size is a \"ResizeObserver loop\" error on the page. The next\n // frame, or a moment later where there's none: a hidden tab draws no frames, and its popup still fits when shown.\n const later = () => {\n frame ||= requestAnimationFrame(fit);\n timer ??= setTimeout(fit, 50);\n };\n fit();\n // Read each frame, as nothing tells of an element moving: the page scrolls, its layout shifts, a panel previews.\n let watching = requestAnimationFrame(function watch() {\n if (moved !== undefined) return;\n watching = requestAnimationFrame(watch);\n if (!element.isConnected) return;\n const now = element.getBoundingClientRect();\n if (now.left === r.left && now.top === r.top && now.width === r.width && now.height === r.height) return;\n r = now;\n fit();\n });\n // A drag starts on the head itself, not on a tab or the close in it.\n let from: { x: number; y: number; left: number; top: number } | undefined;\n const down = (e: PointerEvent) => {\n if (e.button !== 0 || (e.target as Element).closest('button') !== null) return;\n // Kept from the browser: no text selected along the way, and the field being typed in keeps its focus.\n e.preventDefault();\n const at = panel.getBoundingClientRect();\n from = { x: e.clientX, y: e.clientY, left: at.left, top: at.top };\n handle.setPointerCapture(e.pointerId);\n };\n const move = (e: PointerEvent) => {\n if (from === undefined) return;\n const x = e.clientX - from.x;\n const y = e.clientY - from.y;\n if (moved === undefined && Math.hypot(x, y) < SLACK) return;\n moved = { left: from.left + x, top: from.top + y };\n panel.classList.add('dragging');\n fit();\n };\n const up = () => {\n from = undefined;\n panel.classList.remove('dragging');\n };\n handle.addEventListener('pointerdown', down);\n handle.addEventListener('pointermove', move);\n handle.addEventListener('pointerup', up);\n handle.addEventListener('pointercancel', up);\n // A tab's content arrives after the panel opens, and changes as it's used, as does the status line. Both, as a\n // resize observer reports only while the page renders: a hidden tab's popup would keep its first place.\n const resized = new ResizeObserver(later);\n resized.observe(panel);\n const changed = new MutationObserver(later);\n changed.observe(panel, { childList: true, subtree: true, characterData: true });\n window.addEventListener('resize', later);\n return () => {\n cancelAnimationFrame(frame);\n cancelAnimationFrame(watching);\n clearTimeout(timer);\n resized.disconnect();\n changed.disconnect();\n window.removeEventListener('resize', later);\n };\n}\n\nfunction div(className: string): HTMLDivElement {\n const el = document.createElement('div');\n el.className = className;\n return el;\n}\n\n/** A button that is a drawing: named for what it does, as its title, the tooltip, changes with what it would do. */\nfunction iconButton(svg: string, name: string, title: string): HTMLButtonElement {\n const el = button('', title);\n el.className = 'icon';\n el.innerHTML = svg;\n el.setAttribute('aria-label', name);\n return el;\n}\n\nfunction button(text: string, title: string): HTMLButtonElement {\n const el = document.createElement('button');\n el.type = 'button';\n el.textContent = text;\n el.title = title;\n return el;\n}\n\nconst messageOf = (e: unknown) => (e instanceof Error ? e.message : String(e));\n"],"mappings":";;;AAUA,MAAM,OAAO;AACb,MAAM,OAAO;AACb,MAAM,QAAQ;AAEd,MAAM,gBAAgB,WAAW,kCAAkC,CAAC,CAAC;AACrE,MAAM,SAAS,MAAc,GAAG,KAAK,MAAM,IAAI,EAAE,EAAE,GAAG,OAAO,KAAK,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;;;;;AAMhG,SAAgB,aACd,MACA,OACA,EAAE,KAAK,GAAG,MAAM,SAAS,UAAkD,CAAC,GACrD;CACvB,MAAM,MAAMA,MAAI,SAAS,oBAAoB,UAAU;CACvD,IAAI,CAAC,QAAQ;EACX,IAAI,QAAQ,eAAe;EAC3B,IAAI,aAAa,QAAQ,QAAQ;EACjC,IAAI,aAAa,cAAc,MAAM;CACvC;CACA,MAAM,WAAWA,MAAI,aAAa;CAClC,MAAM,QAAQA,MAAI,UAAU;CAC5B,MAAM,OAAOA,MAAI,SAAS;CAC1B,MAAM,QAAQA,MAAI,UAAU;CAC5B,MAAM,QAAQA,MAAI,UAAU;CAC5B,MAAM,UAAUA,MAAI,YAAY;CAChC,MAAM,QAAQC,SAAO,KAAK,eAAe,UAAU;CACnD,KAAK,OAAO,OAAO,OAAO,SAAS,KAAK;CACx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
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
4
+ import { t as keptIn } from "./kept.js";
5
+ import { c as setUp, f as isHost, g as parse, h as openingsIn, l as ASTRO, m as offsetOf, p as lineStarts, u as parseAstro } from "./integration.js";
6
+ // src/tools/source.ts
7
+ /**
8
+ * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute
9
+ * points at. Files are only ever read and written under the project's root, outside `node_modules`.
10
+ */
11
+ /** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */
12
+ function resolveFile(root, file) {
13
+ const path = resolve(root, file);
14
+ const from = relative(root, path);
15
+ if (from === "" || from.startsWith("..") || isAbsolute(from) || from.split(sep).includes("node_modules")) throw new Refusal(`${file} is not a file of this project's own`);
16
+ return path;
17
+ }
18
+ function readSource(root, file) {
19
+ try {
20
+ return readFileSync(resolveFile(root, file), "utf8");
21
+ } catch (e) {
22
+ if (e instanceof Refusal) throw e;
23
+ throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });
24
+ }
25
+ }
26
+ /** The target's file and element, as they are on disk now. */
27
+ function sourceAt(root, target) {
28
+ const { file, line, column } = target.loc;
29
+ const code = readSource(root, file);
30
+ const offset = offsetOf(lineStarts(code), line, column);
31
+ const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);
32
+ const element = elements.find((el) => el.start === offset && isHost(el));
33
+ if (element === void 0 || element.name.type === "JSXIdentifier" && element.name.name !== target.tag) throw new Refusal(`no <${target.tag}> at ${file}:${line}:${column} any more: the file changed since the page loaded, so reload it`);
34
+ return {
35
+ file,
36
+ code,
37
+ program,
38
+ element,
39
+ read: (other) => readSource(root, other)
40
+ };
41
+ }
42
+ function jsx(file, code) {
43
+ const { program, errors } = parse(file, code);
44
+ if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0].message})`);
45
+ return {
46
+ program,
47
+ elements: openingsIn(program)
48
+ };
49
+ }
50
+ function astro(root, file, code) {
51
+ const parsed = parseAstro(root, code);
52
+ if ("problem" in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);
53
+ return parsed;
54
+ }
55
+ /** Each file's text after its edits, which must not overlap. */
56
+ function applyEdits(source, edits) {
57
+ const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);
58
+ const out = /* @__PURE__ */ new Map();
59
+ for (const [file, list] of byFile) {
60
+ const sorted = list.toSorted((a, b) => b.start - a.start);
61
+ let code = file === source.file ? source.code : source.read(file);
62
+ let floor = 1e400;
63
+ for (const edit of sorted) {
64
+ if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);
65
+ code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);
66
+ floor = edit.start;
67
+ }
68
+ out.set(file, code);
69
+ }
70
+ return out;
71
+ }
72
+ // src/tools/history.ts
73
+ /**
74
+ * Every change deictic made, to undo and redo. A change to files holds each file's whole text
75
+ * before and after: source files are small, and the texts make undo exact without a diff to go stale.
76
+ * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the
77
+ * plugin's `undo`.
78
+ *
79
+ * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes
80
+ * within its own: the latest change of this tab on this element, not the latest of all. So a change
81
+ * is taken back out of order, with later ones to the same file still in it. Then only the lines the
82
+ * change wrote go back to what they were, where they're still in the file as it wrote them, once.
83
+ *
84
+ * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo
85
+ * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it
86
+ * outlives a restart of the dev server and stays out of git.
87
+ */
88
+ /** Whether a change is in a scope: any is in none. */
89
+ const within = (scope) => (c) => scope === void 0 || c.scope?.plugin === scope.plugin && c.scope.target === scope.target;
90
+ const summary = (c) => ({
91
+ id: c.id,
92
+ at: c.at,
93
+ label: c.label,
94
+ files: "files" in c ? c.files.map((f) => f.file) : []
95
+ });
96
+ var History = class {
97
+ #done = [];
98
+ #undone = [];
99
+ #root;
100
+ #store;
101
+ #plugins;
102
+ constructor(root, { plugins = [], store = keptIn(root, "history.json") } = {}) {
103
+ this.#root = root;
104
+ this.#store = store;
105
+ this.#plugins = new Map(plugins.map((p) => [p.name, p]));
106
+ if (!existsSync(store)) return;
107
+ try {
108
+ ({done: this.#done, undone: this.#undone} = JSON.parse(readFileSync(store, "utf8")));
109
+ } catch {}
110
+ }
111
+ /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */
112
+ commit(label, texts, scope) {
113
+ const files = [];
114
+ for (const [file, after] of texts) {
115
+ const path = resolveFile(this.#root, file);
116
+ const before = existsSync(path) ? readFileSync(path, "utf8") : null;
117
+ if (before !== after) files.push({
118
+ file,
119
+ before,
120
+ after
121
+ });
122
+ }
123
+ if (files.length === 0) throw new Refusal("nothing to change: the source already says that");
124
+ for (const f of files) write(resolveFile(this.#root, f.file), f.after);
125
+ return this.#push({
126
+ label,
127
+ files
128
+ }, scope);
129
+ }
130
+ /** Records a change `plugin` made itself, with what its `undo` needs. */
131
+ record(label, plugin, record, scope) {
132
+ return this.#push({
133
+ label,
134
+ plugin,
135
+ record
136
+ }, scope);
137
+ }
138
+ /** Takes back the latest change, of a scope where one is given. */
139
+ async undo(scope) {
140
+ const change = this.#done.findLast(within(scope));
141
+ if (change === void 0) throw new Refusal(scope === void 0 ? "nothing to undo" : "nothing to undo here");
142
+ if ("files" in change) this.#put(change, "after", "before");
143
+ else change.record = await this.#pluginOf(change, "undo").undo(change.record) ?? change.record;
144
+ this.#done = this.#done.filter((c) => c !== change);
145
+ this.#undone.push(change);
146
+ this.#save();
147
+ return summary(change);
148
+ }
149
+ /** Makes the change last undone again, of a scope where one is given. */
150
+ async redo(scope) {
151
+ const change = this.#undone.findLast(within(scope));
152
+ if (change === void 0) throw new Refusal(scope === void 0 ? "nothing to redo" : "nothing to redo here");
153
+ if ("files" in change) this.#put(change, "before", "after");
154
+ else change.record = await this.#pluginOf(change, "redo").redo(change.record);
155
+ this.#undone = this.#undone.filter((c) => c !== change);
156
+ this.#done.push(change);
157
+ this.#save();
158
+ return summary(change);
159
+ }
160
+ list(scope) {
161
+ return {
162
+ done: this.#done.filter(within(scope)).map(summary),
163
+ undone: this.#undone.filter(within(scope)).map(summary)
164
+ };
165
+ }
166
+ #push(change, scope) {
167
+ const made = {
168
+ id: Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1,
169
+ at: (/* @__PURE__ */ new Date()).toISOString(),
170
+ ...change,
171
+ ...scope === void 0 ? {} : { scope }
172
+ };
173
+ this.#done = [...this.#done, made].slice(-200);
174
+ this.#undone = this.#undone.filter((c) => !within(scope)(c));
175
+ this.#save();
176
+ return summary(made);
177
+ }
178
+ #pluginOf(change, step) {
179
+ const plugin = this.#plugins.get(change.plugin);
180
+ if (plugin?.[step] === void 0) throw new Refusal(`can't ${step} "${change.label}": the ${change.plugin} plugin that made it isn't loaded, so add it back to \`plugins\``);
181
+ return plugin;
182
+ }
183
+ /**
184
+ * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the
185
+ * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.
186
+ */
187
+ #put(change, from, to) {
188
+ const paths = change.files.map((f) => resolveFile(this.#root, f.file));
189
+ change.files.map((f, i) => {
190
+ const now = existsSync(paths[i]) ? readFileSync(paths[i], "utf8") : null;
191
+ if (now === f[from]) return f[to];
192
+ const text = now === null || f[from] === null || f[to] === null ? void 0 : swapped(now, f[from], f[to]);
193
+ if (text === void 0) throw new Refusal(`${f.file} changed since "${change.label}" ${from === "after" ? "was made" : "was undone"}: use the editor's undo there`);
194
+ return text;
195
+ }).forEach((text, i) => {
196
+ if (text === null) rmSync(paths[i]);
197
+ else write(paths[i], text);
198
+ });
199
+ }
200
+ #save() {
201
+ write(this.#store, JSON.stringify({
202
+ done: this.#done,
203
+ undone: this.#undone
204
+ }));
205
+ }
206
+ };
207
+ /**
208
+ * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as
209
+ * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or
210
+ * where `from` has no such lines to find (the change only removed some).
211
+ */
212
+ function swapped(now, from, to) {
213
+ const [a, b, lines] = [
214
+ from.split("\n"),
215
+ to.split("\n"),
216
+ now.split("\n")
217
+ ];
218
+ let head = 0;
219
+ while (head < a.length && head < b.length && a[head] === b[head]) head++;
220
+ let tail = 0;
221
+ while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;
222
+ const theirs = a.slice(head, a.length - tail);
223
+ if (theirs.length === 0) return void 0;
224
+ const found = lines.flatMap((_, i) => theirs.every((line, j) => lines[i + j] === line) ? [i] : []);
225
+ if (found.length !== 1) return void 0;
226
+ return [
227
+ ...lines.slice(0, found[0]),
228
+ ...b.slice(head, b.length - tail),
229
+ ...lines.slice(found[0] + theirs.length)
230
+ ].join("\n");
231
+ }
232
+ function write(path, text) {
233
+ mkdirSync(dirname(path), { recursive: true });
234
+ writeFileSync(path, text);
235
+ }
236
+ // src/tools/endpoints.ts
237
+ const scopeOf = (plugin, { file, line, column }) => ({
238
+ plugin,
239
+ target: `${file}:${line}:${column}`
240
+ });
241
+ /** The scope an undo or a redo names, or none for the whole history. */
242
+ const scopeIn = ({ plugin, target }) => plugin === void 0 || target === void 0 ? void 0 : scopeOf(plugin, target.loc);
243
+ /** Answers deictic's requests, and nothing for any other path. */
244
+ function endpoints({ root, plugins, base = "/", open, history = new History(root, { plugins }) }) {
245
+ const byName = new Map(plugins.map((p) => [p.name, p]));
246
+ const prefix = `${base}__deictic/`;
247
+ const ready = setUp(root, plugins);
248
+ const pluginOf = (name) => {
249
+ const plugin = byName.get(name);
250
+ if (plugin === void 0) throw new Refusal(`no plugin "${name}" on the server: is it in the bundler plugin's \`plugins\`?`);
251
+ return plugin;
252
+ };
253
+ const routes = {
254
+ read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),
255
+ apply: async ({ plugin: name, target, op }) => {
256
+ const plugin = pluginOf(name);
257
+ if (plugin.apply === void 0) throw new Refusal(`${name} changes nothing from its panel: it has no \`apply\``);
258
+ const source = sourceAt(root, target);
259
+ const before = await readOf(plugin, target);
260
+ const { file, line } = target.loc;
261
+ const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? "edit"}`;
262
+ const result = await plugin.apply(source, target, op);
263
+ const scope = scopeOf(name, target.loc);
264
+ const change = Array.isArray(result) ? history.commit(label, applyEdits(source, result), scope) : history.record(label, name, result.done, scope);
265
+ return {
266
+ model: await readOf(plugin, target),
267
+ change
268
+ };
269
+ },
270
+ undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),
271
+ redo: async (body) => ({ change: await history.redo(scopeIn(body)) })
272
+ };
273
+ const readOf = (plugin, target) => plugin.read === void 0 ? null : plugin.read(sourceAt(root, target), target);
274
+ let queue = Promise.resolve();
275
+ const serially = (run) => {
276
+ const next = queue.then(run, run);
277
+ queue = next.catch(() => {});
278
+ return next;
279
+ };
280
+ return async (req) => {
281
+ const url = new URL(req.url);
282
+ if (!url.pathname.startsWith(prefix)) return void 0;
283
+ const route = url.pathname.slice(prefix.length);
284
+ const origin = req.headers.get("origin");
285
+ const sameOrigin = origin !== null && new URL(origin).host === url.host;
286
+ try {
287
+ const context = await ready;
288
+ if (route.startsWith("plugins/")) {
289
+ const [name = "", first = ""] = route.slice(8).split("/");
290
+ const handle = byName.get(name)?.routes?.[first];
291
+ if (handle === void 0) return new Response(`no endpoint ${url.pathname}`, { status: 404 });
292
+ if (req.method !== "GET" && req.method !== "HEAD" && !sameOrigin) return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });
293
+ return await handle(req, context);
294
+ }
295
+ const loc = {
296
+ file: url.searchParams.get("file") ?? "",
297
+ line: Number(url.searchParams.get("line")),
298
+ column: Number(url.searchParams.get("column"))
299
+ };
300
+ if (route === "history") {
301
+ const plugin = url.searchParams.get("plugin");
302
+ return Response.json(history.list(plugin === null ? void 0 : scopeOf(plugin, loc)));
303
+ }
304
+ if (route === "open") return await open(resolveFile(root, loc.file), loc);
305
+ const handler = routes[route];
306
+ if (handler === void 0) return new Response(`no endpoint ${url.pathname}`, { status: 404 });
307
+ if (req.method !== "POST" || !sameOrigin || req.headers.get("content-type")?.startsWith("application/json") !== true) return Response.json({ problem: "edits come from the page, as JSON" }, { status: 403 });
308
+ const body = await req.json();
309
+ return Response.json(await (route === "read" ? handler(body) : serially(() => handler(body))));
310
+ } catch (e) {
311
+ if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });
312
+ return Response.json({ problem: e instanceof Error ? e.stack ?? e.message : String(e) }, { status: 500 });
313
+ }
314
+ };
315
+ }
316
+ /** A redirect within the page's origin, to a launcher the dev server answers itself. */
317
+ const redirect = (path) => new Response(null, {
318
+ status: 307,
319
+ headers: { Location: path }
320
+ });
321
+ /**
322
+ * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was
323
+ * served from: a proxy's `x-forwarded-host` before its own.
324
+ */
325
+ function nodeMiddleware(handle) {
326
+ return (req, res, next) => {
327
+ if (req.url?.includes("/__deictic/") !== true) return next();
328
+ const forwarded = req.headers["x-forwarded-host"];
329
+ const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? "localhost";
330
+ const headers = new Headers();
331
+ for (const [name, value] of Object.entries(req.headers)) for (const v of Array.isArray(value) ? value : value === void 0 ? [] : [value]) headers.append(name, v);
332
+ const chunks = [];
333
+ req.on("data", (chunk) => chunks.push(chunk));
334
+ req.on("end", () => {
335
+ const body = req.method === "GET" || req.method === "HEAD" ? void 0 : Buffer.concat(chunks);
336
+ handle(new Request(`http://${host}${req.url}`, {
337
+ method: req.method,
338
+ headers,
339
+ body
340
+ })).then(async (response) => {
341
+ if (response === void 0) return next();
342
+ res.statusCode = response.status;
343
+ response.headers.forEach((value, name) => res.setHeader(name, value));
344
+ res.end(Buffer.from(await response.arrayBuffer()));
345
+ }).catch((e) => {
346
+ res.statusCode = 500;
347
+ res.end(e instanceof Error ? e.message : String(e));
348
+ });
349
+ });
350
+ };
351
+ }
352
+ export { nodeMiddleware as n, redirect as r, endpoints as t };
353
+
354
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.js","names":[],"sources":["../src/tools/source.ts","../src/tools/history.ts","../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/** The target's file and element, as they are on disk now. */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const offset = offsetOf(lineStarts(code), line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const element = elements.find((el) => el.start === offset && isHost(el));\n if (element === undefined || (element.name.type === 'JSXIdentifier' && element.name.name !== target.tag))\n throw new Refusal(`no <${target.tag}> at ${file}:${line}:${column} any more: the file changed since the page loaded, so reload it`);\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/** Each file's text after its edits, which must not overlap. */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : source.read(file);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { setUp } from './plugins.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceAt(root, target);\n const before = await readOf(plugin, target);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n const change = Array.isArray(result)\n ? history.commit(label, applyEdits(source, result), scope)\n : history.record(label, name, result.done, scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target) => (plugin.read === undefined ? null : plugin.read(sourceAt(root, target), target));\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n const body = (await req.json()) as Body;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;;AAaA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,MAAM,OAAO,SAAS,MAAM,IAAI;CAEhC,IAAI,SAAS,MAAM,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,GACrG,MAAM,IAAI,QAAQ,GAAG,KAAK,qCAAqC;CACjE,OAAO;AACT;AAEA,SAAgB,WAAW,MAAc,MAAsB;CAC7D,IAAI;EACF,OAAO,aAAa,YAAY,MAAM,IAAI,GAAG,MAAM;CACrD,SAAS,GAAG;EACV,IAAI,aAAa,SAAS,MAAM;EAChC,MAAM,IAAI,QAAQ,cAAc,KAAK,wCAAwC,EAAE,OAAO,EAAE,CAAC;CAC3F;AACF;;AAGA,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,EAAE,MAAM,MAAM,WAAW,OAAO;CACtC,MAAM,OAAO,WAAW,MAAM,IAAI;CAClC,MAAM,SAAS,SAAS,WAAW,IAAI,GAAG,MAAM,MAAM;CACtD,MAAM,EAAE,SAAS,aAAa,MAAM,KAAK,IAAI,IAAI,MAAM,MAAM,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI;CACzF,MAAM,UAAU,SAAS,MAAM,OAAO,GAAG,UAAU,UAAU,OAAO,EAAE,CAAC;CACvE,IAAI,YAAY,KAAA,KAAc,QAAQ,KAAK,SAAS,mBAAmB,QAAQ,KAAK,SAAS,OAAO,KAClG,MAAM,IAAI,QAAQ,OAAO,OAAO,IAAI,OAAO,KAAK,GAAG,KAAK,GAAG,OAAO,gEAAgE;CACpI,OAAO;EAA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