@sessile/core 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ export { extractFieldContourPath, formatRoundedRectPath, } from './contour.ts';
10
10
  export { buildRefractMapDataUrl, createRefractMapBuilder, type RefractMapBuilder, type RefractMapParams, type RefractMapResult, } from './refractMap.ts';
11
11
  export { MAX_REFRACT_TILE_PX, clearRefractTilesCache, resolveRefractTiles, type RefractTileParams, type RefractTilesResult, } from './refractTiles.ts';
12
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';
13
- export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER, createGlassOverlayRenderer, } from './overlayRenderer.ts';
13
+ export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER, createGlassOverlayRenderer, type GlassOverlayRendererOptions, } from './overlayRenderer.ts';
14
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
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';
16
+ export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, compensateLegibilityEdges, 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
@@ -13,4 +13,4 @@ export { BEZEL_HEIGHT_PROFILES, CAUSTIC_FOLD_LIMIT, DEFAULT_REFRACTION_IOR, DEFA
13
13
  export { OVERLAY_FRAGMENT_SHADER, OVERLAY_VERTEX_SHADER, createGlassOverlayRenderer, } from "./overlayRenderer.js";
14
14
  export { clamp, computeAreaPreservingScale, createElasticPressController, createMorphTimeline, createSpringChannel, cubicBezier, deformSizePreservingArea, easeInOutCubic, easeInQuad, easeOutCubic, evaluateSpring, evaluateSpringState, lerp, riseAndFall, smoothstep, } from "./physics.js";
15
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";
16
+ export { LEGIBILITY_CALM_KNEE, LEGIBILITY_LIMIT_MARGIN, LEGIBILITY_POLICIES, LEGIBILITY_SMOOTHING, LEGIBILITY_STAGES, LEGIBILITY_TABLE_SIZE, TELEMETRY_STRIDE, compensateLegibilityEdges, computeBackdropRisk, contrastRatio, createAsymmetricSmoother, createLegibilityParams, createTelemetryAccumulator, linearToSrgb, measureTelemetryGrid, relativeLuminance, srgbLuma, resolveLegibilityGoal, resolveLegibilityParams, srgbToLinear, } from "./legibility.js";
@@ -13,6 +13,7 @@
13
13
  *
14
14
  * SPDX-License-Identifier: MPL-2.0
15
15
  */
16
+ import type { OpticalMaterial } from './contracts.ts';
16
17
  import type { BackdropVeilOptics } from './optics.ts';
17
18
  export type LegibilityTier = 'clear' | 'regular' | 'legible';
18
19
  export type ForegroundPolarity = 'light' | 'dark';
@@ -233,6 +234,12 @@ export declare function resolveLegibilityGoal(target: LegibilityTarget): Legibil
233
234
  */
234
235
  export declare function computeBackdropRisk(telemetry: BackdropTelemetry, goal: LegibilityGoal, veilRgba: ArrayLike<number>, out: LegibilityRisk, optics?: BackdropVeilOptics, saturation?: number): LegibilityRisk;
235
236
  export declare function createLegibilityParams(): LegibilityParams;
237
+ /**
238
+ * Writes `material` with the edge response applied into `out` and returns it. Only alphas scale:
239
+ * blur radii and offsets feed surface bounds, so moving them would resize the overlay mid-flight.
240
+ * Static surfaces and morph overlays both draw through this, so one response yields one edge.
241
+ */
242
+ export declare function compensateLegibilityEdges(material: OpticalMaterial, params: Pick<LegibilityParams, 'hairlineScale' | 'shadowScale'>, out: OpticalMaterial): OpticalMaterial;
236
243
  /**
237
244
  * Solves the material response for the smoothed `risk` and writes it into `out`.
238
245
  * Allocation-free; returns `true` when any output changed.
@@ -271,6 +271,28 @@ export function createLegibilityParams() {
271
271
  feasible: true,
272
272
  };
273
273
  }
274
+ /**
275
+ * Writes `material` with the edge response applied into `out` and returns it. Only alphas scale:
276
+ * blur radii and offsets feed surface bounds, so moving them would resize the overlay mid-flight.
277
+ * Static surfaces and morph overlays both draw through this, so one response yields one edge.
278
+ */
279
+ export function compensateLegibilityEdges(material, params, out) {
280
+ Object.assign(out, material);
281
+ // Object.assign never clears optional keys a previous material set and this one omits.
282
+ out.borderWidth = material.borderWidth;
283
+ out.borderRgba = material.borderRgba;
284
+ out.rimBottomRatio = material.rimBottomRatio;
285
+ out.bevelProfile = material.bevelProfile;
286
+ out.lightAngle = material.lightAngle;
287
+ out.lightElevation = material.lightElevation;
288
+ out.rimShade = material.rimShade;
289
+ out.hairlineSideAlpha = clamp(material.hairlineSideAlpha * params.hairlineScale, 0, 1);
290
+ out.hairlineCornerAlpha = clamp(material.hairlineCornerAlpha * params.hairlineScale, 0, 1);
291
+ out.hairlineFlatAlpha = clamp(material.hairlineFlatAlpha * params.hairlineScale, 0, 1);
292
+ out.rimOpacity = clamp(material.rimOpacity * params.hairlineScale, 0, 1);
293
+ out.shadowAlpha = clamp(material.shadowAlpha * params.shadowScale, 0, 1);
294
+ return out;
295
+ }
274
296
  /**
275
297
  * Soft-knee ceiling in risk space: identity below `knee`, then a rational shoulder whose slope is
276
298
  * continuous at the knee and which lands exactly on `ceiling` at `u = 1`, so the guarantee holds
package/dist/optics.d.ts CHANGED
@@ -68,12 +68,18 @@ export declare function buildCircularBevelTable(bezel: number, blurStd?: number,
68
68
  export declare function buildColorOpticsMatrix(saturate: number, brightness: number, contrast: number, contrastFirst?: boolean): string;
69
69
  /** Encodes a contour SVG path as an inline Data URL for use as an `feImage` alpha mask. */
70
70
  export declare function buildContourAlphaDataUrl(contourPath: string, width: number, height: number): string;
71
- /** Parses a browser-computed `rgb(...)`, `rgba(...)`, or `color(srgb ...)` string into normalized `[0..1]` RGBA. */
71
+ /**
72
+ * Parses a browser-computed `rgb(...)`, `rgba(...)`, `color(srgb ...)`, `oklab(...)` or
73
+ * `oklch(...)` string into normalized `[0..1]` sRGB RGBA.
74
+ */
72
75
  export declare function parseCssRgba(color: string): [number, number, number, number];
73
76
  /**
74
77
  * Like `parseCssRgba`, but returns `null` instead of transparent black for anything it cannot
75
78
  * resolve (`var()`, percentage `color(srgb ...)` channels, other color spaces), so callers can
76
79
  * tell a real transparent color from an unsupported one.
80
+ *
81
+ * Browsers serialize `color-mix()` and alpha-modified theme colors (Tailwind's `text-white/90`)
82
+ * as `oklab()` / `oklch()`, so a host reading computed styles meets these routinely.
77
83
  */
78
84
  export declare function tryParseCssRgba(color: string): [number, number, number, number] | null;
79
85
  /** Extracts `brightness(...)` and `contrast(...)` affine composition from a CSS filter string. */
package/dist/optics.js CHANGED
@@ -104,7 +104,10 @@ export function buildContourAlphaDataUrl(contourPath, width, height) {
104
104
  const svgDoc = `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}"><path d="${contourPath}" fill="white"/></svg>`;
105
105
  return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgDoc)}`;
106
106
  }
107
- /** Parses a browser-computed `rgb(...)`, `rgba(...)`, or `color(srgb ...)` string into normalized `[0..1]` RGBA. */
107
+ /**
108
+ * Parses a browser-computed `rgb(...)`, `rgba(...)`, `color(srgb ...)`, `oklab(...)` or
109
+ * `oklch(...)` string into normalized `[0..1]` sRGB RGBA.
110
+ */
108
111
  export function parseCssRgba(color) {
109
112
  return tryParseCssRgba(color) ?? [0, 0, 0, 0];
110
113
  }
@@ -112,6 +115,9 @@ export function parseCssRgba(color) {
112
115
  * Like `parseCssRgba`, but returns `null` instead of transparent black for anything it cannot
113
116
  * resolve (`var()`, percentage `color(srgb ...)` channels, other color spaces), so callers can
114
117
  * tell a real transparent color from an unsupported one.
118
+ *
119
+ * Browsers serialize `color-mix()` and alpha-modified theme colors (Tailwind's `text-white/90`)
120
+ * as `oklab()` / `oklch()`, so a host reading computed styles meets these routinely.
115
121
  */
116
122
  export function tryParseCssRgba(color) {
117
123
  const trimmed = color.trim().toLowerCase();
@@ -129,6 +135,34 @@ export function tryParseCssRgba(color) {
129
135
  return [r, g, b, clamp(a, 0, 1)];
130
136
  }
131
137
  }
138
+ const okMatch = trimmed.match(/^ok(lab|lch)\(\s*([^)]+)\s*\)$/);
139
+ if (okMatch) {
140
+ const [channels, alphaRaw] = okMatch[2].split('/');
141
+ const parts = channels.trim().split(/\s+/);
142
+ if (parts.length === 3) {
143
+ const polar = okMatch[1] === 'lch';
144
+ // Percent references: L 100% = 1, a/b/C 100% = 0.4 (CSS Color 4).
145
+ const num = (token, percentScale) => token === 'none' ? 0 : token.endsWith('%') ? (parseFloat(token) / 100) * percentScale : parseFloat(token);
146
+ const l = num(parts[0], 1);
147
+ let a = num(parts[1], 0.4);
148
+ let b = num(parts[2], 0.4);
149
+ if (polar) {
150
+ const hue = ((parts[2] === 'none' ? 0 : parseFloat(parts[2])) * Math.PI) / 180;
151
+ b = a * Math.sin(hue);
152
+ a = a * Math.cos(hue);
153
+ }
154
+ const alphaToken = alphaRaw?.trim();
155
+ const alpha = alphaToken === undefined || alphaToken === 'none'
156
+ ? 1
157
+ : alphaToken.endsWith('%')
158
+ ? parseFloat(alphaToken) / 100
159
+ : parseFloat(alphaToken);
160
+ if ([l, a, b, alpha].every(Number.isFinite)) {
161
+ const [r, g, bl] = oklabToSrgb(l, a, b);
162
+ return [r, g, bl, clamp(alpha, 0, 1)];
163
+ }
164
+ }
165
+ }
132
166
  const rgbMatch = trimmed.match(/^rgba?\(\s*([^)]+)\s*\)$/);
133
167
  if (rgbMatch) {
134
168
  const body = rgbMatch[1].replace(/\//g, ' ').trim();
@@ -150,6 +184,21 @@ export function tryParseCssRgba(color) {
150
184
  }
151
185
  return null;
152
186
  }
187
+ /** OKLab to gamma-encoded sRGB (Björn Ottosson's matrices); out-of-gamut channels are clipped. */
188
+ function oklabToSrgb(l, a, b) {
189
+ const lc = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
190
+ const mc = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
191
+ const sc = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
192
+ const encode = (linear) => {
193
+ const x = clamp(linear, 0, 1);
194
+ return x <= 0.0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055;
195
+ };
196
+ return [
197
+ encode(4.0767416621 * lc - 3.3077115913 * mc + 0.2309699292 * sc),
198
+ encode(-1.2684380046 * lc + 2.6097574011 * mc - 0.3413193965 * sc),
199
+ encode(-0.0041960863 * lc - 0.7034186147 * mc + 1.707614701 * sc),
200
+ ];
201
+ }
153
202
  const VEIL_SINGULAR_EPS = 1e-6;
154
203
  function veilOpticsToAffine(veil) {
155
204
  const scale = veil.brightness * veil.contrast;
@@ -15,11 +15,26 @@
15
15
  */
16
16
  import type { IGlassOverlayRenderer } from './contracts.ts';
17
17
  export declare const OVERLAY_VERTEX_SHADER = "#version 300 es\nprecision highp float;\n\nout vec2 vUv;\n\nvoid main() {\n vec2 pos = vec2(\n (gl_VertexID == 1) ? 3.0 : -1.0,\n (gl_VertexID == 2) ? 3.0 : -1.0\n );\n vUv = pos * 0.5 + 0.5;\n gl_Position = vec4(pos, 0.0, 1.0);\n}\n";
18
- export declare const OVERLAY_FRAGMENT_SHADER = "#version 300 es\nprecision highp float;\n\n#define MAX_PRIMITIVES 16\n\nin vec2 vUv;\nout vec4 fragColor;\n\nuniform vec2 uViewport;\nuniform float uDpr;\nuniform int uPrimitiveCount;\nuniform vec4 uPrimitives[MAX_PRIMITIVES]; // (cx, cy, halfW, halfH) in local CSS px\nuniform float uRadii[MAX_PRIMITIVES];\nuniform float uBlendK;\nuniform float uRimOpacity;\nuniform float uStyleMix;\nuniform float uOpacity;\n\nuniform vec4 uRimParams; // (material.rimOpacity, material.rimWidth, material.rimTail, material.rimFocus)\nuniform vec4 uHairline; // (width, sideAlpha, cornerAlpha, flatAlpha)\nuniform vec3 uShadow; // (blur, offsetY, alpha)\nuniform vec4 uBorderColor; // normalized RGBA of optional uniform inner border\nuniform vec2 uBorderParams; // (borderWidthPx, rimBottomRatio)\nuniform vec4 uPhysicalLight; // (lx, ly, lz, enabled)\nuniform vec4 uPhysicalParams; // (bevelPx, specularStrength, shadeStrength, profileCode)\n\nstruct SdfSample {\n float dist;\n vec2 normal;\n};\n\nfloat safePow(float x, float y) {\n return (x <= 1e-6) ? 0.0 : pow(x, y);\n}\n\nfloat computeDirectionalRimWeight(vec2 normal, float focus, float bottomRatio) {\n if (focus < 0.05) {\n return 1.0;\n }\n float topBias = clamp(-normal.y, 0.0, 1.0);\n float botBias = clamp(normal.y, 0.0, 1.0);\n return safePow(max(topBias, botBias * clamp(bottomRatio, 0.0, 1.0)), max(focus, 0.25));\n}\n\nSdfSample sdRoundedBoxRefined(vec2 p, vec2 center, vec2 halfSize, float r) {\n vec2 safeHalf = max(halfSize, vec2(0.001));\n float rad = clamp(r, 0.0, min(safeHalf.x, safeHalf.y));\n vec2 rel = p - center;\n vec2 s = vec2(rel.x >= 0.0 ? 1.0 : -1.0, rel.y >= 0.0 ? 1.0 : -1.0);\n vec2 q = abs(rel) - safeHalf + rad;\n vec2 qPos = max(q, 0.0);\n\n float outside = length(qPos);\n float inside = min(max(q.x, q.y), 0.0);\n float baseDist = outside + inside - rad;\n\n vec2 baseNormal;\n if (q.x > 0.0 && q.y > 0.0) {\n baseNormal = (outside > 1e-5) ? (qPos / outside) * s : normalize(s);\n } else if (q.x > q.y) {\n baseNormal = vec2(s.x, 0.0);\n } else {\n baseNormal = vec2(0.0, s.y);\n }\n\n // Superellipse octant normal refinement within 5 CSS px of the boundary for smooth corner speculars;\n // dist stays exact baseDist for 0px alignment with the Marching Squares contour.\n float rimProximity = smoothstep(5.0, 0.0, abs(baseDist));\n vec2 normal = baseNormal;\n\n if (rimProximity > 0.001 && rad > 1.0 && q.x > 0.0 && q.y > 0.0) {\n const float pExp = 2.55;\n vec2 qn = qPos / rad;\n vec2 grad = vec2(\n safePow(qn.x, pExp - 1.0),\n safePow(qn.y, pExp - 1.0)\n );\n float gl = length(grad);\n if (gl > 1e-5) {\n vec2 superNormal = (grad / gl) * s;\n vec2 mixedN = mix(baseNormal, superNormal, rimProximity);\n float mnl = length(mixedN);\n normal = (mnl > 1e-5) ? (mixedN / mnl) : baseNormal;\n }\n }\n\n return SdfSample(baseDist, normal);\n}\n\nfloat evalBezelHeight(float t, float code) {\n float u = clamp(1.0 - t, 0.0, 1.0);\n if (code > 2.5) {\n float sq = safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n float s = sin(3.14159265 * clamp(t, 0.0, 1.0));\n return sq + 0.14 * s * s;\n }\n if (code > 1.5) {\n return 1.0 - u * u;\n }\n if (code > 0.5) {\n return sqrt(max(0.0, 1.0 - u * u));\n }\n return safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n}\n\nSdfSample evaluateGlassSdf(vec2 p) {\n if (uPrimitiveCount <= 0) {\n return SdfSample(1e6, vec2(0.0, -1.0));\n }\n\n SdfSample acc = sdRoundedBoxRefined(p, uPrimitives[0].xy, uPrimitives[0].zw, uRadii[0]);\n float d = acc.dist;\n vec2 g = acc.normal;\n for (int i = 1; i < MAX_PRIMITIVES; i++) {\n if (i >= uPrimitiveCount) break;\n SdfSample b = sdRoundedBoxRefined(p, uPrimitives[i].xy, uPrimitives[i].zw, uRadii[i]);\n if (uBlendK <= 0.001) {\n if (b.dist < d) {\n d = b.dist;\n g = b.normal;\n }\n } else {\n float h = clamp(0.5 + 0.5 * (b.dist - d) / uBlendK, 0.0, 1.0);\n d = mix(b.dist, d, h) - uBlendK * h * (1.0 - h);\n g = mix(b.normal, g, h);\n }\n }\n\n // Soften cancelling normals in smin saddle necks (NORMAL_FLOOR = 0.25) so speculars never flip 180 degrees.\n float gl = max(length(g), 0.25);\n return SdfSample(d, g / gl);\n}\n\nvoid main() {\n if (uOpacity <= 0.001 || uPrimitiveCount <= 0) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Convert GL UV (bottom-left origin) to local CSS px (top-left origin).\n vec2 pCss = vec2(vUv.x * uViewport.x, (1.0 - vUv.y) * uViewport.y);\n SdfSample sdf = evaluateGlassSdf(pCss);\n float d = sdf.dist;\n vec2 normal = sdf.normal;\n\n float aa = 1.0 / max(uDpr, 1.0);\n float glassMask = smoothstep(0.5 * aa, -0.5 * aa, d);\n float outsideMask = 1.0 - glassMask;\n\n // 1. Outside-only drop shadow (d > 0)\n float shadowA = 0.0;\n if (outsideMask > 0.001 && uShadow.z > 0.001) {\n SdfSample shadowSdf = evaluateGlassSdf(pCss - vec2(0.0, uShadow.y));\n float sigma = max(uShadow.x * 0.5, 1.0);\n float shadowFalloff = 1.0 / (1.0 + exp(clamp(1.65 * shadowSdf.dist / sigma, -12.0, 12.0)));\n shadowA = outsideMask * shadowFalloff * uShadow.z * uOpacity;\n }\n\n // 2. Dark outer hairline: strictly outside when a uniform CSS inner border is present (d >= 0), otherwise straddling the outer edge (d >= -0.25)\n float hw = max(uHairline.x, 0.5 / max(uDpr, 1.0));\n float hairlineHalfW = hw * 0.5;\n float hasUniformBorder = step(0.001, uBorderParams.x);\n float hairlineCenter = mix(-0.25 + hairlineHalfW, hairlineHalfW, hasUniformBorder);\n float hairlineMinD = mix(-0.25 - 0.5 * aa, -0.15 * aa, hasUniformBorder);\n float hairlineBand =\n smoothstep(hairlineHalfW + 0.5 * aa, hairlineHalfW * 0.25, abs(d - hairlineCenter)) *\n smoothstep(hairlineMinD, hairlineMinD + 0.75 * aa, d);\n float hairA = 0.0;\n if (hairlineBand > 0.001) {\n float ax = abs(normal.x);\n float ay = abs(normal.y);\n float cornerW = safePow(clamp(2.0 * ax * ay, 0.0, 1.0), 1.5);\n float sideVsFlat = mix(uHairline.y, uHairline.w, ay * ay);\n float hairlineProfileAlpha = mix(sideVsFlat, uHairline.z, cornerW);\n hairA = hairlineBand * hairlineProfileAlpha * uOpacity;\n }\n\n // 3. Optional 1px uniform inner border + directional/soft inner rim highlight (inset < 5.0 CSS px)\n float inset = max(-d, 0.0);\n float borderMask = 0.0;\n float borderA = 0.0;\n vec3 borderRgb = vec3(0.0);\n if (glassMask > 0.001 && hasUniformBorder > 0.5 && inset < uBorderParams.x + aa) {\n borderMask = smoothstep(uBorderParams.x + 0.5 * aa, max(0.0, uBorderParams.x - 0.5 * aa), inset) * glassMask;\n borderA = clamp(borderMask * uBorderColor.a * uOpacity, 0.0, 1.0);\n borderRgb = uBorderColor.rgb * borderA;\n }\n\n float rimA = 0.0;\n float physLitA = 0.0;\n float physShadeA = 0.0;\n float isPhysicalRim = step(0.5, uPhysicalLight.w) * (1.0 - hasUniformBorder);\n\n if (glassMask > 0.001 && inset < 5.0 && uRimParams.x > 0.001 && isPhysicalRim < 0.5) {\n float ny = abs(normal.y);\n float wDirectional = 1.0 - clamp(uStyleMix, 0.0, 1.0);\n float wSoft = clamp(uStyleMix, 0.0, 1.0) * clamp(uRimOpacity, 0.0, 1.0);\n\n if (hasUniformBorder > 0.5) {\n // Match CSS inset box-shadow: keep inner rim inside the padding edge so the 1px border is not double-brightened\n float padInset = max(inset - uBorderParams.x, 0.0);\n float padMask = 1.0 - borderMask;\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, padInset);\n float tail = exp(-padInset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA = clamp((core + tail) * dirWeight * uRimParams.x * padMask * glassMask * uOpacity, 0.0, 1.0);\n } else {\n if (wDirectional > 0.001) {\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, inset);\n float tail = exp(-inset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA += (core + tail) * dirWeight * uRimParams.x * wDirectional;\n }\n\n if (wSoft > 0.001) {\n float bandT = clamp(inset / 5.0, 0.0, 1.0);\n float steppedT = min(floor(bandT * 9.0) / 9.0, 1.0);\n float bandCurve = mix(safePow(1.0 - bandT, 2.1), safePow(1.0 - steppedT, 2.1), 0.35);\n float rimCoreBoost = 0.65 + 0.35 * smoothstep(1.2, 0.0, inset);\n float angWeight = mix(0.015, 1.0, safePow(ny, 2.1)) * (normal.y < 0.0 ? 1.0 : 0.85);\n rimA += bandCurve * rimCoreBoost * angWeight * uRimParams.x * wSoft;\n }\n\n // Boost specular luminance to match source-over alpha blending expectations\n rimA = clamp(rimA * 1.35 * glassMask * uOpacity, 0.0, 1.0);\n }\n } else if (glassMask > 0.001 && isPhysicalRim > 0.5 && inset < uPhysicalParams.x) {\n float bezelPx = max(uPhysicalParams.x, 1.0);\n float t = clamp(inset / bezelPx, 0.0, 1.0);\n float eps = 0.015;\n float t0 = max(0.0, t - eps);\n float t1 = min(1.0, t + eps);\n float slope = (evalBezelHeight(t1, uPhysicalParams.w) - evalBezelHeight(t0, uPhysicalParams.w)) / max(t1 - t0, 1e-4);\n vec3 N = normalize(vec3(normal * slope, 1.0));\n vec3 L = uPhysicalLight.xyz;\n vec3 H = vec3(L.xy, L.z + 1.0);\n float hLen = max(length(H), 1e-4);\n const float shininess = 36.0;\n float flatBase = safePow(clamp((L.z + 1.0) / hLen, 0.0, 1.0), shininess);\n float denomBase = max(1.0 - flatBase, 1e-4);\n float hDot = clamp(dot(N, H) / hLen, 0.0, 1.0);\n float highlight = max(safePow(hDot, shininess) - flatBase, 0.0) / denomBase;\n vec3 H_bounce = vec3(-L.xy, L.z + 1.0);\n float bDot = clamp(dot(N, H_bounce) / hLen, 0.0, 1.0);\n float bounce = max(safePow(bDot, shininess) - flatBase, 0.0) / denomBase;\n vec2 planar = L.xy / max(length(L.xy), 1e-4);\n float facing = dot(normal, planar);\n float fresnel = safePow(clamp(1.0 - N.z, 0.0, 1.0), 4.0);\n float rimTerm = fresnel * (0.25 + 0.75 * max(facing, 0.0) + 0.45 * max(-facing, 0.0));\n float shadeTerm = safePow(clamp(1.0 - N.z, 0.0, 1.0), 2.5) * (0.45 + 0.55 * max(-facing, 0.0));\n float lit = clamp((uPhysicalParams.y * (highlight + 0.45 * bounce) + uRimParams.x * rimTerm) * glassMask * uOpacity, 0.0, 1.0);\n float dark = clamp(uPhysicalParams.z * shadeTerm * glassMask * uOpacity, 0.0, 1.0) * (1.0 - lit);\n physLitA = lit;\n physShadeA = dark;\n }\n\n // Keep interior strictly transparent when shadow, hairline, border, and rim are all zero\n if (shadowA <= 0.0001 && hairA <= 0.0001 && borderA <= 0.0001 && rimA <= 0.0001 && physLitA <= 0.0001 && physShadeA <= 0.0001) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Premultiplied alpha composite: uniform border over inner/physical rim over hairline and shadow\n float darkA = clamp(shadowA + hairA * (1.0 - shadowA), 0.0, 1.0);\n vec3 shadeColor = vec3(0.03921569, 0.07058824, 0.10980392);\n vec3 afterRimRgb = vec3(rimA + physLitA) + shadeColor * physShadeA;\n float totalRimA = clamp(rimA + physLitA + physShadeA * (1.0 - rimA), 0.0, 1.0);\n float afterRimA = totalRimA + darkA * (1.0 - totalRimA);\n vec3 outRgb = borderRgb + afterRimRgb * (1.0 - borderA);\n float outA = clamp(borderA + afterRimA * (1.0 - borderA), 0.0, 1.0);\n fragColor = vec4(outRgb, outA);\n}\n";
18
+ export declare const OVERLAY_FRAGMENT_SHADER = "#version 300 es\nprecision highp float;\n\n#define MAX_PRIMITIVES 16\n\nin vec2 vUv;\nout vec4 fragColor;\n\nuniform vec2 uViewport;\nuniform float uDpr;\nuniform int uPrimitiveCount;\nuniform vec4 uPrimitives[MAX_PRIMITIVES]; // (cx, cy, halfW, halfH) in local CSS px\nuniform float uRadii[MAX_PRIMITIVES];\nuniform float uBlendK;\nuniform float uRimOpacity;\nuniform float uStyleMix;\nuniform float uOpacity;\n\nuniform vec4 uRimParams; // (material.rimOpacity, material.rimWidth, material.rimTail, material.rimFocus)\nuniform vec4 uHairline; // (width, sideAlpha, cornerAlpha, flatAlpha)\nuniform vec3 uShadow; // (blur, offsetY, alpha)\nuniform vec4 uBorderColor; // normalized RGBA of optional uniform inner border\nuniform vec2 uBorderParams; // (borderWidthPx, rimBottomRatio)\nuniform vec4 uPhysicalLight; // (lx, ly, lz, enabled)\nuniform vec4 uPhysicalParams; // (bevelPx, specularStrength, shadeStrength, profileCode)\n\nstruct SdfSample {\n float dist;\n vec2 normal;\n};\n\nfloat safePow(float x, float y) {\n return (x <= 1e-6) ? 0.0 : pow(x, y);\n}\n\n// Box-filtered coverage of the band lo <= d <= hi over a pixel footprint of width aa. Lines thinner\n// than a pixel keep the same total alpha at every subpixel offset; a smoothstep around the band\n// centre nearly vanishes or doubles as the edge moves, which reads as shimmer while morphing.\nfloat bandCoverage(float d, float lo, float hi, float aa) {\n return clamp(min(d + 0.5 * aa, hi) - max(d - 0.5 * aa, lo), 0.0, aa) / aa;\n}\n\nfloat computeDirectionalRimWeight(vec2 normal, float focus, float bottomRatio) {\n if (focus < 0.05) {\n return 1.0;\n }\n float topBias = clamp(-normal.y, 0.0, 1.0);\n float botBias = clamp(normal.y, 0.0, 1.0);\n return safePow(max(topBias, botBias * clamp(bottomRatio, 0.0, 1.0)), max(focus, 0.25));\n}\n\nSdfSample sdRoundedBoxRefined(vec2 p, vec2 center, vec2 halfSize, float r) {\n vec2 safeHalf = max(halfSize, vec2(0.001));\n float rad = clamp(r, 0.0, min(safeHalf.x, safeHalf.y));\n vec2 rel = p - center;\n vec2 s = vec2(rel.x >= 0.0 ? 1.0 : -1.0, rel.y >= 0.0 ? 1.0 : -1.0);\n vec2 q = abs(rel) - safeHalf + rad;\n vec2 qPos = max(q, 0.0);\n\n float outside = length(qPos);\n float inside = min(max(q.x, q.y), 0.0);\n float baseDist = outside + inside - rad;\n\n vec2 baseNormal;\n if (q.x > 0.0 && q.y > 0.0) {\n baseNormal = (outside > 1e-5) ? (qPos / outside) * s : normalize(s);\n } else if (q.x > q.y) {\n baseNormal = vec2(s.x, 0.0);\n } else {\n baseNormal = vec2(0.0, s.y);\n }\n\n // Superellipse octant normal refinement within 5 CSS px of the boundary for smooth corner speculars;\n // dist stays exact baseDist for 0px alignment with the Marching Squares contour.\n float rimProximity = smoothstep(5.0, 0.0, abs(baseDist));\n vec2 normal = baseNormal;\n\n if (rimProximity > 0.001 && rad > 1.0 && q.x > 0.0 && q.y > 0.0) {\n const float pExp = 2.55;\n vec2 qn = qPos / rad;\n vec2 grad = vec2(\n safePow(qn.x, pExp - 1.0),\n safePow(qn.y, pExp - 1.0)\n );\n float gl = length(grad);\n if (gl > 1e-5) {\n vec2 superNormal = (grad / gl) * s;\n vec2 mixedN = mix(baseNormal, superNormal, rimProximity);\n float mnl = length(mixedN);\n normal = (mnl > 1e-5) ? (mixedN / mnl) : baseNormal;\n }\n }\n\n return SdfSample(baseDist, normal);\n}\n\nfloat evalBezelHeight(float t, float code) {\n float u = clamp(1.0 - t, 0.0, 1.0);\n if (code > 2.5) {\n float sq = safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n float s = sin(3.14159265 * clamp(t, 0.0, 1.0));\n return sq + 0.14 * s * s;\n }\n if (code > 1.5) {\n return 1.0 - u * u;\n }\n if (code > 0.5) {\n return sqrt(max(0.0, 1.0 - u * u));\n }\n return safePow(max(0.0, 1.0 - safePow(u, 4.0)), 0.25);\n}\n\nSdfSample evaluateGlassSdf(vec2 p) {\n if (uPrimitiveCount <= 0) {\n return SdfSample(1e6, vec2(0.0, -1.0));\n }\n\n SdfSample acc = sdRoundedBoxRefined(p, uPrimitives[0].xy, uPrimitives[0].zw, uRadii[0]);\n float d = acc.dist;\n vec2 g = acc.normal;\n for (int i = 1; i < MAX_PRIMITIVES; i++) {\n if (i >= uPrimitiveCount) break;\n SdfSample b = sdRoundedBoxRefined(p, uPrimitives[i].xy, uPrimitives[i].zw, uRadii[i]);\n if (uBlendK <= 0.001) {\n if (b.dist < d) {\n d = b.dist;\n g = b.normal;\n }\n } else {\n float h = clamp(0.5 + 0.5 * (b.dist - d) / uBlendK, 0.0, 1.0);\n d = mix(b.dist, d, h) - uBlendK * h * (1.0 - h);\n g = mix(b.normal, g, h);\n }\n }\n\n // Soften cancelling normals in smin saddle necks (NORMAL_FLOOR = 0.25) so speculars never flip 180 degrees.\n float gl = max(length(g), 0.25);\n return SdfSample(d, g / gl);\n}\n\nvoid main() {\n if (uOpacity <= 0.001 || uPrimitiveCount <= 0) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Convert GL UV (bottom-left origin) to local CSS px (top-left origin).\n vec2 pCss = vec2(vUv.x * uViewport.x, (1.0 - vUv.y) * uViewport.y);\n SdfSample sdf = evaluateGlassSdf(pCss);\n float d = sdf.dist;\n vec2 normal = sdf.normal;\n\n float aa = 1.0 / max(uDpr, 1.0);\n float glassMask = clamp(0.5 - d / aa, 0.0, 1.0);\n float outsideMask = 1.0 - glassMask;\n\n // 1. Outside-only drop shadow (d > 0)\n float shadowA = 0.0;\n if (outsideMask > 0.001 && uShadow.z > 0.001) {\n SdfSample shadowSdf = evaluateGlassSdf(pCss - vec2(0.0, uShadow.y));\n float sigma = max(uShadow.x * 0.5, 1.0);\n float shadowFalloff = 1.0 / (1.0 + exp(clamp(1.65 * shadowSdf.dist / sigma, -12.0, 12.0)));\n shadowA = outsideMask * shadowFalloff * uShadow.z * uOpacity;\n }\n\n // 2. Dark outer hairline: strictly outside when a uniform CSS inner border is present (d >= 0), otherwise straddling the outer edge (d >= -0.25)\n float hw = max(uHairline.x, 0.5 / max(uDpr, 1.0));\n float hasUniformBorder = step(0.001, uBorderParams.x);\n float hairlineLo = mix(-0.25, 0.0, hasUniformBorder);\n float hairlineBand = bandCoverage(d, hairlineLo, hairlineLo + hw, aa);\n float hairA = 0.0;\n if (hairlineBand > 0.001) {\n float ax = abs(normal.x);\n float ay = abs(normal.y);\n float cornerW = safePow(clamp(2.0 * ax * ay, 0.0, 1.0), 1.5);\n float sideVsFlat = mix(uHairline.y, uHairline.w, ay * ay);\n float hairlineProfileAlpha = mix(sideVsFlat, uHairline.z, cornerW);\n hairA = hairlineBand * hairlineProfileAlpha * uOpacity;\n }\n\n // 3. Optional 1px uniform inner border + directional/soft inner rim highlight (inset < 5.0 CSS px)\n float inset = max(-d, 0.0);\n float borderMask = 0.0;\n float borderA = 0.0;\n vec3 borderRgb = vec3(0.0);\n if (hasUniformBorder > 0.5 && d < 0.5 * aa && inset < uBorderParams.x + aa) {\n borderMask = bandCoverage(d, -uBorderParams.x, 0.0, aa);\n borderA = clamp(borderMask * uBorderColor.a * uOpacity, 0.0, 1.0);\n borderRgb = uBorderColor.rgb * borderA;\n }\n\n float rimA = 0.0;\n float physLitA = 0.0;\n float physShadeA = 0.0;\n float isPhysicalRim = step(0.5, uPhysicalLight.w) * (1.0 - hasUniformBorder);\n\n if (glassMask > 0.001 && inset < 5.0 && uRimParams.x > 0.001 && isPhysicalRim < 0.5) {\n float ny = abs(normal.y);\n float wDirectional = 1.0 - clamp(uStyleMix, 0.0, 1.0);\n float wSoft = clamp(uStyleMix, 0.0, 1.0) * clamp(uRimOpacity, 0.0, 1.0);\n\n if (hasUniformBorder > 0.5) {\n // Match CSS inset box-shadow: keep inner rim inside the padding edge so the 1px border is not double-brightened\n float padInset = max(inset - uBorderParams.x, 0.0);\n float padMask = 1.0 - borderMask;\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, padInset);\n float tail = exp(-padInset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA = clamp((core + tail) * dirWeight * uRimParams.x * padMask * glassMask * uOpacity, 0.0, 1.0);\n } else {\n if (wDirectional > 0.001) {\n float dirWeight = computeDirectionalRimWeight(normal, uRimParams.w, uBorderParams.y);\n float core = smoothstep(max(uRimParams.y, 0.4) + 0.6, 0.0, inset);\n float tail = exp(-inset / 1.8) * uRimParams.z * smoothstep(5.0, 3.2, inset);\n rimA += (core + tail) * dirWeight * uRimParams.x * wDirectional;\n }\n\n if (wSoft > 0.001) {\n float bandT = clamp(inset / 5.0, 0.0, 1.0);\n float steppedT = min(floor(bandT * 9.0) / 9.0, 1.0);\n float bandCurve = mix(safePow(1.0 - bandT, 2.1), safePow(1.0 - steppedT, 2.1), 0.35);\n float rimCoreBoost = 0.65 + 0.35 * smoothstep(1.2, 0.0, inset);\n float angWeight = mix(0.015, 1.0, safePow(ny, 2.1)) * (normal.y < 0.0 ? 1.0 : 0.85);\n rimA += bandCurve * rimCoreBoost * angWeight * uRimParams.x * wSoft;\n }\n\n // Boost specular luminance to match source-over alpha blending expectations\n rimA = clamp(rimA * 1.35 * glassMask * uOpacity, 0.0, 1.0);\n }\n } else if (glassMask > 0.001 && isPhysicalRim > 0.5 && inset < uPhysicalParams.x) {\n float bezelPx = max(uPhysicalParams.x, 1.0);\n float t = clamp(inset / bezelPx, 0.0, 1.0);\n float eps = 0.015;\n float t0 = max(0.0, t - eps);\n float t1 = min(1.0, t + eps);\n float slope = (evalBezelHeight(t1, uPhysicalParams.w) - evalBezelHeight(t0, uPhysicalParams.w)) / max(t1 - t0, 1e-4);\n vec3 N = normalize(vec3(normal * slope, 1.0));\n vec3 L = uPhysicalLight.xyz;\n vec3 H = vec3(L.xy, L.z + 1.0);\n float hLen = max(length(H), 1e-4);\n const float shininess = 36.0;\n float flatBase = safePow(clamp((L.z + 1.0) / hLen, 0.0, 1.0), shininess);\n float denomBase = max(1.0 - flatBase, 1e-4);\n float hDot = clamp(dot(N, H) / hLen, 0.0, 1.0);\n float highlight = max(safePow(hDot, shininess) - flatBase, 0.0) / denomBase;\n vec3 H_bounce = vec3(-L.xy, L.z + 1.0);\n float bDot = clamp(dot(N, H_bounce) / hLen, 0.0, 1.0);\n float bounce = max(safePow(bDot, shininess) - flatBase, 0.0) / denomBase;\n vec2 planar = L.xy / max(length(L.xy), 1e-4);\n float facing = dot(normal, planar);\n float fresnel = safePow(clamp(1.0 - N.z, 0.0, 1.0), 4.0);\n float rimTerm = fresnel * (0.25 + 0.75 * max(facing, 0.0) + 0.45 * max(-facing, 0.0));\n float shadeTerm = safePow(clamp(1.0 - N.z, 0.0, 1.0), 2.5) * (0.45 + 0.55 * max(-facing, 0.0));\n float lit = clamp((uPhysicalParams.y * (highlight + 0.45 * bounce) + uRimParams.x * rimTerm) * glassMask * uOpacity, 0.0, 1.0);\n float dark = clamp(uPhysicalParams.z * shadeTerm * glassMask * uOpacity, 0.0, 1.0) * (1.0 - lit);\n physLitA = lit;\n physShadeA = dark;\n }\n\n // Keep interior strictly transparent when shadow, hairline, border, and rim are all zero\n if (shadowA <= 0.0001 && hairA <= 0.0001 && borderA <= 0.0001 && rimA <= 0.0001 && physLitA <= 0.0001 && physShadeA <= 0.0001) {\n fragColor = vec4(0.0);\n return;\n }\n\n // Premultiplied alpha composite: uniform border over inner/physical rim over hairline and shadow\n float darkA = clamp(shadowA + hairA * (1.0 - shadowA), 0.0, 1.0);\n vec3 shadeColor = vec3(0.03921569, 0.07058824, 0.10980392);\n vec3 afterRimRgb = vec3(rimA + physLitA) + shadeColor * physShadeA;\n float totalRimA = clamp(rimA + physLitA + physShadeA * (1.0 - rimA), 0.0, 1.0);\n float afterRimA = totalRimA + darkA * (1.0 - totalRimA);\n vec3 outRgb = borderRgb + afterRimRgb * (1.0 - borderA);\n float outA = clamp(borderA + afterRimA * (1.0 - borderA), 0.0, 1.0);\n fragColor = vec4(outRgb, outA);\n}\n";
19
19
  /**
20
20
  * Traces an SVG path string emitted by `extractFieldContourPath` (`M`, `L`, `A`, `Z`)
21
21
  * directly onto a 2D Canvas context without relying on `Path2D`.
22
22
  */
23
23
  export declare function traceSvgPath2d(ctx: CanvasRenderingContext2D, pathD: string): void;
24
+ export interface GlassOverlayRendererOptions {
25
+ /**
26
+ * Where the edge is drawn.
27
+ * - `'dedicated'` (default): a WebGL2 context on the overlay canvas itself.
28
+ * - `'shared'`: one WebGL2 context per page draws every shared overlay, and each frame is
29
+ * copied into its canvas's 2D context as an `ImageBitmap`. Browsers cap live WebGL contexts (about 16 in Chromium) and
30
+ * evict the oldest past that, so pages with many surfaces use this for all of them, morphing
31
+ * overlays included, and every surface keeps the same shader.
32
+ * - `'2d'`: 2D Canvas only.
33
+ *
34
+ * `'dedicated'` and `'shared'` fall back to 2D Canvas when WebGL2 (or, for `'shared'`,
35
+ * `OffscreenCanvas`) is unavailable or the context is lost.
36
+ */
37
+ context?: 'dedicated' | 'shared' | '2d';
38
+ }
24
39
  /** Creates an optical edge overlay renderer supporting up to MAX_GPU_PRIMITIVES (16) with WebGL2 and automatic 2D Canvas fallback. */
25
- export declare function createGlassOverlayRenderer(): IGlassOverlayRenderer;
40
+ export declare function createGlassOverlayRenderer(options?: GlassOverlayRendererOptions): IGlassOverlayRenderer;
@@ -64,6 +64,13 @@ float safePow(float x, float y) {
64
64
  return (x <= 1e-6) ? 0.0 : pow(x, y);
65
65
  }
66
66
 
67
+ // Box-filtered coverage of the band lo <= d <= hi over a pixel footprint of width aa. Lines thinner
68
+ // than a pixel keep the same total alpha at every subpixel offset; a smoothstep around the band
69
+ // centre nearly vanishes or doubles as the edge moves, which reads as shimmer while morphing.
70
+ float bandCoverage(float d, float lo, float hi, float aa) {
71
+ return clamp(min(d + 0.5 * aa, hi) - max(d - 0.5 * aa, lo), 0.0, aa) / aa;
72
+ }
73
+
67
74
  float computeDirectionalRimWeight(vec2 normal, float focus, float bottomRatio) {
68
75
  if (focus < 0.05) {
69
76
  return 1.0;
@@ -175,7 +182,7 @@ void main() {
175
182
  vec2 normal = sdf.normal;
176
183
 
177
184
  float aa = 1.0 / max(uDpr, 1.0);
178
- float glassMask = smoothstep(0.5 * aa, -0.5 * aa, d);
185
+ float glassMask = clamp(0.5 - d / aa, 0.0, 1.0);
179
186
  float outsideMask = 1.0 - glassMask;
180
187
 
181
188
  // 1. Outside-only drop shadow (d > 0)
@@ -189,13 +196,9 @@ void main() {
189
196
 
190
197
  // 2. Dark outer hairline: strictly outside when a uniform CSS inner border is present (d >= 0), otherwise straddling the outer edge (d >= -0.25)
191
198
  float hw = max(uHairline.x, 0.5 / max(uDpr, 1.0));
192
- float hairlineHalfW = hw * 0.5;
193
199
  float hasUniformBorder = step(0.001, uBorderParams.x);
194
- float hairlineCenter = mix(-0.25 + hairlineHalfW, hairlineHalfW, hasUniformBorder);
195
- float hairlineMinD = mix(-0.25 - 0.5 * aa, -0.15 * aa, hasUniformBorder);
196
- float hairlineBand =
197
- smoothstep(hairlineHalfW + 0.5 * aa, hairlineHalfW * 0.25, abs(d - hairlineCenter)) *
198
- smoothstep(hairlineMinD, hairlineMinD + 0.75 * aa, d);
200
+ float hairlineLo = mix(-0.25, 0.0, hasUniformBorder);
201
+ float hairlineBand = bandCoverage(d, hairlineLo, hairlineLo + hw, aa);
199
202
  float hairA = 0.0;
200
203
  if (hairlineBand > 0.001) {
201
204
  float ax = abs(normal.x);
@@ -211,8 +214,8 @@ void main() {
211
214
  float borderMask = 0.0;
212
215
  float borderA = 0.0;
213
216
  vec3 borderRgb = vec3(0.0);
214
- if (glassMask > 0.001 && hasUniformBorder > 0.5 && inset < uBorderParams.x + aa) {
215
- borderMask = smoothstep(uBorderParams.x + 0.5 * aa, max(0.0, uBorderParams.x - 0.5 * aa), inset) * glassMask;
217
+ if (hasUniformBorder > 0.5 && d < 0.5 * aa && inset < uBorderParams.x + aa) {
218
+ borderMask = bandCoverage(d, -uBorderParams.x, 0.0, aa);
216
219
  borderA = clamp(borderMask * uBorderColor.a * uOpacity, 0.0, 1.0);
217
220
  borderRgb = uBorderColor.rgb * borderA;
218
221
  }
@@ -653,8 +656,125 @@ function renderFallback2d(ctx, frame) {
653
656
  ctx.restore();
654
657
  }
655
658
  }
659
+ const UNIFORM_NAMES = [
660
+ 'uViewport',
661
+ 'uDpr',
662
+ 'uPrimitiveCount',
663
+ 'uPrimitives',
664
+ 'uRadii',
665
+ 'uBlendK',
666
+ 'uRimOpacity',
667
+ 'uStyleMix',
668
+ 'uOpacity',
669
+ 'uRimParams',
670
+ 'uHairline',
671
+ 'uShadow',
672
+ 'uBorderColor',
673
+ 'uBorderParams',
674
+ 'uPhysicalLight',
675
+ 'uPhysicalParams',
676
+ ];
677
+ /** Links the edge program on `gl`; throws when the driver rejects the shaders. */
678
+ function createOverlayProgram(gl) {
679
+ const vao = gl.createVertexArray();
680
+ let program;
681
+ try {
682
+ program = linkProgram(gl, OVERLAY_VERTEX_SHADER, OVERLAY_FRAGMENT_SHADER);
683
+ }
684
+ catch (err) {
685
+ if (vao)
686
+ gl.deleteVertexArray(vao);
687
+ throw err;
688
+ }
689
+ const uniforms = {};
690
+ for (const name of UNIFORM_NAMES)
691
+ uniforms[name] = gl.getUniformLocation(program, name);
692
+ // Upload buffers live with the program so every frame reuses them.
693
+ const primitiveVecData = new Float32Array(MAX_GPU_PRIMITIVES * 4);
694
+ const primitiveRadiiData = new Float32Array(MAX_GPU_PRIMITIVES);
695
+ return {
696
+ draw(frame, width, height) {
697
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
698
+ gl.viewport(0, 0, width, height);
699
+ gl.clearColor(0, 0, 0, 0);
700
+ gl.clear(gl.COLOR_BUFFER_BIT);
701
+ if (frame.opacity <= 0.001)
702
+ return false;
703
+ const { field, material } = frame;
704
+ const primitives = field.primitives;
705
+ let activeCount = 0;
706
+ for (let i = 0; i < primitives.length; i++) {
707
+ const p = primitives[i];
708
+ if (p.size.width > 0.01 && p.size.height > 0.01) {
709
+ const vecOffset = activeCount * 4;
710
+ primitiveVecData[vecOffset] = p.center.x;
711
+ primitiveVecData[vecOffset + 1] = p.center.y;
712
+ primitiveVecData[vecOffset + 2] = p.size.width * 0.5;
713
+ primitiveVecData[vecOffset + 3] = p.size.height * 0.5;
714
+ primitiveRadiiData[activeCount] = p.radius;
715
+ activeCount++;
716
+ if (activeCount >= MAX_GPU_PRIMITIVES)
717
+ break;
718
+ }
719
+ }
720
+ if (activeCount === 0)
721
+ return false;
722
+ gl.useProgram(program);
723
+ gl.bindVertexArray(vao);
724
+ gl.disable(gl.BLEND);
725
+ gl.disable(gl.DEPTH_TEST);
726
+ gl.uniform2f(uniforms.uViewport, Math.max(1, frame.viewport.width), Math.max(1, frame.viewport.height));
727
+ gl.uniform1f(uniforms.uDpr, Math.max(1, frame.dpr));
728
+ gl.uniform1i(uniforms.uPrimitiveCount, activeCount);
729
+ gl.uniform4fv(uniforms.uPrimitives, primitiveVecData);
730
+ gl.uniform1fv(uniforms.uRadii, primitiveRadiiData);
731
+ gl.uniform1f(uniforms.uBlendK, field.blendK);
732
+ gl.uniform1f(uniforms.uRimOpacity, field.rimOpacity ?? 1);
733
+ gl.uniform1f(uniforms.uStyleMix, field.styleMix ?? 0);
734
+ gl.uniform1f(uniforms.uOpacity, frame.opacity);
735
+ gl.uniform4f(uniforms.uRimParams, material.rimOpacity, material.rimWidth, material.rimTail, material.rimFocus);
736
+ gl.uniform4f(uniforms.uHairline, material.hairlineWidth, material.hairlineSideAlpha, material.hairlineCornerAlpha, material.hairlineFlatAlpha);
737
+ gl.uniform3f(uniforms.uShadow, material.shadowBlur, material.shadowOffsetY, material.shadowAlpha);
738
+ const borderRgba = material.borderRgba ?? [1, 1, 1, 0];
739
+ gl.uniform4f(uniforms.uBorderColor, borderRgba[0], borderRgba[1], borderRgba[2], borderRgba[3]);
740
+ gl.uniform2f(uniforms.uBorderParams, material.borderWidth ?? 0, material.rimBottomRatio ?? 0.72);
741
+ const isPhysicalRim = material.rimMode === 'physical';
742
+ const angleRad = ((material.lightAngle ?? -45) * Math.PI) / 180;
743
+ const elevRad = (Math.max(1, Math.min(89, material.lightElevation ?? 22)) * Math.PI) / 180;
744
+ const cosElev = Math.cos(elevRad);
745
+ gl.uniform4f(uniforms.uPhysicalLight, Math.sin(angleRad) * cosElev, -Math.cos(angleRad) * cosElev, Math.sin(elevRad), isPhysicalRim ? 1 : 0);
746
+ const profileCode = material.bevelProfile === 'circle'
747
+ ? 1
748
+ : material.bevelProfile === 'parabolic'
749
+ ? 2
750
+ : material.bevelProfile === 'lip'
751
+ ? 3
752
+ : 0;
753
+ gl.uniform4f(uniforms.uPhysicalParams, Math.max(1, material.bevel), Math.min(1, Math.max(0, material.rimOpacity * 2)), Math.min(1, Math.max(0, material.rimShade ?? 0.32)), profileCode);
754
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
755
+ gl.bindVertexArray(null);
756
+ return true;
757
+ },
758
+ destroy() {
759
+ if (vao)
760
+ gl.deleteVertexArray(vao);
761
+ gl.deleteProgram(program);
762
+ },
763
+ };
764
+ }
765
+ function deviceSize(frame) {
766
+ const dpr = Math.max(1, frame.dpr);
767
+ return {
768
+ width: Math.max(1, Math.round(frame.viewport.width * dpr)),
769
+ height: Math.max(1, Math.round(frame.viewport.height * dpr)),
770
+ };
771
+ }
656
772
  /** Creates an optical edge overlay renderer supporting up to MAX_GPU_PRIMITIVES (16) with WebGL2 and automatic 2D Canvas fallback. */
657
- export function createGlassOverlayRenderer() {
773
+ export function createGlassOverlayRenderer(options = {}) {
774
+ const context = options.context ?? 'dedicated';
775
+ return context === 'shared' ? createSharedOverlayRenderer() : createCanvasOverlayRenderer(context === 'dedicated');
776
+ }
777
+ function createCanvasOverlayRenderer(allowWebGL) {
658
778
  let capabilities = {
659
779
  webgl2: false,
660
780
  floatFbo: false,
@@ -665,50 +785,17 @@ export function createGlassOverlayRenderer() {
665
785
  let gl = null;
666
786
  let fallback2d = null;
667
787
  let contextLost = false;
668
- let vao = null;
669
788
  let program = null;
670
- let uniforms = null;
671
- // Pre-allocated upload buffers inside closure for zero per-frame GC allocation.
672
- const primitiveVecData = new Float32Array(MAX_GPU_PRIMITIVES * 4);
673
- const primitiveRadiiData = new Float32Array(MAX_GPU_PRIMITIVES);
674
789
  function destroyGlResources() {
675
- if (!gl)
676
- return;
677
- if (vao) {
678
- gl.deleteVertexArray(vao);
679
- vao = null;
680
- }
681
- if (program) {
682
- gl.deleteProgram(program);
683
- program = null;
684
- }
685
- uniforms = null;
790
+ program?.destroy();
791
+ program = null;
686
792
  }
687
793
  function initGlResources() {
688
794
  if (!gl)
689
795
  return false;
690
796
  destroyGlResources();
691
797
  try {
692
- vao = gl.createVertexArray();
693
- program = linkProgram(gl, OVERLAY_VERTEX_SHADER, OVERLAY_FRAGMENT_SHADER);
694
- uniforms = {
695
- uViewport: gl.getUniformLocation(program, 'uViewport'),
696
- uDpr: gl.getUniformLocation(program, 'uDpr'),
697
- uPrimitiveCount: gl.getUniformLocation(program, 'uPrimitiveCount'),
698
- uPrimitives: gl.getUniformLocation(program, 'uPrimitives'),
699
- uRadii: gl.getUniformLocation(program, 'uRadii'),
700
- uBlendK: gl.getUniformLocation(program, 'uBlendK'),
701
- uRimOpacity: gl.getUniformLocation(program, 'uRimOpacity'),
702
- uStyleMix: gl.getUniformLocation(program, 'uStyleMix'),
703
- uOpacity: gl.getUniformLocation(program, 'uOpacity'),
704
- uRimParams: gl.getUniformLocation(program, 'uRimParams'),
705
- uHairline: gl.getUniformLocation(program, 'uHairline'),
706
- uShadow: gl.getUniformLocation(program, 'uShadow'),
707
- uBorderColor: gl.getUniformLocation(program, 'uBorderColor'),
708
- uBorderParams: gl.getUniformLocation(program, 'uBorderParams'),
709
- uPhysicalLight: gl.getUniformLocation(program, 'uPhysicalLight'),
710
- uPhysicalParams: gl.getUniformLocation(program, 'uPhysicalParams'),
711
- };
798
+ program = createOverlayProgram(gl);
712
799
  return true;
713
800
  }
714
801
  catch (err) {
@@ -718,7 +805,6 @@ export function createGlassOverlayRenderer() {
718
805
  webgl2: false,
719
806
  fallbackNotice: msg,
720
807
  };
721
- destroyGlResources();
722
808
  return false;
723
809
  }
724
810
  }
@@ -758,7 +844,9 @@ export function createGlassOverlayRenderer() {
758
844
  canvas.addEventListener('webglcontextrestored', handleContextRestored);
759
845
  // Probe shader compilation on an offscreen canvas first so a failing WebGL2 context
760
846
  // never locks targetCanvas out of acquiring a 2D fallback context per the HTML Canvas spec.
761
- const probe = probeWebGL2OverlaySupport(targetCanvas);
847
+ const probe = allowWebGL
848
+ ? probeWebGL2OverlaySupport(targetCanvas)
849
+ : { supported: false, reason: '2D Canvas overlay requested.' };
762
850
  const glCtx = probe.supported
763
851
  ? canvas.getContext('webgl2', WEBGL2_CONTEXT_ATTRS)
764
852
  : null;
@@ -797,77 +885,13 @@ export function createGlassOverlayRenderer() {
797
885
  render(frame) {
798
886
  if (!canvas)
799
887
  return;
800
- const dpr = Math.max(1, frame.dpr);
801
- const targetW = Math.max(1, Math.round(frame.viewport.width * dpr));
802
- const targetH = Math.max(1, Math.round(frame.viewport.height * dpr));
803
- if (canvas.width !== targetW || canvas.height !== targetH) {
804
- canvas.width = targetW;
805
- canvas.height = targetH;
888
+ const target = deviceSize(frame);
889
+ if (canvas.width !== target.width || canvas.height !== target.height) {
890
+ canvas.width = target.width;
891
+ canvas.height = target.height;
806
892
  }
807
- if (gl && !contextLost && capabilities.webgl2 && program && uniforms && vao) {
808
- if (frame.opacity <= 0.001) {
809
- this.clear();
810
- return;
811
- }
812
- const { field, material } = frame;
813
- const primitives = field.primitives;
814
- let activeCount = 0;
815
- for (let i = 0; i < primitives.length; i++) {
816
- const p = primitives[i];
817
- if (p.size.width > 0.01 && p.size.height > 0.01) {
818
- const vecOffset = activeCount * 4;
819
- primitiveVecData[vecOffset] = p.center.x;
820
- primitiveVecData[vecOffset + 1] = p.center.y;
821
- primitiveVecData[vecOffset + 2] = p.size.width * 0.5;
822
- primitiveVecData[vecOffset + 3] = p.size.height * 0.5;
823
- primitiveRadiiData[activeCount] = p.radius;
824
- activeCount++;
825
- if (activeCount >= MAX_GPU_PRIMITIVES)
826
- break;
827
- }
828
- }
829
- if (activeCount === 0) {
830
- this.clear();
831
- return;
832
- }
833
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
834
- gl.viewport(0, 0, canvas.width, canvas.height);
835
- gl.clearColor(0, 0, 0, 0);
836
- gl.clear(gl.COLOR_BUFFER_BIT);
837
- gl.useProgram(program);
838
- gl.bindVertexArray(vao);
839
- gl.disable(gl.BLEND);
840
- gl.disable(gl.DEPTH_TEST);
841
- gl.uniform2f(uniforms.uViewport, Math.max(1, frame.viewport.width), Math.max(1, frame.viewport.height));
842
- gl.uniform1f(uniforms.uDpr, dpr);
843
- gl.uniform1i(uniforms.uPrimitiveCount, activeCount);
844
- gl.uniform4fv(uniforms.uPrimitives, primitiveVecData);
845
- gl.uniform1fv(uniforms.uRadii, primitiveRadiiData);
846
- gl.uniform1f(uniforms.uBlendK, field.blendK);
847
- gl.uniform1f(uniforms.uRimOpacity, field.rimOpacity ?? 1);
848
- gl.uniform1f(uniforms.uStyleMix, field.styleMix ?? 0);
849
- gl.uniform1f(uniforms.uOpacity, frame.opacity);
850
- gl.uniform4f(uniforms.uRimParams, material.rimOpacity, material.rimWidth, material.rimTail, material.rimFocus);
851
- gl.uniform4f(uniforms.uHairline, material.hairlineWidth, material.hairlineSideAlpha, material.hairlineCornerAlpha, material.hairlineFlatAlpha);
852
- gl.uniform3f(uniforms.uShadow, material.shadowBlur, material.shadowOffsetY, material.shadowAlpha);
853
- const borderRgba = material.borderRgba ?? [1, 1, 1, 0];
854
- gl.uniform4f(uniforms.uBorderColor, borderRgba[0], borderRgba[1], borderRgba[2], borderRgba[3]);
855
- gl.uniform2f(uniforms.uBorderParams, material.borderWidth ?? 0, material.rimBottomRatio ?? 0.72);
856
- const isPhysicalRim = material.rimMode === 'physical';
857
- const angleRad = ((material.lightAngle ?? -45) * Math.PI) / 180;
858
- const elevRad = (Math.max(1, Math.min(89, material.lightElevation ?? 22)) * Math.PI) / 180;
859
- const cosElev = Math.cos(elevRad);
860
- gl.uniform4f(uniforms.uPhysicalLight, Math.sin(angleRad) * cosElev, -Math.cos(angleRad) * cosElev, Math.sin(elevRad), isPhysicalRim ? 1 : 0);
861
- const profileCode = material.bevelProfile === 'circle'
862
- ? 1
863
- : material.bevelProfile === 'parabolic'
864
- ? 2
865
- : material.bevelProfile === 'lip'
866
- ? 3
867
- : 0;
868
- gl.uniform4f(uniforms.uPhysicalParams, Math.max(1, material.bevel), Math.min(1, Math.max(0, material.rimOpacity * 2)), Math.min(1, Math.max(0, material.rimShade ?? 0.32)), profileCode);
869
- gl.drawArrays(gl.TRIANGLES, 0, 3);
870
- gl.bindVertexArray(null);
893
+ if (gl && !contextLost && capabilities.webgl2 && program) {
894
+ program.draw(frame, canvas.width, canvas.height);
871
895
  return;
872
896
  }
873
897
  if (fallback2d) {
@@ -899,3 +923,145 @@ export function createGlassOverlayRenderer() {
899
923
  },
900
924
  };
901
925
  }
926
+ let sharedContext = null;
927
+ function loseContext(gl) {
928
+ ;
929
+ gl.getExtension('WEBGL_lose_context')?.loseContext?.();
930
+ }
931
+ /** Returns the page-wide context, creating it on first use; `null` when it cannot draw. */
932
+ function acquireSharedContext() {
933
+ if (sharedContext) {
934
+ sharedContext.users++;
935
+ return sharedContext;
936
+ }
937
+ if (typeof OffscreenCanvas !== 'function')
938
+ return null;
939
+ const surface = new OffscreenCanvas(1, 1);
940
+ const gl = surface.getContext('webgl2', WEBGL2_CONTEXT_ATTRS);
941
+ if (!gl || gl.isContextLost())
942
+ return null;
943
+ let program;
944
+ try {
945
+ program = createOverlayProgram(gl);
946
+ }
947
+ catch {
948
+ loseContext(gl);
949
+ return null;
950
+ }
951
+ const shared = {
952
+ surface,
953
+ gl,
954
+ program,
955
+ users: 1,
956
+ floatFbo: Boolean(gl.getExtension('EXT_color_buffer_float')),
957
+ maxTextureSize: Number(gl.getParameter(gl.MAX_TEXTURE_SIZE)) || 4096,
958
+ };
959
+ surface.addEventListener('webglcontextlost', (event) => {
960
+ event.preventDefault();
961
+ shared.program = null;
962
+ });
963
+ surface.addEventListener('webglcontextrestored', () => {
964
+ try {
965
+ shared.program = createOverlayProgram(gl);
966
+ }
967
+ catch {
968
+ // Hosts stay on their 2D path.
969
+ }
970
+ });
971
+ sharedContext = shared;
972
+ return shared;
973
+ }
974
+ function releaseSharedContext(shared) {
975
+ if (--shared.users > 0)
976
+ return;
977
+ shared.program?.destroy();
978
+ loseContext(shared.gl);
979
+ if (sharedContext === shared)
980
+ sharedContext = null;
981
+ }
982
+ /**
983
+ * Hosts keep a 2D context and copy their region out of the shared surface as an `ImageBitmap`.
984
+ * `bitmaprenderer` would need a bitmap of exactly the host's size, which means resizing the
985
+ * surface per host; copying a GPU bitmap into a 2D canvas does not stall.
986
+ */
987
+ function createSharedOverlayRenderer() {
988
+ let shared = null;
989
+ let host = null;
990
+ let ctx = null;
991
+ function release() {
992
+ if (shared)
993
+ releaseSharedContext(shared);
994
+ shared = null;
995
+ host = null;
996
+ ctx = null;
997
+ }
998
+ function currentCapabilities() {
999
+ if (shared?.program) {
1000
+ return { webgl2: true, floatFbo: shared.floatFbo, maxTextureSize: shared.maxTextureSize };
1001
+ }
1002
+ return {
1003
+ webgl2: false,
1004
+ floatFbo: false,
1005
+ maxTextureSize: 0,
1006
+ fallbackNotice: !ctx
1007
+ ? host
1008
+ ? 'Neither WebGL2 nor 2D Canvas context is available.'
1009
+ : 'Overlay renderer not yet mounted.'
1010
+ : shared
1011
+ ? 'Shared WebGL2 overlay context lost; using 2D Canvas overlay fallback.'
1012
+ : 'Shared WebGL2 overlay context unavailable; using 2D Canvas overlay fallback.',
1013
+ };
1014
+ }
1015
+ return {
1016
+ get capabilities() {
1017
+ return currentCapabilities();
1018
+ },
1019
+ mount(targetCanvas) {
1020
+ release();
1021
+ host = targetCanvas;
1022
+ ctx = targetCanvas.getContext('2d');
1023
+ if (ctx)
1024
+ shared = acquireSharedContext();
1025
+ return currentCapabilities();
1026
+ },
1027
+ render(frame) {
1028
+ if (!host || !ctx)
1029
+ return;
1030
+ const { width, height } = deviceSize(frame);
1031
+ if (host.width !== width || host.height !== height) {
1032
+ host.width = width;
1033
+ host.height = height;
1034
+ }
1035
+ const program = shared?.program;
1036
+ if (!shared || !program) {
1037
+ renderFallback2d(ctx, frame);
1038
+ return;
1039
+ }
1040
+ const surface = shared.surface;
1041
+ if (surface.width < width || surface.height < height) {
1042
+ surface.width = Math.max(surface.width, width);
1043
+ surface.height = Math.max(surface.height, height);
1044
+ }
1045
+ // Drawing and copying happen inside this call, so the edge never lags the clip and filter
1046
+ // the caller updates in the same frame.
1047
+ const drew = program.draw(frame, width, height);
1048
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
1049
+ ctx.clearRect(0, 0, width, height);
1050
+ if (!drew)
1051
+ return;
1052
+ const bitmap = surface.transferToImageBitmap();
1053
+ // The draw sits at the GL origin, the bottom-left of the bitmap.
1054
+ ctx.drawImage(bitmap, 0, shared.gl.drawingBufferHeight - height, width, height, 0, 0, width, height);
1055
+ bitmap.close();
1056
+ },
1057
+ clear() {
1058
+ if (!host || !ctx)
1059
+ return;
1060
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
1061
+ ctx.clearRect(0, 0, host.width, host.height);
1062
+ },
1063
+ dispose() {
1064
+ release();
1065
+ },
1066
+ };
1067
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sessile/core",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Zero-dependency pure TypeScript kernel for live-DOM continuous glass morphing.",