@modelnex/sdk 0.5.44 → 0.5.46
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/dist/{aom-LJNCLNXL.mjs → aom-SP2LMWQI.mjs} +1 -1
- package/dist/chunk-SXGINP3O.mjs +683 -0
- package/dist/index.js +1023 -680
- package/dist/index.mjs +663 -776
- package/package.json +1 -1
- package/dist/chunk-H4LUY7LI.mjs +0 -243
package/package.json
CHANGED
package/dist/chunk-H4LUY7LI.mjs
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
// src/utils/editable-controls.ts
|
|
2
|
-
var EDITABLE_ROLES = /* @__PURE__ */ new Set(["textbox", "combobox"]);
|
|
3
|
-
var EDITABLE_CONTROL_SELECTOR = [
|
|
4
|
-
'input:not([type="hidden"])',
|
|
5
|
-
"textarea",
|
|
6
|
-
"select",
|
|
7
|
-
'[contenteditable="true"]',
|
|
8
|
-
'[role="textbox"]',
|
|
9
|
-
'[role="combobox"]'
|
|
10
|
-
].join(", ");
|
|
11
|
-
function getTagName(element) {
|
|
12
|
-
return String(element?.tagName || "").toLowerCase();
|
|
13
|
-
}
|
|
14
|
-
function getRole(element) {
|
|
15
|
-
const role = element && typeof element.getAttribute === "function" ? element.getAttribute("role") : null;
|
|
16
|
-
return String(role || "").toLowerCase();
|
|
17
|
-
}
|
|
18
|
-
function getLabelControl(element) {
|
|
19
|
-
const labelCtor = typeof HTMLLabelElement !== "undefined" ? HTMLLabelElement : null;
|
|
20
|
-
if (labelCtor && element instanceof labelCtor && element.control instanceof HTMLElement) {
|
|
21
|
-
return element.control;
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
function isValueBearingElement(element) {
|
|
26
|
-
if (!element) return false;
|
|
27
|
-
const inputCtor = typeof HTMLInputElement !== "undefined" ? HTMLInputElement : null;
|
|
28
|
-
if (inputCtor && element instanceof inputCtor) return true;
|
|
29
|
-
const textareaCtor = typeof HTMLTextAreaElement !== "undefined" ? HTMLTextAreaElement : null;
|
|
30
|
-
if (textareaCtor && element instanceof textareaCtor) return true;
|
|
31
|
-
const selectCtor = typeof HTMLSelectElement !== "undefined" ? HTMLSelectElement : null;
|
|
32
|
-
if (selectCtor && element instanceof selectCtor) return true;
|
|
33
|
-
return ["input", "textarea", "select"].includes(getTagName(element));
|
|
34
|
-
}
|
|
35
|
-
function findEditableControlInShadowRoot(root) {
|
|
36
|
-
if (!root) return null;
|
|
37
|
-
if (root.shadowRoot) {
|
|
38
|
-
const found = root.shadowRoot.querySelector(EDITABLE_CONTROL_SELECTOR);
|
|
39
|
-
if (found) {
|
|
40
|
-
return resolveEditableControlElement(found);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
for (const child of Array.from(root.children)) {
|
|
44
|
-
if (child instanceof HTMLElement) {
|
|
45
|
-
const found = findEditableControlInShadowRoot(child);
|
|
46
|
-
if (found) return found;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
function resolveEditableControlElement(element) {
|
|
52
|
-
const labelControl = getLabelControl(element);
|
|
53
|
-
if (labelControl) {
|
|
54
|
-
return resolveEditableControlElement(labelControl);
|
|
55
|
-
}
|
|
56
|
-
if (isValueBearingElement(element) || element.isContentEditable) {
|
|
57
|
-
return element;
|
|
58
|
-
}
|
|
59
|
-
const role = getRole(element);
|
|
60
|
-
if (EDITABLE_ROLES.has(role)) {
|
|
61
|
-
const nested2 = element.querySelector(EDITABLE_CONTROL_SELECTOR);
|
|
62
|
-
if (nested2 && nested2 !== element) {
|
|
63
|
-
return resolveEditableControlElement(nested2);
|
|
64
|
-
}
|
|
65
|
-
const shadowNested2 = findEditableControlInShadowRoot(element);
|
|
66
|
-
return shadowNested2 ?? element;
|
|
67
|
-
}
|
|
68
|
-
const nested = element.querySelector(EDITABLE_CONTROL_SELECTOR);
|
|
69
|
-
if (nested) {
|
|
70
|
-
return resolveEditableControlElement(nested);
|
|
71
|
-
}
|
|
72
|
-
const shadowNested = findEditableControlInShadowRoot(element);
|
|
73
|
-
return shadowNested ?? element;
|
|
74
|
-
}
|
|
75
|
-
function readEditableControlValue(element, options = {}) {
|
|
76
|
-
const target = resolveEditableControlElement(element);
|
|
77
|
-
const maskPasswords = options.maskPasswords !== false;
|
|
78
|
-
if (isValueBearingElement(target)) {
|
|
79
|
-
const type = String(target.type || "").toLowerCase();
|
|
80
|
-
if (maskPasswords && type === "password") {
|
|
81
|
-
return "***";
|
|
82
|
-
}
|
|
83
|
-
return String(target.value || "").trim().slice(0, 100);
|
|
84
|
-
}
|
|
85
|
-
const genericValue = target.value;
|
|
86
|
-
if (typeof genericValue === "string") {
|
|
87
|
-
return genericValue.trim().slice(0, 100);
|
|
88
|
-
}
|
|
89
|
-
if (typeof genericValue === "number" && Number.isFinite(genericValue)) {
|
|
90
|
-
return String(genericValue).trim().slice(0, 100);
|
|
91
|
-
}
|
|
92
|
-
if (target.isContentEditable) {
|
|
93
|
-
return String(target.textContent || "").trim().slice(0, 100);
|
|
94
|
-
}
|
|
95
|
-
const ariaValueText = target.getAttribute("aria-valuetext");
|
|
96
|
-
if (ariaValueText?.trim()) {
|
|
97
|
-
return ariaValueText.trim().slice(0, 100);
|
|
98
|
-
}
|
|
99
|
-
const ariaValueNow = target.getAttribute("aria-valuenow");
|
|
100
|
-
if (ariaValueNow?.trim()) {
|
|
101
|
-
return ariaValueNow.trim().slice(0, 100);
|
|
102
|
-
}
|
|
103
|
-
return String(target.textContent || "").trim().slice(0, 100);
|
|
104
|
-
}
|
|
105
|
-
function readEditableControlPlaceholder(element) {
|
|
106
|
-
const target = resolveEditableControlElement(element);
|
|
107
|
-
if (typeof target.placeholder === "string") {
|
|
108
|
-
return String(target.placeholder || "").trim().slice(0, 100);
|
|
109
|
-
}
|
|
110
|
-
return String(target.getAttribute("placeholder") || "").trim().slice(0, 100);
|
|
111
|
-
}
|
|
112
|
-
function readEditableControlName(element) {
|
|
113
|
-
const target = resolveEditableControlElement(element);
|
|
114
|
-
const explicitName = target.name;
|
|
115
|
-
if (typeof explicitName === "string" && explicitName.trim()) {
|
|
116
|
-
return explicitName.trim().slice(0, 100);
|
|
117
|
-
}
|
|
118
|
-
return String(
|
|
119
|
-
target.getAttribute("name") || target.getAttribute("id") || target.getAttribute("aria-label") || ""
|
|
120
|
-
).trim().slice(0, 100);
|
|
121
|
-
}
|
|
122
|
-
function readEditableControlType(element) {
|
|
123
|
-
const target = resolveEditableControlElement(element);
|
|
124
|
-
const role = getRole(target);
|
|
125
|
-
if (role) return role;
|
|
126
|
-
const explicitType = target.type;
|
|
127
|
-
if (typeof explicitType === "string" && explicitType.trim()) {
|
|
128
|
-
return explicitType.trim().toLowerCase().slice(0, 50);
|
|
129
|
-
}
|
|
130
|
-
const attributeType = target.getAttribute("type");
|
|
131
|
-
if (attributeType?.trim()) {
|
|
132
|
-
return attributeType.trim().toLowerCase().slice(0, 50);
|
|
133
|
-
}
|
|
134
|
-
return getTagName(target);
|
|
135
|
-
}
|
|
136
|
-
function isEditableControlDisabled(element) {
|
|
137
|
-
const target = resolveEditableControlElement(element);
|
|
138
|
-
const ariaDisabled = String(target.getAttribute("aria-disabled") || "").toLowerCase();
|
|
139
|
-
if (ariaDisabled === "true") return true;
|
|
140
|
-
return Boolean(target.disabled);
|
|
141
|
-
}
|
|
142
|
-
function collectEditableControls(scope) {
|
|
143
|
-
const seen = /* @__PURE__ */ new Set();
|
|
144
|
-
const controls = [];
|
|
145
|
-
for (const rawElement of Array.from(scope.querySelectorAll(EDITABLE_CONTROL_SELECTOR))) {
|
|
146
|
-
const resolved = resolveEditableControlElement(rawElement);
|
|
147
|
-
if (seen.has(resolved)) continue;
|
|
148
|
-
if (isValueBearingElement(resolved) && String(resolved.type || "").toLowerCase() === "hidden") {
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
seen.add(resolved);
|
|
152
|
-
controls.push(resolved);
|
|
153
|
-
}
|
|
154
|
-
return controls;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// src/utils/aom.ts
|
|
158
|
-
var uidMap = /* @__PURE__ */ new Map();
|
|
159
|
-
var nextUid = 1;
|
|
160
|
-
function generateMinifiedAOM() {
|
|
161
|
-
uidMap.clear();
|
|
162
|
-
nextUid = 1;
|
|
163
|
-
const interactiveSet = /* @__PURE__ */ new Set();
|
|
164
|
-
const interactiveCandidates = [
|
|
165
|
-
...Array.from(document.querySelectorAll(
|
|
166
|
-
'button, a, input, select, textarea, [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="option"], [role="textbox"], [role="combobox"], [contenteditable="true"]'
|
|
167
|
-
)),
|
|
168
|
-
...collectEditableControls(document)
|
|
169
|
-
];
|
|
170
|
-
const nodes = [];
|
|
171
|
-
interactiveCandidates.forEach((candidate) => {
|
|
172
|
-
const el = resolveEditableControlElement(candidate);
|
|
173
|
-
if (interactiveSet.has(el)) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
interactiveSet.add(el);
|
|
177
|
-
if (!el.offsetParent && (el.offsetWidth === 0 || el.offsetHeight === 0)) {
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
if (el.closest("#modelnex-studio-root") || el.closest("#modelnex-active-agent-root")) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const uid = `node:${nextUid++}`;
|
|
184
|
-
uidMap.set(uid, el);
|
|
185
|
-
let text = (el.textContent || "").replace(/\s+/g, " ").trim();
|
|
186
|
-
const ariaLabel = el.getAttribute("aria-label");
|
|
187
|
-
const placeholder = el.getAttribute("placeholder");
|
|
188
|
-
const value = readEditableControlValue(el, { maskPasswords: false }) || void 0;
|
|
189
|
-
let role = el.tagName.toLowerCase();
|
|
190
|
-
if (el.hasAttribute("role")) {
|
|
191
|
-
role = el.getAttribute("role");
|
|
192
|
-
} else if (role === "a") {
|
|
193
|
-
role = "link";
|
|
194
|
-
} else if (el.tagName.toLowerCase() === "input") {
|
|
195
|
-
const inputType = el.type;
|
|
196
|
-
role = inputType ? `input[${inputType}]` : "input";
|
|
197
|
-
}
|
|
198
|
-
const node = { uid, role };
|
|
199
|
-
const displayLabel = ariaLabel || text || placeholder;
|
|
200
|
-
if (displayLabel) {
|
|
201
|
-
node.text = displayLabel.substring(0, 100);
|
|
202
|
-
}
|
|
203
|
-
const controlName = readEditableControlName(el);
|
|
204
|
-
if (controlName) {
|
|
205
|
-
node.name = controlName;
|
|
206
|
-
}
|
|
207
|
-
if (value) {
|
|
208
|
-
node.value = value.substring(0, 100);
|
|
209
|
-
}
|
|
210
|
-
if (el instanceof HTMLAnchorElement && el.href) {
|
|
211
|
-
try {
|
|
212
|
-
const url = new URL(el.href);
|
|
213
|
-
node.href = url.pathname + url.search + url.hash;
|
|
214
|
-
} catch {
|
|
215
|
-
node.href = el.getAttribute("href");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
nodes.push(node);
|
|
219
|
-
});
|
|
220
|
-
return { nodes };
|
|
221
|
-
}
|
|
222
|
-
function getElementByUid(uid) {
|
|
223
|
-
return uidMap.get(uid) || null;
|
|
224
|
-
}
|
|
225
|
-
function clearAOMMap() {
|
|
226
|
-
uidMap.clear();
|
|
227
|
-
nextUid = 1;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export {
|
|
231
|
-
isValueBearingElement,
|
|
232
|
-
findEditableControlInShadowRoot,
|
|
233
|
-
resolveEditableControlElement,
|
|
234
|
-
readEditableControlValue,
|
|
235
|
-
readEditableControlPlaceholder,
|
|
236
|
-
readEditableControlName,
|
|
237
|
-
readEditableControlType,
|
|
238
|
-
isEditableControlDisabled,
|
|
239
|
-
collectEditableControls,
|
|
240
|
-
generateMinifiedAOM,
|
|
241
|
-
getElementByUid,
|
|
242
|
-
clearAOMMap
|
|
243
|
-
};
|