@bhsd/common 0.4.1 → 0.4.3
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 +7 -1
- package/dist/index.js +6 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ export declare const CDN = "https://testingcf.jsdelivr.net";
|
|
|
2
2
|
declare global {
|
|
3
3
|
const define: unknown;
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* PHP的`rawurldecode`函数的JavaScript实现
|
|
7
|
+
* @param str 要解码的字符串
|
|
8
|
+
*/
|
|
9
|
+
export declare const rawurldecode: (str: string) => string;
|
|
5
10
|
/**
|
|
6
11
|
* 解码标题
|
|
7
12
|
* @param title 标题
|
|
@@ -10,8 +15,9 @@ export declare const normalizeTitle: (title: string) => string;
|
|
|
10
15
|
/**
|
|
11
16
|
* 包含颜色时断开字符串
|
|
12
17
|
* @param str 字符串
|
|
18
|
+
* @param hsl 是否包含 HSL
|
|
13
19
|
*/
|
|
14
|
-
export declare const splitColors: (str: string) => [string, number, number, boolean][];
|
|
20
|
+
export declare const splitColors: (str: string, hsl?: boolean) => [string, number, number, boolean][];
|
|
15
21
|
/**
|
|
16
22
|
* 使用传统方法加载脚本
|
|
17
23
|
* @param src 脚本地址
|
package/dist/index.js
CHANGED
|
@@ -23,27 +23,29 @@ __export(src_exports, {
|
|
|
23
23
|
loadScript: () => loadScript,
|
|
24
24
|
normalizeTitle: () => normalizeTitle,
|
|
25
25
|
parseVersion: () => parseVersion,
|
|
26
|
+
rawurldecode: () => rawurldecode,
|
|
26
27
|
setObject: () => setObject,
|
|
27
28
|
splitColors: () => splitColors
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(src_exports);
|
|
30
31
|
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*\)`,
|
|
32
|
+
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");
|
|
32
33
|
let span;
|
|
33
34
|
if (typeof document === "object") {
|
|
34
35
|
span = document.createElement("span");
|
|
35
36
|
}
|
|
37
|
+
const rawurldecode = (str) => decodeURIComponent(str.replace(/%(?![\da-f]{2})/giu, "%25"));
|
|
36
38
|
const normalizeTitle = (title) => {
|
|
37
|
-
const decoded =
|
|
39
|
+
const decoded = rawurldecode(title);
|
|
38
40
|
if (/[<>[\]|{}]/u.test(decoded)) {
|
|
39
41
|
return decoded;
|
|
40
42
|
}
|
|
41
43
|
span.innerHTML = decoded;
|
|
42
44
|
return span.textContent;
|
|
43
45
|
};
|
|
44
|
-
const splitColors = (str) => {
|
|
46
|
+
const splitColors = (str, hsl = true) => {
|
|
47
|
+
const pieces = [], re = hsl ? reFull : reRGB;
|
|
45
48
|
re.lastIndex = 0;
|
|
46
|
-
const pieces = [];
|
|
47
49
|
let mt = re.exec(str), lastIndex = 0;
|
|
48
50
|
while (mt) {
|
|
49
51
|
const index = mt.index + mt[1].length;
|