@wiajs/core 1.0.11 → 1.1.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/LICENSE +44 -21
- package/README.md +6 -0
- package/dist/{core.cmn.js → core.cjs} +599 -29
- package/dist/core.js +982 -17
- package/dist/core.min.js +5 -5
- package/dist/{core.esm.js → core.mjs} +599 -29
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* wia core v1.
|
|
3
|
-
* (c) 2015-
|
|
2
|
+
* wia core v1.1.2
|
|
3
|
+
* (c) 2015-2024 Sibyl Yu and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
@@ -103,6 +103,10 @@ function clampInt(min, max, input) {
|
|
|
103
103
|
return input < min ? min : input > max ? max : input;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
function clampDouble(min, max, input) {
|
|
107
|
+
return input < min ? min : input > max ? max : input;
|
|
108
|
+
}
|
|
109
|
+
|
|
106
110
|
function sanitizeDegreesDouble(degrees) {
|
|
107
111
|
return (degrees %= 360) < 0 && (degrees += 360), degrees;
|
|
108
112
|
}
|
|
@@ -163,6 +167,10 @@ function yFromLstar(lstar) {
|
|
|
163
167
|
return 100 * labInvf((lstar + 16) / 116);
|
|
164
168
|
}
|
|
165
169
|
|
|
170
|
+
function lstarFromY(y) {
|
|
171
|
+
return 116 * labF(y / 100) - 16;
|
|
172
|
+
}
|
|
173
|
+
|
|
166
174
|
function linearized(rgbComponent) {
|
|
167
175
|
const normalized = rgbComponent / 255;
|
|
168
176
|
return normalized <= .040449936 ? normalized / 12.92 * 100 : 100 * Math.pow((normalized + .055) / 1.055, 2.4);
|
|
@@ -244,6 +252,14 @@ class Cam16 {
|
|
|
244
252
|
const alpha = 0 === this.chroma || 0 === this.j ? 0 : this.chroma / Math.sqrt(this.j / 100), t = Math.pow(alpha / Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), 1 / .9), hRad = this.hue * Math.PI / 180, eHue = .25 * (Math.cos(hRad + 2) + 3.8), ac = viewingConditions.aw * Math.pow(this.j / 100, 1 / viewingConditions.c / viewingConditions.z), p1 = eHue * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb, p2 = ac / viewingConditions.nbb, hSin = Math.sin(hRad), hCos = Math.cos(hRad), gamma = 23 * (p2 + .305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin), a = gamma * hCos, b = gamma * hSin, rA = (460 * p2 + 451 * a + 288 * b) / 1403, gA = (460 * p2 - 891 * a - 261 * b) / 1403, bA = (460 * p2 - 220 * a - 6300 * b) / 1403, rCBase = Math.max(0, 27.13 * Math.abs(rA) / (400 - Math.abs(rA))), rC = signum(rA) * (100 / viewingConditions.fl) * Math.pow(rCBase, 1 / .42), gCBase = Math.max(0, 27.13 * Math.abs(gA) / (400 - Math.abs(gA))), gC = signum(gA) * (100 / viewingConditions.fl) * Math.pow(gCBase, 1 / .42), bCBase = Math.max(0, 27.13 * Math.abs(bA) / (400 - Math.abs(bA))), bC = signum(bA) * (100 / viewingConditions.fl) * Math.pow(bCBase, 1 / .42), rF = rC / viewingConditions.rgbD[0], gF = gC / viewingConditions.rgbD[1], bF = bC / viewingConditions.rgbD[2];
|
|
245
253
|
return argbFromXyz(1.86206786 * rF - 1.01125463 * gF + .14918677 * bF, .38752654 * rF + .62144744 * gF - .00897398 * bF, -.0158415 * rF - .03412294 * gF + 1.04996444 * bF);
|
|
246
254
|
}
|
|
255
|
+
static fromXyzInViewingConditions(x, y, z, viewingConditions) {
|
|
256
|
+
const rC = .401288 * x + .650173 * y - .051461 * z, gC = -.250268 * x + 1.204414 * y + .045854 * z, bC = -.002079 * x + .048952 * y + .953127 * z, rD = viewingConditions.rgbD[0] * rC, gD = viewingConditions.rgbD[1] * gC, bD = viewingConditions.rgbD[2] * bC, rAF = Math.pow(viewingConditions.fl * Math.abs(rD) / 100, .42), gAF = Math.pow(viewingConditions.fl * Math.abs(gD) / 100, .42), bAF = Math.pow(viewingConditions.fl * Math.abs(bD) / 100, .42), rA = 400 * signum(rD) * rAF / (rAF + 27.13), gA = 400 * signum(gD) * gAF / (gAF + 27.13), bA = 400 * signum(bD) * bAF / (bAF + 27.13), a = (11 * rA + -12 * gA + bA) / 11, b = (rA + gA - 2 * bA) / 9, u = (20 * rA + 20 * gA + 21 * bA) / 20, p2 = (40 * rA + 20 * gA + bA) / 20, atanDegrees = 180 * Math.atan2(b, a) / Math.PI, hue = atanDegrees < 0 ? atanDegrees + 360 : atanDegrees >= 360 ? atanDegrees - 360 : atanDegrees, hueRadians = hue * Math.PI / 180, ac = p2 * viewingConditions.nbb, J = 100 * Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z), Q = 4 / viewingConditions.c * Math.sqrt(J / 100) * (viewingConditions.aw + 4) * viewingConditions.fLRoot, huePrime = hue < 20.14 ? hue + 360 : hue, t = 5e4 / 13 * (1 / 4 * (Math.cos(huePrime * Math.PI / 180 + 2) + 3.8)) * viewingConditions.nc * viewingConditions.ncb * Math.sqrt(a * a + b * b) / (u + .305), alpha = Math.pow(t, .9) * Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), C = alpha * Math.sqrt(J / 100), M = C * viewingConditions.fLRoot, s = 50 * Math.sqrt(alpha * viewingConditions.c / (viewingConditions.aw + 4)), jstar = (1 + 100 * .007) * J / (1 + .007 * J), mstar = Math.log(1 + .0228 * M) / .0228, astar = mstar * Math.cos(hueRadians), bstar = mstar * Math.sin(hueRadians);
|
|
257
|
+
return new Cam16(hue, C, J, Q, M, s, jstar, astar, bstar);
|
|
258
|
+
}
|
|
259
|
+
xyzInViewingConditions(viewingConditions) {
|
|
260
|
+
const alpha = 0 === this.chroma || 0 === this.j ? 0 : this.chroma / Math.sqrt(this.j / 100), t = Math.pow(alpha / Math.pow(1.64 - Math.pow(.29, viewingConditions.n), .73), 1 / .9), hRad = this.hue * Math.PI / 180, eHue = .25 * (Math.cos(hRad + 2) + 3.8), ac = viewingConditions.aw * Math.pow(this.j / 100, 1 / viewingConditions.c / viewingConditions.z), p1 = eHue * (5e4 / 13) * viewingConditions.nc * viewingConditions.ncb, p2 = ac / viewingConditions.nbb, hSin = Math.sin(hRad), hCos = Math.cos(hRad), gamma = 23 * (p2 + .305) * t / (23 * p1 + 11 * t * hCos + 108 * t * hSin), a = gamma * hCos, b = gamma * hSin, rA = (460 * p2 + 451 * a + 288 * b) / 1403, gA = (460 * p2 - 891 * a - 261 * b) / 1403, bA = (460 * p2 - 220 * a - 6300 * b) / 1403, rCBase = Math.max(0, 27.13 * Math.abs(rA) / (400 - Math.abs(rA))), rC = signum(rA) * (100 / viewingConditions.fl) * Math.pow(rCBase, 1 / .42), gCBase = Math.max(0, 27.13 * Math.abs(gA) / (400 - Math.abs(gA))), gC = signum(gA) * (100 / viewingConditions.fl) * Math.pow(gCBase, 1 / .42), bCBase = Math.max(0, 27.13 * Math.abs(bA) / (400 - Math.abs(bA))), bC = signum(bA) * (100 / viewingConditions.fl) * Math.pow(bCBase, 1 / .42), rF = rC / viewingConditions.rgbD[0], gF = gC / viewingConditions.rgbD[1], bF = bC / viewingConditions.rgbD[2];
|
|
261
|
+
return [ 1.86206786 * rF - 1.01125463 * gF + .14918677 * bF, .38752654 * rF + .62144744 * gF - .00897398 * bF, -.0158415 * rF - .03412294 * gF + 1.04996444 * bF ];
|
|
262
|
+
}
|
|
247
263
|
}
|
|
248
264
|
|
|
249
265
|
class HctSolver {
|
|
@@ -404,6 +420,10 @@ class Hct {
|
|
|
404
420
|
this.internalHue = cam.hue, this.internalChroma = cam.chroma, this.internalTone = lstarFromArgb(argb),
|
|
405
421
|
this.argb = argb;
|
|
406
422
|
}
|
|
423
|
+
inViewingConditions(vc) {
|
|
424
|
+
const viewedInVc = Cam16.fromInt(this.toInt()).xyzInViewingConditions(vc), recastInVc = Cam16.fromXyzInViewingConditions(viewedInVc[0], viewedInVc[1], viewedInVc[2], ViewingConditions.make());
|
|
425
|
+
return Hct.from(recastInVc.hue, recastInVc.chroma, lstarFromY(viewedInVc[1]));
|
|
426
|
+
}
|
|
407
427
|
}
|
|
408
428
|
|
|
409
429
|
class Blend {
|
|
@@ -421,22 +441,562 @@ class Blend {
|
|
|
421
441
|
}
|
|
422
442
|
}
|
|
423
443
|
|
|
444
|
+
class Contrast {
|
|
445
|
+
static ratioOfTones(toneA, toneB) {
|
|
446
|
+
return toneA = clampDouble(0, 100, toneA), toneB = clampDouble(0, 100, toneB), Contrast.ratioOfYs(yFromLstar(toneA), yFromLstar(toneB));
|
|
447
|
+
}
|
|
448
|
+
static ratioOfYs(y1, y2) {
|
|
449
|
+
const lighter = y1 > y2 ? y1 : y2;
|
|
450
|
+
return (lighter + 5) / ((lighter === y2 ? y1 : y2) + 5);
|
|
451
|
+
}
|
|
452
|
+
static lighter(tone, ratio) {
|
|
453
|
+
if (tone < 0 || tone > 100) return -1;
|
|
454
|
+
const darkY = yFromLstar(tone), lightY = ratio * (darkY + 5) - 5, realContrast = Contrast.ratioOfYs(lightY, darkY), delta = Math.abs(realContrast - ratio);
|
|
455
|
+
if (realContrast < ratio && delta > .04) return -1;
|
|
456
|
+
const returnValue = lstarFromY(lightY) + .4;
|
|
457
|
+
return returnValue < 0 || returnValue > 100 ? -1 : returnValue;
|
|
458
|
+
}
|
|
459
|
+
static darker(tone, ratio) {
|
|
460
|
+
if (tone < 0 || tone > 100) return -1;
|
|
461
|
+
const lightY = yFromLstar(tone), darkY = (lightY + 5) / ratio - 5, realContrast = Contrast.ratioOfYs(lightY, darkY), delta = Math.abs(realContrast - ratio);
|
|
462
|
+
if (realContrast < ratio && delta > .04) return -1;
|
|
463
|
+
const returnValue = lstarFromY(darkY) - .4;
|
|
464
|
+
return returnValue < 0 || returnValue > 100 ? -1 : returnValue;
|
|
465
|
+
}
|
|
466
|
+
static lighterUnsafe(tone, ratio) {
|
|
467
|
+
const lighterSafe = Contrast.lighter(tone, ratio);
|
|
468
|
+
return lighterSafe < 0 ? 100 : lighterSafe;
|
|
469
|
+
}
|
|
470
|
+
static darkerUnsafe(tone, ratio) {
|
|
471
|
+
const darkerSafe = Contrast.darker(tone, ratio);
|
|
472
|
+
return darkerSafe < 0 ? 0 : darkerSafe;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
class DislikeAnalyzer {
|
|
477
|
+
static isDisliked(hct) {
|
|
478
|
+
const huePasses = Math.round(hct.hue) >= 90 && Math.round(hct.hue) <= 111, chromaPasses = Math.round(hct.chroma) > 16, tonePasses = Math.round(hct.tone) < 65;
|
|
479
|
+
return huePasses && chromaPasses && tonePasses;
|
|
480
|
+
}
|
|
481
|
+
static fixIfDisliked(hct) {
|
|
482
|
+
return DislikeAnalyzer.isDisliked(hct) ? Hct.from(hct.hue, hct.chroma, 70) : hct;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
class DynamicColor {
|
|
487
|
+
static fromPalette(args) {
|
|
488
|
+
return new DynamicColor(args.name ?? "", args.palette, args.tone, args.isBackground ?? !1, args.background, args.secondBackground, args.contrastCurve, args.toneDeltaPair);
|
|
489
|
+
}
|
|
490
|
+
constructor(name, palette, tone, isBackground, background, secondBackground, contrastCurve, toneDeltaPair) {
|
|
491
|
+
if (this.name = name, this.palette = palette, this.tone = tone, this.isBackground = isBackground,
|
|
492
|
+
this.background = background, this.secondBackground = secondBackground, this.contrastCurve = contrastCurve,
|
|
493
|
+
this.toneDeltaPair = toneDeltaPair, this.hctCache = new Map, !background && secondBackground) throw new Error(`Color ${name} has secondBackgrounddefined, but background is not defined.`);
|
|
494
|
+
if (!background && contrastCurve) throw new Error(`Color ${name} has contrastCurvedefined, but background is not defined.`);
|
|
495
|
+
if (background && !contrastCurve) throw new Error(`Color ${name} has backgrounddefined, but contrastCurve is not defined.`);
|
|
496
|
+
}
|
|
497
|
+
getArgb(scheme) {
|
|
498
|
+
return this.getHct(scheme).toInt();
|
|
499
|
+
}
|
|
500
|
+
getHct(scheme) {
|
|
501
|
+
const cachedAnswer = this.hctCache.get(scheme);
|
|
502
|
+
if (null != cachedAnswer) return cachedAnswer;
|
|
503
|
+
const tone = this.getTone(scheme), answer = this.palette(scheme).getHct(tone);
|
|
504
|
+
return this.hctCache.size > 4 && this.hctCache.clear(), this.hctCache.set(scheme, answer),
|
|
505
|
+
answer;
|
|
506
|
+
}
|
|
507
|
+
getTone(scheme) {
|
|
508
|
+
const decreasingContrast = scheme.contrastLevel < 0;
|
|
509
|
+
if (this.toneDeltaPair) {
|
|
510
|
+
const toneDeltaPair = this.toneDeltaPair(scheme), roleA = toneDeltaPair.roleA, roleB = toneDeltaPair.roleB, delta = toneDeltaPair.delta, polarity = toneDeltaPair.polarity, stayTogether = toneDeltaPair.stayTogether, bgTone = this.background(scheme).getTone(scheme), aIsNearer = "nearer" === polarity || "lighter" === polarity && !scheme.isDark || "darker" === polarity && scheme.isDark, nearer = aIsNearer ? roleA : roleB, farther = aIsNearer ? roleB : roleA, amNearer = this.name === nearer.name, expansionDir = scheme.isDark ? 1 : -1, nContrast = nearer.contrastCurve.getContrast(scheme.contrastLevel), fContrast = farther.contrastCurve.getContrast(scheme.contrastLevel), nInitialTone = nearer.tone(scheme);
|
|
511
|
+
let nTone = Contrast.ratioOfTones(bgTone, nInitialTone) >= nContrast ? nInitialTone : DynamicColor.foregroundTone(bgTone, nContrast);
|
|
512
|
+
const fInitialTone = farther.tone(scheme);
|
|
513
|
+
let fTone = Contrast.ratioOfTones(bgTone, fInitialTone) >= fContrast ? fInitialTone : DynamicColor.foregroundTone(bgTone, fContrast);
|
|
514
|
+
return decreasingContrast && (nTone = DynamicColor.foregroundTone(bgTone, nContrast),
|
|
515
|
+
fTone = DynamicColor.foregroundTone(bgTone, fContrast)), (fTone - nTone) * expansionDir >= delta || (fTone = clampDouble(0, 100, nTone + delta * expansionDir),
|
|
516
|
+
(fTone - nTone) * expansionDir >= delta || (nTone = clampDouble(0, 100, fTone - delta * expansionDir))),
|
|
517
|
+
50 <= nTone && nTone < 60 ? expansionDir > 0 ? (nTone = 60, fTone = Math.max(fTone, nTone + delta * expansionDir)) : (nTone = 49,
|
|
518
|
+
fTone = Math.min(fTone, nTone + delta * expansionDir)) : 50 <= fTone && fTone < 60 && (stayTogether ? expansionDir > 0 ? (nTone = 60,
|
|
519
|
+
fTone = Math.max(fTone, nTone + delta * expansionDir)) : (nTone = 49, fTone = Math.min(fTone, nTone + delta * expansionDir)) : fTone = expansionDir > 0 ? 60 : 49),
|
|
520
|
+
amNearer ? nTone : fTone;
|
|
521
|
+
}
|
|
522
|
+
{
|
|
523
|
+
let answer = this.tone(scheme);
|
|
524
|
+
if (null == this.background) return answer;
|
|
525
|
+
const bgTone = this.background(scheme).getTone(scheme), desiredRatio = this.contrastCurve.getContrast(scheme.contrastLevel);
|
|
526
|
+
if (Contrast.ratioOfTones(bgTone, answer) >= desiredRatio || (answer = DynamicColor.foregroundTone(bgTone, desiredRatio)),
|
|
527
|
+
decreasingContrast && (answer = DynamicColor.foregroundTone(bgTone, desiredRatio)),
|
|
528
|
+
this.isBackground && 50 <= answer && answer < 60 && (answer = Contrast.ratioOfTones(49, bgTone) >= desiredRatio ? 49 : 60),
|
|
529
|
+
this.secondBackground) {
|
|
530
|
+
const [bg1, bg2] = [ this.background, this.secondBackground ], [bgTone1, bgTone2] = [ bg1(scheme).getTone(scheme), bg2(scheme).getTone(scheme) ], [upper, lower] = [ Math.max(bgTone1, bgTone2), Math.min(bgTone1, bgTone2) ];
|
|
531
|
+
if (Contrast.ratioOfTones(upper, answer) >= desiredRatio && Contrast.ratioOfTones(lower, answer) >= desiredRatio) return answer;
|
|
532
|
+
const lightOption = Contrast.lighter(upper, desiredRatio), darkOption = Contrast.darker(lower, desiredRatio), availables = [];
|
|
533
|
+
-1 !== lightOption && availables.push(lightOption), -1 !== darkOption && availables.push(darkOption);
|
|
534
|
+
return DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2) ? lightOption < 0 ? 100 : lightOption : 1 === availables.length ? availables[0] : darkOption < 0 ? 0 : darkOption;
|
|
535
|
+
}
|
|
536
|
+
return answer;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
static foregroundTone(bgTone, ratio) {
|
|
540
|
+
const lighterTone = Contrast.lighterUnsafe(bgTone, ratio), darkerTone = Contrast.darkerUnsafe(bgTone, ratio), lighterRatio = Contrast.ratioOfTones(lighterTone, bgTone), darkerRatio = Contrast.ratioOfTones(darkerTone, bgTone);
|
|
541
|
+
if (DynamicColor.tonePrefersLightForeground(bgTone)) {
|
|
542
|
+
const negligibleDifference = Math.abs(lighterRatio - darkerRatio) < .1 && lighterRatio < ratio && darkerRatio < ratio;
|
|
543
|
+
return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
|
|
544
|
+
}
|
|
545
|
+
return darkerRatio >= ratio || darkerRatio >= lighterRatio ? darkerTone : lighterTone;
|
|
546
|
+
}
|
|
547
|
+
static tonePrefersLightForeground(tone) {
|
|
548
|
+
return Math.round(tone) < 60;
|
|
549
|
+
}
|
|
550
|
+
static toneAllowsLightForeground(tone) {
|
|
551
|
+
return Math.round(tone) <= 49;
|
|
552
|
+
}
|
|
553
|
+
static enableLightForeground(tone) {
|
|
554
|
+
return DynamicColor.tonePrefersLightForeground(tone) && !DynamicColor.toneAllowsLightForeground(tone) ? 49 : tone;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
var Variant;
|
|
559
|
+
|
|
560
|
+
!function(Variant) {
|
|
561
|
+
Variant[Variant.MONOCHROME = 0] = "MONOCHROME", Variant[Variant.NEUTRAL = 1] = "NEUTRAL",
|
|
562
|
+
Variant[Variant.TONAL_SPOT = 2] = "TONAL_SPOT", Variant[Variant.VIBRANT = 3] = "VIBRANT",
|
|
563
|
+
Variant[Variant.EXPRESSIVE = 4] = "EXPRESSIVE", Variant[Variant.FIDELITY = 5] = "FIDELITY",
|
|
564
|
+
Variant[Variant.CONTENT = 6] = "CONTENT", Variant[Variant.RAINBOW = 7] = "RAINBOW",
|
|
565
|
+
Variant[Variant.FRUIT_SALAD = 8] = "FRUIT_SALAD";
|
|
566
|
+
}(Variant || (Variant = {}));
|
|
567
|
+
|
|
568
|
+
class ContrastCurve {
|
|
569
|
+
constructor(low, normal, medium, high) {
|
|
570
|
+
this.low = low, this.normal = normal, this.medium = medium, this.high = high;
|
|
571
|
+
}
|
|
572
|
+
getContrast(contrastLevel) {
|
|
573
|
+
return contrastLevel <= -1 ? this.low : contrastLevel < 0 ? lerp(this.low, this.normal, (contrastLevel - -1) / 1) : contrastLevel < .5 ? lerp(this.normal, this.medium, (contrastLevel - 0) / .5) : contrastLevel < 1 ? lerp(this.medium, this.high, (contrastLevel - .5) / .5) : this.high;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
class ToneDeltaPair {
|
|
578
|
+
constructor(roleA, roleB, delta, polarity, stayTogether) {
|
|
579
|
+
this.roleA = roleA, this.roleB = roleB, this.delta = delta, this.polarity = polarity,
|
|
580
|
+
this.stayTogether = stayTogether;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function isFidelity(scheme) {
|
|
585
|
+
return scheme.variant === Variant.FIDELITY || scheme.variant === Variant.CONTENT;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function isMonochrome(scheme) {
|
|
589
|
+
return scheme.variant === Variant.MONOCHROME;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
|
|
593
|
+
let answer = tone, closestToChroma = Hct.from(hue, chroma, tone);
|
|
594
|
+
if (closestToChroma.chroma < chroma) {
|
|
595
|
+
let chromaPeak = closestToChroma.chroma;
|
|
596
|
+
for (;closestToChroma.chroma < chroma; ) {
|
|
597
|
+
answer += byDecreasingTone ? -1 : 1;
|
|
598
|
+
const potentialSolution = Hct.from(hue, chroma, answer);
|
|
599
|
+
if (chromaPeak > potentialSolution.chroma) break;
|
|
600
|
+
if (Math.abs(potentialSolution.chroma - chroma) < .4) break;
|
|
601
|
+
Math.abs(potentialSolution.chroma - chroma) < Math.abs(closestToChroma.chroma - chroma) && (closestToChroma = potentialSolution),
|
|
602
|
+
chromaPeak = Math.max(chromaPeak, potentialSolution.chroma);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return answer;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
function viewingConditionsForAlbers(scheme) {
|
|
609
|
+
return ViewingConditions.make(void 0, void 0, scheme.isDark ? 30 : 80, void 0, void 0);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function performAlbers(prealbers, scheme) {
|
|
613
|
+
const albersd = prealbers.inViewingConditions(viewingConditionsForAlbers(scheme));
|
|
614
|
+
return DynamicColor.tonePrefersLightForeground(prealbers.tone) && !DynamicColor.toneAllowsLightForeground(albersd.tone) ? DynamicColor.enableLightForeground(prealbers.tone) : DynamicColor.enableLightForeground(albersd.tone);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
class MaterialDynamicColors {
|
|
618
|
+
static highestSurface(s) {
|
|
619
|
+
return s.isDark ? MaterialDynamicColors.surfaceBright : MaterialDynamicColors.surfaceDim;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
MaterialDynamicColors.contentAccentToneDelta = 15, MaterialDynamicColors.primaryPaletteKeyColor = DynamicColor.fromPalette({
|
|
624
|
+
name: "primary_palette_key_color",
|
|
625
|
+
palette: s => s.primaryPalette,
|
|
626
|
+
tone: s => s.primaryPalette.keyColor.tone
|
|
627
|
+
}), MaterialDynamicColors.secondaryPaletteKeyColor = DynamicColor.fromPalette({
|
|
628
|
+
name: "secondary_palette_key_color",
|
|
629
|
+
palette: s => s.secondaryPalette,
|
|
630
|
+
tone: s => s.secondaryPalette.keyColor.tone
|
|
631
|
+
}), MaterialDynamicColors.tertiaryPaletteKeyColor = DynamicColor.fromPalette({
|
|
632
|
+
name: "tertiary_palette_key_color",
|
|
633
|
+
palette: s => s.tertiaryPalette,
|
|
634
|
+
tone: s => s.tertiaryPalette.keyColor.tone
|
|
635
|
+
}), MaterialDynamicColors.neutralPaletteKeyColor = DynamicColor.fromPalette({
|
|
636
|
+
name: "neutral_palette_key_color",
|
|
637
|
+
palette: s => s.neutralPalette,
|
|
638
|
+
tone: s => s.neutralPalette.keyColor.tone
|
|
639
|
+
}), MaterialDynamicColors.neutralVariantPaletteKeyColor = DynamicColor.fromPalette({
|
|
640
|
+
name: "neutral_variant_palette_key_color",
|
|
641
|
+
palette: s => s.neutralVariantPalette,
|
|
642
|
+
tone: s => s.neutralVariantPalette.keyColor.tone
|
|
643
|
+
}), MaterialDynamicColors.background = DynamicColor.fromPalette({
|
|
644
|
+
name: "background",
|
|
645
|
+
palette: s => s.neutralPalette,
|
|
646
|
+
tone: s => s.isDark ? 6 : 98,
|
|
647
|
+
isBackground: !0
|
|
648
|
+
}), MaterialDynamicColors.onBackground = DynamicColor.fromPalette({
|
|
649
|
+
name: "on_background",
|
|
650
|
+
palette: s => s.neutralPalette,
|
|
651
|
+
tone: s => s.isDark ? 90 : 10,
|
|
652
|
+
background: s => MaterialDynamicColors.background,
|
|
653
|
+
contrastCurve: new ContrastCurve(3, 3, 4.5, 7)
|
|
654
|
+
}), MaterialDynamicColors.surface = DynamicColor.fromPalette({
|
|
655
|
+
name: "surface",
|
|
656
|
+
palette: s => s.neutralPalette,
|
|
657
|
+
tone: s => s.isDark ? 6 : 98,
|
|
658
|
+
isBackground: !0
|
|
659
|
+
}), MaterialDynamicColors.surfaceDim = DynamicColor.fromPalette({
|
|
660
|
+
name: "surface_dim",
|
|
661
|
+
palette: s => s.neutralPalette,
|
|
662
|
+
tone: s => s.isDark ? 6 : 87,
|
|
663
|
+
isBackground: !0
|
|
664
|
+
}), MaterialDynamicColors.surfaceBright = DynamicColor.fromPalette({
|
|
665
|
+
name: "surface_bright",
|
|
666
|
+
palette: s => s.neutralPalette,
|
|
667
|
+
tone: s => s.isDark ? 24 : 98,
|
|
668
|
+
isBackground: !0
|
|
669
|
+
}), MaterialDynamicColors.surfaceContainerLowest = DynamicColor.fromPalette({
|
|
670
|
+
name: "surface_container_lowest",
|
|
671
|
+
palette: s => s.neutralPalette,
|
|
672
|
+
tone: s => s.isDark ? 4 : 100,
|
|
673
|
+
isBackground: !0
|
|
674
|
+
}), MaterialDynamicColors.surfaceContainerLow = DynamicColor.fromPalette({
|
|
675
|
+
name: "surface_container_low",
|
|
676
|
+
palette: s => s.neutralPalette,
|
|
677
|
+
tone: s => s.isDark ? 10 : 96,
|
|
678
|
+
isBackground: !0
|
|
679
|
+
}), MaterialDynamicColors.surfaceContainer = DynamicColor.fromPalette({
|
|
680
|
+
name: "surface_container",
|
|
681
|
+
palette: s => s.neutralPalette,
|
|
682
|
+
tone: s => s.isDark ? 12 : 94,
|
|
683
|
+
isBackground: !0
|
|
684
|
+
}), MaterialDynamicColors.surfaceContainerHigh = DynamicColor.fromPalette({
|
|
685
|
+
name: "surface_container_high",
|
|
686
|
+
palette: s => s.neutralPalette,
|
|
687
|
+
tone: s => s.isDark ? 17 : 92,
|
|
688
|
+
isBackground: !0
|
|
689
|
+
}), MaterialDynamicColors.surfaceContainerHighest = DynamicColor.fromPalette({
|
|
690
|
+
name: "surface_container_highest",
|
|
691
|
+
palette: s => s.neutralPalette,
|
|
692
|
+
tone: s => s.isDark ? 22 : 90,
|
|
693
|
+
isBackground: !0
|
|
694
|
+
}), MaterialDynamicColors.onSurface = DynamicColor.fromPalette({
|
|
695
|
+
name: "on_surface",
|
|
696
|
+
palette: s => s.neutralPalette,
|
|
697
|
+
tone: s => s.isDark ? 90 : 10,
|
|
698
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
699
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
700
|
+
}), MaterialDynamicColors.surfaceVariant = DynamicColor.fromPalette({
|
|
701
|
+
name: "surface_variant",
|
|
702
|
+
palette: s => s.neutralVariantPalette,
|
|
703
|
+
tone: s => s.isDark ? 30 : 90,
|
|
704
|
+
isBackground: !0
|
|
705
|
+
}), MaterialDynamicColors.onSurfaceVariant = DynamicColor.fromPalette({
|
|
706
|
+
name: "on_surface_variant",
|
|
707
|
+
palette: s => s.neutralVariantPalette,
|
|
708
|
+
tone: s => s.isDark ? 80 : 30,
|
|
709
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
710
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
711
|
+
}), MaterialDynamicColors.inverseSurface = DynamicColor.fromPalette({
|
|
712
|
+
name: "inverse_surface",
|
|
713
|
+
palette: s => s.neutralPalette,
|
|
714
|
+
tone: s => s.isDark ? 90 : 20
|
|
715
|
+
}), MaterialDynamicColors.inverseOnSurface = DynamicColor.fromPalette({
|
|
716
|
+
name: "inverse_on_surface",
|
|
717
|
+
palette: s => s.neutralPalette,
|
|
718
|
+
tone: s => s.isDark ? 20 : 95,
|
|
719
|
+
background: s => MaterialDynamicColors.inverseSurface,
|
|
720
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
721
|
+
}), MaterialDynamicColors.outline = DynamicColor.fromPalette({
|
|
722
|
+
name: "outline",
|
|
723
|
+
palette: s => s.neutralVariantPalette,
|
|
724
|
+
tone: s => s.isDark ? 60 : 50,
|
|
725
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
726
|
+
contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7)
|
|
727
|
+
}), MaterialDynamicColors.outlineVariant = DynamicColor.fromPalette({
|
|
728
|
+
name: "outline_variant",
|
|
729
|
+
palette: s => s.neutralVariantPalette,
|
|
730
|
+
tone: s => s.isDark ? 30 : 80,
|
|
731
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
732
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7)
|
|
733
|
+
}), MaterialDynamicColors.shadow = DynamicColor.fromPalette({
|
|
734
|
+
name: "shadow",
|
|
735
|
+
palette: s => s.neutralPalette,
|
|
736
|
+
tone: s => 0
|
|
737
|
+
}), MaterialDynamicColors.scrim = DynamicColor.fromPalette({
|
|
738
|
+
name: "scrim",
|
|
739
|
+
palette: s => s.neutralPalette,
|
|
740
|
+
tone: s => 0
|
|
741
|
+
}), MaterialDynamicColors.surfaceTint = DynamicColor.fromPalette({
|
|
742
|
+
name: "surface_tint",
|
|
743
|
+
palette: s => s.primaryPalette,
|
|
744
|
+
tone: s => s.isDark ? 80 : 40,
|
|
745
|
+
isBackground: !0
|
|
746
|
+
}), MaterialDynamicColors.primary = DynamicColor.fromPalette({
|
|
747
|
+
name: "primary",
|
|
748
|
+
palette: s => s.primaryPalette,
|
|
749
|
+
tone: s => isMonochrome(s) ? s.isDark ? 100 : 0 : s.isDark ? 80 : 40,
|
|
750
|
+
isBackground: !0,
|
|
751
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
752
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
753
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryContainer, MaterialDynamicColors.primary, 15, "nearer", !1)
|
|
754
|
+
}), MaterialDynamicColors.onPrimary = DynamicColor.fromPalette({
|
|
755
|
+
name: "on_primary",
|
|
756
|
+
palette: s => s.primaryPalette,
|
|
757
|
+
tone: s => isMonochrome(s) ? s.isDark ? 10 : 90 : s.isDark ? 20 : 100,
|
|
758
|
+
background: s => MaterialDynamicColors.primary,
|
|
759
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
760
|
+
}), MaterialDynamicColors.primaryContainer = DynamicColor.fromPalette({
|
|
761
|
+
name: "primary_container",
|
|
762
|
+
palette: s => s.primaryPalette,
|
|
763
|
+
tone: s => isFidelity(s) ? performAlbers(s.sourceColorHct, s) : isMonochrome(s) ? s.isDark ? 85 : 25 : s.isDark ? 30 : 90,
|
|
764
|
+
isBackground: !0,
|
|
765
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
766
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
767
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryContainer, MaterialDynamicColors.primary, 15, "nearer", !1)
|
|
768
|
+
}), MaterialDynamicColors.onPrimaryContainer = DynamicColor.fromPalette({
|
|
769
|
+
name: "on_primary_container",
|
|
770
|
+
palette: s => s.primaryPalette,
|
|
771
|
+
tone: s => isFidelity(s) ? DynamicColor.foregroundTone(MaterialDynamicColors.primaryContainer.tone(s), 4.5) : isMonochrome(s) ? s.isDark ? 0 : 100 : s.isDark ? 90 : 10,
|
|
772
|
+
background: s => MaterialDynamicColors.primaryContainer,
|
|
773
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
774
|
+
}), MaterialDynamicColors.inversePrimary = DynamicColor.fromPalette({
|
|
775
|
+
name: "inverse_primary",
|
|
776
|
+
palette: s => s.primaryPalette,
|
|
777
|
+
tone: s => s.isDark ? 40 : 80,
|
|
778
|
+
background: s => MaterialDynamicColors.inverseSurface,
|
|
779
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
780
|
+
}), MaterialDynamicColors.secondary = DynamicColor.fromPalette({
|
|
781
|
+
name: "secondary",
|
|
782
|
+
palette: s => s.secondaryPalette,
|
|
783
|
+
tone: s => s.isDark ? 80 : 40,
|
|
784
|
+
isBackground: !0,
|
|
785
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
786
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
787
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryContainer, MaterialDynamicColors.secondary, 15, "nearer", !1)
|
|
788
|
+
}), MaterialDynamicColors.onSecondary = DynamicColor.fromPalette({
|
|
789
|
+
name: "on_secondary",
|
|
790
|
+
palette: s => s.secondaryPalette,
|
|
791
|
+
tone: s => isMonochrome(s) ? s.isDark ? 10 : 100 : s.isDark ? 20 : 100,
|
|
792
|
+
background: s => MaterialDynamicColors.secondary,
|
|
793
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
794
|
+
}), MaterialDynamicColors.secondaryContainer = DynamicColor.fromPalette({
|
|
795
|
+
name: "secondary_container",
|
|
796
|
+
palette: s => s.secondaryPalette,
|
|
797
|
+
tone: s => {
|
|
798
|
+
const initialTone = s.isDark ? 30 : 90;
|
|
799
|
+
if (isMonochrome(s)) return s.isDark ? 30 : 85;
|
|
800
|
+
if (!isFidelity(s)) return initialTone;
|
|
801
|
+
let answer = findDesiredChromaByTone(s.secondaryPalette.hue, s.secondaryPalette.chroma, initialTone, !s.isDark);
|
|
802
|
+
return answer = performAlbers(s.secondaryPalette.getHct(answer), s), answer;
|
|
803
|
+
},
|
|
804
|
+
isBackground: !0,
|
|
805
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
806
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
807
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryContainer, MaterialDynamicColors.secondary, 15, "nearer", !1)
|
|
808
|
+
}), MaterialDynamicColors.onSecondaryContainer = DynamicColor.fromPalette({
|
|
809
|
+
name: "on_secondary_container",
|
|
810
|
+
palette: s => s.secondaryPalette,
|
|
811
|
+
tone: s => isFidelity(s) ? DynamicColor.foregroundTone(MaterialDynamicColors.secondaryContainer.tone(s), 4.5) : s.isDark ? 90 : 10,
|
|
812
|
+
background: s => MaterialDynamicColors.secondaryContainer,
|
|
813
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
814
|
+
}), MaterialDynamicColors.tertiary = DynamicColor.fromPalette({
|
|
815
|
+
name: "tertiary",
|
|
816
|
+
palette: s => s.tertiaryPalette,
|
|
817
|
+
tone: s => isMonochrome(s) ? s.isDark ? 90 : 25 : s.isDark ? 80 : 40,
|
|
818
|
+
isBackground: !0,
|
|
819
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
820
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
821
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryContainer, MaterialDynamicColors.tertiary, 15, "nearer", !1)
|
|
822
|
+
}), MaterialDynamicColors.onTertiary = DynamicColor.fromPalette({
|
|
823
|
+
name: "on_tertiary",
|
|
824
|
+
palette: s => s.tertiaryPalette,
|
|
825
|
+
tone: s => isMonochrome(s) ? s.isDark ? 10 : 90 : s.isDark ? 20 : 100,
|
|
826
|
+
background: s => MaterialDynamicColors.tertiary,
|
|
827
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
828
|
+
}), MaterialDynamicColors.tertiaryContainer = DynamicColor.fromPalette({
|
|
829
|
+
name: "tertiary_container",
|
|
830
|
+
palette: s => s.tertiaryPalette,
|
|
831
|
+
tone: s => {
|
|
832
|
+
if (isMonochrome(s)) return s.isDark ? 60 : 49;
|
|
833
|
+
if (!isFidelity(s)) return s.isDark ? 30 : 90;
|
|
834
|
+
const albersTone = performAlbers(s.tertiaryPalette.getHct(s.sourceColorHct.tone), s), proposedHct = s.tertiaryPalette.getHct(albersTone);
|
|
835
|
+
return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
|
|
836
|
+
},
|
|
837
|
+
isBackground: !0,
|
|
838
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
839
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
840
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryContainer, MaterialDynamicColors.tertiary, 15, "nearer", !1)
|
|
841
|
+
}), MaterialDynamicColors.onTertiaryContainer = DynamicColor.fromPalette({
|
|
842
|
+
name: "on_tertiary_container",
|
|
843
|
+
palette: s => s.tertiaryPalette,
|
|
844
|
+
tone: s => isMonochrome(s) ? s.isDark ? 0 : 100 : isFidelity(s) ? DynamicColor.foregroundTone(MaterialDynamicColors.tertiaryContainer.tone(s), 4.5) : s.isDark ? 90 : 10,
|
|
845
|
+
background: s => MaterialDynamicColors.tertiaryContainer,
|
|
846
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
847
|
+
}), MaterialDynamicColors.error = DynamicColor.fromPalette({
|
|
848
|
+
name: "error",
|
|
849
|
+
palette: s => s.errorPalette,
|
|
850
|
+
tone: s => s.isDark ? 80 : 40,
|
|
851
|
+
isBackground: !0,
|
|
852
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
853
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11),
|
|
854
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.errorContainer, MaterialDynamicColors.error, 15, "nearer", !1)
|
|
855
|
+
}), MaterialDynamicColors.onError = DynamicColor.fromPalette({
|
|
856
|
+
name: "on_error",
|
|
857
|
+
palette: s => s.errorPalette,
|
|
858
|
+
tone: s => s.isDark ? 20 : 100,
|
|
859
|
+
background: s => MaterialDynamicColors.error,
|
|
860
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
861
|
+
}), MaterialDynamicColors.errorContainer = DynamicColor.fromPalette({
|
|
862
|
+
name: "error_container",
|
|
863
|
+
palette: s => s.errorPalette,
|
|
864
|
+
tone: s => s.isDark ? 30 : 90,
|
|
865
|
+
isBackground: !0,
|
|
866
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
867
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
868
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.errorContainer, MaterialDynamicColors.error, 15, "nearer", !1)
|
|
869
|
+
}), MaterialDynamicColors.onErrorContainer = DynamicColor.fromPalette({
|
|
870
|
+
name: "on_error_container",
|
|
871
|
+
palette: s => s.errorPalette,
|
|
872
|
+
tone: s => s.isDark ? 90 : 10,
|
|
873
|
+
background: s => MaterialDynamicColors.errorContainer,
|
|
874
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
875
|
+
}), MaterialDynamicColors.primaryFixed = DynamicColor.fromPalette({
|
|
876
|
+
name: "primary_fixed",
|
|
877
|
+
palette: s => s.primaryPalette,
|
|
878
|
+
tone: s => isMonochrome(s) ? 40 : 90,
|
|
879
|
+
isBackground: !0,
|
|
880
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
881
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
882
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryFixed, MaterialDynamicColors.primaryFixedDim, 10, "lighter", !0)
|
|
883
|
+
}), MaterialDynamicColors.primaryFixedDim = DynamicColor.fromPalette({
|
|
884
|
+
name: "primary_fixed_dim",
|
|
885
|
+
palette: s => s.primaryPalette,
|
|
886
|
+
tone: s => isMonochrome(s) ? 30 : 80,
|
|
887
|
+
isBackground: !0,
|
|
888
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
889
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
890
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryFixed, MaterialDynamicColors.primaryFixedDim, 10, "lighter", !0)
|
|
891
|
+
}), MaterialDynamicColors.onPrimaryFixed = DynamicColor.fromPalette({
|
|
892
|
+
name: "on_primary_fixed",
|
|
893
|
+
palette: s => s.primaryPalette,
|
|
894
|
+
tone: s => isMonochrome(s) ? 100 : 10,
|
|
895
|
+
background: s => MaterialDynamicColors.primaryFixedDim,
|
|
896
|
+
secondBackground: s => MaterialDynamicColors.primaryFixed,
|
|
897
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
898
|
+
}), MaterialDynamicColors.onPrimaryFixedVariant = DynamicColor.fromPalette({
|
|
899
|
+
name: "on_primary_fixed_variant",
|
|
900
|
+
palette: s => s.primaryPalette,
|
|
901
|
+
tone: s => isMonochrome(s) ? 90 : 30,
|
|
902
|
+
background: s => MaterialDynamicColors.primaryFixedDim,
|
|
903
|
+
secondBackground: s => MaterialDynamicColors.primaryFixed,
|
|
904
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
905
|
+
}), MaterialDynamicColors.secondaryFixed = DynamicColor.fromPalette({
|
|
906
|
+
name: "secondary_fixed",
|
|
907
|
+
palette: s => s.secondaryPalette,
|
|
908
|
+
tone: s => isMonochrome(s) ? 80 : 90,
|
|
909
|
+
isBackground: !0,
|
|
910
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
911
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
912
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryFixed, MaterialDynamicColors.secondaryFixedDim, 10, "lighter", !0)
|
|
913
|
+
}), MaterialDynamicColors.secondaryFixedDim = DynamicColor.fromPalette({
|
|
914
|
+
name: "secondary_fixed_dim",
|
|
915
|
+
palette: s => s.secondaryPalette,
|
|
916
|
+
tone: s => isMonochrome(s) ? 70 : 80,
|
|
917
|
+
isBackground: !0,
|
|
918
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
919
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
920
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryFixed, MaterialDynamicColors.secondaryFixedDim, 10, "lighter", !0)
|
|
921
|
+
}), MaterialDynamicColors.onSecondaryFixed = DynamicColor.fromPalette({
|
|
922
|
+
name: "on_secondary_fixed",
|
|
923
|
+
palette: s => s.secondaryPalette,
|
|
924
|
+
tone: s => 10,
|
|
925
|
+
background: s => MaterialDynamicColors.secondaryFixedDim,
|
|
926
|
+
secondBackground: s => MaterialDynamicColors.secondaryFixed,
|
|
927
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
928
|
+
}), MaterialDynamicColors.onSecondaryFixedVariant = DynamicColor.fromPalette({
|
|
929
|
+
name: "on_secondary_fixed_variant",
|
|
930
|
+
palette: s => s.secondaryPalette,
|
|
931
|
+
tone: s => isMonochrome(s) ? 25 : 30,
|
|
932
|
+
background: s => MaterialDynamicColors.secondaryFixedDim,
|
|
933
|
+
secondBackground: s => MaterialDynamicColors.secondaryFixed,
|
|
934
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
935
|
+
}), MaterialDynamicColors.tertiaryFixed = DynamicColor.fromPalette({
|
|
936
|
+
name: "tertiary_fixed",
|
|
937
|
+
palette: s => s.tertiaryPalette,
|
|
938
|
+
tone: s => isMonochrome(s) ? 40 : 90,
|
|
939
|
+
isBackground: !0,
|
|
940
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
941
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
942
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryFixed, MaterialDynamicColors.tertiaryFixedDim, 10, "lighter", !0)
|
|
943
|
+
}), MaterialDynamicColors.tertiaryFixedDim = DynamicColor.fromPalette({
|
|
944
|
+
name: "tertiary_fixed_dim",
|
|
945
|
+
palette: s => s.tertiaryPalette,
|
|
946
|
+
tone: s => isMonochrome(s) ? 30 : 80,
|
|
947
|
+
isBackground: !0,
|
|
948
|
+
background: s => MaterialDynamicColors.highestSurface(s),
|
|
949
|
+
contrastCurve: new ContrastCurve(1, 1, 3, 7),
|
|
950
|
+
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryFixed, MaterialDynamicColors.tertiaryFixedDim, 10, "lighter", !0)
|
|
951
|
+
}), MaterialDynamicColors.onTertiaryFixed = DynamicColor.fromPalette({
|
|
952
|
+
name: "on_tertiary_fixed",
|
|
953
|
+
palette: s => s.tertiaryPalette,
|
|
954
|
+
tone: s => isMonochrome(s) ? 100 : 10,
|
|
955
|
+
background: s => MaterialDynamicColors.tertiaryFixedDim,
|
|
956
|
+
secondBackground: s => MaterialDynamicColors.tertiaryFixed,
|
|
957
|
+
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
958
|
+
}), MaterialDynamicColors.onTertiaryFixedVariant = DynamicColor.fromPalette({
|
|
959
|
+
name: "on_tertiary_fixed_variant",
|
|
960
|
+
palette: s => s.tertiaryPalette,
|
|
961
|
+
tone: s => isMonochrome(s) ? 90 : 30,
|
|
962
|
+
background: s => MaterialDynamicColors.tertiaryFixedDim,
|
|
963
|
+
secondBackground: s => MaterialDynamicColors.tertiaryFixed,
|
|
964
|
+
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
965
|
+
});
|
|
966
|
+
|
|
424
967
|
class TonalPalette {
|
|
425
968
|
static fromInt(argb) {
|
|
426
969
|
const hct = Hct.fromInt(argb);
|
|
427
|
-
return TonalPalette.
|
|
970
|
+
return TonalPalette.fromHct(hct);
|
|
428
971
|
}
|
|
429
|
-
static
|
|
430
|
-
return new TonalPalette(hue, chroma);
|
|
972
|
+
static fromHct(hct) {
|
|
973
|
+
return new TonalPalette(hct.hue, hct.chroma, hct);
|
|
431
974
|
}
|
|
432
|
-
|
|
433
|
-
|
|
975
|
+
static fromHueAndChroma(hue, chroma) {
|
|
976
|
+
return new TonalPalette(hue, chroma, TonalPalette.createKeyColor(hue, chroma));
|
|
977
|
+
}
|
|
978
|
+
constructor(hue, chroma, keyColor) {
|
|
979
|
+
this.hue = hue, this.chroma = chroma, this.keyColor = keyColor, this.cache = new Map;
|
|
980
|
+
}
|
|
981
|
+
static createKeyColor(hue, chroma) {
|
|
982
|
+
let smallestDeltaHct = Hct.from(hue, chroma, 50), smallestDelta = Math.abs(smallestDeltaHct.chroma - chroma);
|
|
983
|
+
for (let delta = 1; delta < 50; delta += 1) {
|
|
984
|
+
if (Math.round(chroma) === Math.round(smallestDeltaHct.chroma)) return smallestDeltaHct;
|
|
985
|
+
const hctAdd = Hct.from(hue, chroma, 50 + delta), hctAddDelta = Math.abs(hctAdd.chroma - chroma);
|
|
986
|
+
hctAddDelta < smallestDelta && (smallestDelta = hctAddDelta, smallestDeltaHct = hctAdd);
|
|
987
|
+
const hctSubtract = Hct.from(hue, chroma, 50 - delta), hctSubtractDelta = Math.abs(hctSubtract.chroma - chroma);
|
|
988
|
+
hctSubtractDelta < smallestDelta && (smallestDelta = hctSubtractDelta, smallestDeltaHct = hctSubtract);
|
|
989
|
+
}
|
|
990
|
+
return smallestDeltaHct;
|
|
434
991
|
}
|
|
435
992
|
tone(tone) {
|
|
436
993
|
let argb = this.cache.get(tone);
|
|
437
994
|
return void 0 === argb && (argb = Hct.from(this.hue, this.chroma, tone).toInt(),
|
|
438
995
|
this.cache.set(tone, argb)), argb;
|
|
439
996
|
}
|
|
997
|
+
getHct(tone) {
|
|
998
|
+
return Hct.fromInt(this.tone(tone));
|
|
999
|
+
}
|
|
440
1000
|
}
|
|
441
1001
|
|
|
442
1002
|
class CorePalette {
|
|
@@ -1473,7 +2033,7 @@ class Event {
|
|
|
1473
2033
|
const eventsArray = Array.isArray(events) ? events : events.split(' ');
|
|
1474
2034
|
|
|
1475
2035
|
// 本对象事件
|
|
1476
|
-
// ['local
|
|
2036
|
+
// ['local::event'] or ['.event'],不向父组件传递
|
|
1477
2037
|
const selfEvents = eventsArray.map(ev => ev.replace(/local::|^[.]/, ''));
|
|
1478
2038
|
|
|
1479
2039
|
// 非本对象事件,向上传递时,转换为对象,记录来源
|
|
@@ -1648,6 +2208,12 @@ class Page extends Event {
|
|
|
1648
2208
|
this.emit('pageBack', this);
|
|
1649
2209
|
}
|
|
1650
2210
|
|
|
2211
|
+
change(view) {
|
|
2212
|
+
this.emit('local::change', view);
|
|
2213
|
+
// 向上触发跨页面事件,存在安全问题
|
|
2214
|
+
this.emit('pageChange', this);
|
|
2215
|
+
}
|
|
2216
|
+
|
|
1651
2217
|
hide(view) {
|
|
1652
2218
|
this.emit('local::hide', view);
|
|
1653
2219
|
// 向上触发跨页面事件,存在安全问题
|
|
@@ -1663,13 +2229,16 @@ class Page extends Event {
|
|
|
1663
2229
|
|
|
1664
2230
|
/**
|
|
1665
2231
|
* Wia app、router等继承类,通过模块化扩展类功能
|
|
2232
|
+
* 使用 use 装载,注解可能完成类似功能
|
|
2233
|
+
* 不装载则需在代码中按普通泪,单独引用、创建、使用
|
|
2234
|
+
* 装载的模块可能影响其他模块
|
|
1666
2235
|
*/
|
|
1667
2236
|
|
|
1668
2237
|
class Module extends Event {
|
|
1669
2238
|
constructor(params = {}, parents = []) {
|
|
1670
2239
|
super(params, parents);
|
|
1671
|
-
const self = this;
|
|
1672
|
-
self.params = params;
|
|
2240
|
+
const self = this;
|
|
2241
|
+
self.params = params;
|
|
1673
2242
|
}
|
|
1674
2243
|
|
|
1675
2244
|
// eslint-disable-next-line
|
|
@@ -1709,10 +2278,7 @@ class Module extends Event {
|
|
|
1709
2278
|
if (!instance.modules) return;
|
|
1710
2279
|
|
|
1711
2280
|
// 从原型中获得的模块类引用
|
|
1712
|
-
const module =
|
|
1713
|
-
typeof moduleName === 'string'
|
|
1714
|
-
? instance.modules[moduleName]
|
|
1715
|
-
: moduleName;
|
|
2281
|
+
const module = typeof moduleName === 'string' ? instance.modules[moduleName] : moduleName;
|
|
1716
2282
|
if (!module) return;
|
|
1717
2283
|
|
|
1718
2284
|
// 扩展实例的方法和属性,Extend instance methods and props
|
|
@@ -1729,8 +2295,16 @@ class Module extends Event {
|
|
|
1729
2295
|
|
|
1730
2296
|
// 将扩展模块中的on加载到实例的事件侦听中,比如 init 在实例初始化时被调用
|
|
1731
2297
|
if (module.on && instance.on) {
|
|
1732
|
-
Object.keys(module.on).forEach(
|
|
1733
|
-
|
|
2298
|
+
Object.keys(module.on).forEach(eventName => {
|
|
2299
|
+
// 避免模块事件异常溢出影响其他模块
|
|
2300
|
+
const fn = () => {
|
|
2301
|
+
try {
|
|
2302
|
+
module.on[eventName]();
|
|
2303
|
+
} catch (e) {
|
|
2304
|
+
console.log(`${moduleName}.on${eventName} exp:${e.message}`);
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
instance.on(eventName, fn);
|
|
1734
2308
|
});
|
|
1735
2309
|
}
|
|
1736
2310
|
|
|
@@ -1740,10 +2314,8 @@ class Module extends Event {
|
|
|
1740
2314
|
Object.keys(module.vnode).forEach(vnodeId => {
|
|
1741
2315
|
Object.keys(module.vnode[vnodeId]).forEach(hookName => {
|
|
1742
2316
|
const handler = module.vnode[vnodeId][hookName];
|
|
1743
|
-
if (!instance.vnodeHooks[hookName])
|
|
1744
|
-
|
|
1745
|
-
if (!instance.vnodeHooks[hookName][vnodeId])
|
|
1746
|
-
instance.vnodeHooks[hookName][vnodeId] = [];
|
|
2317
|
+
if (!instance.vnodeHooks[hookName]) instance.vnodeHooks[hookName] = {};
|
|
2318
|
+
if (!instance.vnodeHooks[hookName][vnodeId]) instance.vnodeHooks[hookName][vnodeId] = [];
|
|
1747
2319
|
instance.vnodeHooks[hookName][vnodeId].push(handler.bind(instance));
|
|
1748
2320
|
});
|
|
1749
2321
|
});
|
|
@@ -1782,9 +2354,7 @@ class Module extends Event {
|
|
|
1782
2354
|
static installModule(module, ...params) {
|
|
1783
2355
|
const Class = this;
|
|
1784
2356
|
if (!Class.prototype.modules) Class.prototype.modules = {};
|
|
1785
|
-
const name =
|
|
1786
|
-
module.name ||
|
|
1787
|
-
`${Object.keys(Class.prototype.modules).length}_${$.now()}`;
|
|
2357
|
+
const name = module.name || `${Object.keys(Class.prototype.modules).length}_${$.now()}`;
|
|
1788
2358
|
// 原型属性中引用该模块类,类实例
|
|
1789
2359
|
Class.prototype.modules[name] = module;
|
|
1790
2360
|
// 模块如果定义了原型,则将模块原型加载到类原型
|
|
@@ -1807,7 +2377,7 @@ class Module extends Event {
|
|
|
1807
2377
|
}
|
|
1808
2378
|
|
|
1809
2379
|
/**
|
|
1810
|
-
*
|
|
2380
|
+
* 加载扩展模块到类
|
|
1811
2381
|
* @param {*} module
|
|
1812
2382
|
* @param {...any} params
|
|
1813
2383
|
*/
|
|
@@ -3074,7 +3644,7 @@ class App extends Module {
|
|
|
3074
3644
|
const app = this;
|
|
3075
3645
|
if (!app.colorsStyleEl) {
|
|
3076
3646
|
app.colorsStyleEl = document.createElement('style');
|
|
3077
|
-
document.head.
|
|
3647
|
+
document.head.prepend(app.colorsStyleEl);
|
|
3078
3648
|
}
|
|
3079
3649
|
|
|
3080
3650
|
app.colorsStyleEl.textContent = colorThemeCSSStyles(app.colors);
|
|
@@ -3167,8 +3737,8 @@ class App extends Module {
|
|
|
3167
3737
|
const app = this;
|
|
3168
3738
|
const html = document.querySelector('html');
|
|
3169
3739
|
if (app.mq.dark && app.mq.light) {
|
|
3170
|
-
app.mq.dark.
|
|
3171
|
-
app.mq.light.
|
|
3740
|
+
app.mq.dark.addEventListener('change', app.colorSchemeListener);
|
|
3741
|
+
app.mq.light.addEventListener('change', app.colorSchemeListener);
|
|
3172
3742
|
}
|
|
3173
3743
|
if (app.mq.dark && app.mq.dark.matches) {
|
|
3174
3744
|
html.classList.add('dark');
|
|
@@ -3185,8 +3755,8 @@ class App extends Module {
|
|
|
3185
3755
|
if (!window.matchMedia) return;
|
|
3186
3756
|
|
|
3187
3757
|
const app = this;
|
|
3188
|
-
if (app.mq.dark) app.mq.dark.
|
|
3189
|
-
if (app.mq.light) app.mq.light.
|
|
3758
|
+
if (app.mq.dark) app.mq.dark.removeEventListener('change', app.colorSchemeListener);
|
|
3759
|
+
if (app.mq.light) app.mq.light.removeEventListener('change', app.colorSchemeListener);
|
|
3190
3760
|
}
|
|
3191
3761
|
|
|
3192
3762
|
setDarkMode(mode) {
|