@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.
- package/LICENSE +25 -12
- package/README.md +106 -0
- package/array.js +162 -0
- package/cache.js +7 -0
- package/cdn.js +83 -0
- package/component.js +25 -0
- package/cookie.js +71 -0
- package/detectHeight.js +42 -0
- package/dist/cjs/array.js +168 -0
- package/dist/cjs/browser.js +0 -2
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/cdn.js +85 -0
- package/dist/cjs/component.js +45 -0
- package/dist/cjs/cookie.js +75 -0
- package/dist/cjs/date.js +1 -3
- package/dist/cjs/detectHeight.js +22 -13
- package/dist/cjs/element.js +136 -0
- package/dist/cjs/env.js +43 -0
- package/dist/cjs/events.js +39 -0
- package/dist/cjs/extends.js +434 -0
- package/dist/cjs/fibonacci.js +1 -3
- package/dist/cjs/files.js +1 -3
- package/dist/cjs/function.js +114 -0
- package/dist/cjs/globals.js +30 -0
- package/dist/cjs/if.js +48 -0
- package/dist/cjs/index.js +38 -371
- package/dist/cjs/key.js +38 -0
- package/dist/cjs/keys.js +201 -0
- package/dist/cjs/load.js +67 -12
- package/dist/cjs/log.js +34 -0
- package/dist/cjs/metadata.js +310 -0
- package/dist/cjs/methods.js +599 -0
- package/dist/cjs/node.js +35 -0
- package/dist/cjs/object.js +634 -0
- package/dist/cjs/projectKeys.js +35 -0
- package/dist/cjs/props.js +282 -0
- package/dist/cjs/scaling.js +5 -169
- package/dist/cjs/scope.js +44 -0
- package/dist/cjs/sharedLibraries.js +146 -0
- package/dist/cjs/state.js +173 -0
- package/dist/cjs/string-extra.js +72 -0
- package/dist/cjs/string.js +183 -0
- package/dist/cjs/style.js +1 -3
- package/dist/cjs/tags.js +220 -0
- package/dist/cjs/triggerEvent.js +112 -0
- package/dist/cjs/types.js +74 -0
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +148 -0
- package/dist/esm/browser.js +14 -0
- package/dist/esm/cache.js +6 -0
- package/dist/esm/cdn.js +65 -0
- package/dist/esm/component.js +25 -0
- package/dist/esm/cookie.js +55 -0
- package/dist/esm/date.js +11 -0
- package/dist/esm/detectHeight.js +42 -0
- package/dist/esm/element.js +116 -0
- package/dist/esm/env.js +23 -0
- package/dist/esm/events.js +19 -0
- package/dist/esm/extends.js +414 -0
- package/dist/esm/fibonacci.js +10 -0
- package/dist/esm/files.js +4 -0
- package/dist/esm/function.js +94 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/if.js +28 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/key.js +18 -0
- package/dist/esm/keys.js +181 -0
- package/dist/esm/load.js +151 -0
- package/dist/esm/log.js +14 -0
- package/dist/esm/metadata.js +290 -0
- package/dist/esm/methods.js +569 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +621 -0
- package/dist/esm/projectKeys.js +16 -0
- package/dist/esm/props.js +262 -0
- package/dist/esm/scaling.js +15 -0
- package/dist/esm/scope.js +24 -0
- package/dist/esm/sharedLibraries.js +126 -0
- package/dist/esm/state.js +163 -0
- package/dist/esm/string-extra.js +52 -0
- package/dist/esm/string.js +163 -0
- package/dist/esm/style.js +20 -0
- package/dist/esm/tags.js +200 -0
- package/dist/esm/triggerEvent.js +92 -0
- package/dist/esm/types.js +54 -0
- package/dist/esm/update.js +22 -0
- package/dist/iife/index.js +5818 -0
- package/element.js +148 -0
- package/env.js +15 -0
- package/events.js +19 -0
- package/extends.js +519 -0
- package/function.js +145 -0
- package/globals.js +8 -0
- package/if.js +30 -0
- package/index.js +41 -0
- package/key.js +20 -0
- package/keys.js +176 -0
- package/load.js +236 -0
- package/log.js +12 -0
- package/metadata.js +392 -0
- package/methods.js +636 -0
- package/node.js +37 -0
- package/object.js +803 -0
- package/package.json +38 -22
- package/projectKeys.js +30 -0
- package/props.js +327 -0
- package/{src/scaling.js → scaling.js} +1 -1
- package/scope.js +32 -0
- package/sharedLibraries.js +184 -0
- package/state.js +203 -0
- package/{src/index.js → string-extra.js} +22 -25
- package/string.js +206 -0
- package/tags.js +176 -0
- package/triggerEvent.js +102 -0
- package/types.js +55 -0
- package/update.js +27 -0
- package/dist/cjs/package.json +0 -4
- package/src/detectHeight.js +0 -31
- package/src/load.js +0 -105
- /package/{src/browser.js → browser.js} +0 -0
- /package/{src/date.js → date.js} +0 -0
- /package/{src/fibonacci.js → fibonacci.js} +0 -0
- /package/{src/files.js → files.js} +0 -0
- /package/{src/style.js → style.js} +0 -0
package/triggerEvent.js
ADDED
|
@@ -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
|
+
}
|
package/dist/cjs/package.json
DELETED
package/src/detectHeight.js
DELETED
|
@@ -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
|
/package/{src/date.js → date.js}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|