@domql/utils 3.5.1 → 3.6.1
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/cjs/extends.js +81 -20
- package/dist/cjs/node.js +1 -1
- package/dist/cjs/props.js +25 -1
- package/dist/esm/extends.js +81 -20
- package/dist/esm/node.js +1 -1
- package/dist/esm/props.js +25 -1
- package/dist/iife/index.js +107 -22
- package/extends.js +95 -20
- package/node.js +2 -2
- package/package.json +9 -11
- package/props.js +15 -1
package/dist/cjs/extends.js
CHANGED
|
@@ -52,6 +52,7 @@ var import_component = require("./component.js");
|
|
|
52
52
|
var import_object = require("./object.js");
|
|
53
53
|
var import_types = require("./types.js");
|
|
54
54
|
const ENV = process.env.NODE_ENV;
|
|
55
|
+
const isSourcemapEnabled = (options) => options.sourcemap !== false && ENV !== "production";
|
|
55
56
|
const createExtendsFromKeys = (key) => {
|
|
56
57
|
if (key.includes("+")) {
|
|
57
58
|
return key.split("+").filter(import_component.matchesComponentNaming);
|
|
@@ -126,17 +127,17 @@ const getExtendsStackRegistry = (extend, stack) => {
|
|
|
126
127
|
}
|
|
127
128
|
return setHashedExtend(extend, stack);
|
|
128
129
|
};
|
|
129
|
-
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
130
|
+
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, componentNameMap) => {
|
|
130
131
|
for (const each of extend) {
|
|
131
132
|
if ((0, import_types.isArray)(each)) {
|
|
132
|
-
extractArrayExtend(each, stack, context, processed);
|
|
133
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap);
|
|
133
134
|
} else {
|
|
134
|
-
flattenExtend(each, stack, context, processed);
|
|
135
|
+
flattenExtend(each, stack, context, processed, nameStack, void 0, componentNameMap);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
return stack;
|
|
138
139
|
};
|
|
139
|
-
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
140
|
+
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, currentName, componentNameMap) => {
|
|
140
141
|
const extendOflattenExtend = extend.extends || extend.extend;
|
|
141
142
|
const cleanExtend = { ...extend };
|
|
142
143
|
delete cleanExtend.extends;
|
|
@@ -148,26 +149,32 @@ const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(
|
|
|
148
149
|
}
|
|
149
150
|
if (hasKeys) {
|
|
150
151
|
stack.push(cleanExtend);
|
|
152
|
+
if (nameStack) nameStack.push(currentName);
|
|
151
153
|
}
|
|
152
154
|
if (extendOflattenExtend) {
|
|
153
|
-
flattenExtend(extendOflattenExtend, stack, context, processed);
|
|
155
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
154
156
|
}
|
|
155
157
|
return stack;
|
|
156
158
|
};
|
|
157
|
-
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
159
|
+
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, parentName, componentNameMap) => {
|
|
158
160
|
if (!extend) return stack;
|
|
159
161
|
if (processed.has(extend)) return stack;
|
|
160
162
|
if ((0, import_types.isArray)(extend)) {
|
|
161
|
-
return extractArrayExtend(extend, stack, context, processed);
|
|
163
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap);
|
|
162
164
|
}
|
|
165
|
+
let currentName = parentName;
|
|
163
166
|
if ((0, import_types.isString)(extend)) {
|
|
167
|
+
currentName = extend;
|
|
164
168
|
extend = mapStringsWithContextComponents(extend, context);
|
|
169
|
+
} else if (componentNameMap && (0, import_types.isObject)(extend) && componentNameMap.has(extend)) {
|
|
170
|
+
currentName = componentNameMap.get(extend);
|
|
165
171
|
}
|
|
166
172
|
processed.add(extend);
|
|
167
173
|
if (extend?.extends || extend?.extend) {
|
|
168
|
-
deepExtend(extend, stack, context, processed);
|
|
174
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
169
175
|
} else if (extend) {
|
|
170
176
|
stack.push(extend);
|
|
177
|
+
if (nameStack) nameStack.push(currentName);
|
|
171
178
|
}
|
|
172
179
|
return stack;
|
|
173
180
|
};
|
|
@@ -180,7 +187,7 @@ const MERGE_EXTENDS_SKIP = /* @__PURE__ */ new Set([
|
|
|
180
187
|
"childExtend",
|
|
181
188
|
"childExtendRecursive"
|
|
182
189
|
]);
|
|
183
|
-
const deepMergeExtends = (element, extend) => {
|
|
190
|
+
const deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
184
191
|
extend = (0, import_object.deepClone)(extend);
|
|
185
192
|
for (const e in extend) {
|
|
186
193
|
if (MERGE_EXTENDS_SKIP.has(e)) continue;
|
|
@@ -190,11 +197,23 @@ const deepMergeExtends = (element, extend) => {
|
|
|
190
197
|
if (Object.prototype.hasOwnProperty.call(extend, e) && e !== "__proto__" && e !== "constructor" && e !== "prototype") {
|
|
191
198
|
if (elementProp === void 0) {
|
|
192
199
|
element[e] = extendProp;
|
|
200
|
+
if (sourcemap && sourceName) {
|
|
201
|
+
if ((0, import_types.isObject)(extendProp) && !(0, import_types.isArray)(extendProp)) {
|
|
202
|
+
sourcemap[e] = sourcemap[e] || {};
|
|
203
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName);
|
|
204
|
+
} else {
|
|
205
|
+
sourcemap[e] = sourceName;
|
|
206
|
+
}
|
|
207
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
208
|
+
sourcemap[e] = preBuiltSourcemap[e];
|
|
209
|
+
}
|
|
193
210
|
} else if ((0, import_types.isObject)(elementProp) && (0, import_types.isObject)(extendProp)) {
|
|
211
|
+
const nestedSourcemap = sourcemap ? sourcemap[e] = sourcemap[e] || {} : void 0;
|
|
212
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e];
|
|
194
213
|
if ((0, import_component.matchesComponentNaming)(e)) {
|
|
195
|
-
element[e] = deepMergeExtends(elementProp, extendProp);
|
|
214
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
196
215
|
} else {
|
|
197
|
-
deepMergeExtends(elementProp, extendProp);
|
|
216
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
198
217
|
}
|
|
199
218
|
}
|
|
200
219
|
if (e === "extends" || e === "childExtends" || e === "childExtendsRecursive") {
|
|
@@ -209,10 +228,24 @@ const deepMergeExtends = (element, extend) => {
|
|
|
209
228
|
}
|
|
210
229
|
return element;
|
|
211
230
|
};
|
|
212
|
-
const
|
|
213
|
-
|
|
231
|
+
const trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
232
|
+
for (const key in obj) {
|
|
233
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
234
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
235
|
+
const val = obj[key];
|
|
236
|
+
if ((0, import_types.isObject)(val) && !(0, import_types.isArray)(val)) {
|
|
237
|
+
sourcemap[key] = sourcemap[key] || {};
|
|
238
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName);
|
|
239
|
+
} else {
|
|
240
|
+
sourcemap[key] = sourceName;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
245
|
+
return stack.reduce((acc, current, i) => {
|
|
214
246
|
const cloned = (0, import_object.deepClone)(current);
|
|
215
|
-
|
|
247
|
+
const sourceName = extendNames ? extendNames[i] : void 0;
|
|
248
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName);
|
|
216
249
|
}, {});
|
|
217
250
|
};
|
|
218
251
|
const mapStringsWithContextComponents = (extend, context, options = {}, variant) => {
|
|
@@ -235,11 +268,12 @@ const mapStringsWithContextComponents = (extend, context, options = {}, variant)
|
|
|
235
268
|
const jointStacks = (extendStack, childExtendsStack) => {
|
|
236
269
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendsStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendsStack.slice(1));
|
|
237
270
|
};
|
|
238
|
-
const getExtendsStack = (extend, context) => {
|
|
271
|
+
const getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
239
272
|
if (!extend) return [];
|
|
240
273
|
if (extend.__hash) return getHashedExtend(extend) || [];
|
|
241
274
|
const processed = /* @__PURE__ */ new Set();
|
|
242
|
-
const stack = flattenExtend(extend, [], context, processed);
|
|
275
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, void 0, componentNameMap);
|
|
276
|
+
if (nameStack) return stack;
|
|
243
277
|
return getExtendsStackRegistry(extend, stack);
|
|
244
278
|
};
|
|
245
279
|
const addExtend = (newExtends, elementExtends) => {
|
|
@@ -346,6 +380,8 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
346
380
|
const { props, __ref: ref } = element;
|
|
347
381
|
const context = element.context || parent.context;
|
|
348
382
|
const variant = element.variant || props?.variant;
|
|
383
|
+
const sourcemap = isSourcemapEnabled(options);
|
|
384
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null;
|
|
349
385
|
const __extends = (0, import_array.removeDuplicatesInArray)(
|
|
350
386
|
ref.__extends.map((val, i) => {
|
|
351
387
|
return mapStringsWithContextComponents(
|
|
@@ -356,15 +392,40 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
356
392
|
);
|
|
357
393
|
})
|
|
358
394
|
);
|
|
359
|
-
|
|
360
|
-
|
|
395
|
+
if (sourcemap) {
|
|
396
|
+
const componentNameMap = /* @__PURE__ */ new WeakMap();
|
|
397
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
398
|
+
const resolved = __extends[i];
|
|
399
|
+
const originalName = originalExtendNames[i];
|
|
400
|
+
if (resolved && (0, import_types.isObject)(resolved) && (0, import_types.isString)(originalName)) {
|
|
401
|
+
componentNameMap.set(resolved, originalName);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const nameStack = [];
|
|
405
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap);
|
|
406
|
+
ref.__extendsStack = stack;
|
|
407
|
+
ref.__extendsNames = nameStack;
|
|
408
|
+
} else {
|
|
409
|
+
const stack = getExtendsStack(__extends, context);
|
|
410
|
+
ref.__extendsStack = stack;
|
|
411
|
+
}
|
|
361
412
|
return ref.__extendsStack;
|
|
362
413
|
};
|
|
363
414
|
const finalizeExtends = (element, parent, options = {}) => {
|
|
364
415
|
const { __ref: ref } = element;
|
|
365
416
|
const { __extendsStack } = ref;
|
|
366
|
-
|
|
367
|
-
|
|
417
|
+
if (isSourcemapEnabled(options)) {
|
|
418
|
+
const sourcemapAcc = {};
|
|
419
|
+
const extendNames = ref.__extendsNames || [];
|
|
420
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames);
|
|
421
|
+
const appliedSourcemap = {};
|
|
422
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, void 0, sourcemapAcc);
|
|
423
|
+
ref.__sourcemap = appliedSourcemap;
|
|
424
|
+
} else {
|
|
425
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
|
|
426
|
+
deepMergeExtends(element, flattenExtends);
|
|
427
|
+
}
|
|
428
|
+
return element;
|
|
368
429
|
};
|
|
369
430
|
const applyExtends = (element, parent, options = {}) => {
|
|
370
431
|
createElementExtends(element, parent, options);
|
package/dist/cjs/node.js
CHANGED
|
@@ -31,5 +31,5 @@ const isHtmlElement = (obj) => {
|
|
|
31
31
|
return (typeof HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
32
32
|
};
|
|
33
33
|
const isDOMNode = (obj) => {
|
|
34
|
-
return typeof import_globals.window !== "undefined" && (obj instanceof import_globals.window.Node || obj instanceof import_globals.window.Window || obj === import_globals.window || obj === document);
|
|
34
|
+
return typeof import_globals.window !== "undefined" && (import_globals.window.Node && obj instanceof import_globals.window.Node || import_globals.window.Window && obj instanceof import_globals.window.Window || obj === import_globals.window || obj === document);
|
|
35
35
|
};
|
package/dist/cjs/props.js
CHANGED
|
@@ -43,6 +43,30 @@ var import_types = require("./types.js");
|
|
|
43
43
|
var import_string = require("./string.js");
|
|
44
44
|
const RE_UPPER = /^[A-Z]/;
|
|
45
45
|
const RE_DIGITS = /^\d+$/;
|
|
46
|
+
const ELEMENT_INDICATOR_KEYS = /* @__PURE__ */ new Set([
|
|
47
|
+
"extend",
|
|
48
|
+
"props",
|
|
49
|
+
"text",
|
|
50
|
+
"tag",
|
|
51
|
+
"on",
|
|
52
|
+
"if",
|
|
53
|
+
"childExtend",
|
|
54
|
+
"children",
|
|
55
|
+
"childrenAs",
|
|
56
|
+
"state",
|
|
57
|
+
"html",
|
|
58
|
+
"attr",
|
|
59
|
+
"define",
|
|
60
|
+
"content"
|
|
61
|
+
]);
|
|
62
|
+
const looksLikeElement = (value) => {
|
|
63
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
64
|
+
for (const k in value) {
|
|
65
|
+
if (ELEMENT_INDICATOR_KEYS.has(k)) return true;
|
|
66
|
+
if (RE_UPPER.test(k)) return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
46
70
|
const createProps = (element, parent, key) => {
|
|
47
71
|
const { props, __ref: ref } = element;
|
|
48
72
|
ref.__propsStack = [];
|
|
@@ -67,7 +91,7 @@ function pickupPropsFromElement(obj, opts = {}) {
|
|
|
67
91
|
}
|
|
68
92
|
const hasDefine = (0, import_types.isObject)(this.define?.[key]);
|
|
69
93
|
const hasGlobalDefine = (0, import_types.isObject)(this.context?.define?.[key]);
|
|
70
|
-
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
94
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
|
|
71
95
|
const isBuiltin = import_keys.DOMQ_PROPERTIES.has(key);
|
|
72
96
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
73
97
|
obj.props[key] = value;
|
package/dist/esm/extends.js
CHANGED
|
@@ -3,6 +3,7 @@ import { matchesComponentNaming } from "./component.js";
|
|
|
3
3
|
import { deepClone, exec } from "./object.js";
|
|
4
4
|
import { isArray, isObject, isString } from "./types.js";
|
|
5
5
|
const ENV = process.env.NODE_ENV;
|
|
6
|
+
const isSourcemapEnabled = (options) => options.sourcemap !== false && ENV !== "production";
|
|
6
7
|
const createExtendsFromKeys = (key) => {
|
|
7
8
|
if (key.includes("+")) {
|
|
8
9
|
return key.split("+").filter(matchesComponentNaming);
|
|
@@ -77,17 +78,17 @@ const getExtendsStackRegistry = (extend, stack) => {
|
|
|
77
78
|
}
|
|
78
79
|
return setHashedExtend(extend, stack);
|
|
79
80
|
};
|
|
80
|
-
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
81
|
+
const extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, componentNameMap) => {
|
|
81
82
|
for (const each of extend) {
|
|
82
83
|
if (isArray(each)) {
|
|
83
|
-
extractArrayExtend(each, stack, context, processed);
|
|
84
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap);
|
|
84
85
|
} else {
|
|
85
|
-
flattenExtend(each, stack, context, processed);
|
|
86
|
+
flattenExtend(each, stack, context, processed, nameStack, void 0, componentNameMap);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
return stack;
|
|
89
90
|
};
|
|
90
|
-
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
91
|
+
const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, currentName, componentNameMap) => {
|
|
91
92
|
const extendOflattenExtend = extend.extends || extend.extend;
|
|
92
93
|
const cleanExtend = { ...extend };
|
|
93
94
|
delete cleanExtend.extends;
|
|
@@ -99,26 +100,32 @@ const deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(
|
|
|
99
100
|
}
|
|
100
101
|
if (hasKeys) {
|
|
101
102
|
stack.push(cleanExtend);
|
|
103
|
+
if (nameStack) nameStack.push(currentName);
|
|
102
104
|
}
|
|
103
105
|
if (extendOflattenExtend) {
|
|
104
|
-
flattenExtend(extendOflattenExtend, stack, context, processed);
|
|
106
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
105
107
|
}
|
|
106
108
|
return stack;
|
|
107
109
|
};
|
|
108
|
-
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
110
|
+
const flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, parentName, componentNameMap) => {
|
|
109
111
|
if (!extend) return stack;
|
|
110
112
|
if (processed.has(extend)) return stack;
|
|
111
113
|
if (isArray(extend)) {
|
|
112
|
-
return extractArrayExtend(extend, stack, context, processed);
|
|
114
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap);
|
|
113
115
|
}
|
|
116
|
+
let currentName = parentName;
|
|
114
117
|
if (isString(extend)) {
|
|
118
|
+
currentName = extend;
|
|
115
119
|
extend = mapStringsWithContextComponents(extend, context);
|
|
120
|
+
} else if (componentNameMap && isObject(extend) && componentNameMap.has(extend)) {
|
|
121
|
+
currentName = componentNameMap.get(extend);
|
|
116
122
|
}
|
|
117
123
|
processed.add(extend);
|
|
118
124
|
if (extend?.extends || extend?.extend) {
|
|
119
|
-
deepExtend(extend, stack, context, processed);
|
|
125
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
120
126
|
} else if (extend) {
|
|
121
127
|
stack.push(extend);
|
|
128
|
+
if (nameStack) nameStack.push(currentName);
|
|
122
129
|
}
|
|
123
130
|
return stack;
|
|
124
131
|
};
|
|
@@ -131,7 +138,7 @@ const MERGE_EXTENDS_SKIP = /* @__PURE__ */ new Set([
|
|
|
131
138
|
"childExtend",
|
|
132
139
|
"childExtendRecursive"
|
|
133
140
|
]);
|
|
134
|
-
const deepMergeExtends = (element, extend) => {
|
|
141
|
+
const deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
135
142
|
extend = deepClone(extend);
|
|
136
143
|
for (const e in extend) {
|
|
137
144
|
if (MERGE_EXTENDS_SKIP.has(e)) continue;
|
|
@@ -141,11 +148,23 @@ const deepMergeExtends = (element, extend) => {
|
|
|
141
148
|
if (Object.prototype.hasOwnProperty.call(extend, e) && e !== "__proto__" && e !== "constructor" && e !== "prototype") {
|
|
142
149
|
if (elementProp === void 0) {
|
|
143
150
|
element[e] = extendProp;
|
|
151
|
+
if (sourcemap && sourceName) {
|
|
152
|
+
if (isObject(extendProp) && !isArray(extendProp)) {
|
|
153
|
+
sourcemap[e] = sourcemap[e] || {};
|
|
154
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName);
|
|
155
|
+
} else {
|
|
156
|
+
sourcemap[e] = sourceName;
|
|
157
|
+
}
|
|
158
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
159
|
+
sourcemap[e] = preBuiltSourcemap[e];
|
|
160
|
+
}
|
|
144
161
|
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
162
|
+
const nestedSourcemap = sourcemap ? sourcemap[e] = sourcemap[e] || {} : void 0;
|
|
163
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e];
|
|
145
164
|
if (matchesComponentNaming(e)) {
|
|
146
|
-
element[e] = deepMergeExtends(elementProp, extendProp);
|
|
165
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
147
166
|
} else {
|
|
148
|
-
deepMergeExtends(elementProp, extendProp);
|
|
167
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
149
168
|
}
|
|
150
169
|
}
|
|
151
170
|
if (e === "extends" || e === "childExtends" || e === "childExtendsRecursive") {
|
|
@@ -160,10 +179,24 @@ const deepMergeExtends = (element, extend) => {
|
|
|
160
179
|
}
|
|
161
180
|
return element;
|
|
162
181
|
};
|
|
163
|
-
const
|
|
164
|
-
|
|
182
|
+
const trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
183
|
+
for (const key in obj) {
|
|
184
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
185
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
186
|
+
const val = obj[key];
|
|
187
|
+
if (isObject(val) && !isArray(val)) {
|
|
188
|
+
sourcemap[key] = sourcemap[key] || {};
|
|
189
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName);
|
|
190
|
+
} else {
|
|
191
|
+
sourcemap[key] = sourceName;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
const cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
196
|
+
return stack.reduce((acc, current, i) => {
|
|
165
197
|
const cloned = deepClone(current);
|
|
166
|
-
|
|
198
|
+
const sourceName = extendNames ? extendNames[i] : void 0;
|
|
199
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName);
|
|
167
200
|
}, {});
|
|
168
201
|
};
|
|
169
202
|
const mapStringsWithContextComponents = (extend, context, options = {}, variant) => {
|
|
@@ -186,11 +219,12 @@ const mapStringsWithContextComponents = (extend, context, options = {}, variant)
|
|
|
186
219
|
const jointStacks = (extendStack, childExtendsStack) => {
|
|
187
220
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendsStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendsStack.slice(1));
|
|
188
221
|
};
|
|
189
|
-
const getExtendsStack = (extend, context) => {
|
|
222
|
+
const getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
190
223
|
if (!extend) return [];
|
|
191
224
|
if (extend.__hash) return getHashedExtend(extend) || [];
|
|
192
225
|
const processed = /* @__PURE__ */ new Set();
|
|
193
|
-
const stack = flattenExtend(extend, [], context, processed);
|
|
226
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, void 0, componentNameMap);
|
|
227
|
+
if (nameStack) return stack;
|
|
194
228
|
return getExtendsStackRegistry(extend, stack);
|
|
195
229
|
};
|
|
196
230
|
const addExtend = (newExtends, elementExtends) => {
|
|
@@ -297,6 +331,8 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
297
331
|
const { props, __ref: ref } = element;
|
|
298
332
|
const context = element.context || parent.context;
|
|
299
333
|
const variant = element.variant || props?.variant;
|
|
334
|
+
const sourcemap = isSourcemapEnabled(options);
|
|
335
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null;
|
|
300
336
|
const __extends = removeDuplicatesInArray(
|
|
301
337
|
ref.__extends.map((val, i) => {
|
|
302
338
|
return mapStringsWithContextComponents(
|
|
@@ -307,15 +343,40 @@ const createExtendsStack = (element, parent, options = {}) => {
|
|
|
307
343
|
);
|
|
308
344
|
})
|
|
309
345
|
);
|
|
310
|
-
|
|
311
|
-
|
|
346
|
+
if (sourcemap) {
|
|
347
|
+
const componentNameMap = /* @__PURE__ */ new WeakMap();
|
|
348
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
349
|
+
const resolved = __extends[i];
|
|
350
|
+
const originalName = originalExtendNames[i];
|
|
351
|
+
if (resolved && isObject(resolved) && isString(originalName)) {
|
|
352
|
+
componentNameMap.set(resolved, originalName);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const nameStack = [];
|
|
356
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap);
|
|
357
|
+
ref.__extendsStack = stack;
|
|
358
|
+
ref.__extendsNames = nameStack;
|
|
359
|
+
} else {
|
|
360
|
+
const stack = getExtendsStack(__extends, context);
|
|
361
|
+
ref.__extendsStack = stack;
|
|
362
|
+
}
|
|
312
363
|
return ref.__extendsStack;
|
|
313
364
|
};
|
|
314
365
|
const finalizeExtends = (element, parent, options = {}) => {
|
|
315
366
|
const { __ref: ref } = element;
|
|
316
367
|
const { __extendsStack } = ref;
|
|
317
|
-
|
|
318
|
-
|
|
368
|
+
if (isSourcemapEnabled(options)) {
|
|
369
|
+
const sourcemapAcc = {};
|
|
370
|
+
const extendNames = ref.__extendsNames || [];
|
|
371
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames);
|
|
372
|
+
const appliedSourcemap = {};
|
|
373
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, void 0, sourcemapAcc);
|
|
374
|
+
ref.__sourcemap = appliedSourcemap;
|
|
375
|
+
} else {
|
|
376
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
|
|
377
|
+
deepMergeExtends(element, flattenExtends);
|
|
378
|
+
}
|
|
379
|
+
return element;
|
|
319
380
|
};
|
|
320
381
|
const applyExtends = (element, parent, options = {}) => {
|
|
321
382
|
createElementExtends(element, parent, options);
|
package/dist/esm/node.js
CHANGED
|
@@ -6,7 +6,7 @@ const isHtmlElement = (obj) => {
|
|
|
6
6
|
return (typeof HTMLElement === "object" ? obj instanceof window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
7
7
|
};
|
|
8
8
|
const isDOMNode = (obj) => {
|
|
9
|
-
return typeof window !== "undefined" && (obj instanceof window.Node || obj instanceof window.Window || obj === window || obj === document);
|
|
9
|
+
return typeof window !== "undefined" && (window.Node && obj instanceof window.Node || window.Window && obj instanceof window.Window || obj === window || obj === document);
|
|
10
10
|
};
|
|
11
11
|
export {
|
|
12
12
|
isDOMNode,
|
package/dist/esm/props.js
CHANGED
|
@@ -5,6 +5,30 @@ import { is, isArray, isFunction, isObject, isObjectLike } from "./types.js";
|
|
|
5
5
|
import { lowercaseFirstLetter } from "./string.js";
|
|
6
6
|
const RE_UPPER = /^[A-Z]/;
|
|
7
7
|
const RE_DIGITS = /^\d+$/;
|
|
8
|
+
const ELEMENT_INDICATOR_KEYS = /* @__PURE__ */ new Set([
|
|
9
|
+
"extend",
|
|
10
|
+
"props",
|
|
11
|
+
"text",
|
|
12
|
+
"tag",
|
|
13
|
+
"on",
|
|
14
|
+
"if",
|
|
15
|
+
"childExtend",
|
|
16
|
+
"children",
|
|
17
|
+
"childrenAs",
|
|
18
|
+
"state",
|
|
19
|
+
"html",
|
|
20
|
+
"attr",
|
|
21
|
+
"define",
|
|
22
|
+
"content"
|
|
23
|
+
]);
|
|
24
|
+
const looksLikeElement = (value) => {
|
|
25
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
26
|
+
for (const k in value) {
|
|
27
|
+
if (ELEMENT_INDICATOR_KEYS.has(k)) return true;
|
|
28
|
+
if (RE_UPPER.test(k)) return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
8
32
|
const createProps = (element, parent, key) => {
|
|
9
33
|
const { props, __ref: ref } = element;
|
|
10
34
|
ref.__propsStack = [];
|
|
@@ -29,7 +53,7 @@ function pickupPropsFromElement(obj, opts = {}) {
|
|
|
29
53
|
}
|
|
30
54
|
const hasDefine = isObject(this.define?.[key]);
|
|
31
55
|
const hasGlobalDefine = isObject(this.context?.define?.[key]);
|
|
32
|
-
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
56
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
|
|
33
57
|
const isBuiltin = DOMQ_PROPERTIES.has(key);
|
|
34
58
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
35
59
|
obj.props[key] = value;
|
package/dist/iife/index.js
CHANGED
|
@@ -257,7 +257,7 @@ var DomqlUtils = (() => {
|
|
|
257
257
|
return (typeof HTMLElement === "object" ? obj instanceof window2.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
258
258
|
};
|
|
259
259
|
var isDOMNode = (obj) => {
|
|
260
|
-
return typeof window2 !== "undefined" && (obj instanceof window2.Node || obj instanceof window2.Window || obj === window2 || obj === document);
|
|
260
|
+
return typeof window2 !== "undefined" && (window2.Node && obj instanceof window2.Node || window2.Window && obj instanceof window2.Window || obj === window2 || obj === document);
|
|
261
261
|
};
|
|
262
262
|
|
|
263
263
|
// types.js
|
|
@@ -1586,6 +1586,7 @@ var DomqlUtils = (() => {
|
|
|
1586
1586
|
|
|
1587
1587
|
// extends.js
|
|
1588
1588
|
var ENV3 = process.env.NODE_ENV;
|
|
1589
|
+
var isSourcemapEnabled = (options) => options.sourcemap !== false && ENV3 !== "production";
|
|
1589
1590
|
var createExtendsFromKeys = (key) => {
|
|
1590
1591
|
if (key.includes("+")) {
|
|
1591
1592
|
return key.split("+").filter(matchesComponentNaming);
|
|
@@ -1660,17 +1661,17 @@ var DomqlUtils = (() => {
|
|
|
1660
1661
|
}
|
|
1661
1662
|
return setHashedExtend(extend, stack);
|
|
1662
1663
|
};
|
|
1663
|
-
var extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
1664
|
+
var extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, componentNameMap) => {
|
|
1664
1665
|
for (const each of extend) {
|
|
1665
1666
|
if (isArray(each)) {
|
|
1666
|
-
extractArrayExtend(each, stack, context, processed);
|
|
1667
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap);
|
|
1667
1668
|
} else {
|
|
1668
|
-
flattenExtend(each, stack, context, processed);
|
|
1669
|
+
flattenExtend(each, stack, context, processed, nameStack, void 0, componentNameMap);
|
|
1669
1670
|
}
|
|
1670
1671
|
}
|
|
1671
1672
|
return stack;
|
|
1672
1673
|
};
|
|
1673
|
-
var deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
1674
|
+
var deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, currentName, componentNameMap) => {
|
|
1674
1675
|
const extendOflattenExtend = extend.extends || extend.extend;
|
|
1675
1676
|
const cleanExtend = { ...extend };
|
|
1676
1677
|
delete cleanExtend.extends;
|
|
@@ -1682,26 +1683,32 @@ var DomqlUtils = (() => {
|
|
|
1682
1683
|
}
|
|
1683
1684
|
if (hasKeys) {
|
|
1684
1685
|
stack.push(cleanExtend);
|
|
1686
|
+
if (nameStack) nameStack.push(currentName);
|
|
1685
1687
|
}
|
|
1686
1688
|
if (extendOflattenExtend) {
|
|
1687
|
-
flattenExtend(extendOflattenExtend, stack, context, processed);
|
|
1689
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
1688
1690
|
}
|
|
1689
1691
|
return stack;
|
|
1690
1692
|
};
|
|
1691
|
-
var flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
|
|
1693
|
+
var flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, parentName, componentNameMap) => {
|
|
1692
1694
|
if (!extend) return stack;
|
|
1693
1695
|
if (processed.has(extend)) return stack;
|
|
1694
1696
|
if (isArray(extend)) {
|
|
1695
|
-
return extractArrayExtend(extend, stack, context, processed);
|
|
1697
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap);
|
|
1696
1698
|
}
|
|
1699
|
+
let currentName = parentName;
|
|
1697
1700
|
if (isString(extend)) {
|
|
1701
|
+
currentName = extend;
|
|
1698
1702
|
extend = mapStringsWithContextComponents(extend, context);
|
|
1703
|
+
} else if (componentNameMap && isObject(extend) && componentNameMap.has(extend)) {
|
|
1704
|
+
currentName = componentNameMap.get(extend);
|
|
1699
1705
|
}
|
|
1700
1706
|
processed.add(extend);
|
|
1701
1707
|
if (extend?.extends || extend?.extend) {
|
|
1702
|
-
deepExtend(extend, stack, context, processed);
|
|
1708
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap);
|
|
1703
1709
|
} else if (extend) {
|
|
1704
1710
|
stack.push(extend);
|
|
1711
|
+
if (nameStack) nameStack.push(currentName);
|
|
1705
1712
|
}
|
|
1706
1713
|
return stack;
|
|
1707
1714
|
};
|
|
@@ -1714,7 +1721,7 @@ var DomqlUtils = (() => {
|
|
|
1714
1721
|
"childExtend",
|
|
1715
1722
|
"childExtendRecursive"
|
|
1716
1723
|
]);
|
|
1717
|
-
var deepMergeExtends = (element, extend) => {
|
|
1724
|
+
var deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
1718
1725
|
extend = deepClone(extend);
|
|
1719
1726
|
for (const e in extend) {
|
|
1720
1727
|
if (MERGE_EXTENDS_SKIP.has(e)) continue;
|
|
@@ -1724,11 +1731,23 @@ var DomqlUtils = (() => {
|
|
|
1724
1731
|
if (Object.prototype.hasOwnProperty.call(extend, e) && e !== "__proto__" && e !== "constructor" && e !== "prototype") {
|
|
1725
1732
|
if (elementProp === void 0) {
|
|
1726
1733
|
element[e] = extendProp;
|
|
1734
|
+
if (sourcemap && sourceName) {
|
|
1735
|
+
if (isObject(extendProp) && !isArray(extendProp)) {
|
|
1736
|
+
sourcemap[e] = sourcemap[e] || {};
|
|
1737
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName);
|
|
1738
|
+
} else {
|
|
1739
|
+
sourcemap[e] = sourceName;
|
|
1740
|
+
}
|
|
1741
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
1742
|
+
sourcemap[e] = preBuiltSourcemap[e];
|
|
1743
|
+
}
|
|
1727
1744
|
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
1745
|
+
const nestedSourcemap = sourcemap ? sourcemap[e] = sourcemap[e] || {} : void 0;
|
|
1746
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e];
|
|
1728
1747
|
if (matchesComponentNaming(e)) {
|
|
1729
|
-
element[e] = deepMergeExtends(elementProp, extendProp);
|
|
1748
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
1730
1749
|
} else {
|
|
1731
|
-
deepMergeExtends(elementProp, extendProp);
|
|
1750
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
|
|
1732
1751
|
}
|
|
1733
1752
|
}
|
|
1734
1753
|
if (e === "extends" || e === "childExtends" || e === "childExtendsRecursive") {
|
|
@@ -1743,10 +1762,24 @@ var DomqlUtils = (() => {
|
|
|
1743
1762
|
}
|
|
1744
1763
|
return element;
|
|
1745
1764
|
};
|
|
1746
|
-
var
|
|
1747
|
-
|
|
1765
|
+
var trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
1766
|
+
for (const key in obj) {
|
|
1767
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
|
|
1768
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
|
|
1769
|
+
const val = obj[key];
|
|
1770
|
+
if (isObject(val) && !isArray(val)) {
|
|
1771
|
+
sourcemap[key] = sourcemap[key] || {};
|
|
1772
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName);
|
|
1773
|
+
} else {
|
|
1774
|
+
sourcemap[key] = sourceName;
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
var cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
1779
|
+
return stack.reduce((acc, current, i) => {
|
|
1748
1780
|
const cloned = deepClone(current);
|
|
1749
|
-
|
|
1781
|
+
const sourceName = extendNames ? extendNames[i] : void 0;
|
|
1782
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName);
|
|
1750
1783
|
}, {});
|
|
1751
1784
|
};
|
|
1752
1785
|
var mapStringsWithContextComponents = (extend, context, options = {}, variant) => {
|
|
@@ -1769,11 +1802,12 @@ var DomqlUtils = (() => {
|
|
|
1769
1802
|
var jointStacks = (extendStack, childExtendsStack) => {
|
|
1770
1803
|
return [].concat(extendStack.slice(0, 1)).concat(childExtendsStack.slice(0, 1)).concat(extendStack.slice(1)).concat(childExtendsStack.slice(1));
|
|
1771
1804
|
};
|
|
1772
|
-
var getExtendsStack = (extend, context) => {
|
|
1805
|
+
var getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
1773
1806
|
if (!extend) return [];
|
|
1774
1807
|
if (extend.__hash) return getHashedExtend(extend) || [];
|
|
1775
1808
|
const processed = /* @__PURE__ */ new Set();
|
|
1776
|
-
const stack = flattenExtend(extend, [], context, processed);
|
|
1809
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, void 0, componentNameMap);
|
|
1810
|
+
if (nameStack) return stack;
|
|
1777
1811
|
return getExtendsStackRegistry(extend, stack);
|
|
1778
1812
|
};
|
|
1779
1813
|
var addExtend = (newExtends, elementExtends) => {
|
|
@@ -1880,6 +1914,8 @@ var DomqlUtils = (() => {
|
|
|
1880
1914
|
const { props, __ref: ref } = element;
|
|
1881
1915
|
const context = element.context || parent.context;
|
|
1882
1916
|
const variant = element.variant || props?.variant;
|
|
1917
|
+
const sourcemap = isSourcemapEnabled(options);
|
|
1918
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null;
|
|
1883
1919
|
const __extends = removeDuplicatesInArray(
|
|
1884
1920
|
ref.__extends.map((val, i) => {
|
|
1885
1921
|
return mapStringsWithContextComponents(
|
|
@@ -1890,15 +1926,40 @@ var DomqlUtils = (() => {
|
|
|
1890
1926
|
);
|
|
1891
1927
|
})
|
|
1892
1928
|
);
|
|
1893
|
-
|
|
1894
|
-
|
|
1929
|
+
if (sourcemap) {
|
|
1930
|
+
const componentNameMap = /* @__PURE__ */ new WeakMap();
|
|
1931
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
1932
|
+
const resolved = __extends[i];
|
|
1933
|
+
const originalName = originalExtendNames[i];
|
|
1934
|
+
if (resolved && isObject(resolved) && isString(originalName)) {
|
|
1935
|
+
componentNameMap.set(resolved, originalName);
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
const nameStack = [];
|
|
1939
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap);
|
|
1940
|
+
ref.__extendsStack = stack;
|
|
1941
|
+
ref.__extendsNames = nameStack;
|
|
1942
|
+
} else {
|
|
1943
|
+
const stack = getExtendsStack(__extends, context);
|
|
1944
|
+
ref.__extendsStack = stack;
|
|
1945
|
+
}
|
|
1895
1946
|
return ref.__extendsStack;
|
|
1896
1947
|
};
|
|
1897
1948
|
var finalizeExtends = (element, parent, options = {}) => {
|
|
1898
1949
|
const { __ref: ref } = element;
|
|
1899
1950
|
const { __extendsStack } = ref;
|
|
1900
|
-
|
|
1901
|
-
|
|
1951
|
+
if (isSourcemapEnabled(options)) {
|
|
1952
|
+
const sourcemapAcc = {};
|
|
1953
|
+
const extendNames = ref.__extendsNames || [];
|
|
1954
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames);
|
|
1955
|
+
const appliedSourcemap = {};
|
|
1956
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, void 0, sourcemapAcc);
|
|
1957
|
+
ref.__sourcemap = appliedSourcemap;
|
|
1958
|
+
} else {
|
|
1959
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
|
|
1960
|
+
deepMergeExtends(element, flattenExtends);
|
|
1961
|
+
}
|
|
1962
|
+
return element;
|
|
1902
1963
|
};
|
|
1903
1964
|
var applyExtends = (element, parent, options = {}) => {
|
|
1904
1965
|
createElementExtends(element, parent, options);
|
|
@@ -1943,6 +2004,30 @@ var DomqlUtils = (() => {
|
|
|
1943
2004
|
// props.js
|
|
1944
2005
|
var RE_UPPER = /^[A-Z]/;
|
|
1945
2006
|
var RE_DIGITS = /^\d+$/;
|
|
2007
|
+
var ELEMENT_INDICATOR_KEYS = /* @__PURE__ */ new Set([
|
|
2008
|
+
"extend",
|
|
2009
|
+
"props",
|
|
2010
|
+
"text",
|
|
2011
|
+
"tag",
|
|
2012
|
+
"on",
|
|
2013
|
+
"if",
|
|
2014
|
+
"childExtend",
|
|
2015
|
+
"children",
|
|
2016
|
+
"childrenAs",
|
|
2017
|
+
"state",
|
|
2018
|
+
"html",
|
|
2019
|
+
"attr",
|
|
2020
|
+
"define",
|
|
2021
|
+
"content"
|
|
2022
|
+
]);
|
|
2023
|
+
var looksLikeElement = (value) => {
|
|
2024
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
2025
|
+
for (const k in value) {
|
|
2026
|
+
if (ELEMENT_INDICATOR_KEYS.has(k)) return true;
|
|
2027
|
+
if (RE_UPPER.test(k)) return true;
|
|
2028
|
+
}
|
|
2029
|
+
return false;
|
|
2030
|
+
};
|
|
1946
2031
|
var createProps = (element, parent, key) => {
|
|
1947
2032
|
const { props, __ref: ref } = element;
|
|
1948
2033
|
ref.__propsStack = [];
|
|
@@ -1967,7 +2052,7 @@ var DomqlUtils = (() => {
|
|
|
1967
2052
|
}
|
|
1968
2053
|
const hasDefine = isObject(this.define?.[key]);
|
|
1969
2054
|
const hasGlobalDefine = isObject(this.context?.define?.[key]);
|
|
1970
|
-
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
|
|
2055
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
|
|
1971
2056
|
const isBuiltin = DOMQ_PROPERTIES.has(key);
|
|
1972
2057
|
if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
|
|
1973
2058
|
obj.props[key] = value;
|
package/extends.js
CHANGED
|
@@ -5,6 +5,7 @@ import { matchesComponentNaming } from './component.js'
|
|
|
5
5
|
import { deepClone, exec } from './object.js'
|
|
6
6
|
import { isArray, isObject, isString } from './types.js'
|
|
7
7
|
const ENV = process.env.NODE_ENV
|
|
8
|
+
const isSourcemapEnabled = (options) => options.sourcemap !== false && ENV !== 'production'
|
|
8
9
|
|
|
9
10
|
export const createExtendsFromKeys = key => {
|
|
10
11
|
if (key.includes('+')) {
|
|
@@ -112,19 +113,21 @@ export const extractArrayExtend = (
|
|
|
112
113
|
extend,
|
|
113
114
|
stack,
|
|
114
115
|
context,
|
|
115
|
-
processed = new Set()
|
|
116
|
+
processed = new Set(),
|
|
117
|
+
nameStack,
|
|
118
|
+
componentNameMap
|
|
116
119
|
) => {
|
|
117
120
|
for (const each of extend) {
|
|
118
121
|
if (isArray(each)) {
|
|
119
|
-
extractArrayExtend(each, stack, context, processed)
|
|
122
|
+
extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap)
|
|
120
123
|
} else {
|
|
121
|
-
flattenExtend(each, stack, context, processed)
|
|
124
|
+
flattenExtend(each, stack, context, processed, nameStack, undefined, componentNameMap)
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
return stack
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
export const deepExtend = (extend, stack, context, processed = new Set()) => {
|
|
130
|
+
export const deepExtend = (extend, stack, context, processed = new Set(), nameStack, currentName, componentNameMap) => {
|
|
128
131
|
const extendOflattenExtend = extend.extends || extend.extend
|
|
129
132
|
// Remove extends/extend properties before adding to stack
|
|
130
133
|
const cleanExtend = { ...extend }
|
|
@@ -134,9 +137,10 @@ export const deepExtend = (extend, stack, context, processed = new Set()) => {
|
|
|
134
137
|
for (const _k in cleanExtend) { hasKeys = true; break } // eslint-disable-line
|
|
135
138
|
if (hasKeys) {
|
|
136
139
|
stack.push(cleanExtend)
|
|
140
|
+
if (nameStack) nameStack.push(currentName)
|
|
137
141
|
}
|
|
138
142
|
if (extendOflattenExtend) {
|
|
139
|
-
flattenExtend(extendOflattenExtend, stack, context, processed)
|
|
143
|
+
flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap)
|
|
140
144
|
}
|
|
141
145
|
return stack
|
|
142
146
|
}
|
|
@@ -145,25 +149,34 @@ export const flattenExtend = (
|
|
|
145
149
|
extend,
|
|
146
150
|
stack,
|
|
147
151
|
context,
|
|
148
|
-
processed = new Set()
|
|
152
|
+
processed = new Set(),
|
|
153
|
+
nameStack,
|
|
154
|
+
parentName,
|
|
155
|
+
componentNameMap
|
|
149
156
|
) => {
|
|
150
157
|
if (!extend) return stack
|
|
151
158
|
if (processed.has(extend)) return stack
|
|
152
159
|
|
|
153
160
|
if (isArray(extend)) {
|
|
154
|
-
return extractArrayExtend(extend, stack, context, processed)
|
|
161
|
+
return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap)
|
|
155
162
|
}
|
|
156
163
|
|
|
164
|
+
let currentName = parentName
|
|
157
165
|
if (isString(extend)) {
|
|
166
|
+
currentName = extend
|
|
158
167
|
extend = mapStringsWithContextComponents(extend, context)
|
|
168
|
+
} else if (componentNameMap && isObject(extend) && componentNameMap.has(extend)) {
|
|
169
|
+
// Resolve name from pre-built map (top-level resolved extends)
|
|
170
|
+
currentName = componentNameMap.get(extend)
|
|
159
171
|
}
|
|
160
172
|
|
|
161
173
|
processed.add(extend)
|
|
162
174
|
|
|
163
175
|
if (extend?.extends || extend?.extend) {
|
|
164
|
-
deepExtend(extend, stack, context, processed)
|
|
176
|
+
deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap)
|
|
165
177
|
} else if (extend) {
|
|
166
178
|
stack.push(extend)
|
|
179
|
+
if (nameStack) nameStack.push(currentName)
|
|
167
180
|
}
|
|
168
181
|
|
|
169
182
|
return stack
|
|
@@ -173,7 +186,7 @@ const MERGE_EXTENDS_SKIP = new Set([
|
|
|
173
186
|
'parent', 'node', '__ref', '__proto__', 'extend', 'childExtend', 'childExtendRecursive'
|
|
174
187
|
])
|
|
175
188
|
|
|
176
|
-
export const deepMergeExtends = (element, extend) => {
|
|
189
|
+
export const deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
|
|
177
190
|
// Clone extend to prevent mutations
|
|
178
191
|
extend = deepClone(extend)
|
|
179
192
|
|
|
@@ -194,14 +207,28 @@ export const deepMergeExtends = (element, extend) => {
|
|
|
194
207
|
if (elementProp === undefined) {
|
|
195
208
|
// For undefined properties in element, copy from extend
|
|
196
209
|
element[e] = extendProp
|
|
210
|
+
// Track sourcemap for this property
|
|
211
|
+
if (sourcemap && sourceName) {
|
|
212
|
+
if (isObject(extendProp) && !isArray(extendProp)) {
|
|
213
|
+
sourcemap[e] = sourcemap[e] || {}
|
|
214
|
+
trackSourcemapDeep(sourcemap[e], extendProp, sourceName)
|
|
215
|
+
} else {
|
|
216
|
+
sourcemap[e] = sourceName
|
|
217
|
+
}
|
|
218
|
+
} else if (sourcemap && preBuiltSourcemap?.[e]) {
|
|
219
|
+
// Copy sourcemap entry from pre-built sourcemap (used in finalizeExtends)
|
|
220
|
+
sourcemap[e] = preBuiltSourcemap[e]
|
|
221
|
+
}
|
|
197
222
|
} else if (isObject(elementProp) && isObject(extendProp)) {
|
|
198
223
|
// For objects, merge based on type
|
|
224
|
+
const nestedSourcemap = sourcemap ? (sourcemap[e] = sourcemap[e] || {}) : undefined
|
|
225
|
+
const nestedPreBuilt = preBuiltSourcemap?.[e]
|
|
199
226
|
if (matchesComponentNaming(e)) {
|
|
200
227
|
// For components, override base properties with extended ones
|
|
201
|
-
element[e] = deepMergeExtends(elementProp, extendProp)
|
|
228
|
+
element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt)
|
|
202
229
|
} else {
|
|
203
230
|
// For other objects, merge normally
|
|
204
|
-
deepMergeExtends(elementProp, extendProp)
|
|
231
|
+
deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt)
|
|
205
232
|
}
|
|
206
233
|
}
|
|
207
234
|
|
|
@@ -225,12 +252,27 @@ export const deepMergeExtends = (element, extend) => {
|
|
|
225
252
|
return element
|
|
226
253
|
}
|
|
227
254
|
|
|
228
|
-
|
|
229
|
-
|
|
255
|
+
const trackSourcemapDeep = (sourcemap, obj, sourceName) => {
|
|
256
|
+
for (const key in obj) {
|
|
257
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) continue
|
|
258
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue
|
|
259
|
+
const val = obj[key]
|
|
260
|
+
if (isObject(val) && !isArray(val)) {
|
|
261
|
+
sourcemap[key] = sourcemap[key] || {}
|
|
262
|
+
trackSourcemapDeep(sourcemap[key], val, sourceName)
|
|
263
|
+
} else {
|
|
264
|
+
sourcemap[key] = sourceName
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export const cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
|
|
270
|
+
return stack.reduce((acc, current, i) => {
|
|
230
271
|
// Clone current extend to avoid mutations
|
|
231
272
|
const cloned = deepClone(current)
|
|
273
|
+
const sourceName = extendNames ? extendNames[i] : undefined
|
|
232
274
|
// Merge into accumulator, giving priority to current extend
|
|
233
|
-
return deepMergeExtends(acc, cloned)
|
|
275
|
+
return deepMergeExtends(acc, cloned, sourcemap, sourceName)
|
|
234
276
|
}, {})
|
|
235
277
|
}
|
|
236
278
|
|
|
@@ -271,11 +313,12 @@ export const jointStacks = (extendStack, childExtendsStack) => {
|
|
|
271
313
|
}
|
|
272
314
|
|
|
273
315
|
// init
|
|
274
|
-
export const getExtendsStack = (extend, context) => {
|
|
316
|
+
export const getExtendsStack = (extend, context, nameStack, componentNameMap) => {
|
|
275
317
|
if (!extend) return []
|
|
276
318
|
if (extend.__hash) return getHashedExtend(extend) || []
|
|
277
319
|
const processed = new Set()
|
|
278
|
-
const stack = flattenExtend(extend, [], context, processed)
|
|
320
|
+
const stack = flattenExtend(extend, [], context, processed, nameStack, undefined, componentNameMap)
|
|
321
|
+
if (nameStack) return stack
|
|
279
322
|
return getExtendsStackRegistry(extend, stack)
|
|
280
323
|
}
|
|
281
324
|
|
|
@@ -416,6 +459,10 @@ export const createExtendsStack = (element, parent, options = {}) => {
|
|
|
416
459
|
|
|
417
460
|
const variant = element.variant || props?.variant
|
|
418
461
|
|
|
462
|
+
// Keep original string names before resolution for sourcemap tracking
|
|
463
|
+
const sourcemap = isSourcemapEnabled(options)
|
|
464
|
+
const originalExtendNames = sourcemap ? [...ref.__extends] : null
|
|
465
|
+
|
|
419
466
|
const __extends = removeDuplicatesInArray(
|
|
420
467
|
ref.__extends.map((val, i) => {
|
|
421
468
|
return mapStringsWithContextComponents(
|
|
@@ -427,8 +474,24 @@ export const createExtendsStack = (element, parent, options = {}) => {
|
|
|
427
474
|
})
|
|
428
475
|
)
|
|
429
476
|
|
|
430
|
-
|
|
431
|
-
|
|
477
|
+
if (sourcemap) {
|
|
478
|
+
// Build a map from resolved component objects to their original string names
|
|
479
|
+
const componentNameMap = new WeakMap()
|
|
480
|
+
for (let i = 0; i < __extends.length; i++) {
|
|
481
|
+
const resolved = __extends[i]
|
|
482
|
+
const originalName = originalExtendNames[i]
|
|
483
|
+
if (resolved && isObject(resolved) && isString(originalName)) {
|
|
484
|
+
componentNameMap.set(resolved, originalName)
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const nameStack = []
|
|
488
|
+
const stack = getExtendsStack(__extends, context, nameStack, componentNameMap)
|
|
489
|
+
ref.__extendsStack = stack
|
|
490
|
+
ref.__extendsNames = nameStack
|
|
491
|
+
} else {
|
|
492
|
+
const stack = getExtendsStack(__extends, context)
|
|
493
|
+
ref.__extendsStack = stack
|
|
494
|
+
}
|
|
432
495
|
|
|
433
496
|
return ref.__extendsStack
|
|
434
497
|
}
|
|
@@ -436,9 +499,21 @@ export const createExtendsStack = (element, parent, options = {}) => {
|
|
|
436
499
|
export const finalizeExtends = (element, parent, options = {}) => {
|
|
437
500
|
const { __ref: ref } = element
|
|
438
501
|
const { __extendsStack } = ref
|
|
439
|
-
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack)
|
|
440
502
|
|
|
441
|
-
|
|
503
|
+
if (isSourcemapEnabled(options)) {
|
|
504
|
+
const sourcemapAcc = {}
|
|
505
|
+
const extendNames = ref.__extendsNames || []
|
|
506
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames)
|
|
507
|
+
// Only keep sourcemap entries for properties actually merged into element
|
|
508
|
+
const appliedSourcemap = {}
|
|
509
|
+
deepMergeExtends(element, flattenExtends, appliedSourcemap, undefined, sourcemapAcc)
|
|
510
|
+
ref.__sourcemap = appliedSourcemap
|
|
511
|
+
} else {
|
|
512
|
+
const flattenExtends = cloneAndMergeArrayExtend(__extendsStack)
|
|
513
|
+
deepMergeExtends(element, flattenExtends)
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return element
|
|
442
517
|
}
|
|
443
518
|
|
|
444
519
|
export const applyExtends = (element, parent, options = {}) => {
|
package/node.js
CHANGED
|
@@ -29,8 +29,8 @@ export const isHtmlElement = obj => {
|
|
|
29
29
|
export const isDOMNode = obj => {
|
|
30
30
|
return (
|
|
31
31
|
typeof window !== 'undefined' &&
|
|
32
|
-
(obj instanceof window.Node ||
|
|
33
|
-
obj instanceof window.Window ||
|
|
32
|
+
((window.Node && obj instanceof window.Node) ||
|
|
33
|
+
(window.Window && obj instanceof window.Window) ||
|
|
34
34
|
obj === window ||
|
|
35
35
|
obj === document)
|
|
36
36
|
)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -8,24 +8,19 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/esm/index.js",
|
|
11
|
-
"require": "./dist/cjs/index.js"
|
|
12
|
-
"browser": "./dist/esm/index.js",
|
|
13
|
-
"default": "./dist/esm/index.js"
|
|
11
|
+
"require": "./dist/cjs/index.js"
|
|
14
12
|
},
|
|
15
13
|
"./methods": {
|
|
16
14
|
"import": "./dist/esm/methods.js",
|
|
17
|
-
"require": "./dist/cjs/methods.js"
|
|
18
|
-
"default": "./dist/esm/methods.js"
|
|
15
|
+
"require": "./dist/cjs/methods.js"
|
|
19
16
|
},
|
|
20
17
|
"./*.js": {
|
|
21
18
|
"import": "./dist/esm/*.js",
|
|
22
|
-
"require": "./dist/cjs/*.js"
|
|
23
|
-
"default": "./dist/esm/*.js"
|
|
19
|
+
"require": "./dist/cjs/*.js"
|
|
24
20
|
},
|
|
25
21
|
"./*": {
|
|
26
22
|
"import": "./dist/esm/*.js",
|
|
27
|
-
"require": "./dist/cjs/*.js"
|
|
28
|
-
"default": "./dist/esm/*.js"
|
|
23
|
+
"require": "./dist/cjs/*.js"
|
|
29
24
|
}
|
|
30
25
|
},
|
|
31
26
|
"source": "index.js",
|
|
@@ -48,5 +43,8 @@
|
|
|
48
43
|
"browser": "./dist/esm/index.js",
|
|
49
44
|
"unpkg": "./dist/iife/index.js",
|
|
50
45
|
"jsdelivr": "./dist/iife/index.js",
|
|
51
|
-
"sideEffects": false
|
|
46
|
+
"sideEffects": false,
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
52
50
|
}
|
package/props.js
CHANGED
|
@@ -9,6 +9,20 @@ import { lowercaseFirstLetter } from './string.js'
|
|
|
9
9
|
const RE_UPPER = /^[A-Z]/
|
|
10
10
|
const RE_DIGITS = /^\d+$/
|
|
11
11
|
|
|
12
|
+
const ELEMENT_INDICATOR_KEYS = new Set([
|
|
13
|
+
'extend', 'props', 'text', 'tag', 'on', 'if', 'childExtend',
|
|
14
|
+
'children', 'childrenAs', 'state', 'html', 'attr',
|
|
15
|
+
'define', 'content'
|
|
16
|
+
])
|
|
17
|
+
const looksLikeElement = (value) => {
|
|
18
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return false
|
|
19
|
+
for (const k in value) {
|
|
20
|
+
if (ELEMENT_INDICATOR_KEYS.has(k)) return true
|
|
21
|
+
if (RE_UPPER.test(k)) return true
|
|
22
|
+
}
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
export const createProps = (element, parent, key) => {
|
|
13
27
|
const { props, __ref: ref } = element
|
|
14
28
|
ref.__propsStack = []
|
|
@@ -38,7 +52,7 @@ export function pickupPropsFromElement (obj, opts = {}) {
|
|
|
38
52
|
|
|
39
53
|
const hasDefine = isObject(this.define?.[key])
|
|
40
54
|
const hasGlobalDefine = isObject(this.context?.define?.[key])
|
|
41
|
-
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key)
|
|
55
|
+
const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value)
|
|
42
56
|
const isBuiltin = DOMQ_PROPERTIES.has(key)
|
|
43
57
|
|
|
44
58
|
// If it's not a special case, move to props
|