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":"client.js","names":[],"sources":["../../src/plugins/annotations/svg.ts","../../src/plugins/annotations/draw.ts","../../src/plugins/annotations/client.ts"],"sourcesContent":["/**\n * Annotations as SVG: the layer the page shows them in, and what a screenshot draws over itself. Shapes\n * only, no `foreignObject`, so a canvas that draws the SVG isn't tainted, and a browser rendering it\n * elsewhere needs nothing of the page.\n */\nimport type { Annotation, Area, Point } from './index.ts';\n\nexport const STROKE = 3;\nexport const FONT = 14;\nconst PAD = 6;\n\n/** How wide text is, in CSS pixels: measured where there's a canvas, guessed where there isn't. */\nexport type Measure = (text: string) => number;\n\nexport const guess: Measure = (text) => text.length * FONT * 0.6;\n\nconst escape = (text: string) => text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;').replaceAll('\"', '&quot;');\nconst n = (value: number) => Math.round(value * 10) / 10;\n\n/** An arrow's path: its line, then its head, two strokes back from the tip either side of the line. */\nfunction arrow(from: Point, to: Point): string {\n const angle = Math.atan2(to.y - from.y, to.x - from.x);\n const at = (p: Point) => `${n(p.x)},${n(p.y)}`;\n const side = (turn: number) => at({ x: to.x - 14 * Math.cos(angle + turn), y: to.y - 14 * Math.sin(angle + turn) });\n return `M${at(from)} L${at(to)} M${side(0.45)} L${at(to)} L${side(-0.45)}`;\n}\n\nfunction shapeOf({ shape, color }: Annotation, measure: Measure): string {\n const line = `fill=\"none\" stroke=\"${escape(color)}\" stroke-width=\"${STROKE}\" stroke-linecap=\"round\" stroke-linejoin=\"round\"`;\n switch (shape.kind) {\n case 'box':\n return `<rect x=\"${n(shape.x)}\" y=\"${n(shape.y)}\" width=\"${n(shape.width)}\" height=\"${n(shape.height)}\" rx=\"4\" ${line}/>`;\n case 'arrow':\n return `<path d=\"${arrow(shape.from, shape.to)}\" ${line}/>`;\n case 'pen':\n return `<polyline points=\"${shape.points.map((p) => `${n(p.x)},${n(p.y)}`).join(' ')}\" ${line}/>`;\n case 'note': {\n const lines = shape.text.split('\\n');\n const width = Math.max(...lines.map(measure)) + PAD * 2;\n const height = lines.length * FONT * 1.3 + PAD * 2;\n const text = lines\n .map(\n (l, i) => `<tspan x=\"${n(shape.at.x + PAD)}\" y=\"${n(shape.at.y + PAD + FONT * (i + 1) * 1.3 - FONT * 0.3)}\">${escape(l)}</tspan>`,\n )\n .join('');\n return (\n `<rect x=\"${n(shape.at.x)}\" y=\"${n(shape.at.y)}\" width=\"${n(width)}\" height=\"${n(height)}\" rx=\"4\" fill=\"${escape(color)}\"/>` +\n `<text font-family=\"system-ui, sans-serif\" font-size=\"${FONT}\" fill=\"#fff\">${text}</text>`\n );\n }\n }\n}\n\n/**\n * The annotations over `area` of the viewport, the page scrolled by `scroll`: an SVG `area`'s size,\n * whose view is that part of the page.\n */\nexport function toSvg(annotations: readonly Annotation[], area: Area, scroll: Point, measure: Measure = guess): string {\n const view = `${n(area.x + scroll.x)} ${n(area.y + scroll.y)} ${n(area.width)} ${n(area.height)}`;\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${n(area.width)}\" height=\"${n(area.height)}\" viewBox=\"${view}\">${annotations.map((a) => shapeOf(a, measure)).join('')}</svg>`;\n}\n","/**\n * Drawing with the pointer, wherever marks go: the page in annotate mode, or a picture in the editor.\n * Each says where an event is in its marks' coordinates; this is the toolbar and the gestures.\n */\nimport type { Point, Shape } from './index.ts';\nimport { FONT, guess, type Measure } from './svg.ts';\n\nexport const TOOLS_STYLE = `\n.annotations-tools { display: flex; flex-wrap: wrap; gap: 4px; }\n.annotations-tools .icon { display: inline-flex; align-items: center; justify-content: center; padding: 3px 5px; }\n.annotations-tools .icon svg { width: 16px; height: 16px; }\n.annotations-tools .gap { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--deictic-line); }\n.annotations-tools button[aria-pressed='true'] { background: var(--deictic-accent); border-color: var(--deictic-accent); color: var(--deictic-on-accent); }\n.annotations-tools .end { margin-left: auto; }\n.annotations-hint { margin: 6px 0 0; font-size: 12px; color: var(--deictic-muted); }\n`;\n\ntype Tool = 'pointer' | 'box' | 'arrow' | 'pen' | 'note';\nconst TOOLS: Tool[] = ['box', 'arrow', 'pen', 'note'];\nconst NAMES: Record<Tool, string> = {\n pointer: 'Use the page',\n box: 'Draw a box',\n arrow: 'Draw an arrow',\n pen: 'Draw freehand',\n note: 'Add a note',\n};\n\n/** Each icon's strokes, on a 24-pixel grid: drawn here, so the page half needs nothing to show them. */\nconst ICONS = {\n pointer: '<path d=\"M5 3l14 7-6 2-2 6z\"/>',\n box: '<rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"2\"/>',\n arrow: '<path d=\"M6 18 18 6M9 6h9v9\"/>',\n pen: '<path d=\"M4 20l1-4L16 5a2.1 2.1 0 0 1 3 3L8 19z\"/>',\n note: '<path d=\"M4 5h16v11H9l-5 4zM8 9h8M8 12h5\"/>',\n undo: '<path d=\"M9 14 4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3\"/>',\n clear: '<path d=\"M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3\"/>',\n} as const;\n\n/** A button that shows an icon, with its name as its tooltip and for a screen reader. */\nexport function iconButton(icon: keyof typeof ICONS, name: string, run: () => void): HTMLButtonElement {\n const el = button('', name, run);\n el.className = 'icon';\n el.setAttribute('aria-label', name);\n el.innerHTML = `<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">${ICONS[icon]}</svg>`;\n return el;\n}\n\n/** Text's width as the marks draw it, by a canvas's measure, which the guess stands in for without one. */\nexport function measurer(): Measure {\n const ctx = document.createElement('canvas').getContext('2d');\n if (ctx === null) return guess;\n ctx.font = `${FONT}px system-ui, sans-serif`;\n return (text) => ctx.measureText(text).width;\n}\n\nexport function button(label: string, title: string, run: () => void): HTMLButtonElement {\n const el = Object.assign(document.createElement('button'), { type: 'button', textContent: label, title });\n el.addEventListener('click', run);\n return el;\n}\n\nexport interface DrawingOptions {\n /** What takes the pointer to draw on. */\n surface: HTMLElement;\n /** Where an event is, in the coordinates the marks are kept in. */\n at: (e: PointerEvent) => Point;\n /** Shows the shape being drawn, or nothing once it's done. */\n preview: (shape: Shape | undefined) => void;\n add: (shape: Shape) => void;\n removeLast: () => void;\n clear: () => void;\n /**\n * Where the page stays usable between marks (a recording's toolbar): a pointer tool comes first and is\n * picked to start with, and this hears whether a drawing tool is picked, to let the surface take the\n * pointer only then.\n */\n drawing?: (on: boolean) => void;\n}\n\n/**\n * Draws on `surface` with the tool picked: answers the toolbar (the tools, then removing the last mark or all), for the\n * caller to add its own buttons to, and a hint for the tool.\n */\nexport function drawing({ surface, at, preview, add, removeLast, clear, drawing: on }: DrawingOptions) {\n const tools = document.createElement('div');\n tools.className = 'annotations-tools';\n const hint = document.createElement('p');\n hint.className = 'annotations-hint';\n\n let tool: Tool = on === undefined ? 'box' : 'pointer';\n const picks = (on === undefined ? TOOLS : (['pointer', ...TOOLS] as Tool[])).map((t) => ({\n t,\n el: iconButton(t, NAMES[t], () => pick(t)),\n }));\n const pick = (t: Tool) => {\n tool = t;\n for (const p of picks) p.el.setAttribute('aria-pressed', String(p.t === t));\n on?.(t !== 'pointer');\n hint.textContent =\n t === 'pointer'\n ? 'Use the page; pick a tool to draw.'\n : t === 'note'\n ? 'Click where the note goes, type it, Enter to place it.'\n : 'Drag to draw.';\n };\n const gap = document.createElement('span');\n gap.className = 'gap';\n tools.append(\n ...picks.map((p) => p.el),\n gap,\n iconButton('undo', 'Remove the last mark', removeLast),\n iconButton('clear', 'Remove every mark', clear),\n );\n pick(tool);\n\n surface.style.cursor = 'crosshair';\n const shapeFrom = (from: Point, to: Point, points: Point[]): Shape | undefined => {\n if (tool === 'pen') return points.length > 1 ? { kind: 'pen', points } : undefined;\n if (Math.hypot(to.x - from.x, to.y - from.y) < 4) return undefined;\n if (tool === 'arrow') return { kind: 'arrow', from, to };\n return {\n kind: 'box',\n x: Math.min(from.x, to.x),\n y: Math.min(from.y, to.y),\n width: Math.abs(to.x - from.x),\n height: Math.abs(to.y - from.y),\n };\n };\n\n surface.addEventListener('pointerdown', (e) => {\n if (e.button !== 0 || e.target instanceof HTMLInputElement) return;\n e.preventDefault();\n if (tool === 'note') return note(at(e), e);\n const from = at(e);\n const points = [from];\n surface.setPointerCapture(e.pointerId);\n const move = (m: PointerEvent) => {\n points.push(at(m));\n preview(shapeFrom(from, at(m), points));\n };\n const up = (u: PointerEvent) => {\n surface.removeEventListener('pointermove', move);\n preview(undefined);\n const shape = shapeFrom(from, at(u), points);\n if (shape !== undefined) add(shape);\n };\n surface.addEventListener('pointermove', move);\n surface.addEventListener('pointerup', up, { once: true });\n });\n\n /** A field where the note goes: Enter places what's typed, leaving it empty or blurring it places nothing. */\n const note = (point: Point, e: PointerEvent) => {\n const field = Object.assign(document.createElement('input'), { placeholder: 'Note, then Enter' });\n // Its own colours: on the page, outside the popup, it would take the page's text colour on deictic's dark field.\n field.style.cssText = `position:fixed;left:${e.clientX}px;top:${e.clientY}px;width:220px;pointer-events:auto;cursor:text;color:var(--deictic-fg);background:var(--deictic-bg);border-color:var(--deictic-accent)`;\n surface.append(field);\n const place = () => {\n const text = field.value.trim();\n field.remove();\n if (text !== '') add({ kind: 'note', at: point, text });\n };\n field.addEventListener('keydown', (k) => k.key === 'Enter' && place());\n field.addEventListener('blur', () => field.isConnected && place());\n // Now, not a frame later: the pointerdown's default is prevented, so no mousedown takes focus back.\n field.focus();\n };\n\n return { tools, hint };\n}\n","/**\n * Annotations in the page. `setup` keeps them (in the tab's session storage, per page) and shows them in a\n * layer of deictic's overlay that lets the pointer through; it answers the API other plugins `use`. The\n * panel is annotate mode: a toolbar, and while it's open a surface over the page that takes the pointer, so\n * drawing never clicks the page. Esc or Done leaves it; the marks stay.\n *\n * The layer is deictic's, so a screenshot leaves it out with the rest of the overlay and draws the marks\n * itself from `svg(area)`: one way to draw them, wherever a shot is rendered. `edit` draws on a picture\n * instead, a shot most often, in the same toolbar over everything, and `flatten` makes the PNG of it.\n */\nimport { defineClientPlugin } from '#src/index.ts';\n\nimport { button, drawing, measurer, TOOLS_STYLE } from './draw.ts';\nimport type { Annotation, AnnotationEvent, Annotations, Area, MarkSet, Picture, Point, Shape } from './index.ts';\nimport { type Measure, toSvg } from './svg.ts';\n\n/** Under deictic's outline and panels, over the page. */\nconst LAYER = 2147483645;\n/** Over everything of deictic's, the popup too. */\nconst TOP = 2147483647;\n\nconst scroll = (): Point => ({ x: scrollX, y: scrollY });\nconst viewport = (): Area => ({ x: 0, y: 0, width: document.documentElement.clientWidth, height: document.documentElement.clientHeight });\nconst mark = (shape: Shape, color: string): Annotation => ({ id: crypto.randomUUID(), color, shape, at: Date.now() });\n\n/** What's kept for this page in the tab's session, read as it can be. */\nfunction stored(key: string): Annotation[] {\n try {\n const kept: unknown = JSON.parse(sessionStorage.getItem(key) ?? '[]');\n return Array.isArray(kept) ? (kept as Annotation[]) : [];\n } catch {\n // Storage can be off, or hold something else: no marks is the page as it was.\n return [];\n }\n}\n\nfunction fixed(z: number): HTMLDivElement {\n const el = document.createElement('div');\n el.style.cssText = `position:fixed;inset:0;z-index:${z};pointer-events:none`;\n return el;\n}\n\nconst EDITOR_STYLE = `\n.annotations-editor { position: fixed; inset: 0; z-index: ${TOP}; box-sizing: border-box; padding: 16px; display: flex;\n flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: rgb(0 0 0 / 0.75);\n font: 13px/1.4 system-ui, sans-serif; color: var(--deictic-fg); }\n.annotations-editor .bar { box-sizing: border-box; width: min(100%, 720px); padding: 6px 8px; border: 1px solid var(--deictic-line);\n border-radius: 8px; background: var(--deictic-bg); }\n.annotations-editor .stage { position: relative; line-height: 0; box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); touch-action: none; }\n.annotations-editor img { display: block; max-width: calc(100vw - 32px); max-height: calc(100vh - 120px); user-select: none; }\n.annotations-editor .marks { position: absolute; inset: 0; pointer-events: none; }\n`;\n\n/** Loads an image, decoded. */\nasync function image(src: string): Promise<HTMLImageElement> {\n const el = new Image();\n el.src = src;\n await el.decode();\n return el;\n}\n\n/** The marks over a whole picture, as an SVG whose view is the picture's CSS pixels. */\nconst over = (picture: Picture, marks: readonly Annotation[], measure?: Measure) =>\n toSvg(marks, { x: 0, y: 0, width: picture.width, height: picture.height }, { x: 0, y: 0 }, measure);\n\n/**\n * The picture over everything, to draw on: the marks on Save, nothing on Cancel, Esc or `signal`. It holds\n * Esc while it's open (`data-deictic-modal`), so Esc leaves it, not the popup under it.\n */\nfunction edit(\n root: ShadowRoot,\n picture: Picture,\n start: readonly Annotation[],\n { color, measure, signal }: { color: string; measure: Measure; signal?: AbortSignal },\n): Promise<Annotation[] | undefined> {\n return new Promise((resolve) => {\n let marks = [...start];\n const backdrop = document.createElement('div');\n backdrop.className = 'annotations-editor';\n backdrop.dataset.deicticModal = '';\n const style = document.createElement('style');\n style.textContent = TOOLS_STYLE + EDITOR_STYLE;\n const bar = document.createElement('div');\n bar.className = 'bar';\n const stage = document.createElement('div');\n stage.className = 'stage';\n const img = Object.assign(document.createElement('img'), { src: picture.url, alt: 'The screenshot', draggable: false });\n const layer = document.createElement('div');\n layer.className = 'marks';\n stage.append(img, layer);\n\n const show = (preview?: Shape) => {\n layer.innerHTML = over(picture, preview === undefined ? marks : [...marks, mark(preview, color)], measure);\n // Drawn at the size the picture shows at, whatever that is: the view is the picture's own pixels.\n const svg = layer.firstElementChild;\n svg?.setAttribute('width', '100%');\n svg?.setAttribute('height', '100%');\n };\n const { tools, hint } = drawing({\n surface: stage,\n at: (e) => {\n const r = stage.getBoundingClientRect();\n return { x: ((e.clientX - r.left) * picture.width) / r.width, y: ((e.clientY - r.top) * picture.height) / r.height };\n },\n preview: (shape) => show(shape),\n add: (shape) => {\n marks = [...marks, mark(shape, color)];\n show();\n },\n removeLast: () => {\n marks = marks.slice(0, -1);\n show();\n },\n clear: () => {\n marks = [];\n show();\n },\n });\n const end = (result: Annotation[] | undefined) => {\n backdrop.remove();\n window.removeEventListener('keydown', onKey, true);\n signal?.removeEventListener('abort', cancel);\n resolve(result);\n };\n const cancel = () => end(undefined);\n const onKey = (e: KeyboardEvent) => {\n if (e.key !== 'Escape') return;\n e.stopPropagation();\n cancel();\n };\n const save = button('Save', 'Keep these marks', () => end(marks));\n save.classList.add('primary');\n const back = button('Cancel', 'Leave it as it was (Esc)', cancel);\n back.classList.add('end');\n tools.append(back, save);\n bar.append(tools, hint);\n backdrop.append(style, bar, stage);\n root.append(backdrop);\n window.addEventListener('keydown', onKey, true);\n signal?.addEventListener('abort', cancel);\n show();\n });\n}\n\n/**\n * Marks shown on the page, in a layer of the overlay that lets the pointer through, redrawn as it\n * scrolls. With a `key`, kept in the tab's session storage under it, per page; without, kept by nothing.\n */\nfunction marksOnPage(root: ShadowRoot, color: string, measure: Measure, key?: string): { marks: MarkSet; remove: () => void } {\n let list = key === undefined ? [] : stored(key);\n const listeners = new Set<(event: AnnotationEvent) => void>();\n const layer = fixed(LAYER);\n root.append(layer);\n\n let frame = 0;\n const draw = () => {\n frame = 0;\n layer.innerHTML = list.length === 0 ? '' : toSvg(list, viewport(), scroll(), measure);\n };\n const redraw = () => {\n if (frame === 0) frame = requestAnimationFrame(draw);\n };\n window.addEventListener('scroll', redraw, { capture: true, passive: true });\n window.addEventListener('resize', redraw, { passive: true });\n const changed = (event: AnnotationEvent) => {\n if (key !== undefined) {\n try {\n sessionStorage.setItem(key, JSON.stringify(list));\n } catch {\n // Not kept past a reload, then; the page still shows them.\n }\n }\n draw();\n for (const listener of listeners) listener(event);\n };\n draw();\n\n const marks: MarkSet = {\n list: () => [...list],\n add: (shape, given = color) => {\n const annotation = mark(shape, given);\n list = [...list, annotation];\n changed({ type: 'add', annotation });\n return annotation;\n },\n remove: (id) => {\n list = list.filter((a) => a.id !== id);\n changed({ type: 'remove', id });\n },\n clear: () => {\n list = [];\n changed({ type: 'clear' });\n },\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n svg: (area) => (list.length === 0 ? undefined : toSvg(list, area, scroll(), measure)),\n };\n const remove = () => {\n window.removeEventListener('scroll', redraw, { capture: true });\n window.removeEventListener('resize', redraw);\n cancelAnimationFrame(frame);\n layer.remove();\n listeners.clear();\n };\n return { marks, remove };\n}\n\n/**\n * Drawing on the page: a surface over it, under the popup, and the toolbar. Where the page stays usable\n * (`usable`), the surface takes the pointer only while a drawing tool is picked.\n */\nfunction onPage(root: ShadowRoot, marks: MarkSet, color: string, usable: boolean) {\n const surface = fixed(LAYER + 1);\n surface.style.pointerEvents = usable ? 'none' : 'auto';\n const preview = fixed(0);\n surface.append(preview);\n root.append(surface);\n const { tools, hint } = drawing({\n surface,\n at: (e) => ({ x: e.clientX + scrollX, y: e.clientY + scrollY }),\n preview: (shape) => {\n preview.innerHTML = shape === undefined ? '' : toSvg([mark(shape, color)], viewport(), scroll());\n },\n add: (shape) => marks.add(shape),\n removeLast: () => {\n const last = marks.list().at(-1);\n if (last !== undefined) marks.remove(last.id);\n },\n clear: () => marks.clear(),\n ...(usable ? { drawing: (on: boolean) => (surface.style.pointerEvents = on ? 'auto' : 'none') } : {}),\n });\n return { tools, hint, surface };\n}\n\n/** The picture with the marks drawn over it, as a PNG at the picture's own resolution. */\nasync function flatten(picture: Picture, marks: readonly Annotation[], measure: Measure): Promise<Blob> {\n const base = await image(picture.url);\n const canvas = document.createElement('canvas');\n canvas.width = base.naturalWidth;\n canvas.height = base.naturalHeight;\n const ctx = canvas.getContext('2d');\n if (ctx === null) throw new Error(\"annotations: this browser won't draw to a canvas\");\n ctx.drawImage(base, 0, 0);\n if (marks.length > 0) {\n // Shapes only, no `foreignObject`, so drawing the SVG leaves the canvas readable.\n const svg = await image(`data:image/svg+xml;charset=utf-8,${encodeURIComponent(over(picture, marks, measure))}`);\n ctx.drawImage(svg, 0, 0, canvas.width, canvas.height);\n }\n return new Promise((done, fail) =>\n canvas.toBlob((blob) => (blob === null ? fail(new Error('annotations: the picture drew nothing')) : done(blob)), 'image/png'),\n );\n}\n\nexport default defineClientPlugin<null, never, Annotations>({\n name: 'annotations',\n label: 'Annotate',\n setup: ({ root, options }) => {\n const color = (options as { color: string }).color;\n const measure = measurer();\n const page = marksOnPage(root, color, measure, `deictic:annotations:${location.pathname}`);\n\n const api: Annotations = {\n ...page.marks,\n edit: (picture, marks = [], { signal } = {}) => edit(root, picture, marks, { color, measure, ...(signal ? { signal } : {}) }),\n flatten: (picture, marks) => flatten(picture, marks, measure),\n tools: () => {\n // Its own marks, kept by nothing: they show while it's open, and go with it.\n const own = marksOnPage(root, color, measure);\n const { tools, surface } = onPage(root, own.marks, color, true);\n const element = document.createElement('div');\n element.append(Object.assign(document.createElement('style'), { textContent: TOOLS_STYLE }), tools);\n return {\n element,\n marks: own.marks,\n close: () => {\n surface.remove();\n own.remove();\n },\n };\n },\n };\n return api;\n },\n\n mount: (panel, { root, use, close, options }) => {\n const { color } = options as { color: string };\n const marks = use('annotations');\n if (marks === undefined) return;\n const style = document.createElement('style');\n style.textContent = TOOLS_STYLE;\n // Over the page while annotate mode is open: it takes the pointer, so drawing never clicks the page.\n const { tools, hint, surface } = onPage(root, marks, color, false);\n const done = button('Done', 'Leave annotate mode (Esc)', close);\n done.classList.add('primary', 'end');\n tools.append(done);\n panel.append(style, tools, hint);\n return () => surface.remove();\n },\n});\n"],"mappings":";AASA,MAAM,MAAM;AAKZ,MAAa,SAAkB,SAAS,KAAK,SAAA,KAAgB;AAE7D,MAAM,UAAU,SAAiB,KAAK,WAAW,KAAK,OAAO,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,WAAW,MAAK,QAAQ;AACvI,MAAM,KAAK,UAAkB,KAAK,MAAM,QAAQ,EAAE,IAAI;;AAGtD,SAAS,MAAM,MAAa,IAAmB;CAC7C,MAAM,QAAQ,KAAK,MAAM,GAAG,IAAI,KAAK,GAAG,GAAG,IAAI,KAAK,CAAC;CACrD,MAAM,MAAM,MAAa,GAAG,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;CAC3C,MAAM,QAAQ,SAAiB,GAAG;EAAE,GAAG,GAAG,IAAI,KAAK,KAAK,IAAI,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,OAAO,SAAS,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,KAAK,MAAM,SAAS,OAAO;IAAE;IAAO;IAAS,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;GAAG,CAAC;GAC5H,UAAU,SAAS,UAAU,QAAQ,SAAS,OAAO,OAAO;GAC5D,aAAa;IAEX,MAAM,MAAM,YAAY,MAAM,OAAO,OAAO;IAC5C,MAAM,EAAE,OAAO,YAAY,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;IAC9D,MAAM,UAAU,SAAS,cAAc,KAAK;IAC5C,QAAQ,OAAO,OAAO,OAAO,SAAS,cAAc,OAAO,GAAG,EAAE,aAAa,YAAY,CAAC,GAAG,KAAK;IAClG,OAAO;KACL;KACA,OAAO,IAAI;KACX,aAAa;MACX,QAAQ,OAAO;MACf,IAAI,OAAO;KACb;IACF;GACF;EAEO;CACX;CAEA,QAAQ,OAAO,EAAE,MAAM,KAAK,OAAO,cAAc;EAC/C,MAAM,EAAE,UAAU;EAClB,MAAM,QAAQ,IAAI,aAAa;EAC/B,IAAI,UAAU,KAAA,GAAW;EACzB,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;EAEpB,MAAM,EAAE,OAAO,MAAM,YAAY,OAAO,MAAM,OAAO,OAAO,KAAK;EACjE,MAAM,OAAO,OAAO,QAAQ,6BAA6B,KAAK;EAC9D,KAAK,UAAU,IAAI,WAAW,KAAK;EACnC,MAAM,OAAO,IAAI;EACjB,MAAM,OAAO,OAAO,OAAO,IAAI;EAC/B,aAAa,QAAQ,OAAO;CAC9B;AACF,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * `deictic/annotations`: mark up the page itself. Its tab is annotate
3
+ * mode over the page: boxes, arrows, a pen and notes, drawn where the page is, so they stay with
4
+ * it as it scrolls. They're kept for the tab's session, per page, until cleared.
5
+ *
6
+ * They're data other plugins build on, through `use('annotations')` in the page: screenshots draw them
7
+ * over the page (`svg(area)`), tasks repeat their notes, and a recording can keep each change as it
8
+ * happens (`subscribe`). Nothing of it runs on the server.
9
+ */
10
+ import { C as Shortcut } from "../index.js";
11
+ /** A point in page coordinates: CSS pixels from the document's top left, so it stays put as the page scrolls. */
12
+ export interface Point {
13
+ x: number;
14
+ y: number;
15
+ }
16
+ /** A rectangle: in page coordinates for a shape, in viewport coordinates for an area to draw. */
17
+ export interface Area {
18
+ x: number;
19
+ y: number;
20
+ width: number;
21
+ height: number;
22
+ }
23
+ export type Shape = ({
24
+ kind: 'box';
25
+ } & Area) | {
26
+ kind: 'arrow';
27
+ from: Point;
28
+ to: Point;
29
+ } | {
30
+ kind: 'pen';
31
+ points: Point[];
32
+ } | {
33
+ kind: 'note';
34
+ at: Point;
35
+ text: string;
36
+ };
37
+ export interface Annotation {
38
+ id: string;
39
+ color: string;
40
+ shape: Shape;
41
+ /** When it was made, as `Date.now()`. */
42
+ at: number;
43
+ }
44
+ /** A change, as `subscribe` hears it: what a recording keeps, to show the marks as they were made. */
45
+ export type AnnotationEvent = {
46
+ type: 'add';
47
+ annotation: Annotation;
48
+ } | {
49
+ type: 'remove';
50
+ id: string;
51
+ } | {
52
+ type: 'clear';
53
+ };
54
+ /** The page's half, for other plugins' page halves. */
55
+ export interface Annotations {
56
+ /** Every annotation on this page, oldest first. */
57
+ list(): Annotation[];
58
+ add(shape: Shape, color?: string): Annotation;
59
+ remove(id: string): void;
60
+ clear(): void;
61
+ /** Hears every change from now on; answers what stops it. */
62
+ subscribe(listener: (event: AnnotationEvent) => void): () => void;
63
+ /**
64
+ * The annotations over a part of the viewport, in viewport CSS pixels, as an SVG that size: what a
65
+ * screenshot of that area draws over it. Nothing when there are none.
66
+ */
67
+ svg(area: Area): string | undefined;
68
+ /**
69
+ * Opens a picture (a screenshot, most often) over everything, with the toolbar, to draw on: answers the
70
+ * marks, in the picture's CSS pixels, on Save, and nothing on Cancel, Esc or `signal`. It starts from
71
+ * `marks`, to edit them again. They're the picture's alone, not the page's.
72
+ */
73
+ edit(picture: Picture, marks?: readonly Annotation[], options?: {
74
+ signal?: AbortSignal;
75
+ }): Promise<Annotation[] | undefined>;
76
+ /** The picture with the marks drawn over it, as a PNG at the picture's own resolution. */
77
+ flatten(picture: Picture, marks: readonly Annotation[]): Promise<Blob>;
78
+ /**
79
+ * Annotate mode's tools, for another plugin's UI to show (a recording's toolbar): a pointer tool, picked
80
+ * to start with, leaves the page usable; while a drawing tool is picked, the page is drawn on. What's
81
+ * drawn is its own `marks`, not the page's: shown while it's open, kept by nothing, gone on `close`.
82
+ */
83
+ tools(): {
84
+ element: HTMLElement;
85
+ marks: MarkSet;
86
+ close: () => void;
87
+ };
88
+ }
89
+ /** A set of marks on the page: the page's own, kept for the session, or a toolbar's, kept by nothing. */
90
+ export type MarkSet = Pick<Annotations, 'list' | 'add' | 'remove' | 'clear' | 'subscribe' | 'svg'>;
91
+ /** An image to draw on: where it loads from (the page's origin, so a canvas may read it), and its size in CSS pixels, which marks on it are in. */
92
+ export interface Picture {
93
+ url: string;
94
+ width: number;
95
+ height: number;
96
+ }
97
+ declare module 'deictic' {
98
+ interface ClientApis {
99
+ annotations: Annotations;
100
+ }
101
+ }
102
+ export interface AnnotationsOptions {
103
+ /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
104
+ shortcut?: Shortcut;
105
+ /** The colour marks are drawn in: a red that deictic's own green isn't. */
106
+ color?: string;
107
+ }
108
+ export declare function annotations(options?: AnnotationsOptions): import("deictic").ServerPlugin<unknown, unknown, unknown, unknown>;
109
+ export { annotations as default };
110
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/plugins/annotations/index.ts"],"mappings":";;;;;;;;;;;iBAYiB;EACf;EACA;;;iBAIe;EACf;EACA;EACA;EACA;;YAGU;EACL;IAAgB;EACjB;EAAe,MAAM;EAAO,IAAI;;EAChC;EAAa,QAAQ;;EACrB;EAAc,IAAI;EAAO;;iBAEd;EACf;EACA;EACA,OAAO;;EAEP;;;YAIU;EAAoB;EAAa,YAAY;;EAAiB;EAAgB;;EAAiB;;;iBAG1F;;EAEf,QAAQ;EACR,IAAI,OAAO,OAAO,iBAAiB;EACnC,OAAO;EACP;;EAEA,UAAU,WAAW,OAAO;;;;;EAK5B,IAAI,MAAM;;;;;;EAMV,KAAK,SAAS,SAAS,iBAAiB,cAAc;IAAY,SAAS;MAAgB,QAAQ;;EAEnG,QAAQ,SAAS,SAAS,gBAAgB,eAAe,QAAQ;;;;;;EAMjE;IAAW,SAAS;IAAa,OAAO;IAAS;;;;YAIvC,UAAU,KAAK;;iBAGV;EACf;EACA;EACA;;;YAIU;IACR,aAAa;;;iBAIA;;EAEf,WAAW;;EAEX;;wBAGc,YAAY,UAAS,uCAAuB"}
@@ -0,0 +1,22 @@
1
+ import { definePlugin } from "../index.js";
2
+ // src/plugins/annotations/index.ts
3
+ /**
4
+ * `deictic/annotations`: mark up the page itself. Its tab is annotate
5
+ * mode over the page: boxes, arrows, a pen and notes, drawn where the page is, so they stay with
6
+ * it as it scrolls. They're kept for the tab's session, per page, until cleared.
7
+ *
8
+ * They're data other plugins build on, through `use('annotations')` in the page: screenshots draw them
9
+ * over the page (`svg(area)`), tasks repeat their notes, and a recording can keep each change as it
10
+ * happens (`subscribe`). Nothing of it runs on the server.
11
+ */
12
+ function annotations(options = {}) {
13
+ return definePlugin({
14
+ name: "annotations",
15
+ client: "deictic/annotations/client",
16
+ shortcut: options.shortcut,
17
+ clientOptions: { color: options.color ?? "#ef4444" }
18
+ });
19
+ }
20
+ export { annotations, annotations as default };
21
+
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/plugins/annotations/index.ts"],"sourcesContent":["/**\n * `deictic/annotations`: mark up the page itself. Its tab is annotate\n * mode over the page: boxes, arrows, a pen and notes, drawn where the page is, so they stay with\n * it as it scrolls. They're kept for the tab's session, per page, until cleared.\n *\n * They're data other plugins build on, through `use('annotations')` in the page: screenshots draw them\n * over the page (`svg(area)`), tasks repeat their notes, and a recording can keep each change as it\n * happens (`subscribe`). Nothing of it runs on the server.\n */\nimport { definePlugin, type Shortcut } from '#src/index.ts';\n\n/** A point in page coordinates: CSS pixels from the document's top left, so it stays put as the page scrolls. */\nexport interface Point {\n x: number;\n y: number;\n}\n\n/** A rectangle: in page coordinates for a shape, in viewport coordinates for an area to draw. */\nexport interface Area {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport type Shape =\n | ({ kind: 'box' } & Area)\n | { kind: 'arrow'; from: Point; to: Point }\n | { kind: 'pen'; points: Point[] }\n | { kind: 'note'; at: Point; text: string };\n\nexport interface Annotation {\n id: string;\n color: string;\n shape: Shape;\n /** When it was made, as `Date.now()`. */\n at: number;\n}\n\n/** A change, as `subscribe` hears it: what a recording keeps, to show the marks as they were made. */\nexport type AnnotationEvent = { type: 'add'; annotation: Annotation } | { type: 'remove'; id: string } | { type: 'clear' };\n\n/** The page's half, for other plugins' page halves. */\nexport interface Annotations {\n /** Every annotation on this page, oldest first. */\n list(): Annotation[];\n add(shape: Shape, color?: string): Annotation;\n remove(id: string): void;\n clear(): void;\n /** Hears every change from now on; answers what stops it. */\n subscribe(listener: (event: AnnotationEvent) => void): () => void;\n /**\n * The annotations over a part of the viewport, in viewport CSS pixels, as an SVG that size: what a\n * screenshot of that area draws over it. Nothing when there are none.\n */\n svg(area: Area): string | undefined;\n /**\n * Opens a picture (a screenshot, most often) over everything, with the toolbar, to draw on: answers the\n * marks, in the picture's CSS pixels, on Save, and nothing on Cancel, Esc or `signal`. It starts from\n * `marks`, to edit them again. They're the picture's alone, not the page's.\n */\n edit(picture: Picture, marks?: readonly Annotation[], options?: { signal?: AbortSignal }): Promise<Annotation[] | undefined>;\n /** The picture with the marks drawn over it, as a PNG at the picture's own resolution. */\n flatten(picture: Picture, marks: readonly Annotation[]): Promise<Blob>;\n /**\n * Annotate mode's tools, for another plugin's UI to show (a recording's toolbar): a pointer tool, picked\n * to start with, leaves the page usable; while a drawing tool is picked, the page is drawn on. What's\n * drawn is its own `marks`, not the page's: shown while it's open, kept by nothing, gone on `close`.\n */\n tools(): { element: HTMLElement; marks: MarkSet; close: () => void };\n}\n\n/** A set of marks on the page: the page's own, kept for the session, or a toolbar's, kept by nothing. */\nexport type MarkSet = Pick<Annotations, 'list' | 'add' | 'remove' | 'clear' | 'subscribe' | 'svg'>;\n\n/** An image to draw on: where it loads from (the page's origin, so a canvas may read it), and its size in CSS pixels, which marks on it are in. */\nexport interface Picture {\n url: string;\n width: number;\n height: number;\n}\n\ndeclare module 'deictic' {\n interface ClientApis {\n annotations: Annotations;\n }\n}\n\nexport interface AnnotationsOptions {\n /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */\n shortcut?: Shortcut;\n /** The colour marks are drawn in: a red that deictic's own green isn't. */\n color?: string;\n}\n\nexport function annotations(options: AnnotationsOptions = {}) {\n return definePlugin({\n name: 'annotations',\n client: 'deictic/annotations/client',\n shortcut: options.shortcut,\n clientOptions: { color: options.color ?? '#ef4444' },\n });\n}\n\nexport default annotations;\n"],"mappings":";;;;;;;;;;;AA+FA,SAAgB,YAAY,UAA8B,CAAC,GAAG;CAC5D,OAAO,aAAa;EAClB,MAAM;EACN,QAAQ;EACR,UAAU,QAAQ;EAClB,eAAe,EAAE,OAAO,QAAQ,SAAS,UAAU;CACrD,CAAC;AACH"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * `deictic/astro`: the Vite plugin (`vite.ts`) in `astro dev`, and the overlay on every page.
3
+ *
4
+ * Astro renders a page on the server and may send it with no script at all, so nothing in the browser
5
+ * would import the client module, which under Vite comes with the first JSX module. The integration
6
+ * injects it into every page instead. JSX components (React's, Preact's, Solid's) are marked, on the
7
+ * server and in islands, and with Astro 7, whose parser says where their tags are, `.astro` components
8
+ * too (`tools/astro.ts`).
9
+ */
10
+ import { t as DeicticOptions } from "./integration.js";
11
+ import "./vite.js";
12
+ /** What the integration reads of Astro's setup hook: Astro's own types, as far as they're used here. */
13
+ interface Setup {
14
+ command: 'dev' | 'build' | 'preview' | 'sync';
15
+ updateConfig: (config: {
16
+ vite: {
17
+ plugins: unknown[];
18
+ };
19
+ }) => void;
20
+ injectScript: (stage: 'page', content: string) => void;
21
+ }
22
+ export declare function deictic(options?: DeicticOptions): {
23
+ name: string;
24
+ hooks: {
25
+ 'astro:config:setup': ({ command, updateConfig, injectScript }: Setup) => void;
26
+ };
27
+ };
28
+ export { type DeicticOptions as DeicticIntegrationOptions, deictic as default };
29
+ //# sourceMappingURL=astro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro.d.ts","names":[],"sources":["../src/astro.ts"],"mappings":";;;;;;;;;;;;UAcU;EACR;EACA,eAAe;IAAU;MAAQ;;;EACjC,eAAe,eAAe;;wBAGhB,QAAQ,UAAS;EAE7B;EACA;IACE,yBAAoB,SAAA,cAAA,gBAA4C"}
package/dist/astro.js ADDED
@@ -0,0 +1,24 @@
1
+ import deictic$1, { CLIENT } from "./vite.js";
2
+ // src/astro.ts
3
+ /**
4
+ * `deictic/astro`: the Vite plugin (`vite.ts`) in `astro dev`, and the overlay on every page.
5
+ *
6
+ * Astro renders a page on the server and may send it with no script at all, so nothing in the browser
7
+ * would import the client module, which under Vite comes with the first JSX module. The integration
8
+ * injects it into every page instead. JSX components (React's, Preact's, Solid's) are marked, on the
9
+ * server and in islands, and with Astro 7, whose parser says where their tags are, `.astro` components
10
+ * too (`tools/astro.ts`).
11
+ */
12
+ function deictic(options = {}) {
13
+ return {
14
+ name: "deictic",
15
+ hooks: { "astro:config:setup": ({ command, updateConfig, injectScript }) => {
16
+ if (command !== "dev") return;
17
+ updateConfig({ vite: { plugins: [deictic$1(options)] } });
18
+ injectScript("page", `import ${JSON.stringify(CLIENT)};`);
19
+ } }
20
+ };
21
+ }
22
+ export { deictic as default, deictic };
23
+
24
+ //# sourceMappingURL=astro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro.js","names":["vitePlugin"],"sources":["../src/astro.ts"],"sourcesContent":["/**\n * `deictic/astro`: the Vite plugin (`vite.ts`) in `astro dev`, and the overlay on every page.\n *\n * Astro renders a page on the server and may send it with no script at all, so nothing in the browser\n * would import the client module, which under Vite comes with the first JSX module. The integration\n * injects it into every page instead. JSX components (React's, Preact's, Solid's) are marked, on the\n * server and in islands, and with Astro 7, whose parser says where their tags are, `.astro` components\n * too (`tools/astro.ts`).\n */\nimport { CLIENT, deictic as vitePlugin, type DeicticOptions } from './vite.ts';\n\nexport type { DeicticOptions as DeicticIntegrationOptions };\n\n/** What the integration reads of Astro's setup hook: Astro's own types, as far as they're used here. */\ninterface Setup {\n command: 'dev' | 'build' | 'preview' | 'sync';\n updateConfig: (config: { vite: { plugins: unknown[] } }) => void;\n injectScript: (stage: 'page', content: string) => void;\n}\n\nexport function deictic(options: DeicticOptions = {}) {\n return {\n name: 'deictic',\n hooks: {\n 'astro:config:setup': ({ command, updateConfig, injectScript }: Setup) => {\n if (command !== 'dev') return;\n updateConfig({ vite: { plugins: [vitePlugin(options)] } });\n injectScript('page', `import ${JSON.stringify(CLIENT)};`);\n },\n },\n };\n}\n\nexport default deictic;\n"],"mappings":";;;;;;;;;;;AAoBA,SAAgB,QAAQ,UAA0B,CAAC,GAAG;CACpD,OAAO;EACL,MAAM;EACN,OAAO,EACL,uBAAuB,EAAE,SAAS,cAAc,mBAA0B;GACxE,IAAI,YAAY,OAAO;GACvB,aAAa,EAAE,MAAM,EAAE,SAAS,CAACA,UAAW,OAAO,CAAC,EAAE,EAAE,CAAC;GACzD,aAAa,QAAQ,UAAU,KAAK,UAAU,MAAM,EAAE,EAAE;EAC1D,EACF;CACF;AACF"}
package/dist/bun.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { BunPlugin } from "bun";
2
+ import { t as DeicticOptions } from "./integration.js";
3
+ export interface DeicticBunOptions extends DeicticOptions {
4
+ /** The project's root, which marks and edits are from: the working directory by default. */
5
+ root?: string;
6
+ }
7
+ export type DeicticBunPlugin = BunPlugin & {
8
+ /** The endpoints, as `Bun.serve` routes: `routes: { ...plugin.routes, '/*': index }`. */
9
+ routes: Record<string, (req: Request) => Promise<Response>>;
10
+ };
11
+ export declare function deictic(options?: DeicticBunOptions): DeicticBunPlugin;
12
+ //# sourceMappingURL=bun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.d.ts","names":[],"sources":["../src/bun.ts"],"mappings":";;iBA0BiB,0BAA0B;;EAEzC;;YAGU,mBAAmB;;EAE7B,QAAQ,gBAAgB,KAAK,YAAY,QAAQ;;wBAGnC,QAAQ,UAAS,oBAAyB"}
package/dist/bun.js ADDED
@@ -0,0 +1,67 @@
1
+ import { resolve } from "node:path";
2
+ import { t as endpoints } from "./endpoints.js";
3
+ import { d as JSX, i as mark, o as prepare, r as importOf, s as writeClient } from "./integration.js";
4
+ // src/bun.ts
5
+ /**
6
+ * `deictic/bun`: deictic in Bun's dev server, the bundler `Bun.serve` runs for HTML imports. Nothing
7
+ * runs in `Bun.build`.
8
+ *
9
+ * Named in bunfig.toml's `[serve.static] plugins`, it marks each JSX module as it loads, and in the
10
+ * browser appends the import of the client module, written to `.deictic/client.js`, as Bun has no
11
+ * virtual modules for it. A bundler plugin can't add routes to the server, so the endpoints are the
12
+ * plugin's `routes`, spread into `Bun.serve`'s; a place opens in the editor `Bun.openInEditor` finds.
13
+ *
14
+ * bunfig names a module whose default export is the plugin, so the plugin lives in a file of its own,
15
+ * which the server imports too, for its routes:
16
+ *
17
+ * // deictic.ts
18
+ * export default deictic({ plugins: [tailwind()] });
19
+ * // server.ts
20
+ * import tools from './deictic.ts';
21
+ * Bun.serve({ routes: { ...tools.routes, '/*': index }, development: true });
22
+ */
23
+ function deictic(options = {}) {
24
+ const { plugins, shortcut } = prepare(options);
25
+ const root = resolve(options.root ?? process.cwd());
26
+ let handle;
27
+ const route = async (req) => {
28
+ handle ??= endpoints({
29
+ root,
30
+ plugins,
31
+ open: (path, { line, column }) => {
32
+ try {
33
+ Bun.openInEditor(path, {
34
+ line,
35
+ column
36
+ });
37
+ return new Response(null, { status: 204 });
38
+ } catch (e) {
39
+ return new Response(`${e instanceof Error ? e.message : String(e)}: set VISUAL or EDITOR to the editor's command`, { status: 500 });
40
+ }
41
+ }
42
+ });
43
+ return await handle(req) ?? new Response(null, { status: 404 });
44
+ };
45
+ return {
46
+ name: "deictic",
47
+ routes: { "/__deictic/*": route },
48
+ setup(build) {
49
+ if ("entrypoints" in build.config) return;
50
+ const client = writeClient(root, plugins, "/", shortcut);
51
+ const forBrowser = (args) => !("side" in args) || args.side === "client";
52
+ build.onLoad({ filter: JSX }, async (args) => {
53
+ if (/[\\/]node_modules[\\/]/.test(args.path)) return void 0;
54
+ const code = await Bun.file(args.path).text();
55
+ const marked = mark(code, args.path, root, forBrowser(args) ? importOf(client, args.path) : "");
56
+ if (marked === void 0) return void 0;
57
+ return {
58
+ contents: marked.code,
59
+ loader: args.path.endsWith("tsx") ? "tsx" : "jsx"
60
+ };
61
+ });
62
+ }
63
+ };
64
+ }
65
+ export { deictic };
66
+
67
+ //# sourceMappingURL=bun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.js","names":[],"sources":["../src/bun.ts"],"sourcesContent":["/**\n * `deictic/bun`: deictic in Bun's dev server, the bundler `Bun.serve` runs for HTML imports. Nothing\n * runs in `Bun.build`.\n *\n * Named in bunfig.toml's `[serve.static] plugins`, it marks each JSX module as it loads, and in the\n * browser appends the import of the client module, written to `.deictic/client.js`, as Bun has no\n * virtual modules for it. A bundler plugin can't add routes to the server, so the endpoints are the\n * plugin's `routes`, spread into `Bun.serve`'s; a place opens in the editor `Bun.openInEditor` finds.\n *\n * bunfig names a module whose default export is the plugin, so the plugin lives in a file of its own,\n * which the server imports too, for its routes:\n *\n * // deictic.ts\n * export default deictic({ plugins: [tailwind()] });\n * // server.ts\n * import tools from './deictic.ts';\n * Bun.serve({ routes: { ...tools.routes, '/*': index }, development: true });\n */\nimport { resolve } from 'node:path';\n\nimport type { BunPlugin } from 'bun';\n\nimport { endpoints } from './tools/endpoints.ts';\nimport { type DeicticOptions, importOf, mark, prepare, writeClient } from './tools/integration.ts';\nimport { JSX } from './tools/locate.ts';\n\nexport interface DeicticBunOptions extends DeicticOptions {\n /** The project's root, which marks and edits are from: the working directory by default. */\n root?: string;\n}\n\nexport type DeicticBunPlugin = BunPlugin & {\n /** The endpoints, as `Bun.serve` routes: `routes: { ...plugin.routes, '/*': index }`. */\n routes: Record<string, (req: Request) => Promise<Response>>;\n};\n\nexport function deictic(options: DeicticBunOptions = {}): DeicticBunPlugin {\n // Now, so a wrong set of plugins stops the dev server as it starts, rather than the page.\n const { plugins, shortcut } = prepare(options);\n const root = resolve(options.root ?? process.cwd());\n let handle: ((req: Request) => Promise<Response | undefined>) | undefined;\n const route = async (req: Request) => {\n handle ??= endpoints({\n root,\n plugins,\n open: (path, { line, column }) => {\n try {\n Bun.openInEditor(path, { line, column });\n return new Response(null, { status: 204 });\n } catch (e) {\n return new Response(`${e instanceof Error ? e.message : String(e)}: set VISUAL or EDITOR to the editor's command`, {\n status: 500,\n });\n }\n },\n });\n return (await handle(req)) ?? new Response(null, { status: 404 });\n };\n\n return {\n name: 'deictic',\n routes: { '/__deictic/*': route },\n setup(build) {\n // A build names its entry points; the dev server's bundler doesn't.\n if ('entrypoints' in build.config) return;\n const client = writeClient(root, plugins, '/', shortcut);\n // Bun names the side it loads a module for (undocumented, and not in Bun's types); the dev server's is the browser's.\n const forBrowser = (args: object) => !('side' in args) || args.side === 'client';\n build.onLoad({ filter: JSX }, async (args) => {\n // A dependency's is left to Bun, unread.\n if (/[\\\\/]node_modules[\\\\/]/.test(args.path)) return undefined;\n const code = await Bun.file(args.path).text();\n const marked = mark(code, args.path, root, forBrowser(args) ? importOf(client, args.path) : '');\n if (marked === undefined) return undefined;\n return { contents: marked.code, loader: args.path.endsWith('tsx') ? 'tsx' : 'jsx' };\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;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AAM;GACpF,CAAC;EACH;CACF;AACF"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * `deictic/client`: the overlay the page loads in dev. Hold a shortcut's keys (Alt, deictic's own,
3
+ * by default) and point: the element under the pointer that the source marked (`tools/locate.ts`) is
4
+ * outlined, with its tag, its place and how many elements share it. Press the shortcut's button to open
5
+ * the popup there: a tab for each plugin with a panel, at the one used last, or at a plugin's own where
6
+ * its shortcut was pressed.
7
+ *
8
+ * Everything drawn sits in one shadow root, so neither the page's styles nor ours cross over. A
9
+ * panel's undo and redo are its tab's on its element: the latest change that plugin made there.
10
+ */
11
+ import { C as Shortcut, i as ClientPlugin, s as LightboxItem, v as Target } from "../index.js";
12
+ /**
13
+ * Waveforms: a clip's, read off its audio, drawn as bars with what's played in the accent; and a mic's live,
14
+ * a meter scrolling left as it hears. For the lightbox's player and whatever records the mic (the task
15
+ * panel's Voice, the recording toolbar's mic). Bars, not a line: they read at any size, and at a glance.
16
+ */
17
+ /**
18
+ * How loud each of `bars` stretches of the clip at `url` is, from 0 to 1, the loudest 1, and how long it is in
19
+ * seconds: MediaRecorder's webm doesn't say until it's played through.
20
+ */
21
+ export declare function peaksOf(url: string, bars: number): Promise<{
22
+ peaks: number[];
23
+ duration: number;
24
+ }>;
25
+ interface Colors {
26
+ /** What's played. */
27
+ played: string;
28
+ /** What isn't, yet. */
29
+ rest: string;
30
+ }
31
+ /** Draws `peaks` as bars across `canvas`, centred on its middle, the share `progress` (0–1) of them played. */
32
+ export declare function drawBars(canvas: HTMLCanvasElement, peaks: readonly number[], progress: number, colors: Colors): void;
33
+ /**
34
+ * The mic's level, live, as bars scrolling in from the right, drawn on `canvas` until the answer's called.
35
+ * It listens to `stream` on its own; the recording goes on as it was.
36
+ */
37
+ export declare function liveWaveform(canvas: HTMLCanvasElement, stream: MediaStream, colors: Colors): () => void;
38
+ export interface StartOptions {
39
+ /** The dev server's base URL, ending in `/`. */
40
+ base: string;
41
+ /** deictic's own shortcut, checked: it opens the popup at the tab used last. None where it's turned off. */
42
+ shortcut?: Required<Shortcut>;
43
+ /** Each plugin with a half in the page, and its own shortcut as the bundler's plugin checked it, where it has one. */
44
+ plugins: {
45
+ plugin: ClientPlugin;
46
+ shortcut?: Required<Shortcut>;
47
+ options?: unknown;
48
+ }[];
49
+ }
50
+ export declare function targetOf(el: Element): Target | undefined;
51
+ /**
52
+ * What the page hears on `window` as the popup opens over it on an element (its `detail` a `PopupOpened`) and as
53
+ * it closes: for a page that moves on its own to hold still meanwhile, as deictic's site does. Not for one pinned.
54
+ */
55
+ export declare const POPUP_OPENED = "deictic:open";
56
+ export declare const POPUP_CLOSED = "deictic:close";
57
+ export interface PopupOpened {
58
+ /** The element it's open on. */
59
+ element: Element;
60
+ /** The plugin whose tab it opened at. */
61
+ tab: string;
62
+ }
63
+ /**
64
+ * Opens the popup over the page on `element`, as deictic's own shortcut does: at `tab` (a plugin's name), or at the
65
+ * tab used last. For a page that opens it from a gesture of its own, as deictic's site does on a plain click.
66
+ * Answers whether it opened: not where no plugin has a tab, or `element` has no mark. The overlay must have started.
67
+ */
68
+ export declare function openPopup(element: Element, { tab }?: {
69
+ tab?: string;
70
+ }): boolean;
71
+ /**
72
+ * Shows the popup in `container`, open at a tab (`tab`, a plugin's name, or the first) on `element`, where
73
+ * the page puts it rather than over the page: a page of the popup's states, to point at and fix, as deictic's
74
+ * own site does. It's the real popup, its tabs and plugins working. Closing it, or a tab's `away`, opens it
75
+ * again in place. It draws in `container`'s shadow root, made if there isn't one. Answers what removes it.
76
+ * The overlay must have started (the dev server's client module starts it), and `element` be marked.
77
+ */
78
+ export declare function popupIn(container: Element, { tab: name, element }: {
79
+ tab?: string;
80
+ element: Element;
81
+ }): () => void;
82
+ /**
83
+ * Shows the lightbox in `container`, at `at`, where the page puts it rather than over everything: as `popupIn`
84
+ * does the popup, for a page of deictic's own states. Its items step with its arrows; there's no backdrop, close
85
+ * or keys, and an item's actions run without closing it. Answers what removes it.
86
+ */
87
+ export declare function lightboxIn(container: Element, items: LightboxItem[], { at }?: {
88
+ at?: number;
89
+ }): () => void;
90
+ /** Starts the overlay, once per page: the client module runs again when a module importing it is replaced. */
91
+ export declare function start({ base, shortcut: own, plugins: given }: StartOptions): void;
92
+ export type { Colors };
93
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/client/waveform.ts","../../src/client/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;wBAUsB,QAAQ,aAAa,eAAe;EAAU;EAAiB;;UAsBpE;;EAEf;;EAEA;;;wBAIc,SAAS,QAAQ,mBAAmB,0BAA0B,kBAAkB,QAAQ;;;;;wBAoBxF,aAAa,QAAQ,mBAAmB,QAAQ,aAAa,QAAQ;iBCxCpE;;EAEf;;EAEA,WAAW,SAAS;;EAEpB;IAAW,QAAQ;IAAc,WAAW,SAAS;IAAW;;;wBAwBlD,SAAS,IAAI,UAAU;;;;;qBA0C1B;qBACA;iBAEI;;EAEf,SAAS;;EAET;;;;;;;wBAQc,UAAU,SAAS,WAAW;EAAS;;;;;;;;;wBAYvC,QAAQ,WAAW,WAAW,KAAK,MAAM;EAAa;EAAc,SAAS;;;;;;;wBAiD7E,WAAW,WAAW,SAAS,OAAO,kBAAkB;EAAQ;;;wBAchE,QAAQ,MAAM,UAAU,KAAK,SAAS,SAAS"}