@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/dist/esm/load.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
const loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
try {
|
|
4
|
+
const scriptEle = doc.createElement("script");
|
|
5
|
+
scriptEle.type = type;
|
|
6
|
+
scriptEle.async = async;
|
|
7
|
+
scriptEle.src = FILE_URL;
|
|
8
|
+
scriptEle.addEventListener("load", (ev) => {
|
|
9
|
+
resolve({
|
|
10
|
+
status: true
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
scriptEle.addEventListener("error", (ev) => {
|
|
14
|
+
reject(
|
|
15
|
+
new Error({
|
|
16
|
+
status: false,
|
|
17
|
+
message: `Failed to load the script ${FILE_URL}`
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
doc.body.appendChild(scriptEle);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
reject(error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript") => {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const scriptEle = doc.createElement("script");
|
|
30
|
+
scriptEle.type = type;
|
|
31
|
+
scriptEle.src = fileUrl;
|
|
32
|
+
const blocker = doc.createElement("div");
|
|
33
|
+
blocker.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(255,255,255,0.8);z-index:9999;";
|
|
34
|
+
doc.body.appendChild(blocker);
|
|
35
|
+
scriptEle.onload = () => {
|
|
36
|
+
console.log(`Successfully loaded: ${fileUrl}`);
|
|
37
|
+
doc.body.removeChild(blocker);
|
|
38
|
+
resolve();
|
|
39
|
+
};
|
|
40
|
+
scriptEle.onerror = () => {
|
|
41
|
+
doc.body.removeChild(blocker);
|
|
42
|
+
reject(new Error(`Failed to load: ${fileUrl}`));
|
|
43
|
+
};
|
|
44
|
+
doc.body.appendChild(scriptEle);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
const loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "text/javascript") => {
|
|
48
|
+
const xhr = new window.XMLHttpRequest();
|
|
49
|
+
xhr.open("GET", FILE_URL, false);
|
|
50
|
+
xhr.send();
|
|
51
|
+
if (xhr.status === 200) {
|
|
52
|
+
const scriptEle = doc.createElement("script");
|
|
53
|
+
scriptEle.type = type;
|
|
54
|
+
scriptEle.text = xhr.responseText;
|
|
55
|
+
doc.body.appendChild(scriptEle);
|
|
56
|
+
if (typeof fallback === "function") fallback();
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error(`Failed to load the script ${FILE_URL}`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
62
|
+
return new Promise((resolve, reject) => {
|
|
63
|
+
try {
|
|
64
|
+
const linkElem = doc.createElement("link");
|
|
65
|
+
linkElem.rel = "stylesheet";
|
|
66
|
+
linkElem.href = FILE_URL;
|
|
67
|
+
linkElem.addEventListener("load", (ev) => {
|
|
68
|
+
resolve({
|
|
69
|
+
status: true
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
doc.head.appendChild(linkElem);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
reject(error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const loadJavascript = (body, async = false, doc = document, type = "text/javascript", id = "smbls-script") => {
|
|
79
|
+
try {
|
|
80
|
+
const scriptEle = doc.createElement("script");
|
|
81
|
+
scriptEle.type = type;
|
|
82
|
+
scriptEle.async = async;
|
|
83
|
+
scriptEle.id = id;
|
|
84
|
+
scriptEle.innerHTML = body;
|
|
85
|
+
doc.body.appendChild(scriptEle);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.warn(error);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
function loadRemoteScript(url, options = {}) {
|
|
91
|
+
const { window: window2 = globalThis } = options;
|
|
92
|
+
const { document: document2 = window2.document } = options;
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
const existingScript = document2.querySelector(`script[src="${url}"]`);
|
|
95
|
+
if (existingScript) {
|
|
96
|
+
return resolve(existingScript);
|
|
97
|
+
}
|
|
98
|
+
const script = document2.createElement("script");
|
|
99
|
+
script.src = url;
|
|
100
|
+
script.async = options.async === true;
|
|
101
|
+
script.type = options.type || "text/javascript";
|
|
102
|
+
if (options.id) script.id = options.id;
|
|
103
|
+
if (options.integrity) script.integrity = options.integrity;
|
|
104
|
+
if (options.crossOrigin) script.crossOrigin = options.crossOrigin;
|
|
105
|
+
script.onload = () => {
|
|
106
|
+
script.onerror = script.onload = null;
|
|
107
|
+
resolve(script);
|
|
108
|
+
};
|
|
109
|
+
script.onerror = () => {
|
|
110
|
+
script.onerror = script.onload = null;
|
|
111
|
+
reject(new Error(`Failed to load script: ${url}`));
|
|
112
|
+
};
|
|
113
|
+
document2.head.appendChild(script);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async function loadRemoteCSS(url, options = {}) {
|
|
117
|
+
const { window: window2 = globalThis } = options;
|
|
118
|
+
const { document: document2 = window2.document } = options;
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const existingLink = document2.querySelector(`link[href="${url}"]`);
|
|
121
|
+
if (existingLink) {
|
|
122
|
+
return resolve(existingLink);
|
|
123
|
+
}
|
|
124
|
+
const link = document2.createElement("link");
|
|
125
|
+
link.href = url;
|
|
126
|
+
link.rel = options.rel || "stylesheet";
|
|
127
|
+
link.type = "text/css";
|
|
128
|
+
link.media = options.media || "all";
|
|
129
|
+
if (options.id) link.id = options.id;
|
|
130
|
+
if (options.integrity) link.integrity = options.integrity;
|
|
131
|
+
if (options.crossOrigin) link.crossOrigin = options.crossOrigin;
|
|
132
|
+
link.onload = () => {
|
|
133
|
+
link.onerror = link.onload = null;
|
|
134
|
+
resolve(link);
|
|
135
|
+
};
|
|
136
|
+
link.onerror = () => {
|
|
137
|
+
link.onerror = link.onload = null;
|
|
138
|
+
reject(new Error(`Failed to load stylesheet: ${url}`));
|
|
139
|
+
};
|
|
140
|
+
document2.head.appendChild(link);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
export {
|
|
144
|
+
loadCssFile,
|
|
145
|
+
loadJavascript,
|
|
146
|
+
loadJavascriptFile,
|
|
147
|
+
loadJavascriptFileEmbedSync,
|
|
148
|
+
loadJavascriptFileSync,
|
|
149
|
+
loadRemoteCSS,
|
|
150
|
+
loadRemoteScript
|
|
151
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isObject, isArray } from "@domql/utils";
|
|
2
|
+
const findClosestNumber = (number, arr) => {
|
|
3
|
+
return (isArray(arr) ? arr : Object.values(arr)).reduce((prev, curr) => {
|
|
4
|
+
return Math.abs(curr - number) < Math.abs(prev - number) ? curr : prev;
|
|
5
|
+
});
|
|
6
|
+
};
|
|
7
|
+
const findClosestNumberInFactory = (val, factory) => {
|
|
8
|
+
val = parseFloat(val);
|
|
9
|
+
if (isObject(factory)) factory = Object.values(factory);
|
|
10
|
+
return findClosestNumber(val, factory);
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
findClosestNumber,
|
|
14
|
+
findClosestNumberInFactory
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const getEmotionStylesheet = () => {
|
|
2
|
+
const stylesheet = document.styleSheets[0];
|
|
3
|
+
let str = "";
|
|
4
|
+
if (stylesheet) {
|
|
5
|
+
try {
|
|
6
|
+
const cssRules = stylesheet.cssRules || stylesheet.rules;
|
|
7
|
+
for (let i = 0; i < cssRules.length; i++) {
|
|
8
|
+
str += cssRules[i].cssText;
|
|
9
|
+
}
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error("Unable to access CSS rules. This may be due to CORS restrictions:", error);
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
console.log("No stylesheets found in document.styleSheets[0].");
|
|
15
|
+
}
|
|
16
|
+
return str;
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
getEmotionStylesheet
|
|
20
|
+
};
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var SmblsSmblsUtils = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.js
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
arrayzeValue: () => arrayzeValue,
|
|
25
|
+
copyJavaScriptToClipboard: () => copyJavaScriptToClipboard,
|
|
26
|
+
copyStringToClipboard: () => copyStringToClipboard,
|
|
27
|
+
fibonacciNumberByIndex: () => fibonacciNumberByIndex,
|
|
28
|
+
findClosestNumber: () => findClosestNumber,
|
|
29
|
+
findClosestNumberInFactory: () => findClosestNumberInFactory,
|
|
30
|
+
formatDate: () => formatDate,
|
|
31
|
+
isPhoto: () => isPhoto,
|
|
32
|
+
loadCssFile: () => loadCssFile,
|
|
33
|
+
loadJavascript: () => loadJavascript,
|
|
34
|
+
loadJavascriptFile: () => loadJavascriptFile,
|
|
35
|
+
loadJavascriptFileEmbedSync: () => loadJavascriptFileEmbedSync,
|
|
36
|
+
loadJavascriptFileSync: () => loadJavascriptFileSync,
|
|
37
|
+
loadRemoteCSS: () => loadRemoteCSS,
|
|
38
|
+
loadRemoteScript: () => loadRemoteScript,
|
|
39
|
+
removeChars: () => removeChars,
|
|
40
|
+
toCamelCase: () => toCamelCase,
|
|
41
|
+
toDashCase: () => toDashCase,
|
|
42
|
+
toDescriptionCase: () => toDescriptionCase,
|
|
43
|
+
toTitleCase: () => toTitleCase,
|
|
44
|
+
toggleFullscreen: () => toggleFullscreen
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// ../utils/dist/esm/types.js
|
|
48
|
+
var isObject = (arg) => {
|
|
49
|
+
if (arg === null) return false;
|
|
50
|
+
return typeof arg === "object" && arg.constructor === Object;
|
|
51
|
+
};
|
|
52
|
+
var isString = (arg) => typeof arg === "string";
|
|
53
|
+
var isNumber = (arg) => typeof arg === "number";
|
|
54
|
+
var isArray = (arg) => Array.isArray(arg);
|
|
55
|
+
|
|
56
|
+
// src/browser.js
|
|
57
|
+
async function toggleFullscreen(opts) {
|
|
58
|
+
if (!document.fullscreenElement) {
|
|
59
|
+
try {
|
|
60
|
+
await (this.node || document).requestFullscreen();
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.warn(`Error attempting to enable fullscreen mode: ${err.message} (${err.name})`);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
await document.exitFullscreen();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/scaling.js
|
|
70
|
+
var findClosestNumber = (number, arr) => {
|
|
71
|
+
return (isArray(arr) ? arr : Object.values(arr)).reduce((prev, curr) => {
|
|
72
|
+
return Math.abs(curr - number) < Math.abs(prev - number) ? curr : prev;
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var findClosestNumberInFactory = (val, factory) => {
|
|
76
|
+
val = parseFloat(val);
|
|
77
|
+
if (isObject(factory)) factory = Object.values(factory);
|
|
78
|
+
return findClosestNumber(val, factory);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/date.js
|
|
82
|
+
var formatDate = (timestamp) => {
|
|
83
|
+
if (!timestamp) return "";
|
|
84
|
+
const d = new Date(timestamp);
|
|
85
|
+
const ye = new Intl.DateTimeFormat("en", { year: "numeric" }).format(d);
|
|
86
|
+
const mo = new Intl.DateTimeFormat("en", { month: "short" }).format(d);
|
|
87
|
+
const da = new Intl.DateTimeFormat("en", { day: "2-digit" }).format(d);
|
|
88
|
+
return `${da} ${mo}, ${ye}`;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/fibonacci.js
|
|
92
|
+
var fibonacciNumberByIndex = function fibonacciNumberByIndex2(n) {
|
|
93
|
+
const fib = [0, 1];
|
|
94
|
+
for (let i = 2; i <= n; i++) {
|
|
95
|
+
fib[i] = fib[i - 1] + fib[i - 2];
|
|
96
|
+
}
|
|
97
|
+
return fib[n];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/load.js
|
|
101
|
+
var loadJavascriptFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
try {
|
|
104
|
+
const scriptEle = doc.createElement("script");
|
|
105
|
+
scriptEle.type = type;
|
|
106
|
+
scriptEle.async = async;
|
|
107
|
+
scriptEle.src = FILE_URL;
|
|
108
|
+
scriptEle.addEventListener("load", (ev) => {
|
|
109
|
+
resolve({
|
|
110
|
+
status: true
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
scriptEle.addEventListener("error", (ev) => {
|
|
114
|
+
reject(
|
|
115
|
+
new Error({
|
|
116
|
+
status: false,
|
|
117
|
+
message: `Failed to load the script ${FILE_URL}`
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
doc.body.appendChild(scriptEle);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
reject(error);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
var loadJavascriptFileSync = (fileUrl, doc = document, type = "text/javascript") => {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
const scriptEle = doc.createElement("script");
|
|
130
|
+
scriptEle.type = type;
|
|
131
|
+
scriptEle.src = fileUrl;
|
|
132
|
+
const blocker = doc.createElement("div");
|
|
133
|
+
blocker.style.cssText = "position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(255,255,255,0.8);z-index:9999;";
|
|
134
|
+
doc.body.appendChild(blocker);
|
|
135
|
+
scriptEle.onload = () => {
|
|
136
|
+
console.log(`Successfully loaded: ${fileUrl}`);
|
|
137
|
+
doc.body.removeChild(blocker);
|
|
138
|
+
resolve();
|
|
139
|
+
};
|
|
140
|
+
scriptEle.onerror = () => {
|
|
141
|
+
doc.body.removeChild(blocker);
|
|
142
|
+
reject(new Error(`Failed to load: ${fileUrl}`));
|
|
143
|
+
};
|
|
144
|
+
doc.body.appendChild(scriptEle);
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
var loadJavascriptFileEmbedSync = (FILE_URL, doc = document, fallback, type = "text/javascript") => {
|
|
148
|
+
const xhr = new window.XMLHttpRequest();
|
|
149
|
+
xhr.open("GET", FILE_URL, false);
|
|
150
|
+
xhr.send();
|
|
151
|
+
if (xhr.status === 200) {
|
|
152
|
+
const scriptEle = doc.createElement("script");
|
|
153
|
+
scriptEle.type = type;
|
|
154
|
+
scriptEle.text = xhr.responseText;
|
|
155
|
+
doc.body.appendChild(scriptEle);
|
|
156
|
+
if (typeof fallback === "function") fallback();
|
|
157
|
+
} else {
|
|
158
|
+
throw new Error(`Failed to load the script ${FILE_URL}`);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var loadCssFile = (FILE_URL, async = false, doc = document, type = "text/javascript") => {
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
try {
|
|
164
|
+
const linkElem = doc.createElement("link");
|
|
165
|
+
linkElem.rel = "stylesheet";
|
|
166
|
+
linkElem.href = FILE_URL;
|
|
167
|
+
linkElem.addEventListener("load", (ev) => {
|
|
168
|
+
resolve({
|
|
169
|
+
status: true
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
doc.head.appendChild(linkElem);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
reject(error);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
var loadJavascript = (body, async = false, doc = document, type = "text/javascript", id = "smbls-script") => {
|
|
179
|
+
try {
|
|
180
|
+
const scriptEle = doc.createElement("script");
|
|
181
|
+
scriptEle.type = type;
|
|
182
|
+
scriptEle.async = async;
|
|
183
|
+
scriptEle.id = id;
|
|
184
|
+
scriptEle.innerHTML = body;
|
|
185
|
+
doc.body.appendChild(scriptEle);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
console.warn(error);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
function loadRemoteScript(url, options = {}) {
|
|
191
|
+
const { window: window2 = globalThis } = options;
|
|
192
|
+
const { document: document2 = window2.document } = options;
|
|
193
|
+
return new Promise((resolve, reject) => {
|
|
194
|
+
const existingScript = document2.querySelector(`script[src="${url}"]`);
|
|
195
|
+
if (existingScript) {
|
|
196
|
+
return resolve(existingScript);
|
|
197
|
+
}
|
|
198
|
+
const script = document2.createElement("script");
|
|
199
|
+
script.src = url;
|
|
200
|
+
script.async = options.async === true;
|
|
201
|
+
script.type = options.type || "text/javascript";
|
|
202
|
+
if (options.id) script.id = options.id;
|
|
203
|
+
if (options.integrity) script.integrity = options.integrity;
|
|
204
|
+
if (options.crossOrigin) script.crossOrigin = options.crossOrigin;
|
|
205
|
+
script.onload = () => {
|
|
206
|
+
script.onerror = script.onload = null;
|
|
207
|
+
resolve(script);
|
|
208
|
+
};
|
|
209
|
+
script.onerror = () => {
|
|
210
|
+
script.onerror = script.onload = null;
|
|
211
|
+
reject(new Error(`Failed to load script: ${url}`));
|
|
212
|
+
};
|
|
213
|
+
document2.head.appendChild(script);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
async function loadRemoteCSS(url, options = {}) {
|
|
217
|
+
const { window: window2 = globalThis } = options;
|
|
218
|
+
const { document: document2 = window2.document } = options;
|
|
219
|
+
return new Promise((resolve, reject) => {
|
|
220
|
+
const existingLink = document2.querySelector(`link[href="${url}"]`);
|
|
221
|
+
if (existingLink) {
|
|
222
|
+
return resolve(existingLink);
|
|
223
|
+
}
|
|
224
|
+
const link = document2.createElement("link");
|
|
225
|
+
link.href = url;
|
|
226
|
+
link.rel = options.rel || "stylesheet";
|
|
227
|
+
link.type = "text/css";
|
|
228
|
+
link.media = options.media || "all";
|
|
229
|
+
if (options.id) link.id = options.id;
|
|
230
|
+
if (options.integrity) link.integrity = options.integrity;
|
|
231
|
+
if (options.crossOrigin) link.crossOrigin = options.crossOrigin;
|
|
232
|
+
link.onload = () => {
|
|
233
|
+
link.onerror = link.onload = null;
|
|
234
|
+
resolve(link);
|
|
235
|
+
};
|
|
236
|
+
link.onerror = () => {
|
|
237
|
+
link.onerror = link.onload = null;
|
|
238
|
+
reject(new Error(`Failed to load stylesheet: ${url}`));
|
|
239
|
+
};
|
|
240
|
+
document2.head.appendChild(link);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/files.js
|
|
245
|
+
var isPhoto = (format) => ["jpeg", "gif", "jpg", "png", "tiff", "woff"].includes(format);
|
|
246
|
+
|
|
247
|
+
// src/index.js
|
|
248
|
+
var copyStringToClipboard = async (str) => {
|
|
249
|
+
try {
|
|
250
|
+
await navigator.clipboard.writeText(str);
|
|
251
|
+
} catch (err) {
|
|
252
|
+
console.warn("Failed to copy text: ", err);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
var copyJavaScriptToClipboard = async (jsCode) => {
|
|
256
|
+
try {
|
|
257
|
+
const blob = new Blob([jsCode], { type: "text/javascript" });
|
|
258
|
+
const clipboardItem = new window.ClipboardItem({ "text/plain": blob });
|
|
259
|
+
await navigator.clipboard.write([clipboardItem]);
|
|
260
|
+
console.log("JavaScript code copied to clipboard as text/javascript");
|
|
261
|
+
} catch (err) {
|
|
262
|
+
console.error("Failed to copy JavaScript code: ", err);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var removeChars = (str) => {
|
|
266
|
+
return str.replace(/[^a-zA-Z0-9_]/g, "");
|
|
267
|
+
};
|
|
268
|
+
var toCamelCase = (str) => {
|
|
269
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
270
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
271
|
+
}).replaceAll(/\s+/g, "");
|
|
272
|
+
};
|
|
273
|
+
var toTitleCase = (str) => str && str.replace(/\w\S*/g, (txt) => {
|
|
274
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
|
|
275
|
+
});
|
|
276
|
+
var toDashCase = (val) => val.replace(/[^a-zA-Z0-9]/g, " ").trim().toLowerCase().replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
|
|
277
|
+
var toDescriptionCase = (str = "") => {
|
|
278
|
+
if (typeof str !== "string") return;
|
|
279
|
+
const result = str.replace(/([A-Z])/g, " $1");
|
|
280
|
+
return result.charAt(0).toUpperCase() + result.slice(1);
|
|
281
|
+
};
|
|
282
|
+
var arrayzeValue = (val) => {
|
|
283
|
+
if (isArray(val)) return val;
|
|
284
|
+
if (isString(val)) return val.split(" ");
|
|
285
|
+
if (isObject(val)) return Object.values(val);
|
|
286
|
+
if (isNumber(val)) return [val];
|
|
287
|
+
};
|
|
288
|
+
return __toCommonJS(index_exports);
|
|
289
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@symbo.ls/smbls-utils",
|
|
3
|
+
"version": "3.2.7",
|
|
4
|
+
"author": "symbo.ls",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"*.js",
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"main": "./dist/cjs/index.js",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"module": "./dist/esm/index.js",
|
|
13
|
+
"unpkg": "./dist/iife/index.js",
|
|
14
|
+
"jsdelivr": "./dist/iife/index.js",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/esm/index.js",
|
|
18
|
+
"require": "./dist/cjs/index.js",
|
|
19
|
+
"browser": "./dist/iife/index.js",
|
|
20
|
+
"default": "./dist/esm/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"source": "src/index.js",
|
|
24
|
+
"publishConfig": {},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
|
|
27
|
+
"build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild src/*.js --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
28
|
+
"build:cjs": "cross-env NODE_ENV=$NODE_ENV esbuild src/*.js --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
29
|
+
"build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild src/index.js --bundle --target=es2020 --format=iife --global-name=SmblsSmblsUtils --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV",
|
|
30
|
+
"build": "node ../../build/build.js",
|
|
31
|
+
"prepublish": "npm run build && npm run copy:package:cjs"
|
|
32
|
+
},
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@domql/element": "^3.2.3",
|
|
36
|
+
"@domql/utils": "^3.2.3"
|
|
37
|
+
},
|
|
38
|
+
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
39
|
+
"browser": "./dist/iife/index.js",
|
|
40
|
+
"sideEffects": false
|
|
41
|
+
}
|
package/src/browser.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
export async function toggleFullscreen (opts) {
|
|
4
|
+
if (!document.fullscreenElement) {
|
|
5
|
+
try {
|
|
6
|
+
await (this.node || document).requestFullscreen()
|
|
7
|
+
} catch (err) {
|
|
8
|
+
console.warn(`Error attempting to enable fullscreen mode: ${err.message} (${err.name})`)
|
|
9
|
+
}
|
|
10
|
+
} else {
|
|
11
|
+
await document.exitFullscreen()
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/date.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
export const formatDate = (timestamp) => {
|
|
4
|
+
if (!timestamp) return ''
|
|
5
|
+
const d = new Date(timestamp)
|
|
6
|
+
const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
|
|
7
|
+
const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d)
|
|
8
|
+
const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)
|
|
9
|
+
return `${da} ${mo}, ${ye}`
|
|
10
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
export const detectHeightOnInit = (element, state) => {
|
|
4
|
+
const heightTimeout = setTimeout(() => {
|
|
5
|
+
const { props } = element
|
|
6
|
+
if (!state.clientHeight) {
|
|
7
|
+
const {
|
|
8
|
+
node: { clientHeight }
|
|
9
|
+
} = element
|
|
10
|
+
if (clientHeight) {
|
|
11
|
+
state.clientHeight = clientHeight
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (state.active) {
|
|
16
|
+
if (props.height === 'auto') return
|
|
17
|
+
element.setProps(
|
|
18
|
+
{
|
|
19
|
+
height: state.clientHeight
|
|
20
|
+
},
|
|
21
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
22
|
+
)
|
|
23
|
+
const setAutoTimeout = setTimeout(() => {
|
|
24
|
+
element.setProps(
|
|
25
|
+
{
|
|
26
|
+
height: 'auto'
|
|
27
|
+
},
|
|
28
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
29
|
+
)
|
|
30
|
+
clearTimeout(setAutoTimeout)
|
|
31
|
+
}, 450)
|
|
32
|
+
} else {
|
|
33
|
+
element.setProps(
|
|
34
|
+
{
|
|
35
|
+
height: '0'
|
|
36
|
+
},
|
|
37
|
+
{ preventBeforeUpdateListener: true, preventChildrenUpdate: true }
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
clearTimeout(heightTimeout)
|
|
41
|
+
})
|
|
42
|
+
}
|
package/src/fibonacci.js
ADDED
package/src/files.js
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
import { isString, isObject, isArray, isNumber } from '@domql/utils'
|
|
4
|
+
|
|
5
|
+
export * from './browser.js'
|
|
6
|
+
export * from './scaling.js'
|
|
7
|
+
export * from './date.js'
|
|
8
|
+
export * from './fibonacci.js'
|
|
9
|
+
export * from './load.js'
|
|
10
|
+
export * from './files.js'
|
|
11
|
+
|
|
12
|
+
export const copyStringToClipboard = async (str) => {
|
|
13
|
+
try {
|
|
14
|
+
await navigator.clipboard.writeText(str)
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.warn('Failed to copy text: ', err)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const copyJavaScriptToClipboard = async (jsCode) => {
|
|
21
|
+
try {
|
|
22
|
+
// Create a Blob for the JavaScript code with the 'text/javascript' MIME type
|
|
23
|
+
const blob = new Blob([jsCode], { type: 'text/javascript' })
|
|
24
|
+
|
|
25
|
+
// Create a ClipboardItem with the 'text/javascript' Blob
|
|
26
|
+
const clipboardItem = new window.ClipboardItem({ 'text/plain': blob })
|
|
27
|
+
|
|
28
|
+
// Copy the ClipboardItem to the clipboard
|
|
29
|
+
await navigator.clipboard.write([clipboardItem])
|
|
30
|
+
|
|
31
|
+
console.log('JavaScript code copied to clipboard as text/javascript')
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error('Failed to copy JavaScript code: ', err)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const removeChars = (str) => {
|
|
38
|
+
return str.replace(/[^a-zA-Z0-9_]/g, '')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const toCamelCase = (str) => {
|
|
42
|
+
return str
|
|
43
|
+
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) {
|
|
44
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase()
|
|
45
|
+
})
|
|
46
|
+
.replaceAll(/\s+/g, '')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const toTitleCase = (str) =>
|
|
50
|
+
str &&
|
|
51
|
+
str.replace(/\w\S*/g, (txt) => {
|
|
52
|
+
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
export const toDashCase = (val) =>
|
|
56
|
+
val
|
|
57
|
+
.replace(/[^a-zA-Z0-9]/g, ' ') // Replace non-alphanumeric characters with spaces
|
|
58
|
+
.trim() // Remove leading and trailing spaces
|
|
59
|
+
.toLowerCase() // Convert to lowercase
|
|
60
|
+
.replace(/\s+/g, '-') // Replace spaces with dashes
|
|
61
|
+
.replace(/-+/g, '-') // Replace consecutive dashes with a single dash
|
|
62
|
+
.replace(/^-|-$/g, '') // Remove leading and trailing dashes
|
|
63
|
+
|
|
64
|
+
export const toDescriptionCase = (str = '') => {
|
|
65
|
+
if (typeof str !== 'string') return
|
|
66
|
+
const result = str.replace(/([A-Z])/g, ' $1')
|
|
67
|
+
return result.charAt(0).toUpperCase() + result.slice(1)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const arrayzeValue = (val) => {
|
|
71
|
+
if (isArray(val)) return val
|
|
72
|
+
if (isString(val)) return val.split(' ')
|
|
73
|
+
if (isObject(val)) return Object.values(val)
|
|
74
|
+
if (isNumber(val)) return [val]
|
|
75
|
+
}
|