@symbo.ls/utils 3.2.3 → 3.14.0

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 (122) hide show
  1. package/LICENSE +25 -12
  2. package/README.md +106 -0
  3. package/array.js +162 -0
  4. package/cache.js +7 -0
  5. package/cdn.js +83 -0
  6. package/component.js +25 -0
  7. package/cookie.js +71 -0
  8. package/{src/detectHeight.js → detectHeight.js} +3 -3
  9. package/dist/cjs/array.js +168 -0
  10. package/dist/cjs/browser.js +0 -2
  11. package/dist/cjs/cache.js +26 -0
  12. package/dist/cjs/cdn.js +85 -0
  13. package/dist/cjs/component.js +45 -0
  14. package/dist/cjs/cookie.js +75 -0
  15. package/dist/cjs/date.js +1 -3
  16. package/dist/cjs/detectHeight.js +4 -6
  17. package/dist/cjs/element.js +136 -0
  18. package/dist/cjs/env.js +43 -0
  19. package/dist/cjs/events.js +39 -0
  20. package/dist/cjs/extends.js +434 -0
  21. package/dist/cjs/fibonacci.js +1 -3
  22. package/dist/cjs/files.js +1 -3
  23. package/dist/cjs/function.js +114 -0
  24. package/dist/cjs/globals.js +30 -0
  25. package/dist/cjs/if.js +48 -0
  26. package/dist/cjs/index.js +38 -425
  27. package/dist/cjs/key.js +38 -0
  28. package/dist/cjs/keys.js +201 -0
  29. package/dist/cjs/load.js +5 -7
  30. package/dist/cjs/log.js +34 -0
  31. package/dist/cjs/metadata.js +310 -0
  32. package/dist/cjs/methods.js +599 -0
  33. package/dist/cjs/node.js +35 -0
  34. package/dist/cjs/object.js +634 -0
  35. package/dist/cjs/projectKeys.js +35 -0
  36. package/dist/cjs/props.js +282 -0
  37. package/dist/cjs/scaling.js +5 -169
  38. package/dist/cjs/scope.js +44 -0
  39. package/dist/cjs/sharedLibraries.js +146 -0
  40. package/dist/cjs/state.js +173 -0
  41. package/dist/cjs/string-extra.js +72 -0
  42. package/dist/cjs/string.js +183 -0
  43. package/dist/cjs/style.js +1 -3
  44. package/dist/cjs/tags.js +220 -0
  45. package/dist/cjs/triggerEvent.js +112 -0
  46. package/dist/cjs/types.js +74 -0
  47. package/dist/cjs/update.js +42 -0
  48. package/dist/esm/array.js +148 -0
  49. package/dist/esm/browser.js +14 -0
  50. package/dist/esm/cache.js +6 -0
  51. package/dist/esm/cdn.js +65 -0
  52. package/dist/esm/component.js +25 -0
  53. package/dist/esm/cookie.js +55 -0
  54. package/dist/esm/date.js +11 -0
  55. package/dist/esm/detectHeight.js +42 -0
  56. package/dist/esm/element.js +116 -0
  57. package/dist/esm/env.js +23 -0
  58. package/dist/esm/events.js +19 -0
  59. package/dist/esm/extends.js +414 -0
  60. package/dist/esm/fibonacci.js +10 -0
  61. package/dist/esm/files.js +4 -0
  62. package/dist/esm/function.js +94 -0
  63. package/dist/esm/globals.js +10 -0
  64. package/dist/esm/if.js +28 -0
  65. package/dist/esm/index.js +37 -0
  66. package/dist/esm/key.js +18 -0
  67. package/dist/esm/keys.js +181 -0
  68. package/dist/esm/load.js +151 -0
  69. package/dist/esm/log.js +14 -0
  70. package/dist/esm/metadata.js +290 -0
  71. package/dist/esm/methods.js +569 -0
  72. package/dist/esm/node.js +15 -0
  73. package/dist/esm/object.js +621 -0
  74. package/dist/esm/projectKeys.js +16 -0
  75. package/dist/esm/props.js +262 -0
  76. package/dist/esm/scaling.js +15 -0
  77. package/dist/esm/scope.js +24 -0
  78. package/dist/esm/sharedLibraries.js +126 -0
  79. package/dist/esm/state.js +163 -0
  80. package/dist/esm/string-extra.js +52 -0
  81. package/dist/esm/string.js +163 -0
  82. package/dist/esm/style.js +20 -0
  83. package/dist/esm/tags.js +200 -0
  84. package/dist/esm/triggerEvent.js +92 -0
  85. package/dist/esm/types.js +54 -0
  86. package/dist/esm/update.js +22 -0
  87. package/dist/iife/index.js +5818 -0
  88. package/element.js +148 -0
  89. package/env.js +15 -0
  90. package/events.js +19 -0
  91. package/extends.js +519 -0
  92. package/function.js +145 -0
  93. package/globals.js +8 -0
  94. package/if.js +30 -0
  95. package/index.js +41 -0
  96. package/key.js +20 -0
  97. package/keys.js +176 -0
  98. package/log.js +12 -0
  99. package/metadata.js +392 -0
  100. package/methods.js +636 -0
  101. package/node.js +37 -0
  102. package/object.js +803 -0
  103. package/package.json +38 -22
  104. package/projectKeys.js +30 -0
  105. package/props.js +327 -0
  106. package/{src/scaling.js → scaling.js} +1 -1
  107. package/scope.js +32 -0
  108. package/sharedLibraries.js +184 -0
  109. package/state.js +203 -0
  110. package/{src/index.js → string-extra.js} +11 -17
  111. package/string.js +206 -0
  112. package/tags.js +176 -0
  113. package/triggerEvent.js +102 -0
  114. package/types.js +55 -0
  115. package/update.js +27 -0
  116. package/dist/cjs/package.json +0 -4
  117. /package/{src/browser.js → browser.js} +0 -0
  118. /package/{src/date.js → date.js} +0 -0
  119. /package/{src/fibonacci.js → fibonacci.js} +0 -0
  120. /package/{src/files.js → files.js} +0 -0
  121. /package/{src/load.js → load.js} +0 -0
  122. /package/{src/style.js → style.js} +0 -0
package/dist/esm/if.js ADDED
@@ -0,0 +1,28 @@
1
+ import { isFunction } from "./types.js";
2
+ import { exec } from "./object.js";
3
+ const createIfConditionFlag = (element, parent) => {
4
+ const { __ref: ref } = element;
5
+ const ifVal = element.if;
6
+ if (isFunction(ifVal)) {
7
+ let result;
8
+ try {
9
+ result = ifVal(element, element.state, element.context);
10
+ } catch (e) {
11
+ if (typeof console !== "undefined") console.warn("[DOMQL] if condition error:", e);
12
+ delete ref.__if;
13
+ return;
14
+ }
15
+ if (!result) {
16
+ delete ref.__if;
17
+ } else ref.__if = true;
18
+ } else if (ifVal != null && typeof ifVal === "object") {
19
+ const result = exec(ifVal, element);
20
+ if (!result) delete ref.__if;
21
+ else ref.__if = true;
22
+ } else {
23
+ ref.__if = true;
24
+ }
25
+ };
26
+ export {
27
+ createIfConditionFlag
28
+ };
@@ -0,0 +1,37 @@
1
+ export * from "./key.js";
2
+ export * from "./env.js";
3
+ export * from "./types.js";
4
+ export * from "./object.js";
5
+ export * from "./function.js";
6
+ export * from "./array.js";
7
+ export * from "./node.js";
8
+ export * from "./if.js";
9
+ export * from "./log.js";
10
+ export * from "./string.js";
11
+ export * from "./globals.js";
12
+ export * from "./cookie.js";
13
+ export * from "./tags.js";
14
+ export * from "./component.js";
15
+ export * from "./props.js";
16
+ export * from "./extends.js";
17
+ export * from "./element.js";
18
+ export * from "./state.js";
19
+ export * from "./keys.js";
20
+ export * from "./scope.js";
21
+ export * from "./methods.js";
22
+ export * from "./cache.js";
23
+ export * from "./update.js";
24
+ export * from "./triggerEvent.js";
25
+ export * from "./projectKeys.js";
26
+ export * from "./browser.js";
27
+ export * from "./cdn.js";
28
+ export * from "./date.js";
29
+ export * from "./detectHeight.js";
30
+ export * from "./fibonacci.js";
31
+ export * from "./files.js";
32
+ export * from "./load.js";
33
+ export * from "./metadata.js";
34
+ export * from "./scaling.js";
35
+ export * from "./sharedLibraries.js";
36
+ export * from "./string-extra.js";
37
+ export * from "./style.js";
@@ -0,0 +1,18 @@
1
+ import { exec } from "./object.js";
2
+ const generateKey = /* @__PURE__ */ (function() {
3
+ let index = 0;
4
+ function newId() {
5
+ index++;
6
+ return index;
7
+ }
8
+ return newId;
9
+ })();
10
+ const createSnapshotId = generateKey;
11
+ const createKey = (element, parent, key) => {
12
+ return (exec(key, element) || key || element.key || generateKey()).toString();
13
+ };
14
+ export {
15
+ createKey,
16
+ createSnapshotId,
17
+ generateKey
18
+ };
@@ -0,0 +1,181 @@
1
+ const DOMQ_PROPERTIES = /* @__PURE__ */ new Set([
2
+ "attr",
3
+ "style",
4
+ "text",
5
+ "html",
6
+ "content",
7
+ "data",
8
+ "classlist",
9
+ "state",
10
+ "scope",
11
+ "root",
12
+ "deps",
13
+ "extend",
14
+ "extends",
15
+ "$router",
16
+ "routes",
17
+ "children",
18
+ "childExtend",
19
+ "childExtends",
20
+ "childExtendRecursive",
21
+ "childExtendsRecursive",
22
+ "props",
23
+ "if",
24
+ "define",
25
+ "__name",
26
+ "__ref",
27
+ "__hash",
28
+ "__text",
29
+ "key",
30
+ "tag",
31
+ "query",
32
+ "parent",
33
+ "node",
34
+ "variables",
35
+ "on",
36
+ "fetch",
37
+ "component",
38
+ "context",
39
+ "preventContentUpdate",
40
+ "preventContentRecreate"
41
+ ]);
42
+ const PARSED_DOMQ_PROPERTIES = /* @__PURE__ */ new Set([
43
+ "attr",
44
+ "style",
45
+ "text",
46
+ "html",
47
+ "content",
48
+ "data",
49
+ "class",
50
+ "state",
51
+ "scope",
52
+ "children",
53
+ "props",
54
+ "if",
55
+ "key",
56
+ "tag",
57
+ "query",
58
+ "on",
59
+ "context"
60
+ ]);
61
+ const STATE_PROPERTIES = [
62
+ "ref",
63
+ "parent",
64
+ "__element",
65
+ "__depends",
66
+ "__ref",
67
+ "__children",
68
+ "root"
69
+ ];
70
+ const STATE_METHODS = /* @__PURE__ */ new Set([
71
+ "update",
72
+ "parse",
73
+ "clean",
74
+ "create",
75
+ "destroy",
76
+ "add",
77
+ "toggle",
78
+ "remove",
79
+ "apply",
80
+ "set",
81
+ "reset",
82
+ "replace",
83
+ "quietReplace",
84
+ "quietUpdate",
85
+ "applyReplace",
86
+ "applyFunction",
87
+ "keys",
88
+ "values",
89
+ "ref",
90
+ "rootUpdate",
91
+ "parentUpdate",
92
+ "parent",
93
+ "__element",
94
+ "__depends",
95
+ "__ref",
96
+ "__children",
97
+ "root",
98
+ "setByPath",
99
+ "setPathCollection",
100
+ "removeByPath",
101
+ "removePathCollection",
102
+ "getByPath"
103
+ ]);
104
+ const PROPS_METHODS = /* @__PURE__ */ new Set(["update", "__element"]);
105
+ const METHODS = /* @__PURE__ */ new Set([
106
+ "set",
107
+ "reset",
108
+ "update",
109
+ "remove",
110
+ "updateContent",
111
+ "removeContent",
112
+ "lookup",
113
+ "lookdown",
114
+ "lookdownAll",
115
+ "getRef",
116
+ "getPath",
117
+ "setNodeStyles",
118
+ "spotByPath",
119
+ "keys",
120
+ "parse",
121
+ "setProps",
122
+ "parseDeep",
123
+ "variables",
124
+ "if",
125
+ "log",
126
+ "verbose",
127
+ "warn",
128
+ "error",
129
+ "call",
130
+ "nextElement",
131
+ "previousElement",
132
+ "getRootState",
133
+ "getRoot",
134
+ "getRootData",
135
+ "getRootContext",
136
+ "getContext",
137
+ "getQuery",
138
+ "getDB",
139
+ "getChildren",
140
+ "preventContentUpdate",
141
+ "preventContentRecreate"
142
+ ]);
143
+ const METHODS_EXL = /* @__PURE__ */ new Set([
144
+ "node",
145
+ "context",
146
+ "extends",
147
+ "__element",
148
+ "__ref",
149
+ ...METHODS,
150
+ ...STATE_METHODS,
151
+ ...PROPS_METHODS
152
+ ]);
153
+ const DOMQL_EVENTS = /* @__PURE__ */ new Set([
154
+ "init",
155
+ "beforeClassAssign",
156
+ "render",
157
+ "renderRouter",
158
+ "attachNode",
159
+ "stateInit",
160
+ "stateCreated",
161
+ "beforeStateUpdate",
162
+ "stateUpdate",
163
+ "beforeUpdate",
164
+ "done",
165
+ "create",
166
+ "complete",
167
+ "frame",
168
+ "update",
169
+ "fetchError",
170
+ "fetchComplete"
171
+ ]);
172
+ export {
173
+ DOMQL_EVENTS,
174
+ DOMQ_PROPERTIES,
175
+ METHODS,
176
+ METHODS_EXL,
177
+ PARSED_DOMQ_PROPERTIES,
178
+ PROPS_METHODS,
179
+ STATE_METHODS,
180
+ STATE_PROPERTIES
181
+ };
@@ -0,0 +1,151 @@
1
+ const loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
2
+ return new Promise((resolve, reject) => {
3
+ try {
4
+ const scriptEle = doc.createElement("script");
5
+ scriptEle.type = type;
6
+ scriptEle.async = async;
7
+ scriptEle.src = FILE_URL;
8
+ scriptEle.addEventListener("load", (ev) => {
9
+ resolve({
10
+ status: true
11
+ });
12
+ });
13
+ scriptEle.addEventListener("error", (ev) => {
14
+ reject(
15
+ new Error({
16
+ status: false,
17
+ message: `Failed to load the script ${FILE_URL}`
18
+ })
19
+ );
20
+ });
21
+ doc.body.appendChild(scriptEle);
22
+ } catch (error) {
23
+ reject(error);
24
+ }
25
+ });
26
+ };
27
+ const loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript") => {
28
+ return new Promise((resolve, reject) => {
29
+ const scriptEle = doc.createElement("script");
30
+ scriptEle.type = type;
31
+ scriptEle.src = fileUrl;
32
+ const blocker = doc.createElement("div");
33
+ blocker.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(255,255,255,0.8);z-index:9999;";
34
+ doc.body.appendChild(blocker);
35
+ scriptEle.onload = () => {
36
+ console.log(`Successfully loaded: ${fileUrl}`);
37
+ doc.body.removeChild(blocker);
38
+ resolve();
39
+ };
40
+ scriptEle.onerror = () => {
41
+ doc.body.removeChild(blocker);
42
+ reject(new Error(`Failed to load: ${fileUrl}`));
43
+ };
44
+ doc.body.appendChild(scriptEle);
45
+ });
46
+ };
47
+ const loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "text/javascript") => {
48
+ const xhr = new window.XMLHttpRequest();
49
+ xhr.open("GET", FILE_URL, false);
50
+ xhr.send();
51
+ if (xhr.status === 200) {
52
+ const scriptEle = doc.createElement("script");
53
+ scriptEle.type = type;
54
+ scriptEle.text = xhr.responseText;
55
+ doc.body.appendChild(scriptEle);
56
+ if (typeof fallback === "function") fallback();
57
+ } else {
58
+ throw new Error(`Failed to load the script ${FILE_URL}`);
59
+ }
60
+ };
61
+ const loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
62
+ return new Promise((resolve, reject) => {
63
+ try {
64
+ const linkElem = doc.createElement("link");
65
+ linkElem.rel = "stylesheet";
66
+ linkElem.href = FILE_URL;
67
+ linkElem.addEventListener("load", (ev) => {
68
+ resolve({
69
+ status: true
70
+ });
71
+ });
72
+ doc.head.appendChild(linkElem);
73
+ } catch (error) {
74
+ reject(error);
75
+ }
76
+ });
77
+ };
78
+ const loadJavascript = (body, async = false, doc = document, type = "text/javascript", id = "smbls-script") => {
79
+ try {
80
+ const scriptEle = doc.createElement("script");
81
+ scriptEle.type = type;
82
+ scriptEle.async = async;
83
+ scriptEle.id = id;
84
+ scriptEle.innerHTML = body;
85
+ doc.body.appendChild(scriptEle);
86
+ } catch (error) {
87
+ console.warn(error);
88
+ }
89
+ };
90
+ function loadRemoteScript(url, options = {}) {
91
+ const { window: window2 = globalThis } = options;
92
+ const { document: document2 = window2.document } = options;
93
+ return new Promise((resolve, reject) => {
94
+ const existingScript = document2.querySelector(`script[src="${url}"]`);
95
+ if (existingScript) {
96
+ return resolve(existingScript);
97
+ }
98
+ const script = document2.createElement("script");
99
+ script.src = url;
100
+ script.async = options.async === true;
101
+ script.type = options.type || "text/javascript";
102
+ if (options.id) script.id = options.id;
103
+ if (options.integrity) script.integrity = options.integrity;
104
+ if (options.crossOrigin) script.crossOrigin = options.crossOrigin;
105
+ script.onload = () => {
106
+ script.onerror = script.onload = null;
107
+ resolve(script);
108
+ };
109
+ script.onerror = () => {
110
+ script.onerror = script.onload = null;
111
+ reject(new Error(`Failed to load script: ${url}`));
112
+ };
113
+ document2.head.appendChild(script);
114
+ });
115
+ }
116
+ async function loadRemoteCSS(url, options = {}) {
117
+ const { window: window2 = globalThis } = options;
118
+ const { document: document2 = window2.document } = options;
119
+ return new Promise((resolve, reject) => {
120
+ const existingLink = document2.querySelector(`link[href="${url}"]`);
121
+ if (existingLink) {
122
+ return resolve(existingLink);
123
+ }
124
+ const link = document2.createElement("link");
125
+ link.href = url;
126
+ link.rel = options.rel || "stylesheet";
127
+ link.type = "text/css";
128
+ link.media = options.media || "all";
129
+ if (options.id) link.id = options.id;
130
+ if (options.integrity) link.integrity = options.integrity;
131
+ if (options.crossOrigin) link.crossOrigin = options.crossOrigin;
132
+ link.onload = () => {
133
+ link.onerror = link.onload = null;
134
+ resolve(link);
135
+ };
136
+ link.onerror = () => {
137
+ link.onerror = link.onload = null;
138
+ reject(new Error(`Failed to load stylesheet: ${url}`));
139
+ };
140
+ document2.head.appendChild(link);
141
+ });
142
+ }
143
+ export {
144
+ loadCssFile,
145
+ loadJavascript,
146
+ loadJavascriptFile,
147
+ loadJavascriptFileEmbedSync,
148
+ loadJavascriptFileSync,
149
+ loadRemoteCSS,
150
+ loadRemoteScript
151
+ };
@@ -0,0 +1,14 @@
1
+ const logIf = (bool, ...arg) => {
2
+ if (bool) arg.map((v) => console.log(v));
3
+ };
4
+ const logGroupIf = (bool, key, ...arg) => {
5
+ if (bool) {
6
+ console.group(key);
7
+ arg.map((v) => console.log(v));
8
+ console.groupEnd(key);
9
+ }
10
+ };
11
+ export {
12
+ logGroupIf,
13
+ logIf
14
+ };