@symbo.ls/utils 3.14.2 → 3.14.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/array.cjs +1 -0
  3. package/dist/cjs/assets.cjs +1 -0
  4. package/dist/cjs/browser.cjs +1 -0
  5. package/dist/cjs/cache.cjs +1 -0
  6. package/dist/cjs/cdn.cjs +3 -0
  7. package/dist/cjs/component.cjs +1 -0
  8. package/dist/cjs/cookie.cjs +1 -0
  9. package/dist/cjs/date.cjs +1 -0
  10. package/dist/cjs/detectHeight.cjs +1 -0
  11. package/dist/cjs/element.cjs +1 -0
  12. package/dist/cjs/env.cjs +2 -0
  13. package/dist/cjs/events.cjs +1 -0
  14. package/dist/cjs/extends.cjs +1 -0
  15. package/dist/cjs/fibonacci.cjs +1 -0
  16. package/dist/cjs/files.cjs +1 -0
  17. package/dist/cjs/function.cjs +1 -0
  18. package/dist/cjs/globals.cjs +1 -0
  19. package/dist/cjs/if.cjs +1 -0
  20. package/dist/cjs/index.cjs +1 -0
  21. package/dist/cjs/key.cjs +1 -0
  22. package/dist/cjs/keys.cjs +1 -0
  23. package/dist/cjs/load.cjs +1 -0
  24. package/dist/cjs/log.cjs +1 -0
  25. package/dist/cjs/metadata.cjs +2 -0
  26. package/dist/cjs/methods.cjs +10 -0
  27. package/dist/cjs/node.cjs +1 -0
  28. package/dist/cjs/object.cjs +12 -0
  29. package/dist/cjs/projectKeys.cjs +1 -0
  30. package/dist/cjs/props.cjs +1 -0
  31. package/dist/cjs/scaling.cjs +1 -0
  32. package/dist/cjs/scope.cjs +1 -0
  33. package/dist/cjs/sharedLibraries.cjs +1 -0
  34. package/dist/cjs/state.cjs +1 -0
  35. package/dist/cjs/string-extra.cjs +1 -0
  36. package/dist/cjs/string.cjs +3 -0
  37. package/dist/cjs/style.cjs +1 -0
  38. package/dist/cjs/tags.cjs +1 -0
  39. package/dist/cjs/triggerEvent.cjs +1 -0
  40. package/dist/cjs/types.cjs +1 -0
  41. package/dist/cjs/update.cjs +1 -0
  42. package/dist/esm/array.js +1 -0
  43. package/dist/esm/assets.js +1 -0
  44. package/dist/esm/browser.js +1 -0
  45. package/dist/esm/cache.js +1 -0
  46. package/dist/esm/cdn.js +3 -0
  47. package/dist/esm/component.js +1 -0
  48. package/dist/esm/cookie.js +1 -0
  49. package/dist/esm/date.js +1 -0
  50. package/dist/esm/detectHeight.js +1 -0
  51. package/dist/esm/element.js +1 -0
  52. package/dist/esm/env.js +2 -0
  53. package/dist/esm/events.js +1 -0
  54. package/dist/esm/extends.js +1 -0
  55. package/dist/esm/fibonacci.js +1 -0
  56. package/dist/esm/files.js +1 -0
  57. package/dist/esm/function.js +1 -0
  58. package/dist/esm/globals.js +1 -0
  59. package/dist/esm/if.js +1 -0
  60. package/dist/esm/index.js +1 -0
  61. package/dist/esm/key.js +1 -0
  62. package/dist/esm/keys.js +1 -0
  63. package/dist/esm/load.js +1 -0
  64. package/dist/esm/log.js +1 -0
  65. package/dist/esm/metadata.js +2 -0
  66. package/dist/esm/methods.js +10 -0
  67. package/dist/esm/node.js +1 -0
  68. package/dist/esm/object.js +12 -0
  69. package/dist/esm/projectKeys.js +1 -0
  70. package/dist/esm/props.js +1 -0
  71. package/dist/esm/scaling.js +1 -0
  72. package/dist/esm/scope.js +1 -0
  73. package/dist/esm/sharedLibraries.js +1 -0
  74. package/dist/esm/state.js +1 -0
  75. package/dist/esm/string-extra.js +1 -0
  76. package/dist/esm/string.js +3 -0
  77. package/dist/esm/style.js +1 -0
  78. package/dist/esm/tags.js +1 -0
  79. package/dist/esm/triggerEvent.js +1 -0
  80. package/dist/esm/types.js +1 -0
  81. package/dist/esm/update.js +1 -0
  82. package/package.json +35 -18
  83. package/array.js +0 -162
  84. package/assets.js +0 -117
  85. package/browser.js +0 -13
  86. package/cache.js +0 -7
  87. package/cdn.js +0 -83
  88. package/component.js +0 -25
  89. package/cookie.js +0 -78
  90. package/date.js +0 -10
  91. package/detectHeight.js +0 -42
  92. package/element.js +0 -148
  93. package/env.js +0 -15
  94. package/events.js +0 -19
  95. package/extends.js +0 -519
  96. package/fibonacci.js +0 -9
  97. package/files.js +0 -3
  98. package/function.js +0 -145
  99. package/globals.js +0 -8
  100. package/if.js +0 -30
  101. package/index.js +0 -42
  102. package/key.js +0 -20
  103. package/keys.js +0 -176
  104. package/load.js +0 -236
  105. package/log.js +0 -12
  106. package/metadata.js +0 -392
  107. package/methods.js +0 -684
  108. package/node.js +0 -37
  109. package/object.js +0 -837
  110. package/projectKeys.js +0 -30
  111. package/props.js +0 -327
  112. package/scaling.js +0 -15
  113. package/scope.js +0 -32
  114. package/sharedLibraries.js +0 -184
  115. package/state.js +0 -203
  116. package/string-extra.js +0 -69
  117. package/string.js +0 -206
  118. package/style.js +0 -23
  119. package/tags.js +0 -176
  120. package/triggerEvent.js +0 -102
  121. package/types.js +0 -55
  122. package/update.js +0 -27
package/if.js DELETED
@@ -1,30 +0,0 @@
1
- 'use strict'
2
-
3
- import { isFunction } from './types.js'
4
- import { exec } from './object.js'
5
-
6
- export const createIfConditionFlag = (element, parent) => {
7
- const { __ref: ref } = element
8
- const ifVal = element.if
9
-
10
- if (isFunction(ifVal)) {
11
- let result
12
- try {
13
- result = ifVal(element, element.state, element.context)
14
- } catch (e) {
15
- if (typeof console !== 'undefined') console.warn('[DOMQL] if condition error:', e)
16
- delete ref.__if
17
- return
18
- }
19
- if (!result) {
20
- delete ref.__if
21
- } else ref.__if = true
22
- } else if (ifVal != null && typeof ifVal === 'object') {
23
- // funcql schema — evaluate via exec() which delegates to plugins
24
- const result = exec(ifVal, element)
25
- if (!result) delete ref.__if
26
- else ref.__if = true
27
- } else {
28
- ref.__if = true
29
- }
30
- }
package/index.js DELETED
@@ -1,42 +0,0 @@
1
- 'use strict'
2
-
3
- export * from './key.js'
4
- export * from './env.js'
5
- export * from './types.js'
6
- export * from './object.js'
7
- export * from './function.js'
8
- export * from './array.js'
9
- export * from './node.js'
10
- export * from './if.js'
11
- export * from './log.js'
12
- export * from './string.js'
13
- export * from './globals.js'
14
- export * from './cookie.js'
15
- export * from './tags.js'
16
- export * from './component.js'
17
- export * from './props.js'
18
- export * from './extends.js'
19
- export * from './element.js'
20
- export * from './state.js'
21
- export * from './keys.js'
22
- export * from './scope.js'
23
- export * from './methods.js'
24
- export * from './cache.js'
25
- export * from './update.js'
26
- export * from './triggerEvent.js'
27
- export * from './projectKeys.js'
28
-
29
- // ── Merged from the former @symbo.ls/smbls-utils package (4.x) ────────────
30
- export * from './browser.js'
31
- export * from './cdn.js'
32
- export * from './date.js'
33
- export * from './detectHeight.js'
34
- export * from './fibonacci.js'
35
- export * from './files.js'
36
- export * from './load.js'
37
- export * from './metadata.js'
38
- export * from './scaling.js'
39
- export * from './sharedLibraries.js'
40
- export * from './string-extra.js'
41
- export * from './style.js'
42
- export * from './assets.js'
package/key.js DELETED
@@ -1,20 +0,0 @@
1
- 'use strict'
2
-
3
- import { exec } from './object.js'
4
-
5
- export const generateKey = (function () {
6
- let index = 0
7
-
8
- function newId () {
9
- index++
10
- return index
11
- }
12
-
13
- return newId
14
- })()
15
-
16
- export const createSnapshotId = generateKey
17
-
18
- export const createKey = (element, parent, key) => {
19
- return (exec(key, element) || key || element.key || generateKey()).toString()
20
- }
package/keys.js DELETED
@@ -1,176 +0,0 @@
1
- 'use strict'
2
-
3
- export const DOMQ_PROPERTIES = new Set([
4
- 'attr',
5
- 'style',
6
- 'text',
7
- 'html',
8
- 'content',
9
- 'data',
10
- 'classlist',
11
- 'state',
12
- 'scope',
13
- 'root',
14
- 'deps',
15
- 'extend',
16
- 'extends',
17
- '$router',
18
- 'routes',
19
- 'children',
20
- 'childExtend',
21
- 'childExtends',
22
- 'childExtendRecursive',
23
- 'childExtendsRecursive',
24
- 'props',
25
- 'if',
26
- 'define',
27
- '__name',
28
- '__ref',
29
- '__hash',
30
- '__text',
31
- 'key',
32
- 'tag',
33
- 'query',
34
- 'parent',
35
- 'node',
36
- 'variables',
37
- 'on',
38
- 'fetch',
39
- 'component',
40
- 'context',
41
- 'preventContentUpdate',
42
- 'preventContentRecreate'
43
- ])
44
-
45
- export const PARSED_DOMQ_PROPERTIES = new Set([
46
- 'attr',
47
- 'style',
48
- 'text',
49
- 'html',
50
- 'content',
51
- 'data',
52
- 'class',
53
- 'state',
54
- 'scope',
55
- 'children',
56
- 'props',
57
- 'if',
58
- 'key',
59
- 'tag',
60
- 'query',
61
- 'on',
62
- 'context'
63
- ])
64
-
65
- export const STATE_PROPERTIES = [
66
- 'ref',
67
- 'parent',
68
- '__element',
69
- '__depends',
70
- '__ref',
71
- '__children',
72
- 'root'
73
- ]
74
-
75
- export const STATE_METHODS = new Set([
76
- 'update',
77
- 'parse',
78
- 'clean',
79
- 'create',
80
- 'destroy',
81
- 'add',
82
- 'toggle',
83
- 'remove',
84
- 'apply',
85
- 'set',
86
- 'reset',
87
- 'replace',
88
- 'quietReplace',
89
- 'quietUpdate',
90
- 'applyReplace',
91
- 'applyFunction',
92
- 'keys',
93
- 'values',
94
- 'ref',
95
- 'rootUpdate',
96
- 'parentUpdate',
97
- 'parent',
98
- '__element',
99
- '__depends',
100
- '__ref',
101
- '__children',
102
- 'root',
103
- 'setByPath',
104
- 'setPathCollection',
105
- 'removeByPath',
106
- 'removePathCollection',
107
- 'getByPath'
108
- ])
109
-
110
- export const PROPS_METHODS = new Set(['update', '__element'])
111
-
112
- export const METHODS = new Set([
113
- 'set',
114
- 'reset',
115
- 'update',
116
- 'remove',
117
- 'updateContent',
118
- 'removeContent',
119
- 'lookup',
120
- 'lookdown',
121
- 'lookdownAll',
122
- 'getRef',
123
- 'getPath',
124
- 'setNodeStyles',
125
- 'spotByPath',
126
- 'keys',
127
- 'parse',
128
- 'setProps',
129
- 'parseDeep',
130
- 'variables',
131
- 'if',
132
- 'log',
133
- 'verbose',
134
- 'warn',
135
- 'error',
136
- 'call',
137
- 'nextElement',
138
- 'previousElement',
139
- 'getRootState',
140
- 'getRoot',
141
- 'getRootData',
142
- 'getRootContext',
143
- 'getContext',
144
- 'getQuery',
145
- 'getDB',
146
- 'getChildren',
147
- 'preventContentUpdate',
148
- 'preventContentRecreate'
149
- ])
150
-
151
- export const METHODS_EXL = new Set([
152
- 'node', 'context', 'extends', '__element', '__ref',
153
- ...METHODS,
154
- ...STATE_METHODS,
155
- ...PROPS_METHODS
156
- ])
157
-
158
- export const DOMQL_EVENTS = new Set([
159
- 'init',
160
- 'beforeClassAssign',
161
- 'render',
162
- 'renderRouter',
163
- 'attachNode',
164
- 'stateInit',
165
- 'stateCreated',
166
- 'beforeStateUpdate',
167
- 'stateUpdate',
168
- 'beforeUpdate',
169
- 'done',
170
- 'create',
171
- 'complete',
172
- 'frame',
173
- 'update',
174
- 'fetchError',
175
- 'fetchComplete'
176
- ])
package/load.js DELETED
@@ -1,236 +0,0 @@
1
- 'use strict'
2
-
3
- export const loadJavascriptFile = (
4
- FILE_URL,
5
- async = false,
6
- doc = document,
7
- type = 'text/javascript'
8
- ) => {
9
- return new Promise((resolve, reject) => {
10
- try {
11
- const scriptEle = doc.createElement('script')
12
- scriptEle.type = type
13
- scriptEle.async = async
14
- scriptEle.src = FILE_URL
15
-
16
- scriptEle.addEventListener('load', ev => {
17
- resolve({
18
- status: true
19
- })
20
- })
21
-
22
- scriptEle.addEventListener('error', ev => {
23
- reject(
24
- new Error({
25
- status: false,
26
- message: `Failed to load the script ${FILE_URL}`
27
- })
28
- )
29
- })
30
-
31
- doc.body.appendChild(scriptEle)
32
- } catch (error) {
33
- reject(error)
34
- }
35
- })
36
- }
37
-
38
- export const loadJavascriptFileSync = (
39
- fileUrl,
40
- doc = document,
41
- type = 'text/javascript'
42
- ) => {
43
- return new Promise((resolve, reject) => {
44
- const scriptEle = doc.createElement('script')
45
- scriptEle.type = type
46
- scriptEle.src = fileUrl
47
-
48
- // Create a blocking overlay
49
- const blocker = doc.createElement('div')
50
- blocker.style.cssText =
51
- 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(255,255,255,0.8);z-index:9999;'
52
- doc.body.appendChild(blocker)
53
-
54
- scriptEle.onload = () => {
55
- console.log(`Successfully loaded: ${fileUrl}`)
56
- doc.body.removeChild(blocker)
57
- resolve()
58
- }
59
-
60
- scriptEle.onerror = () => {
61
- doc.body.removeChild(blocker)
62
- reject(new Error(`Failed to load: ${fileUrl}`))
63
- }
64
-
65
- doc.body.appendChild(scriptEle)
66
- })
67
- }
68
-
69
- export const loadJavascriptFileEmbedSync = (
70
- FILE_URL,
71
- doc = document,
72
- fallback,
73
- type = 'text/javascript'
74
- ) => {
75
- const xhr = new window.XMLHttpRequest()
76
- xhr.open('GET', FILE_URL, false) // false makes the request synchronous
77
- xhr.send()
78
-
79
- if (xhr.status === 200) {
80
- const scriptEle = doc.createElement('script')
81
- scriptEle.type = type
82
- scriptEle.text = xhr.responseText
83
- doc.body.appendChild(scriptEle)
84
- if (typeof fallback === 'function') fallback()
85
- } else {
86
- throw new Error(`Failed to load the script ${FILE_URL}`)
87
- }
88
- }
89
-
90
- export const loadCssFile = (
91
- FILE_URL,
92
- async = false,
93
- doc = document,
94
- type = 'text/javascript'
95
- ) => {
96
- return new Promise((resolve, reject) => {
97
- try {
98
- const linkElem = doc.createElement('link')
99
- linkElem.rel = 'stylesheet'
100
- linkElem.href = FILE_URL
101
-
102
- linkElem.addEventListener('load', ev => {
103
- resolve({
104
- status: true
105
- })
106
- })
107
-
108
- doc.head.appendChild(linkElem)
109
- } catch (error) {
110
- reject(error)
111
- }
112
- })
113
- }
114
-
115
- export const loadJavascript = (
116
- body,
117
- async = false,
118
- doc = document,
119
- type = 'text/javascript',
120
- id = 'smbls-script'
121
- ) => {
122
- try {
123
- const scriptEle = doc.createElement('script')
124
- scriptEle.type = type
125
- scriptEle.async = async
126
- scriptEle.id = id
127
- scriptEle.innerHTML = body
128
-
129
- doc.body.appendChild(scriptEle)
130
- } catch (error) {
131
- console.warn(error)
132
- }
133
- }
134
-
135
- /**
136
- * Dynamically loads a remote JavaScript file and returns a Promise
137
- * that resolves when the script has completely loaded or rejects on error.
138
- *
139
- * @param {string} url - The URL of the remote JavaScript file to load
140
- * @param {Object} [options] - Optional configuration
141
- * @param {string} [options.id] - Optional ID to assign to the script element
142
- * @param {boolean} [options.async=true] - Whether to load the script asynchronously
143
- * @param {string} [options.type='text/javascript'] - The type attribute for the script
144
- * @param {string} [options.integrity] - Optional integrity hash for SRI
145
- * @param {string} [options.crossOrigin] - Optional crossorigin attribute
146
- * @return {Promise} A promise that resolves when the script loads or rejects on error
147
- */
148
- export function loadRemoteScript (url, options = {}) {
149
- const { window = globalThis } = options
150
- const { document = window.document } = options
151
-
152
- return new Promise((resolve, reject) => {
153
- // Check if script is already loaded
154
- const existingScript = document.querySelector(`script[src="${url}"]`)
155
- if (existingScript) {
156
- return resolve(existingScript)
157
- }
158
-
159
- // Create script element
160
- const script = document.createElement('script')
161
- script.src = url
162
- script.async = options.async === true
163
- script.type = options.type || 'text/javascript'
164
-
165
- // Add optional attributes
166
- if (options.id) script.id = options.id
167
- if (options.integrity) script.integrity = options.integrity
168
- if (options.crossOrigin) script.crossOrigin = options.crossOrigin
169
-
170
- // Setup load and error handlers
171
- script.onload = () => {
172
- script.onerror = script.onload = null
173
- resolve(script)
174
- }
175
-
176
- script.onerror = () => {
177
- script.onerror = script.onload = null
178
- reject(new Error(`Failed to load script: ${url}`))
179
- }
180
-
181
- // Append the script to the document head
182
- document.head.appendChild(script)
183
- })
184
- }
185
-
186
- /**
187
- * Dynamically loads a remote CSS file and returns a Promise
188
- * that resolves when the stylesheet has completely loaded or rejects on error.
189
- *
190
- * @param {string} url - The URL of the remote CSS file to load
191
- * @param {Object} [options] - Optional configuration
192
- * @param {string} [options.id] - Optional ID to assign to the link element
193
- * @param {string} [options.rel='stylesheet'] - The rel attribute for the link
194
- * @param {string} [options.media='all'] - The media attribute
195
- * @param {string} [options.integrity] - Optional integrity hash for SRI
196
- * @param {string} [options.crossOrigin] - Optional crossorigin attribute
197
- * @return {Promise} A promise that resolves when the stylesheet loads or rejects on error
198
- */
199
- export async function loadRemoteCSS (url, options = {}) {
200
- const { window = globalThis } = options
201
- const { document = window.document } = options
202
-
203
- return new Promise((resolve, reject) => {
204
- // Check if stylesheet is already loaded
205
- const existingLink = document.querySelector(`link[href="${url}"]`)
206
- if (existingLink) {
207
- return resolve(existingLink)
208
- }
209
-
210
- // Create link element
211
- const link = document.createElement('link')
212
- link.href = url
213
- link.rel = options.rel || 'stylesheet'
214
- link.type = 'text/css'
215
- link.media = options.media || 'all'
216
-
217
- // Add optional attributes
218
- if (options.id) link.id = options.id
219
- if (options.integrity) link.integrity = options.integrity
220
- if (options.crossOrigin) link.crossOrigin = options.crossOrigin
221
-
222
- // Setup load and error handlers
223
- link.onload = () => {
224
- link.onerror = link.onload = null
225
- resolve(link)
226
- }
227
-
228
- link.onerror = () => {
229
- link.onerror = link.onload = null
230
- reject(new Error(`Failed to load stylesheet: ${url}`))
231
- }
232
-
233
- // Append the link to the document head
234
- document.head.appendChild(link)
235
- })
236
- }
package/log.js DELETED
@@ -1,12 +0,0 @@
1
- 'use strict'
2
-
3
- export const logIf = (bool, ...arg) => {
4
- if (bool) arg.map(v => console.log(v))
5
- }
6
- export const logGroupIf = (bool, key, ...arg) => {
7
- if (bool) {
8
- console.group(key)
9
- arg.map(v => console.log(v))
10
- console.groupEnd(key)
11
- }
12
- }