@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,173 @@
|
|
|
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 state_exports = {};
|
|
20
|
+
__export(state_exports, {
|
|
21
|
+
applyDependentState: () => applyDependentState,
|
|
22
|
+
checkForStateTypes: () => checkForStateTypes,
|
|
23
|
+
checkIfInherits: () => checkIfInherits,
|
|
24
|
+
createInheritedState: () => createInheritedState,
|
|
25
|
+
createNestedObjectByKeyPath: () => createNestedObjectByKeyPath,
|
|
26
|
+
findInheritedState: () => findInheritedState,
|
|
27
|
+
getChildStateInKey: () => getChildStateInKey,
|
|
28
|
+
getParentStateInKey: () => getParentStateInKey,
|
|
29
|
+
getRootStateInKey: () => getRootStateInKey,
|
|
30
|
+
isState: () => isState,
|
|
31
|
+
overwriteState: () => overwriteState
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(state_exports);
|
|
34
|
+
var import_array = require("./array.js");
|
|
35
|
+
var import_keys = require("./keys.js");
|
|
36
|
+
var import_object = require("./object.js");
|
|
37
|
+
var import_types = require("./types.js");
|
|
38
|
+
const checkForStateTypes = (element) => {
|
|
39
|
+
const { state: orig, props, __ref: ref } = element;
|
|
40
|
+
const state = props?.state || orig;
|
|
41
|
+
if ((0, import_types.is)(state)("string", "number")) {
|
|
42
|
+
ref.__state = state;
|
|
43
|
+
return { value: state };
|
|
44
|
+
} else if (state === true) {
|
|
45
|
+
ref.__state = element.key;
|
|
46
|
+
return {};
|
|
47
|
+
} else if (state) {
|
|
48
|
+
ref.__hasRootState = true;
|
|
49
|
+
return state;
|
|
50
|
+
} else {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const getRootStateInKey = (stateKey, parentState) => {
|
|
55
|
+
if (!stateKey.includes("~/")) return;
|
|
56
|
+
const arr = stateKey.split("~/");
|
|
57
|
+
if (arr.length > 1) return parentState.root;
|
|
58
|
+
};
|
|
59
|
+
const getParentStateInKey = (stateKey, parentState) => {
|
|
60
|
+
if (!stateKey.includes("../")) return;
|
|
61
|
+
const arr = stateKey.split("../");
|
|
62
|
+
const arrLength = arr.length - 1;
|
|
63
|
+
for (let i = 0; i < arrLength; i++) {
|
|
64
|
+
if (!parentState.parent) return null;
|
|
65
|
+
parentState = parentState.parent;
|
|
66
|
+
}
|
|
67
|
+
return parentState;
|
|
68
|
+
};
|
|
69
|
+
const getChildStateInKey = (stateKey, parentState, options = {}) => {
|
|
70
|
+
const arr = (0, import_types.isString)(stateKey) ? stateKey.split("/") : [stateKey];
|
|
71
|
+
const arrLength = arr.length - 1;
|
|
72
|
+
for (let i = 0; i < arrLength; i++) {
|
|
73
|
+
const childKey = arr[i];
|
|
74
|
+
const grandChildKey = arr[i + 1];
|
|
75
|
+
if (childKey === "__proto__" || grandChildKey === "__proto__") return;
|
|
76
|
+
let childInParent = parentState[childKey];
|
|
77
|
+
if (!childInParent) childInParent = parentState[childKey] = {};
|
|
78
|
+
if (!childInParent[grandChildKey]) childInParent[grandChildKey] = {};
|
|
79
|
+
stateKey = grandChildKey;
|
|
80
|
+
parentState = childInParent;
|
|
81
|
+
}
|
|
82
|
+
if (options.returnParent) return parentState;
|
|
83
|
+
return parentState[stateKey];
|
|
84
|
+
};
|
|
85
|
+
const findInheritedState = (element, parent, options = {}) => {
|
|
86
|
+
const ref = element.__ref;
|
|
87
|
+
let stateKey = ref.__state;
|
|
88
|
+
if (!checkIfInherits(element)) return;
|
|
89
|
+
const rootState = getRootStateInKey(stateKey, parent.state);
|
|
90
|
+
let parentState = parent.state;
|
|
91
|
+
if (rootState) {
|
|
92
|
+
parentState = rootState;
|
|
93
|
+
stateKey = stateKey.replaceAll("~/", "");
|
|
94
|
+
} else {
|
|
95
|
+
const findGrandParentState = getParentStateInKey(stateKey, parent.state);
|
|
96
|
+
if (findGrandParentState) {
|
|
97
|
+
parentState = findGrandParentState;
|
|
98
|
+
stateKey = stateKey.replaceAll("../", "");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!parentState) return;
|
|
102
|
+
return getChildStateInKey(stateKey, parentState, options);
|
|
103
|
+
};
|
|
104
|
+
const createInheritedState = (element, parent) => {
|
|
105
|
+
const ref = element.__ref;
|
|
106
|
+
const inheritedState = findInheritedState(element, parent);
|
|
107
|
+
if (inheritedState === void 0) return element.state;
|
|
108
|
+
if ((0, import_types.is)(inheritedState)("object", "array")) {
|
|
109
|
+
return (0, import_object.deepClone)(inheritedState);
|
|
110
|
+
} else if ((0, import_types.is)(inheritedState)("string", "number", "boolean")) {
|
|
111
|
+
ref.__stateType = typeof inheritedState;
|
|
112
|
+
return { value: inheritedState };
|
|
113
|
+
}
|
|
114
|
+
console.warn(ref.__state, "is not present. Replacing with", {});
|
|
115
|
+
};
|
|
116
|
+
const checkIfInherits = (element) => {
|
|
117
|
+
const { __ref: ref } = element;
|
|
118
|
+
const stateKey = ref?.__state;
|
|
119
|
+
if (stateKey && (0, import_types.is)(stateKey)("number", "string", "boolean")) return true;
|
|
120
|
+
return false;
|
|
121
|
+
};
|
|
122
|
+
const isState = function(state) {
|
|
123
|
+
if (!(0, import_types.isObjectLike)(state)) return false;
|
|
124
|
+
return Boolean(
|
|
125
|
+
state.update && state.parse && state.clean && state.create && state.parent && state.destroy && state.rootUpdate && state.parentUpdate && state.keys && state.values && state.toggle && state.replace && state.quietUpdate && state.quietReplace && state.add && state.apply && state.applyReplace && state.setByPath && state.setPathCollection && state.removeByPath && state.removePathCollection && state.getByPath && state.applyFunction && state.__element && state.__children
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
const createNestedObjectByKeyPath = (path, value) => {
|
|
129
|
+
if (!path) {
|
|
130
|
+
return value || {};
|
|
131
|
+
}
|
|
132
|
+
const keys = path.split("/");
|
|
133
|
+
const obj = {};
|
|
134
|
+
let ref = obj;
|
|
135
|
+
const lastIdx = keys.length - 1;
|
|
136
|
+
for (let i = 0; i <= lastIdx; i++) {
|
|
137
|
+
ref[keys[i]] = i === lastIdx ? value || {} : {};
|
|
138
|
+
ref = ref[keys[i]];
|
|
139
|
+
}
|
|
140
|
+
return obj;
|
|
141
|
+
};
|
|
142
|
+
const applyDependentState = (element, state) => {
|
|
143
|
+
const { __element } = state;
|
|
144
|
+
const origState = __element?.state;
|
|
145
|
+
if (!origState) return;
|
|
146
|
+
const dependentState = (0, import_object.deepClone)(origState, import_keys.STATE_METHODS);
|
|
147
|
+
const newDepends = { [element.key]: dependentState };
|
|
148
|
+
const __depends = (0, import_types.isObject)(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
|
|
149
|
+
if (Array.isArray(origState)) {
|
|
150
|
+
(0, import_array.addProtoToArray)(origState, {
|
|
151
|
+
...Object.getPrototypeOf(origState),
|
|
152
|
+
__depends
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
Object.setPrototypeOf(origState, {
|
|
156
|
+
...Object.getPrototypeOf(origState),
|
|
157
|
+
__depends
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return dependentState;
|
|
161
|
+
};
|
|
162
|
+
const overwriteState = (state, obj, options = {}) => {
|
|
163
|
+
const { overwrite } = options;
|
|
164
|
+
if (!overwrite) return;
|
|
165
|
+
const shallow = overwrite === "shallow";
|
|
166
|
+
const merge = overwrite === "merge";
|
|
167
|
+
if (merge) {
|
|
168
|
+
(0, import_object.deepMerge)(state, obj, import_keys.STATE_METHODS);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const overwriteFunc = shallow ? import_object.overwriteShallow : import_object.overwriteDeep;
|
|
172
|
+
overwriteFunc(state, obj, import_keys.STATE_METHODS);
|
|
173
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
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 string_extra_exports = {};
|
|
20
|
+
__export(string_extra_exports, {
|
|
21
|
+
arrayzeValue: () => arrayzeValue,
|
|
22
|
+
copyJavaScriptToClipboard: () => copyJavaScriptToClipboard,
|
|
23
|
+
copyStringToClipboard: () => copyStringToClipboard,
|
|
24
|
+
removeChars: () => removeChars,
|
|
25
|
+
toCamelCase: () => toCamelCase,
|
|
26
|
+
toDashCase: () => toDashCase,
|
|
27
|
+
toDescriptionCase: () => toDescriptionCase,
|
|
28
|
+
toTitleCase: () => toTitleCase
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(string_extra_exports);
|
|
31
|
+
var import_types = require("./types.js");
|
|
32
|
+
const copyStringToClipboard = async (str) => {
|
|
33
|
+
try {
|
|
34
|
+
await navigator.clipboard.writeText(str);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.warn("Failed to copy text: ", err);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const copyJavaScriptToClipboard = async (jsCode) => {
|
|
40
|
+
try {
|
|
41
|
+
const blob = new Blob([jsCode], { type: "text/javascript" });
|
|
42
|
+
const clipboardItem = new window.ClipboardItem({ "text/plain": blob });
|
|
43
|
+
await navigator.clipboard.write([clipboardItem]);
|
|
44
|
+
console.log("JavaScript code copied to clipboard as text/javascript");
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.error("Failed to copy JavaScript code: ", err);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const removeChars = (str) => {
|
|
50
|
+
return str.replace(/[^a-zA-Z0-9_]/g, "");
|
|
51
|
+
};
|
|
52
|
+
const toCamelCase = (str) => {
|
|
53
|
+
if (typeof str !== "string") str = String(str || "");
|
|
54
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
55
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
56
|
+
}).replace(/\s+/g, "");
|
|
57
|
+
};
|
|
58
|
+
const toTitleCase = (str) => str && str.replace(/\w\S*/g, (txt) => {
|
|
59
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
60
|
+
});
|
|
61
|
+
const toDashCase = (val) => val.replace(/[^a-zA-Z0-9]/g, " ").trim().toLowerCase().replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
62
|
+
const toDescriptionCase = (str = "") => {
|
|
63
|
+
if (typeof str !== "string") return;
|
|
64
|
+
const result = str.replace(/([A-Z])/g, " $1");
|
|
65
|
+
return result.charAt(0).toUpperCase() + result.slice(1);
|
|
66
|
+
};
|
|
67
|
+
const arrayzeValue = (val) => {
|
|
68
|
+
if ((0, import_types.isArray)(val)) return val;
|
|
69
|
+
if ((0, import_types.isString)(val)) return val.split(" ");
|
|
70
|
+
if ((0, import_types.isObject)(val)) return Object.values(val);
|
|
71
|
+
if ((0, import_types.isNumber)(val)) return [val];
|
|
72
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
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 string_exports = {};
|
|
20
|
+
__export(string_exports, {
|
|
21
|
+
customDecodeURIComponent: () => customDecodeURIComponent,
|
|
22
|
+
customEncodeURIComponent: () => customEncodeURIComponent,
|
|
23
|
+
decodeNewlines: () => decodeNewlines,
|
|
24
|
+
encodeNewlines: () => encodeNewlines,
|
|
25
|
+
findKeyPosition: () => findKeyPosition,
|
|
26
|
+
lowercaseFirstLetter: () => lowercaseFirstLetter,
|
|
27
|
+
replaceLiteralsWithObjectFields: () => replaceLiteralsWithObjectFields,
|
|
28
|
+
replaceOctalEscapeSequences: () => replaceOctalEscapeSequences,
|
|
29
|
+
stringIncludesAny: () => stringIncludesAny,
|
|
30
|
+
trimStringFromSymbols: () => trimStringFromSymbols
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(string_exports);
|
|
33
|
+
const stringIncludesAny = (str, characters) => {
|
|
34
|
+
for (const char of characters) {
|
|
35
|
+
if (str.includes(char)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
const trimStringFromSymbols = (str, characters) => {
|
|
42
|
+
const pattern = new RegExp(`[${characters.join("\\")}]`, "g");
|
|
43
|
+
return str.replace(pattern, "");
|
|
44
|
+
};
|
|
45
|
+
const brackRegex = {
|
|
46
|
+
2: /{{\s*((?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}/g,
|
|
47
|
+
3: /{{{(\s*(?:\.\.\/)*)([\w\d.]+)\s*(?:\|\s*([\w\d.]+))?\s*}}}/g
|
|
48
|
+
};
|
|
49
|
+
const getNestedValue = (obj, path) => {
|
|
50
|
+
return path.split(".").reduce((acc, part) => {
|
|
51
|
+
return acc?.[part];
|
|
52
|
+
}, obj);
|
|
53
|
+
};
|
|
54
|
+
function replaceLiteralsWithObjectFields(str, state, options = {}) {
|
|
55
|
+
const { bracketsLength = 2 } = options;
|
|
56
|
+
const bracketPattern = bracketsLength === 3 ? "{{{" : "{{";
|
|
57
|
+
if (!str.includes(bracketPattern)) return str;
|
|
58
|
+
const reg = brackRegex[bracketsLength];
|
|
59
|
+
const obj = state || this.state || {};
|
|
60
|
+
const element = this;
|
|
61
|
+
return str.replace(reg, (_, parentPath, variable, filter) => {
|
|
62
|
+
const key = variable.trim();
|
|
63
|
+
if (filter) {
|
|
64
|
+
const ctx = element?.context;
|
|
65
|
+
const filterFn = ctx?.functions?.[filter] || ctx?.utils?.[filter] || ctx?.methods?.[filter] || ctx?.snippets?.[filter] || element?.[filter];
|
|
66
|
+
if (filterFn && typeof filterFn === "function") {
|
|
67
|
+
try {
|
|
68
|
+
return String(filterFn.call(element, key) ?? "");
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return "";
|
|
74
|
+
}
|
|
75
|
+
if (parentPath) {
|
|
76
|
+
const parentLevels = (parentPath.match(/\.\.\//g) || []).length;
|
|
77
|
+
let parentState = obj;
|
|
78
|
+
for (let i = 0; i < parentLevels; i++) {
|
|
79
|
+
if (!parentState || !parentState.parent) return "";
|
|
80
|
+
parentState = parentState.parent;
|
|
81
|
+
}
|
|
82
|
+
if (key === "parent") {
|
|
83
|
+
return String(parentState.value ?? "");
|
|
84
|
+
}
|
|
85
|
+
const value = getNestedValue(parentState, key);
|
|
86
|
+
return String(value ?? "");
|
|
87
|
+
} else {
|
|
88
|
+
const value = getNestedValue(obj, key);
|
|
89
|
+
if (value != null) return String(value);
|
|
90
|
+
const poly = element?.context?.polyglot;
|
|
91
|
+
if (poly?.translations) {
|
|
92
|
+
const lang = obj?.root?.lang || obj?.lang || element?.context?.state?.lang || poly.defaultLang || "en";
|
|
93
|
+
const langT = poly.translations[lang];
|
|
94
|
+
if (langT) {
|
|
95
|
+
const tValue = getNestedValue(langT, key);
|
|
96
|
+
if (tValue != null && typeof tValue !== "object") return String(tValue);
|
|
97
|
+
for (const section in langT) {
|
|
98
|
+
const sectionData = langT[section];
|
|
99
|
+
if (sectionData && typeof sectionData === "object" && !Array.isArray(sectionData)) {
|
|
100
|
+
const nested = getNestedValue(sectionData, key);
|
|
101
|
+
if (nested != null && typeof nested !== "object") return String(nested);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const topValue = getNestedValue(poly.translations, key);
|
|
106
|
+
if (topValue != null && typeof topValue !== "object") return String(topValue);
|
|
107
|
+
}
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const lowercaseFirstLetter = (inputString) => {
|
|
113
|
+
return `${inputString.charAt(0).toLowerCase()}${inputString.slice(1)}`;
|
|
114
|
+
};
|
|
115
|
+
const findKeyPosition = (str, key) => {
|
|
116
|
+
const lines = str.split("\n");
|
|
117
|
+
let startLineNumber = -1;
|
|
118
|
+
let endLineNumber = -1;
|
|
119
|
+
let startColumn = -1;
|
|
120
|
+
let endColumn = -1;
|
|
121
|
+
const keyPattern = new RegExp(`\\b${key}\\b\\s*:\\s*`);
|
|
122
|
+
let braceCount = 0;
|
|
123
|
+
let foundKey = false;
|
|
124
|
+
for (let i = 0; i < lines.length; i++) {
|
|
125
|
+
if (keyPattern.test(lines[i]) && !foundKey) {
|
|
126
|
+
foundKey = true;
|
|
127
|
+
startLineNumber = i + 1;
|
|
128
|
+
startColumn = lines[i].indexOf(key) + 1;
|
|
129
|
+
if (lines[i].includes("{}")) {
|
|
130
|
+
endLineNumber = startLineNumber;
|
|
131
|
+
endColumn = lines[i].indexOf("{}") + 3;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
const line = lines[i].slice(startColumn + key.length);
|
|
135
|
+
if (line.includes("{") || line.includes("[")) {
|
|
136
|
+
braceCount = 1;
|
|
137
|
+
} else {
|
|
138
|
+
endLineNumber = i + 1;
|
|
139
|
+
endColumn = lines[i].length + 1;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
} else if (foundKey) {
|
|
143
|
+
braceCount += (lines[i].match(/{/g) || []).length;
|
|
144
|
+
braceCount += (lines[i].match(/\[/g) || []).length;
|
|
145
|
+
braceCount -= (lines[i].match(/}/g) || []).length;
|
|
146
|
+
braceCount -= (lines[i].match(/]/g) || []).length;
|
|
147
|
+
if (braceCount === 0) {
|
|
148
|
+
endLineNumber = i + 1;
|
|
149
|
+
endColumn = lines[i].lastIndexOf("}") !== -1 ? lines[i].lastIndexOf("}") + 2 : lines[i].length + 1;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
startColumn,
|
|
156
|
+
endColumn,
|
|
157
|
+
startLineNumber,
|
|
158
|
+
endLineNumber
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
const RE_OCTAL = /\\([0-7]{1,3})/g;
|
|
162
|
+
const replaceOctalEscapeSequences = (str) => {
|
|
163
|
+
return str.replace(RE_OCTAL, (_, p1) => String.fromCharCode(parseInt(p1, 8)));
|
|
164
|
+
};
|
|
165
|
+
const encodeNewlines = (str) => {
|
|
166
|
+
return str.replace(/\n/g, "/////n").replace(/`/g, "/////tilde").replace(/\$/g, "/////dlrsgn");
|
|
167
|
+
};
|
|
168
|
+
const decodeNewlines = (encodedStr) => {
|
|
169
|
+
return encodedStr.replace(/\/\/\/\/\/n/g, "\n").replace(/\/\/\/\/\/tilde/g, "`").replace(/\/\/\/\/\/dlrsgn/g, "$");
|
|
170
|
+
};
|
|
171
|
+
const RE_NON_ALNUM = /[^a-zA-Z0-9\s]/g;
|
|
172
|
+
const customEncodeURIComponent = (str) => {
|
|
173
|
+
return str.replace(
|
|
174
|
+
RE_NON_ALNUM,
|
|
175
|
+
(char) => "%" + char.charCodeAt(0).toString(16).toUpperCase()
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
const customDecodeURIComponent = (encodedStr) => {
|
|
179
|
+
return encodedStr.replace(
|
|
180
|
+
/%[0-9A-Fa-f]{2}/g,
|
|
181
|
+
(match) => String.fromCharCode(parseInt(match.slice(1), 16))
|
|
182
|
+
);
|
|
183
|
+
};
|
package/dist/cjs/style.js
CHANGED
|
@@ -16,14 +16,12 @@ 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
|
|
21
19
|
var style_exports = {};
|
|
22
20
|
__export(style_exports, {
|
|
23
21
|
getEmotionStylesheet: () => getEmotionStylesheet
|
|
24
22
|
});
|
|
25
23
|
module.exports = __toCommonJS(style_exports);
|
|
26
|
-
|
|
24
|
+
const getEmotionStylesheet = () => {
|
|
27
25
|
const stylesheet = document.styleSheets[0];
|
|
28
26
|
let str = "";
|
|
29
27
|
if (stylesheet) {
|
package/dist/cjs/tags.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
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 tags_exports = {};
|
|
20
|
+
__export(tags_exports, {
|
|
21
|
+
HTML_TAGS: () => HTML_TAGS,
|
|
22
|
+
SVG_TAGS: () => SVG_TAGS,
|
|
23
|
+
isValidHtmlTag: () => isValidHtmlTag
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(tags_exports);
|
|
26
|
+
const HTML_TAGS = {
|
|
27
|
+
root: ["body", "html"],
|
|
28
|
+
head: ["title", "base", "meta", "style", "noscript", "script"],
|
|
29
|
+
body: /* @__PURE__ */ new Set([
|
|
30
|
+
"string",
|
|
31
|
+
"style",
|
|
32
|
+
"fragment",
|
|
33
|
+
"a",
|
|
34
|
+
"abbr",
|
|
35
|
+
"acronym",
|
|
36
|
+
"address",
|
|
37
|
+
"applet",
|
|
38
|
+
"area",
|
|
39
|
+
"article",
|
|
40
|
+
"aside",
|
|
41
|
+
"audio",
|
|
42
|
+
"b",
|
|
43
|
+
"basefont",
|
|
44
|
+
"bdi",
|
|
45
|
+
"bdo",
|
|
46
|
+
"big",
|
|
47
|
+
"blockquote",
|
|
48
|
+
"br",
|
|
49
|
+
"button",
|
|
50
|
+
"canvas",
|
|
51
|
+
"caption",
|
|
52
|
+
"center",
|
|
53
|
+
"cite",
|
|
54
|
+
"code",
|
|
55
|
+
"search",
|
|
56
|
+
"col",
|
|
57
|
+
"colgroup",
|
|
58
|
+
"data",
|
|
59
|
+
"datalist",
|
|
60
|
+
"dd",
|
|
61
|
+
"del",
|
|
62
|
+
"details",
|
|
63
|
+
"dfn",
|
|
64
|
+
"dialog",
|
|
65
|
+
"dir",
|
|
66
|
+
"div",
|
|
67
|
+
"dl",
|
|
68
|
+
"dt",
|
|
69
|
+
"em",
|
|
70
|
+
"embed",
|
|
71
|
+
"fieldset",
|
|
72
|
+
"figcaption",
|
|
73
|
+
"figure",
|
|
74
|
+
"font",
|
|
75
|
+
"footer",
|
|
76
|
+
"form",
|
|
77
|
+
"frame",
|
|
78
|
+
"frameset",
|
|
79
|
+
"h1",
|
|
80
|
+
"h2",
|
|
81
|
+
"h3",
|
|
82
|
+
"h4",
|
|
83
|
+
"h5",
|
|
84
|
+
"h6",
|
|
85
|
+
"head",
|
|
86
|
+
"header",
|
|
87
|
+
"hr",
|
|
88
|
+
"i",
|
|
89
|
+
"iframe",
|
|
90
|
+
"img",
|
|
91
|
+
"input",
|
|
92
|
+
"ins",
|
|
93
|
+
"kbd",
|
|
94
|
+
"label",
|
|
95
|
+
"legend",
|
|
96
|
+
"li",
|
|
97
|
+
"link",
|
|
98
|
+
"main",
|
|
99
|
+
"map",
|
|
100
|
+
"mark",
|
|
101
|
+
"meter",
|
|
102
|
+
"nav",
|
|
103
|
+
"noframes",
|
|
104
|
+
"noscript",
|
|
105
|
+
"object",
|
|
106
|
+
"ol",
|
|
107
|
+
"optgroup",
|
|
108
|
+
"option",
|
|
109
|
+
"output",
|
|
110
|
+
"p",
|
|
111
|
+
"param",
|
|
112
|
+
"picture",
|
|
113
|
+
"pre",
|
|
114
|
+
"progress",
|
|
115
|
+
"hgroup",
|
|
116
|
+
"q",
|
|
117
|
+
"rp",
|
|
118
|
+
"rt",
|
|
119
|
+
"ruby",
|
|
120
|
+
"s",
|
|
121
|
+
"samp",
|
|
122
|
+
"script",
|
|
123
|
+
"section",
|
|
124
|
+
"select",
|
|
125
|
+
"small",
|
|
126
|
+
"source",
|
|
127
|
+
"span",
|
|
128
|
+
"strike",
|
|
129
|
+
"strong",
|
|
130
|
+
"sub",
|
|
131
|
+
"summary",
|
|
132
|
+
"sup",
|
|
133
|
+
"table",
|
|
134
|
+
"tbody",
|
|
135
|
+
"td",
|
|
136
|
+
"template",
|
|
137
|
+
"hgroup",
|
|
138
|
+
"textarea",
|
|
139
|
+
"tfoot",
|
|
140
|
+
"th",
|
|
141
|
+
"thead",
|
|
142
|
+
"time",
|
|
143
|
+
"tr",
|
|
144
|
+
"track",
|
|
145
|
+
"tt",
|
|
146
|
+
"u",
|
|
147
|
+
"ul",
|
|
148
|
+
"var",
|
|
149
|
+
"video",
|
|
150
|
+
"wbr",
|
|
151
|
+
// SVG
|
|
152
|
+
"svg",
|
|
153
|
+
"path",
|
|
154
|
+
"circle",
|
|
155
|
+
"ellipse",
|
|
156
|
+
"line",
|
|
157
|
+
"polygon",
|
|
158
|
+
"polyline",
|
|
159
|
+
"rect",
|
|
160
|
+
"g",
|
|
161
|
+
"defs",
|
|
162
|
+
"symbol",
|
|
163
|
+
"use",
|
|
164
|
+
"text",
|
|
165
|
+
"tspan",
|
|
166
|
+
"image",
|
|
167
|
+
"clipPath",
|
|
168
|
+
"mask",
|
|
169
|
+
"pattern",
|
|
170
|
+
"marker",
|
|
171
|
+
"linearGradient",
|
|
172
|
+
"radialGradient",
|
|
173
|
+
"stop",
|
|
174
|
+
"filter",
|
|
175
|
+
"feGaussianBlur",
|
|
176
|
+
"feOffset",
|
|
177
|
+
"feMerge",
|
|
178
|
+
"feMergeNode",
|
|
179
|
+
"feBlend",
|
|
180
|
+
"feColorMatrix",
|
|
181
|
+
"feFlood",
|
|
182
|
+
"feComposite",
|
|
183
|
+
"foreignObject"
|
|
184
|
+
])
|
|
185
|
+
};
|
|
186
|
+
const SVG_TAGS = /* @__PURE__ */ new Set([
|
|
187
|
+
"svg",
|
|
188
|
+
"path",
|
|
189
|
+
"circle",
|
|
190
|
+
"ellipse",
|
|
191
|
+
"line",
|
|
192
|
+
"polygon",
|
|
193
|
+
"polyline",
|
|
194
|
+
"rect",
|
|
195
|
+
"g",
|
|
196
|
+
"defs",
|
|
197
|
+
"symbol",
|
|
198
|
+
"use",
|
|
199
|
+
"text",
|
|
200
|
+
"tspan",
|
|
201
|
+
"image",
|
|
202
|
+
"clipPath",
|
|
203
|
+
"mask",
|
|
204
|
+
"pattern",
|
|
205
|
+
"marker",
|
|
206
|
+
"linearGradient",
|
|
207
|
+
"radialGradient",
|
|
208
|
+
"stop",
|
|
209
|
+
"filter",
|
|
210
|
+
"feGaussianBlur",
|
|
211
|
+
"feOffset",
|
|
212
|
+
"feMerge",
|
|
213
|
+
"feMergeNode",
|
|
214
|
+
"feBlend",
|
|
215
|
+
"feColorMatrix",
|
|
216
|
+
"feFlood",
|
|
217
|
+
"feComposite",
|
|
218
|
+
"foreignObject"
|
|
219
|
+
]);
|
|
220
|
+
const isValidHtmlTag = (arg) => HTML_TAGS.body.has(arg);
|