@kbach/react 0.6.16 → 0.6.17

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.
@@ -3152,26 +3152,37 @@ function buildColorVarMap(theme, usedCSS) {
3152
3152
  const hexRe = /#[0-9a-fA-F]{3,8}\b/g;
3153
3153
  let hm;
3154
3154
  while ((hm = hexRe.exec(usedCSS)) !== null) usedHexValues.add(hm[0].toLowerCase());
3155
- const map = /* @__PURE__ */ new Map();
3155
+ const replacements = /* @__PURE__ */ new Map();
3156
+ const declarations = /* @__PURE__ */ new Map();
3156
3157
  for (const [name, shades] of Object.entries(theme.colors ?? {})) {
3157
3158
  const entries = typeof shades === "string" ? [[name, shades]] : Object.entries(shades).map(([s, v]) => [`${name}-${s}`, v]);
3158
3159
  for (const [fullName, val] of entries) {
3159
- if (typeof val === "string" && /^#[0-9a-fA-F]{3,8}$/.test(val)) {
3160
- if (usedHexValues.has(val.toLowerCase())) {
3161
- map.set(val, `--color-${fullName}`);
3162
- }
3160
+ if (typeof val !== "string" || !/^#[0-9a-fA-F]{3,8}$/.test(val)) continue;
3161
+ if (usedHexValues.has(val.toLowerCase())) {
3162
+ const varName = `--color-${fullName}`;
3163
+ replacements.set(val, `var(${varName})`);
3164
+ declarations.set(varName, val);
3165
+ }
3166
+ const rgb = parseHexRgb(val);
3167
+ if (!rgb) continue;
3168
+ const triplet = `${rgb[0]},${rgb[1]},${rgb[2]}`;
3169
+ const rgbaPrefix = `rgba(${triplet},`;
3170
+ if (usedCSS.includes(rgbaPrefix)) {
3171
+ const rgbVarName = `--color-${fullName}-rgb`;
3172
+ replacements.set(rgbaPrefix, `rgba(var(${rgbVarName}),`);
3173
+ declarations.set(rgbVarName, triplet);
3163
3174
  }
3164
3175
  }
3165
3176
  }
3166
- return map;
3177
+ return { replacements, declarations };
3167
3178
  }
3168
3179
  function formatKbachCSS(tokenCSS, theme, responsiveRe) {
3169
3180
  const allRaw = [...tokenCSS.values()].filter(Boolean).join("\n");
3170
- const colorVars = buildColorVarMap(theme, allRaw);
3171
- const sortedColorVars = [...colorVars].sort(([a], [b]) => b.length - a.length);
3181
+ const { replacements, declarations } = buildColorVarMap(theme, allRaw);
3182
+ const sortedReplacements = [...replacements].sort(([a], [b]) => b.length - a.length);
3172
3183
  function applyVars(css) {
3173
- for (const [val, varName] of sortedColorVars)
3174
- css = css.split(val).join(`var(${varName})`);
3184
+ for (const [pattern, replacement] of sortedReplacements)
3185
+ css = css.split(pattern).join(replacement);
3175
3186
  return css;
3176
3187
  }
3177
3188
  const groups = new Map(GROUP_ORDER.map((g) => [g, []]));
@@ -3182,9 +3193,9 @@ function formatKbachCSS(tokenCSS, theme, responsiveRe) {
3182
3193
  groups.get(label).push(applyVars(css));
3183
3194
  }
3184
3195
  const out = ["/* Generated by Kbach \u2014 do not edit */"];
3185
- if (colorVars.size > 0) {
3196
+ if (declarations.size > 0) {
3186
3197
  out.push("\n:root {");
3187
- for (const [val, varName] of colorVars) out.push(` ${varName}: ${val};`);
3198
+ for (const [varName, val] of declarations) out.push(` ${varName}: ${val};`);
3188
3199
  out.push("}");
3189
3200
  }
3190
3201
  const globalCSS = buildThemeGlobal(theme);
@@ -3118,26 +3118,37 @@ function buildColorVarMap(theme, usedCSS) {
3118
3118
  const hexRe = /#[0-9a-fA-F]{3,8}\b/g;
3119
3119
  let hm;
3120
3120
  while ((hm = hexRe.exec(usedCSS)) !== null) usedHexValues.add(hm[0].toLowerCase());
3121
- const map = /* @__PURE__ */ new Map();
3121
+ const replacements = /* @__PURE__ */ new Map();
3122
+ const declarations = /* @__PURE__ */ new Map();
3122
3123
  for (const [name, shades] of Object.entries(theme.colors ?? {})) {
3123
3124
  const entries = typeof shades === "string" ? [[name, shades]] : Object.entries(shades).map(([s, v]) => [`${name}-${s}`, v]);
3124
3125
  for (const [fullName, val] of entries) {
3125
- if (typeof val === "string" && /^#[0-9a-fA-F]{3,8}$/.test(val)) {
3126
- if (usedHexValues.has(val.toLowerCase())) {
3127
- map.set(val, `--color-${fullName}`);
3128
- }
3126
+ if (typeof val !== "string" || !/^#[0-9a-fA-F]{3,8}$/.test(val)) continue;
3127
+ if (usedHexValues.has(val.toLowerCase())) {
3128
+ const varName = `--color-${fullName}`;
3129
+ replacements.set(val, `var(${varName})`);
3130
+ declarations.set(varName, val);
3131
+ }
3132
+ const rgb = parseHexRgb(val);
3133
+ if (!rgb) continue;
3134
+ const triplet = `${rgb[0]},${rgb[1]},${rgb[2]}`;
3135
+ const rgbaPrefix = `rgba(${triplet},`;
3136
+ if (usedCSS.includes(rgbaPrefix)) {
3137
+ const rgbVarName = `--color-${fullName}-rgb`;
3138
+ replacements.set(rgbaPrefix, `rgba(var(${rgbVarName}),`);
3139
+ declarations.set(rgbVarName, triplet);
3129
3140
  }
3130
3141
  }
3131
3142
  }
3132
- return map;
3143
+ return { replacements, declarations };
3133
3144
  }
3134
3145
  function formatKbachCSS(tokenCSS, theme, responsiveRe) {
3135
3146
  const allRaw = [...tokenCSS.values()].filter(Boolean).join("\n");
3136
- const colorVars = buildColorVarMap(theme, allRaw);
3137
- const sortedColorVars = [...colorVars].sort(([a], [b]) => b.length - a.length);
3147
+ const { replacements, declarations } = buildColorVarMap(theme, allRaw);
3148
+ const sortedReplacements = [...replacements].sort(([a], [b]) => b.length - a.length);
3138
3149
  function applyVars(css) {
3139
- for (const [val, varName] of sortedColorVars)
3140
- css = css.split(val).join(`var(${varName})`);
3150
+ for (const [pattern, replacement] of sortedReplacements)
3151
+ css = css.split(pattern).join(replacement);
3141
3152
  return css;
3142
3153
  }
3143
3154
  const groups = new Map(GROUP_ORDER.map((g) => [g, []]));
@@ -3148,9 +3159,9 @@ function formatKbachCSS(tokenCSS, theme, responsiveRe) {
3148
3159
  groups.get(label).push(applyVars(css));
3149
3160
  }
3150
3161
  const out = ["/* Generated by Kbach \u2014 do not edit */"];
3151
- if (colorVars.size > 0) {
3162
+ if (declarations.size > 0) {
3152
3163
  out.push("\n:root {");
3153
- for (const [val, varName] of colorVars) out.push(` ${varName}: ${val};`);
3164
+ for (const [varName, val] of declarations) out.push(` ${varName}: ${val};`);
3154
3165
  out.push("}");
3155
3166
  }
3156
3167
  const globalCSS = buildThemeGlobal(theme);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.6.16",
3
+ "version": "0.6.17",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",