@una-ui/extractor-vue-script-edge 1.0.0-alpha.6-29214985.441f53f → 1.0.0-alpha.6-29217002.c6e6b53

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.
Files changed (2) hide show
  1. package/dist/index.mjs +32 -8
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -4,17 +4,17 @@ function generateSelectors(prefix, values) {
4
4
  prefix = prefix.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
5
5
  return values.filter((v) => Boolean(v) && v !== ":").map((v) => `[${prefix}~="${v}"]`);
6
6
  }
7
+ function normalizePrefixes(prefixes) {
8
+ const camelCasePrefixes = prefixes.map((prefix) => prefix.replace(/-([a-z])/g, (_, c) => c.toUpperCase()));
9
+ return [.../* @__PURE__ */ new Set([...prefixes, ...camelCasePrefixes])];
10
+ }
7
11
  function splitCodeWithArbitraryVariants(code, prefixes) {
8
12
  const result = [];
9
- const camelCasePrefixes = prefixes.map((prefix) => prefix.replace(/-([a-z])/g, (_, c) => c.toUpperCase()));
10
- prefixes = [.../* @__PURE__ */ new Set([...prefixes, ...camelCasePrefixes])];
11
- for (const prefix of prefixes) {
13
+ const normalizedPrefixes = normalizePrefixes(prefixes);
14
+ for (const prefix of normalizedPrefixes) {
12
15
  const regex = new RegExp(`\\b${prefix}\\s*:\\s*(?:['"]([^'"]*)['"]|{[^}]*\\bdefault\\s*:\\s*['"]([^'"]*)['"]\\s*,?.*?})`, "gms");
13
16
  let match;
14
- while (true) {
15
- match = regex.exec(code);
16
- if (match === null)
17
- break;
17
+ while ((match = regex.exec(code)) !== null) {
18
18
  const values = (match[1] ?? match[2]).split(defaultSplitRE);
19
19
  const selectors = generateSelectors(prefix, values);
20
20
  result.push(...selectors);
@@ -22,12 +22,36 @@ function splitCodeWithArbitraryVariants(code, prefixes) {
22
22
  }
23
23
  return result;
24
24
  }
25
+ function extractConditionalStatements(code, prefixes) {
26
+ const result = [];
27
+ const normalizedPrefixes = normalizePrefixes(prefixes);
28
+ for (const prefix of normalizedPrefixes) {
29
+ const ternaryRegex = new RegExp(
30
+ `\\b${prefix}\\s*:\\s*[^?]*?\\?\\s*['"\`]([^'"\`]*?)['"\`]\\s*:\\s*['"\`]([^'"\`]*?)['"\`]`,
31
+ "gms"
32
+ );
33
+ let match;
34
+ while ((match = ternaryRegex.exec(code)) !== null) {
35
+ const [, trueValue, falseValue] = match;
36
+ const allValues = [
37
+ ...trueValue.split(defaultSplitRE),
38
+ ...falseValue.split(defaultSplitRE)
39
+ ];
40
+ const selectors = generateSelectors(prefix, allValues);
41
+ result.push(...selectors);
42
+ }
43
+ }
44
+ return result;
45
+ }
25
46
  function extractorVueScript(options) {
26
47
  return {
27
48
  name: "@una-ui/extractor-vue-script",
28
49
  order: 0,
29
50
  async extract({ code }) {
30
- return splitCodeWithArbitraryVariants(code, options?.prefixes ?? []);
51
+ const prefixes = options?.prefixes ?? [];
52
+ const regularResults = splitCodeWithArbitraryVariants(code, prefixes);
53
+ const conditionalResults = extractConditionalStatements(code, prefixes);
54
+ return [.../* @__PURE__ */ new Set([...regularResults, ...conditionalResults])];
31
55
  }
32
56
  };
33
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@una-ui/extractor-vue-script-edge",
3
- "version": "1.0.0-alpha.6-29214985.441f53f",
3
+ "version": "1.0.0-alpha.6-29217002.c6e6b53",
4
4
  "description": "Unocss extractor for Vue script",
5
5
  "author": "Phojie Rengel <phojrengel@gmail.com>",
6
6
  "license": "MIT",