css-typed-vars 0.4.11 → 0.4.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.
@@ -6,6 +6,55 @@ var getDirname = () => path.dirname(getFilename());
6
6
  var __dirname = /* @__PURE__ */ getDirname();
7
7
 
8
8
  // src/parser.ts
9
+ function stripComments(text) {
10
+ let result = "";
11
+ let quote = null;
12
+ let urlDepth = 0;
13
+ for (let i = 0; i < text.length; i++) {
14
+ const char = text[i];
15
+ if (quote) {
16
+ result += char;
17
+ if (char === "\\" && i + 1 < text.length) {
18
+ result += text[++i];
19
+ } else if (char === quote) {
20
+ quote = null;
21
+ }
22
+ continue;
23
+ }
24
+ if (urlDepth > 0) {
25
+ if (char === "(") urlDepth++;
26
+ else if (char === ")") urlDepth--;
27
+ result += char;
28
+ continue;
29
+ }
30
+ if (char === '"' || char === "'") {
31
+ quote = char;
32
+ result += char;
33
+ continue;
34
+ }
35
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
36
+ urlDepth = 1;
37
+ result += char;
38
+ continue;
39
+ }
40
+ if (char === "/" && text[i + 1] === "*") {
41
+ const end = text.indexOf("*/", i + 2);
42
+ if (end === -1) {
43
+ result += char;
44
+ continue;
45
+ }
46
+ i = end + 1;
47
+ continue;
48
+ }
49
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
50
+ const nl = text.indexOf("\n", i);
51
+ i = nl === -1 ? text.length - 1 : nl - 1;
52
+ continue;
53
+ }
54
+ result += char;
55
+ }
56
+ return result;
57
+ }
9
58
  function extractBlock(text, start) {
10
59
  let depth = 1;
11
60
  let quote = null;
@@ -26,12 +75,12 @@ function extractBlock(text, start) {
26
75
  return text.slice(start, depth === 0 ? i - 1 : i);
27
76
  }
28
77
  function parseVarNames(css, selectors) {
29
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
78
+ const stripped = stripComments(css);
30
79
  const names = /* @__PURE__ */ new Set();
31
80
  const allSelectors = [":root", ...selectors ?? []];
32
81
  for (const sel of allSelectors) {
33
82
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
34
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
83
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
35
84
  let match;
36
85
  while (match = openRegex.exec(stripped)) {
37
86
  const start = match.index + match[0].length;
@@ -3,7 +3,7 @@ import {
3
3
  generateDeclaration,
4
4
  generateJs,
5
5
  scanVarNames
6
- } from "./chunk-CHF2ERWU.js";
6
+ } from "./chunk-2GVOUCFD.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-CHF2ERWU.js";
7
+ } from "./chunk-2GVOUCFD.js";
8
8
 
9
9
  // src/index.ts
10
10
  import { writeFile, mkdir } from "fs/promises";
@@ -19,9 +19,10 @@ async function generate(options) {
19
19
  }
20
20
  const outPath = resolve(options.output);
21
21
  await mkdir(dirname(outPath), { recursive: true });
22
- if (options.output.endsWith(".js")) {
22
+ const jsExtMatch = /\.(m|c)?js$/.exec(options.output);
23
+ if (jsExtMatch) {
23
24
  await writeFile(outPath, generateJs(names, options.prefix, options.naming), "utf8");
24
- const dtsPath = outPath.replace(/\.js$/, ".d.ts");
25
+ const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
25
26
  await writeFile(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
26
27
  } else {
27
28
  await writeFile(outPath, generateCode(names, options.prefix, options.naming), "utf8");
package/dist/cli.cjs CHANGED
@@ -42,6 +42,55 @@ 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 stripComments(text) {
46
+ let result = "";
47
+ let quote = null;
48
+ let urlDepth = 0;
49
+ for (let i = 0; i < text.length; i++) {
50
+ const char = text[i];
51
+ if (quote) {
52
+ result += char;
53
+ if (char === "\\" && i + 1 < text.length) {
54
+ result += text[++i];
55
+ } else if (char === quote) {
56
+ quote = null;
57
+ }
58
+ continue;
59
+ }
60
+ if (urlDepth > 0) {
61
+ if (char === "(") urlDepth++;
62
+ else if (char === ")") urlDepth--;
63
+ result += char;
64
+ continue;
65
+ }
66
+ if (char === '"' || char === "'") {
67
+ quote = char;
68
+ result += char;
69
+ continue;
70
+ }
71
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
72
+ urlDepth = 1;
73
+ result += char;
74
+ continue;
75
+ }
76
+ if (char === "/" && text[i + 1] === "*") {
77
+ const end = text.indexOf("*/", i + 2);
78
+ if (end === -1) {
79
+ result += char;
80
+ continue;
81
+ }
82
+ i = end + 1;
83
+ continue;
84
+ }
85
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
86
+ const nl = text.indexOf("\n", i);
87
+ i = nl === -1 ? text.length - 1 : nl - 1;
88
+ continue;
89
+ }
90
+ result += char;
91
+ }
92
+ return result;
93
+ }
45
94
  function extractBlock(text, start) {
46
95
  let depth = 1;
47
96
  let quote = null;
@@ -62,12 +111,12 @@ function extractBlock(text, start) {
62
111
  return text.slice(start, depth === 0 ? i - 1 : i);
63
112
  }
64
113
  function parseVarNames(css, selectors) {
65
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
114
+ const stripped = stripComments(css);
66
115
  const names = /* @__PURE__ */ new Set();
67
116
  const allSelectors = [":root", ...selectors ?? []];
68
117
  for (const sel of allSelectors) {
69
118
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
70
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
119
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
71
120
  let match;
72
121
  while (match = openRegex.exec(stripped)) {
73
122
  const start = match.index + match[0].length;
@@ -186,9 +235,10 @@ async function generate(options) {
186
235
  }
187
236
  const outPath = (0, import_node_path.resolve)(options.output);
188
237
  await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
189
- if (options.output.endsWith(".js")) {
238
+ const jsExtMatch = /\.(m|c)?js$/.exec(options.output);
239
+ if (jsExtMatch) {
190
240
  await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
191
- const dtsPath = outPath.replace(/\.js$/, ".d.ts");
241
+ const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
192
242
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
193
243
  } else {
194
244
  await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
@@ -273,7 +323,8 @@ async function main() {
273
323
  console.log(`${label}: ${file}`);
274
324
  run(input, output, exclude, prefix, naming, selectors).catch(console.error);
275
325
  };
276
- (0, import_chokidar.watch)(patterns).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
326
+ const ignored = exclude ? Array.isArray(exclude) ? exclude : [exclude] : void 0;
327
+ (0, import_chokidar.watch)(patterns, ignored ? { ignored } : void 0).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
277
328
  console.log("Watching for changes...");
278
329
  }
279
330
  }
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  generate
4
- } from "./chunk-IJOMZOB4.js";
5
- import "./chunk-CHF2ERWU.js";
4
+ } from "./chunk-KETRI7BY.js";
5
+ import "./chunk-2GVOUCFD.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { readFile } from "fs/promises";
@@ -86,7 +86,8 @@ async function main() {
86
86
  console.log(`${label}: ${file}`);
87
87
  run(input, output, exclude, prefix, naming, selectors).catch(console.error);
88
88
  };
89
- watch(patterns).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
89
+ const ignored = exclude ? Array.isArray(exclude) ? exclude : [exclude] : void 0;
90
+ watch(patterns, ignored ? { ignored } : void 0).on("change", makeHandler("Changed")).on("add", makeHandler("Added")).on("unlink", makeHandler("Removed"));
90
91
  console.log("Watching for changes...");
91
92
  }
92
93
  }
package/dist/esbuild.cjs CHANGED
@@ -44,6 +44,55 @@ 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 stripComments(text) {
48
+ let result = "";
49
+ let quote = null;
50
+ let urlDepth = 0;
51
+ for (let i = 0; i < text.length; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ result += char;
55
+ if (char === "\\" && i + 1 < text.length) {
56
+ result += text[++i];
57
+ } else if (char === quote) {
58
+ quote = null;
59
+ }
60
+ continue;
61
+ }
62
+ if (urlDepth > 0) {
63
+ if (char === "(") urlDepth++;
64
+ else if (char === ")") urlDepth--;
65
+ result += char;
66
+ continue;
67
+ }
68
+ if (char === '"' || char === "'") {
69
+ quote = char;
70
+ result += char;
71
+ continue;
72
+ }
73
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
74
+ urlDepth = 1;
75
+ result += char;
76
+ continue;
77
+ }
78
+ if (char === "/" && text[i + 1] === "*") {
79
+ const end = text.indexOf("*/", i + 2);
80
+ if (end === -1) {
81
+ result += char;
82
+ continue;
83
+ }
84
+ i = end + 1;
85
+ continue;
86
+ }
87
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
88
+ const nl = text.indexOf("\n", i);
89
+ i = nl === -1 ? text.length - 1 : nl - 1;
90
+ continue;
91
+ }
92
+ result += char;
93
+ }
94
+ return result;
95
+ }
47
96
  function extractBlock(text, start) {
48
97
  let depth = 1;
49
98
  let quote = null;
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
64
113
  return text.slice(start, depth === 0 ? i - 1 : i);
65
114
  }
66
115
  function parseVarNames(css, selectors) {
67
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
116
+ const stripped = stripComments(css);
68
117
  const names = /* @__PURE__ */ new Set();
69
118
  const allSelectors = [":root", ...selectors ?? []];
70
119
  for (const sel of allSelectors) {
71
120
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
72
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
121
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
73
122
  let match;
74
123
  while (match = openRegex.exec(stripped)) {
75
124
  const start = match.index + match[0].length;
package/dist/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-EGDCGDEQ.js";
4
- import "./chunk-CHF2ERWU.js";
3
+ } from "./chunk-DWNF2MKL.js";
4
+ import "./chunk-2GVOUCFD.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  var esbuild_default = unplugin_default.esbuild;
package/dist/index.cjs CHANGED
@@ -46,6 +46,55 @@ 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 stripComments(text) {
50
+ let result = "";
51
+ let quote = null;
52
+ let urlDepth = 0;
53
+ for (let i = 0; i < text.length; i++) {
54
+ const char = text[i];
55
+ if (quote) {
56
+ result += char;
57
+ if (char === "\\" && i + 1 < text.length) {
58
+ result += text[++i];
59
+ } else if (char === quote) {
60
+ quote = null;
61
+ }
62
+ continue;
63
+ }
64
+ if (urlDepth > 0) {
65
+ if (char === "(") urlDepth++;
66
+ else if (char === ")") urlDepth--;
67
+ result += char;
68
+ continue;
69
+ }
70
+ if (char === '"' || char === "'") {
71
+ quote = char;
72
+ result += char;
73
+ continue;
74
+ }
75
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
76
+ urlDepth = 1;
77
+ result += char;
78
+ continue;
79
+ }
80
+ if (char === "/" && text[i + 1] === "*") {
81
+ const end = text.indexOf("*/", i + 2);
82
+ if (end === -1) {
83
+ result += char;
84
+ continue;
85
+ }
86
+ i = end + 1;
87
+ continue;
88
+ }
89
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
90
+ const nl = text.indexOf("\n", i);
91
+ i = nl === -1 ? text.length - 1 : nl - 1;
92
+ continue;
93
+ }
94
+ result += char;
95
+ }
96
+ return result;
97
+ }
49
98
  function extractBlock(text, start) {
50
99
  let depth = 1;
51
100
  let quote = null;
@@ -66,12 +115,12 @@ function extractBlock(text, start) {
66
115
  return text.slice(start, depth === 0 ? i - 1 : i);
67
116
  }
68
117
  function parseVarNames(css, selectors) {
69
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
118
+ const stripped = stripComments(css);
70
119
  const names = /* @__PURE__ */ new Set();
71
120
  const allSelectors = [":root", ...selectors ?? []];
72
121
  for (const sel of allSelectors) {
73
122
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
74
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
123
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
75
124
  let match;
76
125
  while (match = openRegex.exec(stripped)) {
77
126
  const start = match.index + match[0].length;
@@ -190,9 +239,10 @@ async function generate(options) {
190
239
  }
191
240
  const outPath = (0, import_node_path.resolve)(options.output);
192
241
  await (0, import_promises2.mkdir)((0, import_node_path.dirname)(outPath), { recursive: true });
193
- if (options.output.endsWith(".js")) {
242
+ const jsExtMatch = /\.(m|c)?js$/.exec(options.output);
243
+ if (jsExtMatch) {
194
244
  await (0, import_promises2.writeFile)(outPath, generateJs(names, options.prefix, options.naming), "utf8");
195
- const dtsPath = outPath.replace(/\.js$/, ".d.ts");
245
+ const dtsPath = outPath.slice(0, -jsExtMatch[0].length) + ".d.ts";
196
246
  await (0, import_promises2.writeFile)(dtsPath, generateDeclaration(names, options.prefix, options.naming), "utf8");
197
247
  } else {
198
248
  await (0, import_promises2.writeFile)(outPath, generateCode(names, options.prefix, options.naming), "utf8");
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  generate
3
- } from "./chunk-IJOMZOB4.js";
3
+ } from "./chunk-KETRI7BY.js";
4
4
  import {
5
5
  generateCode,
6
6
  generateDeclaration,
7
7
  generateJs,
8
8
  parseVarNames,
9
9
  scanVarNames
10
- } from "./chunk-CHF2ERWU.js";
10
+ } from "./chunk-2GVOUCFD.js";
11
11
  export {
12
12
  generate,
13
13
  generateCode,
package/dist/rollup.cjs CHANGED
@@ -44,6 +44,55 @@ 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 stripComments(text) {
48
+ let result = "";
49
+ let quote = null;
50
+ let urlDepth = 0;
51
+ for (let i = 0; i < text.length; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ result += char;
55
+ if (char === "\\" && i + 1 < text.length) {
56
+ result += text[++i];
57
+ } else if (char === quote) {
58
+ quote = null;
59
+ }
60
+ continue;
61
+ }
62
+ if (urlDepth > 0) {
63
+ if (char === "(") urlDepth++;
64
+ else if (char === ")") urlDepth--;
65
+ result += char;
66
+ continue;
67
+ }
68
+ if (char === '"' || char === "'") {
69
+ quote = char;
70
+ result += char;
71
+ continue;
72
+ }
73
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
74
+ urlDepth = 1;
75
+ result += char;
76
+ continue;
77
+ }
78
+ if (char === "/" && text[i + 1] === "*") {
79
+ const end = text.indexOf("*/", i + 2);
80
+ if (end === -1) {
81
+ result += char;
82
+ continue;
83
+ }
84
+ i = end + 1;
85
+ continue;
86
+ }
87
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
88
+ const nl = text.indexOf("\n", i);
89
+ i = nl === -1 ? text.length - 1 : nl - 1;
90
+ continue;
91
+ }
92
+ result += char;
93
+ }
94
+ return result;
95
+ }
47
96
  function extractBlock(text, start) {
48
97
  let depth = 1;
49
98
  let quote = null;
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
64
113
  return text.slice(start, depth === 0 ? i - 1 : i);
65
114
  }
66
115
  function parseVarNames(css, selectors) {
67
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
116
+ const stripped = stripComments(css);
68
117
  const names = /* @__PURE__ */ new Set();
69
118
  const allSelectors = [":root", ...selectors ?? []];
70
119
  for (const sel of allSelectors) {
71
120
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
72
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
121
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
73
122
  let match;
74
123
  while (match = openRegex.exec(stripped)) {
75
124
  const start = match.index + match[0].length;
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-EGDCGDEQ.js";
4
- import "./chunk-CHF2ERWU.js";
3
+ } from "./chunk-DWNF2MKL.js";
4
+ import "./chunk-2GVOUCFD.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  var rollup_default = unplugin_default.rollup;
package/dist/unplugin.cjs CHANGED
@@ -42,6 +42,55 @@ 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 stripComments(text) {
46
+ let result = "";
47
+ let quote = null;
48
+ let urlDepth = 0;
49
+ for (let i = 0; i < text.length; i++) {
50
+ const char = text[i];
51
+ if (quote) {
52
+ result += char;
53
+ if (char === "\\" && i + 1 < text.length) {
54
+ result += text[++i];
55
+ } else if (char === quote) {
56
+ quote = null;
57
+ }
58
+ continue;
59
+ }
60
+ if (urlDepth > 0) {
61
+ if (char === "(") urlDepth++;
62
+ else if (char === ")") urlDepth--;
63
+ result += char;
64
+ continue;
65
+ }
66
+ if (char === '"' || char === "'") {
67
+ quote = char;
68
+ result += char;
69
+ continue;
70
+ }
71
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
72
+ urlDepth = 1;
73
+ result += char;
74
+ continue;
75
+ }
76
+ if (char === "/" && text[i + 1] === "*") {
77
+ const end = text.indexOf("*/", i + 2);
78
+ if (end === -1) {
79
+ result += char;
80
+ continue;
81
+ }
82
+ i = end + 1;
83
+ continue;
84
+ }
85
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
86
+ const nl = text.indexOf("\n", i);
87
+ i = nl === -1 ? text.length - 1 : nl - 1;
88
+ continue;
89
+ }
90
+ result += char;
91
+ }
92
+ return result;
93
+ }
45
94
  function extractBlock(text, start) {
46
95
  let depth = 1;
47
96
  let quote = null;
@@ -62,12 +111,12 @@ function extractBlock(text, start) {
62
111
  return text.slice(start, depth === 0 ? i - 1 : i);
63
112
  }
64
113
  function parseVarNames(css, selectors) {
65
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
114
+ const stripped = stripComments(css);
66
115
  const names = /* @__PURE__ */ new Set();
67
116
  const allSelectors = [":root", ...selectors ?? []];
68
117
  for (const sel of allSelectors) {
69
118
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
70
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
119
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
71
120
  let match;
72
121
  while (match = openRegex.exec(stripped)) {
73
122
  const start = match.index + match[0].length;
package/dist/unplugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-EGDCGDEQ.js";
4
- import "./chunk-CHF2ERWU.js";
3
+ } from "./chunk-DWNF2MKL.js";
4
+ import "./chunk-2GVOUCFD.js";
5
5
  export {
6
6
  unplugin_default as default
7
7
  };
package/dist/vite.cjs CHANGED
@@ -44,6 +44,55 @@ 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 stripComments(text) {
48
+ let result = "";
49
+ let quote = null;
50
+ let urlDepth = 0;
51
+ for (let i = 0; i < text.length; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ result += char;
55
+ if (char === "\\" && i + 1 < text.length) {
56
+ result += text[++i];
57
+ } else if (char === quote) {
58
+ quote = null;
59
+ }
60
+ continue;
61
+ }
62
+ if (urlDepth > 0) {
63
+ if (char === "(") urlDepth++;
64
+ else if (char === ")") urlDepth--;
65
+ result += char;
66
+ continue;
67
+ }
68
+ if (char === '"' || char === "'") {
69
+ quote = char;
70
+ result += char;
71
+ continue;
72
+ }
73
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
74
+ urlDepth = 1;
75
+ result += char;
76
+ continue;
77
+ }
78
+ if (char === "/" && text[i + 1] === "*") {
79
+ const end = text.indexOf("*/", i + 2);
80
+ if (end === -1) {
81
+ result += char;
82
+ continue;
83
+ }
84
+ i = end + 1;
85
+ continue;
86
+ }
87
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
88
+ const nl = text.indexOf("\n", i);
89
+ i = nl === -1 ? text.length - 1 : nl - 1;
90
+ continue;
91
+ }
92
+ result += char;
93
+ }
94
+ return result;
95
+ }
47
96
  function extractBlock(text, start) {
48
97
  let depth = 1;
49
98
  let quote = null;
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
64
113
  return text.slice(start, depth === 0 ? i - 1 : i);
65
114
  }
66
115
  function parseVarNames(css, selectors) {
67
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
116
+ const stripped = stripComments(css);
68
117
  const names = /* @__PURE__ */ new Set();
69
118
  const allSelectors = [":root", ...selectors ?? []];
70
119
  for (const sel of allSelectors) {
71
120
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
72
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
121
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
73
122
  let match;
74
123
  while (match = openRegex.exec(stripped)) {
75
124
  const start = match.index + match[0].length;
package/dist/vite.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-EGDCGDEQ.js";
4
- import "./chunk-CHF2ERWU.js";
3
+ } from "./chunk-DWNF2MKL.js";
4
+ import "./chunk-2GVOUCFD.js";
5
5
 
6
6
  // src/vite.ts
7
7
  var vite_default = unplugin_default.vite;
package/dist/webpack.cjs CHANGED
@@ -44,6 +44,55 @@ 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 stripComments(text) {
48
+ let result = "";
49
+ let quote = null;
50
+ let urlDepth = 0;
51
+ for (let i = 0; i < text.length; i++) {
52
+ const char = text[i];
53
+ if (quote) {
54
+ result += char;
55
+ if (char === "\\" && i + 1 < text.length) {
56
+ result += text[++i];
57
+ } else if (char === quote) {
58
+ quote = null;
59
+ }
60
+ continue;
61
+ }
62
+ if (urlDepth > 0) {
63
+ if (char === "(") urlDepth++;
64
+ else if (char === ")") urlDepth--;
65
+ result += char;
66
+ continue;
67
+ }
68
+ if (char === '"' || char === "'") {
69
+ quote = char;
70
+ result += char;
71
+ continue;
72
+ }
73
+ if (char === "(" && result.slice(-3).toLowerCase() === "url") {
74
+ urlDepth = 1;
75
+ result += char;
76
+ continue;
77
+ }
78
+ if (char === "/" && text[i + 1] === "*") {
79
+ const end = text.indexOf("*/", i + 2);
80
+ if (end === -1) {
81
+ result += char;
82
+ continue;
83
+ }
84
+ i = end + 1;
85
+ continue;
86
+ }
87
+ if (char === "/" && text[i + 1] === "/" && text[i - 1] !== ":") {
88
+ const nl = text.indexOf("\n", i);
89
+ i = nl === -1 ? text.length - 1 : nl - 1;
90
+ continue;
91
+ }
92
+ result += char;
93
+ }
94
+ return result;
95
+ }
47
96
  function extractBlock(text, start) {
48
97
  let depth = 1;
49
98
  let quote = null;
@@ -64,12 +113,12 @@ function extractBlock(text, start) {
64
113
  return text.slice(start, depth === 0 ? i - 1 : i);
65
114
  }
66
115
  function parseVarNames(css, selectors) {
67
- const stripped = css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(?<!:)\/\/.*$/gm, "");
116
+ const stripped = stripComments(css);
68
117
  const names = /* @__PURE__ */ new Set();
69
118
  const allSelectors = [":root", ...selectors ?? []];
70
119
  for (const sel of allSelectors) {
71
120
  const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
72
- const openRegex = new RegExp(`${escaped}[^{]*\\{`, "g");
121
+ const openRegex = new RegExp(`${escaped}(?![\\w-])[^{]*\\{`, "g");
73
122
  let match;
74
123
  while (match = openRegex.exec(stripped)) {
75
124
  const start = match.index + match[0].length;
package/dist/webpack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unplugin_default
3
- } from "./chunk-EGDCGDEQ.js";
4
- import "./chunk-CHF2ERWU.js";
3
+ } from "./chunk-DWNF2MKL.js";
4
+ import "./chunk-2GVOUCFD.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.11",
3
+ "version": "0.4.12",
4
4
  "description": "Generate TypeScript typed constants from CSS custom properties",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",