@symbo.ls/utils 3.14.0 → 3.14.1

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 (88) hide show
  1. package/README.md +2 -2
  2. package/assets.js +117 -0
  3. package/cookie.js +20 -13
  4. package/dist/cjs/browser.js +2 -0
  5. package/dist/cjs/date.js +3 -1
  6. package/dist/cjs/detectHeight.js +13 -22
  7. package/dist/cjs/domqlv3hacks.js +3845 -0
  8. package/dist/cjs/fibonacci.js +3 -1
  9. package/dist/cjs/files.js +3 -1
  10. package/dist/cjs/index.js +4084 -38
  11. package/dist/cjs/load.js +7 -5
  12. package/dist/cjs/package.json +4 -0
  13. package/dist/cjs/scaling.js +23 -5
  14. package/dist/cjs/style.js +3 -1
  15. package/index.js +1 -0
  16. package/methods.js +51 -3
  17. package/object.js +36 -2
  18. package/package.json +1 -1
  19. package/dist/cjs/array.js +0 -168
  20. package/dist/cjs/cache.js +0 -26
  21. package/dist/cjs/cdn.js +0 -85
  22. package/dist/cjs/component.js +0 -45
  23. package/dist/cjs/cookie.js +0 -75
  24. package/dist/cjs/element.js +0 -136
  25. package/dist/cjs/env.js +0 -43
  26. package/dist/cjs/events.js +0 -39
  27. package/dist/cjs/extends.js +0 -434
  28. package/dist/cjs/function.js +0 -114
  29. package/dist/cjs/globals.js +0 -30
  30. package/dist/cjs/if.js +0 -48
  31. package/dist/cjs/key.js +0 -38
  32. package/dist/cjs/keys.js +0 -201
  33. package/dist/cjs/log.js +0 -34
  34. package/dist/cjs/metadata.js +0 -310
  35. package/dist/cjs/methods.js +0 -599
  36. package/dist/cjs/node.js +0 -35
  37. package/dist/cjs/object.js +0 -634
  38. package/dist/cjs/projectKeys.js +0 -35
  39. package/dist/cjs/props.js +0 -282
  40. package/dist/cjs/scope.js +0 -44
  41. package/dist/cjs/sharedLibraries.js +0 -146
  42. package/dist/cjs/state.js +0 -173
  43. package/dist/cjs/string-extra.js +0 -72
  44. package/dist/cjs/string.js +0 -183
  45. package/dist/cjs/tags.js +0 -220
  46. package/dist/cjs/triggerEvent.js +0 -112
  47. package/dist/cjs/types.js +0 -74
  48. package/dist/cjs/update.js +0 -42
  49. package/dist/esm/array.js +0 -148
  50. package/dist/esm/browser.js +0 -14
  51. package/dist/esm/cache.js +0 -6
  52. package/dist/esm/cdn.js +0 -65
  53. package/dist/esm/component.js +0 -25
  54. package/dist/esm/cookie.js +0 -55
  55. package/dist/esm/date.js +0 -11
  56. package/dist/esm/detectHeight.js +0 -42
  57. package/dist/esm/element.js +0 -116
  58. package/dist/esm/env.js +0 -23
  59. package/dist/esm/events.js +0 -19
  60. package/dist/esm/extends.js +0 -414
  61. package/dist/esm/fibonacci.js +0 -10
  62. package/dist/esm/files.js +0 -4
  63. package/dist/esm/function.js +0 -94
  64. package/dist/esm/globals.js +0 -10
  65. package/dist/esm/if.js +0 -28
  66. package/dist/esm/index.js +0 -37
  67. package/dist/esm/key.js +0 -18
  68. package/dist/esm/keys.js +0 -181
  69. package/dist/esm/load.js +0 -151
  70. package/dist/esm/log.js +0 -14
  71. package/dist/esm/metadata.js +0 -290
  72. package/dist/esm/methods.js +0 -569
  73. package/dist/esm/node.js +0 -15
  74. package/dist/esm/object.js +0 -621
  75. package/dist/esm/projectKeys.js +0 -16
  76. package/dist/esm/props.js +0 -262
  77. package/dist/esm/scaling.js +0 -15
  78. package/dist/esm/scope.js +0 -24
  79. package/dist/esm/sharedLibraries.js +0 -126
  80. package/dist/esm/state.js +0 -163
  81. package/dist/esm/string-extra.js +0 -52
  82. package/dist/esm/string.js +0 -163
  83. package/dist/esm/style.js +0 -20
  84. package/dist/esm/tags.js +0 -200
  85. package/dist/esm/triggerEvent.js +0 -92
  86. package/dist/esm/types.js +0 -54
  87. package/dist/esm/update.js +0 -22
  88. package/dist/iife/index.js +0 -5818
package/dist/cjs/load.js CHANGED
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/load.js
19
21
  var load_exports = {};
20
22
  __export(load_exports, {
21
23
  loadCssFile: () => loadCssFile,
@@ -27,7 +29,7 @@ __export(load_exports, {
27
29
  loadRemoteScript: () => loadRemoteScript
28
30
  });
29
31
  module.exports = __toCommonJS(load_exports);
30
- const loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
32
+ var loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
31
33
  return new Promise((resolve, reject) => {
32
34
  try {
33
35
  const scriptEle = doc.createElement("script");
@@ -53,7 +55,7 @@ const loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "tex
53
55
  }
54
56
  });
55
57
  };
56
- const loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript") => {
58
+ var loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript") => {
57
59
  return new Promise((resolve, reject) => {
58
60
  const scriptEle = doc.createElement("script");
59
61
  scriptEle.type = type;
@@ -73,7 +75,7 @@ const loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript
73
75
  doc.body.appendChild(scriptEle);
74
76
  });
75
77
  };
76
- const loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "text/javascript") => {
78
+ var loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "text/javascript") => {
77
79
  const xhr = new window.XMLHttpRequest();
78
80
  xhr.open("GET", FILE_URL, false);
79
81
  xhr.send();
@@ -87,7 +89,7 @@ const loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type =
87
89
  throw new Error(`Failed to load the script ${FILE_URL}`);
88
90
  }
89
91
  };
90
- const loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
92
+ var loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
91
93
  return new Promise((resolve, reject) => {
92
94
  try {
93
95
  const linkElem = doc.createElement("link");
@@ -104,7 +106,7 @@ const loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javas
104
106
  }
105
107
  });
106
108
  };
107
- const loadJavascript = (body, async = false, doc = document, type = "text/javascript", id = "smbls-script") => {
109
+ var loadJavascript = (body, async = false, doc = document, type = "text/javascript", id = "smbls-script") => {
108
110
  try {
109
111
  const scriptEle = doc.createElement("script");
110
112
  scriptEle.type = type;
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "commonjs",
3
+ "main": "index.js"
4
+ }
@@ -16,20 +16,38 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/scaling.js
19
21
  var scaling_exports = {};
20
22
  __export(scaling_exports, {
21
23
  findClosestNumber: () => findClosestNumber,
22
24
  findClosestNumberInFactory: () => findClosestNumberInFactory
23
25
  });
24
26
  module.exports = __toCommonJS(scaling_exports);
25
- var import_types = require("./types.js");
26
- const findClosestNumber = (number, arr) => {
27
- return ((0, import_types.isArray)(arr) ? arr : Object.values(arr)).reduce((prev, curr) => {
27
+
28
+ // ../../../domql/packages/utils/globals.js
29
+ var window2 = globalThis;
30
+ var document2 = window2.document;
31
+
32
+ // ../../../domql/packages/utils/types.js
33
+ var isObject = (arg) => {
34
+ if (arg === null) return false;
35
+ return typeof arg === "object" && arg.constructor === Object;
36
+ };
37
+ var isArray = (arg) => Array.isArray(arg);
38
+
39
+ // ../../../domql/packages/utils/cookie.js
40
+ var isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
41
+
42
+ // src/scaling.js
43
+ var findClosestNumber = (number, arr) => {
44
+ return (isArray(arr) ? arr : Object.values(arr)).reduce((prev, curr) => {
28
45
  return Math.abs(curr - number) < Math.abs(prev - number) ? curr : prev;
29
46
  });
30
47
  };
31
- const findClosestNumberInFactory = (val, factory) => {
48
+ var findClosestNumberInFactory = (val, factory) => {
32
49
  val = parseFloat(val);
33
- if ((0, import_types.isObject)(factory)) factory = Object.values(factory);
50
+ if (isObject(factory)) factory = Object.values(factory);
34
51
  return findClosestNumber(val, factory);
35
52
  };
53
+ // @preserve-env
package/dist/cjs/style.js CHANGED
@@ -16,12 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/style.js
19
21
  var style_exports = {};
20
22
  __export(style_exports, {
21
23
  getEmotionStylesheet: () => getEmotionStylesheet
22
24
  });
23
25
  module.exports = __toCommonJS(style_exports);
24
- const getEmotionStylesheet = () => {
26
+ var getEmotionStylesheet = () => {
25
27
  const stylesheet = document.styleSheets[0];
26
28
  let str = "";
27
29
  if (stylesheet) {
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.1",
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
- };
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
- };
@@ -1,45 +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 component_exports = {};
20
- __export(component_exports, {
21
- getCapitalCaseKeys: () => getCapitalCaseKeys,
22
- getSpreadChildren: () => getSpreadChildren,
23
- isContextComponent: () => isContextComponent,
24
- matchesComponentNaming: () => matchesComponentNaming
25
- });
26
- module.exports = __toCommonJS(component_exports);
27
- var import_extends = require("./extends.js");
28
- var import_types = require("./types.js");
29
- const matchesComponentNaming = (key) => {
30
- if (!(0, import_types.isString)(key) || !key.length) return false;
31
- const code = key.charCodeAt(0);
32
- return code >= 65 && code <= 90;
33
- };
34
- function getCapitalCaseKeys(obj) {
35
- return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
36
- }
37
- function getSpreadChildren(obj) {
38
- return Object.keys(obj).filter((key) => /^\d+$/.test(key));
39
- }
40
- function isContextComponent(element, parent, passedKey) {
41
- const { context } = parent || {};
42
- const [extendsKey] = (0, import_extends.createExtendsFromKeys)(passedKey);
43
- const key = passedKey || extendsKey;
44
- return context?.components?.[key] || context?.pages?.[key];
45
- }