@telosnex/monet-ui 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +69 -2
- package/dist/afterimage.d.ts +41 -0
- package/dist/afterimage.js +204 -0
- package/dist/afterimage.js.map +1 -0
- package/dist/apca-tone-bounds-data.d.ts +2 -0
- package/dist/apca-tone-bounds-data.js +809 -0
- package/dist/apca-tone-bounds-data.js.map +1 -0
- package/dist/cam16-v11.d.ts +78 -0
- package/dist/cam16-v11.js +229 -0
- package/dist/cam16-v11.js.map +1 -0
- package/dist/color.d.ts +9 -0
- package/dist/color.js +31 -0
- package/dist/color.js.map +1 -0
- package/dist/contrast.d.ts +109 -0
- package/dist/contrast.js +517 -0
- package/dist/contrast.js.map +1 -0
- package/dist/css-vars.d.ts +11 -0
- package/dist/css-vars.js +58 -0
- package/dist/css-vars.js.map +1 -0
- package/dist/extract.d.ts +57 -0
- package/dist/extract.js +261 -0
- package/dist/extract.js.map +1 -0
- package/dist/hct.d.ts +28 -0
- package/dist/hct.js +442 -0
- package/dist/hct.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/lerp.d.ts +58 -0
- package/dist/lerp.js +118 -0
- package/dist/lerp.js.map +1 -0
- package/dist/lru-cache.d.ts +17 -0
- package/dist/lru-cache.js +50 -0
- package/dist/lru-cache.js.map +1 -0
- package/dist/luma.d.ts +10 -0
- package/dist/luma.js +93 -0
- package/dist/luma.js.map +1 -0
- package/dist/math.d.ts +2 -0
- package/dist/math.js +13 -0
- package/dist/math.js.map +1 -0
- package/dist/oklch.d.ts +11 -0
- package/dist/oklch.js +61 -0
- package/dist/oklch.js.map +1 -0
- package/dist/over-image.d.ts +162 -0
- package/dist/over-image.js +440 -0
- package/dist/over-image.js.map +1 -0
- package/dist/palette-snapshot.d.ts +63 -0
- package/dist/palette-snapshot.js +93 -0
- package/dist/palette-snapshot.js.map +1 -0
- package/dist/palette.d.ts +129 -0
- package/dist/palette.js +295 -0
- package/dist/palette.js.map +1 -0
- package/dist/point-provider-lab.d.ts +7 -0
- package/dist/point-provider-lab.js +16 -0
- package/dist/point-provider-lab.js.map +1 -0
- package/dist/point-provider.d.ts +6 -0
- package/dist/point-provider.js +2 -0
- package/dist/point-provider.js.map +1 -0
- package/dist/quantize-worker.d.ts +36 -0
- package/dist/quantize-worker.js +81 -0
- package/dist/quantize-worker.js.map +1 -0
- package/dist/quantizer-celebi.d.ts +7 -0
- package/dist/quantizer-celebi.js +25 -0
- package/dist/quantizer-celebi.js.map +1 -0
- package/dist/quantizer-map.d.ts +5 -0
- package/dist/quantizer-map.js +19 -0
- package/dist/quantizer-map.js.map +1 -0
- package/dist/quantizer-wsmeans.d.ts +21 -0
- package/dist/quantizer-wsmeans.js +569 -0
- package/dist/quantizer-wsmeans.js.map +1 -0
- package/dist/quantizer-wu.d.ts +52 -0
- package/dist/quantizer-wu.js +319 -0
- package/dist/quantizer-wu.js.map +1 -0
- package/dist/size-scale.d.ts +1 -0
- package/dist/size-scale.js +4 -0
- package/dist/size-scale.js.map +1 -0
- package/dist/temperature.d.ts +66 -0
- package/dist/temperature.js +169 -0
- package/dist/temperature.js.map +1 -0
- package/dist/theme.d.ts +33 -0
- package/dist/theme.js +66 -0
- package/dist/theme.js.map +1 -0
- package/dist/uv-harmony.d.ts +23 -0
- package/dist/uv-harmony.js +248 -0
- package/dist/uv-harmony.js.map +1 -0
- package/dist/xyz-lab.d.ts +8 -0
- package/dist/xyz-lab.js +50 -0
- package/dist/xyz-lab.js.map +1 -0
- package/package.json +41 -4
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
// Drawing over something you didn't choose: a wallpaper, a video frame, a
|
|
2
|
+
// gradient, a map. Direct port of lib/effects/over_image.dart; keep the two
|
|
3
|
+
// in lockstep. Parity is enforced by js/fixtures/libmonet_parity.json.
|
|
4
|
+
//
|
|
5
|
+
// A palette's background is one color the theme chose. AnyBackground is
|
|
6
|
+
// whatever is actually behind the UI, as real pixels. Build one per image,
|
|
7
|
+
// then ask it: scrimFor (legible text and icons), sharedBorder (one border
|
|
8
|
+
// tone for surfaces drawn together). See ADR-001.
|
|
9
|
+
import { argbFromRgb, blueFromArgb, greenFromArgb, redFromArgb } from './color.js';
|
|
10
|
+
import { Algo, Usage, apcaContrastOfApcaY, apcaYFromArgb, contrastBetweenArgbs, getAbsoluteContrast, } from './contrast.js';
|
|
11
|
+
import { Hct, defaultColorModel, lstarFromArgb, yFromLstar } from './hct.js';
|
|
12
|
+
import { LruCache } from './lru-cache.js';
|
|
13
|
+
const white = 0xffffffff;
|
|
14
|
+
const black = 0xff000000;
|
|
15
|
+
/** Which way the content reads once the scrim is applied. */
|
|
16
|
+
export var Polarity;
|
|
17
|
+
(function (Polarity) {
|
|
18
|
+
/** Every blended pixel is darker than the content. */
|
|
19
|
+
Polarity["lightOnDark"] = "lightOnDark";
|
|
20
|
+
/** Every blended pixel is lighter than the content. */
|
|
21
|
+
Polarity["darkOnLight"] = "darkOnLight";
|
|
22
|
+
})(Polarity || (Polarity = {}));
|
|
23
|
+
/** A translucent layer that makes content legible over an AnyBackground. */
|
|
24
|
+
export class Scrim {
|
|
25
|
+
scrimArgb;
|
|
26
|
+
opacity;
|
|
27
|
+
meetsTarget;
|
|
28
|
+
worstContrast;
|
|
29
|
+
polarity;
|
|
30
|
+
mixedPolarityRejected;
|
|
31
|
+
/** @internal */
|
|
32
|
+
constructor(
|
|
33
|
+
/** The scrim's color: black or white, or the caller's choice. */
|
|
34
|
+
scrimArgb,
|
|
35
|
+
/** 0..1, quantized to 1/255 so 8-bit compositing is exact. */
|
|
36
|
+
opacity,
|
|
37
|
+
/** False: no opacity of scrimArgb reaches the target; opacity is a 1.0 best effort. */
|
|
38
|
+
meetsTarget,
|
|
39
|
+
/** Weakest absolute contrast over every pixel at opacity. */
|
|
40
|
+
worstContrast, polarity,
|
|
41
|
+
/** A lower opacity passed per pixel but left pixels on both sides of the content. */
|
|
42
|
+
mixedPolarityRejected) {
|
|
43
|
+
this.scrimArgb = scrimArgb;
|
|
44
|
+
this.opacity = opacity;
|
|
45
|
+
this.meetsTarget = meetsTarget;
|
|
46
|
+
this.worstContrast = worstContrast;
|
|
47
|
+
this.polarity = polarity;
|
|
48
|
+
this.mixedPolarityRejected = mixedPolarityRejected;
|
|
49
|
+
}
|
|
50
|
+
get isNeeded() { return this.opacity > 0; }
|
|
51
|
+
/** scrimArgb with opacity as its alpha. Fill a rect with it. */
|
|
52
|
+
get paintArgb() {
|
|
53
|
+
return ((Math.round(this.opacity * 255) << 24) | (this.scrimArgb & 0x00ffffff)) >>> 0;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Draw this scrim hugging the glyph: its shape widened by `stroke` pixels,
|
|
57
|
+
* then blurred by `blurRadius`. Exact; prefer it where the renderer can
|
|
58
|
+
* widen a shape (a stroke, BoxShadow spread, CSS box-shadow).
|
|
59
|
+
*/
|
|
60
|
+
shadowsWithStroke(opts = {}) {
|
|
61
|
+
const stroke = opts.stroke ?? 1.0;
|
|
62
|
+
const blurRadius = opts.blurRadius ?? 4.0;
|
|
63
|
+
if (!(stroke >= 0) || !(blurRadius >= 0)) {
|
|
64
|
+
throw new Error('stroke and blurRadius must be non-negative');
|
|
65
|
+
}
|
|
66
|
+
return new ShadowsWithStroke(this, stroke, blurRadius);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Draw this scrim as stacked blurred copies of the glyph, for renderers that
|
|
70
|
+
* can't widen it (CSS text-shadow). Approximate; prefer shadowsWithStroke.
|
|
71
|
+
*/
|
|
72
|
+
shadows(opts) {
|
|
73
|
+
const { blurRadius } = opts;
|
|
74
|
+
const contentRadius = opts.contentRadius ?? -1.0;
|
|
75
|
+
const maxLayers = opts.maxLayers ?? 8;
|
|
76
|
+
if (!Number.isFinite(blurRadius) || blurRadius < 0)
|
|
77
|
+
throw new Error(`invalid blurRadius: ${blurRadius}`);
|
|
78
|
+
if (!Number.isFinite(contentRadius))
|
|
79
|
+
throw new Error(`invalid contentRadius: ${contentRadius}`);
|
|
80
|
+
if (maxLayers < 1)
|
|
81
|
+
throw new Error(`invalid maxLayers: ${maxLayers}`);
|
|
82
|
+
const alpha = this.opacity;
|
|
83
|
+
if (alpha === 0)
|
|
84
|
+
return new Shadows(this, 0, [], this.meetsTarget, 0);
|
|
85
|
+
// Round the radius once: sigma and coverage use the drawn radius.
|
|
86
|
+
const r = Math.round(blurRadius);
|
|
87
|
+
if (r === 0)
|
|
88
|
+
return new Shadows(this, 0, [], false, 0);
|
|
89
|
+
// Edge coverage at the first outside pixel's center, 0.5px past the edge.
|
|
90
|
+
// Calibrated against Skia pixels (shadow_pixel_calibration_test.dart).
|
|
91
|
+
const sigma = convertRadiusToSigma(r);
|
|
92
|
+
const cr = contentRadius < 0 ? r : Math.round(contentRadius);
|
|
93
|
+
const e = contentRadius < 0
|
|
94
|
+
? 1 - phi(0.5 / sigma)
|
|
95
|
+
: phi((0.5 + 2 * cr) / sigma) - phi(0.5 / sigma);
|
|
96
|
+
if (e <= 0)
|
|
97
|
+
return new Shadows(this, r, [], false, e);
|
|
98
|
+
const n = alpha >= 1
|
|
99
|
+
? maxLayers + 1
|
|
100
|
+
: Math.min(Math.max(Math.ceil(Math.log(1 - alpha) / Math.log(1 - e)), 1), maxLayers + 1);
|
|
101
|
+
if (n > maxLayers) {
|
|
102
|
+
return new Shadows(this, r, Array(maxLayers).fill(1.0), false, e);
|
|
103
|
+
}
|
|
104
|
+
// Round up to 1/255 so the drawn stack never lands below the minimum.
|
|
105
|
+
const perLayerRaw = (1 - Math.pow(1 - alpha, 1 / n)) / e;
|
|
106
|
+
const perLayer = Math.min(Math.max(Math.ceil(perLayerRaw * 255), 0), 255) / 255;
|
|
107
|
+
return new Shadows(this, r, Array(n).fill(perLayer), this.meetsTarget, e);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** A Scrim drawn hugging the glyph; see Scrim.shadowsWithStroke. */
|
|
111
|
+
export class ShadowsWithStroke {
|
|
112
|
+
scrim;
|
|
113
|
+
stroke;
|
|
114
|
+
blurRadius;
|
|
115
|
+
/** @internal */
|
|
116
|
+
constructor(scrim, stroke, blurRadius) {
|
|
117
|
+
this.scrim = scrim;
|
|
118
|
+
this.stroke = stroke;
|
|
119
|
+
this.blurRadius = blurRadius;
|
|
120
|
+
}
|
|
121
|
+
/** Gaussian sigma for blurRadius, as Skia converts it. */
|
|
122
|
+
get blurSigma() { return convertRadiusToSigma(this.blurRadius); }
|
|
123
|
+
}
|
|
124
|
+
/** A Scrim as stacked blurred copies of the glyph; see Scrim.shadows. */
|
|
125
|
+
export class Shadows {
|
|
126
|
+
scrim;
|
|
127
|
+
blurRadius;
|
|
128
|
+
layerOpacities;
|
|
129
|
+
meetsTarget;
|
|
130
|
+
edgeCoverage;
|
|
131
|
+
/** @internal */
|
|
132
|
+
constructor(scrim,
|
|
133
|
+
/** The rounded radius to draw every layer with. */
|
|
134
|
+
blurRadius,
|
|
135
|
+
/** One alpha per layer, all equal. Empty when nothing needs drawing. */
|
|
136
|
+
layerOpacities,
|
|
137
|
+
/** Model-based: calibrated on long straight edges. Stricter than scrim.meetsTarget. */
|
|
138
|
+
meetsTarget,
|
|
139
|
+
/** Modeled share of one layer's alpha on the first pixel outside the glyph. */
|
|
140
|
+
edgeCoverage) {
|
|
141
|
+
this.scrim = scrim;
|
|
142
|
+
this.blurRadius = blurRadius;
|
|
143
|
+
this.layerOpacities = layerOpacities;
|
|
144
|
+
this.meetsTarget = meetsTarget;
|
|
145
|
+
this.edgeCoverage = edgeCoverage;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** One border tone for surfaces drawn together; see AnyBackground.sharedBorder. */
|
|
149
|
+
export class SharedBorder {
|
|
150
|
+
tone;
|
|
151
|
+
borderArgbs;
|
|
152
|
+
clearsBackground;
|
|
153
|
+
meetsTarget;
|
|
154
|
+
worstContrast;
|
|
155
|
+
/** @internal */
|
|
156
|
+
constructor(
|
|
157
|
+
/** The shared tone, 0..100. */
|
|
158
|
+
tone,
|
|
159
|
+
/** One border per surface, same order, each in its surface's hue. */
|
|
160
|
+
borderArgbs,
|
|
161
|
+
/** True: every border clears every pixel. False: each clears its own surface. */
|
|
162
|
+
clearsBackground,
|
|
163
|
+
/** False: no tone works; this is the strongest best effort. */
|
|
164
|
+
meetsTarget,
|
|
165
|
+
/** Weakest contrast backing the guarantee. */
|
|
166
|
+
worstContrast) {
|
|
167
|
+
this.tone = tone;
|
|
168
|
+
this.borderArgbs = borderArgbs;
|
|
169
|
+
this.clearsBackground = clearsBackground;
|
|
170
|
+
this.meetsTarget = meetsTarget;
|
|
171
|
+
this.worstContrast = worstContrast;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/** The pixels behind some UI, plus the contrast policy to judge them by. */
|
|
175
|
+
export class AnyBackground {
|
|
176
|
+
algo;
|
|
177
|
+
/** libmonet's 0..1 contrast dial. */
|
|
178
|
+
contrast;
|
|
179
|
+
argbs;
|
|
180
|
+
pixelsCache;
|
|
181
|
+
luminancesCache;
|
|
182
|
+
scrims = new LruCache(64);
|
|
183
|
+
borders = new LruCache(64);
|
|
184
|
+
/**
|
|
185
|
+
* `argbs` must be real sampled pixels from what's behind the UI: min/max
|
|
186
|
+
* pool when downscaling, never average; quantizer clusters are averages.
|
|
187
|
+
* Read on first use; don't modify afterwards. Empty means unknown.
|
|
188
|
+
*/
|
|
189
|
+
constructor(argbs, opts) {
|
|
190
|
+
if (!(opts.contrast > 0 && opts.contrast <= 1)) {
|
|
191
|
+
throw new Error(`contrast must be in (0, 1]: ${opts.contrast}`);
|
|
192
|
+
}
|
|
193
|
+
this.argbs = argbs;
|
|
194
|
+
this.algo = opts.algo;
|
|
195
|
+
this.contrast = opts.contrast;
|
|
196
|
+
}
|
|
197
|
+
/** Nothing is known about what's behind. */
|
|
198
|
+
static unknown(opts) {
|
|
199
|
+
return new AnyBackground([], opts);
|
|
200
|
+
}
|
|
201
|
+
get isUnknown() { return this.argbs.length === 0; }
|
|
202
|
+
/** Unique opaque pixels, sorted; black and white when unknown. */
|
|
203
|
+
get pixels() {
|
|
204
|
+
if (this.pixelsCache === undefined) {
|
|
205
|
+
this.pixelsCache = this.isUnknown
|
|
206
|
+
? [black, white]
|
|
207
|
+
: [...new Set(this.argbs.map((a) => (a | 0xff000000) >>> 0))].sort((a, b) => a - b);
|
|
208
|
+
}
|
|
209
|
+
return this.pixelsCache;
|
|
210
|
+
}
|
|
211
|
+
/** Unique luminances in algo's space, sorted; empty when unknown. */
|
|
212
|
+
get luminances() {
|
|
213
|
+
if (this.luminancesCache === undefined) {
|
|
214
|
+
this.luminancesCache = this.isUnknown
|
|
215
|
+
? []
|
|
216
|
+
: [...new Set(this.pixels.map((a) => luminance(this.algo, a)))].sort((a, b) => a - b);
|
|
217
|
+
}
|
|
218
|
+
return this.luminancesCache;
|
|
219
|
+
}
|
|
220
|
+
/** Minimum-opacity scrim making `contentArgb` meet usage's contrast against every pixel. */
|
|
221
|
+
scrimFor(contentArgb, opts = {}) {
|
|
222
|
+
const usage = opts.usage ?? Usage.text;
|
|
223
|
+
const key = `${contentArgb}|${usage}|${opts.scrimArgb ?? ''}`;
|
|
224
|
+
const hit = this.scrims.get(key);
|
|
225
|
+
if (hit !== undefined)
|
|
226
|
+
return hit;
|
|
227
|
+
const target = getAbsoluteContrast(this.algo, this.contrast, usage);
|
|
228
|
+
const canMix = !this.isUnknown;
|
|
229
|
+
const solve = (scrim) => solveForScrimColor(contentArgb, this.pixels, target, this.algo, scrim, canMix);
|
|
230
|
+
let result;
|
|
231
|
+
if (opts.scrimArgb !== undefined) {
|
|
232
|
+
result = solve(opts.scrimArgb);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
const b = solve(black);
|
|
236
|
+
const w = solve(white);
|
|
237
|
+
if (b.meetsTarget && w.meetsTarget)
|
|
238
|
+
result = b.opacity <= w.opacity ? b : w;
|
|
239
|
+
else if (b.meetsTarget)
|
|
240
|
+
result = b;
|
|
241
|
+
else if (w.meetsTarget)
|
|
242
|
+
result = w;
|
|
243
|
+
else
|
|
244
|
+
result = b.worstContrast >= w.worstContrast ? b : w;
|
|
245
|
+
}
|
|
246
|
+
this.scrims.set(key, result);
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* One border tone for surfaces drawn together, so they read at one
|
|
251
|
+
* elevation. `surfaceArgbs`: each surface's resting color (sets its
|
|
252
|
+
* border's hue). Hovered and pressed are deliberately excluded. Of the
|
|
253
|
+
* tones that work, the one nearest its farthest surface wins.
|
|
254
|
+
*/
|
|
255
|
+
sharedBorder(surfaceArgbs, opts = {}) {
|
|
256
|
+
if (surfaceArgbs.length === 0)
|
|
257
|
+
throw new Error('surfaceArgbs is empty');
|
|
258
|
+
const surfaces = surfaceArgbs;
|
|
259
|
+
const usage = opts.usage ?? Usage.border;
|
|
260
|
+
const model = opts.colorModel ?? defaultColorModel;
|
|
261
|
+
const key = `${usage}|${model}|${surfaces.join(',')}`;
|
|
262
|
+
const hit = this.borders.get(key);
|
|
263
|
+
if (hit !== undefined)
|
|
264
|
+
return hit;
|
|
265
|
+
const result = this.solveSharedBorder(surfaces, usage, model);
|
|
266
|
+
this.borders.set(key, result);
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
solveSharedBorder(surfaces, usage, model) {
|
|
270
|
+
const algo = this.algo;
|
|
271
|
+
const target = getAbsoluteContrast(algo, this.contrast, usage);
|
|
272
|
+
const rests = surfaces.map((s) => Hct.fromInt(s, model));
|
|
273
|
+
const surfaceYs = surfaces.map((s) => luminance(algo, s));
|
|
274
|
+
const tones = surfaces.map((s) => lstarFromArgb(s));
|
|
275
|
+
const darkest = Math.min(...tones);
|
|
276
|
+
const lightest = Math.max(...tones);
|
|
277
|
+
const memo = new Map();
|
|
278
|
+
const bordersAt = (t) => {
|
|
279
|
+
let bs = memo.get(t);
|
|
280
|
+
if (bs === undefined) {
|
|
281
|
+
bs = rests.map((h) => Hct.from(h.hue, h.chroma, t, model).toInt());
|
|
282
|
+
memo.set(t, bs);
|
|
283
|
+
}
|
|
284
|
+
return bs;
|
|
285
|
+
};
|
|
286
|
+
const backgroundWorst = (t) => {
|
|
287
|
+
if (this.luminances.length === 0)
|
|
288
|
+
return -Infinity;
|
|
289
|
+
let worst = Infinity;
|
|
290
|
+
for (const b of bordersAt(t))
|
|
291
|
+
worst = Math.min(worst, this.nearestContrast(luminance(algo, b)));
|
|
292
|
+
return worst;
|
|
293
|
+
};
|
|
294
|
+
const surfacesWorst = (t) => {
|
|
295
|
+
const bs = bordersAt(t);
|
|
296
|
+
let worst = Infinity;
|
|
297
|
+
for (let i = 0; i < bs.length; i++) {
|
|
298
|
+
worst = Math.min(worst, contrastOfYs(algo, luminance(algo, bs[i]), surfaceYs[i]));
|
|
299
|
+
}
|
|
300
|
+
return worst;
|
|
301
|
+
};
|
|
302
|
+
const at = (t) => {
|
|
303
|
+
const bg = backgroundWorst(t);
|
|
304
|
+
const clears = bg >= target;
|
|
305
|
+
const surf = clears ? Infinity : surfacesWorst(t);
|
|
306
|
+
return new SharedBorder(t, Object.freeze([...bordersAt(t)]), clears, clears || surf >= target, clears ? bg : surf);
|
|
307
|
+
};
|
|
308
|
+
const valid = (t) => backgroundWorst(t) >= target || surfacesWorst(t) >= target;
|
|
309
|
+
// Of the tones that work, the one nearest its farthest surface; ties go
|
|
310
|
+
// to the darker. Reach is the distance from the midpoint of the
|
|
311
|
+
// surfaces' tones plus a constant, so walk down and up from it, merging;
|
|
312
|
+
// a tie is a tone and its mirror, and the darker (down) goes first.
|
|
313
|
+
const reach = (t) => Math.max(t - darkest, lightest - t);
|
|
314
|
+
let down = Math.min(100, Math.max(0, Math.floor((darkest + lightest) / 2)));
|
|
315
|
+
let up = down + 1;
|
|
316
|
+
while (down >= 0 || up <= 100) {
|
|
317
|
+
const t = up > 100 || (down >= 0 && reach(down) <= reach(up)) ? down-- : up++;
|
|
318
|
+
if (valid(t))
|
|
319
|
+
return at(t);
|
|
320
|
+
}
|
|
321
|
+
let best = 0;
|
|
322
|
+
let bestWorst = -Infinity;
|
|
323
|
+
for (let t = 0; t <= 100; t++) {
|
|
324
|
+
const w = Math.max(backgroundWorst(t), surfacesWorst(t));
|
|
325
|
+
if (w > bestWorst) {
|
|
326
|
+
bestWorst = w;
|
|
327
|
+
best = t;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return at(best);
|
|
331
|
+
}
|
|
332
|
+
/** Weakest contrast of luminance y against any pixel; only neighbors can be weakest. */
|
|
333
|
+
nearestContrast(y) {
|
|
334
|
+
const ys = this.luminances;
|
|
335
|
+
let lo = 0, hi = ys.length;
|
|
336
|
+
while (lo < hi) {
|
|
337
|
+
const mid = (lo + hi) >> 1;
|
|
338
|
+
if (ys[mid] < y)
|
|
339
|
+
lo = mid + 1;
|
|
340
|
+
else
|
|
341
|
+
hi = mid;
|
|
342
|
+
}
|
|
343
|
+
let worst = Infinity;
|
|
344
|
+
if (lo < ys.length)
|
|
345
|
+
worst = Math.min(worst, contrastOfYs(this.algo, y, ys[lo]));
|
|
346
|
+
if (lo > 0)
|
|
347
|
+
worst = Math.min(worst, contrastOfYs(this.algo, y, ys[lo - 1]));
|
|
348
|
+
return worst;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// =============================================================================
|
|
352
|
+
// Internals.
|
|
353
|
+
// =============================================================================
|
|
354
|
+
/** Luminance in algo's own space: APCA's per-channel Y, or WCAG's Y (0..100). */
|
|
355
|
+
function luminance(algo, argb) {
|
|
356
|
+
return algo === Algo.apca ? apcaYFromArgb(argb) : yFromLstar(lstarFromArgb(argb));
|
|
357
|
+
}
|
|
358
|
+
/** Absolute contrast between luminances, stronger polarity. */
|
|
359
|
+
function contrastOfYs(algo, a, b) {
|
|
360
|
+
if (algo === Algo.apca) {
|
|
361
|
+
return Math.max(Math.abs(apcaContrastOfApcaY(a, b)), Math.abs(apcaContrastOfApcaY(b, a)));
|
|
362
|
+
}
|
|
363
|
+
return (Math.max(a, b) + 5) / (Math.min(a, b) + 5);
|
|
364
|
+
}
|
|
365
|
+
/** 8-bit source-over blend of scrim at alpha a (0..255) onto opaque bg. */
|
|
366
|
+
function blendArgb(bg, scrim, a) {
|
|
367
|
+
const ch = (b, s) => Math.round(((255 - a) * b + a * s) / 255);
|
|
368
|
+
return argbFromRgb(ch(redFromArgb(bg), redFromArgb(scrim)), ch(greenFromArgb(bg), greenFromArgb(scrim)), ch(blueFromArgb(bg), blueFromArgb(scrim)));
|
|
369
|
+
}
|
|
370
|
+
function evaluate(content, pixels, target, algo, scrim, a) {
|
|
371
|
+
const contentY = luminance(algo, content);
|
|
372
|
+
let allPass = true;
|
|
373
|
+
let anyLow = false, anyHigh = false;
|
|
374
|
+
let worst = Infinity;
|
|
375
|
+
for (const px of pixels) {
|
|
376
|
+
const blended = blendArgb(px, scrim, a);
|
|
377
|
+
const c = Math.abs(contrastBetweenArgbs(algo, blended, content));
|
|
378
|
+
if (c < worst)
|
|
379
|
+
worst = c;
|
|
380
|
+
if (c < target)
|
|
381
|
+
allPass = false;
|
|
382
|
+
if (luminance(algo, blended) < contentY)
|
|
383
|
+
anyLow = true;
|
|
384
|
+
else
|
|
385
|
+
anyHigh = true;
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
allPass,
|
|
389
|
+
oneSided: !(anyLow && anyHigh),
|
|
390
|
+
worstAbs: worst,
|
|
391
|
+
polarity: anyHigh && !anyLow ? Polarity.darkOnLight : Polarity.lightOnDark,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function solveForScrimColor(content, pixels, target, algo, scrim, canMix) {
|
|
395
|
+
const outcomes = [];
|
|
396
|
+
for (let a = 0; a <= 255; a++)
|
|
397
|
+
outcomes.push(evaluate(content, pixels, target, algo, scrim, a));
|
|
398
|
+
// Lowest alpha such that it and every higher alpha passes one-sided.
|
|
399
|
+
let solved;
|
|
400
|
+
for (let a = 255; a >= 0; a--) {
|
|
401
|
+
const o = outcomes[a];
|
|
402
|
+
if (o.allPass && o.oneSided)
|
|
403
|
+
solved = a;
|
|
404
|
+
else
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
if (solved === undefined) {
|
|
408
|
+
const at = outcomes[255];
|
|
409
|
+
return new Scrim(scrim, 1.0, false, at.worstAbs, at.polarity, false);
|
|
410
|
+
}
|
|
411
|
+
let mixed = false;
|
|
412
|
+
for (let a = 0; canMix && a < solved; a++) {
|
|
413
|
+
const o = outcomes[a];
|
|
414
|
+
if (o.allPass && !o.oneSided) {
|
|
415
|
+
mixed = true;
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const at = outcomes[solved];
|
|
420
|
+
return new Scrim(scrim, solved / 255, true, at.worstAbs, at.polarity, mixed);
|
|
421
|
+
}
|
|
422
|
+
// Standard normal CDF via Abramowitz & Stegun 7.1.26 (|err| < 1.5e-7).
|
|
423
|
+
// Keep bit-identical with lib/effects/over_image.dart.
|
|
424
|
+
function phi(z) {
|
|
425
|
+
return 0.5 * (1 + erf(z / Math.SQRT2));
|
|
426
|
+
}
|
|
427
|
+
function erf(x) {
|
|
428
|
+
const sign = x < 0 ? -1 : 1;
|
|
429
|
+
const ax = Math.abs(x);
|
|
430
|
+
const t = 1 / (1 + 0.3275911 * ax);
|
|
431
|
+
const y = 1 -
|
|
432
|
+
((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) *
|
|
433
|
+
t * Math.exp(-ax * ax);
|
|
434
|
+
return sign * y;
|
|
435
|
+
}
|
|
436
|
+
/** Blur radius to the sigma Skia blurs with (SkBlurMask::ConvertRadiusToSigma). */
|
|
437
|
+
function convertRadiusToSigma(radius) {
|
|
438
|
+
return radius > 0 ? radius * 0.57735 + 0.5 : 0;
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=over-image.js.map
|
|
@@ -0,0 +1 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K,CAAC,CAAC;AAC/E,CAAC;AAED,uEAAuE;AACvE,uDAAuD;AACvD,SAAS,GAAG,CAAC,CAAS;IACpB,OAAO,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,GAAG,CAAC,CAAS;IACpB,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvB,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,GAAG,EAAE,CAAC,CAAC;IACnC,MAAM,CAAC,GAAG,CAAC;QACT,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC;YAC3F,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACzB,OAAO,IAAI,GAAG,CAAC,CAAC;AAClB,CAAC;AAED,mFAAmF;AACnF,SAAS,oBAAoB,CAAC,MAAc;IAC1C,OAAO,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Argb } from './color.js';
|
|
2
|
+
import { type Palette, type PaletteRole } from './palette.js';
|
|
3
|
+
export type PaletteSnapshotRecord = Record<PaletteRole, Argb>;
|
|
4
|
+
export type PaletteSnapshotHexRecord = Record<PaletteRole, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Materialized snapshot of a Palette's role outputs.
|
|
7
|
+
*
|
|
8
|
+
* Dart's PaletteSnapshot captures every lazily-computed Palette role at a point
|
|
9
|
+
* in time. The JS version mirrors that behavior with immutable ARGB role data
|
|
10
|
+
* and the same role getters used by Palette.
|
|
11
|
+
*/
|
|
12
|
+
export declare class PaletteSnapshot {
|
|
13
|
+
private readonly roles;
|
|
14
|
+
private constructor();
|
|
15
|
+
static capture(palette: Pick<Palette, PaletteRole | 'toRecord'>): PaletteSnapshot;
|
|
16
|
+
static fromRecord(record: Record<string, Argb>): PaletteSnapshot;
|
|
17
|
+
static fromHexRecord(record: Record<string, string>): PaletteSnapshot;
|
|
18
|
+
private get;
|
|
19
|
+
get background(): Argb;
|
|
20
|
+
get backgroundText(): Argb;
|
|
21
|
+
get backgroundFill(): Argb;
|
|
22
|
+
get backgroundBorder(): Argb;
|
|
23
|
+
get backgroundHovered(): Argb;
|
|
24
|
+
get backgroundSplashed(): Argb;
|
|
25
|
+
get backgroundHoveredFill(): Argb;
|
|
26
|
+
get backgroundSplashedFill(): Argb;
|
|
27
|
+
get backgroundHoveredText(): Argb;
|
|
28
|
+
get backgroundSplashedText(): Argb;
|
|
29
|
+
get backgroundHoveredBorder(): Argb;
|
|
30
|
+
get backgroundSplashedBorder(): Argb;
|
|
31
|
+
get color(): Argb;
|
|
32
|
+
get colorText(): Argb;
|
|
33
|
+
get colorIcon(): Argb;
|
|
34
|
+
get colorHovered(): Argb;
|
|
35
|
+
get colorSplashed(): Argb;
|
|
36
|
+
get colorHoveredText(): Argb;
|
|
37
|
+
get colorSplashedText(): Argb;
|
|
38
|
+
get colorHoveredIcon(): Argb;
|
|
39
|
+
get colorSplashedIcon(): Argb;
|
|
40
|
+
get colorBorder(): Argb;
|
|
41
|
+
get colorHoveredBorder(): Argb;
|
|
42
|
+
get colorSplashedBorder(): Argb;
|
|
43
|
+
get fill(): Argb;
|
|
44
|
+
get fillText(): Argb;
|
|
45
|
+
get fillIcon(): Argb;
|
|
46
|
+
get fillHovered(): Argb;
|
|
47
|
+
get fillSplashed(): Argb;
|
|
48
|
+
get fillHoveredText(): Argb;
|
|
49
|
+
get fillSplashedText(): Argb;
|
|
50
|
+
get fillHoveredIcon(): Argb;
|
|
51
|
+
get fillSplashedIcon(): Argb;
|
|
52
|
+
get fillBorder(): Argb;
|
|
53
|
+
get fillHoveredBorder(): Argb;
|
|
54
|
+
get fillSplashedBorder(): Argb;
|
|
55
|
+
get text(): Argb;
|
|
56
|
+
get textHovered(): Argb;
|
|
57
|
+
get textSplashed(): Argb;
|
|
58
|
+
get textHoveredText(): Argb;
|
|
59
|
+
get textSplashedText(): Argb;
|
|
60
|
+
toRecord(): PaletteSnapshotRecord;
|
|
61
|
+
toHexRecord(): PaletteSnapshotHexRecord;
|
|
62
|
+
equals(other: PaletteSnapshot): boolean;
|
|
63
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { argbFromHex, hexFromArgb } from './color.js';
|
|
2
|
+
import { paletteRoles } from './palette.js';
|
|
3
|
+
/**
|
|
4
|
+
* Materialized snapshot of a Palette's role outputs.
|
|
5
|
+
*
|
|
6
|
+
* Dart's PaletteSnapshot captures every lazily-computed Palette role at a point
|
|
7
|
+
* in time. The JS version mirrors that behavior with immutable ARGB role data
|
|
8
|
+
* and the same role getters used by Palette.
|
|
9
|
+
*/
|
|
10
|
+
export class PaletteSnapshot {
|
|
11
|
+
roles;
|
|
12
|
+
constructor(record) {
|
|
13
|
+
this.roles = Object.freeze({ ...record });
|
|
14
|
+
}
|
|
15
|
+
static capture(palette) {
|
|
16
|
+
return new PaletteSnapshot(palette.toRecord());
|
|
17
|
+
}
|
|
18
|
+
static fromRecord(record) {
|
|
19
|
+
const out = {};
|
|
20
|
+
for (const role of paletteRoles) {
|
|
21
|
+
const value = record[role];
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
throw new Error(`Missing palette role: ${role}`);
|
|
24
|
+
out[role] = value;
|
|
25
|
+
}
|
|
26
|
+
return new PaletteSnapshot(out);
|
|
27
|
+
}
|
|
28
|
+
static fromHexRecord(record) {
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const role of paletteRoles) {
|
|
31
|
+
const value = record[role];
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
throw new Error(`Missing palette role: ${role}`);
|
|
34
|
+
out[role] = argbFromHex(value);
|
|
35
|
+
}
|
|
36
|
+
return new PaletteSnapshot(out);
|
|
37
|
+
}
|
|
38
|
+
get(role) { return this.roles[role]; }
|
|
39
|
+
get background() { return this.get('background'); }
|
|
40
|
+
get backgroundText() { return this.get('backgroundText'); }
|
|
41
|
+
get backgroundFill() { return this.get('backgroundFill'); }
|
|
42
|
+
get backgroundBorder() { return this.get('backgroundBorder'); }
|
|
43
|
+
get backgroundHovered() { return this.get('backgroundHovered'); }
|
|
44
|
+
get backgroundSplashed() { return this.get('backgroundSplashed'); }
|
|
45
|
+
get backgroundHoveredFill() { return this.get('backgroundHoveredFill'); }
|
|
46
|
+
get backgroundSplashedFill() { return this.get('backgroundSplashedFill'); }
|
|
47
|
+
get backgroundHoveredText() { return this.get('backgroundHoveredText'); }
|
|
48
|
+
get backgroundSplashedText() { return this.get('backgroundSplashedText'); }
|
|
49
|
+
get backgroundHoveredBorder() { return this.get('backgroundHoveredBorder'); }
|
|
50
|
+
get backgroundSplashedBorder() { return this.get('backgroundSplashedBorder'); }
|
|
51
|
+
get color() { return this.get('color'); }
|
|
52
|
+
get colorText() { return this.get('colorText'); }
|
|
53
|
+
get colorIcon() { return this.get('colorIcon'); }
|
|
54
|
+
get colorHovered() { return this.get('colorHovered'); }
|
|
55
|
+
get colorSplashed() { return this.get('colorSplashed'); }
|
|
56
|
+
get colorHoveredText() { return this.get('colorHoveredText'); }
|
|
57
|
+
get colorSplashedText() { return this.get('colorSplashedText'); }
|
|
58
|
+
get colorHoveredIcon() { return this.get('colorHoveredIcon'); }
|
|
59
|
+
get colorSplashedIcon() { return this.get('colorSplashedIcon'); }
|
|
60
|
+
get colorBorder() { return this.get('colorBorder'); }
|
|
61
|
+
get colorHoveredBorder() { return this.get('colorHoveredBorder'); }
|
|
62
|
+
get colorSplashedBorder() { return this.get('colorSplashedBorder'); }
|
|
63
|
+
get fill() { return this.get('fill'); }
|
|
64
|
+
get fillText() { return this.get('fillText'); }
|
|
65
|
+
get fillIcon() { return this.get('fillIcon'); }
|
|
66
|
+
get fillHovered() { return this.get('fillHovered'); }
|
|
67
|
+
get fillSplashed() { return this.get('fillSplashed'); }
|
|
68
|
+
get fillHoveredText() { return this.get('fillHoveredText'); }
|
|
69
|
+
get fillSplashedText() { return this.get('fillSplashedText'); }
|
|
70
|
+
get fillHoveredIcon() { return this.get('fillHoveredIcon'); }
|
|
71
|
+
get fillSplashedIcon() { return this.get('fillSplashedIcon'); }
|
|
72
|
+
get fillBorder() { return this.get('fillBorder'); }
|
|
73
|
+
get fillHoveredBorder() { return this.get('fillHoveredBorder'); }
|
|
74
|
+
get fillSplashedBorder() { return this.get('fillSplashedBorder'); }
|
|
75
|
+
get text() { return this.get('text'); }
|
|
76
|
+
get textHovered() { return this.get('textHovered'); }
|
|
77
|
+
get textSplashed() { return this.get('textSplashed'); }
|
|
78
|
+
get textHoveredText() { return this.get('textHoveredText'); }
|
|
79
|
+
get textSplashedText() { return this.get('textSplashedText'); }
|
|
80
|
+
toRecord() {
|
|
81
|
+
return { ...this.roles };
|
|
82
|
+
}
|
|
83
|
+
toHexRecord() {
|
|
84
|
+
const out = {};
|
|
85
|
+
for (const role of paletteRoles)
|
|
86
|
+
out[role] = hexFromArgb(this.roles[role]);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
equals(other) {
|
|
90
|
+
return paletteRoles.every(role => this.roles[role] === other.roles[role]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=palette-snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"palette-snapshot.js","sourceRoot":"","sources":["../src/palette-snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAAE,WAAW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