@webmate-studio/builder 0.2.136 → 0.2.137
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/package.json +1 -1
- package/src/design-tokens-v2.js +375 -59
package/package.json
CHANGED
package/src/design-tokens-v2.js
CHANGED
|
@@ -8,79 +8,117 @@
|
|
|
8
8
|
* Dokumentation: webmate-studio/docs/DESIGN-TOKEN-SCHEMA-V2.md
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
// ─── Farbskala-Generierung
|
|
11
|
+
// ─── OKLCH-Farbskala-Generierung ────────────────────────────────────────────
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Preset-Kurven für die Chroma-Verteilung über die 12 Stufen.
|
|
15
|
+
* stdDev = Breite der Gaußkurve (wie weit Sättigung von der Base ausstrahlt)
|
|
16
|
+
* chromaScale = globaler Sättigungsmultiplikator
|
|
17
|
+
*/
|
|
18
|
+
export const COLOR_SCALE_PRESETS = {
|
|
19
|
+
vivid: { label: 'Leuchtend', stdDev: 28, chromaScale: 1.0 },
|
|
20
|
+
natural: { label: 'Natürlich', stdDev: 20, chromaScale: 0.85 },
|
|
21
|
+
soft: { label: 'Pastellig', stdDev: 13, chromaScale: 0.7 },
|
|
22
|
+
muted: { label: 'Gedämpft', stdDev: 18, chromaScale: 0.5 },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generiert eine 12-Stufen-Farbskala aus einer Basisfarbe im OKLCH-Farbraum.
|
|
15
27
|
* Stufe 9 = Basisfarbe. Stufen 1-8 heller, 10-12 dunkler.
|
|
16
28
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
29
|
+
* Verwendet OKLCH für perceptuell gleichmäßige Helligkeitsverteilung —
|
|
30
|
+
* garantiert monoton abnehmende Helligkeit von Stufe 1 bis 12.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} baseHex - Basisfarbe als Hex-String
|
|
33
|
+
* @param {object} [curve] - Optionale Kurvenparameter: { preset: 'natural' } oder { preset: 'custom', stdDev, chromaScale }
|
|
19
34
|
*/
|
|
20
|
-
export function generateColorScale(baseHex) {
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
35
|
+
export function generateColorScale(baseHex, curve) {
|
|
36
|
+
const base = hexToOklch(baseHex);
|
|
37
|
+
if (!base) return null;
|
|
38
|
+
|
|
39
|
+
// Kurvenparameter bestimmen
|
|
40
|
+
const presetName = curve?.preset || 'natural';
|
|
41
|
+
const preset = COLOR_SCALE_PRESETS[presetName];
|
|
42
|
+
const stdDev = curve?.preset === 'custom' ? (curve.stdDev ?? 20) : (preset?.stdDev ?? 20);
|
|
43
|
+
const chromaScale = curve?.preset === 'custom' ? (curve.chromaScale ?? 0.85) : (preset?.chromaScale ?? 0.85);
|
|
44
|
+
|
|
45
|
+
// Neutral-Erkennung: Basis mit niedriger Chroma
|
|
46
|
+
const isNeutral = base.c < 0.04;
|
|
47
|
+
|
|
48
|
+
// Lightness-Rampe adaptiv an Base-Lightness
|
|
49
|
+
const L = buildLightnessRamp(base.l);
|
|
50
|
+
|
|
51
|
+
// Wurde die Base-Lightness geclampt? (extrem helle/dunkle Farben)
|
|
52
|
+
const baseClamped = Math.abs(L[8] - base.l) > 0.01;
|
|
53
|
+
|
|
54
|
+
const scale = {};
|
|
55
|
+
for (let i = 0; i < 12; i++) {
|
|
56
|
+
const step = i + 1;
|
|
57
|
+
if (step === 9 && !baseClamped) {
|
|
58
|
+
// Step 9 = exakte Base-Farbe (wenn nicht geclampt)
|
|
59
|
+
scale[step] = baseHex;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
23
62
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
63
|
+
// Chroma über Gaußkurve berechnen
|
|
64
|
+
let c;
|
|
65
|
+
if (isNeutral) {
|
|
66
|
+
c = base.c * 0.3;
|
|
67
|
+
} else if (step === 9) {
|
|
68
|
+
// Geclampt: volle Base-Chroma bei korrigierter Lightness
|
|
69
|
+
c = base.c;
|
|
70
|
+
} else {
|
|
71
|
+
c = computeChroma(L[i], L[8], base.c, stdDev, chromaScale);
|
|
72
|
+
}
|
|
28
73
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// Helle Stufen: leichter Hue-Shift für natürlichere Farbverläufe
|
|
33
|
-
const hShift = isNeutral ? 0 : -5;
|
|
74
|
+
const mapped = gamutMapOklch(L[i], c, base.h);
|
|
75
|
+
scale[step] = oklchToHex(mapped.l, mapped.c, mapped.h);
|
|
76
|
+
}
|
|
34
77
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
6: hslToHex(h - 2, Math.min(s * 0.63 * sFactor, isNeutral ? 5 : 52), 77),
|
|
42
|
-
7: hslToHex(h - 1, Math.min(s * 0.6 * sFactor, isNeutral ? 5 : 50), 68),
|
|
43
|
-
8: hslToHex(h, Math.min(s * 0.62 * sFactor, isNeutral ? 6 : 50), 53),
|
|
44
|
-
9: baseHex,
|
|
45
|
-
10: hslToHex(h + 2, Math.min(s * 1.3 * sFactor, isNeutral ? 8 : 100), Math.max(l - 7, 15)),
|
|
46
|
-
11: hslToHex(h + 1, Math.min(s * 1.3 * sFactor, isNeutral ? 6 : 100), Math.max(l - 11, 20)),
|
|
47
|
-
12: hslToHex(h - 5, Math.min(s * 0.55 * sFactor, isNeutral ? 4 : 45), isNeutral ? 13 : Math.max(l * 0.5, 15)),
|
|
48
|
-
};
|
|
78
|
+
// Neutral Step 1 = reines Weiß
|
|
79
|
+
if (isNeutral) {
|
|
80
|
+
scale[1] = '#ffffff';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return scale;
|
|
49
84
|
}
|
|
50
85
|
|
|
51
86
|
/**
|
|
52
|
-
* Generiert eine invertierte 12-Stufen-Skala für Dark Mode.
|
|
87
|
+
* Generiert eine invertierte 12-Stufen-Skala für Dark Mode im OKLCH-Farbraum.
|
|
53
88
|
* Stufe 1 = dunkelster Wert, Stufe 12 = hellster.
|
|
54
89
|
*/
|
|
55
|
-
export function generateDarkColorScale(baseHex) {
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
const isNeutral =
|
|
65
|
-
|
|
90
|
+
export function generateDarkColorScale(baseHex, curve) {
|
|
91
|
+
const base = hexToOklch(baseHex);
|
|
92
|
+
if (!base) return null;
|
|
93
|
+
|
|
94
|
+
const presetName = curve?.preset || 'natural';
|
|
95
|
+
const preset = COLOR_SCALE_PRESETS[presetName];
|
|
96
|
+
const stdDev = curve?.preset === 'custom' ? (curve.stdDev ?? 20) : (preset?.stdDev ?? 20);
|
|
97
|
+
const chromaScale = curve?.preset === 'custom' ? (curve.chromaScale ?? 0.85) : (preset?.chromaScale ?? 0.85);
|
|
98
|
+
|
|
99
|
+
const isNeutral = base.c < 0.04;
|
|
100
|
+
|
|
101
|
+
// Dark Mode: Base etwas heller für bessere Sichtbarkeit
|
|
102
|
+
const darkBaseL = Math.min(base.l + 0.08, 0.65);
|
|
103
|
+
|
|
104
|
+
// Lightness-Rampe adaptiv (invertiert für Dark Mode)
|
|
105
|
+
const L = buildDarkLightnessRamp(darkBaseL);
|
|
106
|
+
|
|
107
|
+
const scale = {};
|
|
108
|
+
for (let i = 0; i < 12; i++) {
|
|
109
|
+
const step = i + 1;
|
|
110
|
+
let c;
|
|
111
|
+
if (isNeutral) {
|
|
112
|
+
c = base.c * 0.3;
|
|
113
|
+
} else {
|
|
114
|
+
c = computeChroma(L[i], L[8], base.c, stdDev, chromaScale);
|
|
115
|
+
}
|
|
66
116
|
|
|
67
|
-
|
|
68
|
-
|
|
117
|
+
const mapped = gamutMapOklch(L[i], c, base.h);
|
|
118
|
+
scale[step] = oklchToHex(mapped.l, mapped.c, mapped.h);
|
|
119
|
+
}
|
|
69
120
|
|
|
70
|
-
return
|
|
71
|
-
1: hslToHex(h, Math.min(s * 0.35 * sFactor, isNeutral ? 2 : 15), 8),
|
|
72
|
-
2: hslToHex(h, Math.min(s * 0.4 * sFactor, isNeutral ? 3 : 18), 12),
|
|
73
|
-
3: hslToHex(h, Math.min(s * 0.5 * sFactor, isNeutral ? 4 : 22), 18),
|
|
74
|
-
4: hslToHex(h, Math.min(s * 0.55 * sFactor, isNeutral ? 4 : 28), 24),
|
|
75
|
-
5: hslToHex(h, Math.min(s * 0.6 * sFactor, isNeutral ? 5 : 32), 30),
|
|
76
|
-
6: hslToHex(h - 2, Math.min(s * 0.63 * sFactor, isNeutral ? 5 : 40), 38),
|
|
77
|
-
7: hslToHex(h - 1, Math.min(s * 0.7 * sFactor, isNeutral ? 5 : 48), 48),
|
|
78
|
-
8: hslToHex(h, Math.min(s * 0.8 * sFactor, isNeutral ? 6 : 55), 58),
|
|
79
|
-
9: darkBase,
|
|
80
|
-
10: hslToHex(h + 1, Math.min(s * 0.85 * sFactor, isNeutral ? 6 : 65), Math.min(l + 20, 75)),
|
|
81
|
-
11: hslToHex(h + 2, Math.min(s * 0.6 * sFactor, isNeutral ? 5 : 50), Math.min(l + 35, 85)),
|
|
82
|
-
12: hslToHex(h - 3, Math.min(s * 0.35 * sFactor, isNeutral ? 3 : 30), Math.min(l + 50, 95)),
|
|
83
|
-
};
|
|
121
|
+
return scale;
|
|
84
122
|
}
|
|
85
123
|
|
|
86
124
|
/**
|
|
@@ -171,6 +209,274 @@ function hslToHex(h, s, l) {
|
|
|
171
209
|
return rgbToHex((r + m) * 255, (g + m) * 255, (b + m) * 255);
|
|
172
210
|
}
|
|
173
211
|
|
|
212
|
+
// ─── OKLCH-Hilfsfunktionen ──────────────────────────────────────────────────
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Baut eine strikt monoton fallende Lightness-Rampe für 12 Stufen.
|
|
216
|
+
* Steps 1-8 werden zwischen topL und baseL verteilt (Ease-Out-Kurve).
|
|
217
|
+
* Steps 10-12 werden zwischen baseL und bottomL verteilt.
|
|
218
|
+
* Step 9 = baseL (exakt).
|
|
219
|
+
*
|
|
220
|
+
* Funktioniert auch bei extremen Base-Werten (sehr hell/dunkel):
|
|
221
|
+
* - Die Rampe wird auf den verfügbaren Bereich komprimiert
|
|
222
|
+
* - Monotonie ist durch die Konstruktion garantiert
|
|
223
|
+
*/
|
|
224
|
+
function buildLightnessRamp(baseL) {
|
|
225
|
+
const topL = 0.985; // Step 1: fast Weiß
|
|
226
|
+
const bottomL = 0.25; // Step 12: dunkelster Wert
|
|
227
|
+
|
|
228
|
+
// Base clampen: min. 0.30 damit 3 dunkle Stufen Platz haben,
|
|
229
|
+
// max. 0.80 damit 8 helle Stufen genug Abstand in sRGB haben
|
|
230
|
+
const safeBaseL = Math.max(0.30, Math.min(0.80, baseL));
|
|
231
|
+
|
|
232
|
+
// Steps 1-8: Von topL nach safeBaseL + Lücke
|
|
233
|
+
// Die Lücke stellt sicher, dass Step 8 immer heller als Step 9 ist
|
|
234
|
+
const gap = Math.max(0.02, (topL - safeBaseL) * 0.05);
|
|
235
|
+
const step8Target = safeBaseL + gap;
|
|
236
|
+
const range = topL - step8Target;
|
|
237
|
+
|
|
238
|
+
// Feste Verteilungs-Gewichte: Steps 1-2 bleiben nahe Weiß,
|
|
239
|
+
// dann beschleunigter Abstieg zur Base. Inspiriert von Radix' Lightness-Verteilung.
|
|
240
|
+
const weights = [0.0, 0.04, 0.10, 0.20, 0.34, 0.50, 0.70, 0.92];
|
|
241
|
+
const lightSteps = weights.map(w => topL - w * range);
|
|
242
|
+
|
|
243
|
+
// Steps 10-12: nach unten von Base weg
|
|
244
|
+
const darkRange = safeBaseL - bottomL;
|
|
245
|
+
const step10L = safeBaseL - darkRange * 0.12;
|
|
246
|
+
const step11L = safeBaseL - darkRange * 0.55;
|
|
247
|
+
const step12L = bottomL;
|
|
248
|
+
|
|
249
|
+
const ramp = [
|
|
250
|
+
...lightSteps, // Steps 1-8
|
|
251
|
+
safeBaseL, // Step 9
|
|
252
|
+
step10L, // Step 10
|
|
253
|
+
step11L, // Step 11
|
|
254
|
+
step12L, // Step 12
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
// Finale Sicherheit: strikt monoton fallend
|
|
258
|
+
for (let i = 1; i < ramp.length; i++) {
|
|
259
|
+
if (ramp[i] >= ramp[i - 1]) {
|
|
260
|
+
ramp[i] = ramp[i - 1] - 0.003;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return ramp;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Baut eine strikt monoton steigende Lightness-Rampe für Dark Mode.
|
|
269
|
+
* Steps 1-8: dunkel → darkBaseL, Steps 10-12: darkBaseL → hell.
|
|
270
|
+
*/
|
|
271
|
+
function buildDarkLightnessRamp(darkBaseL) {
|
|
272
|
+
const bottomL = 0.14;
|
|
273
|
+
const topL = 0.94;
|
|
274
|
+
|
|
275
|
+
const safeBaseL = Math.max(0.22, Math.min(0.85, darkBaseL));
|
|
276
|
+
|
|
277
|
+
const gap = Math.max(0.02, (safeBaseL - bottomL) * 0.05);
|
|
278
|
+
const step8Target = safeBaseL - gap;
|
|
279
|
+
const range = step8Target - bottomL;
|
|
280
|
+
|
|
281
|
+
const weights = [0.0, 0.04, 0.10, 0.20, 0.34, 0.50, 0.70, 0.92];
|
|
282
|
+
const darkSteps = weights.map(w => bottomL + w * range);
|
|
283
|
+
|
|
284
|
+
const lightRange = topL - safeBaseL;
|
|
285
|
+
const step10L = safeBaseL + lightRange * 0.15;
|
|
286
|
+
const step11L = safeBaseL + lightRange * 0.55;
|
|
287
|
+
const step12L = topL;
|
|
288
|
+
|
|
289
|
+
const ramp = [
|
|
290
|
+
...darkSteps,
|
|
291
|
+
safeBaseL,
|
|
292
|
+
step10L,
|
|
293
|
+
step11L,
|
|
294
|
+
step12L,
|
|
295
|
+
];
|
|
296
|
+
|
|
297
|
+
for (let i = 1; i < ramp.length; i++) {
|
|
298
|
+
if (ramp[i] <= ramp[i - 1]) {
|
|
299
|
+
ramp[i] = ramp[i - 1] + 0.003;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return ramp;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Chroma-Berechnung für eine Stufe: Gaußkurve × Lightness-Begrenzung.
|
|
308
|
+
*
|
|
309
|
+
* Die Gaußkurve bestimmt den gewünschten Chroma-Anteil basierend auf der
|
|
310
|
+
* Distanz zur Base-Lightness. Zusätzlich wird die Chroma durch einen
|
|
311
|
+
* Lightness-Faktor begrenzt: Je näher an Weiß (L=1) oder Schwarz (L=0),
|
|
312
|
+
* desto weniger Chroma ist physisch/visuell sinnvoll.
|
|
313
|
+
*
|
|
314
|
+
* Das sorgt dafür, dass Steps 1-2 fast weiß und Steps 11-12 fast schwarz
|
|
315
|
+
* sind — wie bei Radix Colors.
|
|
316
|
+
*/
|
|
317
|
+
function computeChroma(stepL, baseL, baseC, stdDev, chromaScale) {
|
|
318
|
+
// Gaußkurve: Peak bei baseL
|
|
319
|
+
const diff = baseL - stepL;
|
|
320
|
+
const gaussian = Math.exp((-25 / stdDev) * diff * diff);
|
|
321
|
+
|
|
322
|
+
// Lightness-Begrenzung: Wie viel Chroma ist bei dieser Lightness sinnvoll?
|
|
323
|
+
// Bei L=0 oder L=1 → 0, bei L≈0.5-0.7 → Maximum
|
|
324
|
+
// Formel: sin-artige Kurve die bei L=0 und L=1 null ist
|
|
325
|
+
const lightnessLimit = Math.pow(Math.sin(stepL * Math.PI), 1.2);
|
|
326
|
+
|
|
327
|
+
return baseC * gaussian * lightnessLimit * chromaScale;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Hex → OKLCH Konvertierung.
|
|
333
|
+
* Pfad: Hex → sRGB → Linear RGB → OKLab → OKLCH
|
|
334
|
+
*/
|
|
335
|
+
function hexToOklch(hex) {
|
|
336
|
+
const rgb = hexToRgb(hex);
|
|
337
|
+
if (!rgb) return null;
|
|
338
|
+
|
|
339
|
+
// sRGB → Linear RGB (Gamma-Dekodierung)
|
|
340
|
+
const lr = srgbToLinear(rgb.r / 255);
|
|
341
|
+
const lg = srgbToLinear(rgb.g / 255);
|
|
342
|
+
const lb = srgbToLinear(rgb.b / 255);
|
|
343
|
+
|
|
344
|
+
// Linear RGB → OKLab
|
|
345
|
+
const lab = linearRgbToOklab(lr, lg, lb);
|
|
346
|
+
|
|
347
|
+
// OKLab → OKLCH
|
|
348
|
+
const c = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
|
|
349
|
+
let h = Math.atan2(lab.b, lab.a) * 180 / Math.PI;
|
|
350
|
+
if (h < 0) h += 360;
|
|
351
|
+
|
|
352
|
+
return { l: lab.l, c, h };
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* OKLCH → Hex Konvertierung.
|
|
357
|
+
* Pfad: OKLCH → OKLab → Linear RGB → sRGB → Hex
|
|
358
|
+
*/
|
|
359
|
+
function oklchToHex(l, c, h) {
|
|
360
|
+
// OKLCH → OKLab
|
|
361
|
+
const hRad = h * Math.PI / 180;
|
|
362
|
+
const a = c * Math.cos(hRad);
|
|
363
|
+
const b = c * Math.sin(hRad);
|
|
364
|
+
|
|
365
|
+
// OKLab → Linear RGB
|
|
366
|
+
const lin = oklabToLinearRgb(l, a, b);
|
|
367
|
+
|
|
368
|
+
// Linear RGB → sRGB (Gamma-Kodierung)
|
|
369
|
+
const sr = Math.round(linearToSrgb(lin.r) * 255);
|
|
370
|
+
const sg = Math.round(linearToSrgb(lin.g) * 255);
|
|
371
|
+
const sb = Math.round(linearToSrgb(lin.b) * 255);
|
|
372
|
+
|
|
373
|
+
return rgbToHex(
|
|
374
|
+
Math.max(0, Math.min(255, sr)),
|
|
375
|
+
Math.max(0, Math.min(255, sg)),
|
|
376
|
+
Math.max(0, Math.min(255, sb))
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Gamut-Mapping: Reduziert Chroma bis die Farbe in sRGB darstellbar ist.
|
|
382
|
+
* Behält Lightness und Hue bei.
|
|
383
|
+
*/
|
|
384
|
+
function gamutMapOklch(l, c, h) {
|
|
385
|
+
// Triviale Fälle
|
|
386
|
+
if (c <= 0) return { l, c: 0, h };
|
|
387
|
+
if (isInSrgbGamut(l, c, h)) return { l, c, h };
|
|
388
|
+
|
|
389
|
+
// Binary Search: Chroma reduzieren
|
|
390
|
+
let low = 0;
|
|
391
|
+
let high = c;
|
|
392
|
+
for (let i = 0; i < 20; i++) {
|
|
393
|
+
const mid = (low + high) / 2;
|
|
394
|
+
if (isInSrgbGamut(l, mid, h)) {
|
|
395
|
+
low = mid;
|
|
396
|
+
} else {
|
|
397
|
+
high = mid;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return { l, c: low, h };
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Prüft ob eine OKLCH-Farbe innerhalb des sRGB-Gamuts liegt.
|
|
405
|
+
*/
|
|
406
|
+
function isInSrgbGamut(l, c, h) {
|
|
407
|
+
const hRad = h * Math.PI / 180;
|
|
408
|
+
const a = c * Math.cos(hRad);
|
|
409
|
+
const b = c * Math.sin(hRad);
|
|
410
|
+
const lin = oklabToLinearRgb(l, a, b);
|
|
411
|
+
const eps = -0.001; // Kleine Toleranz für Rundungsfehler
|
|
412
|
+
return lin.r >= eps && lin.r <= 1.001 &&
|
|
413
|
+
lin.g >= eps && lin.g <= 1.001 &&
|
|
414
|
+
lin.b >= eps && lin.b <= 1.001;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Linear RGB → OKLab (Bjorn Ottosson, 2020)
|
|
419
|
+
*/
|
|
420
|
+
function linearRgbToOklab(r, g, b) {
|
|
421
|
+
// Linear RGB → LMS (via M1 Matrix)
|
|
422
|
+
const l_ = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
|
|
423
|
+
const m_ = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
|
|
424
|
+
const s_ = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
|
|
425
|
+
|
|
426
|
+
// Kubikwurzel
|
|
427
|
+
const l = Math.cbrt(l_);
|
|
428
|
+
const m = Math.cbrt(m_);
|
|
429
|
+
const s = Math.cbrt(s_);
|
|
430
|
+
|
|
431
|
+
// LMS → OKLab (via M2 Matrix)
|
|
432
|
+
return {
|
|
433
|
+
l: 0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s,
|
|
434
|
+
a: 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
|
|
435
|
+
b: 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* OKLab → Linear RGB (Inverse von linearRgbToOklab)
|
|
441
|
+
*/
|
|
442
|
+
function oklabToLinearRgb(L, a, b) {
|
|
443
|
+
// OKLab → LMS (inverse M2)
|
|
444
|
+
const l = L + 0.3963377774 * a + 0.2158037573 * b;
|
|
445
|
+
const m = L - 0.1055613458 * a - 0.0638541728 * b;
|
|
446
|
+
const s = L - 0.0894841775 * a - 1.2914855480 * b;
|
|
447
|
+
|
|
448
|
+
// LMS kubisch
|
|
449
|
+
const l3 = l * l * l;
|
|
450
|
+
const m3 = m * m * m;
|
|
451
|
+
const s3 = s * s * s;
|
|
452
|
+
|
|
453
|
+
// LMS → Linear RGB (inverse M1)
|
|
454
|
+
return {
|
|
455
|
+
r: 4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3,
|
|
456
|
+
g: -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3,
|
|
457
|
+
b: -0.0041960863 * l3 - 0.7034186147 * m3 + 1.7076147010 * s3,
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* sRGB Gamma-Dekodierung (sRGB → Linear)
|
|
463
|
+
*/
|
|
464
|
+
function srgbToLinear(c) {
|
|
465
|
+
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* sRGB Gamma-Kodierung (Linear → sRGB)
|
|
470
|
+
*/
|
|
471
|
+
function linearToSrgb(c) {
|
|
472
|
+
if (c <= 0) return 0;
|
|
473
|
+
if (c >= 1) return 1;
|
|
474
|
+
return c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
// ─── Legacy Farb-Hilfsfunktionen (HSL, Luminanz) ───────────────────────────
|
|
479
|
+
|
|
174
480
|
function relativeLuminance(r, g, b) {
|
|
175
481
|
const [rs, gs, bs] = [r, g, b].map(c => {
|
|
176
482
|
c = c / 255;
|
|
@@ -193,6 +499,8 @@ function contrastRatio(l1, l2) {
|
|
|
193
499
|
* Brand-Welten (primary, secondary, accent) + Status-Welten (success, warning, error, info) + Neutral.
|
|
194
500
|
*/
|
|
195
501
|
export const COLOR_WORLDS = ['primary', 'secondary', 'accent', 'success', 'warning', 'error', 'info', 'neutral'];
|
|
502
|
+
export const BRAND_COLOR_WORLDS = ['primary', 'secondary', 'accent', 'neutral'];
|
|
503
|
+
export const STATUS_COLOR_WORLDS = ['success', 'warning', 'error', 'info'];
|
|
196
504
|
export const SEMANTIC_COLOR_WORLDS = ['primary', 'secondary', 'accent', 'success', 'warning', 'error', 'info'];
|
|
197
505
|
|
|
198
506
|
/**
|
|
@@ -302,34 +610,42 @@ export const defaultDesignTokensV2 = {
|
|
|
302
610
|
colors: {
|
|
303
611
|
primary: {
|
|
304
612
|
base: '#1E40AF',
|
|
613
|
+
curve: { preset: 'natural' },
|
|
305
614
|
scale: generateColorScale('#1E40AF')
|
|
306
615
|
},
|
|
307
616
|
secondary: {
|
|
308
617
|
base: '#6366F1',
|
|
618
|
+
curve: { preset: 'natural' },
|
|
309
619
|
scale: generateColorScale('#6366F1')
|
|
310
620
|
},
|
|
311
621
|
accent: {
|
|
312
622
|
base: '#8B5CF6',
|
|
623
|
+
curve: { preset: 'natural' },
|
|
313
624
|
scale: generateColorScale('#8B5CF6')
|
|
314
625
|
},
|
|
315
626
|
success: {
|
|
316
627
|
base: '#16A34A',
|
|
628
|
+
curve: { preset: 'natural' },
|
|
317
629
|
scale: generateColorScale('#16A34A')
|
|
318
630
|
},
|
|
319
631
|
warning: {
|
|
320
632
|
base: '#D97706',
|
|
633
|
+
curve: { preset: 'natural' },
|
|
321
634
|
scale: generateColorScale('#D97706')
|
|
322
635
|
},
|
|
323
636
|
error: {
|
|
324
637
|
base: '#DC2626',
|
|
638
|
+
curve: { preset: 'natural' },
|
|
325
639
|
scale: generateColorScale('#DC2626')
|
|
326
640
|
},
|
|
327
641
|
info: {
|
|
328
642
|
base: '#2563EB',
|
|
643
|
+
curve: { preset: 'natural' },
|
|
329
644
|
scale: generateColorScale('#2563EB')
|
|
330
645
|
},
|
|
331
646
|
neutral: {
|
|
332
|
-
base: '#6B7280',
|
|
647
|
+
base: '#6B7280',
|
|
648
|
+
curve: { preset: 'natural' },
|
|
333
649
|
scale: generateColorScale('#6B7280')
|
|
334
650
|
}
|
|
335
651
|
},
|