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