@domql/element 2.4.1 → 2.4.2

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.
@@ -1,262 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var create_exports = {};
30
- __export(create_exports, {
31
- default: () => create_default
32
- });
33
- module.exports = __toCommonJS(create_exports);
34
- var import_utils = require("@domql/utils");
35
- var import_tree = require("./tree");
36
- var import_registry = require("@domql/registry");
37
- var import_event = require("@domql/event");
38
- var import_render = require("@domql/render");
39
- var import_classlist = require("@domql/classlist");
40
- var import_node = require("@domql/node");
41
- var import_state = require("@domql/state");
42
- var import_methods = require("./methods");
43
- var import_props = require("./props");
44
- var import_node2 = __toESM(require("./node"), 1);
45
- var import_extend = require("./extend");
46
- var import_mixins = require("./mixins");
47
- var import_iterate = require("./iterate");
48
- var import_options = __toESM(require("./cache/options"), 1);
49
- var import_component = require("./utils/component");
50
- var import_set = require("./methods/set");
51
- const ENV = "development";
52
- const create = (element, parent, key, options = import_options.default.create || {}) => {
53
- if (options && !import_options.default.create) {
54
- import_options.default.create = options;
55
- import_options.default.create.context = element.context || options.context;
56
- }
57
- if (element === void 0) {
58
- if (ENV === "test" || ENV === "development") {
59
- console.warn(key, "element is undefined in", parent && parent.__ref && parent.__ref.path);
60
- }
61
- element = {};
62
- }
63
- if ((0, import_utils.isString)(key) && key.slice(0, 2 === "__")) {
64
- if (ENV === "test" || ENV === "development") {
65
- console.warn(key, "seems like to be in __ref");
66
- }
67
- }
68
- if (element === null)
69
- return;
70
- if (element === true)
71
- element = { text: true };
72
- if (element.__hash) {
73
- element = { extend: element };
74
- }
75
- if (!parent)
76
- parent = import_tree.ROOT;
77
- if ((0, import_utils.isNode)(parent)) {
78
- parent = import_tree.ROOT[`${key}_parent`] = { key: ":root", node: parent };
79
- }
80
- if (checkIfPrimitive(element)) {
81
- element = applyValueAsText(element, parent, key);
82
- }
83
- const assignedKey = (element.key || key || (0, import_utils.createKey)()).toString();
84
- if ((0, import_component.checkIfKeyIsComponent)(assignedKey)) {
85
- element = (0, import_component.applyKeyComponentAsExtend)(element, parent, assignedKey);
86
- }
87
- if (checkIfMedia(assignedKey)) {
88
- element = applyMediaProps(element, parent, assignedKey);
89
- }
90
- if (element.__ref)
91
- element.__ref.origin = element;
92
- else
93
- element.__ref = { origin: element };
94
- const __ref = element.__ref;
95
- applyContext(element, parent, options);
96
- const { context } = element;
97
- if (context && context.components) {
98
- (0, import_component.applyComponentFromContext)(element, parent, options);
99
- }
100
- (0, import_extend.applyExtend)(element, parent, options);
101
- element.key = assignedKey;
102
- if (options.onlyResolveExtends) {
103
- return resolveExtends(element, parent, options);
104
- }
105
- if (Object.keys(options).length) {
106
- import_mixins.registry.defaultOptions = options;
107
- if (options.ignoreChildExtend)
108
- delete options.ignoreChildExtend;
109
- }
110
- addCaching(element, parent);
111
- (0, import_set.addMethods)(element, parent);
112
- element.state = (0, import_state.createState)(element, parent);
113
- checkIf(element, parent);
114
- if (element.node && __ref.__if) {
115
- return (0, import_render.assignNode)(element, parent, assignedKey);
116
- }
117
- if (__ref.__if)
118
- (0, import_props.createProps)(element, parent);
119
- (0, import_component.applyVariant)(element, parent);
120
- const initReturns = (0, import_event.triggerEventOn)("init", element, options);
121
- if (initReturns === false)
122
- return element;
123
- (0, import_event.triggerEventOn)("beforeClassAssign", element, options);
124
- (0, import_classlist.assignClass)(element);
125
- renderElement(element, parent, options);
126
- if (parent.__ref && parent.__ref.__children)
127
- parent.__ref.__children.push(element.key);
128
- (0, import_event.triggerEventOn)("complete", element, options);
129
- return element;
130
- };
131
- const renderElement = (element, parent, options) => {
132
- const { __ref: ref, key } = element;
133
- (0, import_node2.default)(element, options);
134
- if (!ref.__if)
135
- return element;
136
- (0, import_render.assignNode)(element, parent, key);
137
- (0, import_event.triggerEventOn)("renderRouter", element, options);
138
- (0, import_event.triggerEventOn)("render", element, options);
139
- };
140
- const checkIfPrimitive = (element) => {
141
- return (0, import_utils.is)(element)("string", "number");
142
- };
143
- const applyValueAsText = (element, parent, key) => {
144
- const extendTag = element.extend && element.extend.tag;
145
- const childExtendTag = parent.childExtend && parent.childExtend.tag;
146
- const isKeyValidHTMLTag = import_registry.TAGS.body.indexOf(key) > -1 && key;
147
- return {
148
- text: element,
149
- tag: extendTag || childExtendTag || isKeyValidHTMLTag || "string"
150
- };
151
- };
152
- const applyContext = (element, parent, options) => {
153
- if (options.context && !import_tree.ROOT.context && !element.context)
154
- import_tree.ROOT.context = options.context;
155
- if (!element.context)
156
- element.context = parent.context || options.context || import_tree.ROOT.context;
157
- };
158
- const checkIf = (element, parent) => {
159
- const { __ref: ref } = element;
160
- if ((0, import_utils.isFunction)(element.if)) {
161
- const ifPassed = element.if(element, element.state);
162
- if (!ifPassed) {
163
- const ifFragment = (0, import_node.cacheNode)({ tag: "fragment" });
164
- ref.__ifFragment = (0, import_render.appendNode)(ifFragment, parent.node);
165
- delete ref.__if;
166
- } else
167
- ref.__if = true;
168
- } else
169
- ref.__if = true;
170
- };
171
- const addCaching = (element, parent) => {
172
- const { __ref: ref } = element;
173
- let { __ref: parentRef } = parent;
174
- if (!element.transform)
175
- element.transform = {};
176
- if (!ref.__cached)
177
- ref.__cached = {};
178
- if (!ref.__defineCache)
179
- ref.__defineCache = {};
180
- if (!ref.__exec)
181
- ref.__exec = {};
182
- if (!ref.__class)
183
- ref.__class = {};
184
- if (!ref.__classNames)
185
- ref.__classNames = {};
186
- if (!ref.__attr)
187
- ref.__attr = {};
188
- if (!ref.__changes)
189
- ref.__changes = [];
190
- if (!ref.__children)
191
- ref.__children = [];
192
- const hasRoot = parent && parent.key === ":root";
193
- if (!ref.__root)
194
- ref.__root = hasRoot ? element : parentRef.__root;
195
- if (ENV === "test" || ENV === "development") {
196
- if (!parentRef)
197
- parentRef = parent.ref = {};
198
- if (!parentRef.__path)
199
- parentRef.__path = [];
200
- ref.__path = parentRef.__path.concat(element.key);
201
- }
202
- };
203
- const resolveExtends = (element, parent, options) => {
204
- const { __ref } = element;
205
- element.tag = (0, import_node.detectTag)(element);
206
- if (!__ref.__exec)
207
- __ref.__exec = {};
208
- if (!__ref.__attr)
209
- __ref.__attr = {};
210
- if (!element.props)
211
- element.props = {};
212
- if (!element.state)
213
- element.state = {};
214
- (0, import_state.createState)(element, parent, { skipApplyMethods: true });
215
- (0, import_props.createProps)(element, parent);
216
- (0, import_component.applyVariant)(element, parent);
217
- (0, import_iterate.throughInitialExec)(element, options.propsExcludedFromExec);
218
- for (const param in element) {
219
- const prop = element[param];
220
- if ((0, import_utils.isUndefined)(prop) || (0, import_methods.isMethod)(param) || (0, import_utils.isObject)(import_mixins.registry[param]) || (0, import_component.isVariant)(param))
221
- continue;
222
- const hasDefined = element.define && element.define[param];
223
- const ourParam = import_mixins.registry[param];
224
- const hasOptionsDefine = options.define && options.define[param];
225
- if (ourParam && !hasOptionsDefine)
226
- continue;
227
- else if (element[param] && !hasDefined && !hasOptionsDefine) {
228
- create((0, import_utils.exec)(prop, element), element, param, options);
229
- }
230
- }
231
- delete element.parent;
232
- delete element.update;
233
- delete element.__element;
234
- delete element.props.update;
235
- delete element.props.__element;
236
- delete element.state.__element;
237
- delete element.state.__element;
238
- if (!options.keepRef)
239
- delete element.__ref;
240
- return element;
241
- };
242
- const checkIfMedia = (key) => key.slice(0, 1) === "@";
243
- const applyMediaProps = (element, parent, key) => {
244
- const { props } = element;
245
- if (props) {
246
- props.display = "none";
247
- if (props[key])
248
- props[key].display = props.display;
249
- else
250
- props[key] = { display: props.display || "block" };
251
- return element;
252
- } else {
253
- return {
254
- ...element,
255
- props: {
256
- display: "none",
257
- [key]: { display: "block" }
258
- }
259
- };
260
- }
261
- };
262
- var create_default = create;
@@ -1,87 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var extend_exports = {};
20
- __export(extend_exports, {
21
- applyExtend: () => applyExtend
22
- });
23
- module.exports = __toCommonJS(extend_exports);
24
- var import_utils = require("@domql/utils");
25
- var import_utils2 = require("./utils");
26
- const ENV = "development";
27
- const applyExtend = (element, parent, options = {}) => {
28
- if ((0, import_utils.isFunction)(element))
29
- element = (0, import_utils.exec)(element, parent);
30
- let { extend, props, context, __ref } = element;
31
- const COMPONENTS = context && context.components || options.components;
32
- if ((0, import_utils.isString)(extend)) {
33
- if (COMPONENTS && COMPONENTS[extend])
34
- extend = COMPONENTS[extend];
35
- else {
36
- if (ENV !== "test" || ENV !== "development") {
37
- console.warn("Extend is string but component was not found:", extend);
38
- }
39
- extend = {};
40
- }
41
- }
42
- const extendStack = (0, import_utils2.getExtendStack)(extend);
43
- if (ENV !== "test" || ENV !== "development")
44
- delete element.extend;
45
- let childExtendStack = [];
46
- if (parent) {
47
- element.parent = parent;
48
- if (!options.ignoreChildExtend) {
49
- if (props && props.ignoreChildExtend)
50
- return;
51
- childExtendStack = (0, import_utils2.getExtendStack)(parent.childExtend);
52
- if (parent.childExtendRecursive) {
53
- const canExtendRecursive = !(props == null ? void 0 : props.ignoreChildExtendRecursive) && element.key !== "__text";
54
- if (canExtendRecursive) {
55
- const childExtendRecursiveStack = (0, import_utils2.getExtendStack)(parent.childExtendRecursive);
56
- childExtendStack = childExtendStack.concat(childExtendRecursiveStack);
57
- element.childExtendRecursive = parent.childExtendRecursive;
58
- }
59
- }
60
- }
61
- }
62
- const extendLength = extendStack.length;
63
- const childExtendLength = childExtendStack.length;
64
- let stack = [];
65
- if (extendLength && childExtendLength) {
66
- stack = (0, import_utils2.jointStacks)(extendStack, childExtendStack);
67
- } else if (extendLength) {
68
- stack = extendStack;
69
- } else if (childExtendLength) {
70
- stack = childExtendStack;
71
- } else if (!options.extend)
72
- return element;
73
- if (options.extend) {
74
- const defaultOptionsExtend = (0, import_utils2.getExtendStack)(options.extend);
75
- stack = [].concat(stack, defaultOptionsExtend);
76
- }
77
- if (__ref)
78
- __ref.__extend = stack;
79
- const findAndReplaceStrings = (0, import_utils2.replaceStringsWithComponents)(stack, COMPONENTS);
80
- let mergedExtend = (0, import_utils2.cloneAndMergeArrayExtend)(findAndReplaceStrings);
81
- const component = (0, import_utils.exec)(element.component || mergedExtend.component, element);
82
- if (component && COMPONENTS && COMPONENTS[component]) {
83
- const componentExtend = (0, import_utils2.cloneAndMergeArrayExtend)((0, import_utils2.getExtendStack)(COMPONENTS[component]));
84
- mergedExtend = (0, import_utils2.deepMergeExtend)(componentExtend, mergedExtend);
85
- }
86
- return (0, import_utils2.deepMergeExtend)(element, mergedExtend);
87
- };
@@ -1,108 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var iterate_exports = {};
20
- __export(iterate_exports, {
21
- throughInitialDefine: () => throughInitialDefine,
22
- throughInitialExec: () => throughInitialExec,
23
- throughUpdatedDefine: () => throughUpdatedDefine,
24
- throughUpdatedExec: () => throughUpdatedExec
25
- });
26
- module.exports = __toCommonJS(iterate_exports);
27
- var import_utils = require("@domql/utils");
28
- var import_utils2 = require("./utils");
29
- var import_methods = require("./methods");
30
- const throughInitialExec = (element, exclude = {}) => {
31
- const { __ref: ref } = element;
32
- for (const param in element) {
33
- if (exclude[param])
34
- continue;
35
- const prop = element[param];
36
- if ((0, import_utils.isFunction)(prop) && !(0, import_methods.isMethod)(param) && !(0, import_utils2.isVariant)(param)) {
37
- ref.__exec[param] = prop;
38
- element[param] = prop(element, element.state);
39
- }
40
- }
41
- };
42
- const throughUpdatedExec = (element, options = { excludes: import_utils2.METHODS_EXL }) => {
43
- const { __ref: ref } = element;
44
- const changes = {};
45
- for (const param in ref.__exec) {
46
- const prop = element[param];
47
- const isDefinedParam = ref.__defineCache[param];
48
- if (isDefinedParam)
49
- continue;
50
- const newExec = ref.__exec[param](element, element.state, element.context);
51
- const execReturnsString = (0, import_utils.isString)(newExec) || (0, import_utils.isNumber)(newExec);
52
- if (prop && prop.node && execReturnsString) {
53
- (0, import_utils2.overwrite)(prop, { text: newExec }, options);
54
- } else if (newExec !== prop) {
55
- if ((0, import_utils2.checkIfKeyIsComponent)(param)) {
56
- const { extend, ...newElem } = (0, import_utils2.extendizeByKey)(newExec, element, param);
57
- (0, import_utils2.overwrite)(prop, newElem, options);
58
- } else {
59
- ref.__cached[param] = changes[param] = prop;
60
- element[param] = newExec;
61
- }
62
- }
63
- }
64
- return changes;
65
- };
66
- const throughInitialDefine = (element) => {
67
- const { define, context, __ref: ref } = element;
68
- let defineObj = {};
69
- const hasGlobalDefine = context && (0, import_utils.isObject)(context.define);
70
- if ((0, import_utils.isObject)(define))
71
- defineObj = { ...define };
72
- if (hasGlobalDefine)
73
- defineObj = { ...defineObj, ...context.define };
74
- for (const param in defineObj) {
75
- let elementProp = element[param];
76
- if ((0, import_utils.isFunction)(elementProp) && !(0, import_methods.isMethod)(param) && !(0, import_utils2.isVariant)(param)) {
77
- ref.__exec[param] = elementProp;
78
- const execParam2 = elementProp = (0, import_utils.exec)(elementProp, element);
79
- if (execParam2) {
80
- elementProp = element[param] = execParam2.parse ? execParam2.parse() : execParam2;
81
- ref.__defineCache[param] = elementProp;
82
- }
83
- }
84
- const execParam = defineObj[param](elementProp, element, element.state, element.context);
85
- if (execParam)
86
- element[param] = execParam;
87
- }
88
- return element;
89
- };
90
- const throughUpdatedDefine = (element) => {
91
- const { context, define, __ref: ref } = element;
92
- const changes = {};
93
- let obj = {};
94
- if ((0, import_utils.isObject)(define))
95
- obj = { ...define };
96
- if ((0, import_utils.isObject)(context && context.define))
97
- obj = { ...obj, ...context.define };
98
- for (const param in obj) {
99
- const execParam = ref.__exec[param];
100
- if (execParam)
101
- ref.__defineCache[param] = execParam(element, element.state, element.context);
102
- const cached = (0, import_utils.exec)(ref.__defineCache[param], element);
103
- const newExecParam = obj[param](cached, element, element.state, element.context);
104
- if (newExecParam)
105
- element[param] = newExecParam;
106
- }
107
- return changes;
108
- };
package/dist/cjs/node.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var node_exports = {};
30
- __export(node_exports, {
31
- createNode: () => createNode,
32
- default: () => node_default
33
- });
34
- module.exports = __toCommonJS(node_exports);
35
- var import_utils = require("@domql/utils");
36
- var import_event = require("@domql/event");
37
- var import_methods = require("./methods");
38
- var import_node = require("@domql/node");
39
- var import_create = __toESM(require("./create"), 1);
40
- var import_iterate = require("./iterate");
41
- var import_mixins = require("./mixins");
42
- var import_applyParam = require("./applyParam");
43
- var import_utils2 = require("./utils");
44
- const ENV = "development";
45
- const createNode = (element, options) => {
46
- let { node, tag, __ref: ref } = element;
47
- let isNewNode;
48
- if (!node) {
49
- isNewNode = true;
50
- if (!ref.__if)
51
- return element;
52
- if (tag === "shadow") {
53
- node = element.node = element.parent.node.attachShadow({ mode: "open" });
54
- } else
55
- node = element.node = (0, import_node.cacheNode)(element);
56
- (0, import_event.triggerEventOn)("attachNode", element, options);
57
- }
58
- if (ENV === "test" || ENV === "development" || options.alowRefReference) {
59
- node.ref = element;
60
- if ((0, import_utils.isFunction)(node.setAttribute))
61
- node.setAttribute("key", element.key);
62
- }
63
- if (!ref.__if)
64
- return element;
65
- if (element.tag !== "string" || element.tag !== "fragment") {
66
- (0, import_iterate.throughInitialDefine)(element);
67
- (0, import_iterate.throughInitialExec)(element);
68
- if (isNewNode && (0, import_utils.isObject)(element.on))
69
- (0, import_event.applyEventsOnNode)(element);
70
- for (const param in element) {
71
- const prop = element[param];
72
- if ((0, import_utils.isUndefined)(prop) || (0, import_methods.isMethod)(param) || (0, import_utils2.isVariant)(param) || (0, import_utils.isObject)(import_mixins.registry[param]))
73
- continue;
74
- const isElement = (0, import_applyParam.applyParam)(param, element, options);
75
- if (isElement) {
76
- const { hasDefine, hasContextDefine } = isElement;
77
- if (element[param] && !hasDefine && !hasContextDefine) {
78
- (0, import_create.default)((0, import_utils.exec)(prop, element), element, param, options);
79
- }
80
- }
81
- }
82
- }
83
- return element;
84
- };
85
- var node_default = createNode;