@symbo.ls/smbls-utils 3.2.7
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 +21 -0
- package/dist/cjs/browser.js +34 -0
- package/dist/cjs/date.js +31 -0
- package/dist/cjs/detectHeight.js +62 -0
- package/dist/cjs/fibonacci.js +30 -0
- package/dist/cjs/files.js +24 -0
- package/dist/cjs/index.js +78 -0
- package/dist/cjs/load.js +171 -0
- package/dist/cjs/scaling.js +35 -0
- package/dist/cjs/style.js +40 -0
- package/dist/esm/browser.js +14 -0
- package/dist/esm/date.js +11 -0
- package/dist/esm/detectHeight.js +42 -0
- package/dist/esm/fibonacci.js +10 -0
- package/dist/esm/files.js +4 -0
- package/dist/esm/index.js +57 -0
- package/dist/esm/load.js +151 -0
- package/dist/esm/scaling.js +15 -0
- package/dist/esm/style.js +20 -0
- package/dist/iife/index.js +289 -0
- package/package.json +41 -0
- package/src/browser.js +13 -0
- package/src/date.js +10 -0
- package/src/detectHeight.js +42 -0
- package/src/fibonacci.js +9 -0
- package/src/files.js +3 -0
- package/src/index.js +75 -0
- package/src/load.js +236 -0
- package/src/scaling.js +15 -0
- package/src/style.js +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 symbo.ls
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
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/date.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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 date_exports = {};
|
|
20
|
+
__export(date_exports, {
|
|
21
|
+
formatDate: () => formatDate
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(date_exports);
|
|
24
|
+
const formatDate = (timestamp) => {
|
|
25
|
+
if (!timestamp) return "";
|
|
26
|
+
const d = new Date(timestamp);
|
|
27
|
+
const ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d);
|
|
28
|
+
const mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d);
|
|
29
|
+
const da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d);
|
|
30
|
+
return `${da} ${mo}, ${ye}`;
|
|
31
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
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 detectHeight_exports = {};
|
|
20
|
+
__export(detectHeight_exports, {
|
|
21
|
+
detectHeightOnInit: () => detectHeightOnInit
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(detectHeight_exports);
|
|
24
|
+
const detectHeightOnInit = (element, state) => {
|
|
25
|
+
const heightTimeout = setTimeout(() => {
|
|
26
|
+
const { props } = element;
|
|
27
|
+
if (!state.clientHeight) {
|
|
28
|
+
const {
|
|
29
|
+
node: { clientHeight }
|
|
30
|
+
} = element;
|
|
31
|
+
if (clientHeight) {
|
|
32
|
+
state.clientHeight = clientHeight;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (state.active) {
|
|
36
|
+
if (props.height === "auto") return;
|
|
37
|
+
element.setProps(
|
|
38
|
+
{
|
|
39
|
+
height: state.clientHeight
|
|
40
|
+
},
|
|
41
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
42
|
+
);
|
|
43
|
+
const setAutoTimeout = setTimeout(() => {
|
|
44
|
+
element.setProps(
|
|
45
|
+
{
|
|
46
|
+
height: "auto"
|
|
47
|
+
},
|
|
48
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
49
|
+
);
|
|
50
|
+
clearTimeout(setAutoTimeout);
|
|
51
|
+
}, 450);
|
|
52
|
+
} else {
|
|
53
|
+
element.setProps(
|
|
54
|
+
{
|
|
55
|
+
height: "0"
|
|
56
|
+
},
|
|
57
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
clearTimeout(heightTimeout);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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 fibonacci_exports = {};
|
|
20
|
+
__export(fibonacci_exports, {
|
|
21
|
+
fibonacciNumberByIndex: () => fibonacciNumberByIndex
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(fibonacci_exports);
|
|
24
|
+
const fibonacciNumberByIndex = function fibonacciNumberByIndex2(n) {
|
|
25
|
+
const fib = [0, 1];
|
|
26
|
+
for (let i = 2; i <= n; i++) {
|
|
27
|
+
fib[i] = fib[i - 1] + fib[i - 2];
|
|
28
|
+
}
|
|
29
|
+
return fib[n];
|
|
30
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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 files_exports = {};
|
|
20
|
+
__export(files_exports, {
|
|
21
|
+
isPhoto: () => isPhoto
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(files_exports);
|
|
24
|
+
const isPhoto = (format) => ["jpeg", "gif", "jpg", "png", "tiff", "woff"].includes(format);
|
|
@@ -0,0 +1,78 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
arrayzeValue: () => arrayzeValue,
|
|
23
|
+
copyJavaScriptToClipboard: () => copyJavaScriptToClipboard,
|
|
24
|
+
copyStringToClipboard: () => copyStringToClipboard,
|
|
25
|
+
removeChars: () => removeChars,
|
|
26
|
+
toCamelCase: () => toCamelCase,
|
|
27
|
+
toDashCase: () => toDashCase,
|
|
28
|
+
toDescriptionCase: () => toDescriptionCase,
|
|
29
|
+
toTitleCase: () => toTitleCase
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var import_utils = require("@domql/utils");
|
|
33
|
+
__reExport(index_exports, require("./browser.js"), module.exports);
|
|
34
|
+
__reExport(index_exports, require("./scaling.js"), module.exports);
|
|
35
|
+
__reExport(index_exports, require("./date.js"), module.exports);
|
|
36
|
+
__reExport(index_exports, require("./fibonacci.js"), module.exports);
|
|
37
|
+
__reExport(index_exports, require("./load.js"), module.exports);
|
|
38
|
+
__reExport(index_exports, require("./files.js"), module.exports);
|
|
39
|
+
const copyStringToClipboard = async (str) => {
|
|
40
|
+
try {
|
|
41
|
+
await navigator.clipboard.writeText(str);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.warn("Failed to copy text: ", err);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const copyJavaScriptToClipboard = async (jsCode) => {
|
|
47
|
+
try {
|
|
48
|
+
const blob = new Blob([jsCode], { type: "text/javascript" });
|
|
49
|
+
const clipboardItem = new window.ClipboardItem({ "text/plain": blob });
|
|
50
|
+
await navigator.clipboard.write([clipboardItem]);
|
|
51
|
+
console.log("JavaScript code copied to clipboard as text/javascript");
|
|
52
|
+
} catch (err) {
|
|
53
|
+
console.error("Failed to copy JavaScript code: ", err);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const removeChars = (str) => {
|
|
57
|
+
return str.replace(/[^a-zA-Z0-9_]/g, "");
|
|
58
|
+
};
|
|
59
|
+
const toCamelCase = (str) => {
|
|
60
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
61
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
62
|
+
}).replaceAll(/\s+/g, "");
|
|
63
|
+
};
|
|
64
|
+
const toTitleCase = (str) => str && str.replace(/\w\S*/g, (txt) => {
|
|
65
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
66
|
+
});
|
|
67
|
+
const toDashCase = (val) => val.replace(/[^a-zA-Z0-9]/g, " ").trim().toLowerCase().replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
68
|
+
const toDescriptionCase = (str = "") => {
|
|
69
|
+
if (typeof str !== "string") return;
|
|
70
|
+
const result = str.replace(/([A-Z])/g, " $1");
|
|
71
|
+
return result.charAt(0).toUpperCase() + result.slice(1);
|
|
72
|
+
};
|
|
73
|
+
const arrayzeValue = (val) => {
|
|
74
|
+
if ((0, import_utils.isArray)(val)) return val;
|
|
75
|
+
if ((0, import_utils.isString)(val)) return val.split(" ");
|
|
76
|
+
if ((0, import_utils.isObject)(val)) return Object.values(val);
|
|
77
|
+
if ((0, import_utils.isNumber)(val)) return [val];
|
|
78
|
+
};
|
package/dist/cjs/load.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
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 load_exports = {};
|
|
20
|
+
__export(load_exports, {
|
|
21
|
+
loadCssFile: () => loadCssFile,
|
|
22
|
+
loadJavascript: () => loadJavascript,
|
|
23
|
+
loadJavascriptFile: () => loadJavascriptFile,
|
|
24
|
+
loadJavascriptFileEmbedSync: () => loadJavascriptFileEmbedSync,
|
|
25
|
+
loadJavascriptFileSync: () => loadJavascriptFileSync,
|
|
26
|
+
loadRemoteCSS: () => loadRemoteCSS,
|
|
27
|
+
loadRemoteScript: () => loadRemoteScript
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(load_exports);
|
|
30
|
+
const loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
try {
|
|
33
|
+
const scriptEle = doc.createElement("script");
|
|
34
|
+
scriptEle.type = type;
|
|
35
|
+
scriptEle.async = async;
|
|
36
|
+
scriptEle.src = FILE_URL;
|
|
37
|
+
scriptEle.addEventListener("load", (ev) => {
|
|
38
|
+
resolve({
|
|
39
|
+
status: true
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
scriptEle.addEventListener("error", (ev) => {
|
|
43
|
+
reject(
|
|
44
|
+
new Error({
|
|
45
|
+
status: false,
|
|
46
|
+
message: `Failed to load the script ${FILE_URL}`
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
doc.body.appendChild(scriptEle);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
reject(error);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript") => {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const scriptEle = doc.createElement("script");
|
|
59
|
+
scriptEle.type = type;
|
|
60
|
+
scriptEle.src = fileUrl;
|
|
61
|
+
const blocker = doc.createElement("div");
|
|
62
|
+
blocker.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(255,255,255,0.8);z-index:9999;";
|
|
63
|
+
doc.body.appendChild(blocker);
|
|
64
|
+
scriptEle.onload = () => {
|
|
65
|
+
console.log(`Successfully loaded: ${fileUrl}`);
|
|
66
|
+
doc.body.removeChild(blocker);
|
|
67
|
+
resolve();
|
|
68
|
+
};
|
|
69
|
+
scriptEle.onerror = () => {
|
|
70
|
+
doc.body.removeChild(blocker);
|
|
71
|
+
reject(new Error(`Failed to load: ${fileUrl}`));
|
|
72
|
+
};
|
|
73
|
+
doc.body.appendChild(scriptEle);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "text/javascript") => {
|
|
77
|
+
const xhr = new window.XMLHttpRequest();
|
|
78
|
+
xhr.open("GET", FILE_URL, false);
|
|
79
|
+
xhr.send();
|
|
80
|
+
if (xhr.status === 200) {
|
|
81
|
+
const scriptEle = doc.createElement("script");
|
|
82
|
+
scriptEle.type = type;
|
|
83
|
+
scriptEle.text = xhr.responseText;
|
|
84
|
+
doc.body.appendChild(scriptEle);
|
|
85
|
+
if (typeof fallback === "function") fallback();
|
|
86
|
+
} else {
|
|
87
|
+
throw new Error(`Failed to load the script ${FILE_URL}`);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
try {
|
|
93
|
+
const linkElem = doc.createElement("link");
|
|
94
|
+
linkElem.rel = "stylesheet";
|
|
95
|
+
linkElem.href = FILE_URL;
|
|
96
|
+
linkElem.addEventListener("load", (ev) => {
|
|
97
|
+
resolve({
|
|
98
|
+
status: true
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
doc.head.appendChild(linkElem);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
reject(error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
const loadJavascript = (body, async = false, doc = document, type = "text/javascript", id = "smbls-script") => {
|
|
108
|
+
try {
|
|
109
|
+
const scriptEle = doc.createElement("script");
|
|
110
|
+
scriptEle.type = type;
|
|
111
|
+
scriptEle.async = async;
|
|
112
|
+
scriptEle.id = id;
|
|
113
|
+
scriptEle.innerHTML = body;
|
|
114
|
+
doc.body.appendChild(scriptEle);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.warn(error);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
function loadRemoteScript(url, options = {}) {
|
|
120
|
+
const { window: window2 = globalThis } = options;
|
|
121
|
+
const { document: document2 = window2.document } = options;
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
const existingScript = document2.querySelector(`script[src="${url}"]`);
|
|
124
|
+
if (existingScript) {
|
|
125
|
+
return resolve(existingScript);
|
|
126
|
+
}
|
|
127
|
+
const script = document2.createElement("script");
|
|
128
|
+
script.src = url;
|
|
129
|
+
script.async = options.async === true;
|
|
130
|
+
script.type = options.type || "text/javascript";
|
|
131
|
+
if (options.id) script.id = options.id;
|
|
132
|
+
if (options.integrity) script.integrity = options.integrity;
|
|
133
|
+
if (options.crossOrigin) script.crossOrigin = options.crossOrigin;
|
|
134
|
+
script.onload = () => {
|
|
135
|
+
script.onerror = script.onload = null;
|
|
136
|
+
resolve(script);
|
|
137
|
+
};
|
|
138
|
+
script.onerror = () => {
|
|
139
|
+
script.onerror = script.onload = null;
|
|
140
|
+
reject(new Error(`Failed to load script: ${url}`));
|
|
141
|
+
};
|
|
142
|
+
document2.head.appendChild(script);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
async function loadRemoteCSS(url, options = {}) {
|
|
146
|
+
const { window: window2 = globalThis } = options;
|
|
147
|
+
const { document: document2 = window2.document } = options;
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const existingLink = document2.querySelector(`link[href="${url}"]`);
|
|
150
|
+
if (existingLink) {
|
|
151
|
+
return resolve(existingLink);
|
|
152
|
+
}
|
|
153
|
+
const link = document2.createElement("link");
|
|
154
|
+
link.href = url;
|
|
155
|
+
link.rel = options.rel || "stylesheet";
|
|
156
|
+
link.type = "text/css";
|
|
157
|
+
link.media = options.media || "all";
|
|
158
|
+
if (options.id) link.id = options.id;
|
|
159
|
+
if (options.integrity) link.integrity = options.integrity;
|
|
160
|
+
if (options.crossOrigin) link.crossOrigin = options.crossOrigin;
|
|
161
|
+
link.onload = () => {
|
|
162
|
+
link.onerror = link.onload = null;
|
|
163
|
+
resolve(link);
|
|
164
|
+
};
|
|
165
|
+
link.onerror = () => {
|
|
166
|
+
link.onerror = link.onload = null;
|
|
167
|
+
reject(new Error(`Failed to load stylesheet: ${url}`));
|
|
168
|
+
};
|
|
169
|
+
document2.head.appendChild(link);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 scaling_exports = {};
|
|
20
|
+
__export(scaling_exports, {
|
|
21
|
+
findClosestNumber: () => findClosestNumber,
|
|
22
|
+
findClosestNumberInFactory: () => findClosestNumberInFactory
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(scaling_exports);
|
|
25
|
+
var import_utils = require("@domql/utils");
|
|
26
|
+
const findClosestNumber = (number, arr) => {
|
|
27
|
+
return ((0, import_utils.isArray)(arr) ? arr : Object.values(arr)).reduce((prev, curr) => {
|
|
28
|
+
return Math.abs(curr - number) < Math.abs(prev - number) ? curr : prev;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const findClosestNumberInFactory = (val, factory) => {
|
|
32
|
+
val = parseFloat(val);
|
|
33
|
+
if ((0, import_utils.isObject)(factory)) factory = Object.values(factory);
|
|
34
|
+
return findClosestNumber(val, factory);
|
|
35
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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 style_exports = {};
|
|
20
|
+
__export(style_exports, {
|
|
21
|
+
getEmotionStylesheet: () => getEmotionStylesheet
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(style_exports);
|
|
24
|
+
const getEmotionStylesheet = () => {
|
|
25
|
+
const stylesheet = document.styleSheets[0];
|
|
26
|
+
let str = "";
|
|
27
|
+
if (stylesheet) {
|
|
28
|
+
try {
|
|
29
|
+
const cssRules = stylesheet.cssRules || stylesheet.rules;
|
|
30
|
+
for (let i = 0; i < cssRules.length; i++) {
|
|
31
|
+
str += cssRules[i].cssText;
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error("Unable to access CSS rules. This may be due to CORS restrictions:", error);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
console.log("No stylesheets found in document.styleSheets[0].");
|
|
38
|
+
}
|
|
39
|
+
return str;
|
|
40
|
+
};
|
|
@@ -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/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.setProps(
|
|
15
|
+
{
|
|
16
|
+
height: state.clientHeight
|
|
17
|
+
},
|
|
18
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
19
|
+
);
|
|
20
|
+
const setAutoTimeout = setTimeout(() => {
|
|
21
|
+
element.setProps(
|
|
22
|
+
{
|
|
23
|
+
height: "auto"
|
|
24
|
+
},
|
|
25
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
26
|
+
);
|
|
27
|
+
clearTimeout(setAutoTimeout);
|
|
28
|
+
}, 450);
|
|
29
|
+
} else {
|
|
30
|
+
element.setProps(
|
|
31
|
+
{
|
|
32
|
+
height: "0"
|
|
33
|
+
},
|
|
34
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
clearTimeout(heightTimeout);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
detectHeightOnInit
|
|
42
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isString, isObject, isArray, isNumber } from "@domql/utils";
|
|
2
|
+
export * from "./browser.js";
|
|
3
|
+
export * from "./scaling.js";
|
|
4
|
+
export * from "./date.js";
|
|
5
|
+
export * from "./fibonacci.js";
|
|
6
|
+
export * from "./load.js";
|
|
7
|
+
export * from "./files.js";
|
|
8
|
+
const copyStringToClipboard = async (str) => {
|
|
9
|
+
try {
|
|
10
|
+
await navigator.clipboard.writeText(str);
|
|
11
|
+
} catch (err) {
|
|
12
|
+
console.warn("Failed to copy text: ", err);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const copyJavaScriptToClipboard = async (jsCode) => {
|
|
16
|
+
try {
|
|
17
|
+
const blob = new Blob([jsCode], { type: "text/javascript" });
|
|
18
|
+
const clipboardItem = new window.ClipboardItem({ "text/plain": blob });
|
|
19
|
+
await navigator.clipboard.write([clipboardItem]);
|
|
20
|
+
console.log("JavaScript code copied to clipboard as text/javascript");
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error("Failed to copy JavaScript code: ", err);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const removeChars = (str) => {
|
|
26
|
+
return str.replace(/[^a-zA-Z0-9_]/g, "");
|
|
27
|
+
};
|
|
28
|
+
const toCamelCase = (str) => {
|
|
29
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
30
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
31
|
+
}).replaceAll(/\s+/g, "");
|
|
32
|
+
};
|
|
33
|
+
const toTitleCase = (str) => str && str.replace(/\w\S*/g, (txt) => {
|
|
34
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
35
|
+
});
|
|
36
|
+
const toDashCase = (val) => val.replace(/[^a-zA-Z0-9]/g, " ").trim().toLowerCase().replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
37
|
+
const toDescriptionCase = (str = "") => {
|
|
38
|
+
if (typeof str !== "string") return;
|
|
39
|
+
const result = str.replace(/([A-Z])/g, " $1");
|
|
40
|
+
return result.charAt(0).toUpperCase() + result.slice(1);
|
|
41
|
+
};
|
|
42
|
+
const arrayzeValue = (val) => {
|
|
43
|
+
if (isArray(val)) return val;
|
|
44
|
+
if (isString(val)) return val.split(" ");
|
|
45
|
+
if (isObject(val)) return Object.values(val);
|
|
46
|
+
if (isNumber(val)) return [val];
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
arrayzeValue,
|
|
50
|
+
copyJavaScriptToClipboard,
|
|
51
|
+
copyStringToClipboard,
|
|
52
|
+
removeChars,
|
|
53
|
+
toCamelCase,
|
|
54
|
+
toDashCase,
|
|
55
|
+
toDescriptionCase,
|
|
56
|
+
toTitleCase
|
|
57
|
+
};
|