@bhsd/common 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +0 -0
- package/dist/index.js +85 -73
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -1,78 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (/[<>[\]|{}]/u.test(decoded)) {
|
|
10
|
-
return decoded;
|
|
11
|
-
}
|
|
12
|
-
span.innerHTML = decoded;
|
|
13
|
-
return span.textContent;
|
|
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 });
|
|
14
9
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let mt = re.exec(str), lastIndex = 0;
|
|
23
|
-
while (mt) {
|
|
24
|
-
const index = mt.index + mt[1].length;
|
|
25
|
-
if (index > lastIndex) {
|
|
26
|
-
pieces.push([str.slice(lastIndex, index), lastIndex, index, false]);
|
|
27
|
-
}
|
|
28
|
-
({ lastIndex } = re);
|
|
29
|
-
pieces.push([mt[2], index, lastIndex, true]);
|
|
30
|
-
mt = re.exec(str);
|
|
31
|
-
}
|
|
32
|
-
if (str.length > lastIndex) {
|
|
33
|
-
pieces.push([str.slice(lastIndex), lastIndex, str.length, false]);
|
|
34
|
-
}
|
|
35
|
-
return pieces;
|
|
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;
|
|
36
17
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
CDN: () => CDN,
|
|
22
|
+
getObject: () => getObject,
|
|
23
|
+
loadScript: () => loadScript,
|
|
24
|
+
normalizeTitle: () => normalizeTitle,
|
|
25
|
+
parseVersion: () => parseVersion,
|
|
26
|
+
setObject: () => setObject,
|
|
27
|
+
splitColors: () => splitColors
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(src_exports);
|
|
30
|
+
const CDN = "https://testingcf.jsdelivr.net";
|
|
31
|
+
const hexColor = String.raw`#(?:[\da-f]{3,4}|(?:[\da-f]{2}){3,4})(?![\p{L}\d_])`, rgbValue = String.raw`(?:\d*\.)?\d+%?`, hue = String.raw`(?:\d*\.)?\d+(?:deg|grad|rad|turn)?`, rgbColor = String.raw`rgba?\(\s*(?:${String.raw`${new Array(3).fill(rgbValue).join(String.raw`\s+`)}(?:\s*\/\s*${rgbValue})?`}|${String.raw`${new Array(3).fill(rgbValue).join(String.raw`\s*,\s*`)}(?:\s*,\s*${rgbValue})?`})\s*\)`, hslColor = String.raw`hsla?\(\s*(?:${String.raw`${hue}\s+${rgbValue}\s+${rgbValue}(?:\s*\/\s*${rgbValue})?`}|${String.raw`${hue}${String.raw`\s*,\s*(?:\d*\.)?\d+%`.repeat(2)}(?:\s*,\s*${rgbValue})?`})\s*\)`, re = new RegExp(String.raw`(^|[^\p{L}\d_])(${hexColor}|${rgbColor}|${hslColor})`, "giu");
|
|
32
|
+
let span;
|
|
33
|
+
if (typeof document === "object") {
|
|
34
|
+
span = document.createElement("span");
|
|
35
|
+
}
|
|
36
|
+
const normalizeTitle = (title) => {
|
|
37
|
+
const decoded = decodeURIComponent(title.replace(/%(?![\da-f]{2})/giu, "%25"));
|
|
38
|
+
if (/[<>[\]|{}]/u.test(decoded)) {
|
|
39
|
+
return decoded;
|
|
40
|
+
}
|
|
41
|
+
span.innerHTML = decoded;
|
|
42
|
+
return span.textContent;
|
|
43
|
+
};
|
|
44
|
+
const splitColors = (str) => {
|
|
45
|
+
re.lastIndex = 0;
|
|
46
|
+
const pieces = [];
|
|
47
|
+
let mt = re.exec(str), lastIndex = 0;
|
|
48
|
+
while (mt) {
|
|
49
|
+
const index = mt.index + mt[1].length;
|
|
50
|
+
if (index > lastIndex) {
|
|
51
|
+
pieces.push([str.slice(lastIndex, index), lastIndex, index, false]);
|
|
67
52
|
}
|
|
53
|
+
({ lastIndex } = re);
|
|
54
|
+
pieces.push([mt[2], index, lastIndex, true]);
|
|
55
|
+
mt = re.exec(str);
|
|
56
|
+
}
|
|
57
|
+
if (str.length > lastIndex) {
|
|
58
|
+
pieces.push([str.slice(lastIndex), lastIndex, str.length, false]);
|
|
59
|
+
}
|
|
60
|
+
return pieces;
|
|
61
|
+
};
|
|
62
|
+
const loadScript = (src, globalConst, amd) => new Promise((resolve) => {
|
|
63
|
+
const path = `${CDN}/${src}`;
|
|
64
|
+
let obj = window;
|
|
65
|
+
for (const prop of globalConst.split(".")) {
|
|
66
|
+
obj = obj?.[prop];
|
|
67
|
+
}
|
|
68
|
+
if (obj) {
|
|
69
|
+
resolve();
|
|
70
|
+
} else if (amd && typeof define === "function" && "amd" in define) {
|
|
71
|
+
const requirejs = window.require;
|
|
72
|
+
requirejs.config({ paths: { [globalConst]: path } });
|
|
73
|
+
requirejs([globalConst], (exports) => {
|
|
74
|
+
Object.assign(window, { [globalConst]: exports });
|
|
75
|
+
resolve();
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
const script = document.createElement("script");
|
|
79
|
+
script.src = path;
|
|
80
|
+
script.onload = () => {
|
|
81
|
+
resolve();
|
|
82
|
+
};
|
|
83
|
+
document.head.append(script);
|
|
84
|
+
}
|
|
68
85
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
86
|
+
const getObject = (key) => JSON.parse(String(localStorage.getItem(key)));
|
|
87
|
+
const setObject = (key, value) => {
|
|
88
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
73
89
|
};
|
|
74
|
-
|
|
75
|
-
* 解析版本号
|
|
76
|
-
* @param v 版本号
|
|
77
|
-
*/
|
|
78
|
-
export const parseVersion = (v) => v.split('.', 3).map(Number);
|
|
90
|
+
const parseVersion = (v) => v.split(".", 3).map(Number);
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"license": "GPL-2.0",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"files": [
|
|
7
6
|
"/dist/",
|
|
8
7
|
"*.cjs"
|
|
@@ -10,7 +9,7 @@
|
|
|
10
9
|
"main": "./dist/index.js",
|
|
11
10
|
"types": "./dist/index.d.ts",
|
|
12
11
|
"scripts": {
|
|
13
|
-
"build": "tsc",
|
|
12
|
+
"build": "tsc --emitDeclarationOnly && esbuild src/index.ts --charset=utf8 --target=es2023 --format=cjs --outfile=dist/index.js",
|
|
14
13
|
"lint": "tsc --noEmit && eslint --cache ."
|
|
15
14
|
},
|
|
16
15
|
"devDependencies": {
|