@domql/utils 3.1.2 → 3.2.3

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.
@@ -35,7 +35,7 @@ var import_node = require("./node.js");
35
35
  var import_props = require("./props.js");
36
36
  var import_tags = require("./tags.js");
37
37
  var import_types = require("./types.js");
38
- const ENV = "development";
38
+ const ENV = process.env.NODE_ENV;
39
39
  const returnValueAsText = (element, parent, key) => {
40
40
  const childExtendsTag = parent.childExtends && parent.childExtends.tag;
41
41
  const childPropsTag = parent.props.childProps && parent.props.childProps.tag;
package/dist/cjs/env.js CHANGED
@@ -31,7 +31,7 @@ __export(env_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(env_exports);
33
33
  // @preserve-env
34
- const NODE_ENV = "development";
34
+ const NODE_ENV = process.env.NODE_ENV;
35
35
  const ENV = NODE_ENV;
36
36
  const isProduction = (env = NODE_ENV) => env === "production";
37
37
  const isTest = (env = NODE_ENV) => env === "testing" || env === "test";
@@ -29,9 +29,9 @@ function addEventFromProps(key, obj) {
29
29
  const origEvent = on[eventName];
30
30
  const funcFromProps = props[key];
31
31
  if ((0, import_types.isFunction)(origEvent)) {
32
- on[eventName] = async (...args) => {
33
- const originalEventRetunrs = await origEvent(...args);
34
- if (originalEventRetunrs !== false) await funcFromProps(...args);
32
+ on[eventName] = (...args) => {
33
+ const originalEventRetunrs = origEvent(...args);
34
+ if (originalEventRetunrs !== false) funcFromProps(...args);
35
35
  };
36
36
  } else on[eventName] = funcFromProps;
37
37
  }
@@ -51,7 +51,7 @@ var import_array = require("./array.js");
51
51
  var import_component = require("./component.js");
52
52
  var import_object = require("./object.js");
53
53
  var import_types = require("./types.js");
54
- const ENV = "development";
54
+ const ENV = process.env.NODE_ENV;
55
55
  const createExtendsFromKeys = (key) => {
56
56
  if (key.includes("+")) {
57
57
  return key.split("+").filter(import_component.matchesComponentNaming);
package/dist/cjs/keys.js CHANGED
@@ -38,6 +38,7 @@ const DOMQ_PROPERTIES = [
38
38
  "classlist",
39
39
  "state",
40
40
  "scope",
41
+ "root",
41
42
  "deps",
42
43
  "extends",
43
44
  "$router",
@@ -78,8 +79,7 @@ const PARSED_DOMQ_PROPERTIES = [
78
79
  "key",
79
80
  "tag",
80
81
  "query",
81
- "on",
82
- "context"
82
+ "on"
83
83
  ];
84
84
  const STATE_PROPERTIES = [
85
85
  "ref",
@@ -22,6 +22,7 @@ __export(methods_exports, {
22
22
  defineSetter: () => defineSetter,
23
23
  error: () => error,
24
24
  get: () => get,
25
+ getChildren: () => getChildren,
25
26
  getPath: () => getPath,
26
27
  getRef: () => getRef,
27
28
  isMethod: () => isMethod,
@@ -49,7 +50,7 @@ var import_types = require("./types.js");
49
50
  var import_object = require("./object.js");
50
51
  var import_env = require("./env.js");
51
52
  var import_array = require("./array.js");
52
- const ENV = "development";
53
+ const ENV = process.env.NODE_ENV;
53
54
  function spotByPath(path) {
54
55
  const element = this;
55
56
  const { __ref: ref } = element;
@@ -87,7 +88,8 @@ function lookdown(param) {
87
88
  var _a;
88
89
  const el = this;
89
90
  const { __ref: ref } = el;
90
- const children = ref.__children;
91
+ const children = ref == null ? void 0 : ref.__children;
92
+ if (!children) return;
91
93
  for (let i = 0; i < children.length; i++) {
92
94
  const v = children[i];
93
95
  const childElem = el[v];
@@ -106,7 +108,8 @@ function lookdownAll(param, results = []) {
106
108
  var _a;
107
109
  const el = this;
108
110
  const { __ref: ref } = el;
109
- const children = ref.__children;
111
+ const children = ref == null ? void 0 : ref.__children;
112
+ if (!children) return;
110
113
  for (let i = 0; i < children.length; i++) {
111
114
  const v = children[i];
112
115
  const childElem = el[v];
@@ -159,9 +162,14 @@ function setProps(param, options) {
159
162
  element.update({ props: param }, options);
160
163
  return element;
161
164
  }
162
- function getRef() {
165
+ function getRef(key) {
166
+ if (key) return this.__ref && this.__ref[key];
163
167
  return this.__ref;
164
168
  }
169
+ function getChildren() {
170
+ const __children = this.getRef("__children");
171
+ return __children.map((k) => this[k]);
172
+ }
165
173
  function getPath() {
166
174
  return this.getRef().path;
167
175
  }
@@ -182,32 +190,43 @@ function keys() {
182
190
  }
183
191
  function parse(excl = []) {
184
192
  const element = this;
185
- const { __ref: ref } = element;
186
193
  const obj = {};
187
194
  const keyList = keys.call(element);
195
+ const hasChildren = keyList.includes("children");
188
196
  keyList.forEach((v) => {
189
- if (excl.includes(v)) return;
197
+ if (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) return;
198
+ if (hasChildren && v === "content") return;
190
199
  const val = element[v];
191
200
  if (v === "state") {
192
- if (!(ref == null ? void 0 : ref.__hasRootState)) return;
201
+ if (element.__ref && !element.__ref.__hasRootState) return;
193
202
  const parsedVal = (0, import_types.isFunction)(val && val.parse) ? val.parse() : val;
194
203
  obj[v] = (0, import_types.isFunction)(parsedVal) ? parsedVal : JSON.parse(JSON.stringify(parsedVal || {}));
195
204
  } else if (v === "scope") {
196
- if (!(ref == null ? void 0 : ref.__hasRootScope)) return;
205
+ if (element.__ref && !element.__ref.__hasRootScope) return;
197
206
  obj[v] = JSON.parse(JSON.stringify(val || {}));
207
+ } else if (v === "props") {
208
+ const { __element, update, ...props } = element[v];
209
+ obj[v] = props;
198
210
  } else if ((0, import_types.isDefined)(val) && Object.hasOwnProperty.call(element, v)) {
199
211
  obj[v] = val;
200
212
  }
201
213
  });
202
214
  return obj;
203
215
  }
204
- function parseDeep(excl = []) {
216
+ function parseDeep(excl = [], visited = /* @__PURE__ */ new WeakSet()) {
205
217
  const element = this;
218
+ if (visited.has(element)) return void 0;
219
+ visited.add(element);
206
220
  const obj = parse.call(element, excl);
207
221
  for (const v in obj) {
208
- if (excl.includes(v)) return;
209
- if ((0, import_types.isObjectLike)(obj[v])) {
210
- obj[v] = parseDeep.call(obj[v], excl);
222
+ if (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) continue;
223
+ const val = obj[v];
224
+ if (Array.isArray(val)) {
225
+ obj[v] = val.map(
226
+ (item) => (0, import_types.isObjectLike)(item) ? parseDeep.call(item, excl, visited) : item
227
+ );
228
+ } else if ((0, import_types.isObjectLike)(val)) {
229
+ obj[v] = parseDeep.call(val, excl, visited);
211
230
  }
212
231
  }
213
232
  return obj;
@@ -29,7 +29,6 @@ __export(object_exports, {
29
29
  detectInfiniteLoop: () => detectInfiniteLoop,
30
30
  excludeKeysFromObject: () => excludeKeysFromObject,
31
31
  exec: () => exec,
32
- execPromise: () => execPromise,
33
32
  getInObjectByPath: () => getInObjectByPath,
34
33
  hasFunction: () => hasFunction,
35
34
  hasOwnProperty: () => hasOwnProperty,
@@ -56,26 +55,23 @@ var import_array = require("./array.js");
56
55
  var import_string = require("./string.js");
57
56
  var import_node = require("./node.js");
58
57
  var import_keys = require("./keys.js");
59
- const ENV = "development";
58
+ const ENV = process.env.NODE_ENV;
60
59
  const exec = (param, element, state, context) => {
61
60
  if ((0, import_types.isFunction)(param)) {
62
- return param.call(
63
- element,
64
- element,
65
- state || element.state,
66
- context || element.context
67
- );
68
- }
69
- return param;
70
- };
71
- const execPromise = async (param, element, state, context) => {
72
- if ((0, import_types.isFunction)(param)) {
73
- return await param.call(
61
+ const result = param.call(
74
62
  element,
75
63
  element,
76
64
  state || element.state,
77
65
  context || element.context
78
66
  );
67
+ if (result && typeof result.then === "function") {
68
+ let resolved;
69
+ result.then((value) => {
70
+ resolved = value;
71
+ });
72
+ return resolved;
73
+ }
74
+ return result;
79
75
  }
80
76
  return param;
81
77
  };
@@ -134,13 +130,14 @@ const deepClone = (obj, options = {}) => {
134
130
  visited = /* @__PURE__ */ new WeakMap(),
135
131
  handleExtends = false
136
132
  } = options;
133
+ const contentWindow = targetWindow || import_globals.window || globalThis;
137
134
  if (!(0, import_types.isObjectLike)(obj) || (0, import_node.isDOMNode)(obj)) {
138
135
  return obj;
139
136
  }
140
137
  if (visited.has(obj)) {
141
138
  return visited.get(obj);
142
139
  }
143
- const clone2 = targetWindow ? (0, import_types.isArray)(obj) ? new targetWindow.Array() : new targetWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
140
+ const clone2 = contentWindow ? (0, import_types.isArray)(obj) ? new contentWindow.Array() : new contentWindow.Object() : (0, import_types.isArray)(obj) ? [] : {};
144
141
  visited.set(obj, clone2);
145
142
  for (const key in obj) {
146
143
  if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
@@ -159,8 +156,8 @@ const deepClone = (obj, options = {}) => {
159
156
  clone2[key] = (0, import_array.unstackArrayOfObjects)(value, exclude);
160
157
  continue;
161
158
  }
162
- if ((0, import_types.isFunction)(value) && targetWindow) {
163
- clone2[key] = targetWindow.eval("(" + value.toString() + ")");
159
+ if ((0, import_types.isFunction)(value) && options.window) {
160
+ clone2[key] = contentWindow.eval("(" + value.toString() + ")");
164
161
  continue;
165
162
  }
166
163
  if ((0, import_types.isObjectLike)(value)) {
package/dist/cjs/props.js CHANGED
@@ -135,9 +135,9 @@ const inheritParentProps = (element, parent) => {
135
135
  }
136
136
  return propsStack;
137
137
  };
138
- async function update(props, options) {
138
+ function update(props, options) {
139
139
  const element = this.__element;
140
- await element.update({ props }, options);
140
+ element.update({ props }, options);
141
141
  }
142
142
  function setPropsPrototype(element) {
143
143
  const methods = { update: update.bind(element.props), __element: element };
package/dist/cjs/state.js CHANGED
@@ -35,12 +35,12 @@ var import_array = require("./array.js");
35
35
  var import_keys = require("./keys.js");
36
36
  var import_object = require("./object.js");
37
37
  var import_types = require("./types.js");
38
- const checkForStateTypes = async (element) => {
38
+ const checkForStateTypes = (element) => {
39
39
  const { state: orig, props, __ref: ref } = element;
40
40
  const state = (props == null ? void 0 : props.state) || orig;
41
41
  if ((0, import_types.isFunction)(state)) {
42
42
  ref.__state = state;
43
- return await (0, import_object.execPromise)(state, element);
43
+ return (0, import_object.exec)(state, element);
44
44
  } else if ((0, import_types.is)(state)("string", "number")) {
45
45
  ref.__state = state;
46
46
  return { value: state };
@@ -141,9 +141,9 @@ const createNestedObjectByKeyPath = (path, value) => {
141
141
  });
142
142
  return obj;
143
143
  };
144
- const applyDependentState = async (element, state) => {
144
+ const applyDependentState = (element, state) => {
145
145
  const { __element } = state;
146
- const origState = await (0, import_object.execPromise)(__element == null ? void 0 : __element.state, element);
146
+ const origState = (0, import_object.exec)(__element == null ? void 0 : __element.state, element);
147
147
  if (!origState) return;
148
148
  const dependentState = (0, import_object.deepClone)(origState, import_keys.STATE_METHODS);
149
149
  const newDepends = { [element.key]: dependentState };
package/dist/cjs/tags.js CHANGED
@@ -23,18 +23,8 @@ __export(tags_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(tags_exports);
25
25
  const HTML_TAGS = {
26
- root: [
27
- "body",
28
- "html"
29
- ],
30
- head: [
31
- "title",
32
- "base",
33
- "meta",
34
- "style",
35
- "noscript",
36
- "script"
37
- ],
26
+ root: ["body", "html"],
27
+ head: ["title", "base", "meta", "style", "noscript", "script"],
38
28
  body: [
39
29
  "string",
40
30
  "style",
@@ -23,7 +23,7 @@ import { isNode } from "./node.js";
23
23
  import { createProps } from "./props.js";
24
24
  import { HTML_TAGS } from "./tags.js";
25
25
  import { is, isFunction } from "./types.js";
26
- const ENV = "development";
26
+ const ENV = process.env.NODE_ENV;
27
27
  const returnValueAsText = (element, parent, key) => {
28
28
  const childExtendsTag = parent.childExtends && parent.childExtends.tag;
29
29
  const childPropsTag = parent.props.childProps && parent.props.childProps.tag;
package/dist/esm/env.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // @preserve-env
2
- const NODE_ENV = "development";
2
+ const NODE_ENV = process.env.NODE_ENV;
3
3
  const ENV = NODE_ENV;
4
4
  const isProduction = (env = NODE_ENV) => env === "production";
5
5
  const isTest = (env = NODE_ENV) => env === "testing" || env === "test";
@@ -6,9 +6,9 @@ function addEventFromProps(key, obj) {
6
6
  const origEvent = on[eventName];
7
7
  const funcFromProps = props[key];
8
8
  if (isFunction(origEvent)) {
9
- on[eventName] = async (...args) => {
10
- const originalEventRetunrs = await origEvent(...args);
11
- if (originalEventRetunrs !== false) await funcFromProps(...args);
9
+ on[eventName] = (...args) => {
10
+ const originalEventRetunrs = origEvent(...args);
11
+ if (originalEventRetunrs !== false) funcFromProps(...args);
12
12
  };
13
13
  } else on[eventName] = funcFromProps;
14
14
  }
@@ -21,7 +21,7 @@ import { joinArrays, removeDuplicatesInArray } from "./array.js";
21
21
  import { matchesComponentNaming } from "./component.js";
22
22
  import { deepClone, exec } from "./object.js";
23
23
  import { isArray, isObject, isString } from "./types.js";
24
- const ENV = "development";
24
+ const ENV = process.env.NODE_ENV;
25
25
  const createExtendsFromKeys = (key) => {
26
26
  if (key.includes("+")) {
27
27
  return key.split("+").filter(matchesComponentNaming);
package/dist/esm/keys.js CHANGED
@@ -8,6 +8,7 @@ const DOMQ_PROPERTIES = [
8
8
  "classlist",
9
9
  "state",
10
10
  "scope",
11
+ "root",
11
12
  "deps",
12
13
  "extends",
13
14
  "$router",
@@ -48,8 +49,7 @@ const PARSED_DOMQ_PROPERTIES = [
48
49
  "key",
49
50
  "tag",
50
51
  "query",
51
- "on",
52
- "context"
52
+ "on"
53
53
  ];
54
54
  const STATE_PROPERTIES = [
55
55
  "ref",
@@ -1,10 +1,25 @@
1
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
4
+ var __objRest = (source, exclude) => {
5
+ var target = {};
6
+ for (var prop in source)
7
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
8
+ target[prop] = source[prop];
9
+ if (source != null && __getOwnPropSymbols)
10
+ for (var prop of __getOwnPropSymbols(source)) {
11
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
12
+ target[prop] = source[prop];
13
+ }
14
+ return target;
15
+ };
1
16
  import { triggerEventOn } from "@domql/event";
2
17
  import { DOMQ_PROPERTIES, METHODS, PARSED_DOMQ_PROPERTIES } from "./keys.js";
3
18
  import { isDefined, isFunction, isObject, isObjectLike } from "./types.js";
4
19
  import { deepClone } from "./object.js";
5
20
  import { isProduction } from "./env.js";
6
21
  import { removeValueFromArray } from "./array.js";
7
- const ENV = "development";
22
+ const ENV = process.env.NODE_ENV;
8
23
  function spotByPath(path) {
9
24
  const element = this;
10
25
  const { __ref: ref } = element;
@@ -42,7 +57,8 @@ function lookdown(param) {
42
57
  var _a;
43
58
  const el = this;
44
59
  const { __ref: ref } = el;
45
- const children = ref.__children;
60
+ const children = ref == null ? void 0 : ref.__children;
61
+ if (!children) return;
46
62
  for (let i = 0; i < children.length; i++) {
47
63
  const v = children[i];
48
64
  const childElem = el[v];
@@ -61,7 +77,8 @@ function lookdownAll(param, results = []) {
61
77
  var _a;
62
78
  const el = this;
63
79
  const { __ref: ref } = el;
64
- const children = ref.__children;
80
+ const children = ref == null ? void 0 : ref.__children;
81
+ if (!children) return;
65
82
  for (let i = 0; i < children.length; i++) {
66
83
  const v = children[i];
67
84
  const childElem = el[v];
@@ -114,9 +131,14 @@ function setProps(param, options) {
114
131
  element.update({ props: param }, options);
115
132
  return element;
116
133
  }
117
- function getRef() {
134
+ function getRef(key) {
135
+ if (key) return this.__ref && this.__ref[key];
118
136
  return this.__ref;
119
137
  }
138
+ function getChildren() {
139
+ const __children = this.getRef("__children");
140
+ return __children.map((k) => this[k]);
141
+ }
120
142
  function getPath() {
121
143
  return this.getRef().path;
122
144
  }
@@ -137,32 +159,43 @@ function keys() {
137
159
  }
138
160
  function parse(excl = []) {
139
161
  const element = this;
140
- const { __ref: ref } = element;
141
162
  const obj = {};
142
163
  const keyList = keys.call(element);
164
+ const hasChildren = keyList.includes("children");
143
165
  keyList.forEach((v) => {
144
- if (excl.includes(v)) return;
166
+ if (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) return;
167
+ if (hasChildren && v === "content") return;
145
168
  const val = element[v];
146
169
  if (v === "state") {
147
- if (!(ref == null ? void 0 : ref.__hasRootState)) return;
170
+ if (element.__ref && !element.__ref.__hasRootState) return;
148
171
  const parsedVal = isFunction(val && val.parse) ? val.parse() : val;
149
172
  obj[v] = isFunction(parsedVal) ? parsedVal : JSON.parse(JSON.stringify(parsedVal || {}));
150
173
  } else if (v === "scope") {
151
- if (!(ref == null ? void 0 : ref.__hasRootScope)) return;
174
+ if (element.__ref && !element.__ref.__hasRootScope) return;
152
175
  obj[v] = JSON.parse(JSON.stringify(val || {}));
176
+ } else if (v === "props") {
177
+ const _a = element[v], { __element, update } = _a, props = __objRest(_a, ["__element", "update"]);
178
+ obj[v] = props;
153
179
  } else if (isDefined(val) && Object.hasOwnProperty.call(element, v)) {
154
180
  obj[v] = val;
155
181
  }
156
182
  });
157
183
  return obj;
158
184
  }
159
- function parseDeep(excl = []) {
185
+ function parseDeep(excl = [], visited = /* @__PURE__ */ new WeakSet()) {
160
186
  const element = this;
187
+ if (visited.has(element)) return void 0;
188
+ visited.add(element);
161
189
  const obj = parse.call(element, excl);
162
190
  for (const v in obj) {
163
- if (excl.includes(v)) return;
164
- if (isObjectLike(obj[v])) {
165
- obj[v] = parseDeep.call(obj[v], excl);
191
+ if (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) continue;
192
+ const val = obj[v];
193
+ if (Array.isArray(val)) {
194
+ obj[v] = val.map(
195
+ (item) => isObjectLike(item) ? parseDeep.call(item, excl, visited) : item
196
+ );
197
+ } else if (isObjectLike(val)) {
198
+ obj[v] = parseDeep.call(val, excl, visited);
166
199
  }
167
200
  }
168
201
  return obj;
@@ -263,6 +296,7 @@ export {
263
296
  defineSetter,
264
297
  error,
265
298
  get,
299
+ getChildren,
266
300
  getPath,
267
301
  getRef,
268
302
  isMethod,
@@ -32,26 +32,23 @@ import { unstackArrayOfObjects } from "./array.js";
32
32
  import { stringIncludesAny } from "./string.js";
33
33
  import { isDOMNode } from "./node.js";
34
34
  import { METHODS_EXL } from "./keys.js";
35
- const ENV = "development";
35
+ const ENV = process.env.NODE_ENV;
36
36
  const exec = (param, element, state, context) => {
37
37
  if (isFunction(param)) {
38
- return param.call(
39
- element,
40
- element,
41
- state || element.state,
42
- context || element.context
43
- );
44
- }
45
- return param;
46
- };
47
- const execPromise = async (param, element, state, context) => {
48
- if (isFunction(param)) {
49
- return await param.call(
38
+ const result = param.call(
50
39
  element,
51
40
  element,
52
41
  state || element.state,
53
42
  context || element.context
54
43
  );
44
+ if (result && typeof result.then === "function") {
45
+ let resolved;
46
+ result.then((value) => {
47
+ resolved = value;
48
+ });
49
+ return resolved;
50
+ }
51
+ return result;
55
52
  }
56
53
  return param;
57
54
  };
@@ -110,13 +107,14 @@ const deepClone = (obj, options = {}) => {
110
107
  visited = /* @__PURE__ */ new WeakMap(),
111
108
  handleExtends = false
112
109
  } = options;
110
+ const contentWindow = targetWindow || window || globalThis;
113
111
  if (!isObjectLike(obj) || isDOMNode(obj)) {
114
112
  return obj;
115
113
  }
116
114
  if (visited.has(obj)) {
117
115
  return visited.get(obj);
118
116
  }
119
- const clone2 = targetWindow ? isArray(obj) ? new targetWindow.Array() : new targetWindow.Object() : isArray(obj) ? [] : {};
117
+ const clone2 = contentWindow ? isArray(obj) ? new contentWindow.Array() : new contentWindow.Object() : isArray(obj) ? [] : {};
120
118
  visited.set(obj, clone2);
121
119
  for (const key in obj) {
122
120
  if (!Object.prototype.hasOwnProperty.call(obj, key)) continue;
@@ -135,8 +133,8 @@ const deepClone = (obj, options = {}) => {
135
133
  clone2[key] = unstackArrayOfObjects(value, exclude);
136
134
  continue;
137
135
  }
138
- if (isFunction(value) && targetWindow) {
139
- clone2[key] = targetWindow.eval("(" + value.toString() + ")");
136
+ if (isFunction(value) && options.window) {
137
+ clone2[key] = contentWindow.eval("(" + value.toString() + ")");
140
138
  continue;
141
139
  }
142
140
  if (isObjectLike(value)) {
@@ -555,7 +553,6 @@ export {
555
553
  detectInfiniteLoop,
556
554
  excludeKeysFromObject,
557
555
  exec,
558
- execPromise,
559
556
  getInObjectByPath,
560
557
  hasFunction,
561
558
  hasOwnProperty,
package/dist/esm/props.js CHANGED
@@ -113,9 +113,9 @@ const inheritParentProps = (element, parent) => {
113
113
  }
114
114
  return propsStack;
115
115
  };
116
- async function update(props, options) {
116
+ function update(props, options) {
117
117
  const element = this.__element;
118
- await element.update({ props }, options);
118
+ element.update({ props }, options);
119
119
  }
120
120
  function setPropsPrototype(element) {
121
121
  const methods = { update: update.bind(element.props), __element: element };
package/dist/esm/state.js CHANGED
@@ -22,7 +22,7 @@ import { STATE_METHODS } from "./keys.js";
22
22
  import {
23
23
  deepClone,
24
24
  deepMerge,
25
- execPromise,
25
+ exec,
26
26
  overwriteDeep,
27
27
  overwriteShallow
28
28
  } from "./object.js";
@@ -34,12 +34,12 @@ import {
34
34
  isString,
35
35
  isUndefined
36
36
  } from "./types.js";
37
- const checkForStateTypes = async (element) => {
37
+ const checkForStateTypes = (element) => {
38
38
  const { state: orig, props, __ref: ref } = element;
39
39
  const state = (props == null ? void 0 : props.state) || orig;
40
40
  if (isFunction(state)) {
41
41
  ref.__state = state;
42
- return await execPromise(state, element);
42
+ return exec(state, element);
43
43
  } else if (is(state)("string", "number")) {
44
44
  ref.__state = state;
45
45
  return { value: state };
@@ -140,9 +140,9 @@ const createNestedObjectByKeyPath = (path, value) => {
140
140
  });
141
141
  return obj;
142
142
  };
143
- const applyDependentState = async (element, state) => {
143
+ const applyDependentState = (element, state) => {
144
144
  const { __element } = state;
145
- const origState = await execPromise(__element == null ? void 0 : __element.state, element);
145
+ const origState = exec(__element == null ? void 0 : __element.state, element);
146
146
  if (!origState) return;
147
147
  const dependentState = deepClone(origState, STATE_METHODS);
148
148
  const newDepends = { [element.key]: dependentState };
package/dist/esm/tags.js CHANGED
@@ -1,16 +1,6 @@
1
1
  const HTML_TAGS = {
2
- root: [
3
- "body",
4
- "html"
5
- ],
6
- head: [
7
- "title",
8
- "base",
9
- "meta",
10
- "style",
11
- "noscript",
12
- "script"
13
- ],
2
+ root: ["body", "html"],
3
+ head: ["title", "base", "meta", "style", "noscript", "script"],
14
4
  body: [
15
5
  "string",
16
6
  "style",
package/events.js CHANGED
@@ -9,9 +9,9 @@ export function addEventFromProps (key, obj) {
9
9
  const origEvent = on[eventName]
10
10
  const funcFromProps = props[key]
11
11
  if (isFunction(origEvent)) {
12
- on[eventName] = async (...args) => {
13
- const originalEventRetunrs = await origEvent(...args)
14
- if (originalEventRetunrs !== false) await funcFromProps(...args)
12
+ on[eventName] = (...args) => {
13
+ const originalEventRetunrs = origEvent(...args)
14
+ if (originalEventRetunrs !== false) funcFromProps(...args)
15
15
  }
16
16
  } else on[eventName] = funcFromProps
17
17
  }
package/function.js CHANGED
@@ -16,7 +16,8 @@
16
16
  export function debounce (func, wait, immediate) {
17
17
  let timeout
18
18
  return function () {
19
- const context = this; const args = arguments
19
+ const context = this
20
+ const args = arguments
20
21
  const later = function () {
21
22
  timeout = null
22
23
  if (!immediate) func.apply(context, args)
@@ -46,11 +47,13 @@ export const debounceOnContext = (element, func, timeout = 300) => {
46
47
  let timer
47
48
  return (...args) => {
48
49
  clearTimeout(timer)
49
- timer = setTimeout(() => { func.apply(element, args) }, timeout)
50
+ timer = setTimeout(() => {
51
+ func.apply(element, args)
52
+ }, timeout)
50
53
  }
51
54
  }
52
55
 
53
- export const memoize = (fn) => {
56
+ export const memoize = fn => {
54
57
  const cache = {}
55
58
  return (...args) => {
56
59
  const n = args[0]
package/keys.js CHANGED
@@ -10,6 +10,7 @@ export const DOMQ_PROPERTIES = [
10
10
  'classlist',
11
11
  'state',
12
12
  'scope',
13
+ 'root',
13
14
  'deps',
14
15
  'extends',
15
16
  '$router',
@@ -51,8 +52,7 @@ export const PARSED_DOMQ_PROPERTIES = [
51
52
  'key',
52
53
  'tag',
53
54
  'query',
54
- 'on',
55
- 'context'
55
+ 'on'
56
56
  ]
57
57
 
58
58
  export const STATE_PROPERTIES = [
package/log.js CHANGED
@@ -3,7 +3,6 @@
3
3
  export const logIf = (bool, ...arg) => {
4
4
  if (bool) arg.map(v => console.log(v))
5
5
  }
6
-
7
6
  export const logGroupIf = (bool, key, ...arg) => {
8
7
  if (bool) {
9
8
  console.group(key)
package/methods.js CHANGED
@@ -55,7 +55,9 @@ export function lookup (param) {
55
55
  export function lookdown (param) {
56
56
  const el = this
57
57
  const { __ref: ref } = el
58
- const children = ref.__children
58
+ const children = ref?.__children
59
+
60
+ if (!children) return
59
61
 
60
62
  for (let i = 0; i < children.length; i++) {
61
63
  const v = children[i]
@@ -76,7 +78,9 @@ export function lookdown (param) {
76
78
  export function lookdownAll (param, results = []) {
77
79
  const el = this
78
80
  const { __ref: ref } = el
79
- const children = ref.__children
81
+ const children = ref?.__children
82
+
83
+ if (!children) return
80
84
 
81
85
  for (let i = 0; i < children.length; i++) {
82
86
  const v = children[i]
@@ -138,10 +142,16 @@ export function setProps (param, options) {
138
142
  return element
139
143
  }
140
144
 
141
- export function getRef () {
145
+ export function getRef (key) {
146
+ if (key) return this.__ref && this.__ref[key]
142
147
  return this.__ref
143
148
  }
144
149
 
150
+ export function getChildren () {
151
+ const __children = this.getRef('__children')
152
+ return __children.map(k => this[k])
153
+ }
154
+
145
155
  export function getPath () {
146
156
  return this.getRef().path
147
157
  }
@@ -174,21 +184,25 @@ export function keys () {
174
184
 
175
185
  export function parse (excl = []) {
176
186
  const element = this
177
- const { __ref: ref } = element
178
187
  const obj = {}
179
188
  const keyList = keys.call(element)
189
+ const hasChildren = keyList.includes('children')
180
190
  keyList.forEach(v => {
181
- if (excl.includes(v)) return
191
+ if (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) return
192
+ if (hasChildren && v === 'content') return
182
193
  const val = element[v]
183
194
  if (v === 'state') {
184
- if (!ref?.__hasRootState) return
195
+ if (element.__ref && !element.__ref.__hasRootState) return
185
196
  const parsedVal = isFunction(val && val.parse) ? val.parse() : val
186
197
  obj[v] = isFunction(parsedVal)
187
198
  ? parsedVal
188
199
  : JSON.parse(JSON.stringify(parsedVal || {}))
189
200
  } else if (v === 'scope') {
190
- if (!ref?.__hasRootScope) return
201
+ if (element.__ref && !element.__ref.__hasRootScope) return
191
202
  obj[v] = JSON.parse(JSON.stringify(val || {}))
203
+ } else if (v === 'props') {
204
+ const { __element, update, ...props } = element[v]
205
+ obj[v] = props
192
206
  } else if (isDefined(val) && Object.hasOwnProperty.call(element, v)) {
193
207
  obj[v] = val
194
208
  }
@@ -196,13 +210,20 @@ export function parse (excl = []) {
196
210
  return obj
197
211
  }
198
212
 
199
- export function parseDeep (excl = []) {
213
+ export function parseDeep (excl = [], visited = new WeakSet()) {
200
214
  const element = this
215
+ if (visited.has(element)) return undefined
216
+ visited.add(element)
201
217
  const obj = parse.call(element, excl)
202
218
  for (const v in obj) {
203
- if (excl.includes(v)) return
204
- if (isObjectLike(obj[v])) {
205
- obj[v] = parseDeep.call(obj[v], excl)
219
+ if (excl.includes(v) || !Object.hasOwnProperty.call(element, v)) continue
220
+ const val = obj[v]
221
+ if (Array.isArray(val)) {
222
+ obj[v] = val.map(item =>
223
+ isObjectLike(item) ? parseDeep.call(item, excl, visited) : item
224
+ )
225
+ } else if (isObjectLike(val)) {
226
+ obj[v] = parseDeep.call(val, excl, visited)
206
227
  }
207
228
  }
208
229
  return obj
@@ -300,6 +321,15 @@ export function variables (obj = {}) {
300
321
  }
301
322
  }
302
323
 
324
+ /**
325
+ * A unified call function that detects the calling context and adapts accordingly.
326
+ * - When called in an async context (with await), it fully resolves promises
327
+ * - When called in a sync context, it returns sync results directly and handles promises appropriately
328
+ *
329
+ * @param {string} fnKey - The name of the function to call
330
+ * @param {...any} args - Arguments to pass to the function
331
+ * @returns {any|Promise} - The result or a Promise to the result
332
+ */
303
333
  export function call (fnKey, ...args) {
304
334
  const context = this.context
305
335
  return (
package/object.js CHANGED
@@ -20,24 +20,20 @@ const ENV = process.env.NODE_ENV
20
20
 
21
21
  export const exec = (param, element, state, context) => {
22
22
  if (isFunction(param)) {
23
- return param.call(
24
- element,
25
- element,
26
- state || element.state,
27
- context || element.context
28
- )
29
- }
30
- return param
31
- }
32
-
33
- export const execPromise = async (param, element, state, context) => {
34
- if (isFunction(param)) {
35
- return await param.call(
23
+ const result = param.call(
36
24
  element,
37
25
  element,
38
26
  state || element.state,
39
27
  context || element.context
40
28
  )
29
+ if (result && typeof result.then === 'function') {
30
+ let resolved
31
+ result.then(value => {
32
+ resolved = value
33
+ })
34
+ return resolved
35
+ }
36
+ return result
41
37
  }
42
38
  return param
43
39
  }
@@ -118,6 +114,8 @@ export const deepClone = (obj, options = {}) => {
118
114
  handleExtends = false
119
115
  } = options
120
116
 
117
+ const contentWindow = targetWindow || window || globalThis
118
+
121
119
  // Handle non-object types and special cases
122
120
  if (!isObjectLike(obj) || isDOMNode(obj)) {
123
121
  return obj
@@ -129,10 +127,10 @@ export const deepClone = (obj, options = {}) => {
129
127
  }
130
128
 
131
129
  // Create appropriate container based on type and window context
132
- const clone = targetWindow
130
+ const clone = contentWindow
133
131
  ? isArray(obj)
134
- ? new targetWindow.Array()
135
- : new targetWindow.Object()
132
+ ? new contentWindow.Array()
133
+ : new contentWindow.Object()
136
134
  : isArray(obj)
137
135
  ? []
138
136
  : {}
@@ -172,8 +170,8 @@ export const deepClone = (obj, options = {}) => {
172
170
  }
173
171
 
174
172
  // Handle functions in cross-frame scenario
175
- if (isFunction(value) && targetWindow) {
176
- clone[key] = targetWindow.eval('(' + value.toString() + ')')
173
+ if (isFunction(value) && options.window) {
174
+ clone[key] = contentWindow.eval('(' + value.toString() + ')')
177
175
  continue
178
176
  }
179
177
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "3.1.2",
3
+ "version": "3.2.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "index.js",
7
7
  "main": "index.js",
8
8
  "exports": {
9
9
  ".": {
10
- "default": "./index.js",
10
+ "default": "./dist/esm/index.js",
11
11
  "import": "./dist/esm/index.js",
12
12
  "require": "./dist/cjs/index.js"
13
13
  }
@@ -19,12 +19,12 @@
19
19
  ],
20
20
  "scripts": {
21
21
  "copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
22
- "build:esm": "npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm",
23
- "build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
22
+ "build:esm": "npx cross-env NODE_ENV=$NODE_ENV npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
23
+ "build:cjs": "npx cross-env NODE_ENV=$NODE_ENV npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
24
24
  "build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm",
25
25
  "prepublish": "npm run build; npm run copy:package:cjs"
26
26
  },
27
- "gitHead": "429b36616aa04c8587a26ce3c129815115e35897",
27
+ "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
28
28
  "devDependencies": {
29
29
  "@babel/core": "^7.26.0"
30
30
  }
package/props.js CHANGED
@@ -129,9 +129,9 @@ export const inheritParentProps = (element, parent) => {
129
129
  return propsStack
130
130
  }
131
131
 
132
- export async function update (props, options) {
132
+ export function update (props, options) {
133
133
  const element = this.__element
134
- await element.update({ props }, options)
134
+ element.update({ props }, options)
135
135
  }
136
136
 
137
137
  // TODO: check bind with promise
package/state.js CHANGED
@@ -5,7 +5,7 @@ import { STATE_METHODS } from './keys.js'
5
5
  import {
6
6
  deepClone,
7
7
  deepMerge,
8
- execPromise,
8
+ exec,
9
9
  overwriteDeep,
10
10
  overwriteShallow
11
11
  } from './object.js'
@@ -18,12 +18,12 @@ import {
18
18
  isUndefined
19
19
  } from './types.js'
20
20
 
21
- export const checkForStateTypes = async element => {
21
+ export const checkForStateTypes = element => {
22
22
  const { state: orig, props, __ref: ref } = element
23
23
  const state = props?.state || orig
24
24
  if (isFunction(state)) {
25
25
  ref.__state = state
26
- return await execPromise(state, element)
26
+ return exec(state, element)
27
27
  } else if (is(state)('string', 'number')) {
28
28
  ref.__state = state
29
29
  return { value: state }
@@ -165,9 +165,9 @@ export const createNestedObjectByKeyPath = (path, value) => {
165
165
  return obj
166
166
  }
167
167
 
168
- export const applyDependentState = async (element, state) => {
168
+ export const applyDependentState = (element, state) => {
169
169
  const { __element } = state //
170
- const origState = await execPromise(__element?.state, element)
170
+ const origState = exec(__element?.state, element)
171
171
  if (!origState) return
172
172
  const dependentState = deepClone(origState, STATE_METHODS)
173
173
  const newDepends = { [element.key]: dependentState }
package/tags.js CHANGED
@@ -1,19 +1,9 @@
1
1
  'use strict'
2
2
 
3
3
  export const HTML_TAGS = {
4
- root: [
5
- 'body',
6
- 'html'
7
- ],
4
+ root: ['body', 'html'],
8
5
 
9
- head: [
10
- 'title',
11
- 'base',
12
- 'meta',
13
- 'style',
14
- 'noscript',
15
- 'script'
16
- ],
6
+ head: ['title', 'base', 'meta', 'style', 'noscript', 'script'],
17
7
 
18
8
  body: [
19
9
  'string',
package/types.js CHANGED
@@ -4,7 +4,7 @@ import { isHtmlElement, isNode } from './node.js'
4
4
 
5
5
  export const isObject = arg => {
6
6
  if (arg === null) return false
7
- return (typeof arg === 'object') && (arg.constructor === Object)
7
+ return typeof arg === 'object' && arg.constructor === Object
8
8
  }
9
9
 
10
10
  export const isString = arg => typeof arg === 'string'
@@ -24,11 +24,12 @@ export const isDate = d => d instanceof Date
24
24
  export const isObjectLike = arg => {
25
25
  if (arg === null) return false
26
26
  // if (isArray(arg)) return false
27
- return (typeof arg === 'object')
27
+ return typeof arg === 'object'
28
28
  }
29
29
 
30
30
  export const isDefined = arg => {
31
- return isObject(arg) ||
31
+ return (
32
+ isObject(arg) ||
32
33
  isObjectLike(arg) ||
33
34
  isString(arg) ||
34
35
  isNumber(arg) ||
@@ -38,6 +39,7 @@ export const isDefined = arg => {
38
39
  isBoolean(arg) ||
39
40
  isDate(arg) ||
40
41
  isNull(arg)
42
+ )
41
43
  }
42
44
 
43
45
  export const isUndefined = arg => {
@@ -59,13 +61,13 @@ export const TYPES = {
59
61
  defined: isDefined
60
62
  }
61
63
 
62
- export const is = (arg) => {
64
+ export const is = arg => {
63
65
  return (...args) => {
64
66
  return args.map(val => TYPES[val](arg)).filter(v => v).length > 0
65
67
  }
66
68
  }
67
69
 
68
- export const isNot = (arg) => {
70
+ export const isNot = arg => {
69
71
  return (...args) => {
70
72
  return args.map(val => TYPES[val](arg)).filter(v => v).length === 0
71
73
  }