@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 CHANGED
File without changes
package/dist/index.js CHANGED
@@ -1,78 +1,90 @@
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_])`, 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'), span = document.createElement('span');
3
- /**
4
- * 解码标题
5
- * @param title 标题
6
- */
7
- export const normalizeTitle = (title) => {
8
- const decoded = decodeURIComponent(title.replace(/%(?![\da-f]{2})/giu, '%25'));
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
- * @param str 字符串
18
- */
19
- export const splitColors = (str) => {
20
- re.lastIndex = 0;
21
- const pieces = [];
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
- * @param src 脚本地址
40
- * @param globalConst 脚本全局变量名
41
- * @param amd 是否兼容 AMD
42
- */
43
- export const loadScript = (src, globalConst, amd) => new Promise(resolve => {
44
- const path = `${CDN}/${src}`;
45
- let obj = window;
46
- for (const prop of globalConst.split('.')) {
47
- obj = obj === null || obj === void 0 ? void 0 : obj[prop];
48
- }
49
- if (obj) {
50
- resolve();
51
- }
52
- else if (amd && typeof define === 'function' && 'amd' in define) {
53
- const requirejs = window.require;
54
- requirejs.config({ paths: { [globalConst]: path } });
55
- requirejs([globalConst], (exports) => {
56
- Object.assign(window, { [globalConst]: exports });
57
- resolve();
58
- });
59
- }
60
- else {
61
- const script = document.createElement('script');
62
- script.src = path;
63
- script.onload = () => {
64
- resolve();
65
- };
66
- document.head.append(script);
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
- export const getObject = (key) => JSON.parse(String(localStorage.getItem(key)));
71
- export const setObject = (key, value) => {
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.1",
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": {