@bhsd/common 0.4.1 → 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 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
@@ -28,7 +28,7 @@ __export(src_exports, {
28
28
  });
29
29
  module.exports = __toCommonJS(src_exports);
30
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");
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");
32
32
  let span;
33
33
  if (typeof document === "object") {
34
34
  span = document.createElement("span");
@@ -41,9 +41,9 @@ const normalizeTitle = (title) => {
41
41
  span.innerHTML = decoded;
42
42
  return span.textContent;
43
43
  };
44
- const splitColors = (str) => {
44
+ const splitColors = (str, hsl = true) => {
45
+ const pieces = [], re = hsl ? reFull : reRGB;
45
46
  re.lastIndex = 0;
46
- const pieces = [];
47
47
  let mt = re.exec(str), lastIndex = 0;
48
48
  while (mt) {
49
49
  const index = mt.index + mt[1].length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/common",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "license": "GPL-2.0",
5
5
  "files": [
6
6
  "/dist/",