@symbo.ls/utils 3.2.3 → 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/{src/detectHeight.js → detectHeight.js} +3 -3
- 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 +4 -6
- 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 -425
- package/dist/cjs/key.js +38 -0
- package/dist/cjs/keys.js +201 -0
- package/dist/cjs/load.js +5 -7
- 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/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} +11 -17
- 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/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/load.js → load.js} +0 -0
- /package/{src/style.js → style.js} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
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 triggerEvent_exports = {};
|
|
20
|
+
__export(triggerEvent_exports, {
|
|
21
|
+
applyEvent: () => applyEvent,
|
|
22
|
+
applyEventUpdate: () => applyEventUpdate,
|
|
23
|
+
triggerEventOn: () => triggerEventOn,
|
|
24
|
+
triggerEventOnUpdate: () => triggerEventOnUpdate
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(triggerEvent_exports);
|
|
27
|
+
var import_types = require("./types.js");
|
|
28
|
+
var import_function = require("./function.js");
|
|
29
|
+
const getOnOrPropsEvent = (param, element) => {
|
|
30
|
+
const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
|
|
31
|
+
return element[propKey];
|
|
32
|
+
};
|
|
33
|
+
const applyEvent = (param, element, state, context, options) => {
|
|
34
|
+
param = (0, import_function.resolveHandler)(param, element);
|
|
35
|
+
if (!(0, import_types.isFunction)(param)) return;
|
|
36
|
+
try {
|
|
37
|
+
const result = param.call(
|
|
38
|
+
element,
|
|
39
|
+
element,
|
|
40
|
+
state || element.state,
|
|
41
|
+
context || element.context,
|
|
42
|
+
options
|
|
43
|
+
);
|
|
44
|
+
if (result && typeof result.then === "function") {
|
|
45
|
+
result.catch((err) => {
|
|
46
|
+
element.error = err;
|
|
47
|
+
if (err instanceof ReferenceError) console.warn("[DOMQL] Async event warning:", err.message);
|
|
48
|
+
else console.error("[DOMQL] Async event error:", err);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
} catch (err) {
|
|
53
|
+
element.error = err;
|
|
54
|
+
if (err instanceof ReferenceError) {
|
|
55
|
+
console.warn("[DOMQL] Event handler warning:", err.message);
|
|
56
|
+
} else {
|
|
57
|
+
console.error("[DOMQL] Event handler error:", err);
|
|
58
|
+
}
|
|
59
|
+
if (element.context?.strictMode) throw err;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const triggerEventOn = (param, element, options) => {
|
|
63
|
+
if (!element) {
|
|
64
|
+
throw new Error("Element is required");
|
|
65
|
+
}
|
|
66
|
+
(0, import_function.runPluginHook)(param, element, options);
|
|
67
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
68
|
+
if (appliedFunction) {
|
|
69
|
+
const { state, context } = element;
|
|
70
|
+
return applyEvent(appliedFunction, element, state, context, options);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
|
|
74
|
+
param = (0, import_function.resolveHandler)(param, element);
|
|
75
|
+
if (!(0, import_types.isFunction)(param)) return;
|
|
76
|
+
try {
|
|
77
|
+
const result = param.call(
|
|
78
|
+
element,
|
|
79
|
+
updatedObj,
|
|
80
|
+
element,
|
|
81
|
+
state || element.state,
|
|
82
|
+
context || element.context,
|
|
83
|
+
options
|
|
84
|
+
);
|
|
85
|
+
if (result && typeof result.then === "function") {
|
|
86
|
+
result.catch((err) => {
|
|
87
|
+
element.error = err;
|
|
88
|
+
console.error("[DOMQL] Async event update error:", err);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
} catch (err) {
|
|
93
|
+
element.error = err;
|
|
94
|
+
console.error("[DOMQL] Event update error:", err);
|
|
95
|
+
if (element.context?.strictMode) throw err;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
99
|
+
(0, import_function.runPluginHook)(param, element, updatedObj, options);
|
|
100
|
+
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
101
|
+
if (appliedFunction) {
|
|
102
|
+
const { state, context } = element;
|
|
103
|
+
return applyEventUpdate(
|
|
104
|
+
appliedFunction,
|
|
105
|
+
updatedObj,
|
|
106
|
+
element,
|
|
107
|
+
state,
|
|
108
|
+
context,
|
|
109
|
+
options
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
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 types_exports = {};
|
|
20
|
+
__export(types_exports, {
|
|
21
|
+
TYPES: () => TYPES,
|
|
22
|
+
is: () => is,
|
|
23
|
+
isArray: () => isArray,
|
|
24
|
+
isBoolean: () => isBoolean,
|
|
25
|
+
isDate: () => isDate,
|
|
26
|
+
isDefined: () => isDefined,
|
|
27
|
+
isFunction: () => isFunction,
|
|
28
|
+
isNot: () => isNot,
|
|
29
|
+
isNull: () => isNull,
|
|
30
|
+
isNumber: () => isNumber,
|
|
31
|
+
isObject: () => isObject,
|
|
32
|
+
isObjectLike: () => isObjectLike,
|
|
33
|
+
isString: () => isString,
|
|
34
|
+
isUndefined: () => isUndefined
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(types_exports);
|
|
37
|
+
var import_node = require("./node.js");
|
|
38
|
+
const isObject = (arg) => {
|
|
39
|
+
if (arg === null) return false;
|
|
40
|
+
return typeof arg === "object" && arg.constructor === Object;
|
|
41
|
+
};
|
|
42
|
+
const isString = (arg) => typeof arg === "string";
|
|
43
|
+
const isNumber = (arg) => typeof arg === "number";
|
|
44
|
+
const isFunction = (arg) => typeof arg === "function";
|
|
45
|
+
const isBoolean = (arg) => arg === true || arg === false;
|
|
46
|
+
const isNull = (arg) => arg === null;
|
|
47
|
+
const isArray = (arg) => Array.isArray(arg);
|
|
48
|
+
const isDate = (d) => d instanceof Date;
|
|
49
|
+
const isObjectLike = (arg) => {
|
|
50
|
+
if (arg === null) return false;
|
|
51
|
+
return typeof arg === "object";
|
|
52
|
+
};
|
|
53
|
+
const isDefined = (arg) => arg !== void 0;
|
|
54
|
+
const isUndefined = (arg) => arg === void 0;
|
|
55
|
+
const TYPES = {
|
|
56
|
+
boolean: isBoolean,
|
|
57
|
+
array: isArray,
|
|
58
|
+
object: isObject,
|
|
59
|
+
string: isString,
|
|
60
|
+
date: isDate,
|
|
61
|
+
number: isNumber,
|
|
62
|
+
null: isNull,
|
|
63
|
+
function: isFunction,
|
|
64
|
+
objectLike: isObjectLike,
|
|
65
|
+
node: import_node.isNode,
|
|
66
|
+
htmlElement: import_node.isHtmlElement,
|
|
67
|
+
defined: isDefined
|
|
68
|
+
};
|
|
69
|
+
const is = (arg) => {
|
|
70
|
+
return (...args) => args.some((val) => TYPES[val](arg));
|
|
71
|
+
};
|
|
72
|
+
const isNot = (arg) => {
|
|
73
|
+
return (...args) => !args.some((val) => TYPES[val](arg));
|
|
74
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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 update_exports = {};
|
|
20
|
+
__export(update_exports, {
|
|
21
|
+
captureSnapshot: () => captureSnapshot
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(update_exports);
|
|
24
|
+
var import_key = require("./key.js");
|
|
25
|
+
const snapshot = {
|
|
26
|
+
snapshotId: import_key.createSnapshotId
|
|
27
|
+
};
|
|
28
|
+
const captureSnapshot = (element, options) => {
|
|
29
|
+
const ref = element.__ref;
|
|
30
|
+
const { currentSnapshot, calleeElement } = options;
|
|
31
|
+
const isCallee = calleeElement === element;
|
|
32
|
+
if (!calleeElement || isCallee) {
|
|
33
|
+
const createdStanpshot = snapshot.snapshotId();
|
|
34
|
+
ref.__currentSnapshot = createdStanpshot;
|
|
35
|
+
return [createdStanpshot, element];
|
|
36
|
+
}
|
|
37
|
+
const snapshotOnCallee = calleeElement.__ref.__currentSnapshot;
|
|
38
|
+
if (currentSnapshot < snapshotOnCallee) {
|
|
39
|
+
return [snapshotOnCallee, calleeElement, true];
|
|
40
|
+
}
|
|
41
|
+
return [snapshotOnCallee, calleeElement];
|
|
42
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { deepClone, deepMerge } from "./object.js";
|
|
2
|
+
import { isArray, isNumber, isString } from "./types.js";
|
|
3
|
+
const arrayContainsOtherArray = (arr1, arr2) => {
|
|
4
|
+
return arr2.every((val) => arr1.includes(val));
|
|
5
|
+
};
|
|
6
|
+
const getFrequencyInArray = (arr, value) => {
|
|
7
|
+
let count = 0;
|
|
8
|
+
for (let i = 0; i < arr.length; i++) {
|
|
9
|
+
if (arr[i] === value) count++;
|
|
10
|
+
}
|
|
11
|
+
return count;
|
|
12
|
+
};
|
|
13
|
+
const removeFromArray = (arr, index) => {
|
|
14
|
+
if (isString(index)) index = parseInt(index);
|
|
15
|
+
if (isNumber(index)) {
|
|
16
|
+
if (index < 0 || index >= arr.length || isNaN(index)) {
|
|
17
|
+
throw new Error("Invalid index");
|
|
18
|
+
}
|
|
19
|
+
arr.splice(index, 1);
|
|
20
|
+
} else {
|
|
21
|
+
throw new Error("Invalid index");
|
|
22
|
+
}
|
|
23
|
+
return arr;
|
|
24
|
+
};
|
|
25
|
+
const swapItemsInArray = (arr, i, j) => {
|
|
26
|
+
if (i < 0 || j < 0 || i >= arr.length || j >= arr.length) return;
|
|
27
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
28
|
+
};
|
|
29
|
+
const joinArrays = (...arrays) => {
|
|
30
|
+
return [].concat(...arrays);
|
|
31
|
+
};
|
|
32
|
+
const unstackArrayOfObjects = (arr, exclude = []) => {
|
|
33
|
+
return arr.reduce(
|
|
34
|
+
(a, c) => deepMerge(a, deepClone(c, { exclude }), exclude),
|
|
35
|
+
{}
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
const cutArrayBeforeValue = (arr, value) => {
|
|
39
|
+
const index = arr.indexOf(value);
|
|
40
|
+
if (index !== -1) {
|
|
41
|
+
return arr.slice(0, index);
|
|
42
|
+
}
|
|
43
|
+
return arr;
|
|
44
|
+
};
|
|
45
|
+
const cutArrayAfterValue = (arr, value) => {
|
|
46
|
+
if (!isArray(arr)) return;
|
|
47
|
+
const index = arr.indexOf(value);
|
|
48
|
+
if (index !== -1) {
|
|
49
|
+
return arr.slice(index + 1);
|
|
50
|
+
}
|
|
51
|
+
return arr;
|
|
52
|
+
};
|
|
53
|
+
const removeValueFromArray = (arr, value) => {
|
|
54
|
+
const index = arr.indexOf(value);
|
|
55
|
+
if (index > -1) {
|
|
56
|
+
const newArray = [...arr];
|
|
57
|
+
newArray.splice(index, 1);
|
|
58
|
+
return newArray;
|
|
59
|
+
}
|
|
60
|
+
return arr;
|
|
61
|
+
};
|
|
62
|
+
const removeValueFromArrayAll = (arr, value) => {
|
|
63
|
+
return arr.filter((item) => item !== value);
|
|
64
|
+
};
|
|
65
|
+
const addItemAfterEveryElement = (array, item) => {
|
|
66
|
+
const result = [];
|
|
67
|
+
for (let i = 0; i < array.length; i++) {
|
|
68
|
+
result.push(array[i]);
|
|
69
|
+
if (i < array.length - 1) {
|
|
70
|
+
result.push(item);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
|
|
76
|
+
const newArray = [...array];
|
|
77
|
+
const indexToMove = newArray.indexOf(valueToMove);
|
|
78
|
+
const indexToInsertBefore = newArray.indexOf(insertBeforeValue);
|
|
79
|
+
if (indexToMove !== -1 && indexToInsertBefore !== -1) {
|
|
80
|
+
const removedItem = newArray.splice(indexToMove, 1)[0];
|
|
81
|
+
const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1;
|
|
82
|
+
newArray.splice(insertIndex, 0, removedItem);
|
|
83
|
+
}
|
|
84
|
+
return newArray;
|
|
85
|
+
};
|
|
86
|
+
const arraysEqual = (arr1, arr2) => {
|
|
87
|
+
if (arr1.length !== arr2.length) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
91
|
+
if (arr1[i] !== arr2[i]) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
const filterArrays = (sourceArr, excludeArr) => {
|
|
98
|
+
return sourceArr.filter((item) => !excludeArr.includes(item));
|
|
99
|
+
};
|
|
100
|
+
const filterArraysFast = (sourceArr, excludeArr) => {
|
|
101
|
+
const excludeSet = new Set(excludeArr);
|
|
102
|
+
return sourceArr.filter((item) => !excludeSet.has(item));
|
|
103
|
+
};
|
|
104
|
+
const checkIfStringIsInArray = (string, arr) => {
|
|
105
|
+
if (!string) return 0;
|
|
106
|
+
let count = 0;
|
|
107
|
+
for (let i = 0; i < arr.length; i++) {
|
|
108
|
+
if (string.includes(arr[i])) count++;
|
|
109
|
+
}
|
|
110
|
+
return count;
|
|
111
|
+
};
|
|
112
|
+
const removeDuplicatesInArray = (arr) => {
|
|
113
|
+
if (!isArray(arr)) return arr;
|
|
114
|
+
return [...new Set(arr)];
|
|
115
|
+
};
|
|
116
|
+
const addProtoToArray = (state, proto) => {
|
|
117
|
+
for (const key in proto) {
|
|
118
|
+
Object.defineProperty(state, key, {
|
|
119
|
+
value: proto[key],
|
|
120
|
+
enumerable: false,
|
|
121
|
+
// Set this to true if you want the method to appear in for...in loops
|
|
122
|
+
configurable: true,
|
|
123
|
+
// Set this to true if you want to allow redefining/removing the property later
|
|
124
|
+
writable: true
|
|
125
|
+
// Set this to true if you want to allow changing the function later
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
export {
|
|
130
|
+
addItemAfterEveryElement,
|
|
131
|
+
addProtoToArray,
|
|
132
|
+
arrayContainsOtherArray,
|
|
133
|
+
arraysEqual,
|
|
134
|
+
checkIfStringIsInArray,
|
|
135
|
+
cutArrayAfterValue,
|
|
136
|
+
cutArrayBeforeValue,
|
|
137
|
+
filterArrays,
|
|
138
|
+
filterArraysFast,
|
|
139
|
+
getFrequencyInArray,
|
|
140
|
+
joinArrays,
|
|
141
|
+
removeDuplicatesInArray,
|
|
142
|
+
removeFromArray,
|
|
143
|
+
removeValueFromArray,
|
|
144
|
+
removeValueFromArrayAll,
|
|
145
|
+
reorderArrayByValues,
|
|
146
|
+
swapItemsInArray,
|
|
147
|
+
unstackArrayOfObjects
|
|
148
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
async function toggleFullscreen(opts) {
|
|
2
|
+
if (!document.fullscreenElement) {
|
|
3
|
+
try {
|
|
4
|
+
await (this.node || document).requestFullscreen();
|
|
5
|
+
} catch (err) {
|
|
6
|
+
console.warn(`Error attempting to enable fullscreen mode: ${err.message} (${err.name})`);
|
|
7
|
+
}
|
|
8
|
+
} else {
|
|
9
|
+
await document.exitFullscreen();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
toggleFullscreen
|
|
14
|
+
};
|
package/dist/esm/cdn.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
function onlyDotsAndNumbers(str) {
|
|
2
|
+
return /^[0-9.]+$/.test(str) && str !== "";
|
|
3
|
+
}
|
|
4
|
+
const CDN_PROVIDERS = {
|
|
5
|
+
skypack: {
|
|
6
|
+
url: "https://cdn.skypack.dev",
|
|
7
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.skypack.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
|
|
8
|
+
},
|
|
9
|
+
esmsh: {
|
|
10
|
+
url: "https://esm.sh",
|
|
11
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.esmsh.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
|
|
12
|
+
},
|
|
13
|
+
unpkg: {
|
|
14
|
+
url: "https://unpkg.com",
|
|
15
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.unpkg.url}/${pkg}${version !== "latest" ? `@${version}` : ""}?module`
|
|
16
|
+
},
|
|
17
|
+
jsdelivr: {
|
|
18
|
+
url: "https://cdn.jsdelivr.net/npm",
|
|
19
|
+
formatUrl: (pkg, version) => `${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version !== "latest" ? `@${version}` : ""}/+esm`
|
|
20
|
+
},
|
|
21
|
+
symbols: {
|
|
22
|
+
url: "https://pkg.symbo.ls",
|
|
23
|
+
formatUrl: (pkg, version) => {
|
|
24
|
+
if (pkg.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
|
|
25
|
+
return `${CDN_PROVIDERS.symbols.url}/${pkg}`;
|
|
26
|
+
}
|
|
27
|
+
return `${CDN_PROVIDERS.symbols.url}/${pkg}/${version}.js`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const PACKAGE_MANAGER_TO_CDN = {
|
|
32
|
+
"esm.sh": "esmsh",
|
|
33
|
+
"unpkg": "unpkg",
|
|
34
|
+
"skypack": "skypack",
|
|
35
|
+
"jsdelivr": "jsdelivr",
|
|
36
|
+
"pkg.symbo.ls": "symbols"
|
|
37
|
+
};
|
|
38
|
+
const getCdnProviderFromConfig = (symbolsConfig = {}) => {
|
|
39
|
+
const { packageManager } = symbolsConfig;
|
|
40
|
+
return PACKAGE_MANAGER_TO_CDN[packageManager] || null;
|
|
41
|
+
};
|
|
42
|
+
const getCDNUrl = (packageName, version = "latest", provider = "esmsh") => {
|
|
43
|
+
const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh;
|
|
44
|
+
return cdnConfig.formatUrl(packageName, version);
|
|
45
|
+
};
|
|
46
|
+
const getImportMapScript = (data, defaultProvider = "skypack") => {
|
|
47
|
+
const dependencies = data.dependencies || {};
|
|
48
|
+
const keys = Object.keys(dependencies);
|
|
49
|
+
if (!keys.length) return "";
|
|
50
|
+
const imports = {};
|
|
51
|
+
for (const pkgName of keys) {
|
|
52
|
+
const version = dependencies[pkgName] || "latest";
|
|
53
|
+
imports[pkgName] = getCDNUrl(pkgName, version, defaultProvider);
|
|
54
|
+
}
|
|
55
|
+
return `<script type="importmap">{
|
|
56
|
+
"imports": ${JSON.stringify(imports, null, 2)}
|
|
57
|
+
}<\/script>`;
|
|
58
|
+
};
|
|
59
|
+
export {
|
|
60
|
+
CDN_PROVIDERS,
|
|
61
|
+
PACKAGE_MANAGER_TO_CDN,
|
|
62
|
+
getCDNUrl,
|
|
63
|
+
getCdnProviderFromConfig,
|
|
64
|
+
getImportMapScript
|
|
65
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createExtendsFromKeys } from "./extends.js";
|
|
2
|
+
import { isString } from "./types.js";
|
|
3
|
+
const matchesComponentNaming = (key) => {
|
|
4
|
+
if (!isString(key) || !key.length) return false;
|
|
5
|
+
const code = key.charCodeAt(0);
|
|
6
|
+
return code >= 65 && code <= 90;
|
|
7
|
+
};
|
|
8
|
+
function getCapitalCaseKeys(obj) {
|
|
9
|
+
return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
|
|
10
|
+
}
|
|
11
|
+
function getSpreadChildren(obj) {
|
|
12
|
+
return Object.keys(obj).filter((key) => /^\d+$/.test(key));
|
|
13
|
+
}
|
|
14
|
+
function isContextComponent(element, parent, passedKey) {
|
|
15
|
+
const { context } = parent || {};
|
|
16
|
+
const [extendsKey] = createExtendsFromKeys(passedKey);
|
|
17
|
+
const key = passedKey || extendsKey;
|
|
18
|
+
return context?.components?.[key] || context?.pages?.[key];
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
getCapitalCaseKeys,
|
|
22
|
+
getSpreadChildren,
|
|
23
|
+
isContextComponent,
|
|
24
|
+
matchesComponentNaming
|
|
25
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isUndefined } from "./types.js";
|
|
2
|
+
import { document } from "./globals.js";
|
|
3
|
+
const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
|
|
4
|
+
const setCookie = (cname, cvalue, exdays = 365) => {
|
|
5
|
+
if (isUndefined(document) || isUndefined(document.cookie)) return;
|
|
6
|
+
const d = /* @__PURE__ */ new Date();
|
|
7
|
+
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
|
|
8
|
+
const expires = `expires=${d.toUTCString()}`;
|
|
9
|
+
document.cookie = `${cname}=${cvalue};${expires};path=/`;
|
|
10
|
+
};
|
|
11
|
+
const getCookie = (cname) => {
|
|
12
|
+
if (isUndefined(document) || isUndefined(document.cookie)) return;
|
|
13
|
+
const name = `${cname}=`;
|
|
14
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
15
|
+
const ca = decodedCookie.split(";");
|
|
16
|
+
for (let i = 0; i < ca.length; i++) {
|
|
17
|
+
let c = ca[i];
|
|
18
|
+
while (c.charAt(0) === " ") c = c.substring(1);
|
|
19
|
+
if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
|
|
20
|
+
}
|
|
21
|
+
return "";
|
|
22
|
+
};
|
|
23
|
+
const removeCookie = (cname) => {
|
|
24
|
+
if (isUndefined(document) || isUndefined(document.cookie)) return;
|
|
25
|
+
document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
26
|
+
};
|
|
27
|
+
function getLocalStorage(key) {
|
|
28
|
+
if (!window.localStorage) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
const item = window.localStorage.getItem(key);
|
|
32
|
+
if (item === null) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(item);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function setLocalStorage(key, data) {
|
|
42
|
+
if (!window.localStorage || data === void 0 || data === null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const value = typeof data === "object" ? JSON.stringify(data) : data;
|
|
46
|
+
window.localStorage.setItem(key, value);
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
getCookie,
|
|
50
|
+
getLocalStorage,
|
|
51
|
+
isMobile,
|
|
52
|
+
removeCookie,
|
|
53
|
+
setCookie,
|
|
54
|
+
setLocalStorage
|
|
55
|
+
};
|
package/dist/esm/date.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const formatDate = (timestamp) => {
|
|
2
|
+
if (!timestamp) return "";
|
|
3
|
+
const d = new Date(timestamp);
|
|
4
|
+
const ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d);
|
|
5
|
+
const mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d);
|
|
6
|
+
const da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d);
|
|
7
|
+
return `${da} ${mo}, ${ye}`;
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
formatDate
|
|
11
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const detectHeightOnInit = (element, state) => {
|
|
2
|
+
const heightTimeout = setTimeout(() => {
|
|
3
|
+
const { props } = element;
|
|
4
|
+
if (!state.clientHeight) {
|
|
5
|
+
const {
|
|
6
|
+
node: { clientHeight }
|
|
7
|
+
} = element;
|
|
8
|
+
if (clientHeight) {
|
|
9
|
+
state.clientHeight = clientHeight;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (state.active) {
|
|
13
|
+
if (props.height === "auto") return;
|
|
14
|
+
element.update(
|
|
15
|
+
{
|
|
16
|
+
height: state.clientHeight
|
|
17
|
+
},
|
|
18
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
19
|
+
);
|
|
20
|
+
const setAutoTimeout = setTimeout(() => {
|
|
21
|
+
element.update(
|
|
22
|
+
{
|
|
23
|
+
height: "auto"
|
|
24
|
+
},
|
|
25
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
26
|
+
);
|
|
27
|
+
clearTimeout(setAutoTimeout);
|
|
28
|
+
}, 450);
|
|
29
|
+
} else {
|
|
30
|
+
element.update(
|
|
31
|
+
{
|
|
32
|
+
height: "0"
|
|
33
|
+
},
|
|
34
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
clearTimeout(heightTimeout);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
detectHeightOnInit
|
|
42
|
+
};
|