@vinena/knobs 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -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 +6 -6
- 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/browserdraw.d.ts +5 -0
- package/dist/engine/browserkit.d.ts +2 -0
- package/dist/engine/devices.d.ts +3 -2
- package/dist/engine/dock.d.ts +3 -4
- package/dist/engine/frame.d.ts +1 -1
- package/dist/engine/frames.d.ts +1 -0
- package/dist/engine/identity.d.ts +5 -1
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/mock.d.ts +0 -2
- package/dist/engine/mockdata.d.ts +4 -3
- package/dist/engine/mockdraw.d.ts +2 -14
- package/dist/engine/morphrun.d.ts +4 -0
- package/dist/engine/native.d.ts +31 -3
- package/dist/engine/notice.d.ts +1 -2
- package/dist/engine/style.d.ts +15 -0
- package/dist/engine/width.d.ts +3 -0
- package/dist/{framekit-w0v516w5.js → framekit-622h6w1f.js} +264 -105
- package/dist/{framekit-te90cjs0.js → framekit-yx612r28.js} +264 -105
- package/dist/index-0zp9py56.js +859 -0
- package/dist/{index-9re7sv56.js → index-1mstjadm.js} +126 -2167
- package/dist/{index-30fc6php.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-r72tz2vn.js → index-aymfvd8s.js} +1 -1
- package/dist/{index-trx7bxdk.js → index-aynkv7qk.js} +11 -8
- package/dist/{index-xjhwp5cj.js → index-dzm8ywq0.js} +504 -2362
- package/dist/{index-dan2kpsd.js → index-f60yax1j.js} +13 -8
- package/dist/index-f67wctn3.js +1858 -0
- package/dist/{index-agwr37gw.js → index-ftjdt358.js} +8 -171
- package/dist/{index-pewcdh28.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-sxe5079a.js → index-x59vz1xx.js} +262 -901
- 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 +447 -160
- package/dist/index.js +533 -485
- package/dist/react-0wepdf60.js +1519 -0
- package/dist/{react-4pvp6amm.js → react-1gqwa2yw.js} +1 -1
- package/dist/{index-hv02xka3.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-05jh9jv5.js → react-6fnxxs30.js} +8 -171
- package/dist/react-6q2cw2ya.js +689 -0
- package/dist/{react-sw8d8c94.js → react-6t4dbdzn.js} +11 -8
- package/dist/react-88es9b5q.js +719 -0
- package/dist/react-97b5b8j4.js +46 -0
- package/dist/{react-16spgn0h.js → react-bxzn8vq5.js} +1 -1
- package/dist/{react-ayg1bgw3.js → react-cs62p9qh.js} +83 -722
- package/dist/react-ethftdxp.js +497 -0
- package/dist/react-fp73vhyd.js +36 -0
- package/dist/{react-exjcpxma.js → react-me102s1a.js} +2 -45
- package/dist/react-t2qnewz2.js +24 -0
- package/dist/react-ttj8f9qp.js +1886 -0
- package/dist/{react-zy1mmhgz.js → react-v8497a41.js} +13 -8
- package/dist/{react-fm9y8dbn.js → react-wqn4sx0n.js} +276 -2133
- package/dist/react.js +529 -485
- package/dist/replay-j18rw92k.js +258 -0
- package/dist/replay-vtg0vqj2.js +257 -0
- package/dist/{storageview-s7heg93p.js → storageview-6xj7zb63.js} +11 -7
- package/dist/{storageview-r595qpt9.js → storageview-pzn8yaad.js} +11 -7
- package/dist/styles/force.d.ts +66 -0
- package/dist/types.d.ts +7 -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 +10 -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-2z4pkrdz.js +0 -2873
- package/dist/elementsview-qn8qyksa.js +0 -2874
- package/dist/index-78r0f8pw.js +0 -27
- package/dist/react-adky72h9.js +0 -29
|
@@ -0,0 +1,1519 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
hasNesting,
|
|
4
|
+
parseSubject,
|
|
5
|
+
resolveNesting,
|
|
6
|
+
riskyElement,
|
|
7
|
+
specificity,
|
|
8
|
+
splitList
|
|
9
|
+
} from "./react-6bz05qk1.js";
|
|
10
|
+
import {
|
|
11
|
+
middle
|
|
12
|
+
} from "./react-6fnxxs30.js";
|
|
13
|
+
import {
|
|
14
|
+
NEW_RULE_SHEET,
|
|
15
|
+
isNewRuleSheet,
|
|
16
|
+
isShadowRoot,
|
|
17
|
+
label
|
|
18
|
+
} from "./react-ethftdxp.js";
|
|
19
|
+
import {
|
|
20
|
+
actButton,
|
|
21
|
+
el
|
|
22
|
+
} from "./react-bxzn8vq5.js";
|
|
23
|
+
import {
|
|
24
|
+
icon,
|
|
25
|
+
isDevknobs,
|
|
26
|
+
typesInField
|
|
27
|
+
} from "./react-6q2cw2ya.js";
|
|
28
|
+
import {
|
|
29
|
+
addStyle,
|
|
30
|
+
authoredQuery,
|
|
31
|
+
ensureStyle,
|
|
32
|
+
isDocument,
|
|
33
|
+
isOwnSheet
|
|
34
|
+
} from "./react-wqn4sx0n.js";
|
|
35
|
+
|
|
36
|
+
// src/styles/collect.ts
|
|
37
|
+
function isKind(rule, kind) {
|
|
38
|
+
return rule.constructor.name === kind;
|
|
39
|
+
}
|
|
40
|
+
function sheetName(sheet) {
|
|
41
|
+
if (isNewRuleSheet(sheet))
|
|
42
|
+
return NEW_RULE_SHEET;
|
|
43
|
+
return sheet.href ?? (sheet.ownerNode ? "<style>" : "constructed");
|
|
44
|
+
}
|
|
45
|
+
function ownerOf(sheet) {
|
|
46
|
+
if (isNewRuleSheet(sheet))
|
|
47
|
+
return null;
|
|
48
|
+
const node = sheet.ownerNode;
|
|
49
|
+
return node && "hasAttribute" in node ? node : null;
|
|
50
|
+
}
|
|
51
|
+
function layerPath(walk, name) {
|
|
52
|
+
if (name)
|
|
53
|
+
return name.split(".");
|
|
54
|
+
walk.layers.anonymous += 1;
|
|
55
|
+
return [`(anonymous ${walk.layers.anonymous})`];
|
|
56
|
+
}
|
|
57
|
+
function enterLayer(walk, frame, name) {
|
|
58
|
+
const layer = [...frame.layer, ...layerPath(walk, name)];
|
|
59
|
+
walk.flat.layers.push({ path: layer, conditions: frame.conditions });
|
|
60
|
+
const context = [...frame.context, name ? `@layer ${name}` : "@layer"];
|
|
61
|
+
return { ...frame, layer, context };
|
|
62
|
+
}
|
|
63
|
+
function standalone(text, frame) {
|
|
64
|
+
if (frame.parent !== null || !frame.scope)
|
|
65
|
+
return resolveNesting(text, frame.parent);
|
|
66
|
+
const rooted = text.replace(/:scope(?![\w-])/gi, "&");
|
|
67
|
+
return hasNesting(rooted) ? resolveNesting(rooted, frame.scope.start) : text;
|
|
68
|
+
}
|
|
69
|
+
function partsOf(selectorText, frame) {
|
|
70
|
+
const resolved = [];
|
|
71
|
+
const parts = splitList(selectorText).map((text) => {
|
|
72
|
+
const alone = standalone(text, frame);
|
|
73
|
+
resolved.push(alone);
|
|
74
|
+
return { ...parseSubject(alone), text, specificity: specificity(alone) };
|
|
75
|
+
});
|
|
76
|
+
return { parts, resolved: resolved.join(", ") };
|
|
77
|
+
}
|
|
78
|
+
function push(walk, frame, rule, selectorText, index) {
|
|
79
|
+
const { parts, resolved } = partsOf(selectorText, frame);
|
|
80
|
+
walk.flat.rules.push({
|
|
81
|
+
rule,
|
|
82
|
+
selectorText,
|
|
83
|
+
parts,
|
|
84
|
+
context: frame.context,
|
|
85
|
+
conditions: frame.conditions,
|
|
86
|
+
layer: frame.layer.join("."),
|
|
87
|
+
scope: frame.scope,
|
|
88
|
+
conditional: frame.conditional,
|
|
89
|
+
origin: {
|
|
90
|
+
sheet: walk.sheet,
|
|
91
|
+
owner: walk.owner ? label(walk.owner) : null,
|
|
92
|
+
path: [...frame.path, index]
|
|
93
|
+
},
|
|
94
|
+
order: walk.flat.rules.length
|
|
95
|
+
});
|
|
96
|
+
return resolved;
|
|
97
|
+
}
|
|
98
|
+
function visit(walk, frame, rule, index) {
|
|
99
|
+
const inside = { ...frame, path: [...frame.path, index] };
|
|
100
|
+
if (isKind(rule, "CSSStyleRule")) {
|
|
101
|
+
const resolved = push(walk, frame, rule, rule.selectorText, index);
|
|
102
|
+
if (rule.cssRules?.length) {
|
|
103
|
+
const context = [...frame.context, rule.selectorText];
|
|
104
|
+
walkRules(walk, { ...inside, context, parent: resolved }, rule.cssRules);
|
|
105
|
+
}
|
|
106
|
+
} else if (isKind(rule, "CSSNestedDeclarations")) {
|
|
107
|
+
push(walk, frame, rule, "&", index);
|
|
108
|
+
} else if (isKind(rule, "CSSImportRule")) {
|
|
109
|
+
if (!rule.styleSheet)
|
|
110
|
+
return;
|
|
111
|
+
let next = inside;
|
|
112
|
+
if (rule.layerName != null)
|
|
113
|
+
next = enterLayer(walk, next, rule.layerName);
|
|
114
|
+
if (rule.supportsText) {
|
|
115
|
+
const context = [...next.context, `@supports ${rule.supportsText}`];
|
|
116
|
+
const condition = { kind: "supports", text: rule.supportsText };
|
|
117
|
+
next = { ...next, context, conditions: [...next.conditions, condition] };
|
|
118
|
+
}
|
|
119
|
+
if (rule.media.mediaText)
|
|
120
|
+
next = withMedia(next, rule.media, authoredQuery(rule));
|
|
121
|
+
walkSheet({ ...walk, sheet: sheetName(rule.styleSheet) }, next, rule.styleSheet);
|
|
122
|
+
} else if (isKind(rule, "CSSMediaRule")) {
|
|
123
|
+
walkRules(walk, withMedia(inside, rule.media, authoredQuery(rule)), rule.cssRules);
|
|
124
|
+
} else if (isKind(rule, "CSSSupportsRule")) {
|
|
125
|
+
const context = [...frame.context, `@supports ${rule.conditionText}`];
|
|
126
|
+
const condition = { kind: "supports", text: rule.conditionText };
|
|
127
|
+
const conditions = [...frame.conditions, condition];
|
|
128
|
+
walkRules(walk, { ...inside, context, conditions }, rule.cssRules);
|
|
129
|
+
} else if (isKind(rule, "CSSContainerRule")) {
|
|
130
|
+
const context = [...frame.context, `@container ${rule.conditionText}`];
|
|
131
|
+
walkRules(walk, { ...inside, context, conditional: "container" }, rule.cssRules);
|
|
132
|
+
} else if (isKind(rule, "CSSLayerBlockRule")) {
|
|
133
|
+
walkRules(walk, enterLayer(walk, inside, rule.name), rule.cssRules);
|
|
134
|
+
} else if (isKind(rule, "CSSLayerStatementRule")) {
|
|
135
|
+
for (const name of rule.nameList) {
|
|
136
|
+
const path = [...frame.layer, ...name.split(".")];
|
|
137
|
+
walk.flat.layers.push({ path, conditions: frame.conditions });
|
|
138
|
+
}
|
|
139
|
+
} else if (isKind(rule, "CSSScopeRule")) {
|
|
140
|
+
const limits = rule.end ? `(${rule.start}) to (${rule.end})` : `(${rule.start})`;
|
|
141
|
+
const context = [...frame.context, rule.start ? `@scope ${limits}` : "@scope"];
|
|
142
|
+
const scope = { start: rule.start, end: rule.end, around: walk.owner?.parentElement ?? null };
|
|
143
|
+
const conditional = frame.conditional ?? "scope";
|
|
144
|
+
walkRules(walk, { ...inside, context, scope, conditional, parent: null }, rule.cssRules);
|
|
145
|
+
} else if (isKind(rule, "CSSPropertyRule")) {
|
|
146
|
+
walk.flat.registered.set(rule.name, rule.inherits);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function withMedia(frame, list, authored) {
|
|
150
|
+
return {
|
|
151
|
+
...frame,
|
|
152
|
+
context: [...frame.context, `@media ${authored}`],
|
|
153
|
+
conditions: [...frame.conditions, { kind: "media", list }]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function walkRules(walk, frame, rules) {
|
|
157
|
+
for (let i = 0;i < rules.length; i++) {
|
|
158
|
+
const rule = rules[i];
|
|
159
|
+
if (!rule)
|
|
160
|
+
continue;
|
|
161
|
+
try {
|
|
162
|
+
visit(walk, frame, rule, i);
|
|
163
|
+
} catch {
|
|
164
|
+
walk.flat.skipped += 1;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function isSecurityError(error) {
|
|
169
|
+
if (typeof error !== "object" || error === null)
|
|
170
|
+
return false;
|
|
171
|
+
return "name" in error && error.name === "SecurityError";
|
|
172
|
+
}
|
|
173
|
+
function walkSheet(walk, frame, sheet) {
|
|
174
|
+
if (walk.seen.has(sheet))
|
|
175
|
+
return;
|
|
176
|
+
walk.seen.add(sheet);
|
|
177
|
+
let rules;
|
|
178
|
+
try {
|
|
179
|
+
rules = sheet.cssRules;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
const reason = isSecurityError(error) ? "cross-origin" : "unreadable";
|
|
182
|
+
walk.flat.hidden.push({ sheet: sheetName(sheet), reason });
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
walkRules(walk, frame, rules);
|
|
186
|
+
}
|
|
187
|
+
function sheetsOf(scope) {
|
|
188
|
+
return [...Array.from(scope.styleSheets), ...scope.adoptedStyleSheets ?? []];
|
|
189
|
+
}
|
|
190
|
+
function isOwn(sheet) {
|
|
191
|
+
if (isNewRuleSheet(sheet))
|
|
192
|
+
return false;
|
|
193
|
+
if (isOwnSheet(sheet))
|
|
194
|
+
return true;
|
|
195
|
+
const owner = ownerOf(sheet);
|
|
196
|
+
return owner !== null && isDevknobs(owner);
|
|
197
|
+
}
|
|
198
|
+
function flatten(scope, sheets) {
|
|
199
|
+
const flat = { rules: [], layers: [], hidden: [], registered: new Map, skipped: 0 };
|
|
200
|
+
if (isShadowRoot(scope) && isDevknobs(scope.host))
|
|
201
|
+
return flat;
|
|
202
|
+
const seen = new Set;
|
|
203
|
+
const layers = { anonymous: 0 };
|
|
204
|
+
for (const sheet of sheets) {
|
|
205
|
+
try {
|
|
206
|
+
if (sheet.disabled || isOwn(sheet))
|
|
207
|
+
continue;
|
|
208
|
+
const walk = { flat, seen, sheet: sheetName(sheet), owner: ownerOf(sheet), layers };
|
|
209
|
+
let frame = {
|
|
210
|
+
context: [],
|
|
211
|
+
conditions: [],
|
|
212
|
+
layer: [],
|
|
213
|
+
parent: null,
|
|
214
|
+
scope: null,
|
|
215
|
+
conditional: null,
|
|
216
|
+
path: []
|
|
217
|
+
};
|
|
218
|
+
if (sheet.media.mediaText)
|
|
219
|
+
frame = withMedia(frame, sheet.media, sheet.media.mediaText);
|
|
220
|
+
walkSheet(walk, frame, sheet);
|
|
221
|
+
} catch {
|
|
222
|
+
flat.skipped += 1;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return flat;
|
|
226
|
+
}
|
|
227
|
+
function signature(sheets) {
|
|
228
|
+
return sheets.map((sheet) => {
|
|
229
|
+
try {
|
|
230
|
+
return sheet.disabled ? -2 : sheet.cssRules.length;
|
|
231
|
+
} catch {
|
|
232
|
+
return -1;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
var cache = new WeakMap;
|
|
237
|
+
var version = 0;
|
|
238
|
+
function same(a, b) {
|
|
239
|
+
return a.length === b.length && a.every((value, i) => value === b[i]);
|
|
240
|
+
}
|
|
241
|
+
function invalidate() {
|
|
242
|
+
version += 1;
|
|
243
|
+
}
|
|
244
|
+
function rulesOf(scope) {
|
|
245
|
+
const sheets = sheetsOf(scope);
|
|
246
|
+
const now = signature(sheets);
|
|
247
|
+
const known = cache.get(scope);
|
|
248
|
+
const fresh = known?.version === version && same(known.sheets, sheets);
|
|
249
|
+
if (known && fresh && same(known.signature, now))
|
|
250
|
+
return known.flat;
|
|
251
|
+
const flat = flatten(scope, sheets);
|
|
252
|
+
cache.set(scope, { version, sheets, signature: now, flat });
|
|
253
|
+
return flat;
|
|
254
|
+
}
|
|
255
|
+
function layerRanks(marks, holds) {
|
|
256
|
+
const root = { children: new Map };
|
|
257
|
+
for (const mark of marks) {
|
|
258
|
+
if (!holds(mark.conditions))
|
|
259
|
+
continue;
|
|
260
|
+
let layer = root;
|
|
261
|
+
for (const step of mark.path) {
|
|
262
|
+
let child = layer.children.get(step);
|
|
263
|
+
if (!child) {
|
|
264
|
+
child = { children: new Map };
|
|
265
|
+
layer.children.set(step, child);
|
|
266
|
+
}
|
|
267
|
+
layer = child;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const ranks = new Map;
|
|
271
|
+
const place = (layer, name) => {
|
|
272
|
+
for (const [step, child] of layer.children)
|
|
273
|
+
place(child, name ? `${name}.${step}` : step);
|
|
274
|
+
ranks.set(name, ranks.size);
|
|
275
|
+
};
|
|
276
|
+
place(root, "");
|
|
277
|
+
return ranks;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// src/edit/html.ts
|
|
281
|
+
var HIDE_ATTRIBUTE = "data-devknobs-hide";
|
|
282
|
+
var HIDE_CSS = `[${HIDE_ATTRIBUTE}], [${HIDE_ATTRIBUTE}] * { visibility: hidden !important; }`;
|
|
283
|
+
var HTML = "http://www.w3.org/1999/xhtml";
|
|
284
|
+
var successors = new WeakMap;
|
|
285
|
+
function successor(node) {
|
|
286
|
+
let at = node;
|
|
287
|
+
for (let steps = 0;at && steps < 100; steps++) {
|
|
288
|
+
if (at !== node && at.isConnected)
|
|
289
|
+
return at;
|
|
290
|
+
at = successors.get(at);
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
function viewOf(node) {
|
|
295
|
+
try {
|
|
296
|
+
return node.ownerDocument?.defaultView ?? null;
|
|
297
|
+
} catch {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function isElement(node) {
|
|
302
|
+
return node.nodeType === 1;
|
|
303
|
+
}
|
|
304
|
+
function isShadowRoot2(node) {
|
|
305
|
+
return node.nodeType === 11 && "host" in node;
|
|
306
|
+
}
|
|
307
|
+
function isOwnName(name) {
|
|
308
|
+
return name.toLowerCase().startsWith("data-devknobs");
|
|
309
|
+
}
|
|
310
|
+
function ends(text) {
|
|
311
|
+
const lead = /^\s*/.exec(text)?.[0] ?? "";
|
|
312
|
+
const trail = lead.length === text.length ? "" : /\s*$/.exec(text)?.[0] ?? "";
|
|
313
|
+
return [lead, trail];
|
|
314
|
+
}
|
|
315
|
+
function textEdit(target, node, text, property = "text") {
|
|
316
|
+
const before = node.nodeValue ?? "";
|
|
317
|
+
const next = text.trim();
|
|
318
|
+
const [lead, trail] = ends(before);
|
|
319
|
+
const after = `${lead}${next}${trail}`;
|
|
320
|
+
if (next === "" || after === before)
|
|
321
|
+
return null;
|
|
322
|
+
return {
|
|
323
|
+
edit: { kind: "text", target: { ...target }, property, before: before.trim(), after: next },
|
|
324
|
+
apply() {
|
|
325
|
+
if (node.parentNode === null || node.nodeValue !== before)
|
|
326
|
+
return false;
|
|
327
|
+
node.nodeValue = after;
|
|
328
|
+
return true;
|
|
329
|
+
},
|
|
330
|
+
revert() {
|
|
331
|
+
if (node.nodeValue === after)
|
|
332
|
+
node.nodeValue = before;
|
|
333
|
+
},
|
|
334
|
+
view: viewOf(node)
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function attributeName(element, name) {
|
|
338
|
+
const trimmed = name.trim();
|
|
339
|
+
return element.namespaceURI === HTML ? trimmed.toLowerCase() : trimmed;
|
|
340
|
+
}
|
|
341
|
+
function setAttr(element, name, value) {
|
|
342
|
+
if (value === null)
|
|
343
|
+
element.removeAttribute(name);
|
|
344
|
+
else
|
|
345
|
+
element.setAttribute(name, value);
|
|
346
|
+
}
|
|
347
|
+
function attrEdit(target, element, name, value) {
|
|
348
|
+
const attr = attributeName(element, name);
|
|
349
|
+
if (attr === "" || isOwnName(attr))
|
|
350
|
+
return null;
|
|
351
|
+
const before = element.getAttribute(attr);
|
|
352
|
+
if (before === value)
|
|
353
|
+
return null;
|
|
354
|
+
return {
|
|
355
|
+
edit: { kind: "attr", target: { ...target }, property: attr, before, after: value },
|
|
356
|
+
apply() {
|
|
357
|
+
if (element.getAttribute(attr) !== before)
|
|
358
|
+
return false;
|
|
359
|
+
setAttr(element, attr, value);
|
|
360
|
+
return element.getAttribute(attr) === value;
|
|
361
|
+
},
|
|
362
|
+
revert() {
|
|
363
|
+
if (element.getAttribute(attr) === value)
|
|
364
|
+
setAttr(element, attr, before);
|
|
365
|
+
},
|
|
366
|
+
view: viewOf(element)
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function parseHtml(doc, html) {
|
|
370
|
+
const template = doc.createElement("template");
|
|
371
|
+
template.innerHTML = html;
|
|
372
|
+
return Array.from(template.content.childNodes);
|
|
373
|
+
}
|
|
374
|
+
function markupOfNodes(nodes) {
|
|
375
|
+
return nodes.map((node) => {
|
|
376
|
+
if (isElement(node))
|
|
377
|
+
return node.outerHTML;
|
|
378
|
+
if (node.nodeType === 8)
|
|
379
|
+
return `<!--${node.nodeValue ?? ""}-->`;
|
|
380
|
+
return (node.nodeValue ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
381
|
+
}).join("");
|
|
382
|
+
}
|
|
383
|
+
function holdsReserved(nodes) {
|
|
384
|
+
return nodes.some((node) => isElement(node) && [node, ...Array.from(node.querySelectorAll("*"))].some((one) => Array.from(one.attributes).some((attr) => isOwnName(attr.name))));
|
|
385
|
+
}
|
|
386
|
+
function htmlEdit(target, element, before, nodes) {
|
|
387
|
+
const first = nodes.find(isElement);
|
|
388
|
+
const home = element.parentNode;
|
|
389
|
+
const after = markupOfNodes(nodes).trim();
|
|
390
|
+
if (!first || !home || holdsReserved(nodes) || after === before.trim())
|
|
391
|
+
return null;
|
|
392
|
+
const made = [...nodes];
|
|
393
|
+
const inPlace = () => made.every((node, at) => node.parentNode === home && (at === 0 || made[at - 1]?.nextSibling === node));
|
|
394
|
+
return {
|
|
395
|
+
edit: { kind: "html", target: { ...target }, property: "html", before, after },
|
|
396
|
+
apply() {
|
|
397
|
+
if (element.parentNode !== home || !element.isConnected)
|
|
398
|
+
return false;
|
|
399
|
+
for (const node of made)
|
|
400
|
+
home.insertBefore(node, element);
|
|
401
|
+
home.removeChild(element);
|
|
402
|
+
successors.set(element, first);
|
|
403
|
+
return true;
|
|
404
|
+
},
|
|
405
|
+
revert() {
|
|
406
|
+
if (!inPlace() || element.parentNode !== null)
|
|
407
|
+
return;
|
|
408
|
+
home.insertBefore(element, made[0] ?? null);
|
|
409
|
+
for (const node of made)
|
|
410
|
+
home.removeChild(node);
|
|
411
|
+
successors.set(first, element);
|
|
412
|
+
},
|
|
413
|
+
view: viewOf(element)
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
var shadowStyles = new WeakMap;
|
|
417
|
+
function hideStyle(element) {
|
|
418
|
+
const root = element.getRootNode();
|
|
419
|
+
if (isDocument(root)) {
|
|
420
|
+
const style = ensureStyle("hide", root);
|
|
421
|
+
if (!style.textContent)
|
|
422
|
+
style.textContent = HIDE_CSS;
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (isShadowRoot2(root) && !shadowStyles.has(root))
|
|
426
|
+
shadowStyles.set(root, addStyle(root, HIDE_CSS));
|
|
427
|
+
}
|
|
428
|
+
function hideEdit(target, element, style = hideStyle) {
|
|
429
|
+
const hidden = element.hasAttribute(HIDE_ATTRIBUTE);
|
|
430
|
+
const set = (on) => {
|
|
431
|
+
if (on)
|
|
432
|
+
element.setAttribute(HIDE_ATTRIBUTE, "");
|
|
433
|
+
else
|
|
434
|
+
element.removeAttribute(HIDE_ATTRIBUTE);
|
|
435
|
+
};
|
|
436
|
+
return {
|
|
437
|
+
edit: { kind: "hide", target: { ...target }, property: "hidden", before: hidden ? "hidden" : null, after: hidden ? null : "hidden" },
|
|
438
|
+
apply() {
|
|
439
|
+
if (element.hasAttribute(HIDE_ATTRIBUTE) !== hidden)
|
|
440
|
+
return false;
|
|
441
|
+
if (!hidden)
|
|
442
|
+
style(element);
|
|
443
|
+
set(!hidden);
|
|
444
|
+
return true;
|
|
445
|
+
},
|
|
446
|
+
revert() {
|
|
447
|
+
if (element.hasAttribute(HIDE_ATTRIBUTE) !== hidden)
|
|
448
|
+
set(hidden);
|
|
449
|
+
},
|
|
450
|
+
view: viewOf(element)
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
function deleteEdit(target, node, before, property = "node") {
|
|
454
|
+
const parent = node.parentNode;
|
|
455
|
+
if (!parent)
|
|
456
|
+
return null;
|
|
457
|
+
let next = null;
|
|
458
|
+
let previous = null;
|
|
459
|
+
return {
|
|
460
|
+
edit: { kind: "delete", target: { ...target }, property, before, after: null },
|
|
461
|
+
apply() {
|
|
462
|
+
if (node.parentNode !== parent)
|
|
463
|
+
return false;
|
|
464
|
+
next = node.nextSibling;
|
|
465
|
+
previous = node.previousSibling;
|
|
466
|
+
parent.removeChild(node);
|
|
467
|
+
return true;
|
|
468
|
+
},
|
|
469
|
+
revert() {
|
|
470
|
+
if (node.parentNode !== null || !parent.isConnected)
|
|
471
|
+
return;
|
|
472
|
+
let at = null;
|
|
473
|
+
if (next?.parentNode === parent)
|
|
474
|
+
at = next;
|
|
475
|
+
else if (previous?.parentNode === parent)
|
|
476
|
+
at = previous.nextSibling;
|
|
477
|
+
else if (previous === null)
|
|
478
|
+
at = parent.firstChild;
|
|
479
|
+
parent.insertBefore(node, at);
|
|
480
|
+
},
|
|
481
|
+
view: viewOf(node)
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function isOwnElement(node) {
|
|
485
|
+
return isElement(node) && node.hasAttribute("data-devknobs");
|
|
486
|
+
}
|
|
487
|
+
function nextElementOf(node) {
|
|
488
|
+
for (let at = node.nextSibling;at; at = at.nextSibling)
|
|
489
|
+
if (isElement(at) && !isOwnElement(at))
|
|
490
|
+
return at;
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
function previousElementOf(node) {
|
|
494
|
+
for (let at = node.previousSibling;at; at = at.previousSibling)
|
|
495
|
+
if (isElement(at) && !isOwnElement(at))
|
|
496
|
+
return at;
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
function firstElementOf(node) {
|
|
500
|
+
for (let at = node.firstChild;at; at = at.nextSibling)
|
|
501
|
+
if (isElement(at) && !isOwnElement(at))
|
|
502
|
+
return at;
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
function movable(node) {
|
|
506
|
+
if (!isElement(node) || isOwnElement(node))
|
|
507
|
+
return false;
|
|
508
|
+
const parent = node.parentNode;
|
|
509
|
+
if (!parent || !isElement(parent))
|
|
510
|
+
return false;
|
|
511
|
+
if (node.namespaceURI === HTML && (node.localName === "head" || node.localName === "body"))
|
|
512
|
+
return false;
|
|
513
|
+
if (riskyElement(node) || Array.from(node.querySelectorAll("*")).some(riskyElement))
|
|
514
|
+
return false;
|
|
515
|
+
return node.querySelector("[data-devknobs]") === null;
|
|
516
|
+
}
|
|
517
|
+
var EMPTY = new Set([
|
|
518
|
+
...["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr", "template"],
|
|
519
|
+
...["script", "style", "textarea", "title", "iframe", "noscript", "object", "html", "head"]
|
|
520
|
+
]);
|
|
521
|
+
function above(node) {
|
|
522
|
+
return isShadowRoot2(node) ? node.host : node.parentNode;
|
|
523
|
+
}
|
|
524
|
+
function canHold(parent, element) {
|
|
525
|
+
if (!isElement(parent) || !parent.isConnected || isOwnElement(parent) || parent === element)
|
|
526
|
+
return false;
|
|
527
|
+
if (parent.namespaceURI === HTML && EMPTY.has(parent.localName))
|
|
528
|
+
return false;
|
|
529
|
+
for (let at = parent;at; at = above(at))
|
|
530
|
+
if (at === element)
|
|
531
|
+
return false;
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
function tagLabel(element) {
|
|
535
|
+
const tag = element.localName || element.nodeName.toLowerCase();
|
|
536
|
+
const id = element.getAttribute("id");
|
|
537
|
+
const classes = element.getAttribute("class")?.trim().replace(/\s+/g, " ");
|
|
538
|
+
return `<${tag}${id ? ` id="${id}"` : ""}${classes ? ` class="${classes}"` : ""}>`;
|
|
539
|
+
}
|
|
540
|
+
var ORDINALS = ["th", "st", "nd", "rd"];
|
|
541
|
+
function ordinal(n) {
|
|
542
|
+
const tens = n % 100;
|
|
543
|
+
return `${n}${tens >= 11 && tens <= 13 ? "th" : ORDINALS[n % 10] ?? "th"}`;
|
|
544
|
+
}
|
|
545
|
+
function placeLabel(parent, element) {
|
|
546
|
+
const label2 = tagLabel(element);
|
|
547
|
+
let at = 0;
|
|
548
|
+
let alike = 0;
|
|
549
|
+
for (let one = firstElementOf(parent);one; one = nextElementOf(one)) {
|
|
550
|
+
if (tagLabel(one) !== label2)
|
|
551
|
+
continue;
|
|
552
|
+
alike++;
|
|
553
|
+
if (one === element)
|
|
554
|
+
at = alike;
|
|
555
|
+
}
|
|
556
|
+
return alike > 1 && at > 0 ? `the ${ordinal(at)} ${label2}` : label2;
|
|
557
|
+
}
|
|
558
|
+
function placeWords(parent, next) {
|
|
559
|
+
return next ? `before ${placeLabel(parent, next)} in ${tagLabel(parent)}` : `at the end of ${tagLabel(parent)}`;
|
|
560
|
+
}
|
|
561
|
+
function moveEdit(target, element, to, places) {
|
|
562
|
+
const home = element.parentNode;
|
|
563
|
+
if (!home || !isElement(home) || !movable(element) || !canHold(to.parent, element))
|
|
564
|
+
return null;
|
|
565
|
+
if (to.next === element || to.next !== null && to.next.parentNode !== to.parent)
|
|
566
|
+
return null;
|
|
567
|
+
const fromNext = nextElementOf(element);
|
|
568
|
+
if (to.parent === home && to.next === fromNext)
|
|
569
|
+
return null;
|
|
570
|
+
let next = null;
|
|
571
|
+
let previous = null;
|
|
572
|
+
return {
|
|
573
|
+
edit: { kind: "move", target: { ...target }, property: "node", before: placeWords(home, fromNext), after: placeWords(to.parent, to.next), from: { ...places.from }, to: { ...places.to } },
|
|
574
|
+
apply() {
|
|
575
|
+
if (element.parentNode !== home || !canHold(to.parent, element) || to.next !== null && to.next.parentNode !== to.parent)
|
|
576
|
+
return false;
|
|
577
|
+
next = element.nextSibling;
|
|
578
|
+
previous = element.previousSibling;
|
|
579
|
+
to.parent.insertBefore(element, to.next);
|
|
580
|
+
return true;
|
|
581
|
+
},
|
|
582
|
+
revert() {
|
|
583
|
+
if (element.parentNode !== to.parent || nextElementOf(element) !== to.next || !home.isConnected)
|
|
584
|
+
return;
|
|
585
|
+
let at = null;
|
|
586
|
+
if (next?.parentNode === home)
|
|
587
|
+
at = next;
|
|
588
|
+
else if (previous?.parentNode === home)
|
|
589
|
+
at = previous.nextSibling;
|
|
590
|
+
else if (previous === null)
|
|
591
|
+
at = home.firstChild;
|
|
592
|
+
home.insertBefore(element, at);
|
|
593
|
+
},
|
|
594
|
+
view: viewOf(element)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// src/ui/domtree.ts
|
|
599
|
+
var ELEMENT = 1;
|
|
600
|
+
var TEXT = 3;
|
|
601
|
+
var COMMENT = 8;
|
|
602
|
+
var DOCUMENT = 9;
|
|
603
|
+
var DOCTYPE = 10;
|
|
604
|
+
var FRAGMENT = 11;
|
|
605
|
+
var CHILD_CAP = 500;
|
|
606
|
+
var INLINE_MAX = 80;
|
|
607
|
+
var VALUE_MAX = 100;
|
|
608
|
+
var DATA_URL_MAX = 60;
|
|
609
|
+
var TEXT_MAX = 200;
|
|
610
|
+
var SETTLE = 100;
|
|
611
|
+
var VOID = new Set([
|
|
612
|
+
"area",
|
|
613
|
+
"base",
|
|
614
|
+
"br",
|
|
615
|
+
"col",
|
|
616
|
+
"embed",
|
|
617
|
+
"hr",
|
|
618
|
+
"img",
|
|
619
|
+
"input",
|
|
620
|
+
"link",
|
|
621
|
+
"meta",
|
|
622
|
+
"param",
|
|
623
|
+
"source",
|
|
624
|
+
"track",
|
|
625
|
+
"wbr"
|
|
626
|
+
]);
|
|
627
|
+
function hasContent(content) {
|
|
628
|
+
return content !== "" && content !== "none" && content !== "normal";
|
|
629
|
+
}
|
|
630
|
+
function readPseudos(element) {
|
|
631
|
+
const view = element.ownerDocument.defaultView;
|
|
632
|
+
if (!view)
|
|
633
|
+
return [];
|
|
634
|
+
const found = [];
|
|
635
|
+
try {
|
|
636
|
+
if (view.getComputedStyle(element).display.includes("list-item")) {
|
|
637
|
+
if (view.getComputedStyle(element, "::marker").content !== "none")
|
|
638
|
+
found.push("::marker");
|
|
639
|
+
}
|
|
640
|
+
for (const name of ["::before", "::after"]) {
|
|
641
|
+
const style = view.getComputedStyle(element, name);
|
|
642
|
+
if (hasContent(style.content) && style.display !== "none")
|
|
643
|
+
found.push(name);
|
|
644
|
+
}
|
|
645
|
+
} catch {}
|
|
646
|
+
return found;
|
|
647
|
+
}
|
|
648
|
+
var PAGE = { pseudos: readPseudos };
|
|
649
|
+
function isElement2(node) {
|
|
650
|
+
return node.nodeType === ELEMENT;
|
|
651
|
+
}
|
|
652
|
+
function isShadowRoot3(node) {
|
|
653
|
+
return node.nodeType === FRAGMENT && "host" in node;
|
|
654
|
+
}
|
|
655
|
+
function isDoctype(node) {
|
|
656
|
+
return node.nodeType === DOCTYPE;
|
|
657
|
+
}
|
|
658
|
+
function isDocument2(node) {
|
|
659
|
+
return node.nodeType === DOCUMENT;
|
|
660
|
+
}
|
|
661
|
+
function isOwnNode(node) {
|
|
662
|
+
return isElement2(node) && node.hasAttribute("data-devknobs");
|
|
663
|
+
}
|
|
664
|
+
function isOwnAttribute(name) {
|
|
665
|
+
return name.startsWith("data-devknobs");
|
|
666
|
+
}
|
|
667
|
+
function parentOf(node) {
|
|
668
|
+
if (isShadowRoot3(node))
|
|
669
|
+
return node.host;
|
|
670
|
+
return node.parentNode;
|
|
671
|
+
}
|
|
672
|
+
function shownText(text) {
|
|
673
|
+
return text.replace(/\s+/g, " ").trim();
|
|
674
|
+
}
|
|
675
|
+
function cut(text, max) {
|
|
676
|
+
const chars = [...text];
|
|
677
|
+
return chars.length <= max ? text : `${chars.slice(0, max - 1).join("")}…`;
|
|
678
|
+
}
|
|
679
|
+
function shownValue(value) {
|
|
680
|
+
return middle(value, value.startsWith("data:") ? DATA_URL_MAX : VALUE_MAX);
|
|
681
|
+
}
|
|
682
|
+
function tagOf(element) {
|
|
683
|
+
return element.localName || element.nodeName.toLowerCase();
|
|
684
|
+
}
|
|
685
|
+
function doctypeText(node) {
|
|
686
|
+
const pub = node.publicId ? ` PUBLIC "${node.publicId}"` : "";
|
|
687
|
+
const system = node.systemId ? `${pub ? "" : " SYSTEM"} "${node.systemId}"` : "";
|
|
688
|
+
return `<!DOCTYPE ${node.name}${pub}${system}>`;
|
|
689
|
+
}
|
|
690
|
+
function createTreeModel(page = PAGE) {
|
|
691
|
+
let doc = null;
|
|
692
|
+
let kids = new WeakMap;
|
|
693
|
+
let marks = new WeakMap;
|
|
694
|
+
let open = new WeakSet;
|
|
695
|
+
let all = new WeakSet;
|
|
696
|
+
function pseudosOf(element) {
|
|
697
|
+
let found = marks.get(element);
|
|
698
|
+
if (!found) {
|
|
699
|
+
found = page.pseudos(element);
|
|
700
|
+
marks.set(element, found);
|
|
701
|
+
}
|
|
702
|
+
return found;
|
|
703
|
+
}
|
|
704
|
+
function shows(node) {
|
|
705
|
+
switch (node.nodeType) {
|
|
706
|
+
case ELEMENT:
|
|
707
|
+
return !isOwnNode(node);
|
|
708
|
+
case TEXT:
|
|
709
|
+
return shownText(node.nodeValue ?? "") !== "";
|
|
710
|
+
case COMMENT:
|
|
711
|
+
case DOCTYPE:
|
|
712
|
+
return true;
|
|
713
|
+
default:
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
function children(node) {
|
|
718
|
+
const had = kids.get(node);
|
|
719
|
+
if (had)
|
|
720
|
+
return had;
|
|
721
|
+
const list = [];
|
|
722
|
+
const element = isElement2(node) ? node : null;
|
|
723
|
+
const pseudos = element ? pseudosOf(element) : [];
|
|
724
|
+
if (element?.shadowRoot)
|
|
725
|
+
list.push({ node: element.shadowRoot, pseudo: null });
|
|
726
|
+
if (element) {
|
|
727
|
+
for (const name of pseudos)
|
|
728
|
+
if (name !== "::after")
|
|
729
|
+
list.push({ node: element, pseudo: name });
|
|
730
|
+
}
|
|
731
|
+
for (const child of Array.from(node.childNodes))
|
|
732
|
+
if (shows(child))
|
|
733
|
+
list.push({ node: child, pseudo: null });
|
|
734
|
+
if (element && pseudos.includes("::after"))
|
|
735
|
+
list.push({ node: element, pseudo: "::after" });
|
|
736
|
+
kids.set(node, list);
|
|
737
|
+
return list;
|
|
738
|
+
}
|
|
739
|
+
function inlineText(element) {
|
|
740
|
+
if (element.shadowRoot)
|
|
741
|
+
return null;
|
|
742
|
+
const nodes = element.childNodes;
|
|
743
|
+
const only = nodes[0];
|
|
744
|
+
if (nodes.length !== 1 || !only || only.nodeType !== TEXT)
|
|
745
|
+
return null;
|
|
746
|
+
const text = shownText(only.nodeValue ?? "");
|
|
747
|
+
if (text === "" || text.length > INLINE_MAX)
|
|
748
|
+
return null;
|
|
749
|
+
return pseudosOf(element).length === 0 ? text : null;
|
|
750
|
+
}
|
|
751
|
+
function expandable(node) {
|
|
752
|
+
if (isElement2(node) && inlineText(node) !== null)
|
|
753
|
+
return false;
|
|
754
|
+
return children(node).length > 0;
|
|
755
|
+
}
|
|
756
|
+
function walk(node, depth, out) {
|
|
757
|
+
const list = children(node);
|
|
758
|
+
const limit = all.has(node) ? list.length : Math.min(list.length, CHILD_CAP);
|
|
759
|
+
for (let at = 0;at < limit; at++) {
|
|
760
|
+
const entry = list[at];
|
|
761
|
+
if (entry)
|
|
762
|
+
push2(entry, depth, out);
|
|
763
|
+
}
|
|
764
|
+
if (limit < list.length)
|
|
765
|
+
out.push({ kind: "more", node, pseudo: null, depth, more: list.length - limit });
|
|
766
|
+
}
|
|
767
|
+
function push2({ node, pseudo }, depth, out) {
|
|
768
|
+
const row = (kind) => ({ kind, node, pseudo, depth, more: 0 });
|
|
769
|
+
if (pseudo !== null) {
|
|
770
|
+
out.push(row("pseudo"));
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
switch (node.nodeType) {
|
|
774
|
+
case ELEMENT:
|
|
775
|
+
out.push(row("open"));
|
|
776
|
+
if (open.has(node) && expandable(node)) {
|
|
777
|
+
walk(node, depth + 1, out);
|
|
778
|
+
out.push(row("close"));
|
|
779
|
+
}
|
|
780
|
+
return;
|
|
781
|
+
case FRAGMENT:
|
|
782
|
+
out.push(row("shadow"));
|
|
783
|
+
if (open.has(node))
|
|
784
|
+
walk(node, depth + 1, out);
|
|
785
|
+
return;
|
|
786
|
+
case TEXT:
|
|
787
|
+
out.push(row("text"));
|
|
788
|
+
return;
|
|
789
|
+
case COMMENT:
|
|
790
|
+
out.push(row("comment"));
|
|
791
|
+
return;
|
|
792
|
+
case DOCTYPE:
|
|
793
|
+
out.push(row("doctype"));
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
function openPieces(element) {
|
|
797
|
+
const tag = tagOf(element);
|
|
798
|
+
const pieces2 = [["tag", `<${tag}`]];
|
|
799
|
+
for (const attr of Array.from(element.attributes)) {
|
|
800
|
+
if (isOwnAttribute(attr.name))
|
|
801
|
+
continue;
|
|
802
|
+
pieces2.push(["", " "], ["attr", attr.name, attr.name]);
|
|
803
|
+
if (attr.value !== "")
|
|
804
|
+
pieces2.push(["tag", '="', attr.name], ["val", shownValue(attr.value), attr.name], ["tag", '"', attr.name]);
|
|
805
|
+
}
|
|
806
|
+
if (VOID.has(tag) && element.namespaceURI === "http://www.w3.org/1999/xhtml") {
|
|
807
|
+
pieces2.push(["tag", ">"]);
|
|
808
|
+
return pieces2;
|
|
809
|
+
}
|
|
810
|
+
const text = inlineText(element);
|
|
811
|
+
if (text !== null)
|
|
812
|
+
pieces2.push(["tag", ">"], ["text", text], ["tag", `</${tag}>`]);
|
|
813
|
+
else if (!expandable(element))
|
|
814
|
+
pieces2.push(["tag", `></${tag}>`]);
|
|
815
|
+
else if (open.has(element))
|
|
816
|
+
pieces2.push(["tag", ">"]);
|
|
817
|
+
else
|
|
818
|
+
pieces2.push(["tag", ">"], ["", "…"], ["tag", `</${tag}>`]);
|
|
819
|
+
return pieces2;
|
|
820
|
+
}
|
|
821
|
+
function pieces(row) {
|
|
822
|
+
const { node } = row;
|
|
823
|
+
switch (row.kind) {
|
|
824
|
+
case "open":
|
|
825
|
+
return isElement2(node) ? openPieces(node) : [];
|
|
826
|
+
case "close":
|
|
827
|
+
return isElement2(node) ? [["tag", `</${tagOf(node)}>`]] : [];
|
|
828
|
+
case "text":
|
|
829
|
+
return [["text", `"${cut(shownText(node.nodeValue ?? ""), TEXT_MAX)}"`]];
|
|
830
|
+
case "comment":
|
|
831
|
+
return [["com", `<!--${cut(node.nodeValue ?? "", TEXT_MAX)}-->`]];
|
|
832
|
+
case "doctype":
|
|
833
|
+
return isDoctype(node) ? [["doc", doctypeText(node)]] : [];
|
|
834
|
+
case "shadow":
|
|
835
|
+
return [["", "#shadow-root (open)"]];
|
|
836
|
+
case "pseudo":
|
|
837
|
+
return [["tag", row.pseudo ?? ""]];
|
|
838
|
+
case "more":
|
|
839
|
+
return [["", `Show all nodes (${row.more} more)`]];
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
function setRoot(next) {
|
|
843
|
+
doc = next;
|
|
844
|
+
kids = new WeakMap;
|
|
845
|
+
marks = new WeakMap;
|
|
846
|
+
open = new WeakSet;
|
|
847
|
+
all = new WeakSet;
|
|
848
|
+
const html = next?.documentElement;
|
|
849
|
+
if (html)
|
|
850
|
+
open.add(html);
|
|
851
|
+
if (next?.body)
|
|
852
|
+
open.add(next.body);
|
|
853
|
+
}
|
|
854
|
+
function reveal(node) {
|
|
855
|
+
const path = [];
|
|
856
|
+
let at = node;
|
|
857
|
+
while (at && at.nodeType !== DOCUMENT) {
|
|
858
|
+
if (isOwnNode(at))
|
|
859
|
+
return false;
|
|
860
|
+
path.unshift(at);
|
|
861
|
+
at = parentOf(at);
|
|
862
|
+
}
|
|
863
|
+
if (!at || at !== doc)
|
|
864
|
+
return false;
|
|
865
|
+
let above2 = at;
|
|
866
|
+
for (const step of path) {
|
|
867
|
+
const index = children(above2).findIndex((entry) => entry.node === step && entry.pseudo === null);
|
|
868
|
+
if (index < 0)
|
|
869
|
+
return false;
|
|
870
|
+
if (index >= CHILD_CAP)
|
|
871
|
+
all.add(above2);
|
|
872
|
+
if (step !== node)
|
|
873
|
+
open.add(step);
|
|
874
|
+
above2 = step;
|
|
875
|
+
}
|
|
876
|
+
return true;
|
|
877
|
+
}
|
|
878
|
+
return {
|
|
879
|
+
root: () => doc,
|
|
880
|
+
setRoot,
|
|
881
|
+
children,
|
|
882
|
+
inlineText,
|
|
883
|
+
expandable,
|
|
884
|
+
isExpanded: (node) => open.has(node),
|
|
885
|
+
setExpanded(node, next) {
|
|
886
|
+
if (next)
|
|
887
|
+
open.add(node);
|
|
888
|
+
else
|
|
889
|
+
open.delete(node);
|
|
890
|
+
},
|
|
891
|
+
showAll: (node) => all.add(node),
|
|
892
|
+
forget(node) {
|
|
893
|
+
kids.delete(node);
|
|
894
|
+
if (isElement2(node))
|
|
895
|
+
marks.delete(node);
|
|
896
|
+
},
|
|
897
|
+
reveal,
|
|
898
|
+
rows() {
|
|
899
|
+
const out = [];
|
|
900
|
+
if (doc)
|
|
901
|
+
walk(doc, 0, out);
|
|
902
|
+
return out;
|
|
903
|
+
},
|
|
904
|
+
pieces
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
function dropAt(row, fraction, dragged, open) {
|
|
908
|
+
const target = row.node;
|
|
909
|
+
if (row.pseudo !== null || !isElement2(target) || target === dragged)
|
|
910
|
+
return null;
|
|
911
|
+
const around = target.parentNode;
|
|
912
|
+
const before = () => around && isElement2(around) ? { parent: around, next: target, where: "before" } : null;
|
|
913
|
+
const after = () => around && isElement2(around) ? { parent: around, next: nextElementOf(target), where: "after" } : null;
|
|
914
|
+
let place = null;
|
|
915
|
+
if (row.kind === "close")
|
|
916
|
+
place = fraction < 0.5 ? { parent: target, next: null, where: "into" } : after();
|
|
917
|
+
else if (row.kind === "open") {
|
|
918
|
+
if (fraction < 0.25)
|
|
919
|
+
place = before();
|
|
920
|
+
else if (fraction > 0.75)
|
|
921
|
+
place = open && firstElementOf(target) ? { parent: target, next: firstElementOf(target), where: "after" } : after();
|
|
922
|
+
else
|
|
923
|
+
place = canHold(target, dragged) ? { parent: target, next: null, where: "into" } : fraction < 0.5 ? before() : after();
|
|
924
|
+
}
|
|
925
|
+
if (!place || !canHold(place.parent, dragged) || place.next === dragged)
|
|
926
|
+
return null;
|
|
927
|
+
return place;
|
|
928
|
+
}
|
|
929
|
+
function selectable(row) {
|
|
930
|
+
return row.kind !== "close" && row.kind !== "more";
|
|
931
|
+
}
|
|
932
|
+
function parentRow(rows, at) {
|
|
933
|
+
const row = rows[at];
|
|
934
|
+
if (!row)
|
|
935
|
+
return null;
|
|
936
|
+
for (let up = at - 1;up >= 0; up--) {
|
|
937
|
+
const above2 = rows[up];
|
|
938
|
+
if (above2 && above2.depth === row.depth - 1 && selectable(above2))
|
|
939
|
+
return up;
|
|
940
|
+
}
|
|
941
|
+
return null;
|
|
942
|
+
}
|
|
943
|
+
function stepFor(key, rows, at, model) {
|
|
944
|
+
const lines = rows.map((row2, index) => selectable(row2) ? index : -1).filter((index) => index >= 0);
|
|
945
|
+
const here = lines.indexOf(at);
|
|
946
|
+
const row = rows[at];
|
|
947
|
+
const to = (index) => index === undefined || index === at ? null : { kind: "select", at: index };
|
|
948
|
+
switch (key) {
|
|
949
|
+
case "ArrowDown":
|
|
950
|
+
return to(lines[here < 0 ? 0 : here + 1]);
|
|
951
|
+
case "ArrowUp":
|
|
952
|
+
return to(lines[here < 0 ? 0 : here - 1]);
|
|
953
|
+
case "Home":
|
|
954
|
+
return to(lines[0]);
|
|
955
|
+
case "End":
|
|
956
|
+
return to(lines[lines.length - 1]);
|
|
957
|
+
case "ArrowRight":
|
|
958
|
+
if (!row || !model.expandable(row.node) || row.kind === "pseudo")
|
|
959
|
+
return null;
|
|
960
|
+
if (!model.isExpanded(row.node))
|
|
961
|
+
return { kind: "expand", node: row.node };
|
|
962
|
+
return to(lines[here + 1]);
|
|
963
|
+
case "ArrowLeft":
|
|
964
|
+
if (!row)
|
|
965
|
+
return null;
|
|
966
|
+
if (row.kind !== "pseudo" && model.expandable(row.node) && model.isExpanded(row.node))
|
|
967
|
+
return { kind: "collapse", node: row.node };
|
|
968
|
+
return to(parentRow(rows, at) ?? undefined);
|
|
969
|
+
default:
|
|
970
|
+
return null;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
function elementOf(node) {
|
|
974
|
+
for (let at = node;at; at = parentOf(at))
|
|
975
|
+
if (isElement2(at))
|
|
976
|
+
return at;
|
|
977
|
+
return null;
|
|
978
|
+
}
|
|
979
|
+
function markupOf(node) {
|
|
980
|
+
if (isElement2(node)) {
|
|
981
|
+
const copy = node.cloneNode(true);
|
|
982
|
+
if (!isElement2(copy))
|
|
983
|
+
return "";
|
|
984
|
+
for (const own of Array.from(copy.querySelectorAll("[data-devknobs]")))
|
|
985
|
+
own.remove();
|
|
986
|
+
for (const one of [copy, ...Array.from(copy.querySelectorAll("*"))]) {
|
|
987
|
+
for (const attr of Array.from(one.attributes))
|
|
988
|
+
if (isOwnAttribute(attr.name))
|
|
989
|
+
one.removeAttribute(attr.name);
|
|
990
|
+
}
|
|
991
|
+
return copy.outerHTML;
|
|
992
|
+
}
|
|
993
|
+
if (node.nodeType === TEXT)
|
|
994
|
+
return node.nodeValue ?? "";
|
|
995
|
+
if (node.nodeType === COMMENT)
|
|
996
|
+
return `<!--${node.nodeValue ?? ""}-->`;
|
|
997
|
+
if (isDoctype(node))
|
|
998
|
+
return doctypeText(node);
|
|
999
|
+
return "";
|
|
1000
|
+
}
|
|
1001
|
+
var treesMade = 0;
|
|
1002
|
+
function slot(row) {
|
|
1003
|
+
return row.kind === "pseudo" ? row.pseudo ?? "" : row.kind;
|
|
1004
|
+
}
|
|
1005
|
+
function hasClasses(target) {
|
|
1006
|
+
return target !== null && "classList" in target;
|
|
1007
|
+
}
|
|
1008
|
+
function createDomTree(context, model = createTreeModel()) {
|
|
1009
|
+
const id = `dk-dom-${++treesMade}`;
|
|
1010
|
+
const node = el("div", "dom");
|
|
1011
|
+
const list = el("div", "dom-tree");
|
|
1012
|
+
list.setAttribute("role", "tree");
|
|
1013
|
+
list.setAttribute("aria-label", "DOM tree");
|
|
1014
|
+
list.tabIndex = 0;
|
|
1015
|
+
node.append(list);
|
|
1016
|
+
node.hidden = true;
|
|
1017
|
+
let rows = [];
|
|
1018
|
+
let shown = [];
|
|
1019
|
+
let built = new WeakMap;
|
|
1020
|
+
let selection = null;
|
|
1021
|
+
let lit = new Map;
|
|
1022
|
+
let made = 0;
|
|
1023
|
+
let timer = 0;
|
|
1024
|
+
let frame = 0;
|
|
1025
|
+
let gone = false;
|
|
1026
|
+
const observer = typeof MutationObserver === "undefined" ? null : new MutationObserver(onRecords);
|
|
1027
|
+
function drop(target) {
|
|
1028
|
+
built.delete(target);
|
|
1029
|
+
}
|
|
1030
|
+
function isSelected(row) {
|
|
1031
|
+
if (!selection || !selectable(row))
|
|
1032
|
+
return false;
|
|
1033
|
+
return row.node === selection.node && (row.kind === "pseudo" ? row.pseudo === selection.pseudo : selection.pseudo === null);
|
|
1034
|
+
}
|
|
1035
|
+
function pieceNodes(row) {
|
|
1036
|
+
const code = el("span", "dom-code");
|
|
1037
|
+
const changed = lit.get(row.node);
|
|
1038
|
+
for (const [kind, text, name] of model.pieces(row)) {
|
|
1039
|
+
const piece = kind === "" ? el("span", "", text) : el("span", `tok-${kind}`, text);
|
|
1040
|
+
if (name !== undefined) {
|
|
1041
|
+
piece.setAttribute("data-attr", name);
|
|
1042
|
+
if (changed?.has(name))
|
|
1043
|
+
piece.classList.add("dom-flash");
|
|
1044
|
+
}
|
|
1045
|
+
code.append(piece);
|
|
1046
|
+
}
|
|
1047
|
+
return code;
|
|
1048
|
+
}
|
|
1049
|
+
function mark(line, on) {
|
|
1050
|
+
line.node.classList.toggle("on", on);
|
|
1051
|
+
line.node.setAttribute("aria-selected", on ? "true" : "false");
|
|
1052
|
+
for (const part of line.marks)
|
|
1053
|
+
part.remove();
|
|
1054
|
+
line.marks = [];
|
|
1055
|
+
if (!on)
|
|
1056
|
+
return;
|
|
1057
|
+
const ref = el("span", "dom-ref", " == $0");
|
|
1058
|
+
ref.setAttribute("aria-hidden", "true");
|
|
1059
|
+
const target = line.row.node;
|
|
1060
|
+
const copy = actButton("copy", () => context.copy(markupOf(target)));
|
|
1061
|
+
copy.setAttribute("aria-label", "Copy element");
|
|
1062
|
+
line.code.append(ref, copy);
|
|
1063
|
+
line.marks = [ref, copy];
|
|
1064
|
+
}
|
|
1065
|
+
function build(row, open) {
|
|
1066
|
+
const line = el("div", `dom-row dom-${row.kind}`);
|
|
1067
|
+
line.style.paddingLeft = `calc(var(--view-start) + ${row.depth} * var(--col-icon))`;
|
|
1068
|
+
if (row.kind === "more") {
|
|
1069
|
+
line.setAttribute("role", "none");
|
|
1070
|
+
line.append(actButton(model.pieces(row)[0]?.[1] ?? "", () => {
|
|
1071
|
+
model.showAll(row.node);
|
|
1072
|
+
drop(row.node);
|
|
1073
|
+
render();
|
|
1074
|
+
}));
|
|
1075
|
+
return { node: line, turn: line, code: line, row, open, marks: [] };
|
|
1076
|
+
}
|
|
1077
|
+
const turn = el("span", "sect-turn dom-turn");
|
|
1078
|
+
turn.setAttribute("aria-hidden", "true");
|
|
1079
|
+
const opens = row.kind !== "close" && row.kind !== "pseudo" && model.expandable(row.node);
|
|
1080
|
+
if (opens) {
|
|
1081
|
+
turn.append(icon("chevron-left", 12));
|
|
1082
|
+
turn.addEventListener("click", (event) => {
|
|
1083
|
+
event.stopPropagation();
|
|
1084
|
+
setOpen(row.node, !model.isExpanded(row.node));
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
const code = pieceNodes(row);
|
|
1088
|
+
line.append(turn, code);
|
|
1089
|
+
if (editor && row.kind === "open" && movable(row.node)) {
|
|
1090
|
+
const grip = el("span", "dom-grip", "⋮⋮");
|
|
1091
|
+
grip.setAttribute("aria-hidden", "true");
|
|
1092
|
+
grip.style.left = `max(0px, calc(var(--view-start) + ${row.depth} * var(--col-icon) - 1.2em))`;
|
|
1093
|
+
grip.addEventListener("pointerdown", (event) => startDrag(event, row, line));
|
|
1094
|
+
line.prepend(grip);
|
|
1095
|
+
}
|
|
1096
|
+
if (row.kind === "close") {
|
|
1097
|
+
line.setAttribute("aria-hidden", "true");
|
|
1098
|
+
} else {
|
|
1099
|
+
line.id = `${id}-${++made}`;
|
|
1100
|
+
line.setAttribute("role", "treeitem");
|
|
1101
|
+
line.setAttribute("aria-level", String(row.depth + 1));
|
|
1102
|
+
if (opens)
|
|
1103
|
+
line.setAttribute("aria-expanded", open ? "true" : "false");
|
|
1104
|
+
}
|
|
1105
|
+
const one = { node: line, turn, code, row, open, marks: [] };
|
|
1106
|
+
if (row.kind === "open" && isElement2(row.node) && row.node.hasAttribute(HIDE_ATTRIBUTE))
|
|
1107
|
+
line.classList.add("dom-hid");
|
|
1108
|
+
mark(one, isSelected(row));
|
|
1109
|
+
if (lit.has(row.node) && lit.get(row.node) === null)
|
|
1110
|
+
line.classList.add("dom-flash");
|
|
1111
|
+
const element = elementOf(row.node);
|
|
1112
|
+
line.addEventListener("pointerenter", () => context.outline(element));
|
|
1113
|
+
line.addEventListener("click", () => choose(row));
|
|
1114
|
+
return one;
|
|
1115
|
+
}
|
|
1116
|
+
function builtOf(row) {
|
|
1117
|
+
let lines = built.get(row.node);
|
|
1118
|
+
if (!lines) {
|
|
1119
|
+
lines = new Map;
|
|
1120
|
+
built.set(row.node, lines);
|
|
1121
|
+
}
|
|
1122
|
+
const key = slot(row);
|
|
1123
|
+
const had = lines.get(key);
|
|
1124
|
+
const open = model.isExpanded(row.node);
|
|
1125
|
+
if (had && had.row.depth === row.depth && had.open === open && had.row.more === row.more)
|
|
1126
|
+
return had;
|
|
1127
|
+
const one = build(row, open);
|
|
1128
|
+
lines.set(key, one);
|
|
1129
|
+
return one;
|
|
1130
|
+
}
|
|
1131
|
+
function lineOf(row) {
|
|
1132
|
+
return builtOf(row).node;
|
|
1133
|
+
}
|
|
1134
|
+
function observe() {
|
|
1135
|
+
if (!observer)
|
|
1136
|
+
return;
|
|
1137
|
+
observer.disconnect();
|
|
1138
|
+
const root = model.root();
|
|
1139
|
+
if (!root)
|
|
1140
|
+
return;
|
|
1141
|
+
const watch = new Map([[root, { childList: true }]]);
|
|
1142
|
+
const add = (target, options) => watch.set(target, { ...watch.get(target), ...options });
|
|
1143
|
+
for (const row of rows) {
|
|
1144
|
+
if (row.kind === "open") {
|
|
1145
|
+
add(row.node, { attributes: true, childList: true });
|
|
1146
|
+
const first = row.node.firstChild;
|
|
1147
|
+
if (first && first.nodeType === TEXT && first === row.node.lastChild)
|
|
1148
|
+
add(first, { characterData: true });
|
|
1149
|
+
} else if (row.kind === "shadow")
|
|
1150
|
+
add(row.node, { childList: true });
|
|
1151
|
+
else if (row.kind === "text" || row.kind === "comment")
|
|
1152
|
+
add(row.node, { characterData: true });
|
|
1153
|
+
}
|
|
1154
|
+
for (const [target, options] of watch) {
|
|
1155
|
+
try {
|
|
1156
|
+
observer.observe(target, options);
|
|
1157
|
+
} catch {}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
function settle() {
|
|
1161
|
+
timer = 0;
|
|
1162
|
+
if (editor?.busy())
|
|
1163
|
+
timer = window.setTimeout(settle, SETTLE);
|
|
1164
|
+
else
|
|
1165
|
+
render();
|
|
1166
|
+
}
|
|
1167
|
+
function render() {
|
|
1168
|
+
clearTimeout(timer);
|
|
1169
|
+
timer = 0;
|
|
1170
|
+
rows = model.rows();
|
|
1171
|
+
const lines = rows.map(lineOf);
|
|
1172
|
+
lit = new Map;
|
|
1173
|
+
const same2 = lines.length === shown.length && lines.every((line, at) => line === shown[at]);
|
|
1174
|
+
if (!same2) {
|
|
1175
|
+
list.replaceChildren(...lines);
|
|
1176
|
+
shown = lines;
|
|
1177
|
+
}
|
|
1178
|
+
activate();
|
|
1179
|
+
if (!same2)
|
|
1180
|
+
observe();
|
|
1181
|
+
}
|
|
1182
|
+
function activate() {
|
|
1183
|
+
const row = rows[selectedIndex()];
|
|
1184
|
+
const line = row ? lineOf(row) : null;
|
|
1185
|
+
list.setAttribute("aria-activedescendant", line?.id ?? "");
|
|
1186
|
+
editor?.selected(row ?? null);
|
|
1187
|
+
}
|
|
1188
|
+
function selectedIndex() {
|
|
1189
|
+
return rows.findIndex((row) => isSelected(row));
|
|
1190
|
+
}
|
|
1191
|
+
function cancelFrame() {
|
|
1192
|
+
if (frame)
|
|
1193
|
+
window.cancelAnimationFrame(frame);
|
|
1194
|
+
frame = 0;
|
|
1195
|
+
}
|
|
1196
|
+
function across(line) {
|
|
1197
|
+
const left = line.turn.offsetLeft;
|
|
1198
|
+
const step = line.turn.offsetWidth;
|
|
1199
|
+
const wide = node.clientWidth;
|
|
1200
|
+
if (typeof left !== "number" || typeof step !== "number" || typeof wide !== "number")
|
|
1201
|
+
return;
|
|
1202
|
+
if (left >= node.scrollLeft && left <= node.scrollLeft + wide * 2 / 3)
|
|
1203
|
+
return;
|
|
1204
|
+
node.scrollLeft = Math.max(0, left - step);
|
|
1205
|
+
}
|
|
1206
|
+
function bringIntoView(middleOf, again = true) {
|
|
1207
|
+
cancelFrame();
|
|
1208
|
+
const row = rows[selectedIndex()];
|
|
1209
|
+
if (!row)
|
|
1210
|
+
return;
|
|
1211
|
+
const seen = node.clientHeight;
|
|
1212
|
+
if (seen === 0) {
|
|
1213
|
+
if (again) {
|
|
1214
|
+
frame = window.requestAnimationFrame(() => {
|
|
1215
|
+
frame = 0;
|
|
1216
|
+
bringIntoView(middleOf, false);
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
const line = builtOf(row);
|
|
1222
|
+
across(line);
|
|
1223
|
+
const top = line.node.offsetTop;
|
|
1224
|
+
const height = line.node.offsetHeight;
|
|
1225
|
+
if (typeof top !== "number" || typeof height !== "number" || typeof seen !== "number")
|
|
1226
|
+
return;
|
|
1227
|
+
if (top >= node.scrollTop && top + height <= node.scrollTop + seen)
|
|
1228
|
+
return;
|
|
1229
|
+
if (middleOf)
|
|
1230
|
+
node.scrollTop = Math.max(0, top - (seen - height) / 2);
|
|
1231
|
+
else
|
|
1232
|
+
node.scrollTop = top < node.scrollTop ? top : top + height - seen;
|
|
1233
|
+
}
|
|
1234
|
+
function repaint(target) {
|
|
1235
|
+
for (const line of built.get(target)?.values() ?? [])
|
|
1236
|
+
if (selectable(line.row))
|
|
1237
|
+
mark(line, isSelected(line.row));
|
|
1238
|
+
}
|
|
1239
|
+
function setSelection(next) {
|
|
1240
|
+
const before = selection;
|
|
1241
|
+
selection = next;
|
|
1242
|
+
if (before)
|
|
1243
|
+
repaint(before.node);
|
|
1244
|
+
if (next)
|
|
1245
|
+
repaint(next.node);
|
|
1246
|
+
}
|
|
1247
|
+
function choose(row) {
|
|
1248
|
+
const target = row.kind === "close" ? { node: row.node, pseudo: null } : { node: row.node, pseudo: row.pseudo };
|
|
1249
|
+
setSelection(target);
|
|
1250
|
+
activate();
|
|
1251
|
+
bringIntoView(false);
|
|
1252
|
+
context.select(target.node, target.pseudo);
|
|
1253
|
+
}
|
|
1254
|
+
function setOpen(target, open) {
|
|
1255
|
+
editor?.close(true);
|
|
1256
|
+
if (open)
|
|
1257
|
+
model.forget(target);
|
|
1258
|
+
model.setExpanded(target, open);
|
|
1259
|
+
drop(target);
|
|
1260
|
+
render();
|
|
1261
|
+
}
|
|
1262
|
+
function onKeydown(event) {
|
|
1263
|
+
if (event.altKey || typesInField(event))
|
|
1264
|
+
return;
|
|
1265
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "c") {
|
|
1266
|
+
if (!selection)
|
|
1267
|
+
return;
|
|
1268
|
+
event.preventDefault();
|
|
1269
|
+
context.copy(markupOf(selection.node));
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
if (editor?.key(event, rows[selectedIndex()] ?? null)) {
|
|
1273
|
+
event.preventDefault();
|
|
1274
|
+
event.stopPropagation();
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
if (event.metaKey || event.ctrlKey)
|
|
1278
|
+
return;
|
|
1279
|
+
if (editor && event.shiftKey && (event.key === "ArrowUp" || event.key === "ArrowDown"))
|
|
1280
|
+
return;
|
|
1281
|
+
const step = stepFor(event.key, rows, selectedIndex(), model);
|
|
1282
|
+
if (!step)
|
|
1283
|
+
return;
|
|
1284
|
+
event.preventDefault();
|
|
1285
|
+
if (step.kind === "select") {
|
|
1286
|
+
const row = rows[step.at];
|
|
1287
|
+
if (row)
|
|
1288
|
+
choose(row);
|
|
1289
|
+
return;
|
|
1290
|
+
}
|
|
1291
|
+
setOpen(step.node, step.kind === "expand");
|
|
1292
|
+
}
|
|
1293
|
+
let drag = null;
|
|
1294
|
+
function lineAt(y) {
|
|
1295
|
+
for (let at = 0;at < rows.length; at++) {
|
|
1296
|
+
const line = shown[at];
|
|
1297
|
+
const row = rows[at];
|
|
1298
|
+
if (!line || !row)
|
|
1299
|
+
continue;
|
|
1300
|
+
const box = line.getBoundingClientRect();
|
|
1301
|
+
if (y >= box.top && y < box.bottom)
|
|
1302
|
+
return { row, line, fraction: box.height > 0 ? (y - box.top) / box.height : 0.5 };
|
|
1303
|
+
}
|
|
1304
|
+
return null;
|
|
1305
|
+
}
|
|
1306
|
+
function unmark() {
|
|
1307
|
+
drag?.marked?.classList.remove("dom-drop-before", "dom-drop-after", "dom-drop-into");
|
|
1308
|
+
if (drag)
|
|
1309
|
+
drag.marked = null;
|
|
1310
|
+
}
|
|
1311
|
+
function onDragMove(event) {
|
|
1312
|
+
if (!drag)
|
|
1313
|
+
return;
|
|
1314
|
+
event.preventDefault();
|
|
1315
|
+
const box = node.getBoundingClientRect();
|
|
1316
|
+
if (event.clientY < box.top + 16)
|
|
1317
|
+
node.scrollTop -= 12;
|
|
1318
|
+
else if (event.clientY > box.bottom - 16)
|
|
1319
|
+
node.scrollTop += 12;
|
|
1320
|
+
unmark();
|
|
1321
|
+
const at = lineAt(event.clientY);
|
|
1322
|
+
const drop2 = at ? dropAt(at.row, at.fraction, drag.element, model.isExpanded(at.row.node)) : null;
|
|
1323
|
+
drag.drop = drop2;
|
|
1324
|
+
if (at && drop2) {
|
|
1325
|
+
at.line.classList.add(`dom-drop-${drop2.where}`);
|
|
1326
|
+
drag.marked = at.line;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
function endDrag(commit) {
|
|
1330
|
+
if (!drag)
|
|
1331
|
+
return;
|
|
1332
|
+
const { element, line, drop: drop2 } = drag;
|
|
1333
|
+
unmark();
|
|
1334
|
+
drag = null;
|
|
1335
|
+
line.classList.remove("dom-dragging");
|
|
1336
|
+
node.classList.remove("dom-drag");
|
|
1337
|
+
window.removeEventListener("pointermove", onDragMove, true);
|
|
1338
|
+
window.removeEventListener("pointerup", onDragUp, true);
|
|
1339
|
+
window.removeEventListener("pointercancel", onDragCancel, true);
|
|
1340
|
+
window.removeEventListener("keydown", onDragKey, true);
|
|
1341
|
+
if (commit && drop2)
|
|
1342
|
+
editor?.move(element, drop2.parent, drop2.next);
|
|
1343
|
+
}
|
|
1344
|
+
function onDragUp() {
|
|
1345
|
+
endDrag(true);
|
|
1346
|
+
}
|
|
1347
|
+
function onDragCancel() {
|
|
1348
|
+
endDrag(false);
|
|
1349
|
+
}
|
|
1350
|
+
function onDragKey(event) {
|
|
1351
|
+
if (event.key !== "Escape")
|
|
1352
|
+
return;
|
|
1353
|
+
event.preventDefault();
|
|
1354
|
+
event.stopPropagation();
|
|
1355
|
+
endDrag(false);
|
|
1356
|
+
}
|
|
1357
|
+
function startDrag(event, row, line) {
|
|
1358
|
+
if (event.button !== 0 || !editor || !isElement2(row.node))
|
|
1359
|
+
return;
|
|
1360
|
+
event.preventDefault();
|
|
1361
|
+
event.stopPropagation();
|
|
1362
|
+
endDrag(false);
|
|
1363
|
+
choose(row);
|
|
1364
|
+
drag = { element: row.node, line, drop: null, marked: null };
|
|
1365
|
+
line.classList.add("dom-dragging");
|
|
1366
|
+
node.classList.add("dom-drag");
|
|
1367
|
+
window.addEventListener("pointermove", onDragMove, true);
|
|
1368
|
+
window.addEventListener("pointerup", onDragUp, true);
|
|
1369
|
+
window.addEventListener("pointercancel", onDragCancel, true);
|
|
1370
|
+
window.addEventListener("keydown", onDragKey, true);
|
|
1371
|
+
}
|
|
1372
|
+
function onLeave() {
|
|
1373
|
+
context.outline(null);
|
|
1374
|
+
}
|
|
1375
|
+
function onDoubleClick(event) {
|
|
1376
|
+
if (!editor || !hasClasses(event.target))
|
|
1377
|
+
return;
|
|
1378
|
+
const line = event.target.closest(".dom-row");
|
|
1379
|
+
const row = rows.find((one) => built.get(one.node)?.get(slot(one))?.node === line);
|
|
1380
|
+
if (row && editor.dblclick(row, event.target))
|
|
1381
|
+
event.preventDefault();
|
|
1382
|
+
}
|
|
1383
|
+
function onLit(event) {
|
|
1384
|
+
if (hasClasses(event.target))
|
|
1385
|
+
event.target.classList.remove("dom-flash");
|
|
1386
|
+
}
|
|
1387
|
+
list.addEventListener("keydown", onKeydown);
|
|
1388
|
+
list.addEventListener("pointerleave", onLeave);
|
|
1389
|
+
list.addEventListener("animationend", onLit);
|
|
1390
|
+
list.addEventListener("dblclick", onDoubleClick);
|
|
1391
|
+
function onRecords(records) {
|
|
1392
|
+
if (gone)
|
|
1393
|
+
return;
|
|
1394
|
+
let any = false;
|
|
1395
|
+
const light = (target, name) => {
|
|
1396
|
+
if (name === null) {
|
|
1397
|
+
lit.set(target, null);
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
const names = lit.get(target);
|
|
1401
|
+
if (names === null)
|
|
1402
|
+
return;
|
|
1403
|
+
lit.set(target, new Set([...names ?? [], name]));
|
|
1404
|
+
};
|
|
1405
|
+
for (const record of records) {
|
|
1406
|
+
const target = record.target;
|
|
1407
|
+
if (record.type === "childList") {
|
|
1408
|
+
const nodes = [...Array.from(record.addedNodes ?? []), ...Array.from(record.removedNodes ?? [])];
|
|
1409
|
+
if (nodes.length > 0 && nodes.every(isOwnNode))
|
|
1410
|
+
continue;
|
|
1411
|
+
model.forget(target);
|
|
1412
|
+
drop(target);
|
|
1413
|
+
for (const added of Array.from(record.addedNodes ?? []))
|
|
1414
|
+
if (!isOwnNode(added))
|
|
1415
|
+
light(added, null);
|
|
1416
|
+
any = true;
|
|
1417
|
+
} else if (record.type === "attributes") {
|
|
1418
|
+
const name = record.attributeName ?? "";
|
|
1419
|
+
if (name === HIDE_ATTRIBUTE) {
|
|
1420
|
+
drop(target);
|
|
1421
|
+
any = true;
|
|
1422
|
+
continue;
|
|
1423
|
+
}
|
|
1424
|
+
if (isOwnAttribute(name))
|
|
1425
|
+
continue;
|
|
1426
|
+
model.forget(target);
|
|
1427
|
+
drop(target);
|
|
1428
|
+
light(target, name);
|
|
1429
|
+
any = true;
|
|
1430
|
+
} else if (record.type === "characterData") {
|
|
1431
|
+
drop(target);
|
|
1432
|
+
const parent = target.parentNode;
|
|
1433
|
+
if (parent) {
|
|
1434
|
+
model.forget(parent);
|
|
1435
|
+
drop(parent);
|
|
1436
|
+
}
|
|
1437
|
+
light(target, null);
|
|
1438
|
+
any = true;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
if (any && !timer)
|
|
1442
|
+
timer = window.setTimeout(settle, SETTLE);
|
|
1443
|
+
}
|
|
1444
|
+
function reveal(target, pseudo = null) {
|
|
1445
|
+
editor?.close(true);
|
|
1446
|
+
if (!target) {
|
|
1447
|
+
observer?.disconnect();
|
|
1448
|
+
clearTimeout(timer);
|
|
1449
|
+
timer = 0;
|
|
1450
|
+
cancelFrame();
|
|
1451
|
+
model.setRoot(null);
|
|
1452
|
+
built = new WeakMap;
|
|
1453
|
+
selection = null;
|
|
1454
|
+
rows = [];
|
|
1455
|
+
shown = [];
|
|
1456
|
+
list.replaceChildren();
|
|
1457
|
+
node.hidden = true;
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const doc = isDocument2(target) ? target : target.ownerDocument;
|
|
1461
|
+
if (doc !== model.root()) {
|
|
1462
|
+
model.setRoot(doc);
|
|
1463
|
+
built = new WeakMap;
|
|
1464
|
+
}
|
|
1465
|
+
node.hidden = false;
|
|
1466
|
+
for (let at = parentOf(target);at; at = parentOf(at)) {
|
|
1467
|
+
model.forget(at);
|
|
1468
|
+
drop(at);
|
|
1469
|
+
}
|
|
1470
|
+
model.reveal(target);
|
|
1471
|
+
setSelection({ node: target, pseudo });
|
|
1472
|
+
render();
|
|
1473
|
+
bringIntoView(true);
|
|
1474
|
+
}
|
|
1475
|
+
const editor = context.editor?.({
|
|
1476
|
+
list,
|
|
1477
|
+
code: (row) => rows.includes(row) ? builtOf(row).code : null,
|
|
1478
|
+
children: (target) => model.children(target),
|
|
1479
|
+
select(target) {
|
|
1480
|
+
reveal(target);
|
|
1481
|
+
context.select(target, null);
|
|
1482
|
+
},
|
|
1483
|
+
settled() {
|
|
1484
|
+
if (timer) {
|
|
1485
|
+
clearTimeout(timer);
|
|
1486
|
+
timer = window.setTimeout(settle, 0);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
}) ?? null;
|
|
1490
|
+
if (editor)
|
|
1491
|
+
node.append(editor.bar);
|
|
1492
|
+
return {
|
|
1493
|
+
node,
|
|
1494
|
+
reveal,
|
|
1495
|
+
select(target) {
|
|
1496
|
+
reveal(target);
|
|
1497
|
+
context.select(target, null);
|
|
1498
|
+
},
|
|
1499
|
+
selected: () => selection?.node ?? null,
|
|
1500
|
+
escape: () => editor?.close(false) ?? false,
|
|
1501
|
+
destroy() {
|
|
1502
|
+
endDrag(false);
|
|
1503
|
+
editor?.destroy();
|
|
1504
|
+
gone = true;
|
|
1505
|
+
observer?.disconnect();
|
|
1506
|
+
clearTimeout(timer);
|
|
1507
|
+
timer = 0;
|
|
1508
|
+
cancelFrame();
|
|
1509
|
+
list.removeEventListener("keydown", onKeydown);
|
|
1510
|
+
list.removeEventListener("pointerleave", onLeave);
|
|
1511
|
+
list.removeEventListener("animationend", onLit);
|
|
1512
|
+
list.removeEventListener("dblclick", onDoubleClick);
|
|
1513
|
+
context.outline(null);
|
|
1514
|
+
selection = null;
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
export { invalidate, rulesOf, layerRanks, HIDE_ATTRIBUTE, successor, textEdit, attributeName, attrEdit, parseHtml, htmlEdit, hideEdit, deleteEdit, nextElementOf, previousElementOf, movable, canHold, moveEdit, isElement2 as isElement, parentOf, elementOf, markupOf, createDomTree };
|