rainbowindex 0.3.0 → 0.4.1

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/vite.mjs CHANGED
@@ -1,100 +1,89 @@
1
1
  import {
2
2
  postcss_default
3
- } from "./chunk-AUWGHSTO.mjs";
4
- import "./chunk-AZXWJ625.mjs";
3
+ } from "./chunk-IYIUS7AE.mjs";
4
+ import "./chunk-53WD6U2X.mjs";
5
5
  import {
6
+ isSourceFile
7
+ } from "./chunk-3HRMFZGE.mjs";
8
+ import {
9
+ DIRECTIVE_TYPE_NAMES,
6
10
  expandApplyGroups,
7
11
  findClosingBrace,
8
12
  hasRIActivation,
9
13
  isAtRuleBoundary,
10
- isAtRuleNameChar,
11
- isSourceFile
12
- } from "./chunk-IE6N76PW.mjs";
14
+ isAtRuleNameChar
15
+ } from "./chunk-6GTG5SZJ.mjs";
13
16
  import {
14
17
  devWarn
15
- } from "./chunk-SOMDX7V6.mjs";
18
+ } from "./chunk-KRZL4IDK.mjs";
16
19
 
17
20
  // src/integrations/vite.ts
18
21
  import { existsSync } from "fs";
19
- import { access, readFile, readdir } from "fs/promises";
22
+ import { access, readdir, readFile } from "fs/promises";
20
23
  import { join, relative, resolve } from "path";
21
- var CSS_FILE_RE = /\.(?:module\.)?css$/;
22
- var REMOVAL_BODY_DIRECTIVES = /* @__PURE__ */ new Set([
23
- "color",
24
- "text",
25
- "spacing",
26
- "breakpoint",
27
- "rounded",
28
- "shadow",
29
- "weight",
30
- "ease",
31
- "blur",
32
- "z",
33
- "animate",
34
- "leading",
35
- "tracking",
36
- "opacity",
37
- "duration"
38
- ]);
39
- var KEYWORD_BODY_DIRECTIVES = /* @__PURE__ */ new Set(["fluid"]);
24
+
25
+ // src/directives/postcss-safe.ts
26
+ var BODY_GRAMMAR = {
27
+ color: "removal",
28
+ text: "removal",
29
+ spacing: "removal",
30
+ breakpoint: "removal",
31
+ rounded: "removal",
32
+ shadow: "removal",
33
+ weight: "removal",
34
+ ease: "removal",
35
+ blur: "removal",
36
+ z: "removal",
37
+ animate: "removal",
38
+ leading: "removal",
39
+ tracking: "removal",
40
+ opacity: "removal",
41
+ duration: "removal",
42
+ fluid: "keyword",
43
+ font: "raw",
44
+ preflight: "raw",
45
+ utility: "raw",
46
+ custom: "raw",
47
+ source: "raw",
48
+ layer: "raw",
49
+ register: "raw"
50
+ };
51
+ var REMOVAL_BODY_DIRECTIVES = new Set(
52
+ DIRECTIVE_TYPE_NAMES.filter((n) => BODY_GRAMMAR[n] === "removal")
53
+ );
54
+ var KEYWORD_BODY_DIRECTIVES = new Set(
55
+ DIRECTIVE_TYPE_NAMES.filter((n) => BODY_GRAMMAR[n] === "keyword")
56
+ );
40
57
  var REMOVAL_RE = /!([\w][\w-]*)\s*;/g;
41
58
  var FLUID_KEYWORD_RE = /\b(no-parabolic|parabolic|no-shift|shift)\s*;?/g;
42
59
  var COLOR_FLAG_RE = /(?<=[{;\s]|^)(inline|no-parabolic|parabolic)\s*(?:;|(?=}))/g;
43
- function rewriteTopLevel(body, rewrite) {
44
- if (!body.includes("{")) return rewrite(body);
60
+ function mapTopLevelSpans(body, mapOutside, mapBlock) {
61
+ let brace = body.indexOf("{");
62
+ if (brace === -1) return mapOutside(body);
45
63
  let out = "";
46
64
  let segStart = 0;
47
- let depth = 0;
48
- for (let i = 0; i < body.length; i++) {
49
- const ch = body[i];
50
- if (ch === "{") {
51
- if (depth === 0) {
52
- out += rewrite(body.slice(segStart, i));
53
- segStart = i;
54
- }
55
- depth++;
56
- } else if (ch === "}") {
57
- if (depth > 0) depth--;
58
- if (depth === 0) {
59
- out += body.slice(segStart, i + 1);
60
- segStart = i + 1;
61
- }
62
- }
65
+ while (brace !== -1) {
66
+ out += mapOutside(body.slice(segStart, brace));
67
+ const close = findClosingBrace(body, brace);
68
+ if (close === -1) return out + body.slice(brace);
69
+ out += `{${mapBlock(body.slice(brace + 1, close))}}`;
70
+ segStart = close + 1;
71
+ brace = body.indexOf("{", segStart);
63
72
  }
64
- out += depth === 0 ? rewrite(body.slice(segStart)) : body.slice(segStart);
65
- return out;
73
+ return out + mapOutside(body.slice(segStart));
66
74
  }
75
+ var keepSpan = (span) => span;
67
76
  function rewriteColorOptionFlag(_match, keyword) {
68
77
  if (keyword === "inline") return "--ri-inline: true;";
69
78
  const negated = keyword.startsWith("no-");
70
79
  return `--ri-${negated ? keyword.slice(3) : keyword}: ${negated ? "false" : "true"};`;
71
80
  }
72
81
  function rewriteColorOptionFlags(body) {
73
- if (!body.includes("{")) return body;
74
- let out = "";
75
- let segStart = 0;
76
- let depth = 0;
77
- let blockStart = -1;
78
- for (let i = 0; i < body.length; i++) {
79
- const ch = body[i];
80
- if (ch === "{") {
81
- if (depth === 0) {
82
- out += body.slice(segStart, i + 1);
83
- blockStart = i + 1;
84
- }
85
- depth++;
86
- } else if (ch === "}") {
87
- if (depth > 0) depth--;
88
- if (depth === 0 && blockStart !== -1) {
89
- out += body.slice(blockStart, i).replace(COLOR_FLAG_RE, rewriteColorOptionFlag);
90
- out += "}";
91
- segStart = i + 1;
92
- blockStart = -1;
93
- }
94
- }
95
- }
96
- out += body.slice(segStart);
97
- return out;
82
+ return mapTopLevelSpans(
83
+ body,
84
+ keepSpan,
85
+ (interior) => interior.replace(COLOR_FLAG_RE, rewriteColorOptionFlag)
86
+ );
98
87
  }
99
88
  function rewriteDirectiveBodies(code) {
100
89
  let out = "";
@@ -129,17 +118,21 @@ function rewriteDirectiveBodies(code) {
129
118
  const close = findClosingBrace(code, braceIdx);
130
119
  const bodyStart = braceIdx + 1;
131
120
  const bodyEnd = close === -1 ? code.length : close;
132
- let rewritten = rewriteTopLevel(code.slice(bodyStart, bodyEnd), (span) => {
133
- let s = span;
134
- if (removals) s = s.replace(REMOVAL_RE, "--ri-rm: $1;");
135
- if (keywords) {
136
- s = s.replace(FLUID_KEYWORD_RE, (_, kw) => {
137
- const negated = kw.startsWith("no-");
138
- return `--ri-${negated ? kw.slice(3) : kw}: ${negated ? "false" : "true"};`;
139
- });
140
- }
141
- return s;
142
- });
121
+ let rewritten = mapTopLevelSpans(
122
+ code.slice(bodyStart, bodyEnd),
123
+ (span) => {
124
+ let s = span;
125
+ if (removals) s = s.replace(REMOVAL_RE, "--ri-rm: $1;");
126
+ if (keywords) {
127
+ s = s.replace(FLUID_KEYWORD_RE, (_, kw) => {
128
+ const negated = kw.startsWith("no-");
129
+ return `--ri-${negated ? kw.slice(3) : kw}: ${negated ? "false" : "true"};`;
130
+ });
131
+ }
132
+ return s;
133
+ },
134
+ keepSpan
135
+ );
143
136
  if (name === "color") rewritten = rewriteColorOptionFlags(rewritten);
144
137
  out += code.slice(last, bodyStart) + rewritten;
145
138
  last = bodyEnd;
@@ -148,6 +141,9 @@ function rewriteDirectiveBodies(code) {
148
141
  if (last === 0) return code;
149
142
  return out + code.slice(last);
150
143
  }
144
+
145
+ // src/integrations/vite.ts
146
+ var CSS_FILE_RE = /\.(?:module\.)?css$/;
151
147
  var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist"]);
152
148
  var POSTCSS_CONFIG_FILES = [
153
149
  "postcss.config.js",
@@ -248,11 +244,12 @@ function rainbowindexVite() {
248
244
  }
249
245
  if (!isSourceFile(file)) return;
250
246
  const extraModules = [];
247
+ const hmrModules = new Set(modules);
251
248
  for (const cssFile of riCSSFiles) {
252
249
  const mods = server.moduleGraph.getModulesByFile(cssFile);
253
250
  if (mods) {
254
251
  for (const mod of mods) {
255
- if (!modules.includes(mod)) {
252
+ if (!hmrModules.has(mod)) {
256
253
  extraModules.push(mod);
257
254
  }
258
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rainbowindex",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "CSS-first system for building and maintaining consistent user interfaces",
5
5
  "keywords": [
6
6
  "css",
@@ -97,6 +97,7 @@
97
97
  },
98
98
  "devDependencies": {
99
99
  "@biomejs/biome": "^2.4.16",
100
+ "@capsizecss/metrics": "^4.2.0",
100
101
  "@types/node": "^25.9.1",
101
102
  "@vitest/coverage-v8": "^4.1.0",
102
103
  "postcss": "^8.5.8",