@ng-native/fabric 0.1.3 → 0.3.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.
@@ -7,9 +7,14 @@ export type Vector = [number, number, number];
7
7
  export declare function into(space: MixSpace, rgb: Vector): Vector;
8
8
  /** Back to sRGB, 0 to 1, brought inside the gamut where the space reaches past it. */
9
9
  export declare function outOf(space: MixSpace, coords: Vector): Vector;
10
- /** One side of a mix: a colour as native paints it, and the percentage written beside it. */
10
+ /** A colour's channels, 0 to 255 and unrounded, and its alpha: what one mix hands another. */
11
+ export type Rgba = readonly [r: number, g: number, b: number, alpha: number];
12
+ /**
13
+ * One side of a mix: a colour as native paints it, or the unrounded channels of another mix, and
14
+ * the percentage written beside it.
15
+ */
11
16
  export interface MixSide {
12
- readonly colour: string;
17
+ readonly colour: string | Rgba;
13
18
  readonly percentage?: number;
14
19
  }
15
20
  /**
@@ -18,3 +23,8 @@ export interface MixSide {
18
23
  * two percentages come to zero, which CSS says is not a colour at all.
19
24
  */
20
25
  export declare function mixColours(space: MixSpace, a: MixSide, b: MixSide, hue?: HueMethod): string | undefined;
26
+ /**
27
+ * The same mix, unrounded, for a mix around it to take as one of its sides: CSS works a nested
28
+ * mix out in full and rounds only the colour at the end.
29
+ */
30
+ export declare function mixChannels(space: MixSpace, a: MixSide, b: MixSide, hue?: HueMethod): Rgba | undefined;
package/dist/color-mix.js CHANGED
@@ -241,8 +241,20 @@ const HUE_LIFTS = {
241
241
  * two percentages come to zero, which CSS says is not a colour at all.
242
242
  */
243
243
  export function mixColours(space, a, b, hue = 'shorter') {
244
- const first = parseColor(a.colour);
245
- const second = parseColor(b.colour);
244
+ const mixed = mixChannels(space, a, b, hue);
245
+ if (!mixed)
246
+ return undefined;
247
+ const [r, g, bl] = mixed.map((c) => Math.round(c));
248
+ const opacity = Math.round(mixed[3] * 1000) / 1000;
249
+ return opacity >= 1 ? `rgb(${r}, ${g}, ${bl})` : `rgba(${r}, ${g}, ${bl}, ${opacity})`;
250
+ }
251
+ /**
252
+ * The same mix, unrounded, for a mix around it to take as one of its sides: CSS works a nested
253
+ * mix out in full and rounds only the colour at the end.
254
+ */
255
+ export function mixChannels(space, a, b, hue = 'shorter') {
256
+ const first = typeof a.colour === 'string' ? parseColor(a.colour) : a.colour;
257
+ const second = typeof b.colour === 'string' ? parseColor(b.colour) : b.colour;
246
258
  const weights = weightsOf(a.percentage, b.percentage);
247
259
  if (!first || !second || !weights)
248
260
  return undefined;
@@ -255,9 +267,8 @@ export function mixColours(space, a, b, hue = 'shorter') {
255
267
  const { t, alphaScale } = weights;
256
268
  const alpha = c1.alpha * (1 - t) + c2.alpha * t;
257
269
  const mixed = interpolate(c1, c2, t, alpha, hueAt);
258
- const [r, g, bl] = outOf(space, mixed).map((c) => Math.round(c * 255));
259
- const opacity = Math.round(alpha * alphaScale * 1000) / 1000;
260
- return opacity >= 1 ? `rgb(${r}, ${g}, ${bl})` : `rgba(${r}, ${g}, ${bl}, ${opacity})`;
270
+ const [r, g, bl] = outOf(space, mixed).map((c) => c * 255);
271
+ return [r, g, bl, alpha * alphaScale];
261
272
  }
262
273
  /**
263
274
  * CSS Color 5, 2.1: missing percentages take what the other leaves, or half each; the second
@@ -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,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,EAAE,CAChE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAA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E,CAAC,EAAE,CAAC;QAC/C,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAED,mFAAmF;AACnF,SAAS,WAAW,CAAC,EAAQ,EAAE,EAAQ,EAAE,CAAS,EAAE,KAAa,EAAE,KAAc;IAC/E,MAAM,KAAK,GAAG,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/** One side of a mix: a colour as native paints it, and the percentage written beside it. */\nexport interface MixSide {\n readonly colour: string;\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 first = parseColor(a.colour);\n const second = parseColor(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) => Math.round(c * 255));\n const opacity = Math.round(alpha * alphaScale * 1000) / 1000;\n return opacity >= 1 ? `rgb(${r}, ${g}, ${bl})` : `rgba(${r}, ${g}, ${bl}, ${opacity})`;\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,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,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,EAAE,CAChE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,G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G,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"]}
package/dist/css.d.ts CHANGED
@@ -95,7 +95,16 @@ export interface Conditions {
95
95
  * platform that cannot answer means anyway.
96
96
  */
97
97
  readonly reducedMotion?: boolean;
98
+ /**
99
+ * The system text size, as a multiplier: `PixelRatio.getFontScale()`. What native text scales
100
+ * by; the engine scales the line box it keeps for a single-line iOS text input by it too.
101
+ * Optional, and 1 when absent. A change reaches that line box when text is measured again
102
+ * (`Engine.remeasureText`), which `watchConditions` does after it.
103
+ */
104
+ readonly fontScale?: number;
98
105
  }
106
+ /** A run of CSS whitespace: spaces, tabs, newlines, carriage returns and form feeds, and no other. */
107
+ export declare const CSS_SPACE: RegExp;
99
108
  /** A custom property's value, in each form it can legally take. Absent forms are unusable. */
100
109
  export interface TokenValue {
101
110
  readonly length?: number | string;
@@ -160,6 +169,8 @@ export interface TokenValue {
160
169
  readonly s: HslChannel;
161
170
  readonly l: HslChannel;
162
171
  readonly alpha?: HslChannel;
172
+ /** Written with commas, whose saturation and lightness are percentages alone. */
173
+ readonly legacy?: true;
163
174
  };
164
175
  }
165
176
  /** One channel of an `hsl()` token: settled at build time, or a token to read at match time. */
@@ -168,7 +179,7 @@ export type HslChannel = number | {
168
179
  readonly fallback?: number;
169
180
  };
170
181
  /** The forms a token can be read in: one per kind of value a use site can need. */
171
- export type TokenKind = 'length' | 'color' | 'keyword' | 'number' | 'weight' | 'family' | 'lineHeight' | 'shadow' | 'filter' | 'transform' | 'fontVariant' | 'channels' | 'hslChannels' | 'easing' | 'time' | 'animation';
182
+ export type TokenKind = 'length' | 'color' | 'keyword' | 'number' | 'weight' | 'family' | 'lineHeight' | 'shadow' | 'filter' | 'transform' | 'fontVariant' | 'channels' | 'hslChannels' | 'easing' | 'time' | 'animation' | 'display';
172
183
  export interface DeferredDeclaration {
173
184
  /**
174
185
  * The React Native style properties this lands in. Usually one, but a four-sided shorthand is
@@ -184,6 +195,11 @@ export interface DeferredDeclaration {
184
195
  */
185
196
  readonly alternatives?: readonly string[];
186
197
  readonly fallback?: unknown;
198
+ /**
199
+ * A fallback made of other tokens, `var(--missing, calc(var(--gap) * 2))`, worked out from the
200
+ * tokens in scope where it is used, as a browser substitutes it there.
201
+ */
202
+ readonly fallbackToken?: TokenValue;
187
203
  /**
188
204
  * What to write when the reference resolves, whatever it resolves to: `flex: var(--grow)` sets a
189
205
  * shrink of 1 and a basis of 0%, but only when there is a grow for them to go with.
@@ -219,6 +235,11 @@ export interface DeferredDeclaration {
219
235
  readonly scale?: number;
220
236
  readonly offset?: number;
221
237
  readonly floor?: number;
238
+ /**
239
+ * The reference is multiplied by a length, so it is a number: `calc(var(--n) * 1px)`. Without
240
+ * this it is a length, and a number token is no such thing, as CSS types a calc().
241
+ */
242
+ readonly number?: true;
222
243
  /**
223
244
  * A fraction to multiply the resolved colour's alpha by. What
224
245
  * `color-mix(in oklab, var(--x) 90%, transparent)` becomes, which is Tailwind's `/90`.
@@ -241,6 +262,29 @@ export interface DeferredDeclaration {
241
262
  * somewhere inside it, each marked `{ __defer: compute }`. Filled in where it is used.
242
263
  */
243
264
  readonly within?: unknown;
265
+ /** A `border` or a side's line with tokens in it, each given its role where it is used. */
266
+ readonly line?: LineTemplate;
267
+ }
268
+ /**
269
+ * `border: var(--w) var(--s) var(--c)`: which token is the width, the style or the colour cannot be
270
+ * told at build time, so each is given the role its form says on device. `roles` are those the
271
+ * written parts left open; `props` of the declaration are every longhand, which a line its tokens
272
+ * make nothing of unsets.
273
+ */
274
+ export interface LineTemplate {
275
+ readonly references: readonly {
276
+ readonly reference: string;
277
+ readonly alternatives?: readonly string[];
278
+ readonly fallback?: TokenValue;
279
+ /** `var(--x,)`: nothing at all when the token is unset. */
280
+ readonly empty?: true;
281
+ /** `calc(var(--w) * 2)`: the arithmetic that makes the token the width, and only that. */
282
+ readonly adjust?: DeferredDeclaration['adjust'];
283
+ }[];
284
+ readonly roles: readonly ('width' | 'style' | 'color')[];
285
+ readonly widths: readonly string[];
286
+ readonly colors: readonly string[];
287
+ readonly style?: string;
244
288
  }
245
289
  /**
246
290
  * A colour a deferred value is made of: settled at build time, a token, or a `color-mix()` of two
@@ -253,6 +297,13 @@ export type ColourExpression = {
253
297
  readonly reference: string;
254
298
  readonly alternatives?: readonly string[];
255
299
  readonly fallback?: string;
300
+ /** A fallback made of other tokens, worked out from the tokens where it is used. */
301
+ readonly fallbackToken?: TokenValue;
302
+ /**
303
+ * A shadow's `var(--x,)` with no colour beside it, which holds the colour or the word
304
+ * `inset`: currentcolor when it is `inset` or unset.
305
+ */
306
+ readonly orInset?: true;
256
307
  } | {
257
308
  /** A token of bare channels, as `rgba(var(--channels), <alpha>)` reads it. */
258
309
  readonly channels: {
@@ -506,12 +557,18 @@ export declare class StyleResolver {
506
557
  * selector. Keyed by the creating sheet and then the hosted one, so a component's nodes share a
507
558
  * single index.
508
559
  */
509
- private readonly merged;
560
+ private merged;
510
561
  /**
511
562
  * The application-level sheet, if any: the one set of rules allowed to match a node whatever
512
563
  * component created it, which is what resets, utility classes and `:root` tokens all need.
513
564
  */
514
565
  private readonly globalSheet;
566
+ /**
567
+ * Global sheets added once the engine is running, in the order they came: a
568
+ * `ViewEncapsulation.None` component's, which a browser adds to the document unscoped when the
569
+ * component first renders, after the application's own. See `addGlobalSheet`.
570
+ */
571
+ private readonly addedSheets;
515
572
  /**
516
573
  * Custom properties the host supplies rather than the stylesheet: the safe-area insets, and
517
574
  * whatever else is a property of the device instead of the design.
@@ -528,7 +585,24 @@ export declare class StyleResolver {
528
585
  * which is dropped. Set only in development, where it is how the engine says so.
529
586
  */
530
587
  onUndefinedToken: ((name: string, props: readonly string[]) => void) | null;
588
+ /**
589
+ * Told of a `display: var()` whose token holds no display native has, `grid` or `table`, which
590
+ * leaves display unset. Set only in development, where it is how the engine says so: the
591
+ * compiler refuses the same value written out, but a token is only known here.
592
+ */
593
+ onUnreadDisplay: ((name: string, value: string | undefined) => void) | null;
531
594
  constructor(globalSheet: StyleSheet | null, conditions: Conditions);
595
+ /**
596
+ * Match `sheet` against every node from now on, as a global sheet, after the application's;
597
+ * false when it already is. Every cached result goes, as on a theme switch: rules that were not
598
+ * there can now match anything. `:host` in it matches nothing, since no node hosts it.
599
+ *
600
+ * With `replacing`, a sheet added before, it takes that one's place, and so its order: a hot
601
+ * swap of the component's CSS edits the sheet where it is.
602
+ */
603
+ addGlobalSheet(sheet: StyleSheet, replacing?: StyleSheet): boolean;
604
+ /** Stop matching a sheet `addGlobalSheet` added; false when it is not one. */
605
+ removeGlobalSheet(sheet: StyleSheet): boolean;
532
606
  setConditions(next: Conditions): void;
533
607
  setRootTokens(next: Readonly<Record<string, TokenValue>>): void;
534
608
  /**
@@ -558,7 +632,9 @@ export declare class StyleResolver {
558
632
  *
559
633
  * It still mints a context, because a rule further down may match on one of *its* classes.
560
634
  * When there is nothing to inherit either, one shared cache object serves every such node, so
561
- * an application that writes no CSS allocates nothing per node.
635
+ * an application that writes no CSS allocates nothing per node. Not when there are tokens to
636
+ * carry: the shared object holds none, and the surface root answering with it dropped every
637
+ * token the device had seeded.
562
638
  */
563
639
  private unstyled;
564
640
  /**
@@ -576,6 +652,10 @@ export declare class StyleResolver {
576
652
  * created it. Both carry the bump; the creator comes later and so wins a tie, as the outer
577
653
  * document does over `:host` on the web. The sort is stable, so within one sheet source order
578
654
  * survives and a later sheet wins equal weight.
655
+ *
656
+ * A sheet added with `addGlobalSheet` comes last, with no bump: a browser adds a None
657
+ * component's CSS when the component first renders, after the styles of the components around
658
+ * it, so it loses to their extra attribute and wins a tie with them.
579
659
  */
580
660
  private merge;
581
661
  /**
@@ -621,8 +701,12 @@ export declare class StyleResolver {
621
701
  private applyDeferred;
622
702
  /** One deferred declaration's value, from the tokens in scope and the node's own style. */
623
703
  private settled;
704
+ /** A line's longhands from its tokens, with a width in `em` worked out against the font size. */
705
+ private settledLine;
624
706
  /** A reference with nothing defined for it and nothing to fall back to. */
625
707
  private reportUndefined;
708
+ /** A display token set to a value native has no display for. */
709
+ private reportDisplay;
626
710
  /**
627
711
  * A structured value with every deferred length and colour inside it settled, or undefined when
628
712
  * a colour in it cannot be: a shadow with no colour is not a shadow, as CSS reads it.
@@ -642,11 +726,15 @@ export declare class StyleResolver {
642
726
  type ChannelSpace = 'rgb' | 'hsl';
643
727
  /**
644
728
  * Arithmetic with tokens in it, as the compiler leaves it: numbers, token references and
645
- * `[op, a, b]`, in points, degrees or plain numbers as the slot it fills counts.
729
+ * `[op, a, b]`, in points, degrees or plain numbers as the slot it fills counts. A percentage
730
+ * written where a number is wanted is its fraction, kept apart from a bare number so that what
731
+ * the arithmetic makes is still a percentage (see `calcType`).
646
732
  */
647
733
  type CalcExpression = number | {
734
+ readonly percentage: number;
735
+ } | {
648
736
  readonly reference: string;
649
- readonly fallback?: number;
737
+ readonly fallback?: CalcExpression;
650
738
  } | readonly ['+' | '-' | '*' | '/' | 'max' | 'min', CalcExpression, CalcExpression];
651
739
  interface CalcMarker {
652
740
  readonly expression: CalcExpression;