deictic 0.6.0 → 0.7.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 (90) hide show
  1. package/API.md +136 -30
  2. package/README.md +4 -3
  3. package/dist/annotations/client.d.ts +1 -1
  4. package/dist/annotations/client.d.ts.map +1 -1
  5. package/dist/annotations/client.js +161 -176
  6. package/dist/annotations/client.js.map +1 -1
  7. package/dist/annotations/index.d.ts +2 -11
  8. package/dist/client/index.d.ts +7 -6
  9. package/dist/client/index.d.ts.map +1 -1
  10. package/dist/client/index.js +1007 -192
  11. package/dist/client/index.js.map +1 -1
  12. package/dist/index.d.ts +2 -2
  13. package/dist/recommended/index.d.ts +2 -2
  14. package/dist/recordings/client.d.ts.map +1 -1
  15. package/dist/recordings/client.js +82 -153
  16. package/dist/recordings/client.js.map +1 -1
  17. package/dist/screenshots/client.d.ts.map +1 -1
  18. package/dist/shared/annotations.js +3 -4
  19. package/dist/shared/annotations.js.map +1 -1
  20. package/dist/shared/board.js +1 -1
  21. package/dist/shared/client.js +45 -2
  22. package/dist/shared/client.js.map +1 -1
  23. package/dist/shared/component.js +62 -0
  24. package/dist/shared/component.js.map +1 -0
  25. package/dist/shared/dom.js +79 -0
  26. package/dist/shared/dom.js.map +1 -0
  27. package/dist/shared/drawer.js +217 -0
  28. package/dist/shared/drawer.js.map +1 -0
  29. package/dist/shared/index.d.ts +116 -7
  30. package/dist/shared/index.d.ts.map +1 -1
  31. package/dist/shared/index2.d.ts +9 -19
  32. package/dist/shared/index2.d.ts.map +1 -1
  33. package/dist/shared/index7.d.ts +103 -26
  34. package/dist/shared/index7.d.ts.map +1 -1
  35. package/dist/shared/index9.d.ts +1 -1
  36. package/dist/shared/integration.d.ts +1 -1
  37. package/dist/shared/packages.js +1 -1
  38. package/dist/shared/recording.js +31 -3
  39. package/dist/shared/recording.js.map +1 -1
  40. package/dist/shared/src.js.map +1 -1
  41. package/dist/shared/task.js +44 -29
  42. package/dist/shared/task.js.map +1 -1
  43. package/dist/shared/tasks.js +232 -62
  44. package/dist/shared/tasks.js.map +1 -1
  45. package/dist/shared/vb.js +1 -1
  46. package/dist/shared/voice2.js +6 -4
  47. package/dist/shared/voice2.js.map +1 -1
  48. package/dist/shared/watch.js +14 -14
  49. package/dist/shared/watch.js.map +1 -1
  50. package/dist/tasks/client.d.ts +2 -2
  51. package/dist/tasks/client.d.ts.map +1 -1
  52. package/dist/tasks/client.js +1829 -741
  53. package/dist/tasks/client.js.map +1 -1
  54. package/dist/tasks/index.d.ts +2 -2
  55. package/dist/voice/client.d.ts.map +1 -1
  56. package/dist/voice/client.js +154 -57
  57. package/dist/voice/client.js.map +1 -1
  58. package/package.json +1 -1
  59. package/skills/deictic/SKILL.md +22 -28
  60. package/src/cli/recording.ts +34 -3
  61. package/src/cli/task.ts +59 -30
  62. package/src/cli/voice.ts +9 -4
  63. package/src/cli/watch.ts +14 -13
  64. package/src/client/away.ts +3 -1
  65. package/src/client/component.ts +98 -0
  66. package/src/client/dom.ts +70 -0
  67. package/src/client/drawer.ts +258 -0
  68. package/src/client/index.ts +220 -128
  69. package/src/client/lightbox.ts +8 -8
  70. package/src/client/lighting.ts +279 -0
  71. package/src/client/style.ts +263 -44
  72. package/src/client/tools.ts +279 -0
  73. package/src/client/tooltip.ts +25 -5
  74. package/src/client/tray.ts +48 -0
  75. package/src/index.ts +113 -6
  76. package/src/plugins/annotations/client.ts +103 -129
  77. package/src/plugins/annotations/draw.ts +68 -72
  78. package/src/plugins/annotations/index.ts +12 -19
  79. package/src/plugins/recordings/client.ts +89 -167
  80. package/src/plugins/screenshots/client.ts +53 -2
  81. package/src/plugins/tasks/client.ts +219 -748
  82. package/src/plugins/tasks/composer.ts +797 -0
  83. package/src/plugins/tasks/drawer.ts +516 -0
  84. package/src/plugins/tasks/index.ts +360 -82
  85. package/src/plugins/tasks/pins.ts +275 -0
  86. package/src/plugins/tasks/store.ts +132 -0
  87. package/src/plugins/voice/client.ts +96 -5
  88. package/skills/deictic/references/recordings.md +0 -13
  89. package/skills/deictic/references/tasks.md +0 -22
  90. package/skills/deictic/references/watch.md +0 -17
@@ -1,9 +1,14 @@
1
+ import { u as toolButton } from "./dom.js";
2
+ import { r as trayed } from "./drawer.js";
1
3
  import { n as defineClientPlugin } from "./src.js";
2
4
  // src/plugins/screenshots/client.ts
3
5
  /**
4
6
  * The screenshots plugin's page half, around a renderer's capture: the renderer makes the shot (a PNG,
5
7
  * or what its server half makes one of), and this sends it to the plugin's `add` route and answers the
6
8
  * `Shot`. A renderer's page module default-exports `screenshotsClient(itsCapture)`.
9
+ *
10
+ * 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
11
+ * tray, for the next task.
7
12
  */
8
13
  /** Leaves out deictic's own UI: the overlay with its hover outline and any open panel. */
9
14
  const notOurs = (node) => !(node instanceof Element && node.localName === "deictic-overlay");
@@ -23,6 +28,8 @@ function boxOf(element, area) {
23
28
  };
24
29
  }
25
30
  const BLANK = "#d4d4d8";
31
+ /** A camera, on a 24-pixel grid. */
32
+ const CAMERA = "<path d=\"M4 8h3l2-3h6l2 3h3v11H4z\"/><circle cx=\"12\" cy=\"13\" r=\"3.5\"/>";
26
33
  const selector = (className, extra) => [`.${CSS.escape(className)}`, ...extra ? [extra] : []].join(", ");
27
34
  /**
28
35
  * Hides in a copy of the page's what rrweb would: blocked elements become a blank box their size (the copy keeps each
@@ -52,7 +59,7 @@ function mask(copy, m) {
52
59
  function screenshotsClient(capture) {
53
60
  return defineClientPlugin({
54
61
  name: "screenshots",
55
- setup: ({ base, request, options, use }) => {
62
+ setup: ({ base, request, options, use, tools, tray, drawer, lightbox }) => {
56
63
  const { masking, renderer } = options;
57
64
  const overlay = (area) => {
58
65
  return use("annotations")?.svg(area);
@@ -72,7 +79,7 @@ function screenshotsClient(capture) {
72
79
  size
73
80
  };
74
81
  };
75
- return {
82
+ const api = {
76
83
  capture: async (element, { area = "viewport" } = {}) => {
77
84
  const { body, type, box } = await capture(element, {
78
85
  area,
@@ -100,6 +107,42 @@ function screenshotsClient(capture) {
100
107
  return copy;
101
108
  }
102
109
  };
110
+ const group = Object.assign(document.createElement("div"), { className: "tool-group" });
111
+ const shoot = toolButton(CAMERA, "Screenshot", "S", () => {
112
+ shoot.disabled = true;
113
+ shoot.classList.remove("problem");
114
+ const done = tools.keep();
115
+ api.capture(document.documentElement).then((shot) => {
116
+ tray.add("screenshots", shot.id, shot);
117
+ shoot.title = "Screenshot";
118
+ }, (e) => {
119
+ shoot.classList.add("problem");
120
+ shoot.title = e instanceof Error ? e.message : String(e);
121
+ }).finally(() => {
122
+ shoot.disabled = false;
123
+ done();
124
+ });
125
+ });
126
+ group.append(shoot);
127
+ tools.add(group, { section: "capture" });
128
+ drawer.add(trayed({ tray }, "screenshots", "Screenshots", (item, i, all) => {
129
+ const name = (n) => all.length === 1 ? "Screenshot" : `Screenshot ${n + 1}`;
130
+ return {
131
+ label: [Object.assign(document.createElement("img"), {
132
+ src: item.value.url,
133
+ alt: ""
134
+ }), name(i)],
135
+ open: (from) => lightbox(all.map((each, n) => ({
136
+ kind: "image",
137
+ url: each.value.url,
138
+ title: name(n)
139
+ })), {
140
+ at: i,
141
+ from
142
+ })
143
+ };
144
+ }));
145
+ return api;
103
146
  }
104
147
  });
105
148
  }
@@ -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 */\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\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 }) => {\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 return {\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 });\n}\n"],"mappings":";;;;;;;;AA2BA,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,Y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c;IAE7B,OADuC,IAAI,aAChC,CAAC,EAAE,IAAI,IAAI;GACxB;GACA,MAAM,MAAM,OAAO,MAAqB,MAAc,EAAE,KAAK,WAAsD;IACjH,MAAM,MAAM,MAAM,QAAQ,OAAO;KAAE,QAAQ;KAAQ,SAAS,EAAE,gBAAgB,KAAK;KAAG;IAAK,CAAC;IAG5F,MAAM,EAAE,IAAI,KAAK,SAAS,KAAK,UAAW,MAAM,IAAI,KAAK;IACzD,IAAI,OAAO,KAAA,GAAW,MAAM,IAAI,MAAM,gBAAgB,WAAW,IAAI,YAAY;IACjF,OAAO;KAAE;KAAI,KAAK,OAAO,GAAG,KAAK,qCAAqC;KAAM,KAAK,SAAS;KAAK;IAAK;GACtG;GACA,OAAO;IACL,SAAS,OAAO,SAAS,EAAE,OAAO,eAAe,CAAC,MAAM;KACtD,MAAM,EAAE,MAAM,MAAM,QAAQ,MAAM,QAAQ,SAAS;MAAE;MAAM;MAAS;MAAU;KAAQ,CAAC;KACvF,MAAM,EAAE,aAAa,iBAAiB,SAAS;KAC/C,MAAM,OAAO,SAAS,YAAY;MAAE,OAAO,IAAI;MAAO,QAAQ,IAAI;KAAO,IAAI;MAAE,OAAO;MAAa,QAAQ;KAAa;KACxH,OAAO,IAAI,MAAM,MAAM;MAAE;MAAK;KAAK,CAAC;IACtC;IACA,SAAS,KAAK,OAAO,IAAI,KAAK,aAAa,EAAE;IAC7C,SAAS,YAAY;KACnB,MAAM,OAAO,QAAQ,UAAU,IAAI;KACnC,KAAK,MAAM,OAAO;KAClB,OAAO;IACT;GACF;EACF;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 { 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,YAAY;EAAE,GAAG;EAAG,GAAG;EAAG;EAAO;CAAO,IAAI;EAAE;EAAG;EAAG;EAAO;CAAO;AACpF;AAEA,MAAM,QAAQ;;AAEd,MAAM,SAAS;AAEf,MAAM,YAAY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C,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"}
@@ -0,0 +1,62 @@
1
+ // src/client/component.ts
2
+ /** React's fiber of an element it rendered, which it keeps on the element under a key of its own. */
3
+ const fiberOf = (el) => {
4
+ const key = Object.keys(el).find((k) => k.startsWith("__reactFiber$"));
5
+ return key === void 0 ? void 0 : el[key];
6
+ };
7
+ const ownerOf = (of) => of?._debugOwner ?? of?.owner ?? void 0;
8
+ /** A component's name, through `memo` and `forwardRef`, or nothing for one written without. */
9
+ function componentOf(owner) {
10
+ if (typeof owner.name === "string") return owner.name === "" ? void 0 : owner.name;
11
+ let type = owner.type;
12
+ for (let depth = 0; depth < 4 && type !== null && type !== void 0; depth++) {
13
+ const name = type.displayName ?? type.name;
14
+ if (typeof name === "string" && name !== "") return name;
15
+ type = type.render ?? type.type;
16
+ }
17
+ }
18
+ /** How far under a component its elements are counted: past that it's taken to have several. */
19
+ const LOOKED = 400;
20
+ /** Whether `owner` wrote no element but the one: read off what it rendered, which holds what it passed down as children too. */
21
+ function wroteOne(owner) {
22
+ const its = (fiber) => fiber !== null && fiber !== void 0 && (fiber === owner || fiber === owner.alternate);
23
+ let wrote = 0;
24
+ let looked = 0;
25
+ for (let at = owner.child; at !== null && at !== void 0;) {
26
+ if (++looked > LOOKED) return false;
27
+ if (typeof at.type === "string" && its(ownerOf(at)) && ++wrote > 1) return false;
28
+ if (at.child !== null && at.child !== void 0) {
29
+ at = at.child;
30
+ continue;
31
+ }
32
+ while (at.sibling === null || at.sibling === void 0) {
33
+ const up = at.return;
34
+ if (up === null || up === void 0 || its(up)) return wrote === 1;
35
+ at = up;
36
+ }
37
+ at = at.sibling;
38
+ }
39
+ return wrote === 1;
40
+ }
41
+ const known = /* @__PURE__ */ new WeakMap();
42
+ function named(el) {
43
+ const kept = known.get(el);
44
+ if (kept !== void 0) return kept;
45
+ const owner = ownerOf(fiberOf(el));
46
+ const component = owner === void 0 ? void 0 : componentOf(owner);
47
+ const answer = owner === void 0 || component === void 0 ? {
48
+ tag: el.localName,
49
+ sole: false
50
+ } : {
51
+ tag: el.localName,
52
+ component,
53
+ sole: wroteOne(owner)
54
+ };
55
+ known.set(el, answer);
56
+ return answer;
57
+ }
58
+ /** `<PlanCard>` for the only element of one, `<PlanCard> <li>` for one of several, `<li>` where no component is known. */
59
+ const tell = ({ tag, component, sole }) => component === void 0 ? `<${tag}>` : sole ? `<${component}>` : `<${component}> <${tag}>`;
60
+ export { tell as a, ownerOf as i, fiberOf as n, named as r, componentOf as t };
61
+
62
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","names":[],"sources":["../../src/client/component.ts"],"sourcesContent":["/**\n * The component that wrote an element, where the page can say: with React in development, which keeps who wrote\n * each element on its fiber. Anything else (another framework, a production build) says nothing, and an element is\n * then known by its tag alone.\n */\n\n/**\n * What React keeps, in development, of who wrote an element: a fiber (its `type` the component), or for a server\n * component its `name`. Each has the one that wrote it in turn. A fiber has what it rendered under it, too.\n */\nexport interface Owner {\n name?: unknown;\n type?: unknown;\n alternate?: Owner | null;\n owner?: Owner | null;\n _debugOwner?: Owner | null;\n child?: Owner | null;\n sibling?: Owner | null;\n return?: Owner | null;\n}\n\n/** React's fiber of an element it rendered, which it keeps on the element under a key of its own. */\nexport const fiberOf = (el: Element): Owner | undefined => {\n const key = Object.keys(el).find((k) => k.startsWith('__reactFiber$'));\n return key === undefined ? undefined : (el as unknown as Record<string, Owner>)[key];\n};\n\nexport const ownerOf = (of: Owner | undefined): Owner | undefined => of?._debugOwner ?? of?.owner ?? undefined;\n\n/** A component's name, through `memo` and `forwardRef`, or nothing for one written without. */\nexport function componentOf(owner: Owner): string | undefined {\n if (typeof owner.name === 'string') return owner.name === '' ? undefined : owner.name;\n let type = owner.type as { displayName?: unknown; name?: unknown; render?: unknown; type?: unknown } | null | undefined;\n for (let depth = 0; depth < 4 && type !== null && type !== undefined; depth++) {\n // A function's own name, where it has no `displayName`; a `memo` or `forwardRef` object has neither.\n const name = type.displayName ?? type.name;\n if (typeof name === 'string' && name !== '') return name;\n type = (type.render ?? type.type) as typeof type;\n }\n return undefined;\n}\n\n/** How an element is told to a person: its tag, and the component that wrote it where the page says. */\nexport interface Named {\n tag: string;\n /** The component whose JSX has the element: `PlanCard`. */\n component?: string;\n /** Whether the element is the only one that component wrote: then the component's name says it all. */\n sole: boolean;\n}\n\n/** How far under a component its elements are counted: past that it's taken to have several. */\nconst LOOKED = 400;\n\n/** Whether `owner` wrote no element but the one: read off what it rendered, which holds what it passed down as children too. */\nfunction wroteOne(owner: Owner): boolean {\n // A component's fiber is one of two, by turns: an element may name either.\n const its = (fiber: Owner | null | undefined) => fiber !== null && fiber !== undefined && (fiber === owner || fiber === owner.alternate);\n let wrote = 0;\n let looked = 0;\n // Down, then across, then back up to the next across: every fiber under it, without a stack.\n for (let at = owner.child; at !== null && at !== undefined;) {\n if (++looked > LOOKED) return false;\n if (typeof at.type === 'string' && its(ownerOf(at)) && ++wrote > 1) return false;\n if (at.child !== null && at.child !== undefined) {\n at = at.child;\n continue;\n }\n while (at.sibling === null || at.sibling === undefined) {\n const up: Owner | null | undefined = at.return;\n // Back at the component: that was all of it.\n if (up === null || up === undefined || its(up)) return wrote === 1;\n at = up;\n }\n at = at.sibling;\n }\n return wrote === 1;\n}\n\n// Asked each frame while it's pointed at: an element's answer is kept while the element is.\nconst known = new WeakMap<Element, Named>();\n\nexport function named(el: Element): Named {\n const kept = known.get(el);\n if (kept !== undefined) return kept;\n const owner = ownerOf(fiberOf(el));\n const component = owner === undefined ? undefined : componentOf(owner);\n const answer: Named =\n owner === undefined || component === undefined\n ? { tag: el.localName, sole: false }\n : { tag: el.localName, component, sole: wroteOne(owner) };\n known.set(el, answer);\n return answer;\n}\n\n/** `<PlanCard>` for the only element of one, `<PlanCard> <li>` for one of several, `<li>` where no component is known. */\nexport const tell = ({ tag, component, sole }: Named) =>\n component === undefined ? `<${tag}>` : sole ? `<${component}>` : `<${component}> <${tag}>`;\n"],"mappings":";;AAsBA,MAAa,WAAW,OAAmC;CACzD,MAAM,MAAM,OAAO,KAAK,EAAE,CAAC,CAAC,MAAM,MAAM,EAAE,WAAW,eAAe,CAAC;CACrE,OAAO,QAAQ,KAAA,IAAY,KAAA,IAAa,GAAwC;AAClF;AAEA,MAAa,WAAW,OAA6C,IAAI,eAAe,IAAI,SAAS,KAAA;;AAGrG,SAAgB,YAAY,OAAkC;CAC5D,IAAI,OAAO,MAAM,SAAS,UAAU,OAAO,MAAM,SAAS,KAAK,KAAA,IAAY,MAAM;CACjF,IAAI,OAAO,MAAM;CACjB,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,SAAS,QAAQ,SAAS,KAAA,GAAW,SAAS;EAE7E,MAAM,O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,QAAQ,EAAE,KAAK,WAAW,WACrC,cAAc,KAAA,IAAY,IAAI,IAAI,KAAK,OAAO,IAAI,UAAU,KAAK,IAAI,UAAU,KAAK,IAAI"}
@@ -0,0 +1,79 @@
1
+ // src/client/dom.ts
2
+ /** The attribute the transform marks an element with: `file:line:column`. */
3
+ const ATTRIBUTE = "data-deictic";
4
+ /** An element's place in the source, as its mark has it, or nothing for one with none. */
5
+ function targetOf(el) {
6
+ const at = el.getAttribute(ATTRIBUTE);
7
+ const match = at === null ? null : /^(.*):(\d+):(\d+)$/.exec(at);
8
+ if (match === null) return void 0;
9
+ return {
10
+ loc: {
11
+ file: match[1],
12
+ line: Number(match[2]),
13
+ column: Number(match[3])
14
+ },
15
+ tag: el.localName
16
+ };
17
+ }
18
+ /** Every element on the page from the same place in the source as `el`. */
19
+ const sameAs = (el) => [...document.querySelectorAll(`[${ATTRIBUTE}="${CSS.escape(el.getAttribute("data-deictic") ?? "")}"]`)];
20
+ function div(className) {
21
+ const el = document.createElement("div");
22
+ el.className = className;
23
+ return el;
24
+ }
25
+ /** Puts a fixed box over `r`. */
26
+ function place(el, r) {
27
+ Object.assign(el.style, {
28
+ left: `${r.left}px`,
29
+ top: `${r.top}px`,
30
+ width: `${r.width}px`,
31
+ height: `${r.height}px`
32
+ });
33
+ }
34
+ /** `button.tab`: the element as a selector, its own classes only, for a person to tell it by. */
35
+ const nameOf = (el) => `${el.localName}${[...el.classList].map((c) => `.${c}`).join("")}`;
36
+ const reduced = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
37
+ /**
38
+ * A button for the tool panel: an icon (its strokes, on a 24-pixel grid), named by its tooltip and for a screen
39
+ * reader, with the keys that press it (`B`, `Control+Z`), which the tooltip shows and the panel hears.
40
+ */
41
+ function toolButton(strokes, name, keys, run) {
42
+ const el = Object.assign(document.createElement("button"), {
43
+ type: "button",
44
+ className: "icon",
45
+ title: name
46
+ });
47
+ 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>`;
48
+ el.setAttribute("aria-label", name);
49
+ if (keys !== void 0) el.setAttribute("aria-keyshortcuts", keys);
50
+ el.addEventListener("click", run);
51
+ return el;
52
+ }
53
+ /**
54
+ * The control in `within` that a key is for, by its `aria-keyshortcuts`: a key alone, or with the keys it names.
55
+ * `loose` takes a key alone whatever is held with it, for while a shortcut's keys are held to point.
56
+ */
57
+ function controlFor(within, e, loose = false) {
58
+ const key = /^[a-z]$/i.test(e.key) ? e.key.toUpperCase() : e.code.startsWith("Key") ? e.code.slice(3) : e.key;
59
+ const held = [
60
+ e.ctrlKey && "Control",
61
+ e.metaKey && "Meta",
62
+ e.shiftKey && "Shift"
63
+ ].filter((m) => m !== false);
64
+ for (const el of within.querySelectorAll("[aria-keyshortcuts]")) {
65
+ if (el instanceof HTMLButtonElement && el.disabled) continue;
66
+ if (el.offsetParent === null) continue;
67
+ for (const keys of (el.getAttribute("aria-keyshortcuts") ?? "").split(" ")) {
68
+ const named = keys.split("+");
69
+ if (named.at(-1) !== key) continue;
70
+ const mods = named.slice(0, -1);
71
+ if (mods.length === 0 ? loose || held.length === 0 : mods.length === held.length && mods.every((m) => held.includes(m))) return el;
72
+ }
73
+ }
74
+ }
75
+ /** The key held with a letter for a command, as the platform has it, by the name `aria-keyshortcuts` gives it. */
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 };
78
+
79
+ //# sourceMappingURL=dom.js.map
@@ -0,0 +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,CAAC;AAExI,SAAgB,IAAI,WAAmC;CACrD,MAAM,KAAK,SAAS,cAAc,KAAK;CACvC,GAAG,YAAY;CACf,OA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,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"}
@@ -0,0 +1,217 @@
1
+ import { i as div } from "./dom.js";
2
+ // src/client/drawer.ts
3
+ /** How long the drawer outlasts the keys, in milliseconds: time to get the pointer to it. */
4
+ const LINGER = 600;
5
+ /** Where whether it's folded is kept. */
6
+ const FOLDED = "deictic:drawer";
7
+ const FOLD = "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M5 12h14\"/></svg>";
8
+ const TRAY = "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M4 13l2.5-8h11l2.5 8v6H4zM4 13h5l1 2h4l1-2h5\"/></svg>";
9
+ const BACK = "<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M15 6l-6 6 6 6\"/></svg>";
10
+ /** A play mark, for a row that plays something: drawn, as a system's own differs from one to the next. */
11
+ function playMark() {
12
+ const mark = document.createElement("span");
13
+ mark.innerHTML = "<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M7 4v16l13-8z\" fill=\"currentColor\"/></svg>";
14
+ return mark;
15
+ }
16
+ function drawerIn(root, { crowded }) {
17
+ const drawer = div("drawer");
18
+ drawer.setAttribute("role", "complementary");
19
+ drawer.setAttribute("aria-label", "deictic drawer");
20
+ const sections = div("drawer-sections");
21
+ const viewing = div("drawer-view");
22
+ viewing.hidden = true;
23
+ const fold = Object.assign(document.createElement("button"), {
24
+ type: "button",
25
+ className: "icon drawer-fold",
26
+ title: "Fold the drawer away",
27
+ innerHTML: FOLD
28
+ });
29
+ const pill = Object.assign(document.createElement("button"), {
30
+ type: "button",
31
+ className: "drawer-pill",
32
+ title: "Open the drawer",
33
+ innerHTML: TRAY
34
+ });
35
+ const count = document.createElement("span");
36
+ pill.append(count);
37
+ drawer.append(fold, pill, sections, viewing);
38
+ root.append(drawer);
39
+ let folded = false;
40
+ try {
41
+ folded = localStorage.getItem(FOLDED) === "folded";
42
+ } catch {}
43
+ const foldTo = (on) => {
44
+ folded = on;
45
+ drawer.classList.toggle("folded", on);
46
+ try {
47
+ localStorage.setItem(FOLDED, on ? "folded" : "open");
48
+ } catch {}
49
+ };
50
+ drawer.classList.toggle("folded", folded);
51
+ fold.addEventListener("click", () => foldTo(true));
52
+ pill.addEventListener("click", () => foldTo(false));
53
+ /** What the pill says: how much the sections shown have, or how much of it is unread, in the overlay's green. */
54
+ const counted = () => {
55
+ const shown = [...sections.children].filter((section) => !section.hasAttribute("hidden"));
56
+ const sum = (key) => shown.reduce((n, section) => {
57
+ const said = Number(section.dataset[key] ?? 0);
58
+ return n + (Number.isFinite(said) ? said : 0);
59
+ }, 0);
60
+ const unread = sum("unread");
61
+ count.textContent = String(unread > 0 ? unread : sum("count"));
62
+ pill.classList.toggle("news", unread > 0);
63
+ pill.title = unread > 0 ? `Open the drawer: ${unread} unread` : "Open the drawer";
64
+ };
65
+ let pointing = false;
66
+ let over = false;
67
+ let keeps = 0;
68
+ let leave;
69
+ let leaving;
70
+ const shown = () => drawer.classList.contains("shown");
71
+ const empty = () => leave === void 0 && ![...sections.children].some((section) => !section.hasAttribute("hidden"));
72
+ const show = () => {
73
+ clearTimeout(leaving);
74
+ leaving = void 0;
75
+ const on = !empty() && (pointing || over || keeps > 0 || leave !== void 0 || drawer.contains(root.activeElement));
76
+ if (on === shown()) return;
77
+ if (!on && empty()) {
78
+ drawer.classList.add("emptied");
79
+ drawer.classList.remove("shown");
80
+ return;
81
+ }
82
+ drawer.classList.remove("emptied");
83
+ if (!on) {
84
+ leaving = setTimeout(() => drawer.classList.remove("shown"), LINGER);
85
+ return;
86
+ }
87
+ drawer.classList.toggle("left", crowded());
88
+ drawer.classList.add("shown");
89
+ };
90
+ drawer.addEventListener("pointerenter", () => {
91
+ over = true;
92
+ show();
93
+ });
94
+ drawer.addEventListener("pointerleave", () => {
95
+ over = false;
96
+ show();
97
+ });
98
+ drawer.addEventListener("focusout", () => queueMicrotask(show));
99
+ new MutationObserver(() => {
100
+ counted();
101
+ show();
102
+ }).observe(sections, {
103
+ subtree: true,
104
+ attributes: true,
105
+ attributeFilter: [
106
+ "hidden",
107
+ "data-count",
108
+ "data-unread"
109
+ ]
110
+ });
111
+ const close = () => {
112
+ const closed = leave;
113
+ if (closed === void 0) return;
114
+ leave = void 0;
115
+ viewing.replaceChildren();
116
+ viewing.hidden = true;
117
+ sections.hidden = false;
118
+ closed();
119
+ show();
120
+ };
121
+ window.addEventListener("keydown", (e) => {
122
+ if (e.key !== "Escape" || leave === void 0 || root.querySelector("[data-deictic-modal]") !== null) return;
123
+ if (!drawer.contains(root.activeElement) && root.querySelector(".panel") !== null) return;
124
+ e.preventDefault();
125
+ e.stopImmediatePropagation();
126
+ close();
127
+ }, true);
128
+ return {
129
+ add: (section, options) => {
130
+ section.classList.add("drawer-section");
131
+ if (options?.first === true) sections.prepend(section);
132
+ else sections.append(section);
133
+ counted();
134
+ show();
135
+ },
136
+ show: (view, { title = "", closed = () => {} } = {}) => {
137
+ close();
138
+ const back = Object.assign(document.createElement("button"), {
139
+ type: "button",
140
+ className: "icon",
141
+ title: "Back to the list",
142
+ innerHTML: BACK
143
+ });
144
+ back.setAttribute("aria-keyshortcuts", "Escape");
145
+ back.addEventListener("click", close);
146
+ const head = div("drawer-head");
147
+ head.append(back, Object.assign(document.createElement("span"), {
148
+ className: "drawer-title",
149
+ textContent: title
150
+ }));
151
+ viewing.replaceChildren(head, view);
152
+ sections.hidden = true;
153
+ viewing.hidden = false;
154
+ leave = closed;
155
+ if (folded) foldTo(false);
156
+ show();
157
+ return () => {
158
+ if (leave === closed) close();
159
+ };
160
+ },
161
+ keep: () => {
162
+ keeps++;
163
+ show();
164
+ let kept = true;
165
+ return () => {
166
+ if (!kept) return;
167
+ kept = false;
168
+ keeps--;
169
+ show();
170
+ };
171
+ },
172
+ point: (on) => {
173
+ pointing = on;
174
+ show();
175
+ }
176
+ };
177
+ }
178
+ /**
179
+ * A section of what a plugin's tools made and no task has taken, from the tray: a heading and a row each, which
180
+ * opens it; its × takes it out of the tray. Away while there are none.
181
+ */
182
+ function trayed({ tray }, plugin, title, row) {
183
+ const section = document.createElement("section");
184
+ const heading = Object.assign(document.createElement("h3"), { textContent: title });
185
+ const list = div("drawer-rows");
186
+ section.append(heading, list);
187
+ const draw = () => {
188
+ const items = tray.list(plugin);
189
+ section.hidden = items.length === 0;
190
+ section.dataset.count = String(items.length);
191
+ list.replaceChildren(...items.map((item, i) => {
192
+ const { label, open } = row(item, i, items);
193
+ const opener = Object.assign(document.createElement("button"), {
194
+ type: "button",
195
+ className: "drawer-open"
196
+ });
197
+ opener.append(...label);
198
+ opener.addEventListener("click", () => open(el));
199
+ const remover = Object.assign(document.createElement("button"), {
200
+ type: "button",
201
+ className: "icon",
202
+ textContent: "×",
203
+ title: "Remove"
204
+ });
205
+ remover.addEventListener("click", () => tray.remove(plugin, item.id));
206
+ const el = div("drawer-row");
207
+ el.append(opener, remover);
208
+ return el;
209
+ }));
210
+ };
211
+ tray.subscribe(draw);
212
+ draw();
213
+ return section;
214
+ }
215
+ export { playMark as n, trayed as r, drawerIn as t };
216
+
217
+ //# sourceMappingURL=drawer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drawer.js","names":[],"sources":["../../src/client/drawer.ts"],"sourcesContent":["/**\n * The drawer: on the window's side, where what the plugins have for the page lands, a section each (the\n * tasks still to do, the shots and recordings no task has taken). It shows while a shortcut's keys are held, as the\n * tool panel does, and only while a section has something in it; it stays while the pointer is on it, while something\n * goes on in it (`keep`), and while one of its items is open.\n *\n * An item opens in the drawer itself (`show`): its view takes the sections' place, with a way back. Esc is the view's\n * while the focus is in the drawer, or no popup is open to have it first.\n *\n * It folds away to a pill, by the button in its corner, and stays so (`localStorage`) until the pill is pressed or an\n * item opens in it. The pill counts what the sections have (`data-count`), or what's unread there (`data-unread`).\n */\nimport type { ClientContext, Drawer, TrayItem } from '#src/index.ts';\n\nimport { div } from './dom.ts';\n\n/** How long the drawer outlasts the keys, in milliseconds: time to get the pointer to it. */\nconst LINGER = 600;\n/** Where whether it's folded is kept. */\nconst FOLDED = 'deictic:drawer';\nconst FOLD =\n '<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M5 12h14\"/></svg>';\nconst TRAY =\n '<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M4 13l2.5-8h11l2.5 8v6H4zM4 13h5l1 2h4l1-2h5\"/></svg>';\nconst BACK =\n '<svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M15 6l-6 6 6 6\"/></svg>';\n\n/** A play mark, for a row that plays something: drawn, as a system's own differs from one to the next. */\nexport function playMark(): HTMLElement {\n const mark = document.createElement('span');\n mark.innerHTML = '<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M7 4v16l13-8z\" fill=\"currentColor\"/></svg>';\n return mark;\n}\n\nexport interface OwnDrawer extends Drawer {\n /** Whether a shortcut's keys are held: the drawer shows while they are. */\n point: (on: boolean) => void;\n}\n\nexport interface DrawerOptions {\n /** Whether the tool panel is on the window's right: the drawer is then on its left, out from under it. */\n crowded: () => boolean;\n}\n\nexport function drawerIn(root: ShadowRoot, { crowded }: DrawerOptions): OwnDrawer {\n const drawer = div('drawer');\n drawer.setAttribute('role', 'complementary');\n drawer.setAttribute('aria-label', 'deictic drawer');\n const sections = div('drawer-sections');\n const viewing = div('drawer-view');\n viewing.hidden = true;\n const fold = Object.assign(document.createElement('button'), {\n type: 'button',\n className: 'icon drawer-fold',\n title: 'Fold the drawer away',\n innerHTML: FOLD,\n });\n const pill = Object.assign(document.createElement('button'), {\n type: 'button',\n className: 'drawer-pill',\n title: 'Open the drawer',\n innerHTML: TRAY,\n });\n const count = document.createElement('span');\n pill.append(count);\n drawer.append(fold, pill, sections, viewing);\n root.append(drawer);\n\n let folded = false;\n try {\n folded = localStorage.getItem(FOLDED) === 'folded';\n } catch {\n // Storage can be off: open, then.\n }\n const foldTo = (on: boolean) => {\n folded = on;\n drawer.classList.toggle('folded', on);\n try {\n localStorage.setItem(FOLDED, on ? 'folded' : 'open');\n } catch {\n // Not kept past the page, then.\n }\n };\n drawer.classList.toggle('folded', folded);\n fold.addEventListener('click', () => foldTo(true));\n pill.addEventListener('click', () => foldTo(false));\n /** What the pill says: how much the sections shown have, or how much of it is unread, in the overlay's green. */\n const counted = () => {\n const shown = [...sections.children].filter((section) => !section.hasAttribute('hidden')) as HTMLElement[];\n // A section that says nothing, or something that isn't a number, counts none.\n const sum = (key: 'count' | 'unread') =>\n shown.reduce((n, section) => {\n const said = Number(section.dataset[key] ?? 0);\n return n + (Number.isFinite(said) ? said : 0);\n }, 0);\n const unread = sum('unread');\n count.textContent = String(unread > 0 ? unread : sum('count'));\n pill.classList.toggle('news', unread > 0);\n pill.title = unread > 0 ? `Open the drawer: ${unread} unread` : 'Open the drawer';\n };\n\n let pointing = false;\n let over = false;\n let keeps = 0;\n // What closes the item that's open, where one is.\n let leave: (() => void) | undefined;\n let leaving: ReturnType<typeof setTimeout> | undefined;\n const shown = () => drawer.classList.contains('shown');\n // A section with nothing to show hides itself: the drawer has nothing then, and stays away.\n const empty = () => leave === undefined && ![...sections.children].some((section) => !section.hasAttribute('hidden'));\n const show = () => {\n clearTimeout(leaving);\n leaving = undefined;\n const on = !empty() && (pointing || over || keeps > 0 || leave !== undefined || drawer.contains(root.activeElement));\n if (on === shown()) return;\n // Emptied, it goes at once, not shrunk to its corner's button for a while: nothing is left to get the pointer to.\n if (!on && empty()) {\n drawer.classList.add('emptied');\n drawer.classList.remove('shown');\n return;\n }\n drawer.classList.remove('emptied');\n if (!on) {\n // Not at once: the keys are let go on the way to it.\n leaving = setTimeout(() => drawer.classList.remove('shown'), LINGER);\n return;\n }\n drawer.classList.toggle('left', crowded());\n drawer.classList.add('shown');\n };\n drawer.addEventListener('pointerenter', () => {\n over = true;\n show();\n });\n drawer.addEventListener('pointerleave', () => {\n over = false;\n show();\n });\n drawer.addEventListener('focusout', () => queueMicrotask(show));\n // A section fills as its plugin reads what it has: the drawer is there once one does.\n new MutationObserver(() => {\n counted();\n show();\n }).observe(sections, { subtree: true, attributes: true, attributeFilter: ['hidden', 'data-count', 'data-unread'] });\n\n const close = () => {\n const closed = leave;\n if (closed === undefined) return;\n leave = undefined;\n viewing.replaceChildren();\n viewing.hidden = true;\n sections.hidden = false;\n closed();\n show();\n };\n // Before the popup's own Esc, which is added as a popup opens: the item's while it's typed in, or with no popup.\n window.addEventListener(\n 'keydown',\n (e) => {\n if (e.key !== 'Escape' || leave === undefined || root.querySelector('[data-deictic-modal]') !== null) return;\n if (!drawer.contains(root.activeElement) && root.querySelector('.panel') !== null) return;\n e.preventDefault();\n e.stopImmediatePropagation();\n close();\n },\n true,\n );\n\n return {\n add: (section, options) => {\n section.classList.add('drawer-section');\n if (options?.first === true) sections.prepend(section);\n else sections.append(section);\n counted();\n show();\n },\n show: (view, { title = '', closed = () => {} } = {}) => {\n close();\n const back = Object.assign(document.createElement('button'), {\n type: 'button',\n className: 'icon',\n title: 'Back to the list',\n innerHTML: BACK,\n });\n back.setAttribute('aria-keyshortcuts', 'Escape');\n back.addEventListener('click', close);\n const head = div('drawer-head');\n head.append(back, Object.assign(document.createElement('span'), { className: 'drawer-title', textContent: title }));\n viewing.replaceChildren(head, view);\n sections.hidden = true;\n viewing.hidden = false;\n leave = closed;\n // Something asked to be seen: folded away, it couldn't be.\n if (folded) foldTo(false);\n show();\n return () => {\n if (leave === closed) close();\n };\n },\n keep: () => {\n keeps++;\n show();\n let kept = true;\n return () => {\n if (!kept) return;\n kept = false;\n keeps--;\n show();\n };\n },\n point: (on) => {\n pointing = on;\n show();\n },\n };\n}\n\n/**\n * A section of what a plugin's tools made and no task has taken, from the tray: a heading and a row each, which\n * opens it; its × takes it out of the tray. Away while there are none.\n */\nexport function trayed(\n { tray }: Pick<ClientContext, 'tray'>,\n plugin: string,\n title: string,\n row: (item: TrayItem, index: number, all: TrayItem[]) => { label: (string | Node)[]; open: (from: HTMLElement) => void },\n): HTMLElement {\n const section = document.createElement('section');\n const heading = Object.assign(document.createElement('h3'), { textContent: title });\n const list = div('drawer-rows');\n section.append(heading, list);\n const draw = () => {\n const items = tray.list(plugin);\n section.hidden = items.length === 0;\n section.dataset.count = String(items.length);\n list.replaceChildren(\n ...items.map((item, i) => {\n const { label, open } = row(item, i, items);\n const opener = Object.assign(document.createElement('button'), { type: 'button', className: 'drawer-open' });\n opener.append(...label);\n opener.addEventListener('click', () => open(el));\n const remover = Object.assign(document.createElement('button'), {\n type: 'button',\n className: 'icon',\n textContent: '×',\n title: 'Remove',\n });\n remover.addEventListener('click', () => tray.remove(plugin, item.id));\n const el = div('drawer-row');\n el.append(opener, remover);\n return el;\n }),\n );\n };\n tray.subscribe(draw);\n draw();\n return section;\n}\n"],"mappings":";;;AAiBA,MAAM,SAAS;;AAEf,MAAM,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