@cssxio/react-native 0.3.0 → 0.3.3

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/babel.cjs CHANGED
@@ -230,11 +230,40 @@ function nativeValue(value, candidate) {
230
230
  if (/^(?:#|rgb|rgba|hsl|hsla|hwb|transparent|black|white)/.test(important) || important.endsWith("%")) {
231
231
  return important;
232
232
  }
233
+ const oklch = oklchToSrgbHex(important);
234
+ if (oklch) {
235
+ return oklch;
236
+ }
233
237
  if (important.startsWith("var(") || important.startsWith("color-mix(") || important.startsWith("oklch(")) {
234
238
  throw new Error(`CSSX React Native requires "${candidate}" to resolve to a native color or value at build time.`);
235
239
  }
236
240
  return important;
237
241
  }
242
+ function oklchToSrgbHex(value) {
243
+ const match = /^oklch\(([\d.]+)%(?:\s|_)+([\d.]+)(?:\s|_)+([\d.]+)\)$/.exec(value);
244
+ if (!match) {
245
+ return null;
246
+ }
247
+ const lightness = Number(match[1]) / 100;
248
+ const chroma = Number(match[2]);
249
+ const hue = Number(match[3]) * Math.PI / 180;
250
+ const a = chroma * Math.cos(hue);
251
+ const b = chroma * Math.sin(hue);
252
+ const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
253
+ const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
254
+ const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
255
+ const channels = [
256
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
257
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
258
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
259
+ ];
260
+ const hex = channels.map((channel) => {
261
+ const bounded = Math.max(0, Math.min(1, channel));
262
+ const srgb = bounded <= 31308e-7 ? 12.92 * bounded : 1.055 * bounded ** (1 / 2.4) - 0.055;
263
+ return Math.round(srgb * 255).toString(16).padStart(2, "0");
264
+ }).join("");
265
+ return `#${hex}`;
266
+ }
238
267
 
239
268
  // src/babel.ts
240
269
  function cssxReactNativeBabelPlugin(api, options = {}) {
package/dist/babel.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  create
3
- } from "./chunk-P3KGLFG3.js";
3
+ } from "./chunk-7REDTOKV.js";
4
4
 
5
5
  // src/babel.ts
6
6
  function cssxReactNativeBabelPlugin(api, options = {}) {
@@ -251,11 +251,40 @@ function nativeValue(value, candidate) {
251
251
  if (/^(?:#|rgb|rgba|hsl|hsla|hwb|transparent|black|white)/.test(important) || important.endsWith("%")) {
252
252
  return important;
253
253
  }
254
+ const oklch = oklchToSrgbHex(important);
255
+ if (oklch) {
256
+ return oklch;
257
+ }
254
258
  if (important.startsWith("var(") || important.startsWith("color-mix(") || important.startsWith("oklch(")) {
255
259
  throw new Error(`CSSX React Native requires "${candidate}" to resolve to a native color or value at build time.`);
256
260
  }
257
261
  return important;
258
262
  }
263
+ function oklchToSrgbHex(value) {
264
+ const match = /^oklch\(([\d.]+)%(?:\s|_)+([\d.]+)(?:\s|_)+([\d.]+)\)$/.exec(value);
265
+ if (!match) {
266
+ return null;
267
+ }
268
+ const lightness = Number(match[1]) / 100;
269
+ const chroma = Number(match[2]);
270
+ const hue = Number(match[3]) * Math.PI / 180;
271
+ const a = chroma * Math.cos(hue);
272
+ const b = chroma * Math.sin(hue);
273
+ const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
274
+ const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
275
+ const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
276
+ const channels = [
277
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
278
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
279
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
280
+ ];
281
+ const hex = channels.map((channel) => {
282
+ const bounded = Math.max(0, Math.min(1, channel));
283
+ const srgb = bounded <= 31308e-7 ? 12.92 * bounded : 1.055 * bounded ** (1 / 2.4) - 0.055;
284
+ return Math.round(srgb * 255).toString(16).padStart(2, "0");
285
+ }).join("");
286
+ return `#${hex}`;
287
+ }
259
288
 
260
289
  export {
261
290
  create,
package/dist/index.cjs CHANGED
@@ -277,11 +277,40 @@ function nativeValue(value, candidate) {
277
277
  if (/^(?:#|rgb|rgba|hsl|hsla|hwb|transparent|black|white)/.test(important) || important.endsWith("%")) {
278
278
  return important;
279
279
  }
280
+ const oklch = oklchToSrgbHex(important);
281
+ if (oklch) {
282
+ return oklch;
283
+ }
280
284
  if (important.startsWith("var(") || important.startsWith("color-mix(") || important.startsWith("oklch(")) {
281
285
  throw new Error(`CSSX React Native requires "${candidate}" to resolve to a native color or value at build time.`);
282
286
  }
283
287
  return important;
284
288
  }
289
+ function oklchToSrgbHex(value) {
290
+ const match = /^oklch\(([\d.]+)%(?:\s|_)+([\d.]+)(?:\s|_)+([\d.]+)\)$/.exec(value);
291
+ if (!match) {
292
+ return null;
293
+ }
294
+ const lightness = Number(match[1]) / 100;
295
+ const chroma = Number(match[2]);
296
+ const hue = Number(match[3]) * Math.PI / 180;
297
+ const a = chroma * Math.cos(hue);
298
+ const b = chroma * Math.sin(hue);
299
+ const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
300
+ const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
301
+ const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
302
+ const channels = [
303
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
304
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
305
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
306
+ ];
307
+ const hex = channels.map((channel) => {
308
+ const bounded = Math.max(0, Math.min(1, channel));
309
+ const srgb = bounded <= 31308e-7 ? 12.92 * bounded : 1.055 * bounded ** (1 / 2.4) - 0.055;
310
+ return Math.round(srgb * 255).toString(16).padStart(2, "0");
311
+ }).join("");
312
+ return `#${hex}`;
313
+ }
285
314
  // Annotate the CommonJS export names for ESM import in node:
286
315
  0 && (module.exports = {
287
316
  create,
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  create,
3
3
  props,
4
4
  sx
5
- } from "./chunk-P3KGLFG3.js";
5
+ } from "./chunk-7REDTOKV.js";
6
6
  export {
7
7
  create,
8
8
  props,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cssxio/react-native",
3
- "version": "0.3.0",
3
+ "version": "0.3.3",
4
4
  "description": "CSSX utility styling runtime and compiler transform for React Native and Expo.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "sideEffects": false,
31
31
  "dependencies": {
32
- "@cssxio/compiler": "^0.2.0"
32
+ "@cssxio/compiler": "^0.5.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@babel/core": "^7.28.0"