@fakhrirafiki/theme-engine 0.4.5 → 0.4.7

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/index.js CHANGED
@@ -3983,6 +3983,29 @@ function ThemeScript({ presetStorageKey = "theme-preset", defaultPreset }) {
3983
3983
  if (rgb) return toTriplet(rgbToHsl(rgb.r, rgb.g, rgb.b));
3984
3984
  }
3985
3985
 
3986
+ // Any other CSS color (e.g. oklch(...), named colors) -> resolve via computed styles.
3987
+ try {
3988
+ const probe = document.createElement('span');
3989
+ probe.style.color = trimmed;
3990
+ probe.style.position = 'absolute';
3991
+ probe.style.left = '-9999px';
3992
+ probe.style.top = '-9999px';
3993
+ probe.style.visibility = 'hidden';
3994
+ document.documentElement.appendChild(probe);
3995
+ const computed = getComputedStyle(probe).color; // rgb(...) or rgba(...)
3996
+ probe.remove();
3997
+
3998
+ const match = computed && computed.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/i);
3999
+ if (match) {
4000
+ const r = clamp(parseFloat(match[1]) || 0, 0, 255);
4001
+ const g = clamp(parseFloat(match[2]) || 0, 0, 255);
4002
+ const b = clamp(parseFloat(match[3]) || 0, 0, 255);
4003
+ return toTriplet(rgbToHsl(r, g, b));
4004
+ }
4005
+ } catch (e) {
4006
+ // ignore and fall through
4007
+ }
4008
+
3986
4009
  return value;
3987
4010
  }
3988
4011
 
@@ -4255,7 +4278,31 @@ function normalizeColorValueToHslTriplet(value) {
4255
4278
  if (parsedHsl) return formatHSL(parsedHsl, false);
4256
4279
  const parsedRgb = parseHex(trimmed);
4257
4280
  if (parsedRgb) return formatHSL(rgbToHsl(parsedRgb), false);
4258
- return value;
4281
+ if (typeof document !== "undefined") {
4282
+ try {
4283
+ if (trimmed.startsWith("var(")) return trimmed;
4284
+ const probe = document.createElement("span");
4285
+ probe.style.color = trimmed;
4286
+ probe.style.position = "absolute";
4287
+ probe.style.left = "-9999px";
4288
+ probe.style.top = "-9999px";
4289
+ probe.style.visibility = "hidden";
4290
+ document.documentElement.appendChild(probe);
4291
+ const computed = getComputedStyle(probe).color;
4292
+ probe.remove();
4293
+ const match = computed.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);
4294
+ if (match) {
4295
+ const r = Number(match[1]);
4296
+ const g = Number(match[2]);
4297
+ const b = Number(match[3]);
4298
+ if (Number.isFinite(r) && Number.isFinite(g) && Number.isFinite(b)) {
4299
+ return formatHSL(rgbToHsl({ r, g, b }), false);
4300
+ }
4301
+ }
4302
+ } catch {
4303
+ }
4304
+ }
4305
+ return trimmed;
4259
4306
  }
4260
4307
  function ThemeProvider({
4261
4308
  children,
package/dist/index.mjs CHANGED
@@ -3940,6 +3940,29 @@ function ThemeScript({ presetStorageKey = "theme-preset", defaultPreset }) {
3940
3940
  if (rgb) return toTriplet(rgbToHsl(rgb.r, rgb.g, rgb.b));
3941
3941
  }
3942
3942
 
3943
+ // Any other CSS color (e.g. oklch(...), named colors) -> resolve via computed styles.
3944
+ try {
3945
+ const probe = document.createElement('span');
3946
+ probe.style.color = trimmed;
3947
+ probe.style.position = 'absolute';
3948
+ probe.style.left = '-9999px';
3949
+ probe.style.top = '-9999px';
3950
+ probe.style.visibility = 'hidden';
3951
+ document.documentElement.appendChild(probe);
3952
+ const computed = getComputedStyle(probe).color; // rgb(...) or rgba(...)
3953
+ probe.remove();
3954
+
3955
+ const match = computed && computed.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/i);
3956
+ if (match) {
3957
+ const r = clamp(parseFloat(match[1]) || 0, 0, 255);
3958
+ const g = clamp(parseFloat(match[2]) || 0, 0, 255);
3959
+ const b = clamp(parseFloat(match[3]) || 0, 0, 255);
3960
+ return toTriplet(rgbToHsl(r, g, b));
3961
+ }
3962
+ } catch (e) {
3963
+ // ignore and fall through
3964
+ }
3965
+
3943
3966
  return value;
3944
3967
  }
3945
3968
 
@@ -4212,7 +4235,31 @@ function normalizeColorValueToHslTriplet(value) {
4212
4235
  if (parsedHsl) return formatHSL(parsedHsl, false);
4213
4236
  const parsedRgb = parseHex(trimmed);
4214
4237
  if (parsedRgb) return formatHSL(rgbToHsl(parsedRgb), false);
4215
- return value;
4238
+ if (typeof document !== "undefined") {
4239
+ try {
4240
+ if (trimmed.startsWith("var(")) return trimmed;
4241
+ const probe = document.createElement("span");
4242
+ probe.style.color = trimmed;
4243
+ probe.style.position = "absolute";
4244
+ probe.style.left = "-9999px";
4245
+ probe.style.top = "-9999px";
4246
+ probe.style.visibility = "hidden";
4247
+ document.documentElement.appendChild(probe);
4248
+ const computed = getComputedStyle(probe).color;
4249
+ probe.remove();
4250
+ const match = computed.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);
4251
+ if (match) {
4252
+ const r = Number(match[1]);
4253
+ const g = Number(match[2]);
4254
+ const b = Number(match[3]);
4255
+ if (Number.isFinite(r) && Number.isFinite(g) && Number.isFinite(b)) {
4256
+ return formatHSL(rgbToHsl({ r, g, b }), false);
4257
+ }
4258
+ }
4259
+ } catch {
4260
+ }
4261
+ }
4262
+ return trimmed;
4216
4263
  }
4217
4264
  function ThemeProvider({
4218
4265
  children,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fakhrirafiki/theme-engine",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Elegant theming system with smooth transitions, custom presets, semantic accent colors, and complete shadcn/ui support for modern React applications",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",