@bhsd/common 0.4.0 → 0.4.2
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 +2 -1
- package/dist/index.js +83 -75
- package/package.json +2 -3
- package/dist/index.cjs +0 -90
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ export declare const normalizeTitle: (title: string) => string;
|
|
|
10
10
|
/**
|
|
11
11
|
* 包含颜色时断开字符串
|
|
12
12
|
* @param str 字符串
|
|
13
|
+
* @param hsl 是否包含 HSL
|
|
13
14
|
*/
|
|
14
|
-
export declare const splitColors: (str: string) => [string, number, number, boolean][];
|
|
15
|
+
export declare const splitColors: (str: string, hsl?: boolean) => [string, number, number, boolean][];
|
|
15
16
|
/**
|
|
16
17
|
* 使用传统方法加载脚本
|
|
17
18
|
* @param src 脚本地址
|
package/dist/index.js
CHANGED
|
@@ -1,82 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 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*\)`, reFull = new RegExp(String.raw`(^|[^\p{L}\d_])(${hexColor}|${rgbColor}|${hslColor})`, "giu"), reRGB = new RegExp(String.raw`(^|[^\p{L}\d_])(${hexColor}|${rgbColor})`, "giu");
|
|
3
32
|
let span;
|
|
4
|
-
if (typeof document ===
|
|
5
|
-
|
|
33
|
+
if (typeof document === "object") {
|
|
34
|
+
span = document.createElement("span");
|
|
6
35
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return decoded;
|
|
15
|
-
}
|
|
16
|
-
span.innerHTML = decoded;
|
|
17
|
-
return span.textContent;
|
|
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;
|
|
18
43
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
while (mt) {
|
|
28
|
-
const index = mt.index + mt[1].length;
|
|
29
|
-
if (index > lastIndex) {
|
|
30
|
-
pieces.push([str.slice(lastIndex, index), lastIndex, index, false]);
|
|
31
|
-
}
|
|
32
|
-
({ lastIndex } = re);
|
|
33
|
-
pieces.push([mt[2], index, lastIndex, true]);
|
|
34
|
-
mt = re.exec(str);
|
|
35
|
-
}
|
|
36
|
-
if (str.length > lastIndex) {
|
|
37
|
-
pieces.push([str.slice(lastIndex), lastIndex, str.length, false]);
|
|
44
|
+
const splitColors = (str, hsl = true) => {
|
|
45
|
+
const pieces = [], re = hsl ? reFull : reRGB;
|
|
46
|
+
re.lastIndex = 0;
|
|
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]);
|
|
38
52
|
}
|
|
39
|
-
|
|
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;
|
|
40
61
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
else {
|
|
65
|
-
const script = document.createElement('script');
|
|
66
|
-
script.src = path;
|
|
67
|
-
script.onload = () => {
|
|
68
|
-
resolve();
|
|
69
|
-
};
|
|
70
|
-
document.head.append(script);
|
|
71
|
-
}
|
|
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
|
+
}
|
|
72
85
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
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));
|
|
77
89
|
};
|
|
78
|
-
|
|
79
|
-
* 解析版本号
|
|
80
|
-
* @param v 版本号
|
|
81
|
-
*/
|
|
82
|
-
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.4.
|
|
3
|
+
"version": "0.4.2",
|
|
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 && esbuild src/index.ts --charset=utf8 --target=es2023 --format=cjs --outfile=dist/index.
|
|
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": {
|
package/dist/index.cjs
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
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 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]);
|
|
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
|
-
}
|
|
85
|
-
});
|
|
86
|
-
const getObject = (key) => JSON.parse(String(localStorage.getItem(key)));
|
|
87
|
-
const setObject = (key, value) => {
|
|
88
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
89
|
-
};
|
|
90
|
-
const parseVersion = (v) => v.split(".", 3).map(Number);
|