@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,208 @@
|
|
|
1
|
+
// src/grab/selector.ts
|
|
2
|
+
var VALUE_MAX = 120;
|
|
3
|
+
var PREFERRED = [
|
|
4
|
+
"data-testid",
|
|
5
|
+
"data-test-id",
|
|
6
|
+
"data-test",
|
|
7
|
+
"data-cy",
|
|
8
|
+
"data-qa",
|
|
9
|
+
"aria-label",
|
|
10
|
+
"href",
|
|
11
|
+
"src",
|
|
12
|
+
"role",
|
|
13
|
+
"name",
|
|
14
|
+
"title",
|
|
15
|
+
"alt"
|
|
16
|
+
];
|
|
17
|
+
var ACTIONABLE_ROLES = new Set([
|
|
18
|
+
"button",
|
|
19
|
+
"link",
|
|
20
|
+
"checkbox",
|
|
21
|
+
"radio",
|
|
22
|
+
"switch",
|
|
23
|
+
"tab",
|
|
24
|
+
"menuitem",
|
|
25
|
+
"option",
|
|
26
|
+
"textbox",
|
|
27
|
+
"combobox",
|
|
28
|
+
"slider",
|
|
29
|
+
"spinbutton"
|
|
30
|
+
]);
|
|
31
|
+
var IDENTIFIER_QUERY = [
|
|
32
|
+
...PREFERRED.filter((name) => name !== "role").map((name) => `[${name}]`),
|
|
33
|
+
...[...ACTIONABLE_ROLES].map((role) => `[role~="${role}"]`)
|
|
34
|
+
].join(",");
|
|
35
|
+
var GENERIC_QUERY = "button,input,select,textarea";
|
|
36
|
+
var GENERATED_IDS = [
|
|
37
|
+
/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i,
|
|
38
|
+
/:r[a-z0-9]+:/i,
|
|
39
|
+
/_r_[a-z0-9]+_(?:$|-)/i,
|
|
40
|
+
/«r[a-z0-9]+»/i,
|
|
41
|
+
/^(?:downshift-\d+(?:-|$)|headlessui-[a-z-]+-\d+(?:-|$)|mui-\d+(?:-|$)|radix-\d+(?:-|$)|react-aria-\d+(?:-|$)|react-select-\d+(?:-|$))/i,
|
|
42
|
+
/^ember\d+$/i,
|
|
43
|
+
/^\d+$/
|
|
44
|
+
];
|
|
45
|
+
function isStableId(id) {
|
|
46
|
+
return id.length > 0 && id.length <= VALUE_MAX && !GENERATED_IDS.some((pattern) => pattern.test(id));
|
|
47
|
+
}
|
|
48
|
+
function isShadowRoot(node) {
|
|
49
|
+
return "host" in node;
|
|
50
|
+
}
|
|
51
|
+
function escape(element, value) {
|
|
52
|
+
const css = element.ownerDocument.defaultView?.CSS ?? globalThis.CSS;
|
|
53
|
+
return css.escape(value);
|
|
54
|
+
}
|
|
55
|
+
function isPreferred(name, value) {
|
|
56
|
+
if (value.length === 0 || value.length > VALUE_MAX)
|
|
57
|
+
return false;
|
|
58
|
+
return name !== "role" || value.split(/\s+/).some((role) => ACTIONABLE_ROLES.has(role));
|
|
59
|
+
}
|
|
60
|
+
function isUnique(element, selector) {
|
|
61
|
+
try {
|
|
62
|
+
const root = element.getRootNode();
|
|
63
|
+
const matches = (isShadowRoot(root) ? root : element.ownerDocument).querySelectorAll(selector);
|
|
64
|
+
return matches.length === 1 && matches[0] === element;
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function fastSelector(element) {
|
|
70
|
+
const id = element.getAttribute("id");
|
|
71
|
+
let fallback = null;
|
|
72
|
+
if (id) {
|
|
73
|
+
const selector = `#${escape(element, id)}`;
|
|
74
|
+
if (isUnique(element, selector)) {
|
|
75
|
+
if (isStableId(id))
|
|
76
|
+
return { selector, semantic: true };
|
|
77
|
+
fallback = selector;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const name of PREFERRED) {
|
|
81
|
+
const value = element.getAttribute(name);
|
|
82
|
+
if (!value || !isPreferred(name, value))
|
|
83
|
+
continue;
|
|
84
|
+
const attribute = `[${name}=${JSON.stringify(value)}]`;
|
|
85
|
+
if (isUnique(element, attribute))
|
|
86
|
+
return { selector: attribute, semantic: true };
|
|
87
|
+
const tagged = `${element.tagName.toLowerCase()}${attribute}`;
|
|
88
|
+
if (isUnique(element, tagged))
|
|
89
|
+
return { selector: tagged, semantic: true };
|
|
90
|
+
}
|
|
91
|
+
return fallback ? { selector: fallback, semantic: false } : null;
|
|
92
|
+
}
|
|
93
|
+
function nthChildSelector(element) {
|
|
94
|
+
const steps = [];
|
|
95
|
+
const rootNode = element.getRootNode();
|
|
96
|
+
const root = isShadowRoot(rootNode) ? rootNode : element.ownerDocument.body ?? element.ownerDocument.documentElement;
|
|
97
|
+
let current = element;
|
|
98
|
+
while (current) {
|
|
99
|
+
const id = current.getAttribute("id");
|
|
100
|
+
if (id) {
|
|
101
|
+
steps.unshift(`#${escape(current, id)}`);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
const parent = current.parentNode;
|
|
105
|
+
const tag = current.tagName.toLowerCase();
|
|
106
|
+
if (!parent) {
|
|
107
|
+
steps.unshift(tag);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
steps.unshift(`${tag}:nth-child(${Array.from(parent.children).indexOf(current) + 1})`);
|
|
111
|
+
if (parent === root) {
|
|
112
|
+
if ("tagName" in root)
|
|
113
|
+
steps.unshift(root.tagName.toLowerCase());
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
current = "tagName" in parent ? parent : null;
|
|
117
|
+
}
|
|
118
|
+
return steps.join(" > ");
|
|
119
|
+
}
|
|
120
|
+
function frameOf(element) {
|
|
121
|
+
try {
|
|
122
|
+
const frame = element.ownerDocument.defaultView?.frameElement ?? null;
|
|
123
|
+
return frame?.hasAttribute("data-devknobs-frame") ? null : frame;
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function elementSelector(element) {
|
|
129
|
+
const local = fastSelector(element) ?? { selector: nthChildSelector(element), semantic: false };
|
|
130
|
+
const root = element.getRootNode();
|
|
131
|
+
const outer = isShadowRoot(root) ? root.host : frameOf(element);
|
|
132
|
+
if (!outer)
|
|
133
|
+
return local;
|
|
134
|
+
const host = elementSelector(outer);
|
|
135
|
+
const join = isShadowRoot(root) ? ">>>" : ">>iframe>>";
|
|
136
|
+
return {
|
|
137
|
+
selector: `${host.selector} ${join} ${local.selector}`,
|
|
138
|
+
semantic: host.semantic && local.semantic
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function semanticSelector(element) {
|
|
142
|
+
const local = fastSelector(element);
|
|
143
|
+
if (!local?.semantic)
|
|
144
|
+
return null;
|
|
145
|
+
const root = element.getRootNode();
|
|
146
|
+
const outer = isShadowRoot(root) ? root.host : frameOf(element);
|
|
147
|
+
if (!outer)
|
|
148
|
+
return local;
|
|
149
|
+
const host = semanticSelector(outer);
|
|
150
|
+
if (!host)
|
|
151
|
+
return null;
|
|
152
|
+
const join = isShadowRoot(root) ? ">>>" : ">>iframe>>";
|
|
153
|
+
return { selector: `${host.selector} ${join} ${local.selector}`, semantic: true };
|
|
154
|
+
}
|
|
155
|
+
function hasIdentifier(element) {
|
|
156
|
+
const id = element.getAttribute("id");
|
|
157
|
+
return Boolean(id && isStableId(id) || element.matches(IDENTIFIER_QUERY));
|
|
158
|
+
}
|
|
159
|
+
function isTarget(element) {
|
|
160
|
+
return hasIdentifier(element) || element.matches(GENERIC_QUERY);
|
|
161
|
+
}
|
|
162
|
+
function isBroad(element) {
|
|
163
|
+
const { body, documentElement } = element.ownerDocument;
|
|
164
|
+
if (element === body || element === documentElement)
|
|
165
|
+
return true;
|
|
166
|
+
if (!body)
|
|
167
|
+
return false;
|
|
168
|
+
const total = body.getElementsByTagName("*").length;
|
|
169
|
+
return total > 0 && element.getElementsByTagName("*").length / total >= 0.5;
|
|
170
|
+
}
|
|
171
|
+
function composedParent(element) {
|
|
172
|
+
if (element.assignedSlot)
|
|
173
|
+
return element.assignedSlot;
|
|
174
|
+
if (element.parentElement)
|
|
175
|
+
return element.parentElement;
|
|
176
|
+
const root = element.getRootNode();
|
|
177
|
+
return isShadowRoot(root) ? root.host : frameOf(element);
|
|
178
|
+
}
|
|
179
|
+
function selectorTarget(element, accept) {
|
|
180
|
+
const root = element.getRootNode();
|
|
181
|
+
let current = element;
|
|
182
|
+
while (current) {
|
|
183
|
+
if (isTarget(current)) {
|
|
184
|
+
const broad = isBroad(current);
|
|
185
|
+
if (broad && current !== element)
|
|
186
|
+
return element;
|
|
187
|
+
if (!accept || accept(current))
|
|
188
|
+
return current;
|
|
189
|
+
if (broad)
|
|
190
|
+
return current;
|
|
191
|
+
if (!hasIdentifier(current) && current === element)
|
|
192
|
+
return current;
|
|
193
|
+
}
|
|
194
|
+
const parent = composedParent(current);
|
|
195
|
+
current = parent?.getRootNode() === root ? parent : null;
|
|
196
|
+
}
|
|
197
|
+
return element;
|
|
198
|
+
}
|
|
199
|
+
function nearestSemanticSelector(element) {
|
|
200
|
+
let found = null;
|
|
201
|
+
selectorTarget(element, (candidate) => {
|
|
202
|
+
found = semanticSelector(candidate);
|
|
203
|
+
return found !== null;
|
|
204
|
+
});
|
|
205
|
+
return found;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { elementSelector, selectorTarget, nearestSemanticSelector };
|