deictic 0.8.1 → 0.10.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 (128) hide show
  1. package/API.md +81 -17
  2. package/README.md +1 -1
  3. package/dist/annotations/client.js +1 -1
  4. package/dist/bun.d.ts.map +1 -1
  5. package/dist/bun.js +26 -8
  6. package/dist/bun.js.map +1 -1
  7. package/dist/cli.js +1 -1
  8. package/dist/cli.js.map +1 -1
  9. package/dist/client/index.d.ts +13 -13
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +19 -7
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/next.d.ts.map +1 -1
  14. package/dist/next.js +45 -25
  15. package/dist/next.js.map +1 -1
  16. package/dist/react/client.d.ts +19 -0
  17. package/dist/react/client.d.ts.map +1 -0
  18. package/dist/react/client.js +504 -0
  19. package/dist/react/client.js.map +1 -0
  20. package/dist/react/index.d.ts +2 -0
  21. package/dist/react/index.js +1 -0
  22. package/dist/recommended/index.d.ts +15 -7
  23. package/dist/recommended/index.d.ts.map +1 -1
  24. package/dist/recommended/index.js +1 -1
  25. package/dist/recordings/client.d.ts.map +1 -1
  26. package/dist/recordings/client.js +48 -5
  27. package/dist/recordings/client.js.map +1 -1
  28. package/dist/screenshots/client.d.ts +9 -1
  29. package/dist/screenshots/client.d.ts.map +1 -1
  30. package/dist/screenshots/rrweb.d.ts +0 -6
  31. package/dist/screenshots/rrweb.d.ts.map +1 -1
  32. package/dist/screenshots/rrweb.js +46 -12
  33. package/dist/screenshots/rrweb.js.map +1 -1
  34. package/dist/shared/board.js +1 -1
  35. package/dist/shared/client.js +44 -2
  36. package/dist/shared/client.js.map +1 -1
  37. package/dist/shared/dom.js +7 -1
  38. package/dist/shared/dom.js.map +1 -1
  39. package/dist/shared/drawer.js +1 -1
  40. package/dist/shared/endpoints.js +15 -4
  41. package/dist/shared/endpoints.js.map +1 -1
  42. package/dist/shared/index.d.ts +11 -0
  43. package/dist/shared/index.d.ts.map +1 -1
  44. package/dist/shared/index10.d.ts +70 -0
  45. package/dist/shared/index10.d.ts.map +1 -0
  46. package/dist/shared/index3.d.ts +11 -0
  47. package/dist/shared/index3.d.ts.map +1 -1
  48. package/dist/shared/index7.d.ts +92 -312
  49. package/dist/shared/index7.d.ts.map +1 -1
  50. package/dist/shared/index8.d.ts +324 -47
  51. package/dist/shared/index8.d.ts.map +1 -1
  52. package/dist/shared/index9.d.ts +45 -63
  53. package/dist/shared/index9.d.ts.map +1 -1
  54. package/dist/shared/init.js +15 -11
  55. package/dist/shared/init.js.map +1 -1
  56. package/dist/shared/integration.d.ts +6 -0
  57. package/dist/shared/integration.d.ts.map +1 -1
  58. package/dist/shared/integration.js +28 -1
  59. package/dist/shared/integration.js.map +1 -1
  60. package/dist/shared/marks.js +7 -1
  61. package/dist/shared/marks.js.map +1 -1
  62. package/dist/shared/package.js +3 -1
  63. package/dist/shared/packages.js +1 -1
  64. package/dist/shared/playwright.js +39 -1
  65. package/dist/shared/playwright.js.map +1 -1
  66. package/dist/shared/react.js +25 -0
  67. package/dist/shared/react.js.map +1 -0
  68. package/dist/shared/recommended.js +6 -3
  69. package/dist/shared/recommended.js.map +1 -1
  70. package/dist/shared/recording.js +80 -3
  71. package/dist/shared/recording.js.map +1 -1
  72. package/dist/shared/recordings.js +30 -2
  73. package/dist/shared/recordings.js.map +1 -1
  74. package/dist/shared/screenshots.js.map +1 -1
  75. package/dist/shared/src.js.map +1 -1
  76. package/dist/shared/task.js +1 -0
  77. package/dist/shared/task.js.map +1 -1
  78. package/dist/shared/tasks.js +11 -0
  79. package/dist/shared/tasks.js.map +1 -1
  80. package/dist/shared/vite.d.ts +1 -1
  81. package/dist/shared/vite.d.ts.map +1 -1
  82. package/dist/shared/vite.js +28 -10
  83. package/dist/shared/vite.js.map +1 -1
  84. package/dist/tailwind/client.d.ts +1 -1
  85. package/dist/tailwind/index.d.ts +1 -1
  86. package/dist/tasks/client.d.ts +1 -1
  87. package/dist/tasks/client.js +45 -19
  88. package/dist/tasks/client.js.map +1 -1
  89. package/dist/tasks/index.d.ts +1 -1
  90. package/dist/voice/client.d.ts +1 -1
  91. package/dist/voice/client.js +1 -1
  92. package/dist/voice/index.d.ts +1 -1
  93. package/dist/webpack.d.ts +4 -0
  94. package/dist/webpack.d.ts.map +1 -1
  95. package/dist/webpack.js +37 -15
  96. package/dist/webpack.js.map +1 -1
  97. package/package.json +25 -1
  98. package/src/bun.ts +32 -8
  99. package/src/cli/bun.ts +2 -2
  100. package/src/cli/init.ts +14 -9
  101. package/src/cli/recording.ts +90 -4
  102. package/src/cli/task.ts +4 -0
  103. package/src/cli.ts +13 -6
  104. package/src/client/dom.ts +14 -0
  105. package/src/client/index.ts +25 -14
  106. package/src/index.ts +11 -0
  107. package/src/next.ts +34 -15
  108. package/src/plugins/react/client.ts +162 -0
  109. package/src/plugins/react/index.ts +130 -0
  110. package/src/plugins/react/renders.ts +219 -0
  111. package/src/plugins/react/serialize.ts +139 -0
  112. package/src/plugins/react/timeline.ts +143 -0
  113. package/src/plugins/recommended/index.ts +17 -5
  114. package/src/plugins/recordings/client.ts +64 -4
  115. package/src/plugins/recordings/marks.ts +7 -0
  116. package/src/plugins/recordings/replay.ts +30 -2
  117. package/src/plugins/screenshots/client.ts +42 -2
  118. package/src/plugins/screenshots/index.ts +11 -0
  119. package/src/plugins/screenshots/playwright.ts +65 -1
  120. package/src/plugins/screenshots/rrweb.ts +55 -28
  121. package/src/plugins/screenshots/states.ts +26 -0
  122. package/src/plugins/tasks/client.ts +41 -6
  123. package/src/plugins/tasks/composer.ts +24 -7
  124. package/src/plugins/tasks/index.ts +16 -2
  125. package/src/tools/integration.ts +33 -0
  126. package/src/tools/source.ts +14 -2
  127. package/src/vite.ts +31 -10
  128. package/src/webpack.ts +48 -16
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/screenshots/client.ts"],"sourcesContent":["/**\n * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,\n * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the\n * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.\n *\n * Its tool in the tool panel takes the window as it is, with what's drawn on the page, and puts the shot in the\n * tray, for the next task.\n */\nimport { toolButton } from '#src/client/dom.ts';\nimport { trayed } from '#src/client/drawer.ts';\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { Annotations } from '#src/plugins/annotations/index.ts';\n\nimport type { Box, Capture, CaptureOptions, ResolvedMasking, Shot } from './index.ts';\n\n/**\n * What a renderer's page half makes of the element: a body for `add`, its type, and where the element is\n * in the shot. `overlay(area)` is what's drawn over the page in that part of the viewport, in viewport CSS\n * pixels, as an SVG that size, or nothing: the annotations plugin's marks, where it's loaded. The renderer\n * draws it over the shot, as deictic's own layers are left out.\n */\nexport type PageCapture = (\n element: Element,\n options: {\n area: NonNullable<CaptureOptions['area']>;\n masking: ResolvedMasking;\n renderer: unknown;\n overlay: (area: Box) => string | undefined;\n },\n) => Promise<{ body: Blob | string; type: string; box: Box }>;\n\n/** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */\nexport const notOurs = (node: Node) => !(node instanceof Element && node.localName === 'deictic-overlay');\n\n/** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */\nexport function boxOf(element: Element, area: NonNullable<CaptureOptions['area']>): Box {\n const { x, y, width, height } = element.getBoundingClientRect();\n return area === 'element' ? { x: 0, y: 0, width, height } : { x, y, width, height };\n}\n\nconst BLANK = '#d4d4d8';\n/** A camera, on a 24-pixel grid. */\nconst CAMERA = '<path d=\"M4 8h3l2-3h6l2 3h3v11H4z\"/><circle cx=\"12\" cy=\"13\" r=\"3.5\"/>';\n\nconst selector = (className: string, extra: string | undefined) => [`.${CSS.escape(className)}`, ...(extra ? [extra] : [])].join(', ');\n\n/**\n * Hides in a copy of the page's what rrweb would: blocked elements become a blank box their size (the copy keeps each\n * element's size as its styles), masked text keeps its spaces but shows `*`, and so do passwords' values,\n * or every field's.\n */\nexport function mask(copy: Node, m: ResolvedMasking): void {\n if (!(copy instanceof Element)) return;\n const all = (sel: string) => [...(copy.matches(sel) ? [copy] : []), ...copy.querySelectorAll(sel)];\n const stars = (text: string) => text.replace(/\\S/g, '*');\n for (const el of all(selector(m.blockClass, m.blockSelector))) {\n el.replaceChildren();\n if (el instanceof HTMLElement || el instanceof SVGElement) el.style.background = BLANK;\n }\n for (const el of all(selector(m.maskTextClass, m.maskTextSelector))) {\n const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);\n for (let text = walker.nextNode(); text !== null; text = walker.nextNode()) text.textContent = stars(text.textContent ?? '');\n }\n for (const field of all('input, textarea')) {\n if (!(field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement)) continue;\n if (!m.maskAllInputs && !(field instanceof HTMLInputElement && field.type === 'password')) continue;\n field.value = stars(field.value);\n field.setAttribute('value', field.value);\n if (field instanceof HTMLTextAreaElement) field.textContent = field.value;\n }\n}\n\nexport function screenshotsClient(capture: PageCapture) {\n return defineClientPlugin<never, never, Capture>({\n name: 'screenshots',\n setup: ({ base, request, options, use, tools, tray, drawer, lightbox }) => {\n const { masking, renderer } = options as { masking: ResolvedMasking; renderer: unknown };\n // Asked at each shot: the annotations plugin may be set up after this one.\n const overlay = (area: Box) => {\n const marks: Annotations | undefined = use('annotations');\n return marks?.svg(area);\n };\n const add = async (body: Blob | string, type: string, { box, size }: Pick<Shot, 'box' | 'size'>): Promise<Shot> => {\n const res = await request('add', { method: 'POST', headers: { 'content-type': type }, body });\n // `url`: where the shot is, said by what keeps it with no server to serve it from (a `standalone` build).\n // `box`: where the element is in a shot drawn again elsewhere, which is what's true of the PNG.\n const { id, url, problem, box: drawn } = (await res.json()) as { id?: string; url?: string; problem?: string; box?: Box };\n if (id === undefined) throw new Error(`screenshots: ${problem ?? res.statusText}`);\n return { id, url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`, box: drawn ?? box, size };\n };\n const api: Capture = {\n capture: async (element, { area = 'viewport' } = {}) => {\n const { body, type, box } = await capture(element, { area, masking, renderer, overlay });\n const { clientWidth, clientHeight } = document.documentElement;\n const size = area === 'element' ? { width: box.width, height: box.height } : { width: clientWidth, height: clientHeight };\n return add(body, type, { box, size });\n },\n upload: (png, of) => add(png, 'image/png', of),\n masked: (element) => {\n const copy = element.cloneNode(true) as Element;\n mask(copy, masking);\n return copy;\n },\n };\n\n const group = Object.assign(document.createElement('div'), { className: 'tool-group' });\n const shoot = toolButton(CAMERA, 'Screenshot', 'S', () => {\n shoot.disabled = true;\n shoot.classList.remove('problem');\n // The panel stays while the shot is made: it's in none, as nothing of deictic's is.\n const done = tools.keep();\n api\n .capture(document.documentElement)\n .then(\n (shot) => {\n tray.add('screenshots', shot.id, shot);\n shoot.title = 'Screenshot';\n },\n (e: unknown) => {\n // Said where it was asked for: its tooltip, which a missing renderer's fix fits in.\n shoot.classList.add('problem');\n shoot.title = e instanceof Error ? e.message : String(e);\n },\n )\n .finally(() => {\n shoot.disabled = false;\n done();\n });\n });\n group.append(shoot);\n // Beside the other tools that capture the page: a shot, a recording, the mic.\n tools.add(group, { section: 'capture' });\n // In the drawer until a task takes them: each opens among the others.\n drawer.add(\n trayed({ tray }, 'screenshots', 'Screenshots', (item, i, all) => {\n const name = (n: number) => (all.length === 1 ? 'Screenshot' : `Screenshot ${n + 1}`);\n const thumb = Object.assign(document.createElement('img'), { src: (item.value as Shot).url, alt: '' });\n return {\n label: [thumb, name(i)],\n open: (from) =>\n lightbox(\n all.map((each, n) => ({ kind: 'image' as const, url: (each.value as Shot).url, title: name(n) })),\n { at: i, from },\n ),\n };\n }),\n );\n return api;\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAgCA,MAAa,WAAW,SAAe,EAAE,gBAAgB,WAAW,KAAK,cAAc;;AAGvF,SAAgB,MAAM,SAAkB,MAAgD;CACtF,MAAM,EAAE,GAAG,GAAG,OAAO,WAAW,QAAQ,sBAAsB;CAC9D,OAAO,SAAS,YAA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Q,WAAW,QAAQ,cAAc,WAAW;IACxD,MAAM,WAAW;IACjB,MAAM,UAAU,OAAO,SAAS;IAEhC,MAAM,OAAO,MAAM,KAAK;IACxB,IACG,QAAQ,SAAS,eAAe,CAAC,CACjC,MACE,SAAS;KACR,KAAK,IAAI,eAAe,KAAK,IAAI,IAAI;KACrC,MAAM,QAAQ;IAChB,IACC,MAAe;KAEd,MAAM,UAAU,IAAI,SAAS;KAC7B,MAAM,QAAQ,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;IACzD,CACF,CAAC,CACA,cAAc;KACb,MAAM,WAAW;KACjB,KAAK;IACP,CAAC;GACL,CAAC;GACD,MAAM,OAAO,KAAK;GAElB,MAAM,IAAI,OAAO,EAAE,SAAS,UAAU,CAAC;GAEvC,OAAO,IACL,OAAO,EAAE,KAAK,GAAG,eAAe,gBAAgB,MAAM,GAAG,QAAQ;IAC/D,MAAM,QAAQ,MAAe,IAAI,WAAW,IAAI,eAAe,cAAc,IAAI;IAEjF,OAAO;KACL,OAAO,CAFK,OAAO,OAAO,SAAS,cAAc,KAAK,GAAG;MAAE,KAAM,KAAK,MAAe;MAAK,KAAK;KAAG,CAEtF,GAAG,KAAK,CAAC,CAAC;KACtB,OAAO,SACL,SACE,IAAI,KAAK,MAAM,OAAO;MAAE,MAAM;MAAkB,KAAM,KAAK,MAAe;MAAK,OAAO,KAAK,CAAC;KAAE,EAAE,GAChG;MAAE,IAAI;MAAG;KAAK,CAChB;IACJ;GACF,CAAC,CACH;GACA,OAAO;EACT;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/screenshots/client.ts"],"sourcesContent":["/**\n * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,\n * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the\n * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.\n *\n * Its tool in the tool panel takes the window as it is, with what's drawn on the page, and puts the shot in the\n * tray, for the next task.\n */\nimport { POPUP_CLOSED, POPUP_OPENED, type PopupOpened, toolButton } from '#src/client/dom.ts';\nimport { trayed } from '#src/client/drawer.ts';\nimport { defineClientPlugin } from '#src/index.ts';\nimport type { Annotations } from '#src/plugins/annotations/index.ts';\n\nimport type { Box, Capture, CaptureOptions, ResolvedMasking, Shot } from './index.ts';\n\n/**\n * What a renderer's page half makes of the element: a body for `add`, its type, and where the element is\n * in the shot. `overlay(area)` is what's drawn over the page in that part of the viewport, in viewport CSS\n * pixels, as an SVG that size, or nothing: the annotations plugin's marks, where it's loaded. The renderer\n * draws it over the shot, as deictic's own layers are left out.\n */\nexport type PageCapture = (\n element: Element,\n options: {\n area: NonNullable<CaptureOptions['area']>;\n masking: ResolvedMasking;\n renderer: unknown;\n overlay: (area: Box) => string | undefined;\n },\n) => Promise<{ body: Blob | string; type: string; box: Box }>;\n\n/**\n * What a renderer that can take the page at once makes of it, synchronously: as `PageCapture` answers, or nothing\n * where it isn't ready (what it imports hasn't loaded). `prepare` loads it, once the page has started.\n */\nexport interface PageFreeze {\n freeze: (element: Element, options: Parameters<PageCapture>[1]) => Awaited<ReturnType<PageCapture>> | undefined;\n prepare: () => void;\n}\n\n/** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */\nexport const notOurs = (node: Node) => !(node instanceof Element && node.localName === 'deictic-overlay');\n\n/** The element's box, in CSS pixels from the viewport's top left, or from its own for a shot of it alone. */\nexport function boxOf(element: Element, area: NonNullable<CaptureOptions['area']>): Box {\n const { x, y, width, height } = element.getBoundingClientRect();\n return area === 'element' ? { x: 0, y: 0, width, height } : { x, y, width, height };\n}\n\nconst BLANK = '#d4d4d8';\n/** How long after its press a popup may first ask for the shot it froze, in milliseconds: later, it's another's. */\nconst ASKED = 60_000;\n/** A camera, on a 24-pixel grid. */\nconst CAMERA = '<path d=\"M4 8h3l2-3h6l2 3h3v11H4z\"/><circle cx=\"12\" cy=\"13\" r=\"3.5\"/>';\n\nconst selector = (className: string, extra: string | undefined) => [`.${CSS.escape(className)}`, ...(extra ? [extra] : [])].join(', ');\n\n/**\n * Hides in a copy of the page's what rrweb would: blocked elements become a blank box their size (the copy keeps each\n * element's size as its styles), masked text keeps its spaces but shows `*`, and so do passwords' values,\n * or every field's.\n */\nexport function mask(copy: Node, m: ResolvedMasking): void {\n if (!(copy instanceof Element)) return;\n const all = (sel: string) => [...(copy.matches(sel) ? [copy] : []), ...copy.querySelectorAll(sel)];\n const stars = (text: string) => text.replace(/\\S/g, '*');\n for (const el of all(selector(m.blockClass, m.blockSelector))) {\n el.replaceChildren();\n if (el instanceof HTMLElement || el instanceof SVGElement) el.style.background = BLANK;\n }\n for (const el of all(selector(m.maskTextClass, m.maskTextSelector))) {\n const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);\n for (let text = walker.nextNode(); text !== null; text = walker.nextNode()) text.textContent = stars(text.textContent ?? '');\n }\n for (const field of all('input, textarea')) {\n if (!(field instanceof HTMLInputElement || field instanceof HTMLTextAreaElement)) continue;\n if (!m.maskAllInputs && !(field instanceof HTMLInputElement && field.type === 'password')) continue;\n field.value = stars(field.value);\n field.setAttribute('value', field.value);\n if (field instanceof HTMLTextAreaElement) field.textContent = field.value;\n }\n}\n\nexport function screenshotsClient(capture: PageCapture, freezer?: PageFreeze) {\n return defineClientPlugin<never, never, Capture>({\n name: 'screenshots',\n ...(freezer === undefined ? {} : { pressed: ({ use }, element) => use('screenshots')?.freeze(element) }),\n setup: ({ base, request, options, use, tools, tray, drawer, lightbox }) => {\n const { masking, renderer } = options as { masking: ResolvedMasking; renderer: unknown };\n // Ready for a press, which can't wait for an import: once the page has started, while the browser is idle.\n if (freezer !== undefined) {\n if (typeof requestIdleCallback === 'function') requestIdleCallback(freezer.prepare, { timeout: 5000 });\n else setTimeout(freezer.prepare, 1000);\n }\n // Asked at each shot: the annotations plugin may be set up after this one.\n const overlay = (area: Box) => {\n const marks: Annotations | undefined = use('annotations');\n return marks?.svg(area);\n };\n const add = async (body: Blob | string, type: string, { box, size }: Pick<Shot, 'box' | 'size'>): Promise<Shot> => {\n const res = await request('add', { method: 'POST', headers: { 'content-type': type }, body });\n // `url`: where the shot is, said by what keeps it with no server to serve it from (a `standalone` build).\n // `box`: where the element is in a shot drawn again elsewhere, which is what's true of the PNG.\n const { id, url, problem, box: drawn } = (await res.json()) as { id?: string; url?: string; problem?: string; box?: Box };\n if (id === undefined) throw new Error(`screenshots: ${problem ?? res.statusText}`);\n return { id, url: url ?? `${base}__deictic/plugins/screenshots/shot/${id}`, box: drawn ?? box, size };\n };\n // The last press's page, and its shot once it's asked for: the popup that press opened has it while it's open,\n // whichever of its tabs asks. Not a popup opened on another element, nor one long after the press.\n let last:\n { element: Element; at: number; made: Awaited<ReturnType<PageCapture>>; size: Shot['size']; shot?: Promise<Shot> } | undefined;\n window.addEventListener(POPUP_CLOSED, () => (last = undefined));\n window.addEventListener(POPUP_OPENED, (e) => {\n if (last !== undefined && (e as CustomEvent<PopupOpened>).detail.element !== last.element) last = undefined;\n });\n const api: Capture = {\n freeze: (element) => {\n const { clientWidth: width, clientHeight: height } = document.documentElement;\n const made = freezer?.freeze(element, { area: 'viewport', masking, renderer, overlay });\n last = made === undefined ? undefined : { element, at: performance.now(), made, size: { width, height } };\n },\n frozen: (element) => {\n if (last?.element !== element || (last.shot === undefined && performance.now() - last.at > ASKED)) return undefined;\n const { made, size } = last;\n if (last.shot === undefined) {\n last.shot = add(made.body, made.type, { box: made.box, size });\n // Asked for while the popup opens, and maybe never used: a failure is said where it's awaited.\n last.shot.catch(() => {});\n }\n return last.shot;\n },\n capture: async (element, { area = 'viewport' } = {}) => {\n const { body, type, box } = await capture(element, { area, masking, renderer, overlay });\n const { clientWidth, clientHeight } = document.documentElement;\n const size = area === 'element' ? { width: box.width, height: box.height } : { width: clientWidth, height: clientHeight };\n return add(body, type, { box, size });\n },\n upload: (png, of) => add(png, 'image/png', of),\n masked: (element) => {\n const copy = element.cloneNode(true) as Element;\n mask(copy, masking);\n return copy;\n },\n };\n\n const group = Object.assign(document.createElement('div'), { className: 'tool-group' });\n const shoot = toolButton(CAMERA, 'Screenshot', 'S', () => {\n shoot.disabled = true;\n shoot.classList.remove('problem');\n // The panel stays while the shot is made: it's in none, as nothing of deictic's is.\n const done = tools.keep();\n api\n .capture(document.documentElement)\n .then(\n (shot) => {\n tray.add('screenshots', shot.id, shot);\n shoot.title = 'Screenshot';\n },\n (e: unknown) => {\n // Said where it was asked for: its tooltip, which a missing renderer's fix fits in.\n shoot.classList.add('problem');\n shoot.title = e instanceof Error ? e.message : String(e);\n },\n )\n .finally(() => {\n shoot.disabled = false;\n done();\n });\n });\n group.append(shoot);\n // Beside the other tools that capture the page: a shot, a recording, the mic.\n tools.add(group, { section: 'capture' });\n // In the drawer until a task takes them: each opens among the others.\n drawer.add(\n trayed({ tray }, 'screenshots', 'Screenshots', (item, i, all) => {\n const name = (n: number) => (all.length === 1 ? 'Screenshot' : `Screenshot ${n + 1}`);\n const thumb = Object.assign(document.createElement('img'), { src: (item.value as Shot).url, alt: '' });\n return {\n label: [thumb, name(i)],\n open: (from) =>\n lightbox(\n all.map((each, n) => ({ kind: 'image' as const, url: (each.value as Shot).url, title: name(n) })),\n { at: i, from },\n ),\n };\n }),\n );\n return api;\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;AAyCA,MAAa,WAAW,SAAe,EAAE,gBAAgB,WAAW,KAAK,cAAc;;AAGvF,SAAgB,MAAM,SAAkB,MAAgD;CACtF,MAAM,EAAE,GAAG,GAAG,OAAO,WAAW,QAAQ,sBAAsB;CAC9D,OAAO,SAAS,YAAY;EAAE,GAAG;EAAG,GAAG;EAAG;EAAO;CAAO,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO;AACpF;AAEA,MAAM,QAAQ;;AAEd,MAAM,QAAQ;;AAEd,MAAM,SAAS;AAEf,MAAM,YAAY,WAAmB,UAA8B,CAAC,IAAI,IAAI,OAAO,SAAS,KAAK,GAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAE,CAAC,CAAC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K;GAElB,MAAM,IAAI,OAAO,EAAE,SAAS,UAAU,CAAC;GAEvC,OAAO,IACL,OAAO,EAAE,KAAK,GAAG,eAAe,gBAAgB,MAAM,GAAG,QAAQ;IAC/D,MAAM,QAAQ,MAAe,IAAI,WAAW,IAAI,eAAe,cAAc,IAAI;IAEjF,OAAO;KACL,OAAO,CAFK,OAAO,OAAO,SAAS,cAAc,KAAK,GAAG;MAAE,KAAM,KAAK,MAAe;MAAK,KAAK;KAAG,CAEtF,GAAG,KAAK,CAAC,CAAC;KACtB,OAAO,SACL,SACE,IAAI,KAAK,MAAM,OAAO;MAAE,MAAM;MAAkB,KAAM,KAAK,MAAe;MAAK,OAAO,KAAK,CAAC;KAAE,EAAE,GAChG;MAAE,IAAI;MAAG;KAAK,CAChB;IACJ;GACF,CAAC,CACH;GACA,OAAO;EACT;CACF,CAAC;AACH"}
@@ -74,6 +74,12 @@ function controlFor(within, e, loose = false) {
74
74
  }
75
75
  /** The key held with a letter for a command, as the platform has it, by the name `aria-keyshortcuts` gives it. */
76
76
  const MOD = typeof navigator !== "undefined" && /Mac|iP(?:hone|ad)/.test(navigator.platform) ? "Meta" : "Control";
77
- export { nameOf as a, sameAs as c, div as i, targetOf as l, MOD as n, place as o, controlFor as r, reduced as s, ATTRIBUTE as t, toolButton as u };
77
+ /**
78
+ * What the page hears on `window` as the popup opens over it on an element (its `detail` a `PopupOpened`) and as
79
+ * it closes: for a page that moves on its own to hold still meanwhile, as deictic's site does. Not for one pinned.
80
+ */
81
+ const POPUP_OPENED = "deictic:open";
82
+ const POPUP_CLOSED = "deictic:close";
83
+ export { controlFor as a, place as c, targetOf as d, toolButton as f, POPUP_OPENED as i, reduced as l, MOD as n, div as o, POPUP_CLOSED as r, nameOf as s, ATTRIBUTE as t, sameAs as u };
78
84
 
79
85
  //# sourceMappingURL=dom.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom.js","names":[],"sources":["../../src/client/dom.ts"],"sourcesContent":["/** The little the overlay's parts all draw with. */\nimport type { Target } from '#src/index.ts';\n\n/** The attribute the transform marks an element with: `file:line:column`. */\nexport const ATTRIBUTE = 'data-deictic';\n\n/** An element's place in the source, as its mark has it, or nothing for one with none. */\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\n/** Every element on the page from the same place in the source as `el`. */\nexport const sameAs = (el: Element) => [...document.querySelectorAll(`[${ATTRIBUTE}=\"${CSS.escape(el.getAttribute(ATTRIBUTE) ?? '')}\"]`)];\n\nexport function div(className: string): HTMLDivElement {\n const el = document.createElement('div');\n el.className = className;\n return el;\n}\n\n/** Puts a fixed box over `r`. */\nexport function 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/** `button.tab`: the element as a selector, its own classes only, for a person to tell it by. */\nexport const nameOf = (el: Element) => `${el.localName}${[...el.classList].map((c) => `.${c}`).join('')}`;\n\nexport const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/**\n * A button for the tool panel: an icon (its strokes, on a 24-pixel grid), named by its tooltip and for a screen\n * reader, with the keys that press it (`B`, `Control+Z`), which the tooltip shows and the panel hears.\n */\nexport function toolButton(strokes: string, name: string, keys: string | undefined, run: () => void): HTMLButtonElement {\n const el = Object.assign(document.createElement('button'), { type: 'button', className: 'icon', title: 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\">${strokes}</svg>`;\n el.setAttribute('aria-label', name);\n if (keys !== undefined) el.setAttribute('aria-keyshortcuts', keys);\n el.addEventListener('click', run);\n return el;\n}\n\n/**\n * The control in `within` that a key is for, by its `aria-keyshortcuts`: a key alone, or with the keys it names.\n * `loose` takes a key alone whatever is held with it, for while a shortcut's keys are held to point.\n */\nexport function controlFor(within: ParentNode, e: KeyboardEvent, loose = false): HTMLElement | undefined {\n // By the letter typed, and by where the key is where it types no Latin letter (another layout, or Alt held).\n const key = /^[a-z]$/i.test(e.key) ? e.key.toUpperCase() : e.code.startsWith('Key') ? e.code.slice(3) : e.key;\n const held = [e.ctrlKey && 'Control', e.metaKey && 'Meta', e.shiftKey && 'Shift'].filter((m) => m !== false);\n for (const el of within.querySelectorAll<HTMLElement>('[aria-keyshortcuts]')) {\n if (el instanceof HTMLButtonElement && el.disabled) continue;\n // One that isn't shown now: a recording's Stop while none is going.\n if (el.offsetParent === null) continue;\n for (const keys of (el.getAttribute('aria-keyshortcuts') ?? '').split(' ')) {\n const named = keys.split('+');\n if (named.at(-1) !== key) continue;\n const mods = named.slice(0, -1);\n if (mods.length === 0 ? loose || held.length === 0 : mods.length === held.length && mods.every((m) => held.includes(m))) return el;\n }\n }\n return undefined;\n}\n\n/** The key held with a letter for a command, as the platform has it, by the name `aria-keyshortcuts` gives it. */\nexport const MOD = typeof navigator !== 'undefined' && /Mac|iP(?:hone|ad)/.test(navigator.platform) ? 'Meta' : 'Control';\n"],"mappings":";;AAIA,MAAa,YAAY;;AAGzB,SAAgB,SAAS,IAAiC;CACxD,MAAM,KAAK,GAAG,aAAa,SAAS;CACpC,MAAM,QAAQ,OAAO,OAAO,OAAO,qBAAqB,KAAK,EAAE;CAC/D,IAAI,UAAU,MAAM,OAAO,KAAA;CAC3B,OAAO;EAAE,KAAK;GAAE,MAAM,MAAM;GAAK,MAAM,OAAO,MAAM,EAAE;GAAG,QAAQ,OAAO,MAAM,EAAE;EAAE;EAAG,KAAK,GAAG;CAAU;AACzG;;AAGA,MAAa,UAAU,OAAgB,CAAC,GAAG,SAAS,iBAAiB,IAAI,UAAU,IAAI,IAAI,OAAO,GAAG,aAAA,cAAsB,KAAK,EAAE,EAAE,GAAG,CAA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,iBAAiB,MAAM;EAC9B,KAAK,MAAM,SAAS,GAAG,aAAa,mBAAmB,KAAK,GAAA,CAAI,MAAM,GAAG,GAAG;GAC1E,MAAM,QAAQ,KAAK,MAAM,GAAG;GAC5B,IAAI,MAAM,GAAG,EAAE,MAAM,KAAK;GAC1B,MAAM,OAAO,MAAM,MAAM,GAAG,EAAE;GAC9B,IAAI,KAAK,WAAW,IAAI,SAAS,KAAK,WAAW,IAAI,KAAK,WAAW,KAAK,UAAU,KAAK,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,GAAG,OAAO;EAClI;CACF;AAEF;;AAGA,MAAa,MAAM,OAAO,cAAc,eAAe,oBAAoB,KAAK,UAAU,QAAQ,IAAI,SAAS"}
1
+ {"version":3,"file":"dom.js","names":[],"sources":["../../src/client/dom.ts"],"sourcesContent":["/** The little the overlay's parts all draw with. */\nimport type { Target } from '#src/index.ts';\n\n/** The attribute the transform marks an element with: `file:line:column`. */\nexport const ATTRIBUTE = 'data-deictic';\n\n/** An element's place in the source, as its mark has it, or nothing for one with none. */\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\n/** Every element on the page from the same place in the source as `el`. */\nexport const sameAs = (el: Element) => [...document.querySelectorAll(`[${ATTRIBUTE}=\"${CSS.escape(el.getAttribute(ATTRIBUTE) ?? '')}\"]`)];\n\nexport function div(className: string): HTMLDivElement {\n const el = document.createElement('div');\n el.className = className;\n return el;\n}\n\n/** Puts a fixed box over `r`. */\nexport function 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/** `button.tab`: the element as a selector, its own classes only, for a person to tell it by. */\nexport const nameOf = (el: Element) => `${el.localName}${[...el.classList].map((c) => `.${c}`).join('')}`;\n\nexport const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;\n\n/**\n * A button for the tool panel: an icon (its strokes, on a 24-pixel grid), named by its tooltip and for a screen\n * reader, with the keys that press it (`B`, `Control+Z`), which the tooltip shows and the panel hears.\n */\nexport function toolButton(strokes: string, name: string, keys: string | undefined, run: () => void): HTMLButtonElement {\n const el = Object.assign(document.createElement('button'), { type: 'button', className: 'icon', title: 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\">${strokes}</svg>`;\n el.setAttribute('aria-label', name);\n if (keys !== undefined) el.setAttribute('aria-keyshortcuts', keys);\n el.addEventListener('click', run);\n return el;\n}\n\n/**\n * The control in `within` that a key is for, by its `aria-keyshortcuts`: a key alone, or with the keys it names.\n * `loose` takes a key alone whatever is held with it, for while a shortcut's keys are held to point.\n */\nexport function controlFor(within: ParentNode, e: KeyboardEvent, loose = false): HTMLElement | undefined {\n // By the letter typed, and by where the key is where it types no Latin letter (another layout, or Alt held).\n const key = /^[a-z]$/i.test(e.key) ? e.key.toUpperCase() : e.code.startsWith('Key') ? e.code.slice(3) : e.key;\n const held = [e.ctrlKey && 'Control', e.metaKey && 'Meta', e.shiftKey && 'Shift'].filter((m) => m !== false);\n for (const el of within.querySelectorAll<HTMLElement>('[aria-keyshortcuts]')) {\n if (el instanceof HTMLButtonElement && el.disabled) continue;\n // One that isn't shown now: a recording's Stop while none is going.\n if (el.offsetParent === null) continue;\n for (const keys of (el.getAttribute('aria-keyshortcuts') ?? '').split(' ')) {\n const named = keys.split('+');\n if (named.at(-1) !== key) continue;\n const mods = named.slice(0, -1);\n if (mods.length === 0 ? loose || held.length === 0 : mods.length === held.length && mods.every((m) => held.includes(m))) return el;\n }\n }\n return undefined;\n}\n\n/** The key held with a letter for a command, as the platform has it, by the name `aria-keyshortcuts` gives it. */\nexport const MOD = typeof navigator !== 'undefined' && /Mac|iP(?:hone|ad)/.test(navigator.platform) ? 'Meta' : 'Control';\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"],"mappings":";;AAIA,MAAa,YAAY;;AAGzB,SAAgB,SAAS,IAAiC;CACxD,MAAM,KAAK,GAAG,aAAa,SAAS;CACpC,MAAM,QAAQ,OAAO,OAAO,OAAO,qBAAqB,KAAK,EAAE;CAC/D,IAAI,UAAU,MAAM,OAAO,KAAA;CAC3B,OAAO;EAAE,KAAK;GAAE,MAAM,MAAM;GAAK,MAAM,OAAO,MAAM,EAAE;GAAG,QAAQ,OAAO,MAAM,EAAE;EAAE;EAAG,KAAK,GAAG;CAAU;AACzG;;AAGA,MAAa,UAAU,OAAgB,CAAC,GAAG,SAAS,iBAAiB,IAAI,UAAU,IAAI,IAAI,OAAO,GAAG,aAAA,cAAsB,KAAK,EAAE,EAAE,GAAG,CAAC;AAExI,SAAgB,IAAI,WAAmC;CACrD,MAAM,KAAK,SAAS,cAAc,KAAK;CACvC,GAAG,YAAY;CACf,OAAO;AACT;;AAGA,SAAgB,MAAM,IAAiB,GAAkB;CACvD,OAAO,OAAO,GAAG,OAAO;EAAE,MAAM,GAAG,EAAE,KAAK;EAAK,KAAK,GAAG,EAAE,IAAI;EAAK,OAAO,GAAG,EAAE,MAAM;EAAK,QAAQ,GAAG,EAAE,OAAO;CAAI,CAAC;AACpH;;AAGA,MAAa,UAAU,OAAgB,GAAG,GAAG,YAAY,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC,KAAK,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE;AAEtG,MAAa,gBAAgB,WAAW,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G,MAAa,eAAe;AAC5B,MAAa,eAAe"}
@@ -1,4 +1,4 @@
1
- import { i as div } from "./dom.js";
1
+ import { o as div } from "./dom.js";
2
2
  // src/client/drawer.ts
3
3
  /** How long the drawer outlasts the keys, in milliseconds: time to get the pointer to it. */
4
4
  const LINGER = 600;
@@ -2,8 +2,8 @@ import { t as Refusal } from "./src.js";
2
2
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
4
4
  import { t as keptIn } from "./kept.js";
5
- import { _ as lineStarts, b as parse, c as setUp, d as reporter, f as stackOf, g as isHost, l as messageOf, m as parseAstro, p as ASTRO, u as problemIn, v as offsetOf, y as openingsIn } from "./integration.js";
6
- import { r as missingProblem } from "./packages.js";
5
+ import { _ as isHost, b as openingsIn, d as problemIn, f as reporter, h as parseAstro, l as setUp, m as ASTRO, p as stackOf, u as messageOf, v as lineStarts, x as parse, y as offsetOf } from "./integration.js";
6
+ import { i as missingProblem } from "./packages.js";
7
7
  // src/tools/source.ts
8
8
  /**
9
9
  * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute
@@ -66,13 +66,16 @@ function astro(root, file, code) {
66
66
  if ("problem" in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);
67
67
  return parsed;
68
68
  }
69
- /** Each file's text after its edits, which must not overlap. */
69
+ /**
70
+ * Each file's text after its edits, which must not overlap. A file that isn't there is made where every edit to it is
71
+ * at its start (a locale's first translation, say); any other edit to one is refused.
72
+ */
70
73
  function applyEdits(source, edits) {
71
74
  const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);
72
75
  const out = /* @__PURE__ */ new Map();
73
76
  for (const [file, list] of byFile) {
74
77
  const sorted = list.toSorted((a, b) => b.start - a.start);
75
- let code = file === source.file ? source.code : source.read(file);
78
+ let code = file === source.file ? source.code : textOf(source, file, list);
76
79
  let floor = 1e400;
77
80
  for (const edit of sorted) {
78
81
  if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);
@@ -83,6 +86,14 @@ function applyEdits(source, edits) {
83
86
  }
84
87
  return out;
85
88
  }
89
+ function textOf(source, file, edits) {
90
+ try {
91
+ return source.read(file);
92
+ } catch (e) {
93
+ if (e instanceof Refusal && e.cause !== void 0 && edits.every((edit) => edit.start === 0 && edit.end === 0)) return "";
94
+ throw e;
95
+ }
96
+ }
86
97
  // src/tools/history.ts
87
98
  /**
88
99
  * Every change deictic made, to undo and redo. A change to files holds each file's whole text
@@ -1 +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/**\n * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the\n * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.\n */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const lines = lineStarts(code);\n const offset = offsetOf(lines, line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);\n const start = lines[line - 1];\n const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));\n const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);\n if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\n/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */\nfunction notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {\n const start = lines[line - 1];\n const found =\n start === undefined\n ? `${file} has no line ${line}`\n : onLine === 0\n ? `line ${line} of ${file} has no <${tag}>: it reads \\`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\\``\n : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;\n return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;\n}\n\nconst clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);\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 * `problem` is the page's way to report one (`Problem`): it and the server's own, and any request that fails with\n * something other than a `Refusal`, are said once and handed to the plugins that hear of them (`problems.ts`).\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 Source, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingProblem } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { messageOf, problemIn, reporter, stackOf } from './problems.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 // What goes wrong that nothing in the page caused: said, and handed to the plugins that hear of it once set up.\n const report = reporter(plugins, () => ready);\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins, report);\n const gone = missingProblem(root, plugins);\n if (gone !== undefined) report(gone);\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 = sourceOf(target);\n const before = await readOf(plugin, target, source);\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 if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };\n // Edits to a file whose element isn't found would go who knows where: refused, as only they need it.\n if (source instanceof Refusal) throw source;\n const change = history.commit(label, applyEdits(source, result), 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 // The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.\n const sourceOf = (target: Target): Source | Refusal => {\n try {\n return sourceAt(root, target);\n } catch (e) {\n if (e instanceof Refusal) return e;\n throw e;\n }\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, source?: Source | Refusal) =>\n plugin.read === undefined ? null : plugin.read(source ?? sourceOf(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 // What failed, for a problem's key: a plugin's route by its first segment, not the IDs after it.\n let where = route;\n let plugin: string | undefined;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n where = `plugins/${name}/${first}`;\n plugin = name;\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 && route !== 'problem') 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 if (handler === undefined) {\n const problem = problemIn(await req.json());\n if (problem === undefined) return Response.json({ problem: 'a problem has a key, a kind and a message' }, { status: 400 });\n report(problem);\n return Response.json({});\n }\n const body = (await req.json()) as Body;\n plugin = body.plugin;\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 // Not a refusal, which says what to do instead: something broke, which no one in the page can fix.\n const message = messageOf(e);\n report({\n key: `error:${where}:${message.split('\\n', 1)[0]!.slice(0, 200)}`,\n kind: 'bug',\n ...(plugin === undefined ? {} : { plugin }),\n message: `${prefix}${where} failed: ${message}`,\n ...stackOf(e),\n });\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;;;;;AAMA,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,EAAE,MAAM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MAAM,QAAQ,KAAK,IAAI,QAAQ,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,OAAO,MAAM,CAAC;EAE3G,MAAM,SAAmB,CAAC;EAC1B,IAAI,GAAG,SAAS,UAAkB,OAAO,KAAK,KAAK,CAAC;EACpD,IAAI,GAAG,aAAa;GAClB,MAAM,OAAO,IAAI,WAAW,SAAS,IAAI,WAAW,SAAS,KAAA,IAAY,OAAO,OAAO,MAAM;GAC7F,OAAO,IAAI,QAAQ,UAAU,OAAO,IAAI,OAAO;IAAE,QAAQ,IAAI;IAAQ;IAAS;GAAK,CAAC,CAAC,CAAC,CACnF,KAAK,OAAO,aAAa;IACxB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAK;IACxC,IAAI,aAAa,SAAS;IAC1B,SAAS,QAAQ,SAAS,OAAO,SAAS,IAAI,UAAU,MAAM,KAAK,CAAC;IACpE,IAAI,IAAI,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC,CAAC;GACnD,CAAC,CAAC,CACD,OAAO,MAAe;IACrB,IAAI,aAAa;IACjB,IAAI,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
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/**\n * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the\n * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.\n */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const lines = lineStarts(code);\n const offset = offsetOf(lines, line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);\n const start = lines[line - 1];\n const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));\n const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);\n if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\n/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */\nfunction notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {\n const start = lines[line - 1];\n const found =\n start === undefined\n ? `${file} has no line ${line}`\n : onLine === 0\n ? `line ${line} of ${file} has no <${tag}>: it reads \\`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\\``\n : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;\n return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;\n}\n\nconst clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);\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/**\n * Each file's text after its edits, which must not overlap. A file that isn't there is made where every edit to it is\n * at its start (a locale's first translation, say); any other edit to one is refused.\n */\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 : textOf(source, file, list);\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\nfunction textOf(source: Source, file: string, edits: TextEdit[]): string {\n try {\n return source.read(file);\n } catch (e) {\n if (e instanceof Refusal && e.cause !== undefined && edits.every((edit) => edit.start === 0 && edit.end === 0)) return '';\n throw e;\n }\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 * `problem` is the page's way to report one (`Problem`): it and the server's own, and any request that fails with\n * something other than a `Refusal`, are said once and handed to the plugins that hear of them (`problems.ts`).\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 Source, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingProblem } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { messageOf, problemIn, reporter, stackOf } from './problems.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 // What goes wrong that nothing in the page caused: said, and handed to the plugins that hear of it once set up.\n const report = reporter(plugins, () => ready);\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins, report);\n const gone = missingProblem(root, plugins);\n if (gone !== undefined) report(gone);\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 = sourceOf(target);\n const before = await readOf(plugin, target, source);\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 if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };\n // Edits to a file whose element isn't found would go who knows where: refused, as only they need it.\n if (source instanceof Refusal) throw source;\n const change = history.commit(label, applyEdits(source, result), 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 // The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.\n const sourceOf = (target: Target): Source | Refusal => {\n try {\n return sourceAt(root, target);\n } catch (e) {\n if (e instanceof Refusal) return e;\n throw e;\n }\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, source?: Source | Refusal) =>\n plugin.read === undefined ? null : plugin.read(source ?? sourceOf(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 // What failed, for a problem's key: a plugin's route by its first segment, not the IDs after it.\n let where = route;\n let plugin: string | undefined;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n where = `plugins/${name}/${first}`;\n plugin = name;\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 && route !== 'problem') 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 if (handler === undefined) {\n const problem = problemIn(await req.json());\n if (problem === undefined) return Response.json({ problem: 'a problem has a key, a kind and a message' }, { status: 400 });\n report(problem);\n return Response.json({});\n }\n const body = (await req.json()) as Body;\n plugin = body.plugin;\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 // Not a refusal, which says what to do instead: something broke, which no one in the page can fix.\n const message = messageOf(e);\n report({\n key: `error:${where}:${message.split('\\n', 1)[0]!.slice(0, 200)}`,\n kind: 'bug',\n ...(plugin === undefined ? {} : { plugin }),\n message: `${prefix}${where} failed: ${message}`,\n ...stackOf(e),\n });\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) => {\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AO;IAAE,QAAQ,IAAI;IAAQ;IAAS;GAAK,CAAC,CAAC,CAAC,CACnF,KAAK,OAAO,aAAa;IACxB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAK;IACxC,IAAI,aAAa,SAAS;IAC1B,SAAS,QAAQ,SAAS,OAAO,SAAS,IAAI,UAAU,MAAM,KAAK,CAAC;IACpE,IAAI,IAAI,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC,CAAC;GACnD,CAAC,CAAC,CACD,OAAO,MAAe;IACrB,IAAI,aAAa;IACjB,IAAI,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
@@ -256,6 +256,11 @@ interface ClientContext {
256
256
  request: (route: string, init?: RequestInit) => Promise<Response>;
257
257
  /** Says a problem of the plugin's own to the dev server, as the server half's `report` does: its `plugin` is this one. */
258
258
  report: (problem: Problem) => void;
259
+ /**
260
+ * Opens a place in a file under the root in the editor, as the popup's own link opens the element's: through the
261
+ * dev server, or what answers in its place (`Standalone`). Rejects with why it couldn't.
262
+ */
263
+ edit: (place: Loc) => Promise<void>;
259
264
  /**
260
265
  * Opens the popup on an element at a plugin's tab, as its shortcut would, or with `at` on a spot in it: the
261
266
  * popup is then beside the spot, which is what's lit, and the tab's context has it. An element rendered again
@@ -380,6 +385,12 @@ interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
380
385
  * plugin pins each task where its element is. Answers what takes it away.
381
386
  */
382
387
  pointing?(context: ClientContext): () => void;
388
+ /**
389
+ * A shortcut's press on a marked element, before the page hears it and before the popup opens: the page as the
390
+ * person saw it, a tooltip still open under the pointer, a menu still focused. Called as the press goes down, so
391
+ * it must be quick; the screenshots plugin keeps what a shot needs here, and renders it later.
392
+ */
393
+ pressed?(context: ClientContext, element: Element): void;
383
394
  /** Draws into `panel`, inside deictic's shadow root. Returns what to undo on the page when the panel closes. */
384
395
  mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (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,gBAAgB;;;;;EAKjC,UAAU,SAAS;;;;;;EAMnB,SAAS,SAAS,eAAe,SAAS;;EAE1C,SAAS,OAAO,aAAa,SAAS,aAAa,OAAO;;cAG/C,qBAAsB,OAAO,IAAI,eAAa,QAAU,aAAa,OAAO,IAAI,SAAO,aAAa,OAAO,IAAI"}
@@ -0,0 +1,70 @@
1
+ import { j as Shortcut } from "./index.js";
2
+ /** A class as the panel shows it. */
3
+ interface ClassInfo {
4
+ name: string;
5
+ /** Whether Tailwind makes anything of it: a class of the project's own isn't known. */
6
+ known: boolean;
7
+ /** The colour it sets, as CSS. */
8
+ color?: string;
9
+ /** What it sets its main property to, theme values resolved: `0.875rem`. */
10
+ value?: string;
11
+ /** A variant to go on typing after (`hover:`), not a class. */
12
+ variant?: true;
13
+ }
14
+ /** The classes of one kind, and how to write one with a value of the user's own. */
15
+ interface Alternatives {
16
+ /** The property the kind sets: `font-size`. */
17
+ label: string;
18
+ /** Whether the kind is a colour's, shown as swatches. */
19
+ colors: boolean;
20
+ items: ClassInfo[];
21
+ /** A custom value goes between these: `md:text-[` and `]`. None for a kind that takes no value (`flex`). */
22
+ custom?: {
23
+ before: string;
24
+ after: string;
25
+ value?: string;
26
+ };
27
+ }
28
+ interface TailwindOptions {
29
+ /** Calls whose first argument is a class list: `cn`, `clsx`, `cx`, `twMerge`, `classNames` by default. */
30
+ helpers?: string[];
31
+ /** The attribute an element without one gets: `className`, or `class` for Solid and Preact. */
32
+ attribute?: 'className' | 'class';
33
+ /**
34
+ * The stylesheet that imports Tailwind and holds the theme, from the project's root: `src/index.css`. What
35
+ * the panel completes and shows comes from it. Tailwind's default theme without one.
36
+ */
37
+ css?: string;
38
+ /** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
39
+ shortcut?: Shortcut;
40
+ }
41
+ type Model = {
42
+ editable: true;
43
+ classes: string;
44
+ /** The helper's other arguments, which add classes at runtime, each read as far as the source says. */
45
+ others?: Extra[];
46
+ } | {
47
+ editable: false;
48
+ source: string;
49
+ };
50
+ /** Classes a helper's argument adds: `active && 'ring'` is `ring` when `active`. */
51
+ interface Extra {
52
+ /** The argument, or the part of it these classes come from, as written. */
53
+ source: string;
54
+ /** The classes, where the source spells them out: there, or in a `const` of the file it names. */
55
+ classes?: string;
56
+ /** What must hold for them to be added, as written: `active === 'h3'`. None where they always are. */
57
+ when?: string;
58
+ /** Set where the classes are a string in this file, which an op with `at` can write. */
59
+ editable?: true;
60
+ /** The `const` the string is in, where it isn't the argument itself: other elements may use it too. */
61
+ shared?: string;
62
+ }
63
+ interface Op {
64
+ classes: string;
65
+ /** Which of the model's `others` the classes are for, by its place there. The element's own list without. */
66
+ at?: number;
67
+ }
68
+ declare function tailwind(options?: TailwindOptions): import("deictic").ServerPlugin<Model, Op, unknown, unknown>;
69
+ export { tailwind as a, TailwindOptions as i, Model as n, Alternatives as o, Op as r, ClassInfo as s, Extra as t };
70
+ //# sourceMappingURL=index10.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index10.d.ts","names":[],"sources":["../../src/plugins/tailwind/catalog.ts","../../src/plugins/tailwind/index.ts"],"mappings":";;UAeiB;EACf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;EACA,OAAO;;EAEP;IAAW;IAAgB;IAAe;;;UCf3B;;EAEf;;EAEA;;;;;EAKA;;EAEA,WAAW;;KAGD;EAEN;EACA;;EAEA,SAAS;;EAET;EAAiB;;;UAGN;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;UAGe;EACf;;EAEA;;iBASc,SAAS,UAAS,oCAAoB,aAAA,OAAA"}
@@ -28,6 +28,17 @@ interface Capture {
28
28
  upload(png: Blob, of: Pick<Shot, 'box' | 'size'>): Promise<Shot>;
29
29
  /** A copy of an element with what a shot hides hidden in it too: for a plugin that sends its HTML somewhere. */
30
30
  masked(element: Element): Element;
31
+ /**
32
+ * Keeps what a shot of the page now needs, to render later: the overlay calls it (through the plugin's
33
+ * `pressed`) as a shortcut's press goes down, so a tooltip, a hover's styles or a focused menu are still there.
34
+ * Only a renderer that can take the page at once does (`rrweb()`, once it has loaded); the last press's is kept.
35
+ */
36
+ freeze(element: Element): void;
37
+ /**
38
+ * The shot of the page as the last press on `element` froze it, rendered on the first ask, or nothing where the
39
+ * last press was on another element or nothing was frozen: then `capture` takes the page as it is now.
40
+ */
41
+ frozen(element: Element): Promise<Shot> | undefined;
31
42
  }
32
43
  /** The server's half, for other plugins' server halves. */
33
44
  interface Screenshots {
@@ -1 +1 @@
1
- {"version":3,"file":"index3.d.ts","names":[],"sources":["../../src/plugins/screenshots/index.ts"],"mappings":";UAqBiB;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;;EAEA,KAAK;;EAEL;IAAQ;IAAe;;;UAGR;;EAEf;;;UAIe;EACf,QAAQ,SAAS,SAAS,UAAU,iBAAiB,QAAQ;;EAE7D,OAAO,KAAK,MAAM,IAAI,KAAK,wBAAwB,QAAQ;;EAE3D,OAAO,SAAS,UAAU;;;UAIX;;EAEf,KAAK;IAAe,MAAM,WAAW;IAAc;IAAc;;;;YAIvD;IACR,aAAa;;YAEL;IACR,aAAa;;;;;;;UAQA;;EAEf;EACA;;EAEA;EACA;;EAEA;;;KAIU,kBAAkB,SAAS,KAAK,8DAA8D;;;;;;UAOzF;EACf;;EAEA;;EAEA;;EAEA,QAAQ,iBAAiB,QAAQ;IAAe,KAAK;IAAY,MAAM;;;;UAIxD;;EAEf;;EAEA;;;cAIW,WAAU;;;;;cAMV,QAAK,UAAa,mBAAsB;UAOpC,2BAA2B;;EAE1C,WAAW;;EAEX;;EAEA;;iBAOc,YAAY,UAAS,uCAAuB,kCAAA"}
1
+ {"version":3,"file":"index3.d.ts","names":[],"sources":["../../src/plugins/screenshots/index.ts"],"mappings":";UAqBiB;EACf;EACA;EACA;EACA;;;UAIe;EACf;EACA;;EAEA,KAAK;;EAEL;IAAQ;IAAe;;;UAGR;;EAEf;;;UAIe;EACf,QAAQ,SAAS,SAAS,UAAU,i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