deictic 0.5.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 (103) hide show
  1. package/API.md +150 -37
  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/endpoints.js +34 -8
  30. package/dist/shared/endpoints.js.map +1 -1
  31. package/dist/shared/find.js +2 -1
  32. package/dist/shared/find.js.map +1 -1
  33. package/dist/shared/index.d.ts +124 -11
  34. package/dist/shared/index.d.ts.map +1 -1
  35. package/dist/shared/index2.d.ts +9 -19
  36. package/dist/shared/index2.d.ts.map +1 -1
  37. package/dist/shared/index7.d.ts +105 -26
  38. package/dist/shared/index7.d.ts.map +1 -1
  39. package/dist/shared/index9.d.ts +1 -1
  40. package/dist/shared/init.js +12 -10
  41. package/dist/shared/init.js.map +1 -1
  42. package/dist/shared/integration.d.ts +1 -1
  43. package/dist/shared/packages.js +1 -1
  44. package/dist/shared/recording.js +31 -3
  45. package/dist/shared/recording.js.map +1 -1
  46. package/dist/shared/src.js.map +1 -1
  47. package/dist/shared/task.js +72 -21
  48. package/dist/shared/task.js.map +1 -1
  49. package/dist/shared/tasks.js +330 -166
  50. package/dist/shared/tasks.js.map +1 -1
  51. package/dist/shared/vb.js +1 -1
  52. package/dist/shared/voice2.js +6 -4
  53. package/dist/shared/voice2.js.map +1 -1
  54. package/dist/shared/watch.js +14 -14
  55. package/dist/shared/watch.js.map +1 -1
  56. package/dist/tailwind/index.js +6 -2
  57. package/dist/tailwind/index.js.map +1 -1
  58. package/dist/tasks/client.d.ts +2 -2
  59. package/dist/tasks/client.d.ts.map +1 -1
  60. package/dist/tasks/client.js +1829 -742
  61. package/dist/tasks/client.js.map +1 -1
  62. package/dist/tasks/index.d.ts +2 -2
  63. package/dist/voice/client.d.ts.map +1 -1
  64. package/dist/voice/client.js +154 -57
  65. package/dist/voice/client.js.map +1 -1
  66. package/package.json +1 -1
  67. package/skills/deictic/SKILL.md +22 -28
  68. package/src/cli/find.ts +3 -1
  69. package/src/cli/init.ts +13 -11
  70. package/src/cli/recording.ts +34 -3
  71. package/src/cli/task.ts +94 -23
  72. package/src/cli/voice.ts +9 -4
  73. package/src/cli/watch.ts +14 -13
  74. package/src/client/away.ts +3 -1
  75. package/src/client/component.ts +98 -0
  76. package/src/client/dom.ts +70 -0
  77. package/src/client/drawer.ts +258 -0
  78. package/src/client/index.ts +220 -128
  79. package/src/client/lightbox.ts +8 -8
  80. package/src/client/lighting.ts +279 -0
  81. package/src/client/style.ts +263 -44
  82. package/src/client/tools.ts +279 -0
  83. package/src/client/tooltip.ts +25 -5
  84. package/src/client/tray.ts +48 -0
  85. package/src/index.ts +121 -10
  86. package/src/plugins/annotations/client.ts +103 -129
  87. package/src/plugins/annotations/draw.ts +68 -72
  88. package/src/plugins/annotations/index.ts +12 -19
  89. package/src/plugins/recordings/client.ts +89 -167
  90. package/src/plugins/screenshots/client.ts +53 -2
  91. package/src/plugins/tailwind/index.ts +6 -2
  92. package/src/plugins/tasks/client.ts +219 -749
  93. package/src/plugins/tasks/composer.ts +797 -0
  94. package/src/plugins/tasks/drawer.ts +516 -0
  95. package/src/plugins/tasks/index.ts +459 -192
  96. package/src/plugins/tasks/pins.ts +275 -0
  97. package/src/plugins/tasks/store.ts +132 -0
  98. package/src/plugins/voice/client.ts +96 -5
  99. package/src/tools/endpoints.ts +18 -7
  100. package/src/tools/source.ts +25 -5
  101. package/skills/deictic/references/recordings.md +0 -13
  102. package/skills/deictic/references/tasks.md +0 -21
  103. package/skills/deictic/references/watch.md +0 -17
@@ -6,13 +6,13 @@
6
6
  */
7
7
  import type { LightboxItem, LightboxOptions } from '#src/index.ts';
8
8
 
9
+ import { div, reduced } from './dom.ts';
9
10
  import { type Colors, drawBars, peaksOf } from './waveform.ts';
10
11
 
11
12
  const EASE = 'cubic-bezier(0.2, 0.8, 0.2, 1)';
12
13
  const PLAY = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 4v16l13-8z" fill="currentColor"/></svg>';
13
14
  const PAUSE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 4h4v16H6zM14 4h4v16h-4z" fill="currentColor"/></svg>';
14
15
 
15
- const reduced = () => matchMedia('(prefers-reduced-motion: reduce)').matches;
16
16
  const clock = (s: number) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}`;
17
17
 
18
18
  /**
@@ -40,8 +40,11 @@ export function openLightbox(
40
40
  head.append(title, count, actions, close);
41
41
  const body = div('lb-body');
42
42
  stage.append(head, body);
43
- const prev = button('‹', 'Previous (←)', 'lb-prev');
44
- const next = button('›', 'Next (→)', 'lb-next');
43
+ // Drawn, not glyphs: a font's ‹ and › sit off the middle of a round button, each font its own way.
44
+ const prev = button('', 'Previous (←)', 'lb-prev');
45
+ prev.innerHTML = chevron('M15 6l-6 6 6 6');
46
+ const next = button('', 'Next (→)', 'lb-next');
47
+ next.innerHTML = chevron('M9 6l6 6-6 6');
45
48
  box.append(backdrop, stage, ...(items.length > 1 ? [prev, next] : []));
46
49
  root.append(box);
47
50
 
@@ -240,11 +243,8 @@ function player(url: string, autoplay: boolean): { element: HTMLElement; leave:
240
243
  };
241
244
  }
242
245
 
243
- function div(className: string): HTMLDivElement {
244
- const el = document.createElement('div');
245
- el.className = className;
246
- return el;
247
- }
246
+ const chevron = (d: string) =>
247
+ `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
248
248
 
249
249
  function button(text: string, title: string, className: string): HTMLButtonElement {
250
250
  const el = document.createElement('button');
@@ -0,0 +1,279 @@
1
+ /**
2
+ * What the overlay draws on the page itself: the element under the pointer while a shortcut's keys are held, and
3
+ * the one the popup is open on.
4
+ *
5
+ * It uses the whole page: it dims around the element, which stays lit in a ring, with guides from its edges across
6
+ * the window and a caption saying what it is. The light glides from one element to the next. While the popup is
7
+ * open the element stays lit, tied to the popup by a line that follows both. Nothing here takes the pointer, and
8
+ * the page comes back to full light once the pointer has been out on it a moment.
9
+ */
10
+ import type { Point, Target } from '#src/index.ts';
11
+
12
+ import { named } from './component.ts';
13
+ import { div, nameOf, place, reduced } from './dom.ts';
14
+
15
+ /** What's pointed at while a shortcut's keys are held. */
16
+ export interface Pointed {
17
+ /** The marked element. */
18
+ el: Element;
19
+ /** What's under the pointer inside it, where that differs. */
20
+ pointed?: Element;
21
+ target: Target;
22
+ /**
23
+ * The tabs that plugins' own shortcuts would open, each by its label: several where they share keys and differ by
24
+ * button, and none for deictic's own shortcut alone.
25
+ */
26
+ names: string[];
27
+ /** How many elements on the page are from its place in the source. */
28
+ count: number;
29
+ }
30
+
31
+ export interface Lighting {
32
+ /** Shows what's pointed at. Not `glide`: it moved with the page, which nothing eases. */
33
+ point(at: Pointed, glide?: boolean): void;
34
+ hide(): void;
35
+ /** Marks the element the popup (`panel`) is open on, or the spot `at` in it, for as long as it is. Answers what ends it. */
36
+ hold(element: Element, panel: HTMLElement, at?: Point): () => void;
37
+ }
38
+
39
+ /**
40
+ * How far from the element its ring is, in pixels: the ring glows, and a border, an outline or a ring tried on the
41
+ * element has to show apart from it.
42
+ */
43
+ export const CLEAR = 8;
44
+
45
+ const grown = (r: DOMRect) => new DOMRect(r.left - CLEAR, r.top - CLEAR, r.width + 2 * CLEAR, r.height + 2 * CLEAR);
46
+
47
+ /** How far around a spot its light reaches, in pixels: a circle that shows what's under the point. */
48
+ const SPOT = 16;
49
+
50
+ /** A spot in an element, as the box its light fills. */
51
+ export function spotOf(element: Element, at: Point): DOMRect {
52
+ const r = element.getBoundingClientRect();
53
+ return new DOMRect(r.left + at.x - SPOT, r.top + at.y - SPOT, 2 * SPOT, 2 * SPOT);
54
+ }
55
+
56
+ /** How long the pointer is out on the page, in milliseconds, before the page gets its light back. */
57
+ const LINGER = 700;
58
+ /** How long the light takes from one element to the next, in milliseconds: as the styles have it. */
59
+ const GLIDE = 240;
60
+ /** How far from a corner the line to the popup starts and ends, in pixels. */
61
+ const INSET = 22;
62
+
63
+ // The ring and the line, drawn as strokes: a dash can run along a stroke (the line is drawn out to the popup, and
64
+ // a light goes along it, once), which no border can. Wide faint strokes under them are the glow, as a filter over
65
+ // the whole window would be drawn again with every frame of it.
66
+ const LIT = `<svg aria-hidden="true">
67
+ <rect class="halo"/><rect class="lock"/>
68
+ <path class="halo" pathLength="1"/><path class="tether" pathLength="1"/><path class="flow" pathLength="1"/>
69
+ <circle r="3"/><circle r="3"/></svg>`;
70
+
71
+ const clamp = (n: number, low: number, high: number) => Math.max(low, Math.min(n, high));
72
+
73
+ /** The light's corner for an element, as far out as the light is: a pill stays a pill, a square corner is eased a little. */
74
+ function radiusOf(el: Element, r: DOMRect): number {
75
+ // A computed radius is a length or a percentage, and two of them where the corner is an ellipse: the first, then.
76
+ const [first = '0px'] = getComputedStyle(el).borderTopLeftRadius.split(' ');
77
+ const n = Number.parseFloat(first);
78
+ const least = Math.min(r.width, r.height);
79
+ return Math.min(first.endsWith('%') ? (n / 100) * least : n + CLEAR, least / 2);
80
+ }
81
+
82
+ /**
83
+ * The line from the lit box to the popup: an S from side to side where the popup is beside it, else down or up to
84
+ * it, and none where they overlap. It ends on the popup level with the box's middle, as near as the popup reaches.
85
+ */
86
+ function tetherOf(e: DOMRect, p: DOMRect): { d: string; ends: [number, number][] } | undefined {
87
+ for (const [near, far, low, high] of [
88
+ ['left', 'right', 'top', 'bottom'],
89
+ ['top', 'bottom', 'left', 'right'],
90
+ ] as const) {
91
+ const way = p[near] >= e[far] ? 1 : p[far] <= e[near] ? -1 : 0;
92
+ if (way === 0) continue;
93
+ const a1 = way > 0 ? e[far] : e[near];
94
+ const a2 = way > 0 ? p[near] : p[far];
95
+ const inset = (r: DOMRect) => Math.min(INSET, (r[high] - r[low]) / 2);
96
+ const b2 = clamp((e[low] + e[high]) / 2, p[low] + inset(p), p[high] - inset(p));
97
+ const b1 = clamp(b2, e[low] + inset(e), e[high] - inset(e));
98
+ const bend = (a2 - a1) / 2;
99
+ const at = (a: number, b: number): [number, number] => (near === 'left' ? [a, b] : [b, a]);
100
+ const points = [at(a1, b1), at(a1 + bend, b1), at(a2 - bend, b2), at(a2, b2)].map(([x, y]) => `${x} ${y}`);
101
+ return { d: `M${points[0]}C${points.slice(1).join(' ')}`, ends: [at(a1, b1), at(a2, b2)] };
102
+ }
103
+ return undefined;
104
+ }
105
+
106
+ export function spotlight(root: ShadowRoot): Lighting {
107
+ // Under the marks a page keeps (annotations'), which are drawn as bright as ever.
108
+ const veil = div('veil');
109
+ const aim = div('aim');
110
+ const ring = div('ring');
111
+ const caption = div('caption');
112
+ ring.append(caption);
113
+ const guides = { left: div('guide gx'), right: div('guide gx'), top: div('guide gy'), bottom: div('guide gy') };
114
+ const inner = div('inner');
115
+ aim.append(...Object.values(guides), ring);
116
+ root.append(veil, aim, inner);
117
+
118
+ let pointing = false;
119
+ let held = false;
120
+ let said = '';
121
+ // Not at once: a press that opens the popup hides what's pointed at and holds the same element in one go, and
122
+ // the popup moving to another element lets one go and holds the next. The light stays on through both, and glides.
123
+ const dark = () =>
124
+ queueMicrotask(() => {
125
+ if (!pointing && !held) veil.classList.remove('shown');
126
+ });
127
+ const light = (r: DOMRect, radius: number, glide: boolean) => {
128
+ veil.classList.toggle('glide', glide && veil.classList.contains('shown'));
129
+ place(veil, r);
130
+ veil.style.borderRadius = `${radius}px`;
131
+ veil.classList.add('shown');
132
+ };
133
+ const part = (className: string, text: string) => Object.assign(document.createElement('span'), { className, textContent: text });
134
+
135
+ return {
136
+ point({ el, pointed, target, names, count }, glide = true) {
137
+ pointing = true;
138
+ const box = el.getBoundingClientRect();
139
+ const r = grown(box);
140
+ const radius = radiusOf(el, r);
141
+ aim.classList.toggle('glide', glide && aim.classList.contains('shown'));
142
+ place(ring, r);
143
+ ring.style.borderRadius = `${radius}px`;
144
+ guides.left.style.translate = `${r.left}px`;
145
+ guides.right.style.translate = `${r.right - 1}px`;
146
+ guides.top.style.translate = `0 ${r.top}px`;
147
+ guides.bottom.style.translate = `0 ${r.bottom - 1}px`;
148
+ // The popup's element keeps the light while it's open: another pointed at then has the ring alone.
149
+ if (!held) light(r, radius, glide);
150
+ inner.classList.toggle('shown', pointed !== undefined);
151
+ if (pointed !== undefined) place(inner, pointed.getBoundingClientRect());
152
+
153
+ // What it is, where it's from, how big, how many share its place, what's pointed at in it, and the tab a
154
+ // plugin's own shortcut opens.
155
+ const dim = [
156
+ `${Math.round(box.width)}×${Math.round(box.height)}`,
157
+ ...(count > 1 ? [`×${count}`] : []),
158
+ ...(pointed === undefined ? [] : [`› ${nameOf(pointed)}`]),
159
+ ];
160
+ // By the component that wrote it, where the page says which: its name alone for its only element, and with
161
+ // the tag for one of several.
162
+ const { component, sole } = named(el);
163
+ const texts = {
164
+ tag: `<${component ?? target.tag}>`,
165
+ inside: component === undefined || sole ? '' : `<${target.tag}>`,
166
+ from: `${target.loc.file}:${target.loc.line}`,
167
+ opens: names.join(' / '),
168
+ };
169
+ const saying = JSON.stringify([texts, dim]);
170
+ if (saying !== said) {
171
+ said = saying;
172
+ caption.replaceChildren(
173
+ part('tag', texts.tag),
174
+ ...(texts.inside === '' ? [] : [part('dim', texts.inside)]),
175
+ part('', texts.from),
176
+ ...dim.map((text) => part('dim', text)),
177
+ ...(names.length === 0 ? [] : [part('opens', texts.opens)]),
178
+ );
179
+ }
180
+ caption.classList.toggle('below', r.top < 40);
181
+ // Kept in the window: a caption is longer than most of what it names.
182
+ caption.style.translate = `${Math.min(0, document.documentElement.clientWidth - 8 - r.left - caption.offsetWidth)}px`;
183
+ aim.classList.add('shown');
184
+ },
185
+ hide() {
186
+ pointing = false;
187
+ aim.classList.remove('shown');
188
+ inner.classList.remove('shown');
189
+ dark();
190
+ },
191
+ hold(element, panel, at) {
192
+ held = true;
193
+ const lit = div('lit');
194
+ lit.innerHTML = LIT;
195
+ root.append(lit);
196
+ const rects = [...lit.querySelectorAll('rect')];
197
+ const paths = [...lit.querySelectorAll('path')];
198
+ const dots = [...lit.querySelectorAll('circle')];
199
+ // A ring that leaves the element as the popup opens on it, once.
200
+ const pulse = reduced() ? undefined : div('pulse');
201
+ if (pulse !== undefined) {
202
+ root.append(pulse);
203
+ pulse.addEventListener('animationend', () => pulse.remove());
204
+ }
205
+
206
+ let frame = 0;
207
+ let was: string | undefined;
208
+ // The first place may be a glide, from the element lit before; after it the light keeps to its element as the
209
+ // page moves it, each frame, with no easing to fall behind by.
210
+ let first = true;
211
+ const settled = setTimeout(() => veil.classList.remove('glide'), GLIDE);
212
+ const follow = () => {
213
+ frame = requestAnimationFrame(follow);
214
+ const on = element.isConnected;
215
+ const e = at === undefined ? grown(element.getBoundingClientRect()) : spotOf(element, at);
216
+ const p = panel.getBoundingClientRect();
217
+ const now = on ? [e.left, e.top, e.width, e.height, p.left, p.top, p.width, p.height].join() : '';
218
+ if (now === was) return;
219
+ was = now;
220
+ lit.classList.toggle('shown', on);
221
+ // An element that's not on the page has nothing to light: the page stays as it is.
222
+ if (!on) return veil.classList.remove('shown');
223
+ const radius = at === undefined ? radiusOf(element, e) : SPOT;
224
+ if (first) light(e, radius, true);
225
+ else place(veil, e);
226
+ veil.style.borderRadius = `${radius}px`;
227
+ if (first && pulse !== undefined) {
228
+ place(pulse, e);
229
+ pulse.style.borderRadius = `${radius}px`;
230
+ }
231
+ first = false;
232
+ for (const rect of rects) {
233
+ for (const [name, value] of Object.entries({ x: e.left, y: e.top, width: e.width, height: e.height, rx: radius }))
234
+ rect.setAttribute(name, String(value));
235
+ }
236
+ // From what of the element is in the window: one scrolled out of it is tied from the edge it left by.
237
+ const width = document.documentElement.clientWidth;
238
+ const height = document.documentElement.clientHeight;
239
+ const [left, right] = [clamp(e.left, 0, width), clamp(e.right, 0, width)];
240
+ const [top, bottom] = [clamp(e.top, 0, height), clamp(e.bottom, 0, height)];
241
+ const tie = tetherOf(new DOMRect(left, top, right - left, bottom - top), p);
242
+ lit.classList.toggle('tied', tie !== undefined);
243
+ if (tie === undefined) return;
244
+ for (const path of paths) path.setAttribute('d', tie.d);
245
+ for (const [i, dot] of dots.entries()) {
246
+ dot.setAttribute('cx', String(tie.ends[i]![0]));
247
+ dot.setAttribute('cy', String(tie.ends[i]![1]));
248
+ }
249
+ };
250
+ follow();
251
+
252
+ // The page dims for what's being done in the popup, and no longer: with the pointer out on the page a
253
+ // moment, it's the page that's looked at, and it gets its light back until the pointer is in the overlay again.
254
+ let lift: ReturnType<typeof setTimeout> | undefined;
255
+ const moved = (e: PointerEvent) => {
256
+ if (!e.composedPath().includes(root.host)) {
257
+ lift ??= setTimeout(() => veil.classList.add('lifted'), LINGER);
258
+ return;
259
+ }
260
+ clearTimeout(lift);
261
+ lift = undefined;
262
+ veil.classList.remove('lifted');
263
+ };
264
+ window.addEventListener('pointermove', moved, { capture: true, passive: true });
265
+
266
+ return () => {
267
+ held = false;
268
+ cancelAnimationFrame(frame);
269
+ clearTimeout(settled);
270
+ clearTimeout(lift);
271
+ window.removeEventListener('pointermove', moved, true);
272
+ lit.remove();
273
+ pulse?.remove();
274
+ veil.classList.remove('lifted');
275
+ dark();
276
+ };
277
+ },
278
+ };
279
+ }