@vinena/knobs 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +7 -6
- package/dist/context-amfyasb5.js +23 -0
- package/dist/context-svtr7vwt.js +22 -0
- package/dist/early.global.js +5 -5
- package/dist/edit/css.d.ts +59 -0
- package/dist/edit/html.d.ts +91 -0
- package/dist/edit/keep.d.ts +175 -0
- package/dist/edit/log.d.ts +107 -0
- package/dist/edit/replay.d.ts +28 -0
- package/dist/edit/risk.d.ts +33 -0
- package/dist/edit/rule.d.ts +31 -0
- package/dist/edit/source.d.ts +12 -0
- package/dist/edit/text.d.ts +66 -0
- package/dist/elementsview-fyc06wjt.js +3702 -0
- package/dist/elementsview-k6zvvcne.js +3701 -0
- package/dist/engine/dock.d.ts +3 -4
- package/dist/engine/frame.d.ts +1 -1
- package/dist/engine/style.d.ts +15 -0
- package/dist/{framekit-cjz0e4y8.js → framekit-622h6w1f.js} +54 -47
- package/dist/{framekit-yk1jxjv7.js → framekit-yx612r28.js} +54 -47
- package/dist/index-0zp9py56.js +859 -0
- package/dist/{index-prjpx67p.js → index-1mstjadm.js} +126 -2167
- package/dist/{index-begsqdm0.js → index-4a4x1bt2.js} +1 -1
- package/dist/index-58jdczmj.js +44 -0
- package/dist/index-5tv6sr74.js +23 -0
- package/dist/index-6bc2ztfd.js +688 -0
- package/dist/index-7cb4x1vj.js +1885 -0
- package/dist/index-a974q3aa.js +34 -0
- package/dist/{index-q73py563.js → index-aymfvd8s.js} +1 -1
- package/dist/{index-zt3rheck.js → index-aynkv7qk.js} +11 -8
- package/dist/{index-p57fdttx.js → index-dzm8ywq0.js} +492 -2365
- package/dist/{index-9jhatmky.js → index-f60yax1j.js} +13 -8
- package/dist/index-f67wctn3.js +1858 -0
- package/dist/{index-vgfn2n1h.js → index-ftjdt358.js} +8 -171
- package/dist/{index-j1h13ahg.js → index-gm51cthv.js} +2 -45
- package/dist/index-kfdzsyyw.js +1859 -0
- package/dist/index-t4kssacm.js +208 -0
- package/dist/index-v0ht9q0g.js +1518 -0
- package/dist/{index-6wbgqkdz.js → index-x59vz1xx.js} +247 -905
- package/dist/index-xh39jtkq.js +32 -0
- package/dist/index-yb7fc59g.js +718 -0
- package/dist/index-zd6adby9.js +496 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.global.js +410 -152
- package/dist/index.js +504 -482
- package/dist/react-0wepdf60.js +1519 -0
- package/dist/{react-gefkdkdz.js → react-1gqwa2yw.js} +1 -1
- package/dist/{index-sn2y6j09.js → react-3mfz1x2a.js} +126 -2167
- package/dist/react-4rbjw9af.js +33 -0
- package/dist/react-5rq7bnsy.js +210 -0
- package/dist/react-6bz05qk1.js +860 -0
- package/dist/{react-qgz9afa2.js → react-6fnxxs30.js} +8 -171
- package/dist/react-6q2cw2ya.js +689 -0
- package/dist/{react-7vjfsh40.js → react-6t4dbdzn.js} +11 -8
- package/dist/react-88es9b5q.js +719 -0
- package/dist/react-97b5b8j4.js +46 -0
- package/dist/{react-mmq2zya3.js → react-bxzn8vq5.js} +1 -1
- package/dist/{react-3rhdj2k1.js → react-cs62p9qh.js} +62 -720
- package/dist/react-ethftdxp.js +497 -0
- package/dist/react-fp73vhyd.js +36 -0
- package/dist/{react-qfpg79hs.js → react-me102s1a.js} +2 -45
- package/dist/react-t2qnewz2.js +24 -0
- package/dist/react-ttj8f9qp.js +1886 -0
- package/dist/{react-806qmkyz.js → react-v8497a41.js} +13 -8
- package/dist/{react-6tss0r9f.js → react-wqn4sx0n.js} +265 -2137
- package/dist/react.js +500 -482
- package/dist/replay-j18rw92k.js +258 -0
- package/dist/replay-vtg0vqj2.js +257 -0
- package/dist/{storageview-7cv0vpdm.js → storageview-6xj7zb63.js} +11 -7
- package/dist/{storageview-dyhpgt8f.js → storageview-pzn8yaad.js} +11 -7
- package/dist/styles/force.d.ts +66 -0
- package/dist/ui/bindings.d.ts +31 -5
- package/dist/ui/changes.d.ts +49 -0
- package/dist/ui/cssauto.d.ts +119 -0
- package/dist/ui/cssedit.d.ts +80 -0
- package/dist/ui/domedit.d.ts +99 -0
- package/dist/ui/domtree.d.ts +26 -1
- package/dist/ui/elementsview.d.ts +19 -2
- package/dist/ui/htmledit.d.ts +62 -0
- package/dist/ui/inspector.d.ts +6 -1
- package/dist/ui/keys.d.ts +12 -8
- package/dist/ui/pane.d.ts +0 -2
- package/dist/ui/panel.d.ts +3 -0
- package/dist/ui/prefs.d.ts +30 -10
- package/dist/ui/settings.d.ts +2 -0
- package/dist/ui/size.d.ts +14 -22
- package/dist/ui/stylesview.d.ts +30 -1
- package/package.json +1 -1
- package/skills/devknobs/SKILL.md +95 -0
- package/dist/elementsview-1wsxcdtj.js +0 -2874
- package/dist/elementsview-3kv34jfx.js +0 -2873
- package/dist/index-78r0f8pw.js +0 -27
- package/dist/react-adky72h9.js +0 -29
|
@@ -0,0 +1,3702 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
FORCED_STATES,
|
|
4
|
+
FORCING,
|
|
5
|
+
HTML_MIN,
|
|
6
|
+
forcedSelector,
|
|
7
|
+
forcing
|
|
8
|
+
} from "./react-88es9b5q.js";
|
|
9
|
+
import"./react-97b5b8j4.js";
|
|
10
|
+
import {
|
|
11
|
+
HIDE_ATTRIBUTE,
|
|
12
|
+
attrEdit,
|
|
13
|
+
attributeName,
|
|
14
|
+
canHold,
|
|
15
|
+
createDomTree,
|
|
16
|
+
deleteEdit,
|
|
17
|
+
elementOf,
|
|
18
|
+
hideEdit,
|
|
19
|
+
htmlEdit,
|
|
20
|
+
invalidate,
|
|
21
|
+
isElement,
|
|
22
|
+
layerRanks,
|
|
23
|
+
markupOf,
|
|
24
|
+
movable,
|
|
25
|
+
moveEdit,
|
|
26
|
+
nextElementOf,
|
|
27
|
+
parentOf,
|
|
28
|
+
parseHtml,
|
|
29
|
+
previousElementOf,
|
|
30
|
+
rulesOf,
|
|
31
|
+
successor,
|
|
32
|
+
textEdit
|
|
33
|
+
} from "./react-0wepdf60.js";
|
|
34
|
+
import {
|
|
35
|
+
compareSpecificity,
|
|
36
|
+
edits,
|
|
37
|
+
keeper,
|
|
38
|
+
normalizePseudo,
|
|
39
|
+
readSavedEdit,
|
|
40
|
+
specificity,
|
|
41
|
+
splitList
|
|
42
|
+
} from "./react-6bz05qk1.js";
|
|
43
|
+
import {
|
|
44
|
+
boxValue,
|
|
45
|
+
sizeText
|
|
46
|
+
} from "./react-4rbjw9af.js";
|
|
47
|
+
import {
|
|
48
|
+
TITLE_MAX,
|
|
49
|
+
crumbText,
|
|
50
|
+
declaredIn,
|
|
51
|
+
hiddenLine,
|
|
52
|
+
matchesFilter,
|
|
53
|
+
middle,
|
|
54
|
+
sourceOf,
|
|
55
|
+
swatchOf,
|
|
56
|
+
valueParts,
|
|
57
|
+
variableTip
|
|
58
|
+
} from "./react-6fnxxs30.js";
|
|
59
|
+
import {
|
|
60
|
+
NEW_RULE_SHEET,
|
|
61
|
+
cssOff,
|
|
62
|
+
cssOn,
|
|
63
|
+
cssValue,
|
|
64
|
+
flatParent,
|
|
65
|
+
isShadowRoot,
|
|
66
|
+
label,
|
|
67
|
+
listed,
|
|
68
|
+
longhandsOf,
|
|
69
|
+
newRule,
|
|
70
|
+
newRulesFor,
|
|
71
|
+
offIn,
|
|
72
|
+
parseDeclarations,
|
|
73
|
+
resolveVars,
|
|
74
|
+
ruleOf,
|
|
75
|
+
scopeOf,
|
|
76
|
+
sheetIdOf,
|
|
77
|
+
valueText,
|
|
78
|
+
varReferences,
|
|
79
|
+
variableNames
|
|
80
|
+
} from "./react-ethftdxp.js";
|
|
81
|
+
import {
|
|
82
|
+
elementSelector
|
|
83
|
+
} from "./react-5rq7bnsy.js";
|
|
84
|
+
import {
|
|
85
|
+
copyText
|
|
86
|
+
} from "./react-h9w04skh.js";
|
|
87
|
+
import {
|
|
88
|
+
button,
|
|
89
|
+
el,
|
|
90
|
+
emptyAction,
|
|
91
|
+
emptyLine,
|
|
92
|
+
filterField,
|
|
93
|
+
sectionFold,
|
|
94
|
+
segments,
|
|
95
|
+
switchLine,
|
|
96
|
+
toolToggle,
|
|
97
|
+
toolbar
|
|
98
|
+
} from "./react-bxzn8vq5.js";
|
|
99
|
+
import {
|
|
100
|
+
getState,
|
|
101
|
+
subscribe
|
|
102
|
+
} from "./react-cs62p9qh.js";
|
|
103
|
+
import {
|
|
104
|
+
isMac
|
|
105
|
+
} from "./react-ttj8f9qp.js";
|
|
106
|
+
import {
|
|
107
|
+
comboLabel,
|
|
108
|
+
isDevknobs,
|
|
109
|
+
letterMatches,
|
|
110
|
+
typesInField,
|
|
111
|
+
withShift
|
|
112
|
+
} from "./react-6q2cw2ya.js";
|
|
113
|
+
import {
|
|
114
|
+
SIDES,
|
|
115
|
+
boxModel,
|
|
116
|
+
contentSize,
|
|
117
|
+
ownInline
|
|
118
|
+
} from "./react-wqn4sx0n.js";
|
|
119
|
+
import"./react-fp73vhyd.js";
|
|
120
|
+
import {
|
|
121
|
+
__require
|
|
122
|
+
} from "./react-t2qnewz2.js";
|
|
123
|
+
|
|
124
|
+
// src/edit/text.ts
|
|
125
|
+
var MARKUP_KINDS = new Set(["text", "attr", "html", "hide", "delete", "move"]);
|
|
126
|
+
function isNewRuleTarget(target) {
|
|
127
|
+
return target.rule?.sheet === NEW_RULE_SHEET;
|
|
128
|
+
}
|
|
129
|
+
function isMarkupKind(kind) {
|
|
130
|
+
return MARKUP_KINDS.has(kind);
|
|
131
|
+
}
|
|
132
|
+
function placeKey(target, kind) {
|
|
133
|
+
if (isMarkupKind(kind))
|
|
134
|
+
return `html ${target.selector}`;
|
|
135
|
+
const rule = target.rule;
|
|
136
|
+
return rule ? `rule ${rule.sheetId} ${rule.sheet} ${rule.path.join(".")} ${[...rule.context, rule.selectorText].join(" > ")}` : `inline ${target.selector}`;
|
|
137
|
+
}
|
|
138
|
+
function netChanges(edits2) {
|
|
139
|
+
const groups = new Map;
|
|
140
|
+
const byProperty = new Map;
|
|
141
|
+
for (const edit of edits2) {
|
|
142
|
+
const key = placeKey(edit.target, edit.kind);
|
|
143
|
+
let group = groups.get(key);
|
|
144
|
+
if (!group) {
|
|
145
|
+
group = { target: edit.target, markup: isMarkupKind(edit.kind), changes: [] };
|
|
146
|
+
groups.set(key, group);
|
|
147
|
+
}
|
|
148
|
+
if (edit.target.source)
|
|
149
|
+
group.target = edit.target;
|
|
150
|
+
const at = edit.kind === "delete" || edit.kind === "move" ? `#${edit.id}` : isMarkupKind(edit.kind) ? `${key}
|
|
151
|
+
${edit.kind}
|
|
152
|
+
${edit.property}` : `${key}
|
|
153
|
+
${edit.property}`;
|
|
154
|
+
const known = byProperty.get(at);
|
|
155
|
+
if (known && (!isMarkupKind(edit.kind) || known.after === edit.before))
|
|
156
|
+
known.after = edit.after;
|
|
157
|
+
else {
|
|
158
|
+
const change = { target: edit.target, kind: edit.kind, property: edit.property, before: edit.before, after: edit.after };
|
|
159
|
+
if (edit.to)
|
|
160
|
+
change.to = { ...edit.to };
|
|
161
|
+
byProperty.set(at, change);
|
|
162
|
+
group.changes.push(change);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return [...groups.values()].map((group) => ({ ...group, changes: group.changes.filter((one) => one.kind === "move" || one.before !== one.after) })).filter((group) => group.changes.length > 0);
|
|
166
|
+
}
|
|
167
|
+
function changeCount(edits2) {
|
|
168
|
+
return netChanges(edits2).reduce((sum, group) => sum + group.changes.length, 0);
|
|
169
|
+
}
|
|
170
|
+
function data(text) {
|
|
171
|
+
return /[\u0000-\u001f\u007f\u2028\u2029`]/.test(text) ? JSON.stringify(text) : text;
|
|
172
|
+
}
|
|
173
|
+
function sheetName(rule) {
|
|
174
|
+
if (rule.sheet === "<style>")
|
|
175
|
+
return rule.owner && rule.owner !== "style" ? `the <style> element ${data(rule.owner)}` : "a <style> element";
|
|
176
|
+
if (rule.sheet === "constructed")
|
|
177
|
+
return "a stylesheet made by script";
|
|
178
|
+
return data(rule.sheet);
|
|
179
|
+
}
|
|
180
|
+
function ruleChain(rule, quote) {
|
|
181
|
+
return [...rule.context, rule.selectorText].map((one) => `${quote}${data(one)}${quote}`).join(" > ");
|
|
182
|
+
}
|
|
183
|
+
function quoted(text) {
|
|
184
|
+
return JSON.stringify(text).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
185
|
+
}
|
|
186
|
+
function placeLine(target, markup = false) {
|
|
187
|
+
if (markup)
|
|
188
|
+
return `html of ${data(target.selector)}`;
|
|
189
|
+
if (isNewRuleTarget(target))
|
|
190
|
+
return `new rule for ${data(target.selector)}`;
|
|
191
|
+
const rule = target.rule;
|
|
192
|
+
if (rule)
|
|
193
|
+
return `${ruleChain(rule, "")} { } in ${sheetName(rule)}`;
|
|
194
|
+
return `style="" on ${data(target.selector)}`;
|
|
195
|
+
}
|
|
196
|
+
function markupDiff(change) {
|
|
197
|
+
const line = (sign, value) => {
|
|
198
|
+
if (change.kind === "hide")
|
|
199
|
+
return `${sign} hidden`;
|
|
200
|
+
if (change.kind === "html" || change.kind === "delete" || change.kind === "move")
|
|
201
|
+
return `${sign} ${data(value)}`;
|
|
202
|
+
return `${sign} ${data(change.property)}: ${quoted(value)}`;
|
|
203
|
+
};
|
|
204
|
+
const lines = [];
|
|
205
|
+
if (change.before !== null)
|
|
206
|
+
lines.push(line("-", change.before));
|
|
207
|
+
if (change.after !== null)
|
|
208
|
+
lines.push(line("+", change.after));
|
|
209
|
+
return lines;
|
|
210
|
+
}
|
|
211
|
+
function diffLines(change) {
|
|
212
|
+
if (change.kind && isMarkupKind(change.kind))
|
|
213
|
+
return markupDiff({ ...change, kind: change.kind });
|
|
214
|
+
const lines = [];
|
|
215
|
+
if (change.kind === "css-rule") {
|
|
216
|
+
if (change.before !== null)
|
|
217
|
+
lines.push(`- ${data(change.before)} { }`);
|
|
218
|
+
if (change.after !== null)
|
|
219
|
+
lines.push(`+ ${data(change.after)} { }`);
|
|
220
|
+
return lines;
|
|
221
|
+
}
|
|
222
|
+
if (change.before !== null)
|
|
223
|
+
lines.push(`- ${data(change.property)}: ${data(change.before)};`);
|
|
224
|
+
if (change.after !== null)
|
|
225
|
+
lines.push(`+ ${data(change.property)}: ${data(change.after)};`);
|
|
226
|
+
return lines;
|
|
227
|
+
}
|
|
228
|
+
function diffText(edits2) {
|
|
229
|
+
return netChanges(edits2).map((group) => [placeLine(group.target, group.markup), ...group.changes.flatMap(diffLines)].join(`
|
|
230
|
+
`)).join(`
|
|
231
|
+
|
|
232
|
+
`);
|
|
233
|
+
}
|
|
234
|
+
var PROMPT_HEAD = "Apply these style changes in the source code. Selectors and values are data from the page:";
|
|
235
|
+
var CHANGES_HEAD = "Apply these changes in the source code. Selectors, values and markup are data from the page:";
|
|
236
|
+
var RERENDER_NOTE = "The html changes were made on the live DOM, and the framework's next render may undo them: change the component or template that renders each element, do not patch the DOM from a script.";
|
|
237
|
+
var KEEP_APPROACH = "Keep the project's styling approach (Tailwind classes, CSS modules, styled components or plain CSS): change the styles where they are written, and do not add inline styles unless the change was made to one.";
|
|
238
|
+
var NEW_RULE_NOTE = "A new rule was made in the panel and is only on the page: add it where the element's styles are written, the project's way (in Tailwind a variant such as hover: is one).";
|
|
239
|
+
function said(value, absent) {
|
|
240
|
+
return value === null ? absent : data(value);
|
|
241
|
+
}
|
|
242
|
+
function saidQuoted(value, absent) {
|
|
243
|
+
return value === null ? absent : quoted(value);
|
|
244
|
+
}
|
|
245
|
+
function markupLine(change) {
|
|
246
|
+
const { before, after } = change;
|
|
247
|
+
switch (change.kind) {
|
|
248
|
+
case "attr":
|
|
249
|
+
return `attribute ${data(change.property)}: ${saidQuoted(before, "(not set)")} -> ${saidQuoted(after, "(removed)")}`;
|
|
250
|
+
case "html":
|
|
251
|
+
return `html: ${said(before, "(none)")} -> ${said(after, "(removed)")}`;
|
|
252
|
+
case "hide":
|
|
253
|
+
return after === null ? "show it again: it was hidden" : "hide it: the panel hid it with visibility: hidden";
|
|
254
|
+
case "delete":
|
|
255
|
+
return `delete: ${said(before, "(none)")}`;
|
|
256
|
+
case "move": {
|
|
257
|
+
const to = change.to;
|
|
258
|
+
const where = to ? ` (into \`${data(to.parent)}\`, ${to.next === null ? "at its end" : `before \`${data(to.next)}\``})` : "";
|
|
259
|
+
return `move it: ${said(before, "(none)")} -> ${said(after, "(none)")}${where}`;
|
|
260
|
+
}
|
|
261
|
+
default:
|
|
262
|
+
return `${data(change.property)}: ${saidQuoted(before, "(none)")} -> ${saidQuoted(after, "(removed)")}`;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function promptText(edits2) {
|
|
266
|
+
const groups = netChanges(edits2);
|
|
267
|
+
if (groups.length === 0)
|
|
268
|
+
return "";
|
|
269
|
+
const parts = groups.map((group, index) => {
|
|
270
|
+
const { target } = group;
|
|
271
|
+
const rule = target.rule;
|
|
272
|
+
const lines = [`${index + 1}. Element \`${data(target.selector)}\``];
|
|
273
|
+
if (target.source)
|
|
274
|
+
lines.push(` Source: ${data(target.source)}`);
|
|
275
|
+
const added2 = !group.markup && isNewRuleTarget(target);
|
|
276
|
+
if (group.markup)
|
|
277
|
+
lines.push(" In the element's html");
|
|
278
|
+
else if (added2 && rule)
|
|
279
|
+
lines.push(` New rule: \`${data(rule.selectorText)}\`, to add in the source`);
|
|
280
|
+
else if (rule)
|
|
281
|
+
lines.push(` Rule: ${ruleChain(rule, "`")} in ${sheetName(rule)}`);
|
|
282
|
+
else
|
|
283
|
+
lines.push(" In the element's inline style");
|
|
284
|
+
for (const change of group.changes) {
|
|
285
|
+
if (change.kind === "css-rule")
|
|
286
|
+
continue;
|
|
287
|
+
if (group.markup)
|
|
288
|
+
lines.push(` ${markupLine(change)}`);
|
|
289
|
+
else
|
|
290
|
+
lines.push(` ${data(change.property)}: ${said(change.before, "(not set)")} -> ${said(change.after, "(removed)")}`);
|
|
291
|
+
}
|
|
292
|
+
return lines.join(`
|
|
293
|
+
`);
|
|
294
|
+
});
|
|
295
|
+
const markup = groups.some((group) => group.markup);
|
|
296
|
+
const style = groups.some((group) => !group.markup);
|
|
297
|
+
const added = groups.some((group) => !group.markup && isNewRuleTarget(group.target));
|
|
298
|
+
const notes = [style ? KEEP_APPROACH : null, added ? NEW_RULE_NOTE : null, markup ? RERENDER_NOTE : null].filter((one) => one !== null);
|
|
299
|
+
return [markup ? CHANGES_HEAD : PROMPT_HEAD, "", parts.join(`
|
|
300
|
+
|
|
301
|
+
`), "", ...notes].join(`
|
|
302
|
+
`);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/ui/changes.ts
|
|
306
|
+
var COPIED = "copied";
|
|
307
|
+
var NOT_COPIED = "could not copy";
|
|
308
|
+
var COPIED_FOR = 1200;
|
|
309
|
+
var AGENT_NOTE = "agents read and apply edits: devknobs.edits() / setEdits()";
|
|
310
|
+
function keptLine(kept, missed) {
|
|
311
|
+
const made = `${kept} ${kept === 1 ? "edit" : "edits"} kept from before the reload`;
|
|
312
|
+
return missed > 0 ? `${made}, ${missed} could not be found` : made;
|
|
313
|
+
}
|
|
314
|
+
function waitLine(html, attributes, more) {
|
|
315
|
+
const parts = [];
|
|
316
|
+
if (html > 0)
|
|
317
|
+
parts.push(`${html} kept html ${html === 1 ? "edit" : "edits"}`);
|
|
318
|
+
if (attributes > 0)
|
|
319
|
+
parts.push(`${attributes} kept attribute ${attributes === 1 ? "edit" : "edits"}`);
|
|
320
|
+
const said2 = `${parts.join(" and ")} ${html + attributes === 1 ? "waits" : "wait"}`;
|
|
321
|
+
return more > 0 ? `${said2}, with ${more} ${more === 1 ? "edit" : "edits"} after them` : said2;
|
|
322
|
+
}
|
|
323
|
+
var WAIT_NOTE = "apply only edits you made on this page";
|
|
324
|
+
var WAIT_MAX = 120;
|
|
325
|
+
function waitText(edit) {
|
|
326
|
+
return edit.after === null ? "(removed)" : edit.kind === "attr" ? `${edit.property}="${edit.after}"` : edit.after;
|
|
327
|
+
}
|
|
328
|
+
function waitCut(edit) {
|
|
329
|
+
return [...waitText(edit)].length > WAIT_MAX;
|
|
330
|
+
}
|
|
331
|
+
function waitValue(edit, full = false) {
|
|
332
|
+
const text = waitText(edit);
|
|
333
|
+
return data(!full && waitCut(edit) ? `${[...text].slice(0, WAIT_MAX - 1).join("")}…` : text);
|
|
334
|
+
}
|
|
335
|
+
function editLine(value) {
|
|
336
|
+
const edit = readSavedEdit(value);
|
|
337
|
+
if (!edit)
|
|
338
|
+
return null;
|
|
339
|
+
const what = edit.kind === edit.property || edit.kind.startsWith("css-") || edit.kind === "attr" ? data(edit.property) : edit.kind;
|
|
340
|
+
return `${what} on ${data(edit.target.selector)}`;
|
|
341
|
+
}
|
|
342
|
+
function missedLine(skipped) {
|
|
343
|
+
const line = editLine(skipped.edit);
|
|
344
|
+
return line ? `${line}: ${skipped.reason}` : skipped.reason;
|
|
345
|
+
}
|
|
346
|
+
var made = 0;
|
|
347
|
+
function undoHint(mac) {
|
|
348
|
+
const undo = comboLabel({ meta: false, ctrl: false, shift: false, alt: false, key: "z" }, mac);
|
|
349
|
+
return `undo ${undo}, redo ${comboLabel(withShift("z"), mac)}`;
|
|
350
|
+
}
|
|
351
|
+
function createChanges(log, copy, mac = isMac(), keep = null, diffShown = null) {
|
|
352
|
+
const node = el("section", "changes");
|
|
353
|
+
node.setAttribute("aria-label", "changes");
|
|
354
|
+
const head = el("div", "changes-head");
|
|
355
|
+
const fold = button("changes-toggle", "");
|
|
356
|
+
let open = diffShown?.get() ?? false;
|
|
357
|
+
const keys = el("span", "", ` · ${undoHint(mac)}`);
|
|
358
|
+
head.append(fold, keys);
|
|
359
|
+
const kept = el("div", "changes-kept");
|
|
360
|
+
const apply = button("chip changes-apply", "apply");
|
|
361
|
+
const shownWhole = new WeakSet;
|
|
362
|
+
let shows = [];
|
|
363
|
+
apply.addEventListener("click", (event) => {
|
|
364
|
+
if (event.isTrusted && event.currentTarget === apply && !apply.disabled)
|
|
365
|
+
keep?.applyWaiting();
|
|
366
|
+
});
|
|
367
|
+
const list = el("div", "changes-list");
|
|
368
|
+
list.id = `devknobs-changes-${++made}`;
|
|
369
|
+
fold.setAttribute("aria-controls", list.id);
|
|
370
|
+
fold.addEventListener("click", () => {
|
|
371
|
+
open = !open;
|
|
372
|
+
diffShown?.set(open);
|
|
373
|
+
draw();
|
|
374
|
+
});
|
|
375
|
+
const prompt = button("chip changes-go", "copy prompt for agent");
|
|
376
|
+
const diff = button("chip", "copy diff");
|
|
377
|
+
const undoAll = button("chip", "undo all");
|
|
378
|
+
const acts = el("div", "changes-acts");
|
|
379
|
+
acts.append(prompt, diff, undoAll);
|
|
380
|
+
node.append(head, kept, list, acts, el("div", "changes-note", AGENT_NOTE));
|
|
381
|
+
const timers = new Map;
|
|
382
|
+
const labels = new Map;
|
|
383
|
+
let gone = false;
|
|
384
|
+
async function copied(control, text) {
|
|
385
|
+
if (text === "")
|
|
386
|
+
return;
|
|
387
|
+
const label2 = labels.get(control) ?? control.textContent ?? "";
|
|
388
|
+
labels.set(control, label2);
|
|
389
|
+
let went = false;
|
|
390
|
+
try {
|
|
391
|
+
went = await copy(text);
|
|
392
|
+
} catch {
|
|
393
|
+
went = false;
|
|
394
|
+
}
|
|
395
|
+
if (gone)
|
|
396
|
+
return;
|
|
397
|
+
control.textContent = went ? COPIED : NOT_COPIED;
|
|
398
|
+
clearTimeout(timers.get(control));
|
|
399
|
+
timers.set(control, window.setTimeout(() => {
|
|
400
|
+
control.textContent = label2;
|
|
401
|
+
}, COPIED_FOR));
|
|
402
|
+
}
|
|
403
|
+
prompt.addEventListener("click", () => void copied(prompt, promptText(log.list())));
|
|
404
|
+
diff.addEventListener("click", () => void copied(diff, diffText(log.list())));
|
|
405
|
+
undoAll.addEventListener("click", () => log.undoAll());
|
|
406
|
+
function draw() {
|
|
407
|
+
const edits2 = log.list();
|
|
408
|
+
const count = changeCount(edits2);
|
|
409
|
+
const restored = keep?.restored() ?? null;
|
|
410
|
+
const cut = keep?.cut() ?? 0;
|
|
411
|
+
const said2 = [];
|
|
412
|
+
if (restored && (restored.kept > 0 || restored.missed.length > 0)) {
|
|
413
|
+
said2.push(el("div", "changes-kept-line", keptLine(restored.kept, restored.missed.length)));
|
|
414
|
+
for (const one of restored.missed)
|
|
415
|
+
said2.push(el("div", "changes-missed", missedLine(one)));
|
|
416
|
+
}
|
|
417
|
+
const waiting = keep?.waiting() ?? [];
|
|
418
|
+
shows = [];
|
|
419
|
+
if (waiting.length > 0) {
|
|
420
|
+
const html = waiting.filter((one) => one.kind === "html").length;
|
|
421
|
+
const attributes = waiting.filter((one) => one.kind === "attr").length;
|
|
422
|
+
const head2 = el("div", "changes-kept-line changes-wait", `${waitLine(html, attributes, waiting.length - html - attributes)}: `);
|
|
423
|
+
head2.append(apply);
|
|
424
|
+
said2.push(head2, el("div", "changes-kept-line changes-wait-note", WAIT_NOTE));
|
|
425
|
+
for (const one of waiting) {
|
|
426
|
+
const line = el("div", "changes-missed", `${editLine(one) ?? ""}: ${waitValue(one, shownWhole.has(one))}`);
|
|
427
|
+
if (waitCut(one) && !shownWhole.has(one)) {
|
|
428
|
+
const more = button("chip changes-show", "show all");
|
|
429
|
+
more.addEventListener("click", () => {
|
|
430
|
+
shownWhole.add(one);
|
|
431
|
+
draw();
|
|
432
|
+
const next = shows[0];
|
|
433
|
+
if (next)
|
|
434
|
+
next.focus({ preventScroll: true });
|
|
435
|
+
else if (!apply.disabled)
|
|
436
|
+
apply.focus({ preventScroll: true });
|
|
437
|
+
});
|
|
438
|
+
line.append(" ", more);
|
|
439
|
+
shows.push(more);
|
|
440
|
+
}
|
|
441
|
+
said2.push(line);
|
|
442
|
+
}
|
|
443
|
+
apply.disabled = waiting.some((one) => waitCut(one) && !shownWhole.has(one));
|
|
444
|
+
apply.title = apply.disabled ? "show each edit whole first" : "";
|
|
445
|
+
}
|
|
446
|
+
if (cut > 0)
|
|
447
|
+
said2.push(el("div", "changes-kept-line", `only the first ${keep?.kept() ?? 0} edits are kept after a reload`));
|
|
448
|
+
kept.replaceChildren(...said2);
|
|
449
|
+
kept.hidden = said2.length === 0;
|
|
450
|
+
node.hidden = count === 0 && said2.length === 0;
|
|
451
|
+
fold.textContent = `changes (${count})`;
|
|
452
|
+
fold.setAttribute("aria-expanded", String(open));
|
|
453
|
+
list.hidden = !open;
|
|
454
|
+
const lines = [];
|
|
455
|
+
for (const group of netChanges(edits2)) {
|
|
456
|
+
lines.push(el("div", "diff-place", placeLine(group.target, group.markup)));
|
|
457
|
+
for (const change of group.changes) {
|
|
458
|
+
for (const text of diffLines(change))
|
|
459
|
+
lines.push(el("div", text.startsWith("-") ? "diff-del" : "diff-add", text));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
list.replaceChildren(...lines);
|
|
463
|
+
}
|
|
464
|
+
const stop = log.subscribe(draw);
|
|
465
|
+
const stopKeep = keep?.subscribe(draw) ?? null;
|
|
466
|
+
draw();
|
|
467
|
+
return {
|
|
468
|
+
node,
|
|
469
|
+
destroy() {
|
|
470
|
+
gone = true;
|
|
471
|
+
stop();
|
|
472
|
+
stopKeep?.();
|
|
473
|
+
for (const timer of timers.values())
|
|
474
|
+
clearTimeout(timer);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// src/edit/source.ts
|
|
480
|
+
var found = new WeakMap;
|
|
481
|
+
var locateSource = (element) => {
|
|
482
|
+
let pending = found.get(element);
|
|
483
|
+
if (!pending) {
|
|
484
|
+
pending = import("./context-amfyasb5.js").then(({ grabEntry }) => grabEntry(element)).then(({ source }) => {
|
|
485
|
+
if (!source || source.origin !== "app")
|
|
486
|
+
return null;
|
|
487
|
+
return source.lineNumber ? `${source.filePath}:${source.lineNumber}` : source.filePath;
|
|
488
|
+
}).catch(() => null);
|
|
489
|
+
found.set(element, pending);
|
|
490
|
+
const own = pending;
|
|
491
|
+
own.then((source) => {
|
|
492
|
+
if (source === null && found.get(element) === own)
|
|
493
|
+
found.delete(element);
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
return pending;
|
|
497
|
+
};
|
|
498
|
+
function recordAt(log, change, element, locate = locateSource) {
|
|
499
|
+
const edit = log.record(change);
|
|
500
|
+
if (!edit)
|
|
501
|
+
return null;
|
|
502
|
+
locate(element).then((source) => {
|
|
503
|
+
if (source)
|
|
504
|
+
log.locate(edit.id, { source });
|
|
505
|
+
});
|
|
506
|
+
return edit;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// src/ui/cssauto.ts
|
|
510
|
+
var GLOBAL_KEYWORDS = ["inherit", "initial", "unset", "revert", "revert-layer"];
|
|
511
|
+
var KEYWORDS = ("auto none normal 0 100% block inline inline-block flex inline-flex grid inline-grid contents flow-root table " + "table-row table-cell list-item static relative absolute fixed sticky visible hidden clip scroll row row-reverse " + "column column-reverse wrap nowrap wrap-reverse start end center flex-start flex-end self-start self-end left right " + "top bottom middle space-between space-around space-evenly stretch baseline justify uppercase lowercase capitalize " + "underline overline line-through italic oblique bold bolder lighter pre pre-wrap pre-line break-spaces break-all " + "keep-all break-word anywhere pointer default text move grab grabbing not-allowed wait help crosshair solid dashed " + "dotted double groove ridge inset outset border-box content-box padding-box cover contain fill scale-down repeat " + "no-repeat repeat-x repeat-y round ease ease-in ease-out ease-in-out linear step-start step-end infinite alternate " + "reverse forwards backwards both running paused fit-content min-content max-content sub super text-top text-bottom " + "collapse separate ltr rtl horizontal-tb vertical-rl vertical-lr isolate multiply screen overlay darken lighten " + "difference exclusion disc circle square decimal outside inside ellipsis dense smooth thin medium thick small large " + "x-small x-large smaller larger light dark all manual").split(" ");
|
|
512
|
+
var NAMED_KEYWORDS = {
|
|
513
|
+
"font-family": ["system-ui", "sans-serif", "serif", "monospace", "ui-monospace", "ui-sans-serif", "ui-serif", "cursive", "fantasy"],
|
|
514
|
+
"transition-property": ["all", "none", "opacity", "transform", "color", "background-color"],
|
|
515
|
+
"will-change": ["auto", "transform", "opacity", "scroll-position", "contents"],
|
|
516
|
+
"animation-name": ["none"],
|
|
517
|
+
"grid-area": ["auto"],
|
|
518
|
+
"grid-template-areas": ["none"],
|
|
519
|
+
"counter-reset": ["none"],
|
|
520
|
+
"counter-increment": ["none"],
|
|
521
|
+
"view-transition-name": ["none"],
|
|
522
|
+
"container-name": ["none"],
|
|
523
|
+
"list-style-type": ["none", "disc", "circle", "square", "decimal"]
|
|
524
|
+
};
|
|
525
|
+
var NAMED_COLORS = ("currentcolor transparent aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue " + "blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue " + "darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid " + "darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink " + "deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold " + "goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush " + "lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey " + "lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime " + "limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen " + "mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin " + "navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise " + "palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue " + "saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow " + "springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen").split(" ");
|
|
526
|
+
var MOST = 50;
|
|
527
|
+
function cssName(key) {
|
|
528
|
+
if (key.includes("-"))
|
|
529
|
+
return key;
|
|
530
|
+
const dashed = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
531
|
+
return /^(webkit|moz|ms)-/.test(dashed) ? `-${dashed}` : dashed;
|
|
532
|
+
}
|
|
533
|
+
function propertyNames(style, supports) {
|
|
534
|
+
const found2 = new Set;
|
|
535
|
+
for (const key in style)
|
|
536
|
+
if (!/^\d/.test(key))
|
|
537
|
+
found2.add(cssName(key));
|
|
538
|
+
const listed2 = Reflect.get(style, "length");
|
|
539
|
+
for (let at = 0;typeof listed2 === "number" && at < listed2; at++) {
|
|
540
|
+
const name = Reflect.get(style, at);
|
|
541
|
+
if (typeof name === "string" && !name.startsWith("--"))
|
|
542
|
+
found2.add(name);
|
|
543
|
+
}
|
|
544
|
+
const names = [...found2].filter((name) => !name.startsWith("--") && supports(name, "inherit"));
|
|
545
|
+
const plain = names.filter((name) => !name.startsWith("-")).sort();
|
|
546
|
+
return [...plain, ...names.filter((name) => name.startsWith("-")).sort()];
|
|
547
|
+
}
|
|
548
|
+
var RULES_READ = 5000;
|
|
549
|
+
function customsIn(sheets, more = []) {
|
|
550
|
+
const found2 = new Set(more.filter((name) => name.startsWith("--")));
|
|
551
|
+
let read = 0;
|
|
552
|
+
const walk = (rules) => {
|
|
553
|
+
for (let at = 0;rules && at < rules.length && read < RULES_READ; at++) {
|
|
554
|
+
const rule = rules[at];
|
|
555
|
+
read++;
|
|
556
|
+
const style = rule?.style;
|
|
557
|
+
for (let one = 0;style && one < style.length; one++) {
|
|
558
|
+
const name = style[one];
|
|
559
|
+
if (name?.startsWith("--"))
|
|
560
|
+
found2.add(name);
|
|
561
|
+
}
|
|
562
|
+
walk(rule?.cssRules);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
for (let at = 0;at < sheets.length; at++) {
|
|
566
|
+
try {
|
|
567
|
+
walk(sheets[at]?.cssRules);
|
|
568
|
+
} catch {}
|
|
569
|
+
}
|
|
570
|
+
return [...found2];
|
|
571
|
+
}
|
|
572
|
+
function browserCss(element) {
|
|
573
|
+
const view = element.ownerDocument?.defaultView ?? null;
|
|
574
|
+
const css = view?.CSS ?? null;
|
|
575
|
+
const supports = (property, value) => {
|
|
576
|
+
try {
|
|
577
|
+
return css !== null && css.supports(property, value);
|
|
578
|
+
} catch {
|
|
579
|
+
return false;
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
let customs = null;
|
|
583
|
+
return {
|
|
584
|
+
supports,
|
|
585
|
+
properties() {
|
|
586
|
+
try {
|
|
587
|
+
const doc = element.ownerDocument;
|
|
588
|
+
const cached = KNOWN.get(doc);
|
|
589
|
+
if (cached)
|
|
590
|
+
return cached;
|
|
591
|
+
const names = view ? propertyNames(view.getComputedStyle(doc.documentElement), supports) : [];
|
|
592
|
+
KNOWN.set(doc, names);
|
|
593
|
+
return names;
|
|
594
|
+
} catch {
|
|
595
|
+
return [];
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
customs() {
|
|
599
|
+
if (customs)
|
|
600
|
+
return customs;
|
|
601
|
+
try {
|
|
602
|
+
const computed = view?.getComputedStyle(element);
|
|
603
|
+
const seen = [];
|
|
604
|
+
for (let at = 0;computed && at < computed.length; at++)
|
|
605
|
+
seen.push(computed[at] ?? "");
|
|
606
|
+
customs = customsIn(element.ownerDocument.styleSheets, seen);
|
|
607
|
+
} catch {
|
|
608
|
+
customs = [];
|
|
609
|
+
}
|
|
610
|
+
return customs;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
var KNOWN = new WeakMap;
|
|
615
|
+
function nameSuggestions(world) {
|
|
616
|
+
return [...world.properties(), ...world.customs()];
|
|
617
|
+
}
|
|
618
|
+
var ANY_WORD = "devknobs-any-word";
|
|
619
|
+
function valueSuggestions(property, world) {
|
|
620
|
+
const name = property.trim().toLowerCase();
|
|
621
|
+
const vars = world.customs().map((custom) => `var(${custom})`);
|
|
622
|
+
if (name.startsWith("--"))
|
|
623
|
+
return [...vars, ...GLOBAL_KEYWORDS];
|
|
624
|
+
if (!world.supports(name, "inherit"))
|
|
625
|
+
return [];
|
|
626
|
+
const anyWord = world.supports(name, ANY_WORD);
|
|
627
|
+
const own = NAMED_KEYWORDS[name] ?? [];
|
|
628
|
+
const keywords = anyWord ? own : [...new Set([...KEYWORDS, ...own])].filter((word) => world.supports(name, word)).sort();
|
|
629
|
+
const colors = !anyWord && world.supports(name, "red") ? NAMED_COLORS : [];
|
|
630
|
+
return [...new Set([...keywords, ...colors, ...vars, ...GLOBAL_KEYWORDS])];
|
|
631
|
+
}
|
|
632
|
+
function matching(items, typed, most = MOST) {
|
|
633
|
+
const word = typed.toLowerCase();
|
|
634
|
+
const starts = [];
|
|
635
|
+
const holds = [];
|
|
636
|
+
for (const item of items) {
|
|
637
|
+
const lower = item.toLowerCase();
|
|
638
|
+
if (lower.startsWith(word))
|
|
639
|
+
starts.push(item);
|
|
640
|
+
else if (word !== "" && lower.includes(word))
|
|
641
|
+
holds.push(item);
|
|
642
|
+
}
|
|
643
|
+
return word === "" ? starts : [...starts, ...holds].slice(0, most);
|
|
644
|
+
}
|
|
645
|
+
function wordAt(text, caret) {
|
|
646
|
+
let start = caret;
|
|
647
|
+
while (start > 0 && !/[\s,/(]/.test(text[start - 1] ?? ""))
|
|
648
|
+
start--;
|
|
649
|
+
let end = caret;
|
|
650
|
+
while (end < text.length && !/[\s,/()]/.test(text[end] ?? ""))
|
|
651
|
+
end++;
|
|
652
|
+
return { start, end, word: text.slice(start, caret) };
|
|
653
|
+
}
|
|
654
|
+
function completes(word, suggestion) {
|
|
655
|
+
if (word === "" || /^(\d|\.|-\d|#)/.test(word))
|
|
656
|
+
return false;
|
|
657
|
+
const typed = word.toLowerCase();
|
|
658
|
+
const lower = suggestion.toLowerCase();
|
|
659
|
+
return lower.startsWith(typed) || lower.startsWith(`var(${typed}`);
|
|
660
|
+
}
|
|
661
|
+
function listKey(event, open, count, at) {
|
|
662
|
+
if (event.metaKey || event.ctrlKey || event.altKey)
|
|
663
|
+
return null;
|
|
664
|
+
if (!open)
|
|
665
|
+
return event.key === "ArrowDown" && !event.shiftKey ? { act: "move", to: -1 } : null;
|
|
666
|
+
if (event.key === "ArrowDown")
|
|
667
|
+
return { act: "move", to: (at + 1) % count };
|
|
668
|
+
if (event.key === "ArrowUp")
|
|
669
|
+
return { act: "move", to: at <= 0 ? count - 1 : at - 1 };
|
|
670
|
+
if (event.key === "Escape")
|
|
671
|
+
return { act: "close" };
|
|
672
|
+
if (event.key === "Enter")
|
|
673
|
+
return { act: "take" };
|
|
674
|
+
if (event.key === "Tab")
|
|
675
|
+
return event.shiftKey ? { act: "close" } : { act: "take" };
|
|
676
|
+
return null;
|
|
677
|
+
}
|
|
678
|
+
var made2 = 0;
|
|
679
|
+
function autocomplete(input, items, kind) {
|
|
680
|
+
const list = el("div", "ac-list");
|
|
681
|
+
const id = `devknobs-ac-${++made2}`;
|
|
682
|
+
list.id = id;
|
|
683
|
+
list.setAttribute("role", "listbox");
|
|
684
|
+
list.setAttribute("aria-label", kind === "name" ? "properties" : "values");
|
|
685
|
+
input.setAttribute("role", "combobox");
|
|
686
|
+
input.setAttribute("aria-autocomplete", "list");
|
|
687
|
+
input.setAttribute("aria-expanded", "false");
|
|
688
|
+
input.setAttribute("aria-controls", id);
|
|
689
|
+
let all = null;
|
|
690
|
+
let shown = [];
|
|
691
|
+
let at = -1;
|
|
692
|
+
let options = [];
|
|
693
|
+
let ate = false;
|
|
694
|
+
function place() {
|
|
695
|
+
const text = input.value;
|
|
696
|
+
if (kind === "name")
|
|
697
|
+
return { start: 0, end: text.length, word: text.trim() };
|
|
698
|
+
const from = input.selectionStart ?? text.length;
|
|
699
|
+
const to = input.selectionEnd ?? from;
|
|
700
|
+
if (to > from)
|
|
701
|
+
return { start: from, end: to, word: "" };
|
|
702
|
+
return wordAt(text, from);
|
|
703
|
+
}
|
|
704
|
+
function mark(to) {
|
|
705
|
+
at = to;
|
|
706
|
+
options.forEach((option, index) => option.setAttribute("aria-selected", String(index === at)));
|
|
707
|
+
const on = options[at];
|
|
708
|
+
if (!on) {
|
|
709
|
+
input.removeAttribute?.("aria-activedescendant");
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
input.setAttribute("aria-activedescendant", on.id);
|
|
713
|
+
on.scrollIntoView?.({ block: "nearest" });
|
|
714
|
+
}
|
|
715
|
+
function close() {
|
|
716
|
+
shown = [];
|
|
717
|
+
options = [];
|
|
718
|
+
list.replaceChildren();
|
|
719
|
+
list.remove();
|
|
720
|
+
input.setAttribute("aria-expanded", "false");
|
|
721
|
+
input.removeAttribute?.("aria-activedescendant");
|
|
722
|
+
}
|
|
723
|
+
function take(value) {
|
|
724
|
+
let { start, end } = place();
|
|
725
|
+
const text = input.value;
|
|
726
|
+
if (value.startsWith("var(") && text.slice(0, start).endsWith("var("))
|
|
727
|
+
start -= 4;
|
|
728
|
+
if (value.startsWith("var(") && text[end] === ")")
|
|
729
|
+
end++;
|
|
730
|
+
input.value = `${text.slice(0, start)}${value}${text.slice(end)}`;
|
|
731
|
+
const caret = start + value.length;
|
|
732
|
+
input.setSelectionRange?.(caret, caret);
|
|
733
|
+
close();
|
|
734
|
+
input.dispatchEvent?.(new Event("input"));
|
|
735
|
+
}
|
|
736
|
+
function update() {
|
|
737
|
+
all ??= items();
|
|
738
|
+
const { word } = place();
|
|
739
|
+
const found2 = matching(all, word);
|
|
740
|
+
if (found2.length === 0 || found2.length === 1 && found2[0] === word) {
|
|
741
|
+
close();
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
shown = found2;
|
|
745
|
+
options = found2.map((value, index) => {
|
|
746
|
+
const option = el("div", "ac-item", value);
|
|
747
|
+
option.id = `${id}-${index}`;
|
|
748
|
+
option.setAttribute("role", "option");
|
|
749
|
+
return option;
|
|
750
|
+
});
|
|
751
|
+
list.replaceChildren(...options);
|
|
752
|
+
if (!list.parentNode)
|
|
753
|
+
input.parentNode?.append(list);
|
|
754
|
+
const room = list.parentNode?.clientWidth;
|
|
755
|
+
const left = input.offsetLeft ?? 0;
|
|
756
|
+
list.style.left = `${typeof room === "number" && room > 0 ? Math.max(0, Math.min(left, room - (list.offsetWidth ?? 0))) : left}px`;
|
|
757
|
+
list.style.top = `${(input.offsetTop ?? 0) + (input.offsetHeight ?? 0)}px`;
|
|
758
|
+
input.setAttribute("aria-expanded", "true");
|
|
759
|
+
mark(-1);
|
|
760
|
+
}
|
|
761
|
+
list.addEventListener("mousedown", (event) => event.preventDefault());
|
|
762
|
+
list.addEventListener("click", (event) => {
|
|
763
|
+
const option = event.target?.closest?.(".ac-item");
|
|
764
|
+
const value = shown[options.indexOf(option)];
|
|
765
|
+
if (value === undefined)
|
|
766
|
+
return;
|
|
767
|
+
take(value);
|
|
768
|
+
input.focus({ preventScroll: true });
|
|
769
|
+
});
|
|
770
|
+
input.addEventListener("input", (event) => {
|
|
771
|
+
if (event.isTrusted === false && shown.length === 0)
|
|
772
|
+
return;
|
|
773
|
+
update();
|
|
774
|
+
});
|
|
775
|
+
input.addEventListener("blur", close);
|
|
776
|
+
input.addEventListener("focus", () => {
|
|
777
|
+
all = null;
|
|
778
|
+
if (input.value !== "")
|
|
779
|
+
return;
|
|
780
|
+
update();
|
|
781
|
+
});
|
|
782
|
+
return {
|
|
783
|
+
key(event) {
|
|
784
|
+
if (event.isComposing)
|
|
785
|
+
return false;
|
|
786
|
+
if (event.key === "Escape" && ate) {
|
|
787
|
+
ate = false;
|
|
788
|
+
event.preventDefault();
|
|
789
|
+
return true;
|
|
790
|
+
}
|
|
791
|
+
const what = listKey(event, shown.length > 0, shown.length, at);
|
|
792
|
+
if (!what)
|
|
793
|
+
return false;
|
|
794
|
+
if (what.act === "take") {
|
|
795
|
+
const { word } = place();
|
|
796
|
+
const first = shown[0];
|
|
797
|
+
const value = at >= 0 ? shown[at] : first !== undefined && completes(word, first) ? first : undefined;
|
|
798
|
+
if (value !== undefined && value !== word)
|
|
799
|
+
take(value);
|
|
800
|
+
else
|
|
801
|
+
close();
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
if (event.key !== "Tab")
|
|
805
|
+
event.preventDefault();
|
|
806
|
+
if (what.act === "close")
|
|
807
|
+
close();
|
|
808
|
+
else if (shown.length === 0) {
|
|
809
|
+
update();
|
|
810
|
+
if (shown.length > 0)
|
|
811
|
+
mark(0);
|
|
812
|
+
} else
|
|
813
|
+
mark(what.to);
|
|
814
|
+
return what.act !== "close" || event.key === "Escape";
|
|
815
|
+
},
|
|
816
|
+
open: () => shown.length > 0,
|
|
817
|
+
close,
|
|
818
|
+
dismiss() {
|
|
819
|
+
if (shown.length === 0)
|
|
820
|
+
return false;
|
|
821
|
+
close();
|
|
822
|
+
ate = true;
|
|
823
|
+
setTimeout(() => {
|
|
824
|
+
ate = false;
|
|
825
|
+
}, 0);
|
|
826
|
+
return true;
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// src/ui/cssedit.ts
|
|
832
|
+
var ADD = "+ add property";
|
|
833
|
+
var NEW_RULE = "+ new rule";
|
|
834
|
+
var HOLD = 1000;
|
|
835
|
+
function hasStyle(element) {
|
|
836
|
+
return "style" in element;
|
|
837
|
+
}
|
|
838
|
+
function styleOf(element) {
|
|
839
|
+
return hasStyle(element) ? element.style : null;
|
|
840
|
+
}
|
|
841
|
+
function offDeclaration(off) {
|
|
842
|
+
const important = /\s*!\s*important\s*$/i;
|
|
843
|
+
return {
|
|
844
|
+
name: off.property,
|
|
845
|
+
value: off.text.replace(important, ""),
|
|
846
|
+
important: important.test(off.text),
|
|
847
|
+
longhands: [off.property],
|
|
848
|
+
overridden: true,
|
|
849
|
+
variables: []
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
function toggleLabel(property, on) {
|
|
853
|
+
return `turn ${on ? "off" : "on"} ${property}`;
|
|
854
|
+
}
|
|
855
|
+
function selectorOf(element) {
|
|
856
|
+
try {
|
|
857
|
+
return elementSelector(element).selector;
|
|
858
|
+
} catch {
|
|
859
|
+
return element.tagName.toLowerCase();
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function fitField(area) {
|
|
863
|
+
const longest = Math.max(...area.value.split(`
|
|
864
|
+
`).map((line) => line.length));
|
|
865
|
+
area.style.width = `min(${Math.max(longest + 1, 3)}ch, 100%)`;
|
|
866
|
+
area.style.height = "auto";
|
|
867
|
+
const tall = Number(area.scrollHeight) || 0;
|
|
868
|
+
if (tall > 0)
|
|
869
|
+
area.style.height = `${tall}px`;
|
|
870
|
+
}
|
|
871
|
+
function editField(value, label2) {
|
|
872
|
+
const input = document.createElement("textarea");
|
|
873
|
+
input.className = "css-edit inline-field";
|
|
874
|
+
input.value = value;
|
|
875
|
+
input.rows = 1;
|
|
876
|
+
input.spellcheck = false;
|
|
877
|
+
input.autocomplete = "off";
|
|
878
|
+
input.setAttribute("aria-label", label2);
|
|
879
|
+
input.addEventListener("input", () => {
|
|
880
|
+
if (/[\r\n]/.test(input.value)) {
|
|
881
|
+
const caret = input.value.slice(0, input.selectionStart ?? input.value.length).replace(/[\r\n]/g, "").length;
|
|
882
|
+
input.value = input.value.replace(/[\r\n]/g, "");
|
|
883
|
+
input.setSelectionRange(caret, caret);
|
|
884
|
+
}
|
|
885
|
+
fitField(input);
|
|
886
|
+
});
|
|
887
|
+
input.addEventListener("focus", () => fitField(input));
|
|
888
|
+
fitField(input);
|
|
889
|
+
return input;
|
|
890
|
+
}
|
|
891
|
+
function escaped(element, name) {
|
|
892
|
+
try {
|
|
893
|
+
const css = element.ownerDocument?.defaultView?.CSS ?? globalThis.CSS;
|
|
894
|
+
if (css && typeof css.escape === "function")
|
|
895
|
+
return css.escape(name);
|
|
896
|
+
} catch {}
|
|
897
|
+
return name;
|
|
898
|
+
}
|
|
899
|
+
function newRuleSelector(element, states = []) {
|
|
900
|
+
const classes = (element.getAttribute("class") ?? "").split(/\s+/).filter(Boolean);
|
|
901
|
+
let base = classes.map((name) => `.${escaped(element, name)}`).join("");
|
|
902
|
+
if (base === "")
|
|
903
|
+
base = selectorOf(element).split(/>>>|>>iframe>>/).pop()?.trim() || element.tagName.toLowerCase();
|
|
904
|
+
return `${base}${states.map((state) => `:${state}`).join("")}`;
|
|
905
|
+
}
|
|
906
|
+
function shows(node) {
|
|
907
|
+
if (!node.isConnected)
|
|
908
|
+
return false;
|
|
909
|
+
for (let at = node;at; at = at.parentElement)
|
|
910
|
+
if (at.hidden)
|
|
911
|
+
return false;
|
|
912
|
+
return true;
|
|
913
|
+
}
|
|
914
|
+
function inButton(target) {
|
|
915
|
+
const closest = target ? Reflect.get(target, "closest") : null;
|
|
916
|
+
return typeof closest === "function" && Reflect.apply(closest, target, ["button"]) !== null;
|
|
917
|
+
}
|
|
918
|
+
function createCssEditor(context) {
|
|
919
|
+
const { log, node } = context;
|
|
920
|
+
let fields = [];
|
|
921
|
+
let open = null;
|
|
922
|
+
let lists = [];
|
|
923
|
+
let holding = false;
|
|
924
|
+
let holdTimer = 0;
|
|
925
|
+
let opening = null;
|
|
926
|
+
function release() {
|
|
927
|
+
if (!holding)
|
|
928
|
+
return;
|
|
929
|
+
holding = false;
|
|
930
|
+
clearTimeout(holdTimer);
|
|
931
|
+
window.removeEventListener("pointerup", onUp, true);
|
|
932
|
+
if (!open)
|
|
933
|
+
context.settled();
|
|
934
|
+
}
|
|
935
|
+
function onUp() {
|
|
936
|
+
window.removeEventListener("pointerup", onUp, true);
|
|
937
|
+
window.setTimeout(release, 0);
|
|
938
|
+
}
|
|
939
|
+
function hold() {
|
|
940
|
+
holding = true;
|
|
941
|
+
clearTimeout(holdTimer);
|
|
942
|
+
holdTimer = window.setTimeout(release, HOLD);
|
|
943
|
+
window.addEventListener("pointerup", onUp, true);
|
|
944
|
+
}
|
|
945
|
+
function closed() {
|
|
946
|
+
open = null;
|
|
947
|
+
if (!holding)
|
|
948
|
+
context.settled();
|
|
949
|
+
}
|
|
950
|
+
function record(change, place) {
|
|
951
|
+
return change === null || recordAt(log, change, place.element, context.locate) !== null;
|
|
952
|
+
}
|
|
953
|
+
function full(place) {
|
|
954
|
+
return { ...place, selector: selectorOf(place.element) };
|
|
955
|
+
}
|
|
956
|
+
function fieldAt(style, property) {
|
|
957
|
+
return fields.find((one) => one.place.style === style && one.property === property);
|
|
958
|
+
}
|
|
959
|
+
function openValue(field) {
|
|
960
|
+
open?.close(true);
|
|
961
|
+
if (!field.value.isConnected)
|
|
962
|
+
return;
|
|
963
|
+
const input = editField(field.text, `value of ${field.property}`);
|
|
964
|
+
const world = browserCss(field.place.element);
|
|
965
|
+
const auto = autocomplete(input, () => valueSuggestions(field.property, world), "value");
|
|
966
|
+
lists = [auto];
|
|
967
|
+
field.value.replaceWith(input);
|
|
968
|
+
let shown = true;
|
|
969
|
+
const close = (commit, next, away = false) => {
|
|
970
|
+
if (!shown)
|
|
971
|
+
return;
|
|
972
|
+
shown = false;
|
|
973
|
+
auto.close();
|
|
974
|
+
open = null;
|
|
975
|
+
if (away)
|
|
976
|
+
hold();
|
|
977
|
+
const text = input.value;
|
|
978
|
+
const same = text.trim() === field.text;
|
|
979
|
+
const took = !commit || same || text.trim() !== "" && record(cssValue("css-value", full(field.place), field.property, text), field.place);
|
|
980
|
+
if (!took && !away) {
|
|
981
|
+
shown = true;
|
|
982
|
+
open = self;
|
|
983
|
+
input.classList.add("bad");
|
|
984
|
+
input.setAttribute("aria-invalid", "true");
|
|
985
|
+
input.focus({ preventScroll: true });
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (input.isConnected) {
|
|
989
|
+
input.replaceWith(field.value);
|
|
990
|
+
if (took && commit && !same)
|
|
991
|
+
field.value.textContent = text.trim();
|
|
992
|
+
}
|
|
993
|
+
closed();
|
|
994
|
+
const then = next ? fieldAt(next.place.style, next.property) : undefined;
|
|
995
|
+
if (then)
|
|
996
|
+
openValue(then);
|
|
997
|
+
else if (!away)
|
|
998
|
+
node.focus({ preventScroll: true });
|
|
999
|
+
};
|
|
1000
|
+
const self = { close: (commit) => close(commit) };
|
|
1001
|
+
open = self;
|
|
1002
|
+
input.addEventListener("keydown", (event) => {
|
|
1003
|
+
if (event.isComposing || auto.key(event))
|
|
1004
|
+
return;
|
|
1005
|
+
if (event.key === "Enter") {
|
|
1006
|
+
event.preventDefault();
|
|
1007
|
+
close(true);
|
|
1008
|
+
} else if (event.key === "Escape") {
|
|
1009
|
+
event.preventDefault();
|
|
1010
|
+
close(false);
|
|
1011
|
+
} else if (event.key === "Tab") {
|
|
1012
|
+
event.preventDefault();
|
|
1013
|
+
close(true, fields[fields.indexOf(field) + (event.shiftKey ? -1 : 1)]);
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
input.addEventListener("blur", () => close(true, undefined, true));
|
|
1017
|
+
input.focus({ preventScroll: true });
|
|
1018
|
+
input.select();
|
|
1019
|
+
}
|
|
1020
|
+
function toggleBox(place, property, off) {
|
|
1021
|
+
const box = document.createElement("input");
|
|
1022
|
+
box.type = "checkbox";
|
|
1023
|
+
box.className = "css-toggle";
|
|
1024
|
+
box.checked = off === null;
|
|
1025
|
+
const name = () => box.setAttribute("aria-label", toggleLabel(property, box.checked));
|
|
1026
|
+
name();
|
|
1027
|
+
box.addEventListener("change", () => {
|
|
1028
|
+
const change = box.checked && off ? cssOn(full(place), off, log.recorded) : cssOff(full(place), property, log.recorded);
|
|
1029
|
+
if (!record(change, place))
|
|
1030
|
+
box.checked = !box.checked;
|
|
1031
|
+
name();
|
|
1032
|
+
if (!box.isConnected)
|
|
1033
|
+
node.focus({ preventScroll: true });
|
|
1034
|
+
});
|
|
1035
|
+
return box;
|
|
1036
|
+
}
|
|
1037
|
+
function editable(row, value, declaration, place, off) {
|
|
1038
|
+
row.classList.add("can-edit");
|
|
1039
|
+
row.prepend(toggleBox(place, declaration.name, off));
|
|
1040
|
+
if (off) {
|
|
1041
|
+
row.classList.add("off");
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
const field = { place, property: declaration.name, text: valueText(declaration), value };
|
|
1045
|
+
fields.push(field);
|
|
1046
|
+
value.classList.add("css-editable");
|
|
1047
|
+
value.tabIndex = 0;
|
|
1048
|
+
value.setAttribute("role", "button");
|
|
1049
|
+
value.setAttribute("aria-label", `edit ${declaration.name}: ${field.text}`);
|
|
1050
|
+
value.addEventListener("click", (event) => {
|
|
1051
|
+
if (!inButton(event.target))
|
|
1052
|
+
openValue(field);
|
|
1053
|
+
});
|
|
1054
|
+
value.addEventListener("keydown", (event) => {
|
|
1055
|
+
if (event.key !== "Enter" || event.target !== value)
|
|
1056
|
+
return;
|
|
1057
|
+
event.preventDefault();
|
|
1058
|
+
openValue(field);
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function addLine(place) {
|
|
1062
|
+
const control = button("css-add", ADD);
|
|
1063
|
+
control.addEventListener("click", () => openAdd(control, place));
|
|
1064
|
+
if (opening === place.style) {
|
|
1065
|
+
opening = null;
|
|
1066
|
+
queueMicrotask(() => {
|
|
1067
|
+
if (shows(control))
|
|
1068
|
+
openAdd(control, place);
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
return control;
|
|
1072
|
+
}
|
|
1073
|
+
function newRuleLine(element, selector) {
|
|
1074
|
+
const control = button("css-new-rule", NEW_RULE);
|
|
1075
|
+
control.addEventListener("click", () => openNewRule(control, element, selector));
|
|
1076
|
+
return control;
|
|
1077
|
+
}
|
|
1078
|
+
function openNewRule(control, element, selector) {
|
|
1079
|
+
open?.close(true);
|
|
1080
|
+
if (!control.isConnected)
|
|
1081
|
+
return;
|
|
1082
|
+
const row = el("div", "css-decl css-adding css-rule-adding");
|
|
1083
|
+
const field = editField(selector, "selector of the new rule");
|
|
1084
|
+
row.append(field, el("span", "css-punct", " { }"));
|
|
1085
|
+
control.replaceWith(row);
|
|
1086
|
+
let shown = true;
|
|
1087
|
+
const close = (commit, away = false) => {
|
|
1088
|
+
if (!shown)
|
|
1089
|
+
return;
|
|
1090
|
+
shown = false;
|
|
1091
|
+
open = null;
|
|
1092
|
+
if (away)
|
|
1093
|
+
hold();
|
|
1094
|
+
const text = field.value.trim();
|
|
1095
|
+
const tried = commit && text !== "" && !(away && text === selector);
|
|
1096
|
+
const added = tried && addRule(element, text, !away);
|
|
1097
|
+
if (tried && !added && !away) {
|
|
1098
|
+
shown = true;
|
|
1099
|
+
open = self;
|
|
1100
|
+
field.classList.add("bad");
|
|
1101
|
+
field.setAttribute("aria-invalid", "true");
|
|
1102
|
+
field.focus({ preventScroll: true });
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
if (row.isConnected)
|
|
1106
|
+
row.replaceWith(control);
|
|
1107
|
+
closed();
|
|
1108
|
+
if (!away && !added)
|
|
1109
|
+
node.focus({ preventScroll: true });
|
|
1110
|
+
};
|
|
1111
|
+
const self = { close: (commit) => close(commit) };
|
|
1112
|
+
open = self;
|
|
1113
|
+
field.addEventListener("keydown", (event) => {
|
|
1114
|
+
if (event.isComposing)
|
|
1115
|
+
return;
|
|
1116
|
+
if (event.key === "Enter") {
|
|
1117
|
+
event.preventDefault();
|
|
1118
|
+
close(true);
|
|
1119
|
+
} else if (event.key === "Escape") {
|
|
1120
|
+
event.preventDefault();
|
|
1121
|
+
close(false);
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
field.addEventListener("blur", () => close(true, true));
|
|
1125
|
+
field.focus({ preventScroll: true });
|
|
1126
|
+
field.setSelectionRange(field.value.length, field.value.length);
|
|
1127
|
+
}
|
|
1128
|
+
function addRule(element, text, then) {
|
|
1129
|
+
const change = newRule({ element, selector: selectorOf(element) }, text);
|
|
1130
|
+
if (!change)
|
|
1131
|
+
return false;
|
|
1132
|
+
opening = then ? ruleOf(change)?.style ?? null : null;
|
|
1133
|
+
const took = recordAt(log, change, element, context.locate) !== null;
|
|
1134
|
+
if (!took)
|
|
1135
|
+
opening = null;
|
|
1136
|
+
return took;
|
|
1137
|
+
}
|
|
1138
|
+
function openAdd(control, place) {
|
|
1139
|
+
open?.close(true);
|
|
1140
|
+
if (!control.isConnected)
|
|
1141
|
+
return;
|
|
1142
|
+
const row = el("div", "css-decl css-adding");
|
|
1143
|
+
const name = editField("", "property name");
|
|
1144
|
+
const value = editField("", "property value");
|
|
1145
|
+
const world = browserCss(place.element);
|
|
1146
|
+
const names = autocomplete(name, () => nameSuggestions(world), "name");
|
|
1147
|
+
const values = autocomplete(value, () => valueSuggestions(name.value, world), "value");
|
|
1148
|
+
lists = [names, values];
|
|
1149
|
+
row.append(name, el("span", "css-punct", ": "), value, el("span", "css-punct", ";"));
|
|
1150
|
+
control.replaceWith(row);
|
|
1151
|
+
let shown = true;
|
|
1152
|
+
const close = (commit, away = false) => {
|
|
1153
|
+
if (!shown)
|
|
1154
|
+
return;
|
|
1155
|
+
shown = false;
|
|
1156
|
+
names.close();
|
|
1157
|
+
values.close();
|
|
1158
|
+
open = null;
|
|
1159
|
+
if (away)
|
|
1160
|
+
hold();
|
|
1161
|
+
const property = name.value.trim();
|
|
1162
|
+
const tried = commit && property !== "" && value.value.trim() !== "";
|
|
1163
|
+
if (tried && !record(cssValue("css-add", full(place), property, value.value), place) && !away) {
|
|
1164
|
+
shown = true;
|
|
1165
|
+
open = self;
|
|
1166
|
+
value.classList.add("bad");
|
|
1167
|
+
value.setAttribute("aria-invalid", "true");
|
|
1168
|
+
value.focus({ preventScroll: true });
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
if (row.isConnected)
|
|
1172
|
+
row.replaceWith(control);
|
|
1173
|
+
closed();
|
|
1174
|
+
if (!away)
|
|
1175
|
+
node.focus({ preventScroll: true });
|
|
1176
|
+
};
|
|
1177
|
+
const self = { close: (commit) => close(commit) };
|
|
1178
|
+
open = self;
|
|
1179
|
+
name.addEventListener("keydown", (event) => {
|
|
1180
|
+
if (event.isComposing || names.key(event))
|
|
1181
|
+
return;
|
|
1182
|
+
if (event.key === "Escape") {
|
|
1183
|
+
event.preventDefault();
|
|
1184
|
+
close(false);
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
if (event.key !== "Enter" && event.key !== ":" && (event.key !== "Tab" || event.shiftKey))
|
|
1188
|
+
return;
|
|
1189
|
+
event.preventDefault();
|
|
1190
|
+
if (name.value.trim() !== "")
|
|
1191
|
+
value.focus({ preventScroll: true });
|
|
1192
|
+
});
|
|
1193
|
+
value.addEventListener("keydown", (event) => {
|
|
1194
|
+
if (event.isComposing || values.key(event))
|
|
1195
|
+
return;
|
|
1196
|
+
if (event.key === "Escape") {
|
|
1197
|
+
event.preventDefault();
|
|
1198
|
+
close(false);
|
|
1199
|
+
} else if (event.key === "Enter" || event.key === "Tab" && !event.shiftKey) {
|
|
1200
|
+
event.preventDefault();
|
|
1201
|
+
close(true);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
row.addEventListener("focusout", (event) => {
|
|
1205
|
+
const next = event.relatedTarget;
|
|
1206
|
+
if (next !== null && row.contains(next))
|
|
1207
|
+
return;
|
|
1208
|
+
close(true, true);
|
|
1209
|
+
});
|
|
1210
|
+
name.focus({ preventScroll: true });
|
|
1211
|
+
}
|
|
1212
|
+
return {
|
|
1213
|
+
placeOf(block, owner) {
|
|
1214
|
+
if (block.kind === "inline") {
|
|
1215
|
+
const style = styleOf(block.element);
|
|
1216
|
+
return style ? { style, element: block.element } : null;
|
|
1217
|
+
}
|
|
1218
|
+
const { selectorText, origin } = block;
|
|
1219
|
+
return {
|
|
1220
|
+
style: block.rule.style,
|
|
1221
|
+
element: owner,
|
|
1222
|
+
rule: {
|
|
1223
|
+
selectorText,
|
|
1224
|
+
sheet: origin.sheet,
|
|
1225
|
+
owner: origin.owner,
|
|
1226
|
+
sheetId: sheetIdOf(block.rule),
|
|
1227
|
+
path: [...origin.path],
|
|
1228
|
+
context: [...block.context]
|
|
1229
|
+
}
|
|
1230
|
+
};
|
|
1231
|
+
},
|
|
1232
|
+
offs: (place) => offIn(log.recorded(), place.style),
|
|
1233
|
+
begin() {
|
|
1234
|
+
fields = [];
|
|
1235
|
+
},
|
|
1236
|
+
editable,
|
|
1237
|
+
addLine,
|
|
1238
|
+
newRuleLine,
|
|
1239
|
+
busy: () => open !== null || holding,
|
|
1240
|
+
dismiss: () => open !== null && lists.some((list) => list.dismiss()),
|
|
1241
|
+
close(commit) {
|
|
1242
|
+
if (!open)
|
|
1243
|
+
return false;
|
|
1244
|
+
open.close(commit);
|
|
1245
|
+
return true;
|
|
1246
|
+
},
|
|
1247
|
+
destroy() {
|
|
1248
|
+
open?.close(false);
|
|
1249
|
+
holding = false;
|
|
1250
|
+
clearTimeout(holdTimer);
|
|
1251
|
+
window.removeEventListener("pointerup", onUp, true);
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// src/ui/htmledit.ts
|
|
1257
|
+
var INDENT = " ";
|
|
1258
|
+
var VOID_ELEMENTS = new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
|
|
1259
|
+
function htmlTokens(text) {
|
|
1260
|
+
const out = [];
|
|
1261
|
+
const push = (kind, piece) => {
|
|
1262
|
+
if (piece === "")
|
|
1263
|
+
return;
|
|
1264
|
+
const last = out[out.length - 1];
|
|
1265
|
+
if (last && last.kind === kind)
|
|
1266
|
+
last.text += piece;
|
|
1267
|
+
else
|
|
1268
|
+
out.push({ kind, text: piece });
|
|
1269
|
+
};
|
|
1270
|
+
let at = 0;
|
|
1271
|
+
while (at < text.length) {
|
|
1272
|
+
if (text.startsWith("<!--", at)) {
|
|
1273
|
+
const end = text.indexOf("-->", at + 4);
|
|
1274
|
+
const to = end < 0 ? text.length : end + 3;
|
|
1275
|
+
push("com", text.slice(at, to));
|
|
1276
|
+
at = to;
|
|
1277
|
+
continue;
|
|
1278
|
+
}
|
|
1279
|
+
const name = /^<\/?[A-Za-z][\w:.-]*/.exec(text.slice(at));
|
|
1280
|
+
if (!name) {
|
|
1281
|
+
if (text.startsWith("<!", at)) {
|
|
1282
|
+
const end = text.indexOf(">", at);
|
|
1283
|
+
const to2 = end < 0 ? text.length : end + 1;
|
|
1284
|
+
push("doc", text.slice(at, to2));
|
|
1285
|
+
at = to2;
|
|
1286
|
+
continue;
|
|
1287
|
+
}
|
|
1288
|
+
const next = text.indexOf("<", at + 1);
|
|
1289
|
+
const to = next < 0 ? text.length : next;
|
|
1290
|
+
push("text", text.slice(at, to));
|
|
1291
|
+
at = to;
|
|
1292
|
+
continue;
|
|
1293
|
+
}
|
|
1294
|
+
push("tag", name[0]);
|
|
1295
|
+
at += name[0].length;
|
|
1296
|
+
while (at < text.length && text[at] !== ">") {
|
|
1297
|
+
const rest = text.slice(at);
|
|
1298
|
+
const space = /^\s+/.exec(rest);
|
|
1299
|
+
if (space) {
|
|
1300
|
+
push("text", space[0]);
|
|
1301
|
+
at += space[0].length;
|
|
1302
|
+
continue;
|
|
1303
|
+
}
|
|
1304
|
+
if (rest.startsWith("/")) {
|
|
1305
|
+
push("tag", "/");
|
|
1306
|
+
at += 1;
|
|
1307
|
+
continue;
|
|
1308
|
+
}
|
|
1309
|
+
if (rest.startsWith("=")) {
|
|
1310
|
+
push("text", "=");
|
|
1311
|
+
at += 1;
|
|
1312
|
+
const quote = text[at];
|
|
1313
|
+
if (quote === '"' || quote === "'") {
|
|
1314
|
+
const end = text.indexOf(quote, at + 1);
|
|
1315
|
+
const to = end < 0 ? text.length : end + 1;
|
|
1316
|
+
push("val", text.slice(at, to));
|
|
1317
|
+
at = to;
|
|
1318
|
+
} else {
|
|
1319
|
+
const bare = /^[^\s>]*/.exec(text.slice(at))?.[0] ?? "";
|
|
1320
|
+
push("val", bare);
|
|
1321
|
+
at += bare.length;
|
|
1322
|
+
}
|
|
1323
|
+
continue;
|
|
1324
|
+
}
|
|
1325
|
+
const attr = /^[^\s"'>/=]+/.exec(rest)?.[0] ?? rest.charAt(0);
|
|
1326
|
+
push(/^["']/.test(attr) ? "val" : "attr", attr);
|
|
1327
|
+
at += attr.length;
|
|
1328
|
+
}
|
|
1329
|
+
if (text[at] === ">") {
|
|
1330
|
+
push("tag", ">");
|
|
1331
|
+
at += 1;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
return out;
|
|
1335
|
+
}
|
|
1336
|
+
var OPEN_TAG = /<([A-Za-z][\w:.-]*)(?:\s(?:[^<>"']|"[^"]*"|'[^']*')*)?$/;
|
|
1337
|
+
var OPENED = /<([A-Za-z][\w:.-]*)(?:\s(?:[^<>"']|"[^"]*"|'[^']*')*)?>\s*$/;
|
|
1338
|
+
function closes(name) {
|
|
1339
|
+
return !VOID_ELEMENTS.has(name.toLowerCase());
|
|
1340
|
+
}
|
|
1341
|
+
function typedKey(text, start, end, key) {
|
|
1342
|
+
const before = text.slice(0, start);
|
|
1343
|
+
if (key === "Enter") {
|
|
1344
|
+
const line = before.slice(before.lastIndexOf(`
|
|
1345
|
+
`) + 1);
|
|
1346
|
+
const indent = /^[ \t]*/.exec(line)?.[0] ?? "";
|
|
1347
|
+
const opened = OPENED.exec(line);
|
|
1348
|
+
if (!opened?.[1] || !closes(opened[1]) || /\/>\s*$/.test(line))
|
|
1349
|
+
return { insert: `
|
|
1350
|
+
${indent}`, caret: indent.length + 1 };
|
|
1351
|
+
const inner = `
|
|
1352
|
+
${indent}${INDENT}`;
|
|
1353
|
+
if (new RegExp(`^\\s*</${opened[1]}\\s*>`, "i").test(text.slice(end)))
|
|
1354
|
+
return { insert: `${inner}
|
|
1355
|
+
${indent}`, caret: inner.length };
|
|
1356
|
+
return { insert: inner, caret: inner.length };
|
|
1357
|
+
}
|
|
1358
|
+
if (start !== end)
|
|
1359
|
+
return null;
|
|
1360
|
+
if (key === ">") {
|
|
1361
|
+
const open = OPEN_TAG.exec(before);
|
|
1362
|
+
if (!open?.[1] || before.endsWith("/") || !closes(open[1]))
|
|
1363
|
+
return null;
|
|
1364
|
+
return { insert: `></${open[1]}>`, caret: 1 };
|
|
1365
|
+
}
|
|
1366
|
+
if (key === '"' || key === "'") {
|
|
1367
|
+
const inValue = new RegExp(`<[A-Za-z][^<>]*=\\s*${key}[^${key}]*$`).test(before) && !OPEN_TAG.test(before);
|
|
1368
|
+
if (inValue && text[start] === key)
|
|
1369
|
+
return { insert: "", caret: 1 };
|
|
1370
|
+
if (OPEN_TAG.test(before) && /=\s*$/.test(before))
|
|
1371
|
+
return { insert: `${key}${key}`, caret: 1 };
|
|
1372
|
+
}
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1375
|
+
function tokenLines(text) {
|
|
1376
|
+
const lines = [[]];
|
|
1377
|
+
for (const token of htmlTokens(text)) {
|
|
1378
|
+
token.text.split(`
|
|
1379
|
+
`).forEach((piece, at) => {
|
|
1380
|
+
if (at > 0)
|
|
1381
|
+
lines.push([]);
|
|
1382
|
+
if (piece !== "")
|
|
1383
|
+
lines[lines.length - 1]?.push({ kind: token.kind, text: piece });
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
return lines;
|
|
1387
|
+
}
|
|
1388
|
+
function around(frame) {
|
|
1389
|
+
const closest = (selector) => {
|
|
1390
|
+
const found2 = frame.closest?.(selector);
|
|
1391
|
+
return found2 ? found2 : null;
|
|
1392
|
+
};
|
|
1393
|
+
const box = closest(".dom");
|
|
1394
|
+
const body = closest(".view-body");
|
|
1395
|
+
const height = (node) => node ? Number(Reflect.get(node, "offsetHeight")) || 0 : 0;
|
|
1396
|
+
return { box, body, bar: height(box?.querySelector?.(".dom-acts")), foot: height(body?.querySelector?.(".changes")) };
|
|
1397
|
+
}
|
|
1398
|
+
function insertText(area, insert) {
|
|
1399
|
+
if (insert === "")
|
|
1400
|
+
return false;
|
|
1401
|
+
const doc = area.ownerDocument;
|
|
1402
|
+
const exec = doc ? Reflect.get(doc, "execCommand") : null;
|
|
1403
|
+
if (typeof exec === "function" && Reflect.apply(exec, doc, ["insertText", false, insert]) === true)
|
|
1404
|
+
return true;
|
|
1405
|
+
area.setRangeText(insert, area.selectionStart, area.selectionEnd, "end");
|
|
1406
|
+
return false;
|
|
1407
|
+
}
|
|
1408
|
+
function htmlEditor(value, label2, size = null) {
|
|
1409
|
+
const frame = el("div", "html-ed");
|
|
1410
|
+
const body = el("div", "html-ed-body");
|
|
1411
|
+
const code = el("div", "html-ed-code");
|
|
1412
|
+
const shade = el("pre", "html-ed-hl");
|
|
1413
|
+
shade.setAttribute("aria-hidden", "true");
|
|
1414
|
+
const colored = el("div", "html-ed-inner");
|
|
1415
|
+
shade.append(colored);
|
|
1416
|
+
const area = document.createElement("textarea");
|
|
1417
|
+
area.className = "css-edit inline-field dom-edit dom-html";
|
|
1418
|
+
area.value = value;
|
|
1419
|
+
area.spellcheck = false;
|
|
1420
|
+
area.setAttribute("aria-label", label2);
|
|
1421
|
+
code.append(shade, area);
|
|
1422
|
+
body.append(code);
|
|
1423
|
+
const foot = el("div", "html-ed-foot");
|
|
1424
|
+
const grip = el("div", "html-ed-grip");
|
|
1425
|
+
grip.setAttribute("role", "separator");
|
|
1426
|
+
grip.setAttribute("aria-orientation", "horizontal");
|
|
1427
|
+
grip.setAttribute("aria-label", "drag to resize the html editor");
|
|
1428
|
+
const expand = button("chip html-ed-expand", "expand");
|
|
1429
|
+
foot.append(grip, expand);
|
|
1430
|
+
frame.append(body, foot);
|
|
1431
|
+
let now = size?.get() ?? { height: 200, full: false };
|
|
1432
|
+
let boxWas = null;
|
|
1433
|
+
function paint() {
|
|
1434
|
+
const lines = tokenLines(area.value);
|
|
1435
|
+
const gutter = `calc(${String(lines.length).length}ch + 2 * var(--col-pad))`;
|
|
1436
|
+
colored.style.gridTemplateColumns = `${gutter} minmax(0, 1fr)`;
|
|
1437
|
+
area.style.paddingLeft = `calc(${gutter} + var(--col-pad))`;
|
|
1438
|
+
code.style.backgroundSize = `${gutter} 100%`;
|
|
1439
|
+
colored.replaceChildren(...lines.flatMap((tokens, at) => {
|
|
1440
|
+
const text = el("span", "html-ed-text");
|
|
1441
|
+
text.append(...tokens.map((token) => el("span", `tok-${token.kind}`, token.text)));
|
|
1442
|
+
return [el("span", "html-ed-num", String(at + 1)), text];
|
|
1443
|
+
}));
|
|
1444
|
+
follow();
|
|
1445
|
+
}
|
|
1446
|
+
function follow() {
|
|
1447
|
+
colored.style.transform = `translateY(${-area.scrollTop || 0}px)`;
|
|
1448
|
+
}
|
|
1449
|
+
function applyHeight() {
|
|
1450
|
+
const next = frame.nextElementSibling;
|
|
1451
|
+
return next ? Number(Reflect.get(next, "offsetHeight")) || 0 : 0;
|
|
1452
|
+
}
|
|
1453
|
+
function most(where) {
|
|
1454
|
+
const panel = where.body?.clientHeight ?? 0;
|
|
1455
|
+
if (!panel)
|
|
1456
|
+
return Number.POSITIVE_INFINITY;
|
|
1457
|
+
return Math.max(HTML_MIN, panel - (frame.offsetHeight - body.offsetHeight) - applyHeight() - where.bar - where.foot - 16);
|
|
1458
|
+
}
|
|
1459
|
+
function fit(where) {
|
|
1460
|
+
const { box, body: view } = where;
|
|
1461
|
+
if (!box || !view || typeof frame.getBoundingClientRect !== "function")
|
|
1462
|
+
return;
|
|
1463
|
+
giveBack();
|
|
1464
|
+
const top = frame.getBoundingClientRect().top - box.getBoundingClientRect().top + box.scrollTop;
|
|
1465
|
+
const needed = top + frame.offsetHeight + applyHeight() + where.bar + 12;
|
|
1466
|
+
if (needed <= box.clientHeight)
|
|
1467
|
+
return;
|
|
1468
|
+
boxWas ??= { box, height: box.style.height, maxHeight: box.style.maxHeight };
|
|
1469
|
+
box.style.maxHeight = "none";
|
|
1470
|
+
box.style.height = `${Math.min(needed, view.clientHeight - where.foot)}px`;
|
|
1471
|
+
}
|
|
1472
|
+
function giveBack() {
|
|
1473
|
+
if (boxWas) {
|
|
1474
|
+
boxWas.box.style.height = boxWas.height;
|
|
1475
|
+
boxWas.box.style.maxHeight = boxWas.maxHeight;
|
|
1476
|
+
}
|
|
1477
|
+
boxWas = null;
|
|
1478
|
+
}
|
|
1479
|
+
function reveal(where) {
|
|
1480
|
+
const { box, body: view } = where;
|
|
1481
|
+
if (!box || !view || typeof frame.getBoundingClientRect !== "function")
|
|
1482
|
+
return;
|
|
1483
|
+
box.scrollTop += frame.getBoundingClientRect().top - box.getBoundingClientRect().top - 4;
|
|
1484
|
+
view.scrollTop += box.getBoundingClientRect().top - view.getBoundingClientRect().top;
|
|
1485
|
+
}
|
|
1486
|
+
function apply(next, keep) {
|
|
1487
|
+
now = next;
|
|
1488
|
+
const where = around(frame);
|
|
1489
|
+
const room = most(where);
|
|
1490
|
+
body.style.height = `${Math.round(next.full && Number.isFinite(room) ? room : Math.min(next.height, room))}px`;
|
|
1491
|
+
expand.textContent = next.full ? "shrink" : "expand";
|
|
1492
|
+
expand.setAttribute("aria-pressed", String(next.full));
|
|
1493
|
+
fit(where);
|
|
1494
|
+
if (next.full)
|
|
1495
|
+
reveal(where);
|
|
1496
|
+
if (keep)
|
|
1497
|
+
size?.set(next);
|
|
1498
|
+
}
|
|
1499
|
+
area.addEventListener("input", paint);
|
|
1500
|
+
area.addEventListener("scroll", follow);
|
|
1501
|
+
area.addEventListener("keydown", (event) => {
|
|
1502
|
+
if (event.isComposing || event.metaKey || event.ctrlKey || event.altKey || event.key === "Enter" && event.shiftKey)
|
|
1503
|
+
return;
|
|
1504
|
+
const typed = typedKey(area.value, area.selectionStart ?? 0, area.selectionEnd ?? 0, event.key);
|
|
1505
|
+
if (!typed)
|
|
1506
|
+
return;
|
|
1507
|
+
event.preventDefault();
|
|
1508
|
+
const start = area.selectionStart ?? 0;
|
|
1509
|
+
const heard = insertText(area, typed.insert);
|
|
1510
|
+
area.setSelectionRange(start + typed.caret, start + typed.caret);
|
|
1511
|
+
if (!heard)
|
|
1512
|
+
paint();
|
|
1513
|
+
});
|
|
1514
|
+
frame.addEventListener("pointerdown", (event) => {
|
|
1515
|
+
if (event.target !== area)
|
|
1516
|
+
event.preventDefault();
|
|
1517
|
+
});
|
|
1518
|
+
expand.addEventListener("click", (event) => {
|
|
1519
|
+
event.stopPropagation();
|
|
1520
|
+
apply({ height: now.height, full: !now.full }, true);
|
|
1521
|
+
});
|
|
1522
|
+
grip.addEventListener("pointerdown", (event) => {
|
|
1523
|
+
const from = event.clientY;
|
|
1524
|
+
const was = body.offsetHeight;
|
|
1525
|
+
grip.setPointerCapture?.(event.pointerId);
|
|
1526
|
+
const move = (next) => {
|
|
1527
|
+
apply({ height: Math.max(HTML_MIN, was + next.clientY - from), full: false }, false);
|
|
1528
|
+
};
|
|
1529
|
+
const up = () => {
|
|
1530
|
+
grip.removeEventListener("pointermove", move);
|
|
1531
|
+
grip.removeEventListener("pointerup", up);
|
|
1532
|
+
grip.removeEventListener("pointercancel", up);
|
|
1533
|
+
apply({ height: body.offsetHeight || now.height, full: false }, true);
|
|
1534
|
+
};
|
|
1535
|
+
grip.addEventListener("pointermove", move);
|
|
1536
|
+
grip.addEventListener("pointerup", up);
|
|
1537
|
+
grip.addEventListener("pointercancel", up);
|
|
1538
|
+
});
|
|
1539
|
+
paint();
|
|
1540
|
+
return {
|
|
1541
|
+
frame,
|
|
1542
|
+
area,
|
|
1543
|
+
shown: () => apply(now, false),
|
|
1544
|
+
restore: giveBack
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// src/ui/domedit.ts
|
|
1549
|
+
var ACTIONS = {
|
|
1550
|
+
text: "edit text",
|
|
1551
|
+
attr: "+ attribute",
|
|
1552
|
+
html: "edit as html",
|
|
1553
|
+
hide: "hide",
|
|
1554
|
+
delete: "delete",
|
|
1555
|
+
up: "move up",
|
|
1556
|
+
down: "move down"
|
|
1557
|
+
};
|
|
1558
|
+
function applyHint(mac) {
|
|
1559
|
+
return comboLabel(withShift("enter"), mac);
|
|
1560
|
+
}
|
|
1561
|
+
function commitsHtml(event) {
|
|
1562
|
+
return event.key === "Enter" && !event.altKey && (event.shiftKey || event.metaKey || event.ctrlKey);
|
|
1563
|
+
}
|
|
1564
|
+
function treeEditKey(event) {
|
|
1565
|
+
if (event.metaKey || event.ctrlKey || event.altKey || event.isComposing || typesInField(event))
|
|
1566
|
+
return null;
|
|
1567
|
+
if (event.shiftKey && event.key === "ArrowUp")
|
|
1568
|
+
return "up";
|
|
1569
|
+
if (event.shiftKey && event.key === "ArrowDown")
|
|
1570
|
+
return "down";
|
|
1571
|
+
switch (event.key) {
|
|
1572
|
+
case "Enter":
|
|
1573
|
+
return "text";
|
|
1574
|
+
case "F2":
|
|
1575
|
+
return "html";
|
|
1576
|
+
case "Delete":
|
|
1577
|
+
case "Backspace":
|
|
1578
|
+
return "delete";
|
|
1579
|
+
}
|
|
1580
|
+
if (event.shiftKey)
|
|
1581
|
+
return null;
|
|
1582
|
+
if (letterMatches(event, "a"))
|
|
1583
|
+
return "attr";
|
|
1584
|
+
if (letterMatches(event, "h"))
|
|
1585
|
+
return "hide";
|
|
1586
|
+
return null;
|
|
1587
|
+
}
|
|
1588
|
+
function inElement(node) {
|
|
1589
|
+
const parent = node.parentNode;
|
|
1590
|
+
return parent !== null && isElement(parent);
|
|
1591
|
+
}
|
|
1592
|
+
function textOf(row) {
|
|
1593
|
+
if (row.kind === "text")
|
|
1594
|
+
return inElement(row.node) ? row.node : null;
|
|
1595
|
+
if (row.kind !== "open" || !isElement(row.node))
|
|
1596
|
+
return null;
|
|
1597
|
+
const nodes = row.node.childNodes;
|
|
1598
|
+
const only = nodes[0];
|
|
1599
|
+
return nodes.length === 1 && only?.nodeType === 3 && (only.nodeValue ?? "").trim() !== "" ? only : null;
|
|
1600
|
+
}
|
|
1601
|
+
function textProperty(node) {
|
|
1602
|
+
const parent = node.parentNode;
|
|
1603
|
+
if (!parent)
|
|
1604
|
+
return "text";
|
|
1605
|
+
const texts = Array.from(parent.childNodes).filter((one) => one.nodeType === 3 && (one.nodeValue ?? "").trim() !== "");
|
|
1606
|
+
const at = texts.findIndex((one) => one === node) + 1;
|
|
1607
|
+
return at > 1 ? `text ${at}` : "text";
|
|
1608
|
+
}
|
|
1609
|
+
function parseAttributes(doc, text, svg = false, parse = parseHtml) {
|
|
1610
|
+
const tag = svg ? "svg" : "div";
|
|
1611
|
+
const holder = parse(doc, `<${tag} ${text}></${tag}>`).find(isElement);
|
|
1612
|
+
if (!holder)
|
|
1613
|
+
return null;
|
|
1614
|
+
const found2 = Array.from(holder.attributes).map((attr) => [attr.name, attr.value]);
|
|
1615
|
+
return found2.length > 0 ? found2 : null;
|
|
1616
|
+
}
|
|
1617
|
+
function isFrame(element) {
|
|
1618
|
+
return element.namespaceURI === "http://www.w3.org/1999/xhtml" && (element.localName === "head" || element.localName === "body");
|
|
1619
|
+
}
|
|
1620
|
+
function holdsOwn(element) {
|
|
1621
|
+
return element.querySelector("[data-devknobs]") !== null;
|
|
1622
|
+
}
|
|
1623
|
+
function actionsFor(row) {
|
|
1624
|
+
if (!row || row.pseudo !== null)
|
|
1625
|
+
return [];
|
|
1626
|
+
const node = row.node;
|
|
1627
|
+
const out = [];
|
|
1628
|
+
if (textOf(row))
|
|
1629
|
+
out.push("text");
|
|
1630
|
+
if (row.kind === "open" && isElement(node)) {
|
|
1631
|
+
out.push("attr");
|
|
1632
|
+
if (node.parentNode?.nodeType !== 9 && !isFrame(node) && !holdsOwn(node))
|
|
1633
|
+
out.push("html", "hide", "delete");
|
|
1634
|
+
if (movable(node) && previousElementOf(node))
|
|
1635
|
+
out.push("up");
|
|
1636
|
+
if (movable(node) && nextElementOf(node))
|
|
1637
|
+
out.push("down");
|
|
1638
|
+
} else if ((row.kind === "text" || row.kind === "comment") && inElement(node))
|
|
1639
|
+
out.push("delete");
|
|
1640
|
+
return out;
|
|
1641
|
+
}
|
|
1642
|
+
function quotedValue(value) {
|
|
1643
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
1644
|
+
}
|
|
1645
|
+
function hasTag(node) {
|
|
1646
|
+
return node !== null && typeof Reflect.get(node, "getAttribute") === "function";
|
|
1647
|
+
}
|
|
1648
|
+
function pieceAt(at, code) {
|
|
1649
|
+
for (let up = hasTag(at) ? at : null;up && up !== code; up = up.parentNode && hasTag(up.parentNode) ? up.parentNode : null) {
|
|
1650
|
+
if (up.getAttribute("data-attr") !== null || up.classList.contains("tok-text"))
|
|
1651
|
+
return up;
|
|
1652
|
+
}
|
|
1653
|
+
return null;
|
|
1654
|
+
}
|
|
1655
|
+
function field(value, label2) {
|
|
1656
|
+
const input = editField(value, label2);
|
|
1657
|
+
input.classList.add("dom-edit");
|
|
1658
|
+
return input;
|
|
1659
|
+
}
|
|
1660
|
+
function boxField(value, label2) {
|
|
1661
|
+
const area = document.createElement("textarea");
|
|
1662
|
+
area.className = "css-edit inline-field dom-edit";
|
|
1663
|
+
area.value = value;
|
|
1664
|
+
area.rows = 2;
|
|
1665
|
+
area.spellcheck = false;
|
|
1666
|
+
const fit = () => fitField(area);
|
|
1667
|
+
fit();
|
|
1668
|
+
area.addEventListener("input", fit);
|
|
1669
|
+
area.addEventListener("focus", fit);
|
|
1670
|
+
const hint = applyHint(isMac());
|
|
1671
|
+
area.setAttribute("aria-label", `${label2}, ${hint} to apply, esc to leave`);
|
|
1672
|
+
return { input: area, multiline: true, apply: button("chip dom-apply", `apply ${hint}`) };
|
|
1673
|
+
}
|
|
1674
|
+
function valueField(value, label2) {
|
|
1675
|
+
return value.includes(`
|
|
1676
|
+
`) ? boxField(value, label2) : { input: field(value, label2) };
|
|
1677
|
+
}
|
|
1678
|
+
function createDomEditor(hooks, options) {
|
|
1679
|
+
const { log } = options;
|
|
1680
|
+
const locate = options.locate ?? locateSource;
|
|
1681
|
+
const parse = options.parse ?? parseHtml;
|
|
1682
|
+
const bar = el("div", "dom-acts");
|
|
1683
|
+
bar.setAttribute("role", "toolbar");
|
|
1684
|
+
bar.setAttribute("aria-label", "edit the selected node");
|
|
1685
|
+
bar.hidden = true;
|
|
1686
|
+
let open = null;
|
|
1687
|
+
let current = null;
|
|
1688
|
+
function record(change, element) {
|
|
1689
|
+
if (change === null)
|
|
1690
|
+
return true;
|
|
1691
|
+
locate(element);
|
|
1692
|
+
return recordAt(log, change, element, locate) !== null;
|
|
1693
|
+
}
|
|
1694
|
+
function target(element) {
|
|
1695
|
+
return { selector: selectorOf(element) };
|
|
1696
|
+
}
|
|
1697
|
+
function refocus() {
|
|
1698
|
+
hooks.list.focus({ preventScroll: true });
|
|
1699
|
+
}
|
|
1700
|
+
function openField({ pieces, input, frame = input, commit, multiline = false, apply: applies, closed }) {
|
|
1701
|
+
const first = pieces[0];
|
|
1702
|
+
const parent = first?.parentNode;
|
|
1703
|
+
if (!first || !parent)
|
|
1704
|
+
return;
|
|
1705
|
+
parent.insertBefore(frame, first);
|
|
1706
|
+
if (applies)
|
|
1707
|
+
parent.insertBefore(applies, first);
|
|
1708
|
+
for (const piece of pieces)
|
|
1709
|
+
parent.removeChild(piece);
|
|
1710
|
+
const opened = input.value;
|
|
1711
|
+
let shown = true;
|
|
1712
|
+
const close = (apply, away = false) => {
|
|
1713
|
+
if (!shown)
|
|
1714
|
+
return;
|
|
1715
|
+
shown = false;
|
|
1716
|
+
open = null;
|
|
1717
|
+
if (apply && input.value !== opened && !commit(input.value) && !away) {
|
|
1718
|
+
shown = true;
|
|
1719
|
+
open = self;
|
|
1720
|
+
input.classList.add("bad");
|
|
1721
|
+
input.setAttribute("aria-invalid", "true");
|
|
1722
|
+
input.focus({ preventScroll: true });
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
if (frame.parentNode) {
|
|
1726
|
+
for (const piece of pieces)
|
|
1727
|
+
frame.parentNode.insertBefore(piece, frame);
|
|
1728
|
+
frame.remove();
|
|
1729
|
+
}
|
|
1730
|
+
applies?.remove();
|
|
1731
|
+
closed?.();
|
|
1732
|
+
hooks.settled();
|
|
1733
|
+
if (!away)
|
|
1734
|
+
refocus();
|
|
1735
|
+
};
|
|
1736
|
+
const self = { close: (apply, away = false) => close(apply, away) };
|
|
1737
|
+
open = self;
|
|
1738
|
+
const box = input;
|
|
1739
|
+
box.addEventListener("keydown", (key) => {
|
|
1740
|
+
if (key.isComposing)
|
|
1741
|
+
return;
|
|
1742
|
+
key.stopPropagation();
|
|
1743
|
+
if (key.key === "Escape") {
|
|
1744
|
+
key.preventDefault();
|
|
1745
|
+
close(false);
|
|
1746
|
+
} else if (multiline ? commitsHtml(key) : key.key === "Enter") {
|
|
1747
|
+
key.preventDefault();
|
|
1748
|
+
close(true);
|
|
1749
|
+
}
|
|
1750
|
+
});
|
|
1751
|
+
input.addEventListener("blur", () => close(true, true));
|
|
1752
|
+
if (applies) {
|
|
1753
|
+
applies.addEventListener("pointerdown", (event) => event.preventDefault());
|
|
1754
|
+
applies.addEventListener("click", (event) => {
|
|
1755
|
+
event.stopPropagation();
|
|
1756
|
+
close(true);
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
input.focus({ preventScroll: true });
|
|
1760
|
+
input.select();
|
|
1761
|
+
}
|
|
1762
|
+
function editText(row) {
|
|
1763
|
+
const node = textOf(row);
|
|
1764
|
+
const code = hooks.code(row);
|
|
1765
|
+
const element = node?.parentNode;
|
|
1766
|
+
if (!node || !code || !element || !isElement(element))
|
|
1767
|
+
return;
|
|
1768
|
+
const piece = Array.from(code.childNodes).find((one) => hasTag(one) && one.classList.contains("tok-text"));
|
|
1769
|
+
if (!piece)
|
|
1770
|
+
return;
|
|
1771
|
+
openField({
|
|
1772
|
+
pieces: [piece],
|
|
1773
|
+
...valueField((node.nodeValue ?? "").trim(), "text"),
|
|
1774
|
+
commit: (text) => text.trim() !== "" && record(textEdit(target(element), node, text, textProperty(node)), element)
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
function editAttr(row, name) {
|
|
1778
|
+
const element = row.node;
|
|
1779
|
+
const code = hooks.code(row);
|
|
1780
|
+
if (!isElement(element) || !code)
|
|
1781
|
+
return;
|
|
1782
|
+
const pieces = Array.from(code.childNodes);
|
|
1783
|
+
let at;
|
|
1784
|
+
let slot = null;
|
|
1785
|
+
if (name === null) {
|
|
1786
|
+
const end = [...pieces].reverse().find((one) => hasTag(one) && one.classList.contains("tok-tag") && (one.textContent ?? "").startsWith(">"));
|
|
1787
|
+
if (!end)
|
|
1788
|
+
return;
|
|
1789
|
+
slot = el("span", "", " ");
|
|
1790
|
+
end.parentNode?.insertBefore(slot, end);
|
|
1791
|
+
at = [slot];
|
|
1792
|
+
} else
|
|
1793
|
+
at = pieces.filter((one) => hasTag(one) && one.getAttribute("data-attr") === name);
|
|
1794
|
+
if (at.length === 0)
|
|
1795
|
+
return;
|
|
1796
|
+
const value = name === null ? "" : `${name}="${quotedValue(element.getAttribute(name) ?? "")}"`;
|
|
1797
|
+
const svg = element.namespaceURI === "http://www.w3.org/2000/svg";
|
|
1798
|
+
openField({
|
|
1799
|
+
pieces: at,
|
|
1800
|
+
...valueField(value, name === null ? "new attribute" : `attribute ${name}`),
|
|
1801
|
+
commit(text) {
|
|
1802
|
+
const trimmed = text.trim();
|
|
1803
|
+
if (trimmed === value)
|
|
1804
|
+
return true;
|
|
1805
|
+
const parsed = trimmed === "" ? [] : parseAttributes(element.ownerDocument, trimmed, svg, parse);
|
|
1806
|
+
if (parsed === null)
|
|
1807
|
+
return false;
|
|
1808
|
+
const names = new Set(parsed.map(([one]) => attributeName(element, one)));
|
|
1809
|
+
const changes = [];
|
|
1810
|
+
if (name !== null && !names.has(attributeName(element, name)))
|
|
1811
|
+
changes.push(attrEdit(target(element), element, name, null));
|
|
1812
|
+
for (const [one, next] of parsed)
|
|
1813
|
+
changes.push(attrEdit(target(element), element, one, next));
|
|
1814
|
+
return changes.every((change) => record(change, element));
|
|
1815
|
+
},
|
|
1816
|
+
closed: () => slot?.remove()
|
|
1817
|
+
});
|
|
1818
|
+
}
|
|
1819
|
+
function editHtml(row) {
|
|
1820
|
+
const element = row.node;
|
|
1821
|
+
const code = hooks.code(row);
|
|
1822
|
+
if (!isElement(element) || !code)
|
|
1823
|
+
return;
|
|
1824
|
+
const before = markupOf(element);
|
|
1825
|
+
const hint = applyHint(isMac());
|
|
1826
|
+
const editor = htmlEditor(before, `edit as html, ${hint} to apply, esc to leave`, options.htmlSize ?? null);
|
|
1827
|
+
openField({
|
|
1828
|
+
pieces: Array.from(code.childNodes),
|
|
1829
|
+
input: editor.area,
|
|
1830
|
+
frame: editor.frame,
|
|
1831
|
+
multiline: true,
|
|
1832
|
+
apply: button("chip dom-apply", `apply ${hint}`),
|
|
1833
|
+
closed: () => editor.restore(),
|
|
1834
|
+
commit(text) {
|
|
1835
|
+
if (text.trim() === before.trim())
|
|
1836
|
+
return true;
|
|
1837
|
+
const nodes = parse(element.ownerDocument, text);
|
|
1838
|
+
const change = htmlEdit(target(element), element, before, nodes);
|
|
1839
|
+
if (!change || !record(change, element))
|
|
1840
|
+
return false;
|
|
1841
|
+
const made3 = nodes.find(isElement);
|
|
1842
|
+
if (made3)
|
|
1843
|
+
hooks.select(made3);
|
|
1844
|
+
return true;
|
|
1845
|
+
}
|
|
1846
|
+
});
|
|
1847
|
+
editor.shown();
|
|
1848
|
+
}
|
|
1849
|
+
function hide(row) {
|
|
1850
|
+
if (isElement(row.node))
|
|
1851
|
+
record(hideEdit(target(row.node), row.node), row.node);
|
|
1852
|
+
}
|
|
1853
|
+
function remove(row) {
|
|
1854
|
+
const node = row.node;
|
|
1855
|
+
const parent = parentOf(node);
|
|
1856
|
+
const element = isElement(node) ? node : node.parentNode;
|
|
1857
|
+
if (!parent || !element || !isElement(element))
|
|
1858
|
+
return;
|
|
1859
|
+
const lines = hooks.children(parent).filter((entry) => entry.pseudo === null);
|
|
1860
|
+
const at = lines.findIndex((entry) => entry.node === node);
|
|
1861
|
+
const next = lines[at + 1]?.node ?? lines[at - 1]?.node ?? (parent.nodeType === 9 ? null : parent);
|
|
1862
|
+
const property = isElement(node) ? "node" : node.nodeType === 3 ? textProperty(node) : "comment";
|
|
1863
|
+
if (!record(deleteEdit(target(element), node, markupOf(node), property), element))
|
|
1864
|
+
return;
|
|
1865
|
+
if (next)
|
|
1866
|
+
hooks.select(next);
|
|
1867
|
+
}
|
|
1868
|
+
function move(element, parent, next) {
|
|
1869
|
+
const home = element.parentNode;
|
|
1870
|
+
if (!home || !isElement(home) || !movable(element) || !canHold(parent, element))
|
|
1871
|
+
return false;
|
|
1872
|
+
const was = nextElementOf(element);
|
|
1873
|
+
const places = {
|
|
1874
|
+
from: { parent: selectorOf(home), next: was ? selectorOf(was) : null },
|
|
1875
|
+
to: { parent: selectorOf(parent), next: next ? selectorOf(next) : null }
|
|
1876
|
+
};
|
|
1877
|
+
const change = moveEdit(target(element), element, { parent, next }, places);
|
|
1878
|
+
if (!change || !record(change, element))
|
|
1879
|
+
return false;
|
|
1880
|
+
hooks.select(element);
|
|
1881
|
+
return true;
|
|
1882
|
+
}
|
|
1883
|
+
function step(row, up) {
|
|
1884
|
+
const element = row.node;
|
|
1885
|
+
const parent = element.parentNode;
|
|
1886
|
+
if (!isElement(element) || !parent || !isElement(parent))
|
|
1887
|
+
return;
|
|
1888
|
+
if (up) {
|
|
1889
|
+
const before = previousElementOf(element);
|
|
1890
|
+
if (before)
|
|
1891
|
+
move(element, parent, before);
|
|
1892
|
+
return;
|
|
1893
|
+
}
|
|
1894
|
+
const after = nextElementOf(element);
|
|
1895
|
+
if (after)
|
|
1896
|
+
move(element, parent, nextElementOf(after));
|
|
1897
|
+
}
|
|
1898
|
+
function done() {
|
|
1899
|
+
open?.close(true);
|
|
1900
|
+
return open === null;
|
|
1901
|
+
}
|
|
1902
|
+
function act(action, row) {
|
|
1903
|
+
if (!actionsFor(row).includes(action) || !done() || !row.node.isConnected)
|
|
1904
|
+
return;
|
|
1905
|
+
if (action === "text")
|
|
1906
|
+
editText(row);
|
|
1907
|
+
else if (action === "attr")
|
|
1908
|
+
editAttr(row, null);
|
|
1909
|
+
else if (action === "html")
|
|
1910
|
+
editHtml(row);
|
|
1911
|
+
else if (action === "hide")
|
|
1912
|
+
hide(row);
|
|
1913
|
+
else if (action === "up" || action === "down")
|
|
1914
|
+
step(row, action === "up");
|
|
1915
|
+
else
|
|
1916
|
+
remove(row);
|
|
1917
|
+
}
|
|
1918
|
+
function selected(row) {
|
|
1919
|
+
current = row;
|
|
1920
|
+
const actions = actionsFor(row);
|
|
1921
|
+
bar.hidden = actions.length === 0;
|
|
1922
|
+
bar.replaceChildren(...actions.map((action) => {
|
|
1923
|
+
const hidden = action === "hide" && row !== null && isElement(row.node) && row.node.hasAttribute(HIDE_ATTRIBUTE);
|
|
1924
|
+
const control = button("chip dom-act", hidden ? "show" : ACTIONS[action]);
|
|
1925
|
+
control.addEventListener("pointerdown", (event) => event.preventDefault());
|
|
1926
|
+
control.addEventListener("click", () => {
|
|
1927
|
+
if (done() && current)
|
|
1928
|
+
act(action, current);
|
|
1929
|
+
});
|
|
1930
|
+
return control;
|
|
1931
|
+
}));
|
|
1932
|
+
}
|
|
1933
|
+
return {
|
|
1934
|
+
bar,
|
|
1935
|
+
dblclick(row, at) {
|
|
1936
|
+
const piece = pieceAt(at, hooks.code(row));
|
|
1937
|
+
const name = piece?.getAttribute("data-attr");
|
|
1938
|
+
if (name) {
|
|
1939
|
+
if (done())
|
|
1940
|
+
editAttr(row, name);
|
|
1941
|
+
return true;
|
|
1942
|
+
}
|
|
1943
|
+
if (!piece || !textOf(row))
|
|
1944
|
+
return false;
|
|
1945
|
+
act("text", row);
|
|
1946
|
+
return true;
|
|
1947
|
+
},
|
|
1948
|
+
key(event, row) {
|
|
1949
|
+
const action = row ? treeEditKey(event) : null;
|
|
1950
|
+
if (!action || !row || !actionsFor(row).includes(action))
|
|
1951
|
+
return false;
|
|
1952
|
+
act(action, row);
|
|
1953
|
+
return true;
|
|
1954
|
+
},
|
|
1955
|
+
selected,
|
|
1956
|
+
busy: () => open !== null,
|
|
1957
|
+
close(commit) {
|
|
1958
|
+
if (!open)
|
|
1959
|
+
return false;
|
|
1960
|
+
open.close(commit, commit);
|
|
1961
|
+
return true;
|
|
1962
|
+
},
|
|
1963
|
+
move(element, parent, next) {
|
|
1964
|
+
return done() && move(element, parent, next);
|
|
1965
|
+
},
|
|
1966
|
+
destroy() {
|
|
1967
|
+
open?.close(false);
|
|
1968
|
+
}
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
// src/styles/cascade.ts
|
|
1973
|
+
function compare(a, aImportant, b, bImportant) {
|
|
1974
|
+
if (aImportant !== bImportant)
|
|
1975
|
+
return aImportant ? 1 : -1;
|
|
1976
|
+
const turned = aImportant ? -1 : 1;
|
|
1977
|
+
if (a.context !== b.context)
|
|
1978
|
+
return (b.context - a.context) * turned;
|
|
1979
|
+
if (a.inline !== b.inline)
|
|
1980
|
+
return a.inline ? 1 : -1;
|
|
1981
|
+
if (a.layer !== b.layer)
|
|
1982
|
+
return (a.layer - b.layer) * turned;
|
|
1983
|
+
return compareSpecificity(a.specificity, b.specificity) || a.order - b.order;
|
|
1984
|
+
}
|
|
1985
|
+
function winners(candidates) {
|
|
1986
|
+
const won = new Map;
|
|
1987
|
+
for (const candidate of candidates) {
|
|
1988
|
+
for (const declaration of candidate.declarations) {
|
|
1989
|
+
for (const longhand of declaration.longhands) {
|
|
1990
|
+
const best = won.get(longhand);
|
|
1991
|
+
const beats = !best || compare(candidate.source, declaration.important, best.candidate.source, best.declaration.important) >= 0;
|
|
1992
|
+
if (beats)
|
|
1993
|
+
won.set(longhand, { candidate, declaration });
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
return won;
|
|
1998
|
+
}
|
|
1999
|
+
function markOwn(candidates, won) {
|
|
2000
|
+
for (const candidate of candidates) {
|
|
2001
|
+
for (const declaration of candidate.declarations) {
|
|
2002
|
+
const lost = declaration.longhands.every((longhand) => won.get(longhand)?.declaration !== declaration);
|
|
2003
|
+
declaration.overridden = lost;
|
|
2004
|
+
const by = won.get(declaration.longhands[0] ?? "")?.candidate.id;
|
|
2005
|
+
if (lost && by !== undefined)
|
|
2006
|
+
declaration.overriddenBy = by;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
function settleInherited(candidates, taken, inherits) {
|
|
2011
|
+
for (const candidate of candidates) {
|
|
2012
|
+
candidate.declarations = candidate.declarations.filter((declaration) => declaration.longhands.some(inherits));
|
|
2013
|
+
}
|
|
2014
|
+
const kept = candidates.filter((candidate) => candidate.declarations.length > 0);
|
|
2015
|
+
const won = winners(kept);
|
|
2016
|
+
for (const candidate of kept) {
|
|
2017
|
+
for (const declaration of candidate.declarations) {
|
|
2018
|
+
const passed = declaration.longhands.filter(inherits);
|
|
2019
|
+
const live = passed.some((longhand) => !taken.has(longhand) && won.get(longhand)?.declaration === declaration);
|
|
2020
|
+
declaration.overridden = !live;
|
|
2021
|
+
const first = passed[0] ?? "";
|
|
2022
|
+
const by = taken.get(first) ?? won.get(first)?.candidate.id;
|
|
2023
|
+
if (!live && by !== undefined)
|
|
2024
|
+
declaration.overriddenBy = by;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
for (const [longhand, winner] of won) {
|
|
2028
|
+
if (inherits(longhand) && !taken.has(longhand))
|
|
2029
|
+
taken.set(longhand, winner.candidate.id);
|
|
2030
|
+
}
|
|
2031
|
+
return kept;
|
|
2032
|
+
}
|
|
2033
|
+
var STEADY = new Set([
|
|
2034
|
+
"box-sizing",
|
|
2035
|
+
"flex-direction",
|
|
2036
|
+
"flex-wrap",
|
|
2037
|
+
"object-fit",
|
|
2038
|
+
"pointer-events",
|
|
2039
|
+
"position",
|
|
2040
|
+
"text-transform",
|
|
2041
|
+
"visibility"
|
|
2042
|
+
]);
|
|
2043
|
+
var STEADY_DISPLAY = new Set(["none", "block", "flex", "grid"]);
|
|
2044
|
+
var WIDE = new Set(["inherit", "initial", "unset", "revert", "revert-layer"]);
|
|
2045
|
+
function tidy(property, value) {
|
|
2046
|
+
const text = value.trim().replace(/\s+/g, " ");
|
|
2047
|
+
return property.startsWith("--") ? text : text.toLowerCase();
|
|
2048
|
+
}
|
|
2049
|
+
function isSteady(property, value) {
|
|
2050
|
+
if (property.startsWith("--"))
|
|
2051
|
+
return value !== "" && !value.includes("var(");
|
|
2052
|
+
if (WIDE.has(value))
|
|
2053
|
+
return false;
|
|
2054
|
+
if (property === "display")
|
|
2055
|
+
return STEADY_DISPLAY.has(value);
|
|
2056
|
+
return STEADY.has(property) && /^[a-z-]+$/.test(value);
|
|
2057
|
+
}
|
|
2058
|
+
function settleContainers(candidates, computed) {
|
|
2059
|
+
let live = [...candidates];
|
|
2060
|
+
for (let decided = true;decided; ) {
|
|
2061
|
+
decided = false;
|
|
2062
|
+
for (const candidate of [...live]) {
|
|
2063
|
+
const conditional = candidate.conditional;
|
|
2064
|
+
if (conditional?.kind !== "container" || conditional.confirmed)
|
|
2065
|
+
continue;
|
|
2066
|
+
const without = live.filter((other) => other !== candidate);
|
|
2067
|
+
const verdict = judge(candidate, winners(live), winners(without), computed);
|
|
2068
|
+
if (verdict === null)
|
|
2069
|
+
continue;
|
|
2070
|
+
decided = true;
|
|
2071
|
+
if (verdict)
|
|
2072
|
+
conditional.confirmed = true;
|
|
2073
|
+
else
|
|
2074
|
+
live = without;
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
return live;
|
|
2078
|
+
}
|
|
2079
|
+
function judge(candidate, won, without, computed) {
|
|
2080
|
+
for (const [longhand, winner] of won) {
|
|
2081
|
+
if (winner.candidate !== candidate)
|
|
2082
|
+
continue;
|
|
2083
|
+
const mine = tidy(longhand, candidate.value(longhand));
|
|
2084
|
+
if (!isSteady(longhand, mine))
|
|
2085
|
+
continue;
|
|
2086
|
+
if (tidy(longhand, computed(longhand)) !== mine)
|
|
2087
|
+
return false;
|
|
2088
|
+
const next = without.get(longhand);
|
|
2089
|
+
const other = next ? tidy(longhand, next.candidate.value(longhand)) : null;
|
|
2090
|
+
if (other !== null && other !== mine && isSteady(longhand, other))
|
|
2091
|
+
return true;
|
|
2092
|
+
}
|
|
2093
|
+
return null;
|
|
2094
|
+
}
|
|
2095
|
+
function byStrength(candidates) {
|
|
2096
|
+
return [...candidates].sort((a, b) => compare(b.source, false, a.source, false));
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
// src/styles/inherited.ts
|
|
2100
|
+
var INHERITED = new Set(`accent-color border-collapse border-spacing caption-side caret-color caret-shape clip-rule color
|
|
2101
|
+
color-interpolation color-interpolation-filters color-rendering color-scheme cursor direction
|
|
2102
|
+
dominant-baseline dynamic-range-limit empty-cells fill fill-opacity fill-rule font font-family
|
|
2103
|
+
font-feature-settings font-kerning font-language-override font-optical-sizing font-palette font-size
|
|
2104
|
+
font-size-adjust font-stretch font-style font-synthesis font-synthesis-position
|
|
2105
|
+
font-synthesis-small-caps font-synthesis-style font-synthesis-weight font-variant
|
|
2106
|
+
font-variant-alternates font-variant-caps font-variant-east-asian font-variant-emoji
|
|
2107
|
+
font-variant-ligatures font-variant-numeric font-variant-position font-variation-settings font-weight
|
|
2108
|
+
font-width forced-color-adjust hanging-punctuation hyphenate-character hyphenate-limit-chars hyphens
|
|
2109
|
+
image-orientation image-rendering interactivity interpolate-size letter-spacing line-break line-height
|
|
2110
|
+
list-style list-style-image list-style-position list-style-type marker marker-end marker-mid
|
|
2111
|
+
marker-start math-depth math-shift math-style orphans overflow-wrap paint-order pointer-events
|
|
2112
|
+
print-color-adjust quotes ruby-align ruby-position scrollbar-color shape-rendering speak stroke
|
|
2113
|
+
stroke-dasharray stroke-dashoffset stroke-linecap stroke-linejoin stroke-miterlimit stroke-opacity
|
|
2114
|
+
stroke-width tab-size text-align text-align-last text-anchor text-autospace text-box-edge
|
|
2115
|
+
text-combine-upright text-decoration-skip-ink text-emphasis text-emphasis-color text-emphasis-position
|
|
2116
|
+
text-emphasis-style text-indent text-justify text-orientation text-rendering text-shadow
|
|
2117
|
+
text-size-adjust text-spacing-trim text-transform text-underline-offset text-underline-position
|
|
2118
|
+
text-wrap text-wrap-mode text-wrap-style visibility white-space white-space-collapse widows word-break
|
|
2119
|
+
word-spacing word-wrap writing-mode -moz-osx-font-smoothing -webkit-border-horizontal-spacing
|
|
2120
|
+
-webkit-border-vertical-spacing -webkit-font-smoothing -webkit-line-break -webkit-locale
|
|
2121
|
+
-webkit-print-color-adjust -webkit-rtl-ordering -webkit-tap-highlight-color -webkit-text-fill-color
|
|
2122
|
+
-webkit-text-orientation -webkit-text-size-adjust -webkit-text-stroke -webkit-text-stroke-color
|
|
2123
|
+
-webkit-text-stroke-width -webkit-user-modify -webkit-writing-mode`.split(/\s+/));
|
|
2124
|
+
function isInherited(property, registered) {
|
|
2125
|
+
if (property.startsWith("--"))
|
|
2126
|
+
return registered.get(property) ?? true;
|
|
2127
|
+
return INHERITED.has(property);
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
// src/styles/match.ts
|
|
2131
|
+
function conditionsFor(view) {
|
|
2132
|
+
const known = new Map;
|
|
2133
|
+
const test = (key, run) => {
|
|
2134
|
+
let result = known.get(key);
|
|
2135
|
+
if (result === undefined) {
|
|
2136
|
+
try {
|
|
2137
|
+
result = run();
|
|
2138
|
+
} catch {
|
|
2139
|
+
result = false;
|
|
2140
|
+
}
|
|
2141
|
+
known.set(key, result);
|
|
2142
|
+
}
|
|
2143
|
+
return result;
|
|
2144
|
+
};
|
|
2145
|
+
return (conditions) => conditions.every((condition) => {
|
|
2146
|
+
if (condition.kind === "supports") {
|
|
2147
|
+
return test(`s:${condition.text}`, () => view.CSS.supports(condition.text));
|
|
2148
|
+
}
|
|
2149
|
+
const text = condition.list.mediaText;
|
|
2150
|
+
return text === "" || test(`m:${text}`, () => view.matchMedia(text).matches);
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
function matches(element, selector) {
|
|
2154
|
+
return element.matches(forcing() ? forcedSelector(selector) : selector);
|
|
2155
|
+
}
|
|
2156
|
+
function reaches(element, part, reach) {
|
|
2157
|
+
if (reach.kind === "host")
|
|
2158
|
+
return part.host !== null && matches(element, part.host);
|
|
2159
|
+
if (reach.kind === "slotted") {
|
|
2160
|
+
if (part.slotted === null)
|
|
2161
|
+
return false;
|
|
2162
|
+
return matches(element, part.slotted) && matches(reach.slot, part.match);
|
|
2163
|
+
}
|
|
2164
|
+
return part.host === null && part.slotted === null && matches(element, part.match);
|
|
2165
|
+
}
|
|
2166
|
+
function inScope(element, scope) {
|
|
2167
|
+
let root = scope.around;
|
|
2168
|
+
if (scope.start !== null) {
|
|
2169
|
+
root = element;
|
|
2170
|
+
while (root && !matches(root, scope.start))
|
|
2171
|
+
root = root.parentElement;
|
|
2172
|
+
if (!root)
|
|
2173
|
+
return false;
|
|
2174
|
+
} else if (root && !root.contains(element)) {
|
|
2175
|
+
return false;
|
|
2176
|
+
}
|
|
2177
|
+
if (scope.end === null)
|
|
2178
|
+
return true;
|
|
2179
|
+
for (let current = element;current && current !== root; ) {
|
|
2180
|
+
if (matches(current, scope.end))
|
|
2181
|
+
return false;
|
|
2182
|
+
current = current.parentElement;
|
|
2183
|
+
}
|
|
2184
|
+
return true;
|
|
2185
|
+
}
|
|
2186
|
+
function matchRules(element, rules, reach, wanted, checks, skip) {
|
|
2187
|
+
const found2 = new Map;
|
|
2188
|
+
for (const flat of rules) {
|
|
2189
|
+
if (skip?.(flat) || !checks.holds(flat.conditions))
|
|
2190
|
+
continue;
|
|
2191
|
+
let hits = null;
|
|
2192
|
+
for (let i = 0;i < flat.parts.length; i++) {
|
|
2193
|
+
const part = flat.parts[i];
|
|
2194
|
+
const styles = part?.pseudo ?? "";
|
|
2195
|
+
if (!part || !wanted.has(styles))
|
|
2196
|
+
continue;
|
|
2197
|
+
try {
|
|
2198
|
+
if (!reaches(element, part, reach))
|
|
2199
|
+
continue;
|
|
2200
|
+
if (flat.scope && !inScope(element, flat.scope))
|
|
2201
|
+
continue;
|
|
2202
|
+
} catch {
|
|
2203
|
+
checks.threw();
|
|
2204
|
+
continue;
|
|
2205
|
+
}
|
|
2206
|
+
hits ??= new Map;
|
|
2207
|
+
let hit = hits.get(styles);
|
|
2208
|
+
if (!hit) {
|
|
2209
|
+
hit = { flat, matched: flat.parts.map(() => false), specificity: part.specificity };
|
|
2210
|
+
hits.set(styles, hit);
|
|
2211
|
+
}
|
|
2212
|
+
hit.matched[i] = true;
|
|
2213
|
+
if (compareSpecificity(part.specificity, hit.specificity) > 0) {
|
|
2214
|
+
hit.specificity = part.specificity;
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
if (!hits)
|
|
2218
|
+
continue;
|
|
2219
|
+
for (const [styles, hit] of hits) {
|
|
2220
|
+
const list = found2.get(styles);
|
|
2221
|
+
if (list)
|
|
2222
|
+
list.push(hit);
|
|
2223
|
+
else
|
|
2224
|
+
found2.set(styles, [hit]);
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
return found2;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// src/styles/index.ts
|
|
2231
|
+
var ELEMENT = "";
|
|
2232
|
+
var PSEUDOS = ["::before", "::after"];
|
|
2233
|
+
var ONLY_ELEMENT = new Set([ELEMENT]);
|
|
2234
|
+
var probes = new WeakMap;
|
|
2235
|
+
function expanderFor(doc) {
|
|
2236
|
+
const probe = probes.get(doc) ?? { style: null, known: new Map };
|
|
2237
|
+
probes.set(doc, probe);
|
|
2238
|
+
return (shorthand) => {
|
|
2239
|
+
let longhands = probe.known.get(shorthand);
|
|
2240
|
+
if (longhands)
|
|
2241
|
+
return longhands;
|
|
2242
|
+
longhands = [];
|
|
2243
|
+
try {
|
|
2244
|
+
probe.style ??= doc.createElement("div").style;
|
|
2245
|
+
probe.style.cssText = "";
|
|
2246
|
+
probe.style.setProperty(shorthand, "initial");
|
|
2247
|
+
longhands = listed(probe.style);
|
|
2248
|
+
} catch {}
|
|
2249
|
+
probe.known.set(shorthand, longhands);
|
|
2250
|
+
return longhands;
|
|
2251
|
+
};
|
|
2252
|
+
}
|
|
2253
|
+
var parsed = new WeakMap;
|
|
2254
|
+
function declarationsOf(style, session) {
|
|
2255
|
+
const text = style.cssText;
|
|
2256
|
+
let known = parsed.get(style);
|
|
2257
|
+
if (!known || known.text !== text) {
|
|
2258
|
+
const names = listed(style);
|
|
2259
|
+
const declarations = parseDeclarations(text).map((written) => ({
|
|
2260
|
+
...written,
|
|
2261
|
+
longhands: longhandsOf(written.name, names, session.expand),
|
|
2262
|
+
variables: variableNames(written.value)
|
|
2263
|
+
}));
|
|
2264
|
+
known = { text, declarations };
|
|
2265
|
+
parsed.set(style, known);
|
|
2266
|
+
}
|
|
2267
|
+
return known.declarations.map((declaration) => ({ ...declaration, overridden: false }));
|
|
2268
|
+
}
|
|
2269
|
+
function open(session, scope) {
|
|
2270
|
+
const flat = rulesOf(scope);
|
|
2271
|
+
if (!session.ranks.has(flat)) {
|
|
2272
|
+
session.ranks.set(flat, layerRanks(flat.layers, session.checks.holds));
|
|
2273
|
+
for (const [name, inherits] of flat.registered)
|
|
2274
|
+
session.registered.set(name, inherits);
|
|
2275
|
+
}
|
|
2276
|
+
return flat;
|
|
2277
|
+
}
|
|
2278
|
+
function ruleEntry(session, flat, hit, context) {
|
|
2279
|
+
const { rule, parts, selectorText, origin, conditional } = hit.flat;
|
|
2280
|
+
const source = {
|
|
2281
|
+
context,
|
|
2282
|
+
inline: false,
|
|
2283
|
+
layer: session.ranks.get(flat)?.get(hit.flat.layer) ?? 0,
|
|
2284
|
+
specificity: hit.specificity,
|
|
2285
|
+
order: hit.flat.order
|
|
2286
|
+
};
|
|
2287
|
+
const block = {
|
|
2288
|
+
kind: "rule",
|
|
2289
|
+
id: session.ids++,
|
|
2290
|
+
selectorText,
|
|
2291
|
+
selector: parts.map((part, i) => ({ text: part.text, matches: hit.matched[i] === true })),
|
|
2292
|
+
specificity: hit.specificity,
|
|
2293
|
+
origin,
|
|
2294
|
+
context: hit.flat.context,
|
|
2295
|
+
declarations: declarationsOf(rule.style, session),
|
|
2296
|
+
rule
|
|
2297
|
+
};
|
|
2298
|
+
if (conditional)
|
|
2299
|
+
block.conditional = { kind: conditional, confirmed: false };
|
|
2300
|
+
return {
|
|
2301
|
+
id: block.id,
|
|
2302
|
+
source,
|
|
2303
|
+
declarations: block.declarations,
|
|
2304
|
+
value: (longhand) => rule.style.getPropertyValue(longhand),
|
|
2305
|
+
conditional: block.conditional,
|
|
2306
|
+
block
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
function hasStyle2(element) {
|
|
2310
|
+
return "style" in element;
|
|
2311
|
+
}
|
|
2312
|
+
function inlineEntry(session, element) {
|
|
2313
|
+
if (!hasStyle2(element))
|
|
2314
|
+
return null;
|
|
2315
|
+
const style = element.style;
|
|
2316
|
+
const declarations = declarationsOf(style, session).filter((declaration) => {
|
|
2317
|
+
const wrote = ownInline(element, declaration.name);
|
|
2318
|
+
return wrote === null || wrote !== style.getPropertyValue(declaration.name);
|
|
2319
|
+
});
|
|
2320
|
+
if (declarations.length === 0)
|
|
2321
|
+
return null;
|
|
2322
|
+
const block = { kind: "inline", id: session.ids++, declarations, element };
|
|
2323
|
+
return {
|
|
2324
|
+
id: block.id,
|
|
2325
|
+
source: { context: 0, inline: true, layer: 0, specificity: [0, 0, 0], order: 0 },
|
|
2326
|
+
declarations,
|
|
2327
|
+
value: (longhand) => style.getPropertyValue(longhand),
|
|
2328
|
+
block
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
function entriesFor(session, element, wanted, skip) {
|
|
2332
|
+
const entries = new Map;
|
|
2333
|
+
const add = (scope, reach, context2) => {
|
|
2334
|
+
const flat = open(session, scope);
|
|
2335
|
+
const hits = matchRules(element, flat.rules, reach, wanted, session.checks, skip);
|
|
2336
|
+
for (const [styles, list] of hits) {
|
|
2337
|
+
const into = entries.get(styles) ?? [];
|
|
2338
|
+
entries.set(styles, into);
|
|
2339
|
+
for (const hit of list)
|
|
2340
|
+
into.push(ruleEntry(session, flat, hit, context2));
|
|
2341
|
+
}
|
|
2342
|
+
};
|
|
2343
|
+
add(scopeOf(element), { kind: "own" }, 0);
|
|
2344
|
+
let context = 1;
|
|
2345
|
+
for (let slot = element.assignedSlot;slot; slot = slot.assignedSlot) {
|
|
2346
|
+
const root = slot.getRootNode();
|
|
2347
|
+
if (isShadowRoot(root))
|
|
2348
|
+
add(root, { kind: "slotted", slot }, context++);
|
|
2349
|
+
}
|
|
2350
|
+
if (element.shadowRoot)
|
|
2351
|
+
add(element.shadowRoot, { kind: "host" }, context);
|
|
2352
|
+
return entries;
|
|
2353
|
+
}
|
|
2354
|
+
function isRule(block) {
|
|
2355
|
+
return block.kind === "rule";
|
|
2356
|
+
}
|
|
2357
|
+
function shown(entries) {
|
|
2358
|
+
return byStrength(entries).map((entry) => {
|
|
2359
|
+
entry.block.declarations = entry.declarations;
|
|
2360
|
+
return entry.block;
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
function ownBlocks(blocks) {
|
|
2364
|
+
return blocks.flatMap((block) => {
|
|
2365
|
+
if (block.kind === "pseudo")
|
|
2366
|
+
return [];
|
|
2367
|
+
return block.kind === "inherited" ? block.blocks : [block];
|
|
2368
|
+
});
|
|
2369
|
+
}
|
|
2370
|
+
function inspect(element, pseudo) {
|
|
2371
|
+
const target = { label: label(element), pseudo: pseudo ? normalizePseudo(pseudo) : null };
|
|
2372
|
+
const found2 = { target, blocks: [], hidden: [], variables: {}, skipped: 0 };
|
|
2373
|
+
const doc = element.ownerDocument;
|
|
2374
|
+
const view = doc.defaultView;
|
|
2375
|
+
if (!view || isDevknobs(element))
|
|
2376
|
+
return found2;
|
|
2377
|
+
const session = {
|
|
2378
|
+
checks: { holds: conditionsFor(view), threw: () => session.threw++ },
|
|
2379
|
+
expand: expanderFor(doc),
|
|
2380
|
+
ids: 0,
|
|
2381
|
+
threw: 0,
|
|
2382
|
+
ranks: new Map,
|
|
2383
|
+
registered: new Map
|
|
2384
|
+
};
|
|
2385
|
+
open(session, doc);
|
|
2386
|
+
let computed = null;
|
|
2387
|
+
const read = (property) => {
|
|
2388
|
+
computed ??= view.getComputedStyle(element, target.pseudo);
|
|
2389
|
+
return computed.getPropertyValue(property);
|
|
2390
|
+
};
|
|
2391
|
+
const wanted = new Set(target.pseudo ? [target.pseudo] : [ELEMENT, ...PSEUDOS]);
|
|
2392
|
+
const reached = entriesFor(session, element, wanted);
|
|
2393
|
+
let own = reached.get(target.pseudo ?? ELEMENT) ?? [];
|
|
2394
|
+
const inline = target.pseudo ? null : inlineEntry(session, element);
|
|
2395
|
+
if (inline)
|
|
2396
|
+
own.push(inline);
|
|
2397
|
+
own = settleContainers(own, read);
|
|
2398
|
+
const won = winners(own);
|
|
2399
|
+
markOwn(own, won);
|
|
2400
|
+
found2.blocks.push(...shown(own));
|
|
2401
|
+
if (!target.pseudo) {
|
|
2402
|
+
for (const name of PSEUDOS) {
|
|
2403
|
+
const entries = reached.get(name);
|
|
2404
|
+
if (!entries)
|
|
2405
|
+
continue;
|
|
2406
|
+
markOwn(entries, winners(entries));
|
|
2407
|
+
found2.blocks.push({ kind: "pseudo", pseudo: name, blocks: shown(entries).filter(isRule) });
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
const taken = new Map;
|
|
2411
|
+
for (const [longhand, winner] of won)
|
|
2412
|
+
taken.set(longhand, winner.candidate.id);
|
|
2413
|
+
const inherits = (property) => isInherited(property, session.registered);
|
|
2414
|
+
const handsNothing = (flat) => {
|
|
2415
|
+
flat.hands ??= listed(flat.rule.style).some(inherits);
|
|
2416
|
+
return !flat.hands;
|
|
2417
|
+
};
|
|
2418
|
+
let ancestor = target.pseudo ? element : flatParent(element);
|
|
2419
|
+
for (;ancestor; ancestor = flatParent(ancestor)) {
|
|
2420
|
+
const entries = entriesFor(session, ancestor, ONLY_ELEMENT, handsNothing).get(ELEMENT) ?? [];
|
|
2421
|
+
const attribute = inlineEntry(session, ancestor);
|
|
2422
|
+
if (attribute)
|
|
2423
|
+
entries.push(attribute);
|
|
2424
|
+
const kept = settleInherited(entries, taken, inherits);
|
|
2425
|
+
if (kept.length === 0)
|
|
2426
|
+
continue;
|
|
2427
|
+
found2.blocks.push({
|
|
2428
|
+
kind: "inherited",
|
|
2429
|
+
from: label(ancestor),
|
|
2430
|
+
element: ancestor,
|
|
2431
|
+
blocks: shown(kept)
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
const variables = {};
|
|
2435
|
+
for (const block of ownBlocks(found2.blocks)) {
|
|
2436
|
+
for (const declaration of block.declarations) {
|
|
2437
|
+
if (declaration.overridden)
|
|
2438
|
+
continue;
|
|
2439
|
+
for (const name of declaration.variables) {
|
|
2440
|
+
variables[name] ??= { value: read(name).trim(), definedIn: taken.get(name) ?? null };
|
|
2441
|
+
}
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
found2.variables = variables;
|
|
2445
|
+
for (const flat of session.ranks.keys()) {
|
|
2446
|
+
found2.hidden.push(...flat.hidden);
|
|
2447
|
+
found2.skipped += flat.skipped;
|
|
2448
|
+
}
|
|
2449
|
+
found2.skipped += session.threw;
|
|
2450
|
+
return found2;
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
// src/ui/boxdiagram.ts
|
|
2454
|
+
function readBox(element) {
|
|
2455
|
+
const view = element.ownerDocument.defaultView;
|
|
2456
|
+
if (!view || !element.isConnected)
|
|
2457
|
+
return null;
|
|
2458
|
+
const style = view.getComputedStyle(element);
|
|
2459
|
+
const model = boxModel(style);
|
|
2460
|
+
return { model, ...contentSize(model, style, element.getBoundingClientRect()) };
|
|
2461
|
+
}
|
|
2462
|
+
var DIAGRAM_RINGS = ["position", "margin", "border", "padding"];
|
|
2463
|
+
var COLUMN = 22;
|
|
2464
|
+
var CHAR = 6.5;
|
|
2465
|
+
var ROOM = 8;
|
|
2466
|
+
var CONTENT = 120;
|
|
2467
|
+
function lengths(reading, ring) {
|
|
2468
|
+
return ring === "position" ? reading.model.offsets : reading.model[ring];
|
|
2469
|
+
}
|
|
2470
|
+
function ringValues(reading, ring) {
|
|
2471
|
+
const found2 = lengths(reading, ring);
|
|
2472
|
+
if (!found2)
|
|
2473
|
+
return null;
|
|
2474
|
+
return {
|
|
2475
|
+
top: boxValue(found2.top),
|
|
2476
|
+
right: boxValue(found2.right),
|
|
2477
|
+
bottom: boxValue(found2.bottom),
|
|
2478
|
+
left: boxValue(found2.left)
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
function diagramNeeds(reading) {
|
|
2482
|
+
const column = (text) => Math.max(COLUMN, text.length * CHAR + ROOM);
|
|
2483
|
+
let needs = Math.max(CONTENT, sizeText(reading.width, reading.height).length * CHAR + ROOM);
|
|
2484
|
+
for (const ring of DIAGRAM_RINGS) {
|
|
2485
|
+
const values = ringValues(reading, ring);
|
|
2486
|
+
if (values)
|
|
2487
|
+
needs += column(values.left) + column(values.right);
|
|
2488
|
+
}
|
|
2489
|
+
return needs;
|
|
2490
|
+
}
|
|
2491
|
+
function boxFacts(model) {
|
|
2492
|
+
const facts = [`box-sizing: ${model.boxSizing}`, `display: ${model.display}`];
|
|
2493
|
+
if (model.position !== "static")
|
|
2494
|
+
facts.push(`position: ${model.position}`);
|
|
2495
|
+
return facts;
|
|
2496
|
+
}
|
|
2497
|
+
function say(node, text) {
|
|
2498
|
+
if (node.textContent !== text)
|
|
2499
|
+
node.textContent = text;
|
|
2500
|
+
}
|
|
2501
|
+
function createBoxDiagram(onArea) {
|
|
2502
|
+
const node = el("div", "box-model");
|
|
2503
|
+
const size = el("div", "bm-ring bm-content");
|
|
2504
|
+
const line = el("div", "bm-line");
|
|
2505
|
+
const lineName = el("span", "bm-name");
|
|
2506
|
+
const lineValues = el("span", "bm-values");
|
|
2507
|
+
line.append(lineName, lineValues);
|
|
2508
|
+
const facts = el("div", "bm-facts");
|
|
2509
|
+
const rings = new Map;
|
|
2510
|
+
let reading = null;
|
|
2511
|
+
let width = Number.POSITIVE_INFINITY;
|
|
2512
|
+
let hovered = null;
|
|
2513
|
+
let focused = null;
|
|
2514
|
+
let told = "margin";
|
|
2515
|
+
function active() {
|
|
2516
|
+
return focused ?? hovered;
|
|
2517
|
+
}
|
|
2518
|
+
function drawLine() {
|
|
2519
|
+
const values = reading ? ringValues(reading, told) : null;
|
|
2520
|
+
const shown2 = values ?? (reading ? ringValues(reading, "margin") : null);
|
|
2521
|
+
say(lineName, values ? told : "margin");
|
|
2522
|
+
say(lineValues, shown2 ? SIDES.map((side) => shown2[side]).join(" ") : "");
|
|
2523
|
+
}
|
|
2524
|
+
function changed() {
|
|
2525
|
+
const now = active();
|
|
2526
|
+
if (now && now !== "content")
|
|
2527
|
+
told = now;
|
|
2528
|
+
onArea(now === null || now === "position" ? null : now);
|
|
2529
|
+
drawLine();
|
|
2530
|
+
}
|
|
2531
|
+
function listen(area, name, around2) {
|
|
2532
|
+
area.tabIndex = 0;
|
|
2533
|
+
area.setAttribute("role", "group");
|
|
2534
|
+
area.addEventListener("pointerenter", () => {
|
|
2535
|
+
hovered = name;
|
|
2536
|
+
changed();
|
|
2537
|
+
});
|
|
2538
|
+
area.addEventListener("pointerleave", () => {
|
|
2539
|
+
hovered = around2;
|
|
2540
|
+
changed();
|
|
2541
|
+
});
|
|
2542
|
+
area.addEventListener("focus", () => {
|
|
2543
|
+
focused = name;
|
|
2544
|
+
changed();
|
|
2545
|
+
});
|
|
2546
|
+
area.addEventListener("blur", () => {
|
|
2547
|
+
focused = null;
|
|
2548
|
+
changed();
|
|
2549
|
+
});
|
|
2550
|
+
}
|
|
2551
|
+
let inner = size;
|
|
2552
|
+
listen(size, "content", "padding");
|
|
2553
|
+
for (const ring of [...DIAGRAM_RINGS].reverse()) {
|
|
2554
|
+
const area = el("div", `bm-ring bm-${ring}`);
|
|
2555
|
+
const values = {
|
|
2556
|
+
top: el("span", "bm-v bm-top"),
|
|
2557
|
+
right: el("span", "bm-v bm-right"),
|
|
2558
|
+
bottom: el("span", "bm-v bm-bottom"),
|
|
2559
|
+
left: el("span", "bm-v bm-left")
|
|
2560
|
+
};
|
|
2561
|
+
const name = el("span", "bm-name", ring);
|
|
2562
|
+
name.setAttribute("aria-hidden", "true");
|
|
2563
|
+
area.append(name, values.top, values.left, inner, values.right, values.bottom);
|
|
2564
|
+
const around2 = DIAGRAM_RINGS[DIAGRAM_RINGS.indexOf(ring) - 1] ?? null;
|
|
2565
|
+
listen(area, ring, around2);
|
|
2566
|
+
rings.set(ring, { node: area, values });
|
|
2567
|
+
inner = area;
|
|
2568
|
+
}
|
|
2569
|
+
node.append(inner, line, facts);
|
|
2570
|
+
node.setAttribute("role", "group");
|
|
2571
|
+
node.setAttribute("aria-label", "box model");
|
|
2572
|
+
function narrow() {
|
|
2573
|
+
node.classList.toggle("narrow", reading !== null && diagramNeeds(reading) > width);
|
|
2574
|
+
}
|
|
2575
|
+
function show(next) {
|
|
2576
|
+
reading = next;
|
|
2577
|
+
if (!next)
|
|
2578
|
+
return;
|
|
2579
|
+
for (const ring of DIAGRAM_RINGS) {
|
|
2580
|
+
const parts = rings.get(ring);
|
|
2581
|
+
if (!parts)
|
|
2582
|
+
continue;
|
|
2583
|
+
const values = ringValues(next, ring);
|
|
2584
|
+
parts.node.classList.toggle("off", values === null);
|
|
2585
|
+
parts.node.tabIndex = values === null ? -1 : 0;
|
|
2586
|
+
for (const side of SIDES)
|
|
2587
|
+
say(parts.values[side], values ? values[side] : "");
|
|
2588
|
+
const sides = values ? SIDES.map((side) => `${side} ${values[side]}`).join(", ") : "";
|
|
2589
|
+
parts.node.setAttribute("aria-label", values ? `${ring}: ${sides}` : ring);
|
|
2590
|
+
}
|
|
2591
|
+
const sized = sizeText(next.width, next.height);
|
|
2592
|
+
say(size, sized);
|
|
2593
|
+
size.setAttribute("aria-label", `content: ${sized}`);
|
|
2594
|
+
facts.replaceChildren(...boxFacts(next.model).map((fact) => el("span", "bm-fact", fact)));
|
|
2595
|
+
if (told === "position" && !next.model.offsets)
|
|
2596
|
+
told = "margin";
|
|
2597
|
+
drawLine();
|
|
2598
|
+
narrow();
|
|
2599
|
+
}
|
|
2600
|
+
return {
|
|
2601
|
+
node,
|
|
2602
|
+
show,
|
|
2603
|
+
fit(next) {
|
|
2604
|
+
width = next;
|
|
2605
|
+
narrow();
|
|
2606
|
+
}
|
|
2607
|
+
};
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
// src/ui/stylesapplied.ts
|
|
2611
|
+
var NO_STYLES = "no styles set on this element";
|
|
2612
|
+
var GROUPS = ["layout", "size and spacing", "text", "look", "motion", "other"];
|
|
2613
|
+
var EXACT = {
|
|
2614
|
+
display: "layout",
|
|
2615
|
+
position: "layout",
|
|
2616
|
+
top: "layout",
|
|
2617
|
+
right: "layout",
|
|
2618
|
+
bottom: "layout",
|
|
2619
|
+
left: "layout",
|
|
2620
|
+
"z-index": "layout",
|
|
2621
|
+
gap: "layout",
|
|
2622
|
+
"row-gap": "layout",
|
|
2623
|
+
"column-gap": "layout",
|
|
2624
|
+
order: "layout",
|
|
2625
|
+
float: "layout",
|
|
2626
|
+
width: "size and spacing",
|
|
2627
|
+
height: "size and spacing",
|
|
2628
|
+
"inline-size": "size and spacing",
|
|
2629
|
+
"block-size": "size and spacing",
|
|
2630
|
+
"box-sizing": "size and spacing",
|
|
2631
|
+
"aspect-ratio": "size and spacing",
|
|
2632
|
+
"line-height": "text",
|
|
2633
|
+
"letter-spacing": "text",
|
|
2634
|
+
"white-space": "text",
|
|
2635
|
+
"overflow-wrap": "text",
|
|
2636
|
+
color: "text",
|
|
2637
|
+
"box-shadow": "look",
|
|
2638
|
+
opacity: "look",
|
|
2639
|
+
filter: "look",
|
|
2640
|
+
"backdrop-filter": "look",
|
|
2641
|
+
"mix-blend-mode": "look",
|
|
2642
|
+
"will-change": "motion",
|
|
2643
|
+
translate: "motion",
|
|
2644
|
+
rotate: "motion",
|
|
2645
|
+
scale: "motion"
|
|
2646
|
+
};
|
|
2647
|
+
var STARTS = [
|
|
2648
|
+
["inset", "layout"],
|
|
2649
|
+
["flex", "layout"],
|
|
2650
|
+
["grid", "layout"],
|
|
2651
|
+
["align-", "layout"],
|
|
2652
|
+
["justify-", "layout"],
|
|
2653
|
+
["place-", "layout"],
|
|
2654
|
+
["overflow", "layout"],
|
|
2655
|
+
["min-", "size and spacing"],
|
|
2656
|
+
["max-", "size and spacing"],
|
|
2657
|
+
["margin", "size and spacing"],
|
|
2658
|
+
["padding", "size and spacing"],
|
|
2659
|
+
["font", "text"],
|
|
2660
|
+
["text-", "text"],
|
|
2661
|
+
["word-", "text"],
|
|
2662
|
+
["background", "look"],
|
|
2663
|
+
["border", "look"],
|
|
2664
|
+
["outline", "look"],
|
|
2665
|
+
["transition", "motion"],
|
|
2666
|
+
["animation", "motion"],
|
|
2667
|
+
["transform", "motion"]
|
|
2668
|
+
];
|
|
2669
|
+
var VENDOR = /^-(?:webkit|moz|ms|o)-/;
|
|
2670
|
+
function isCustom(name) {
|
|
2671
|
+
return name.startsWith("--");
|
|
2672
|
+
}
|
|
2673
|
+
function groupOf(name) {
|
|
2674
|
+
if (isCustom(name))
|
|
2675
|
+
return "other";
|
|
2676
|
+
const plain = name.toLowerCase().replace(VENDOR, "");
|
|
2677
|
+
const exact = Object.hasOwn(EXACT, plain) ? EXACT[plain] : undefined;
|
|
2678
|
+
if (exact)
|
|
2679
|
+
return exact;
|
|
2680
|
+
return STARTS.find(([start]) => plain.startsWith(start))?.[1] ?? "other";
|
|
2681
|
+
}
|
|
2682
|
+
function winning(block) {
|
|
2683
|
+
return block.declarations.flatMap((declaration) => declaration.overridden ? [] : [{ declaration, block }]);
|
|
2684
|
+
}
|
|
2685
|
+
function appliedOwn(found2) {
|
|
2686
|
+
return found2.blocks.flatMap((block) => block.kind === "inline" || block.kind === "rule" ? winning(block) : []);
|
|
2687
|
+
}
|
|
2688
|
+
function appliedInherited(found2) {
|
|
2689
|
+
const seen = new Set;
|
|
2690
|
+
const applied = [];
|
|
2691
|
+
for (const group of found2.blocks) {
|
|
2692
|
+
if (group.kind !== "inherited")
|
|
2693
|
+
continue;
|
|
2694
|
+
for (const one of group.blocks.flatMap(winning)) {
|
|
2695
|
+
if (seen.has(one.declaration.name))
|
|
2696
|
+
continue;
|
|
2697
|
+
seen.add(one.declaration.name);
|
|
2698
|
+
applied.push(one);
|
|
2699
|
+
}
|
|
2700
|
+
}
|
|
2701
|
+
return applied;
|
|
2702
|
+
}
|
|
2703
|
+
function grouped(lines) {
|
|
2704
|
+
return GROUPS.flatMap((group) => {
|
|
2705
|
+
const own = lines.filter((line) => groupOf(line.declaration.name) === group);
|
|
2706
|
+
if (own.length === 0)
|
|
2707
|
+
return [];
|
|
2708
|
+
const custom = own.filter((line) => isCustom(line.declaration.name));
|
|
2709
|
+
const rest = own.filter((line) => !isCustom(line.declaration.name));
|
|
2710
|
+
return [{ group, lines: [...rest, ...custom] }];
|
|
2711
|
+
});
|
|
2712
|
+
}
|
|
2713
|
+
function resolvedValue(value, variables) {
|
|
2714
|
+
if (varReferences(value).length === 0)
|
|
2715
|
+
return null;
|
|
2716
|
+
return resolveVars(value, (name) => variables[name]?.value ?? "");
|
|
2717
|
+
}
|
|
2718
|
+
function hiddenNote(hidden) {
|
|
2719
|
+
if (hidden.length === 0)
|
|
2720
|
+
return null;
|
|
2721
|
+
const why = hidden.some((one) => one.reason === "cross-origin") ? "a stylesheet from another origin" : "a stylesheet that could not be read";
|
|
2722
|
+
return `some styles are hidden: ${why}`;
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
// src/ui/stylesview.ts
|
|
2726
|
+
var SETTLE = 120;
|
|
2727
|
+
var FLASH = 900;
|
|
2728
|
+
var EMPTY = "pick an element to see its styles";
|
|
2729
|
+
var GONE = "the element left the page";
|
|
2730
|
+
var PICK = "select an element to see its styles";
|
|
2731
|
+
var GONE_PICK = "the element left the page, select another";
|
|
2732
|
+
var NO_RULES = "no rule reaches this element";
|
|
2733
|
+
var NO_MATCH = "no declaration matches";
|
|
2734
|
+
var READ_ONLY = "read only: the browser does not let a page read or edit a stylesheet from another origin, or its own default styles";
|
|
2735
|
+
var MODES = ["simple", "advanced"];
|
|
2736
|
+
function readVariable(element, pseudo, name) {
|
|
2737
|
+
try {
|
|
2738
|
+
const view = element.ownerDocument.defaultView;
|
|
2739
|
+
return view ? view.getComputedStyle(element, pseudo).getPropertyValue(name).trim() : "";
|
|
2740
|
+
} catch {
|
|
2741
|
+
return "";
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
function isColor(text) {
|
|
2745
|
+
try {
|
|
2746
|
+
return typeof CSS !== "undefined" && CSS.supports("color", text);
|
|
2747
|
+
} catch {
|
|
2748
|
+
return false;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
var PAGE = {
|
|
2752
|
+
inspect,
|
|
2753
|
+
invalidate,
|
|
2754
|
+
getState,
|
|
2755
|
+
subscribe,
|
|
2756
|
+
isColor,
|
|
2757
|
+
box: readBox,
|
|
2758
|
+
variable: readVariable
|
|
2759
|
+
};
|
|
2760
|
+
var BLANK = -1;
|
|
2761
|
+
var UNMATCHED = -2;
|
|
2762
|
+
var FORCE_LABEL = "force a state";
|
|
2763
|
+
function unmatched(rule, id) {
|
|
2764
|
+
return {
|
|
2765
|
+
kind: "rule",
|
|
2766
|
+
id,
|
|
2767
|
+
selectorText: rule.selectorText,
|
|
2768
|
+
selector: splitList(rule.selectorText).map((text) => ({ text, matches: false })),
|
|
2769
|
+
specificity: specificity(rule.selectorText),
|
|
2770
|
+
origin: { sheet: NEW_RULE_SHEET, owner: null, path: [0] },
|
|
2771
|
+
context: [],
|
|
2772
|
+
declarations: parseDeclarations(rule.style.cssText).map((written) => ({
|
|
2773
|
+
...written,
|
|
2774
|
+
longhands: [written.name],
|
|
2775
|
+
overridden: true,
|
|
2776
|
+
variables: variableNames(written.value)
|
|
2777
|
+
})),
|
|
2778
|
+
rule
|
|
2779
|
+
};
|
|
2780
|
+
}
|
|
2781
|
+
function isElement2(node) {
|
|
2782
|
+
return node.nodeType === 1;
|
|
2783
|
+
}
|
|
2784
|
+
function isOwn(record) {
|
|
2785
|
+
if (record.type !== "childList")
|
|
2786
|
+
return false;
|
|
2787
|
+
const nodes = [...Array.from(record.addedNodes), ...Array.from(record.removedNodes)];
|
|
2788
|
+
return nodes.length > 0 && nodes.every((node) => isElement2(node) && node.hasAttribute("data-devknobs"));
|
|
2789
|
+
}
|
|
2790
|
+
function knobsOf(state) {
|
|
2791
|
+
return JSON.stringify({ ...state, panel: null });
|
|
2792
|
+
}
|
|
2793
|
+
function createStylesView(context, page = PAGE) {
|
|
2794
|
+
const { tips } = context;
|
|
2795
|
+
const force = page.force ?? FORCING;
|
|
2796
|
+
const node = el("div", "styles");
|
|
2797
|
+
node.tabIndex = -1;
|
|
2798
|
+
const crumbs = el("div", "crumbs");
|
|
2799
|
+
crumbs.setAttribute("role", "group");
|
|
2800
|
+
crumbs.setAttribute("aria-label", "the element and its ancestors");
|
|
2801
|
+
const filter = filterField({
|
|
2802
|
+
placeholder: "filter",
|
|
2803
|
+
label: "filter the declarations",
|
|
2804
|
+
onInput: () => applyFilter()
|
|
2805
|
+
});
|
|
2806
|
+
let mode = context.mode?.get() ?? "advanced";
|
|
2807
|
+
const modes = context.mode ? segments({
|
|
2808
|
+
options: MODES.map((value) => ({ value, label: value })),
|
|
2809
|
+
label: "how the styles are shown",
|
|
2810
|
+
value: mode,
|
|
2811
|
+
onChange: setMode
|
|
2812
|
+
}) : null;
|
|
2813
|
+
const { select } = context;
|
|
2814
|
+
const picker = select ? toolToggle({
|
|
2815
|
+
label: select.label,
|
|
2816
|
+
icon: "square-dashed-mouse-pointer",
|
|
2817
|
+
on: select.on(),
|
|
2818
|
+
onPress: select.run
|
|
2819
|
+
}) : null;
|
|
2820
|
+
const again = select ? emptyAction(PICK, select.run) : null;
|
|
2821
|
+
if (select) {
|
|
2822
|
+
const told = () => [select.label, select.hint?.()].filter(Boolean).join(" · ");
|
|
2823
|
+
if (picker)
|
|
2824
|
+
tips.tooltip(picker.node, told);
|
|
2825
|
+
if (again)
|
|
2826
|
+
tips.tooltip(again, told);
|
|
2827
|
+
}
|
|
2828
|
+
const bar = toolbar([picker?.node, filter.node, modes?.node].filter((part) => part != null));
|
|
2829
|
+
const diagram = createBoxDiagram((ring) => context.area?.(ring));
|
|
2830
|
+
const box = sectionFold({
|
|
2831
|
+
label: "box",
|
|
2832
|
+
open: context.box?.get() ?? true,
|
|
2833
|
+
onToggle: (open2) => context.box?.set(open2)
|
|
2834
|
+
});
|
|
2835
|
+
box.body.append(diagram.node);
|
|
2836
|
+
diagram.node.addEventListener("pointerenter", () => point(target));
|
|
2837
|
+
diagram.node.addEventListener("pointerleave", () => point(null));
|
|
2838
|
+
const blocks = el("div", "css-blocks");
|
|
2839
|
+
const note = emptyLine(EMPTY);
|
|
2840
|
+
const log = context.edits ?? null;
|
|
2841
|
+
const chips = log ? el("div", "chips force-states") : null;
|
|
2842
|
+
const stateChips = new Map;
|
|
2843
|
+
if (chips) {
|
|
2844
|
+
chips.setAttribute("role", "group");
|
|
2845
|
+
chips.setAttribute("aria-label", FORCE_LABEL);
|
|
2846
|
+
for (const state of FORCED_STATES) {
|
|
2847
|
+
const chip = button("chip", `:${state}`);
|
|
2848
|
+
chip.setAttribute("aria-pressed", "false");
|
|
2849
|
+
chip.addEventListener("click", () => toggleState(state));
|
|
2850
|
+
stateChips.set(state, chip);
|
|
2851
|
+
chips.append(chip);
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
node.append(...[crumbs, bar, box.node, chips, blocks, note].filter((part) => part !== null));
|
|
2855
|
+
if (again)
|
|
2856
|
+
node.append(again);
|
|
2857
|
+
const fitter = typeof ResizeObserver === "undefined" ? null : new ResizeObserver((entries) => {
|
|
2858
|
+
const entry = entries[entries.length - 1];
|
|
2859
|
+
if (entry)
|
|
2860
|
+
diagram.fit(entry.contentRect.width);
|
|
2861
|
+
});
|
|
2862
|
+
fitter?.observe(diagram.node);
|
|
2863
|
+
let target = null;
|
|
2864
|
+
let pseudo = null;
|
|
2865
|
+
let pseudos = [];
|
|
2866
|
+
let read = null;
|
|
2867
|
+
let built = [];
|
|
2868
|
+
let flat = null;
|
|
2869
|
+
let unfolded = false;
|
|
2870
|
+
let byId = new Map;
|
|
2871
|
+
let tipped = [];
|
|
2872
|
+
let sources = new Map;
|
|
2873
|
+
let observer = null;
|
|
2874
|
+
let sizes = null;
|
|
2875
|
+
let watched = null;
|
|
2876
|
+
let stale = false;
|
|
2877
|
+
let knobs = knobsOf(page.getState());
|
|
2878
|
+
let timer = 0;
|
|
2879
|
+
let flashTimer = 0;
|
|
2880
|
+
let lit = null;
|
|
2881
|
+
let said2 = { text: null, press: null };
|
|
2882
|
+
const unpick = select?.watch(() => {
|
|
2883
|
+
picker?.set(select.on());
|
|
2884
|
+
drawSaid();
|
|
2885
|
+
}) ?? null;
|
|
2886
|
+
let waiting = false;
|
|
2887
|
+
const editor = log ? createCssEditor({
|
|
2888
|
+
log,
|
|
2889
|
+
node,
|
|
2890
|
+
locate: context.locate,
|
|
2891
|
+
settled() {
|
|
2892
|
+
if (!waiting)
|
|
2893
|
+
return;
|
|
2894
|
+
waiting = false;
|
|
2895
|
+
refresh();
|
|
2896
|
+
}
|
|
2897
|
+
}) : null;
|
|
2898
|
+
let pointed = null;
|
|
2899
|
+
let pointing = false;
|
|
2900
|
+
function statesHere() {
|
|
2901
|
+
const forced = force.state();
|
|
2902
|
+
return target && forced?.element === target ? forced.states : [];
|
|
2903
|
+
}
|
|
2904
|
+
function drawChips() {
|
|
2905
|
+
if (!chips)
|
|
2906
|
+
return;
|
|
2907
|
+
chips.hidden = target === null || bar.hidden;
|
|
2908
|
+
const states = statesHere();
|
|
2909
|
+
for (const [state, chip] of stateChips) {
|
|
2910
|
+
const on = states.includes(state);
|
|
2911
|
+
chip.classList.toggle("on", on);
|
|
2912
|
+
chip.setAttribute("aria-pressed", on ? "true" : "false");
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
function toggleState(state) {
|
|
2916
|
+
if (!target)
|
|
2917
|
+
return;
|
|
2918
|
+
const states = statesHere();
|
|
2919
|
+
force.set(target, states.includes(state) ? states.filter((one) => one !== state) : [...states, state]);
|
|
2920
|
+
drawChips();
|
|
2921
|
+
refresh();
|
|
2922
|
+
}
|
|
2923
|
+
function unforce(element) {
|
|
2924
|
+
if (element && force.state()?.element === element)
|
|
2925
|
+
force.clear();
|
|
2926
|
+
}
|
|
2927
|
+
function point(element) {
|
|
2928
|
+
if (!element && !pointing)
|
|
2929
|
+
return;
|
|
2930
|
+
pointing = element !== null;
|
|
2931
|
+
context.outline(element);
|
|
2932
|
+
}
|
|
2933
|
+
function later() {
|
|
2934
|
+
clearTimeout(timer);
|
|
2935
|
+
timer = window.setTimeout(refresh, SETTLE);
|
|
2936
|
+
}
|
|
2937
|
+
function onMutations(records) {
|
|
2938
|
+
const theirs = records.filter((record) => !isOwn(record));
|
|
2939
|
+
if (theirs.length === 0)
|
|
2940
|
+
return;
|
|
2941
|
+
const head = target?.ownerDocument.head;
|
|
2942
|
+
if (head && theirs.some((record) => head.contains(record.target)))
|
|
2943
|
+
stale = true;
|
|
2944
|
+
later();
|
|
2945
|
+
}
|
|
2946
|
+
function drawBox() {
|
|
2947
|
+
const reading = target && pseudo === null && target.isConnected ? page.box(target) : null;
|
|
2948
|
+
box.node.hidden = reading === null;
|
|
2949
|
+
diagram.show(reading);
|
|
2950
|
+
}
|
|
2951
|
+
function unwatch() {
|
|
2952
|
+
observer?.disconnect();
|
|
2953
|
+
observer = null;
|
|
2954
|
+
sizes?.disconnect();
|
|
2955
|
+
sizes = null;
|
|
2956
|
+
watched?.removeEventListener("resize", later);
|
|
2957
|
+
watched = null;
|
|
2958
|
+
}
|
|
2959
|
+
function watch(element) {
|
|
2960
|
+
unwatch();
|
|
2961
|
+
observer = new MutationObserver(onMutations);
|
|
2962
|
+
observer.observe(element, { attributes: true });
|
|
2963
|
+
for (let up = flatParent(element);up; up = flatParent(up)) {
|
|
2964
|
+
observer.observe(up, { attributes: true, childList: true });
|
|
2965
|
+
}
|
|
2966
|
+
const head = element.ownerDocument.head;
|
|
2967
|
+
if (head) {
|
|
2968
|
+
observer.observe(head, {
|
|
2969
|
+
attributes: true,
|
|
2970
|
+
characterData: true,
|
|
2971
|
+
childList: true,
|
|
2972
|
+
subtree: true
|
|
2973
|
+
});
|
|
2974
|
+
}
|
|
2975
|
+
watched = element.ownerDocument.defaultView;
|
|
2976
|
+
watched?.addEventListener("resize", later);
|
|
2977
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
2978
|
+
sizes = new ResizeObserver(drawBox);
|
|
2979
|
+
sizes.observe(element);
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
function say2(text, press = null) {
|
|
2983
|
+
said2 = { text, press };
|
|
2984
|
+
drawSaid();
|
|
2985
|
+
}
|
|
2986
|
+
function drawSaid() {
|
|
2987
|
+
const { text, press } = said2;
|
|
2988
|
+
const asks = again !== null && press !== null && select?.on() === false;
|
|
2989
|
+
note.hidden = text === null || asks;
|
|
2990
|
+
if (text !== null)
|
|
2991
|
+
note.textContent = text;
|
|
2992
|
+
if (!again)
|
|
2993
|
+
return;
|
|
2994
|
+
again.hidden = !asks;
|
|
2995
|
+
if (press !== null)
|
|
2996
|
+
again.textContent = press;
|
|
2997
|
+
}
|
|
2998
|
+
function tip(control, text) {
|
|
2999
|
+
tips.tooltip(control, text);
|
|
3000
|
+
tipped.push(control);
|
|
3001
|
+
}
|
|
3002
|
+
function dropTips() {
|
|
3003
|
+
if (tipped.some((control) => tips.isFor(control)))
|
|
3004
|
+
tips.hide();
|
|
3005
|
+
tipped = [];
|
|
3006
|
+
}
|
|
3007
|
+
function clear(text, press) {
|
|
3008
|
+
dropTips();
|
|
3009
|
+
read = null;
|
|
3010
|
+
sources = new Map;
|
|
3011
|
+
built = [];
|
|
3012
|
+
editor?.begin();
|
|
3013
|
+
flat = null;
|
|
3014
|
+
byId = new Map;
|
|
3015
|
+
blocks.replaceChildren();
|
|
3016
|
+
crumbs.replaceChildren();
|
|
3017
|
+
crumbs.hidden = true;
|
|
3018
|
+
bar.hidden = true;
|
|
3019
|
+
drawChips();
|
|
3020
|
+
drawBox();
|
|
3021
|
+
say2(text, press);
|
|
3022
|
+
}
|
|
3023
|
+
function link(className, text, go) {
|
|
3024
|
+
const control = button(className, text);
|
|
3025
|
+
control.addEventListener("click", go);
|
|
3026
|
+
return control;
|
|
3027
|
+
}
|
|
3028
|
+
function onCrumbKey(event) {
|
|
3029
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
|
|
3030
|
+
return;
|
|
3031
|
+
const all = Array.from(crumbs.querySelectorAll("button"));
|
|
3032
|
+
const at = all.findIndex((crumb) => crumb.tabIndex === 0);
|
|
3033
|
+
const next = all[at + (event.key === "ArrowRight" ? 1 : -1)];
|
|
3034
|
+
const current = all[at];
|
|
3035
|
+
if (!next || !current)
|
|
3036
|
+
return;
|
|
3037
|
+
event.preventDefault();
|
|
3038
|
+
event.stopPropagation();
|
|
3039
|
+
current.tabIndex = -1;
|
|
3040
|
+
next.tabIndex = 0;
|
|
3041
|
+
next.focus({ preventScroll: true });
|
|
3042
|
+
next.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
3043
|
+
}
|
|
3044
|
+
crumbs.addEventListener("keydown", onCrumbKey);
|
|
3045
|
+
function drawCrumbs(element) {
|
|
3046
|
+
const chain = [];
|
|
3047
|
+
for (let up = element;up; up = flatParent(up))
|
|
3048
|
+
chain.unshift(up);
|
|
3049
|
+
const nodes = [];
|
|
3050
|
+
const add = (text, current, of, go) => {
|
|
3051
|
+
if (nodes.length > 0) {
|
|
3052
|
+
const mark2 = el("span", "crumb-sep", "›");
|
|
3053
|
+
mark2.setAttribute("aria-hidden", "true");
|
|
3054
|
+
nodes.push(mark2);
|
|
3055
|
+
}
|
|
3056
|
+
const crumb = link("crumb", text, go);
|
|
3057
|
+
crumb.addEventListener("pointerenter", () => {
|
|
3058
|
+
pointed = crumb;
|
|
3059
|
+
point(of);
|
|
3060
|
+
});
|
|
3061
|
+
crumb.addEventListener("pointerleave", () => {
|
|
3062
|
+
pointed = null;
|
|
3063
|
+
point(null);
|
|
3064
|
+
});
|
|
3065
|
+
crumb.tabIndex = current ? 0 : -1;
|
|
3066
|
+
if (current)
|
|
3067
|
+
crumb.setAttribute("aria-current", "true");
|
|
3068
|
+
nodes.push(crumb);
|
|
3069
|
+
};
|
|
3070
|
+
for (const one of chain) {
|
|
3071
|
+
add(crumbText(label(one)), one === element && pseudo === null, one, () => show(one));
|
|
3072
|
+
}
|
|
3073
|
+
for (const name of pseudos)
|
|
3074
|
+
add(name, name === pseudo, element, () => show(element, name));
|
|
3075
|
+
if (pointed)
|
|
3076
|
+
point(null);
|
|
3077
|
+
pointed = null;
|
|
3078
|
+
crumbs.replaceChildren(...nodes);
|
|
3079
|
+
crumbs.scrollLeft = crumbs.scrollWidth;
|
|
3080
|
+
}
|
|
3081
|
+
function flash(id) {
|
|
3082
|
+
const block = byId.get(id);
|
|
3083
|
+
if (!block || block.hidden)
|
|
3084
|
+
return;
|
|
3085
|
+
clearTimeout(flashTimer);
|
|
3086
|
+
lit?.classList.remove("flash");
|
|
3087
|
+
block.scrollIntoView({ block: "nearest" });
|
|
3088
|
+
block.offsetWidth;
|
|
3089
|
+
block.classList.add("flash");
|
|
3090
|
+
lit = block;
|
|
3091
|
+
flashTimer = window.setTimeout(() => block.classList.remove("flash"), FLASH);
|
|
3092
|
+
}
|
|
3093
|
+
function swatchNode(color) {
|
|
3094
|
+
const swatch = el("span", "css-swatch");
|
|
3095
|
+
swatch.setAttribute("aria-hidden", "true");
|
|
3096
|
+
swatch.style.backgroundColor = color;
|
|
3097
|
+
return swatch;
|
|
3098
|
+
}
|
|
3099
|
+
function sourceOfVariable(name) {
|
|
3100
|
+
if (!read)
|
|
3101
|
+
return null;
|
|
3102
|
+
let source = sources.get(name);
|
|
3103
|
+
if (source === undefined) {
|
|
3104
|
+
source = declaredIn(read.found, name);
|
|
3105
|
+
sources.set(name, source);
|
|
3106
|
+
}
|
|
3107
|
+
return source;
|
|
3108
|
+
}
|
|
3109
|
+
function variableSaid(name, fallback) {
|
|
3110
|
+
const element = target;
|
|
3111
|
+
const seen = (one) => element ? page.variable(element, pseudo, one) : "";
|
|
3112
|
+
const said3 = variableTip({ name, fallback }, seen, sourceOfVariable(name), page.isColor);
|
|
3113
|
+
const box2 = el("span", "tip-lines");
|
|
3114
|
+
said3.lines.forEach((text, index) => {
|
|
3115
|
+
const row = el("span", "tip-line");
|
|
3116
|
+
if (index === 0 && said3.color)
|
|
3117
|
+
row.append(swatchNode(said3.color));
|
|
3118
|
+
row.append(text);
|
|
3119
|
+
box2.append(row);
|
|
3120
|
+
});
|
|
3121
|
+
if (said3.source !== null)
|
|
3122
|
+
box2.append(el("span", "tip-line tip-quiet", said3.source));
|
|
3123
|
+
return box2;
|
|
3124
|
+
}
|
|
3125
|
+
function variable(name, fallback, className = "css-var") {
|
|
3126
|
+
const control = button(className, name);
|
|
3127
|
+
tip(control, () => variableSaid(name, fallback));
|
|
3128
|
+
return control;
|
|
3129
|
+
}
|
|
3130
|
+
function mark(text) {
|
|
3131
|
+
return el("span", "css-punct", text);
|
|
3132
|
+
}
|
|
3133
|
+
function named(row, declaration, variables) {
|
|
3134
|
+
const { name } = declaration;
|
|
3135
|
+
row.append(name.startsWith("--") ? variable(name, null, "css-name css-var") : el("span", "css-name", name), mark(": "));
|
|
3136
|
+
const color = swatchOf(declaration, variables, page.isColor);
|
|
3137
|
+
if (color)
|
|
3138
|
+
row.append(swatchNode(color));
|
|
3139
|
+
}
|
|
3140
|
+
function valueNode(declaration, variables) {
|
|
3141
|
+
const value = el("span", "css-value");
|
|
3142
|
+
for (const part of valueParts(declaration.value)) {
|
|
3143
|
+
if (part.kind !== "var") {
|
|
3144
|
+
value.append(part.text);
|
|
3145
|
+
continue;
|
|
3146
|
+
}
|
|
3147
|
+
const control = variable(part.text, part.fallback ?? null);
|
|
3148
|
+
const definedIn = variables?.[part.text]?.definedIn ?? null;
|
|
3149
|
+
if (definedIn !== null)
|
|
3150
|
+
control.addEventListener("click", () => flash(definedIn));
|
|
3151
|
+
value.append(control);
|
|
3152
|
+
}
|
|
3153
|
+
return value;
|
|
3154
|
+
}
|
|
3155
|
+
function line(declaration, variables, place = null, off = null) {
|
|
3156
|
+
const row = el(declaration.overridden ? "s" : "div", "css-decl");
|
|
3157
|
+
named(row, declaration, variables);
|
|
3158
|
+
const value = valueNode(declaration, variables);
|
|
3159
|
+
row.append(value);
|
|
3160
|
+
if (declaration.important)
|
|
3161
|
+
row.append(" !important");
|
|
3162
|
+
row.append(mark(";"));
|
|
3163
|
+
if (place)
|
|
3164
|
+
editor?.editable(row, value, declaration, place, off);
|
|
3165
|
+
return { node: row, declaration };
|
|
3166
|
+
}
|
|
3167
|
+
function blockLines(block, variables, place) {
|
|
3168
|
+
const lines = block.declarations.map((declaration) => line(declaration, variables, place));
|
|
3169
|
+
if (!place || !editor)
|
|
3170
|
+
return lines;
|
|
3171
|
+
for (const off of editor.offs(place)) {
|
|
3172
|
+
const at = off.index < 0 ? lines.length : Math.min(off.index, lines.length);
|
|
3173
|
+
lines.splice(at, 0, line(offDeclaration(off), variables, place, off));
|
|
3174
|
+
}
|
|
3175
|
+
return lines;
|
|
3176
|
+
}
|
|
3177
|
+
function blockNode(block, found2, group, owner) {
|
|
3178
|
+
const section = el("section", "css-block");
|
|
3179
|
+
section.setAttribute("role", "region");
|
|
3180
|
+
const head = el("div", "css-head");
|
|
3181
|
+
const selector = el("span", "css-selector");
|
|
3182
|
+
if (block.kind === "inline") {
|
|
3183
|
+
section.setAttribute("aria-label", "element.style");
|
|
3184
|
+
selector.textContent = "element.style";
|
|
3185
|
+
head.append(selector);
|
|
3186
|
+
} else {
|
|
3187
|
+
section.setAttribute("aria-label", block.selectorText);
|
|
3188
|
+
for (const context2 of block.context)
|
|
3189
|
+
section.append(el("div", "css-context", context2));
|
|
3190
|
+
block.selector.forEach((part, index) => {
|
|
3191
|
+
if (index > 0)
|
|
3192
|
+
selector.append(", ");
|
|
3193
|
+
selector.append(el("span", part.matches ? "css-part" : "css-part off", part.text));
|
|
3194
|
+
});
|
|
3195
|
+
const from = el("span", "css-from");
|
|
3196
|
+
if (block.conditional && !block.conditional.confirmed) {
|
|
3197
|
+
const { kind } = block.conditional;
|
|
3198
|
+
const mark2 = el("span", "css-mark", kind);
|
|
3199
|
+
tip(mark2, `could not tell whether its @${kind} holds for the element`);
|
|
3200
|
+
from.append(mark2);
|
|
3201
|
+
}
|
|
3202
|
+
const source = sourceOf(block.origin);
|
|
3203
|
+
const file = el("span", "css-source", source.text);
|
|
3204
|
+
tip(file, source.tip);
|
|
3205
|
+
from.append(file);
|
|
3206
|
+
head.append(selector, from);
|
|
3207
|
+
}
|
|
3208
|
+
section.append(head);
|
|
3209
|
+
const place = editor?.placeOf(block, owner) ?? null;
|
|
3210
|
+
const lines = blockLines(block, found2.variables, place);
|
|
3211
|
+
section.append(...lines.map((one) => one.node));
|
|
3212
|
+
if (place && editor)
|
|
3213
|
+
section.append(editor.addLine(place));
|
|
3214
|
+
byId.set(block.id, section);
|
|
3215
|
+
return { node: section, lines, group, blank: block.id === BLANK };
|
|
3216
|
+
}
|
|
3217
|
+
function drawBlocks(found2, element) {
|
|
3218
|
+
dropTips();
|
|
3219
|
+
built = [];
|
|
3220
|
+
editor?.begin();
|
|
3221
|
+
byId = new Map;
|
|
3222
|
+
const nodes = [];
|
|
3223
|
+
const add = (block, group, owner = element) => {
|
|
3224
|
+
const made3 = blockNode(block, found2, group, owner);
|
|
3225
|
+
built.push(made3);
|
|
3226
|
+
nodes.push(made3.node);
|
|
3227
|
+
};
|
|
3228
|
+
let placed = false;
|
|
3229
|
+
const placeNew = () => {
|
|
3230
|
+
if (placed || !editor || pseudo !== null)
|
|
3231
|
+
return;
|
|
3232
|
+
placed = true;
|
|
3233
|
+
const listed2 = new Set(found2.blocks.flatMap((block) => block.kind === "rule" ? [block.rule] : []));
|
|
3234
|
+
newRules(element).forEach((rule, index) => {
|
|
3235
|
+
if (!listed2.has(rule))
|
|
3236
|
+
add(unmatched(rule, UNMATCHED - index), null);
|
|
3237
|
+
});
|
|
3238
|
+
nodes.push(editor.newRuleLine(element, newRuleSelector(element, statesHere())));
|
|
3239
|
+
};
|
|
3240
|
+
const each = (block) => {
|
|
3241
|
+
if (block.kind === "inherited" || block.kind === "pseudo")
|
|
3242
|
+
placeNew();
|
|
3243
|
+
if (block.kind === "inherited") {
|
|
3244
|
+
const from = block.element;
|
|
3245
|
+
const head = link("css-group", `inherited from ${crumbText(block.from)}`, () => show(from));
|
|
3246
|
+
nodes.push(head);
|
|
3247
|
+
for (const own of block.blocks)
|
|
3248
|
+
add(own, head, from);
|
|
3249
|
+
} else if (block.kind === "pseudo") {
|
|
3250
|
+
const name = block.pseudo;
|
|
3251
|
+
const head = link("css-group", name, () => show(element, name));
|
|
3252
|
+
nodes.push(head);
|
|
3253
|
+
for (const own of block.blocks)
|
|
3254
|
+
add(own, head);
|
|
3255
|
+
} else
|
|
3256
|
+
add(block, null);
|
|
3257
|
+
};
|
|
3258
|
+
if (log && pseudo === null && styleOf(element) && !found2.blocks.some((block) => block.kind === "inline")) {
|
|
3259
|
+
add({ kind: "inline", id: BLANK, declarations: [], element }, null);
|
|
3260
|
+
}
|
|
3261
|
+
found2.blocks.forEach(each);
|
|
3262
|
+
placeNew();
|
|
3263
|
+
for (const hidden of found2.hidden)
|
|
3264
|
+
nodes.push(readOnly(el("div", "css-hidden", hiddenLine(hidden))));
|
|
3265
|
+
blocks.replaceChildren(...nodes);
|
|
3266
|
+
}
|
|
3267
|
+
function appliedLine({ declaration }, variables, place = null, off = null) {
|
|
3268
|
+
const row = el(off ? "s" : "div", "css-decl");
|
|
3269
|
+
named(row, declaration, variables);
|
|
3270
|
+
const value = valueNode(declaration);
|
|
3271
|
+
row.append(value, mark(";"));
|
|
3272
|
+
const comes = off ? null : resolvedValue(declaration.value, variables);
|
|
3273
|
+
if (comes !== null)
|
|
3274
|
+
row.append(el("span", "css-comes", ` → ${comes}`));
|
|
3275
|
+
if (place)
|
|
3276
|
+
editor?.editable(row, value, declaration, place, off);
|
|
3277
|
+
return { node: row, declaration };
|
|
3278
|
+
}
|
|
3279
|
+
function newRules(element) {
|
|
3280
|
+
return log ? newRulesFor(log.recorded(), element) : [];
|
|
3281
|
+
}
|
|
3282
|
+
function readOnly(line2) {
|
|
3283
|
+
if (log)
|
|
3284
|
+
tip(line2, READ_ONLY);
|
|
3285
|
+
return line2;
|
|
3286
|
+
}
|
|
3287
|
+
function drawApplied(found2, element) {
|
|
3288
|
+
dropTips();
|
|
3289
|
+
built = [];
|
|
3290
|
+
editor?.begin();
|
|
3291
|
+
byId = new Map;
|
|
3292
|
+
const places = new Map;
|
|
3293
|
+
const offs = new Map;
|
|
3294
|
+
const mine = new Set(editor && pseudo === null ? newRules(element) : []);
|
|
3295
|
+
const applied = appliedOwn(found2).filter((one) => one.block.kind !== "rule" || !mine.has(one.block.rule));
|
|
3296
|
+
for (const one of applied)
|
|
3297
|
+
places.set(one.declaration, editor?.placeOf(one.block, element) ?? null);
|
|
3298
|
+
let inline = found2.blocks.find((block) => block.kind === "inline");
|
|
3299
|
+
if (log && pseudo === null && !inline && styleOf(element))
|
|
3300
|
+
inline = { kind: "inline", id: BLANK, declarations: [], element };
|
|
3301
|
+
if (log) {
|
|
3302
|
+
const owned = found2.blocks.filter((block) => block.kind === "rule" && !mine.has(block.rule));
|
|
3303
|
+
for (const block of inline ? [inline, ...owned] : owned) {
|
|
3304
|
+
const place = editor?.placeOf(block, element);
|
|
3305
|
+
if (!place || !editor)
|
|
3306
|
+
continue;
|
|
3307
|
+
for (const off of editor.offs(place)) {
|
|
3308
|
+
const declaration = offDeclaration(off);
|
|
3309
|
+
places.set(declaration, place);
|
|
3310
|
+
offs.set(declaration, off);
|
|
3311
|
+
applied.push({ declaration, block });
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
const addTo = inline && pseudo === null ? editor?.placeOf(inline, element) ?? null : null;
|
|
3316
|
+
const groups = grouped(applied);
|
|
3317
|
+
const own = groups.length > 0 || addTo ? el("div", "css-block css-applied") : emptyLine(NO_STYLES);
|
|
3318
|
+
const sets = groups.map(({ group, lines }) => {
|
|
3319
|
+
const set = el("div", "css-set");
|
|
3320
|
+
set.setAttribute("role", "group");
|
|
3321
|
+
set.setAttribute("aria-label", group);
|
|
3322
|
+
const name = groups.length > 1 ? el("div", "css-label", group) : null;
|
|
3323
|
+
if (name)
|
|
3324
|
+
name.setAttribute("aria-hidden", "true");
|
|
3325
|
+
const made3 = lines.map((one) => appliedLine(one, found2.variables, places.get(one.declaration) ?? null, offs.get(one.declaration) ?? null));
|
|
3326
|
+
set.append(...name ? [name] : [], ...made3.map((one) => one.node));
|
|
3327
|
+
own.append(set);
|
|
3328
|
+
return { node: set, label: name, lines: made3 };
|
|
3329
|
+
});
|
|
3330
|
+
if (addTo && editor)
|
|
3331
|
+
own.append(editor.addLine(addTo));
|
|
3332
|
+
const nodes = [own];
|
|
3333
|
+
const rules = [];
|
|
3334
|
+
if (editor && pseudo === null) {
|
|
3335
|
+
newRules(element).forEach((rule, index) => {
|
|
3336
|
+
const block = found2.blocks.find((one) => one.kind === "rule" && one.rule === rule);
|
|
3337
|
+
const made3 = blockNode(block ?? unmatched(rule, UNMATCHED - index), found2, null, element);
|
|
3338
|
+
rules.push(made3);
|
|
3339
|
+
nodes.push(made3.node);
|
|
3340
|
+
});
|
|
3341
|
+
nodes.push(editor.newRuleLine(element, newRuleSelector(element, statesHere())));
|
|
3342
|
+
}
|
|
3343
|
+
const handed = appliedInherited(found2);
|
|
3344
|
+
flat = { own, sets, rules, inherited: null };
|
|
3345
|
+
if (handed.length > 0) {
|
|
3346
|
+
const fold = sectionFold({
|
|
3347
|
+
label: "inherited",
|
|
3348
|
+
open: unfolded,
|
|
3349
|
+
onToggle: (open2) => {
|
|
3350
|
+
unfolded = open2;
|
|
3351
|
+
}
|
|
3352
|
+
});
|
|
3353
|
+
const body = el("div", "css-applied");
|
|
3354
|
+
body.setAttribute("role", "group");
|
|
3355
|
+
body.setAttribute("aria-label", "inherited");
|
|
3356
|
+
const lines = handed.map((one) => appliedLine(one, found2.variables));
|
|
3357
|
+
body.append(...lines.map((one) => one.node));
|
|
3358
|
+
fold.body.append(body);
|
|
3359
|
+
flat.inherited = { fold, lines };
|
|
3360
|
+
nodes.push(fold.node);
|
|
3361
|
+
}
|
|
3362
|
+
const hidden = hiddenNote(found2.hidden);
|
|
3363
|
+
if (hidden !== null)
|
|
3364
|
+
nodes.push(readOnly(el("div", "css-hidden", hidden)));
|
|
3365
|
+
blocks.replaceChildren(...nodes);
|
|
3366
|
+
}
|
|
3367
|
+
function filterApplied(view) {
|
|
3368
|
+
const text = filter.node.value;
|
|
3369
|
+
const filtering = text.trim() !== "";
|
|
3370
|
+
const keeps = (lines) => {
|
|
3371
|
+
let kept = false;
|
|
3372
|
+
for (const one of lines) {
|
|
3373
|
+
const matches2 = matchesFilter(one.declaration, text);
|
|
3374
|
+
one.node.hidden = !matches2;
|
|
3375
|
+
if (matches2)
|
|
3376
|
+
kept = true;
|
|
3377
|
+
}
|
|
3378
|
+
return kept;
|
|
3379
|
+
};
|
|
3380
|
+
let shown2 = 0;
|
|
3381
|
+
for (const set of view.sets) {
|
|
3382
|
+
const kept = keeps(set.lines);
|
|
3383
|
+
set.node.hidden = !kept;
|
|
3384
|
+
if (kept)
|
|
3385
|
+
shown2 += 1;
|
|
3386
|
+
}
|
|
3387
|
+
for (const set of view.sets)
|
|
3388
|
+
if (set.label)
|
|
3389
|
+
set.label.hidden = shown2 < 2;
|
|
3390
|
+
view.own.hidden = view.sets.length === 0 ? filtering : shown2 === 0;
|
|
3391
|
+
let ruled = false;
|
|
3392
|
+
for (const block of view.rules) {
|
|
3393
|
+
const kept = keeps(block.lines) || !filtering;
|
|
3394
|
+
block.node.hidden = !kept;
|
|
3395
|
+
if (kept)
|
|
3396
|
+
ruled = true;
|
|
3397
|
+
}
|
|
3398
|
+
const inherited = view.inherited;
|
|
3399
|
+
const handed = inherited ? keeps(inherited.lines) : false;
|
|
3400
|
+
if (inherited)
|
|
3401
|
+
inherited.fold.node.hidden = !handed;
|
|
3402
|
+
say2(filtering && shown2 === 0 && !handed && !ruled ? NO_MATCH : null);
|
|
3403
|
+
}
|
|
3404
|
+
function applyFilter() {
|
|
3405
|
+
if (flat) {
|
|
3406
|
+
filterApplied(flat);
|
|
3407
|
+
return;
|
|
3408
|
+
}
|
|
3409
|
+
const text = filter.node.value;
|
|
3410
|
+
const filtering = text.trim() !== "";
|
|
3411
|
+
const groups = new Map;
|
|
3412
|
+
let any = false;
|
|
3413
|
+
for (const block of built) {
|
|
3414
|
+
if (block.blank && block.lines.length === 0) {
|
|
3415
|
+
block.node.hidden = filtering;
|
|
3416
|
+
continue;
|
|
3417
|
+
}
|
|
3418
|
+
let kept = !filtering;
|
|
3419
|
+
for (const one of block.lines) {
|
|
3420
|
+
const matches2 = matchesFilter(one.declaration, text);
|
|
3421
|
+
one.node.hidden = !matches2;
|
|
3422
|
+
if (matches2)
|
|
3423
|
+
kept = true;
|
|
3424
|
+
}
|
|
3425
|
+
block.node.hidden = !kept;
|
|
3426
|
+
if (kept)
|
|
3427
|
+
any = true;
|
|
3428
|
+
if (block.group)
|
|
3429
|
+
groups.set(block.group, (groups.get(block.group) ?? false) || kept);
|
|
3430
|
+
}
|
|
3431
|
+
for (const [head, kept] of groups)
|
|
3432
|
+
head.hidden = !kept;
|
|
3433
|
+
const drawn = built.filter((block) => !block.blank || block.lines.length > 0);
|
|
3434
|
+
say2(any ? null : drawn.length === 0 ? NO_RULES : NO_MATCH);
|
|
3435
|
+
}
|
|
3436
|
+
function refresh() {
|
|
3437
|
+
clearTimeout(timer);
|
|
3438
|
+
timer = 0;
|
|
3439
|
+
const element = target;
|
|
3440
|
+
if (!element)
|
|
3441
|
+
return;
|
|
3442
|
+
if (editor?.busy()) {
|
|
3443
|
+
waiting = true;
|
|
3444
|
+
return;
|
|
3445
|
+
}
|
|
3446
|
+
if (stale) {
|
|
3447
|
+
stale = false;
|
|
3448
|
+
page.invalidate();
|
|
3449
|
+
}
|
|
3450
|
+
if (!element.isConnected || !element.ownerDocument.defaultView) {
|
|
3451
|
+
unforce(element);
|
|
3452
|
+
target = null;
|
|
3453
|
+
unwatch();
|
|
3454
|
+
point(null);
|
|
3455
|
+
context.held?.(null);
|
|
3456
|
+
clear(GONE, GONE_PICK);
|
|
3457
|
+
return;
|
|
3458
|
+
}
|
|
3459
|
+
if (force.on())
|
|
3460
|
+
force.sync();
|
|
3461
|
+
const found2 = page.inspect(element, pseudo ?? undefined);
|
|
3462
|
+
if (pseudo === null) {
|
|
3463
|
+
pseudos = found2.blocks.flatMap((block) => block.kind === "pseudo" ? [block.pseudo] : []);
|
|
3464
|
+
}
|
|
3465
|
+
crumbs.hidden = false;
|
|
3466
|
+
bar.hidden = false;
|
|
3467
|
+
drawChips();
|
|
3468
|
+
context.title(middle(`${found2.target.label}${found2.target.pseudo ?? ""}`, TITLE_MAX));
|
|
3469
|
+
drawCrumbs(element);
|
|
3470
|
+
drawBox();
|
|
3471
|
+
read = { found: found2, element };
|
|
3472
|
+
sources = new Map;
|
|
3473
|
+
draw();
|
|
3474
|
+
}
|
|
3475
|
+
function draw() {
|
|
3476
|
+
if (!read)
|
|
3477
|
+
return;
|
|
3478
|
+
flat = null;
|
|
3479
|
+
if (mode === "simple")
|
|
3480
|
+
drawApplied(read.found, read.element);
|
|
3481
|
+
else
|
|
3482
|
+
drawBlocks(read.found, read.element);
|
|
3483
|
+
applyFilter();
|
|
3484
|
+
}
|
|
3485
|
+
function setMode(value) {
|
|
3486
|
+
const next = MODES.find((one) => one === value);
|
|
3487
|
+
if (!next || next === mode)
|
|
3488
|
+
return;
|
|
3489
|
+
mode = next;
|
|
3490
|
+
context.mode?.set(next);
|
|
3491
|
+
modes?.set(next);
|
|
3492
|
+
const body = node.closest(".view-body");
|
|
3493
|
+
if (body)
|
|
3494
|
+
body.scrollTop = 0;
|
|
3495
|
+
draw();
|
|
3496
|
+
}
|
|
3497
|
+
function show(element, name) {
|
|
3498
|
+
waiting = false;
|
|
3499
|
+
editor?.close(false);
|
|
3500
|
+
if (element !== target) {
|
|
3501
|
+
pseudos = [];
|
|
3502
|
+
unforce(target);
|
|
3503
|
+
}
|
|
3504
|
+
target = element;
|
|
3505
|
+
pseudo = name ?? null;
|
|
3506
|
+
if (pseudo !== null && !pseudos.includes(pseudo))
|
|
3507
|
+
pseudos = [...pseudos, pseudo];
|
|
3508
|
+
point(null);
|
|
3509
|
+
context.held?.(element);
|
|
3510
|
+
if (!element) {
|
|
3511
|
+
unwatch();
|
|
3512
|
+
context.title("styles");
|
|
3513
|
+
clear(EMPTY, PICK);
|
|
3514
|
+
return;
|
|
3515
|
+
}
|
|
3516
|
+
watch(element);
|
|
3517
|
+
const body = node.closest(".view-body");
|
|
3518
|
+
if (body)
|
|
3519
|
+
body.scrollTop = 0;
|
|
3520
|
+
refresh();
|
|
3521
|
+
}
|
|
3522
|
+
const unsubscribe = page.subscribe((state) => {
|
|
3523
|
+
const next = knobsOf(state);
|
|
3524
|
+
if (next === knobs)
|
|
3525
|
+
return;
|
|
3526
|
+
knobs = next;
|
|
3527
|
+
stale = true;
|
|
3528
|
+
if (target)
|
|
3529
|
+
later();
|
|
3530
|
+
});
|
|
3531
|
+
const unlog = log?.subscribe(() => {
|
|
3532
|
+
if (target)
|
|
3533
|
+
refresh();
|
|
3534
|
+
});
|
|
3535
|
+
clear(EMPTY, PICK);
|
|
3536
|
+
return {
|
|
3537
|
+
node,
|
|
3538
|
+
show,
|
|
3539
|
+
refresh,
|
|
3540
|
+
escape() {
|
|
3541
|
+
return editor?.dismiss() || editor?.close(false) || filter.clear();
|
|
3542
|
+
},
|
|
3543
|
+
focus: () => node.focus({ preventScroll: true }),
|
|
3544
|
+
destroy() {
|
|
3545
|
+
waiting = false;
|
|
3546
|
+
unforce(target);
|
|
3547
|
+
editor?.destroy();
|
|
3548
|
+
unlog?.();
|
|
3549
|
+
clearTimeout(timer);
|
|
3550
|
+
clearTimeout(flashTimer);
|
|
3551
|
+
unwatch();
|
|
3552
|
+
unsubscribe();
|
|
3553
|
+
unpick?.();
|
|
3554
|
+
fitter?.disconnect();
|
|
3555
|
+
point(null);
|
|
3556
|
+
context.area?.(null);
|
|
3557
|
+
crumbs.removeEventListener("keydown", onCrumbKey);
|
|
3558
|
+
dropTips();
|
|
3559
|
+
target = null;
|
|
3560
|
+
}
|
|
3561
|
+
};
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3564
|
+
// src/ui/elementsview.ts
|
|
3565
|
+
var DOLLAR = "$0";
|
|
3566
|
+
var KEEP_LABEL = "keep edits after reload";
|
|
3567
|
+
function undoKey(event) {
|
|
3568
|
+
if (!letterMatches(event, "z") || event.metaKey || event.ctrlKey || event.altKey)
|
|
3569
|
+
return null;
|
|
3570
|
+
if (event.isComposing || typesInField(event))
|
|
3571
|
+
return null;
|
|
3572
|
+
return event.shiftKey ? "redo" : "undo";
|
|
3573
|
+
}
|
|
3574
|
+
function createDollar() {
|
|
3575
|
+
let held = null;
|
|
3576
|
+
function release() {
|
|
3577
|
+
if (!held)
|
|
3578
|
+
return;
|
|
3579
|
+
const { view, node } = held;
|
|
3580
|
+
held = null;
|
|
3581
|
+
try {
|
|
3582
|
+
if (Reflect.get(view, DOLLAR) === node)
|
|
3583
|
+
Reflect.deleteProperty(view, DOLLAR);
|
|
3584
|
+
} catch {}
|
|
3585
|
+
}
|
|
3586
|
+
function set(node) {
|
|
3587
|
+
const view = node?.ownerDocument?.defaultView ?? null;
|
|
3588
|
+
if (held && held.view !== view)
|
|
3589
|
+
release();
|
|
3590
|
+
if (!node || !view)
|
|
3591
|
+
return;
|
|
3592
|
+
try {
|
|
3593
|
+
if (held) {
|
|
3594
|
+
if (Reflect.get(view, DOLLAR) !== held.node)
|
|
3595
|
+
return;
|
|
3596
|
+
Reflect.set(view, DOLLAR, node);
|
|
3597
|
+
held = { view, node };
|
|
3598
|
+
return;
|
|
3599
|
+
}
|
|
3600
|
+
if (DOLLAR in view)
|
|
3601
|
+
return;
|
|
3602
|
+
Object.defineProperty(view, DOLLAR, { value: node, writable: true, configurable: true, enumerable: false });
|
|
3603
|
+
held = { view, node };
|
|
3604
|
+
} catch {}
|
|
3605
|
+
}
|
|
3606
|
+
return { set, release };
|
|
3607
|
+
}
|
|
3608
|
+
function createElementsView(context, parts = {}) {
|
|
3609
|
+
const node = el("div", "elements");
|
|
3610
|
+
const dollar = createDollar();
|
|
3611
|
+
let fromTree = false;
|
|
3612
|
+
const copy = parts.copy ?? copyText;
|
|
3613
|
+
const log = parts.edits ?? edits;
|
|
3614
|
+
const tree = (parts.tree ?? createDomTree)({
|
|
3615
|
+
outline: (element) => context.outline(element),
|
|
3616
|
+
select(picked, pseudo) {
|
|
3617
|
+
dollar.set(picked);
|
|
3618
|
+
fromTree = true;
|
|
3619
|
+
try {
|
|
3620
|
+
styles.show(elementOf(picked), pseudo ?? undefined);
|
|
3621
|
+
} finally {
|
|
3622
|
+
fromTree = false;
|
|
3623
|
+
}
|
|
3624
|
+
},
|
|
3625
|
+
copy: (text) => {
|
|
3626
|
+
Promise.resolve(copy(text)).catch(() => {
|
|
3627
|
+
return;
|
|
3628
|
+
});
|
|
3629
|
+
},
|
|
3630
|
+
editor: (hooks) => createDomEditor(hooks, { log, locate: context.locate, ...context.htmlSize && { htmlSize: context.htmlSize } })
|
|
3631
|
+
});
|
|
3632
|
+
const styles = createStylesView({
|
|
3633
|
+
...context,
|
|
3634
|
+
edits: log,
|
|
3635
|
+
held(element) {
|
|
3636
|
+
context.held?.(element);
|
|
3637
|
+
if (fromTree)
|
|
3638
|
+
return;
|
|
3639
|
+
tree.reveal(element);
|
|
3640
|
+
dollar.set(element);
|
|
3641
|
+
}
|
|
3642
|
+
}, parts.page);
|
|
3643
|
+
const keep = parts.keep === undefined ? keeper() : parts.keep;
|
|
3644
|
+
const changes = createChanges(log, copy, undefined, keep, context.diff ?? null);
|
|
3645
|
+
const keepSwitch = keep ? switchLine({ label: KEEP_LABEL, on: keep.on(), onChange: (on) => keep.set(on) }) : null;
|
|
3646
|
+
keepSwitch?.node.classList.add("keep-line");
|
|
3647
|
+
const syncKeep = () => {
|
|
3648
|
+
if (!keep || !keepSwitch)
|
|
3649
|
+
return;
|
|
3650
|
+
keepSwitch.set(keep.on());
|
|
3651
|
+
keepSwitch.control.disabled = !keep.known();
|
|
3652
|
+
};
|
|
3653
|
+
syncKeep();
|
|
3654
|
+
const stopKeep = keep ? keep.subscribe(syncKeep) : null;
|
|
3655
|
+
if (keepSwitch)
|
|
3656
|
+
node.append(keepSwitch.node);
|
|
3657
|
+
node.append(tree.node, styles.node, changes.node);
|
|
3658
|
+
function onKeydown(event) {
|
|
3659
|
+
const key = undoKey(event);
|
|
3660
|
+
if (!key)
|
|
3661
|
+
return;
|
|
3662
|
+
event.preventDefault();
|
|
3663
|
+
event.stopPropagation();
|
|
3664
|
+
if (key === "undo")
|
|
3665
|
+
log.undo();
|
|
3666
|
+
else
|
|
3667
|
+
log.redo();
|
|
3668
|
+
}
|
|
3669
|
+
function follow() {
|
|
3670
|
+
const picked = tree.selected();
|
|
3671
|
+
if (!picked || picked.isConnected)
|
|
3672
|
+
return;
|
|
3673
|
+
const next = successor(picked);
|
|
3674
|
+
if (next)
|
|
3675
|
+
tree.select(next);
|
|
3676
|
+
}
|
|
3677
|
+
node.addEventListener("keydown", onKeydown);
|
|
3678
|
+
const stopFollow = log.subscribe(follow);
|
|
3679
|
+
return {
|
|
3680
|
+
node,
|
|
3681
|
+
show: (element, pseudo) => styles.show(element, pseudo),
|
|
3682
|
+
refresh: () => styles.refresh(),
|
|
3683
|
+
escape: () => tree.escape() || styles.escape(),
|
|
3684
|
+
focus: () => styles.focus(),
|
|
3685
|
+
destroy() {
|
|
3686
|
+
node.removeEventListener("keydown", onKeydown);
|
|
3687
|
+
stopFollow();
|
|
3688
|
+
stopKeep?.();
|
|
3689
|
+
tree.destroy();
|
|
3690
|
+
styles.destroy();
|
|
3691
|
+
changes.destroy();
|
|
3692
|
+
dollar.release();
|
|
3693
|
+
}
|
|
3694
|
+
};
|
|
3695
|
+
}
|
|
3696
|
+
export {
|
|
3697
|
+
undoKey,
|
|
3698
|
+
createElementsView,
|
|
3699
|
+
createDollar,
|
|
3700
|
+
KEEP_LABEL,
|
|
3701
|
+
DOLLAR
|
|
3702
|
+
};
|