@ng-native/fabric 0.4.0 → 0.5.0

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/color-mix.js CHANGED
@@ -11,7 +11,7 @@
11
11
  * convert a literal colour at build time, copied here because the engine cannot depend on the
12
12
  * build step; the tests hold the two to the same answers.
13
13
  */
14
- import { parseColor } from "./transition.js";
14
+ import { hslToSrgb, hwbToSrgb, parseColor } from "./transition.js";
15
15
  export const MIX_SPACES = new Set([
16
16
  'srgb',
17
17
  'oklab',
@@ -112,25 +112,10 @@ function srgbToHsl([r, g, b]) {
112
112
  : ((r - g) / d + 4) * 60;
113
113
  return [h, s, l];
114
114
  }
115
- function hslToSrgb([h, s, l]) {
116
- const hue = Number.isFinite(h) ? ((h % 360) + 360) % 360 : 0;
117
- const f = (n) => {
118
- const k = (n + hue / 30) % 12;
119
- return l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1));
120
- };
121
- return [f(0), f(8), f(4)];
122
- }
123
115
  function srgbToHwb(rgb) {
124
116
  const [h] = srgbToHsl(rgb);
125
117
  return [h, Math.min(...rgb), 1 - Math.max(...rgb)];
126
118
  }
127
- function hwbToSrgb([h, w, b]) {
128
- if (w + b >= 1) {
129
- const grey = w / (w + b);
130
- return [grey, grey, grey];
131
- }
132
- return hslToSrgb([h, 1, 0.5]).map((c) => c * (1 - w - b) + w);
133
- }
134
119
  /** Where the hue sits in each space's coordinates, if it has one. */
135
120
  const HUE_INDEX = { oklch: 2, lch: 2, hsl: 0, hwb: 0 };
136
121
  /** An sRGB colour, channels 0 to 1, in the space's own coordinates. */
@@ -1 +1 @@
1
- {"version":3,"file":"color-mix.js","sourceRoot":"","sources":["../src/color-mix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,MAAM,CAAC,MAAM,UAAU,GAAwB,IAAI,GAAG,C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,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAChC,IAAI,CAAC,KAAK,KAAK;YAAE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC;QACnF,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC5C,CAAC,CAAW,CAAC;IACb,IAAI,KAAK,KAAK,SAAS;QAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAE,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IAC5E,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * `color-mix()` worked out on device, for a mix with a token in it.\n *\n * The compiler folds a mix of literal colours at build time (lightningcss does the arithmetic); a\n * mix with a `var()` in it can only be done once the token is known, so it is done here, with CSS\n * Color 4 and 5's own arithmetic: each colour converted into the named space, premultiplied by its\n * alpha, interpolated (a hue the shorter way round), and brought back to the sRGB native paints,\n * inside its gamut by CSS Color 4's chroma reduction rather than a clip.\n *\n * The matrices and the gamut mapping are the ones `@ng-native/metro`'s `color-spaces.cjs` uses to\n * convert a literal colour at build time, copied here because the engine cannot depend on the\n * build step; the tests hold the two to the same answers.\n */\nimport { parseColor } from './transition.ts';\n\n/** The spaces a mix is worked out in: every one the compiler also folds a literal mix in. */\nexport type MixSpace = 'srgb' | 'oklab' | 'oklch' | 'lab' | 'lch' | 'hsl' | 'hwb';\n\nexport const MIX_SPACES: ReadonlySet<string> = new Set<MixSpace>([\n 'srgb',\n 'oklab',\n 'oklch',\n 'lab',\n 'lch',\n 'hsl',\n 'hwb',\n]);\n\nexport type HueMethod = 'shorter' | 'longer' | 'increasing' | 'decreasing';\n\nexport type Vector = [number, number, number];\n\nconst times = (m: readonly Vector[], [x, y, z]: Vector): Vector =>\n m.map(([a, b, c]) => a * x + b * y + c * z) as Vector;\n\nconst OKLAB_TO_LMS: Vector[] = [\n [1.0, 0.3963377773761749, 0.2158037573099136],\n [1.0, -0.1055613458156586, -0.0638541728258133],\n [1.0, -0.0894841775298119, -1.2914855480194092],\n];\nconst LMS_TO_XYZ: Vector[] = [\n [1.2268798758459243, -0.5578149944602171, 0.2813910456659647],\n [-0.0405757452148008, 1.112286803280317, -0.0717110580655164],\n [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816],\n];\nconst XYZ_TO_LMS: Vector[] = [\n [0.819022437996703, 0.3619062600528904, -0.1288737815209879],\n [0.0329836539323885, 0.9292868615863434, 0.0361446663506424],\n [0.0481771893596242, 0.2642395317527308, 0.6335478284694309],\n];\nconst LMS_TO_OKLAB: Vector[] = [\n [0.210454268309314, 0.7936177747023054, -0.0040720430116193],\n [1.9779985324311684, -2.4285922420485799, 0.450593709617411],\n [0.0259040424655478, 0.7827717124575296, -0.8086757549230774],\n];\nconst XYZ_TO_LINEAR_SRGB: Vector[] = [\n [3.2409699419045226, -1.537383177570094, -0.4986107602930034],\n [-0.9692436362808796, 1.8759675015077202, 0.04155505740717559],\n [0.05563007969699366, -0.20397695888897652, 1.0569715142428786],\n];\nconst LINEAR_SRGB_TO_XYZ: Vector[] = [\n [0.41239079926595934, 0.357584339383878, 0.1804807884018343],\n [0.21263900587151027, 0.715168678767756, 0.07219231536073371],\n [0.01933081871559182, 0.11919477979462598, 0.9505321522496607],\n];\n/** Bradford chromatic adaptation between `lab()`'s D50 white and sRGB's D65. */\nconst D50_TO_D65: Vector[] = [\n [0.955473421488075, -0.02309845494876471, 0.06325924320057072],\n [-0.0283697093338637, 1.0099953980813041, 0.021041441191917323],\n [0.012314014864481998, -0.020507649298898964, 1.330365926242124],\n];\nconst D65_TO_D50: Vector[] = [\n [1.0479298208405488, 0.022946793341019088, -0.05019222954313557],\n [0.029627815688159344, 0.990434484573249, -0.01707382502938514],\n [-0.009243058152591178, 0.015055144896577895, 0.7518742899580008],\n];\nconst D50_WHITE: Vector = [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585];\n\nconst encode = (c: number) =>\n Math.sign(c) * (Math.abs(c) > 0.0031308 ? 1.055 * Math.abs(c) ** (1 / 2.4) - 0.055 : 12.92 * c);\nconst decode = (c: number) =>\n Math.sign(c) * (Math.abs(c) > 0.04045 ? ((Math.abs(c) + 0.055) / 1.055) ** 2.4 : c / 12.92);\n\nconst srgbToXyz = (rgb: Vector) => times(LINEAR_SRGB_TO_XYZ, rgb.map(decode) as Vector);\nconst xyzToSrgb = (xyz: Vector) => times(XYZ_TO_LINEAR_SRGB, xyz).map(encode) as Vector;\nconst xyzToOklab = (xyz: Vector) =>\n times(LMS_TO_OKLAB, times(XYZ_TO_LMS, xyz).map(Math.cbrt) as Vector);\nconst oklabToXyz = (lab: Vector) =>\n times(LMS_TO_XYZ, times(OKLAB_TO_LMS, lab).map((c) => c ** 3) as Vector);\n\nconst KAPPA = 24389 / 27;\nconst EPSILON = 216 / 24389;\n\nfunction xyzToLab(xyz: Vector): Vector {\n const [x, y, z] = times(D65_TO_D50, xyz).map((c, i) => c / D50_WHITE[i]!);\n const f = (c: number) => (c > EPSILON ? Math.cbrt(c) : (KAPPA * c + 16) / 116);\n const [fx, fy, fz] = [f(x!), f(y!), f(z!)];\n return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];\n}\n\nfunction labToXyz([l, a, b]: Vector): Vector {\n const fy = (l + 16) / 116;\n const fx = a / 500 + fy;\n const fz = fy - b / 200;\n const x = fx ** 3 > EPSILON ? fx ** 3 : (116 * fx - 16) / KAPPA;\n const y = l > KAPPA * EPSILON ? fy ** 3 : l / KAPPA;\n const z = fz ** 3 > EPSILON ? fz ** 3 : (116 * fz - 16) / KAPPA;\n return times(D50_TO_D65, [x, y, z].map((c, i) => c * D50_WHITE[i]!) as Vector);\n}\n\n/** Lightness, chroma and hue in degrees, from the rectangular form, and back. */\nconst polar = ([l, a, b]: Vector): Vector => {\n const hue = (Math.atan2(b, a) * 180) / Math.PI;\n return [l, Math.hypot(a, b), hue < 0 ? hue + 360 : hue];\n};\nconst rectangular = ([l, c, h]: Vector): Vector => [\n l,\n c * Math.cos((h * Math.PI) / 180),\n c * Math.sin((h * Math.PI) / 180),\n];\n\nfunction srgbToHsl([r, g, b]: Vector): Vector {\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const l = (max + min) / 2;\n const d = max - min;\n if (d === 0) return [NaN, 0, l];\n const s = l === 0 || l === 1 ? 0 : (max - l) / Math.min(l, 1 - l);\n const h =\n max === r\n ? ((g - b) / d + (g < b ? 6 : 0)) * 60\n : max === g\n ? ((b - r) / d + 2) * 60\n : ((r - g) / d + 4) * 60;\n return [h, s, l];\n}\n\nfunction hslToSrgb([h, s, l]: Vector): Vector {\n const hue = Number.isFinite(h) ? ((h % 360) + 360) % 360 : 0;\n const f = (n: number) => {\n const k = (n + hue / 30) % 12;\n return l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1));\n };\n return [f(0), f(8), f(4)];\n}\n\nfunction srgbToHwb(rgb: Vector): Vector {\n const [h] = srgbToHsl(rgb);\n return [h, Math.min(...rgb), 1 - Math.max(...rgb)];\n}\n\nfunction hwbToSrgb([h, w, b]: Vector): Vector {\n if (w + b >= 1) {\n const grey = w / (w + b);\n return [grey, grey, grey];\n }\n return hslToSrgb([h, 1, 0.5]).map((c) => c * (1 - w - b) + w) as Vector;\n}\n\n/** Where the hue sits in each space's coordinates, if it has one. */\nconst HUE_INDEX: Partial<Record<MixSpace, number>> = { oklch: 2, lch: 2, hsl: 0, hwb: 0 };\n\n/** An sRGB colour, channels 0 to 1, in the space's own coordinates. */\nexport function into(space: MixSpace, rgb: Vector): Vector {\n switch (space) {\n case 'srgb':\n return rgb;\n case 'oklab':\n return xyzToOklab(srgbToXyz(rgb));\n case 'oklch':\n return powerless(polar(xyzToOklab(srgbToXyz(rgb))), 0.000004);\n case 'lab':\n return xyzToLab(srgbToXyz(rgb));\n case 'lch':\n return powerless(polar(xyzToLab(srgbToXyz(rgb))), 0.0015);\n case 'hsl':\n return srgbToHsl(rgb);\n case 'hwb':\n return srgbToHwb(rgb);\n }\n}\n\n/** A hue that does not matter, for a colour with no chroma to speak of, is missing, as CSS says. */\nconst powerless = ([l, c, h]: Vector, threshold: number): Vector => [\n l,\n c,\n c <= threshold ? NaN : h,\n];\n\n/** Back to sRGB, 0 to 1, brought inside the gamut where the space reaches past it. */\nexport function outOf(space: MixSpace, coords: Vector): Vector {\n const finite = coords.map((c) => (Number.isFinite(c) ? c : 0)) as Vector;\n switch (space) {\n case 'srgb':\n return clip(finite);\n case 'oklab':\n return gamutMap(finite);\n case 'oklch':\n return gamutMap(rectangular(finite));\n case 'lab':\n return gamutMap(xyzToOklab(labToXyz(finite)));\n case 'lch':\n return gamutMap(xyzToOklab(labToXyz(rectangular(finite))));\n case 'hsl':\n return clip(hslToSrgb(finite));\n case 'hwb':\n return clip(hwbToSrgb(finite));\n }\n}\n\nconst clip = (rgb: Vector) => rgb.map((c) => Math.min(1, Math.max(0, c))) as Vector;\nconst inGamut = (rgb: Vector) => rgb.every((c) => c >= -1e-6 && c <= 1 + 1e-6);\nconst deltaEOK = (a: Vector, b: Vector) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);\n\n/** CSS Color 4 section 13.2.2: reduce OKLCh chroma until clipping no longer shows. */\nfunction gamutMap(oklab: Vector): Vector {\n const origin = polar(oklab);\n if (origin[0] >= 1) return [1, 1, 1];\n if (origin[0] <= 0) return [0, 0, 0];\n const srgbOf = (lch: Vector) => xyzToSrgb(oklabToXyz(rectangular(lch)));\n const rgb = srgbOf(origin);\n if (inGamut(rgb)) return clip(rgb);\n\n const JND = 0.02;\n const EPS = 0.0001;\n let clipped = clip(rgb);\n if (deltaEOK(xyzToOklab(srgbToXyz(clipped)), oklab) < JND) return clipped;\n let min = 0;\n let max = origin[1];\n let minInGamut = true;\n while (max - min > EPS) {\n const chroma = (min + max) / 2;\n const current: Vector = [origin[0], chroma, origin[2]];\n const converted = srgbOf(current);\n if (minInGamut && inGamut(converted)) {\n min = chroma;\n continue;\n }\n clipped = clip(converted);\n const error = deltaEOK(xyzToOklab(srgbToXyz(clipped)), rectangular(current));\n if (error < JND) {\n if (JND - error < EPS) return clipped;\n minInGamut = false;\n min = chroma;\n } else {\n max = chroma;\n }\n }\n return clipped;\n}\n\n/** Two hues, one moved by whole turns so that interpolating between them goes the way asked. */\nfunction fixHues(a: number, b: number, method: HueMethod): [number, number] {\n const delta = b - a;\n const lift = HUE_LIFTS[method](delta);\n return lift === 'a' ? [a + 360, b] : lift === 'b' ? [a, b + 360] : [a, b];\n}\n\n/** For each method, which of the two hues takes a whole turn more, given how far apart they are. */\nconst HUE_LIFTS: Record<HueMethod, (delta: number) => 'a' | 'b' | null> = {\n shorter: (delta) => (delta > 180 ? 'a' : delta < -180 ? 'b' : null),\n longer: (delta) => (delta > 0 && delta < 180 ? 'a' : delta > -180 && delta <= 0 ? 'b' : null),\n increasing: (delta) => (delta < 0 ? 'b' : null),\n decreasing: (delta) => (delta > 0 ? 'a' : null),\n};\n\n/** A colour's channels, 0 to 255 and unrounded, and its alpha: what one mix hands another. */\nexport type Rgba = readonly [r: number, g: number, b: number, alpha: number];\n\n/**\n * One side of a mix: a colour as native paints it, or the unrounded channels of another mix, and\n * the percentage written beside it.\n */\nexport interface MixSide {\n readonly colour: string | Rgba;\n readonly percentage?: number;\n}\n\n/**\n * `color-mix(in <space> [<hue> hue], <a> [p%], <b> [q%])`, as the `rgb()` or `rgba()` native\n * reads. Undefined when a side is not a colour it can read - a platform colour, say - or when the\n * two percentages come to zero, which CSS says is not a colour at all.\n */\nexport function mixColours(\n space: MixSpace,\n a: MixSide,\n b: MixSide,\n hue: HueMethod = 'shorter',\n): string | undefined {\n const mixed = mixChannels(space, a, b, hue);\n if (!mixed) return undefined;\n const [r, g, bl] = mixed.map((c) => Math.round(c));\n const opacity = Math.round(mixed[3] * 1000) / 1000;\n return opacity >= 1 ? `rgb(${r}, ${g}, ${bl})` : `rgba(${r}, ${g}, ${bl}, ${opacity})`;\n}\n\n/**\n * The same mix, unrounded, for a mix around it to take as one of its sides: CSS works a nested\n * mix out in full and rounds only the colour at the end.\n */\nexport function mixChannels(\n space: MixSpace,\n a: MixSide,\n b: MixSide,\n hue: HueMethod = 'shorter',\n): Rgba | undefined {\n const first = typeof a.colour === 'string' ? parseColor(a.colour) : a.colour;\n const second = typeof b.colour === 'string' ? parseColor(b.colour) : b.colour;\n const weights = weightsOf(a.percentage, b.percentage);\n if (!first || !second || !weights) return undefined;\n\n const [c1, c2] = [first, second].map(([r, g, bl, alpha]) => ({\n coords: into(space, [r / 255, g / 255, bl / 255]),\n alpha,\n })) as [Side, Side];\n const hueAt = HUE_INDEX[space];\n alignComponents(c1, c2, hueAt, hue);\n\n const { t, alphaScale } = weights;\n const alpha = c1.alpha * (1 - t) + c2.alpha * t;\n const mixed = interpolate(c1, c2, t, alpha, hueAt);\n const [r, g, bl] = outOf(space, mixed).map((c) => c * 255);\n return [r!, g!, bl!, alpha * alphaScale];\n}\n\ninterface Side {\n coords: Vector;\n alpha: number;\n}\n\n/**\n * CSS Color 5, 2.1: missing percentages take what the other leaves, or half each; the second\n * colour's share is `t`, and a pair summing under 100 scales the alpha down.\n */\nfunction weightsOf(p?: number, q?: number): { t: number; alphaScale: number } | null {\n const [first, second] =\n p === undefined && q === undefined\n ? [50, 50]\n : p === undefined\n ? [100 - q!, q!]\n : q === undefined\n ? [p, 100 - p]\n : [p, q];\n const sum = first + second;\n if (sum <= 0) return null;\n return { t: second / sum, alphaScale: sum < 100 ? sum / 100 : 1 };\n}\n\n/** A missing component takes the other colour's, and the hues are set to go the way asked. */\nfunction alignComponents(c1: Side, c2: Side, hueAt: number | undefined, hue: HueMethod): void {\n for (let i = 0; i < 3; i++) {\n if (Number.isNaN(c1.coords[i])) c1.coords[i] = c2.coords[i]!;\n if (Number.isNaN(c2.coords[i])) c2.coords[i] = c1.coords[i]!;\n }\n if (hueAt === undefined) return;\n const [h1, h2] = [c1.coords[hueAt]!, c2.coords[hueAt]!];\n if (Number.isFinite(h1) && Number.isFinite(h2)) {\n [c1.coords[hueAt], c2.coords[hueAt]] = fixHues(h1, h2, hue);\n }\n}\n\n/** Premultiplied by alpha, except the hue, which is an angle and not an amount. */\nfunction interpolate(c1: Side, c2: Side, t: number, alpha: number, hueAt?: number): Vector {\n const mixed = [0, 1, 2].map((i) => {\n if (i === hueAt) return c1.coords[i]! * (1 - t) + c2.coords[i]! * t;\n const premixed = c1.coords[i]! * c1.alpha * (1 - t) + c2.coords[i]! * c2.alpha * t;\n return alpha === 0 ? 0 : premixed / alpha;\n }) as Vector;\n if (hueAt !== undefined) mixed[hueAt] = ((mixed[hueAt]! % 360) + 360) % 360;\n return mixed;\n}\n"]}
1
+ {"version":3,"file":"color-mix.js","sourceRoot":"","sources":["../src/color-mix.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKnE,MAAM,CAAC,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAW;IAC/D,MAAM;IACN,OAAO;IACP,OAAO;IACP,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC,CAAC;AAMH,MAAM,KAAK,GAAG,CAAC,CAAoB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAS,EAAU,EAA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,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAE,GAAG,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC;QACnF,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,KAAK,CAAC;IAC5C,CAAC,CAAW,CAAC;IACb,IAAI,KAAK,KAAK,SAAS;QAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAE,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IAC5E,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * `color-mix()` worked out on device, for a mix with a token in it.\n *\n * The compiler folds a mix of literal colours at build time (lightningcss does the arithmetic); a\n * mix with a `var()` in it can only be done once the token is known, so it is done here, with CSS\n * Color 4 and 5's own arithmetic: each colour converted into the named space, premultiplied by its\n * alpha, interpolated (a hue the shorter way round), and brought back to the sRGB native paints,\n * inside its gamut by CSS Color 4's chroma reduction rather than a clip.\n *\n * The matrices and the gamut mapping are the ones `@ng-native/metro`'s `color-spaces.cjs` uses to\n * convert a literal colour at build time, copied here because the engine cannot depend on the\n * build step; the tests hold the two to the same answers.\n */\nimport { hslToSrgb, hwbToSrgb, parseColor } from './transition.ts';\n\n/** The spaces a mix is worked out in: every one the compiler also folds a literal mix in. */\nexport type MixSpace = 'srgb' | 'oklab' | 'oklch' | 'lab' | 'lch' | 'hsl' | 'hwb';\n\nexport const MIX_SPACES: ReadonlySet<string> = new Set<MixSpace>([\n 'srgb',\n 'oklab',\n 'oklch',\n 'lab',\n 'lch',\n 'hsl',\n 'hwb',\n]);\n\nexport type HueMethod = 'shorter' | 'longer' | 'increasing' | 'decreasing';\n\nexport type Vector = [number, number, number];\n\nconst times = (m: readonly Vector[], [x, y, z]: Vector): Vector =>\n m.map(([a, b, c]) => a * x + b * y + c * z) as Vector;\n\nconst OKLAB_TO_LMS: Vector[] = [\n [1.0, 0.3963377773761749, 0.2158037573099136],\n [1.0, -0.1055613458156586, -0.0638541728258133],\n [1.0, -0.0894841775298119, -1.2914855480194092],\n];\nconst LMS_TO_XYZ: Vector[] = [\n [1.2268798758459243, -0.5578149944602171, 0.2813910456659647],\n [-0.0405757452148008, 1.112286803280317, -0.0717110580655164],\n [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816],\n];\nconst XYZ_TO_LMS: Vector[] = [\n [0.819022437996703, 0.3619062600528904, -0.1288737815209879],\n [0.0329836539323885, 0.9292868615863434, 0.0361446663506424],\n [0.0481771893596242, 0.2642395317527308, 0.6335478284694309],\n];\nconst LMS_TO_OKLAB: Vector[] = [\n [0.210454268309314, 0.7936177747023054, -0.0040720430116193],\n [1.9779985324311684, -2.4285922420485799, 0.450593709617411],\n [0.0259040424655478, 0.7827717124575296, -0.8086757549230774],\n];\nconst XYZ_TO_LINEAR_SRGB: Vector[] = [\n [3.2409699419045226, -1.537383177570094, -0.4986107602930034],\n [-0.9692436362808796, 1.8759675015077202, 0.04155505740717559],\n [0.05563007969699366, -0.20397695888897652, 1.0569715142428786],\n];\nconst LINEAR_SRGB_TO_XYZ: Vector[] = [\n [0.41239079926595934, 0.357584339383878, 0.1804807884018343],\n [0.21263900587151027, 0.715168678767756, 0.07219231536073371],\n [0.01933081871559182, 0.11919477979462598, 0.9505321522496607],\n];\n/** Bradford chromatic adaptation between `lab()`'s D50 white and sRGB's D65. */\nconst D50_TO_D65: Vector[] = [\n [0.955473421488075, -0.02309845494876471, 0.06325924320057072],\n [-0.0283697093338637, 1.0099953980813041, 0.021041441191917323],\n [0.012314014864481998, -0.020507649298898964, 1.330365926242124],\n];\nconst D65_TO_D50: Vector[] = [\n [1.0479298208405488, 0.022946793341019088, -0.05019222954313557],\n [0.029627815688159344, 0.990434484573249, -0.01707382502938514],\n [-0.009243058152591178, 0.015055144896577895, 0.7518742899580008],\n];\nconst D50_WHITE: Vector = [0.3457 / 0.3585, 1, (1 - 0.3457 - 0.3585) / 0.3585];\n\nconst encode = (c: number) =>\n Math.sign(c) * (Math.abs(c) > 0.0031308 ? 1.055 * Math.abs(c) ** (1 / 2.4) - 0.055 : 12.92 * c);\nconst decode = (c: number) =>\n Math.sign(c) * (Math.abs(c) > 0.04045 ? ((Math.abs(c) + 0.055) / 1.055) ** 2.4 : c / 12.92);\n\nconst srgbToXyz = (rgb: Vector) => times(LINEAR_SRGB_TO_XYZ, rgb.map(decode) as Vector);\nconst xyzToSrgb = (xyz: Vector) => times(XYZ_TO_LINEAR_SRGB, xyz).map(encode) as Vector;\nconst xyzToOklab = (xyz: Vector) =>\n times(LMS_TO_OKLAB, times(XYZ_TO_LMS, xyz).map(Math.cbrt) as Vector);\nconst oklabToXyz = (lab: Vector) =>\n times(LMS_TO_XYZ, times(OKLAB_TO_LMS, lab).map((c) => c ** 3) as Vector);\n\nconst KAPPA = 24389 / 27;\nconst EPSILON = 216 / 24389;\n\nfunction xyzToLab(xyz: Vector): Vector {\n const [x, y, z] = times(D65_TO_D50, xyz).map((c, i) => c / D50_WHITE[i]!);\n const f = (c: number) => (c > EPSILON ? Math.cbrt(c) : (KAPPA * c + 16) / 116);\n const [fx, fy, fz] = [f(x!), f(y!), f(z!)];\n return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];\n}\n\nfunction labToXyz([l, a, b]: Vector): Vector {\n const fy = (l + 16) / 116;\n const fx = a / 500 + fy;\n const fz = fy - b / 200;\n const x = fx ** 3 > EPSILON ? fx ** 3 : (116 * fx - 16) / KAPPA;\n const y = l > KAPPA * EPSILON ? fy ** 3 : l / KAPPA;\n const z = fz ** 3 > EPSILON ? fz ** 3 : (116 * fz - 16) / KAPPA;\n return times(D50_TO_D65, [x, y, z].map((c, i) => c * D50_WHITE[i]!) as Vector);\n}\n\n/** Lightness, chroma and hue in degrees, from the rectangular form, and back. */\nconst polar = ([l, a, b]: Vector): Vector => {\n const hue = (Math.atan2(b, a) * 180) / Math.PI;\n return [l, Math.hypot(a, b), hue < 0 ? hue + 360 : hue];\n};\nconst rectangular = ([l, c, h]: Vector): Vector => [\n l,\n c * Math.cos((h * Math.PI) / 180),\n c * Math.sin((h * Math.PI) / 180),\n];\n\nfunction srgbToHsl([r, g, b]: Vector): Vector {\n const max = Math.max(r, g, b);\n const min = Math.min(r, g, b);\n const l = (max + min) / 2;\n const d = max - min;\n if (d === 0) return [NaN, 0, l];\n const s = l === 0 || l === 1 ? 0 : (max - l) / Math.min(l, 1 - l);\n const h =\n max === r\n ? ((g - b) / d + (g < b ? 6 : 0)) * 60\n : max === g\n ? ((b - r) / d + 2) * 60\n : ((r - g) / d + 4) * 60;\n return [h, s, l];\n}\n\nfunction srgbToHwb(rgb: Vector): Vector {\n const [h] = srgbToHsl(rgb);\n return [h, Math.min(...rgb), 1 - Math.max(...rgb)];\n}\n\n/** Where the hue sits in each space's coordinates, if it has one. */\nconst HUE_INDEX: Partial<Record<MixSpace, number>> = { oklch: 2, lch: 2, hsl: 0, hwb: 0 };\n\n/** An sRGB colour, channels 0 to 1, in the space's own coordinates. */\nexport function into(space: MixSpace, rgb: Vector): Vector {\n switch (space) {\n case 'srgb':\n return rgb;\n case 'oklab':\n return xyzToOklab(srgbToXyz(rgb));\n case 'oklch':\n return powerless(polar(xyzToOklab(srgbToXyz(rgb))), 0.000004);\n case 'lab':\n return xyzToLab(srgbToXyz(rgb));\n case 'lch':\n return powerless(polar(xyzToLab(srgbToXyz(rgb))), 0.0015);\n case 'hsl':\n return srgbToHsl(rgb);\n case 'hwb':\n return srgbToHwb(rgb);\n }\n}\n\n/** A hue that does not matter, for a colour with no chroma to speak of, is missing, as CSS says. */\nconst powerless = ([l, c, h]: Vector, threshold: number): Vector => [\n l,\n c,\n c <= threshold ? NaN : h,\n];\n\n/** Back to sRGB, 0 to 1, brought inside the gamut where the space reaches past it. */\nexport function outOf(space: MixSpace, coords: Vector): Vector {\n const finite = coords.map((c) => (Number.isFinite(c) ? c : 0)) as Vector;\n switch (space) {\n case 'srgb':\n return clip(finite);\n case 'oklab':\n return gamutMap(finite);\n case 'oklch':\n return gamutMap(rectangular(finite));\n case 'lab':\n return gamutMap(xyzToOklab(labToXyz(finite)));\n case 'lch':\n return gamutMap(xyzToOklab(labToXyz(rectangular(finite))));\n case 'hsl':\n return clip(hslToSrgb(finite));\n case 'hwb':\n return clip(hwbToSrgb(finite));\n }\n}\n\nconst clip = (rgb: Vector) => rgb.map((c) => Math.min(1, Math.max(0, c))) as Vector;\nconst inGamut = (rgb: Vector) => rgb.every((c) => c >= -1e-6 && c <= 1 + 1e-6);\nconst deltaEOK = (a: Vector, b: Vector) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);\n\n/** CSS Color 4 section 13.2.2: reduce OKLCh chroma until clipping no longer shows. */\nfunction gamutMap(oklab: Vector): Vector {\n const origin = polar(oklab);\n if (origin[0] >= 1) return [1, 1, 1];\n if (origin[0] <= 0) return [0, 0, 0];\n const srgbOf = (lch: Vector) => xyzToSrgb(oklabToXyz(rectangular(lch)));\n const rgb = srgbOf(origin);\n if (inGamut(rgb)) return clip(rgb);\n\n const JND = 0.02;\n const EPS = 0.0001;\n let clipped = clip(rgb);\n if (deltaEOK(xyzToOklab(srgbToXyz(clipped)), oklab) < JND) return clipped;\n let min = 0;\n let max = origin[1];\n let minInGamut = true;\n while (max - min > EPS) {\n const chroma = (min + max) / 2;\n const current: Vector = [origin[0], chroma, origin[2]];\n const converted = srgbOf(current);\n if (minInGamut && inGamut(converted)) {\n min = chroma;\n continue;\n }\n clipped = clip(converted);\n const error = deltaEOK(xyzToOklab(srgbToXyz(clipped)), rectangular(current));\n if (error < JND) {\n if (JND - error < EPS) return clipped;\n minInGamut = false;\n min = chroma;\n } else {\n max = chroma;\n }\n }\n return clipped;\n}\n\n/** Two hues, one moved by whole turns so that interpolating between them goes the way asked. */\nfunction fixHues(a: number, b: number, method: HueMethod): [number, number] {\n const delta = b - a;\n const lift = HUE_LIFTS[method](delta);\n return lift === 'a' ? [a + 360, b] : lift === 'b' ? [a, b + 360] : [a, b];\n}\n\n/** For each method, which of the two hues takes a whole turn more, given how far apart they are. */\nconst HUE_LIFTS: Record<HueMethod, (delta: number) => 'a' | 'b' | null> = {\n shorter: (delta) => (delta > 180 ? 'a' : delta < -180 ? 'b' : null),\n longer: (delta) => (delta > 0 && delta < 180 ? 'a' : delta > -180 && delta <= 0 ? 'b' : null),\n increasing: (delta) => (delta < 0 ? 'b' : null),\n decreasing: (delta) => (delta > 0 ? 'a' : null),\n};\n\n/** A colour's channels, 0 to 255 and unrounded, and its alpha: what one mix hands another. */\nexport type Rgba = readonly [r: number, g: number, b: number, alpha: number];\n\n/**\n * One side of a mix: a colour as native paints it, or the unrounded channels of another mix, and\n * the percentage written beside it.\n */\nexport interface MixSide {\n readonly colour: string | Rgba;\n readonly percentage?: number;\n}\n\n/**\n * `color-mix(in <space> [<hue> hue], <a> [p%], <b> [q%])`, as the `rgb()` or `rgba()` native\n * reads. Undefined when a side is not a colour it can read - a platform colour, say - or when the\n * two percentages come to zero, which CSS says is not a colour at all.\n */\nexport function mixColours(\n space: MixSpace,\n a: MixSide,\n b: MixSide,\n hue: HueMethod = 'shorter',\n): string | undefined {\n const mixed = mixChannels(space, a, b, hue);\n if (!mixed) return undefined;\n const [r, g, bl] = mixed.map((c) => Math.round(c));\n const opacity = Math.round(mixed[3] * 1000) / 1000;\n return opacity >= 1 ? `rgb(${r}, ${g}, ${bl})` : `rgba(${r}, ${g}, ${bl}, ${opacity})`;\n}\n\n/**\n * The same mix, unrounded, for a mix around it to take as one of its sides: CSS works a nested\n * mix out in full and rounds only the colour at the end.\n */\nexport function mixChannels(\n space: MixSpace,\n a: MixSide,\n b: MixSide,\n hue: HueMethod = 'shorter',\n): Rgba | undefined {\n const first = typeof a.colour === 'string' ? parseColor(a.colour) : a.colour;\n const second = typeof b.colour === 'string' ? parseColor(b.colour) : b.colour;\n const weights = weightsOf(a.percentage, b.percentage);\n if (!first || !second || !weights) return undefined;\n\n const [c1, c2] = [first, second].map(([r, g, bl, alpha]) => ({\n coords: into(space, [r / 255, g / 255, bl / 255]),\n alpha,\n })) as [Side, Side];\n const hueAt = HUE_INDEX[space];\n alignComponents(c1, c2, hueAt, hue);\n\n const { t, alphaScale } = weights;\n const alpha = c1.alpha * (1 - t) + c2.alpha * t;\n const mixed = interpolate(c1, c2, t, alpha, hueAt);\n const [r, g, bl] = outOf(space, mixed).map((c) => c * 255);\n return [r!, g!, bl!, alpha * alphaScale];\n}\n\ninterface Side {\n coords: Vector;\n alpha: number;\n}\n\n/**\n * CSS Color 5, 2.1: missing percentages take what the other leaves, or half each; the second\n * colour's share is `t`, and a pair summing under 100 scales the alpha down.\n */\nfunction weightsOf(p?: number, q?: number): { t: number; alphaScale: number } | null {\n const [first, second] =\n p === undefined && q === undefined\n ? [50, 50]\n : p === undefined\n ? [100 - q!, q!]\n : q === undefined\n ? [p, 100 - p]\n : [p, q];\n const sum = first + second;\n if (sum <= 0) return null;\n return { t: second / sum, alphaScale: sum < 100 ? sum / 100 : 1 };\n}\n\n/** A missing component takes the other colour's, and the hues are set to go the way asked. */\nfunction alignComponents(c1: Side, c2: Side, hueAt: number | undefined, hue: HueMethod): void {\n for (let i = 0; i < 3; i++) {\n if (Number.isNaN(c1.coords[i])) c1.coords[i] = c2.coords[i]!;\n if (Number.isNaN(c2.coords[i])) c2.coords[i] = c1.coords[i]!;\n }\n if (hueAt === undefined) return;\n const [h1, h2] = [c1.coords[hueAt]!, c2.coords[hueAt]!];\n if (Number.isFinite(h1) && Number.isFinite(h2)) {\n [c1.coords[hueAt], c2.coords[hueAt]] = fixHues(h1, h2, hue);\n }\n}\n\n/** Premultiplied by alpha, except the hue, which is an angle and not an amount. */\nfunction interpolate(c1: Side, c2: Side, t: number, alpha: number, hueAt?: number): Vector {\n const mixed = [0, 1, 2].map((i) => {\n if (i === hueAt) return c1.coords[i]! * (1 - t) + c2.coords[i]! * t;\n const premixed = c1.coords[i]! * c1.alpha * (1 - t) + c2.coords[i]! * c2.alpha * t;\n return alpha === 0 ? 0 : premixed / alpha;\n }) as Vector;\n if (hueAt !== undefined) mixed[hueAt] = ((mixed[hueAt]! % 360) + 360) % 360;\n return mixed;\n}\n"]}
package/dist/css.d.ts CHANGED
@@ -37,6 +37,11 @@ export interface Compound {
37
37
  * What Tailwind's `group-*` variants compile to.
38
38
  */
39
39
  readonly ancestors?: readonly Compound[];
40
+ /**
41
+ * `:is(<compound> > *)`: every one of these must match the node's parent. What Tailwind's `*:`
42
+ * variant compiles to.
43
+ */
44
+ readonly parents?: readonly Compound[];
40
45
  /** Interaction state the engine tracks: `:focus` and `:active`. */
41
46
  readonly pseudo?: readonly ('focus' | 'active')[];
42
47
  /**
@@ -46,6 +51,14 @@ export interface Compound {
46
51
  readonly nth?: readonly NthTest[];
47
52
  /** `:empty`: no children at all, text included. */
48
53
  readonly empty?: true;
54
+ /** `:has()`: every one of these must find a match beneath the node. */
55
+ readonly has?: readonly HasTest[];
56
+ }
57
+ /** One `:has()`: some element beneath the node, or some child of it, matches one of `any`. */
58
+ export interface HasTest {
59
+ /** `:has(> x)`: a child, not any descendant. */
60
+ readonly child?: true;
61
+ readonly any: readonly Compound[];
49
62
  }
50
63
  /** `an + b`, counted from the start unless `fromEnd`. */
51
64
  export interface NthTest {
@@ -73,6 +86,15 @@ export interface StyleRule {
73
86
  readonly importantTokens?: readonly string[];
74
87
  /** Declarations whose value is a `var()`, resolved once the token map is known. */
75
88
  readonly deferred?: readonly DeferredDeclaration[];
89
+ /**
90
+ * The corners and edges the rule's plain declarations wrote, in the order it wrote them, where
91
+ * it wrote one in both its logical form and its physical one. The cascade settles the two as
92
+ * one property, and a value settled on device is in a list of its own, with no order between
93
+ * it and the rest.
94
+ */
95
+ readonly sides?: readonly string[];
96
+ /** The same for the rule's important declarations. */
97
+ readonly importantSides?: readonly string[];
76
98
  /** The media query guarding this rule, if any. */
77
99
  readonly condition?: MediaCondition;
78
100
  /** Memo of the last condition evaluation, and the conditions version it was made against. */
@@ -88,7 +110,8 @@ export type MediaCondition = {
88
110
  readonly op: 'gt' | 'gte' | 'lt' | 'lte' | 'eq';
89
111
  readonly value: number;
90
112
  } | {
91
- readonly feature: 'orientation' | 'prefers-color-scheme' | 'prefers-reduced-motion';
113
+ /** `direction` is not a media feature: it is what `:dir()` asks, of the app as a whole. */
114
+ readonly feature: 'orientation' | 'prefers-color-scheme' | 'prefers-reduced-motion' | 'direction';
92
115
  readonly value: string;
93
116
  };
94
117
  /** What media queries are evaluated against. Pushed in by the host: the engine imports no RN. */
@@ -109,6 +132,12 @@ export interface Conditions {
109
132
  * (`Engine.remeasureText`), which `watchConditions` does after it.
110
133
  */
111
134
  readonly fontScale?: number;
135
+ /**
136
+ * The direction the app is laid out in, which is the device's unless the app forced one:
137
+ * `I18nManager.isRTL`. Optional, and left to right when absent. It decides which physical
138
+ * corner or edge a logical one is, where an element has both and no `direction` of its own.
139
+ */
140
+ readonly direction?: 'ltr' | 'rtl';
112
141
  }
113
142
  /** A run of CSS whitespace: spaces, tabs, newlines, carriage returns and form feeds, and no other. */
114
143
  export declare const CSS_SPACE: RegExp;
@@ -394,6 +423,12 @@ export interface StyleSheet {
394
423
  * has to re-resolve a whole child list when it changes. It only does that where a sheet asks.
395
424
  */
396
425
  readonly structural?: true;
426
+ /**
427
+ * Some rule uses `:has()`, so what a node matches can change when something beneath it does.
428
+ * Said on the sheet for the same reason `structural` is: the cost is invalidation, and only a
429
+ * sheet that asks has the engine match a changed node's ancestors again.
430
+ */
431
+ readonly has?: true;
397
432
  /**
398
433
  * The `@font-face` rules the sheet declares, each `source` the bundler's `require` of the file.
399
434
  * The engine does not read them: `loadFonts()` in `@ng-native/expo/fonts` registers them with
@@ -432,6 +467,11 @@ export interface StyleCache {
432
467
  * values do, and by the same copy-on-write rule, so a subtree that defines none shares one map.
433
468
  */
434
469
  tokens: Readonly<Record<string, TokenValue>>;
470
+ /**
471
+ * The rules the node matched, kept only while a sheet uses `:has()`: what a node whose
472
+ * subtree changed is compared against, to tell whether it has to be restyled.
473
+ */
474
+ matched?: readonly StyleRule[];
435
475
  }
436
476
  /** What the matcher needs of a node. The engine's node satisfies this structurally. */
437
477
  export interface StyleTarget {
@@ -487,6 +527,19 @@ export interface StyleTarget {
487
527
  styleCache: StyleCache | null;
488
528
  /** Set when something that could change what this node matches has changed. */
489
529
  styleDirty: boolean;
530
+ /**
531
+ * Set when something beneath this node changed and a sheet uses `:has()`: the node is matched
532
+ * again, and restyled only if the rules it matches came out different. Absent on a hand-built
533
+ * target.
534
+ */
535
+ hasDirty?: boolean;
536
+ /**
537
+ * Set by the engine when the node's own interaction state changed and nothing else about it
538
+ * did: a press began or ended on it or under it. It is matched again, and keeps the style it
539
+ * has, and everything under it, when it matches the rules it did. Not for an element a rule
540
+ * asks about from another one, which is restyled: see `usesActive`.
541
+ */
542
+ stateDirty?: boolean;
490
543
  /** `:focus`. Set by the engine from the native focus and blur events. */
491
544
  focused?: boolean;
492
545
  /**
@@ -505,6 +558,18 @@ export interface StyleTarget {
505
558
  * The cost is one integer increment per comparison, against a Set lookup and several property
506
559
  * reads, so it does not distort what it measures.
507
560
  */
561
+ /**
562
+ * What a sheet asks about a pressed element. `own` is whether a rule styles one, `.button:active`,
563
+ * which matching the pressed elements again answers. `elsewhere` is each compound that asks about
564
+ * a pressed element from another one: `.card:active .title`, `.a:active + .b`, or `:active`
565
+ * inside `:not()`, `:is()` or `:has()`. An element such a compound could be is restyled with
566
+ * everything under it when it is pressed, as what it changes is not itself alone.
567
+ */
568
+ export declare function usesActive(sheet: StyleSheet): ActiveUse;
569
+ export interface ActiveUse {
570
+ readonly own: boolean;
571
+ readonly elsewhere: readonly Compound[];
572
+ }
508
573
  export declare const styleStats: {
509
574
  /** Calls to `matchesCompound`, the innermost unit of matching work. */
510
575
  compoundTests: number;
@@ -668,6 +733,26 @@ export declare class StyleResolver {
668
733
  * resolves at most once however many descendants ask for its inherited values.
669
734
  */
670
735
  resolve(node: StyleTarget, epoch: number): StyleCache;
736
+ /** The rules a node matched, for its cache to keep, while a sheet uses `:has()`. */
737
+ private record;
738
+ /**
739
+ * Set by the engine once a sheet uses `:has()`. Until then no cache keeps the rules it matched,
740
+ * so an app that never asks pays nothing for it.
741
+ */
742
+ tracksHas: boolean;
743
+ /**
744
+ * The cache of a node whose subtree changed, and nothing else, when it matches the rules it
745
+ * did: keeping the object is what leaves everything under it alone. Nothing when it has to be
746
+ * resolved, as it does with no record of what it matched, made before any sheet asked.
747
+ */
748
+ private keptBeneath;
749
+ /** A cache that still stands for a node marked for its subtree or its state alone. */
750
+ private kept;
751
+ /**
752
+ * The cache of a node whose pressed state changed and nothing else, where no rule can match
753
+ * it at all: it has no style of its own to change, so it and all under it stay as they are.
754
+ */
755
+ private keptUnmatched;
671
756
  /**
672
757
  * Whether a node's last answer still stands under a parent that resolved to `parentContext`,
673
758
  * without resolving it. What lets a commit step over a clean child in one comparison.
@@ -741,6 +826,16 @@ export declare class StyleResolver {
741
826
  private matched;
742
827
  /** The declarations of the rules a node matched. The list is sorted, so later simply wins. */
743
828
  private cascade;
829
+ /**
830
+ * An inline style over the style the cascade settled, both already in `style`: a corner or an
831
+ * edge the inline style sets takes the other form of it out, as a later rule would.
832
+ */
833
+ overOtherForms(inline: Readonly<Record<string, unknown>>, style: Record<string, unknown>): void;
834
+ /**
835
+ * The direction an element is laid out in: the last `direction` its own rules give it, the one
836
+ * it inherits, or the app's. A logical corner is a different physical one in each.
837
+ */
838
+ private directionOf;
744
839
  /**
745
840
  * Whether a rule's media query holds, memoised per rule.
746
841
  *