@sessile/core 0.1.0 → 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.
package/dist/contour.js CHANGED
@@ -99,8 +99,34 @@ function fmt(value) {
99
99
  const rounded = Math.round(value * 100) / 100;
100
100
  return rounded === 0 ? 0 : rounded;
101
101
  }
102
- function clampInt(value, min, max) {
103
- return value < min ? min : value > max ? max : value;
102
+ /**
103
+ * Selects the smallest grid step from the half-octave lattice `{1, 1.5} * 2^k`
104
+ * that is at least `minStep` so multi-primitive Marching Squares sample nodes stay
105
+ * locked to fixed world-space coordinates when only one primitive moves.
106
+ */
107
+ function pickDiscreteGridStep(minStep) {
108
+ if (!(minStep > 0) || !Number.isFinite(minStep)) {
109
+ return 1;
110
+ }
111
+ const exp = Math.floor(Math.log2(minStep));
112
+ const pow2 = Math.pow(2, exp);
113
+ if (pow2 >= minStep) {
114
+ return pow2;
115
+ }
116
+ const mid = pow2 * 1.5;
117
+ if (mid >= minStep) {
118
+ return mid;
119
+ }
120
+ return pow2 * 2;
121
+ }
122
+ /** Advances to the next rung on the `{1, 1.5} * 2^k` world-lattice step ladder. */
123
+ function nextDiscreteGridStep(step) {
124
+ if (!(step > 0) || !Number.isFinite(step)) {
125
+ return 1;
126
+ }
127
+ const exp = Math.floor(Math.log2(step));
128
+ const pow2 = Math.pow(2, exp);
129
+ return step < pow2 * 1.25 ? pow2 * 1.5 : pow2 * 2;
104
130
  }
105
131
  function isActivePrimitive(shape) {
106
132
  return shape.size.width > MIN_ACTIVE_SIZE && shape.size.height > MIN_ACTIVE_SIZE;
@@ -284,19 +310,38 @@ export function extractFieldContourPath(field, offset = ZERO_POINT) {
284
310
  function appendClusterMarchingSquaresLoops(minX, maxX, minY, maxY, clusterSize, blendK, prepared, offset, outLoops) {
285
311
  // Margin compensating for multi-primitive cumulative smin dilation so outer boundary nodes stay strictly positive and form closed loops.
286
312
  const msPadding = computeMaxSminDilationFactor(clusterSize) * blendK + 4;
287
- const boundsX = minX - msPadding;
288
- const boundsY = minY - msPadding;
289
- const boundsW = maxX - minX + msPadding * 2;
290
- const boundsH = maxY - minY + msPadding * 2;
291
- const longest = boundsW > boundsH ? boundsW : boundsH;
313
+ const rawMinX = minX - msPadding;
314
+ const rawMaxX = maxX + msPadding;
315
+ const rawMinY = minY - msPadding;
316
+ const rawMaxY = maxY + msPadding;
317
+ const rawW = rawMaxX - rawMinX;
318
+ const rawH = rawMaxY - rawMinY;
319
+ const longest = rawW > rawH ? rawW : rawH;
292
320
  if (longest <= MIN_ACTIVE_SIZE) {
293
321
  return;
294
322
  }
295
- const targetStep = longest / MAX_GRID_STEPS;
296
- const cols = clampInt(Math.ceil(boundsW / targetStep), MIN_GRID_STEPS, MAX_GRID_STEPS);
297
- const rows = clampInt(Math.ceil(boundsH / targetStep), MIN_GRID_STEPS, MAX_GRID_STEPS);
298
- const dx = boundsW / cols;
299
- const dy = boundsH / rows;
323
+ // Reserve 2 cells for outward world-lattice snapping (`floor` min / `ceil` max) within `MAX_GRID_STEPS`.
324
+ const baseStep = pickDiscreteGridStep(longest / (MAX_GRID_STEPS - 2));
325
+ let dx = rawW / baseStep < MIN_GRID_STEPS
326
+ ? Math.min(baseStep, pickDiscreteGridStep(rawW / (MIN_GRID_STEPS + 12)))
327
+ : baseStep;
328
+ let dy = rawH / baseStep < MIN_GRID_STEPS
329
+ ? Math.min(baseStep, pickDiscreteGridStep(rawH / (MIN_GRID_STEPS + 12)))
330
+ : baseStep;
331
+ let boundsX = Math.floor(rawMinX / dx) * dx;
332
+ let cols = Math.max(1, Math.round((Math.ceil(rawMaxX / dx) * dx - boundsX) / dx));
333
+ while (cols > MAX_GRID_STEPS) {
334
+ dx = nextDiscreteGridStep(dx);
335
+ boundsX = Math.floor(rawMinX / dx) * dx;
336
+ cols = Math.max(1, Math.round((Math.ceil(rawMaxX / dx) * dx - boundsX) / dx));
337
+ }
338
+ let boundsY = Math.floor(rawMinY / dy) * dy;
339
+ let rows = Math.max(1, Math.round((Math.ceil(rawMaxY / dy) * dy - boundsY) / dy));
340
+ while (rows > MAX_GRID_STEPS) {
341
+ dy = nextDiscreteGridStep(dy);
342
+ boundsY = Math.floor(rawMinY / dy) * dy;
343
+ rows = Math.max(1, Math.round((Math.ceil(rawMaxY / dy) * dy - boundsY) / dy));
344
+ }
300
345
  const stride = cols + 1;
301
346
  const ox = offset.x;
302
347
  const oy = offset.y;
@@ -5,6 +5,7 @@
5
5
  *
6
6
  * SPDX-License-Identifier: MPL-2.0
7
7
  */
8
+ import type { BezelHeightProfileName } from './refractProfile.ts';
8
9
  export interface Point {
9
10
  x: number;
10
11
  y: number;
@@ -45,8 +46,8 @@ export interface GlassFieldState {
45
46
  /** Material transition weight from directional to soft rim highlights in [0, 1] (defaults to 0). */
46
47
  styleMix?: number;
47
48
  }
48
- /** Rim highlight mode: 'directional' favors directional speculars; 'soft' favors wide diffuse glow. */
49
- export type RimMode = 'directional' | 'soft';
49
+ /** Rim highlight mode: 'directional' favors directional speculars; 'soft' favors wide diffuse glow; 'physical' uses 3D bevel-slope optics. */
50
+ export type RimMode = 'directional' | 'soft' | 'physical';
50
51
  export type ThemeMode = 'light' | 'dark';
51
52
  export type OpticalPresetVariant = 'crisp' | 'frosted';
52
53
  export interface OpticalMaterial {
@@ -78,6 +79,14 @@ export interface OpticalMaterial {
78
79
  borderRgba?: readonly [number, number, number, number];
79
80
  /** Optional bottom directional highlight ratio relative to the top edge (defaults to 0.72). */
80
81
  rimBottomRatio?: number;
82
+ /** Optional bezel cross-section height curve used when `rimMode === 'physical'` (defaults to `'squircle'`). */
83
+ bevelProfile?: BezelHeightProfileName;
84
+ /** Optional directional light azimuth in degrees clockwise from top for `rimMode === 'physical'` (defaults to `-45`). */
85
+ lightAngle?: number;
86
+ /** Optional directional light elevation above the surface in degrees for `rimMode === 'physical'` (defaults to `22`). */
87
+ lightElevation?: number;
88
+ /** Optional grazing blue-black rim shade strength in `[0, 1]` for `rimMode === 'physical'` (defaults to `0.32`). */
89
+ rimShade?: number;
81
90
  }
82
91
  export declare const DEFAULT_OPTICAL_MATERIALS: {
83
92
  readonly light: {
package/dist/index.d.ts CHANGED
@@ -8,6 +8,9 @@ export { DEFAULT_OPTICAL_MATERIALS, DEFAULT_SPRINGS, MAX_GPU_PRIMITIVES, type Ed
8
8
  export { computeFieldBounds, computePairMergeStatus, computeRoundedBoxDistance, computeRoundedBoxSdf, computeSmin, computeSminDistance, createPreparedField, evaluateFieldDistance, evaluateFieldSdf, prepareField, type PairMergeStatus, type PreparedField, } from './sdf.ts';
9
9
  export { extractFieldContourPath, formatRoundedRectPath, } from './contour.ts';
10
10
  export { buildRefractMapDataUrl, createRefractMapBuilder, type RefractMapBuilder, type RefractMapParams, type RefractMapResult, } from './refractMap.ts';
11
+ export { MAX_REFRACT_TILE_PX, clearRefractTilesCache, resolveRefractTiles, type RefractTileParams, type RefractTilesResult, } from './refractTiles.ts';
12
+ export { BEZEL_HEIGHT_PROFILES, CAUSTIC_FOLD_LIMIT, DEFAULT_REFRACTION_IOR, DEFAULT_REFRACTION_SAMPLES, NORMAL_FLOOR, computeRefractionProfileLut, getRefractionProfileKey, resolveRefractionProfileLut, sampleRefractionLut, traceBezelRay, type BezelHeightFn, type BezelHeightProfileName, type BezelRayTrace, type BezelRayTraceInput, type RefractionProfileLut, type RefractionProfileName, type RefractionProfileOptions, type RefractionProfileSpec, } from './refractProfile.ts';
11
13
  export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER, createGlassOverlayRenderer, } from './overlayRenderer.ts';
12
- export { clamp, createElasticPressController, createMorphTimeline, createSpringChannel, cubicBezier, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, evaluateSpringState, lerp, riseAndFall, smoothstep, type ElasticPressController, type ElasticPressOptions, type ElasticPressState, type MorphTimeline, type MorphTimelineOptions, type MorphTimelinePhase, type MorphTimelineState, type SpringChannel, type SpringChannelOptions, type SpringChannelState, type SpringSample, } from './physics.ts';
13
- export { buildCircularBevelTable, buildColorOpticsMatrix, buildContourAlphaDataUrl, interpolateCssGlassSurfaceToMaterial, interpolateOpticalMaterial, interpolateVeilOptics, parseCssBoxShadow, parseCssFilterOptics, parseCssGlassSurface, parseCssRgba, resolveOpticalMaterial, type BackdropVeilOptics, type CircularBevelTable, type ExtractedCssGlassSurface, type ParseCssGlassSurfaceInput, type ParsedBoxShadowLayer, } from './optics.ts';
14
+ export { clamp, computeAreaPreservingScale, createElasticPressController, createMorphTimeline, createSpringChannel, cubicBezier, deformSizePreservingArea, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, evaluateSpringState, lerp, riseAndFall, smoothstep, type AreaPreservingScale, type ElasticPressController, type ElasticPressOptions, type ElasticPressState, type MorphTimeline, type MorphTimelineOptions, type MorphTimelinePhase, type MorphTimelineState, type SpringChannel, type SpringChannelOptions, type SpringChannelState, type SpringSample, } from './physics.ts';
15
+ export { buildCircularBevelTable, buildColorOpticsMatrix, buildContourAlphaDataUrl, interpolateCssGlassSurfaceToMaterial, interpolateOpticalMaterial, interpolateVeilOptics, parseCssBoxShadow, parseCssFilterOptics, parseCssGlassSurface, parseCssRgba, tryParseCssRgba, resolveOpticalMaterial, type BackdropVeilOptics, type CircularBevelTable, type ExtractedCssGlassSurface, type ParseCssGlassSurfaceInput, type ParsedBoxShadowLayer, } from './optics.ts';
16
+ export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, computeBackdropRisk, contrastRatio, createAsymmetricSmoother, createLegibilityParams, createTelemetryAccumulator, linearToSrgb, measureTelemetryGrid, relativeLuminance, srgbLuma, resolveLegibilityGoal, resolveLegibilityParams, srgbToLinear, type AsymmetricSmoother, type AsymmetricSmootherOptions, type BackdropTelemetry, type BackdropTelemetryAccumulator, type BackdropTelemetryGrid, type ForegroundPolarity, type LegibilityGoal, type LegibilityParams, type LegibilityPolicy, type LegibilityRisk, type LegibilityTarget, type LegibilityTier, } from './legibility.ts';
package/dist/index.js CHANGED
@@ -8,6 +8,9 @@ export { DEFAULT_OPTICAL_MATERIALS, DEFAULT_SPRINGS, MAX_GPU_PRIMITIVES, } from
8
8
  export { computeFieldBounds, computePairMergeStatus, computeRoundedBoxDistance, computeRoundedBoxSdf, computeSmin, computeSminDistance, createPreparedField, evaluateFieldDistance, evaluateFieldSdf, prepareField, } from "./sdf.js";
9
9
  export { extractFieldContourPath, formatRoundedRectPath, } from "./contour.js";
10
10
  export { buildRefractMapDataUrl, createRefractMapBuilder, } from "./refractMap.js";
11
+ export { MAX_REFRACT_TILE_PX, clearRefractTilesCache, resolveRefractTiles, } from "./refractTiles.js";
12
+ export { BEZEL_HEIGHT_PROFILES, CAUSTIC_FOLD_LIMIT, DEFAULT_REFRACTION_IOR, DEFAULT_REFRACTION_SAMPLES, NORMAL_FLOOR, computeRefractionProfileLut, getRefractionProfileKey, resolveRefractionProfileLut, sampleRefractionLut, traceBezelRay, } from "./refractProfile.js";
11
13
  export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER, createGlassOverlayRenderer, } from "./overlayRenderer.js";
12
- export { clamp, createElasticPressController, createMorphTimeline, createSpringChannel, cubicBezier, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, evaluateSpringState, lerp, riseAndFall, smoothstep, } from "./physics.js";
13
- export { buildCircularBevelTable, buildColorOpticsMatrix, buildContourAlphaDataUrl, interpolateCssGlassSurfaceToMaterial, interpolateOpticalMaterial, interpolateVeilOptics, parseCssBoxShadow, parseCssFilterOptics, parseCssGlassSurface, parseCssRgba, resolveOpticalMaterial, } from "./optics.js";
14
+ export { clamp, computeAreaPreservingScale, createElasticPressController, createMorphTimeline, createSpringChannel, cubicBezier, deformSizePreservingArea, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, evaluateSpringState, lerp, riseAndFall, smoothstep, } from "./physics.js";
15
+ export { buildCircularBevelTable, buildColorOpticsMatrix, buildContourAlphaDataUrl, interpolateCssGlassSurfaceToMaterial, interpolateOpticalMaterial, interpolateVeilOptics, parseCssBoxShadow, parseCssFilterOptics, parseCssGlassSurface, parseCssRgba, tryParseCssRgba, resolveOpticalMaterial, } from "./optics.js";
16
+ export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, computeBackdropRisk, contrastRatio, createAsymmetricSmoother, createLegibilityParams, createTelemetryAccumulator, linearToSrgb, measureTelemetryGrid, relativeLuminance, srgbLuma, resolveLegibilityGoal, resolveLegibilityParams, srgbToLinear, } from "./legibility.js";
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Adaptive backdrop legibility kernel.
3
+ *
4
+ * The host fixes the foreground (text color, polarity, target contrast); the glass yields.
5
+ * Every quantity here is expressed in sRGB-encoded relative luminance ("encoded luminance"),
6
+ * the domain browsers composite in, so veil-over-backdrop blending stays affine and WCAG
7
+ * bounds convert exactly for neutrals.
8
+ *
9
+ * The per-pixel stage is a luminance-keyed multiplicative film evaluated by the Route B3 SVG
10
+ * filter: `out = c * M(x)` for light text and `1 - out = (1 - c) * M(x)` for dark text. Scaling
11
+ * all channels by one factor keeps hue and saturation (no signed chroma intermediates, no gamut
12
+ * clipping) while absolute chroma converges exactly where luminance is compressed.
13
+ *
14
+ * SPDX-License-Identifier: MPL-2.0
15
+ */
16
+ import type { BackdropVeilOptics } from './optics.ts';
17
+ export type LegibilityTier = 'clear' | 'regular' | 'legible';
18
+ export type ForegroundPolarity = 'light' | 'dark';
19
+ /** Material response of one legibility tier. Gains and floors are reached at full risk. */
20
+ export interface LegibilityPolicy {
21
+ /** WCAG 2 contrast ratio the foreground keeps against the composited glass. */
22
+ contrast: number;
23
+ /**
24
+ * Fraction of the safe limit where the soft knee starts bending at full luminance risk, in
25
+ * `(0, LEGIBILITY_CALM_KNEE)`. A calm backdrop keeps a harder shoulder that spares mid-tones;
26
+ * the ceiling itself always holds, because aggregate telemetry cannot see a small bright
27
+ * patch (a speech balloon) that still sits under the text.
28
+ */
29
+ knee: number;
30
+ /** Uniform film alpha added on the veil at full risk. */
31
+ filmMax: number;
32
+ /** Backdrop saturation multiplier at full chroma risk. */
33
+ saturationFloor: number;
34
+ /** Extra backdrop blur in CSS px at full detail risk. */
35
+ blurBoostPx: number;
36
+ /** Displacement-scale multiplier at full detail risk (never re-encodes the map). */
37
+ refractionFloor: number;
38
+ /** Relative hairline and rim alpha gain at full risk. */
39
+ edgeGain: number;
40
+ /** Relative outer-shadow alpha gain at full luminance risk. */
41
+ shadowGain: number;
42
+ /** Risk assumed on every channel while no telemetry is available. */
43
+ assumedRisk: number;
44
+ }
45
+ export declare const LEGIBILITY_POLICIES: {
46
+ readonly clear: {
47
+ readonly contrast: 3;
48
+ readonly knee: 0.72;
49
+ readonly filmMax: 0.06;
50
+ readonly saturationFloor: 0.88;
51
+ readonly blurBoostPx: 1.5;
52
+ readonly refractionFloor: 0.85;
53
+ readonly edgeGain: 0.35;
54
+ readonly shadowGain: 0.4;
55
+ readonly assumedRisk: 0.3;
56
+ };
57
+ readonly regular: {
58
+ readonly contrast: 4.5;
59
+ readonly knee: 0.7;
60
+ readonly filmMax: 0.14;
61
+ readonly saturationFloor: 0.72;
62
+ readonly blurBoostPx: 3;
63
+ readonly refractionFloor: 0.65;
64
+ readonly edgeGain: 0.6;
65
+ readonly shadowGain: 0.8;
66
+ readonly assumedRisk: 0.5;
67
+ };
68
+ readonly legible: {
69
+ readonly contrast: 7;
70
+ readonly knee: 0.65;
71
+ readonly filmMax: 0.26;
72
+ readonly saturationFloor: 0.55;
73
+ readonly blurBoostPx: 6;
74
+ readonly refractionFloor: 0.4;
75
+ readonly edgeGain: 0.9;
76
+ readonly shadowGain: 1.2;
77
+ readonly assumedRisk: 0.8;
78
+ };
79
+ };
80
+ /**
81
+ * Attack is fast so text never sits on an unsafe backdrop for more than a few frames; hold and
82
+ * release bridge the calm gutters between cards so scrolling across a grid does not strobe.
83
+ */
84
+ export declare const LEGIBILITY_SMOOTHING: {
85
+ readonly attackMs: 90;
86
+ readonly holdMs: 240;
87
+ readonly releaseMs: 700;
88
+ readonly epsilon: 0.004;
89
+ };
90
+ /** Knee fraction used at zero luminance risk. */
91
+ export declare const LEGIBILITY_CALM_KNEE = 0.9;
92
+ /** Samples in each per-pixel multiplier table (`feFunc* type="table"`). */
93
+ export declare const LEGIBILITY_TABLE_SIZE = 33;
94
+ /**
95
+ * Filter-graph contract for the per-pixel stage, keyed by polarity.
96
+ * `k` are `feComposite operator="arithmetic"` coefficients with `in` = color, `in2` = multiplier.
97
+ * Light text keys on true luminance (`linearRGB` matrix): sRGB luma underestimates saturated
98
+ * colors (pure red has luma 0.21 but encoded luminance ~0.50) and would leave them unclamped.
99
+ * Dark text keys on sRGB luma, which only ever underestimates, so the lift errs on the safe side
100
+ * and avoids quantizing shadows in an 8-bit linear buffer.
101
+ */
102
+ export declare const LEGIBILITY_STAGES: {
103
+ readonly light: {
104
+ readonly luminanceSpace: "linearRGB";
105
+ readonly k: readonly [1, 0, 0, 0];
106
+ };
107
+ readonly dark: {
108
+ readonly luminanceSpace: "sRGB";
109
+ readonly k: readonly [1, 0, -1, 1];
110
+ };
111
+ };
112
+ /**
113
+ * Encoded-luminance headroom kept below the exact limit. Covers the residual error of
114
+ * scaling in sRGB space (the transfer curve is not a pure power law), veil blending of colored
115
+ * pixels, and 8-bit filter intermediates; sized by the reference-model sweep in the unit tests.
116
+ */
117
+ export declare const LEGIBILITY_LIMIT_MARGIN = 0.008;
118
+ export interface LegibilityTarget {
119
+ /** Foreground text color as normalized sRGB `[r, g, b]` (a trailing alpha is ignored). */
120
+ foreground: readonly number[];
121
+ /** Tier preset (defaults to `'regular'`). */
122
+ tier?: LegibilityTier;
123
+ /** Overrides the tier's WCAG contrast ratio. */
124
+ contrast?: number;
125
+ /** Overrides the polarity inferred from the foreground luminance. */
126
+ polarity?: ForegroundPolarity;
127
+ }
128
+ export interface LegibilityGoal {
129
+ readonly polarity: ForegroundPolarity;
130
+ readonly contrast: number;
131
+ readonly policy: LegibilityPolicy;
132
+ /** Encoded-luminance bound the composited glass must stay beyond (ceiling for light text, floor for dark). */
133
+ readonly perceivedLimit: number;
134
+ }
135
+ /**
136
+ * Backdrop statistics under a glass region, in encoded luminance and sRGB channel units.
137
+ * Hosts may inject these directly or let a probe aggregate them.
138
+ */
139
+ export interface BackdropTelemetry {
140
+ /** Bright-tail encoded luminance (about the 95th percentile). */
141
+ lumaHigh: number;
142
+ /**
143
+ * Dark tail (about the 5th percentile) of sRGB luma (`srgbLuma`). Dark text needs a lower
144
+ * bound that survives per-channel lifts: by Jensen's inequality luma never exceeds encoded
145
+ * luminance, and unlike luminance it moves exactly affinely under per-channel
146
+ * `brightness`/`contrast` and the fallback lift, so a lift solved on it holds on saturated
147
+ * pixels too.
148
+ */
149
+ lumaLow: number;
150
+ /**
151
+ * Bright tail (about the 95th percentile) of each pixel's largest sRGB channel. Host
152
+ * brightness/contrast clip per channel, so luminance alone cannot bound a colored backdrop
153
+ * under them. Omitted, the backdrop is assumed neutral (`lumaHigh`).
154
+ */
155
+ channelHigh?: number;
156
+ /** Dark tail (about the 5th percentile) of each pixel's smallest sRGB channel; defaults to `lumaLow`. */
157
+ channelLow?: number;
158
+ /** Mean chroma (`max - min` of the sRGB channels). */
159
+ chroma: number;
160
+ /** Mean absolute luminance gradient per pixel, scaled to roughly `[0, 1]` (dense text reads high). */
161
+ detail: number;
162
+ }
163
+ export interface LegibilityRisk {
164
+ luma: number;
165
+ chroma: number;
166
+ detail: number;
167
+ }
168
+ /** Telemetry floats per grid cell: `lumaHigh, lumaLow, channelHigh, channelLow, chroma, detail`. */
169
+ export declare const TELEMETRY_STRIDE = 6;
170
+ export interface BackdropTelemetryGrid {
171
+ cols: number;
172
+ rows: number;
173
+ /** `cols * rows * TELEMETRY_STRIDE` floats, row-major. */
174
+ data: Float32Array;
175
+ }
176
+ /** Preallocated solver output; `resolveLegibilityParams` rewrites it in place. */
177
+ export interface LegibilityParams {
178
+ polarity: ForegroundPolarity;
179
+ /** Per-pixel multiplier `M` sampled uniformly over the luminance index `[0, 1]`. */
180
+ readonly table: Float32Array;
181
+ /** Increments whenever `table` changes beyond 8-bit precision, so consumers rewrite filter nodes only then. */
182
+ tableRevision: number;
183
+ /** Veil tint with the uniform film composited over it, normalized RGBA. */
184
+ readonly veilRgba: Float32Array;
185
+ blurBoostPx: number;
186
+ refractionScale: number;
187
+ saturationScale: number;
188
+ hairlineScale: number;
189
+ shadowScale: number;
190
+ /**
191
+ * Whole-backdrop correction for paths without the per-pixel filter. Apply it as its own
192
+ * `brightness`/`contrast` stage after the host's veil optics: CSS clamps between filter
193
+ * functions and the risk is solved on that clamped output, so folding it into the host pair
194
+ * would let an over-brightened backdrop escape the ceiling.
195
+ */
196
+ readonly fallbackVeil: BackdropVeilOptics;
197
+ /** Encoded-luminance limit the backdrop is compressed toward after the film. */
198
+ backdropLimit: number;
199
+ /** `false` when the veil tint alone already violates the goal. */
200
+ feasible: boolean;
201
+ }
202
+ export declare function srgbToLinear(c: number): number;
203
+ export declare function linearToSrgb(l: number): number;
204
+ /** WCAG 2 relative luminance of a normalized sRGB color. */
205
+ /** Rec. 709 weights applied to the encoded sRGB channels; a lower bound on encoded luminance. */
206
+ export declare function srgbLuma(r: number, g: number, b: number): number;
207
+ export declare function relativeLuminance(r: number, g: number, b: number): number;
208
+ /** WCAG 2 contrast ratio between two relative luminances. */
209
+ export declare function contrastRatio(a: number, b: number): number;
210
+ /** Resolves the host declaration into a polarity and an encoded-luminance limit. */
211
+ export declare function resolveLegibilityGoal(target: LegibilityTarget): LegibilityGoal;
212
+ /**
213
+ * Maps backdrop telemetry to `[0, 1]` risk per channel for the given goal and base veil.
214
+ * Telemetry describes the raw page, but the glass shows it after the host's `optics`, and the
215
+ * fallback correction runs after those optics too. The optics clip each channel, so a colored
216
+ * pixel's output luminance is not a function of its input luminance. It is bounded instead:
217
+ * - by the optics applied to its extreme channel, since luminance lies between min and max
218
+ * channel and the optics are monotonic;
219
+ * - by `L + D`, where `D` is the extreme of `f(x) - x` over its channel range. The dark tail is
220
+ * sRGB luma, a weighted mean of the channels, so this holds exactly; the bright tail is
221
+ * encoded luminance, a translated power mean, which by Minkowski's inequality moves no
222
+ * further than a shift applied to every channel.
223
+ * Both bounds are exact for neutral pixels and collapse to `L` under identity optics, so the
224
+ * estimate stays continuous as the host's optics change. Chroma and gradients scale by the
225
+ * affine slope.
226
+ *
227
+ * `saturation` is the host's `saturate()`, which runs first: `x' = luma + s * (x - luma)` per
228
+ * channel, then clipped. Desaturating never clips, keeps sRGB luma and (by Jensen) never raises
229
+ * encoded luminance, so only `s > 1` matters; there each clipped channel moves by at most
230
+ * `(s - 1)` times the channel spread, a bounded shift that widens the channel range and the
231
+ * luminance tails by the same amount. The legibility response only ever lowers saturation, so
232
+ * the host's value bounds the effective one.
233
+ */
234
+ export declare function computeBackdropRisk(telemetry: BackdropTelemetry, goal: LegibilityGoal, veilRgba: ArrayLike<number>, out: LegibilityRisk, optics?: BackdropVeilOptics, saturation?: number): LegibilityRisk;
235
+ export declare function createLegibilityParams(): LegibilityParams;
236
+ /**
237
+ * Solves the material response for the smoothed `risk` and writes it into `out`.
238
+ * Allocation-free; returns `true` when any output changed.
239
+ */
240
+ export declare function resolveLegibilityParams(goal: LegibilityGoal, risk: LegibilityRisk, baseVeilRgba: ArrayLike<number>, out: LegibilityParams): boolean;
241
+ /**
242
+ * Area-weighted telemetry accumulator. Tails use a quadratic mean so a small bright patch still
243
+ * outweighs its area share, while the slope at small coverage stays bounded: a plain max (or a
244
+ * high power mean) would jump the moment a sliver of a white card enters the glass rect, which
245
+ * shows up as a material seam when primitives merge or scroll across card edges.
246
+ */
247
+ export interface BackdropTelemetryAccumulator {
248
+ readonly weight: number;
249
+ reset(): void;
250
+ add(telemetry: BackdropTelemetry, weight: number): void;
251
+ /** Adds one `TELEMETRY_STRIDE` record from a grid or flat buffer without allocating. */
252
+ addRecord(data: ArrayLike<number>, offset: number, weight: number): void;
253
+ /** Writes the aggregate into `out`; returns `false` (leaving `out` untouched) when nothing was added. */
254
+ resolve(out: BackdropTelemetry): boolean;
255
+ }
256
+ export declare function createTelemetryAccumulator(): BackdropTelemetryAccumulator;
257
+ /**
258
+ * Measures a `cols x rows` telemetry grid from straight (non-premultiplied) RGBA bytes.
259
+ * Runs once per source image, never per frame; callers obtain pixels through normal
260
+ * same-origin or CORS-approved channels only.
261
+ */
262
+ export declare function measureTelemetryGrid(rgba: ArrayLike<number>, width: number, height: number, cols: number, rows: number): BackdropTelemetryGrid;
263
+ export interface AsymmetricSmootherOptions {
264
+ attackMs: number;
265
+ /** Time a falling target must persist before release starts (defaults to `0`). */
266
+ holdMs?: number;
267
+ releaseMs: number;
268
+ /** Distance under which a channel snaps to its target and counts as settled (defaults to `1e-3`). */
269
+ epsilon?: number;
270
+ }
271
+ /**
272
+ * Frame-rate independent attack/hold/release smoother over a fixed channel count.
273
+ * Rising targets follow `attackMs`; falling targets wait `holdMs`, then follow `releaseMs`.
274
+ */
275
+ export interface AsymmetricSmoother {
276
+ readonly values: Float32Array;
277
+ /** Advances by `dtMs` toward `target`; returns `true` once every channel has settled. */
278
+ step(target: ArrayLike<number>, dtMs: number): boolean;
279
+ reset(values: ArrayLike<number> | number): void;
280
+ }
281
+ export declare function createAsymmetricSmoother(channels: number, options: AsymmetricSmootherOptions): AsymmetricSmoother;