@weapp-tailwindcss/shared 2.0.0-next.0 → 2.0.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.
@@ -1,6 +1,7 @@
1
1
  //#region src/extractors/split.d.ts
2
2
  declare const validateFilterRE: RegExp;
3
3
  declare function isValidSelector(selector?: string): selector is string;
4
- declare function splitCode(code: string, allowDoubleQuotes?: boolean): string[];
4
+ declare function splitCandidateTokens(code: string): string[];
5
+ declare function splitCode(code: string, _allowDoubleQuotes?: boolean): string[];
5
6
  //#endregion
6
- export { isValidSelector, splitCode, validateFilterRE };
7
+ export { isValidSelector, splitCandidateTokens, splitCode, validateFilterRE };
@@ -4,29 +4,64 @@ const validateFilterRE = /[\w\u00A0-\uFFFF%-?]/;
4
4
  function isValidSelector(selector = "") {
5
5
  return validateFilterRE.test(selector);
6
6
  }
7
- /**
8
- * splitCode 结果缓存,避免对相同字符串重复分割和过滤。
9
- * 使用两个独立缓存分别对应 allowDoubleQuotes 的两种取值。
10
- */
11
- const splitCacheDefault = /* @__PURE__ */ new Map();
12
- const splitCacheAllowQuotes = /* @__PURE__ */ new Map();
7
+ /** 候选 token 分割结果缓存,避免对相同字符串重复分割和过滤。 */
8
+ const splitCache = /* @__PURE__ */ new Map();
13
9
  const SPLIT_CACHE_LIMIT = 8192;
14
- /** 预编译的分割正则,避免每次调用都创建 */
15
- const SPLITTER_DEFAULT = /\s+|"/;
16
- const SPLITTER_ALLOW_QUOTES = /\s+/;
17
10
  const ESCAPED_WHITESPACE_RE = /\\[nrt]/g;
18
- function splitCode(code, allowDoubleQuotes = false) {
19
- const cache = allowDoubleQuotes ? splitCacheAllowQuotes : splitCacheDefault;
20
- const cached = cache.get(code);
11
+ function isSplitter(char, bracketDepth) {
12
+ return bracketDepth === 0 && (char === "\"" || /\s/.test(char));
13
+ }
14
+ function hasClosingQuotedArbitraryValue(code, start, quote) {
15
+ for (let index = start; index < code.length; index++) {
16
+ if (code[index] === "\\") {
17
+ index++;
18
+ continue;
19
+ }
20
+ if (code[index] === quote) return code.includes("]", index + 1);
21
+ }
22
+ return false;
23
+ }
24
+ function splitBracketAware(code) {
25
+ const result = [];
26
+ let bracketDepth = 0;
27
+ let bracketQuote;
28
+ let start = 0;
29
+ for (let index = 0; index < code.length; index++) {
30
+ const char = code[index];
31
+ if (bracketDepth > 0 && char === "\\") {
32
+ index++;
33
+ continue;
34
+ }
35
+ if (bracketDepth > 0 && (char === "\"" || char === "'")) {
36
+ if (bracketQuote === char) bracketQuote = void 0;
37
+ else if (bracketQuote === void 0 && hasClosingQuotedArbitraryValue(code, index + 1, char)) bracketQuote = char;
38
+ }
39
+ if (bracketQuote === void 0) {
40
+ if (char === "[" && code.includes("]", index + 1)) bracketDepth++;
41
+ else if (char === "]" && bracketDepth > 0) bracketDepth--;
42
+ }
43
+ if (!isSplitter(char, bracketDepth)) continue;
44
+ const candidate = code.slice(start, index);
45
+ if (isValidSelector(candidate)) result.push(candidate);
46
+ start = index + 1;
47
+ }
48
+ const candidate = code.slice(start);
49
+ if (isValidSelector(candidate)) result.push(candidate);
50
+ return result;
51
+ }
52
+ function splitCandidateTokens(code) {
53
+ const cached = splitCache.get(code);
21
54
  if (cached) return cached;
22
- const normalized = code.includes("\\") ? code.replace(ESCAPED_WHITESPACE_RE, " ") : code;
23
- const splitter = allowDoubleQuotes ? SPLITTER_ALLOW_QUOTES : SPLITTER_DEFAULT;
24
- const result = normalized.split(splitter).filter((element) => isValidSelector(element));
25
- if (cache.size >= SPLIT_CACHE_LIMIT) cache.clear();
26
- cache.set(code, result);
55
+ const result = splitBracketAware(code.includes("\\") ? code.replace(ESCAPED_WHITESPACE_RE, " ") : code);
56
+ if (splitCache.size >= SPLIT_CACHE_LIMIT) splitCache.clear();
57
+ splitCache.set(code, result);
27
58
  return result;
28
59
  }
60
+ function splitCode(code, _allowDoubleQuotes = false) {
61
+ return splitCandidateTokens(code);
62
+ }
29
63
  //#endregion
30
64
  exports.isValidSelector = isValidSelector;
65
+ exports.splitCandidateTokens = splitCandidateTokens;
31
66
  exports.splitCode = splitCode;
32
67
  exports.validateFilterRE = validateFilterRE;
@@ -3,27 +3,61 @@ const validateFilterRE = /[\w\u00A0-\uFFFF%-?]/;
3
3
  function isValidSelector(selector = "") {
4
4
  return validateFilterRE.test(selector);
5
5
  }
6
- /**
7
- * splitCode 结果缓存,避免对相同字符串重复分割和过滤。
8
- * 使用两个独立缓存分别对应 allowDoubleQuotes 的两种取值。
9
- */
10
- const splitCacheDefault = /* @__PURE__ */ new Map();
11
- const splitCacheAllowQuotes = /* @__PURE__ */ new Map();
6
+ /** 候选 token 分割结果缓存,避免对相同字符串重复分割和过滤。 */
7
+ const splitCache = /* @__PURE__ */ new Map();
12
8
  const SPLIT_CACHE_LIMIT = 8192;
13
- /** 预编译的分割正则,避免每次调用都创建 */
14
- const SPLITTER_DEFAULT = /\s+|"/;
15
- const SPLITTER_ALLOW_QUOTES = /\s+/;
16
9
  const ESCAPED_WHITESPACE_RE = /\\[nrt]/g;
17
- function splitCode(code, allowDoubleQuotes = false) {
18
- const cache = allowDoubleQuotes ? splitCacheAllowQuotes : splitCacheDefault;
19
- const cached = cache.get(code);
10
+ function isSplitter(char, bracketDepth) {
11
+ return bracketDepth === 0 && (char === "\"" || /\s/.test(char));
12
+ }
13
+ function hasClosingQuotedArbitraryValue(code, start, quote) {
14
+ for (let index = start; index < code.length; index++) {
15
+ if (code[index] === "\\") {
16
+ index++;
17
+ continue;
18
+ }
19
+ if (code[index] === quote) return code.includes("]", index + 1);
20
+ }
21
+ return false;
22
+ }
23
+ function splitBracketAware(code) {
24
+ const result = [];
25
+ let bracketDepth = 0;
26
+ let bracketQuote;
27
+ let start = 0;
28
+ for (let index = 0; index < code.length; index++) {
29
+ const char = code[index];
30
+ if (bracketDepth > 0 && char === "\\") {
31
+ index++;
32
+ continue;
33
+ }
34
+ if (bracketDepth > 0 && (char === "\"" || char === "'")) {
35
+ if (bracketQuote === char) bracketQuote = void 0;
36
+ else if (bracketQuote === void 0 && hasClosingQuotedArbitraryValue(code, index + 1, char)) bracketQuote = char;
37
+ }
38
+ if (bracketQuote === void 0) {
39
+ if (char === "[" && code.includes("]", index + 1)) bracketDepth++;
40
+ else if (char === "]" && bracketDepth > 0) bracketDepth--;
41
+ }
42
+ if (!isSplitter(char, bracketDepth)) continue;
43
+ const candidate = code.slice(start, index);
44
+ if (isValidSelector(candidate)) result.push(candidate);
45
+ start = index + 1;
46
+ }
47
+ const candidate = code.slice(start);
48
+ if (isValidSelector(candidate)) result.push(candidate);
49
+ return result;
50
+ }
51
+ function splitCandidateTokens(code) {
52
+ const cached = splitCache.get(code);
20
53
  if (cached) return cached;
21
- const normalized = code.includes("\\") ? code.replace(ESCAPED_WHITESPACE_RE, " ") : code;
22
- const splitter = allowDoubleQuotes ? SPLITTER_ALLOW_QUOTES : SPLITTER_DEFAULT;
23
- const result = normalized.split(splitter).filter((element) => isValidSelector(element));
24
- if (cache.size >= SPLIT_CACHE_LIMIT) cache.clear();
25
- cache.set(code, result);
54
+ const result = splitBracketAware(code.includes("\\") ? code.replace(ESCAPED_WHITESPACE_RE, " ") : code);
55
+ if (splitCache.size >= SPLIT_CACHE_LIMIT) splitCache.clear();
56
+ splitCache.set(code, result);
26
57
  return result;
27
58
  }
59
+ function splitCode(code, _allowDoubleQuotes = false) {
60
+ return splitCandidateTokens(code);
61
+ }
28
62
  //#endregion
29
- export { isValidSelector, splitCode, validateFilterRE };
63
+ export { isValidSelector, splitCandidateTokens, splitCode, validateFilterRE };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- import * as _$defu from "defu";
2
- import { defu } from "defu";
3
1
  import getValue from "get-value";
4
2
  import setValue from "set-value";
3
+ import { defu } from "defu";
5
4
 
6
5
  //#region src/index.d.ts
7
6
  declare function isRegexp(value: unknown): value is RegExp;
@@ -18,6 +17,6 @@ declare function regExpTest(arr: (string | RegExp)[], str: string, options?: {
18
17
  declare function noop(): void;
19
18
  declare function groupBy<T>(arr: T[], cb: (arg: T) => string): Record<string, T[]>;
20
19
  declare function removeExt(file: string): string;
21
- declare const defuOverrideArray: _$defu.DefuFn;
20
+ declare const defuOverrideArray: import("defu").DefuFn;
22
21
  //#endregion
23
22
  export { cleanUrl, defu, defuOverrideArray, ensurePosix, getValue, groupBy, isHttp, isMap, isRegexp, noop, normalizeRelativeImport, normalizeRoot, regExpTest, removeExt, setValue, toArray };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_chunk = require("./chunk-8l464Juk.js");
2
+ const require_chunk = require("./chunk-D6vf50IK.js");
3
3
  let defu = require("defu");
4
4
  let get_value = require("get-value");
5
5
  get_value = require_chunk.__toESM(get_value);
package/dist/node.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_chunk = require("./chunk-8l464Juk.js");
2
+ const require_chunk = require("./chunk-D6vf50IK.js");
3
3
  let node_crypto = require("node:crypto");
4
4
  node_crypto = require_chunk.__toESM(node_crypto);
5
5
  //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
@@ -432,7 +432,7 @@ const _path = {
432
432
  };
433
433
  //#endregion
434
434
  //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
435
- const delimiter = globalThis.process?.platform === "win32" ? ";" : ":";
435
+ const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
436
436
  const _platforms = {
437
437
  posix: void 0,
438
438
  win32: void 0
package/dist/node.mjs CHANGED
@@ -429,7 +429,7 @@ const _path = {
429
429
  };
430
430
  //#endregion
431
431
  //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.mjs
432
- const delimiter = globalThis.process?.platform === "win32" ? ";" : ":";
432
+ const delimiter = /* @__PURE__ */ (() => globalThis.process?.platform === "win32" ? ";" : ":")();
433
433
  const _platforms = {
434
434
  posix: void 0,
435
435
  win32: void 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/shared",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0",
4
4
  "description": "@weapp-tailwindcss/shared",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
File without changes