@pixerate/editor 0.256.0 → 0.257.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/agent/index.cjs +40 -38
- package/dist/agent/index.js +9 -7
- package/dist/animation/index.cjs +4 -2
- package/dist/animation/index.js +4 -2
- package/dist/animation-editor/index.cjs +63 -61
- package/dist/animation-editor/index.js +7 -5
- package/dist/brushes/colour.d.cts +11 -0
- package/dist/brushes/colour.d.ts +11 -0
- package/dist/brushes/index.cjs +51 -30
- package/dist/brushes/index.d.cts +1 -0
- package/dist/brushes/index.d.ts +1 -0
- package/dist/brushes/index.js +25 -4
- package/dist/brushes/resolve.d.cts +2 -0
- package/dist/brushes/resolve.d.ts +2 -0
- package/dist/brushes/schema.d.cts +1 -0
- package/dist/brushes/schema.d.ts +1 -0
- package/dist/brushes/tools.d.cts +7 -0
- package/dist/brushes/tools.d.ts +7 -0
- package/dist/brushes/types.d.cts +10 -2
- package/dist/brushes/types.d.ts +10 -2
- package/dist/brushes/ui.d.cts +14 -3
- package/dist/brushes/ui.d.ts +14 -3
- package/dist/{brushstrokeRender-HCOQUSWW.js → brushstrokeRender-JI4W6F2G.js} +2 -2
- package/dist/{brushstrokeRender-ZZOXI5O5.cjs → brushstrokeRender-MQ6PSDM5.cjs} +11 -11
- package/dist/canvas/index.cjs +20 -18
- package/dist/canvas/index.js +7 -5
- package/dist/chart/index.cjs +159 -157
- package/dist/chart/index.js +9 -7
- package/dist/{chunk-7272D3K2.js → chunk-2EUW2XZX.js} +27 -276
- package/dist/{chunk-L6Y7TSQ4.js → chunk-2VJ6OVJV.js} +1 -1
- package/dist/{chunk-6ZZKRH7R.js → chunk-47V3WXDG.js} +2 -2
- package/dist/{chunk-H7ET2ISK.cjs → chunk-4IMD2TLY.cjs} +52 -52
- package/dist/{chunk-VUKUTT2W.js → chunk-4M4E3N6X.js} +1 -1
- package/dist/{chunk-TBAVCLEQ.cjs → chunk-5Q5MLXAD.cjs} +23 -23
- package/dist/{chunk-MONXNVZK.js → chunk-6I23ZCGK.js} +5 -3
- package/dist/{chunk-GOBOCZZI.js → chunk-6NQPKNUZ.js} +1 -1
- package/dist/{chunk-WYGSR3IJ.js → chunk-AORZ5M5C.js} +1 -1
- package/dist/chunk-AVTPZO4Z.cjs +142 -0
- package/dist/{chunk-WKMUBATU.js → chunk-C2WEIEUB.js} +1 -1
- package/dist/{chunk-P3K2JCJA.js → chunk-D5BXSOSU.js} +3 -3
- package/dist/chunk-E2V5DA3W.js +36 -0
- package/dist/{chunk-WZOGDKCQ.js → chunk-F7CPSRLN.js} +0 -133
- package/dist/chunk-FJBQTZS4.js +17 -0
- package/dist/{chunk-SOSBOS5T.cjs → chunk-G23BTQA5.cjs} +22 -22
- package/dist/{chunk-EUIDTZNQ.cjs → chunk-I3Y2Q3PM.cjs} +59 -308
- package/dist/{chunk-YHUMGBZD.js → chunk-ICTPLVSR.js} +22 -4
- package/dist/{chunk-LRNUZKWV.cjs → chunk-IPUTIUGQ.cjs} +1 -1
- package/dist/{chunk-6GRUVGKU.js → chunk-ITURMC2M.js} +3 -3
- package/dist/{chunk-HYWRU5VX.js → chunk-IXQZHCOF.js} +1 -1
- package/dist/chunk-J5UQHWVL.js +142 -0
- package/dist/{chunk-YBAPT7NL.js → chunk-JC2SHA4A.js} +1 -23
- package/dist/chunk-LRTR4ASZ.cjs +17 -0
- package/dist/{chunk-HUAISCUX.cjs → chunk-M2HG5DJ2.cjs} +18 -18
- package/dist/{chunk-N76AMOKE.cjs → chunk-MDLEGVEN.cjs} +42 -42
- package/dist/chunk-MEGSQUQO.cjs +36 -0
- package/dist/chunk-MLLTWAXH.cjs +276 -0
- package/dist/{chunk-RHPSE2YR.js → chunk-MQ6MGIQM.js} +2 -2
- package/dist/{chunk-PGPFWC35.cjs → chunk-MQGQTKVW.cjs} +51 -33
- package/dist/{chunk-5YWWQ36H.cjs → chunk-O3ZVZSNJ.cjs} +9 -9
- package/dist/{chunk-GCTUOTCW.cjs → chunk-P3PZ63M3.cjs} +35 -35
- package/dist/{chunk-WRZ6C4TU.cjs → chunk-P6WYDBTH.cjs} +4 -4
- package/dist/{chunk-CJ6TBL2N.cjs → chunk-RHEMMGCN.cjs} +16 -16
- package/dist/{chunk-HIMGBZAM.cjs → chunk-RSIKDWOP.cjs} +201 -38
- package/dist/{chunk-SABJMH6M.cjs → chunk-RVGP2XLF.cjs} +2 -135
- package/dist/{chunk-JVRLGV3C.js → chunk-SMTUQWGY.js} +184 -21
- package/dist/{chunk-DMTEQ6SH.js → chunk-SSFMWJDK.js} +4 -4
- package/dist/{chunk-TFF2GTGN.cjs → chunk-SXQHWXEL.cjs} +2 -24
- package/dist/{chunk-IWEVV63O.cjs → chunk-UEYLANO3.cjs} +18 -16
- package/dist/chunk-VR6OGHU5.js +276 -0
- package/dist/{chunk-AF23QK5F.js → chunk-YQ4PQTBB.js} +1 -1
- package/dist/{chunk-B7V34GIH.cjs → chunk-YSGW7VV4.cjs} +88 -88
- package/dist/{chunk-3NS5C7FB.cjs → chunk-YYBW6DF2.cjs} +76 -76
- package/dist/{chunk-UFEDHACQ.js → chunk-Z7BX4TWO.js} +2 -2
- package/dist/{chunk-RUONPPMC.cjs → chunk-ZSE25IZA.cjs} +8 -8
- package/dist/color/index.cjs +7 -3
- package/dist/color/index.js +18 -14
- package/dist/export/index.cjs +8 -6
- package/dist/export/index.js +7 -5
- package/dist/extensions/index.cjs +11 -9
- package/dist/extensions/index.js +10 -8
- package/dist/gradient/index.cjs +33 -31
- package/dist/gradient/index.js +5 -3
- package/dist/image-editor/brush-presets.d.cts +4 -1
- package/dist/image-editor/brush-presets.d.ts +4 -1
- package/dist/image-editor/controller.d.cts +10 -5
- package/dist/image-editor/controller.d.ts +10 -5
- package/dist/image-editor/index.cjs +1090 -1073
- package/dist/image-editor/index.js +37 -20
- package/dist/index.cjs +17 -15
- package/dist/index.js +11 -9
- package/dist/paint-editor/brushes.d.cts +18 -1
- package/dist/paint-editor/brushes.d.ts +18 -1
- package/dist/paint-editor/controller.d.cts +29 -0
- package/dist/paint-editor/controller.d.ts +29 -0
- package/dist/paint-editor/engine.d.cts +7 -0
- package/dist/paint-editor/engine.d.ts +7 -0
- package/dist/paint-editor/index.cjs +1443 -1280
- package/dist/paint-editor/index.js +1117 -954
- package/dist/paint-editor/mark-settings.d.cts +1 -1
- package/dist/paint-editor/mark-settings.d.ts +1 -1
- package/dist/paint-editor/procedural.d.cts +4 -2
- package/dist/paint-editor/procedural.d.ts +4 -2
- package/dist/paint-editor/stamp-tip.d.cts +45 -0
- package/dist/paint-editor/stamp-tip.d.ts +45 -0
- package/dist/paint-editor/stroke.d.cts +2 -0
- package/dist/paint-editor/stroke.d.ts +2 -0
- package/dist/stickers/index.cjs +4 -2
- package/dist/stickers/index.js +6 -4
- package/dist/typography/index.cjs +3 -2
- package/dist/typography/index.js +2 -1
- package/dist/vector/index.cjs +971 -969
- package/dist/vector/index.js +8 -6
- package/dist/video-editor/index.cjs +4 -2
- package/dist/video-editor/index.js +4 -2
- package/package.json +1 -1
- package/skills/pixerate-brushes/SKILL.md +21 -11
- package/skills/pixerate-brushes-design/SKILL.md +6 -2
- package/skills/pixerate-brushes-design/evals/canvas-chalk.json +8 -8
- package/skills/pixerate-canvas/SKILL.md +3 -2
- package/skills/pixerate-image-editor/SKILL.md +1 -1
- package/skills/pixerate-paint-editor/SKILL.md +4 -1
- package/skills/pixerate-vector/SKILL.md +1 -1
package/dist/chart/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
TRENDLINE_PROPS,
|
|
18
18
|
VALUE,
|
|
19
19
|
WIDTH
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-6NQPKNUZ.js";
|
|
21
21
|
import {
|
|
22
22
|
CHART_OOXML_CONTENT_TYPE,
|
|
23
23
|
CHART_OOXML_NS,
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
chartFormatToCode,
|
|
26
26
|
chartFromOoxml,
|
|
27
27
|
chartToOoxml
|
|
28
|
-
} from "../chunk-
|
|
28
|
+
} from "../chunk-2VJ6OVJV.js";
|
|
29
29
|
import {
|
|
30
30
|
CHART_COLOR_SCHEMES,
|
|
31
31
|
CHART_LAYOUT_PRESETS,
|
|
@@ -47,7 +47,7 @@ import {
|
|
|
47
47
|
monochromeChartPalette,
|
|
48
48
|
sparklineToSvg,
|
|
49
49
|
summarizeChart
|
|
50
|
-
} from "../chunk-
|
|
50
|
+
} from "../chunk-MQ6MGIQM.js";
|
|
51
51
|
import "../chunk-KGRZMHZB.js";
|
|
52
52
|
import {
|
|
53
53
|
CHART_DATE_STEPS,
|
|
@@ -100,7 +100,7 @@ import {
|
|
|
100
100
|
suggestChartReferences,
|
|
101
101
|
summarizeChartSeries,
|
|
102
102
|
trendNumberText
|
|
103
|
-
} from "../chunk-
|
|
103
|
+
} from "../chunk-C2WEIEUB.js";
|
|
104
104
|
import "../chunk-O6OGNDND.js";
|
|
105
105
|
import {
|
|
106
106
|
CHART_AXIS_KINDS,
|
|
@@ -195,7 +195,7 @@ import {
|
|
|
195
195
|
shadeChartColor,
|
|
196
196
|
simulateChartVision,
|
|
197
197
|
uniqueChartSeriesId
|
|
198
|
-
} from "../chunk-
|
|
198
|
+
} from "../chunk-47V3WXDG.js";
|
|
199
199
|
import "../chunk-II2WIF5Z.js";
|
|
200
200
|
import {
|
|
201
201
|
parseCsv
|
|
@@ -216,8 +216,10 @@ import {
|
|
|
216
216
|
} from "../chunk-XBQX76CT.js";
|
|
217
217
|
import "../chunk-HF5QZS7Z.js";
|
|
218
218
|
import "../chunk-NS62CQ2B.js";
|
|
219
|
-
import "../chunk-
|
|
220
|
-
import "../chunk-
|
|
219
|
+
import "../chunk-2EUW2XZX.js";
|
|
220
|
+
import "../chunk-E2V5DA3W.js";
|
|
221
|
+
import "../chunk-VR6OGHU5.js";
|
|
222
|
+
import "../chunk-JC2SHA4A.js";
|
|
221
223
|
import "../chunk-MHLU6GRJ.js";
|
|
222
224
|
import "../chunk-6ONMQ6WF.js";
|
|
223
225
|
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
suggestAccessibleForeground
|
|
3
|
+
} from "./chunk-E2V5DA3W.js";
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_SCHEME_SURFACES,
|
|
6
|
+
checkDualColorContrast,
|
|
7
|
+
deriveDualColor,
|
|
8
|
+
dualColorsToCss,
|
|
9
|
+
formatDualColor,
|
|
10
|
+
normalizeDualColor
|
|
11
|
+
} from "./chunk-VR6OGHU5.js";
|
|
1
12
|
import {
|
|
2
13
|
deltaEOK,
|
|
3
14
|
formatColor,
|
|
4
15
|
formatHex,
|
|
5
16
|
inSrgbGamut,
|
|
6
17
|
normalizeColor,
|
|
7
|
-
suggestAccessibleForeground,
|
|
8
18
|
toSrgbGamut
|
|
9
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-JC2SHA4A.js";
|
|
10
20
|
import {
|
|
11
21
|
contrastLevel,
|
|
12
22
|
contrastRatio,
|
|
@@ -277,254 +287,6 @@ function pushRecentColor(list, color, max = 12) {
|
|
|
277
287
|
return next.slice(0, max);
|
|
278
288
|
}
|
|
279
289
|
|
|
280
|
-
// src/color/dual.ts
|
|
281
|
-
var DEFAULT_SCHEME_SURFACES = {
|
|
282
|
-
light: "#ffffff",
|
|
283
|
-
dark: "#0b0b0f"
|
|
284
|
-
};
|
|
285
|
-
var clamp = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
286
|
-
function isDualColor(value) {
|
|
287
|
-
return typeof value === "object" && value !== null && typeof value.light === "string" && typeof value.dark === "string";
|
|
288
|
-
}
|
|
289
|
-
function parseDualColor(input) {
|
|
290
|
-
if (input === null || input === void 0) return null;
|
|
291
|
-
if (isDualColor(input)) {
|
|
292
|
-
if (parseColor(input.light) === null || parseColor(input.dark) === null) {
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
return { light: input.light, dark: input.dark };
|
|
296
|
-
}
|
|
297
|
-
if (typeof input === "string") {
|
|
298
|
-
const trimmed = input.trim();
|
|
299
|
-
if (trimmed.toLowerCase().startsWith("light-dark(") && trimmed.endsWith(")")) {
|
|
300
|
-
const inner = trimmed.slice("light-dark(".length, -1).trim();
|
|
301
|
-
if (inner.toLowerCase().includes("light-dark(")) {
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
let depth = 0;
|
|
305
|
-
let commaIndex = -1;
|
|
306
|
-
for (let i = 0; i < inner.length; i++) {
|
|
307
|
-
const char = inner[i];
|
|
308
|
-
if (char === "(") {
|
|
309
|
-
depth++;
|
|
310
|
-
} else if (char === ")") {
|
|
311
|
-
depth--;
|
|
312
|
-
if (depth < 0) return null;
|
|
313
|
-
} else if (char === "," && depth === 0) {
|
|
314
|
-
if (commaIndex !== -1) {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
commaIndex = i;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
if (depth !== 0 || commaIndex === -1) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
const lightPart = inner.slice(0, commaIndex).trim();
|
|
324
|
-
const darkPart = inner.slice(commaIndex + 1).trim();
|
|
325
|
-
if (!lightPart || !darkPart) return null;
|
|
326
|
-
if (parseColor(lightPart) === null || parseColor(darkPart) === null) {
|
|
327
|
-
return null;
|
|
328
|
-
}
|
|
329
|
-
return { light: lightPart, dark: darkPart };
|
|
330
|
-
}
|
|
331
|
-
if (parseColor(trimmed) !== null) {
|
|
332
|
-
return { light: trimmed, dark: trimmed };
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
return null;
|
|
336
|
-
}
|
|
337
|
-
function normalizeDualColor(input) {
|
|
338
|
-
const parsed = parseDualColor(input);
|
|
339
|
-
if (!parsed) return null;
|
|
340
|
-
const light = normalizeColor(parsed.light);
|
|
341
|
-
const dark = normalizeColor(parsed.dark);
|
|
342
|
-
if (!light || !dark) return null;
|
|
343
|
-
return { light, dark };
|
|
344
|
-
}
|
|
345
|
-
function resolveColor(value, scheme) {
|
|
346
|
-
const normalized = normalizeDualColor(value);
|
|
347
|
-
if (!normalized) return null;
|
|
348
|
-
return scheme === "dark" ? normalized.dark : normalized.light;
|
|
349
|
-
}
|
|
350
|
-
function formatDualColor(value) {
|
|
351
|
-
const light = normalizeColor(value.light) ?? value.light;
|
|
352
|
-
const dark = normalizeColor(value.dark) ?? value.dark;
|
|
353
|
-
if (light === dark) {
|
|
354
|
-
return light;
|
|
355
|
-
}
|
|
356
|
-
return `light-dark(${light}, ${dark})`;
|
|
357
|
-
}
|
|
358
|
-
function isSameInBothSchemes(value) {
|
|
359
|
-
const light = normalizeColor(value.light);
|
|
360
|
-
const dark = normalizeColor(value.dark);
|
|
361
|
-
if (!light || !dark) return value.light === value.dark;
|
|
362
|
-
return light === dark;
|
|
363
|
-
}
|
|
364
|
-
function setDualColorSide(value, scheme, color) {
|
|
365
|
-
const base = normalizeDualColor(value) ?? { light: "#000000", dark: "#000000" };
|
|
366
|
-
const normColor = normalizeColor(color) ?? color;
|
|
367
|
-
return {
|
|
368
|
-
light: scheme === "light" ? normColor : base.light,
|
|
369
|
-
dark: scheme === "dark" ? normColor : base.dark
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
function deriveDualColor(color, options) {
|
|
373
|
-
const fromScheme = options?.from ?? "light";
|
|
374
|
-
const baseRgba = parseColor(color);
|
|
375
|
-
if (!baseRgba) {
|
|
376
|
-
throw new Error(`"${String(color)}" is not a colour; pass hex, rgb(), hsl(), oklch() or a CSS colour name.`);
|
|
377
|
-
}
|
|
378
|
-
if (options?.surfaces && !normalizeDualColor(options.surfaces)) {
|
|
379
|
-
throw new Error('The surfaces need a readable light and dark colour, e.g. { light: "#ffffff", dark: "#0b0b0f" }.');
|
|
380
|
-
}
|
|
381
|
-
const baseHex = formatHex(baseRgba);
|
|
382
|
-
const lab = rgbToOklab(baseRgba);
|
|
383
|
-
const lch = oklabToOklch(lab);
|
|
384
|
-
const startL = clamp(1.05 - lch.l, 0.12, 0.95);
|
|
385
|
-
const targetC = lch.c * 0.9;
|
|
386
|
-
const targetH = lch.h;
|
|
387
|
-
let derivedHex;
|
|
388
|
-
if (options?.surfaces) {
|
|
389
|
-
const surfaces = options.surfaces;
|
|
390
|
-
const fromSurfaceRgba = parseColor(surfaces[fromScheme]);
|
|
391
|
-
const targetScheme = fromScheme === "light" ? "dark" : "light";
|
|
392
|
-
const targetSurfaceRgba = parseColor(surfaces[targetScheme]);
|
|
393
|
-
const targetRatio = contrastRatio(baseRgba, fromSurfaceRgba);
|
|
394
|
-
const targetSurfaceL = oklabToOklch(rgbToOklab(targetSurfaceRgba)).l;
|
|
395
|
-
const preferHigherL = targetSurfaceL < 0.5;
|
|
396
|
-
let bestDiff = Infinity;
|
|
397
|
-
let bestL = startL;
|
|
398
|
-
for (let candL = 0.05; candL <= 0.98; candL += 5e-3) {
|
|
399
|
-
const candRgb = toSrgbGamut(
|
|
400
|
-
oklabToRgb(oklchToOklab({ l: candL, c: targetC, h: targetH, alpha: baseRgba.a }))
|
|
401
|
-
);
|
|
402
|
-
const ratio = contrastRatio(candRgb, targetSurfaceRgba);
|
|
403
|
-
const diff = Math.abs(ratio - targetRatio);
|
|
404
|
-
const isBetter = diff < bestDiff - 1e-4 || Math.abs(diff - bestDiff) <= 1e-4 && (preferHigherL ? candL > bestL : candL < bestL);
|
|
405
|
-
if (isBetter) {
|
|
406
|
-
bestDiff = diff;
|
|
407
|
-
bestL = candL;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
const finalRgba = toSrgbGamut(
|
|
411
|
-
oklabToRgb(oklchToOklab({ l: bestL, c: targetC, h: targetH, alpha: baseRgba.a }))
|
|
412
|
-
);
|
|
413
|
-
derivedHex = formatHex(finalRgba);
|
|
414
|
-
} else {
|
|
415
|
-
const finalRgba = toSrgbGamut(
|
|
416
|
-
oklabToRgb(oklchToOklab({ l: startL, c: targetC, h: targetH, alpha: baseRgba.a }))
|
|
417
|
-
);
|
|
418
|
-
derivedHex = formatHex(finalRgba);
|
|
419
|
-
}
|
|
420
|
-
return fromScheme === "light" ? { light: baseHex, dark: derivedHex } : { light: derivedHex, dark: baseHex };
|
|
421
|
-
}
|
|
422
|
-
function checkDualColorContrast(foreground, background, options) {
|
|
423
|
-
const large = options?.large ?? false;
|
|
424
|
-
const requiredRatio = large ? 3 : 4.5;
|
|
425
|
-
const fg = normalizeDualColor(foreground);
|
|
426
|
-
const bg = normalizeDualColor(background);
|
|
427
|
-
if (!fg) throw new Error(`The foreground "${describeValue(foreground)}" is not a colour, light-dark() or { light, dark }.`);
|
|
428
|
-
if (!bg) throw new Error(`The background "${describeValue(background)}" is not a colour, light-dark() or { light, dark }.`);
|
|
429
|
-
const lightFgHex = fg.light;
|
|
430
|
-
const lightBgHex = bg.light;
|
|
431
|
-
const darkFgHex = fg.dark;
|
|
432
|
-
const darkBgHex = bg.dark;
|
|
433
|
-
const lightFg = parseColor(lightFgHex);
|
|
434
|
-
const lightBg = parseColor(lightBgHex);
|
|
435
|
-
const darkFg = parseColor(darkFgHex);
|
|
436
|
-
const darkBg = parseColor(darkBgHex);
|
|
437
|
-
const lightRatio = Math.round(contrastRatio(lightFg, lightBg) * 100) / 100;
|
|
438
|
-
const darkRatio = Math.round(contrastRatio(darkFg, darkBg) * 100) / 100;
|
|
439
|
-
const lightLevel = contrastLevel(lightRatio, { large });
|
|
440
|
-
const darkLevel = contrastLevel(darkRatio, { large });
|
|
441
|
-
const issues = [];
|
|
442
|
-
if (lightLevel === "fail") {
|
|
443
|
-
issues.push(
|
|
444
|
-
`In light mode, ${lightFgHex} on ${lightBgHex} has a contrast of ${lightRatio.toFixed(1)} (needs ${requiredRatio} for AA).`
|
|
445
|
-
);
|
|
446
|
-
}
|
|
447
|
-
if (darkLevel === "fail") {
|
|
448
|
-
issues.push(
|
|
449
|
-
`In dark mode, ${darkFgHex} on ${darkBgHex} has a contrast of ${darkRatio.toFixed(1)} (needs ${requiredRatio} for AA).`
|
|
450
|
-
);
|
|
451
|
-
}
|
|
452
|
-
return {
|
|
453
|
-
light: { ratio: lightRatio, level: lightLevel },
|
|
454
|
-
dark: { ratio: darkRatio, level: darkLevel },
|
|
455
|
-
issues
|
|
456
|
-
};
|
|
457
|
-
}
|
|
458
|
-
var CSS_VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
459
|
-
function describeValue(value) {
|
|
460
|
-
return typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
461
|
-
}
|
|
462
|
-
function dualColorsToCss(colors, options) {
|
|
463
|
-
const selector = options?.selector ?? ":root";
|
|
464
|
-
const strategy = options?.strategy ?? "light-dark";
|
|
465
|
-
const darkSelector = options?.darkSelector ?? ".dark";
|
|
466
|
-
for (const [label, sel] of [["selector", selector], ["darkSelector", darkSelector]]) {
|
|
467
|
-
if (!sel.trim() || /[{};]/.test(sel)) {
|
|
468
|
-
throw new Error(`The ${label} "${sel}" is not a CSS selector (it can't be empty or contain "{", "}" or ";").`);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
const normalized = {};
|
|
472
|
-
for (const [key, value] of Object.entries(colors)) {
|
|
473
|
-
if (!CSS_VARIABLE_NAME.test(key)) {
|
|
474
|
-
throw new Error(`"${key}" is not a CSS variable name; use letters, digits, "-" and "_" without the leading "--" (e.g. "brand-color").`);
|
|
475
|
-
}
|
|
476
|
-
const dual = normalizeDualColor(value);
|
|
477
|
-
if (!dual) throw new Error(`"${key}" has "${describeValue(value)}", which is not a colour, light-dark() or { light, dark }.`);
|
|
478
|
-
normalized[key] = dual;
|
|
479
|
-
}
|
|
480
|
-
const sortedKeys = Object.keys(normalized).sort();
|
|
481
|
-
switch (strategy) {
|
|
482
|
-
case "light-dark": {
|
|
483
|
-
const lines = [
|
|
484
|
-
`${selector} {`,
|
|
485
|
-
...selector === ":root" ? [" color-scheme: light dark;"] : [],
|
|
486
|
-
...sortedKeys.map((k) => {
|
|
487
|
-
return ` --${k}: ${formatDualColor(normalized[k])};`;
|
|
488
|
-
}),
|
|
489
|
-
"}"
|
|
490
|
-
];
|
|
491
|
-
return lines.join("\n");
|
|
492
|
-
}
|
|
493
|
-
case "media": {
|
|
494
|
-
const lightLines = [
|
|
495
|
-
`${selector} {`,
|
|
496
|
-
...sortedKeys.map((k) => ` --${k}: ${normalized[k].light};`),
|
|
497
|
-
"}"
|
|
498
|
-
];
|
|
499
|
-
const darkLines = [
|
|
500
|
-
`@media (prefers-color-scheme: dark) {`,
|
|
501
|
-
` ${selector} {`,
|
|
502
|
-
...sortedKeys.map((k) => ` --${k}: ${normalized[k].dark};`),
|
|
503
|
-
` }`,
|
|
504
|
-
`}`
|
|
505
|
-
];
|
|
506
|
-
return `${lightLines.join("\n")}
|
|
507
|
-
|
|
508
|
-
${darkLines.join("\n")}`;
|
|
509
|
-
}
|
|
510
|
-
case "class": {
|
|
511
|
-
const lightLines = [
|
|
512
|
-
`${selector} {`,
|
|
513
|
-
...sortedKeys.map((k) => ` --${k}: ${normalized[k].light};`),
|
|
514
|
-
"}"
|
|
515
|
-
];
|
|
516
|
-
const darkLines = [
|
|
517
|
-
`${darkSelector} {`,
|
|
518
|
-
...sortedKeys.map((k) => ` --${k}: ${normalized[k].dark};`),
|
|
519
|
-
"}"
|
|
520
|
-
];
|
|
521
|
-
return `${lightLines.join("\n")}
|
|
522
|
-
|
|
523
|
-
${darkLines.join("\n")}`;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
290
|
// src/color/tools.ts
|
|
529
291
|
var READ = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
|
|
530
292
|
var fail = (message) => {
|
|
@@ -964,7 +726,7 @@ function createColorToolProvider(options = {}) {
|
|
|
964
726
|
}
|
|
965
727
|
|
|
966
728
|
// src/color/picker.ts
|
|
967
|
-
var
|
|
729
|
+
var clamp = (val, min, max) => Math.max(min, Math.min(max, val));
|
|
968
730
|
function pickerStateFromColor(input, previous) {
|
|
969
731
|
if (input === null || input === void 0) return null;
|
|
970
732
|
let rgba;
|
|
@@ -991,10 +753,10 @@ function pickerStateFromColor(input, previous) {
|
|
|
991
753
|
}
|
|
992
754
|
}
|
|
993
755
|
return {
|
|
994
|
-
h:
|
|
995
|
-
s:
|
|
996
|
-
v:
|
|
997
|
-
alpha:
|
|
756
|
+
h: clamp(h, 0, 360) % 360,
|
|
757
|
+
s: clamp(s, 0, 1),
|
|
758
|
+
v: clamp(v, 0, 1),
|
|
759
|
+
alpha: clamp(alpha, 0, 1)
|
|
998
760
|
};
|
|
999
761
|
}
|
|
1000
762
|
function pickerStateToHex(state, forceAlpha = false) {
|
|
@@ -1013,12 +775,12 @@ function pickerStateToHex(state, forceAlpha = false) {
|
|
|
1013
775
|
function pickerStateFromArea(state, x, y) {
|
|
1014
776
|
return {
|
|
1015
777
|
...state,
|
|
1016
|
-
s:
|
|
1017
|
-
v:
|
|
778
|
+
s: clamp(x, 0, 1),
|
|
779
|
+
v: clamp(1 - y, 0, 1)
|
|
1018
780
|
};
|
|
1019
781
|
}
|
|
1020
782
|
function pickerStateFromHue(state, t) {
|
|
1021
|
-
const clampedT =
|
|
783
|
+
const clampedT = clamp(t, 0, 1);
|
|
1022
784
|
const h = clampedT >= 1 ? 0 : clampedT * 360;
|
|
1023
785
|
return {
|
|
1024
786
|
...state,
|
|
@@ -1028,7 +790,7 @@ function pickerStateFromHue(state, t) {
|
|
|
1028
790
|
function pickerStateFromAlpha(state, t) {
|
|
1029
791
|
return {
|
|
1030
792
|
...state,
|
|
1031
|
-
alpha:
|
|
793
|
+
alpha: clamp(t, 0, 1)
|
|
1032
794
|
};
|
|
1033
795
|
}
|
|
1034
796
|
function pickerKeyStep(state, target, key, shift) {
|
|
@@ -1037,16 +799,16 @@ function pickerKeyStep(state, target, key, shift) {
|
|
|
1037
799
|
switch (target) {
|
|
1038
800
|
case "area": {
|
|
1039
801
|
if (key === "ArrowLeft") {
|
|
1040
|
-
return { ...state, s:
|
|
802
|
+
return { ...state, s: clamp(state.s - step, 0, 1) };
|
|
1041
803
|
}
|
|
1042
804
|
if (key === "ArrowRight") {
|
|
1043
|
-
return { ...state, s:
|
|
805
|
+
return { ...state, s: clamp(state.s + step, 0, 1) };
|
|
1044
806
|
}
|
|
1045
807
|
if (key === "ArrowDown") {
|
|
1046
|
-
return { ...state, v:
|
|
808
|
+
return { ...state, v: clamp(state.v - step, 0, 1) };
|
|
1047
809
|
}
|
|
1048
810
|
if (key === "ArrowUp") {
|
|
1049
|
-
return { ...state, v:
|
|
811
|
+
return { ...state, v: clamp(state.v + step, 0, 1) };
|
|
1050
812
|
}
|
|
1051
813
|
if (key === "Home") {
|
|
1052
814
|
return { ...state, s: 0, v: 1 };
|
|
@@ -1075,10 +837,10 @@ function pickerKeyStep(state, target, key, shift) {
|
|
|
1075
837
|
}
|
|
1076
838
|
case "alpha": {
|
|
1077
839
|
if (key === "ArrowLeft" || key === "ArrowDown") {
|
|
1078
|
-
return { ...state, alpha:
|
|
840
|
+
return { ...state, alpha: clamp(state.alpha - step, 0, 1) };
|
|
1079
841
|
}
|
|
1080
842
|
if (key === "ArrowRight" || key === "ArrowUp") {
|
|
1081
|
-
return { ...state, alpha:
|
|
843
|
+
return { ...state, alpha: clamp(state.alpha + step, 0, 1) };
|
|
1082
844
|
}
|
|
1083
845
|
if (key === "Home") {
|
|
1084
846
|
return { ...state, alpha: 0 };
|
|
@@ -1122,17 +884,6 @@ export {
|
|
|
1122
884
|
colorHarmony,
|
|
1123
885
|
mixColors,
|
|
1124
886
|
pushRecentColor,
|
|
1125
|
-
DEFAULT_SCHEME_SURFACES,
|
|
1126
|
-
isDualColor,
|
|
1127
|
-
parseDualColor,
|
|
1128
|
-
normalizeDualColor,
|
|
1129
|
-
resolveColor,
|
|
1130
|
-
formatDualColor,
|
|
1131
|
-
isSameInBothSchemes,
|
|
1132
|
-
setDualColorSide,
|
|
1133
|
-
deriveDualColor,
|
|
1134
|
-
checkDualColorContrast,
|
|
1135
|
-
dualColorsToCss,
|
|
1136
887
|
createColorToolProvider,
|
|
1137
888
|
pickerStateFromColor,
|
|
1138
889
|
pickerStateToHex,
|