@domql/element 2.31.25 → 2.31.27

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/create.js CHANGED
@@ -26,7 +26,7 @@ import { applyAnimationFrame, triggerEventOn } from '@domql/event'
26
26
  import { assignNode } from '@domql/render'
27
27
  import { createState } from '@domql/state'
28
28
 
29
- import { isMethod } from './methods/index.js'
29
+ import { error, isMethod } from './methods/index.js'
30
30
  import { createProps } from './props/index.js'
31
31
  import { applyExtend } from './extend.js'
32
32
  import { REGISTRY, registry } from './mixins/index.js'
@@ -52,6 +52,16 @@ export const create = async (
52
52
  options = OPTIONS.create || {},
53
53
  attachOptions
54
54
  ) => {
55
+ const isValid = validateElement(element, options)
56
+ if (!isValid) {
57
+ error.call(
58
+ element,
59
+ 'Error while creating element: Not valid type',
60
+ element,
61
+ options
62
+ )
63
+ return
64
+ }
55
65
  cacheOptions(element, options)
56
66
 
57
67
  // if element is STRING
@@ -85,13 +95,13 @@ export const create = async (
85
95
 
86
96
  switchDefaultOptions(element, parent, options)
87
97
 
88
- addCaching(element, parent)
98
+ addCaching(element, parent, options)
89
99
 
90
100
  addMethods(element, parent, options)
91
101
 
92
- createScope(element, parent)
102
+ createScope(element, parent, options)
93
103
 
94
- await createState(element, parent)
104
+ await createState(element, parent, options)
95
105
  if (element.scope === 'state') element.scope = element.state
96
106
 
97
107
  createIfConditionFlag(element, parent)
@@ -156,6 +166,14 @@ const createBasedOnType = (element, parent, key, options) => {
156
166
  return { extend: element }
157
167
  }
158
168
 
169
+ // Check if element was passed as node, reassign it to element.node
170
+ if (
171
+ (typeof Node !== 'undefined' && element instanceof Node) ||
172
+ (typeof DocumentFragment !== 'undefined' &&
173
+ element instanceof DocumentFragment)
174
+ )
175
+ return { node: element }
176
+
159
177
  return element
160
178
  }
161
179
 
@@ -193,6 +211,87 @@ const redefineParent = (element, parent, key, options) => {
193
211
  return parent
194
212
  }
195
213
 
214
+ const validateElement = (value, options) => {
215
+ if (value == null) return false // null or undefined are not valid elements
216
+
217
+ // --- 1. Invalid primitive types
218
+ const t = typeof value
219
+ if (t === 'function' || t === 'symbol' || t === 'bigint') return false
220
+ if (Number.isNaN(value) || value === Infinity || value === -Infinity)
221
+ return false
222
+
223
+ // --- 2. Global / host objects
224
+ const unsafeGlobals = [
225
+ typeof window !== 'undefined' && window,
226
+ typeof document !== 'undefined' && document,
227
+ typeof globalThis !== 'undefined' && globalThis,
228
+ typeof navigator !== 'undefined' && navigator,
229
+ typeof location !== 'undefined' && location,
230
+ typeof history !== 'undefined' && history,
231
+ typeof screen !== 'undefined' && screen,
232
+ typeof frames !== 'undefined' && frames,
233
+ typeof parent !== 'undefined' && parent,
234
+ typeof self !== 'undefined' && self,
235
+ typeof top !== 'undefined' && top,
236
+ typeof performance !== 'undefined' && performance,
237
+ typeof console !== 'undefined' && console,
238
+ typeof indexedDB !== 'undefined' && indexedDB,
239
+ typeof caches !== 'undefined' && caches,
240
+ typeof localStorage !== 'undefined' && localStorage,
241
+ typeof sessionStorage !== 'undefined' && sessionStorage,
242
+ typeof crypto !== 'undefined' && crypto,
243
+ typeof visualViewport !== 'undefined' && visualViewport,
244
+ typeof customElements !== 'undefined' && customElements
245
+ ].filter(Boolean)
246
+
247
+ if (unsafeGlobals.includes(value)) return false
248
+
249
+ // --- 3. DOM node instances
250
+ // allow nodes in order to assign it in element.node
251
+ // if (typeof Node !== 'undefined' && value instanceof Node) return false
252
+ // if (typeof DocumentFragment !== 'undefined' && value instanceof DocumentFragment) return false
253
+ if (typeof EventTarget !== 'undefined' && value instanceof EventTarget)
254
+ return false
255
+ if (typeof Event !== 'undefined' && value instanceof Event) return false
256
+
257
+ // --- 4. Prototype / built-in objects
258
+ if (
259
+ value === Object.prototype ||
260
+ value === Array.prototype ||
261
+ value === Function.prototype ||
262
+ value === Map.prototype ||
263
+ value === Set.prototype ||
264
+ value === WeakMap.prototype ||
265
+ value === WeakSet.prototype ||
266
+ value === Promise.prototype ||
267
+ value === Symbol.prototype
268
+ )
269
+ return false
270
+
271
+ // --- 5. Platform API instances
272
+ const unsafeConstructors = [
273
+ typeof Worker !== 'undefined' && Worker,
274
+ typeof SharedWorker !== 'undefined' && SharedWorker,
275
+ typeof MessagePort !== 'undefined' && MessagePort,
276
+ typeof BroadcastChannel !== 'undefined' && BroadcastChannel,
277
+ typeof ReadableStream !== 'undefined' && ReadableStream,
278
+ typeof WritableStream !== 'undefined' && WritableStream,
279
+ typeof TransformStream !== 'undefined' && TransformStream,
280
+ typeof File !== 'undefined' && File,
281
+ typeof Blob !== 'undefined' && Blob,
282
+ typeof FormData !== 'undefined' && FormData,
283
+ typeof XMLHttpRequest !== 'undefined' && XMLHttpRequest,
284
+ typeof AbortController !== 'undefined' && AbortController,
285
+ typeof AbortSignal !== 'undefined' && AbortSignal
286
+ ].filter(Boolean)
287
+
288
+ for (const Ctor of unsafeConstructors) {
289
+ if (value instanceof Ctor) return false
290
+ }
291
+
292
+ return true
293
+ }
294
+
196
295
  const cacheOptions = (element, options) => {
197
296
  if (options && !OPTIONS.create) {
198
297
  OPTIONS.create = options
@@ -252,7 +351,7 @@ const renderElement = async (element, parent, options, attachOptions) => {
252
351
  path.splice(0, path.indexOf('ComponentsGrid') + 2)
253
352
  if (path.includes('demoComponent'))
254
353
  path.splice(0, path.indexOf('demoComponent') + 1)
255
- const isDemoComponent = element.lookup(el => el.state.key)?.state?.key
354
+ const isDemoComponent = element.lookup((el) => el.state.key)?.state?.key
256
355
  element.warn(
257
356
  'Error happened in:',
258
357
  isDemoComponent ? isDemoComponent + ' ' : '' + path.join('.')
@@ -297,7 +396,7 @@ const renderElement = async (element, parent, options, attachOptions) => {
297
396
  await triggerEventOn('create', element, options)
298
397
  }
299
398
 
300
- const checkIfPrimitive = element => is(element)('string', 'number')
399
+ const checkIfPrimitive = (element) => is(element)('string', 'number')
301
400
 
302
401
  const applyValueAsText = (element, parent, key) => {
303
402
  const extendTag = element.extend && element.extend.tag
@@ -395,7 +494,7 @@ const onlyResolveExtends = async (element, parent, key, options) => {
395
494
 
396
495
  createScope(element, parent)
397
496
 
398
- createState(element, parent)
497
+ createState(element, parent, options)
399
498
  if (element.scope === 'state') element.scope = element.state
400
499
 
401
500
  createIfConditionFlag(element, parent)
@@ -460,7 +559,7 @@ const onlyResolveExtends = async (element, parent, key, options) => {
460
559
  return element
461
560
  }
462
561
 
463
- const checkIfMedia = key => key.slice(0, 1) === '@'
562
+ const checkIfMedia = (key) => key.slice(0, 1) === '@'
464
563
 
465
564
  const applyMediaProps = (element, parent, key) => {
466
565
  const { props } = element
@@ -38,58 +38,68 @@ var import_iterate = require("./iterate.js");
38
38
  var import_options = require("./cache/options.js");
39
39
  var import_component = require("./utils/component.js");
40
40
  var import_env = require("@domql/utils/env.js");
41
- const create = async (element, parent, key, options = import_options.OPTIONS.create || {}, attachOptions) => {
41
+ const create = async (element, parent2, key, options = import_options.OPTIONS.create || {}, attachOptions) => {
42
+ const isValid = validateElement(element, options);
43
+ if (!isValid) {
44
+ import_methods.error.call(
45
+ element,
46
+ "Error while creating element: Not valid type",
47
+ element,
48
+ options
49
+ );
50
+ return;
51
+ }
42
52
  cacheOptions(element, options);
43
53
  if (checkIfPrimitive(element)) {
44
- element = applyValueAsText(element, parent, key);
54
+ element = applyValueAsText(element, parent2, key);
45
55
  }
46
- element = redefineElement(element, parent, key, options);
47
- parent = redefineParent(element, parent, key);
48
- key = createKey(element, parent, key);
49
- const ref = addRef(element, parent, key);
56
+ element = redefineElement(element, parent2, key, options);
57
+ parent2 = redefineParent(element, parent2, key);
58
+ key = createKey(element, parent2, key);
59
+ const ref = addRef(element, parent2, key);
50
60
  ref.__initialProps = (0, import_utils.deepClone)(element.props);
51
- applyContext(element, parent, options);
52
- (0, import_utils.applyComponentFromContext)(element, parent, options);
61
+ applyContext(element, parent2, options);
62
+ (0, import_utils.applyComponentFromContext)(element, parent2, options);
53
63
  if (!ref.__skipCreate) {
54
- (0, import_extend.applyExtend)(element, parent, options);
64
+ (0, import_extend.applyExtend)(element, parent2, options);
55
65
  }
56
66
  element.key = key;
57
67
  if (options.onlyResolveExtends) {
58
- return await onlyResolveExtends(element, parent, key, options);
68
+ return await onlyResolveExtends(element, parent2, key, options);
59
69
  }
60
70
  await (0, import_event.triggerEventOn)("start", element, options);
61
- switchDefaultOptions(element, parent, options);
62
- addCaching(element, parent);
63
- (0, import_set.addMethods)(element, parent, options);
64
- createScope(element, parent);
65
- await (0, import_state.createState)(element, parent);
71
+ switchDefaultOptions(element, parent2, options);
72
+ addCaching(element, parent2, options);
73
+ (0, import_set.addMethods)(element, parent2, options);
74
+ createScope(element, parent2, options);
75
+ await (0, import_state.createState)(element, parent2, options);
66
76
  if (element.scope === "state") element.scope = element.state;
67
- createIfConditionFlag(element, parent);
68
- (0, import_props.createProps)(element, parent, options);
77
+ createIfConditionFlag(element, parent2);
78
+ (0, import_props.createProps)(element, parent2, options);
69
79
  if (element.scope === "props" || element.scope === true)
70
80
  element.scope = element.props;
71
- createIfConditionFlag(element, parent);
81
+ createIfConditionFlag(element, parent2);
72
82
  if (element.node && ref.__if) {
73
- return (0, import_render.assignNode)(element, parent, key, attachOptions);
83
+ return (0, import_render.assignNode)(element, parent2, key, attachOptions);
74
84
  }
75
- (0, import_component.applyVariant)(element, parent);
76
- (0, import_utils.addChildrenIfNotInOriginal)(element, parent, key);
85
+ (0, import_component.applyVariant)(element, parent2);
86
+ (0, import_utils.addChildrenIfNotInOriginal)(element, parent2, key);
77
87
  const onInit = await (0, import_event.triggerEventOn)("init", element, options);
78
88
  if (onInit === false) return element;
79
89
  await (0, import_event.triggerEventOn)("beforeClassAssign", element, options);
80
90
  (0, import_classList.assignKeyAsClassname)(element);
81
- await renderElement(element, parent, options, attachOptions);
82
- addElementIntoParentChildren(element, parent);
91
+ await renderElement(element, parent2, options, attachOptions);
92
+ addElementIntoParentChildren(element, parent2);
83
93
  await (0, import_event.triggerEventOn)("complete", element, options);
84
94
  return element;
85
95
  };
86
- const createBasedOnType = (element, parent, key, options) => {
96
+ const createBasedOnType = (element, parent2, key, options) => {
87
97
  if (element === void 0) {
88
98
  if ((0, import_env.isNotProduction)()) {
89
99
  console.warn(
90
100
  key,
91
101
  "element is undefined in",
92
- parent && parent.__ref && parent.__ref.path
102
+ parent2 && parent2.__ref && parent2.__ref.path
93
103
  );
94
104
  }
95
105
  return {};
@@ -104,30 +114,86 @@ const createBasedOnType = (element, parent, key, options) => {
104
114
  if (element.__hash) {
105
115
  return { extend: element };
106
116
  }
117
+ if (typeof Node !== "undefined" && element instanceof Node || typeof DocumentFragment !== "undefined" && element instanceof DocumentFragment)
118
+ return { node: element };
107
119
  return element;
108
120
  };
109
- const redefineElement = (element, parent, key, options) => {
110
- const elementWrapper = createBasedOnType(element, parent, key, options);
111
- if (options.syntaxv3 || element.props && element.props.syntaxv3 || parent && parent.props && parent.props.syntaxv3) {
121
+ const redefineElement = (element, parent2, key, options) => {
122
+ const elementWrapper = createBasedOnType(element, parent2, key, options);
123
+ if (options.syntaxv3 || element.props && element.props.syntaxv3 || parent2 && parent2.props && parent2.props.syntaxv3) {
112
124
  if (element.props) element.props.syntaxv3 = true;
113
125
  else element.syntaxv3 = true;
114
- return (0, import_component.createValidDomqlObjectFromSugar)(element, parent, key, options);
126
+ return (0, import_component.createValidDomqlObjectFromSugar)(element, parent2, key, options);
115
127
  } else if ((0, import_utils.checkIfKeyIsComponent)(key)) {
116
- return (0, import_utils.applyKeyComponentAsExtend)(elementWrapper, parent, key);
128
+ return (0, import_utils.applyKeyComponentAsExtend)(elementWrapper, parent2, key);
117
129
  }
118
130
  if (checkIfMedia(key)) {
119
- return applyMediaProps(elementWrapper, parent, key);
131
+ return applyMediaProps(elementWrapper, parent2, key);
120
132
  }
121
133
  return elementWrapper;
122
134
  };
123
- const redefineParent = (element, parent, key, options) => {
124
- if (!parent) return import_tree.ROOT;
125
- if ((0, import_utils.isNode)(parent)) {
126
- const parentNodeWrapper = { key: ":root", node: parent };
135
+ const redefineParent = (element, parent2, key, options) => {
136
+ if (!parent2) return import_tree.ROOT;
137
+ if ((0, import_utils.isNode)(parent2)) {
138
+ const parentNodeWrapper = { key: ":root", node: parent2 };
127
139
  import_tree.ROOT[`${key}_parent`] = parentNodeWrapper;
128
140
  return parentNodeWrapper;
129
141
  }
130
- return parent;
142
+ return parent2;
143
+ };
144
+ const validateElement = (value, options) => {
145
+ if (value == null) return false;
146
+ const t = typeof value;
147
+ if (t === "function" || t === "symbol" || t === "bigint") return false;
148
+ if (Number.isNaN(value) || value === Infinity || value === -Infinity)
149
+ return false;
150
+ const unsafeGlobals = [
151
+ typeof window !== "undefined" && window,
152
+ typeof document !== "undefined" && document,
153
+ typeof globalThis !== "undefined" && globalThis,
154
+ typeof navigator !== "undefined" && navigator,
155
+ typeof location !== "undefined" && location,
156
+ typeof history !== "undefined" && history,
157
+ typeof screen !== "undefined" && screen,
158
+ typeof frames !== "undefined" && frames,
159
+ typeof parent !== "undefined" && parent,
160
+ typeof self !== "undefined" && self,
161
+ typeof top !== "undefined" && top,
162
+ typeof performance !== "undefined" && performance,
163
+ typeof console !== "undefined" && console,
164
+ typeof indexedDB !== "undefined" && indexedDB,
165
+ typeof caches !== "undefined" && caches,
166
+ typeof localStorage !== "undefined" && localStorage,
167
+ typeof sessionStorage !== "undefined" && sessionStorage,
168
+ typeof crypto !== "undefined" && crypto,
169
+ typeof visualViewport !== "undefined" && visualViewport,
170
+ typeof customElements !== "undefined" && customElements
171
+ ].filter(Boolean);
172
+ if (unsafeGlobals.includes(value)) return false;
173
+ if (typeof EventTarget !== "undefined" && value instanceof EventTarget)
174
+ return false;
175
+ if (typeof Event !== "undefined" && value instanceof Event) return false;
176
+ if (value === Object.prototype || value === Array.prototype || value === Function.prototype || value === Map.prototype || value === Set.prototype || value === WeakMap.prototype || value === WeakSet.prototype || value === Promise.prototype || value === Symbol.prototype)
177
+ return false;
178
+ const unsafeConstructors = [
179
+ typeof Worker !== "undefined" && Worker,
180
+ typeof SharedWorker !== "undefined" && SharedWorker,
181
+ typeof MessagePort !== "undefined" && MessagePort,
182
+ typeof BroadcastChannel !== "undefined" && BroadcastChannel,
183
+ typeof ReadableStream !== "undefined" && ReadableStream,
184
+ typeof WritableStream !== "undefined" && WritableStream,
185
+ typeof TransformStream !== "undefined" && TransformStream,
186
+ typeof File !== "undefined" && File,
187
+ typeof Blob !== "undefined" && Blob,
188
+ typeof FormData !== "undefined" && FormData,
189
+ typeof XMLHttpRequest !== "undefined" && XMLHttpRequest,
190
+ typeof AbortController !== "undefined" && AbortController,
191
+ typeof AbortSignal !== "undefined" && AbortSignal
192
+ ].filter(Boolean);
193
+ for (const Ctor of unsafeConstructors) {
194
+ if (value instanceof Ctor) return false;
195
+ }
196
+ return true;
131
197
  };
132
198
  const cacheOptions = (element, options) => {
133
199
  if (options && !import_options.OPTIONS.create) {
@@ -135,26 +201,26 @@ const cacheOptions = (element, options) => {
135
201
  import_options.OPTIONS.create.context = element.context || options.context;
136
202
  }
137
203
  };
138
- const createKey = (element, parent, key) => {
204
+ const createKey = (element, parent2, key) => {
139
205
  return ((0, import_utils.exec)(key, element) || key || element.key || (0, import_utils.generateKey)()).toString();
140
206
  };
141
- const addRef = (element, parent) => {
207
+ const addRef = (element, parent2) => {
142
208
  if (element.__ref) element.__ref.origin = element;
143
209
  else element.__ref = { origin: element };
144
210
  return element.__ref;
145
211
  };
146
- const switchDefaultOptions = (element, parent, options) => {
212
+ const switchDefaultOptions = (element, parent2, options) => {
147
213
  if (Object.keys(options).length) {
148
214
  import_mixins.registry.defaultOptions = options;
149
215
  if (options.ignoreChildExtend) delete options.ignoreChildExtend;
150
216
  }
151
217
  };
152
- const addElementIntoParentChildren = (element, parent) => {
153
- if (parent.__ref && parent.__ref.__children)
154
- parent.__ref.__children.push(element.key);
218
+ const addElementIntoParentChildren = (element, parent2) => {
219
+ if (parent2.__ref && parent2.__ref.__children)
220
+ parent2.__ref.__children.push(element.key);
155
221
  };
156
222
  const visitedElements = /* @__PURE__ */ new WeakMap();
157
- const renderElement = async (element, parent, options, attachOptions) => {
223
+ const renderElement = async (element, parent2, options, attachOptions) => {
158
224
  var _a, _b, _c, _d;
159
225
  if (visitedElements.has(element)) {
160
226
  if ((0, import_env.isNotProduction)())
@@ -199,10 +265,10 @@ const renderElement = async (element, parent, options, attachOptions) => {
199
265
  }
200
266
  }
201
267
  if (!ref.__if) {
202
- parent[key || element.key] = element;
268
+ parent2[key || element.key] = element;
203
269
  return element;
204
270
  }
205
- (0, import_render.assignNode)(element, parent, key, attachOptions);
271
+ (0, import_render.assignNode)(element, parent2, key, attachOptions);
206
272
  (0, import_event.applyAnimationFrame)(element, options);
207
273
  await (0, import_event.triggerEventOn)("render", element, options);
208
274
  await (0, import_event.triggerEventOn)("renderRouter", element, options);
@@ -210,35 +276,35 @@ const renderElement = async (element, parent, options, attachOptions) => {
210
276
  await (0, import_event.triggerEventOn)("create", element, options);
211
277
  };
212
278
  const checkIfPrimitive = (element) => (0, import_utils.is)(element)("string", "number");
213
- const applyValueAsText = (element, parent, key) => {
279
+ const applyValueAsText = (element, parent2, key) => {
214
280
  const extendTag = element.extend && element.extend.tag;
215
- const childExtendTag = parent.childExtend && parent.childExtend.tag;
216
- const childPropsTag = parent.props.childProps && parent.props.childProps.tag;
281
+ const childExtendTag = parent2.childExtend && parent2.childExtend.tag;
282
+ const childPropsTag = parent2.props.childProps && parent2.props.childProps.tag;
217
283
  const isKeyValidHTMLTag = import_utils.HTML_TAGS.body.indexOf(key) > -1 && key;
218
284
  return {
219
285
  text: element,
220
286
  tag: extendTag || childExtendTag || childPropsTag || isKeyValidHTMLTag || "string"
221
287
  };
222
288
  };
223
- const applyContext = (element, parent, options) => {
289
+ const applyContext = (element, parent2, options) => {
224
290
  const forcedOptionsContext = options.context && !import_tree.ROOT.context && !element.context;
225
291
  if (forcedOptionsContext) import_tree.ROOT.context = options.context;
226
292
  if (!element.context)
227
- element.context = parent.context || options.context || import_tree.ROOT.context;
293
+ element.context = parent2.context || options.context || import_tree.ROOT.context;
228
294
  };
229
- const createScope = (element, parent) => {
295
+ const createScope = (element, parent2) => {
230
296
  const { __ref: ref } = element;
231
- if (!element.scope) element.scope = parent.scope || ref.root.scope || {};
297
+ if (!element.scope) element.scope = parent2.scope || ref.root.scope || {};
232
298
  };
233
- const createIfConditionFlag = (element, parent) => {
299
+ const createIfConditionFlag = (element, parent2) => {
234
300
  const { __ref: ref } = element;
235
301
  if ((0, import_utils.isFunction)(element.if) && !element.if(element, element.state, element.context)) {
236
302
  delete ref.__if;
237
303
  } else ref.__if = true;
238
304
  };
239
- const addCaching = (element, parent) => {
305
+ const addCaching = (element, parent2) => {
240
306
  const { __ref: ref, key } = element;
241
- let { __ref: parentRef } = parent;
307
+ let { __ref: parentRef } = parent2;
242
308
  if (!element.transform) element.transform = {};
243
309
  if (!ref.__cached) ref.__cached = {};
244
310
  if (!ref.__defineCache) ref.__defineCache = {};
@@ -251,30 +317,30 @@ const addCaching = (element, parent) => {
251
317
  if (!ref.__children) ref.__children = [];
252
318
  if ((0, import_utils.checkIfKeyIsComponent)(key))
253
319
  ref.__componentKey = key.split("_")[0].split(".")[0].split("+")[0];
254
- const hasRoot = parent && parent.key === ":root";
320
+ const hasRoot = parent2 && parent2.key === ":root";
255
321
  if (!ref.root) ref.root = hasRoot ? element : parentRef.root;
256
- if (!parentRef) parentRef = parent.ref = {};
322
+ if (!parentRef) parentRef = parent2.ref = {};
257
323
  if (!parentRef.path) parentRef.path = [];
258
324
  ref.path = parentRef.path.concat(element.key);
259
325
  };
260
- const onlyResolveExtends = async (element, parent, key, options) => {
326
+ const onlyResolveExtends = async (element, parent2, key, options) => {
261
327
  const { __ref: ref } = element;
262
328
  if (!ref.__skipCreate) {
263
- addCaching(element, parent);
264
- (0, import_set.addMethods)(element, parent, options);
265
- createScope(element, parent);
266
- (0, import_state.createState)(element, parent);
329
+ addCaching(element, parent2);
330
+ (0, import_set.addMethods)(element, parent2, options);
331
+ createScope(element, parent2);
332
+ (0, import_state.createState)(element, parent2, options);
267
333
  if (element.scope === "state") element.scope = element.state;
268
- createIfConditionFlag(element, parent);
269
- (0, import_props.createProps)(element, parent, options);
334
+ createIfConditionFlag(element, parent2);
335
+ (0, import_props.createProps)(element, parent2, options);
270
336
  if (element.scope === "props" || element.scope === true)
271
337
  element.scope = element.props;
272
338
  if (element.node && ref.__if) {
273
- parent[key || element.key] = element;
339
+ parent2[key || element.key] = element;
274
340
  }
275
341
  if (!element.props) element.props = {};
276
- (0, import_component.applyVariant)(element, parent);
277
- addElementIntoParentChildren(element, parent);
342
+ (0, import_component.applyVariant)(element, parent2);
343
+ addElementIntoParentChildren(element, parent2);
278
344
  }
279
345
  if (element.tag !== "string" && element.tag !== "fragment") {
280
346
  await (0, import_iterate.throughInitialDefine)(element);
@@ -292,7 +358,7 @@ const onlyResolveExtends = async (element, parent, key, options) => {
292
358
  }
293
359
  }
294
360
  }
295
- parent[key || element.key] = element;
361
+ parent2[key || element.key] = element;
296
362
  delete element.update;
297
363
  delete element.__element;
298
364
  if (element.props) {
@@ -302,7 +368,7 @@ const onlyResolveExtends = async (element, parent, key, options) => {
302
368
  return element;
303
369
  };
304
370
  const checkIfMedia = (key) => key.slice(0, 1) === "@";
305
- const applyMediaProps = (element, parent, key) => {
371
+ const applyMediaProps = (element, parent2, key) => {
306
372
  const { props } = element;
307
373
  if (props) {
308
374
  props.display = "none";
@@ -71,6 +71,8 @@ const throughExecProps = (element) => {
71
71
  const { props } = element;
72
72
  for (const k in props) {
73
73
  const isDefine = k.startsWith("is") || k.startsWith("has") || k.startsWith("use");
74
+ if (!ref.__execProps)
75
+ return import_methods.warn.call(element, "Element was not initiated to execute props");
74
76
  const cachedExecProp = ref.__execProps[k];
75
77
  if ((0, import_utils.isFunction)(cachedExecProp)) {
76
78
  props[k] = (0, import_utils.exec)(cachedExecProp, element);
@@ -99,6 +99,12 @@ function lookdown(param) {
99
99
  );
100
100
  if (v === param) return childElem;
101
101
  else if ((0, import_utils.isFunction)(param)) {
102
+ if (!childElem) {
103
+ this.error(
104
+ `"${v}" found in element __children, but content is not defined`
105
+ );
106
+ continue;
107
+ }
102
108
  const exec = param(childElem, childElem.state, childElem.context);
103
109
  if (childElem.state && exec) {
104
110
  return childElem;
@@ -119,6 +125,12 @@ function lookdownAll(param, results = []) {
119
125
  const childElem = el[v];
120
126
  if (v === param) results.push(childElem);
121
127
  else if ((0, import_utils.isFunction)(param)) {
128
+ if (!childElem) {
129
+ this.error(
130
+ `"${v}" found in element __children, but content is not defined`
131
+ );
132
+ continue;
133
+ }
122
134
  const exec = param(childElem, childElem.state, childElem.context);
123
135
  if (childElem.state && exec) results.push(childElem);
124
136
  }
@@ -138,7 +150,7 @@ function setNodeStyles(params = {}) {
138
150
  }
139
151
  return el;
140
152
  }
141
- async function remove(opts) {
153
+ async function remove(opts = {}) {
142
154
  const element = this;
143
155
  const beforeRemoveReturns = (0, import_event.triggerEventOn)("beforeRemove", element, opts);
144
156
  if (beforeRemoveReturns === false) return element;
@@ -159,10 +171,10 @@ function get(param) {
159
171
  const element = this;
160
172
  return element[param];
161
173
  }
162
- function setProps(param, options) {
174
+ function setProps(param, opts = {}) {
163
175
  const element = this;
164
176
  if (!param || !element.props) return;
165
- element.update({ props: param }, options);
177
+ element.update({ props: param }, opts);
166
178
  return element;
167
179
  }
168
180
  function getRef(key) {
@@ -253,9 +265,11 @@ function warn(...params) {
253
265
  console.warn(...params, this);
254
266
  }
255
267
  function error(...params) {
256
- var _a, _b;
268
+ var _a, _b, _c, _d;
257
269
  if ((_a = params[params.length - 1]) == null ? void 0 : _a.debugger) debugger;
258
270
  if ((_b = params[params.length - 1]) == null ? void 0 : _b.verbose) verbose.call(this, ...params);
271
+ if ((0, import_utils.isFunction)((_c = params[params.length - 1]) == null ? void 0 : _c.onError))
272
+ (_d = params[params.length - 1]) == null ? void 0 : _d.onError.call(this, ...params);
259
273
  console.error(...params, this);
260
274
  }
261
275
  function nextElement() {
@@ -266,8 +280,8 @@ function nextElement() {
266
280
  const nextChild = __children[currentIndex + 1];
267
281
  return parent[nextChild];
268
282
  }
269
- async function append(el, key) {
270
- return await (0, import_create.create)(el, this, key);
283
+ async function append(el, key, opts) {
284
+ return await (0, import_create.create)(el, this, key, opts);
271
285
  }
272
286
  function previousElement(el) {
273
287
  const element = el || this;
@@ -318,8 +332,8 @@ function call(fnKey, ...args) {
318
332
  }
319
333
  return result;
320
334
  } catch (error2) {
321
- console.error(`Error calling '${fnKey}':`, error2);
322
- throw error2;
335
+ console.error(`Error calling '${fnKey}'`);
336
+ throw new Error(error2);
323
337
  }
324
338
  }
325
339
  const METHODS = [
@@ -56,7 +56,7 @@ const removeContent = function(el, opts = {}) {
56
56
  else if (__cached[contentElementKey] && (0, import_utils.isFunction)(__cached[contentElementKey].remove))
57
57
  __cached[contentElementKey].remove();
58
58
  }
59
- ref.__children.splice(ref.__children.indexOf(element[contentElementKey]), 1);
59
+ ref.__children.splice(ref.__children.indexOf(contentElementKey), 1);
60
60
  delete element[contentElementKey];
61
61
  }
62
62
  };
package/dist/cjs/node.js CHANGED
@@ -57,11 +57,15 @@ const createNode = async (element, options) => {
57
57
  (0, import_event.applyEventsOnNode)(element, options);
58
58
  }
59
59
  }
60
- for (const param in element) {
60
+ const keys = Object.keys(element);
61
+ for (const param of keys) {
61
62
  const value = element[param];
62
63
  if (!Object.hasOwnProperty.call(element, param)) continue;
63
64
  if ((0, import_utils.isUndefined)(value) || (0, import_methods.isMethod)(param, element) || (0, import_utils.isVariant)(param) || (0, import_utils.isObject)(import_mixins.REGISTRY[param]))
64
65
  continue;
66
+ if (param === "onClick") {
67
+ debugger;
68
+ }
65
69
  const isElement = await (0, import_applyParam.applyParam)(param, element, options);
66
70
  if (!isElement) continue;
67
71
  const { hasDefine, hasContextDefine } = isElement;