@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,496 @@
|
|
|
1
|
+
import {
|
|
2
|
+
switchedSheet
|
|
3
|
+
} from "./index-dzm8ywq0.js";
|
|
4
|
+
|
|
5
|
+
// src/styles/varrefs.ts
|
|
6
|
+
var SPACE = /\s/;
|
|
7
|
+
var IDENT = /[\w\-\\\u0080-]/;
|
|
8
|
+
function pastString(value, at) {
|
|
9
|
+
const quote = value[at];
|
|
10
|
+
let i = at + 1;
|
|
11
|
+
while (i < value.length && value[i] !== quote)
|
|
12
|
+
i += value[i] === "\\" ? 2 : 1;
|
|
13
|
+
return Math.min(i + 1, value.length);
|
|
14
|
+
}
|
|
15
|
+
function calls(value, at, name) {
|
|
16
|
+
if (value.slice(at, at + name.length + 1).toLowerCase() !== `${name}(`)
|
|
17
|
+
return false;
|
|
18
|
+
return at === 0 || !IDENT.test(value[at - 1] ?? "");
|
|
19
|
+
}
|
|
20
|
+
function past(value, at) {
|
|
21
|
+
const char = value[at];
|
|
22
|
+
if (char === "\\")
|
|
23
|
+
return Math.min(at + 2, value.length);
|
|
24
|
+
if (char === '"' || char === "'")
|
|
25
|
+
return pastString(value, at);
|
|
26
|
+
if (char === "/" && value[at + 1] === "*") {
|
|
27
|
+
const stop = value.indexOf("*/", at + 2);
|
|
28
|
+
return stop < 0 ? value.length : stop + 2;
|
|
29
|
+
}
|
|
30
|
+
if (!calls(value, at, "url"))
|
|
31
|
+
return at;
|
|
32
|
+
let i = at + 4;
|
|
33
|
+
while (i < value.length && SPACE.test(value[i] ?? ""))
|
|
34
|
+
i++;
|
|
35
|
+
if (value[i] === '"' || value[i] === "'")
|
|
36
|
+
return at;
|
|
37
|
+
while (i < value.length && value[i] !== ")")
|
|
38
|
+
i += value[i] === "\\" ? 2 : 1;
|
|
39
|
+
return Math.min(i + 1, value.length);
|
|
40
|
+
}
|
|
41
|
+
function pastSpace(value, at) {
|
|
42
|
+
let i = at;
|
|
43
|
+
while (i < value.length) {
|
|
44
|
+
if (SPACE.test(value[i] ?? ""))
|
|
45
|
+
i++;
|
|
46
|
+
else if (value[i] === "/" && value[i + 1] === "*")
|
|
47
|
+
i = past(value, i);
|
|
48
|
+
else
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return i;
|
|
52
|
+
}
|
|
53
|
+
function closeOf(value, from) {
|
|
54
|
+
let depth = 1;
|
|
55
|
+
let i = from;
|
|
56
|
+
while (i < value.length) {
|
|
57
|
+
const next = past(value, i);
|
|
58
|
+
if (next > i) {
|
|
59
|
+
i = next;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (value[i] === "(")
|
|
63
|
+
depth++;
|
|
64
|
+
else if (value[i] === ")" && --depth === 0)
|
|
65
|
+
return i;
|
|
66
|
+
i++;
|
|
67
|
+
}
|
|
68
|
+
return value.length;
|
|
69
|
+
}
|
|
70
|
+
function plain(value) {
|
|
71
|
+
let text = "";
|
|
72
|
+
let i = 0;
|
|
73
|
+
while (i < value.length) {
|
|
74
|
+
const next = past(value, i);
|
|
75
|
+
const comment = value[i] === "/" && value[i + 1] === "*";
|
|
76
|
+
if (!comment)
|
|
77
|
+
text += value.slice(i, Math.max(next, i + 1));
|
|
78
|
+
i = Math.max(next, i + 1);
|
|
79
|
+
}
|
|
80
|
+
return text;
|
|
81
|
+
}
|
|
82
|
+
function referenceAt(value, start) {
|
|
83
|
+
const at = pastSpace(value, start + 4);
|
|
84
|
+
if (!value.startsWith("--", at))
|
|
85
|
+
return null;
|
|
86
|
+
let stop = at;
|
|
87
|
+
while (stop < value.length) {
|
|
88
|
+
const char = value[stop] ?? "";
|
|
89
|
+
if (SPACE.test(char) || char === "," || char === ")")
|
|
90
|
+
break;
|
|
91
|
+
if (char === "/" && value[stop + 1] === "*")
|
|
92
|
+
break;
|
|
93
|
+
stop += char === "\\" ? 2 : 1;
|
|
94
|
+
}
|
|
95
|
+
stop = Math.min(stop, value.length);
|
|
96
|
+
const name = value.slice(at, stop);
|
|
97
|
+
if (name.length < 3)
|
|
98
|
+
return null;
|
|
99
|
+
const after = pastSpace(value, stop);
|
|
100
|
+
if (after >= value.length || value[after] === ")") {
|
|
101
|
+
const closed2 = after < value.length;
|
|
102
|
+
return { start, end: closed2 ? after + 1 : value.length, name, at, fallback: null, closed: closed2 };
|
|
103
|
+
}
|
|
104
|
+
if (value[after] !== ",")
|
|
105
|
+
return null;
|
|
106
|
+
const close = closeOf(value, after + 1);
|
|
107
|
+
const fallback = plain(value.slice(after + 1, close)).trim();
|
|
108
|
+
const closed = close < value.length;
|
|
109
|
+
return { start, end: closed ? close + 1 : value.length, name, at, fallback, closed };
|
|
110
|
+
}
|
|
111
|
+
function varReferences(value) {
|
|
112
|
+
const found = [];
|
|
113
|
+
let i = 0;
|
|
114
|
+
while (i < value.length) {
|
|
115
|
+
const next = past(value, i);
|
|
116
|
+
if (next > i) {
|
|
117
|
+
i = next;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const reference = calls(value, i, "var") ? referenceAt(value, i) : null;
|
|
121
|
+
if (reference)
|
|
122
|
+
found.push(reference);
|
|
123
|
+
i = reference ? reference.at + reference.name.length : i + 1;
|
|
124
|
+
}
|
|
125
|
+
return found;
|
|
126
|
+
}
|
|
127
|
+
function resolveVars(value, read) {
|
|
128
|
+
let text = "";
|
|
129
|
+
let at = 0;
|
|
130
|
+
for (const reference of varReferences(value)) {
|
|
131
|
+
if (reference.start < at)
|
|
132
|
+
continue;
|
|
133
|
+
if (!reference.closed)
|
|
134
|
+
return null;
|
|
135
|
+
const seen = read(reference.name);
|
|
136
|
+
const comes = seen !== "" ? seen : reference.fallback === null ? null : resolveVars(reference.fallback, read);
|
|
137
|
+
if (comes === null)
|
|
138
|
+
return null;
|
|
139
|
+
text += value.slice(at, reference.start) + comes;
|
|
140
|
+
at = reference.end;
|
|
141
|
+
}
|
|
142
|
+
return text + value.slice(at);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/styles/declarations.ts
|
|
146
|
+
var IMPORTANT = /!\s*important\s*$/i;
|
|
147
|
+
function skipString(text, at) {
|
|
148
|
+
const quote = text[at];
|
|
149
|
+
let i = at + 1;
|
|
150
|
+
while (i < text.length && text[i] !== quote)
|
|
151
|
+
i += text[i] === "\\" ? 2 : 1;
|
|
152
|
+
return i + 1;
|
|
153
|
+
}
|
|
154
|
+
function split(text) {
|
|
155
|
+
const found = [];
|
|
156
|
+
let name = null;
|
|
157
|
+
let piece = "";
|
|
158
|
+
let depth = 0;
|
|
159
|
+
const close = () => {
|
|
160
|
+
if (name !== null && name.trim())
|
|
161
|
+
found.push({ name: name.trim(), value: piece.trim() });
|
|
162
|
+
name = null;
|
|
163
|
+
piece = "";
|
|
164
|
+
};
|
|
165
|
+
let i = 0;
|
|
166
|
+
while (i < text.length) {
|
|
167
|
+
const char = text[i] ?? "";
|
|
168
|
+
let end = i + 1;
|
|
169
|
+
if (char === "\\")
|
|
170
|
+
end = i + 2;
|
|
171
|
+
else if (char === '"' || char === "'")
|
|
172
|
+
end = skipString(text, i);
|
|
173
|
+
else if (char === "/" && text[i + 1] === "*") {
|
|
174
|
+
const stop = text.indexOf("*/", i + 2);
|
|
175
|
+
i = stop < 0 ? text.length : stop + 2;
|
|
176
|
+
continue;
|
|
177
|
+
} else if (char === "(" || char === "[" || char === "{")
|
|
178
|
+
depth++;
|
|
179
|
+
else if (char === ")" || char === "]" || char === "}")
|
|
180
|
+
depth = Math.max(0, depth - 1);
|
|
181
|
+
else if (depth === 0 && char === ";") {
|
|
182
|
+
close();
|
|
183
|
+
i = end;
|
|
184
|
+
continue;
|
|
185
|
+
} else if (depth === 0 && char === ":" && name === null) {
|
|
186
|
+
name = piece;
|
|
187
|
+
piece = "";
|
|
188
|
+
i = end;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
piece += text.slice(i, end);
|
|
192
|
+
i = end;
|
|
193
|
+
}
|
|
194
|
+
close();
|
|
195
|
+
return found;
|
|
196
|
+
}
|
|
197
|
+
function parseDeclarations(cssText) {
|
|
198
|
+
return split(cssText).map(({ name, value }) => {
|
|
199
|
+
const important = IMPORTANT.test(value);
|
|
200
|
+
return {
|
|
201
|
+
name: name.startsWith("--") ? name : name.toLowerCase(),
|
|
202
|
+
value: important ? value.replace(IMPORTANT, "").trim() : value,
|
|
203
|
+
important
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function variableNames(value) {
|
|
208
|
+
return [...new Set(varReferences(value).map((reference) => reference.name))];
|
|
209
|
+
}
|
|
210
|
+
function listed(style) {
|
|
211
|
+
const names = [];
|
|
212
|
+
for (let i = 0;i < style.length; i++) {
|
|
213
|
+
const name = style.item(i);
|
|
214
|
+
if (name)
|
|
215
|
+
names.push(name);
|
|
216
|
+
}
|
|
217
|
+
return names;
|
|
218
|
+
}
|
|
219
|
+
function longhandsOf(name, names, expand) {
|
|
220
|
+
if (name.startsWith("--") || names.includes(name))
|
|
221
|
+
return [name];
|
|
222
|
+
const known = expand(name).filter((longhand) => names.includes(longhand));
|
|
223
|
+
if (known.length > 0)
|
|
224
|
+
return known;
|
|
225
|
+
const under = names.filter((longhand) => longhand.startsWith(`${name}-`));
|
|
226
|
+
return under.length > 0 ? under : [name];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// src/edit/css.ts
|
|
230
|
+
var IMPORTANT2 = /\s*!\s*important\s*$/i;
|
|
231
|
+
function valueText(written) {
|
|
232
|
+
return written.important ? `${written.value} !important` : written.value;
|
|
233
|
+
}
|
|
234
|
+
function written(name, text) {
|
|
235
|
+
const important = IMPORTANT2.test(text);
|
|
236
|
+
return { name, value: text.replace(IMPORTANT2, "").trim(), important };
|
|
237
|
+
}
|
|
238
|
+
function declarationIn(style, property) {
|
|
239
|
+
const list = parseDeclarations(style.cssText);
|
|
240
|
+
const index = list.findIndex((one) => one.name === property);
|
|
241
|
+
const found = list[index];
|
|
242
|
+
return found ? { text: valueText(found), index } : null;
|
|
243
|
+
}
|
|
244
|
+
function valueIn(style, property) {
|
|
245
|
+
const found = declarationIn(style, property);
|
|
246
|
+
if (found)
|
|
247
|
+
return found.text;
|
|
248
|
+
const value = style.getPropertyValue(property);
|
|
249
|
+
if (value === "")
|
|
250
|
+
return null;
|
|
251
|
+
return style.getPropertyPriority(property) === "important" ? `${value} !important` : value;
|
|
252
|
+
}
|
|
253
|
+
function supports(element, property, value) {
|
|
254
|
+
try {
|
|
255
|
+
const css = element.ownerDocument?.defaultView?.CSS ?? globalThis.CSS;
|
|
256
|
+
return css ? css.supports(property, value) : true;
|
|
257
|
+
} catch {
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function setText(style, element, property, text) {
|
|
262
|
+
if (text === null) {
|
|
263
|
+
style.removeProperty(property);
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
const { value, important } = written(property, text);
|
|
267
|
+
if (value === "" || !supports(element, property, value))
|
|
268
|
+
return false;
|
|
269
|
+
style.setProperty(property, value, important ? "important" : "");
|
|
270
|
+
return style.getPropertyValue(property) !== "";
|
|
271
|
+
}
|
|
272
|
+
function insertAt(style, element, property, text, at) {
|
|
273
|
+
const list = parseDeclarations(style.cssText);
|
|
274
|
+
if (list.some((one2) => one2.value === "") || list.some((one2) => one2.name === property)) {
|
|
275
|
+
return setText(style, element, property, text);
|
|
276
|
+
}
|
|
277
|
+
const one = written(property, text);
|
|
278
|
+
if (one.value === "" || !supports(element, property, one.value))
|
|
279
|
+
return false;
|
|
280
|
+
list.splice(Math.max(0, Math.min(at, list.length)), 0, one);
|
|
281
|
+
style.cssText = list.map((each) => `${each.name}: ${valueText(each)};`).join(" ");
|
|
282
|
+
return style.getPropertyValue(property) !== "";
|
|
283
|
+
}
|
|
284
|
+
var sheetIds = new WeakMap;
|
|
285
|
+
var sheetsSeen = 0;
|
|
286
|
+
function sheetIdOf(rule) {
|
|
287
|
+
const sheet = Reflect.get(rule, "parentStyleSheet");
|
|
288
|
+
const key = typeof sheet === "object" && sheet !== null ? sheet : rule;
|
|
289
|
+
let id = sheetIds.get(key);
|
|
290
|
+
if (id === undefined) {
|
|
291
|
+
id = ++sheetsSeen;
|
|
292
|
+
sheetIds.set(key, id);
|
|
293
|
+
}
|
|
294
|
+
return id;
|
|
295
|
+
}
|
|
296
|
+
var places = new WeakMap;
|
|
297
|
+
function nameOf(property) {
|
|
298
|
+
return property.startsWith("--") ? property.trim() : property.trim().toLowerCase();
|
|
299
|
+
}
|
|
300
|
+
function targetOf(place) {
|
|
301
|
+
const target = { selector: place.selector };
|
|
302
|
+
if (place.rule)
|
|
303
|
+
target.rule = { ...place.rule, path: [...place.rule.path], context: [...place.rule.context] };
|
|
304
|
+
return target;
|
|
305
|
+
}
|
|
306
|
+
function viewOf(place) {
|
|
307
|
+
try {
|
|
308
|
+
return place.element.ownerDocument?.defaultView ?? null;
|
|
309
|
+
} catch {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function cssValue(kind, place, property, after) {
|
|
314
|
+
const name = nameOf(property);
|
|
315
|
+
const next = after.trim();
|
|
316
|
+
if (name === "" || next === "")
|
|
317
|
+
return null;
|
|
318
|
+
const { style, element } = place;
|
|
319
|
+
const before = valueIn(style, name);
|
|
320
|
+
if (before === next)
|
|
321
|
+
return null;
|
|
322
|
+
const change = {
|
|
323
|
+
edit: { kind, target: targetOf(place), property: name, before, after: next },
|
|
324
|
+
apply: () => setText(style, element, name, next),
|
|
325
|
+
revert: () => void setText(style, element, name, before),
|
|
326
|
+
view: viewOf(place)
|
|
327
|
+
};
|
|
328
|
+
places.set(change, { style, index: -1 });
|
|
329
|
+
return change;
|
|
330
|
+
}
|
|
331
|
+
function offIn(recorded, style) {
|
|
332
|
+
const last = new Map;
|
|
333
|
+
for (const { edit, change } of recorded) {
|
|
334
|
+
const place = places.get(change);
|
|
335
|
+
if (place?.style !== style)
|
|
336
|
+
continue;
|
|
337
|
+
const off = edit.kind === "css-toggle" && edit.after === null && edit.before !== null && place.index >= 0;
|
|
338
|
+
last.set(edit.property, off && edit.before !== null ? { property: edit.property, text: edit.before, index: place.index } : null);
|
|
339
|
+
}
|
|
340
|
+
return [...last.values()].filter((one) => one !== null).sort((a, b) => a.index - b.index);
|
|
341
|
+
}
|
|
342
|
+
function othersOff(recorded, style, property) {
|
|
343
|
+
return offIn(recorded(), style).filter((one) => one.property !== property);
|
|
344
|
+
}
|
|
345
|
+
function putBack(recorded, place, property, text, index) {
|
|
346
|
+
const before = othersOff(recorded, place.style, property).filter((one) => one.index < index).length;
|
|
347
|
+
return insertAt(place.style, place.element, property, text, index - before);
|
|
348
|
+
}
|
|
349
|
+
function cssOff(place, property, recorded) {
|
|
350
|
+
const name = nameOf(property);
|
|
351
|
+
const { style, element } = place;
|
|
352
|
+
const before = valueIn(style, name);
|
|
353
|
+
if (before === null)
|
|
354
|
+
return null;
|
|
355
|
+
const found = declarationIn(style, name);
|
|
356
|
+
let index = -1;
|
|
357
|
+
if (found) {
|
|
358
|
+
index = found.index;
|
|
359
|
+
for (const one of othersOff(recorded, style, name))
|
|
360
|
+
if (one.index <= index)
|
|
361
|
+
index++;
|
|
362
|
+
}
|
|
363
|
+
const change = {
|
|
364
|
+
edit: { kind: "css-toggle", target: targetOf(place), property: name, before, after: null },
|
|
365
|
+
apply: () => setText(style, element, name, null),
|
|
366
|
+
revert: () => {
|
|
367
|
+
if (index < 0)
|
|
368
|
+
setText(style, element, name, before);
|
|
369
|
+
else
|
|
370
|
+
putBack(recorded, place, name, before, index);
|
|
371
|
+
},
|
|
372
|
+
view: viewOf(place)
|
|
373
|
+
};
|
|
374
|
+
places.set(change, { style, index });
|
|
375
|
+
return change;
|
|
376
|
+
}
|
|
377
|
+
function cssOn(place, off, recorded) {
|
|
378
|
+
const { style, element } = place;
|
|
379
|
+
const change = {
|
|
380
|
+
edit: { kind: "css-toggle", target: targetOf(place), property: off.property, before: null, after: off.text },
|
|
381
|
+
apply: () => putBack(recorded, place, off.property, off.text, off.index),
|
|
382
|
+
revert: () => void setText(style, element, off.property, null),
|
|
383
|
+
view: viewOf(place)
|
|
384
|
+
};
|
|
385
|
+
places.set(change, { style, index: off.index });
|
|
386
|
+
return change;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// src/edit/rule.ts
|
|
390
|
+
var NEW_RULE_SHEET = "new rule";
|
|
391
|
+
var NEW_RULE = Symbol.for("devknobs.newrule");
|
|
392
|
+
function isNewRuleSheet(sheet) {
|
|
393
|
+
return Reflect.get(sheet, NEW_RULE) === true;
|
|
394
|
+
}
|
|
395
|
+
var made = new WeakMap;
|
|
396
|
+
function isShadowRoot(node) {
|
|
397
|
+
return node.nodeType === 11 && "host" in node;
|
|
398
|
+
}
|
|
399
|
+
function isDocumentNode(node) {
|
|
400
|
+
return node.nodeType === 9;
|
|
401
|
+
}
|
|
402
|
+
function isStyleRule(rule) {
|
|
403
|
+
return rule?.constructor.name === "CSSStyleRule";
|
|
404
|
+
}
|
|
405
|
+
function viewOf2(element) {
|
|
406
|
+
try {
|
|
407
|
+
return element.ownerDocument?.defaultView ?? null;
|
|
408
|
+
} catch {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function newRule(place, text) {
|
|
413
|
+
const selectorText = text.trim();
|
|
414
|
+
if (selectorText === "" || selectorText.startsWith("@"))
|
|
415
|
+
return null;
|
|
416
|
+
const { element } = place;
|
|
417
|
+
const root = element.getRootNode();
|
|
418
|
+
if (!isDocumentNode(root) && !isShadowRoot(root))
|
|
419
|
+
return null;
|
|
420
|
+
const switched = switchedSheet(root, "new-rule");
|
|
421
|
+
if (!switched)
|
|
422
|
+
return null;
|
|
423
|
+
const { sheet } = switched;
|
|
424
|
+
try {
|
|
425
|
+
sheet.insertRule(`${selectorText} {}`, 0);
|
|
426
|
+
} catch {
|
|
427
|
+
switched.remove();
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
const rule = sheet.cssRules[0];
|
|
431
|
+
if (sheet.cssRules.length !== 1 || !isStyleRule(rule)) {
|
|
432
|
+
switched.remove();
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
Reflect.set(sheet, NEW_RULE, true);
|
|
436
|
+
const change = {
|
|
437
|
+
edit: {
|
|
438
|
+
kind: "css-rule",
|
|
439
|
+
target: {
|
|
440
|
+
selector: place.selector,
|
|
441
|
+
rule: { selectorText: rule.selectorText, sheet: NEW_RULE_SHEET, owner: null, sheetId: sheetIdOf(rule), path: [0], context: [] }
|
|
442
|
+
},
|
|
443
|
+
property: "rule",
|
|
444
|
+
before: null,
|
|
445
|
+
after: rule.selectorText
|
|
446
|
+
},
|
|
447
|
+
apply() {
|
|
448
|
+
switched.on();
|
|
449
|
+
return true;
|
|
450
|
+
},
|
|
451
|
+
revert: () => switched.off(),
|
|
452
|
+
view: viewOf2(element)
|
|
453
|
+
};
|
|
454
|
+
made.set(change, { rule, element });
|
|
455
|
+
return change;
|
|
456
|
+
}
|
|
457
|
+
function ruleOf(change) {
|
|
458
|
+
return made.get(change)?.rule ?? null;
|
|
459
|
+
}
|
|
460
|
+
function newRulesFor(recorded, element) {
|
|
461
|
+
const rules = [];
|
|
462
|
+
for (const { change } of recorded) {
|
|
463
|
+
const one = made.get(change);
|
|
464
|
+
if (one?.element === element)
|
|
465
|
+
rules.push(one.rule);
|
|
466
|
+
}
|
|
467
|
+
return rules;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/styles/tree.ts
|
|
471
|
+
function isShadowRoot2(node) {
|
|
472
|
+
return "host" in node;
|
|
473
|
+
}
|
|
474
|
+
function scopeOf(element) {
|
|
475
|
+
const root = element.getRootNode();
|
|
476
|
+
return isShadowRoot2(root) ? root : element.ownerDocument;
|
|
477
|
+
}
|
|
478
|
+
function flatParent(element) {
|
|
479
|
+
if (element.assignedSlot)
|
|
480
|
+
return element.assignedSlot;
|
|
481
|
+
if (element.parentElement)
|
|
482
|
+
return element.parentElement;
|
|
483
|
+
const root = element.getRootNode();
|
|
484
|
+
return isShadowRoot2(root) ? root.host : null;
|
|
485
|
+
}
|
|
486
|
+
function label(element) {
|
|
487
|
+
const id = element.getAttribute("id");
|
|
488
|
+
const classes = (element.getAttribute("class") ?? "").split(/\s+/).filter(Boolean);
|
|
489
|
+
return [
|
|
490
|
+
element.tagName.toLowerCase(),
|
|
491
|
+
id ? `#${id}` : "",
|
|
492
|
+
...classes.map((name) => `.${name}`)
|
|
493
|
+
].join("");
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export { isShadowRoot2 as isShadowRoot, scopeOf, flatParent, label, varReferences, resolveVars, parseDeclarations, variableNames, listed, longhandsOf, valueText, sheetIdOf, cssValue, offIn, cssOff, cssOn, NEW_RULE_SHEET, isNewRuleSheet, newRule, ruleOf, newRulesFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import * as engine from "./engine";
|
|
2
2
|
import { type KnobDescription } from "./engine/describe";
|
|
3
|
+
import { type EditsStore, type Replayed } from "./edit/keep";
|
|
4
|
+
import { type Edit } from "./edit/log";
|
|
5
|
+
import { type ForcedState } from "./styles/force";
|
|
3
6
|
import type { GrabOptions, GrabResult } from "./grab/types";
|
|
4
7
|
import { type HostBuild, type PreferSetting, type PreferValue } from "./host";
|
|
5
8
|
import type { DevknobsState, DevknobsStatePatch, GrabColorValue } from "./types";
|
|
9
|
+
import { type KeysStore } from "./ui/bindings";
|
|
6
10
|
export type { BarsValue, BrowserValue, ClockMode, ClockValue, ConnectionValue, ContrastValue, DevknobsState, DevknobsStatePatch, DevIconValue, DirValue, DprValue, EdgeValue, GeoErrorValue, GeoValue, GrabColorValue, HeightValue, Knob, LocaleValue, MotionValue, NetworkValue, OnlineValue, OrientationValue, PanelValue, SaveDataValue, SchemeValue, SideValue, SpeedValue, TextValue, TimeZoneValue, TransparencyValue, UaValue, VisionValue, WidthValue, ZoomValue, } from "./types";
|
|
7
11
|
export type { KnobDescription, KnobField, KnobReload, KnobShape, KnobValue, } from "./engine/describe";
|
|
8
12
|
export type { DeviceKind, DevicePreset } from "./engine/devices";
|
|
13
|
+
export type { Edit, EditKind, EditPlace, EditTarget } from "./edit/log";
|
|
14
|
+
export type { Replayed, SavedEdit, Skipped } from "./edit/keep";
|
|
15
|
+
export type { ForcedState } from "./styles/force";
|
|
9
16
|
export type { GeoPreset } from "./engine/geo";
|
|
10
17
|
export type { UaBrand, UaHints, UaPreset } from "./engine/ua";
|
|
11
18
|
export type { EngineOptions } from "./engine";
|
|
12
19
|
export type { FrameRefusal, NativeDriver, NativeMedia, NativeSetting, NativeUa, NativeViewport } from "./engine/native";
|
|
13
20
|
export type { SystemMedia } from "./engine/system";
|
|
14
21
|
export type { HostBuild, PreferSetting, PreferValue } from "./host";
|
|
22
|
+
/** @internal For the devknobs extension, with `keysStore`: not public api. */
|
|
23
|
+
export type { KeysStore, StoredKeys } from "./ui/bindings";
|
|
24
|
+
/** @internal For the devknobs extension, with `editsStore`: not public api. */
|
|
25
|
+
export type { EditsStore, KeptEdits } from "./edit/keep";
|
|
15
26
|
export type { GrabEntry, GrabFrame, GrabOptions, GrabPayload, GrabResult, ResolvedSource, } from "./grab/types";
|
|
16
27
|
export interface MountOptions extends engine.EngineOptions {
|
|
17
28
|
/**
|
|
@@ -63,6 +74,18 @@ export interface MountOptions extends engine.EngineOptions {
|
|
|
63
74
|
build?: HostBuild;
|
|
64
75
|
/** For a host with a `build`: it stood down for another host, which holds the page for this load. */
|
|
65
76
|
stoodDown?: () => void;
|
|
77
|
+
/**
|
|
78
|
+
* @internal For the devknobs extension: where the keys the user sets are
|
|
79
|
+
* kept in place of the page's `localStorage`, so they are the same on every
|
|
80
|
+
* site. Not public api: it may change in any release.
|
|
81
|
+
*/
|
|
82
|
+
keysStore?: KeysStore;
|
|
83
|
+
/**
|
|
84
|
+
* @internal For the devknobs extension: where the edits kept after a
|
|
85
|
+
* reload are kept in place of the page's `localStorage`. Not public api:
|
|
86
|
+
* it may change in any release.
|
|
87
|
+
*/
|
|
88
|
+
editsStore?: EditsStore;
|
|
66
89
|
}
|
|
67
90
|
export declare const PRESETS: {
|
|
68
91
|
locale: readonly ["en", "en-US", "tr", "de", "fr", "es", "ar", "he", "ja", "zh-CN"];
|
|
@@ -121,6 +144,41 @@ export declare function describe(): KnobDescription[];
|
|
|
121
144
|
* Null when the elements gave nothing.
|
|
122
145
|
*/
|
|
123
146
|
export declare function grab(elements?: Element | Iterable<Element | null | undefined> | null, options?: GrabOptions): Promise<GrabResult | null>;
|
|
147
|
+
/**
|
|
148
|
+
* The edits made in inspect's Elements view that are in force, oldest first,
|
|
149
|
+
* as plain data: each one's kind, the element's selector, its source file and
|
|
150
|
+
* line where grab finds it, the rule and stylesheet, the property and its
|
|
151
|
+
* value before and after (null where it is not set). An html edit has in
|
|
152
|
+
* place of a css property `text` (`text 2` and on), the attribute's name,
|
|
153
|
+
* `html`, `hidden` or `node`, and a delete of a text or a comment `text` or
|
|
154
|
+
* `comment`. A move has `node`, and `from` and `to`, the places as selectors. Undo and the panel's
|
|
155
|
+
* reset take edits back, and so does `unmount`. `reset()` leaves them, so an
|
|
156
|
+
* agent can loop over conditions with the edits on.
|
|
157
|
+
*/
|
|
158
|
+
export declare function edits(): Edit[];
|
|
159
|
+
/**
|
|
160
|
+
* Make edits on the page from their plain data, in the shape `edits()` gives,
|
|
161
|
+
* oldest first: an agent can read `edits()`, save the list, and make the same
|
|
162
|
+
* edits again with this on a fresh load. Each edit is made only where its
|
|
163
|
+
* element is found by its selector (and its rule by its selector, what it
|
|
164
|
+
* sits in and its stylesheet) and the value there is still its `before`.
|
|
165
|
+
* They go to the same log as the panel's, so the panel lists them and undo
|
|
166
|
+
* takes them back. Resolves to the edits made and those skipped, each with
|
|
167
|
+
* why. Not a list throws a TypeError.
|
|
168
|
+
*/
|
|
169
|
+
export declare function setEdits(list: readonly unknown[]): Promise<Replayed>;
|
|
170
|
+
/** Undo the last edit in force, as Z does in the panel. Returns it, or null with none. */
|
|
171
|
+
export declare function undoEdit(): Edit | null;
|
|
172
|
+
/**
|
|
173
|
+
* Force states on an element, so it renders as if hovered, focused or
|
|
174
|
+
* pressed, for a screenshot of that state: `hover`, `focus`,
|
|
175
|
+
* `focus-visible`, `active` and `focus-within`, with or without the colon.
|
|
176
|
+
* Takes the element or a selector for it. One element at a time: the states
|
|
177
|
+
* on another come off first, and with no states, or no element found,
|
|
178
|
+
* nothing is forced. Returns the states forced. Not an edit, so not in
|
|
179
|
+
* `edits()`; the panel's reset and `unmount` take them off, `reset()` leaves them.
|
|
180
|
+
*/
|
|
181
|
+
export declare function forceState(target: Element | string | null, states?: readonly string[]): ForcedState[];
|
|
124
182
|
declare const api: {
|
|
125
183
|
mount: typeof mount;
|
|
126
184
|
unmount: typeof unmount;
|
|
@@ -131,6 +189,10 @@ declare const api: {
|
|
|
131
189
|
grab: typeof grab;
|
|
132
190
|
describe: typeof describe;
|
|
133
191
|
ready: typeof ready;
|
|
192
|
+
edits: typeof edits;
|
|
193
|
+
setEdits: typeof setEdits;
|
|
194
|
+
undoEdit: typeof undoEdit;
|
|
195
|
+
forceState: typeof forceState;
|
|
134
196
|
};
|
|
135
197
|
/** What `mount` puts at `window.devknobs`, for agents that run code in the page. */
|
|
136
198
|
export type DevknobsApi = typeof api;
|