css-typed-vars 0.4.10 → 0.4.11

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.
@@ -6,17 +6,40 @@ var getDirname = () => path.dirname(getFilename());
6
6
  var __dirname = /* @__PURE__ */ getDirname();
7
7
 
8
8
  // src/parser.ts
9
+ function extractBlock(text, start) {
10
+ let depth = 1;
11
+ let quote = null;
12
+ let i = start;
13
+ for (; i < text.length && depth > 0; i++) {
14
+ const char = text[i];
15
+ if (quote) {
16
+ if (char === "\\") i++;
17
+ else if (char === quote) quote = null;
18
+ } else if (char === '"' || char === "'") {
19
+ quote = char;
20
+ } else if (char === "{") {
21
+ depth++;
22
+ } else if (char === "}") {
23
+ depth--;
24
+ }
25
+ }
26
+ return text.slice(start, depth === 0 ? i - 1 : i);
27
+ }
9
28
  function parseVarNames(css, selectors) {
10
29
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
11
30
  const names = /* @__PURE__ */ new Set();
12
31
  const allSelectors = [":root", ...selectors ?? []];
13
32
  for (const sel of allSelectors) {
14
33
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
15
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
16
- for (const match of stripped.matchAll(regex)) {
17
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
34
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
35
+ let match;
36
+ while (match = openRegex.exec(stripped)) {
37
+ const start = match.index + match[0].length;
38
+ const block = extractBlock(stripped, start);
39
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
18
40
  names.add(prop[0]);
19
41
  }
42
+ openRegex.lastIndex = start + block.length + 1;
20
43
  }
21
44
  }
22
45
  return [...names];
@@ -44,17 +67,20 @@ async function scanVarNames(patterns, exclude, selectors) {
44
67
  }
45
68
 
46
69
  // src/generator.ts
70
+ function convertCase(value, naming) {
71
+ if (naming === "kebab") return value;
72
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
73
+ }
47
74
  function toKey(cssVarName, naming = "camelCase") {
48
- const stripped = cssVarName.replace(/^--/, "");
49
- if (naming === "kebab") return stripped;
50
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
51
- return /^\d/.test(key) ? `_${key}` : key;
75
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
76
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
52
77
  }
53
78
  function applyPrefix(key, prefix, naming = "camelCase") {
54
79
  if (!prefix) return key;
55
- if (naming === "snake") return `${prefix}_${key}`;
56
- if (naming === "kebab") return `${prefix}-${key}`;
57
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
80
+ const normalizedPrefix = convertCase(prefix, naming);
81
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
82
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
83
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
58
84
  }
59
85
  function formatKey(key, naming = "camelCase") {
60
86
  if (naming === "kebab") return `'${key}'`;
@@ -3,7 +3,7 @@ import {
3
3
  generateDeclaration,
4
4
  generateJs,
5
5
  scanVarNames
6
- } from "./chunk-YVFKCMBF.js";
6
+ } from "./chunk-CHF2ERWU.js";
7
7
 
8
8
  // src/unplugin.ts
9
9
  import { createUnplugin } from "unplugin";
@@ -4,7 +4,7 @@ import {
4
4
  generateDeclaration,
5
5
  generateJs,
6
6
  scanVarNames
7
- } from "./chunk-YVFKCMBF.js";
7
+ } from "./chunk-CHF2ERWU.js";
8
8
 
9
9
  // src/index.ts
10
10
  import { writeFile, mkdir } from "fs/promises";
package/dist/cli.cjs CHANGED
@@ -42,17 +42,40 @@ var import_promises = require("fs/promises");
42
42
  var import_fast_glob = __toESM(require("fast-glob"), 1);
43
43
 
44
44
  // src/parser.ts
45
+ function extractBlock(text, start) {
46
+ let depth = 1;
47
+ let quote = null;
48
+ let i = start;
49
+ for (; i < text.length && depth > 0; i++) {
50
+ const char = text[i];
51
+ if (quote) {
52
+ if (char === "\\") i++;
53
+ else if (char === quote) quote = null;
54
+ } else if (char === '"' || char === "'") {
55
+ quote = char;
56
+ } else if (char === "{") {
57
+ depth++;
58
+ } else if (char === "}") {
59
+ depth--;
60
+ }
61
+ }
62
+ return text.slice(start, depth === 0 ? i - 1 : i);
63
+ }
45
64
  function parseVarNames(css, selectors) {
46
65
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
47
66
  const names = /* @__PURE__ */ new Set();
48
67
  const allSelectors = [":root", ...selectors ?? []];
49
68
  for (const sel of allSelectors) {
50
69
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
51
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
52
- for (const match of stripped.matchAll(regex)) {
53
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
70
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
71
+ let match;
72
+ while (match = openRegex.exec(stripped)) {
73
+ const start = match.index + match[0].length;
74
+ const block = extractBlock(stripped, start);
75
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
54
76
  names.add(prop[0]);
55
77
  }
78
+ openRegex.lastIndex = start + block.length + 1;
56
79
  }
57
80
  }
58
81
  return [...names];
@@ -78,17 +101,20 @@ async function scanVarNames(patterns, exclude, selectors) {
78
101
  }
79
102
 
80
103
  // src/generator.ts
104
+ function convertCase(value, naming) {
105
+ if (naming === "kebab") return value;
106
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
107
+ }
81
108
  function toKey(cssVarName, naming = "camelCase") {
82
- const stripped = cssVarName.replace(/^--/, "");
83
- if (naming === "kebab") return stripped;
84
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
85
- return /^\d/.test(key) ? `_${key}` : key;
109
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
110
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
86
111
  }
87
112
  function applyPrefix(key, prefix, naming = "camelCase") {
88
113
  if (!prefix) return key;
89
- if (naming === "snake") return `${prefix}_${key}`;
90
- if (naming === "kebab") return `${prefix}-${key}`;
91
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
114
+ const normalizedPrefix = convertCase(prefix, naming);
115
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
116
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
117
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
92
118
  }
93
119
  function formatKey(key, naming = "camelCase") {
94
120
  if (naming === "kebab") return `'${key}'`;
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  generate
4
- } from "./chunk-K5FAEWQE.js";
5
- import "./chunk-YVFKCMBF.js";
4
+ } from "./chunk-IJOMZOB4.js";
5
+ import "./chunk-CHF2ERWU.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { readFile } from "fs/promises";
package/dist/esbuild.cjs CHANGED
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
44
44
  var import_fast_glob = __toESM(require("fast-glob"), 1);
45
45
 
46
46
  // src/parser.ts
47
+ function extractBlock(text, start) {
48
+ let depth = 1;
49
+ let quote = null;
50
+ let i = start;
51
+ for (; i < text.length && depth > 0; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ if (char === "\\") i++;
55
+ else if (char === quote) quote = null;
56
+ } else if (char === '"' || char === "'") {
57
+ quote = char;
58
+ } else if (char === "{") {
59
+ depth++;
60
+ } else if (char === "}") {
61
+ depth--;
62
+ }
63
+ }
64
+ return text.slice(start, depth === 0 ? i - 1 : i);
65
+ }
47
66
  function parseVarNames(css, selectors) {
48
67
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
49
68
  const names = /* @__PURE__ */ new Set();
50
69
  const allSelectors = [":root", ...selectors ?? []];
51
70
  for (const sel of allSelectors) {
52
71
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
53
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
54
- for (const match of stripped.matchAll(regex)) {
55
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
72
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
73
+ let match;
74
+ while (match = openRegex.exec(stripped)) {
75
+ const start = match.index + match[0].length;
76
+ const block = extractBlock(stripped, start);
77
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
56
78
  names.add(prop[0]);
57
79
  }
80
+ openRegex.lastIndex = start + block.length + 1;
58
81
  }
59
82
  }
60
83
  return [...names];
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
80
103
  }
81
104
 
82
105
  // src/generator.ts
106
+ function convertCase(value, naming) {
107
+ if (naming === "kebab") return value;
108
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
109
+ }
83
110
  function toKey(cssVarName, naming = "camelCase") {
84
- const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "kebab") return stripped;
86
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
87
- return /^\d/.test(key) ? `_${key}` : key;
111
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
112
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
88
113
  }
89
114
  function applyPrefix(key, prefix, naming = "camelCase") {
90
115
  if (!prefix) return key;
91
- if (naming === "snake") return `${prefix}_${key}`;
92
- if (naming === "kebab") return `${prefix}-${key}`;
93
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
116
+ const normalizedPrefix = convertCase(prefix, naming);
117
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
118
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
119
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
94
120
  }
95
121
  function formatKey(key, naming = "camelCase") {
96
122
  if (naming === "kebab") return `'${key}'`;
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-3YUKUAJQ.js";
4
- import "./chunk-YVFKCMBF.js";
3
+ } from "./chunk-EGDCGDEQ.js";
4
+ import "./chunk-CHF2ERWU.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -46,17 +46,40 @@ var import_promises = require("fs/promises");
46
46
  var import_fast_glob = __toESM(require("fast-glob"), 1);
47
47
 
48
48
  // src/parser.ts
49
+ function extractBlock(text, start) {
50
+ let depth = 1;
51
+ let quote = null;
52
+ let i = start;
53
+ for (; i < text.length && depth > 0; i++) {
54
+ const char = text[i];
55
+ if (quote) {
56
+ if (char === "\\") i++;
57
+ else if (char === quote) quote = null;
58
+ } else if (char === '"' || char === "'") {
59
+ quote = char;
60
+ } else if (char === "{") {
61
+ depth++;
62
+ } else if (char === "}") {
63
+ depth--;
64
+ }
65
+ }
66
+ return text.slice(start, depth === 0 ? i - 1 : i);
67
+ }
49
68
  function parseVarNames(css, selectors) {
50
69
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
51
70
  const names = /* @__PURE__ */ new Set();
52
71
  const allSelectors = [":root", ...selectors ?? []];
53
72
  for (const sel of allSelectors) {
54
73
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
55
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
56
- for (const match of stripped.matchAll(regex)) {
57
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
74
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
75
+ let match;
76
+ while (match = openRegex.exec(stripped)) {
77
+ const start = match.index + match[0].length;
78
+ const block = extractBlock(stripped, start);
79
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
58
80
  names.add(prop[0]);
59
81
  }
82
+ openRegex.lastIndex = start + block.length + 1;
60
83
  }
61
84
  }
62
85
  return [...names];
@@ -82,17 +105,20 @@ async function scanVarNames(patterns, exclude, selectors) {
82
105
  }
83
106
 
84
107
  // src/generator.ts
108
+ function convertCase(value, naming) {
109
+ if (naming === "kebab") return value;
110
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
111
+ }
85
112
  function toKey(cssVarName, naming = "camelCase") {
86
- const stripped = cssVarName.replace(/^--/, "");
87
- if (naming === "kebab") return stripped;
88
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
89
- return /^\d/.test(key) ? `_${key}` : key;
113
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
114
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
90
115
  }
91
116
  function applyPrefix(key, prefix, naming = "camelCase") {
92
117
  if (!prefix) return key;
93
- if (naming === "snake") return `${prefix}_${key}`;
94
- if (naming === "kebab") return `${prefix}-${key}`;
95
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
118
+ const normalizedPrefix = convertCase(prefix, naming);
119
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
120
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
121
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
96
122
  }
97
123
  function formatKey(key, naming = "camelCase") {
98
124
  if (naming === "kebab") return `'${key}'`;
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  generate
3
- } from "./chunk-K5FAEWQE.js";
3
+ } from "./chunk-IJOMZOB4.js";
4
4
  import {
5
5
  generateCode,
6
6
  generateDeclaration,
7
7
  generateJs,
8
8
  parseVarNames,
9
9
  scanVarNames
10
- } from "./chunk-YVFKCMBF.js";
10
+ } from "./chunk-CHF2ERWU.js";
11
11
  export {
12
12
  generate,
13
13
  generateCode,
package/dist/rollup.cjs CHANGED
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
44
44
  var import_fast_glob = __toESM(require("fast-glob"), 1);
45
45
 
46
46
  // src/parser.ts
47
+ function extractBlock(text, start) {
48
+ let depth = 1;
49
+ let quote = null;
50
+ let i = start;
51
+ for (; i < text.length && depth > 0; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ if (char === "\\") i++;
55
+ else if (char === quote) quote = null;
56
+ } else if (char === '"' || char === "'") {
57
+ quote = char;
58
+ } else if (char === "{") {
59
+ depth++;
60
+ } else if (char === "}") {
61
+ depth--;
62
+ }
63
+ }
64
+ return text.slice(start, depth === 0 ? i - 1 : i);
65
+ }
47
66
  function parseVarNames(css, selectors) {
48
67
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
49
68
  const names = /* @__PURE__ */ new Set();
50
69
  const allSelectors = [":root", ...selectors ?? []];
51
70
  for (const sel of allSelectors) {
52
71
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
53
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
54
- for (const match of stripped.matchAll(regex)) {
55
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
72
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
73
+ let match;
74
+ while (match = openRegex.exec(stripped)) {
75
+ const start = match.index + match[0].length;
76
+ const block = extractBlock(stripped, start);
77
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
56
78
  names.add(prop[0]);
57
79
  }
80
+ openRegex.lastIndex = start + block.length + 1;
58
81
  }
59
82
  }
60
83
  return [...names];
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
80
103
  }
81
104
 
82
105
  // src/generator.ts
106
+ function convertCase(value, naming) {
107
+ if (naming === "kebab") return value;
108
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
109
+ }
83
110
  function toKey(cssVarName, naming = "camelCase") {
84
- const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "kebab") return stripped;
86
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
87
- return /^\d/.test(key) ? `_${key}` : key;
111
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
112
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
88
113
  }
89
114
  function applyPrefix(key, prefix, naming = "camelCase") {
90
115
  if (!prefix) return key;
91
- if (naming === "snake") return `${prefix}_${key}`;
92
- if (naming === "kebab") return `${prefix}-${key}`;
93
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
116
+ const normalizedPrefix = convertCase(prefix, naming);
117
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
118
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
119
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
94
120
  }
95
121
  function formatKey(key, naming = "camelCase") {
96
122
  if (naming === "kebab") return `'${key}'`;
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-3YUKUAJQ.js";
4
- import "./chunk-YVFKCMBF.js";
3
+ } from "./chunk-EGDCGDEQ.js";
4
+ import "./chunk-CHF2ERWU.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -42,17 +42,40 @@ var import_promises = require("fs/promises");
42
42
  var import_fast_glob = __toESM(require("fast-glob"), 1);
43
43
 
44
44
  // src/parser.ts
45
+ function extractBlock(text, start) {
46
+ let depth = 1;
47
+ let quote = null;
48
+ let i = start;
49
+ for (; i < text.length && depth > 0; i++) {
50
+ const char = text[i];
51
+ if (quote) {
52
+ if (char === "\\") i++;
53
+ else if (char === quote) quote = null;
54
+ } else if (char === '"' || char === "'") {
55
+ quote = char;
56
+ } else if (char === "{") {
57
+ depth++;
58
+ } else if (char === "}") {
59
+ depth--;
60
+ }
61
+ }
62
+ return text.slice(start, depth === 0 ? i - 1 : i);
63
+ }
45
64
  function parseVarNames(css, selectors) {
46
65
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
47
66
  const names = /* @__PURE__ */ new Set();
48
67
  const allSelectors = [":root", ...selectors ?? []];
49
68
  for (const sel of allSelectors) {
50
69
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
51
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
52
- for (const match of stripped.matchAll(regex)) {
53
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
70
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
71
+ let match;
72
+ while (match = openRegex.exec(stripped)) {
73
+ const start = match.index + match[0].length;
74
+ const block = extractBlock(stripped, start);
75
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
54
76
  names.add(prop[0]);
55
77
  }
78
+ openRegex.lastIndex = start + block.length + 1;
56
79
  }
57
80
  }
58
81
  return [...names];
@@ -78,17 +101,20 @@ async function scanVarNames(patterns, exclude, selectors) {
78
101
  }
79
102
 
80
103
  // src/generator.ts
104
+ function convertCase(value, naming) {
105
+ if (naming === "kebab") return value;
106
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
107
+ }
81
108
  function toKey(cssVarName, naming = "camelCase") {
82
- const stripped = cssVarName.replace(/^--/, "");
83
- if (naming === "kebab") return stripped;
84
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
85
- return /^\d/.test(key) ? `_${key}` : key;
109
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
110
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
86
111
  }
87
112
  function applyPrefix(key, prefix, naming = "camelCase") {
88
113
  if (!prefix) return key;
89
- if (naming === "snake") return `${prefix}_${key}`;
90
- if (naming === "kebab") return `${prefix}-${key}`;
91
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
114
+ const normalizedPrefix = convertCase(prefix, naming);
115
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
116
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
117
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
92
118
  }
93
119
  function formatKey(key, naming = "camelCase") {
94
120
  if (naming === "kebab") return `'${key}'`;
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-3YUKUAJQ.js";
4
- import "./chunk-YVFKCMBF.js";
3
+ } from "./chunk-EGDCGDEQ.js";
4
+ import "./chunk-CHF2ERWU.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
44
44
  var import_fast_glob = __toESM(require("fast-glob"), 1);
45
45
 
46
46
  // src/parser.ts
47
+ function extractBlock(text, start) {
48
+ let depth = 1;
49
+ let quote = null;
50
+ let i = start;
51
+ for (; i < text.length && depth > 0; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ if (char === "\\") i++;
55
+ else if (char === quote) quote = null;
56
+ } else if (char === '"' || char === "'") {
57
+ quote = char;
58
+ } else if (char === "{") {
59
+ depth++;
60
+ } else if (char === "}") {
61
+ depth--;
62
+ }
63
+ }
64
+ return text.slice(start, depth === 0 ? i - 1 : i);
65
+ }
47
66
  function parseVarNames(css, selectors) {
48
67
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
49
68
  const names = /* @__PURE__ */ new Set();
50
69
  const allSelectors = [":root", ...selectors ?? []];
51
70
  for (const sel of allSelectors) {
52
71
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
53
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
54
- for (const match of stripped.matchAll(regex)) {
55
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
72
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
73
+ let match;
74
+ while (match = openRegex.exec(stripped)) {
75
+ const start = match.index + match[0].length;
76
+ const block = extractBlock(stripped, start);
77
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
56
78
  names.add(prop[0]);
57
79
  }
80
+ openRegex.lastIndex = start + block.length + 1;
58
81
  }
59
82
  }
60
83
  return [...names];
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
80
103
  }
81
104
 
82
105
  // src/generator.ts
106
+ function convertCase(value, naming) {
107
+ if (naming === "kebab") return value;
108
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
109
+ }
83
110
  function toKey(cssVarName, naming = "camelCase") {
84
- const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "kebab") return stripped;
86
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
87
- return /^\d/.test(key) ? `_${key}` : key;
111
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
112
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
88
113
  }
89
114
  function applyPrefix(key, prefix, naming = "camelCase") {
90
115
  if (!prefix) return key;
91
- if (naming === "snake") return `${prefix}_${key}`;
92
- if (naming === "kebab") return `${prefix}-${key}`;
93
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
116
+ const normalizedPrefix = convertCase(prefix, naming);
117
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
118
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
119
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
94
120
  }
95
121
  function formatKey(key, naming = "camelCase") {
96
122
  if (naming === "kebab") return `'${key}'`;
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-3YUKUAJQ.js";
4
- import "./chunk-YVFKCMBF.js";
3
+ } from "./chunk-EGDCGDEQ.js";
4
+ import "./chunk-CHF2ERWU.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -44,17 +44,40 @@ var import_promises = require("fs/promises");
44
44
  var import_fast_glob = __toESM(require("fast-glob"), 1);
45
45
 
46
46
  // src/parser.ts
47
+ function extractBlock(text, start) {
48
+ let depth = 1;
49
+ let quote = null;
50
+ let i = start;
51
+ for (; i < text.length && depth > 0; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ if (char === "\\") i++;
55
+ else if (char === quote) quote = null;
56
+ } else if (char === '"' || char === "'") {
57
+ quote = char;
58
+ } else if (char === "{") {
59
+ depth++;
60
+ } else if (char === "}") {
61
+ depth--;
62
+ }
63
+ }
64
+ return text.slice(start, depth === 0 ? i - 1 : i);
65
+ }
47
66
  function parseVarNames(css, selectors) {
48
67
  const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
49
68
  const names = /* @__PURE__ */ new Set();
50
69
  const allSelectors = [":root", ...selectors ?? []];
51
70
  for (const sel of allSelectors) {
52
71
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
53
- const regex = new RegExp(`${escaped}[^{]*\\{([^}]*)\\}`, "g");
54
- for (const match of stripped.matchAll(regex)) {
55
- for (const prop of match[1].matchAll(/--[\w-]+(?=\s*:)/g)) {
72
+ const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
73
+ let match;
74
+ while (match = openRegex.exec(stripped)) {
75
+ const start = match.index + match[0].length;
76
+ const block = extractBlock(stripped, start);
77
+ for (const prop of block.matchAll(/--[\w-]+(?=\s*:)/g)) {
56
78
  names.add(prop[0]);
57
79
  }
80
+ openRegex.lastIndex = start + block.length + 1;
58
81
  }
59
82
  }
60
83
  return [...names];
@@ -80,17 +103,20 @@ async function scanVarNames(patterns, exclude, selectors) {
80
103
  }
81
104
 
82
105
  // src/generator.ts
106
+ function convertCase(value, naming) {
107
+ if (naming === "kebab") return value;
108
+ return naming === "snake" ? value.replace(/-+/g, "_") : value.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
109
+ }
83
110
  function toKey(cssVarName, naming = "camelCase") {
84
- const stripped = cssVarName.replace(/^--/, "");
85
- if (naming === "kebab") return stripped;
86
- const key = naming === "snake" ? stripped.replace(/-+/g, "_") : stripped.replace(/-+([a-z0-9])/g, (_, c) => c.toUpperCase()).replace(/-/g, "");
87
- return /^\d/.test(key) ? `_${key}` : key;
111
+ const key = convertCase(cssVarName.replace(/^--/, ""), naming);
112
+ return naming !== "kebab" && /^\d/.test(key) ? `_${key}` : key;
88
113
  }
89
114
  function applyPrefix(key, prefix, naming = "camelCase") {
90
115
  if (!prefix) return key;
91
- if (naming === "snake") return `${prefix}_${key}`;
92
- if (naming === "kebab") return `${prefix}-${key}`;
93
- return prefix + key.charAt(0).toUpperCase() + key.slice(1);
116
+ const normalizedPrefix = convertCase(prefix, naming);
117
+ if (naming === "snake") return `${normalizedPrefix}_${key}`;
118
+ if (naming === "kebab") return `${normalizedPrefix}-${key}`;
119
+ return normalizedPrefix + key.charAt(0).toUpperCase() + key.slice(1);
94
120
  }
95
121
  function formatKey(key, naming = "camelCase") {
96
122
  if (naming === "kebab") return `'${key}'`;
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-3YUKUAJQ.js";
4
- import "./chunk-YVFKCMBF.js";
3
+ } from "./chunk-EGDCGDEQ.js";
4
+ import "./chunk-CHF2ERWU.js";
5
5
 
6
6
  // src/webpack.ts
7
7
  var webpack_default = unplugin_default.webpack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-typed-vars",
3
- "version": "0.4.10",
3
+ "version": "0.4.11",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",