@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,258 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
attrEdit,
|
|
4
|
+
deleteEdit,
|
|
5
|
+
hideEdit,
|
|
6
|
+
htmlEdit,
|
|
7
|
+
markupOf,
|
|
8
|
+
moveEdit,
|
|
9
|
+
nextElementOf,
|
|
10
|
+
parseHtml,
|
|
11
|
+
rulesOf,
|
|
12
|
+
textEdit
|
|
13
|
+
} from "./react-0wepdf60.js";
|
|
14
|
+
import {
|
|
15
|
+
REASONS,
|
|
16
|
+
RISK,
|
|
17
|
+
readSavedEdit,
|
|
18
|
+
riskyAttribute,
|
|
19
|
+
riskyElement,
|
|
20
|
+
riskyNodes
|
|
21
|
+
} from "./react-6bz05qk1.js";
|
|
22
|
+
import"./react-6fnxxs30.js";
|
|
23
|
+
import {
|
|
24
|
+
NEW_RULE_SHEET,
|
|
25
|
+
cssOff,
|
|
26
|
+
cssOn,
|
|
27
|
+
cssValue,
|
|
28
|
+
newRule,
|
|
29
|
+
offIn,
|
|
30
|
+
ruleOf,
|
|
31
|
+
sheetIdOf
|
|
32
|
+
} from "./react-ethftdxp.js";
|
|
33
|
+
import"./react-bxzn8vq5.js";
|
|
34
|
+
import"./react-6q2cw2ya.js";
|
|
35
|
+
import"./react-wqn4sx0n.js";
|
|
36
|
+
import"./react-t2qnewz2.js";
|
|
37
|
+
|
|
38
|
+
// src/edit/replay.ts
|
|
39
|
+
var AFTER_MISSED = "an earlier edit it may depend on was not made";
|
|
40
|
+
var STRUCTURE = new Set(["delete", "move", "html"]);
|
|
41
|
+
var JOIN = /\s*(>>>|>>iframe>>)\s*/;
|
|
42
|
+
function isScope(node) {
|
|
43
|
+
if (typeof node !== "object" || node === null)
|
|
44
|
+
return false;
|
|
45
|
+
const type = Reflect.get(node, "nodeType");
|
|
46
|
+
return type === 9 || type === 11;
|
|
47
|
+
}
|
|
48
|
+
function hasStyle(element) {
|
|
49
|
+
return "style" in element;
|
|
50
|
+
}
|
|
51
|
+
function findElement(doc, selector) {
|
|
52
|
+
const steps = selector.split(JOIN);
|
|
53
|
+
let scope = doc;
|
|
54
|
+
let found = null;
|
|
55
|
+
for (let at = 0;at < steps.length; at += 2) {
|
|
56
|
+
if (!scope)
|
|
57
|
+
return null;
|
|
58
|
+
try {
|
|
59
|
+
found = scope.querySelector(steps[at] ?? "");
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (!found)
|
|
64
|
+
return null;
|
|
65
|
+
const join = steps[at + 1];
|
|
66
|
+
if (join === ">>>")
|
|
67
|
+
scope = found.shadowRoot;
|
|
68
|
+
else if (join) {
|
|
69
|
+
const inner = Reflect.get(found, "contentDocument");
|
|
70
|
+
scope = isScope(inner) ? inner : null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return found;
|
|
74
|
+
}
|
|
75
|
+
function textAt(element, property) {
|
|
76
|
+
const match = /^text(?: (\d+))?$/.exec(property);
|
|
77
|
+
if (!match)
|
|
78
|
+
return null;
|
|
79
|
+
const at = Number(match[1] ?? "1");
|
|
80
|
+
const texts = Array.from(element.childNodes).filter((one) => one.nodeType === 3 && (one.nodeValue ?? "").trim() !== "");
|
|
81
|
+
return texts[at - 1] ?? null;
|
|
82
|
+
}
|
|
83
|
+
function same(a, b) {
|
|
84
|
+
return a.length === b.length && a.every((one, at) => one === b[at]);
|
|
85
|
+
}
|
|
86
|
+
function placeOf(edit, element, made) {
|
|
87
|
+
const rule = edit.target.rule;
|
|
88
|
+
const selector = edit.target.selector;
|
|
89
|
+
if (!rule)
|
|
90
|
+
return hasStyle(element) ? { style: element.style, element, selector } : REASONS.missing;
|
|
91
|
+
if (rule.sheet === NEW_RULE_SHEET) {
|
|
92
|
+
const found2 = made.get(rule.sheetId);
|
|
93
|
+
if (!found2)
|
|
94
|
+
return REASONS.rule;
|
|
95
|
+
return { style: found2.style, element, selector, rule: { ...rule, sheetId: sheetIdOf(found2), path: [0], context: [] } };
|
|
96
|
+
}
|
|
97
|
+
const scope = element.getRootNode();
|
|
98
|
+
if (!isScope(scope))
|
|
99
|
+
return REASONS.rule;
|
|
100
|
+
const fits = rulesOf(scope).rules.filter((one) => one.selectorText === rule.selectorText && same(one.context, rule.context) && one.origin.sheet === rule.sheet && one.origin.owner === rule.owner);
|
|
101
|
+
const found = fits.find((one) => same(one.origin.path.map(String), rule.path.map(String))) ?? fits[0];
|
|
102
|
+
if (!found)
|
|
103
|
+
return REASONS.rule;
|
|
104
|
+
return {
|
|
105
|
+
style: found.rule.style,
|
|
106
|
+
element,
|
|
107
|
+
selector,
|
|
108
|
+
rule: { selectorText: rule.selectorText, sheet: rule.sheet, owner: rule.owner, sheetId: sheetIdOf(found.rule), path: [...found.origin.path], context: [...found.context] }
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function cssChange(log, edit, element, made) {
|
|
112
|
+
if (edit.kind === "css-rule") {
|
|
113
|
+
if (edit.before !== null || edit.after === null)
|
|
114
|
+
return REASONS.invalid;
|
|
115
|
+
const change2 = newRule({ element, selector: edit.target.selector }, edit.after);
|
|
116
|
+
if (!change2)
|
|
117
|
+
return REASONS.refused;
|
|
118
|
+
const rule = ruleOf(change2);
|
|
119
|
+
if (rule && edit.target.rule)
|
|
120
|
+
made.set(edit.target.rule.sheetId, rule);
|
|
121
|
+
return change2;
|
|
122
|
+
}
|
|
123
|
+
const place = placeOf(edit, element, made);
|
|
124
|
+
if (typeof place === "string")
|
|
125
|
+
return place;
|
|
126
|
+
if (edit.kind === "css-toggle" && edit.after === null) {
|
|
127
|
+
const change2 = cssOff(place, edit.property, log.recorded);
|
|
128
|
+
return change2 && change2.edit.before === edit.before ? change2 : REASONS.changed;
|
|
129
|
+
}
|
|
130
|
+
if (edit.kind === "css-toggle") {
|
|
131
|
+
const off = offIn(log.recorded(), place.style).find((one) => one.property === edit.property && one.text === edit.after);
|
|
132
|
+
return off && edit.before === null ? cssOn(place, off, log.recorded) : REASONS.changed;
|
|
133
|
+
}
|
|
134
|
+
if (edit.after === null || edit.kind !== "css-value" && edit.kind !== "css-add")
|
|
135
|
+
return REASONS.invalid;
|
|
136
|
+
const change = cssValue(edit.kind, place, edit.property, edit.after);
|
|
137
|
+
return change && change.edit.before === edit.before ? change : REASONS.changed;
|
|
138
|
+
}
|
|
139
|
+
function htmlChange(edit, element) {
|
|
140
|
+
const target = { selector: edit.target.selector };
|
|
141
|
+
const doc = element.ownerDocument;
|
|
142
|
+
switch (edit.kind) {
|
|
143
|
+
case "text": {
|
|
144
|
+
const node = textAt(element, edit.property);
|
|
145
|
+
if (!node)
|
|
146
|
+
return REASONS.missing;
|
|
147
|
+
if (edit.after === null)
|
|
148
|
+
return REASONS.invalid;
|
|
149
|
+
if (riskyElement(element))
|
|
150
|
+
return RISK;
|
|
151
|
+
if ((node.nodeValue ?? "").trim() !== edit.before)
|
|
152
|
+
return REASONS.changed;
|
|
153
|
+
return textEdit(target, node, edit.after, edit.property) ?? REASONS.changed;
|
|
154
|
+
}
|
|
155
|
+
case "attr": {
|
|
156
|
+
if (riskyElement(element) || riskyAttribute(edit.property, edit.after))
|
|
157
|
+
return RISK;
|
|
158
|
+
const change = attrEdit(target, element, edit.property, edit.after);
|
|
159
|
+
return change && change.edit.before === edit.before ? change : REASONS.changed;
|
|
160
|
+
}
|
|
161
|
+
case "html": {
|
|
162
|
+
if (edit.before === null || edit.after === null)
|
|
163
|
+
return REASONS.invalid;
|
|
164
|
+
if (markupOf(element) !== edit.before)
|
|
165
|
+
return REASONS.changed;
|
|
166
|
+
const nodes = parseHtml(doc, edit.after);
|
|
167
|
+
if (riskyNodes(nodes))
|
|
168
|
+
return RISK;
|
|
169
|
+
return htmlEdit(target, element, edit.before, nodes) ?? REASONS.refused;
|
|
170
|
+
}
|
|
171
|
+
case "hide": {
|
|
172
|
+
const change = hideEdit(target, element);
|
|
173
|
+
return change.edit.before === edit.before ? change : REASONS.changed;
|
|
174
|
+
}
|
|
175
|
+
case "delete": {
|
|
176
|
+
if (edit.before === null)
|
|
177
|
+
return REASONS.invalid;
|
|
178
|
+
let node = element;
|
|
179
|
+
if (edit.property === "comment")
|
|
180
|
+
node = Array.from(element.childNodes).find((one) => one.nodeType === 8 && markupOf(one) === edit.before) ?? null;
|
|
181
|
+
else if (edit.property !== "node")
|
|
182
|
+
node = textAt(element, edit.property);
|
|
183
|
+
if (!node)
|
|
184
|
+
return REASONS.missing;
|
|
185
|
+
if (markupOf(node) !== edit.before)
|
|
186
|
+
return REASONS.changed;
|
|
187
|
+
return deleteEdit(target, node, edit.before, edit.property) ?? REASONS.refused;
|
|
188
|
+
}
|
|
189
|
+
case "move": {
|
|
190
|
+
const { from, to } = edit;
|
|
191
|
+
if (!from || !to)
|
|
192
|
+
return REASONS.invalid;
|
|
193
|
+
const home = findElement(doc, from.parent);
|
|
194
|
+
const was = from.next === null ? null : findElement(doc, from.next);
|
|
195
|
+
if (element.parentNode !== home || from.next !== null && !was || nextElementOf(element) !== was)
|
|
196
|
+
return REASONS.changed;
|
|
197
|
+
const parent = findElement(doc, to.parent);
|
|
198
|
+
const next = to.next === null ? null : findElement(doc, to.next);
|
|
199
|
+
if (!parent || to.next !== null && !next)
|
|
200
|
+
return REASONS.missing;
|
|
201
|
+
return moveEdit(target, element, { parent, next }, { from, to }) ?? REASONS.refused;
|
|
202
|
+
}
|
|
203
|
+
default:
|
|
204
|
+
return REASONS.invalid;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function replayEdits(log, list, hold = false, doc = document) {
|
|
208
|
+
const applied = [];
|
|
209
|
+
const skipped = [];
|
|
210
|
+
const waiting = [];
|
|
211
|
+
const made = new Map;
|
|
212
|
+
let broken = false;
|
|
213
|
+
for (const entry of list) {
|
|
214
|
+
const edit = readSavedEdit(entry);
|
|
215
|
+
if (!edit) {
|
|
216
|
+
skipped.push({ edit: entry, reason: REASONS.invalid });
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (waiting.length > 0 || hold && (edit.kind === "html" || edit.kind === "attr")) {
|
|
220
|
+
waiting.push(edit);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (broken) {
|
|
224
|
+
skipped.push({ edit, reason: AFTER_MISSED });
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const element = findElement(doc, edit.target.selector);
|
|
228
|
+
if (!element) {
|
|
229
|
+
skipped.push({ edit, reason: REASONS.missing });
|
|
230
|
+
if (STRUCTURE.has(edit.kind))
|
|
231
|
+
broken = true;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
let change;
|
|
235
|
+
try {
|
|
236
|
+
change = edit.kind.startsWith("css-") ? cssChange(log, edit, element, made) : htmlChange(edit, element);
|
|
237
|
+
} catch {
|
|
238
|
+
change = REASONS.refused;
|
|
239
|
+
}
|
|
240
|
+
const recorded = typeof change === "string" ? null : log.record(change);
|
|
241
|
+
if (!recorded) {
|
|
242
|
+
skipped.push({ edit, reason: typeof change === "string" ? change : REASONS.refused });
|
|
243
|
+
if (STRUCTURE.has(edit.kind))
|
|
244
|
+
broken = true;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
const source = edit.target.source;
|
|
248
|
+
if (source)
|
|
249
|
+
log.locate(recorded.id, { source });
|
|
250
|
+
applied.push(source ? { ...recorded, target: { ...recorded.target, source } } : recorded);
|
|
251
|
+
}
|
|
252
|
+
return { applied, skipped, waiting };
|
|
253
|
+
}
|
|
254
|
+
export {
|
|
255
|
+
replayEdits,
|
|
256
|
+
findElement,
|
|
257
|
+
AFTER_MISSED
|
|
258
|
+
};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import {
|
|
2
|
+
attrEdit,
|
|
3
|
+
deleteEdit,
|
|
4
|
+
hideEdit,
|
|
5
|
+
htmlEdit,
|
|
6
|
+
markupOf,
|
|
7
|
+
moveEdit,
|
|
8
|
+
nextElementOf,
|
|
9
|
+
parseHtml,
|
|
10
|
+
rulesOf,
|
|
11
|
+
textEdit
|
|
12
|
+
} from "./index-v0ht9q0g.js";
|
|
13
|
+
import {
|
|
14
|
+
REASONS,
|
|
15
|
+
RISK,
|
|
16
|
+
readSavedEdit,
|
|
17
|
+
riskyAttribute,
|
|
18
|
+
riskyElement,
|
|
19
|
+
riskyNodes
|
|
20
|
+
} from "./index-0zp9py56.js";
|
|
21
|
+
import"./index-ftjdt358.js";
|
|
22
|
+
import {
|
|
23
|
+
NEW_RULE_SHEET,
|
|
24
|
+
cssOff,
|
|
25
|
+
cssOn,
|
|
26
|
+
cssValue,
|
|
27
|
+
newRule,
|
|
28
|
+
offIn,
|
|
29
|
+
ruleOf,
|
|
30
|
+
sheetIdOf
|
|
31
|
+
} from "./index-zd6adby9.js";
|
|
32
|
+
import"./index-4a4x1bt2.js";
|
|
33
|
+
import"./index-6bc2ztfd.js";
|
|
34
|
+
import"./index-dzm8ywq0.js";
|
|
35
|
+
import"./index-5tv6sr74.js";
|
|
36
|
+
|
|
37
|
+
// src/edit/replay.ts
|
|
38
|
+
var AFTER_MISSED = "an earlier edit it may depend on was not made";
|
|
39
|
+
var STRUCTURE = new Set(["delete", "move", "html"]);
|
|
40
|
+
var JOIN = /\s*(>>>|>>iframe>>)\s*/;
|
|
41
|
+
function isScope(node) {
|
|
42
|
+
if (typeof node !== "object" || node === null)
|
|
43
|
+
return false;
|
|
44
|
+
const type = Reflect.get(node, "nodeType");
|
|
45
|
+
return type === 9 || type === 11;
|
|
46
|
+
}
|
|
47
|
+
function hasStyle(element) {
|
|
48
|
+
return "style" in element;
|
|
49
|
+
}
|
|
50
|
+
function findElement(doc, selector) {
|
|
51
|
+
const steps = selector.split(JOIN);
|
|
52
|
+
let scope = doc;
|
|
53
|
+
let found = null;
|
|
54
|
+
for (let at = 0;at < steps.length; at += 2) {
|
|
55
|
+
if (!scope)
|
|
56
|
+
return null;
|
|
57
|
+
try {
|
|
58
|
+
found = scope.querySelector(steps[at] ?? "");
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (!found)
|
|
63
|
+
return null;
|
|
64
|
+
const join = steps[at + 1];
|
|
65
|
+
if (join === ">>>")
|
|
66
|
+
scope = found.shadowRoot;
|
|
67
|
+
else if (join) {
|
|
68
|
+
const inner = Reflect.get(found, "contentDocument");
|
|
69
|
+
scope = isScope(inner) ? inner : null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
74
|
+
function textAt(element, property) {
|
|
75
|
+
const match = /^text(?: (\d+))?$/.exec(property);
|
|
76
|
+
if (!match)
|
|
77
|
+
return null;
|
|
78
|
+
const at = Number(match[1] ?? "1");
|
|
79
|
+
const texts = Array.from(element.childNodes).filter((one) => one.nodeType === 3 && (one.nodeValue ?? "").trim() !== "");
|
|
80
|
+
return texts[at - 1] ?? null;
|
|
81
|
+
}
|
|
82
|
+
function same(a, b) {
|
|
83
|
+
return a.length === b.length && a.every((one, at) => one === b[at]);
|
|
84
|
+
}
|
|
85
|
+
function placeOf(edit, element, made) {
|
|
86
|
+
const rule = edit.target.rule;
|
|
87
|
+
const selector = edit.target.selector;
|
|
88
|
+
if (!rule)
|
|
89
|
+
return hasStyle(element) ? { style: element.style, element, selector } : REASONS.missing;
|
|
90
|
+
if (rule.sheet === NEW_RULE_SHEET) {
|
|
91
|
+
const found2 = made.get(rule.sheetId);
|
|
92
|
+
if (!found2)
|
|
93
|
+
return REASONS.rule;
|
|
94
|
+
return { style: found2.style, element, selector, rule: { ...rule, sheetId: sheetIdOf(found2), path: [0], context: [] } };
|
|
95
|
+
}
|
|
96
|
+
const scope = element.getRootNode();
|
|
97
|
+
if (!isScope(scope))
|
|
98
|
+
return REASONS.rule;
|
|
99
|
+
const fits = rulesOf(scope).rules.filter((one) => one.selectorText === rule.selectorText && same(one.context, rule.context) && one.origin.sheet === rule.sheet && one.origin.owner === rule.owner);
|
|
100
|
+
const found = fits.find((one) => same(one.origin.path.map(String), rule.path.map(String))) ?? fits[0];
|
|
101
|
+
if (!found)
|
|
102
|
+
return REASONS.rule;
|
|
103
|
+
return {
|
|
104
|
+
style: found.rule.style,
|
|
105
|
+
element,
|
|
106
|
+
selector,
|
|
107
|
+
rule: { selectorText: rule.selectorText, sheet: rule.sheet, owner: rule.owner, sheetId: sheetIdOf(found.rule), path: [...found.origin.path], context: [...found.context] }
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function cssChange(log, edit, element, made) {
|
|
111
|
+
if (edit.kind === "css-rule") {
|
|
112
|
+
if (edit.before !== null || edit.after === null)
|
|
113
|
+
return REASONS.invalid;
|
|
114
|
+
const change2 = newRule({ element, selector: edit.target.selector }, edit.after);
|
|
115
|
+
if (!change2)
|
|
116
|
+
return REASONS.refused;
|
|
117
|
+
const rule = ruleOf(change2);
|
|
118
|
+
if (rule && edit.target.rule)
|
|
119
|
+
made.set(edit.target.rule.sheetId, rule);
|
|
120
|
+
return change2;
|
|
121
|
+
}
|
|
122
|
+
const place = placeOf(edit, element, made);
|
|
123
|
+
if (typeof place === "string")
|
|
124
|
+
return place;
|
|
125
|
+
if (edit.kind === "css-toggle" && edit.after === null) {
|
|
126
|
+
const change2 = cssOff(place, edit.property, log.recorded);
|
|
127
|
+
return change2 && change2.edit.before === edit.before ? change2 : REASONS.changed;
|
|
128
|
+
}
|
|
129
|
+
if (edit.kind === "css-toggle") {
|
|
130
|
+
const off = offIn(log.recorded(), place.style).find((one) => one.property === edit.property && one.text === edit.after);
|
|
131
|
+
return off && edit.before === null ? cssOn(place, off, log.recorded) : REASONS.changed;
|
|
132
|
+
}
|
|
133
|
+
if (edit.after === null || edit.kind !== "css-value" && edit.kind !== "css-add")
|
|
134
|
+
return REASONS.invalid;
|
|
135
|
+
const change = cssValue(edit.kind, place, edit.property, edit.after);
|
|
136
|
+
return change && change.edit.before === edit.before ? change : REASONS.changed;
|
|
137
|
+
}
|
|
138
|
+
function htmlChange(edit, element) {
|
|
139
|
+
const target = { selector: edit.target.selector };
|
|
140
|
+
const doc = element.ownerDocument;
|
|
141
|
+
switch (edit.kind) {
|
|
142
|
+
case "text": {
|
|
143
|
+
const node = textAt(element, edit.property);
|
|
144
|
+
if (!node)
|
|
145
|
+
return REASONS.missing;
|
|
146
|
+
if (edit.after === null)
|
|
147
|
+
return REASONS.invalid;
|
|
148
|
+
if (riskyElement(element))
|
|
149
|
+
return RISK;
|
|
150
|
+
if ((node.nodeValue ?? "").trim() !== edit.before)
|
|
151
|
+
return REASONS.changed;
|
|
152
|
+
return textEdit(target, node, edit.after, edit.property) ?? REASONS.changed;
|
|
153
|
+
}
|
|
154
|
+
case "attr": {
|
|
155
|
+
if (riskyElement(element) || riskyAttribute(edit.property, edit.after))
|
|
156
|
+
return RISK;
|
|
157
|
+
const change = attrEdit(target, element, edit.property, edit.after);
|
|
158
|
+
return change && change.edit.before === edit.before ? change : REASONS.changed;
|
|
159
|
+
}
|
|
160
|
+
case "html": {
|
|
161
|
+
if (edit.before === null || edit.after === null)
|
|
162
|
+
return REASONS.invalid;
|
|
163
|
+
if (markupOf(element) !== edit.before)
|
|
164
|
+
return REASONS.changed;
|
|
165
|
+
const nodes = parseHtml(doc, edit.after);
|
|
166
|
+
if (riskyNodes(nodes))
|
|
167
|
+
return RISK;
|
|
168
|
+
return htmlEdit(target, element, edit.before, nodes) ?? REASONS.refused;
|
|
169
|
+
}
|
|
170
|
+
case "hide": {
|
|
171
|
+
const change = hideEdit(target, element);
|
|
172
|
+
return change.edit.before === edit.before ? change : REASONS.changed;
|
|
173
|
+
}
|
|
174
|
+
case "delete": {
|
|
175
|
+
if (edit.before === null)
|
|
176
|
+
return REASONS.invalid;
|
|
177
|
+
let node = element;
|
|
178
|
+
if (edit.property === "comment")
|
|
179
|
+
node = Array.from(element.childNodes).find((one) => one.nodeType === 8 && markupOf(one) === edit.before) ?? null;
|
|
180
|
+
else if (edit.property !== "node")
|
|
181
|
+
node = textAt(element, edit.property);
|
|
182
|
+
if (!node)
|
|
183
|
+
return REASONS.missing;
|
|
184
|
+
if (markupOf(node) !== edit.before)
|
|
185
|
+
return REASONS.changed;
|
|
186
|
+
return deleteEdit(target, node, edit.before, edit.property) ?? REASONS.refused;
|
|
187
|
+
}
|
|
188
|
+
case "move": {
|
|
189
|
+
const { from, to } = edit;
|
|
190
|
+
if (!from || !to)
|
|
191
|
+
return REASONS.invalid;
|
|
192
|
+
const home = findElement(doc, from.parent);
|
|
193
|
+
const was = from.next === null ? null : findElement(doc, from.next);
|
|
194
|
+
if (element.parentNode !== home || from.next !== null && !was || nextElementOf(element) !== was)
|
|
195
|
+
return REASONS.changed;
|
|
196
|
+
const parent = findElement(doc, to.parent);
|
|
197
|
+
const next = to.next === null ? null : findElement(doc, to.next);
|
|
198
|
+
if (!parent || to.next !== null && !next)
|
|
199
|
+
return REASONS.missing;
|
|
200
|
+
return moveEdit(target, element, { parent, next }, { from, to }) ?? REASONS.refused;
|
|
201
|
+
}
|
|
202
|
+
default:
|
|
203
|
+
return REASONS.invalid;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function replayEdits(log, list, hold = false, doc = document) {
|
|
207
|
+
const applied = [];
|
|
208
|
+
const skipped = [];
|
|
209
|
+
const waiting = [];
|
|
210
|
+
const made = new Map;
|
|
211
|
+
let broken = false;
|
|
212
|
+
for (const entry of list) {
|
|
213
|
+
const edit = readSavedEdit(entry);
|
|
214
|
+
if (!edit) {
|
|
215
|
+
skipped.push({ edit: entry, reason: REASONS.invalid });
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (waiting.length > 0 || hold && (edit.kind === "html" || edit.kind === "attr")) {
|
|
219
|
+
waiting.push(edit);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (broken) {
|
|
223
|
+
skipped.push({ edit, reason: AFTER_MISSED });
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const element = findElement(doc, edit.target.selector);
|
|
227
|
+
if (!element) {
|
|
228
|
+
skipped.push({ edit, reason: REASONS.missing });
|
|
229
|
+
if (STRUCTURE.has(edit.kind))
|
|
230
|
+
broken = true;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
let change;
|
|
234
|
+
try {
|
|
235
|
+
change = edit.kind.startsWith("css-") ? cssChange(log, edit, element, made) : htmlChange(edit, element);
|
|
236
|
+
} catch {
|
|
237
|
+
change = REASONS.refused;
|
|
238
|
+
}
|
|
239
|
+
const recorded = typeof change === "string" ? null : log.record(change);
|
|
240
|
+
if (!recorded) {
|
|
241
|
+
skipped.push({ edit, reason: typeof change === "string" ? change : REASONS.refused });
|
|
242
|
+
if (STRUCTURE.has(edit.kind))
|
|
243
|
+
broken = true;
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const source = edit.target.source;
|
|
247
|
+
if (source)
|
|
248
|
+
log.locate(recorded.id, { source });
|
|
249
|
+
applied.push(source ? { ...recorded, target: { ...recorded.target, source } } : recorded);
|
|
250
|
+
}
|
|
251
|
+
return { applied, skipped, waiting };
|
|
252
|
+
}
|
|
253
|
+
export {
|
|
254
|
+
replayEdits,
|
|
255
|
+
findElement,
|
|
256
|
+
AFTER_MISSED
|
|
257
|
+
};
|
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
cookieText,
|
|
7
7
|
put,
|
|
8
8
|
storedPresets
|
|
9
|
-
} from "./react-
|
|
9
|
+
} from "./react-6t4dbdzn.js";
|
|
10
|
+
import {
|
|
11
|
+
copyText
|
|
12
|
+
} from "./react-h9w04skh.js";
|
|
10
13
|
import {
|
|
11
14
|
branch,
|
|
12
15
|
codeBlock,
|
|
@@ -28,17 +31,18 @@ import {
|
|
|
28
31
|
textArea,
|
|
29
32
|
textField,
|
|
30
33
|
toolbar
|
|
31
|
-
} from "./react-
|
|
32
|
-
import
|
|
33
|
-
|
|
34
|
-
} from "./react-h9w04skh.js";
|
|
34
|
+
} from "./react-bxzn8vq5.js";
|
|
35
|
+
import"./react-cs62p9qh.js";
|
|
36
|
+
import"./react-ttj8f9qp.js";
|
|
35
37
|
import {
|
|
36
38
|
icon
|
|
37
|
-
} from "./react-
|
|
39
|
+
} from "./react-6q2cw2ya.js";
|
|
38
40
|
import {
|
|
39
41
|
stamped,
|
|
40
42
|
webStorage
|
|
41
|
-
} from "./react-
|
|
43
|
+
} from "./react-wqn4sx0n.js";
|
|
44
|
+
import"./react-fp73vhyd.js";
|
|
45
|
+
import"./react-t2qnewz2.js";
|
|
42
46
|
|
|
43
47
|
// src/storage/site.ts
|
|
44
48
|
function isOwn(key) {
|
|
@@ -5,7 +5,10 @@ import {
|
|
|
5
5
|
cookieText,
|
|
6
6
|
put,
|
|
7
7
|
storedPresets
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-aynkv7qk.js";
|
|
9
|
+
import {
|
|
10
|
+
copyText
|
|
11
|
+
} from "./index-ztnjefrh.js";
|
|
9
12
|
import {
|
|
10
13
|
branch,
|
|
11
14
|
codeBlock,
|
|
@@ -27,17 +30,18 @@ import {
|
|
|
27
30
|
textArea,
|
|
28
31
|
textField,
|
|
29
32
|
toolbar
|
|
30
|
-
} from "./index-
|
|
31
|
-
import
|
|
32
|
-
|
|
33
|
-
} from "./index-ztnjefrh.js";
|
|
33
|
+
} from "./index-4a4x1bt2.js";
|
|
34
|
+
import"./index-x59vz1xx.js";
|
|
35
|
+
import"./index-7cb4x1vj.js";
|
|
34
36
|
import {
|
|
35
37
|
icon
|
|
36
|
-
} from "./index-
|
|
38
|
+
} from "./index-6bc2ztfd.js";
|
|
37
39
|
import {
|
|
38
40
|
stamped,
|
|
39
41
|
webStorage
|
|
40
|
-
} from "./index-
|
|
42
|
+
} from "./index-dzm8ywq0.js";
|
|
43
|
+
import"./index-a974q3aa.js";
|
|
44
|
+
import"./index-5tv6sr74.js";
|
|
41
45
|
|
|
42
46
|
// src/storage/site.ts
|
|
43
47
|
function isOwn(key) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* States forced on an element, as the browsers' tools force them: the
|
|
3
|
+
* element renders, and the styles engine reads it, as if it were hovered,
|
|
4
|
+
* focused or pressed. A page's script cannot set those states, so they are
|
|
5
|
+
* emulated. The element carries `data-devknobs-force` with the states, its
|
|
6
|
+
* ancestors with those the states bring to them (`hover`, `active`,
|
|
7
|
+
* `focus-within`), and every rule of the page whose selector has one of the
|
|
8
|
+
* states is copied into a stylesheet of devknobs' own, with each such
|
|
9
|
+
* pseudo-class `:hover` written `:is(:hover, [data-devknobs-force~="hover"])`:
|
|
10
|
+
* as heavy as before, and true where the page has the state for real too.
|
|
11
|
+
* The copy keeps the `@media`, `@supports`, `@container`, `@layer` and
|
|
12
|
+
* `@scope` around a rule, and nested rules come out whole. One element at a
|
|
13
|
+
* time. Forcing is no edit: the log never sees it. To use it:
|
|
14
|
+
*
|
|
15
|
+
* forceState(element, ["hover"]); // the states now forced
|
|
16
|
+
* syncForced(); // after the page's stylesheets changed
|
|
17
|
+
* clearForced();
|
|
18
|
+
*
|
|
19
|
+
* Where it falls short: a stylesheet from another origin cannot be read, so
|
|
20
|
+
* its rules are not copied; a copied rule comes after the page's rules, so it
|
|
21
|
+
* wins a tie of equal weight that the page's own order would have lost; a
|
|
22
|
+
* state is on the element and its ancestors only, so `:has()` finds it there
|
|
23
|
+
* and nowhere else, as with a real hover; a selector the browser will not
|
|
24
|
+
* take once written so is left out; an `@scope` with no start is scoped to
|
|
25
|
+
* the whole document; a rule in a `@layer` with no name is not copied, as a
|
|
26
|
+
* copy would be a layer of its own; and `:visited` is not forced, as
|
|
27
|
+
* browsers hide it from a page. A rule nested in a list that has a state in only some of its
|
|
28
|
+
* selectors, as `.a:hover, .b { .icon { } }`, is copied under the whole list,
|
|
29
|
+
* `:is(.a:hover, .b) .icon`, so it applies again to `.b .icon` too.
|
|
30
|
+
*/
|
|
31
|
+
import { type Scope } from "./tree";
|
|
32
|
+
/** The states that can be forced, in the order the view shows them. */
|
|
33
|
+
export declare const FORCED_STATES: readonly ["hover", "focus", "focus-visible", "active", "focus-within"];
|
|
34
|
+
export type ForcedState = (typeof FORCED_STATES)[number];
|
|
35
|
+
/** The attribute that carries the states forced, on the element and on its ancestors. */
|
|
36
|
+
export declare const FORCE_ATTRIBUTE = "data-devknobs-force";
|
|
37
|
+
/** A selector as it matches while states are forced. The same where it has none of them. */
|
|
38
|
+
export declare function forcedSelector(selector: string): string;
|
|
39
|
+
/** Whether a state is forced anywhere now. */
|
|
40
|
+
export declare function forcing(): boolean;
|
|
41
|
+
/** The element whose states are forced, and the states. Null with none. */
|
|
42
|
+
export declare function forcedState(): {
|
|
43
|
+
element: Element;
|
|
44
|
+
states: ForcedState[];
|
|
45
|
+
} | null;
|
|
46
|
+
/** The copies of every rule of a tree that has a state wanted. */
|
|
47
|
+
export declare function mirrorText(scope: Scope, wanted: ReadonlySet<ForcedState>): string;
|
|
48
|
+
/** Copy the rules again, as the page's stylesheets are now. */
|
|
49
|
+
export declare function syncForced(): void;
|
|
50
|
+
/** Take every forced state off the page. */
|
|
51
|
+
export declare function clearForced(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Force states on an element, those on another taken off first. The states
|
|
54
|
+
* are names such as `hover` or `:hover`; ones that cannot be forced are left
|
|
55
|
+
* out. With none, or no element, nothing is forced. Returns the states forced.
|
|
56
|
+
*/
|
|
57
|
+
export declare function forceState(element: Element | null, states: readonly string[]): ForcedState[];
|
|
58
|
+
/** The forcing as the styles view drives it, so a test can stand in for it. */
|
|
59
|
+
export interface Forcing {
|
|
60
|
+
state: typeof forcedState;
|
|
61
|
+
set: typeof forceState;
|
|
62
|
+
clear: typeof clearForced;
|
|
63
|
+
sync: typeof syncForced;
|
|
64
|
+
on: typeof forcing;
|
|
65
|
+
}
|
|
66
|
+
export declare const FORCING: Forcing;
|