@domql/element 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/README.md CHANGED
@@ -16,4 +16,22 @@ const Poster = {
16
16
  }
17
17
 
18
18
  DOM.create(Poster, document.body)
19
- ```
19
+ ```
20
+
21
+ ### html mixin
22
+
23
+ The `html` mixin sets raw HTML content on an element. It supports both direct assignment and props:
24
+
25
+ ```javascript
26
+ // Direct assignment (el.html)
27
+ const MyComponent = {
28
+ html: '<strong>Hello</strong>'
29
+ }
30
+
31
+ // Via props (el.props.html) — works as an alias
32
+ const MyComponent = {
33
+ props: { html: '<strong>Hello</strong>' }
34
+ }
35
+ ```
36
+
37
+ `el.html` takes priority when both are set. `props.html` is used as a fallback when `el.html` is not defined.
package/create.js CHANGED
@@ -150,7 +150,9 @@ const resetOptions = (element, parent, options) => {
150
150
 
151
151
  const addElementIntoParentChildren = (element, parent) => {
152
152
  if (parent.__ref && parent.__ref.__children) {
153
- parent.__ref.__children.push(element.key)
153
+ if (!parent.__ref.__children.includes(element.key)) {
154
+ parent.__ref.__children.push(element.key)
155
+ }
154
156
  }
155
157
  }
156
158
 
@@ -111,7 +111,9 @@ const resetOptions = (element, parent, options) => {
111
111
  };
112
112
  const addElementIntoParentChildren = (element, parent) => {
113
113
  if (parent.__ref && parent.__ref.__children) {
114
- parent.__ref.__children.push(element.key);
114
+ if (!parent.__ref.__children.includes(element.key)) {
115
+ parent.__ref.__children.push(element.key);
116
+ }
115
117
  }
116
118
  };
117
119
  let _uniqIdCounter = 1;
@@ -64,7 +64,8 @@ const processFrameListeners = (frameListeners) => {
64
64
  }
65
65
  };
66
66
  const startFrameLoop = (frameListeners) => {
67
- if (_frameRunning) return;
67
+ const raf = typeof window !== "undefined" && window.requestAnimationFrame;
68
+ if (_frameRunning || !raf) return;
68
69
  _frameRunning = true;
69
70
  function requestFrame() {
70
71
  if (frameListeners.size === 0) {
@@ -72,9 +73,9 @@ const startFrameLoop = (frameListeners) => {
72
73
  return;
73
74
  }
74
75
  processFrameListeners(frameListeners);
75
- window.requestAnimationFrame(requestFrame);
76
+ raf(requestFrame);
76
77
  }
77
- window.requestAnimationFrame(requestFrame);
78
+ raf(requestFrame);
78
79
  };
79
80
  const applyAnimationFrame = (element) => {
80
81
  if (!element) {
@@ -24,7 +24,7 @@ __export(html_exports, {
24
24
  module.exports = __toCommonJS(html_exports);
25
25
  var import_utils = require("@domql/utils");
26
26
  function html(param, element, node) {
27
- const prop = (0, import_utils.exec)(element?.props?.html || param, element);
27
+ const prop = (0, import_utils.exec)(param ?? element?.props?.html, element);
28
28
  const { __ref } = element;
29
29
  if (prop !== __ref.__html) {
30
30
  if (node.nodeName === "SVG") node.textContent = prop;
package/dist/cjs/set.js CHANGED
@@ -130,7 +130,7 @@ const set = function(params, options = {}, el) {
130
130
  }
131
131
  return;
132
132
  }
133
- if (!params) return element;
133
+ if (!params || typeof params !== "object") return element;
134
134
  let { childExtends, props, tag } = params;
135
135
  if (!props) props = params.props = {};
136
136
  if (tag === "fragment") {
@@ -215,6 +215,34 @@ const update = function(params = {}, opts) {
215
215
  (0, import_event.triggerEventOn)("update", element, options);
216
216
  }
217
217
  };
218
+ const findSiblingAttachOptions = (element, parent) => {
219
+ const { __children } = parent.__ref || {};
220
+ if (!__children) return false;
221
+ const currentIndex = __children.indexOf(element.key);
222
+ let previousNode;
223
+ for (let i = currentIndex - 1; i >= 0; i--) {
224
+ const sibling = parent[__children[i]];
225
+ if (sibling?.node?.parentNode) {
226
+ previousNode = sibling.node;
227
+ break;
228
+ }
229
+ }
230
+ if (previousNode) {
231
+ return { position: "after", node: previousNode };
232
+ }
233
+ let nextNode;
234
+ for (let i = currentIndex + 1; i < __children.length; i++) {
235
+ const sibling = parent[__children[i]];
236
+ if (sibling?.node?.parentNode) {
237
+ nextNode = sibling.node;
238
+ break;
239
+ }
240
+ }
241
+ if (nextNode) {
242
+ return { position: "before", node: nextNode };
243
+ }
244
+ return false;
245
+ };
218
246
  const checkIfOnUpdate = (element, parent, options) => {
219
247
  if (!(0, import_utils.isFunction)(element.if) && !(0, import_utils.isFunction)(element.props?.if) || !parent) {
220
248
  return;
@@ -251,16 +279,7 @@ const checkIfOnUpdate = (element, parent, options) => {
251
279
  } else if (element[contentKey]?.parseDeep) {
252
280
  element[contentKey] = element[contentKey].parseDeep();
253
281
  }
254
- const previousElement = element.previousElement();
255
- const previousNode = previousElement?.node;
256
- const hasPrevious = previousNode?.parentNode;
257
- const nextElement = element.nextElement();
258
- const nextNode = nextElement?.node;
259
- const hasNext = nextNode?.parentNode;
260
- const attachOptions = (hasPrevious || hasNext) && {
261
- position: hasPrevious ? "after" : hasNext ? "before" : null,
262
- node: hasPrevious && previousNode || hasNext && nextNode
263
- };
282
+ const attachOptions = findSiblingAttachOptions(element, parent);
264
283
  delete element.__ref;
265
284
  delete element.parent;
266
285
  const createdElement = (0, import_create.create)(
@@ -102,7 +102,9 @@ const resetOptions = (element, parent, options) => {
102
102
  };
103
103
  const addElementIntoParentChildren = (element, parent) => {
104
104
  if (parent.__ref && parent.__ref.__children) {
105
- parent.__ref.__children.push(element.key);
105
+ if (!parent.__ref.__children.includes(element.key)) {
106
+ parent.__ref.__children.push(element.key);
107
+ }
106
108
  }
107
109
  };
108
110
  let _uniqIdCounter = 1;
@@ -39,7 +39,8 @@ const processFrameListeners = (frameListeners) => {
39
39
  }
40
40
  };
41
41
  const startFrameLoop = (frameListeners) => {
42
- if (_frameRunning) return;
42
+ const raf = typeof window !== "undefined" && window.requestAnimationFrame;
43
+ if (_frameRunning || !raf) return;
43
44
  _frameRunning = true;
44
45
  function requestFrame() {
45
46
  if (frameListeners.size === 0) {
@@ -47,9 +48,9 @@ const startFrameLoop = (frameListeners) => {
47
48
  return;
48
49
  }
49
50
  processFrameListeners(frameListeners);
50
- window.requestAnimationFrame(requestFrame);
51
+ raf(requestFrame);
51
52
  }
52
- window.requestAnimationFrame(requestFrame);
53
+ raf(requestFrame);
53
54
  };
54
55
  const applyAnimationFrame = (element) => {
55
56
  if (!element) {
@@ -1,6 +1,6 @@
1
1
  import { exec } from "@domql/utils";
2
2
  function html(param, element, node) {
3
- const prop = exec(element?.props?.html || param, element);
3
+ const prop = exec(param ?? element?.props?.html, element);
4
4
  const { __ref } = element;
5
5
  if (prop !== __ref.__html) {
6
6
  if (node.nodeName === "SVG") node.textContent = prop;
package/dist/esm/set.js CHANGED
@@ -100,7 +100,7 @@ const set = function(params, options = {}, el) {
100
100
  }
101
101
  return;
102
102
  }
103
- if (!params) return element;
103
+ if (!params || typeof params !== "object") return element;
104
104
  let { childExtends, props, tag } = params;
105
105
  if (!props) props = params.props = {};
106
106
  if (tag === "fragment") {
@@ -202,6 +202,34 @@ const update = function(params = {}, opts) {
202
202
  triggerEventOn("update", element, options);
203
203
  }
204
204
  };
205
+ const findSiblingAttachOptions = (element, parent) => {
206
+ const { __children } = parent.__ref || {};
207
+ if (!__children) return false;
208
+ const currentIndex = __children.indexOf(element.key);
209
+ let previousNode;
210
+ for (let i = currentIndex - 1; i >= 0; i--) {
211
+ const sibling = parent[__children[i]];
212
+ if (sibling?.node?.parentNode) {
213
+ previousNode = sibling.node;
214
+ break;
215
+ }
216
+ }
217
+ if (previousNode) {
218
+ return { position: "after", node: previousNode };
219
+ }
220
+ let nextNode;
221
+ for (let i = currentIndex + 1; i < __children.length; i++) {
222
+ const sibling = parent[__children[i]];
223
+ if (sibling?.node?.parentNode) {
224
+ nextNode = sibling.node;
225
+ break;
226
+ }
227
+ }
228
+ if (nextNode) {
229
+ return { position: "before", node: nextNode };
230
+ }
231
+ return false;
232
+ };
205
233
  const checkIfOnUpdate = (element, parent, options) => {
206
234
  if (!isFunction(element.if) && !isFunction(element.props?.if) || !parent) {
207
235
  return;
@@ -238,16 +266,7 @@ const checkIfOnUpdate = (element, parent, options) => {
238
266
  } else if (element[contentKey]?.parseDeep) {
239
267
  element[contentKey] = element[contentKey].parseDeep();
240
268
  }
241
- const previousElement = element.previousElement();
242
- const previousNode = previousElement?.node;
243
- const hasPrevious = previousNode?.parentNode;
244
- const nextElement = element.nextElement();
245
- const nextNode = nextElement?.node;
246
- const hasNext = nextNode?.parentNode;
247
- const attachOptions = (hasPrevious || hasNext) && {
248
- position: hasPrevious ? "after" : hasNext ? "before" : null,
249
- node: hasPrevious && previousNode || hasNext && nextNode
250
- };
269
+ const attachOptions = findSiblingAttachOptions(element, parent);
251
270
  delete element.__ref;
252
271
  delete element.parent;
253
272
  const createdElement = create(
@@ -57,7 +57,7 @@ var DomqlElement = (() => {
57
57
  return (typeof HTMLElement === "object" ? obj instanceof window2.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
58
58
  };
59
59
  var isDOMNode = (obj) => {
60
- return typeof window2 !== "undefined" && (obj instanceof window2.Node || obj instanceof window2.Window || obj === window2 || obj === document);
60
+ return typeof window2 !== "undefined" && (window2.Node && obj instanceof window2.Node || window2.Window && obj instanceof window2.Window || obj === window2 || obj === document);
61
61
  };
62
62
 
63
63
  // ../utils/dist/esm/types.js
@@ -801,6 +801,7 @@ var DomqlElement = (() => {
801
801
 
802
802
  // ../utils/dist/esm/extends.js
803
803
  var ENV2 = process.env.NODE_ENV;
804
+ var isSourcemapEnabled = (options) => options.sourcemap !== false && ENV2 !== "production";
804
805
  var createExtendsFromKeys = (key) => {
805
806
  if (key.includes("+")) {
806
807
  return key.split("+").filter(matchesComponentNaming);
@@ -874,17 +875,17 @@ var DomqlElement = (() => {
874
875
  }
875
876
  return setHashedExtend(extend, stack);
876
877
  };
877
- var extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
878
+ var extractArrayExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, componentNameMap) => {
878
879
  for (const each of extend) {
879
880
  if (isArray(each)) {
880
- extractArrayExtend(each, stack, context, processed);
881
+ extractArrayExtend(each, stack, context, processed, nameStack, componentNameMap);
881
882
  } else {
882
- flattenExtend(each, stack, context, processed);
883
+ flattenExtend(each, stack, context, processed, nameStack, void 0, componentNameMap);
883
884
  }
884
885
  }
885
886
  return stack;
886
887
  };
887
- var deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
888
+ var deepExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, currentName, componentNameMap) => {
888
889
  const extendOflattenExtend = extend.extends || extend.extend;
889
890
  const cleanExtend = { ...extend };
890
891
  delete cleanExtend.extends;
@@ -896,26 +897,32 @@ var DomqlElement = (() => {
896
897
  }
897
898
  if (hasKeys) {
898
899
  stack.push(cleanExtend);
900
+ if (nameStack) nameStack.push(currentName);
899
901
  }
900
902
  if (extendOflattenExtend) {
901
- flattenExtend(extendOflattenExtend, stack, context, processed);
903
+ flattenExtend(extendOflattenExtend, stack, context, processed, nameStack, currentName, componentNameMap);
902
904
  }
903
905
  return stack;
904
906
  };
905
- var flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set()) => {
907
+ var flattenExtend = (extend, stack, context, processed = /* @__PURE__ */ new Set(), nameStack, parentName, componentNameMap) => {
906
908
  if (!extend) return stack;
907
909
  if (processed.has(extend)) return stack;
908
910
  if (isArray(extend)) {
909
- return extractArrayExtend(extend, stack, context, processed);
911
+ return extractArrayExtend(extend, stack, context, processed, nameStack, componentNameMap);
910
912
  }
913
+ let currentName = parentName;
911
914
  if (isString(extend)) {
915
+ currentName = extend;
912
916
  extend = mapStringsWithContextComponents(extend, context);
917
+ } else if (componentNameMap && isObject(extend) && componentNameMap.has(extend)) {
918
+ currentName = componentNameMap.get(extend);
913
919
  }
914
920
  processed.add(extend);
915
921
  if (extend?.extends || extend?.extend) {
916
- deepExtend(extend, stack, context, processed);
922
+ deepExtend(extend, stack, context, processed, nameStack, currentName, componentNameMap);
917
923
  } else if (extend) {
918
924
  stack.push(extend);
925
+ if (nameStack) nameStack.push(currentName);
919
926
  }
920
927
  return stack;
921
928
  };
@@ -928,7 +935,7 @@ var DomqlElement = (() => {
928
935
  "childExtend",
929
936
  "childExtendRecursive"
930
937
  ]);
931
- var deepMergeExtends = (element, extend) => {
938
+ var deepMergeExtends = (element, extend, sourcemap, sourceName, preBuiltSourcemap) => {
932
939
  extend = deepClone(extend);
933
940
  for (const e in extend) {
934
941
  if (MERGE_EXTENDS_SKIP.has(e)) continue;
@@ -938,11 +945,23 @@ var DomqlElement = (() => {
938
945
  if (Object.prototype.hasOwnProperty.call(extend, e) && e !== "__proto__" && e !== "constructor" && e !== "prototype") {
939
946
  if (elementProp === void 0) {
940
947
  element[e] = extendProp;
948
+ if (sourcemap && sourceName) {
949
+ if (isObject(extendProp) && !isArray(extendProp)) {
950
+ sourcemap[e] = sourcemap[e] || {};
951
+ trackSourcemapDeep(sourcemap[e], extendProp, sourceName);
952
+ } else {
953
+ sourcemap[e] = sourceName;
954
+ }
955
+ } else if (sourcemap && preBuiltSourcemap?.[e]) {
956
+ sourcemap[e] = preBuiltSourcemap[e];
957
+ }
941
958
  } else if (isObject(elementProp) && isObject(extendProp)) {
959
+ const nestedSourcemap = sourcemap ? sourcemap[e] = sourcemap[e] || {} : void 0;
960
+ const nestedPreBuilt = preBuiltSourcemap?.[e];
942
961
  if (matchesComponentNaming(e)) {
943
- element[e] = deepMergeExtends(elementProp, extendProp);
962
+ element[e] = deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
944
963
  } else {
945
- deepMergeExtends(elementProp, extendProp);
964
+ deepMergeExtends(elementProp, extendProp, nestedSourcemap, sourceName, nestedPreBuilt);
946
965
  }
947
966
  }
948
967
  if (e === "extends" || e === "childExtends" || e === "childExtendsRecursive") {
@@ -957,10 +976,24 @@ var DomqlElement = (() => {
957
976
  }
958
977
  return element;
959
978
  };
960
- var cloneAndMergeArrayExtend = (stack) => {
961
- return stack.reduce((acc, current) => {
979
+ var trackSourcemapDeep = (sourcemap, obj, sourceName) => {
980
+ for (const key in obj) {
981
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
982
+ if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
983
+ const val = obj[key];
984
+ if (isObject(val) && !isArray(val)) {
985
+ sourcemap[key] = sourcemap[key] || {};
986
+ trackSourcemapDeep(sourcemap[key], val, sourceName);
987
+ } else {
988
+ sourcemap[key] = sourceName;
989
+ }
990
+ }
991
+ };
992
+ var cloneAndMergeArrayExtend = (stack, sourcemap, extendNames) => {
993
+ return stack.reduce((acc, current, i) => {
962
994
  const cloned = deepClone(current);
963
- return deepMergeExtends(acc, cloned);
995
+ const sourceName = extendNames ? extendNames[i] : void 0;
996
+ return deepMergeExtends(acc, cloned, sourcemap, sourceName);
964
997
  }, {});
965
998
  };
966
999
  var mapStringsWithContextComponents = (extend, context, options = {}, variant) => {
@@ -980,11 +1013,12 @@ var DomqlElement = (() => {
980
1013
  }
981
1014
  return extend;
982
1015
  };
983
- var getExtendsStack = (extend, context) => {
1016
+ var getExtendsStack = (extend, context, nameStack, componentNameMap) => {
984
1017
  if (!extend) return [];
985
1018
  if (extend.__hash) return getHashedExtend(extend) || [];
986
1019
  const processed = /* @__PURE__ */ new Set();
987
- const stack = flattenExtend(extend, [], context, processed);
1020
+ const stack = flattenExtend(extend, [], context, processed, nameStack, void 0, componentNameMap);
1021
+ if (nameStack) return stack;
988
1022
  return getExtendsStackRegistry(extend, stack);
989
1023
  };
990
1024
  var createElementExtends = (element, parent, options = {}) => {
@@ -1062,6 +1096,8 @@ var DomqlElement = (() => {
1062
1096
  const { props, __ref: ref } = element;
1063
1097
  const context = element.context || parent.context;
1064
1098
  const variant = element.variant || props?.variant;
1099
+ const sourcemap = isSourcemapEnabled(options);
1100
+ const originalExtendNames = sourcemap ? [...ref.__extends] : null;
1065
1101
  const __extends = removeDuplicatesInArray(
1066
1102
  ref.__extends.map((val, i) => {
1067
1103
  return mapStringsWithContextComponents(
@@ -1072,15 +1108,40 @@ var DomqlElement = (() => {
1072
1108
  );
1073
1109
  })
1074
1110
  );
1075
- const stack = getExtendsStack(__extends, context);
1076
- ref.__extendsStack = stack;
1111
+ if (sourcemap) {
1112
+ const componentNameMap = /* @__PURE__ */ new WeakMap();
1113
+ for (let i = 0; i < __extends.length; i++) {
1114
+ const resolved = __extends[i];
1115
+ const originalName = originalExtendNames[i];
1116
+ if (resolved && isObject(resolved) && isString(originalName)) {
1117
+ componentNameMap.set(resolved, originalName);
1118
+ }
1119
+ }
1120
+ const nameStack = [];
1121
+ const stack = getExtendsStack(__extends, context, nameStack, componentNameMap);
1122
+ ref.__extendsStack = stack;
1123
+ ref.__extendsNames = nameStack;
1124
+ } else {
1125
+ const stack = getExtendsStack(__extends, context);
1126
+ ref.__extendsStack = stack;
1127
+ }
1077
1128
  return ref.__extendsStack;
1078
1129
  };
1079
1130
  var finalizeExtends = (element, parent, options = {}) => {
1080
1131
  const { __ref: ref } = element;
1081
1132
  const { __extendsStack } = ref;
1082
- const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
1083
- return deepMergeExtends(element, flattenExtends);
1133
+ if (isSourcemapEnabled(options)) {
1134
+ const sourcemapAcc = {};
1135
+ const extendNames = ref.__extendsNames || [];
1136
+ const flattenExtends = cloneAndMergeArrayExtend(__extendsStack, sourcemapAcc, extendNames);
1137
+ const appliedSourcemap = {};
1138
+ deepMergeExtends(element, flattenExtends, appliedSourcemap, void 0, sourcemapAcc);
1139
+ ref.__sourcemap = appliedSourcemap;
1140
+ } else {
1141
+ const flattenExtends = cloneAndMergeArrayExtend(__extendsStack);
1142
+ deepMergeExtends(element, flattenExtends);
1143
+ }
1144
+ return element;
1084
1145
  };
1085
1146
  var applyExtends = (element, parent, options = {}) => {
1086
1147
  createElementExtends(element, parent, options);
@@ -1119,6 +1180,30 @@ var DomqlElement = (() => {
1119
1180
  // ../utils/dist/esm/props.js
1120
1181
  var RE_UPPER = /^[A-Z]/;
1121
1182
  var RE_DIGITS = /^\d+$/;
1183
+ var ELEMENT_INDICATOR_KEYS = /* @__PURE__ */ new Set([
1184
+ "extend",
1185
+ "props",
1186
+ "text",
1187
+ "tag",
1188
+ "on",
1189
+ "if",
1190
+ "childExtend",
1191
+ "children",
1192
+ "childrenAs",
1193
+ "state",
1194
+ "html",
1195
+ "attr",
1196
+ "define",
1197
+ "content"
1198
+ ]);
1199
+ var looksLikeElement = (value) => {
1200
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1201
+ for (const k in value) {
1202
+ if (ELEMENT_INDICATOR_KEYS.has(k)) return true;
1203
+ if (RE_UPPER.test(k)) return true;
1204
+ }
1205
+ return false;
1206
+ };
1122
1207
  var createProps = (element, parent, key) => {
1123
1208
  const { props, __ref: ref } = element;
1124
1209
  ref.__propsStack = [];
@@ -1143,7 +1228,7 @@ var DomqlElement = (() => {
1143
1228
  }
1144
1229
  const hasDefine = isObject(this.define?.[key]);
1145
1230
  const hasGlobalDefine = isObject(this.context?.define?.[key]);
1146
- const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
1231
+ const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
1147
1232
  const isBuiltin = DOMQ_PROPERTIES.has(key);
1148
1233
  if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
1149
1234
  obj.props[key] = value;
@@ -2151,7 +2236,8 @@ ${element}` : "";
2151
2236
  }
2152
2237
  };
2153
2238
  var startFrameLoop = (frameListeners) => {
2154
- if (_frameRunning) return;
2239
+ const raf = typeof window !== "undefined" && window.requestAnimationFrame;
2240
+ if (_frameRunning || !raf) return;
2155
2241
  _frameRunning = true;
2156
2242
  function requestFrame() {
2157
2243
  if (frameListeners.size === 0) {
@@ -2159,9 +2245,9 @@ ${element}` : "";
2159
2245
  return;
2160
2246
  }
2161
2247
  processFrameListeners(frameListeners);
2162
- window.requestAnimationFrame(requestFrame);
2248
+ raf(requestFrame);
2163
2249
  }
2164
- window.requestAnimationFrame(requestFrame);
2250
+ raf(requestFrame);
2165
2251
  };
2166
2252
  var applyAnimationFrame = (element) => {
2167
2253
  if (!element) {
@@ -2544,7 +2630,7 @@ ${element}` : "";
2544
2630
 
2545
2631
  // mixins/html.js
2546
2632
  function html(param, element, node) {
2547
- const prop = exec(element?.props?.html || param, element);
2633
+ const prop = exec(param ?? element?.props?.html, element);
2548
2634
  const { __ref } = element;
2549
2635
  if (prop !== __ref.__html) {
2550
2636
  if (node.nodeName === "SVG") node.textContent = prop;
@@ -2874,7 +2960,7 @@ ${element}` : "";
2874
2960
  }
2875
2961
  return;
2876
2962
  }
2877
- if (!params) return element;
2963
+ if (!params || typeof params !== "object") return element;
2878
2964
  let { childExtends, props, tag } = params;
2879
2965
  if (!props) props = params.props = {};
2880
2966
  if (tag === "fragment") {
@@ -3495,6 +3581,34 @@ ${element}` : "";
3495
3581
  triggerEventOn("update", element, options);
3496
3582
  }
3497
3583
  };
3584
+ var findSiblingAttachOptions = (element, parent) => {
3585
+ const { __children } = parent.__ref || {};
3586
+ if (!__children) return false;
3587
+ const currentIndex = __children.indexOf(element.key);
3588
+ let previousNode;
3589
+ for (let i = currentIndex - 1; i >= 0; i--) {
3590
+ const sibling = parent[__children[i]];
3591
+ if (sibling?.node?.parentNode) {
3592
+ previousNode = sibling.node;
3593
+ break;
3594
+ }
3595
+ }
3596
+ if (previousNode) {
3597
+ return { position: "after", node: previousNode };
3598
+ }
3599
+ let nextNode;
3600
+ for (let i = currentIndex + 1; i < __children.length; i++) {
3601
+ const sibling = parent[__children[i]];
3602
+ if (sibling?.node?.parentNode) {
3603
+ nextNode = sibling.node;
3604
+ break;
3605
+ }
3606
+ }
3607
+ if (nextNode) {
3608
+ return { position: "before", node: nextNode };
3609
+ }
3610
+ return false;
3611
+ };
3498
3612
  var checkIfOnUpdate = (element, parent, options) => {
3499
3613
  if (!isFunction(element.if) && !isFunction(element.props?.if) || !parent) {
3500
3614
  return;
@@ -3531,16 +3645,7 @@ ${element}` : "";
3531
3645
  } else if (element[contentKey]?.parseDeep) {
3532
3646
  element[contentKey] = element[contentKey].parseDeep();
3533
3647
  }
3534
- const previousElement2 = element.previousElement();
3535
- const previousNode = previousElement2?.node;
3536
- const hasPrevious = previousNode?.parentNode;
3537
- const nextElement2 = element.nextElement();
3538
- const nextNode = nextElement2?.node;
3539
- const hasNext = nextNode?.parentNode;
3540
- const attachOptions = (hasPrevious || hasNext) && {
3541
- position: hasPrevious ? "after" : hasNext ? "before" : null,
3542
- node: hasPrevious && previousNode || hasNext && nextNode
3543
- };
3648
+ const attachOptions = findSiblingAttachOptions(element, parent);
3544
3649
  delete element.__ref;
3545
3650
  delete element.parent;
3546
3651
  const createdElement = create(
@@ -4649,7 +4754,9 @@ ${element}` : "";
4649
4754
  };
4650
4755
  var addElementIntoParentChildren = (element, parent) => {
4651
4756
  if (parent.__ref && parent.__ref.__children) {
4652
- parent.__ref.__children.push(element.key);
4757
+ if (!parent.__ref.__children.includes(element.key)) {
4758
+ parent.__ref.__children.push(element.key);
4759
+ }
4653
4760
  }
4654
4761
  };
4655
4762
  var _uniqIdCounter = 1;
@@ -51,7 +51,8 @@ const processFrameListeners = (frameListeners) => {
51
51
  }
52
52
 
53
53
  const startFrameLoop = (frameListeners) => {
54
- if (_frameRunning) return
54
+ const raf = typeof window !== 'undefined' && window.requestAnimationFrame
55
+ if (_frameRunning || !raf) return
55
56
  _frameRunning = true
56
57
 
57
58
  function requestFrame () {
@@ -60,10 +61,10 @@ const startFrameLoop = (frameListeners) => {
60
61
  return
61
62
  }
62
63
  processFrameListeners(frameListeners)
63
- window.requestAnimationFrame(requestFrame)
64
+ raf(requestFrame)
64
65
  }
65
66
 
66
- window.requestAnimationFrame(requestFrame)
67
+ raf(requestFrame)
67
68
  }
68
69
 
69
70
  export const applyAnimationFrame = element => {
package/mixins/html.js CHANGED
@@ -7,7 +7,7 @@ import { exec } from '@domql/utils'
7
7
  * an original one as a child
8
8
  */
9
9
  export function html (param, element, node) {
10
- const prop = exec(element?.props?.html || param, element)
10
+ const prop = exec(param ?? element?.props?.html, element)
11
11
  const { __ref } = element
12
12
  if (prop !== __ref.__html) {
13
13
  if (node.nodeName === 'SVG') node.textContent = prop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domql/element",
3
- "version": "3.5.1",
3
+ "version": "3.6.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
@@ -8,29 +8,23 @@
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
  "./event": {
16
14
  "import": "./dist/esm/event/index.js",
17
- "require": "./dist/cjs/event/index.js",
18
- "default": "./dist/esm/event/index.js"
15
+ "require": "./dist/cjs/event/index.js"
19
16
  },
20
17
  "./render": {
21
18
  "import": "./dist/esm/render/index.js",
22
- "require": "./dist/cjs/render/index.js",
23
- "default": "./dist/esm/render/index.js"
19
+ "require": "./dist/cjs/render/index.js"
24
20
  },
25
21
  "./*.js": {
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
  "import": "./dist/esm/*.js",
32
- "require": "./dist/cjs/*.js",
33
- "default": "./dist/esm/*.js"
27
+ "require": "./dist/cjs/*.js"
34
28
  }
35
29
  },
36
30
  "source": "index.js",
@@ -52,10 +46,10 @@
52
46
  "build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=DomqlElement --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
53
47
  },
54
48
  "dependencies": {
55
- "@domql/report": "^3.5.1",
56
- "@domql/state": "^3.5.1",
57
- "@domql/utils": "^3.5.1",
58
- "attrs-in-props": "^3.5.1"
49
+ "@domql/report": "^3.6.1",
50
+ "@domql/state": "^3.6.1",
51
+ "@domql/utils": "^3.6.1",
52
+ "attrs-in-props": "^3.6.1"
59
53
  },
60
54
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
61
55
  "devDependencies": {
@@ -64,5 +58,8 @@
64
58
  "browser": "./dist/esm/index.js",
65
59
  "unpkg": "./dist/iife/index.js",
66
60
  "jsdelivr": "./dist/iife/index.js",
67
- "sideEffects": false
61
+ "sideEffects": false,
62
+ "publishConfig": {
63
+ "access": "public"
64
+ }
68
65
  }
package/set.js CHANGED
@@ -130,7 +130,7 @@ export const set = function (params, options = {}, el) {
130
130
  return
131
131
  }
132
132
 
133
- if (!params) return element
133
+ if (!params || typeof params !== 'object') return element
134
134
 
135
135
  let { childExtends, props, tag } = params
136
136
  if (!props) props = params.props = {}
package/update.js CHANGED
@@ -288,6 +288,43 @@ export const update = function (params = {}, opts) {
288
288
  }
289
289
  }
290
290
 
291
+ const findSiblingAttachOptions = (element, parent) => {
292
+ const { __children } = parent.__ref || {}
293
+ if (!__children) return false
294
+
295
+ const currentIndex = __children.indexOf(element.key)
296
+
297
+ // Walk backwards to find nearest previous sibling with a DOM node
298
+ let previousNode
299
+ for (let i = currentIndex - 1; i >= 0; i--) {
300
+ const sibling = parent[__children[i]]
301
+ if (sibling?.node?.parentNode) {
302
+ previousNode = sibling.node
303
+ break
304
+ }
305
+ }
306
+
307
+ if (previousNode) {
308
+ return { position: 'after', node: previousNode }
309
+ }
310
+
311
+ // Walk forwards to find nearest next sibling with a DOM node
312
+ let nextNode
313
+ for (let i = currentIndex + 1; i < __children.length; i++) {
314
+ const sibling = parent[__children[i]]
315
+ if (sibling?.node?.parentNode) {
316
+ nextNode = sibling.node
317
+ break
318
+ }
319
+ }
320
+
321
+ if (nextNode) {
322
+ return { position: 'before', node: nextNode }
323
+ }
324
+
325
+ return false
326
+ }
327
+
291
328
  const checkIfOnUpdate = (element, parent, options) => {
292
329
  if ((!isFunction(element.if) && !isFunction(element.props?.if)) || !parent) {
293
330
  return
@@ -331,18 +368,7 @@ const checkIfOnUpdate = (element, parent, options) => {
331
368
  element[contentKey] = element[contentKey].parseDeep()
332
369
  }
333
370
 
334
- const previousElement = element.previousElement()
335
- const previousNode = previousElement?.node // document.body.contains(previousElement.node)
336
- const hasPrevious = previousNode?.parentNode // document.body.contains(previousElement.node)
337
-
338
- const nextElement = element.nextElement()
339
- const nextNode = nextElement?.node // document.body.contains(previousElement.node)
340
- const hasNext = nextNode?.parentNode
341
-
342
- const attachOptions = (hasPrevious || hasNext) && {
343
- position: hasPrevious ? 'after' : hasNext ? 'before' : null,
344
- node: (hasPrevious && previousNode) || (hasNext && nextNode)
345
- }
371
+ const attachOptions = findSiblingAttachOptions(element, parent)
346
372
 
347
373
  delete element.__ref
348
374
  delete element.parent