@unocss/extractor-arbitrary-variants 66.5.10 → 66.5.12

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.mts CHANGED
@@ -1,8 +1,38 @@
1
- import { Extractor } from '@unocss/core';
2
-
1
+ //#region ../../packages-engine/core/src/utils/countable-set.d.ts
2
+ declare class CountableSet<K$1> extends Set<K$1> {
3
+ _map: Map<K$1, number>;
4
+ constructor(values?: Iterable<K$1>);
5
+ add(key: K$1): this;
6
+ delete(key: K$1): boolean;
7
+ clear(): void;
8
+ getCount(key: K$1): number;
9
+ setCount(key: K$1, count: number): this;
10
+ }
11
+ //#endregion
12
+ //#region ../../packages-engine/core/src/types.d.ts
13
+ type Awaitable<T> = T | Promise<T>;
14
+ interface ExtractorContext {
15
+ readonly original: string;
16
+ code: string;
17
+ id?: string;
18
+ extracted: Set<string> | CountableSet<string>;
19
+ envMode?: 'dev' | 'build';
20
+ }
21
+ interface Extractor {
22
+ name: string;
23
+ order?: number;
24
+ /**
25
+ * Extract the code and return a list of selectors.
26
+ *
27
+ * Return `undefined` to skip this extractor.
28
+ */
29
+ extract?: (ctx: ExtractorContext) => Awaitable<Set<string> | CountableSet<string> | string[] | undefined | void>;
30
+ }
31
+ //#endregion
32
+ //#region src/index.d.ts
3
33
  declare const quotedArbitraryValuesRE: RegExp;
4
34
  declare const arbitraryPropertyRE: RegExp;
5
35
  declare function splitCodeWithArbitraryVariants(code: string): string[];
6
36
  declare function extractorArbitraryVariants(): Extractor;
7
-
8
- export { arbitraryPropertyRE, extractorArbitraryVariants, quotedArbitraryValuesRE, splitCodeWithArbitraryVariants };
37
+ //#endregion
38
+ export { arbitraryPropertyRE, extractorArbitraryVariants, quotedArbitraryValuesRE, splitCodeWithArbitraryVariants };
package/dist/index.mjs CHANGED
@@ -1,72 +1,69 @@
1
- import { defaultSplitRE, isValidSelector } from '@unocss/core';
1
+ import { defaultSplitRE, isValidSelector } from "@unocss/core";
2
2
 
3
+ //#region ../../virtual-shared/integration/src/utils.ts
3
4
  function hash(str) {
4
- let i;
5
- let l;
6
- let hval = 2166136261;
7
- for (i = 0, l = str.length; i < l; i++) {
8
- hval ^= str.charCodeAt(i);
9
- hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
10
- }
11
- return `00000${(hval >>> 0).toString(36)}`.slice(-6);
5
+ let i;
6
+ let l;
7
+ let hval = 2166136261;
8
+ for (i = 0, l = str.length; i < l; i++) {
9
+ hval ^= str.charCodeAt(i);
10
+ hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
11
+ }
12
+ return `00000${(hval >>> 0).toString(36)}`.slice(-6);
12
13
  }
13
14
  function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
14
- for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
15
- if (item != null) {
16
- const matched = item[0];
17
- const withHashKey = `${keyFlag}${hash(matched)}`;
18
- map.set(withHashKey, matched);
19
- code = code.replace(matched, withHashKey);
20
- }
21
- }
22
- return code;
15
+ for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) if (item != null) {
16
+ const matched = item[0];
17
+ const withHashKey = `${keyFlag}${hash(matched)}`;
18
+ map.set(withHashKey, matched);
19
+ code = code.replace(matched, withHashKey);
20
+ }
21
+ return code;
23
22
  }
24
23
  function restoreSkipCode(code, map) {
25
- for (const [withHashKey, matched] of map.entries())
26
- code = code.replaceAll(withHashKey, matched);
27
- return code;
24
+ for (const [withHashKey, matched] of map.entries()) code = code.replaceAll(withHashKey, matched);
25
+ return code;
28
26
  }
29
27
 
28
+ //#endregion
29
+ //#region src/source-map.ts
30
30
  const sourceMapRE = /\/\/#\s*sourceMappingURL=.*\n?/g;
31
31
  function removeSourceMap(code) {
32
- if (code.includes("sourceMappingURL="))
33
- return code.replace(sourceMapRE, "");
34
- return code;
32
+ if (code.includes("sourceMappingURL=")) return code.replace(sourceMapRE, "");
33
+ return code;
35
34
  }
36
35
 
36
+ //#endregion
37
+ //#region src/index.ts
37
38
  const quotedArbitraryValuesRE = /(?:[\w&:[\]-]|\[\S{1,64}=\S{1,64}\]){1,64}\[\\?['"]?\S{1,64}?['"]\]\]?[\w:-]{0,64}/g;
38
39
  const arbitraryPropertyRE = /\[(\\\W|[\w-]){1,64}:[^\s:]{0,64}?("\S{1,64}?"|'\S{1,64}?'|`\S{1,64}?`|[^\s:]{1,64}?)[^\s:]{0,64}?\)?\]/g;
39
40
  const arbitraryPropertyCandidateRE = /^\[(?:\\\W|[\w-]){1,64}:['"]?\S{1,64}?['"]?\]$/;
40
41
  function splitCodeWithArbitraryVariants(code) {
41
- const result = [];
42
- for (const match of code.matchAll(arbitraryPropertyRE)) {
43
- if (match.index !== 0 && !/^[\s'"`]/.test(code[match.index - 1] ?? ""))
44
- continue;
45
- result.push(match[0]);
46
- }
47
- for (const match of code.matchAll(quotedArbitraryValuesRE))
48
- result.push(match[0]);
49
- const skipMap = /* @__PURE__ */ new Map();
50
- const skipFlag = "@unocss-skip-arbitrary-brackets";
51
- code = transformSkipCode(code, skipMap, /-\[(?!&.+?;)[^\]]*\]/g, skipFlag);
52
- if (!code)
53
- return result;
54
- code.split(defaultSplitRE).forEach((match) => {
55
- if (match.includes(skipFlag))
56
- match = restoreSkipCode(match, skipMap);
57
- if (isValidSelector(match) && !arbitraryPropertyCandidateRE.test(match))
58
- result.push(match);
59
- });
60
- return result;
42
+ const result = [];
43
+ for (const match of code.matchAll(arbitraryPropertyRE)) {
44
+ if (match.index !== 0 && !/^[\s'"`]/.test(code[match.index - 1] ?? "")) continue;
45
+ result.push(match[0]);
46
+ }
47
+ for (const match of code.matchAll(quotedArbitraryValuesRE)) result.push(match[0]);
48
+ const skipMap = /* @__PURE__ */ new Map();
49
+ const skipFlag = "@unocss-skip-arbitrary-brackets";
50
+ code = transformSkipCode(code, skipMap, /-\[(?!&.+?;)[^\]]*\]/g, skipFlag);
51
+ if (!code) return result;
52
+ code.split(defaultSplitRE).forEach((match) => {
53
+ if (match.includes(skipFlag)) match = restoreSkipCode(match, skipMap);
54
+ if (isValidSelector(match) && !arbitraryPropertyCandidateRE.test(match)) result.push(match);
55
+ });
56
+ return result;
61
57
  }
62
58
  function extractorArbitraryVariants() {
63
- return {
64
- name: "@unocss/extractor-arbitrary-variants",
65
- order: 0,
66
- extract({ code }) {
67
- return splitCodeWithArbitraryVariants(removeSourceMap(code));
68
- }
69
- };
59
+ return {
60
+ name: "@unocss/extractor-arbitrary-variants",
61
+ order: 0,
62
+ extract({ code }) {
63
+ return splitCodeWithArbitraryVariants(removeSourceMap(code));
64
+ }
65
+ };
70
66
  }
71
67
 
72
- export { arbitraryPropertyRE, extractorArbitraryVariants, quotedArbitraryValuesRE, splitCodeWithArbitraryVariants };
68
+ //#endregion
69
+ export { arbitraryPropertyRE, extractorArbitraryVariants, quotedArbitraryValuesRE, splitCodeWithArbitraryVariants };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/extractor-arbitrary-variants",
3
3
  "type": "module",
4
- "version": "66.5.10",
4
+ "version": "66.5.12",
5
5
  "description": "Extractor arbitrary variants for utilities",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -28,16 +28,15 @@
28
28
  },
29
29
  "main": "./dist/index.mjs",
30
30
  "module": "./dist/index.mjs",
31
- "types": "./dist/index.d.ts",
31
+ "types": "./dist/index.d.mts",
32
32
  "files": [
33
33
  "dist"
34
34
  ],
35
35
  "dependencies": {
36
- "@unocss/core": "66.5.10"
36
+ "@unocss/core": "66.5.12"
37
37
  },
38
38
  "scripts": {
39
- "build": "unbuild",
40
- "stub": "unbuild --stub",
41
- "test:attw": "attw --pack --config-path ../../.attw-esm-only.json"
39
+ "build": "tsdown --config-loader unrun",
40
+ "dev": "tsdown --config-loader unrun --watch"
42
41
  }
43
42
  }
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { Extractor } from '@unocss/core';
2
-
3
- declare const quotedArbitraryValuesRE: RegExp;
4
- declare const arbitraryPropertyRE: RegExp;
5
- declare function splitCodeWithArbitraryVariants(code: string): string[];
6
- declare function extractorArbitraryVariants(): Extractor;
7
-
8
- export { arbitraryPropertyRE, extractorArbitraryVariants, quotedArbitraryValuesRE, splitCodeWithArbitraryVariants };