@symbo.ls/utils 3.1.2 → 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 (124) 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/detectHeight.js +42 -0
  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 +22 -13
  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 -371
  27. package/dist/cjs/key.js +38 -0
  28. package/dist/cjs/keys.js +201 -0
  29. package/dist/cjs/load.js +67 -12
  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/load.js +236 -0
  99. package/log.js +12 -0
  100. package/metadata.js +392 -0
  101. package/methods.js +636 -0
  102. package/node.js +37 -0
  103. package/object.js +803 -0
  104. package/package.json +38 -22
  105. package/projectKeys.js +30 -0
  106. package/props.js +327 -0
  107. package/{src/scaling.js → scaling.js} +1 -1
  108. package/scope.js +32 -0
  109. package/sharedLibraries.js +184 -0
  110. package/state.js +203 -0
  111. package/{src/index.js → string-extra.js} +22 -25
  112. package/string.js +206 -0
  113. package/tags.js +176 -0
  114. package/triggerEvent.js +102 -0
  115. package/types.js +55 -0
  116. package/update.js +27 -0
  117. package/dist/cjs/package.json +0 -4
  118. package/src/detectHeight.js +0 -31
  119. package/src/load.js +0 -105
  120. /package/{src/browser.js → browser.js} +0 -0
  121. /package/{src/date.js → date.js} +0 -0
  122. /package/{src/fibonacci.js → fibonacci.js} +0 -0
  123. /package/{src/files.js → files.js} +0 -0
  124. /package/{src/style.js → style.js} +0 -0
@@ -0,0 +1,102 @@
1
+ 'use strict'
2
+
3
+ import { isFunction } from './types.js'
4
+ import { resolveHandler, runPluginHook } from './function.js'
5
+
6
+ const getOnOrPropsEvent = (param, element) => {
7
+ const propKey = 'on' + param.charAt(0).toUpperCase() + param.slice(1)
8
+ return element[propKey]
9
+ }
10
+
11
+ export const applyEvent = (param, element, state, context, options) => {
12
+ param = resolveHandler(param, element)
13
+ if (!isFunction(param)) return
14
+ try {
15
+ const result = param.call(
16
+ element,
17
+ element,
18
+ state || element.state,
19
+ context || element.context,
20
+ options
21
+ )
22
+ if (result && typeof result.then === 'function') {
23
+ result.catch((err) => {
24
+ element.error = err
25
+ if (err instanceof ReferenceError) console.warn('[DOMQL] Async event warning:', err.message)
26
+ else console.error('[DOMQL] Async event error:', err)
27
+ })
28
+ }
29
+ return result
30
+ } catch (err) {
31
+ element.error = err
32
+ // In SSR/brender mode, ReferenceErrors for missing client-only helpers
33
+ // are expected (e.g. DOM animation functions). Log concisely.
34
+ if (err instanceof ReferenceError) {
35
+ console.warn('[DOMQL] Event handler warning:', err.message)
36
+ } else {
37
+ console.error('[DOMQL] Event handler error:', err)
38
+ }
39
+ if (element.context?.strictMode) throw err
40
+ }
41
+ }
42
+
43
+ export const triggerEventOn = (param, element, options) => {
44
+ if (!element) {
45
+ throw new Error('Element is required')
46
+ }
47
+ runPluginHook(param, element, options)
48
+ const appliedFunction = getOnOrPropsEvent(param, element)
49
+ if (appliedFunction) {
50
+ const { state, context } = element
51
+ return applyEvent(appliedFunction, element, state, context, options)
52
+ }
53
+ }
54
+
55
+ export const applyEventUpdate = (
56
+ param,
57
+ updatedObj,
58
+ element,
59
+ state,
60
+ context,
61
+ options
62
+ ) => {
63
+ param = resolveHandler(param, element)
64
+ if (!isFunction(param)) return
65
+ try {
66
+ const result = param.call(
67
+ element,
68
+ updatedObj,
69
+ element,
70
+ state || element.state,
71
+ context || element.context,
72
+ options
73
+ )
74
+ if (result && typeof result.then === 'function') {
75
+ result.catch((err) => {
76
+ element.error = err
77
+ console.error('[DOMQL] Async event update error:', err)
78
+ })
79
+ }
80
+ return result
81
+ } catch (err) {
82
+ element.error = err
83
+ console.error('[DOMQL] Event update error:', err)
84
+ if (element.context?.strictMode) throw err
85
+ }
86
+ }
87
+
88
+ export const triggerEventOnUpdate = (param, updatedObj, element, options) => {
89
+ runPluginHook(param, element, updatedObj, options)
90
+ const appliedFunction = getOnOrPropsEvent(param, element)
91
+ if (appliedFunction) {
92
+ const { state, context } = element
93
+ return applyEventUpdate(
94
+ appliedFunction,
95
+ updatedObj,
96
+ element,
97
+ state,
98
+ context,
99
+ options
100
+ )
101
+ }
102
+ }
package/types.js ADDED
@@ -0,0 +1,55 @@
1
+ 'use strict'
2
+
3
+ import { isHtmlElement, isNode } from './node.js'
4
+
5
+ export const isObject = arg => {
6
+ if (arg === null) return false
7
+ return typeof arg === 'object' && arg.constructor === Object
8
+ }
9
+
10
+ export const isString = arg => typeof arg === 'string'
11
+
12
+ export const isNumber = arg => typeof arg === 'number'
13
+
14
+ export const isFunction = arg => typeof arg === 'function'
15
+
16
+ export const isBoolean = arg => arg === true || arg === false
17
+
18
+ export const isNull = arg => arg === null
19
+
20
+ export const isArray = arg => Array.isArray(arg)
21
+
22
+ export const isDate = d => d instanceof Date
23
+
24
+ export const isObjectLike = arg => {
25
+ if (arg === null) return false
26
+ // if (isArray(arg)) return false
27
+ return typeof arg === 'object'
28
+ }
29
+
30
+ export const isDefined = arg => arg !== undefined
31
+
32
+ export const isUndefined = arg => arg === undefined
33
+
34
+ export const TYPES = {
35
+ boolean: isBoolean,
36
+ array: isArray,
37
+ object: isObject,
38
+ string: isString,
39
+ date: isDate,
40
+ number: isNumber,
41
+ null: isNull,
42
+ function: isFunction,
43
+ objectLike: isObjectLike,
44
+ node: isNode,
45
+ htmlElement: isHtmlElement,
46
+ defined: isDefined
47
+ }
48
+
49
+ export const is = arg => {
50
+ return (...args) => args.some(val => TYPES[val](arg))
51
+ }
52
+
53
+ export const isNot = arg => {
54
+ return (...args) => !args.some(val => TYPES[val](arg))
55
+ }
package/update.js ADDED
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ import { createSnapshotId } from './key.js'
4
+
5
+ const snapshot = {
6
+ snapshotId: createSnapshotId
7
+ }
8
+
9
+ export const captureSnapshot = (element, options) => {
10
+ const ref = element.__ref
11
+
12
+ const { currentSnapshot, calleeElement } = options
13
+ const isCallee = calleeElement === element
14
+ if (!calleeElement || isCallee) {
15
+ const createdStanpshot = snapshot.snapshotId()
16
+ ref.__currentSnapshot = createdStanpshot
17
+ return [createdStanpshot, element]
18
+ }
19
+
20
+ const snapshotOnCallee = calleeElement.__ref.__currentSnapshot
21
+
22
+ if (currentSnapshot < snapshotOnCallee) {
23
+ return [snapshotOnCallee, calleeElement, true]
24
+ }
25
+
26
+ return [snapshotOnCallee, calleeElement]
27
+ }
@@ -1,4 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "main": "index.js"
4
- }
@@ -1,31 +0,0 @@
1
- 'use strict'
2
-
3
- export const detectHeightOnInit = (element, state) => {
4
- const heightTimeout = setTimeout(() => {
5
- const { props } = element
6
- if (!state.clientHeight) {
7
- const { node: { clientHeight } } = element
8
- if (clientHeight) {
9
- state.clientHeight = clientHeight
10
- }
11
- }
12
-
13
- if (state.active) {
14
- if (props.height === 'auto') return
15
- element.update({
16
- props: { height: state.clientHeight }
17
- }, { preventBeforeUpdateListener: true, preventChildrenUpdate: true })
18
- const setAutoTimeout = setTimeout(() => {
19
- element.update({
20
- props: { height: 'auto' }
21
- }, { preventBeforeUpdateListener: true, preventChildrenUpdate: true })
22
- clearTimeout(setAutoTimeout)
23
- }, 450)
24
- } else {
25
- element.update({
26
- props: { height: '0' }
27
- }, { preventBeforeUpdateListener: true, preventChildrenUpdate: true })
28
- }
29
- clearTimeout(heightTimeout)
30
- })
31
- }
package/src/load.js DELETED
@@ -1,105 +0,0 @@
1
- 'use strict'
2
-
3
- export const loadJavascriptFile = (FILE_URL, async = false, doc = document, type = 'text/javascript') => {
4
- return new Promise((resolve, reject) => {
5
- try {
6
- const scriptEle = doc.createElement('script')
7
- scriptEle.type = type
8
- scriptEle.async = async
9
- scriptEle.src = FILE_URL
10
-
11
- scriptEle.addEventListener('load', (ev) => {
12
- resolve({
13
- status: true
14
- })
15
- })
16
-
17
- scriptEle.addEventListener('error', (ev) => {
18
- reject(new Error({
19
- status: false,
20
- message: `Failed to load the script ${FILE_URL}`
21
- }))
22
- })
23
-
24
- doc.body.appendChild(scriptEle)
25
- } catch (error) {
26
- reject(error)
27
- }
28
- })
29
- }
30
-
31
- export const loadJavascriptFileSync = (fileUrl, doc = document, type = 'text/javascript') => {
32
- return new Promise((resolve, reject) => {
33
- const scriptEle = doc.createElement('script')
34
- scriptEle.type = type
35
- scriptEle.src = fileUrl
36
-
37
- // Create a blocking overlay
38
- const blocker = doc.createElement('div')
39
- blocker.style.cssText = 'position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(255,255,255,0.8);z-index:9999;'
40
- doc.body.appendChild(blocker)
41
-
42
- scriptEle.onload = () => {
43
- console.log(`Successfully loaded: ${fileUrl}`)
44
- doc.body.removeChild(blocker)
45
- resolve()
46
- }
47
-
48
- scriptEle.onerror = () => {
49
- doc.body.removeChild(blocker)
50
- reject(new Error(`Failed to load: ${fileUrl}`))
51
- }
52
-
53
- doc.body.appendChild(scriptEle)
54
- })
55
- }
56
-
57
- export const loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = 'text/javascript') => {
58
- const xhr = new window.XMLHttpRequest()
59
- xhr.open('GET', FILE_URL, false) // false makes the request synchronous
60
- xhr.send()
61
-
62
- if (xhr.status === 200) {
63
- const scriptEle = doc.createElement('script')
64
- scriptEle.type = type
65
- scriptEle.text = xhr.responseText
66
- doc.body.appendChild(scriptEle)
67
- if (typeof fallback === 'function') fallback()
68
- } else {
69
- throw new Error(`Failed to load the script ${FILE_URL}`)
70
- }
71
- }
72
-
73
- export const loadCssFile = (FILE_URL, async = false, doc = document, type = 'text/javascript') => {
74
- return new Promise((resolve, reject) => {
75
- try {
76
- const linkElem = doc.createElement('link')
77
- linkElem.rel = 'stylesheet'
78
- linkElem.href = FILE_URL
79
-
80
- linkElem.addEventListener('load', (ev) => {
81
- resolve({
82
- status: true
83
- })
84
- })
85
-
86
- doc.head.appendChild(linkElem)
87
- } catch (error) {
88
- reject(error)
89
- }
90
- })
91
- }
92
-
93
- export const loadJavascript = (body, async = false, doc = document, type = 'text/javascript', id = 'smbls-script') => {
94
- try {
95
- const scriptEle = doc.createElement('script')
96
- scriptEle.type = type
97
- scriptEle.async = async
98
- scriptEle.id = id
99
- scriptEle.innerHTML = body
100
-
101
- doc.body.appendChild(scriptEle)
102
- } catch (error) {
103
- console.warn(error)
104
- }
105
- }
File without changes
File without changes
File without changes
File without changes
File without changes