@vinena/knobs 0.5.2 → 0.6.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 (108) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +7 -6
  3. package/dist/context-amfyasb5.js +23 -0
  4. package/dist/context-svtr7vwt.js +22 -0
  5. package/dist/early.global.js +6 -6
  6. package/dist/edit/css.d.ts +59 -0
  7. package/dist/edit/html.d.ts +91 -0
  8. package/dist/edit/keep.d.ts +175 -0
  9. package/dist/edit/log.d.ts +107 -0
  10. package/dist/edit/replay.d.ts +28 -0
  11. package/dist/edit/risk.d.ts +33 -0
  12. package/dist/edit/rule.d.ts +31 -0
  13. package/dist/edit/source.d.ts +12 -0
  14. package/dist/edit/text.d.ts +66 -0
  15. package/dist/elementsview-fyc06wjt.js +3702 -0
  16. package/dist/elementsview-k6zvvcne.js +3701 -0
  17. package/dist/engine/browserdraw.d.ts +5 -0
  18. package/dist/engine/browserkit.d.ts +2 -0
  19. package/dist/engine/devices.d.ts +3 -2
  20. package/dist/engine/dock.d.ts +3 -4
  21. package/dist/engine/frame.d.ts +1 -1
  22. package/dist/engine/frames.d.ts +1 -0
  23. package/dist/engine/identity.d.ts +5 -1
  24. package/dist/engine/index.d.ts +2 -0
  25. package/dist/engine/mock.d.ts +0 -2
  26. package/dist/engine/mockdata.d.ts +4 -3
  27. package/dist/engine/mockdraw.d.ts +2 -14
  28. package/dist/engine/morphrun.d.ts +4 -0
  29. package/dist/engine/native.d.ts +31 -3
  30. package/dist/engine/notice.d.ts +1 -2
  31. package/dist/engine/style.d.ts +15 -0
  32. package/dist/engine/width.d.ts +3 -0
  33. package/dist/{framekit-w0v516w5.js → framekit-622h6w1f.js} +264 -105
  34. package/dist/{framekit-te90cjs0.js → framekit-yx612r28.js} +264 -105
  35. package/dist/index-0zp9py56.js +859 -0
  36. package/dist/{index-9re7sv56.js → index-1mstjadm.js} +126 -2167
  37. package/dist/{index-30fc6php.js → index-4a4x1bt2.js} +1 -1
  38. package/dist/index-58jdczmj.js +44 -0
  39. package/dist/index-5tv6sr74.js +23 -0
  40. package/dist/index-6bc2ztfd.js +688 -0
  41. package/dist/index-7cb4x1vj.js +1885 -0
  42. package/dist/index-a974q3aa.js +34 -0
  43. package/dist/{index-r72tz2vn.js → index-aymfvd8s.js} +1 -1
  44. package/dist/{index-trx7bxdk.js → index-aynkv7qk.js} +11 -8
  45. package/dist/{index-xjhwp5cj.js → index-dzm8ywq0.js} +504 -2362
  46. package/dist/{index-dan2kpsd.js → index-f60yax1j.js} +13 -8
  47. package/dist/index-f67wctn3.js +1858 -0
  48. package/dist/{index-agwr37gw.js → index-ftjdt358.js} +8 -171
  49. package/dist/{index-pewcdh28.js → index-gm51cthv.js} +2 -45
  50. package/dist/index-kfdzsyyw.js +1859 -0
  51. package/dist/index-t4kssacm.js +208 -0
  52. package/dist/index-v0ht9q0g.js +1518 -0
  53. package/dist/{index-sxe5079a.js → index-x59vz1xx.js} +262 -901
  54. package/dist/index-xh39jtkq.js +32 -0
  55. package/dist/index-yb7fc59g.js +718 -0
  56. package/dist/index-zd6adby9.js +496 -0
  57. package/dist/index.d.ts +62 -0
  58. package/dist/index.global.js +447 -160
  59. package/dist/index.js +533 -485
  60. package/dist/react-0wepdf60.js +1519 -0
  61. package/dist/{react-4pvp6amm.js → react-1gqwa2yw.js} +1 -1
  62. package/dist/{index-hv02xka3.js → react-3mfz1x2a.js} +126 -2167
  63. package/dist/react-4rbjw9af.js +33 -0
  64. package/dist/react-5rq7bnsy.js +210 -0
  65. package/dist/react-6bz05qk1.js +860 -0
  66. package/dist/{react-05jh9jv5.js → react-6fnxxs30.js} +8 -171
  67. package/dist/react-6q2cw2ya.js +689 -0
  68. package/dist/{react-sw8d8c94.js → react-6t4dbdzn.js} +11 -8
  69. package/dist/react-88es9b5q.js +719 -0
  70. package/dist/react-97b5b8j4.js +46 -0
  71. package/dist/{react-16spgn0h.js → react-bxzn8vq5.js} +1 -1
  72. package/dist/{react-ayg1bgw3.js → react-cs62p9qh.js} +83 -722
  73. package/dist/react-ethftdxp.js +497 -0
  74. package/dist/react-fp73vhyd.js +36 -0
  75. package/dist/{react-exjcpxma.js → react-me102s1a.js} +2 -45
  76. package/dist/react-t2qnewz2.js +24 -0
  77. package/dist/react-ttj8f9qp.js +1886 -0
  78. package/dist/{react-zy1mmhgz.js → react-v8497a41.js} +13 -8
  79. package/dist/{react-fm9y8dbn.js → react-wqn4sx0n.js} +276 -2133
  80. package/dist/react.js +529 -485
  81. package/dist/replay-j18rw92k.js +258 -0
  82. package/dist/replay-vtg0vqj2.js +257 -0
  83. package/dist/{storageview-s7heg93p.js → storageview-6xj7zb63.js} +11 -7
  84. package/dist/{storageview-r595qpt9.js → storageview-pzn8yaad.js} +11 -7
  85. package/dist/styles/force.d.ts +66 -0
  86. package/dist/types.d.ts +7 -0
  87. package/dist/ui/bindings.d.ts +31 -5
  88. package/dist/ui/changes.d.ts +49 -0
  89. package/dist/ui/cssauto.d.ts +119 -0
  90. package/dist/ui/cssedit.d.ts +80 -0
  91. package/dist/ui/domedit.d.ts +99 -0
  92. package/dist/ui/domtree.d.ts +26 -1
  93. package/dist/ui/elementsview.d.ts +19 -2
  94. package/dist/ui/htmledit.d.ts +62 -0
  95. package/dist/ui/inspector.d.ts +6 -1
  96. package/dist/ui/keys.d.ts +12 -8
  97. package/dist/ui/pane.d.ts +0 -2
  98. package/dist/ui/panel.d.ts +3 -0
  99. package/dist/ui/prefs.d.ts +30 -10
  100. package/dist/ui/settings.d.ts +10 -0
  101. package/dist/ui/size.d.ts +14 -22
  102. package/dist/ui/stylesview.d.ts +30 -1
  103. package/package.json +1 -1
  104. package/skills/devknobs/SKILL.md +95 -0
  105. package/dist/elementsview-2z4pkrdz.js +0 -2873
  106. package/dist/elementsview-qn8qyksa.js +0 -2874
  107. package/dist/index-78r0f8pw.js +0 -27
  108. package/dist/react-adky72h9.js +0 -29
@@ -0,0 +1,1859 @@
1
+ "use client";
2
+ import {
3
+ GRAB_COLORS,
4
+ GRAB_COLOR_NAMES,
5
+ boxTint,
6
+ copyText,
7
+ grabColor,
8
+ isCLike,
9
+ isElement
10
+ } from "./react-v8497a41.js";
11
+ import {
12
+ componentOf,
13
+ escapeText,
14
+ grabContext,
15
+ grabEntry,
16
+ joinEntries,
17
+ quickEntry
18
+ } from "./react-3mfz1x2a.js";
19
+ import"./react-1gqwa2yw.js";
20
+ import {
21
+ shorthand,
22
+ sizeText,
23
+ tidy
24
+ } from "./react-4rbjw9af.js";
25
+ import {
26
+ middle
27
+ } from "./react-6fnxxs30.js";
28
+ import"./react-ethftdxp.js";
29
+ import"./react-5rq7bnsy.js";
30
+ import {
31
+ HOST_RESET,
32
+ LAYER,
33
+ getState,
34
+ holdInTopLayer,
35
+ pause,
36
+ subscribe
37
+ } from "./react-cs62p9qh.js";
38
+ import"./react-ttj8f9qp.js";
39
+ import {
40
+ composedParent,
41
+ grabTargetAt,
42
+ icon,
43
+ isDevknobs,
44
+ isGrabbable
45
+ } from "./react-6q2cw2ya.js";
46
+ import {
47
+ RINGS,
48
+ addStyle,
49
+ alignQuads,
50
+ baseMatchMedia,
51
+ boxModel,
52
+ ensureStyle,
53
+ hasBox,
54
+ isCustomColor,
55
+ isPlain,
56
+ luminance,
57
+ oneQuad,
58
+ parseColor,
59
+ pxOf,
60
+ removeStyle,
61
+ ringPaths,
62
+ ringQuads,
63
+ systemMedia,
64
+ watchSystemMedia
65
+ } from "./react-wqn4sx0n.js";
66
+ import"./react-fp73vhyd.js";
67
+ import"./react-t2qnewz2.js";
68
+
69
+ // src/grab/clipboard.ts
70
+ var DEVKNOBS_TYPE = "application/x-devknobs-grab";
71
+ var REACT_GRAB_TYPE = "application/x-react-grab";
72
+ function clipboardData(payload, now = Date.now()) {
73
+ const entries = payload.entries.map((entry) => ({
74
+ tagName: entry.tagName,
75
+ componentName: entry.componentName,
76
+ content: entry.content,
77
+ source: entry.source,
78
+ stackContext: entry.stackContext,
79
+ frames: entry.frames
80
+ }));
81
+ return {
82
+ "text/plain": payload.content,
83
+ "text/html": `<meta charset='utf-8'><pre><code>${escapeText(payload.content)}</code></pre>`,
84
+ [DEVKNOBS_TYPE]: JSON.stringify({ ...payload, timestamp: now }),
85
+ [REACT_GRAB_TYPE]: JSON.stringify({
86
+ version: "devknobs",
87
+ content: payload.content,
88
+ entries,
89
+ timestamp: now
90
+ })
91
+ };
92
+ }
93
+ function copyGrab(payload) {
94
+ return copyText(payload.content, clipboardData(payload));
95
+ }
96
+
97
+ // src/grab/dwell.ts
98
+ var DWELL = 80;
99
+ var SLOW = 0.3;
100
+ function settles(hover) {
101
+ return !hover.boxed || hover.speed < SLOW || hover.held >= DWELL;
102
+ }
103
+ function speedOf(from, to, elapsed) {
104
+ return Math.hypot(to.x - from.x, to.y - from.y) / Math.max(elapsed, 1);
105
+ }
106
+
107
+ // src/grab/navigate.ts
108
+ var HISTORY = 50;
109
+ function stepOf(event) {
110
+ switch (event.key) {
111
+ case "ArrowUp":
112
+ return "up";
113
+ case "ArrowDown":
114
+ return "down";
115
+ case "ArrowLeft":
116
+ return "left";
117
+ case "ArrowRight":
118
+ return "right";
119
+ case "Tab":
120
+ return event.shiftKey ? "left" : "right";
121
+ default:
122
+ return null;
123
+ }
124
+ }
125
+ function firstChild(element, accept) {
126
+ const children = element.children.length > 0 ? element.children : element.shadowRoot?.children;
127
+ for (const child of Array.from(children ?? []))
128
+ if (accept(child))
129
+ return child;
130
+ return null;
131
+ }
132
+ function createNavigator(accept = isGrabbable) {
133
+ let history = [];
134
+ function up(current) {
135
+ let parent = composedParent(current);
136
+ while (parent && !accept(parent)) {
137
+ const tag = parent.tagName.toLowerCase();
138
+ if (tag === "body" || tag === "html")
139
+ return null;
140
+ parent = composedParent(parent);
141
+ }
142
+ if (!parent)
143
+ return null;
144
+ history.push(current);
145
+ if (history.length > HISTORY)
146
+ history = history.slice(-HISTORY);
147
+ return parent;
148
+ }
149
+ function down(current) {
150
+ const previous = history.pop();
151
+ if (previous?.isConnected)
152
+ return previous;
153
+ history = [];
154
+ return firstChild(current, accept);
155
+ }
156
+ function along(current, forward) {
157
+ const sibling = (element) => forward ? element.nextElementSibling : element.previousElementSibling;
158
+ for (let from = current;from; from = composedParent(from)) {
159
+ const tag = from.tagName.toLowerCase();
160
+ if (tag === "body" || tag === "html")
161
+ return null;
162
+ for (let next = sibling(from);next; next = sibling(next)) {
163
+ if (!accept(next))
164
+ continue;
165
+ history = [];
166
+ return next;
167
+ }
168
+ }
169
+ return null;
170
+ }
171
+ return {
172
+ next(step, current) {
173
+ if (step === "up")
174
+ return up(current);
175
+ if (step === "down")
176
+ return down(current);
177
+ return along(current, step === "right");
178
+ },
179
+ clear() {
180
+ history = [];
181
+ }
182
+ };
183
+ }
184
+
185
+ // src/grab/colorvalue.ts
186
+ var NAMED = {
187
+ black: "#000000",
188
+ silver: "#c0c0c0",
189
+ gray: "#808080",
190
+ grey: "#808080",
191
+ white: "#ffffff",
192
+ maroon: "#800000",
193
+ red: "#ff0000",
194
+ purple: "#800080",
195
+ fuchsia: "#ff00ff",
196
+ green: "#008000",
197
+ lime: "#00ff00",
198
+ olive: "#808000",
199
+ yellow: "#ffff00",
200
+ navy: "#000080",
201
+ blue: "#0000ff",
202
+ teal: "#008080",
203
+ aqua: "#00ffff",
204
+ orange: "#ffa500",
205
+ rebeccapurple: "#663399"
206
+ };
207
+ var WHITE = { red: 255, green: 255, blue: 255, alpha: 1 };
208
+ function hex(value) {
209
+ const match = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(value);
210
+ if (!match?.[1])
211
+ return null;
212
+ const digits = match[1];
213
+ const wide = digits.length <= 4 ? [...digits].map((digit) => digit + digit).join("") : digits;
214
+ const channel = (at) => Number.parseInt(wide.slice(at, at + 2), 16);
215
+ return {
216
+ red: channel(0),
217
+ green: channel(2),
218
+ blue: channel(4),
219
+ alpha: wide.length === 8 ? channel(6) / 255 : 1
220
+ };
221
+ }
222
+ function degrees(value) {
223
+ const number = Number.parseFloat(value);
224
+ if (value.endsWith("turn"))
225
+ return number * 360;
226
+ if (value.endsWith("grad"))
227
+ return number * 0.9;
228
+ if (value.endsWith("rad"))
229
+ return number * 180 / Math.PI;
230
+ return number;
231
+ }
232
+ function hsl(value) {
233
+ const match = /^hsla?\(([^)]+)\)$/i.exec(value);
234
+ if (!match?.[1])
235
+ return null;
236
+ const parts = match[1].split(/[\s,/]+/).filter(Boolean);
237
+ if (parts.length < 3 || parts.length > 4)
238
+ return null;
239
+ const [h = "", s = "", l = "", a] = parts;
240
+ const hue = (degrees(h) % 360 + 360) % 360 / 30;
241
+ const saturation = Math.min(Math.max(Number.parseFloat(s) / 100, 0), 1);
242
+ const lightness = Math.min(Math.max(Number.parseFloat(l) / 100, 0), 1);
243
+ const alpha = a === undefined ? 1 : a.endsWith("%") ? Number.parseFloat(a) / 100 : Number.parseFloat(a);
244
+ if (![hue, saturation, lightness, alpha].every(Number.isFinite))
245
+ return null;
246
+ const reach = saturation * Math.min(lightness, 1 - lightness);
247
+ const channel = (n) => {
248
+ const k = (n + hue) % 12;
249
+ return 255 * (lightness - reach * Math.max(-1, Math.min(k - 3, 9 - k, 1)));
250
+ };
251
+ return { red: channel(0), green: channel(8), blue: channel(4), alpha };
252
+ }
253
+ function parseCss(value) {
254
+ const text = value.trim().toLowerCase();
255
+ if (text === "transparent")
256
+ return { red: 0, green: 0, blue: 0, alpha: 0 };
257
+ const named = Object.hasOwn(NAMED, text) ? NAMED[text] : undefined;
258
+ return hex(named ?? text) ?? hsl(text) ?? parseColor(text);
259
+ }
260
+ function composite(top, under) {
261
+ const alpha = top.alpha + under.alpha * (1 - top.alpha);
262
+ if (alpha <= 0)
263
+ return { red: 0, green: 0, blue: 0, alpha: 0 };
264
+ const mix = (over, below) => (over * top.alpha + below * under.alpha * (1 - top.alpha)) / alpha;
265
+ return {
266
+ red: mix(top.red, under.red),
267
+ green: mix(top.green, under.green),
268
+ blue: mix(top.blue, under.blue),
269
+ alpha
270
+ };
271
+ }
272
+ function byte(channel) {
273
+ return Math.min(255, Math.max(0, Math.round(channel)));
274
+ }
275
+ function shortColor(color) {
276
+ const channels = [byte(color.red), byte(color.green), byte(color.blue)];
277
+ const alpha = Math.round(color.alpha * 100) / 100;
278
+ if (alpha <= 0)
279
+ return "transparent";
280
+ if (alpha >= 1)
281
+ return `#${channels.map((one) => one.toString(16).padStart(2, "0")).join("")}`;
282
+ return `rgb(${channels.join(" ")} / ${alpha})`;
283
+ }
284
+ var WALK_CAP = 20;
285
+ function walkBackgrounds(start, read, parent, cap = WALK_CAP) {
286
+ const found = [];
287
+ let node = start;
288
+ while (node !== null && found.length <= cap) {
289
+ const color = read(node);
290
+ found.push(color);
291
+ if (color && color.alpha >= 1)
292
+ break;
293
+ node = parent(node);
294
+ }
295
+ return found;
296
+ }
297
+ function effectiveBackground(backgrounds) {
298
+ let color = WHITE;
299
+ for (let at = backgrounds.length - 1;at >= 0; at -= 1) {
300
+ const layer = backgrounds[at];
301
+ if (layer && layer.alpha > 0)
302
+ color = composite(layer, color);
303
+ }
304
+ return color;
305
+ }
306
+ function contrastRatio(a, b) {
307
+ const first = luminance(a.red, a.green, a.blue);
308
+ const second = luminance(b.red, b.green, b.blue);
309
+ return (Math.max(first, second) + 0.05) / (Math.min(first, second) + 0.05);
310
+ }
311
+ var LARGE = 24;
312
+ var LARGE_BOLD = 18.66;
313
+ var BOLD = 700;
314
+ function aaRatio(size, weight) {
315
+ return size >= LARGE || size >= LARGE_BOLD && weight >= BOLD ? 3 : 4.5;
316
+ }
317
+ function passesAA(ratio, size, weight) {
318
+ return ratio >= aaRatio(size, weight);
319
+ }
320
+
321
+ // src/grab/card.ts
322
+ var CARD_KEYS = [
323
+ "color",
324
+ "background",
325
+ "font",
326
+ "type",
327
+ "contrast",
328
+ "margin",
329
+ "padding"
330
+ ];
331
+ var CARD_LABELS = {
332
+ color: "color",
333
+ background: "background",
334
+ font: "font",
335
+ type: "",
336
+ contrast: "contrast",
337
+ margin: "margin",
338
+ padding: "padding"
339
+ };
340
+ function colorRow(key, color, quiet = false) {
341
+ const text = shortColor(color);
342
+ return quiet ? { key, text, swatch: text, quiet } : { key, text, swatch: text };
343
+ }
344
+ function cardRows(facts) {
345
+ const rows = [];
346
+ const own = facts.backgrounds[0] ?? null;
347
+ const behind = effectiveBackground(facts.backgrounds);
348
+ if (facts.text && facts.color)
349
+ rows.push(colorRow("color", facts.color));
350
+ if (own && own.alpha > 0)
351
+ rows.push(colorRow("background", own));
352
+ else if (facts.text)
353
+ rows.push(colorRow("background", behind, true));
354
+ if (facts.text) {
355
+ const parts = [`${tidy(facts.fontSize)} / ${tidy(facts.lineHeight)}`, facts.fontWeight];
356
+ if (facts.letterSpacing !== "normal")
357
+ parts.push(tidy(facts.letterSpacing));
358
+ if (facts.family)
359
+ rows.push({ key: "font", text: facts.family });
360
+ rows.push({ key: facts.family ? "type" : "font", text: parts.join(" · ") });
361
+ if (facts.color) {
362
+ const ratio = contrastRatio(composite(facts.color, behind), behind);
363
+ const size = pxOf(facts.fontSize) ?? 16;
364
+ const weight = Number.parseFloat(facts.fontWeight) || 400;
365
+ rows.push({ key: "contrast", text: ratio.toFixed(2), pass: passesAA(ratio, size, weight) });
366
+ }
367
+ }
368
+ const margin = shorthand(facts.margin);
369
+ if (margin)
370
+ rows.push({ key: "margin", text: margin });
371
+ const padding = shorthand(facts.padding);
372
+ if (padding)
373
+ rows.push({ key: "padding", text: padding });
374
+ return rows;
375
+ }
376
+
377
+ // src/grab/fontused.ts
378
+ var GENERIC = new Set([
379
+ "serif",
380
+ "sans-serif",
381
+ "monospace",
382
+ "cursive",
383
+ "fantasy",
384
+ "system-ui",
385
+ "ui-serif",
386
+ "ui-sans-serif",
387
+ "ui-monospace",
388
+ "ui-rounded",
389
+ "math",
390
+ "emoji",
391
+ "fangsong",
392
+ "-apple-system",
393
+ "blinkmacsystemfont"
394
+ ]);
395
+ function families(stack) {
396
+ const found = [];
397
+ let name = "";
398
+ let quote = "";
399
+ for (const char of stack) {
400
+ if (quote) {
401
+ if (char === quote)
402
+ quote = "";
403
+ else
404
+ name += char;
405
+ } else if (char === '"' || char === "'")
406
+ quote = char;
407
+ else if (char === ",") {
408
+ found.push(name.trim());
409
+ name = "";
410
+ } else
411
+ name += char;
412
+ }
413
+ found.push(name.trim());
414
+ return found.filter((family) => family !== "");
415
+ }
416
+ function isGeneric(family) {
417
+ return GENERIC.has(family.toLowerCase());
418
+ }
419
+ function usedFamily(stack, available) {
420
+ return families(stack).find((family) => isGeneric(family) || available(family)) ?? null;
421
+ }
422
+ function fontCheck(fonts) {
423
+ return (family) => {
424
+ if (!fonts)
425
+ return false;
426
+ try {
427
+ return fonts.check(`16px "${family.replace(/["\\]/g, "\\$&")}"`);
428
+ } catch {
429
+ return false;
430
+ }
431
+ };
432
+ }
433
+
434
+ // src/grab/cardread.ts
435
+ var TEXT_CAP = 40;
436
+ var TEXT_CONTROLS = new Set(["INPUT", "TEXTAREA", "SELECT"]);
437
+ function parentOf(element) {
438
+ if (element.parentElement)
439
+ return element.parentElement;
440
+ const root = element.getRootNode();
441
+ return root instanceof ShadowRoot ? root.host : null;
442
+ }
443
+ function hasOwnText(element) {
444
+ if (TEXT_CONTROLS.has(element.tagName))
445
+ return true;
446
+ const nodes = element.childNodes;
447
+ for (let at = 0;at < nodes.length && at < TEXT_CAP; at += 1) {
448
+ const node = nodes[at];
449
+ if (node?.nodeType === 3 && (node.textContent ?? "").trim() !== "")
450
+ return true;
451
+ }
452
+ return false;
453
+ }
454
+ function readFacts(element, style, colorOf) {
455
+ const text = hasOwnText(element);
456
+ return {
457
+ text,
458
+ color: colorOf(style.color),
459
+ backgrounds: walkBackgrounds(element, (node) => colorOf((node === element ? style : getComputedStyle(node)).backgroundColor), parentOf),
460
+ family: text ? usedFamily(style.fontFamily, fontCheck(element.ownerDocument.fonts)) : null,
461
+ fontSize: style.fontSize,
462
+ lineHeight: style.lineHeight,
463
+ fontWeight: style.fontWeight,
464
+ letterSpacing: style.letterSpacing
465
+ };
466
+ }
467
+ function quadsOf(element, bounds) {
468
+ const read = Reflect.get(element, "getBoxQuads");
469
+ if (typeof read !== "function")
470
+ return null;
471
+ const found = new Map;
472
+ for (const ring of RINGS) {
473
+ let answer = null;
474
+ try {
475
+ answer = Reflect.apply(read, element, [{ box: ring }]);
476
+ } catch {
477
+ return null;
478
+ }
479
+ const quad = oneQuad(answer);
480
+ if (!quad)
481
+ return null;
482
+ found.set(ring, quad);
483
+ }
484
+ const [margin, border, padding, content] = RINGS.map((ring) => found.get(ring));
485
+ if (!margin || !border || !padding || !content)
486
+ return null;
487
+ const laid = element instanceof HTMLElement ? { width: element.offsetWidth, height: element.offsetHeight } : null;
488
+ if (isPlain(border, laid))
489
+ return null;
490
+ return alignQuads({ margin, border, padding, content }, { x: bounds.left, y: bounds.top });
491
+ }
492
+ function readBox(element, style) {
493
+ const bounds = element.getBoundingClientRect();
494
+ if (!hasBox(style.display, bounds))
495
+ return null;
496
+ return { model: boxModel(style), quads: quadsOf(element, bounds) };
497
+ }
498
+
499
+ // src/grab/cardview.ts
500
+ function span(className, text = "") {
501
+ const node = document.createElement("span");
502
+ node.className = className;
503
+ if (text)
504
+ node.textContent = text;
505
+ return node;
506
+ }
507
+ function say(node, text) {
508
+ if (node.textContent !== text)
509
+ node.textContent = text;
510
+ }
511
+ function show(node, on) {
512
+ if (node.hidden === on)
513
+ node.hidden = !on;
514
+ }
515
+ function mark(className, name) {
516
+ const node = span(className);
517
+ node.append(icon(name, 12));
518
+ node.hidden = true;
519
+ return node;
520
+ }
521
+ function createCardView() {
522
+ const size = span("size");
523
+ const rows = document.createElement("div");
524
+ rows.className = "rows";
525
+ rows.hidden = true;
526
+ const nodes = new Map;
527
+ for (const key of CARD_KEYS) {
528
+ const node = document.createElement("div");
529
+ node.className = "info";
530
+ node.hidden = true;
531
+ const value = span("val");
532
+ const swatch = span("dot");
533
+ swatch.hidden = true;
534
+ const pass = mark("mark", "check");
535
+ const fail = mark("mark fail", "x");
536
+ const text = span("text");
537
+ value.append(swatch, text, pass, fail);
538
+ node.append(span("key", CARD_LABELS[key]), value);
539
+ rows.append(node);
540
+ nodes.set(key, { node, swatch, pass, fail, text });
541
+ }
542
+ function write(sized, next) {
543
+ say(size, sized);
544
+ const shown = [];
545
+ for (const key of CARD_KEYS) {
546
+ const parts = nodes.get(key);
547
+ if (!parts)
548
+ continue;
549
+ const row = next.find((one) => one.key === key);
550
+ show(parts.node, row !== undefined);
551
+ if (!row)
552
+ continue;
553
+ shown.push(key);
554
+ say(parts.text, row.text);
555
+ const quiet = row.quiet ? "text quiet" : "text";
556
+ if (parts.text.className !== quiet)
557
+ parts.text.className = quiet;
558
+ show(parts.swatch, row.swatch !== undefined);
559
+ if (row.swatch !== undefined)
560
+ parts.swatch.style.backgroundColor = row.swatch;
561
+ show(parts.pass, row.pass === true);
562
+ show(parts.fail, row.pass === false);
563
+ }
564
+ show(rows, shown.length > 0);
565
+ return shown.join(" ");
566
+ }
567
+ return { size, rows, write };
568
+ }
569
+
570
+ // src/grab/paint.ts
571
+ function createColorReader() {
572
+ const colors = new Map;
573
+ let context;
574
+ function paint(value) {
575
+ if (!CSS.supports("color", value))
576
+ return null;
577
+ if (context === undefined) {
578
+ const canvas = document.createElement("canvas");
579
+ canvas.width = 1;
580
+ canvas.height = 1;
581
+ context = canvas.getContext("2d", { willReadFrequently: true });
582
+ }
583
+ if (!context)
584
+ return null;
585
+ context.clearRect(0, 0, 1, 1);
586
+ context.fillStyle = value;
587
+ context.fillRect(0, 0, 1, 1);
588
+ const [red = 0, green = 0, blue = 0, alpha = 0] = context.getImageData(0, 0, 1, 1).data;
589
+ return { red, green, blue, alpha: alpha / 255 };
590
+ }
591
+ return (value) => {
592
+ let color = colors.get(value);
593
+ if (color === undefined) {
594
+ color = parseCss(value) ?? paint(value);
595
+ colors.set(value, color);
596
+ }
597
+ return color;
598
+ };
599
+ }
600
+
601
+ // src/grab/theme.ts
602
+ var DARK_BACKGROUND = 0.18;
603
+ var LIGHT_TEXT = 0.6;
604
+ var SOLID = 0.5;
605
+ var THEME_ATTRIBUTES = [
606
+ "data-theme",
607
+ "data-mode",
608
+ "data-color-scheme",
609
+ "data-bs-theme",
610
+ "data-mui-color-scheme",
611
+ "data-mantine-color-scheme"
612
+ ];
613
+ function backgroundTheme(color) {
614
+ if (!color || color.alpha <= SOLID)
615
+ return null;
616
+ return luminance(color.red, color.green, color.blue) < DARK_BACKGROUND ? "dark" : "light";
617
+ }
618
+ function textTheme(color) {
619
+ if (!color || color.alpha <= SOLID)
620
+ return null;
621
+ return luminance(color.red, color.green, color.blue) > LIGHT_TEXT ? "dark" : null;
622
+ }
623
+ function markerTheme(hasClass, attribute) {
624
+ if (hasClass("dark"))
625
+ return "dark";
626
+ if (hasClass("light"))
627
+ return "light";
628
+ for (const name of THEME_ATTRIBUTES) {
629
+ const value = attribute(name)?.toLowerCase();
630
+ if (value === "dark" || value === "light")
631
+ return value;
632
+ }
633
+ if (attribute("data-dark") !== null)
634
+ return "dark";
635
+ if (attribute("data-light") !== null)
636
+ return "light";
637
+ return null;
638
+ }
639
+ function schemeTheme(value) {
640
+ const tokens = value.trim().toLowerCase().split(/\s+/);
641
+ const dark = tokens.includes("dark");
642
+ if (dark === tokens.includes("light"))
643
+ return null;
644
+ return dark ? "dark" : "light";
645
+ }
646
+ function decideTheme(signals) {
647
+ return signals.surface ?? signals.marker ?? signals.scheme ?? signals.backdrop ?? signals.text ?? "light";
648
+ }
649
+ var BLUE_HUES = [190, 260];
650
+ var BLUE_SATURATION = 0.35;
651
+ var BLUE_LIGHTNESS = [0.15, 0.85];
652
+ function toHsl(color) {
653
+ const red = color.red / 255;
654
+ const green = color.green / 255;
655
+ const blue = color.blue / 255;
656
+ const high = Math.max(red, green, blue);
657
+ const low = Math.min(red, green, blue);
658
+ const spread = high - low;
659
+ const lightness = (high + low) / 2;
660
+ if (spread === 0)
661
+ return { hue: 0, saturation: 0, lightness };
662
+ const saturation = spread / (1 - Math.abs(2 * lightness - 1));
663
+ let hue;
664
+ if (high === red)
665
+ hue = (green - blue) / spread % 6;
666
+ else if (high === green)
667
+ hue = (blue - red) / spread + 2;
668
+ else
669
+ hue = (red - green) / spread + 4;
670
+ return { hue: (hue * 60 + 360) % 360, saturation, lightness };
671
+ }
672
+ function isBlue(color) {
673
+ if (!color || color.alpha <= SOLID)
674
+ return false;
675
+ const { hue, saturation, lightness } = toHsl(color);
676
+ return hue >= BLUE_HUES[0] && hue <= BLUE_HUES[1] && saturation > BLUE_SATURATION && lightness >= BLUE_LIGHTNESS[0] && lightness <= BLUE_LIGHTNESS[1];
677
+ }
678
+ function decideGrab(signals) {
679
+ if (isBlue(signals.surface))
680
+ return "green";
681
+ const clear = !signals.own || signals.own.alpha <= SOLID;
682
+ if (clear && (isBlue(signals.border) || isBlue(signals.text)))
683
+ return "green";
684
+ return "blue";
685
+ }
686
+ function invertTheme(theme) {
687
+ return theme === "dark" ? "light" : "dark";
688
+ }
689
+ function createThemeReader() {
690
+ const surfaces = new WeakMap;
691
+ const tones = new WeakMap;
692
+ const colorOf = createColorReader();
693
+ let page = null;
694
+ function parentOf2(element) {
695
+ if (element.parentElement)
696
+ return element.parentElement;
697
+ const root = element.getRootNode();
698
+ return root instanceof ShadowRoot ? root.host : null;
699
+ }
700
+ function solid(color) {
701
+ return color && color.alpha > SOLID ? color : null;
702
+ }
703
+ function surfaceOf(element) {
704
+ const walked = [];
705
+ let found = null;
706
+ let node = element;
707
+ while (node && node !== document.body && node !== document.documentElement) {
708
+ const known = surfaces.get(node);
709
+ if (known !== undefined) {
710
+ found = known;
711
+ break;
712
+ }
713
+ walked.push(node);
714
+ found = solid(colorOf(getComputedStyle(node).backgroundColor));
715
+ if (found)
716
+ break;
717
+ node = parentOf2(node);
718
+ }
719
+ for (const each of walked)
720
+ surfaces.set(each, found);
721
+ return found;
722
+ }
723
+ function first(roots, read) {
724
+ for (const root of roots) {
725
+ const value = root ? read(root) : null;
726
+ if (value)
727
+ return value;
728
+ }
729
+ return null;
730
+ }
731
+ function readPage() {
732
+ const html = document.documentElement;
733
+ const body = document.body;
734
+ const meta = document.querySelector('meta[name="color-scheme"]')?.getAttribute("content");
735
+ const backdrop = first([body, html], (root) => solid(colorOf(getComputedStyle(root).backgroundColor)));
736
+ const signals = {
737
+ marker: first([html, body], (root) => markerTheme((name) => root.classList.contains(name), (name) => root.getAttribute(name))),
738
+ scheme: first([html, body], (root) => schemeTheme(root.style.colorScheme || getComputedStyle(root).colorScheme)) ?? schemeTheme(meta ?? ""),
739
+ backdrop: backgroundTheme(backdrop),
740
+ text: textTheme(colorOf(getComputedStyle(html).color))
741
+ };
742
+ return { signals, backdrop };
743
+ }
744
+ function toneOf(element, surface) {
745
+ let tone = tones.get(element);
746
+ if (tone === undefined) {
747
+ const style = getComputedStyle(element);
748
+ tone = decideGrab({
749
+ surface,
750
+ own: colorOf(style.backgroundColor),
751
+ border: Number.parseFloat(style.borderTopWidth) > 0 ? colorOf(style.borderTopColor) : null,
752
+ text: colorOf(style.color)
753
+ });
754
+ tones.set(element, tone);
755
+ }
756
+ return tone;
757
+ }
758
+ return (element) => {
759
+ page ??= readPage();
760
+ const near = element ? surfaceOf(element) : null;
761
+ const surface = near ?? page.backdrop;
762
+ return {
763
+ theme: decideTheme({ surface: backgroundTheme(near), ...page.signals }),
764
+ grab: element ? toneOf(element, surface) : decideGrab({ surface, own: null, border: null, text: null })
765
+ };
766
+ };
767
+ }
768
+
769
+ // src/grab/overlay.ts
770
+ var Z_INDEX = 2147483646;
771
+ var HOST_CSS = `
772
+ :host([popover]) {
773
+ inset: 0 !important;
774
+ width: auto !important;
775
+ height: auto !important;
776
+ pointer-events: none !important;
777
+ }`;
778
+ var GAP = 6;
779
+ var MARGIN = 8;
780
+ var MIN_RADIUS = 2;
781
+ var LERP = 0.3;
782
+ var FRAME = 1000 / 60;
783
+ var SNAP = 0.5;
784
+ var FADE = 125;
785
+ var HIDE_WAIT = 100;
786
+ var SYNC_EVERY = 100;
787
+ var TOAST_TIME = 1500;
788
+ var TOAST_FADE = 100;
789
+ var MAX_WIDTH = 280;
790
+ var CARD_WIDTH = 264;
791
+ var CARD_HEIGHT = 180;
792
+ var NAME_MAX = 26;
793
+ function over(top, under) {
794
+ return 100 - (100 - top) * (100 - under) / 100;
795
+ }
796
+ function colorRules(gamut) {
797
+ return GRAB_COLOR_NAMES.map((name) => `.layer[data-grab="${name}"] { --grab: ${GRAB_COLORS[name][gamut]}; }`).join(`
798
+ `);
799
+ }
800
+ var CSS2 = `
801
+ .layer {
802
+ all: initial;
803
+ position: fixed;
804
+ inset: 0;
805
+ overflow: hidden;
806
+ contain: strict;
807
+ pointer-events: none;
808
+ direction: ltr;
809
+ --grab: ${GRAB_COLORS.blue.srgb};
810
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
811
+ font-size: 13px;
812
+ font-weight: 400;
813
+ line-height: 16px;
814
+ -webkit-font-smoothing: antialiased;
815
+ }
816
+ ${colorRules("srgb")}
817
+ @media (color-gamut: p3) {
818
+ ${colorRules("p3")}
819
+ }
820
+ .glow {
821
+ position: absolute;
822
+ inset: 0;
823
+ opacity: 0;
824
+ box-shadow: inset 0 0 50px color-mix(in srgb, var(--grab) 15%, transparent);
825
+ transition: opacity ${FADE}ms ease-out, box-shadow ${FADE}ms ease-out;
826
+ }
827
+ .glow.on { opacity: 1; }
828
+ .glide, .part {
829
+ position: absolute;
830
+ top: 0;
831
+ left: 0;
832
+ transform-origin: 0 0;
833
+ will-change: transform;
834
+ }
835
+ .fills > .part, .lines > .part {
836
+ width: var(--unit);
837
+ height: var(--unit);
838
+ background-color: currentColor;
839
+ }
840
+ .box {
841
+ opacity: 0;
842
+ will-change: opacity;
843
+ --line: color-mix(in srgb, var(--grab) 50%, transparent);
844
+ --fill: color-mix(in srgb, var(--grab) 8%, transparent);
845
+ --edge: color-mix(in srgb, var(--grab) ${over(50, 8)}%, transparent);
846
+ transition: opacity ${FADE}ms ease-out;
847
+ }
848
+ .box.on { opacity: 1; }
849
+ .box.copied {
850
+ --line: color-mix(in srgb, var(--grab) 60%, transparent);
851
+ --fill: color-mix(in srgb, var(--grab) 20%, transparent);
852
+ --edge: color-mix(in srgb, var(--grab) ${over(60, 20)}%, transparent);
853
+ }
854
+ .fills, .lines, .corners { transition: color ${FADE}ms ease-out; }
855
+ .fills { color: var(--fill); }
856
+ .lines { color: var(--edge); }
857
+ .corners { color: var(--line); }
858
+ .corner {
859
+ box-sizing: border-box;
860
+ width: var(--corner-width);
861
+ height: var(--corner-height);
862
+ border: 0 solid;
863
+ background-color: var(--fill);
864
+ transition: background-color ${FADE}ms ease-out;
865
+ }
866
+ .top > .corner { border-top-width: 1px; }
867
+ .bottom > .corner { border-bottom-width: 1px; }
868
+ .left > .corner { border-left-width: 1px; }
869
+ .right > .corner { border-right-width: 1px; }
870
+ .top.left > .corner { border-top-left-radius: var(--corner-radius); }
871
+ .top.right > .corner { border-top-right-radius: var(--corner-radius); }
872
+ .bottom.left > .corner { border-bottom-left-radius: var(--corner-radius); }
873
+ .bottom.right > .corner { border-bottom-right-radius: var(--corner-radius); }
874
+ .pick {
875
+ position: absolute;
876
+ top: 0;
877
+ left: 0;
878
+ box-sizing: border-box;
879
+ will-change: transform;
880
+ border: 1px solid color-mix(in srgb, var(--grab) 30%, transparent);
881
+ border-radius: ${MIN_RADIUS}px;
882
+ background: color-mix(in srgb, var(--grab) 5%, transparent);
883
+ transition: border-color ${FADE}ms ease-out, background-color ${FADE}ms ease-out;
884
+ }
885
+ .tint {
886
+ position: absolute;
887
+ inset: 0;
888
+ opacity: 0;
889
+ transition: opacity ${FADE}ms ease-out;
890
+ }
891
+ .tint.on { opacity: 1; }
892
+ ${RINGS.map((ring) => `.tint.${ring} { background: ${boxTint(ring)}; }`).join(`
893
+ `)}
894
+ .tip {
895
+ position: absolute;
896
+ inset: 0;
897
+ will-change: transform;
898
+ }
899
+ .pill {
900
+ position: absolute;
901
+ top: 0;
902
+ left: 0;
903
+ display: flex;
904
+ align-items: center;
905
+ gap: 6px;
906
+ max-width: min(${MAX_WIDTH}px, calc(100% - ${2 * MARGIN}px));
907
+ box-sizing: border-box;
908
+ padding: 6px 8px;
909
+ white-space: nowrap;
910
+ opacity: 0;
911
+ --bar: #161616;
912
+ --quiet: #a7a7a7;
913
+ color: #ffffff;
914
+ background: var(--bar);
915
+ border-radius: 6px;
916
+ box-shadow: 0 0 0 1px rgb(255 255 255 / 12%), 0 2px 8px rgb(0 0 0 / 24%);
917
+ transition: opacity ${FADE}ms ease-out;
918
+ }
919
+ .pill.on { opacity: 1; }
920
+ .pill.toast.on { transition: opacity ${TOAST_FADE}ms ease-out; }
921
+ .pill span {
922
+ min-width: 0;
923
+ overflow: hidden;
924
+ text-overflow: ellipsis;
925
+ }
926
+ .check {
927
+ flex: none;
928
+ margin-right: -2px;
929
+ opacity: 0.85;
930
+ }
931
+ .check circle { fill: currentColor; }
932
+ .check path {
933
+ fill: none;
934
+ stroke: var(--bar);
935
+ stroke-width: 1.5;
936
+ stroke-linecap: round;
937
+ stroke-linejoin: round;
938
+ }
939
+ .pill .tag { flex: none; color: #a7a7a7; }
940
+ .pill[data-bar="light"] {
941
+ --bar: #ffffff;
942
+ --quiet: #737373;
943
+ color: #171717;
944
+ box-shadow: 0 0 0 1px rgb(0 0 0 / 10%), 0 2px 8px rgb(0 0 0 / 32%);
945
+ }
946
+ .pill[data-bar="light"] .tag { color: #737373; }
947
+ /* Inspect's card: the label grown to a few rows, one width whatever it says. */
948
+ .pill.card {
949
+ display: block;
950
+ width: ${CARD_WIDTH}px;
951
+ max-height: ${CARD_HEIGHT}px;
952
+ overflow: hidden;
953
+ padding: 8px;
954
+ border-radius: 8px;
955
+ }
956
+ .card .head { display: flex; align-items: center; gap: 6px; }
957
+ .card .size, .card .val {
958
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
959
+ font-size: 11px;
960
+ font-variant-numeric: tabular-nums;
961
+ }
962
+ .card .size { flex: none; margin-left: auto; color: var(--quiet); }
963
+ .card .rows { display: grid; gap: 2px; margin-top: 6px; }
964
+ .card .info { display: flex; align-items: center; gap: 12px; }
965
+ .card .key { flex: none; font-size: 11px; color: var(--quiet); }
966
+ .card .val { display: flex; align-items: center; gap: 5px; min-width: 0; margin-left: auto; }
967
+ .card .quiet { color: var(--quiet); }
968
+ .card .dot {
969
+ flex: none;
970
+ width: 9px;
971
+ height: 9px;
972
+ border-radius: 2px;
973
+ box-shadow: inset 0 0 0 1px rgb(128 128 128 / 45%);
974
+ }
975
+ .card .mark { flex: none; display: grid; overflow: visible; }
976
+ .card .mark.fail { color: var(--quiet); }
977
+ .layer [hidden] { display: none; }
978
+ .layer[data-still] * { transition: none; }
979
+ `;
980
+ function clamp(value, low, high) {
981
+ return Math.min(Math.max(value, low), Math.max(low, high));
982
+ }
983
+ function tweenStep(from, to, elapsed, reduce) {
984
+ const share = reduce ? 1 : 1 - (1 - LERP) ** (Math.max(elapsed, 1) / FRAME);
985
+ const values = to.map((end, index) => {
986
+ const start = from[index] ?? end;
987
+ return start + (end - start) * share;
988
+ });
989
+ const done = values.every((value, index) => Math.abs((to[index] ?? value) - value) < SNAP);
990
+ return done ? { values: [...to], done } : { values, done };
991
+ }
992
+ function labelPlace(box, pill, view, pointerX) {
993
+ const anchor = pointerX === null ? (box.left + box.right) / 2 : clamp(pointerX, box.left, box.right);
994
+ const x = clamp(anchor - pill.width / 2, MARGIN, view.width - pill.width - MARGIN);
995
+ let y = box.bottom + GAP;
996
+ if (y + pill.height > view.height - MARGIN)
997
+ y = box.top - pill.height - GAP;
998
+ y = clamp(y, MARGIN, view.height - pill.height - MARGIN);
999
+ return { x, y };
1000
+ }
1001
+ function cardPlace(box, card, view) {
1002
+ const { y } = labelPlace(box, card, view, null);
1003
+ return { x: clamp(box.left, MARGIN, view.width - card.width - MARGIN), y };
1004
+ }
1005
+ function parseRadius(value) {
1006
+ const match = /(\d*\.?\d+)px/.exec(value);
1007
+ return match ? Number(match[1]) : 0;
1008
+ }
1009
+ function boxRadius(radius, width, height) {
1010
+ return Math.max(MIN_RADIUS, Math.min(radius, Math.min(width, height) / 2));
1011
+ }
1012
+ var CORNERS = ["top right", "bottom left", "bottom right"];
1013
+ var LINES = ["top", "bottom", "left", "right"];
1014
+ var FILLS = ["middle", "west", "east"];
1015
+ function snap(value, ratio) {
1016
+ return Math.round(value * ratio) / ratio;
1017
+ }
1018
+ function onPixels(shape, ratio) {
1019
+ const [x = 0, y = 0, width = 0, height = 0] = shape;
1020
+ const left = snap(x, ratio);
1021
+ const top = snap(y, ratio);
1022
+ return [left, top, snap(x + width, ratio) - left, snap(y + height, ratio) - top];
1023
+ }
1024
+ function boxParts(shape, radius, ratio) {
1025
+ const [x, y, wide, tall] = onPixels(shape, ratio);
1026
+ const line = Math.max(1, Math.floor(ratio)) / ratio;
1027
+ const width = Math.max(wide, 2 * line);
1028
+ const height = Math.max(tall, 2 * line);
1029
+ const round = Math.min(radius, width / 2, height / 2);
1030
+ const reach = Math.max(Math.ceil(round * ratio - 0.000001) / ratio, line);
1031
+ const cornerWidth = Math.min(reach, Math.floor(width / 2 * ratio + 0.000001) / ratio);
1032
+ const cornerHeight = Math.min(reach, Math.floor(height / 2 * ratio + 0.000001) / ratio);
1033
+ const right = width - cornerWidth;
1034
+ const bottom = height - cornerHeight;
1035
+ const acrossBy = width - 2 * cornerWidth;
1036
+ const downBy = height - 2 * cornerHeight;
1037
+ const sideBy = cornerWidth - line;
1038
+ const whole = (length) => Math.round(length * ratio);
1039
+ const part = (left, top, across, down) => `translate(${left}px, ${top}px) scale(${whole(across)}, ${whole(down)})`;
1040
+ return {
1041
+ at: `translate(${x}px, ${y}px)`,
1042
+ unit: 1 / ratio,
1043
+ corner: { width: cornerWidth, height: cornerHeight, radius: round },
1044
+ pieces: {
1045
+ "top right": `translate(${right}px, 0px)`,
1046
+ "bottom left": `translate(0px, ${bottom}px)`,
1047
+ "bottom right": `translate(${right}px, ${bottom}px)`,
1048
+ top: part(cornerWidth, 0, acrossBy, line),
1049
+ bottom: part(cornerWidth, height - line, acrossBy, line),
1050
+ left: part(0, cornerHeight, line, downBy),
1051
+ right: part(width - line, cornerHeight, line, downBy),
1052
+ middle: part(cornerWidth, line, acrossBy, height - 2 * line),
1053
+ west: part(line, cornerHeight, sideBy, downBy),
1054
+ east: part(right, cornerHeight, sideBy, downBy)
1055
+ }
1056
+ };
1057
+ }
1058
+ var SVG = "http://www.w3.org/2000/svg";
1059
+ function checkIcon() {
1060
+ const icon2 = document.createElementNS(SVG, "svg");
1061
+ icon2.setAttribute("class", "check");
1062
+ icon2.setAttribute("width", "14");
1063
+ icon2.setAttribute("height", "14");
1064
+ icon2.setAttribute("viewBox", "0 0 14 14");
1065
+ icon2.setAttribute("aria-hidden", "true");
1066
+ const disc = document.createElementNS(SVG, "circle");
1067
+ disc.setAttribute("cx", "7");
1068
+ disc.setAttribute("cy", "7");
1069
+ disc.setAttribute("r", "6");
1070
+ const mark2 = document.createElementNS(SVG, "path");
1071
+ mark2.setAttribute("d", "M4.4 7.2 6.2 9l3.4-3.8");
1072
+ icon2.append(disc, mark2);
1073
+ return icon2;
1074
+ }
1075
+ var written = new WeakMap;
1076
+ function write(node, name, value) {
1077
+ let styles = written.get(node);
1078
+ if (!styles) {
1079
+ styles = new Map;
1080
+ written.set(node, styles);
1081
+ }
1082
+ if (styles.get(name) === value)
1083
+ return;
1084
+ styles.set(name, value);
1085
+ node.style.setProperty(name, value);
1086
+ }
1087
+ function place(node, shape, ratio) {
1088
+ const [x, y, width, height] = onPixels(shape, ratio);
1089
+ write(node, "transform", `translate(${x}px, ${y}px)`);
1090
+ write(node, "width", `${width}px`);
1091
+ write(node, "height", `${height}px`);
1092
+ write(node, "border-radius", `${shape[4] ?? 0}px`);
1093
+ }
1094
+ function createOverlay(quiet = false, model = false) {
1095
+ const host = document.createElement("div");
1096
+ host.setAttribute("data-devknobs", "grab");
1097
+ host.style.cssText = `position:fixed;inset:0;width:auto;height:auto;pointer-events:none;z-index:${Z_INDEX}`;
1098
+ const root = host.attachShadow({ mode: "open" });
1099
+ addStyle(root, HOST_RESET + HOST_CSS + CSS2);
1100
+ const layer = document.createElement("div");
1101
+ layer.className = "layer";
1102
+ const glow = document.createElement("div");
1103
+ glow.className = "glow";
1104
+ const glide = document.createElement("div");
1105
+ glide.className = "glide";
1106
+ const box = document.createElement("div");
1107
+ box.className = "box";
1108
+ glide.append(box);
1109
+ const pieces = [];
1110
+ function group(name2, names) {
1111
+ const parent = document.createElement("div");
1112
+ parent.className = name2;
1113
+ for (const piece of names) {
1114
+ const node = document.createElement("div");
1115
+ node.className = `part ${piece}`;
1116
+ if (name2 === "corners") {
1117
+ const corner = document.createElement("div");
1118
+ corner.className = "corner";
1119
+ node.append(corner);
1120
+ }
1121
+ parent.append(node);
1122
+ if (piece !== "top left")
1123
+ pieces.push({ piece, node });
1124
+ }
1125
+ box.append(parent);
1126
+ }
1127
+ group("fills", FILLS);
1128
+ group("lines", LINES);
1129
+ group("corners", ["top left", ...CORNERS]);
1130
+ const tip = document.createElement("div");
1131
+ tip.className = "tip";
1132
+ const label = document.createElement("div");
1133
+ label.className = "pill";
1134
+ tip.append(label);
1135
+ const check = checkIcon();
1136
+ const tag = document.createElement("span");
1137
+ tag.className = "tag";
1138
+ const name = document.createElement("span");
1139
+ const card = model && !quiet ? createCardView() : null;
1140
+ if (card) {
1141
+ const head = document.createElement("div");
1142
+ head.className = "head";
1143
+ head.append(check, tag, name, card.size);
1144
+ label.classList.add("card");
1145
+ label.append(head, card.rows);
1146
+ } else
1147
+ label.append(check, tag, name);
1148
+ const picks = [];
1149
+ const tints = (model ? RINGS : []).map((ring) => {
1150
+ const node = document.createElement("div");
1151
+ node.className = `tint ${ring}`;
1152
+ layer.append(node);
1153
+ return { ring, node };
1154
+ });
1155
+ layer.append(glow, glide, tip);
1156
+ root.append(layer);
1157
+ (document.body ?? document.documentElement).append(host);
1158
+ const hold = holdInTopLayer(host, LAYER.overlay);
1159
+ const reduce = baseMatchMedia("(prefers-reduced-motion: reduce)");
1160
+ let reduced = reduce.matches;
1161
+ const radii = new WeakMap;
1162
+ const read = createThemeReader();
1163
+ const sizes = new Map;
1164
+ let color = getState().grabColor;
1165
+ let tone = "blue";
1166
+ let bar = null;
1167
+ let element = null;
1168
+ let measured = null;
1169
+ let picked = [];
1170
+ let shapes = [];
1171
+ let at = null;
1172
+ let target = null;
1173
+ let labelAt = null;
1174
+ let shown = false;
1175
+ let stale = false;
1176
+ let pointerX = null;
1177
+ let text = { tag: "", name: null };
1178
+ let checked = false;
1179
+ let sized = null;
1180
+ let size = { width: 0, height: 0 };
1181
+ const styles = new WeakMap;
1182
+ const colorOf = createColorReader();
1183
+ let rings = null;
1184
+ let ringsAt = null;
1185
+ let only = null;
1186
+ let facts = null;
1187
+ let factsTimer = 0;
1188
+ let rows = [];
1189
+ let toasting = false;
1190
+ let closing = false;
1191
+ let removed = false;
1192
+ let frame = 0;
1193
+ let last = 0;
1194
+ let hideTimer = 0;
1195
+ let toastTimer = 0;
1196
+ let fadeTimer = 0;
1197
+ function fade() {
1198
+ return reduced ? 0 : FADE;
1199
+ }
1200
+ function still() {
1201
+ const own = systemMedia();
1202
+ reduced = own ? own.motion === "reduce" : reduce.matches;
1203
+ layer.toggleAttribute("data-still", reduced);
1204
+ }
1205
+ function paint() {
1206
+ const name2 = grabColor(color, tone);
1207
+ if (layer.dataset.grab !== name2) {
1208
+ layer.dataset.grab = name2;
1209
+ if (isCustomColor(name2))
1210
+ layer.style.setProperty("--grab", name2);
1211
+ else
1212
+ layer.style.removeProperty("--grab");
1213
+ }
1214
+ if (bar && label.dataset.bar !== bar)
1215
+ label.dataset.bar = bar;
1216
+ }
1217
+ function schedule() {
1218
+ if (!frame && !removed)
1219
+ frame = window.requestAnimationFrame(draw);
1220
+ }
1221
+ function sync() {
1222
+ if (!element && picked.length === 0)
1223
+ return;
1224
+ stale = true;
1225
+ schedule();
1226
+ }
1227
+ function radiusOf(of) {
1228
+ let radius = radii.get(of);
1229
+ if (radius === undefined) {
1230
+ radius = parseRadius(getComputedStyle(of).borderRadius);
1231
+ radii.set(of, radius);
1232
+ }
1233
+ return radius;
1234
+ }
1235
+ function shapeOf(of) {
1236
+ const rect = of.getBoundingClientRect();
1237
+ const radius = boxRadius(radiusOf(of), rect.width, rect.height);
1238
+ return [rect.left, rect.top, rect.width, rect.height, radius];
1239
+ }
1240
+ function drawPicks(ratio) {
1241
+ while (picks.length < shapes.length) {
1242
+ const node = document.createElement("div");
1243
+ node.className = "pick";
1244
+ layer.insertBefore(node, glide);
1245
+ picks.push(node);
1246
+ }
1247
+ picks.forEach((node, index) => {
1248
+ const shape = shapes[index] ?? null;
1249
+ if (node.hidden !== (shape === null))
1250
+ node.hidden = shape === null;
1251
+ if (shape)
1252
+ place(node, shape, ratio);
1253
+ });
1254
+ }
1255
+ function drawBox(parts) {
1256
+ write(glide, "transform", parts.at);
1257
+ write(box, "--unit", `${parts.unit}px`);
1258
+ write(box, "--corner-width", `${parts.corner.width}px`);
1259
+ write(box, "--corner-height", `${parts.corner.height}px`);
1260
+ write(box, "--corner-radius", `${parts.corner.radius}px`);
1261
+ for (const { piece, node } of pieces)
1262
+ write(node, "transform", parts.pieces[piece]);
1263
+ }
1264
+ function styleOf(of) {
1265
+ let style = styles.get(of);
1266
+ if (!style) {
1267
+ style = getComputedStyle(of);
1268
+ styles.set(of, style);
1269
+ }
1270
+ return style;
1271
+ }
1272
+ function measureBox() {
1273
+ const first = element ? -1 : picked.findIndex((pick) => pick.isConnected);
1274
+ const subject = element ?? picked[first] ?? null;
1275
+ rings = subject ? readBox(subject, styleOf(subject)) : null;
1276
+ ringsAt = shapes[first] ?? null;
1277
+ if (!card || !element || facts?.of !== element)
1278
+ return;
1279
+ rows = rings ? cardRows({ ...facts.read, margin: rings.model.margin, padding: rings.model.padding }) : [];
1280
+ }
1281
+ function readCard(of) {
1282
+ if (removed || of !== element || !of.isConnected)
1283
+ return;
1284
+ facts = { of, read: readFacts(of, styleOf(of), colorOf) };
1285
+ stale = true;
1286
+ schedule();
1287
+ }
1288
+ function drawTints(glide2) {
1289
+ const [x, y, width, height] = glide2 ?? ringsAt ?? [];
1290
+ const on = rings !== null && x !== undefined && y !== undefined;
1291
+ if (rings && on) {
1292
+ const paths = ringPaths(rings.quads ?? ringQuads({ x, y, width: width ?? 0, height: height ?? 0 }, rings.model));
1293
+ for (const { ring, node } of tints)
1294
+ write(node, "clip-path", paths[ring]);
1295
+ }
1296
+ for (const { ring, node } of tints) {
1297
+ node.classList.toggle("on", on && (only === null || only === ring));
1298
+ }
1299
+ }
1300
+ function measure() {
1301
+ if (element && !element.isConnected)
1302
+ element = null;
1303
+ shapes = picked.map((pick) => pick.isConnected ? shapeOf(pick) : null);
1304
+ if (model)
1305
+ measureBox();
1306
+ if (element || toasting) {
1307
+ const { theme, grab } = read(element);
1308
+ bar = invertTheme(theme);
1309
+ tone = grab;
1310
+ }
1311
+ if (!element) {
1312
+ measured = null;
1313
+ target = null;
1314
+ return;
1315
+ }
1316
+ const next = shapeOf(element);
1317
+ if (!shown || !at || !target) {
1318
+ at = next;
1319
+ labelAt = null;
1320
+ } else if (measured === element) {
1321
+ const from = target;
1322
+ at = at.map((value, index) => value + (next[index] ?? 0) - (from[index] ?? 0));
1323
+ if (labelAt) {
1324
+ labelAt = [(labelAt[0] ?? 0) + next[0] - from[0], (labelAt[1] ?? 0) + next[1] - from[1]];
1325
+ }
1326
+ }
1327
+ target = next;
1328
+ measured = element;
1329
+ }
1330
+ function writeLabel() {
1331
+ const said = card && target ? sizeText(target[2], target[3]) : "";
1332
+ const told = card ? `
1333
+ ${said}
1334
+ ${JSON.stringify(rows)}` : "";
1335
+ const key = `${checked}
1336
+ ${text.tag}
1337
+ ${text.name ?? ""}${told}`;
1338
+ if (key === sized)
1339
+ return;
1340
+ check.toggleAttribute("hidden", !checked);
1341
+ tag.textContent = text.tag;
1342
+ tag.hidden = !text.tag;
1343
+ name.textContent = card ? middle(text.name ?? "", NAME_MAX) : text.name ?? "";
1344
+ name.hidden = !text.name;
1345
+ const shape = card ? `card
1346
+ ${card.write(said, rows)}` : key;
1347
+ let known = sizes.get(shape);
1348
+ if (!known) {
1349
+ known = { width: label.offsetWidth, height: label.offsetHeight };
1350
+ sizes.set(shape, known);
1351
+ }
1352
+ size = known;
1353
+ sized = key;
1354
+ }
1355
+ function resize() {
1356
+ sizes.clear();
1357
+ sync();
1358
+ }
1359
+ function draw(now) {
1360
+ frame = 0;
1361
+ if (removed)
1362
+ return;
1363
+ const fresh = stale;
1364
+ if (stale) {
1365
+ stale = false;
1366
+ measure();
1367
+ }
1368
+ const view = {
1369
+ width: document.documentElement.clientWidth,
1370
+ height: document.documentElement.clientHeight
1371
+ };
1372
+ const ratio = window.devicePixelRatio || 1;
1373
+ shown = at !== null && target !== null;
1374
+ if (shown || toasting)
1375
+ writeLabel();
1376
+ if (fresh) {
1377
+ paint();
1378
+ drawPicks(ratio);
1379
+ }
1380
+ box.classList.toggle("on", shown);
1381
+ label.classList.toggle("toast", toasting);
1382
+ label.classList.toggle("on", shown || toasting);
1383
+ if (!at || !target) {
1384
+ last = 0;
1385
+ labelAt = null;
1386
+ if (model)
1387
+ drawTints(null);
1388
+ if (!toasting)
1389
+ return;
1390
+ const x2 = Math.round((view.width - size.width) / 2);
1391
+ write(tip, "transform", `translate(${x2}px, ${MARGIN * 2}px)`);
1392
+ return;
1393
+ }
1394
+ const elapsed = last ? now - last : FRAME;
1395
+ const step = tweenStep(at, target, elapsed, reduced);
1396
+ at = step.values;
1397
+ drawBox(boxParts(at, target[4], ratio));
1398
+ if (model)
1399
+ drawTints(at);
1400
+ const edges = {
1401
+ top: target[1],
1402
+ bottom: target[1] + target[3],
1403
+ left: target[0],
1404
+ right: target[0] + target[2]
1405
+ };
1406
+ const spot = card ? cardPlace(edges, size, view) : labelPlace(edges, size, view, pointerX);
1407
+ const goal = [Math.round(spot.x), Math.round(spot.y)];
1408
+ const move = tweenStep(labelAt ?? goal, goal, elapsed, reduced);
1409
+ labelAt = move.values;
1410
+ const [x = 0, y = 0] = labelAt;
1411
+ write(tip, "transform", `translate(${snap(x, ratio)}px, ${snap(y, ratio)}px)`);
1412
+ const done = step.done && move.done;
1413
+ last = done ? 0 : now;
1414
+ if (!done)
1415
+ schedule();
1416
+ }
1417
+ function hide() {
1418
+ hideTimer = 0;
1419
+ element = null;
1420
+ clearTimeout(factsTimer);
1421
+ facts = null;
1422
+ rows = [];
1423
+ box.classList.remove("on");
1424
+ label.classList.remove("on");
1425
+ stale = true;
1426
+ schedule();
1427
+ }
1428
+ function remove() {
1429
+ if (removed)
1430
+ return;
1431
+ removed = true;
1432
+ clearTimeout(hideTimer);
1433
+ clearTimeout(toastTimer);
1434
+ clearTimeout(fadeTimer);
1435
+ clearTimeout(factsTimer);
1436
+ clearInterval(ticker);
1437
+ if (frame)
1438
+ window.cancelAnimationFrame(frame);
1439
+ window.removeEventListener("scroll", sync, true);
1440
+ window.removeEventListener("resize", resize);
1441
+ reduce.removeEventListener("change", still);
1442
+ stopSystem();
1443
+ stopColor();
1444
+ hold.release();
1445
+ host.remove();
1446
+ }
1447
+ const stopSystem = watchSystemMedia(still);
1448
+ paint();
1449
+ const stopColor = subscribe((state) => {
1450
+ color = state.grabColor;
1451
+ paint();
1452
+ });
1453
+ reduce.addEventListener("change", still);
1454
+ window.addEventListener("scroll", sync, { capture: true, passive: true });
1455
+ window.addEventListener("resize", resize);
1456
+ const ticker = window.setInterval(sync, SYNC_EVERY);
1457
+ getComputedStyle(glow).opacity;
1458
+ if (!quiet)
1459
+ glow.classList.add("on");
1460
+ return {
1461
+ draw(current, next, gathered) {
1462
+ if (closing)
1463
+ return;
1464
+ picked = gathered;
1465
+ if (current) {
1466
+ clearTimeout(hideTimer);
1467
+ hideTimer = 0;
1468
+ if (card && current !== element) {
1469
+ clearTimeout(factsTimer);
1470
+ factsTimer = window.setTimeout(() => readCard(current), DWELL);
1471
+ }
1472
+ element = current;
1473
+ text = next;
1474
+ checked = false;
1475
+ } else if (element && !hideTimer) {
1476
+ hideTimer = window.setTimeout(hide, HIDE_WAIT);
1477
+ }
1478
+ stale = true;
1479
+ schedule();
1480
+ },
1481
+ point(x) {
1482
+ if (closing || x === pointerX)
1483
+ return;
1484
+ pointerX = x;
1485
+ if (element)
1486
+ schedule();
1487
+ },
1488
+ toast(message, near, mark2) {
1489
+ if (removed)
1490
+ return;
1491
+ clearTimeout(hideTimer);
1492
+ clearTimeout(toastTimer);
1493
+ clearTimeout(fadeTimer);
1494
+ hideTimer = 0;
1495
+ toasting = true;
1496
+ box.classList.toggle("copied", mark2);
1497
+ element = near?.isConnected ? near : null;
1498
+ text = { tag: "", name: message };
1499
+ checked = mark2;
1500
+ stale = true;
1501
+ schedule();
1502
+ toastTimer = window.setTimeout(() => {
1503
+ toasting = false;
1504
+ hide();
1505
+ if (!closing)
1506
+ box.classList.remove("copied");
1507
+ if (closing)
1508
+ fadeTimer = window.setTimeout(remove, fade());
1509
+ }, TOAST_TIME);
1510
+ },
1511
+ area(ring) {
1512
+ if (closing || ring === only)
1513
+ return;
1514
+ only = ring;
1515
+ schedule();
1516
+ },
1517
+ destroy() {
1518
+ if (closing)
1519
+ return;
1520
+ closing = true;
1521
+ clearTimeout(hideTimer);
1522
+ glow.classList.remove("on");
1523
+ picked = [];
1524
+ shapes = [];
1525
+ drawPicks(1);
1526
+ if (toasting)
1527
+ return;
1528
+ hide();
1529
+ fadeTimer = window.setTimeout(remove, fade());
1530
+ }
1531
+ };
1532
+ }
1533
+
1534
+ // src/grab/picks.ts
1535
+ function togglePick(picked, item) {
1536
+ return picked.includes(item) ? picked.filter((entry) => entry !== item) : [...picked, item];
1537
+ }
1538
+ function flushPicks(picked, clicked) {
1539
+ if (clicked === null || picked.includes(clicked))
1540
+ return [...picked];
1541
+ return [...picked, clicked];
1542
+ }
1543
+ function copiedText(count) {
1544
+ return count > 1 ? `Copied ${count}` : "Copied";
1545
+ }
1546
+
1547
+ // src/grab/mode.ts
1548
+ var PREPARE = 80;
1549
+ var HIT_EVERY = 32;
1550
+ var BLOCKED = [
1551
+ "pointerdown",
1552
+ "mousedown",
1553
+ "pointerup",
1554
+ "mouseup",
1555
+ "click",
1556
+ "dblclick",
1557
+ "auxclick",
1558
+ "pointerover",
1559
+ "pointerout",
1560
+ "mouseover",
1561
+ "mouseout"
1562
+ ];
1563
+ var PAGE = {
1564
+ componentOf,
1565
+ copyGrab,
1566
+ createOverlay,
1567
+ grabEntry,
1568
+ grabTargetAt,
1569
+ quickEntry
1570
+ };
1571
+ function fromDevknobs(event) {
1572
+ const target = event.composedPath()[0];
1573
+ return target instanceof Element && isDevknobs(target);
1574
+ }
1575
+ function isTyping(event) {
1576
+ const target = event.composedPath()[0];
1577
+ if (!(target instanceof HTMLElement))
1578
+ return false;
1579
+ return target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable;
1580
+ }
1581
+ function onControl(event) {
1582
+ const target = event.composedPath()[0];
1583
+ return isTyping(event) || target instanceof HTMLElement && target.tagName === "BUTTON";
1584
+ }
1585
+ function startMode(options, page = PAGE) {
1586
+ const { purpose } = options;
1587
+ const overlay = page.createOverlay(false, purpose !== undefined);
1588
+ const navigator = createNavigator();
1589
+ const ready = new WeakMap;
1590
+ const warming = new WeakSet;
1591
+ const labels = new WeakMap;
1592
+ let current = null;
1593
+ let candidate = null;
1594
+ let since = 0;
1595
+ let leftAt = Number.NEGATIVE_INFINITY;
1596
+ let picked = [];
1597
+ let prepareTimer = 0;
1598
+ let point = null;
1599
+ let hitPoint = null;
1600
+ let hitAt = 0;
1601
+ let hitTimer = 0;
1602
+ let settleTimer = 0;
1603
+ let stopped = false;
1604
+ ensureStyle("grab-cursor").textContent = "*:not([data-devknobs]){cursor:crosshair!important}";
1605
+ pause(true);
1606
+ function warm(element) {
1607
+ if (purpose || ready.has(element) || warming.has(element))
1608
+ return;
1609
+ warming.add(element);
1610
+ page.grabEntry(element).then((entry) => ready.set(element, entry)).catch(() => {
1611
+ return;
1612
+ }).finally(() => warming.delete(element));
1613
+ }
1614
+ function labelOf(element) {
1615
+ if (purpose)
1616
+ return purpose.label(element);
1617
+ let name = labels.get(element);
1618
+ if (name === undefined) {
1619
+ name = page.componentOf(element);
1620
+ labels.set(element, name);
1621
+ }
1622
+ return { tag: element.tagName.toLowerCase(), name };
1623
+ }
1624
+ function draw() {
1625
+ if (stopped)
1626
+ return;
1627
+ if (current && !current.isConnected)
1628
+ current = null;
1629
+ picked = picked.filter((element) => element.isConnected);
1630
+ overlay.draw(current, current ? labelOf(current) : { tag: "", name: null }, picked);
1631
+ }
1632
+ function select(element) {
1633
+ if (element === current)
1634
+ return;
1635
+ current = element;
1636
+ if (!element)
1637
+ leftAt = performance.now();
1638
+ clearTimeout(prepareTimer);
1639
+ if (element)
1640
+ prepareTimer = window.setTimeout(() => warm(element), PREPARE);
1641
+ draw();
1642
+ }
1643
+ function copy(elements) {
1644
+ if (elements.length === 0)
1645
+ return;
1646
+ const entries = elements.map((element) => ready.get(element) ?? page.quickEntry(element));
1647
+ const anchor = elements[elements.length - 1] ?? null;
1648
+ overlay.toast(copiedText(elements.length), anchor, true);
1649
+ page.copyGrab({ content: joinEntries(entries), entries }).then((copied) => {
1650
+ if (!copied)
1651
+ overlay.toast("Copy failed", anchor, false);
1652
+ });
1653
+ for (const element of elements)
1654
+ warm(element);
1655
+ exit();
1656
+ }
1657
+ function drop() {
1658
+ clearTimeout(hitTimer);
1659
+ clearTimeout(settleTimer);
1660
+ hitTimer = 0;
1661
+ settleTimer = 0;
1662
+ }
1663
+ function hit(now = false) {
1664
+ drop();
1665
+ if (!point)
1666
+ return;
1667
+ const at = performance.now();
1668
+ const target = page.grabTargetAt(document, point.x, point.y);
1669
+ const speed = speedOf(hitPoint ?? point, point, at - hitAt);
1670
+ hitAt = at;
1671
+ hitPoint = point;
1672
+ if (target !== candidate) {
1673
+ candidate = target;
1674
+ since = at;
1675
+ }
1676
+ if (target === current)
1677
+ return;
1678
+ const held = at - since;
1679
+ const boxed = current !== null || at - leftAt < HIDE_WAIT;
1680
+ if (now || !target || settles({ boxed, held, speed })) {
1681
+ navigator.clear();
1682
+ select(target);
1683
+ return;
1684
+ }
1685
+ settleTimer = window.setTimeout(() => hit(), Math.min(HIT_EVERY, DWELL - held));
1686
+ }
1687
+ function resolve(at = point) {
1688
+ if (!hitTimer && !settleTimer)
1689
+ return;
1690
+ point = at;
1691
+ hit(true);
1692
+ }
1693
+ function onPointerMove(event) {
1694
+ if (!event.isPrimary)
1695
+ return;
1696
+ point = { x: event.clientX, y: event.clientY };
1697
+ overlay.point(point.x);
1698
+ const wait = HIT_EVERY - (performance.now() - hitAt);
1699
+ if (wait <= 0) {
1700
+ hit();
1701
+ } else if (!hitTimer) {
1702
+ hitTimer = window.setTimeout(() => hit(), wait);
1703
+ }
1704
+ }
1705
+ function onBlocked(event) {
1706
+ if (fromDevknobs(event))
1707
+ return;
1708
+ event.preventDefault();
1709
+ event.stopPropagation();
1710
+ if (event.type !== "click" || !(event instanceof MouseEvent))
1711
+ return;
1712
+ resolve({ x: event.clientX, y: event.clientY });
1713
+ const target = page.grabTargetAt(document, event.clientX, event.clientY) ?? (current?.isConnected ? current : null);
1714
+ if (!target)
1715
+ return;
1716
+ if (purpose) {
1717
+ purpose.pick(target);
1718
+ exit();
1719
+ return;
1720
+ }
1721
+ if (event.shiftKey) {
1722
+ picked = togglePick(picked, target);
1723
+ warm(target);
1724
+ draw();
1725
+ return;
1726
+ }
1727
+ copy(flushPicks(picked, target));
1728
+ }
1729
+ function keydown(event) {
1730
+ if (event.key === "Escape") {
1731
+ event.preventDefault();
1732
+ event.stopImmediatePropagation();
1733
+ exit();
1734
+ return;
1735
+ }
1736
+ const step = stepOf(event);
1737
+ if (step) {
1738
+ if (isTyping(event) || event.metaKey || event.ctrlKey || event.altKey)
1739
+ return;
1740
+ if (purpose && (event.key === "Tab" || onControl(event)))
1741
+ return;
1742
+ event.preventDefault();
1743
+ event.stopImmediatePropagation();
1744
+ const next = current?.isConnected ? navigator.next(step, current) : null;
1745
+ if (next) {
1746
+ drop();
1747
+ overlay.point(null);
1748
+ select(next);
1749
+ }
1750
+ return;
1751
+ }
1752
+ if (event.repeat) {
1753
+ if (options.heldKey(event))
1754
+ event.preventDefault();
1755
+ return;
1756
+ }
1757
+ if (purpose) {
1758
+ if (event.key !== "Enter" || onControl(event))
1759
+ return;
1760
+ resolve();
1761
+ if (!current?.isConnected)
1762
+ return;
1763
+ event.preventDefault();
1764
+ event.stopImmediatePropagation();
1765
+ purpose.pick(current);
1766
+ exit();
1767
+ return;
1768
+ }
1769
+ if (event.key !== "Enter" && !isCLike(event.key, event.code))
1770
+ return;
1771
+ resolve();
1772
+ const elements = flushPicks(picked, current);
1773
+ if (elements.length === 0)
1774
+ return;
1775
+ event.preventDefault();
1776
+ event.stopImmediatePropagation();
1777
+ copy(elements);
1778
+ }
1779
+ function onKeyup(event) {
1780
+ if (event.key === "Shift" && picked.length > 0)
1781
+ copy(picked);
1782
+ }
1783
+ for (const type of BLOCKED)
1784
+ window.addEventListener(type, onBlocked, true);
1785
+ window.addEventListener("pointermove", onPointerMove, true);
1786
+ window.addEventListener("keyup", onKeyup, true);
1787
+ function stop() {
1788
+ if (stopped)
1789
+ return;
1790
+ stopped = true;
1791
+ clearTimeout(prepareTimer);
1792
+ drop();
1793
+ for (const type of BLOCKED)
1794
+ window.removeEventListener(type, onBlocked, true);
1795
+ window.removeEventListener("pointermove", onPointerMove, true);
1796
+ window.removeEventListener("keyup", onKeyup, true);
1797
+ removeStyle("grab-cursor");
1798
+ pause(false);
1799
+ overlay.destroy();
1800
+ }
1801
+ function exit() {
1802
+ stop();
1803
+ options.onExit();
1804
+ }
1805
+ if (options.pointer) {
1806
+ point = options.pointer;
1807
+ overlay.point(point.x);
1808
+ hit();
1809
+ }
1810
+ return { keydown, stop };
1811
+ }
1812
+ // src/grab/outline.ts
1813
+ var NO_LABEL = { tag: "", name: null };
1814
+ function createOutline(make = createOverlay) {
1815
+ let overlay = null;
1816
+ let only = null;
1817
+ function show2(element) {
1818
+ if (!element) {
1819
+ overlay?.destroy();
1820
+ overlay = null;
1821
+ return;
1822
+ }
1823
+ if (!overlay) {
1824
+ overlay = make(true, true);
1825
+ if (only)
1826
+ overlay.area(only);
1827
+ }
1828
+ overlay.draw(null, NO_LABEL, [element]);
1829
+ }
1830
+ function area(ring) {
1831
+ only = ring;
1832
+ overlay?.area(ring);
1833
+ }
1834
+ return { show: show2, area, destroy: () => show2(null) };
1835
+ }
1836
+
1837
+ // src/grab/index.ts
1838
+ function iterable(value) {
1839
+ return typeof value === "object" && value !== null && typeof Reflect.get(value, Symbol.iterator) === "function";
1840
+ }
1841
+ function listOf(elements) {
1842
+ if (isElement(elements))
1843
+ return [elements];
1844
+ return iterable(elements) ? Array.from(elements) : [];
1845
+ }
1846
+ async function grab(elements, options = {}) {
1847
+ const found = listOf(elements).filter(isElement);
1848
+ if (found.length === 0)
1849
+ return null;
1850
+ const payload = await grabContext(found, options);
1851
+ if (!payload.content.trim())
1852
+ return null;
1853
+ return { ...payload, copied: await copyGrab(payload) };
1854
+ }
1855
+ export {
1856
+ startMode,
1857
+ grab,
1858
+ createOutline
1859
+ };