@symbo.ls/utils 3.14.0 → 3.14.2

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 (86) hide show
  1. package/README.md +2 -2
  2. package/assets.js +117 -0
  3. package/cookie.js +20 -13
  4. package/index.js +1 -0
  5. package/methods.js +51 -3
  6. package/object.js +36 -2
  7. package/package.json +1 -1
  8. package/dist/cjs/array.js +0 -168
  9. package/dist/cjs/browser.js +0 -34
  10. package/dist/cjs/cache.js +0 -26
  11. package/dist/cjs/cdn.js +0 -85
  12. package/dist/cjs/component.js +0 -45
  13. package/dist/cjs/cookie.js +0 -75
  14. package/dist/cjs/date.js +0 -31
  15. package/dist/cjs/detectHeight.js +0 -62
  16. package/dist/cjs/element.js +0 -136
  17. package/dist/cjs/env.js +0 -43
  18. package/dist/cjs/events.js +0 -39
  19. package/dist/cjs/extends.js +0 -434
  20. package/dist/cjs/fibonacci.js +0 -30
  21. package/dist/cjs/files.js +0 -24
  22. package/dist/cjs/function.js +0 -114
  23. package/dist/cjs/globals.js +0 -30
  24. package/dist/cjs/if.js +0 -48
  25. package/dist/cjs/index.js +0 -54
  26. package/dist/cjs/key.js +0 -38
  27. package/dist/cjs/keys.js +0 -201
  28. package/dist/cjs/load.js +0 -171
  29. package/dist/cjs/log.js +0 -34
  30. package/dist/cjs/metadata.js +0 -310
  31. package/dist/cjs/methods.js +0 -599
  32. package/dist/cjs/node.js +0 -35
  33. package/dist/cjs/object.js +0 -634
  34. package/dist/cjs/projectKeys.js +0 -35
  35. package/dist/cjs/props.js +0 -282
  36. package/dist/cjs/scaling.js +0 -35
  37. package/dist/cjs/scope.js +0 -44
  38. package/dist/cjs/sharedLibraries.js +0 -146
  39. package/dist/cjs/state.js +0 -173
  40. package/dist/cjs/string-extra.js +0 -72
  41. package/dist/cjs/string.js +0 -183
  42. package/dist/cjs/style.js +0 -40
  43. package/dist/cjs/tags.js +0 -220
  44. package/dist/cjs/triggerEvent.js +0 -112
  45. package/dist/cjs/types.js +0 -74
  46. package/dist/cjs/update.js +0 -42
  47. package/dist/esm/array.js +0 -148
  48. package/dist/esm/browser.js +0 -14
  49. package/dist/esm/cache.js +0 -6
  50. package/dist/esm/cdn.js +0 -65
  51. package/dist/esm/component.js +0 -25
  52. package/dist/esm/cookie.js +0 -55
  53. package/dist/esm/date.js +0 -11
  54. package/dist/esm/detectHeight.js +0 -42
  55. package/dist/esm/element.js +0 -116
  56. package/dist/esm/env.js +0 -23
  57. package/dist/esm/events.js +0 -19
  58. package/dist/esm/extends.js +0 -414
  59. package/dist/esm/fibonacci.js +0 -10
  60. package/dist/esm/files.js +0 -4
  61. package/dist/esm/function.js +0 -94
  62. package/dist/esm/globals.js +0 -10
  63. package/dist/esm/if.js +0 -28
  64. package/dist/esm/index.js +0 -37
  65. package/dist/esm/key.js +0 -18
  66. package/dist/esm/keys.js +0 -181
  67. package/dist/esm/load.js +0 -151
  68. package/dist/esm/log.js +0 -14
  69. package/dist/esm/metadata.js +0 -290
  70. package/dist/esm/methods.js +0 -569
  71. package/dist/esm/node.js +0 -15
  72. package/dist/esm/object.js +0 -621
  73. package/dist/esm/projectKeys.js +0 -16
  74. package/dist/esm/props.js +0 -262
  75. package/dist/esm/scaling.js +0 -15
  76. package/dist/esm/scope.js +0 -24
  77. package/dist/esm/sharedLibraries.js +0 -126
  78. package/dist/esm/state.js +0 -163
  79. package/dist/esm/string-extra.js +0 -52
  80. package/dist/esm/string.js +0 -163
  81. package/dist/esm/style.js +0 -20
  82. package/dist/esm/tags.js +0 -200
  83. package/dist/esm/triggerEvent.js +0 -92
  84. package/dist/esm/types.js +0 -54
  85. package/dist/esm/update.js +0 -22
  86. package/dist/iife/index.js +0 -5818
package/README.md CHANGED
@@ -6,7 +6,7 @@ Core utility functions for the DOMQL element system.
6
6
 
7
7
  The propertization system normalizes element definitions by classifying keys into child elements, framework keys, and CSS/design-token properties.
8
8
 
9
- In v4, properties go directly on the element (no `props:` wrapper needed). The propertization system operates internally to route properties to the atomic CSS engine (`@symbo.ls/css`).
9
+ In v3.14, properties go directly on the element (no `props:` wrapper needed). The propertization system operates internally to route properties to the atomic CSS engine (`@symbo.ls/css`).
10
10
 
11
11
  ### Two-phase process
12
12
 
@@ -15,7 +15,7 @@ In v4, properties go directly on the element (no `props:` wrapper needed). The p
15
15
 
16
16
  ### Key classification rules
17
17
 
18
- In v4, properties go directly on the element (no `props:` wrapper needed). The propertization system still operates internally for the CSS engine.
18
+ In v3.14, properties go directly on the element (no `props:` wrapper needed). The propertization system still operates internally for the CSS engine.
19
19
 
20
20
  | Pattern | Classification | Example |
21
21
  |---------|---------------|---------|
package/assets.js ADDED
@@ -0,0 +1,117 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * Asset resolution + variant emitters shared across media components
5
+ * (Img, Video, Audio, AssetPicture, …) and any plugin that reads from
6
+ * `context.assets` / `context.files`.
7
+ *
8
+ * Components don't care WHERE an asset lives — runner-discovered file,
9
+ * cloud-uploaded entry, or hand-authored URL — they call `resolveAsset`
10
+ * with the element and get back a normalized shape (or null).
11
+ */
12
+
13
+ /**
14
+ * Look up `el.src` in `el.context.assets`, falling back to
15
+ * `el.context.files`. Normalizes the two source-side shapes:
16
+ *
17
+ * - **String URL** — cloud-resolved or hand-authored bare URLs.
18
+ * Returns `{ src, type: null, variants: null }`. Components emit
19
+ * a single-source tag with no `<source>` chain and no `srcset`.
20
+ *
21
+ * - **Manifest object** — `{ src, type, category, variants[] }`.
22
+ * Shape produced by the runner's filename-based asset walker
23
+ * (and any cloud provider that exposes variant metadata). Returned
24
+ * verbatim.
25
+ *
26
+ * Anything else (object without `.src`, missing key, non-string `el.src`)
27
+ * returns null. Components fall through to plain markup using `el.src`.
28
+ */
29
+ export const resolveAsset = (el) => {
30
+ const key = el && el.src
31
+ if (!key || typeof key !== 'string') return null
32
+ const ctx = el.context
33
+ if (!ctx) return null
34
+ const found = (ctx.assets && ctx.assets[key]) || (ctx.files && ctx.files[key])
35
+ if (!found) return null
36
+ if (typeof found === 'string') {
37
+ return { src: found, type: null, variants: null }
38
+ }
39
+ if (typeof found === 'object' && typeof found.src === 'string') {
40
+ return found
41
+ }
42
+ return null
43
+ }
44
+
45
+ /**
46
+ * Render an `srcset` value from a list of variants.
47
+ *
48
+ * Width descriptors take precedence over scale when present. Bare 1x
49
+ * entries are kept or dropped based on context:
50
+ *
51
+ * - `<source srcset>` (`keepOneX: true`, default): bare 1x URLs are
52
+ * required because `<source>` has no `src` fallback — without a 1x
53
+ * entry the source can't match default-DPR clients.
54
+ * - `<img srcset>` (`keepOneX: false`): bare 1x URLs are redundant
55
+ * because the `src` attribute already covers them.
56
+ */
57
+ export const srcsetFor = (variants, { keepOneX = true } = {}) => {
58
+ if (!Array.isArray(variants) || !variants.length) return ''
59
+ const usingWidth = variants.some((v) => typeof v.width === 'number')
60
+ const parts = []
61
+ for (const v of variants) {
62
+ if (usingWidth && typeof v.width === 'number') {
63
+ parts.push(`${v.src} ${v.width}w`)
64
+ } else if (!usingWidth) {
65
+ if (v.scale === 1 && keepOneX) parts.push(v.src)
66
+ else if (v.scale && v.scale !== 1) parts.push(`${v.src} ${v.scale}x`)
67
+ }
68
+ }
69
+ return parts.join(', ')
70
+ }
71
+
72
+ /**
73
+ * Same-format srcset for an `<img>` tag — filtered to the asset's
74
+ * primary format and with `keepOneX: false`. Used by `<Img>`.
75
+ */
76
+ export const buildImgSrcset = (asset) => {
77
+ if (!asset || !Array.isArray(asset.variants)) return ''
78
+ const sameFormat = asset.variants.filter((v) => v.format === asset.type)
79
+ return srcsetFor(sameFormat, { keepOneX: false })
80
+ }
81
+
82
+ /**
83
+ * Build the children of an `<picture>` (or any format-negotiating tag)
84
+ * from an asset manifest: one `<source type="…" srcset="…">` per non-
85
+ * primary format, plus a trailing `<img>` for the primary format.
86
+ *
87
+ * Returns a list of DOMQL element configs. When the asset has no
88
+ * variants array (cloud-string URL or single-source entry), returns
89
+ * just the `<img>`.
90
+ */
91
+ export const buildSourcesAndImg = (asset, alt) => {
92
+ if (!asset || typeof asset !== 'object' || typeof asset.src !== 'string') return []
93
+ if (!Array.isArray(asset.variants) || !asset.variants.length) {
94
+ return [{ tag: 'img', attr: { src: asset.src, alt: alt || '' } }]
95
+ }
96
+ // Group by format. Format that matches `asset.type` is the fallback
97
+ // and gets emitted as the trailing `<img>` (browsers fall through to
98
+ // it when no `<source>` matches). Other formats become `<source>`.
99
+ const byFormat = new Map()
100
+ for (const v of asset.variants) {
101
+ if (!byFormat.has(v.format)) byFormat.set(v.format, [])
102
+ byFormat.get(v.format).push(v)
103
+ }
104
+ const sources = []
105
+ for (const [format, list] of byFormat) {
106
+ if (format === asset.type) continue
107
+ sources.push({
108
+ tag: 'source',
109
+ attr: { type: format, srcset: srcsetFor(list, { keepOneX: true }) }
110
+ })
111
+ }
112
+ const sameFormat = byFormat.get(asset.type) || []
113
+ const fallbackSrcset = srcsetFor(sameFormat, { keepOneX: false })
114
+ const imgAttr = { src: asset.src, alt: alt || '' }
115
+ if (fallbackSrcset) imgAttr.srcset = fallbackSrcset
116
+ return [...sources, { tag: 'img', attr: imgAttr }]
117
+ }
package/cookie.js CHANGED
@@ -38,16 +38,19 @@ export const removeCookie = cname => {
38
38
  * @returns {*} -- parsed data or undefined
39
39
  */
40
40
  export function getLocalStorage (key) {
41
- if (!window.localStorage) {
42
- return undefined
43
- }
44
-
45
- const item = window.localStorage.getItem(key)
46
-
47
- if (item === null) {
41
+ // localStorage access throws in: Safari private mode (quota), sandboxed
42
+ // iframes without `allow-storage-access-by-user-activation`, Firefox with
43
+ // `dom.storage.enabled=false`. Wrap the access itself, not just the
44
+ // JSON.parse — the existing try only covered parse and let the read
45
+ // crash the host.
46
+ let item
47
+ try {
48
+ if (!window.localStorage) return undefined
49
+ item = window.localStorage.getItem(key)
50
+ } catch (e) {
48
51
  return undefined
49
52
  }
50
-
53
+ if (item === null) return undefined
51
54
  try {
52
55
  return JSON.parse(item)
53
56
  } catch (e) {
@@ -62,10 +65,14 @@ export function getLocalStorage (key) {
62
65
  * @param data - the data to save
63
66
  */
64
67
  export function setLocalStorage (key, data) {
65
- if (!window.localStorage || data === undefined || data === null) {
66
- return
68
+ if (data === undefined || data === null) return
69
+ try {
70
+ if (!window.localStorage) return
71
+ const value = typeof data === 'object' ? JSON.stringify(data) : data
72
+ window.localStorage.setItem(key, value)
73
+ } catch (e) {
74
+ // QuotaExceededError (Safari private + over quota), SecurityError
75
+ // (sandboxed iframe / disabled storage). Silent fail — caller doesn't
76
+ // expect an exception out of a "save best-effort" helper.
67
77
  }
68
-
69
- const value = typeof data === 'object' ? JSON.stringify(data) : data
70
- window.localStorage.setItem(key, value)
71
78
  }
package/index.js CHANGED
@@ -39,3 +39,4 @@ export * from './scaling.js'
39
39
  export * from './sharedLibraries.js'
40
40
  export * from './string-extra.js'
41
41
  export * from './style.js'
42
+ export * from './assets.js'
package/methods.js CHANGED
@@ -106,7 +106,11 @@ export function setNodeStyles (params = {}) {
106
106
  const value = params[param]
107
107
  const childElem = el[param]
108
108
  if (isObject(value) && childElem) setNodeStyles.call(childElem, value)
109
- else el.node.style[param] = value
109
+ else if (value != null) {
110
+ const cssProp = param.replace(/[A-Z]/g, m => '-' + m.toLowerCase())
111
+ const str = String(value).replace(/\s*!important\s*$/, '')
112
+ el.node.style.setProperty(cssProp, str, 'important')
113
+ }
110
114
  }
111
115
 
112
116
  return el
@@ -157,11 +161,55 @@ export function getPath () {
157
161
  return this.getRef().path
158
162
  }
159
163
 
164
+ // Module-level registry for the active root state. Smbls.create's
165
+ // prepareContext registers the root state here as soon as it's
166
+ // constructed — early enough that any component rendering during the
167
+ // rest of context preparation (and in createElement) can resolve via
168
+ // `getRootState()` without needing `this`.
169
+ //
170
+ // Why this exists: `getRootState()` historically read from
171
+ // `window.platformState || window.smblsApp?.state`. Projects had to
172
+ // pre-set `window.smblsApp = { state: context.state }` in their
173
+ // `index.js` BEFORE calling `create(...)` so the framework could find
174
+ // the state during early render. The runner's boot script bypasses the
175
+ // project's index.js, so projects depending on that pre-init silently
176
+ // renderered blank under runner. A registry the framework owns
177
+ // eliminates the project-side pre-init requirement.
178
+ let _activeRootState = null
179
+
180
+ /**
181
+ * Register the active root state so `getRootState()` (called without a
182
+ * `this` context) can find it during early render. Called by
183
+ * `prepareContext` in `packages/smbls/src/createDomql.js` immediately
184
+ * after `prepareState` resolves.
185
+ *
186
+ * Multi-app pages: this is a singleton — second app overwrites the
187
+ * first. Same behaviour as `window.smblsApp.state` had before. Apps
188
+ * that render concurrently on one page need the element-walk path
189
+ * (`el.getRootState()`), not the free-function path.
190
+ */
191
+ export const setActiveRootState = (state) => {
192
+ _activeRootState = state || null
193
+ }
194
+
195
+ const readFallbackState = () => {
196
+ // The framework-managed registry (set by prepareContext during
197
+ // create(...)) is the single source of truth for the active root
198
+ // state when called without a `this` context. The previous version
199
+ // of this fallback also consulted `window.platformState` and
200
+ // `window.smblsApp?.state` — but per the FA409 rule the framework
201
+ // must not depend on values written to the global object. Projects
202
+ // that need free-function `getRootState()` rely on the registry being
203
+ // populated by `prepareContext`, which happens before any user code
204
+ // runs in `createDomqlElement`.
205
+ return _activeRootState || null
206
+ }
207
+
160
208
  export function getRootState (param) {
161
209
  let state = null
162
210
  const hasRootState = (obj) => obj.__element && obj.root?.isRootState
163
211
  if (!this) {
164
- state = window.platformState || window.smblsApp?.state
212
+ state = readFallbackState()
165
213
  } else if (hasRootState(this)) {
166
214
  state = this.root
167
215
  } else if (this.__ref && this.__ref.path) {
@@ -175,7 +223,7 @@ export function getRootState (param) {
175
223
  }
176
224
  }
177
225
  if (!state) {
178
- state = window.platformState || window.smblsApp?.state
226
+ state = readFallbackState()
179
227
  }
180
228
  return param ? state?.[param] : state
181
229
  }
package/object.js CHANGED
@@ -81,6 +81,14 @@ export const deepMerge = (element, extend, excludeFrom = METHODS_EXL) => {
81
81
  // overhead. We track only the (element, extend) pairs in the *current
82
82
  // descent* — once a pair pops off the stack we forget it, so legitimate
83
83
  // reuse of shared extend objects across siblings is unaffected.
84
+ //
85
+ // PROTOTYPE POLLUTION GUARD: dunder keys are already skipped via
86
+ // `_startsWithDunder`, but `constructor` and `prototype` are NOT dunder
87
+ // and would otherwise be merged through. JSON.parse('{"constructor":
88
+ // {"prototype": {"isAdmin": true}}}') passed as `extend` would walk into
89
+ // `element.constructor` (the real Object constructor), then recurse and
90
+ // set `element.constructor.prototype.isAdmin = true` — polluting every
91
+ // object globally. Drop those segments.
84
92
  const _deepMerge = (element, extend, excludeFrom, ancestors) => {
85
93
  if (element === extend) return element
86
94
  if (ancestors) {
@@ -92,6 +100,7 @@ const _deepMerge = (element, extend, excludeFrom, ancestors) => {
92
100
  for (const e in extend) {
93
101
  if (!Object.prototype.hasOwnProperty.call(extend, e)) continue
94
102
  if (_startsWithDunder(e)) continue
103
+ if (e === 'constructor' || e === 'prototype') continue
95
104
  if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue
96
105
  const elementProp = element[e]
97
106
  const extendProp = extend[e]
@@ -382,7 +391,21 @@ export const deepDestringifyFunctions = (
382
391
  try {
383
392
  destringified[prop] = opts.window.eval(`(${objProp})`)
384
393
  } catch (e) {
385
- if (e) destringified[prop] = objProp
394
+ // FR-1 (FRANK-RUNNER.md): the silent string-fallback used to
395
+ // mask broken serialization — eight aihouse functions stored
396
+ // as strings instead of functions, `el.call(name)` no-op'd
397
+ // with no error. Surface the failure so consumers can audit
398
+ // what frank produced. Keep the fallback (don't crash boot)
399
+ // but make it loud.
400
+ if (typeof console !== 'undefined' && console.warn) {
401
+ console.warn(
402
+ '[smbls] deepDestringifyFunctions: eval failed on "' + prop + '" — ' +
403
+ 'function will be left as a string and el.call("' + prop + '") ' +
404
+ 'will silently no-op. Reason: ' + (e && e.message ? e.message : String(e)) + '.\n' +
405
+ 'First 200 chars of source: ' + String(objProp).slice(0, 200)
406
+ )
407
+ }
408
+ destringified[prop] = objProp
386
409
  }
387
410
  } else {
388
411
  destringified[prop] = objProp
@@ -396,7 +419,14 @@ export const deepDestringifyFunctions = (
396
419
  try {
397
420
  arr.push(opts.window.eval(`(${arrProp})`))
398
421
  } catch (e) {
399
- if (e) arr.push(arrProp)
422
+ if (typeof console !== 'undefined' && console.warn) {
423
+ console.warn(
424
+ `[smbls] deepDestringifyFunctions: eval failed in array at index ${i} ` +
425
+ `(prop "${prop}"). Reason: ${e && e.message ? e.message : String(e)}.\n` +
426
+ `First 200 chars: ${String(arrProp).slice(0, 200)}`
427
+ )
428
+ }
429
+ arr.push(arrProp)
400
430
  }
401
431
  } else {
402
432
  arr.push(arrProp)
@@ -491,6 +521,8 @@ export const overwrite = (element, params, opts = {}) => {
491
521
 
492
522
  for (const e in params) {
493
523
  if (excl.includes(e) || (!allowDunder && _startsWithDunder(e))) continue
524
+ // Block prototype-pollution writes (see _deepMerge for rationale).
525
+ if (e === 'constructor' || e === 'prototype') continue
494
526
  if (params[e] !== undefined) {
495
527
  element[e] = params[e]
496
528
  }
@@ -503,6 +535,7 @@ export const overwriteShallow = (obj, params, excludeFrom = []) => {
503
535
  const useSet = excludeFrom instanceof Set
504
536
  for (const e in params) {
505
537
  if (_startsWithDunder(e)) continue
538
+ if (e === 'constructor' || e === 'prototype') continue
506
539
  if (useSet ? excludeFrom.has(e) : excludeFrom.includes(e)) continue
507
540
  obj[e] = params[e]
508
541
  }
@@ -538,6 +571,7 @@ export const overwriteDeep = (
538
571
  if (!Object.prototype.hasOwnProperty.call(params, e)) continue
539
572
  if ((exclSet && exclSet.has(e)) || (forcedExclude && _startsWithDunder(e)))
540
573
  continue
574
+ if (e === 'constructor' || e === 'prototype') continue
541
575
 
542
576
  const objProp = obj[e]
543
577
  const paramsProp = params[e]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/utils",
3
- "version": "3.14.0",
3
+ "version": "3.14.2",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./index.js",
package/dist/cjs/array.js DELETED
@@ -1,168 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var array_exports = {};
20
- __export(array_exports, {
21
- addItemAfterEveryElement: () => addItemAfterEveryElement,
22
- addProtoToArray: () => addProtoToArray,
23
- arrayContainsOtherArray: () => arrayContainsOtherArray,
24
- arraysEqual: () => arraysEqual,
25
- checkIfStringIsInArray: () => checkIfStringIsInArray,
26
- cutArrayAfterValue: () => cutArrayAfterValue,
27
- cutArrayBeforeValue: () => cutArrayBeforeValue,
28
- filterArrays: () => filterArrays,
29
- filterArraysFast: () => filterArraysFast,
30
- getFrequencyInArray: () => getFrequencyInArray,
31
- joinArrays: () => joinArrays,
32
- removeDuplicatesInArray: () => removeDuplicatesInArray,
33
- removeFromArray: () => removeFromArray,
34
- removeValueFromArray: () => removeValueFromArray,
35
- removeValueFromArrayAll: () => removeValueFromArrayAll,
36
- reorderArrayByValues: () => reorderArrayByValues,
37
- swapItemsInArray: () => swapItemsInArray,
38
- unstackArrayOfObjects: () => unstackArrayOfObjects
39
- });
40
- module.exports = __toCommonJS(array_exports);
41
- var import_object = require("./object.js");
42
- var import_types = require("./types.js");
43
- const arrayContainsOtherArray = (arr1, arr2) => {
44
- return arr2.every((val) => arr1.includes(val));
45
- };
46
- const getFrequencyInArray = (arr, value) => {
47
- let count = 0;
48
- for (let i = 0; i < arr.length; i++) {
49
- if (arr[i] === value) count++;
50
- }
51
- return count;
52
- };
53
- const removeFromArray = (arr, index) => {
54
- if ((0, import_types.isString)(index)) index = parseInt(index);
55
- if ((0, import_types.isNumber)(index)) {
56
- if (index < 0 || index >= arr.length || isNaN(index)) {
57
- throw new Error("Invalid index");
58
- }
59
- arr.splice(index, 1);
60
- } else {
61
- throw new Error("Invalid index");
62
- }
63
- return arr;
64
- };
65
- const swapItemsInArray = (arr, i, j) => {
66
- if (i < 0 || j < 0 || i >= arr.length || j >= arr.length) return;
67
- [arr[i], arr[j]] = [arr[j], arr[i]];
68
- };
69
- const joinArrays = (...arrays) => {
70
- return [].concat(...arrays);
71
- };
72
- const unstackArrayOfObjects = (arr, exclude = []) => {
73
- return arr.reduce(
74
- (a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, { exclude }), exclude),
75
- {}
76
- );
77
- };
78
- const cutArrayBeforeValue = (arr, value) => {
79
- const index = arr.indexOf(value);
80
- if (index !== -1) {
81
- return arr.slice(0, index);
82
- }
83
- return arr;
84
- };
85
- const cutArrayAfterValue = (arr, value) => {
86
- if (!(0, import_types.isArray)(arr)) return;
87
- const index = arr.indexOf(value);
88
- if (index !== -1) {
89
- return arr.slice(index + 1);
90
- }
91
- return arr;
92
- };
93
- const removeValueFromArray = (arr, value) => {
94
- const index = arr.indexOf(value);
95
- if (index > -1) {
96
- const newArray = [...arr];
97
- newArray.splice(index, 1);
98
- return newArray;
99
- }
100
- return arr;
101
- };
102
- const removeValueFromArrayAll = (arr, value) => {
103
- return arr.filter((item) => item !== value);
104
- };
105
- const addItemAfterEveryElement = (array, item) => {
106
- const result = [];
107
- for (let i = 0; i < array.length; i++) {
108
- result.push(array[i]);
109
- if (i < array.length - 1) {
110
- result.push(item);
111
- }
112
- }
113
- return result;
114
- };
115
- const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
116
- const newArray = [...array];
117
- const indexToMove = newArray.indexOf(valueToMove);
118
- const indexToInsertBefore = newArray.indexOf(insertBeforeValue);
119
- if (indexToMove !== -1 && indexToInsertBefore !== -1) {
120
- const removedItem = newArray.splice(indexToMove, 1)[0];
121
- const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1;
122
- newArray.splice(insertIndex, 0, removedItem);
123
- }
124
- return newArray;
125
- };
126
- const arraysEqual = (arr1, arr2) => {
127
- if (arr1.length !== arr2.length) {
128
- return false;
129
- }
130
- for (let i = 0; i < arr1.length; i++) {
131
- if (arr1[i] !== arr2[i]) {
132
- return false;
133
- }
134
- }
135
- return true;
136
- };
137
- const filterArrays = (sourceArr, excludeArr) => {
138
- return sourceArr.filter((item) => !excludeArr.includes(item));
139
- };
140
- const filterArraysFast = (sourceArr, excludeArr) => {
141
- const excludeSet = new Set(excludeArr);
142
- return sourceArr.filter((item) => !excludeSet.has(item));
143
- };
144
- const checkIfStringIsInArray = (string, arr) => {
145
- if (!string) return 0;
146
- let count = 0;
147
- for (let i = 0; i < arr.length; i++) {
148
- if (string.includes(arr[i])) count++;
149
- }
150
- return count;
151
- };
152
- const removeDuplicatesInArray = (arr) => {
153
- if (!(0, import_types.isArray)(arr)) return arr;
154
- return [...new Set(arr)];
155
- };
156
- const addProtoToArray = (state, proto) => {
157
- for (const key in proto) {
158
- Object.defineProperty(state, key, {
159
- value: proto[key],
160
- enumerable: false,
161
- // Set this to true if you want the method to appear in for...in loops
162
- configurable: true,
163
- // Set this to true if you want to allow redefining/removing the property later
164
- writable: true
165
- // Set this to true if you want to allow changing the function later
166
- });
167
- }
168
- };
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var browser_exports = {};
20
- __export(browser_exports, {
21
- toggleFullscreen: () => toggleFullscreen
22
- });
23
- module.exports = __toCommonJS(browser_exports);
24
- async function toggleFullscreen(opts) {
25
- if (!document.fullscreenElement) {
26
- try {
27
- await (this.node || document).requestFullscreen();
28
- } catch (err) {
29
- console.warn(`Error attempting to enable fullscreen mode: ${err.message} (${err.name})`);
30
- }
31
- } else {
32
- await document.exitFullscreen();
33
- }
34
- }
package/dist/cjs/cache.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var cache_exports = {};
20
- __export(cache_exports, {
21
- OPTIONS: () => OPTIONS,
22
- cache: () => cache
23
- });
24
- module.exports = __toCommonJS(cache_exports);
25
- const cache = {};
26
- const OPTIONS = {};
package/dist/cjs/cdn.js DELETED
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var cdn_exports = {};
20
- __export(cdn_exports, {
21
- CDN_PROVIDERS: () => CDN_PROVIDERS,
22
- PACKAGE_MANAGER_TO_CDN: () => PACKAGE_MANAGER_TO_CDN,
23
- getCDNUrl: () => getCDNUrl,
24
- getCdnProviderFromConfig: () => getCdnProviderFromConfig,
25
- getImportMapScript: () => getImportMapScript
26
- });
27
- module.exports = __toCommonJS(cdn_exports);
28
- function onlyDotsAndNumbers(str) {
29
- return /^[0-9.]+$/.test(str) && str !== "";
30
- }
31
- const CDN_PROVIDERS = {
32
- skypack: {
33
- url: "https://cdn.skypack.dev",
34
- formatUrl: (pkg, version) => `${CDN_PROVIDERS.skypack.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
35
- },
36
- esmsh: {
37
- url: "https://esm.sh",
38
- formatUrl: (pkg, version) => `${CDN_PROVIDERS.esmsh.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
39
- },
40
- unpkg: {
41
- url: "https://unpkg.com",
42
- formatUrl: (pkg, version) => `${CDN_PROVIDERS.unpkg.url}/${pkg}${version !== "latest" ? `@${version}` : ""}?module`
43
- },
44
- jsdelivr: {
45
- url: "https://cdn.jsdelivr.net/npm",
46
- formatUrl: (pkg, version) => `${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version !== "latest" ? `@${version}` : ""}/+esm`
47
- },
48
- symbols: {
49
- url: "https://pkg.symbo.ls",
50
- formatUrl: (pkg, version) => {
51
- if (pkg.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
52
- return `${CDN_PROVIDERS.symbols.url}/${pkg}`;
53
- }
54
- return `${CDN_PROVIDERS.symbols.url}/${pkg}/${version}.js`;
55
- }
56
- }
57
- };
58
- const PACKAGE_MANAGER_TO_CDN = {
59
- "esm.sh": "esmsh",
60
- "unpkg": "unpkg",
61
- "skypack": "skypack",
62
- "jsdelivr": "jsdelivr",
63
- "pkg.symbo.ls": "symbols"
64
- };
65
- const getCdnProviderFromConfig = (symbolsConfig = {}) => {
66
- const { packageManager } = symbolsConfig;
67
- return PACKAGE_MANAGER_TO_CDN[packageManager] || null;
68
- };
69
- const getCDNUrl = (packageName, version = "latest", provider = "esmsh") => {
70
- const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh;
71
- return cdnConfig.formatUrl(packageName, version);
72
- };
73
- const getImportMapScript = (data, defaultProvider = "skypack") => {
74
- const dependencies = data.dependencies || {};
75
- const keys = Object.keys(dependencies);
76
- if (!keys.length) return "";
77
- const imports = {};
78
- for (const pkgName of keys) {
79
- const version = dependencies[pkgName] || "latest";
80
- imports[pkgName] = getCDNUrl(pkgName, version, defaultProvider);
81
- }
82
- return `<script type="importmap">{
83
- "imports": ${JSON.stringify(imports, null, 2)}
84
- }<\/script>`;
85
- };