@domql/element 3.2.3 → 3.2.7

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.
Files changed (105) hide show
  1. package/children.js +40 -12
  2. package/create.js +40 -26
  3. package/define.js +1 -1
  4. package/dist/cjs/children.js +39 -11
  5. package/dist/cjs/create.js +41 -11
  6. package/dist/cjs/define.js +1 -1
  7. package/dist/cjs/event/animationFrame.js +96 -0
  8. package/dist/cjs/event/can.js +28 -0
  9. package/dist/cjs/event/index.js +20 -0
  10. package/dist/cjs/event/on.js +84 -0
  11. package/dist/cjs/event/store.js +27 -0
  12. package/dist/cjs/extend.js +6 -6
  13. package/dist/cjs/index.js +9 -6
  14. package/dist/cjs/iterate.js +13 -13
  15. package/dist/cjs/methods/set.js +5 -0
  16. package/dist/cjs/methods/v2.js +1 -1
  17. package/dist/cjs/mixins/attr.js +3 -2
  18. package/dist/cjs/mixins/classList.js +11 -1
  19. package/dist/cjs/mixins/content.js +1 -2
  20. package/dist/cjs/mixins/html.js +1 -2
  21. package/dist/cjs/mixins/state.js +2 -2
  22. package/dist/cjs/mixins/style.js +11 -2
  23. package/dist/cjs/mixins/text.js +5 -1
  24. package/dist/cjs/node.js +8 -5
  25. package/dist/cjs/render/append.js +72 -0
  26. package/dist/cjs/render/cache.js +80 -0
  27. package/dist/cjs/render/create.js +25 -0
  28. package/dist/cjs/render/index.js +20 -0
  29. package/dist/cjs/set.js +12 -14
  30. package/dist/cjs/update.js +80 -40
  31. package/dist/cjs/utils/applyParam.js +3 -3
  32. package/dist/cjs/utils/extendUtils.js +5 -5
  33. package/dist/cjs/utils/index.js +2 -0
  34. package/dist/cjs/utils/propEvents.js +21 -4
  35. package/dist/esm/children.js +39 -11
  36. package/dist/esm/create.js +42 -11
  37. package/dist/esm/define.js +1 -1
  38. package/dist/esm/event/animationFrame.js +76 -0
  39. package/dist/esm/event/can.js +8 -0
  40. package/dist/esm/event/index.js +3 -0
  41. package/dist/esm/event/on.js +64 -0
  42. package/dist/esm/event/store.js +7 -0
  43. package/dist/esm/extend.js +7 -7
  44. package/dist/esm/index.js +8 -6
  45. package/dist/esm/iterate.js +13 -13
  46. package/dist/esm/methods/set.js +10 -0
  47. package/dist/esm/methods/v2.js +1 -1
  48. package/dist/esm/mixins/attr.js +4 -3
  49. package/dist/esm/mixins/classList.js +11 -1
  50. package/dist/esm/mixins/content.js +1 -2
  51. package/dist/esm/mixins/html.js +1 -2
  52. package/dist/esm/mixins/state.js +2 -2
  53. package/dist/esm/mixins/style.js +12 -3
  54. package/dist/esm/mixins/text.js +6 -2
  55. package/dist/esm/node.js +8 -5
  56. package/dist/esm/render/append.js +52 -0
  57. package/dist/esm/render/cache.js +60 -0
  58. package/dist/esm/render/create.js +5 -0
  59. package/dist/esm/render/index.js +3 -0
  60. package/dist/esm/set.js +12 -14
  61. package/dist/esm/update.js +80 -42
  62. package/dist/esm/utils/applyParam.js +3 -3
  63. package/dist/esm/utils/extendUtils.js +5 -5
  64. package/dist/esm/utils/index.js +1 -0
  65. package/dist/esm/utils/propEvents.js +21 -4
  66. package/dist/iife/index.js +4718 -0
  67. package/extend.js +7 -10
  68. package/index.js +9 -6
  69. package/iterate.js +20 -13
  70. package/node.js +10 -8
  71. package/package.json +42 -18
  72. package/set.js +6 -5
  73. package/update.js +90 -52
  74. package/__tests__/checkIfOnUpdate.test.js +0 -103
  75. package/__tests__/children.test.js +0 -209
  76. package/__tests__/define.test.js +0 -75
  77. package/__tests__/inheritStateUpdates.test.js +0 -79
  78. package/__tests__/renderElement.test.js +0 -131
  79. package/__tests__/resetElement.test.js +0 -44
  80. package/__tests__/set.test.js +0 -312
  81. package/__tests__/throughExecProps.test.js +0 -86
  82. package/__tests__/throughInitialDefine.test.js +0 -104
  83. package/__tests__/throughInitialExec.test.js +0 -92
  84. package/__tests__/throughUpdatedDefine.test.js +0 -92
  85. package/__tests__/throughUpdatedExec.test.js +0 -111
  86. package/__tests__/tree.test.js +0 -15
  87. package/__tests__/update.test.js +0 -256
  88. package/dist/cjs/package.json +0 -4
  89. package/methods/set.js +0 -63
  90. package/methods/v2.js +0 -83
  91. package/mixins/attr.js +0 -32
  92. package/mixins/classList.js +0 -54
  93. package/mixins/content.js +0 -65
  94. package/mixins/data.js +0 -26
  95. package/mixins/html.js +0 -21
  96. package/mixins/index.js +0 -23
  97. package/mixins/registry.js +0 -46
  98. package/mixins/scope.js +0 -23
  99. package/mixins/state.js +0 -19
  100. package/mixins/style.js +0 -16
  101. package/mixins/text.js +0 -26
  102. package/utils/applyParam.js +0 -34
  103. package/utils/extendUtils.js +0 -149
  104. package/utils/index.js +0 -3
  105. package/utils/propEvents.js +0 -19
package/children.js CHANGED
@@ -16,6 +16,29 @@ import {
16
16
  matchesComponentNaming
17
17
  } from '@domql/utils'
18
18
 
19
+ const shallowChildrenEqual = (a, b) => {
20
+ if (a === b) return true
21
+ if (!a || !b) return false
22
+ if (isArray(a) && isArray(b)) {
23
+ if (a.length !== b.length) return false
24
+ for (let i = 0; i < a.length; i++) {
25
+ if (a[i] !== b[i]) return false
26
+ }
27
+ return true
28
+ }
29
+ if (isObject(a) && isObject(b)) {
30
+ const keysA = Object.keys(a)
31
+ const keysB = Object.keys(b)
32
+ if (keysA.length !== keysB.length) return false
33
+ for (let i = 0; i < keysA.length; i++) {
34
+ const key = keysA[i]
35
+ if (a[key] !== b[key]) return false
36
+ }
37
+ return true
38
+ }
39
+ return a === b
40
+ }
41
+
19
42
  /**
20
43
  * Apply data parameters on the DOM nodes
21
44
  * this should only work if `showOnNode: true` is passed
@@ -57,36 +80,41 @@ export function setChildren (param, element, opts) {
57
80
 
58
81
  if (!children || isNot(children)('array', 'object')) return
59
82
 
60
- if (isArray(children) && children.find(v => v?.$$typeof)) {
61
- const filterReact = children.filter(v => !v?.$$typeof)
62
- if (filterReact.length !== children.length) {
63
- const extractedReactComponents = children.filter(v => v?.$$typeof)
64
- element.call('renderReact', extractedReactComponents, element)
83
+ if (isArray(children) && children.some(v => v?.$$typeof)) {
84
+ const filterReact = []
85
+ const reactComponents = []
86
+ for (let i = 0; i < children.length; i++) {
87
+ if (children[i]?.$$typeof) reactComponents.push(children[i])
88
+ else filterReact.push(children[i])
89
+ }
90
+ if (reactComponents.length) {
91
+ element.call('renderReact', reactComponents, element)
65
92
  }
66
93
  children = filterReact
67
94
  }
68
95
 
96
+ let cloned
69
97
  if (ref.__childrenCache) {
70
- const equals =
71
- JSON.stringify(children) === JSON.stringify(ref.__childrenCache) // make smarter diff
72
- if (equals) {
98
+ if (shallowChildrenEqual(children, ref.__childrenCache)) {
73
99
  ref.__noChildrenDifference = true
74
100
  } else {
75
- ref.__childrenCache = deepClone(children)
101
+ cloned = deepClone(children)
102
+ ref.__childrenCache = cloned
76
103
  delete ref.__noChildrenDifference
77
104
  }
78
105
  } else {
79
- ref.__childrenCache = deepClone(children)
106
+ cloned = deepClone(children)
107
+ ref.__childrenCache = cloned
80
108
  }
81
109
 
82
110
  if (isObject(children) || isArray(children)) {
83
- children = deepClone(children)
111
+ children = cloned || deepClone(children)
84
112
  }
85
113
 
86
114
  const content = { tag: 'fragment' }
87
115
 
88
116
  for (const key in children) {
89
- const value = Object.hasOwnProperty.call(children, key) && children[key]
117
+ const value = Object.prototype.hasOwnProperty.call(children, key) && children[key]
90
118
  if (isDefined(value) && value !== null && value !== false) {
91
119
  content[key] = isObjectLike(value)
92
120
  ? childrenAs
package/create.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  isUndefined,
10
10
  detectInfiniteLoop,
11
11
  propertizeElement,
12
+ pickupElementFromProps,
12
13
  createElement,
13
14
  applyExtends,
14
15
  createScope,
@@ -19,14 +20,37 @@ import {
19
20
  createRoot
20
21
  } from '@domql/utils'
21
22
 
22
- import { applyAnimationFrame, triggerEventOn } from '@domql/event'
23
- import { assignNode } from '@domql/render'
23
+ import { applyAnimationFrame, triggerEventOn } from './event/index.js'
24
+ import { assignNode } from './render/index.js'
24
25
  import { createState } from '@domql/state'
25
26
 
26
27
  import { REGISTRY } from './mixins/index.js'
27
28
  import { addMethods } from './methods/set.js'
28
29
  import { assignKeyAsClassname } from './mixins/classList.js'
29
30
  import { throughInitialExec, throughInitialDefine } from './iterate.js'
31
+ import { filterAttributesByTagName } from 'attrs-in-props'
32
+
33
+ const EXCLUDED_ATTRS = new Set(['class', 'style'])
34
+
35
+ const applyPropsAsAttrs = (element) => {
36
+ const { tag, props, context } = element
37
+ if (!tag || !props) return
38
+
39
+ const autoAttrs = filterAttributesByTagName(tag, props, context?.cssPropsRegistry)
40
+ const filtered = {}
41
+ for (const key in autoAttrs) {
42
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key]
43
+ }
44
+ let hasFiltered = false
45
+ for (const _k in filtered) { hasFiltered = true; break } // eslint-disable-line
46
+ if (!hasFiltered) return
47
+
48
+ if (!element.attr) {
49
+ element.attr = filtered
50
+ } else if (typeof element.attr === 'object') {
51
+ element.attr = { ...filtered, ...element.attr }
52
+ }
53
+ }
30
54
 
31
55
  const ENV = process.env.NODE_ENV
32
56
 
@@ -72,6 +96,10 @@ export const create = (
72
96
 
73
97
  // apply props settings
74
98
  initProps(element, parent, options)
99
+ // Re-pickup component-named properties that entered props via childProps/inheritParentProps
100
+ pickupElementFromProps.call(element, element, { cachedKeys: [] })
101
+ // Populate element.attr from props matching the tag's HTML spec
102
+ applyPropsAsAttrs(element)
75
103
  if (element.scope === 'props' || element.scope === true) {
76
104
  element.scope = element.props
77
105
  }
@@ -112,7 +140,9 @@ const cacheOptions = options => {
112
140
  }
113
141
 
114
142
  const resetOptions = (element, parent, options) => {
115
- if (Object.keys(options).length) {
143
+ let hasKeys = false
144
+ for (const _k in options) { hasKeys = true; break } // eslint-disable-line
145
+ if (hasKeys) {
116
146
  OPTIONS.defaultOptions = options
117
147
  if (options.ignoreChildExtends) delete options.ignoreChildExtends
118
148
  }
@@ -124,6 +154,7 @@ const addElementIntoParentChildren = (element, parent) => {
124
154
  }
125
155
  }
126
156
 
157
+ let _uniqIdCounter = 1
127
158
  const visitedElements = new WeakMap()
128
159
  const renderElement = (element, parent, options, attachOptions) => {
129
160
  if (visitedElements.has(element)) {
@@ -140,7 +171,7 @@ const renderElement = (element, parent, options, attachOptions) => {
140
171
  const isInfiniteLoopDetected = detectInfiniteLoop(ref.path)
141
172
  if (ref.__uniqId || isInfiniteLoopDetected) return
142
173
  createNode(element, options)
143
- ref.__uniqId = Math.random()
174
+ ref.__uniqId = _uniqIdCounter++
144
175
  }
145
176
 
146
177
  // CREATE a real NODE
@@ -209,6 +240,8 @@ const onlyResolveExtends = (element, parent, key, options) => {
209
240
 
210
241
  // apply props settings
211
242
  initProps(element, parent, options)
243
+ // Re-pickup component-named properties that entered props via childProps/inheritParentProps
244
+ pickupElementFromProps.call(element, element, { cachedKeys: [] })
212
245
  if (element.scope === 'props' || element.scope === true) {
213
246
  element.scope = element.props
214
247
  }
@@ -235,10 +268,9 @@ const onlyResolveExtends = (element, parent, key, options) => {
235
268
  continue
236
269
  }
237
270
 
238
- const hasDefine = element.define && element.define[k]
239
- const contextHasDefine =
240
- element.context && element.context.define && element.context.define[k]
241
- const optionsHasDefine = options.define && options.define[k]
271
+ const hasDefine = element.define?.[k]
272
+ const contextHasDefine = element.context?.define?.[k]
273
+ const optionsHasDefine = options.define?.[k]
242
274
 
243
275
  if (!ref.__skipCreate && REGISTRY[k] && !optionsHasDefine) {
244
276
  continue
@@ -267,22 +299,4 @@ const onlyResolveExtends = (element, parent, key, options) => {
267
299
  return element
268
300
  }
269
301
 
270
- // const checkIfMedia = (key) => key.slice(0, 1) === '@'
271
-
272
- // const applyMediaProps = (element, parent, key) => {
273
- // const { props } = element
274
- // if (props) {
275
- // props.display = 'none'
276
- // if (props[key]) props[key].display = props.display
277
- // else props[key] = { display: props.display || 'block' }
278
- // return element
279
- // } else {
280
- // return {
281
- // ...element,
282
- // display: 'none',
283
- // [key]: { display: 'block' }
284
- // }
285
- // }
286
- // }
287
-
288
302
  export default create
package/define.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  import { report } from '@domql/report'
4
- import { REGISTRY } from './mixins'
4
+ import { REGISTRY } from './mixins/index.js'
5
5
 
6
6
  export default (params, options = {}) => {
7
7
  const { overwrite } = options
@@ -23,6 +23,28 @@ __export(children_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(children_exports);
25
25
  var import_utils = require("@domql/utils");
26
+ const shallowChildrenEqual = (a, b) => {
27
+ if (a === b) return true;
28
+ if (!a || !b) return false;
29
+ if ((0, import_utils.isArray)(a) && (0, import_utils.isArray)(b)) {
30
+ if (a.length !== b.length) return false;
31
+ for (let i = 0; i < a.length; i++) {
32
+ if (a[i] !== b[i]) return false;
33
+ }
34
+ return true;
35
+ }
36
+ if ((0, import_utils.isObject)(a) && (0, import_utils.isObject)(b)) {
37
+ const keysA = Object.keys(a);
38
+ const keysB = Object.keys(b);
39
+ if (keysA.length !== keysB.length) return false;
40
+ for (let i = 0; i < keysA.length; i++) {
41
+ const key = keysA[i];
42
+ if (a[key] !== b[key]) return false;
43
+ }
44
+ return true;
45
+ }
46
+ return a === b;
47
+ };
26
48
  function setChildren(param, element, opts) {
27
49
  let { children, __ref: ref, state } = element;
28
50
  let { childrenAs } = element.props || {};
@@ -55,31 +77,37 @@ function setChildren(param, element, opts) {
55
77
  }
56
78
  }
57
79
  if (!children || (0, import_utils.isNot)(children)("array", "object")) return;
58
- if ((0, import_utils.isArray)(children) && children.find((v) => v == null ? void 0 : v.$$typeof)) {
59
- const filterReact = children.filter((v) => !(v == null ? void 0 : v.$$typeof));
60
- if (filterReact.length !== children.length) {
61
- const extractedReactComponents = children.filter((v) => v == null ? void 0 : v.$$typeof);
62
- element.call("renderReact", extractedReactComponents, element);
80
+ if ((0, import_utils.isArray)(children) && children.some((v) => v?.$$typeof)) {
81
+ const filterReact = [];
82
+ const reactComponents = [];
83
+ for (let i = 0; i < children.length; i++) {
84
+ if (children[i]?.$$typeof) reactComponents.push(children[i]);
85
+ else filterReact.push(children[i]);
86
+ }
87
+ if (reactComponents.length) {
88
+ element.call("renderReact", reactComponents, element);
63
89
  }
64
90
  children = filterReact;
65
91
  }
92
+ let cloned;
66
93
  if (ref.__childrenCache) {
67
- const equals = JSON.stringify(children) === JSON.stringify(ref.__childrenCache);
68
- if (equals) {
94
+ if (shallowChildrenEqual(children, ref.__childrenCache)) {
69
95
  ref.__noChildrenDifference = true;
70
96
  } else {
71
- ref.__childrenCache = (0, import_utils.deepClone)(children);
97
+ cloned = (0, import_utils.deepClone)(children);
98
+ ref.__childrenCache = cloned;
72
99
  delete ref.__noChildrenDifference;
73
100
  }
74
101
  } else {
75
- ref.__childrenCache = (0, import_utils.deepClone)(children);
102
+ cloned = (0, import_utils.deepClone)(children);
103
+ ref.__childrenCache = cloned;
76
104
  }
77
105
  if ((0, import_utils.isObject)(children) || (0, import_utils.isArray)(children)) {
78
- children = (0, import_utils.deepClone)(children);
106
+ children = cloned || (0, import_utils.deepClone)(children);
79
107
  }
80
108
  const content = { tag: "fragment" };
81
109
  for (const key in children) {
82
- const value = Object.hasOwnProperty.call(children, key) && children[key];
110
+ const value = Object.prototype.hasOwnProperty.call(children, key) && children[key];
83
111
  if ((0, import_utils.isDefined)(value) && value !== null && value !== false) {
84
112
  content[key] = (0, import_utils.isObjectLike)(value) ? childrenAs ? { [childrenAs]: value } : value : childrenAs ? { [childrenAs]: childrenAs === "state" ? { value } : { text: value } } : { text: value };
85
113
  }
@@ -25,14 +25,36 @@ module.exports = __toCommonJS(create_exports);
25
25
  var import_node = require("./node.js");
26
26
  var import_tree = require("./tree.js");
27
27
  var import_utils = require("@domql/utils");
28
- var import_event = require("@domql/event");
29
- var import_render = require("@domql/render");
28
+ var import_event = require("./event/index.js");
29
+ var import_render = require("./render/index.js");
30
30
  var import_state = require("@domql/state");
31
31
  var import_mixins = require("./mixins/index.js");
32
32
  var import_set = require("./methods/set.js");
33
33
  var import_classList = require("./mixins/classList.js");
34
34
  var import_iterate = require("./iterate.js");
35
- const ENV = "development";
35
+ var import_attrs_in_props = require("attrs-in-props");
36
+ const EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
37
+ const applyPropsAsAttrs = (element) => {
38
+ const { tag, props, context } = element;
39
+ if (!tag || !props) return;
40
+ const autoAttrs = (0, import_attrs_in_props.filterAttributesByTagName)(tag, props, context?.cssPropsRegistry);
41
+ const filtered = {};
42
+ for (const key in autoAttrs) {
43
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key];
44
+ }
45
+ let hasFiltered = false;
46
+ for (const _k in filtered) {
47
+ hasFiltered = true;
48
+ break;
49
+ }
50
+ if (!hasFiltered) return;
51
+ if (!element.attr) {
52
+ element.attr = filtered;
53
+ } else if (typeof element.attr === "object") {
54
+ element.attr = { ...filtered, ...element.attr };
55
+ }
56
+ };
57
+ const ENV = process.env.NODE_ENV;
36
58
  const create = (props, parentEl, passedKey, options = import_utils.OPTIONS.create || {}, attachOptions) => {
37
59
  cacheOptions(options);
38
60
  const element = (0, import_utils.createElement)(props, parentEl, passedKey, options, import_tree.ROOT);
@@ -52,6 +74,8 @@ const create = (props, parentEl, passedKey, options = import_utils.OPTIONS.creat
52
74
  if (element.scope === "state") element.scope = element.state;
53
75
  (0, import_utils.createIfConditionFlag)(element, parent);
54
76
  (0, import_utils.initProps)(element, parent, options);
77
+ import_utils.pickupElementFromProps.call(element, element, { cachedKeys: [] });
78
+ applyPropsAsAttrs(element);
55
79
  if (element.scope === "props" || element.scope === true) {
56
80
  element.scope = element.props;
57
81
  }
@@ -75,7 +99,12 @@ const cacheOptions = (options) => {
75
99
  }
76
100
  };
77
101
  const resetOptions = (element, parent, options) => {
78
- if (Object.keys(options).length) {
102
+ let hasKeys = false;
103
+ for (const _k in options) {
104
+ hasKeys = true;
105
+ break;
106
+ }
107
+ if (hasKeys) {
79
108
  import_utils.OPTIONS.defaultOptions = options;
80
109
  if (options.ignoreChildExtends) delete options.ignoreChildExtends;
81
110
  }
@@ -85,9 +114,9 @@ const addElementIntoParentChildren = (element, parent) => {
85
114
  parent.__ref.__children.push(element.key);
86
115
  }
87
116
  };
117
+ let _uniqIdCounter = 1;
88
118
  const visitedElements = /* @__PURE__ */ new WeakMap();
89
119
  const renderElement = (element, parent, options, attachOptions) => {
90
- var _a, _b, _c;
91
120
  if (visitedElements.has(element)) {
92
121
  if (ENV === "test" || ENV === "development") {
93
122
  console.warn("Cyclic rendering detected:", element.__ref.path);
@@ -99,7 +128,7 @@ const renderElement = (element, parent, options, attachOptions) => {
99
128
  const isInfiniteLoopDetected = (0, import_utils.detectInfiniteLoop)(ref.path);
100
129
  if (ref.__uniqId || isInfiniteLoopDetected) return;
101
130
  (0, import_node.createNode)(element, options);
102
- ref.__uniqId = Math.random();
131
+ ref.__uniqId = _uniqIdCounter++;
103
132
  };
104
133
  if (ENV === "test" || ENV === "development") {
105
134
  createNestedChild();
@@ -114,14 +143,14 @@ const renderElement = (element, parent, options, attachOptions) => {
114
143
  if (path.includes("demoComponent")) {
115
144
  path.splice(0, path.indexOf("demoComponent") + 1);
116
145
  }
117
- const isDemoComponent = (_b = (_a = element.lookup((el) => el.state.key)) == null ? void 0 : _a.state) == null ? void 0 : _b.key;
146
+ const isDemoComponent = element.lookup((el) => el.state.key)?.state?.key;
118
147
  element.warn(
119
148
  "Error happened in:",
120
149
  isDemoComponent ? isDemoComponent + " " : "" + path.join(".")
121
150
  );
122
151
  element.verbose();
123
152
  element.error(e, options);
124
- if ((_c = element.on) == null ? void 0 : _c.error) {
153
+ if (element.on?.error) {
125
154
  element.on.error(e, element, element.state, element.context, options);
126
155
  }
127
156
  }
@@ -145,6 +174,7 @@ const onlyResolveExtends = (element, parent, key, options) => {
145
174
  if (element.scope === "state") element.scope = element.state;
146
175
  (0, import_utils.createIfConditionFlag)(element, parent);
147
176
  (0, import_utils.initProps)(element, parent, options);
177
+ import_utils.pickupElementFromProps.call(element, element, { cachedKeys: [] });
148
178
  if (element.scope === "props" || element.scope === true) {
149
179
  element.scope = element.props;
150
180
  }
@@ -160,9 +190,9 @@ const onlyResolveExtends = (element, parent, key, options) => {
160
190
  if ((0, import_utils.isUndefined)(element[k]) || (0, import_utils.isMethod)(k, element) || (0, import_utils.isObject)(import_mixins.REGISTRY[k])) {
161
191
  continue;
162
192
  }
163
- const hasDefine = element.define && element.define[k];
164
- const contextHasDefine = element.context && element.context.define && element.context.define[k];
165
- const optionsHasDefine = options.define && options.define[k];
193
+ const hasDefine = element.define?.[k];
194
+ const contextHasDefine = element.context?.define?.[k];
195
+ const optionsHasDefine = options.define?.[k];
166
196
  if (!ref.__skipCreate && import_mixins.REGISTRY[k] && !optionsHasDefine) {
167
197
  continue;
168
198
  } else if (element[k] && !hasDefine && !optionsHasDefine && !contextHasDefine) {
@@ -22,7 +22,7 @@ __export(define_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(define_exports);
24
24
  var import_report = require("@domql/report");
25
- var import_mixins = require("./mixins");
25
+ var import_mixins = require("./mixins/index.js");
26
26
  var define_default = (params, options = {}) => {
27
27
  const { overwrite } = options;
28
28
  for (const param in params) {
@@ -0,0 +1,96 @@
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 animationFrame_exports = {};
20
+ __export(animationFrame_exports, {
21
+ applyAnimationFrame: () => applyAnimationFrame,
22
+ initAnimationFrame: () => initAnimationFrame,
23
+ registerFrameListener: () => registerFrameListener
24
+ });
25
+ module.exports = __toCommonJS(animationFrame_exports);
26
+ const registerFrameListener = (el) => {
27
+ if (!el || !el.__ref) {
28
+ throw new Error("Element reference is invalid");
29
+ }
30
+ const { __ref: ref } = el;
31
+ if (!ref.root) {
32
+ throw new Error("Root reference is invalid");
33
+ }
34
+ if (!ref.root.data) {
35
+ throw new Error("Data are undefined");
36
+ }
37
+ const { frameListeners } = ref.root.data;
38
+ if (frameListeners && !frameListeners.has(el)) {
39
+ frameListeners.add(el);
40
+ }
41
+ };
42
+ const processFrameListeners = (frameListeners) => {
43
+ for (const element of frameListeners) {
44
+ if (!element.__ref.__frameHandler) {
45
+ const handler = element.on?.frame || element.onFrame || element.props?.onFrame;
46
+ if (handler) element.__ref.__frameHandler = handler;
47
+ else {
48
+ frameListeners.delete(element);
49
+ continue;
50
+ }
51
+ }
52
+ if (!element.node?.parentNode) {
53
+ frameListeners.delete(element);
54
+ delete element.__ref.__frameHandler;
55
+ } else {
56
+ try {
57
+ element.__ref.__frameHandler(element, element.state, element.context);
58
+ } catch (e) {
59
+ console.warn(e);
60
+ frameListeners.delete(element);
61
+ delete element.__ref.__frameHandler;
62
+ }
63
+ }
64
+ }
65
+ };
66
+ const startFrameLoop = (frameListeners) => {
67
+ if (_frameRunning) return;
68
+ _frameRunning = true;
69
+ function requestFrame() {
70
+ if (frameListeners.size === 0) {
71
+ _frameRunning = false;
72
+ return;
73
+ }
74
+ processFrameListeners(frameListeners);
75
+ window.requestAnimationFrame(requestFrame);
76
+ }
77
+ window.requestAnimationFrame(requestFrame);
78
+ };
79
+ const applyAnimationFrame = (element) => {
80
+ if (!element) {
81
+ throw new Error("Element is invalid");
82
+ }
83
+ const { on, props, __ref: ref } = element;
84
+ if (!ref.root || !ref.root.data) return;
85
+ const { frameListeners } = ref.root.data;
86
+ if (frameListeners && (on?.frame || element.onFrame || props?.onFrame)) {
87
+ registerFrameListener(element);
88
+ startFrameLoop(frameListeners);
89
+ }
90
+ };
91
+ let _frameRunning = false;
92
+ const initAnimationFrame = () => {
93
+ const frameListeners = /* @__PURE__ */ new Set();
94
+ startFrameLoop(frameListeners);
95
+ return frameListeners;
96
+ };
@@ -0,0 +1,28 @@
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 can_exports = {};
20
+ __export(can_exports, {
21
+ canRenderTag: () => canRenderTag
22
+ });
23
+ module.exports = __toCommonJS(can_exports);
24
+ var import_report = require("@domql/report");
25
+ var import_utils = require("@domql/utils");
26
+ const canRenderTag = (tag) => {
27
+ return (0, import_utils.isValidHtmlTag)(tag || "div") || (0, import_report.report)("HTMLInvalidTag");
28
+ };
@@ -0,0 +1,20 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var event_exports = {};
17
+ module.exports = __toCommonJS(event_exports);
18
+ __reExport(event_exports, require("./on.js"), module.exports);
19
+ __reExport(event_exports, require("./can.js"), module.exports);
20
+ __reExport(event_exports, require("./animationFrame.js"), module.exports);
@@ -0,0 +1,84 @@
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 on_exports = {};
20
+ __export(on_exports, {
21
+ applyEvent: () => import_utils2.applyEvent,
22
+ applyEventUpdate: () => import_utils2.applyEventUpdate,
23
+ applyEventsOnNode: () => applyEventsOnNode,
24
+ triggerEventOn: () => import_utils2.triggerEventOn,
25
+ triggerEventOnUpdate: () => import_utils2.triggerEventOnUpdate
26
+ });
27
+ module.exports = __toCommonJS(on_exports);
28
+ var import_utils = require("@domql/utils");
29
+ var import_utils2 = require("@domql/utils");
30
+ const getOnOrPropsEvent = (param, element) => {
31
+ const onEvent = element.on?.[param];
32
+ if (onEvent) return onEvent;
33
+ const props = element.props;
34
+ if (!props) return;
35
+ const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
36
+ return props[propKey];
37
+ };
38
+ const registerNodeEvent = (param, element, node, options) => {
39
+ const appliedFunction = getOnOrPropsEvent(param, element);
40
+ if ((0, import_utils.isFunction)(appliedFunction)) {
41
+ const { __ref: ref } = element;
42
+ if (!ref.__eventListeners) ref.__eventListeners = {};
43
+ if (ref.__eventListeners[param]) {
44
+ node.removeEventListener(param, ref.__eventListeners[param]);
45
+ }
46
+ const handler = (event) => {
47
+ const { state, context } = element;
48
+ const result = appliedFunction.call(
49
+ element,
50
+ event,
51
+ element,
52
+ state,
53
+ context,
54
+ options
55
+ );
56
+ if (result && typeof result.then === "function") {
57
+ result.catch(() => {
58
+ });
59
+ }
60
+ };
61
+ ref.__eventListeners[param] = handler;
62
+ node.addEventListener(param, handler);
63
+ }
64
+ };
65
+ const applyEventsOnNode = (element, options) => {
66
+ const { node, on, props } = element;
67
+ const handled = /* @__PURE__ */ new Set();
68
+ for (const param in on) {
69
+ if (import_utils.DOMQL_EVENTS.has(param)) continue;
70
+ handled.add(param);
71
+ registerNodeEvent(param, element, node, options);
72
+ }
73
+ if (props) {
74
+ for (const key in props) {
75
+ if (key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && (0, import_utils.isFunction)(props[key])) {
76
+ const thirdChar = key[2];
77
+ if (thirdChar !== thirdChar.toUpperCase()) continue;
78
+ const eventName = thirdChar.toLowerCase() + key.slice(3);
79
+ if (handled.has(eventName) || import_utils.DOMQL_EVENTS.has(eventName)) continue;
80
+ registerNodeEvent(eventName, element, node, options);
81
+ }
82
+ }
83
+ }
84
+ };