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