@bhsd/common 0.3.0 → 0.4.0
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.cjs +90 -0
- package/dist/index.js +5 -1
- package/package.json +2 -2
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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);
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export const CDN = 'https://testingcf.jsdelivr.net';
|
|
2
|
-
const hexColor = String.raw `#(?:[\da-f]{3,4}|(?:[\da-f]{2}){3,4})(?![\p{L}\d_])`, rgbColor = String.raw `rgba?\(\s*(?:${String.raw
|
|
2
|
+
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');
|
|
3
|
+
let span;
|
|
4
|
+
if (typeof document === 'object') {
|
|
5
|
+
span = document.createElement('span');
|
|
6
|
+
}
|
|
3
7
|
/**
|
|
4
8
|
* 解码标题
|
|
5
9
|
* @param title 标题
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "GPL-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "tsc",
|
|
13
|
+
"build": "tsc && esbuild src/index.ts --charset=utf8 --target=es2023 --format=cjs --outfile=dist/index.cjs",
|
|
14
14
|
"lint": "tsc --noEmit && eslint --cache ."
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|