@vinena/knobs 0.5.0 → 0.5.2
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 +21 -0
- package/README.md +7 -0
- package/dist/early.global.js +6 -6
- package/dist/{elementsview-6g274ptr.js → elementsview-2z4pkrdz.js} +4 -4
- package/dist/{elementsview-pkzp9kc6.js → elementsview-qn8qyksa.js} +4 -4
- package/dist/engine/browserdraw.d.ts +24 -2
- package/dist/engine/browserkit.d.ts +18 -1
- package/dist/engine/browserui.d.ts +162 -22
- package/dist/engine/devicon.d.ts +59 -0
- package/dist/engine/fit.d.ts +4 -3
- package/dist/engine/foldflip.d.ts +40 -0
- package/dist/engine/identity.d.ts +7 -4
- package/dist/engine/mock.d.ts +16 -0
- package/dist/engine/mockdata.d.ts +4 -1
- package/dist/engine/mockdraw.d.ts +14 -2
- package/dist/engine/pageshot.d.ts +5 -2
- package/dist/engine/safaridraw.d.ts +162 -10
- package/dist/engine/screen.d.ts +24 -0
- package/dist/engine/store.d.ts +2 -1
- package/dist/engine/tabicon.d.ts +43 -0
- package/dist/engine/toplayer.d.ts +62 -0
- package/dist/engine/touchpointer.d.ts +0 -21
- package/dist/engine/underbar.d.ts +61 -0
- package/dist/{framekit-g96t6nmq.js → framekit-te90cjs0.js} +2325 -1572
- package/dist/{framekit-3n7p79ht.js → framekit-w0v516w5.js} +2325 -1572
- package/dist/host.d.ts +51 -0
- package/dist/{index-64rd634h.js → index-30fc6php.js} +1 -1
- package/dist/{index-dvr4x91q.js → index-9re7sv56.js} +20 -8
- package/dist/{index-0casarhy.js → index-agwr37gw.js} +1 -1
- package/dist/{index-2d6wvs8h.js → index-dan2kpsd.js} +4 -4
- package/dist/{index-kzsb9drs.js → index-hv02xka3.js} +20 -8
- package/dist/{index-peh33xjv.js → index-pewcdh28.js} +1 -1
- package/dist/{index-d0cjxjsm.js → index-r72tz2vn.js} +1 -1
- package/dist/{index-33x9hxe3.js → index-sxe5079a.js} +605 -187
- package/dist/{index-5d6qzte3.js → index-trx7bxdk.js} +4 -4
- package/dist/{index-5baxvd3v.js → index-xjhwp5cj.js} +275 -112
- package/dist/index.d.ts +26 -1
- package/dist/index.global.js +270 -176
- package/dist/index.js +398 -124
- package/dist/instance.d.ts +23 -4
- package/dist/{react-pdvseef0.js → react-05jh9jv5.js} +1 -1
- package/dist/{react-4kbj1t4h.js → react-16spgn0h.js} +1 -1
- package/dist/{react-65tgdbs8.js → react-4pvp6amm.js} +1 -1
- package/dist/{react-qv0nykcv.js → react-ayg1bgw3.js} +602 -184
- package/dist/{react-xxfpfddf.js → react-exjcpxma.js} +1 -1
- package/dist/{react-carf84xv.js → react-fm9y8dbn.js} +275 -112
- package/dist/{react-mv9y20jy.js → react-sw8d8c94.js} +4 -4
- package/dist/{react-71a9ypex.js → react-zy1mmhgz.js} +4 -4
- package/dist/react.js +394 -123
- package/dist/{storageview-vdkbp6rt.js → storageview-r595qpt9.js} +4 -4
- package/dist/{storageview-j9d44f99.js → storageview-s7heg93p.js} +4 -4
- package/dist/types.d.ts +7 -0
- package/dist/ui/footer.d.ts +9 -2
- package/dist/ui/panel.d.ts +16 -2
- package/dist/ui/settings.d.ts +17 -1
- package/dist/version.d.ts +2 -0
- package/package.json +3 -2
- package/skills/devknobs/SKILL.md +1 -1
- package/dist/elementsview-jnkbhzkj.js +0 -2873
- package/dist/elementsview-tf4qzmtw.js +0 -2874
- package/dist/engine/endroom.d.ts +0 -21
- package/dist/framekit-095qevka.js +0 -8838
- package/dist/framekit-q5aad770.js +0 -8839
- package/dist/index-hw56t3zy.js +0 -4800
- package/dist/index-k015tb6c.js +0 -357
- package/dist/index-ke6v7919.js +0 -4801
- package/dist/index-qxye1j73.js +0 -528
- package/dist/index-z5ytnj01.js +0 -4563
- package/dist/index-zvze25nf.js +0 -686
- package/dist/react-eygws6cx.js +0 -358
- package/dist/react-sq9pkw4k.js +0 -687
- package/dist/react-vjm88w4t.js +0 -4564
- package/dist/react-znfrjqk8.js +0 -529
- package/dist/storageview-sb23henh.js +0 -2729
- package/dist/storageview-vf8v8q8j.js +0 -2728
|
@@ -1,2874 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
TITLE_MAX,
|
|
4
|
-
boxValue,
|
|
5
|
-
crumbText,
|
|
6
|
-
declaredIn,
|
|
7
|
-
hiddenLine,
|
|
8
|
-
matchesFilter,
|
|
9
|
-
middle,
|
|
10
|
-
resolveVars,
|
|
11
|
-
sizeText,
|
|
12
|
-
sourceOf,
|
|
13
|
-
swatchOf,
|
|
14
|
-
valueParts,
|
|
15
|
-
varReferences,
|
|
16
|
-
variableTip
|
|
17
|
-
} from "./react-pdvseef0.js";
|
|
18
|
-
import {
|
|
19
|
-
flatParent,
|
|
20
|
-
isShadowRoot,
|
|
21
|
-
label,
|
|
22
|
-
scopeOf
|
|
23
|
-
} from "./react-adky72h9.js";
|
|
24
|
-
import {
|
|
25
|
-
actButton,
|
|
26
|
-
button,
|
|
27
|
-
el,
|
|
28
|
-
emptyAction,
|
|
29
|
-
emptyLine,
|
|
30
|
-
filterField,
|
|
31
|
-
sectionFold,
|
|
32
|
-
segments,
|
|
33
|
-
toolToggle,
|
|
34
|
-
toolbar
|
|
35
|
-
} from "./react-sq9pkw4k.js";
|
|
36
|
-
import {
|
|
37
|
-
copyText
|
|
38
|
-
} from "./react-h9w04skh.js";
|
|
39
|
-
import {
|
|
40
|
-
getState,
|
|
41
|
-
icon,
|
|
42
|
-
isDevknobs,
|
|
43
|
-
subscribe
|
|
44
|
-
} from "./react-qv0nykcv.js";
|
|
45
|
-
import {
|
|
46
|
-
SIDES,
|
|
47
|
-
authoredQuery,
|
|
48
|
-
boxModel,
|
|
49
|
-
contentSize,
|
|
50
|
-
isOwnSheet,
|
|
51
|
-
ownInline
|
|
52
|
-
} from "./react-carf84xv.js";
|
|
53
|
-
|
|
54
|
-
// src/ui/domtree.ts
|
|
55
|
-
var ELEMENT = 1;
|
|
56
|
-
var TEXT = 3;
|
|
57
|
-
var COMMENT = 8;
|
|
58
|
-
var DOCUMENT = 9;
|
|
59
|
-
var DOCTYPE = 10;
|
|
60
|
-
var FRAGMENT = 11;
|
|
61
|
-
var CHILD_CAP = 500;
|
|
62
|
-
var INLINE_MAX = 80;
|
|
63
|
-
var VALUE_MAX = 100;
|
|
64
|
-
var DATA_URL_MAX = 60;
|
|
65
|
-
var TEXT_MAX = 200;
|
|
66
|
-
var SETTLE = 100;
|
|
67
|
-
var VOID = new Set([
|
|
68
|
-
"area",
|
|
69
|
-
"base",
|
|
70
|
-
"br",
|
|
71
|
-
"col",
|
|
72
|
-
"embed",
|
|
73
|
-
"hr",
|
|
74
|
-
"img",
|
|
75
|
-
"input",
|
|
76
|
-
"link",
|
|
77
|
-
"meta",
|
|
78
|
-
"param",
|
|
79
|
-
"source",
|
|
80
|
-
"track",
|
|
81
|
-
"wbr"
|
|
82
|
-
]);
|
|
83
|
-
function hasContent(content) {
|
|
84
|
-
return content !== "" && content !== "none" && content !== "normal";
|
|
85
|
-
}
|
|
86
|
-
function readPseudos(element) {
|
|
87
|
-
const view = element.ownerDocument.defaultView;
|
|
88
|
-
if (!view)
|
|
89
|
-
return [];
|
|
90
|
-
const found = [];
|
|
91
|
-
try {
|
|
92
|
-
if (view.getComputedStyle(element).display.includes("list-item")) {
|
|
93
|
-
if (view.getComputedStyle(element, "::marker").content !== "none")
|
|
94
|
-
found.push("::marker");
|
|
95
|
-
}
|
|
96
|
-
for (const name of ["::before", "::after"]) {
|
|
97
|
-
const style = view.getComputedStyle(element, name);
|
|
98
|
-
if (hasContent(style.content) && style.display !== "none")
|
|
99
|
-
found.push(name);
|
|
100
|
-
}
|
|
101
|
-
} catch {}
|
|
102
|
-
return found;
|
|
103
|
-
}
|
|
104
|
-
var PAGE = { pseudos: readPseudos };
|
|
105
|
-
function isElement(node) {
|
|
106
|
-
return node.nodeType === ELEMENT;
|
|
107
|
-
}
|
|
108
|
-
function isShadowRoot2(node) {
|
|
109
|
-
return node.nodeType === FRAGMENT && "host" in node;
|
|
110
|
-
}
|
|
111
|
-
function isDoctype(node) {
|
|
112
|
-
return node.nodeType === DOCTYPE;
|
|
113
|
-
}
|
|
114
|
-
function isDocument(node) {
|
|
115
|
-
return node.nodeType === DOCUMENT;
|
|
116
|
-
}
|
|
117
|
-
function isOwnNode(node) {
|
|
118
|
-
return isElement(node) && node.hasAttribute("data-devknobs");
|
|
119
|
-
}
|
|
120
|
-
function isOwnAttribute(name) {
|
|
121
|
-
return name.startsWith("data-devknobs");
|
|
122
|
-
}
|
|
123
|
-
function parentOf(node) {
|
|
124
|
-
if (isShadowRoot2(node))
|
|
125
|
-
return node.host;
|
|
126
|
-
return node.parentNode;
|
|
127
|
-
}
|
|
128
|
-
function shownText(text) {
|
|
129
|
-
return text.replace(/\s+/g, " ").trim();
|
|
130
|
-
}
|
|
131
|
-
function cut(text, max) {
|
|
132
|
-
const chars = [...text];
|
|
133
|
-
return chars.length <= max ? text : `${chars.slice(0, max - 1).join("")}…`;
|
|
134
|
-
}
|
|
135
|
-
function shownValue(value) {
|
|
136
|
-
return middle(value, value.startsWith("data:") ? DATA_URL_MAX : VALUE_MAX);
|
|
137
|
-
}
|
|
138
|
-
function tagOf(element) {
|
|
139
|
-
return element.localName || element.nodeName.toLowerCase();
|
|
140
|
-
}
|
|
141
|
-
function doctypeText(node) {
|
|
142
|
-
const pub = node.publicId ? ` PUBLIC "${node.publicId}"` : "";
|
|
143
|
-
const system = node.systemId ? `${pub ? "" : " SYSTEM"} "${node.systemId}"` : "";
|
|
144
|
-
return `<!DOCTYPE ${node.name}${pub}${system}>`;
|
|
145
|
-
}
|
|
146
|
-
function createTreeModel(page = PAGE) {
|
|
147
|
-
let doc = null;
|
|
148
|
-
let kids = new WeakMap;
|
|
149
|
-
let marks = new WeakMap;
|
|
150
|
-
let open = new WeakSet;
|
|
151
|
-
let all = new WeakSet;
|
|
152
|
-
function pseudosOf(element) {
|
|
153
|
-
let found = marks.get(element);
|
|
154
|
-
if (!found) {
|
|
155
|
-
found = page.pseudos(element);
|
|
156
|
-
marks.set(element, found);
|
|
157
|
-
}
|
|
158
|
-
return found;
|
|
159
|
-
}
|
|
160
|
-
function shows(node) {
|
|
161
|
-
switch (node.nodeType) {
|
|
162
|
-
case ELEMENT:
|
|
163
|
-
return !isOwnNode(node);
|
|
164
|
-
case TEXT:
|
|
165
|
-
return shownText(node.nodeValue ?? "") !== "";
|
|
166
|
-
case COMMENT:
|
|
167
|
-
case DOCTYPE:
|
|
168
|
-
return true;
|
|
169
|
-
default:
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function children(node) {
|
|
174
|
-
const had = kids.get(node);
|
|
175
|
-
if (had)
|
|
176
|
-
return had;
|
|
177
|
-
const list = [];
|
|
178
|
-
const element = isElement(node) ? node : null;
|
|
179
|
-
const pseudos = element ? pseudosOf(element) : [];
|
|
180
|
-
if (element?.shadowRoot)
|
|
181
|
-
list.push({ node: element.shadowRoot, pseudo: null });
|
|
182
|
-
if (element) {
|
|
183
|
-
for (const name of pseudos)
|
|
184
|
-
if (name !== "::after")
|
|
185
|
-
list.push({ node: element, pseudo: name });
|
|
186
|
-
}
|
|
187
|
-
for (const child of Array.from(node.childNodes))
|
|
188
|
-
if (shows(child))
|
|
189
|
-
list.push({ node: child, pseudo: null });
|
|
190
|
-
if (element && pseudos.includes("::after"))
|
|
191
|
-
list.push({ node: element, pseudo: "::after" });
|
|
192
|
-
kids.set(node, list);
|
|
193
|
-
return list;
|
|
194
|
-
}
|
|
195
|
-
function inlineText(element) {
|
|
196
|
-
if (element.shadowRoot)
|
|
197
|
-
return null;
|
|
198
|
-
const nodes = element.childNodes;
|
|
199
|
-
const only = nodes[0];
|
|
200
|
-
if (nodes.length !== 1 || !only || only.nodeType !== TEXT)
|
|
201
|
-
return null;
|
|
202
|
-
const text = shownText(only.nodeValue ?? "");
|
|
203
|
-
if (text === "" || text.length > INLINE_MAX)
|
|
204
|
-
return null;
|
|
205
|
-
return pseudosOf(element).length === 0 ? text : null;
|
|
206
|
-
}
|
|
207
|
-
function expandable(node) {
|
|
208
|
-
if (isElement(node) && inlineText(node) !== null)
|
|
209
|
-
return false;
|
|
210
|
-
return children(node).length > 0;
|
|
211
|
-
}
|
|
212
|
-
function walk(node, depth, out) {
|
|
213
|
-
const list = children(node);
|
|
214
|
-
const limit = all.has(node) ? list.length : Math.min(list.length, CHILD_CAP);
|
|
215
|
-
for (let at = 0;at < limit; at++) {
|
|
216
|
-
const entry = list[at];
|
|
217
|
-
if (entry)
|
|
218
|
-
push(entry, depth, out);
|
|
219
|
-
}
|
|
220
|
-
if (limit < list.length)
|
|
221
|
-
out.push({ kind: "more", node, pseudo: null, depth, more: list.length - limit });
|
|
222
|
-
}
|
|
223
|
-
function push({ node, pseudo }, depth, out) {
|
|
224
|
-
const row = (kind) => ({ kind, node, pseudo, depth, more: 0 });
|
|
225
|
-
if (pseudo !== null) {
|
|
226
|
-
out.push(row("pseudo"));
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
switch (node.nodeType) {
|
|
230
|
-
case ELEMENT:
|
|
231
|
-
out.push(row("open"));
|
|
232
|
-
if (open.has(node) && expandable(node)) {
|
|
233
|
-
walk(node, depth + 1, out);
|
|
234
|
-
out.push(row("close"));
|
|
235
|
-
}
|
|
236
|
-
return;
|
|
237
|
-
case FRAGMENT:
|
|
238
|
-
out.push(row("shadow"));
|
|
239
|
-
if (open.has(node))
|
|
240
|
-
walk(node, depth + 1, out);
|
|
241
|
-
return;
|
|
242
|
-
case TEXT:
|
|
243
|
-
out.push(row("text"));
|
|
244
|
-
return;
|
|
245
|
-
case COMMENT:
|
|
246
|
-
out.push(row("comment"));
|
|
247
|
-
return;
|
|
248
|
-
case DOCTYPE:
|
|
249
|
-
out.push(row("doctype"));
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
function openPieces(element) {
|
|
253
|
-
const tag = tagOf(element);
|
|
254
|
-
const pieces2 = [["tag", `<${tag}`]];
|
|
255
|
-
for (const attr of Array.from(element.attributes)) {
|
|
256
|
-
if (isOwnAttribute(attr.name))
|
|
257
|
-
continue;
|
|
258
|
-
pieces2.push(["", " "], ["attr", attr.name, attr.name]);
|
|
259
|
-
if (attr.value !== "")
|
|
260
|
-
pieces2.push(["tag", '="', attr.name], ["val", shownValue(attr.value), attr.name], ["tag", '"', attr.name]);
|
|
261
|
-
}
|
|
262
|
-
if (VOID.has(tag) && element.namespaceURI === "http://www.w3.org/1999/xhtml") {
|
|
263
|
-
pieces2.push(["tag", ">"]);
|
|
264
|
-
return pieces2;
|
|
265
|
-
}
|
|
266
|
-
const text = inlineText(element);
|
|
267
|
-
if (text !== null)
|
|
268
|
-
pieces2.push(["tag", ">"], ["text", text], ["tag", `</${tag}>`]);
|
|
269
|
-
else if (!expandable(element))
|
|
270
|
-
pieces2.push(["tag", `></${tag}>`]);
|
|
271
|
-
else if (open.has(element))
|
|
272
|
-
pieces2.push(["tag", ">"]);
|
|
273
|
-
else
|
|
274
|
-
pieces2.push(["tag", ">"], ["", "…"], ["tag", `</${tag}>`]);
|
|
275
|
-
return pieces2;
|
|
276
|
-
}
|
|
277
|
-
function pieces(row) {
|
|
278
|
-
const { node } = row;
|
|
279
|
-
switch (row.kind) {
|
|
280
|
-
case "open":
|
|
281
|
-
return isElement(node) ? openPieces(node) : [];
|
|
282
|
-
case "close":
|
|
283
|
-
return isElement(node) ? [["tag", `</${tagOf(node)}>`]] : [];
|
|
284
|
-
case "text":
|
|
285
|
-
return [["text", `"${cut(shownText(node.nodeValue ?? ""), TEXT_MAX)}"`]];
|
|
286
|
-
case "comment":
|
|
287
|
-
return [["com", `<!--${cut(node.nodeValue ?? "", TEXT_MAX)}-->`]];
|
|
288
|
-
case "doctype":
|
|
289
|
-
return isDoctype(node) ? [["doc", doctypeText(node)]] : [];
|
|
290
|
-
case "shadow":
|
|
291
|
-
return [["", "#shadow-root (open)"]];
|
|
292
|
-
case "pseudo":
|
|
293
|
-
return [["tag", row.pseudo ?? ""]];
|
|
294
|
-
case "more":
|
|
295
|
-
return [["", `Show all nodes (${row.more} more)`]];
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
function setRoot(next) {
|
|
299
|
-
doc = next;
|
|
300
|
-
kids = new WeakMap;
|
|
301
|
-
marks = new WeakMap;
|
|
302
|
-
open = new WeakSet;
|
|
303
|
-
all = new WeakSet;
|
|
304
|
-
const html = next?.documentElement;
|
|
305
|
-
if (html)
|
|
306
|
-
open.add(html);
|
|
307
|
-
if (next?.body)
|
|
308
|
-
open.add(next.body);
|
|
309
|
-
}
|
|
310
|
-
function reveal(node) {
|
|
311
|
-
const path = [];
|
|
312
|
-
let at = node;
|
|
313
|
-
while (at && at.nodeType !== DOCUMENT) {
|
|
314
|
-
if (isOwnNode(at))
|
|
315
|
-
return false;
|
|
316
|
-
path.unshift(at);
|
|
317
|
-
at = parentOf(at);
|
|
318
|
-
}
|
|
319
|
-
if (!at || at !== doc)
|
|
320
|
-
return false;
|
|
321
|
-
let above = at;
|
|
322
|
-
for (const step of path) {
|
|
323
|
-
const index = children(above).findIndex((entry) => entry.node === step && entry.pseudo === null);
|
|
324
|
-
if (index < 0)
|
|
325
|
-
return false;
|
|
326
|
-
if (index >= CHILD_CAP)
|
|
327
|
-
all.add(above);
|
|
328
|
-
if (step !== node)
|
|
329
|
-
open.add(step);
|
|
330
|
-
above = step;
|
|
331
|
-
}
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
return {
|
|
335
|
-
root: () => doc,
|
|
336
|
-
setRoot,
|
|
337
|
-
children,
|
|
338
|
-
inlineText,
|
|
339
|
-
expandable,
|
|
340
|
-
isExpanded: (node) => open.has(node),
|
|
341
|
-
setExpanded(node, next) {
|
|
342
|
-
if (next)
|
|
343
|
-
open.add(node);
|
|
344
|
-
else
|
|
345
|
-
open.delete(node);
|
|
346
|
-
},
|
|
347
|
-
showAll: (node) => all.add(node),
|
|
348
|
-
forget(node) {
|
|
349
|
-
kids.delete(node);
|
|
350
|
-
if (isElement(node))
|
|
351
|
-
marks.delete(node);
|
|
352
|
-
},
|
|
353
|
-
reveal,
|
|
354
|
-
rows() {
|
|
355
|
-
const out = [];
|
|
356
|
-
if (doc)
|
|
357
|
-
walk(doc, 0, out);
|
|
358
|
-
return out;
|
|
359
|
-
},
|
|
360
|
-
pieces
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
function selectable(row) {
|
|
364
|
-
return row.kind !== "close" && row.kind !== "more";
|
|
365
|
-
}
|
|
366
|
-
function parentRow(rows, at) {
|
|
367
|
-
const row = rows[at];
|
|
368
|
-
if (!row)
|
|
369
|
-
return null;
|
|
370
|
-
for (let up = at - 1;up >= 0; up--) {
|
|
371
|
-
const above = rows[up];
|
|
372
|
-
if (above && above.depth === row.depth - 1 && selectable(above))
|
|
373
|
-
return up;
|
|
374
|
-
}
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
function stepFor(key, rows, at, model) {
|
|
378
|
-
const lines = rows.map((row2, index) => selectable(row2) ? index : -1).filter((index) => index >= 0);
|
|
379
|
-
const here = lines.indexOf(at);
|
|
380
|
-
const row = rows[at];
|
|
381
|
-
const to = (index) => index === undefined || index === at ? null : { kind: "select", at: index };
|
|
382
|
-
switch (key) {
|
|
383
|
-
case "ArrowDown":
|
|
384
|
-
return to(lines[here < 0 ? 0 : here + 1]);
|
|
385
|
-
case "ArrowUp":
|
|
386
|
-
return to(lines[here < 0 ? 0 : here - 1]);
|
|
387
|
-
case "Home":
|
|
388
|
-
return to(lines[0]);
|
|
389
|
-
case "End":
|
|
390
|
-
return to(lines[lines.length - 1]);
|
|
391
|
-
case "ArrowRight":
|
|
392
|
-
if (!row || !model.expandable(row.node) || row.kind === "pseudo")
|
|
393
|
-
return null;
|
|
394
|
-
if (!model.isExpanded(row.node))
|
|
395
|
-
return { kind: "expand", node: row.node };
|
|
396
|
-
return to(lines[here + 1]);
|
|
397
|
-
case "ArrowLeft":
|
|
398
|
-
if (!row)
|
|
399
|
-
return null;
|
|
400
|
-
if (row.kind !== "pseudo" && model.expandable(row.node) && model.isExpanded(row.node))
|
|
401
|
-
return { kind: "collapse", node: row.node };
|
|
402
|
-
return to(parentRow(rows, at) ?? undefined);
|
|
403
|
-
default:
|
|
404
|
-
return null;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
function elementOf(node) {
|
|
408
|
-
for (let at = node;at; at = parentOf(at))
|
|
409
|
-
if (isElement(at))
|
|
410
|
-
return at;
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
function markupOf(node) {
|
|
414
|
-
if (isElement(node)) {
|
|
415
|
-
const copy = node.cloneNode(true);
|
|
416
|
-
if (!isElement(copy))
|
|
417
|
-
return "";
|
|
418
|
-
for (const own of Array.from(copy.querySelectorAll("[data-devknobs]")))
|
|
419
|
-
own.remove();
|
|
420
|
-
for (const one of [copy, ...Array.from(copy.querySelectorAll("*"))]) {
|
|
421
|
-
for (const attr of Array.from(one.attributes))
|
|
422
|
-
if (isOwnAttribute(attr.name))
|
|
423
|
-
one.removeAttribute(attr.name);
|
|
424
|
-
}
|
|
425
|
-
return copy.outerHTML;
|
|
426
|
-
}
|
|
427
|
-
if (node.nodeType === TEXT)
|
|
428
|
-
return node.nodeValue ?? "";
|
|
429
|
-
if (node.nodeType === COMMENT)
|
|
430
|
-
return `<!--${node.nodeValue ?? ""}-->`;
|
|
431
|
-
if (isDoctype(node))
|
|
432
|
-
return doctypeText(node);
|
|
433
|
-
return "";
|
|
434
|
-
}
|
|
435
|
-
var treesMade = 0;
|
|
436
|
-
function slot(row) {
|
|
437
|
-
return row.kind === "pseudo" ? row.pseudo ?? "" : row.kind;
|
|
438
|
-
}
|
|
439
|
-
function hasClasses(target) {
|
|
440
|
-
return target !== null && "classList" in target;
|
|
441
|
-
}
|
|
442
|
-
function createDomTree(context, model = createTreeModel()) {
|
|
443
|
-
const id = `dk-dom-${++treesMade}`;
|
|
444
|
-
const node = el("div", "dom");
|
|
445
|
-
const list = el("div", "dom-tree");
|
|
446
|
-
list.setAttribute("role", "tree");
|
|
447
|
-
list.setAttribute("aria-label", "DOM tree");
|
|
448
|
-
list.tabIndex = 0;
|
|
449
|
-
node.append(list);
|
|
450
|
-
node.hidden = true;
|
|
451
|
-
let rows = [];
|
|
452
|
-
let shown = [];
|
|
453
|
-
let built = new WeakMap;
|
|
454
|
-
let selection = null;
|
|
455
|
-
let lit = new Map;
|
|
456
|
-
let made = 0;
|
|
457
|
-
let timer = 0;
|
|
458
|
-
let frame = 0;
|
|
459
|
-
let gone = false;
|
|
460
|
-
const observer = typeof MutationObserver === "undefined" ? null : new MutationObserver(onRecords);
|
|
461
|
-
function drop(target) {
|
|
462
|
-
built.delete(target);
|
|
463
|
-
}
|
|
464
|
-
function isSelected(row) {
|
|
465
|
-
if (!selection || !selectable(row))
|
|
466
|
-
return false;
|
|
467
|
-
return row.node === selection.node && (row.kind === "pseudo" ? row.pseudo === selection.pseudo : selection.pseudo === null);
|
|
468
|
-
}
|
|
469
|
-
function pieceNodes(row) {
|
|
470
|
-
const code = el("span", "dom-code");
|
|
471
|
-
const changed = lit.get(row.node);
|
|
472
|
-
for (const [kind, text, name] of model.pieces(row)) {
|
|
473
|
-
const piece = kind === "" ? el("span", "", text) : el("span", `tok-${kind}`, text);
|
|
474
|
-
if (name !== undefined && changed?.has(name))
|
|
475
|
-
piece.classList.add("dom-flash");
|
|
476
|
-
code.append(piece);
|
|
477
|
-
}
|
|
478
|
-
return code;
|
|
479
|
-
}
|
|
480
|
-
function mark(line, on) {
|
|
481
|
-
line.node.classList.toggle("on", on);
|
|
482
|
-
line.node.setAttribute("aria-selected", on ? "true" : "false");
|
|
483
|
-
for (const part of line.marks)
|
|
484
|
-
part.remove();
|
|
485
|
-
line.marks = [];
|
|
486
|
-
if (!on)
|
|
487
|
-
return;
|
|
488
|
-
const ref = el("span", "dom-ref", " == $0");
|
|
489
|
-
ref.setAttribute("aria-hidden", "true");
|
|
490
|
-
const target = line.row.node;
|
|
491
|
-
const copy = actButton("copy", () => context.copy(markupOf(target)));
|
|
492
|
-
copy.setAttribute("aria-label", "Copy element");
|
|
493
|
-
line.code.append(ref, copy);
|
|
494
|
-
line.marks = [ref, copy];
|
|
495
|
-
}
|
|
496
|
-
function build(row, open) {
|
|
497
|
-
const line = el("div", `dom-row dom-${row.kind}`);
|
|
498
|
-
line.style.paddingLeft = `calc(var(--view-start) + ${row.depth} * var(--col-icon))`;
|
|
499
|
-
if (row.kind === "more") {
|
|
500
|
-
line.setAttribute("role", "none");
|
|
501
|
-
line.append(actButton(model.pieces(row)[0]?.[1] ?? "", () => {
|
|
502
|
-
model.showAll(row.node);
|
|
503
|
-
drop(row.node);
|
|
504
|
-
render();
|
|
505
|
-
}));
|
|
506
|
-
return { node: line, turn: line, code: line, row, open, marks: [] };
|
|
507
|
-
}
|
|
508
|
-
const turn = el("span", "sect-turn dom-turn");
|
|
509
|
-
turn.setAttribute("aria-hidden", "true");
|
|
510
|
-
const opens = row.kind !== "close" && row.kind !== "pseudo" && model.expandable(row.node);
|
|
511
|
-
if (opens) {
|
|
512
|
-
turn.append(icon("chevron-left", 12));
|
|
513
|
-
turn.addEventListener("click", (event) => {
|
|
514
|
-
event.stopPropagation();
|
|
515
|
-
setOpen(row.node, !model.isExpanded(row.node));
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
const code = pieceNodes(row);
|
|
519
|
-
line.append(turn, code);
|
|
520
|
-
if (row.kind === "close") {
|
|
521
|
-
line.setAttribute("aria-hidden", "true");
|
|
522
|
-
} else {
|
|
523
|
-
line.id = `${id}-${++made}`;
|
|
524
|
-
line.setAttribute("role", "treeitem");
|
|
525
|
-
line.setAttribute("aria-level", String(row.depth + 1));
|
|
526
|
-
if (opens)
|
|
527
|
-
line.setAttribute("aria-expanded", open ? "true" : "false");
|
|
528
|
-
}
|
|
529
|
-
const one = { node: line, turn, code, row, open, marks: [] };
|
|
530
|
-
mark(one, isSelected(row));
|
|
531
|
-
if (lit.has(row.node) && lit.get(row.node) === null)
|
|
532
|
-
line.classList.add("dom-flash");
|
|
533
|
-
const element = elementOf(row.node);
|
|
534
|
-
line.addEventListener("pointerenter", () => context.outline(element));
|
|
535
|
-
line.addEventListener("click", () => choose(row));
|
|
536
|
-
return one;
|
|
537
|
-
}
|
|
538
|
-
function builtOf(row) {
|
|
539
|
-
let lines = built.get(row.node);
|
|
540
|
-
if (!lines) {
|
|
541
|
-
lines = new Map;
|
|
542
|
-
built.set(row.node, lines);
|
|
543
|
-
}
|
|
544
|
-
const key = slot(row);
|
|
545
|
-
const had = lines.get(key);
|
|
546
|
-
const open = model.isExpanded(row.node);
|
|
547
|
-
if (had && had.row.depth === row.depth && had.open === open && had.row.more === row.more)
|
|
548
|
-
return had;
|
|
549
|
-
const one = build(row, open);
|
|
550
|
-
lines.set(key, one);
|
|
551
|
-
return one;
|
|
552
|
-
}
|
|
553
|
-
function lineOf(row) {
|
|
554
|
-
return builtOf(row).node;
|
|
555
|
-
}
|
|
556
|
-
function observe() {
|
|
557
|
-
if (!observer)
|
|
558
|
-
return;
|
|
559
|
-
observer.disconnect();
|
|
560
|
-
const root = model.root();
|
|
561
|
-
if (!root)
|
|
562
|
-
return;
|
|
563
|
-
const watch = new Map([[root, { childList: true }]]);
|
|
564
|
-
const add = (target, options) => watch.set(target, { ...watch.get(target), ...options });
|
|
565
|
-
for (const row of rows) {
|
|
566
|
-
if (row.kind === "open") {
|
|
567
|
-
add(row.node, { attributes: true, childList: true });
|
|
568
|
-
const first = row.node.firstChild;
|
|
569
|
-
if (first && first.nodeType === TEXT && first === row.node.lastChild)
|
|
570
|
-
add(first, { characterData: true });
|
|
571
|
-
} else if (row.kind === "shadow")
|
|
572
|
-
add(row.node, { childList: true });
|
|
573
|
-
else if (row.kind === "text" || row.kind === "comment")
|
|
574
|
-
add(row.node, { characterData: true });
|
|
575
|
-
}
|
|
576
|
-
for (const [target, options] of watch) {
|
|
577
|
-
try {
|
|
578
|
-
observer.observe(target, options);
|
|
579
|
-
} catch {}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
function render() {
|
|
583
|
-
clearTimeout(timer);
|
|
584
|
-
timer = 0;
|
|
585
|
-
rows = model.rows();
|
|
586
|
-
const lines = rows.map(lineOf);
|
|
587
|
-
lit = new Map;
|
|
588
|
-
const same = lines.length === shown.length && lines.every((line, at) => line === shown[at]);
|
|
589
|
-
if (!same) {
|
|
590
|
-
list.replaceChildren(...lines);
|
|
591
|
-
shown = lines;
|
|
592
|
-
}
|
|
593
|
-
activate();
|
|
594
|
-
if (!same)
|
|
595
|
-
observe();
|
|
596
|
-
}
|
|
597
|
-
function activate() {
|
|
598
|
-
const row = rows[selectedIndex()];
|
|
599
|
-
const line = row ? lineOf(row) : null;
|
|
600
|
-
list.setAttribute("aria-activedescendant", line?.id ?? "");
|
|
601
|
-
}
|
|
602
|
-
function selectedIndex() {
|
|
603
|
-
return rows.findIndex((row) => isSelected(row));
|
|
604
|
-
}
|
|
605
|
-
function cancelFrame() {
|
|
606
|
-
if (frame)
|
|
607
|
-
window.cancelAnimationFrame(frame);
|
|
608
|
-
frame = 0;
|
|
609
|
-
}
|
|
610
|
-
function across(line) {
|
|
611
|
-
const left = line.turn.offsetLeft;
|
|
612
|
-
const step = line.turn.offsetWidth;
|
|
613
|
-
const wide = node.clientWidth;
|
|
614
|
-
if (typeof left !== "number" || typeof step !== "number" || typeof wide !== "number")
|
|
615
|
-
return;
|
|
616
|
-
if (left >= node.scrollLeft && left <= node.scrollLeft + wide * 2 / 3)
|
|
617
|
-
return;
|
|
618
|
-
node.scrollLeft = Math.max(0, left - step);
|
|
619
|
-
}
|
|
620
|
-
function bringIntoView(middleOf, again = true) {
|
|
621
|
-
cancelFrame();
|
|
622
|
-
const row = rows[selectedIndex()];
|
|
623
|
-
if (!row)
|
|
624
|
-
return;
|
|
625
|
-
const seen = node.clientHeight;
|
|
626
|
-
if (seen === 0) {
|
|
627
|
-
if (again) {
|
|
628
|
-
frame = window.requestAnimationFrame(() => {
|
|
629
|
-
frame = 0;
|
|
630
|
-
bringIntoView(middleOf, false);
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
return;
|
|
634
|
-
}
|
|
635
|
-
const line = builtOf(row);
|
|
636
|
-
across(line);
|
|
637
|
-
const top = line.node.offsetTop;
|
|
638
|
-
const height = line.node.offsetHeight;
|
|
639
|
-
if (typeof top !== "number" || typeof height !== "number" || typeof seen !== "number")
|
|
640
|
-
return;
|
|
641
|
-
if (top >= node.scrollTop && top + height <= node.scrollTop + seen)
|
|
642
|
-
return;
|
|
643
|
-
if (middleOf)
|
|
644
|
-
node.scrollTop = Math.max(0, top - (seen - height) / 2);
|
|
645
|
-
else
|
|
646
|
-
node.scrollTop = top < node.scrollTop ? top : top + height - seen;
|
|
647
|
-
}
|
|
648
|
-
function repaint(target) {
|
|
649
|
-
for (const line of built.get(target)?.values() ?? [])
|
|
650
|
-
if (selectable(line.row))
|
|
651
|
-
mark(line, isSelected(line.row));
|
|
652
|
-
}
|
|
653
|
-
function setSelection(next) {
|
|
654
|
-
const before = selection;
|
|
655
|
-
selection = next;
|
|
656
|
-
if (before)
|
|
657
|
-
repaint(before.node);
|
|
658
|
-
if (next)
|
|
659
|
-
repaint(next.node);
|
|
660
|
-
}
|
|
661
|
-
function choose(row) {
|
|
662
|
-
const target = row.kind === "close" ? { node: row.node, pseudo: null } : { node: row.node, pseudo: row.pseudo };
|
|
663
|
-
setSelection(target);
|
|
664
|
-
activate();
|
|
665
|
-
bringIntoView(false);
|
|
666
|
-
context.select(target.node, target.pseudo);
|
|
667
|
-
}
|
|
668
|
-
function setOpen(target, open) {
|
|
669
|
-
if (open)
|
|
670
|
-
model.forget(target);
|
|
671
|
-
model.setExpanded(target, open);
|
|
672
|
-
drop(target);
|
|
673
|
-
render();
|
|
674
|
-
}
|
|
675
|
-
function onKeydown(event) {
|
|
676
|
-
if (event.altKey)
|
|
677
|
-
return;
|
|
678
|
-
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "c") {
|
|
679
|
-
if (!selection)
|
|
680
|
-
return;
|
|
681
|
-
event.preventDefault();
|
|
682
|
-
context.copy(markupOf(selection.node));
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
if (event.metaKey || event.ctrlKey)
|
|
686
|
-
return;
|
|
687
|
-
const step = stepFor(event.key, rows, selectedIndex(), model);
|
|
688
|
-
if (!step)
|
|
689
|
-
return;
|
|
690
|
-
event.preventDefault();
|
|
691
|
-
if (step.kind === "select") {
|
|
692
|
-
const row = rows[step.at];
|
|
693
|
-
if (row)
|
|
694
|
-
choose(row);
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
setOpen(step.node, step.kind === "expand");
|
|
698
|
-
}
|
|
699
|
-
function onLeave() {
|
|
700
|
-
context.outline(null);
|
|
701
|
-
}
|
|
702
|
-
function onLit(event) {
|
|
703
|
-
if (hasClasses(event.target))
|
|
704
|
-
event.target.classList.remove("dom-flash");
|
|
705
|
-
}
|
|
706
|
-
list.addEventListener("keydown", onKeydown);
|
|
707
|
-
list.addEventListener("pointerleave", onLeave);
|
|
708
|
-
list.addEventListener("animationend", onLit);
|
|
709
|
-
function onRecords(records) {
|
|
710
|
-
if (gone)
|
|
711
|
-
return;
|
|
712
|
-
let any = false;
|
|
713
|
-
const light = (target, name) => {
|
|
714
|
-
if (name === null) {
|
|
715
|
-
lit.set(target, null);
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
const names = lit.get(target);
|
|
719
|
-
if (names === null)
|
|
720
|
-
return;
|
|
721
|
-
lit.set(target, new Set([...names ?? [], name]));
|
|
722
|
-
};
|
|
723
|
-
for (const record of records) {
|
|
724
|
-
const target = record.target;
|
|
725
|
-
if (record.type === "childList") {
|
|
726
|
-
const nodes = [...Array.from(record.addedNodes ?? []), ...Array.from(record.removedNodes ?? [])];
|
|
727
|
-
if (nodes.length > 0 && nodes.every(isOwnNode))
|
|
728
|
-
continue;
|
|
729
|
-
model.forget(target);
|
|
730
|
-
drop(target);
|
|
731
|
-
for (const added of Array.from(record.addedNodes ?? []))
|
|
732
|
-
if (!isOwnNode(added))
|
|
733
|
-
light(added, null);
|
|
734
|
-
any = true;
|
|
735
|
-
} else if (record.type === "attributes") {
|
|
736
|
-
const name = record.attributeName ?? "";
|
|
737
|
-
if (isOwnAttribute(name))
|
|
738
|
-
continue;
|
|
739
|
-
model.forget(target);
|
|
740
|
-
drop(target);
|
|
741
|
-
light(target, name);
|
|
742
|
-
any = true;
|
|
743
|
-
} else if (record.type === "characterData") {
|
|
744
|
-
drop(target);
|
|
745
|
-
const parent = target.parentNode;
|
|
746
|
-
if (parent) {
|
|
747
|
-
model.forget(parent);
|
|
748
|
-
drop(parent);
|
|
749
|
-
}
|
|
750
|
-
light(target, null);
|
|
751
|
-
any = true;
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
if (any && !timer)
|
|
755
|
-
timer = window.setTimeout(render, SETTLE);
|
|
756
|
-
}
|
|
757
|
-
function reveal(target, pseudo = null) {
|
|
758
|
-
if (!target) {
|
|
759
|
-
observer?.disconnect();
|
|
760
|
-
clearTimeout(timer);
|
|
761
|
-
timer = 0;
|
|
762
|
-
cancelFrame();
|
|
763
|
-
model.setRoot(null);
|
|
764
|
-
built = new WeakMap;
|
|
765
|
-
selection = null;
|
|
766
|
-
rows = [];
|
|
767
|
-
shown = [];
|
|
768
|
-
list.replaceChildren();
|
|
769
|
-
node.hidden = true;
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
const doc = isDocument(target) ? target : target.ownerDocument;
|
|
773
|
-
if (doc !== model.root()) {
|
|
774
|
-
model.setRoot(doc);
|
|
775
|
-
built = new WeakMap;
|
|
776
|
-
}
|
|
777
|
-
node.hidden = false;
|
|
778
|
-
for (let at = parentOf(target);at; at = parentOf(at)) {
|
|
779
|
-
model.forget(at);
|
|
780
|
-
drop(at);
|
|
781
|
-
}
|
|
782
|
-
model.reveal(target);
|
|
783
|
-
setSelection({ node: target, pseudo });
|
|
784
|
-
render();
|
|
785
|
-
bringIntoView(true);
|
|
786
|
-
}
|
|
787
|
-
return {
|
|
788
|
-
node,
|
|
789
|
-
reveal,
|
|
790
|
-
selected: () => selection?.node ?? null,
|
|
791
|
-
destroy() {
|
|
792
|
-
gone = true;
|
|
793
|
-
observer?.disconnect();
|
|
794
|
-
clearTimeout(timer);
|
|
795
|
-
timer = 0;
|
|
796
|
-
cancelFrame();
|
|
797
|
-
list.removeEventListener("keydown", onKeydown);
|
|
798
|
-
list.removeEventListener("pointerleave", onLeave);
|
|
799
|
-
list.removeEventListener("animationend", onLit);
|
|
800
|
-
context.outline(null);
|
|
801
|
-
selection = null;
|
|
802
|
-
}
|
|
803
|
-
};
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
// src/styles/selector.ts
|
|
807
|
-
var LEGACY = new Set(["before", "after", "first-line", "first-letter"]);
|
|
808
|
-
var HEAVIEST = new Set(["is", "not", "has", "matches", "-webkit-any", "-moz-any"]);
|
|
809
|
-
var HEX = /[0-9a-f]/i;
|
|
810
|
-
function isIdentChar(char) {
|
|
811
|
-
return /[\w-]/.test(char) || char > "";
|
|
812
|
-
}
|
|
813
|
-
function skipEscape(text, at) {
|
|
814
|
-
let i = at + 1;
|
|
815
|
-
if (!HEX.test(text[i] ?? ""))
|
|
816
|
-
return i + 1;
|
|
817
|
-
for (let count = 0;count < 6 && HEX.test(text[i] ?? ""); count++)
|
|
818
|
-
i++;
|
|
819
|
-
return text[i] === " " ? i + 1 : i;
|
|
820
|
-
}
|
|
821
|
-
function skipIdent(text, at) {
|
|
822
|
-
let i = at;
|
|
823
|
-
while (i < text.length) {
|
|
824
|
-
const char = text[i] ?? "";
|
|
825
|
-
if (char === "\\")
|
|
826
|
-
i = skipEscape(text, i);
|
|
827
|
-
else if (isIdentChar(char))
|
|
828
|
-
i++;
|
|
829
|
-
else
|
|
830
|
-
break;
|
|
831
|
-
}
|
|
832
|
-
return i;
|
|
833
|
-
}
|
|
834
|
-
function skipString(text, at) {
|
|
835
|
-
const quote = text[at];
|
|
836
|
-
let i = at + 1;
|
|
837
|
-
while (i < text.length && text[i] !== quote)
|
|
838
|
-
i += text[i] === "\\" ? 2 : 1;
|
|
839
|
-
return i + 1;
|
|
840
|
-
}
|
|
841
|
-
function skipBlock(text, at) {
|
|
842
|
-
let depth = 0;
|
|
843
|
-
let i = at;
|
|
844
|
-
while (i < text.length) {
|
|
845
|
-
const char = text[i];
|
|
846
|
-
if (char === "\\") {
|
|
847
|
-
i += 2;
|
|
848
|
-
continue;
|
|
849
|
-
}
|
|
850
|
-
if (char === '"' || char === "'") {
|
|
851
|
-
i = skipString(text, i);
|
|
852
|
-
continue;
|
|
853
|
-
}
|
|
854
|
-
if (char === "(" || char === "[")
|
|
855
|
-
depth++;
|
|
856
|
-
else if (char === ")" || char === "]")
|
|
857
|
-
depth--;
|
|
858
|
-
i++;
|
|
859
|
-
if (depth === 0)
|
|
860
|
-
break;
|
|
861
|
-
}
|
|
862
|
-
return i;
|
|
863
|
-
}
|
|
864
|
-
function splitList(text) {
|
|
865
|
-
const parts = [];
|
|
866
|
-
let start = 0;
|
|
867
|
-
let i = 0;
|
|
868
|
-
while (i < text.length) {
|
|
869
|
-
const char = text[i];
|
|
870
|
-
if (char === "\\")
|
|
871
|
-
i += 2;
|
|
872
|
-
else if (char === '"' || char === "'")
|
|
873
|
-
i = skipString(text, i);
|
|
874
|
-
else if (char === "(" || char === "[")
|
|
875
|
-
i = skipBlock(text, i);
|
|
876
|
-
else {
|
|
877
|
-
if (char === ",") {
|
|
878
|
-
parts.push(text.slice(start, i));
|
|
879
|
-
start = i + 1;
|
|
880
|
-
}
|
|
881
|
-
i++;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
parts.push(text.slice(start));
|
|
885
|
-
return parts.map((part) => part.trim()).filter((part) => part.length > 0);
|
|
886
|
-
}
|
|
887
|
-
function readPseudo(text, at) {
|
|
888
|
-
const double = text[at + 1] === ":";
|
|
889
|
-
const nameStart = at + (double ? 2 : 1);
|
|
890
|
-
const nameEnd = skipIdent(text, nameStart);
|
|
891
|
-
const name = text.slice(nameStart, nameEnd).toLowerCase();
|
|
892
|
-
let end = nameEnd;
|
|
893
|
-
let args = null;
|
|
894
|
-
if (text[nameEnd] === "(") {
|
|
895
|
-
end = skipBlock(text, nameEnd);
|
|
896
|
-
args = text.slice(nameEnd + 1, text[end - 1] === ")" ? end - 1 : end).trim();
|
|
897
|
-
}
|
|
898
|
-
return { start: at, end, name, args, element: double || args === null && LEGACY.has(name) };
|
|
899
|
-
}
|
|
900
|
-
function add(a, b) {
|
|
901
|
-
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
902
|
-
}
|
|
903
|
-
function compareSpecificity(a, b) {
|
|
904
|
-
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
905
|
-
}
|
|
906
|
-
function heaviest(list) {
|
|
907
|
-
let best = [0, 0, 0];
|
|
908
|
-
for (const selector of splitList(list)) {
|
|
909
|
-
const found = specificity(selector);
|
|
910
|
-
if (compareSpecificity(found, best) > 0)
|
|
911
|
-
best = found;
|
|
912
|
-
}
|
|
913
|
-
return best;
|
|
914
|
-
}
|
|
915
|
-
function pseudoWeight(pseudo) {
|
|
916
|
-
const { name, args } = pseudo;
|
|
917
|
-
if (pseudo.element) {
|
|
918
|
-
return name === "slotted" && args ? add([0, 0, 1], specificity(args)) : [0, 0, 1];
|
|
919
|
-
}
|
|
920
|
-
if (args === null)
|
|
921
|
-
return [0, 1, 0];
|
|
922
|
-
if (name === "where")
|
|
923
|
-
return [0, 0, 0];
|
|
924
|
-
if (HEAVIEST.has(name))
|
|
925
|
-
return heaviest(args);
|
|
926
|
-
if (name === "nth-child" || name === "nth-last-child") {
|
|
927
|
-
const of = args.search(/\sof\s/i);
|
|
928
|
-
return of < 0 ? [0, 1, 0] : add([0, 1, 0], heaviest(args.slice(of + 4)));
|
|
929
|
-
}
|
|
930
|
-
if (name === "host" || name === "host-context")
|
|
931
|
-
return add([0, 1, 0], heaviest(args));
|
|
932
|
-
return [0, 1, 0];
|
|
933
|
-
}
|
|
934
|
-
function specificity(selector) {
|
|
935
|
-
let total = [0, 0, 0];
|
|
936
|
-
let i = 0;
|
|
937
|
-
while (i < selector.length) {
|
|
938
|
-
const char = selector[i] ?? "";
|
|
939
|
-
if (char === "#") {
|
|
940
|
-
total = add(total, [1, 0, 0]);
|
|
941
|
-
i = skipIdent(selector, i + 1);
|
|
942
|
-
} else if (char === ".") {
|
|
943
|
-
total = add(total, [0, 1, 0]);
|
|
944
|
-
i = skipIdent(selector, i + 1);
|
|
945
|
-
} else if (char === "[") {
|
|
946
|
-
total = add(total, [0, 1, 0]);
|
|
947
|
-
i = skipBlock(selector, i);
|
|
948
|
-
} else if (char === ":") {
|
|
949
|
-
const pseudo = readPseudo(selector, i);
|
|
950
|
-
total = add(total, pseudoWeight(pseudo));
|
|
951
|
-
i = Math.max(pseudo.end, i + 1);
|
|
952
|
-
} else if (char === "\\" || isIdentChar(char) && !/[\d]/.test(char)) {
|
|
953
|
-
const end = Math.max(skipIdent(selector, i), i + 1);
|
|
954
|
-
const namespace = selector[end] === "|" && selector[end + 1] !== "|";
|
|
955
|
-
if (!namespace)
|
|
956
|
-
total = add(total, [0, 0, 1]);
|
|
957
|
-
i = end;
|
|
958
|
-
} else {
|
|
959
|
-
i++;
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
return total;
|
|
963
|
-
}
|
|
964
|
-
function scan(selector) {
|
|
965
|
-
const pseudos = [];
|
|
966
|
-
const combinators = [];
|
|
967
|
-
let i = 0;
|
|
968
|
-
while (i < selector.length) {
|
|
969
|
-
const char = selector[i] ?? "";
|
|
970
|
-
if (char === "\\")
|
|
971
|
-
i += 2;
|
|
972
|
-
else if (char === "[" || char === "(")
|
|
973
|
-
i = skipBlock(selector, i);
|
|
974
|
-
else if (char === ":") {
|
|
975
|
-
const pseudo = readPseudo(selector, i);
|
|
976
|
-
pseudos.push(pseudo);
|
|
977
|
-
i = Math.max(pseudo.end, i + 1);
|
|
978
|
-
} else {
|
|
979
|
-
if (/[\s>+~]/.test(char))
|
|
980
|
-
combinators.push(i);
|
|
981
|
-
i++;
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
return { pseudos, combinators };
|
|
985
|
-
}
|
|
986
|
-
function isEdge(char) {
|
|
987
|
-
return char === undefined || /[\s>+~]/.test(char);
|
|
988
|
-
}
|
|
989
|
-
function cut2(selector, start, end) {
|
|
990
|
-
const empty = isEdge(selector[start - 1]) && isEdge(selector[end]);
|
|
991
|
-
return `${selector.slice(0, start)}${empty ? "*" : ""}${selector.slice(end)}`;
|
|
992
|
-
}
|
|
993
|
-
function normalizePseudo(pseudo) {
|
|
994
|
-
const text = pseudo.trim();
|
|
995
|
-
const colons = text.startsWith("::") ? 2 : text.startsWith(":") ? 1 : 0;
|
|
996
|
-
const open = text.indexOf("(");
|
|
997
|
-
const name = (open < 0 ? text : text.slice(0, open)).slice(colons).toLowerCase();
|
|
998
|
-
return `::${name}${open < 0 ? "" : text.slice(open)}`;
|
|
999
|
-
}
|
|
1000
|
-
function hostForm(selector) {
|
|
1001
|
-
const { pseudos, combinators } = scan(selector);
|
|
1002
|
-
const hosts = pseudos.filter(({ name }) => name === "host" || name === "host-context");
|
|
1003
|
-
if (hosts.length === 0 || combinators.length > 0)
|
|
1004
|
-
return null;
|
|
1005
|
-
let next = selector;
|
|
1006
|
-
for (const host of hosts.reverse()) {
|
|
1007
|
-
let own = ":scope";
|
|
1008
|
-
if (host.args !== null && host.name === "host")
|
|
1009
|
-
own = `:scope:is(${host.args})`;
|
|
1010
|
-
if (host.args !== null && host.name === "host-context") {
|
|
1011
|
-
own = `:scope:is(${host.args}, :is(${host.args}) *)`;
|
|
1012
|
-
}
|
|
1013
|
-
next = `${next.slice(0, host.start)}${own}${next.slice(host.end)}`;
|
|
1014
|
-
}
|
|
1015
|
-
return next;
|
|
1016
|
-
}
|
|
1017
|
-
function parseSubject(selector) {
|
|
1018
|
-
const text = selector.trim();
|
|
1019
|
-
const elements = scan(text).pseudos.filter((pseudo2) => pseudo2.element);
|
|
1020
|
-
let match = text;
|
|
1021
|
-
let pseudo = null;
|
|
1022
|
-
let slotted = null;
|
|
1023
|
-
for (const found of elements.reverse()) {
|
|
1024
|
-
if (found.name === "slotted" && found.args !== null)
|
|
1025
|
-
slotted = found.args;
|
|
1026
|
-
else
|
|
1027
|
-
pseudo ??= normalizePseudo(text.slice(found.start, found.end));
|
|
1028
|
-
match = cut2(match, found.start, found.end);
|
|
1029
|
-
}
|
|
1030
|
-
return { match, pseudo, slotted, host: slotted === null ? hostForm(match) : null };
|
|
1031
|
-
}
|
|
1032
|
-
function hasNesting(selector) {
|
|
1033
|
-
let i = 0;
|
|
1034
|
-
while (i < selector.length) {
|
|
1035
|
-
const char = selector[i];
|
|
1036
|
-
if (char === "\\")
|
|
1037
|
-
i += 2;
|
|
1038
|
-
else if (char === "[")
|
|
1039
|
-
i = skipBlock(selector, i);
|
|
1040
|
-
else if (char === '"' || char === "'")
|
|
1041
|
-
i = skipString(selector, i);
|
|
1042
|
-
else if (char === "&")
|
|
1043
|
-
return true;
|
|
1044
|
-
else
|
|
1045
|
-
i++;
|
|
1046
|
-
}
|
|
1047
|
-
return false;
|
|
1048
|
-
}
|
|
1049
|
-
function replaceNesting(selector, parent) {
|
|
1050
|
-
let next = "";
|
|
1051
|
-
let i = 0;
|
|
1052
|
-
while (i < selector.length) {
|
|
1053
|
-
const char = selector[i] ?? "";
|
|
1054
|
-
let end = i + 1;
|
|
1055
|
-
if (char === "\\")
|
|
1056
|
-
end = i + 2;
|
|
1057
|
-
else if (char === "[")
|
|
1058
|
-
end = skipBlock(selector, i);
|
|
1059
|
-
else if (char === '"' || char === "'")
|
|
1060
|
-
end = skipString(selector, i);
|
|
1061
|
-
next += char === "&" ? parent : selector.slice(i, end);
|
|
1062
|
-
i = end;
|
|
1063
|
-
}
|
|
1064
|
-
return next;
|
|
1065
|
-
}
|
|
1066
|
-
function resolveNesting(selector, parent) {
|
|
1067
|
-
const text = selector.trim();
|
|
1068
|
-
const stands = parent === null ? ":scope" : `:is(${parent})`;
|
|
1069
|
-
if (hasNesting(text))
|
|
1070
|
-
return replaceNesting(text, stands);
|
|
1071
|
-
if (parent === null)
|
|
1072
|
-
return text;
|
|
1073
|
-
return `${stands} ${text}`;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
// src/styles/cascade.ts
|
|
1077
|
-
function compare(a, aImportant, b, bImportant) {
|
|
1078
|
-
if (aImportant !== bImportant)
|
|
1079
|
-
return aImportant ? 1 : -1;
|
|
1080
|
-
const turned = aImportant ? -1 : 1;
|
|
1081
|
-
if (a.context !== b.context)
|
|
1082
|
-
return (b.context - a.context) * turned;
|
|
1083
|
-
if (a.inline !== b.inline)
|
|
1084
|
-
return a.inline ? 1 : -1;
|
|
1085
|
-
if (a.layer !== b.layer)
|
|
1086
|
-
return (a.layer - b.layer) * turned;
|
|
1087
|
-
return compareSpecificity(a.specificity, b.specificity) || a.order - b.order;
|
|
1088
|
-
}
|
|
1089
|
-
function winners(candidates) {
|
|
1090
|
-
const won = new Map;
|
|
1091
|
-
for (const candidate of candidates) {
|
|
1092
|
-
for (const declaration of candidate.declarations) {
|
|
1093
|
-
for (const longhand of declaration.longhands) {
|
|
1094
|
-
const best = won.get(longhand);
|
|
1095
|
-
const beats = !best || compare(candidate.source, declaration.important, best.candidate.source, best.declaration.important) >= 0;
|
|
1096
|
-
if (beats)
|
|
1097
|
-
won.set(longhand, { candidate, declaration });
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
return won;
|
|
1102
|
-
}
|
|
1103
|
-
function markOwn(candidates, won) {
|
|
1104
|
-
for (const candidate of candidates) {
|
|
1105
|
-
for (const declaration of candidate.declarations) {
|
|
1106
|
-
const lost = declaration.longhands.every((longhand) => won.get(longhand)?.declaration !== declaration);
|
|
1107
|
-
declaration.overridden = lost;
|
|
1108
|
-
const by = won.get(declaration.longhands[0] ?? "")?.candidate.id;
|
|
1109
|
-
if (lost && by !== undefined)
|
|
1110
|
-
declaration.overriddenBy = by;
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
function settleInherited(candidates, taken, inherits) {
|
|
1115
|
-
for (const candidate of candidates) {
|
|
1116
|
-
candidate.declarations = candidate.declarations.filter((declaration) => declaration.longhands.some(inherits));
|
|
1117
|
-
}
|
|
1118
|
-
const kept = candidates.filter((candidate) => candidate.declarations.length > 0);
|
|
1119
|
-
const won = winners(kept);
|
|
1120
|
-
for (const candidate of kept) {
|
|
1121
|
-
for (const declaration of candidate.declarations) {
|
|
1122
|
-
const passed = declaration.longhands.filter(inherits);
|
|
1123
|
-
const live = passed.some((longhand) => !taken.has(longhand) && won.get(longhand)?.declaration === declaration);
|
|
1124
|
-
declaration.overridden = !live;
|
|
1125
|
-
const first = passed[0] ?? "";
|
|
1126
|
-
const by = taken.get(first) ?? won.get(first)?.candidate.id;
|
|
1127
|
-
if (!live && by !== undefined)
|
|
1128
|
-
declaration.overriddenBy = by;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
for (const [longhand, winner] of won) {
|
|
1132
|
-
if (inherits(longhand) && !taken.has(longhand))
|
|
1133
|
-
taken.set(longhand, winner.candidate.id);
|
|
1134
|
-
}
|
|
1135
|
-
return kept;
|
|
1136
|
-
}
|
|
1137
|
-
var STEADY = new Set([
|
|
1138
|
-
"box-sizing",
|
|
1139
|
-
"flex-direction",
|
|
1140
|
-
"flex-wrap",
|
|
1141
|
-
"object-fit",
|
|
1142
|
-
"pointer-events",
|
|
1143
|
-
"position",
|
|
1144
|
-
"text-transform",
|
|
1145
|
-
"visibility"
|
|
1146
|
-
]);
|
|
1147
|
-
var STEADY_DISPLAY = new Set(["none", "block", "flex", "grid"]);
|
|
1148
|
-
var WIDE = new Set(["inherit", "initial", "unset", "revert", "revert-layer"]);
|
|
1149
|
-
function tidy(property, value) {
|
|
1150
|
-
const text = value.trim().replace(/\s+/g, " ");
|
|
1151
|
-
return property.startsWith("--") ? text : text.toLowerCase();
|
|
1152
|
-
}
|
|
1153
|
-
function isSteady(property, value) {
|
|
1154
|
-
if (property.startsWith("--"))
|
|
1155
|
-
return value !== "" && !value.includes("var(");
|
|
1156
|
-
if (WIDE.has(value))
|
|
1157
|
-
return false;
|
|
1158
|
-
if (property === "display")
|
|
1159
|
-
return STEADY_DISPLAY.has(value);
|
|
1160
|
-
return STEADY.has(property) && /^[a-z-]+$/.test(value);
|
|
1161
|
-
}
|
|
1162
|
-
function settleContainers(candidates, computed) {
|
|
1163
|
-
let live = [...candidates];
|
|
1164
|
-
for (let decided = true;decided; ) {
|
|
1165
|
-
decided = false;
|
|
1166
|
-
for (const candidate of [...live]) {
|
|
1167
|
-
const conditional = candidate.conditional;
|
|
1168
|
-
if (conditional?.kind !== "container" || conditional.confirmed)
|
|
1169
|
-
continue;
|
|
1170
|
-
const without = live.filter((other) => other !== candidate);
|
|
1171
|
-
const verdict = judge(candidate, winners(live), winners(without), computed);
|
|
1172
|
-
if (verdict === null)
|
|
1173
|
-
continue;
|
|
1174
|
-
decided = true;
|
|
1175
|
-
if (verdict)
|
|
1176
|
-
conditional.confirmed = true;
|
|
1177
|
-
else
|
|
1178
|
-
live = without;
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
return live;
|
|
1182
|
-
}
|
|
1183
|
-
function judge(candidate, won, without, computed) {
|
|
1184
|
-
for (const [longhand, winner] of won) {
|
|
1185
|
-
if (winner.candidate !== candidate)
|
|
1186
|
-
continue;
|
|
1187
|
-
const mine = tidy(longhand, candidate.value(longhand));
|
|
1188
|
-
if (!isSteady(longhand, mine))
|
|
1189
|
-
continue;
|
|
1190
|
-
if (tidy(longhand, computed(longhand)) !== mine)
|
|
1191
|
-
return false;
|
|
1192
|
-
const next = without.get(longhand);
|
|
1193
|
-
const other = next ? tidy(longhand, next.candidate.value(longhand)) : null;
|
|
1194
|
-
if (other !== null && other !== mine && isSteady(longhand, other))
|
|
1195
|
-
return true;
|
|
1196
|
-
}
|
|
1197
|
-
return null;
|
|
1198
|
-
}
|
|
1199
|
-
function byStrength(candidates) {
|
|
1200
|
-
return [...candidates].sort((a, b) => compare(b.source, false, a.source, false));
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
// src/styles/collect.ts
|
|
1204
|
-
function isKind(rule, kind) {
|
|
1205
|
-
return rule.constructor.name === kind;
|
|
1206
|
-
}
|
|
1207
|
-
function sheetName(sheet) {
|
|
1208
|
-
return sheet.href ?? (sheet.ownerNode ? "<style>" : "constructed");
|
|
1209
|
-
}
|
|
1210
|
-
function ownerOf(sheet) {
|
|
1211
|
-
const node = sheet.ownerNode;
|
|
1212
|
-
return node && "hasAttribute" in node ? node : null;
|
|
1213
|
-
}
|
|
1214
|
-
function layerPath(walk, name) {
|
|
1215
|
-
if (name)
|
|
1216
|
-
return name.split(".");
|
|
1217
|
-
walk.layers.anonymous += 1;
|
|
1218
|
-
return [`(anonymous ${walk.layers.anonymous})`];
|
|
1219
|
-
}
|
|
1220
|
-
function enterLayer(walk, frame, name) {
|
|
1221
|
-
const layer = [...frame.layer, ...layerPath(walk, name)];
|
|
1222
|
-
walk.flat.layers.push({ path: layer, conditions: frame.conditions });
|
|
1223
|
-
const context = [...frame.context, name ? `@layer ${name}` : "@layer"];
|
|
1224
|
-
return { ...frame, layer, context };
|
|
1225
|
-
}
|
|
1226
|
-
function standalone(text, frame) {
|
|
1227
|
-
if (frame.parent !== null || !frame.scope)
|
|
1228
|
-
return resolveNesting(text, frame.parent);
|
|
1229
|
-
const rooted = text.replace(/:scope(?![\w-])/gi, "&");
|
|
1230
|
-
return hasNesting(rooted) ? resolveNesting(rooted, frame.scope.start) : text;
|
|
1231
|
-
}
|
|
1232
|
-
function partsOf(selectorText, frame) {
|
|
1233
|
-
const resolved = [];
|
|
1234
|
-
const parts = splitList(selectorText).map((text) => {
|
|
1235
|
-
const alone = standalone(text, frame);
|
|
1236
|
-
resolved.push(alone);
|
|
1237
|
-
return { ...parseSubject(alone), text, specificity: specificity(alone) };
|
|
1238
|
-
});
|
|
1239
|
-
return { parts, resolved: resolved.join(", ") };
|
|
1240
|
-
}
|
|
1241
|
-
function push(walk, frame, rule, selectorText, index) {
|
|
1242
|
-
const { parts, resolved } = partsOf(selectorText, frame);
|
|
1243
|
-
walk.flat.rules.push({
|
|
1244
|
-
rule,
|
|
1245
|
-
selectorText,
|
|
1246
|
-
parts,
|
|
1247
|
-
context: frame.context,
|
|
1248
|
-
conditions: frame.conditions,
|
|
1249
|
-
layer: frame.layer.join("."),
|
|
1250
|
-
scope: frame.scope,
|
|
1251
|
-
conditional: frame.conditional,
|
|
1252
|
-
origin: {
|
|
1253
|
-
sheet: walk.sheet,
|
|
1254
|
-
owner: walk.owner ? label(walk.owner) : null,
|
|
1255
|
-
path: [...frame.path, index]
|
|
1256
|
-
},
|
|
1257
|
-
order: walk.flat.rules.length
|
|
1258
|
-
});
|
|
1259
|
-
return resolved;
|
|
1260
|
-
}
|
|
1261
|
-
function visit(walk, frame, rule, index) {
|
|
1262
|
-
const inside = { ...frame, path: [...frame.path, index] };
|
|
1263
|
-
if (isKind(rule, "CSSStyleRule")) {
|
|
1264
|
-
const resolved = push(walk, frame, rule, rule.selectorText, index);
|
|
1265
|
-
if (rule.cssRules?.length) {
|
|
1266
|
-
const context = [...frame.context, rule.selectorText];
|
|
1267
|
-
walkRules(walk, { ...inside, context, parent: resolved }, rule.cssRules);
|
|
1268
|
-
}
|
|
1269
|
-
} else if (isKind(rule, "CSSNestedDeclarations")) {
|
|
1270
|
-
push(walk, frame, rule, "&", index);
|
|
1271
|
-
} else if (isKind(rule, "CSSImportRule")) {
|
|
1272
|
-
if (!rule.styleSheet)
|
|
1273
|
-
return;
|
|
1274
|
-
let next = inside;
|
|
1275
|
-
if (rule.layerName != null)
|
|
1276
|
-
next = enterLayer(walk, next, rule.layerName);
|
|
1277
|
-
if (rule.supportsText) {
|
|
1278
|
-
const context = [...next.context, `@supports ${rule.supportsText}`];
|
|
1279
|
-
const condition = { kind: "supports", text: rule.supportsText };
|
|
1280
|
-
next = { ...next, context, conditions: [...next.conditions, condition] };
|
|
1281
|
-
}
|
|
1282
|
-
if (rule.media.mediaText)
|
|
1283
|
-
next = withMedia(next, rule.media, authoredQuery(rule));
|
|
1284
|
-
walkSheet({ ...walk, sheet: sheetName(rule.styleSheet) }, next, rule.styleSheet);
|
|
1285
|
-
} else if (isKind(rule, "CSSMediaRule")) {
|
|
1286
|
-
walkRules(walk, withMedia(inside, rule.media, authoredQuery(rule)), rule.cssRules);
|
|
1287
|
-
} else if (isKind(rule, "CSSSupportsRule")) {
|
|
1288
|
-
const context = [...frame.context, `@supports ${rule.conditionText}`];
|
|
1289
|
-
const condition = { kind: "supports", text: rule.conditionText };
|
|
1290
|
-
const conditions = [...frame.conditions, condition];
|
|
1291
|
-
walkRules(walk, { ...inside, context, conditions }, rule.cssRules);
|
|
1292
|
-
} else if (isKind(rule, "CSSContainerRule")) {
|
|
1293
|
-
const context = [...frame.context, `@container ${rule.conditionText}`];
|
|
1294
|
-
walkRules(walk, { ...inside, context, conditional: "container" }, rule.cssRules);
|
|
1295
|
-
} else if (isKind(rule, "CSSLayerBlockRule")) {
|
|
1296
|
-
walkRules(walk, enterLayer(walk, inside, rule.name), rule.cssRules);
|
|
1297
|
-
} else if (isKind(rule, "CSSLayerStatementRule")) {
|
|
1298
|
-
for (const name of rule.nameList) {
|
|
1299
|
-
const path = [...frame.layer, ...name.split(".")];
|
|
1300
|
-
walk.flat.layers.push({ path, conditions: frame.conditions });
|
|
1301
|
-
}
|
|
1302
|
-
} else if (isKind(rule, "CSSScopeRule")) {
|
|
1303
|
-
const limits = rule.end ? `(${rule.start}) to (${rule.end})` : `(${rule.start})`;
|
|
1304
|
-
const context = [...frame.context, rule.start ? `@scope ${limits}` : "@scope"];
|
|
1305
|
-
const scope = { start: rule.start, end: rule.end, around: walk.owner?.parentElement ?? null };
|
|
1306
|
-
const conditional = frame.conditional ?? "scope";
|
|
1307
|
-
walkRules(walk, { ...inside, context, scope, conditional, parent: null }, rule.cssRules);
|
|
1308
|
-
} else if (isKind(rule, "CSSPropertyRule")) {
|
|
1309
|
-
walk.flat.registered.set(rule.name, rule.inherits);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
function withMedia(frame, list, authored) {
|
|
1313
|
-
return {
|
|
1314
|
-
...frame,
|
|
1315
|
-
context: [...frame.context, `@media ${authored}`],
|
|
1316
|
-
conditions: [...frame.conditions, { kind: "media", list }]
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
function walkRules(walk, frame, rules) {
|
|
1320
|
-
for (let i = 0;i < rules.length; i++) {
|
|
1321
|
-
const rule = rules[i];
|
|
1322
|
-
if (!rule)
|
|
1323
|
-
continue;
|
|
1324
|
-
try {
|
|
1325
|
-
visit(walk, frame, rule, i);
|
|
1326
|
-
} catch {
|
|
1327
|
-
walk.flat.skipped += 1;
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
function isSecurityError(error) {
|
|
1332
|
-
if (typeof error !== "object" || error === null)
|
|
1333
|
-
return false;
|
|
1334
|
-
return "name" in error && error.name === "SecurityError";
|
|
1335
|
-
}
|
|
1336
|
-
function walkSheet(walk, frame, sheet) {
|
|
1337
|
-
if (walk.seen.has(sheet))
|
|
1338
|
-
return;
|
|
1339
|
-
walk.seen.add(sheet);
|
|
1340
|
-
let rules;
|
|
1341
|
-
try {
|
|
1342
|
-
rules = sheet.cssRules;
|
|
1343
|
-
} catch (error) {
|
|
1344
|
-
const reason = isSecurityError(error) ? "cross-origin" : "unreadable";
|
|
1345
|
-
walk.flat.hidden.push({ sheet: sheetName(sheet), reason });
|
|
1346
|
-
return;
|
|
1347
|
-
}
|
|
1348
|
-
walkRules(walk, frame, rules);
|
|
1349
|
-
}
|
|
1350
|
-
function sheetsOf(scope) {
|
|
1351
|
-
return [...Array.from(scope.styleSheets), ...scope.adoptedStyleSheets ?? []];
|
|
1352
|
-
}
|
|
1353
|
-
function isOwn(sheet) {
|
|
1354
|
-
if (isOwnSheet(sheet))
|
|
1355
|
-
return true;
|
|
1356
|
-
const owner = ownerOf(sheet);
|
|
1357
|
-
return owner !== null && isDevknobs(owner);
|
|
1358
|
-
}
|
|
1359
|
-
function flatten(scope, sheets) {
|
|
1360
|
-
const flat = { rules: [], layers: [], hidden: [], registered: new Map, skipped: 0 };
|
|
1361
|
-
if (isShadowRoot(scope) && isDevknobs(scope.host))
|
|
1362
|
-
return flat;
|
|
1363
|
-
const seen = new Set;
|
|
1364
|
-
const layers = { anonymous: 0 };
|
|
1365
|
-
for (const sheet of sheets) {
|
|
1366
|
-
try {
|
|
1367
|
-
if (sheet.disabled || isOwn(sheet))
|
|
1368
|
-
continue;
|
|
1369
|
-
const walk = { flat, seen, sheet: sheetName(sheet), owner: ownerOf(sheet), layers };
|
|
1370
|
-
let frame = {
|
|
1371
|
-
context: [],
|
|
1372
|
-
conditions: [],
|
|
1373
|
-
layer: [],
|
|
1374
|
-
parent: null,
|
|
1375
|
-
scope: null,
|
|
1376
|
-
conditional: null,
|
|
1377
|
-
path: []
|
|
1378
|
-
};
|
|
1379
|
-
if (sheet.media.mediaText)
|
|
1380
|
-
frame = withMedia(frame, sheet.media, sheet.media.mediaText);
|
|
1381
|
-
walkSheet(walk, frame, sheet);
|
|
1382
|
-
} catch {
|
|
1383
|
-
flat.skipped += 1;
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
return flat;
|
|
1387
|
-
}
|
|
1388
|
-
function signature(sheets) {
|
|
1389
|
-
return sheets.map((sheet) => {
|
|
1390
|
-
try {
|
|
1391
|
-
return sheet.disabled ? -2 : sheet.cssRules.length;
|
|
1392
|
-
} catch {
|
|
1393
|
-
return -1;
|
|
1394
|
-
}
|
|
1395
|
-
});
|
|
1396
|
-
}
|
|
1397
|
-
var cache = new WeakMap;
|
|
1398
|
-
var version = 0;
|
|
1399
|
-
function same(a, b) {
|
|
1400
|
-
return a.length === b.length && a.every((value, i) => value === b[i]);
|
|
1401
|
-
}
|
|
1402
|
-
function invalidate() {
|
|
1403
|
-
version += 1;
|
|
1404
|
-
}
|
|
1405
|
-
function rulesOf(scope) {
|
|
1406
|
-
const sheets = sheetsOf(scope);
|
|
1407
|
-
const now = signature(sheets);
|
|
1408
|
-
const known = cache.get(scope);
|
|
1409
|
-
const fresh = known?.version === version && same(known.sheets, sheets);
|
|
1410
|
-
if (known && fresh && same(known.signature, now))
|
|
1411
|
-
return known.flat;
|
|
1412
|
-
const flat = flatten(scope, sheets);
|
|
1413
|
-
cache.set(scope, { version, sheets, signature: now, flat });
|
|
1414
|
-
return flat;
|
|
1415
|
-
}
|
|
1416
|
-
function layerRanks(marks, holds) {
|
|
1417
|
-
const root = { children: new Map };
|
|
1418
|
-
for (const mark of marks) {
|
|
1419
|
-
if (!holds(mark.conditions))
|
|
1420
|
-
continue;
|
|
1421
|
-
let layer = root;
|
|
1422
|
-
for (const step of mark.path) {
|
|
1423
|
-
let child = layer.children.get(step);
|
|
1424
|
-
if (!child) {
|
|
1425
|
-
child = { children: new Map };
|
|
1426
|
-
layer.children.set(step, child);
|
|
1427
|
-
}
|
|
1428
|
-
layer = child;
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
const ranks = new Map;
|
|
1432
|
-
const place = (layer, name) => {
|
|
1433
|
-
for (const [step, child] of layer.children)
|
|
1434
|
-
place(child, name ? `${name}.${step}` : step);
|
|
1435
|
-
ranks.set(name, ranks.size);
|
|
1436
|
-
};
|
|
1437
|
-
place(root, "");
|
|
1438
|
-
return ranks;
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
// src/styles/declarations.ts
|
|
1442
|
-
var IMPORTANT = /!\s*important\s*$/i;
|
|
1443
|
-
function skipString2(text, at) {
|
|
1444
|
-
const quote = text[at];
|
|
1445
|
-
let i = at + 1;
|
|
1446
|
-
while (i < text.length && text[i] !== quote)
|
|
1447
|
-
i += text[i] === "\\" ? 2 : 1;
|
|
1448
|
-
return i + 1;
|
|
1449
|
-
}
|
|
1450
|
-
function split(text) {
|
|
1451
|
-
const found = [];
|
|
1452
|
-
let name = null;
|
|
1453
|
-
let piece = "";
|
|
1454
|
-
let depth = 0;
|
|
1455
|
-
const close = () => {
|
|
1456
|
-
if (name !== null && name.trim())
|
|
1457
|
-
found.push({ name: name.trim(), value: piece.trim() });
|
|
1458
|
-
name = null;
|
|
1459
|
-
piece = "";
|
|
1460
|
-
};
|
|
1461
|
-
let i = 0;
|
|
1462
|
-
while (i < text.length) {
|
|
1463
|
-
const char = text[i] ?? "";
|
|
1464
|
-
let end = i + 1;
|
|
1465
|
-
if (char === "\\")
|
|
1466
|
-
end = i + 2;
|
|
1467
|
-
else if (char === '"' || char === "'")
|
|
1468
|
-
end = skipString2(text, i);
|
|
1469
|
-
else if (char === "/" && text[i + 1] === "*") {
|
|
1470
|
-
const stop = text.indexOf("*/", i + 2);
|
|
1471
|
-
i = stop < 0 ? text.length : stop + 2;
|
|
1472
|
-
continue;
|
|
1473
|
-
} else if (char === "(" || char === "[" || char === "{")
|
|
1474
|
-
depth++;
|
|
1475
|
-
else if (char === ")" || char === "]" || char === "}")
|
|
1476
|
-
depth = Math.max(0, depth - 1);
|
|
1477
|
-
else if (depth === 0 && char === ";") {
|
|
1478
|
-
close();
|
|
1479
|
-
i = end;
|
|
1480
|
-
continue;
|
|
1481
|
-
} else if (depth === 0 && char === ":" && name === null) {
|
|
1482
|
-
name = piece;
|
|
1483
|
-
piece = "";
|
|
1484
|
-
i = end;
|
|
1485
|
-
continue;
|
|
1486
|
-
}
|
|
1487
|
-
piece += text.slice(i, end);
|
|
1488
|
-
i = end;
|
|
1489
|
-
}
|
|
1490
|
-
close();
|
|
1491
|
-
return found;
|
|
1492
|
-
}
|
|
1493
|
-
function parseDeclarations(cssText) {
|
|
1494
|
-
return split(cssText).map(({ name, value }) => {
|
|
1495
|
-
const important = IMPORTANT.test(value);
|
|
1496
|
-
return {
|
|
1497
|
-
name: name.startsWith("--") ? name : name.toLowerCase(),
|
|
1498
|
-
value: important ? value.replace(IMPORTANT, "").trim() : value,
|
|
1499
|
-
important
|
|
1500
|
-
};
|
|
1501
|
-
});
|
|
1502
|
-
}
|
|
1503
|
-
function variableNames(value) {
|
|
1504
|
-
return [...new Set(varReferences(value).map((reference) => reference.name))];
|
|
1505
|
-
}
|
|
1506
|
-
function listed(style) {
|
|
1507
|
-
const names = [];
|
|
1508
|
-
for (let i = 0;i < style.length; i++) {
|
|
1509
|
-
const name = style.item(i);
|
|
1510
|
-
if (name)
|
|
1511
|
-
names.push(name);
|
|
1512
|
-
}
|
|
1513
|
-
return names;
|
|
1514
|
-
}
|
|
1515
|
-
function longhandsOf(name, names, expand) {
|
|
1516
|
-
if (name.startsWith("--") || names.includes(name))
|
|
1517
|
-
return [name];
|
|
1518
|
-
const known = expand(name).filter((longhand) => names.includes(longhand));
|
|
1519
|
-
if (known.length > 0)
|
|
1520
|
-
return known;
|
|
1521
|
-
const under = names.filter((longhand) => longhand.startsWith(`${name}-`));
|
|
1522
|
-
return under.length > 0 ? under : [name];
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
// src/styles/inherited.ts
|
|
1526
|
-
var INHERITED = new Set(`accent-color border-collapse border-spacing caption-side caret-color caret-shape clip-rule color
|
|
1527
|
-
color-interpolation color-interpolation-filters color-rendering color-scheme cursor direction
|
|
1528
|
-
dominant-baseline dynamic-range-limit empty-cells fill fill-opacity fill-rule font font-family
|
|
1529
|
-
font-feature-settings font-kerning font-language-override font-optical-sizing font-palette font-size
|
|
1530
|
-
font-size-adjust font-stretch font-style font-synthesis font-synthesis-position
|
|
1531
|
-
font-synthesis-small-caps font-synthesis-style font-synthesis-weight font-variant
|
|
1532
|
-
font-variant-alternates font-variant-caps font-variant-east-asian font-variant-emoji
|
|
1533
|
-
font-variant-ligatures font-variant-numeric font-variant-position font-variation-settings font-weight
|
|
1534
|
-
font-width forced-color-adjust hanging-punctuation hyphenate-character hyphenate-limit-chars hyphens
|
|
1535
|
-
image-orientation image-rendering interactivity interpolate-size letter-spacing line-break line-height
|
|
1536
|
-
list-style list-style-image list-style-position list-style-type marker marker-end marker-mid
|
|
1537
|
-
marker-start math-depth math-shift math-style orphans overflow-wrap paint-order pointer-events
|
|
1538
|
-
print-color-adjust quotes ruby-align ruby-position scrollbar-color shape-rendering speak stroke
|
|
1539
|
-
stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity
|
|
1540
|
-
stroke-width tab-size text-align text-align-last text-anchor text-autospace text-box-edge
|
|
1541
|
-
text-combine-upright text-decoration-skip-ink text-emphasis text-emphasis-color text-emphasis-position
|
|
1542
|
-
text-emphasis-style text-indent text-justify text-orientation text-rendering text-shadow
|
|
1543
|
-
text-size-adjust text-spacing-trim text-transform text-underline-offset text-underline-position
|
|
1544
|
-
text-wrap text-wrap-mode text-wrap-style visibility white-space white-space-collapse widows word-break
|
|
1545
|
-
word-spacing word-wrap writing-mode -moz-osx-font-smoothing -webkit-border-horizontal-spacing
|
|
1546
|
-
-webkit-border-vertical-spacing -webkit-font-smoothing -webkit-line-break -webkit-locale
|
|
1547
|
-
-webkit-print-color-adjust -webkit-rtl-ordering -webkit-tap-highlight-color -webkit-text-fill-color
|
|
1548
|
-
-webkit-text-orientation -webkit-text-size-adjust -webkit-text-stroke -webkit-text-stroke-color
|
|
1549
|
-
-webkit-text-stroke-width -webkit-user-modify -webkit-writing-mode`.split(/\s+/));
|
|
1550
|
-
function isInherited(property, registered) {
|
|
1551
|
-
if (property.startsWith("--"))
|
|
1552
|
-
return registered.get(property) ?? true;
|
|
1553
|
-
return INHERITED.has(property);
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
// src/styles/match.ts
|
|
1557
|
-
function conditionsFor(view) {
|
|
1558
|
-
const known = new Map;
|
|
1559
|
-
const test = (key, run) => {
|
|
1560
|
-
let result = known.get(key);
|
|
1561
|
-
if (result === undefined) {
|
|
1562
|
-
try {
|
|
1563
|
-
result = run();
|
|
1564
|
-
} catch {
|
|
1565
|
-
result = false;
|
|
1566
|
-
}
|
|
1567
|
-
known.set(key, result);
|
|
1568
|
-
}
|
|
1569
|
-
return result;
|
|
1570
|
-
};
|
|
1571
|
-
return (conditions) => conditions.every((condition) => {
|
|
1572
|
-
if (condition.kind === "supports") {
|
|
1573
|
-
return test(`s:${condition.text}`, () => view.CSS.supports(condition.text));
|
|
1574
|
-
}
|
|
1575
|
-
const text = condition.list.mediaText;
|
|
1576
|
-
return text === "" || test(`m:${text}`, () => view.matchMedia(text).matches);
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
function reaches(element, part, reach) {
|
|
1580
|
-
if (reach.kind === "host")
|
|
1581
|
-
return part.host !== null && element.matches(part.host);
|
|
1582
|
-
if (reach.kind === "slotted") {
|
|
1583
|
-
if (part.slotted === null)
|
|
1584
|
-
return false;
|
|
1585
|
-
return element.matches(part.slotted) && reach.slot.matches(part.match);
|
|
1586
|
-
}
|
|
1587
|
-
return part.host === null && part.slotted === null && element.matches(part.match);
|
|
1588
|
-
}
|
|
1589
|
-
function inScope(element, scope) {
|
|
1590
|
-
let root = scope.around;
|
|
1591
|
-
if (scope.start !== null) {
|
|
1592
|
-
root = element;
|
|
1593
|
-
while (root && !root.matches(scope.start))
|
|
1594
|
-
root = root.parentElement;
|
|
1595
|
-
if (!root)
|
|
1596
|
-
return false;
|
|
1597
|
-
} else if (root && !root.contains(element)) {
|
|
1598
|
-
return false;
|
|
1599
|
-
}
|
|
1600
|
-
if (scope.end === null)
|
|
1601
|
-
return true;
|
|
1602
|
-
for (let current = element;current && current !== root; ) {
|
|
1603
|
-
if (current.matches(scope.end))
|
|
1604
|
-
return false;
|
|
1605
|
-
current = current.parentElement;
|
|
1606
|
-
}
|
|
1607
|
-
return true;
|
|
1608
|
-
}
|
|
1609
|
-
function matchRules(element, rules, reach, wanted, checks, skip) {
|
|
1610
|
-
const found = new Map;
|
|
1611
|
-
for (const flat of rules) {
|
|
1612
|
-
if (skip?.(flat) || !checks.holds(flat.conditions))
|
|
1613
|
-
continue;
|
|
1614
|
-
let hits = null;
|
|
1615
|
-
for (let i = 0;i < flat.parts.length; i++) {
|
|
1616
|
-
const part = flat.parts[i];
|
|
1617
|
-
const styles = part?.pseudo ?? "";
|
|
1618
|
-
if (!part || !wanted.has(styles))
|
|
1619
|
-
continue;
|
|
1620
|
-
try {
|
|
1621
|
-
if (!reaches(element, part, reach))
|
|
1622
|
-
continue;
|
|
1623
|
-
if (flat.scope && !inScope(element, flat.scope))
|
|
1624
|
-
continue;
|
|
1625
|
-
} catch {
|
|
1626
|
-
checks.threw();
|
|
1627
|
-
continue;
|
|
1628
|
-
}
|
|
1629
|
-
hits ??= new Map;
|
|
1630
|
-
let hit = hits.get(styles);
|
|
1631
|
-
if (!hit) {
|
|
1632
|
-
hit = { flat, matched: flat.parts.map(() => false), specificity: part.specificity };
|
|
1633
|
-
hits.set(styles, hit);
|
|
1634
|
-
}
|
|
1635
|
-
hit.matched[i] = true;
|
|
1636
|
-
if (compareSpecificity(part.specificity, hit.specificity) > 0) {
|
|
1637
|
-
hit.specificity = part.specificity;
|
|
1638
|
-
}
|
|
1639
|
-
}
|
|
1640
|
-
if (!hits)
|
|
1641
|
-
continue;
|
|
1642
|
-
for (const [styles, hit] of hits) {
|
|
1643
|
-
const list = found.get(styles);
|
|
1644
|
-
if (list)
|
|
1645
|
-
list.push(hit);
|
|
1646
|
-
else
|
|
1647
|
-
found.set(styles, [hit]);
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
return found;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
// src/styles/index.ts
|
|
1654
|
-
var ELEMENT2 = "";
|
|
1655
|
-
var PSEUDOS = ["::before", "::after"];
|
|
1656
|
-
var ONLY_ELEMENT = new Set([ELEMENT2]);
|
|
1657
|
-
var probes = new WeakMap;
|
|
1658
|
-
function expanderFor(doc) {
|
|
1659
|
-
const probe = probes.get(doc) ?? { style: null, known: new Map };
|
|
1660
|
-
probes.set(doc, probe);
|
|
1661
|
-
return (shorthand) => {
|
|
1662
|
-
let longhands = probe.known.get(shorthand);
|
|
1663
|
-
if (longhands)
|
|
1664
|
-
return longhands;
|
|
1665
|
-
longhands = [];
|
|
1666
|
-
try {
|
|
1667
|
-
probe.style ??= doc.createElement("div").style;
|
|
1668
|
-
probe.style.cssText = "";
|
|
1669
|
-
probe.style.setProperty(shorthand, "initial");
|
|
1670
|
-
longhands = listed(probe.style);
|
|
1671
|
-
} catch {}
|
|
1672
|
-
probe.known.set(shorthand, longhands);
|
|
1673
|
-
return longhands;
|
|
1674
|
-
};
|
|
1675
|
-
}
|
|
1676
|
-
var parsed = new WeakMap;
|
|
1677
|
-
function declarationsOf(style, session) {
|
|
1678
|
-
const text = style.cssText;
|
|
1679
|
-
let known = parsed.get(style);
|
|
1680
|
-
if (!known || known.text !== text) {
|
|
1681
|
-
const names = listed(style);
|
|
1682
|
-
const declarations = parseDeclarations(text).map((written) => ({
|
|
1683
|
-
...written,
|
|
1684
|
-
longhands: longhandsOf(written.name, names, session.expand),
|
|
1685
|
-
variables: variableNames(written.value)
|
|
1686
|
-
}));
|
|
1687
|
-
known = { text, declarations };
|
|
1688
|
-
parsed.set(style, known);
|
|
1689
|
-
}
|
|
1690
|
-
return known.declarations.map((declaration) => ({ ...declaration, overridden: false }));
|
|
1691
|
-
}
|
|
1692
|
-
function open(session, scope) {
|
|
1693
|
-
const flat = rulesOf(scope);
|
|
1694
|
-
if (!session.ranks.has(flat)) {
|
|
1695
|
-
session.ranks.set(flat, layerRanks(flat.layers, session.checks.holds));
|
|
1696
|
-
for (const [name, inherits] of flat.registered)
|
|
1697
|
-
session.registered.set(name, inherits);
|
|
1698
|
-
}
|
|
1699
|
-
return flat;
|
|
1700
|
-
}
|
|
1701
|
-
function ruleEntry(session, flat, hit, context) {
|
|
1702
|
-
const { rule, parts, selectorText, origin, conditional } = hit.flat;
|
|
1703
|
-
const source = {
|
|
1704
|
-
context,
|
|
1705
|
-
inline: false,
|
|
1706
|
-
layer: session.ranks.get(flat)?.get(hit.flat.layer) ?? 0,
|
|
1707
|
-
specificity: hit.specificity,
|
|
1708
|
-
order: hit.flat.order
|
|
1709
|
-
};
|
|
1710
|
-
const block = {
|
|
1711
|
-
kind: "rule",
|
|
1712
|
-
id: session.ids++,
|
|
1713
|
-
selectorText,
|
|
1714
|
-
selector: parts.map((part, i) => ({ text: part.text, matches: hit.matched[i] === true })),
|
|
1715
|
-
specificity: hit.specificity,
|
|
1716
|
-
origin,
|
|
1717
|
-
context: hit.flat.context,
|
|
1718
|
-
declarations: declarationsOf(rule.style, session),
|
|
1719
|
-
rule
|
|
1720
|
-
};
|
|
1721
|
-
if (conditional)
|
|
1722
|
-
block.conditional = { kind: conditional, confirmed: false };
|
|
1723
|
-
return {
|
|
1724
|
-
id: block.id,
|
|
1725
|
-
source,
|
|
1726
|
-
declarations: block.declarations,
|
|
1727
|
-
value: (longhand) => rule.style.getPropertyValue(longhand),
|
|
1728
|
-
conditional: block.conditional,
|
|
1729
|
-
block
|
|
1730
|
-
};
|
|
1731
|
-
}
|
|
1732
|
-
function hasStyle(element) {
|
|
1733
|
-
return "style" in element;
|
|
1734
|
-
}
|
|
1735
|
-
function inlineEntry(session, element) {
|
|
1736
|
-
if (!hasStyle(element))
|
|
1737
|
-
return null;
|
|
1738
|
-
const style = element.style;
|
|
1739
|
-
const declarations = declarationsOf(style, session).filter((declaration) => {
|
|
1740
|
-
const wrote = ownInline(element, declaration.name);
|
|
1741
|
-
return wrote === null || wrote !== style.getPropertyValue(declaration.name);
|
|
1742
|
-
});
|
|
1743
|
-
if (declarations.length === 0)
|
|
1744
|
-
return null;
|
|
1745
|
-
const block = { kind: "inline", id: session.ids++, declarations, element };
|
|
1746
|
-
return {
|
|
1747
|
-
id: block.id,
|
|
1748
|
-
source: { context: 0, inline: true, layer: 0, specificity: [0, 0, 0], order: 0 },
|
|
1749
|
-
declarations,
|
|
1750
|
-
value: (longhand) => style.getPropertyValue(longhand),
|
|
1751
|
-
block
|
|
1752
|
-
};
|
|
1753
|
-
}
|
|
1754
|
-
function entriesFor(session, element, wanted, skip) {
|
|
1755
|
-
const entries = new Map;
|
|
1756
|
-
const add2 = (scope, reach, context2) => {
|
|
1757
|
-
const flat = open(session, scope);
|
|
1758
|
-
const hits = matchRules(element, flat.rules, reach, wanted, session.checks, skip);
|
|
1759
|
-
for (const [styles, list] of hits) {
|
|
1760
|
-
const into = entries.get(styles) ?? [];
|
|
1761
|
-
entries.set(styles, into);
|
|
1762
|
-
for (const hit of list)
|
|
1763
|
-
into.push(ruleEntry(session, flat, hit, context2));
|
|
1764
|
-
}
|
|
1765
|
-
};
|
|
1766
|
-
add2(scopeOf(element), { kind: "own" }, 0);
|
|
1767
|
-
let context = 1;
|
|
1768
|
-
for (let slot2 = element.assignedSlot;slot2; slot2 = slot2.assignedSlot) {
|
|
1769
|
-
const root = slot2.getRootNode();
|
|
1770
|
-
if (isShadowRoot(root))
|
|
1771
|
-
add2(root, { kind: "slotted", slot: slot2 }, context++);
|
|
1772
|
-
}
|
|
1773
|
-
if (element.shadowRoot)
|
|
1774
|
-
add2(element.shadowRoot, { kind: "host" }, context);
|
|
1775
|
-
return entries;
|
|
1776
|
-
}
|
|
1777
|
-
function isRule(block) {
|
|
1778
|
-
return block.kind === "rule";
|
|
1779
|
-
}
|
|
1780
|
-
function shown(entries) {
|
|
1781
|
-
return byStrength(entries).map((entry) => {
|
|
1782
|
-
entry.block.declarations = entry.declarations;
|
|
1783
|
-
return entry.block;
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
function ownBlocks(blocks) {
|
|
1787
|
-
return blocks.flatMap((block) => {
|
|
1788
|
-
if (block.kind === "pseudo")
|
|
1789
|
-
return [];
|
|
1790
|
-
return block.kind === "inherited" ? block.blocks : [block];
|
|
1791
|
-
});
|
|
1792
|
-
}
|
|
1793
|
-
function inspect(element, pseudo) {
|
|
1794
|
-
const target = { label: label(element), pseudo: pseudo ? normalizePseudo(pseudo) : null };
|
|
1795
|
-
const found = { target, blocks: [], hidden: [], variables: {}, skipped: 0 };
|
|
1796
|
-
const doc = element.ownerDocument;
|
|
1797
|
-
const view = doc.defaultView;
|
|
1798
|
-
if (!view || isDevknobs(element))
|
|
1799
|
-
return found;
|
|
1800
|
-
const session = {
|
|
1801
|
-
checks: { holds: conditionsFor(view), threw: () => session.threw++ },
|
|
1802
|
-
expand: expanderFor(doc),
|
|
1803
|
-
ids: 0,
|
|
1804
|
-
threw: 0,
|
|
1805
|
-
ranks: new Map,
|
|
1806
|
-
registered: new Map
|
|
1807
|
-
};
|
|
1808
|
-
open(session, doc);
|
|
1809
|
-
let computed = null;
|
|
1810
|
-
const read = (property) => {
|
|
1811
|
-
computed ??= view.getComputedStyle(element, target.pseudo);
|
|
1812
|
-
return computed.getPropertyValue(property);
|
|
1813
|
-
};
|
|
1814
|
-
const wanted = new Set(target.pseudo ? [target.pseudo] : [ELEMENT2, ...PSEUDOS]);
|
|
1815
|
-
const reached = entriesFor(session, element, wanted);
|
|
1816
|
-
let own = reached.get(target.pseudo ?? ELEMENT2) ?? [];
|
|
1817
|
-
const inline = target.pseudo ? null : inlineEntry(session, element);
|
|
1818
|
-
if (inline)
|
|
1819
|
-
own.push(inline);
|
|
1820
|
-
own = settleContainers(own, read);
|
|
1821
|
-
const won = winners(own);
|
|
1822
|
-
markOwn(own, won);
|
|
1823
|
-
found.blocks.push(...shown(own));
|
|
1824
|
-
if (!target.pseudo) {
|
|
1825
|
-
for (const name of PSEUDOS) {
|
|
1826
|
-
const entries = reached.get(name);
|
|
1827
|
-
if (!entries)
|
|
1828
|
-
continue;
|
|
1829
|
-
markOwn(entries, winners(entries));
|
|
1830
|
-
found.blocks.push({ kind: "pseudo", pseudo: name, blocks: shown(entries).filter(isRule) });
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
const taken = new Map;
|
|
1834
|
-
for (const [longhand, winner] of won)
|
|
1835
|
-
taken.set(longhand, winner.candidate.id);
|
|
1836
|
-
const inherits = (property) => isInherited(property, session.registered);
|
|
1837
|
-
const handsNothing = (flat) => {
|
|
1838
|
-
flat.hands ??= listed(flat.rule.style).some(inherits);
|
|
1839
|
-
return !flat.hands;
|
|
1840
|
-
};
|
|
1841
|
-
let ancestor = target.pseudo ? element : flatParent(element);
|
|
1842
|
-
for (;ancestor; ancestor = flatParent(ancestor)) {
|
|
1843
|
-
const entries = entriesFor(session, ancestor, ONLY_ELEMENT, handsNothing).get(ELEMENT2) ?? [];
|
|
1844
|
-
const attribute = inlineEntry(session, ancestor);
|
|
1845
|
-
if (attribute)
|
|
1846
|
-
entries.push(attribute);
|
|
1847
|
-
const kept = settleInherited(entries, taken, inherits);
|
|
1848
|
-
if (kept.length === 0)
|
|
1849
|
-
continue;
|
|
1850
|
-
found.blocks.push({
|
|
1851
|
-
kind: "inherited",
|
|
1852
|
-
from: label(ancestor),
|
|
1853
|
-
element: ancestor,
|
|
1854
|
-
blocks: shown(kept)
|
|
1855
|
-
});
|
|
1856
|
-
}
|
|
1857
|
-
const variables = {};
|
|
1858
|
-
for (const block of ownBlocks(found.blocks)) {
|
|
1859
|
-
for (const declaration of block.declarations) {
|
|
1860
|
-
if (declaration.overridden)
|
|
1861
|
-
continue;
|
|
1862
|
-
for (const name of declaration.variables) {
|
|
1863
|
-
variables[name] ??= { value: read(name).trim(), definedIn: taken.get(name) ?? null };
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
found.variables = variables;
|
|
1868
|
-
for (const flat of session.ranks.keys()) {
|
|
1869
|
-
found.hidden.push(...flat.hidden);
|
|
1870
|
-
found.skipped += flat.skipped;
|
|
1871
|
-
}
|
|
1872
|
-
found.skipped += session.threw;
|
|
1873
|
-
return found;
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
// src/ui/boxdiagram.ts
|
|
1877
|
-
function readBox(element) {
|
|
1878
|
-
const view = element.ownerDocument.defaultView;
|
|
1879
|
-
if (!view || !element.isConnected)
|
|
1880
|
-
return null;
|
|
1881
|
-
const style = view.getComputedStyle(element);
|
|
1882
|
-
const model = boxModel(style);
|
|
1883
|
-
return { model, ...contentSize(model, style, element.getBoundingClientRect()) };
|
|
1884
|
-
}
|
|
1885
|
-
var DIAGRAM_RINGS = ["position", "margin", "border", "padding"];
|
|
1886
|
-
var COLUMN = 22;
|
|
1887
|
-
var CHAR = 6.5;
|
|
1888
|
-
var ROOM = 8;
|
|
1889
|
-
var CONTENT = 120;
|
|
1890
|
-
function lengths(reading, ring) {
|
|
1891
|
-
return ring === "position" ? reading.model.offsets : reading.model[ring];
|
|
1892
|
-
}
|
|
1893
|
-
function ringValues(reading, ring) {
|
|
1894
|
-
const found = lengths(reading, ring);
|
|
1895
|
-
if (!found)
|
|
1896
|
-
return null;
|
|
1897
|
-
return {
|
|
1898
|
-
top: boxValue(found.top),
|
|
1899
|
-
right: boxValue(found.right),
|
|
1900
|
-
bottom: boxValue(found.bottom),
|
|
1901
|
-
left: boxValue(found.left)
|
|
1902
|
-
};
|
|
1903
|
-
}
|
|
1904
|
-
function diagramNeeds(reading) {
|
|
1905
|
-
const column = (text) => Math.max(COLUMN, text.length * CHAR + ROOM);
|
|
1906
|
-
let needs = Math.max(CONTENT, sizeText(reading.width, reading.height).length * CHAR + ROOM);
|
|
1907
|
-
for (const ring of DIAGRAM_RINGS) {
|
|
1908
|
-
const values = ringValues(reading, ring);
|
|
1909
|
-
if (values)
|
|
1910
|
-
needs += column(values.left) + column(values.right);
|
|
1911
|
-
}
|
|
1912
|
-
return needs;
|
|
1913
|
-
}
|
|
1914
|
-
function boxFacts(model) {
|
|
1915
|
-
const facts = [`box-sizing: ${model.boxSizing}`, `display: ${model.display}`];
|
|
1916
|
-
if (model.position !== "static")
|
|
1917
|
-
facts.push(`position: ${model.position}`);
|
|
1918
|
-
return facts;
|
|
1919
|
-
}
|
|
1920
|
-
function say(node, text) {
|
|
1921
|
-
if (node.textContent !== text)
|
|
1922
|
-
node.textContent = text;
|
|
1923
|
-
}
|
|
1924
|
-
function createBoxDiagram(onArea) {
|
|
1925
|
-
const node = el("div", "box-model");
|
|
1926
|
-
const size = el("div", "bm-ring bm-content");
|
|
1927
|
-
const line = el("div", "bm-line");
|
|
1928
|
-
const lineName = el("span", "bm-name");
|
|
1929
|
-
const lineValues = el("span", "bm-values");
|
|
1930
|
-
line.append(lineName, lineValues);
|
|
1931
|
-
const facts = el("div", "bm-facts");
|
|
1932
|
-
const rings = new Map;
|
|
1933
|
-
let reading = null;
|
|
1934
|
-
let width = Number.POSITIVE_INFINITY;
|
|
1935
|
-
let hovered = null;
|
|
1936
|
-
let focused = null;
|
|
1937
|
-
let told = "margin";
|
|
1938
|
-
function active() {
|
|
1939
|
-
return focused ?? hovered;
|
|
1940
|
-
}
|
|
1941
|
-
function drawLine() {
|
|
1942
|
-
const values = reading ? ringValues(reading, told) : null;
|
|
1943
|
-
const shown2 = values ?? (reading ? ringValues(reading, "margin") : null);
|
|
1944
|
-
say(lineName, values ? told : "margin");
|
|
1945
|
-
say(lineValues, shown2 ? SIDES.map((side) => shown2[side]).join(" ") : "");
|
|
1946
|
-
}
|
|
1947
|
-
function changed() {
|
|
1948
|
-
const now = active();
|
|
1949
|
-
if (now && now !== "content")
|
|
1950
|
-
told = now;
|
|
1951
|
-
onArea(now === null || now === "position" ? null : now);
|
|
1952
|
-
drawLine();
|
|
1953
|
-
}
|
|
1954
|
-
function listen(area, name, around) {
|
|
1955
|
-
area.tabIndex = 0;
|
|
1956
|
-
area.setAttribute("role", "group");
|
|
1957
|
-
area.addEventListener("pointerenter", () => {
|
|
1958
|
-
hovered = name;
|
|
1959
|
-
changed();
|
|
1960
|
-
});
|
|
1961
|
-
area.addEventListener("pointerleave", () => {
|
|
1962
|
-
hovered = around;
|
|
1963
|
-
changed();
|
|
1964
|
-
});
|
|
1965
|
-
area.addEventListener("focus", () => {
|
|
1966
|
-
focused = name;
|
|
1967
|
-
changed();
|
|
1968
|
-
});
|
|
1969
|
-
area.addEventListener("blur", () => {
|
|
1970
|
-
focused = null;
|
|
1971
|
-
changed();
|
|
1972
|
-
});
|
|
1973
|
-
}
|
|
1974
|
-
let inner = size;
|
|
1975
|
-
listen(size, "content", "padding");
|
|
1976
|
-
for (const ring of [...DIAGRAM_RINGS].reverse()) {
|
|
1977
|
-
const area = el("div", `bm-ring bm-${ring}`);
|
|
1978
|
-
const values = {
|
|
1979
|
-
top: el("span", "bm-v bm-top"),
|
|
1980
|
-
right: el("span", "bm-v bm-right"),
|
|
1981
|
-
bottom: el("span", "bm-v bm-bottom"),
|
|
1982
|
-
left: el("span", "bm-v bm-left")
|
|
1983
|
-
};
|
|
1984
|
-
const name = el("span", "bm-name", ring);
|
|
1985
|
-
name.setAttribute("aria-hidden", "true");
|
|
1986
|
-
area.append(name, values.top, values.left, inner, values.right, values.bottom);
|
|
1987
|
-
const around = DIAGRAM_RINGS[DIAGRAM_RINGS.indexOf(ring) - 1] ?? null;
|
|
1988
|
-
listen(area, ring, around);
|
|
1989
|
-
rings.set(ring, { node: area, values });
|
|
1990
|
-
inner = area;
|
|
1991
|
-
}
|
|
1992
|
-
node.append(inner, line, facts);
|
|
1993
|
-
node.setAttribute("role", "group");
|
|
1994
|
-
node.setAttribute("aria-label", "box model");
|
|
1995
|
-
function narrow() {
|
|
1996
|
-
node.classList.toggle("narrow", reading !== null && diagramNeeds(reading) > width);
|
|
1997
|
-
}
|
|
1998
|
-
function show(next) {
|
|
1999
|
-
reading = next;
|
|
2000
|
-
if (!next)
|
|
2001
|
-
return;
|
|
2002
|
-
for (const ring of DIAGRAM_RINGS) {
|
|
2003
|
-
const parts = rings.get(ring);
|
|
2004
|
-
if (!parts)
|
|
2005
|
-
continue;
|
|
2006
|
-
const values = ringValues(next, ring);
|
|
2007
|
-
parts.node.classList.toggle("off", values === null);
|
|
2008
|
-
parts.node.tabIndex = values === null ? -1 : 0;
|
|
2009
|
-
for (const side of SIDES)
|
|
2010
|
-
say(parts.values[side], values ? values[side] : "");
|
|
2011
|
-
const sides = values ? SIDES.map((side) => `${side} ${values[side]}`).join(", ") : "";
|
|
2012
|
-
parts.node.setAttribute("aria-label", values ? `${ring}: ${sides}` : ring);
|
|
2013
|
-
}
|
|
2014
|
-
const sized = sizeText(next.width, next.height);
|
|
2015
|
-
say(size, sized);
|
|
2016
|
-
size.setAttribute("aria-label", `content: ${sized}`);
|
|
2017
|
-
facts.replaceChildren(...boxFacts(next.model).map((fact) => el("span", "bm-fact", fact)));
|
|
2018
|
-
if (told === "position" && !next.model.offsets)
|
|
2019
|
-
told = "margin";
|
|
2020
|
-
drawLine();
|
|
2021
|
-
narrow();
|
|
2022
|
-
}
|
|
2023
|
-
return {
|
|
2024
|
-
node,
|
|
2025
|
-
show,
|
|
2026
|
-
fit(next) {
|
|
2027
|
-
width = next;
|
|
2028
|
-
narrow();
|
|
2029
|
-
}
|
|
2030
|
-
};
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
// src/ui/stylesapplied.ts
|
|
2034
|
-
var NO_STYLES = "no styles set on this element";
|
|
2035
|
-
var GROUPS = ["layout", "size and spacing", "text", "look", "motion", "other"];
|
|
2036
|
-
var EXACT = {
|
|
2037
|
-
display: "layout",
|
|
2038
|
-
position: "layout",
|
|
2039
|
-
top: "layout",
|
|
2040
|
-
right: "layout",
|
|
2041
|
-
bottom: "layout",
|
|
2042
|
-
left: "layout",
|
|
2043
|
-
"z-index": "layout",
|
|
2044
|
-
gap: "layout",
|
|
2045
|
-
"row-gap": "layout",
|
|
2046
|
-
"column-gap": "layout",
|
|
2047
|
-
order: "layout",
|
|
2048
|
-
float: "layout",
|
|
2049
|
-
width: "size and spacing",
|
|
2050
|
-
height: "size and spacing",
|
|
2051
|
-
"inline-size": "size and spacing",
|
|
2052
|
-
"block-size": "size and spacing",
|
|
2053
|
-
"box-sizing": "size and spacing",
|
|
2054
|
-
"aspect-ratio": "size and spacing",
|
|
2055
|
-
"line-height": "text",
|
|
2056
|
-
"letter-spacing": "text",
|
|
2057
|
-
"white-space": "text",
|
|
2058
|
-
"overflow-wrap": "text",
|
|
2059
|
-
color: "text",
|
|
2060
|
-
"box-shadow": "look",
|
|
2061
|
-
opacity: "look",
|
|
2062
|
-
filter: "look",
|
|
2063
|
-
"backdrop-filter": "look",
|
|
2064
|
-
"mix-blend-mode": "look",
|
|
2065
|
-
"will-change": "motion",
|
|
2066
|
-
translate: "motion",
|
|
2067
|
-
rotate: "motion",
|
|
2068
|
-
scale: "motion"
|
|
2069
|
-
};
|
|
2070
|
-
var STARTS = [
|
|
2071
|
-
["inset", "layout"],
|
|
2072
|
-
["flex", "layout"],
|
|
2073
|
-
["grid", "layout"],
|
|
2074
|
-
["align-", "layout"],
|
|
2075
|
-
["justify-", "layout"],
|
|
2076
|
-
["place-", "layout"],
|
|
2077
|
-
["overflow", "layout"],
|
|
2078
|
-
["min-", "size and spacing"],
|
|
2079
|
-
["max-", "size and spacing"],
|
|
2080
|
-
["margin", "size and spacing"],
|
|
2081
|
-
["padding", "size and spacing"],
|
|
2082
|
-
["font", "text"],
|
|
2083
|
-
["text-", "text"],
|
|
2084
|
-
["word-", "text"],
|
|
2085
|
-
["background", "look"],
|
|
2086
|
-
["border", "look"],
|
|
2087
|
-
["outline", "look"],
|
|
2088
|
-
["transition", "motion"],
|
|
2089
|
-
["animation", "motion"],
|
|
2090
|
-
["transform", "motion"]
|
|
2091
|
-
];
|
|
2092
|
-
var VENDOR = /^-(?:webkit|moz|ms|o)-/;
|
|
2093
|
-
function isCustom(name) {
|
|
2094
|
-
return name.startsWith("--");
|
|
2095
|
-
}
|
|
2096
|
-
function groupOf(name) {
|
|
2097
|
-
if (isCustom(name))
|
|
2098
|
-
return "other";
|
|
2099
|
-
const plain = name.toLowerCase().replace(VENDOR, "");
|
|
2100
|
-
const exact = Object.hasOwn(EXACT, plain) ? EXACT[plain] : undefined;
|
|
2101
|
-
if (exact)
|
|
2102
|
-
return exact;
|
|
2103
|
-
return STARTS.find(([start]) => plain.startsWith(start))?.[1] ?? "other";
|
|
2104
|
-
}
|
|
2105
|
-
function winning(block) {
|
|
2106
|
-
return block.declarations.flatMap((declaration) => declaration.overridden ? [] : [{ declaration, block }]);
|
|
2107
|
-
}
|
|
2108
|
-
function appliedOwn(found) {
|
|
2109
|
-
return found.blocks.flatMap((block) => block.kind === "inline" || block.kind === "rule" ? winning(block) : []);
|
|
2110
|
-
}
|
|
2111
|
-
function appliedInherited(found) {
|
|
2112
|
-
const seen = new Set;
|
|
2113
|
-
const applied = [];
|
|
2114
|
-
for (const group of found.blocks) {
|
|
2115
|
-
if (group.kind !== "inherited")
|
|
2116
|
-
continue;
|
|
2117
|
-
for (const one of group.blocks.flatMap(winning)) {
|
|
2118
|
-
if (seen.has(one.declaration.name))
|
|
2119
|
-
continue;
|
|
2120
|
-
seen.add(one.declaration.name);
|
|
2121
|
-
applied.push(one);
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
return applied;
|
|
2125
|
-
}
|
|
2126
|
-
function grouped(lines) {
|
|
2127
|
-
return GROUPS.flatMap((group) => {
|
|
2128
|
-
const own = lines.filter((line) => groupOf(line.declaration.name) === group);
|
|
2129
|
-
if (own.length === 0)
|
|
2130
|
-
return [];
|
|
2131
|
-
const custom = own.filter((line) => isCustom(line.declaration.name));
|
|
2132
|
-
const rest = own.filter((line) => !isCustom(line.declaration.name));
|
|
2133
|
-
return [{ group, lines: [...rest, ...custom] }];
|
|
2134
|
-
});
|
|
2135
|
-
}
|
|
2136
|
-
function resolvedValue(value, variables) {
|
|
2137
|
-
if (varReferences(value).length === 0)
|
|
2138
|
-
return null;
|
|
2139
|
-
return resolveVars(value, (name) => variables[name]?.value ?? "");
|
|
2140
|
-
}
|
|
2141
|
-
function hiddenNote(hidden) {
|
|
2142
|
-
if (hidden.length === 0)
|
|
2143
|
-
return null;
|
|
2144
|
-
const why = hidden.some((one) => one.reason === "cross-origin") ? "a stylesheet from another origin" : "a stylesheet that could not be read";
|
|
2145
|
-
return `some styles are hidden: ${why}`;
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
// src/ui/stylesview.ts
|
|
2149
|
-
var SETTLE2 = 120;
|
|
2150
|
-
var FLASH = 900;
|
|
2151
|
-
var EMPTY = "pick an element to see its styles";
|
|
2152
|
-
var GONE = "the element left the page";
|
|
2153
|
-
var PICK = "select an element to see its styles";
|
|
2154
|
-
var GONE_PICK = "the element left the page, select another";
|
|
2155
|
-
var NO_RULES = "no rule reaches this element";
|
|
2156
|
-
var NO_MATCH = "no declaration matches";
|
|
2157
|
-
var MODES = ["simple", "advanced"];
|
|
2158
|
-
function readVariable(element, pseudo, name) {
|
|
2159
|
-
try {
|
|
2160
|
-
const view = element.ownerDocument.defaultView;
|
|
2161
|
-
return view ? view.getComputedStyle(element, pseudo).getPropertyValue(name).trim() : "";
|
|
2162
|
-
} catch {
|
|
2163
|
-
return "";
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
function isColor(text) {
|
|
2167
|
-
try {
|
|
2168
|
-
return typeof CSS !== "undefined" && CSS.supports("color", text);
|
|
2169
|
-
} catch {
|
|
2170
|
-
return false;
|
|
2171
|
-
}
|
|
2172
|
-
}
|
|
2173
|
-
var PAGE2 = {
|
|
2174
|
-
inspect,
|
|
2175
|
-
invalidate,
|
|
2176
|
-
getState,
|
|
2177
|
-
subscribe,
|
|
2178
|
-
isColor,
|
|
2179
|
-
box: readBox,
|
|
2180
|
-
variable: readVariable
|
|
2181
|
-
};
|
|
2182
|
-
function isElement2(node) {
|
|
2183
|
-
return node.nodeType === 1;
|
|
2184
|
-
}
|
|
2185
|
-
function isOwn2(record) {
|
|
2186
|
-
if (record.type !== "childList")
|
|
2187
|
-
return false;
|
|
2188
|
-
const nodes = [...Array.from(record.addedNodes), ...Array.from(record.removedNodes)];
|
|
2189
|
-
return nodes.length > 0 && nodes.every((node) => isElement2(node) && node.hasAttribute("data-devknobs"));
|
|
2190
|
-
}
|
|
2191
|
-
function knobsOf(state) {
|
|
2192
|
-
return JSON.stringify({ ...state, panel: null });
|
|
2193
|
-
}
|
|
2194
|
-
function createStylesView(context, page = PAGE2) {
|
|
2195
|
-
const { tips } = context;
|
|
2196
|
-
const node = el("div", "styles");
|
|
2197
|
-
node.tabIndex = -1;
|
|
2198
|
-
const crumbs = el("div", "crumbs");
|
|
2199
|
-
crumbs.setAttribute("role", "group");
|
|
2200
|
-
crumbs.setAttribute("aria-label", "the element and its ancestors");
|
|
2201
|
-
const filter = filterField({
|
|
2202
|
-
placeholder: "filter",
|
|
2203
|
-
label: "filter the declarations",
|
|
2204
|
-
onInput: () => applyFilter()
|
|
2205
|
-
});
|
|
2206
|
-
let mode = context.mode?.get() ?? "advanced";
|
|
2207
|
-
const modes = context.mode ? segments({
|
|
2208
|
-
options: MODES.map((value) => ({ value, label: value })),
|
|
2209
|
-
label: "how the styles are shown",
|
|
2210
|
-
value: mode,
|
|
2211
|
-
onChange: setMode
|
|
2212
|
-
}) : null;
|
|
2213
|
-
const { select } = context;
|
|
2214
|
-
const picker = select ? toolToggle({
|
|
2215
|
-
label: select.label,
|
|
2216
|
-
icon: "square-dashed-mouse-pointer",
|
|
2217
|
-
on: select.on(),
|
|
2218
|
-
onPress: select.run
|
|
2219
|
-
}) : null;
|
|
2220
|
-
const again = select ? emptyAction(PICK, select.run) : null;
|
|
2221
|
-
if (select) {
|
|
2222
|
-
const told = () => [select.label, select.hint?.()].filter(Boolean).join(" · ");
|
|
2223
|
-
if (picker)
|
|
2224
|
-
tips.tooltip(picker.node, told);
|
|
2225
|
-
if (again)
|
|
2226
|
-
tips.tooltip(again, told);
|
|
2227
|
-
}
|
|
2228
|
-
const bar = toolbar([picker?.node, filter.node, modes?.node].filter((part) => part != null));
|
|
2229
|
-
const diagram = createBoxDiagram((ring) => context.area?.(ring));
|
|
2230
|
-
const box = sectionFold({
|
|
2231
|
-
label: "box",
|
|
2232
|
-
open: context.box?.get() ?? true,
|
|
2233
|
-
onToggle: (open2) => context.box?.set(open2)
|
|
2234
|
-
});
|
|
2235
|
-
box.body.append(diagram.node);
|
|
2236
|
-
diagram.node.addEventListener("pointerenter", () => point(target));
|
|
2237
|
-
diagram.node.addEventListener("pointerleave", () => point(null));
|
|
2238
|
-
const blocks = el("div", "css-blocks");
|
|
2239
|
-
const note = emptyLine(EMPTY);
|
|
2240
|
-
node.append(crumbs, bar, box.node, blocks, note);
|
|
2241
|
-
if (again)
|
|
2242
|
-
node.append(again);
|
|
2243
|
-
const fitter = typeof ResizeObserver === "undefined" ? null : new ResizeObserver((entries) => {
|
|
2244
|
-
const entry = entries[entries.length - 1];
|
|
2245
|
-
if (entry)
|
|
2246
|
-
diagram.fit(entry.contentRect.width);
|
|
2247
|
-
});
|
|
2248
|
-
fitter?.observe(diagram.node);
|
|
2249
|
-
let target = null;
|
|
2250
|
-
let pseudo = null;
|
|
2251
|
-
let pseudos = [];
|
|
2252
|
-
let read = null;
|
|
2253
|
-
let built = [];
|
|
2254
|
-
let flat = null;
|
|
2255
|
-
let unfolded = false;
|
|
2256
|
-
let byId = new Map;
|
|
2257
|
-
let tipped = [];
|
|
2258
|
-
let sources = new Map;
|
|
2259
|
-
let observer = null;
|
|
2260
|
-
let sizes = null;
|
|
2261
|
-
let watched = null;
|
|
2262
|
-
let stale = false;
|
|
2263
|
-
let knobs = knobsOf(page.getState());
|
|
2264
|
-
let timer = 0;
|
|
2265
|
-
let flashTimer = 0;
|
|
2266
|
-
let lit = null;
|
|
2267
|
-
let said = { text: null, press: null };
|
|
2268
|
-
const unpick = select?.watch(() => {
|
|
2269
|
-
picker?.set(select.on());
|
|
2270
|
-
drawSaid();
|
|
2271
|
-
}) ?? null;
|
|
2272
|
-
let pointed = null;
|
|
2273
|
-
let pointing = false;
|
|
2274
|
-
function point(element) {
|
|
2275
|
-
if (!element && !pointing)
|
|
2276
|
-
return;
|
|
2277
|
-
pointing = element !== null;
|
|
2278
|
-
context.outline(element);
|
|
2279
|
-
}
|
|
2280
|
-
function later() {
|
|
2281
|
-
clearTimeout(timer);
|
|
2282
|
-
timer = window.setTimeout(refresh, SETTLE2);
|
|
2283
|
-
}
|
|
2284
|
-
function onMutations(records) {
|
|
2285
|
-
const theirs = records.filter((record) => !isOwn2(record));
|
|
2286
|
-
if (theirs.length === 0)
|
|
2287
|
-
return;
|
|
2288
|
-
const head = target?.ownerDocument.head;
|
|
2289
|
-
if (head && theirs.some((record) => head.contains(record.target)))
|
|
2290
|
-
stale = true;
|
|
2291
|
-
later();
|
|
2292
|
-
}
|
|
2293
|
-
function drawBox() {
|
|
2294
|
-
const reading = target && pseudo === null && target.isConnected ? page.box(target) : null;
|
|
2295
|
-
box.node.hidden = reading === null;
|
|
2296
|
-
diagram.show(reading);
|
|
2297
|
-
}
|
|
2298
|
-
function unwatch() {
|
|
2299
|
-
observer?.disconnect();
|
|
2300
|
-
observer = null;
|
|
2301
|
-
sizes?.disconnect();
|
|
2302
|
-
sizes = null;
|
|
2303
|
-
watched?.removeEventListener("resize", later);
|
|
2304
|
-
watched = null;
|
|
2305
|
-
}
|
|
2306
|
-
function watch(element) {
|
|
2307
|
-
unwatch();
|
|
2308
|
-
observer = new MutationObserver(onMutations);
|
|
2309
|
-
observer.observe(element, { attributes: true });
|
|
2310
|
-
for (let up = flatParent(element);up; up = flatParent(up)) {
|
|
2311
|
-
observer.observe(up, { attributes: true, childList: true });
|
|
2312
|
-
}
|
|
2313
|
-
const head = element.ownerDocument.head;
|
|
2314
|
-
if (head) {
|
|
2315
|
-
observer.observe(head, {
|
|
2316
|
-
attributes: true,
|
|
2317
|
-
characterData: true,
|
|
2318
|
-
childList: true,
|
|
2319
|
-
subtree: true
|
|
2320
|
-
});
|
|
2321
|
-
}
|
|
2322
|
-
watched = element.ownerDocument.defaultView;
|
|
2323
|
-
watched?.addEventListener("resize", later);
|
|
2324
|
-
if (typeof ResizeObserver !== "undefined") {
|
|
2325
|
-
sizes = new ResizeObserver(drawBox);
|
|
2326
|
-
sizes.observe(element);
|
|
2327
|
-
}
|
|
2328
|
-
}
|
|
2329
|
-
function say2(text, press = null) {
|
|
2330
|
-
said = { text, press };
|
|
2331
|
-
drawSaid();
|
|
2332
|
-
}
|
|
2333
|
-
function drawSaid() {
|
|
2334
|
-
const { text, press } = said;
|
|
2335
|
-
const asks = again !== null && press !== null && select?.on() === false;
|
|
2336
|
-
note.hidden = text === null || asks;
|
|
2337
|
-
if (text !== null)
|
|
2338
|
-
note.textContent = text;
|
|
2339
|
-
if (!again)
|
|
2340
|
-
return;
|
|
2341
|
-
again.hidden = !asks;
|
|
2342
|
-
if (press !== null)
|
|
2343
|
-
again.textContent = press;
|
|
2344
|
-
}
|
|
2345
|
-
function tip(control, text) {
|
|
2346
|
-
tips.tooltip(control, text);
|
|
2347
|
-
tipped.push(control);
|
|
2348
|
-
}
|
|
2349
|
-
function dropTips() {
|
|
2350
|
-
if (tipped.some((control) => tips.isFor(control)))
|
|
2351
|
-
tips.hide();
|
|
2352
|
-
tipped = [];
|
|
2353
|
-
}
|
|
2354
|
-
function clear(text, press) {
|
|
2355
|
-
dropTips();
|
|
2356
|
-
read = null;
|
|
2357
|
-
sources = new Map;
|
|
2358
|
-
built = [];
|
|
2359
|
-
flat = null;
|
|
2360
|
-
byId = new Map;
|
|
2361
|
-
blocks.replaceChildren();
|
|
2362
|
-
crumbs.replaceChildren();
|
|
2363
|
-
crumbs.hidden = true;
|
|
2364
|
-
bar.hidden = true;
|
|
2365
|
-
drawBox();
|
|
2366
|
-
say2(text, press);
|
|
2367
|
-
}
|
|
2368
|
-
function link(className, text, go) {
|
|
2369
|
-
const control = button(className, text);
|
|
2370
|
-
control.addEventListener("click", go);
|
|
2371
|
-
return control;
|
|
2372
|
-
}
|
|
2373
|
-
function onCrumbKey(event) {
|
|
2374
|
-
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
|
|
2375
|
-
return;
|
|
2376
|
-
const all = Array.from(crumbs.querySelectorAll("button"));
|
|
2377
|
-
const at = all.findIndex((crumb) => crumb.tabIndex === 0);
|
|
2378
|
-
const next = all[at + (event.key === "ArrowRight" ? 1 : -1)];
|
|
2379
|
-
const current = all[at];
|
|
2380
|
-
if (!next || !current)
|
|
2381
|
-
return;
|
|
2382
|
-
event.preventDefault();
|
|
2383
|
-
event.stopPropagation();
|
|
2384
|
-
current.tabIndex = -1;
|
|
2385
|
-
next.tabIndex = 0;
|
|
2386
|
-
next.focus({ preventScroll: true });
|
|
2387
|
-
next.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
2388
|
-
}
|
|
2389
|
-
crumbs.addEventListener("keydown", onCrumbKey);
|
|
2390
|
-
function drawCrumbs(element) {
|
|
2391
|
-
const chain = [];
|
|
2392
|
-
for (let up = element;up; up = flatParent(up))
|
|
2393
|
-
chain.unshift(up);
|
|
2394
|
-
const nodes = [];
|
|
2395
|
-
const add2 = (text, current, of, go) => {
|
|
2396
|
-
if (nodes.length > 0) {
|
|
2397
|
-
const mark2 = el("span", "crumb-sep", "›");
|
|
2398
|
-
mark2.setAttribute("aria-hidden", "true");
|
|
2399
|
-
nodes.push(mark2);
|
|
2400
|
-
}
|
|
2401
|
-
const crumb = link("crumb", text, go);
|
|
2402
|
-
crumb.addEventListener("pointerenter", () => {
|
|
2403
|
-
pointed = crumb;
|
|
2404
|
-
point(of);
|
|
2405
|
-
});
|
|
2406
|
-
crumb.addEventListener("pointerleave", () => {
|
|
2407
|
-
pointed = null;
|
|
2408
|
-
point(null);
|
|
2409
|
-
});
|
|
2410
|
-
crumb.tabIndex = current ? 0 : -1;
|
|
2411
|
-
if (current)
|
|
2412
|
-
crumb.setAttribute("aria-current", "true");
|
|
2413
|
-
nodes.push(crumb);
|
|
2414
|
-
};
|
|
2415
|
-
for (const one of chain) {
|
|
2416
|
-
add2(crumbText(label(one)), one === element && pseudo === null, one, () => show(one));
|
|
2417
|
-
}
|
|
2418
|
-
for (const name of pseudos)
|
|
2419
|
-
add2(name, name === pseudo, element, () => show(element, name));
|
|
2420
|
-
if (pointed)
|
|
2421
|
-
point(null);
|
|
2422
|
-
pointed = null;
|
|
2423
|
-
crumbs.replaceChildren(...nodes);
|
|
2424
|
-
crumbs.scrollLeft = crumbs.scrollWidth;
|
|
2425
|
-
}
|
|
2426
|
-
function flash(id) {
|
|
2427
|
-
const block = byId.get(id);
|
|
2428
|
-
if (!block || block.hidden)
|
|
2429
|
-
return;
|
|
2430
|
-
clearTimeout(flashTimer);
|
|
2431
|
-
lit?.classList.remove("flash");
|
|
2432
|
-
block.scrollIntoView({ block: "nearest" });
|
|
2433
|
-
block.offsetWidth;
|
|
2434
|
-
block.classList.add("flash");
|
|
2435
|
-
lit = block;
|
|
2436
|
-
flashTimer = window.setTimeout(() => block.classList.remove("flash"), FLASH);
|
|
2437
|
-
}
|
|
2438
|
-
function swatchNode(color) {
|
|
2439
|
-
const swatch = el("span", "css-swatch");
|
|
2440
|
-
swatch.setAttribute("aria-hidden", "true");
|
|
2441
|
-
swatch.style.backgroundColor = color;
|
|
2442
|
-
return swatch;
|
|
2443
|
-
}
|
|
2444
|
-
function sourceOfVariable(name) {
|
|
2445
|
-
if (!read)
|
|
2446
|
-
return null;
|
|
2447
|
-
let source = sources.get(name);
|
|
2448
|
-
if (source === undefined) {
|
|
2449
|
-
source = declaredIn(read.found, name);
|
|
2450
|
-
sources.set(name, source);
|
|
2451
|
-
}
|
|
2452
|
-
return source;
|
|
2453
|
-
}
|
|
2454
|
-
function variableSaid(name, fallback) {
|
|
2455
|
-
const element = target;
|
|
2456
|
-
const seen = (one) => element ? page.variable(element, pseudo, one) : "";
|
|
2457
|
-
const said2 = variableTip({ name, fallback }, seen, sourceOfVariable(name), page.isColor);
|
|
2458
|
-
const box2 = el("span", "tip-lines");
|
|
2459
|
-
said2.lines.forEach((text, index) => {
|
|
2460
|
-
const row = el("span", "tip-line");
|
|
2461
|
-
if (index === 0 && said2.color)
|
|
2462
|
-
row.append(swatchNode(said2.color));
|
|
2463
|
-
row.append(text);
|
|
2464
|
-
box2.append(row);
|
|
2465
|
-
});
|
|
2466
|
-
if (said2.source !== null)
|
|
2467
|
-
box2.append(el("span", "tip-line tip-quiet", said2.source));
|
|
2468
|
-
return box2;
|
|
2469
|
-
}
|
|
2470
|
-
function variable(name, fallback, className = "css-var") {
|
|
2471
|
-
const control = button(className, name);
|
|
2472
|
-
tip(control, () => variableSaid(name, fallback));
|
|
2473
|
-
return control;
|
|
2474
|
-
}
|
|
2475
|
-
function mark(text) {
|
|
2476
|
-
return el("span", "css-punct", text);
|
|
2477
|
-
}
|
|
2478
|
-
function named(row, declaration, variables) {
|
|
2479
|
-
const { name } = declaration;
|
|
2480
|
-
row.append(name.startsWith("--") ? variable(name, null, "css-name css-var") : el("span", "css-name", name), mark(": "));
|
|
2481
|
-
const color = swatchOf(declaration, variables, page.isColor);
|
|
2482
|
-
if (color)
|
|
2483
|
-
row.append(swatchNode(color));
|
|
2484
|
-
}
|
|
2485
|
-
function valueNode(declaration, variables) {
|
|
2486
|
-
const value = el("span", "css-value");
|
|
2487
|
-
for (const part of valueParts(declaration.value)) {
|
|
2488
|
-
if (part.kind !== "var") {
|
|
2489
|
-
value.append(part.text);
|
|
2490
|
-
continue;
|
|
2491
|
-
}
|
|
2492
|
-
const control = variable(part.text, part.fallback ?? null);
|
|
2493
|
-
const definedIn = variables?.[part.text]?.definedIn ?? null;
|
|
2494
|
-
if (definedIn !== null)
|
|
2495
|
-
control.addEventListener("click", () => flash(definedIn));
|
|
2496
|
-
value.append(control);
|
|
2497
|
-
}
|
|
2498
|
-
return value;
|
|
2499
|
-
}
|
|
2500
|
-
function line(declaration, variables) {
|
|
2501
|
-
const row = el(declaration.overridden ? "s" : "div", "css-decl");
|
|
2502
|
-
named(row, declaration, variables);
|
|
2503
|
-
row.append(valueNode(declaration, variables));
|
|
2504
|
-
if (declaration.important)
|
|
2505
|
-
row.append(" !important");
|
|
2506
|
-
row.append(mark(";"));
|
|
2507
|
-
return { node: row, declaration };
|
|
2508
|
-
}
|
|
2509
|
-
function blockNode(block, found, group) {
|
|
2510
|
-
const section = el("section", "css-block");
|
|
2511
|
-
section.setAttribute("role", "region");
|
|
2512
|
-
const head = el("div", "css-head");
|
|
2513
|
-
const selector = el("span", "css-selector");
|
|
2514
|
-
if (block.kind === "inline") {
|
|
2515
|
-
section.setAttribute("aria-label", "element.style");
|
|
2516
|
-
selector.textContent = "element.style";
|
|
2517
|
-
head.append(selector);
|
|
2518
|
-
} else {
|
|
2519
|
-
section.setAttribute("aria-label", block.selectorText);
|
|
2520
|
-
for (const context2 of block.context)
|
|
2521
|
-
section.append(el("div", "css-context", context2));
|
|
2522
|
-
block.selector.forEach((part, index) => {
|
|
2523
|
-
if (index > 0)
|
|
2524
|
-
selector.append(", ");
|
|
2525
|
-
selector.append(el("span", part.matches ? "css-part" : "css-part off", part.text));
|
|
2526
|
-
});
|
|
2527
|
-
const from = el("span", "css-from");
|
|
2528
|
-
if (block.conditional && !block.conditional.confirmed) {
|
|
2529
|
-
const { kind } = block.conditional;
|
|
2530
|
-
const mark2 = el("span", "css-mark", kind);
|
|
2531
|
-
tip(mark2, `could not tell whether its @${kind} holds for the element`);
|
|
2532
|
-
from.append(mark2);
|
|
2533
|
-
}
|
|
2534
|
-
const source = sourceOf(block.origin);
|
|
2535
|
-
const file = el("span", "css-source", source.text);
|
|
2536
|
-
tip(file, source.tip);
|
|
2537
|
-
from.append(file);
|
|
2538
|
-
head.append(selector, from);
|
|
2539
|
-
}
|
|
2540
|
-
section.append(head);
|
|
2541
|
-
const lines = block.declarations.map((declaration) => line(declaration, found.variables));
|
|
2542
|
-
section.append(...lines.map((one) => one.node));
|
|
2543
|
-
byId.set(block.id, section);
|
|
2544
|
-
return { node: section, lines, group };
|
|
2545
|
-
}
|
|
2546
|
-
function drawBlocks(found, element) {
|
|
2547
|
-
dropTips();
|
|
2548
|
-
built = [];
|
|
2549
|
-
byId = new Map;
|
|
2550
|
-
const nodes = [];
|
|
2551
|
-
const add2 = (block, group) => {
|
|
2552
|
-
const made = blockNode(block, found, group);
|
|
2553
|
-
built.push(made);
|
|
2554
|
-
nodes.push(made.node);
|
|
2555
|
-
};
|
|
2556
|
-
const each = (block) => {
|
|
2557
|
-
if (block.kind === "inherited") {
|
|
2558
|
-
const from = block.element;
|
|
2559
|
-
const head = link("css-group", `inherited from ${crumbText(block.from)}`, () => show(from));
|
|
2560
|
-
nodes.push(head);
|
|
2561
|
-
for (const own of block.blocks)
|
|
2562
|
-
add2(own, head);
|
|
2563
|
-
} else if (block.kind === "pseudo") {
|
|
2564
|
-
const name = block.pseudo;
|
|
2565
|
-
const head = link("css-group", name, () => show(element, name));
|
|
2566
|
-
nodes.push(head);
|
|
2567
|
-
for (const own of block.blocks)
|
|
2568
|
-
add2(own, head);
|
|
2569
|
-
} else
|
|
2570
|
-
add2(block, null);
|
|
2571
|
-
};
|
|
2572
|
-
found.blocks.forEach(each);
|
|
2573
|
-
for (const hidden of found.hidden)
|
|
2574
|
-
nodes.push(el("div", "css-hidden", hiddenLine(hidden)));
|
|
2575
|
-
blocks.replaceChildren(...nodes);
|
|
2576
|
-
}
|
|
2577
|
-
function appliedLine({ declaration }, variables) {
|
|
2578
|
-
const row = el("div", "css-decl");
|
|
2579
|
-
named(row, declaration, variables);
|
|
2580
|
-
row.append(valueNode(declaration));
|
|
2581
|
-
const comes = resolvedValue(declaration.value, variables);
|
|
2582
|
-
if (comes !== null)
|
|
2583
|
-
row.append(el("span", "css-comes", ` → ${comes}`));
|
|
2584
|
-
return { node: row, declaration };
|
|
2585
|
-
}
|
|
2586
|
-
function drawApplied(found) {
|
|
2587
|
-
dropTips();
|
|
2588
|
-
built = [];
|
|
2589
|
-
byId = new Map;
|
|
2590
|
-
const groups = grouped(appliedOwn(found));
|
|
2591
|
-
const own = groups.length > 0 ? el("div", "css-block css-applied") : emptyLine(NO_STYLES);
|
|
2592
|
-
const sets = groups.map(({ group, lines }) => {
|
|
2593
|
-
const set = el("div", "css-set");
|
|
2594
|
-
set.setAttribute("role", "group");
|
|
2595
|
-
set.setAttribute("aria-label", group);
|
|
2596
|
-
const name = groups.length > 1 ? el("div", "css-label", group) : null;
|
|
2597
|
-
if (name)
|
|
2598
|
-
name.setAttribute("aria-hidden", "true");
|
|
2599
|
-
const made = lines.map((one) => appliedLine(one, found.variables));
|
|
2600
|
-
set.append(...name ? [name] : [], ...made.map((one) => one.node));
|
|
2601
|
-
own.append(set);
|
|
2602
|
-
return { node: set, label: name, lines: made };
|
|
2603
|
-
});
|
|
2604
|
-
const nodes = [own];
|
|
2605
|
-
const handed = appliedInherited(found);
|
|
2606
|
-
flat = { own, sets, inherited: null };
|
|
2607
|
-
if (handed.length > 0) {
|
|
2608
|
-
const fold = sectionFold({
|
|
2609
|
-
label: "inherited",
|
|
2610
|
-
open: unfolded,
|
|
2611
|
-
onToggle: (open2) => {
|
|
2612
|
-
unfolded = open2;
|
|
2613
|
-
}
|
|
2614
|
-
});
|
|
2615
|
-
const body = el("div", "css-applied");
|
|
2616
|
-
body.setAttribute("role", "group");
|
|
2617
|
-
body.setAttribute("aria-label", "inherited");
|
|
2618
|
-
const lines = handed.map((one) => appliedLine(one, found.variables));
|
|
2619
|
-
body.append(...lines.map((one) => one.node));
|
|
2620
|
-
fold.body.append(body);
|
|
2621
|
-
flat.inherited = { fold, lines };
|
|
2622
|
-
nodes.push(fold.node);
|
|
2623
|
-
}
|
|
2624
|
-
const hidden = hiddenNote(found.hidden);
|
|
2625
|
-
if (hidden !== null)
|
|
2626
|
-
nodes.push(el("div", "css-hidden", hidden));
|
|
2627
|
-
blocks.replaceChildren(...nodes);
|
|
2628
|
-
}
|
|
2629
|
-
function filterApplied(view) {
|
|
2630
|
-
const text = filter.node.value;
|
|
2631
|
-
const filtering = text.trim() !== "";
|
|
2632
|
-
const keeps = (lines) => {
|
|
2633
|
-
let kept = false;
|
|
2634
|
-
for (const one of lines) {
|
|
2635
|
-
const matches = matchesFilter(one.declaration, text);
|
|
2636
|
-
one.node.hidden = !matches;
|
|
2637
|
-
if (matches)
|
|
2638
|
-
kept = true;
|
|
2639
|
-
}
|
|
2640
|
-
return kept;
|
|
2641
|
-
};
|
|
2642
|
-
let shown2 = 0;
|
|
2643
|
-
for (const set of view.sets) {
|
|
2644
|
-
const kept = keeps(set.lines);
|
|
2645
|
-
set.node.hidden = !kept;
|
|
2646
|
-
if (kept)
|
|
2647
|
-
shown2 += 1;
|
|
2648
|
-
}
|
|
2649
|
-
for (const set of view.sets)
|
|
2650
|
-
if (set.label)
|
|
2651
|
-
set.label.hidden = shown2 < 2;
|
|
2652
|
-
view.own.hidden = view.sets.length === 0 ? filtering : shown2 === 0;
|
|
2653
|
-
const inherited = view.inherited;
|
|
2654
|
-
const handed = inherited ? keeps(inherited.lines) : false;
|
|
2655
|
-
if (inherited)
|
|
2656
|
-
inherited.fold.node.hidden = !handed;
|
|
2657
|
-
say2(filtering && shown2 === 0 && !handed ? NO_MATCH : null);
|
|
2658
|
-
}
|
|
2659
|
-
function applyFilter() {
|
|
2660
|
-
if (flat) {
|
|
2661
|
-
filterApplied(flat);
|
|
2662
|
-
return;
|
|
2663
|
-
}
|
|
2664
|
-
const text = filter.node.value;
|
|
2665
|
-
const filtering = text.trim() !== "";
|
|
2666
|
-
const groups = new Map;
|
|
2667
|
-
let any = false;
|
|
2668
|
-
for (const block of built) {
|
|
2669
|
-
let kept = !filtering;
|
|
2670
|
-
for (const one of block.lines) {
|
|
2671
|
-
const matches = matchesFilter(one.declaration, text);
|
|
2672
|
-
one.node.hidden = !matches;
|
|
2673
|
-
if (matches)
|
|
2674
|
-
kept = true;
|
|
2675
|
-
}
|
|
2676
|
-
block.node.hidden = !kept;
|
|
2677
|
-
if (kept)
|
|
2678
|
-
any = true;
|
|
2679
|
-
if (block.group)
|
|
2680
|
-
groups.set(block.group, (groups.get(block.group) ?? false) || kept);
|
|
2681
|
-
}
|
|
2682
|
-
for (const [head, kept] of groups)
|
|
2683
|
-
head.hidden = !kept;
|
|
2684
|
-
say2(any ? null : built.length === 0 ? NO_RULES : NO_MATCH);
|
|
2685
|
-
}
|
|
2686
|
-
function refresh() {
|
|
2687
|
-
clearTimeout(timer);
|
|
2688
|
-
timer = 0;
|
|
2689
|
-
const element = target;
|
|
2690
|
-
if (!element)
|
|
2691
|
-
return;
|
|
2692
|
-
if (stale) {
|
|
2693
|
-
stale = false;
|
|
2694
|
-
page.invalidate();
|
|
2695
|
-
}
|
|
2696
|
-
if (!element.isConnected || !element.ownerDocument.defaultView) {
|
|
2697
|
-
target = null;
|
|
2698
|
-
unwatch();
|
|
2699
|
-
point(null);
|
|
2700
|
-
context.held?.(null);
|
|
2701
|
-
clear(GONE, GONE_PICK);
|
|
2702
|
-
return;
|
|
2703
|
-
}
|
|
2704
|
-
const found = page.inspect(element, pseudo ?? undefined);
|
|
2705
|
-
if (pseudo === null) {
|
|
2706
|
-
pseudos = found.blocks.flatMap((block) => block.kind === "pseudo" ? [block.pseudo] : []);
|
|
2707
|
-
}
|
|
2708
|
-
crumbs.hidden = false;
|
|
2709
|
-
bar.hidden = false;
|
|
2710
|
-
context.title(middle(`${found.target.label}${found.target.pseudo ?? ""}`, TITLE_MAX));
|
|
2711
|
-
drawCrumbs(element);
|
|
2712
|
-
drawBox();
|
|
2713
|
-
read = { found, element };
|
|
2714
|
-
sources = new Map;
|
|
2715
|
-
draw();
|
|
2716
|
-
}
|
|
2717
|
-
function draw() {
|
|
2718
|
-
if (!read)
|
|
2719
|
-
return;
|
|
2720
|
-
flat = null;
|
|
2721
|
-
if (mode === "simple")
|
|
2722
|
-
drawApplied(read.found);
|
|
2723
|
-
else
|
|
2724
|
-
drawBlocks(read.found, read.element);
|
|
2725
|
-
applyFilter();
|
|
2726
|
-
}
|
|
2727
|
-
function setMode(value) {
|
|
2728
|
-
const next = MODES.find((one) => one === value);
|
|
2729
|
-
if (!next || next === mode)
|
|
2730
|
-
return;
|
|
2731
|
-
mode = next;
|
|
2732
|
-
context.mode?.set(next);
|
|
2733
|
-
modes?.set(next);
|
|
2734
|
-
const body = node.closest(".view-body");
|
|
2735
|
-
if (body)
|
|
2736
|
-
body.scrollTop = 0;
|
|
2737
|
-
draw();
|
|
2738
|
-
}
|
|
2739
|
-
function show(element, name) {
|
|
2740
|
-
if (element !== target)
|
|
2741
|
-
pseudos = [];
|
|
2742
|
-
target = element;
|
|
2743
|
-
pseudo = name ?? null;
|
|
2744
|
-
if (pseudo !== null && !pseudos.includes(pseudo))
|
|
2745
|
-
pseudos = [...pseudos, pseudo];
|
|
2746
|
-
point(null);
|
|
2747
|
-
context.held?.(element);
|
|
2748
|
-
if (!element) {
|
|
2749
|
-
unwatch();
|
|
2750
|
-
context.title("styles");
|
|
2751
|
-
clear(EMPTY, PICK);
|
|
2752
|
-
return;
|
|
2753
|
-
}
|
|
2754
|
-
watch(element);
|
|
2755
|
-
const body = node.closest(".view-body");
|
|
2756
|
-
if (body)
|
|
2757
|
-
body.scrollTop = 0;
|
|
2758
|
-
refresh();
|
|
2759
|
-
}
|
|
2760
|
-
const unsubscribe = page.subscribe((state) => {
|
|
2761
|
-
const next = knobsOf(state);
|
|
2762
|
-
if (next === knobs)
|
|
2763
|
-
return;
|
|
2764
|
-
knobs = next;
|
|
2765
|
-
stale = true;
|
|
2766
|
-
if (target)
|
|
2767
|
-
later();
|
|
2768
|
-
});
|
|
2769
|
-
clear(EMPTY, PICK);
|
|
2770
|
-
return {
|
|
2771
|
-
node,
|
|
2772
|
-
show,
|
|
2773
|
-
refresh,
|
|
2774
|
-
escape: filter.clear,
|
|
2775
|
-
focus: () => node.focus({ preventScroll: true }),
|
|
2776
|
-
destroy() {
|
|
2777
|
-
clearTimeout(timer);
|
|
2778
|
-
clearTimeout(flashTimer);
|
|
2779
|
-
unwatch();
|
|
2780
|
-
unsubscribe();
|
|
2781
|
-
unpick?.();
|
|
2782
|
-
fitter?.disconnect();
|
|
2783
|
-
point(null);
|
|
2784
|
-
context.area?.(null);
|
|
2785
|
-
crumbs.removeEventListener("keydown", onCrumbKey);
|
|
2786
|
-
dropTips();
|
|
2787
|
-
target = null;
|
|
2788
|
-
}
|
|
2789
|
-
};
|
|
2790
|
-
}
|
|
2791
|
-
|
|
2792
|
-
// src/ui/elementsview.ts
|
|
2793
|
-
var DOLLAR = "$0";
|
|
2794
|
-
function createDollar() {
|
|
2795
|
-
let held = null;
|
|
2796
|
-
function release() {
|
|
2797
|
-
if (!held)
|
|
2798
|
-
return;
|
|
2799
|
-
const { view, node } = held;
|
|
2800
|
-
held = null;
|
|
2801
|
-
try {
|
|
2802
|
-
if (Reflect.get(view, DOLLAR) === node)
|
|
2803
|
-
Reflect.deleteProperty(view, DOLLAR);
|
|
2804
|
-
} catch {}
|
|
2805
|
-
}
|
|
2806
|
-
function set(node) {
|
|
2807
|
-
const view = node?.ownerDocument?.defaultView ?? null;
|
|
2808
|
-
if (held && held.view !== view)
|
|
2809
|
-
release();
|
|
2810
|
-
if (!node || !view)
|
|
2811
|
-
return;
|
|
2812
|
-
try {
|
|
2813
|
-
if (held) {
|
|
2814
|
-
if (Reflect.get(view, DOLLAR) !== held.node)
|
|
2815
|
-
return;
|
|
2816
|
-
Reflect.set(view, DOLLAR, node);
|
|
2817
|
-
held = { view, node };
|
|
2818
|
-
return;
|
|
2819
|
-
}
|
|
2820
|
-
if (DOLLAR in view)
|
|
2821
|
-
return;
|
|
2822
|
-
Object.defineProperty(view, DOLLAR, { value: node, writable: true, configurable: true, enumerable: false });
|
|
2823
|
-
held = { view, node };
|
|
2824
|
-
} catch {}
|
|
2825
|
-
}
|
|
2826
|
-
return { set, release };
|
|
2827
|
-
}
|
|
2828
|
-
function createElementsView(context, parts = {}) {
|
|
2829
|
-
const node = el("div", "elements");
|
|
2830
|
-
const dollar = createDollar();
|
|
2831
|
-
let fromTree = false;
|
|
2832
|
-
const copy = parts.copy ?? ((text) => void copyText(text));
|
|
2833
|
-
const tree = (parts.tree ?? createDomTree)({
|
|
2834
|
-
outline: (element) => context.outline(element),
|
|
2835
|
-
select(picked, pseudo) {
|
|
2836
|
-
dollar.set(picked);
|
|
2837
|
-
fromTree = true;
|
|
2838
|
-
try {
|
|
2839
|
-
styles.show(elementOf(picked), pseudo ?? undefined);
|
|
2840
|
-
} finally {
|
|
2841
|
-
fromTree = false;
|
|
2842
|
-
}
|
|
2843
|
-
},
|
|
2844
|
-
copy
|
|
2845
|
-
});
|
|
2846
|
-
const styles = createStylesView({
|
|
2847
|
-
...context,
|
|
2848
|
-
held(element) {
|
|
2849
|
-
context.held?.(element);
|
|
2850
|
-
if (fromTree)
|
|
2851
|
-
return;
|
|
2852
|
-
tree.reveal(element);
|
|
2853
|
-
dollar.set(element);
|
|
2854
|
-
}
|
|
2855
|
-
}, parts.page);
|
|
2856
|
-
node.append(tree.node, styles.node);
|
|
2857
|
-
return {
|
|
2858
|
-
node,
|
|
2859
|
-
show: (element, pseudo) => styles.show(element, pseudo),
|
|
2860
|
-
refresh: () => styles.refresh(),
|
|
2861
|
-
escape: () => styles.escape(),
|
|
2862
|
-
focus: () => styles.focus(),
|
|
2863
|
-
destroy() {
|
|
2864
|
-
tree.destroy();
|
|
2865
|
-
styles.destroy();
|
|
2866
|
-
dollar.release();
|
|
2867
|
-
}
|
|
2868
|
-
};
|
|
2869
|
-
}
|
|
2870
|
-
export {
|
|
2871
|
-
createElementsView,
|
|
2872
|
-
createDollar,
|
|
2873
|
-
DOLLAR
|
|
2874
|
-
};
|