@m3e/web 2.5.7 → 2.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/all.js +3908 -987
- package/dist/all.js.map +1 -1
- package/dist/all.min.js +119 -56
- package/dist/all.min.js.map +1 -1
- package/dist/button-group.js +31 -12
- package/dist/button-group.js.map +1 -1
- package/dist/button-group.min.js +1 -1
- package/dist/button-group.min.js.map +1 -1
- package/dist/button.js +62 -30
- package/dist/button.js.map +1 -1
- package/dist/button.min.js +1 -1
- package/dist/button.min.js.map +1 -1
- package/dist/card.js +2 -2
- package/dist/card.js.map +1 -1
- package/dist/card.min.js +1 -1
- package/dist/card.min.js.map +1 -1
- package/dist/content-pane.js +1 -1
- package/dist/content-pane.js.map +1 -1
- package/dist/content-pane.min.js +1 -1
- package/dist/content-pane.min.js.map +1 -1
- package/dist/core.js +57 -5
- package/dist/core.js.map +1 -1
- package/dist/core.min.js +1 -1
- package/dist/core.min.js.map +1 -1
- package/dist/css-custom-data.json +370 -355
- package/dist/custom-elements.json +5331 -5173
- package/dist/drawer-container.js +13 -7
- package/dist/drawer-container.js.map +1 -1
- package/dist/drawer-container.min.js +1 -1
- package/dist/drawer-container.min.js.map +1 -1
- package/dist/html-custom-data.json +276 -276
- package/dist/icon-button.js +62 -30
- package/dist/icon-button.js.map +1 -1
- package/dist/icon-button.min.js +1 -1
- package/dist/icon-button.min.js.map +1 -1
- package/dist/loading-indicator.js +8 -8
- package/dist/loading-indicator.js.map +1 -1
- package/dist/loading-indicator.min.js +1 -1
- package/dist/loading-indicator.min.js.map +1 -1
- package/dist/slide-group.js +1 -1
- package/dist/slide-group.js.map +1 -1
- package/dist/slide-group.min.js.map +1 -1
- package/dist/snackbar.js +2 -2
- package/dist/snackbar.js.map +1 -1
- package/dist/snackbar.min.js +1 -1
- package/dist/snackbar.min.js.map +1 -1
- package/dist/src/button/ButtonElement.d.ts.map +1 -1
- package/dist/src/button/styles/ButtonSizeStyle.d.ts.map +1 -1
- package/dist/src/button/styles/ButtonStyle.d.ts.map +1 -1
- package/dist/src/button-group/ButtonGroupElement.d.ts.map +1 -1
- package/dist/src/card/styles/CardStyle.d.ts.map +1 -1
- package/dist/src/content-pane/ContentPaneElement.d.ts.map +1 -1
- package/dist/src/core/shared/controllers/ScrollController.d.ts.map +1 -1
- package/dist/src/core/shared/tokens/DesignToken.d.ts +18 -0
- package/dist/src/core/shared/tokens/DesignToken.d.ts.map +1 -1
- package/dist/src/core/shared/tokens/MeasurementToken.d.ts +34 -0
- package/dist/src/core/shared/tokens/MeasurementToken.d.ts.map +1 -0
- package/dist/src/drawer-container/DrawerContainerElement.d.ts.map +1 -1
- package/dist/src/drawer-container/DrawerToggleElement.d.ts.map +1 -1
- package/dist/src/icon-button/IconButtonElement.d.ts.map +1 -1
- package/dist/src/icon-button/styles/IconButtonSizeStyle.d.ts.map +1 -1
- package/dist/src/icon-button/styles/IconButtonStyle.d.ts.map +1 -1
- package/dist/src/loading-indicator/LoadingIndicatorElement.d.ts +1 -1
- package/dist/src/loading-indicator/LoadingIndicatorElement.d.ts.map +1 -1
- package/dist/src/snackbar/SnackbarElement.d.ts.map +1 -1
- package/dist/src/theme/ThemeElement.d.ts.map +1 -1
- package/dist/src/toc/TocElement.d.ts +4 -0
- package/dist/src/toc/TocElement.d.ts.map +1 -1
- package/dist/theme.js +3580 -834
- package/dist/theme.js.map +1 -1
- package/dist/theme.min.js +94 -31
- package/dist/theme.min.js.map +1 -1
- package/dist/toc.js +42 -8
- package/dist/toc.js.map +1 -1
- package/dist/toc.min.js +1 -1
- package/dist/toc.min.js.map +1 -1
- package/package.json +2 -2
package/dist/theme.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* See LICENSE file in the project root for full license text.
|
|
5
5
|
*/
|
|
6
6
|
import { __decorate, __classPrivateFieldGet, __classPrivateFieldSet } from 'tslib';
|
|
7
|
-
import { css, LitElement, html } from 'lit';
|
|
7
|
+
import { unsafeCSS, css, LitElement, html } from 'lit';
|
|
8
8
|
import { property } from 'lit/decorators.js';
|
|
9
|
-
import {
|
|
9
|
+
import { DesignToken, registerStyleSheet, customElement } from '@m3e/web/core';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @license
|
|
@@ -104,6 +104,24 @@ function sanitizeDegreesDouble(degrees) {
|
|
|
104
104
|
}
|
|
105
105
|
return degrees;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Sign of direction change needed to travel from one angle to
|
|
109
|
+
* another.
|
|
110
|
+
*
|
|
111
|
+
* For angles that are 180 degrees apart from each other, both
|
|
112
|
+
* directions have the same travel distance, so either direction is
|
|
113
|
+
* shortest. The value 1.0 is returned in this case.
|
|
114
|
+
*
|
|
115
|
+
* @param from The angle travel starts from, in degrees.
|
|
116
|
+
* @param to The angle travel ends at, in degrees.
|
|
117
|
+
* @return -1 if decreasing from leads to the shortest travel
|
|
118
|
+
* distance, 1 if increasing from leads to the shortest travel
|
|
119
|
+
* distance.
|
|
120
|
+
*/
|
|
121
|
+
function rotationDirection(from, to) {
|
|
122
|
+
const increasingDifference = sanitizeDegreesDouble(to - from);
|
|
123
|
+
return increasingDifference <= 180.0 ? 1.0 : -1;
|
|
124
|
+
}
|
|
107
125
|
/**
|
|
108
126
|
* Distance of two points on a circle, represented using degrees.
|
|
109
127
|
*/
|
|
@@ -582,7 +600,7 @@ class Cam16 {
|
|
|
582
600
|
const p2 = (40.0 * rA + 20.0 * gA + bA) / 20.0;
|
|
583
601
|
const atan2 = Math.atan2(b, a);
|
|
584
602
|
const atanDegrees = atan2 * 180.0 / Math.PI;
|
|
585
|
-
const hue = atanDegrees
|
|
603
|
+
const hue = sanitizeDegreesDouble(atanDegrees);
|
|
586
604
|
const hueRadians = hue * Math.PI / 180.0;
|
|
587
605
|
const ac = p2 * viewingConditions.nbb;
|
|
588
606
|
const j = 100.0 * Math.pow(ac / viewingConditions.aw, viewingConditions.c * viewingConditions.z);
|
|
@@ -1249,6 +1267,22 @@ class Hct {
|
|
|
1249
1267
|
set tone(newTone) {
|
|
1250
1268
|
this.setInternalState(HctSolver.solveToInt(this.internalHue, this.internalChroma, newTone));
|
|
1251
1269
|
}
|
|
1270
|
+
/** Sets a property of the Hct object. */
|
|
1271
|
+
setValue(propertyName, value) {
|
|
1272
|
+
this[propertyName] = value;
|
|
1273
|
+
}
|
|
1274
|
+
toString() {
|
|
1275
|
+
return `HCT(${this.hue.toFixed(0)}, ${this.chroma.toFixed(0)}, ${this.tone.toFixed(0)})`;
|
|
1276
|
+
}
|
|
1277
|
+
static isBlue(hue) {
|
|
1278
|
+
return hue >= 250 && hue < 270;
|
|
1279
|
+
}
|
|
1280
|
+
static isYellow(hue) {
|
|
1281
|
+
return hue >= 105 && hue < 125;
|
|
1282
|
+
}
|
|
1283
|
+
static isCyan(hue) {
|
|
1284
|
+
return hue >= 170 && hue < 207;
|
|
1285
|
+
}
|
|
1252
1286
|
constructor(argb) {
|
|
1253
1287
|
this.argb = argb;
|
|
1254
1288
|
const cam = Cam16.fromInt(argb);
|
|
@@ -1292,6 +1326,93 @@ class Hct {
|
|
|
1292
1326
|
}
|
|
1293
1327
|
}
|
|
1294
1328
|
|
|
1329
|
+
/**
|
|
1330
|
+
* @license
|
|
1331
|
+
* Copyright 2021 Google LLC
|
|
1332
|
+
*
|
|
1333
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1334
|
+
* you may not use this file except in compliance with the License.
|
|
1335
|
+
* You may obtain a copy of the License at
|
|
1336
|
+
*
|
|
1337
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1338
|
+
*
|
|
1339
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1340
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1341
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1342
|
+
* See the License for the specific language governing permissions and
|
|
1343
|
+
* limitations under the License.
|
|
1344
|
+
*/
|
|
1345
|
+
// This file is automatically generated. Do not modify it.
|
|
1346
|
+
// material_color_utilities is designed to have a consistent API across
|
|
1347
|
+
// platforms and modular components that can be moved around easily. Using a
|
|
1348
|
+
// class as a namespace facilitates this.
|
|
1349
|
+
//
|
|
1350
|
+
// tslint:disable:class-as-namespace
|
|
1351
|
+
/**
|
|
1352
|
+
* Functions for blending in HCT and CAM16.
|
|
1353
|
+
*/
|
|
1354
|
+
class Blend {
|
|
1355
|
+
/**
|
|
1356
|
+
* Blend the design color's HCT hue towards the key color's HCT
|
|
1357
|
+
* hue, in a way that leaves the original color recognizable and
|
|
1358
|
+
* recognizably shifted towards the key color.
|
|
1359
|
+
*
|
|
1360
|
+
* @param designColor ARGB representation of an arbitrary color.
|
|
1361
|
+
* @param sourceColor ARGB representation of the main theme color.
|
|
1362
|
+
* @return The design color with a hue shifted towards the
|
|
1363
|
+
* system's color, a slightly warmer/cooler variant of the design
|
|
1364
|
+
* color's hue.
|
|
1365
|
+
*/
|
|
1366
|
+
static harmonize(designColor, sourceColor) {
|
|
1367
|
+
const fromHct = Hct.fromInt(designColor);
|
|
1368
|
+
const toHct = Hct.fromInt(sourceColor);
|
|
1369
|
+
const differenceDegrees$1 = differenceDegrees(fromHct.hue, toHct.hue);
|
|
1370
|
+
const rotationDegrees = Math.min(differenceDegrees$1 * 0.5, 15.0);
|
|
1371
|
+
const outputHue = sanitizeDegreesDouble(fromHct.hue + rotationDegrees * rotationDirection(fromHct.hue, toHct.hue));
|
|
1372
|
+
return Hct.from(outputHue, fromHct.chroma, fromHct.tone).toInt();
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Blends hue from one color into another. The chroma and tone of
|
|
1376
|
+
* the original color are maintained.
|
|
1377
|
+
*
|
|
1378
|
+
* @param from ARGB representation of color
|
|
1379
|
+
* @param to ARGB representation of color
|
|
1380
|
+
* @param amount how much blending to perform; 0.0 >= and <= 1.0
|
|
1381
|
+
* @return from, with a hue blended towards to. Chroma and tone
|
|
1382
|
+
* are constant.
|
|
1383
|
+
*/
|
|
1384
|
+
static hctHue(from, to, amount) {
|
|
1385
|
+
const ucs = Blend.cam16Ucs(from, to, amount);
|
|
1386
|
+
const ucsCam = Cam16.fromInt(ucs);
|
|
1387
|
+
const fromCam = Cam16.fromInt(from);
|
|
1388
|
+
const blended = Hct.from(ucsCam.hue, fromCam.chroma, lstarFromArgb(from));
|
|
1389
|
+
return blended.toInt();
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Blend in CAM16-UCS space.
|
|
1393
|
+
*
|
|
1394
|
+
* @param from ARGB representation of color
|
|
1395
|
+
* @param to ARGB representation of color
|
|
1396
|
+
* @param amount how much blending to perform; 0.0 >= and <= 1.0
|
|
1397
|
+
* @return from, blended towards to. Hue, chroma, and tone will
|
|
1398
|
+
* change.
|
|
1399
|
+
*/
|
|
1400
|
+
static cam16Ucs(from, to, amount) {
|
|
1401
|
+
const fromCam = Cam16.fromInt(from);
|
|
1402
|
+
const toCam = Cam16.fromInt(to);
|
|
1403
|
+
const fromJ = fromCam.jstar;
|
|
1404
|
+
const fromA = fromCam.astar;
|
|
1405
|
+
const fromB = fromCam.bstar;
|
|
1406
|
+
const toJ = toCam.jstar;
|
|
1407
|
+
const toA = toCam.astar;
|
|
1408
|
+
const toB = toCam.bstar;
|
|
1409
|
+
const jstar = fromJ + (toJ - fromJ) * amount;
|
|
1410
|
+
const astar = fromA + (toA - fromA) * amount;
|
|
1411
|
+
const bstar = fromB + (toB - fromB) * amount;
|
|
1412
|
+
return Cam16.fromUcs(jstar, astar, bstar).toInt();
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1295
1416
|
/**
|
|
1296
1417
|
* @license
|
|
1297
1418
|
* Copyright 2022 Google LLC
|
|
@@ -1514,6 +1635,51 @@ class DislikeAnalyzer {
|
|
|
1514
1635
|
* See the License for the specific language governing permissions and
|
|
1515
1636
|
* limitations under the License.
|
|
1516
1637
|
*/
|
|
1638
|
+
function validateExtendedColor(originalColor, specVersion, extendedColor) {
|
|
1639
|
+
if (originalColor.name !== extendedColor.name) {
|
|
1640
|
+
throw new Error(`Attempting to extend color ${originalColor.name} with color ${extendedColor.name} of different name for spec version ${specVersion}.`);
|
|
1641
|
+
}
|
|
1642
|
+
if (originalColor.isBackground !== extendedColor.isBackground) {
|
|
1643
|
+
throw new Error(`Attempting to extend color ${originalColor.name} as a ${originalColor.isBackground ? 'background' : 'foreground'} with color ${extendedColor.name} as a ${extendedColor.isBackground ? 'background' : 'foreground'} for spec version ${specVersion}.`);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Returns a new DynamicColor that is the same as the original color, but with
|
|
1648
|
+
* the extended dynamic color's constraints for the given spec version.
|
|
1649
|
+
*
|
|
1650
|
+
* @param originlColor The original color.
|
|
1651
|
+
* @param specVersion The spec version to extend.
|
|
1652
|
+
* @param extendedColor The color with the values to extend.
|
|
1653
|
+
*/
|
|
1654
|
+
function extendSpecVersion(originlColor, specVersion, extendedColor) {
|
|
1655
|
+
validateExtendedColor(originlColor, specVersion, extendedColor);
|
|
1656
|
+
return DynamicColor.fromPalette({
|
|
1657
|
+
name: originlColor.name,
|
|
1658
|
+
palette: s => s.specVersion === specVersion ? extendedColor.palette(s) : originlColor.palette(s),
|
|
1659
|
+
tone: s => s.specVersion === specVersion ? extendedColor.tone(s) : originlColor.tone(s),
|
|
1660
|
+
isBackground: originlColor.isBackground,
|
|
1661
|
+
chromaMultiplier: s => {
|
|
1662
|
+
const chromaMultiplier = s.specVersion === specVersion ? extendedColor.chromaMultiplier : originlColor.chromaMultiplier;
|
|
1663
|
+
return chromaMultiplier !== undefined ? chromaMultiplier(s) : 1;
|
|
1664
|
+
},
|
|
1665
|
+
background: s => {
|
|
1666
|
+
const background = s.specVersion === specVersion ? extendedColor.background : originlColor.background;
|
|
1667
|
+
return background !== undefined ? background(s) : undefined;
|
|
1668
|
+
},
|
|
1669
|
+
secondBackground: s => {
|
|
1670
|
+
const secondBackground = s.specVersion === specVersion ? extendedColor.secondBackground : originlColor.secondBackground;
|
|
1671
|
+
return secondBackground !== undefined ? secondBackground(s) : undefined;
|
|
1672
|
+
},
|
|
1673
|
+
contrastCurve: s => {
|
|
1674
|
+
const contrastCurve = s.specVersion === specVersion ? extendedColor.contrastCurve : originlColor.contrastCurve;
|
|
1675
|
+
return contrastCurve !== undefined ? contrastCurve(s) : undefined;
|
|
1676
|
+
},
|
|
1677
|
+
toneDeltaPair: s => {
|
|
1678
|
+
const toneDeltaPair = s.specVersion === specVersion ? extendedColor.toneDeltaPair : originlColor.toneDeltaPair;
|
|
1679
|
+
return toneDeltaPair !== undefined ? toneDeltaPair(s) : undefined;
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1517
1683
|
/**
|
|
1518
1684
|
* A color that adjusts itself based on UI state provided by DynamicScheme.
|
|
1519
1685
|
*
|
|
@@ -1530,10 +1696,16 @@ class DynamicColor {
|
|
|
1530
1696
|
* Create a DynamicColor defined by a TonalPalette and HCT tone.
|
|
1531
1697
|
*
|
|
1532
1698
|
* @param args Functions with DynamicScheme as input. Must provide a palette
|
|
1533
|
-
*
|
|
1699
|
+
* and tone. May provide a background DynamicColor and ToneDeltaPair.
|
|
1534
1700
|
*/
|
|
1535
1701
|
static fromPalette(args) {
|
|
1536
|
-
return new DynamicColor(args.name ?? '', args.palette, args.tone, args.isBackground ?? false, args.background, args.secondBackground, args.contrastCurve, args.toneDeltaPair);
|
|
1702
|
+
return new DynamicColor(args.name ?? '', args.palette, args.tone ?? DynamicColor.getInitialToneFromBackground(args.background), args.isBackground ?? false, args.chromaMultiplier, args.background, args.secondBackground, args.contrastCurve, args.toneDeltaPair);
|
|
1703
|
+
}
|
|
1704
|
+
static getInitialToneFromBackground(background) {
|
|
1705
|
+
if (background === undefined) {
|
|
1706
|
+
return s => 50;
|
|
1707
|
+
}
|
|
1708
|
+
return s => background(s) ? background(s).getTone(s) : 50;
|
|
1537
1709
|
}
|
|
1538
1710
|
/**
|
|
1539
1711
|
* The base constructor for DynamicColor.
|
|
@@ -1549,29 +1721,31 @@ class DynamicColor {
|
|
|
1549
1721
|
* always, in every case.
|
|
1550
1722
|
*
|
|
1551
1723
|
* @param name The name of the dynamic color. Defaults to empty.
|
|
1552
|
-
* @param palette Function that provides a TonalPalette given
|
|
1553
|
-
*
|
|
1554
|
-
*
|
|
1555
|
-
*
|
|
1724
|
+
* @param palette Function that provides a TonalPalette given DynamicScheme. A
|
|
1725
|
+
* TonalPalette is defined by a hue and chroma, so this replaces the need
|
|
1726
|
+
* to specify hue/chroma. By providing a tonal palette, when contrast
|
|
1727
|
+
* adjustments are made, intended chroma can be preserved.
|
|
1556
1728
|
* @param tone Function that provides a tone, given a DynamicScheme.
|
|
1557
|
-
* @param isBackground Whether this dynamic color is a background, with
|
|
1558
|
-
*
|
|
1729
|
+
* @param isBackground Whether this dynamic color is a background, with some
|
|
1730
|
+
* other color as the foreground. Defaults to false.
|
|
1731
|
+
* @param chromaMultiplier A factor that multiplies the chroma for this color.
|
|
1559
1732
|
* @param background The background of the dynamic color (as a function of a
|
|
1560
1733
|
* `DynamicScheme`), if it exists.
|
|
1561
1734
|
* @param secondBackground A second background of the dynamic color (as a
|
|
1562
|
-
* function of a `DynamicScheme`), if it
|
|
1563
|
-
* exists.
|
|
1735
|
+
* function of a `DynamicScheme`), if it exists.
|
|
1564
1736
|
* @param contrastCurve A `ContrastCurve` object specifying how its contrast
|
|
1565
|
-
*
|
|
1737
|
+
* against its background should behave in various contrast levels
|
|
1738
|
+
* options.
|
|
1566
1739
|
* @param toneDeltaPair A `ToneDeltaPair` object specifying a tone delta
|
|
1567
|
-
*
|
|
1568
|
-
*
|
|
1740
|
+
* constraint between two colors. One of them must be the color being
|
|
1741
|
+
* constructed.
|
|
1569
1742
|
*/
|
|
1570
|
-
constructor(name, palette, tone, isBackground, background, secondBackground, contrastCurve, toneDeltaPair) {
|
|
1743
|
+
constructor(name, palette, tone, isBackground, chromaMultiplier, background, secondBackground, contrastCurve, toneDeltaPair) {
|
|
1571
1744
|
this.name = name;
|
|
1572
1745
|
this.palette = palette;
|
|
1573
1746
|
this.tone = tone;
|
|
1574
1747
|
this.isBackground = isBackground;
|
|
1748
|
+
this.chromaMultiplier = chromaMultiplier;
|
|
1575
1749
|
this.background = background;
|
|
1576
1750
|
this.secondBackground = secondBackground;
|
|
1577
1751
|
this.contrastCurve = contrastCurve;
|
|
@@ -1588,30 +1762,52 @@ class DynamicColor {
|
|
|
1588
1762
|
}
|
|
1589
1763
|
}
|
|
1590
1764
|
/**
|
|
1591
|
-
*
|
|
1765
|
+
* Returns a deep copy of this DynamicColor.
|
|
1766
|
+
*/
|
|
1767
|
+
clone() {
|
|
1768
|
+
return DynamicColor.fromPalette({
|
|
1769
|
+
name: this.name,
|
|
1770
|
+
palette: this.palette,
|
|
1771
|
+
tone: this.tone,
|
|
1772
|
+
isBackground: this.isBackground,
|
|
1773
|
+
chromaMultiplier: this.chromaMultiplier,
|
|
1774
|
+
background: this.background,
|
|
1775
|
+
secondBackground: this.secondBackground,
|
|
1776
|
+
contrastCurve: this.contrastCurve,
|
|
1777
|
+
toneDeltaPair: this.toneDeltaPair
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Clears the cache of HCT values for this color. For testing or debugging
|
|
1782
|
+
* purposes.
|
|
1783
|
+
*/
|
|
1784
|
+
clearCache() {
|
|
1785
|
+
this.hctCache.clear();
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Returns a ARGB integer (i.e. a hex code).
|
|
1592
1789
|
*
|
|
1593
1790
|
* @param scheme Defines the conditions of the user interface, for example,
|
|
1594
|
-
*
|
|
1595
|
-
*
|
|
1791
|
+
* whether or not it is dark mode or light mode, and what the desired
|
|
1792
|
+
* contrast level is.
|
|
1596
1793
|
*/
|
|
1597
1794
|
getArgb(scheme) {
|
|
1598
1795
|
return this.getHct(scheme).toInt();
|
|
1599
1796
|
}
|
|
1600
1797
|
/**
|
|
1601
|
-
*
|
|
1798
|
+
* Returns a color, expressed in the HCT color space, that this
|
|
1602
1799
|
* DynamicColor is under the conditions in scheme.
|
|
1603
1800
|
*
|
|
1604
1801
|
* @param scheme Defines the conditions of the user interface, for example,
|
|
1605
|
-
*
|
|
1606
|
-
*
|
|
1802
|
+
* whether or not it is dark mode or light mode, and what the desired
|
|
1803
|
+
* contrast level is.
|
|
1607
1804
|
*/
|
|
1608
1805
|
getHct(scheme) {
|
|
1609
1806
|
const cachedAnswer = this.hctCache.get(scheme);
|
|
1610
1807
|
if (cachedAnswer != null) {
|
|
1611
1808
|
return cachedAnswer;
|
|
1612
1809
|
}
|
|
1613
|
-
const
|
|
1614
|
-
const answer = this.palette(scheme).getHct(tone);
|
|
1810
|
+
const answer = getSpec$1(scheme.specVersion).getHct(scheme, this);
|
|
1615
1811
|
if (this.hctCache.size > 4) {
|
|
1616
1812
|
this.hctCache.clear();
|
|
1617
1813
|
}
|
|
@@ -1619,48 +1815,135 @@ class DynamicColor {
|
|
|
1619
1815
|
return answer;
|
|
1620
1816
|
}
|
|
1621
1817
|
/**
|
|
1622
|
-
*
|
|
1818
|
+
* Returns a tone, T in the HCT color space, that this DynamicColor is under
|
|
1623
1819
|
* the conditions in scheme.
|
|
1624
1820
|
*
|
|
1625
1821
|
* @param scheme Defines the conditions of the user interface, for example,
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1822
|
+
* whether or not it is dark mode or light mode, and what the desired
|
|
1823
|
+
* contrast level is.
|
|
1628
1824
|
*/
|
|
1629
1825
|
getTone(scheme) {
|
|
1826
|
+
return getSpec$1(scheme.specVersion).getTone(scheme, this);
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* Given a background tone, finds a foreground tone, while ensuring they reach
|
|
1830
|
+
* a contrast ratio that is as close to [ratio] as possible.
|
|
1831
|
+
*
|
|
1832
|
+
* @param bgTone Tone in HCT. Range is 0 to 100, undefined behavior when it
|
|
1833
|
+
* falls outside that range.
|
|
1834
|
+
* @param ratio The contrast ratio desired between bgTone and the return
|
|
1835
|
+
* value.
|
|
1836
|
+
*/
|
|
1837
|
+
static foregroundTone(bgTone, ratio) {
|
|
1838
|
+
const lighterTone = Contrast.lighterUnsafe(bgTone, ratio);
|
|
1839
|
+
const darkerTone = Contrast.darkerUnsafe(bgTone, ratio);
|
|
1840
|
+
const lighterRatio = Contrast.ratioOfTones(lighterTone, bgTone);
|
|
1841
|
+
const darkerRatio = Contrast.ratioOfTones(darkerTone, bgTone);
|
|
1842
|
+
const preferLighter = DynamicColor.tonePrefersLightForeground(bgTone);
|
|
1843
|
+
if (preferLighter) {
|
|
1844
|
+
// This handles an edge case where the initial contrast ratio is high
|
|
1845
|
+
// (ex. 13.0), and the ratio passed to the function is that high
|
|
1846
|
+
// ratio, and both the lighter and darker ratio fails to pass that
|
|
1847
|
+
// ratio.
|
|
1848
|
+
//
|
|
1849
|
+
// This was observed with Tonal Spot's On Primary Container turning
|
|
1850
|
+
// black momentarily between high and max contrast in light mode. PC's
|
|
1851
|
+
// standard tone was T90, OPC's was T10, it was light mode, and the
|
|
1852
|
+
// contrast value was 0.6568521221032331.
|
|
1853
|
+
const negligibleDifference = Math.abs(lighterRatio - darkerRatio) < 0.1 && lighterRatio < ratio && darkerRatio < ratio;
|
|
1854
|
+
return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
|
|
1855
|
+
} else {
|
|
1856
|
+
return darkerRatio >= ratio || darkerRatio >= lighterRatio ? darkerTone : lighterTone;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Returns whether [tone] prefers a light foreground.
|
|
1861
|
+
*
|
|
1862
|
+
* People prefer white foregrounds on ~T60-70. Observed over time, and also
|
|
1863
|
+
* by Andrew Somers during research for APCA.
|
|
1864
|
+
*
|
|
1865
|
+
* T60 used as to create the smallest discontinuity possible when skipping
|
|
1866
|
+
* down to T49 in order to ensure light foregrounds.
|
|
1867
|
+
* Since `tertiaryContainer` in dark monochrome scheme requires a tone of
|
|
1868
|
+
* 60, it should not be adjusted. Therefore, 60 is excluded here.
|
|
1869
|
+
*/
|
|
1870
|
+
static tonePrefersLightForeground(tone) {
|
|
1871
|
+
return Math.round(tone) < 60.0;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Returns whether [tone] can reach a contrast ratio of 4.5 with a lighter
|
|
1875
|
+
* color.
|
|
1876
|
+
*/
|
|
1877
|
+
static toneAllowsLightForeground(tone) {
|
|
1878
|
+
return Math.round(tone) <= 49.0;
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Adjusts a tone such that white has 4.5 contrast, if the tone is
|
|
1882
|
+
* reasonably close to supporting it.
|
|
1883
|
+
*/
|
|
1884
|
+
static enableLightForeground(tone) {
|
|
1885
|
+
if (DynamicColor.tonePrefersLightForeground(tone) && !DynamicColor.toneAllowsLightForeground(tone)) {
|
|
1886
|
+
return 49.0;
|
|
1887
|
+
}
|
|
1888
|
+
return tone;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* A delegate for the color calculation of a DynamicScheme in the 2021 spec.
|
|
1893
|
+
*/
|
|
1894
|
+
class ColorCalculationDelegateImpl2021 {
|
|
1895
|
+
getHct(scheme, color) {
|
|
1896
|
+
const tone = color.getTone(scheme);
|
|
1897
|
+
const palette = color.palette(scheme);
|
|
1898
|
+
return palette.getHct(tone);
|
|
1899
|
+
}
|
|
1900
|
+
getTone(scheme, color) {
|
|
1630
1901
|
const decreasingContrast = scheme.contrastLevel < 0;
|
|
1902
|
+
const toneDeltaPair = color.toneDeltaPair ? color.toneDeltaPair(scheme) : undefined;
|
|
1631
1903
|
// Case 1: dual foreground, pair of colors with delta constraint.
|
|
1632
|
-
if (
|
|
1633
|
-
const toneDeltaPair = this.toneDeltaPair(scheme);
|
|
1904
|
+
if (toneDeltaPair) {
|
|
1634
1905
|
const roleA = toneDeltaPair.roleA;
|
|
1635
1906
|
const roleB = toneDeltaPair.roleB;
|
|
1636
1907
|
const delta = toneDeltaPair.delta;
|
|
1637
1908
|
const polarity = toneDeltaPair.polarity;
|
|
1638
1909
|
const stayTogether = toneDeltaPair.stayTogether;
|
|
1639
|
-
const bg = this.background(scheme);
|
|
1640
|
-
const bgTone = bg.getTone(scheme);
|
|
1641
1910
|
const aIsNearer = polarity === 'nearer' || polarity === 'lighter' && !scheme.isDark || polarity === 'darker' && scheme.isDark;
|
|
1642
1911
|
const nearer = aIsNearer ? roleA : roleB;
|
|
1643
1912
|
const farther = aIsNearer ? roleB : roleA;
|
|
1644
|
-
const amNearer =
|
|
1913
|
+
const amNearer = color.name === nearer.name;
|
|
1645
1914
|
const expansionDir = scheme.isDark ? 1 : -1;
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
//
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1915
|
+
let nTone = nearer.tone(scheme);
|
|
1916
|
+
let fTone = farther.tone(scheme);
|
|
1917
|
+
// 1st round: solve to min for each, if background and contrast curve
|
|
1918
|
+
// are defined.
|
|
1919
|
+
if (color.background && nearer.contrastCurve && farther.contrastCurve) {
|
|
1920
|
+
const bg = color.background(scheme);
|
|
1921
|
+
const nContrastCurve = nearer.contrastCurve(scheme);
|
|
1922
|
+
const fContrastCurve = farther.contrastCurve(scheme);
|
|
1923
|
+
if (bg && nContrastCurve && fContrastCurve) {
|
|
1924
|
+
const bgTone = bg.getTone(scheme);
|
|
1925
|
+
const nContrast = nContrastCurve.get(scheme.contrastLevel);
|
|
1926
|
+
const fContrast = fContrastCurve.get(scheme.contrastLevel);
|
|
1927
|
+
// If a color is good enough, it is not adjusted.
|
|
1928
|
+
// Initial and adjusted tones for `nearer`
|
|
1929
|
+
if (Contrast.ratioOfTones(bgTone, nTone) < nContrast) {
|
|
1930
|
+
nTone = DynamicColor.foregroundTone(bgTone, nContrast);
|
|
1931
|
+
}
|
|
1932
|
+
// Initial and adjusted tones for `farther`
|
|
1933
|
+
if (Contrast.ratioOfTones(bgTone, fTone) < fContrast) {
|
|
1934
|
+
fTone = DynamicColor.foregroundTone(bgTone, fContrast);
|
|
1935
|
+
}
|
|
1936
|
+
if (decreasingContrast) {
|
|
1937
|
+
// If decreasing contrast, adjust color to the "bare minimum"
|
|
1938
|
+
// that satisfies contrast.
|
|
1939
|
+
nTone = DynamicColor.foregroundTone(bgTone, nContrast);
|
|
1940
|
+
fTone = DynamicColor.foregroundTone(bgTone, fContrast);
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1661
1943
|
}
|
|
1662
|
-
if ((fTone - nTone) * expansionDir
|
|
1663
|
-
// 2nd round: expand farther to match delta
|
|
1944
|
+
if ((fTone - nTone) * expansionDir < delta) {
|
|
1945
|
+
// 2nd round: expand farther to match delta, if contrast is not
|
|
1946
|
+
// satisfied.
|
|
1664
1947
|
fTone = clampDouble(0, 100, nTone + delta * expansionDir);
|
|
1665
1948
|
if ((fTone - nTone) * expansionDir >= delta) ; else {
|
|
1666
1949
|
// 3rd round: contract nearer to match delta.
|
|
@@ -1702,12 +1985,12 @@ class DynamicColor {
|
|
|
1702
1985
|
return amNearer ? nTone : fTone;
|
|
1703
1986
|
} else {
|
|
1704
1987
|
// Case 2: No contrast pair; just solve for itself.
|
|
1705
|
-
let answer =
|
|
1706
|
-
if (
|
|
1988
|
+
let answer = color.tone(scheme);
|
|
1989
|
+
if (color.background == undefined || color.background(scheme) === undefined || color.contrastCurve == undefined || color.contrastCurve(scheme) === undefined) {
|
|
1707
1990
|
return answer; // No adjustment for colors with no background.
|
|
1708
1991
|
}
|
|
1709
|
-
const bgTone =
|
|
1710
|
-
const desiredRatio =
|
|
1992
|
+
const bgTone = color.background(scheme).getTone(scheme);
|
|
1993
|
+
const desiredRatio = color.contrastCurve(scheme).get(scheme.contrastLevel);
|
|
1711
1994
|
if (Contrast.ratioOfTones(bgTone, answer) >= desiredRatio) ; else {
|
|
1712
1995
|
// Rough improvement.
|
|
1713
1996
|
answer = DynamicColor.foregroundTone(bgTone, desiredRatio);
|
|
@@ -1715,7 +1998,7 @@ class DynamicColor {
|
|
|
1715
1998
|
if (decreasingContrast) {
|
|
1716
1999
|
answer = DynamicColor.foregroundTone(bgTone, desiredRatio);
|
|
1717
2000
|
}
|
|
1718
|
-
if (
|
|
2001
|
+
if (color.isBackground && 50 <= answer && answer < 60) {
|
|
1719
2002
|
// Must adjust
|
|
1720
2003
|
if (Contrast.ratioOfTones(49, bgTone) >= desiredRatio) {
|
|
1721
2004
|
answer = 49;
|
|
@@ -1723,99 +2006,159 @@ class DynamicColor {
|
|
|
1723
2006
|
answer = 60;
|
|
1724
2007
|
}
|
|
1725
2008
|
}
|
|
1726
|
-
if (
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
2009
|
+
if (color.secondBackground == undefined || color.secondBackground(scheme) === undefined) {
|
|
2010
|
+
return answer;
|
|
2011
|
+
}
|
|
2012
|
+
// Case 3: Adjust for dual backgrounds.
|
|
2013
|
+
const [bg1, bg2] = [color.background, color.secondBackground];
|
|
2014
|
+
const [bgTone1, bgTone2] = [bg1(scheme).getTone(scheme), bg2(scheme).getTone(scheme)];
|
|
2015
|
+
const [upper, lower] = [Math.max(bgTone1, bgTone2), Math.min(bgTone1, bgTone2)];
|
|
2016
|
+
if (Contrast.ratioOfTones(upper, answer) >= desiredRatio && Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
|
|
2017
|
+
return answer;
|
|
2018
|
+
}
|
|
2019
|
+
// The darkest light tone that satisfies the desired ratio,
|
|
2020
|
+
// or -1 if such ratio cannot be reached.
|
|
2021
|
+
const lightOption = Contrast.lighter(upper, desiredRatio);
|
|
2022
|
+
// The lightest dark tone that satisfies the desired ratio,
|
|
2023
|
+
// or -1 if such ratio cannot be reached.
|
|
2024
|
+
const darkOption = Contrast.darker(lower, desiredRatio);
|
|
2025
|
+
// Tones suitable for the foreground.
|
|
2026
|
+
const availables = [];
|
|
2027
|
+
if (lightOption !== -1) availables.push(lightOption);
|
|
2028
|
+
if (darkOption !== -1) availables.push(darkOption);
|
|
2029
|
+
const prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
|
|
2030
|
+
if (prefersLight) {
|
|
2031
|
+
return lightOption < 0 ? 100 : lightOption;
|
|
2032
|
+
}
|
|
2033
|
+
if (availables.length === 1) {
|
|
2034
|
+
return availables[0];
|
|
2035
|
+
}
|
|
2036
|
+
return darkOption < 0 ? 0 : darkOption;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* A delegate for the color calculation of a DynamicScheme in the 2025 spec.
|
|
2042
|
+
*/
|
|
2043
|
+
class ColorCalculationDelegateImpl2025 {
|
|
2044
|
+
getHct(scheme, color) {
|
|
2045
|
+
const palette = color.palette(scheme);
|
|
2046
|
+
const tone = color.getTone(scheme);
|
|
2047
|
+
const hue = palette.hue;
|
|
2048
|
+
const chroma = palette.chroma * (color.chromaMultiplier ? color.chromaMultiplier(scheme) : 1);
|
|
2049
|
+
return Hct.from(hue, chroma, tone);
|
|
2050
|
+
}
|
|
2051
|
+
getTone(scheme, color) {
|
|
2052
|
+
const toneDeltaPair = color.toneDeltaPair ? color.toneDeltaPair(scheme) : undefined;
|
|
2053
|
+
// Case 0: tone delta constraint.
|
|
2054
|
+
if (toneDeltaPair) {
|
|
2055
|
+
const roleA = toneDeltaPair.roleA;
|
|
2056
|
+
const roleB = toneDeltaPair.roleB;
|
|
2057
|
+
const polarity = toneDeltaPair.polarity;
|
|
2058
|
+
const constraint = toneDeltaPair.constraint;
|
|
2059
|
+
const absoluteDelta = polarity === 'darker' || polarity === 'relative_lighter' && scheme.isDark || polarity === 'relative_darker' && !scheme.isDark ? -toneDeltaPair.delta : toneDeltaPair.delta;
|
|
2060
|
+
const amRoleA = color.name === roleA.name;
|
|
2061
|
+
const selfRole = amRoleA ? roleA : roleB;
|
|
2062
|
+
const refRole = amRoleA ? roleB : roleA;
|
|
2063
|
+
let selfTone = selfRole.tone(scheme);
|
|
2064
|
+
let refTone = refRole.getTone(scheme);
|
|
2065
|
+
const relativeDelta = absoluteDelta * (amRoleA ? 1 : -1);
|
|
2066
|
+
if (constraint === 'exact') {
|
|
2067
|
+
selfTone = clampDouble(0, 100, refTone + relativeDelta);
|
|
2068
|
+
} else if (constraint === 'nearer') {
|
|
2069
|
+
if (relativeDelta > 0) {
|
|
2070
|
+
selfTone = clampDouble(0, 100, clampDouble(refTone, refTone + relativeDelta, selfTone));
|
|
2071
|
+
} else {
|
|
2072
|
+
selfTone = clampDouble(0, 100, clampDouble(refTone + relativeDelta, refTone, selfTone));
|
|
1733
2073
|
}
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
const darkOption = Contrast.darker(lower, desiredRatio);
|
|
1740
|
-
// Tones suitable for the foreground.
|
|
1741
|
-
const availables = [];
|
|
1742
|
-
if (lightOption !== -1) availables.push(lightOption);
|
|
1743
|
-
if (darkOption !== -1) availables.push(darkOption);
|
|
1744
|
-
const prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
|
|
1745
|
-
if (prefersLight) {
|
|
1746
|
-
return lightOption < 0 ? 100 : lightOption;
|
|
2074
|
+
} else if (constraint === 'farther') {
|
|
2075
|
+
if (relativeDelta > 0) {
|
|
2076
|
+
selfTone = clampDouble(refTone + relativeDelta, 100, selfTone);
|
|
2077
|
+
} else {
|
|
2078
|
+
selfTone = clampDouble(0, refTone + relativeDelta, selfTone);
|
|
1747
2079
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
2080
|
+
}
|
|
2081
|
+
if (color.background && color.contrastCurve) {
|
|
2082
|
+
const background = color.background(scheme);
|
|
2083
|
+
const contrastCurve = color.contrastCurve(scheme);
|
|
2084
|
+
if (background && contrastCurve) {
|
|
2085
|
+
// Adjust the tones for contrast, if background and contrast curve
|
|
2086
|
+
// are defined.
|
|
2087
|
+
const bgTone = background.getTone(scheme);
|
|
2088
|
+
const selfContrast = contrastCurve.get(scheme.contrastLevel);
|
|
2089
|
+
selfTone = Contrast.ratioOfTones(bgTone, selfTone) >= selfContrast && scheme.contrastLevel >= 0 ? selfTone : DynamicColor.foregroundTone(bgTone, selfContrast);
|
|
1750
2090
|
}
|
|
1751
|
-
return darkOption < 0 ? 0 : darkOption;
|
|
1752
2091
|
}
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
* value.
|
|
1764
|
-
*/
|
|
1765
|
-
static foregroundTone(bgTone, ratio) {
|
|
1766
|
-
const lighterTone = Contrast.lighterUnsafe(bgTone, ratio);
|
|
1767
|
-
const darkerTone = Contrast.darkerUnsafe(bgTone, ratio);
|
|
1768
|
-
const lighterRatio = Contrast.ratioOfTones(lighterTone, bgTone);
|
|
1769
|
-
const darkerRatio = Contrast.ratioOfTones(darkerTone, bgTone);
|
|
1770
|
-
const preferLighter = DynamicColor.tonePrefersLightForeground(bgTone);
|
|
1771
|
-
if (preferLighter) {
|
|
1772
|
-
// This handles an edge case where the initial contrast ratio is high
|
|
1773
|
-
// (ex. 13.0), and the ratio passed to the function is that high
|
|
1774
|
-
// ratio, and both the lighter and darker ratio fails to pass that
|
|
1775
|
-
// ratio.
|
|
1776
|
-
//
|
|
1777
|
-
// This was observed with Tonal Spot's On Primary Container turning
|
|
1778
|
-
// black momentarily between high and max contrast in light mode. PC's
|
|
1779
|
-
// standard tone was T90, OPC's was T10, it was light mode, and the
|
|
1780
|
-
// contrast value was 0.6568521221032331.
|
|
1781
|
-
const negligibleDifference = Math.abs(lighterRatio - darkerRatio) < 0.1 && lighterRatio < ratio && darkerRatio < ratio;
|
|
1782
|
-
return lighterRatio >= ratio || lighterRatio >= darkerRatio || negligibleDifference ? lighterTone : darkerTone;
|
|
2092
|
+
// This can avoid the awkward tones for background colors including the
|
|
2093
|
+
// access fixed colors. Accent fixed dim colors should not be adjusted.
|
|
2094
|
+
if (color.isBackground && !color.name.endsWith('_fixed_dim')) {
|
|
2095
|
+
if (selfTone >= 57) {
|
|
2096
|
+
selfTone = clampDouble(65, 100, selfTone);
|
|
2097
|
+
} else {
|
|
2098
|
+
selfTone = clampDouble(0, 49, selfTone);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
return selfTone;
|
|
1783
2102
|
} else {
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
2103
|
+
// Case 1: No tone delta pair; just solve for itself.
|
|
2104
|
+
let answer = color.tone(scheme);
|
|
2105
|
+
if (color.background == undefined || color.background(scheme) === undefined || color.contrastCurve == undefined || color.contrastCurve(scheme) === undefined) {
|
|
2106
|
+
return answer; // No adjustment for colors with no background.
|
|
2107
|
+
}
|
|
2108
|
+
const bgTone = color.background(scheme).getTone(scheme);
|
|
2109
|
+
const desiredRatio = color.contrastCurve(scheme).get(scheme.contrastLevel);
|
|
2110
|
+
// Recalculate the tone from desired contrast ratio if the current
|
|
2111
|
+
// contrast ratio is not enough or desired contrast level is decreasing
|
|
2112
|
+
// (<0).
|
|
2113
|
+
answer = Contrast.ratioOfTones(bgTone, answer) >= desiredRatio && scheme.contrastLevel >= 0 ? answer : DynamicColor.foregroundTone(bgTone, desiredRatio);
|
|
2114
|
+
// This can avoid the awkward tones for background colors including the
|
|
2115
|
+
// access fixed colors. Accent fixed dim colors should not be adjusted.
|
|
2116
|
+
if (color.isBackground && !color.name.endsWith('_fixed_dim')) {
|
|
2117
|
+
if (answer >= 57) {
|
|
2118
|
+
answer = clampDouble(65, 100, answer);
|
|
2119
|
+
} else {
|
|
2120
|
+
answer = clampDouble(0, 49, answer);
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
if (color.secondBackground == undefined || color.secondBackground(scheme) === undefined) {
|
|
2124
|
+
return answer;
|
|
2125
|
+
}
|
|
2126
|
+
// Case 2: Adjust for dual backgrounds.
|
|
2127
|
+
const [bg1, bg2] = [color.background, color.secondBackground];
|
|
2128
|
+
const [bgTone1, bgTone2] = [bg1(scheme).getTone(scheme), bg2(scheme).getTone(scheme)];
|
|
2129
|
+
const [upper, lower] = [Math.max(bgTone1, bgTone2), Math.min(bgTone1, bgTone2)];
|
|
2130
|
+
if (Contrast.ratioOfTones(upper, answer) >= desiredRatio && Contrast.ratioOfTones(lower, answer) >= desiredRatio) {
|
|
2131
|
+
return answer;
|
|
2132
|
+
}
|
|
2133
|
+
// The darkest light tone that satisfies the desired ratio,
|
|
2134
|
+
// or -1 if such ratio cannot be reached.
|
|
2135
|
+
const lightOption = Contrast.lighter(upper, desiredRatio);
|
|
2136
|
+
// The lightest dark tone that satisfies the desired ratio,
|
|
2137
|
+
// or -1 if such ratio cannot be reached.
|
|
2138
|
+
const darkOption = Contrast.darker(lower, desiredRatio);
|
|
2139
|
+
// Tones suitable for the foreground.
|
|
2140
|
+
const availables = [];
|
|
2141
|
+
if (lightOption !== -1) availables.push(lightOption);
|
|
2142
|
+
if (darkOption !== -1) availables.push(darkOption);
|
|
2143
|
+
const prefersLight = DynamicColor.tonePrefersLightForeground(bgTone1) || DynamicColor.tonePrefersLightForeground(bgTone2);
|
|
2144
|
+
if (prefersLight) {
|
|
2145
|
+
return lightOption < 0 ? 100 : lightOption;
|
|
2146
|
+
}
|
|
2147
|
+
if (availables.length === 1) {
|
|
2148
|
+
return availables[0];
|
|
2149
|
+
}
|
|
2150
|
+
return darkOption < 0 ? 0 : darkOption;
|
|
1815
2151
|
}
|
|
1816
|
-
return tone;
|
|
1817
2152
|
}
|
|
1818
2153
|
}
|
|
2154
|
+
const spec2021$1 = new ColorCalculationDelegateImpl2021();
|
|
2155
|
+
const spec2025$1 = new ColorCalculationDelegateImpl2025();
|
|
2156
|
+
/**
|
|
2157
|
+
* Returns the ColorCalculationDelegate for the given spec version.
|
|
2158
|
+
*/
|
|
2159
|
+
function getSpec$1(specVersion) {
|
|
2160
|
+
return specVersion === '2025' ? spec2025$1 : spec2021$1;
|
|
2161
|
+
}
|
|
1819
2162
|
|
|
1820
2163
|
/**
|
|
1821
2164
|
* @license
|
|
@@ -1875,7 +2218,11 @@ class TonalPalette {
|
|
|
1875
2218
|
tone(tone) {
|
|
1876
2219
|
let argb = this.cache.get(tone);
|
|
1877
2220
|
if (argb === undefined) {
|
|
1878
|
-
|
|
2221
|
+
if (tone == 99 && Hct.isYellow(this.hue)) {
|
|
2222
|
+
argb = this.averageArgb(this.tone(98), this.tone(100));
|
|
2223
|
+
} else {
|
|
2224
|
+
argb = Hct.from(this.hue, this.chroma, tone).toInt();
|
|
2225
|
+
}
|
|
1879
2226
|
this.cache.set(tone, argb);
|
|
1880
2227
|
}
|
|
1881
2228
|
return argb;
|
|
@@ -1887,6 +2234,18 @@ class TonalPalette {
|
|
|
1887
2234
|
getHct(tone) {
|
|
1888
2235
|
return Hct.fromInt(this.tone(tone));
|
|
1889
2236
|
}
|
|
2237
|
+
averageArgb(argb1, argb2) {
|
|
2238
|
+
const red1 = argb1 >>> 16 & 0xff;
|
|
2239
|
+
const green1 = argb1 >>> 8 & 0xff;
|
|
2240
|
+
const blue1 = argb1 & 0xff;
|
|
2241
|
+
const red2 = argb2 >>> 16 & 0xff;
|
|
2242
|
+
const green2 = argb2 >>> 8 & 0xff;
|
|
2243
|
+
const blue2 = argb2 & 0xff;
|
|
2244
|
+
const red = Math.round((red1 + red2) / 2);
|
|
2245
|
+
const green = Math.round((green1 + green2) / 2);
|
|
2246
|
+
const blue = Math.round((blue1 + blue2) / 2);
|
|
2247
|
+
return (255 << 24 | (red & 255) << 16 | (green & 255) << 8 | blue & 255) >>> 0;
|
|
2248
|
+
}
|
|
1890
2249
|
}
|
|
1891
2250
|
/**
|
|
1892
2251
|
* Key color is a color that represents the hue and chroma of a tonal palette
|
|
@@ -1972,34 +2331,299 @@ class KeyColor {
|
|
|
1972
2331
|
* See the License for the specific language governing permissions and
|
|
1973
2332
|
* limitations under the License.
|
|
1974
2333
|
*/
|
|
2334
|
+
// This file is automatically generated. Do not modify it.
|
|
1975
2335
|
/**
|
|
1976
|
-
*
|
|
2336
|
+
* Design utilities using color temperature theory.
|
|
1977
2337
|
*
|
|
1978
|
-
*
|
|
1979
|
-
*
|
|
1980
|
-
* 0.0, 0.5, and 1.0, respectively.
|
|
2338
|
+
* Analogous colors, complementary color, and cache to efficiently, lazily,
|
|
2339
|
+
* generate data for calculations when needed.
|
|
1981
2340
|
*/
|
|
1982
|
-
class
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
this.
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
2341
|
+
class TemperatureCache {
|
|
2342
|
+
constructor(input) {
|
|
2343
|
+
this.input = input;
|
|
2344
|
+
this.hctsByTempCache = [];
|
|
2345
|
+
this.hctsByHueCache = [];
|
|
2346
|
+
this.tempsByHctCache = new Map();
|
|
2347
|
+
this.inputRelativeTemperatureCache = -1;
|
|
2348
|
+
this.complementCache = null;
|
|
2349
|
+
}
|
|
2350
|
+
get hctsByTemp() {
|
|
2351
|
+
if (this.hctsByTempCache.length > 0) {
|
|
2352
|
+
return this.hctsByTempCache;
|
|
2353
|
+
}
|
|
2354
|
+
const hcts = this.hctsByHue.concat([this.input]);
|
|
2355
|
+
const temperaturesByHct = this.tempsByHct;
|
|
2356
|
+
hcts.sort((a, b) => temperaturesByHct.get(a) - temperaturesByHct.get(b));
|
|
2357
|
+
this.hctsByTempCache = hcts;
|
|
2358
|
+
return hcts;
|
|
2359
|
+
}
|
|
2360
|
+
get warmest() {
|
|
2361
|
+
return this.hctsByTemp[this.hctsByTemp.length - 1];
|
|
2362
|
+
}
|
|
2363
|
+
get coldest() {
|
|
2364
|
+
return this.hctsByTemp[0];
|
|
1996
2365
|
}
|
|
1997
2366
|
/**
|
|
1998
|
-
*
|
|
2367
|
+
* A set of colors with differing hues, equidistant in temperature.
|
|
1999
2368
|
*
|
|
2000
|
-
*
|
|
2001
|
-
*
|
|
2002
|
-
*
|
|
2369
|
+
* In art, this is usually described as a set of 5 colors on a color wheel
|
|
2370
|
+
* divided into 12 sections. This method allows provision of either of those
|
|
2371
|
+
* values.
|
|
2372
|
+
*
|
|
2373
|
+
* Behavior is undefined when [count] or [divisions] is 0.
|
|
2374
|
+
* When divisions < count, colors repeat.
|
|
2375
|
+
*
|
|
2376
|
+
* [count] The number of colors to return, includes the input color.
|
|
2377
|
+
* [divisions] The number of divisions on the color wheel.
|
|
2378
|
+
*/
|
|
2379
|
+
analogous(count = 5, divisions = 12) {
|
|
2380
|
+
const startHue = Math.round(this.input.hue);
|
|
2381
|
+
const startHct = this.hctsByHue[startHue];
|
|
2382
|
+
let lastTemp = this.relativeTemperature(startHct);
|
|
2383
|
+
const allColors = [startHct];
|
|
2384
|
+
let absoluteTotalTempDelta = 0.0;
|
|
2385
|
+
for (let i = 0; i < 360; i++) {
|
|
2386
|
+
const hue = sanitizeDegreesInt(startHue + i);
|
|
2387
|
+
const hct = this.hctsByHue[hue];
|
|
2388
|
+
const temp = this.relativeTemperature(hct);
|
|
2389
|
+
const tempDelta = Math.abs(temp - lastTemp);
|
|
2390
|
+
lastTemp = temp;
|
|
2391
|
+
absoluteTotalTempDelta += tempDelta;
|
|
2392
|
+
}
|
|
2393
|
+
let hueAddend = 1;
|
|
2394
|
+
const tempStep = absoluteTotalTempDelta / divisions;
|
|
2395
|
+
let totalTempDelta = 0.0;
|
|
2396
|
+
lastTemp = this.relativeTemperature(startHct);
|
|
2397
|
+
while (allColors.length < divisions) {
|
|
2398
|
+
const hue = sanitizeDegreesInt(startHue + hueAddend);
|
|
2399
|
+
const hct = this.hctsByHue[hue];
|
|
2400
|
+
const temp = this.relativeTemperature(hct);
|
|
2401
|
+
const tempDelta = Math.abs(temp - lastTemp);
|
|
2402
|
+
totalTempDelta += tempDelta;
|
|
2403
|
+
const desiredTotalTempDeltaForIndex = allColors.length * tempStep;
|
|
2404
|
+
let indexSatisfied = totalTempDelta >= desiredTotalTempDeltaForIndex;
|
|
2405
|
+
let indexAddend = 1;
|
|
2406
|
+
// Keep adding this hue to the answers until its temperature is
|
|
2407
|
+
// insufficient. This ensures consistent behavior when there aren't
|
|
2408
|
+
// [divisions] discrete steps between 0 and 360 in hue with [tempStep]
|
|
2409
|
+
// delta in temperature between them.
|
|
2410
|
+
//
|
|
2411
|
+
// For example, white and black have no analogues: there are no other
|
|
2412
|
+
// colors at T100/T0. Therefore, they should just be added to the array
|
|
2413
|
+
// as answers.
|
|
2414
|
+
while (indexSatisfied && allColors.length < divisions) {
|
|
2415
|
+
allColors.push(hct);
|
|
2416
|
+
const desiredTotalTempDeltaForIndex = (allColors.length + indexAddend) * tempStep;
|
|
2417
|
+
indexSatisfied = totalTempDelta >= desiredTotalTempDeltaForIndex;
|
|
2418
|
+
indexAddend++;
|
|
2419
|
+
}
|
|
2420
|
+
lastTemp = temp;
|
|
2421
|
+
hueAddend++;
|
|
2422
|
+
if (hueAddend > 360) {
|
|
2423
|
+
while (allColors.length < divisions) {
|
|
2424
|
+
allColors.push(hct);
|
|
2425
|
+
}
|
|
2426
|
+
break;
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
const answers = [this.input];
|
|
2430
|
+
// First, generate analogues from rotating counter-clockwise.
|
|
2431
|
+
const increaseHueCount = Math.floor((count - 1) / 2.0);
|
|
2432
|
+
for (let i = 1; i < increaseHueCount + 1; i++) {
|
|
2433
|
+
let index = 0 - i;
|
|
2434
|
+
while (index < 0) {
|
|
2435
|
+
index = allColors.length + index;
|
|
2436
|
+
}
|
|
2437
|
+
if (index >= allColors.length) {
|
|
2438
|
+
index = index % allColors.length;
|
|
2439
|
+
}
|
|
2440
|
+
answers.splice(0, 0, allColors[index]);
|
|
2441
|
+
}
|
|
2442
|
+
// Second, generate analogues from rotating clockwise.
|
|
2443
|
+
const decreaseHueCount = count - increaseHueCount - 1;
|
|
2444
|
+
for (let i = 1; i < decreaseHueCount + 1; i++) {
|
|
2445
|
+
let index = i;
|
|
2446
|
+
while (index < 0) {
|
|
2447
|
+
index = allColors.length + index;
|
|
2448
|
+
}
|
|
2449
|
+
if (index >= allColors.length) {
|
|
2450
|
+
index = index % allColors.length;
|
|
2451
|
+
}
|
|
2452
|
+
answers.push(allColors[index]);
|
|
2453
|
+
}
|
|
2454
|
+
return answers;
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* A color that complements the input color aesthetically.
|
|
2458
|
+
*
|
|
2459
|
+
* In art, this is usually described as being across the color wheel.
|
|
2460
|
+
* History of this shows intent as a color that is just as cool-warm as the
|
|
2461
|
+
* input color is warm-cool.
|
|
2462
|
+
*/
|
|
2463
|
+
get complement() {
|
|
2464
|
+
if (this.complementCache != null) {
|
|
2465
|
+
return this.complementCache;
|
|
2466
|
+
}
|
|
2467
|
+
const coldestHue = this.coldest.hue;
|
|
2468
|
+
const coldestTemp = this.tempsByHct.get(this.coldest);
|
|
2469
|
+
const warmestHue = this.warmest.hue;
|
|
2470
|
+
const warmestTemp = this.tempsByHct.get(this.warmest);
|
|
2471
|
+
const range = warmestTemp - coldestTemp;
|
|
2472
|
+
const startHueIsColdestToWarmest = TemperatureCache.isBetween(this.input.hue, coldestHue, warmestHue);
|
|
2473
|
+
const startHue = startHueIsColdestToWarmest ? warmestHue : coldestHue;
|
|
2474
|
+
const endHue = startHueIsColdestToWarmest ? coldestHue : warmestHue;
|
|
2475
|
+
const directionOfRotation = 1.0;
|
|
2476
|
+
let smallestError = 1000.0;
|
|
2477
|
+
let answer = this.hctsByHue[Math.round(this.input.hue)];
|
|
2478
|
+
const complementRelativeTemp = 1.0 - this.inputRelativeTemperature;
|
|
2479
|
+
// Find the color in the other section, closest to the inverse percentile
|
|
2480
|
+
// of the input color. This is the complement.
|
|
2481
|
+
for (let hueAddend = 0.0; hueAddend <= 360.0; hueAddend += 1.0) {
|
|
2482
|
+
const hue = sanitizeDegreesDouble(startHue + directionOfRotation * hueAddend);
|
|
2483
|
+
if (!TemperatureCache.isBetween(hue, startHue, endHue)) {
|
|
2484
|
+
continue;
|
|
2485
|
+
}
|
|
2486
|
+
const possibleAnswer = this.hctsByHue[Math.round(hue)];
|
|
2487
|
+
const relativeTemp = (this.tempsByHct.get(possibleAnswer) - coldestTemp) / range;
|
|
2488
|
+
const error = Math.abs(complementRelativeTemp - relativeTemp);
|
|
2489
|
+
if (error < smallestError) {
|
|
2490
|
+
smallestError = error;
|
|
2491
|
+
answer = possibleAnswer;
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
this.complementCache = answer;
|
|
2495
|
+
return this.complementCache;
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Temperature relative to all colors with the same chroma and tone.
|
|
2499
|
+
* Value on a scale from 0 to 1.
|
|
2500
|
+
*/
|
|
2501
|
+
relativeTemperature(hct) {
|
|
2502
|
+
const range = this.tempsByHct.get(this.warmest) - this.tempsByHct.get(this.coldest);
|
|
2503
|
+
const differenceFromColdest = this.tempsByHct.get(hct) - this.tempsByHct.get(this.coldest);
|
|
2504
|
+
// Handle when there's no difference in temperature between warmest and
|
|
2505
|
+
// coldest: for example, at T100, only one color is available, white.
|
|
2506
|
+
if (range === 0.0) {
|
|
2507
|
+
return 0.5;
|
|
2508
|
+
}
|
|
2509
|
+
return differenceFromColdest / range;
|
|
2510
|
+
}
|
|
2511
|
+
/** Relative temperature of the input color. See [relativeTemperature]. */
|
|
2512
|
+
get inputRelativeTemperature() {
|
|
2513
|
+
if (this.inputRelativeTemperatureCache >= 0.0) {
|
|
2514
|
+
return this.inputRelativeTemperatureCache;
|
|
2515
|
+
}
|
|
2516
|
+
this.inputRelativeTemperatureCache = this.relativeTemperature(this.input);
|
|
2517
|
+
return this.inputRelativeTemperatureCache;
|
|
2518
|
+
}
|
|
2519
|
+
/** A Map with keys of HCTs in [hctsByTemp], values of raw temperature. */
|
|
2520
|
+
get tempsByHct() {
|
|
2521
|
+
if (this.tempsByHctCache.size > 0) {
|
|
2522
|
+
return this.tempsByHctCache;
|
|
2523
|
+
}
|
|
2524
|
+
const allHcts = this.hctsByHue.concat([this.input]);
|
|
2525
|
+
const temperaturesByHct = new Map();
|
|
2526
|
+
for (const e of allHcts) {
|
|
2527
|
+
temperaturesByHct.set(e, TemperatureCache.rawTemperature(e));
|
|
2528
|
+
}
|
|
2529
|
+
this.tempsByHctCache = temperaturesByHct;
|
|
2530
|
+
return temperaturesByHct;
|
|
2531
|
+
}
|
|
2532
|
+
/**
|
|
2533
|
+
* HCTs for all hues, with the same chroma/tone as the input.
|
|
2534
|
+
* Sorted ascending, hue 0 to 360.
|
|
2535
|
+
*/
|
|
2536
|
+
get hctsByHue() {
|
|
2537
|
+
if (this.hctsByHueCache.length > 0) {
|
|
2538
|
+
return this.hctsByHueCache;
|
|
2539
|
+
}
|
|
2540
|
+
const hcts = [];
|
|
2541
|
+
for (let hue = 0.0; hue <= 360.0; hue += 1.0) {
|
|
2542
|
+
const colorAtHue = Hct.from(hue, this.input.chroma, this.input.tone);
|
|
2543
|
+
hcts.push(colorAtHue);
|
|
2544
|
+
}
|
|
2545
|
+
this.hctsByHueCache = hcts;
|
|
2546
|
+
return this.hctsByHueCache;
|
|
2547
|
+
}
|
|
2548
|
+
/** Determines if an angle is between two other angles, rotating clockwise. */
|
|
2549
|
+
static isBetween(angle, a, b) {
|
|
2550
|
+
if (a < b) {
|
|
2551
|
+
return a <= angle && angle <= b;
|
|
2552
|
+
}
|
|
2553
|
+
return a <= angle || angle <= b;
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* Value representing cool-warm factor of a color.
|
|
2557
|
+
* Values below 0 are considered cool, above, warm.
|
|
2558
|
+
*
|
|
2559
|
+
* Color science has researched emotion and harmony, which art uses to select
|
|
2560
|
+
* colors. Warm-cool is the foundation of analogous and complementary colors.
|
|
2561
|
+
* See:
|
|
2562
|
+
* - Li-Chen Ou's Chapter 19 in Handbook of Color Psychology (2015).
|
|
2563
|
+
* - Josef Albers' Interaction of Color chapters 19 and 21.
|
|
2564
|
+
*
|
|
2565
|
+
* Implementation of Ou, Woodcock and Wright's algorithm, which uses
|
|
2566
|
+
* L*a*b* / LCH color space.
|
|
2567
|
+
* Return value has these properties:
|
|
2568
|
+
* - Values below 0 are cool, above 0 are warm.
|
|
2569
|
+
* - Lower bound: -0.52 - (chroma ^ 1.07 / 20). L*a*b* chroma is infinite.
|
|
2570
|
+
* Assuming max of 130 chroma, -9.66.
|
|
2571
|
+
* - Upper bound: -0.52 + (chroma ^ 1.07 / 20). L*a*b* chroma is infinite.
|
|
2572
|
+
* Assuming max of 130 chroma, 8.61.
|
|
2573
|
+
*/
|
|
2574
|
+
static rawTemperature(color) {
|
|
2575
|
+
const lab = labFromArgb(color.toInt());
|
|
2576
|
+
const hue = sanitizeDegreesDouble(Math.atan2(lab[2], lab[1]) * 180.0 / Math.PI);
|
|
2577
|
+
const chroma = Math.sqrt(lab[1] * lab[1] + lab[2] * lab[2]);
|
|
2578
|
+
const temperature = -0.5 + 0.02 * Math.pow(chroma, 1.07) * Math.cos(sanitizeDegreesDouble(hue - 50.0) * Math.PI / 180.0);
|
|
2579
|
+
return temperature;
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
/**
|
|
2584
|
+
* @license
|
|
2585
|
+
* Copyright 2023 Google LLC
|
|
2586
|
+
*
|
|
2587
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2588
|
+
* you may not use this file except in compliance with the License.
|
|
2589
|
+
* You may obtain a copy of the License at
|
|
2590
|
+
*
|
|
2591
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2592
|
+
*
|
|
2593
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2594
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2595
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2596
|
+
* See the License for the specific language governing permissions and
|
|
2597
|
+
* limitations under the License.
|
|
2598
|
+
*/
|
|
2599
|
+
/**
|
|
2600
|
+
* A class containing a value that changes with the contrast level.
|
|
2601
|
+
*
|
|
2602
|
+
* Usually represents the contrast requirements for a dynamic color on its
|
|
2603
|
+
* background. The four values correspond to values for contrast levels -1.0,
|
|
2604
|
+
* 0.0, 0.5, and 1.0, respectively.
|
|
2605
|
+
*/
|
|
2606
|
+
class ContrastCurve {
|
|
2607
|
+
/**
|
|
2608
|
+
* Creates a `ContrastCurve` object.
|
|
2609
|
+
*
|
|
2610
|
+
* @param low Value for contrast level -1.0
|
|
2611
|
+
* @param normal Value for contrast level 0.0
|
|
2612
|
+
* @param medium Value for contrast level 0.5
|
|
2613
|
+
* @param high Value for contrast level 1.0
|
|
2614
|
+
*/
|
|
2615
|
+
constructor(low, normal, medium, high) {
|
|
2616
|
+
this.low = low;
|
|
2617
|
+
this.normal = normal;
|
|
2618
|
+
this.medium = medium;
|
|
2619
|
+
this.high = high;
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Returns the value at a given contrast level.
|
|
2623
|
+
*
|
|
2624
|
+
* @param contrastLevel The contrast level. 0.0 is the default (normal); -1.0
|
|
2625
|
+
* is the lowest; 1.0 is the highest.
|
|
2626
|
+
* @return The value. For contrast ratios, a number between 1.0 and 21.0.
|
|
2003
2627
|
*/
|
|
2004
2628
|
get(contrastLevel) {
|
|
2005
2629
|
if (contrastLevel <= -1) {
|
|
@@ -2046,13 +2670,14 @@ class ToneDeltaPair {
|
|
|
2046
2670
|
*
|
|
2047
2671
|
* The polarity is an adjective that describes "A", compared to "B".
|
|
2048
2672
|
*
|
|
2049
|
-
* For instance, ToneDeltaPair(A, B, 15, 'darker',
|
|
2050
|
-
* A's tone should be
|
|
2673
|
+
* For instance, ToneDeltaPair(A, B, 15, 'darker', 'exact') states that
|
|
2674
|
+
* A's tone should be exactly 15 darker than B's.
|
|
2051
2675
|
*
|
|
2052
|
-
* '
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2676
|
+
* 'relative_darker' and 'relative_lighter' describes the tone adjustment
|
|
2677
|
+
* relative to the surface color trend (white in light mode; black in dark
|
|
2678
|
+
* mode). For instance, ToneDeltaPair(A, B, 10, 'relative_lighter',
|
|
2679
|
+
* 'farther') states that A should be at least 10 lighter than B in light
|
|
2680
|
+
* mode, and at least 10 darker than B in dark mode.
|
|
2056
2681
|
*
|
|
2057
2682
|
* @param roleA The first role in a pair.
|
|
2058
2683
|
* @param roleB The second role in a pair.
|
|
@@ -2060,16 +2685,19 @@ class ToneDeltaPair {
|
|
|
2060
2685
|
* values have undefined behavior.
|
|
2061
2686
|
* @param polarity The relative relation between tones of roleA and roleB,
|
|
2062
2687
|
* as described above.
|
|
2063
|
-
* @param
|
|
2064
|
-
*
|
|
2688
|
+
* @param constraint How to fulfill the tone delta pair constraint.
|
|
2689
|
+
* @param stayTogether Whether these two roles should stay on the same side
|
|
2690
|
+
* of the "awkward zone" (T50-59). This is necessary for certain cases where
|
|
2065
2691
|
* one role has two backgrounds.
|
|
2066
2692
|
*/
|
|
2067
|
-
constructor(roleA, roleB, delta, polarity, stayTogether) {
|
|
2693
|
+
constructor(roleA, roleB, delta, polarity, stayTogether, constraint) {
|
|
2068
2694
|
this.roleA = roleA;
|
|
2069
2695
|
this.roleB = roleB;
|
|
2070
2696
|
this.delta = delta;
|
|
2071
2697
|
this.polarity = polarity;
|
|
2072
2698
|
this.stayTogether = stayTogether;
|
|
2699
|
+
this.constraint = constraint;
|
|
2700
|
+
this.constraint = constraint ?? 'exact';
|
|
2073
2701
|
}
|
|
2074
2702
|
}
|
|
2075
2703
|
|
|
@@ -2109,7 +2737,7 @@ var Variant;
|
|
|
2109
2737
|
|
|
2110
2738
|
/**
|
|
2111
2739
|
* @license
|
|
2112
|
-
* Copyright
|
|
2740
|
+
* Copyright 2025 Google LLC
|
|
2113
2741
|
*
|
|
2114
2742
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2115
2743
|
* you may not use this file except in compliance with the License.
|
|
@@ -2123,12 +2751,26 @@ var Variant;
|
|
|
2123
2751
|
* See the License for the specific language governing permissions and
|
|
2124
2752
|
* limitations under the License.
|
|
2125
2753
|
*/
|
|
2754
|
+
/**
|
|
2755
|
+
* Returns true if the scheme is Fidelity or Content.
|
|
2756
|
+
*/
|
|
2126
2757
|
function isFidelity(scheme) {
|
|
2127
2758
|
return scheme.variant === Variant.FIDELITY || scheme.variant === Variant.CONTENT;
|
|
2128
2759
|
}
|
|
2760
|
+
/**
|
|
2761
|
+
* Returns true if the scheme is Monochrome.
|
|
2762
|
+
*/
|
|
2129
2763
|
function isMonochrome(scheme) {
|
|
2130
2764
|
return scheme.variant === Variant.MONOCHROME;
|
|
2131
2765
|
}
|
|
2766
|
+
/**
|
|
2767
|
+
* Returns the desired chroma for a given tone at a specific hue.
|
|
2768
|
+
*
|
|
2769
|
+
* @param hue The given hue.
|
|
2770
|
+
* @param chroma The target chroma.
|
|
2771
|
+
* @param tone The tone to start with.
|
|
2772
|
+
* @param byDecreasingTone Whether to search for lower tones.
|
|
2773
|
+
*/
|
|
2132
2774
|
function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
|
|
2133
2775
|
let answer = tone;
|
|
2134
2776
|
let closestToChroma = Hct.from(hue, chroma, tone);
|
|
@@ -2154,482 +2796,1979 @@ function findDesiredChromaByTone(hue, chroma, tone, byDecreasingTone) {
|
|
|
2154
2796
|
return answer;
|
|
2155
2797
|
}
|
|
2156
2798
|
/**
|
|
2157
|
-
*
|
|
2799
|
+
* A delegate for the dynamic color spec of a DynamicScheme in the 2021 spec.
|
|
2158
2800
|
*/
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2801
|
+
class ColorSpecDelegateImpl2021 {
|
|
2802
|
+
////////////////////////////////////////////////////////////////
|
|
2803
|
+
// Main Palettes //
|
|
2804
|
+
////////////////////////////////////////////////////////////////
|
|
2805
|
+
primaryPaletteKeyColor() {
|
|
2806
|
+
return DynamicColor.fromPalette({
|
|
2807
|
+
name: 'primary_palette_key_color',
|
|
2808
|
+
palette: s => s.primaryPalette,
|
|
2809
|
+
tone: s => s.primaryPalette.keyColor.tone
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
secondaryPaletteKeyColor() {
|
|
2813
|
+
return DynamicColor.fromPalette({
|
|
2814
|
+
name: 'secondary_palette_key_color',
|
|
2815
|
+
palette: s => s.secondaryPalette,
|
|
2816
|
+
tone: s => s.secondaryPalette.keyColor.tone
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
tertiaryPaletteKeyColor() {
|
|
2820
|
+
return DynamicColor.fromPalette({
|
|
2821
|
+
name: 'tertiary_palette_key_color',
|
|
2822
|
+
palette: s => s.tertiaryPalette,
|
|
2823
|
+
tone: s => s.tertiaryPalette.keyColor.tone
|
|
2824
|
+
});
|
|
2825
|
+
}
|
|
2826
|
+
neutralPaletteKeyColor() {
|
|
2827
|
+
return DynamicColor.fromPalette({
|
|
2828
|
+
name: 'neutral_palette_key_color',
|
|
2829
|
+
palette: s => s.neutralPalette,
|
|
2830
|
+
tone: s => s.neutralPalette.keyColor.tone
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
neutralVariantPaletteKeyColor() {
|
|
2834
|
+
return DynamicColor.fromPalette({
|
|
2835
|
+
name: 'neutral_variant_palette_key_color',
|
|
2836
|
+
palette: s => s.neutralVariantPalette,
|
|
2837
|
+
tone: s => s.neutralVariantPalette.keyColor.tone
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2840
|
+
errorPaletteKeyColor() {
|
|
2841
|
+
return DynamicColor.fromPalette({
|
|
2842
|
+
name: 'error_palette_key_color',
|
|
2843
|
+
palette: s => s.errorPalette,
|
|
2844
|
+
tone: s => s.errorPalette.keyColor.tone
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2847
|
+
////////////////////////////////////////////////////////////////
|
|
2848
|
+
// Surfaces [S] //
|
|
2849
|
+
////////////////////////////////////////////////////////////////
|
|
2850
|
+
background() {
|
|
2851
|
+
return DynamicColor.fromPalette({
|
|
2852
|
+
name: 'background',
|
|
2853
|
+
palette: s => s.neutralPalette,
|
|
2854
|
+
tone: s => s.isDark ? 6 : 98,
|
|
2855
|
+
isBackground: true
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
onBackground() {
|
|
2859
|
+
return DynamicColor.fromPalette({
|
|
2860
|
+
name: 'on_background',
|
|
2861
|
+
palette: s => s.neutralPalette,
|
|
2862
|
+
tone: s => s.isDark ? 90 : 10,
|
|
2863
|
+
background: s => this.background(),
|
|
2864
|
+
contrastCurve: s => new ContrastCurve(3, 3, 4.5, 7)
|
|
2865
|
+
});
|
|
2866
|
+
}
|
|
2867
|
+
surface() {
|
|
2868
|
+
return DynamicColor.fromPalette({
|
|
2869
|
+
name: 'surface',
|
|
2870
|
+
palette: s => s.neutralPalette,
|
|
2871
|
+
tone: s => s.isDark ? 6 : 98,
|
|
2872
|
+
isBackground: true
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2875
|
+
surfaceDim() {
|
|
2876
|
+
return DynamicColor.fromPalette({
|
|
2877
|
+
name: 'surface_dim',
|
|
2878
|
+
palette: s => s.neutralPalette,
|
|
2879
|
+
tone: s => s.isDark ? 6 : new ContrastCurve(87, 87, 80, 75).get(s.contrastLevel),
|
|
2880
|
+
isBackground: true
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
surfaceBright() {
|
|
2884
|
+
return DynamicColor.fromPalette({
|
|
2885
|
+
name: 'surface_bright',
|
|
2886
|
+
palette: s => s.neutralPalette,
|
|
2887
|
+
tone: s => s.isDark ? new ContrastCurve(24, 24, 29, 34).get(s.contrastLevel) : 98,
|
|
2888
|
+
isBackground: true
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
surfaceContainerLowest() {
|
|
2892
|
+
return DynamicColor.fromPalette({
|
|
2893
|
+
name: 'surface_container_lowest',
|
|
2894
|
+
palette: s => s.neutralPalette,
|
|
2895
|
+
tone: s => s.isDark ? new ContrastCurve(4, 4, 2, 0).get(s.contrastLevel) : 100,
|
|
2896
|
+
isBackground: true
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
surfaceContainerLow() {
|
|
2900
|
+
return DynamicColor.fromPalette({
|
|
2901
|
+
name: 'surface_container_low',
|
|
2902
|
+
palette: s => s.neutralPalette,
|
|
2903
|
+
tone: s => s.isDark ? new ContrastCurve(10, 10, 11, 12).get(s.contrastLevel) : new ContrastCurve(96, 96, 96, 95).get(s.contrastLevel),
|
|
2904
|
+
isBackground: true
|
|
2905
|
+
});
|
|
2906
|
+
}
|
|
2907
|
+
surfaceContainer() {
|
|
2908
|
+
return DynamicColor.fromPalette({
|
|
2909
|
+
name: 'surface_container',
|
|
2910
|
+
palette: s => s.neutralPalette,
|
|
2911
|
+
tone: s => s.isDark ? new ContrastCurve(12, 12, 16, 20).get(s.contrastLevel) : new ContrastCurve(94, 94, 92, 90).get(s.contrastLevel),
|
|
2912
|
+
isBackground: true
|
|
2913
|
+
});
|
|
2914
|
+
}
|
|
2915
|
+
surfaceContainerHigh() {
|
|
2916
|
+
return DynamicColor.fromPalette({
|
|
2917
|
+
name: 'surface_container_high',
|
|
2918
|
+
palette: s => s.neutralPalette,
|
|
2919
|
+
tone: s => s.isDark ? new ContrastCurve(17, 17, 21, 25).get(s.contrastLevel) : new ContrastCurve(92, 92, 88, 85).get(s.contrastLevel),
|
|
2920
|
+
isBackground: true
|
|
2921
|
+
});
|
|
2922
|
+
}
|
|
2923
|
+
surfaceContainerHighest() {
|
|
2924
|
+
return DynamicColor.fromPalette({
|
|
2925
|
+
name: 'surface_container_highest',
|
|
2926
|
+
palette: s => s.neutralPalette,
|
|
2927
|
+
tone: s => s.isDark ? new ContrastCurve(22, 22, 26, 30).get(s.contrastLevel) : new ContrastCurve(90, 90, 84, 80).get(s.contrastLevel),
|
|
2928
|
+
isBackground: true
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
onSurface() {
|
|
2932
|
+
return DynamicColor.fromPalette({
|
|
2933
|
+
name: 'on_surface',
|
|
2934
|
+
palette: s => s.neutralPalette,
|
|
2935
|
+
tone: s => s.isDark ? 90 : 10,
|
|
2936
|
+
background: s => this.highestSurface(s),
|
|
2937
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
2938
|
+
});
|
|
2939
|
+
}
|
|
2940
|
+
surfaceVariant() {
|
|
2941
|
+
return DynamicColor.fromPalette({
|
|
2942
|
+
name: 'surface_variant',
|
|
2943
|
+
palette: s => s.neutralVariantPalette,
|
|
2944
|
+
tone: s => s.isDark ? 30 : 90,
|
|
2945
|
+
isBackground: true
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
onSurfaceVariant() {
|
|
2949
|
+
return DynamicColor.fromPalette({
|
|
2950
|
+
name: 'on_surface_variant',
|
|
2951
|
+
palette: s => s.neutralVariantPalette,
|
|
2952
|
+
tone: s => s.isDark ? 80 : 30,
|
|
2953
|
+
background: s => this.highestSurface(s),
|
|
2954
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
2955
|
+
});
|
|
2956
|
+
}
|
|
2957
|
+
inverseSurface() {
|
|
2958
|
+
return DynamicColor.fromPalette({
|
|
2959
|
+
name: 'inverse_surface',
|
|
2960
|
+
palette: s => s.neutralPalette,
|
|
2961
|
+
tone: s => s.isDark ? 90 : 20,
|
|
2962
|
+
isBackground: true
|
|
2963
|
+
});
|
|
2964
|
+
}
|
|
2965
|
+
inverseOnSurface() {
|
|
2966
|
+
return DynamicColor.fromPalette({
|
|
2967
|
+
name: 'inverse_on_surface',
|
|
2968
|
+
palette: s => s.neutralPalette,
|
|
2969
|
+
tone: s => s.isDark ? 20 : 95,
|
|
2970
|
+
background: s => this.inverseSurface(),
|
|
2971
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2974
|
+
outline() {
|
|
2975
|
+
return DynamicColor.fromPalette({
|
|
2976
|
+
name: 'outline',
|
|
2977
|
+
palette: s => s.neutralVariantPalette,
|
|
2978
|
+
tone: s => s.isDark ? 60 : 50,
|
|
2979
|
+
background: s => this.highestSurface(s),
|
|
2980
|
+
contrastCurve: s => new ContrastCurve(1.5, 3, 4.5, 7)
|
|
2981
|
+
});
|
|
2982
|
+
}
|
|
2983
|
+
outlineVariant() {
|
|
2984
|
+
return DynamicColor.fromPalette({
|
|
2985
|
+
name: 'outline_variant',
|
|
2986
|
+
palette: s => s.neutralVariantPalette,
|
|
2987
|
+
tone: s => s.isDark ? 30 : 80,
|
|
2988
|
+
background: s => this.highestSurface(s),
|
|
2989
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5)
|
|
2990
|
+
});
|
|
2991
|
+
}
|
|
2992
|
+
shadow() {
|
|
2993
|
+
return DynamicColor.fromPalette({
|
|
2994
|
+
name: 'shadow',
|
|
2995
|
+
palette: s => s.neutralPalette,
|
|
2996
|
+
tone: s => 0
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
2999
|
+
scrim() {
|
|
3000
|
+
return DynamicColor.fromPalette({
|
|
3001
|
+
name: 'scrim',
|
|
3002
|
+
palette: s => s.neutralPalette,
|
|
3003
|
+
tone: s => 0
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
surfaceTint() {
|
|
3007
|
+
return DynamicColor.fromPalette({
|
|
3008
|
+
name: 'surface_tint',
|
|
3009
|
+
palette: s => s.primaryPalette,
|
|
3010
|
+
tone: s => s.isDark ? 80 : 40,
|
|
3011
|
+
isBackground: true
|
|
3012
|
+
});
|
|
3013
|
+
}
|
|
3014
|
+
////////////////////////////////////////////////////////////////
|
|
3015
|
+
// Primary [P]. //
|
|
3016
|
+
////////////////////////////////////////////////////////////////
|
|
3017
|
+
primary() {
|
|
3018
|
+
return DynamicColor.fromPalette({
|
|
3019
|
+
name: 'primary',
|
|
3020
|
+
palette: s => s.primaryPalette,
|
|
3021
|
+
tone: s => {
|
|
3022
|
+
if (isMonochrome(s)) {
|
|
3023
|
+
return s.isDark ? 100 : 0;
|
|
3024
|
+
}
|
|
3025
|
+
return s.isDark ? 80 : 40;
|
|
3026
|
+
},
|
|
3027
|
+
isBackground: true,
|
|
3028
|
+
background: s => this.highestSurface(s),
|
|
3029
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 7),
|
|
3030
|
+
toneDeltaPair: s => new ToneDeltaPair(this.primaryContainer(), this.primary(), 10, 'nearer', false)
|
|
3031
|
+
});
|
|
3032
|
+
}
|
|
3033
|
+
primaryDim() {
|
|
3034
|
+
return undefined;
|
|
3035
|
+
}
|
|
3036
|
+
onPrimary() {
|
|
3037
|
+
return DynamicColor.fromPalette({
|
|
3038
|
+
name: 'on_primary',
|
|
3039
|
+
palette: s => s.primaryPalette,
|
|
3040
|
+
tone: s => {
|
|
3041
|
+
if (isMonochrome(s)) {
|
|
3042
|
+
return s.isDark ? 10 : 90;
|
|
3043
|
+
}
|
|
3044
|
+
return s.isDark ? 20 : 100;
|
|
3045
|
+
},
|
|
3046
|
+
background: s => this.primary(),
|
|
3047
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
3048
|
+
});
|
|
3049
|
+
}
|
|
3050
|
+
primaryContainer() {
|
|
3051
|
+
return DynamicColor.fromPalette({
|
|
3052
|
+
name: 'primary_container',
|
|
3053
|
+
palette: s => s.primaryPalette,
|
|
3054
|
+
tone: s => {
|
|
3055
|
+
if (isFidelity(s)) {
|
|
3056
|
+
return s.sourceColorHct.tone;
|
|
3057
|
+
}
|
|
3058
|
+
if (isMonochrome(s)) {
|
|
3059
|
+
return s.isDark ? 85 : 25;
|
|
3060
|
+
}
|
|
3061
|
+
return s.isDark ? 30 : 90;
|
|
3062
|
+
},
|
|
3063
|
+
isBackground: true,
|
|
3064
|
+
background: s => this.highestSurface(s),
|
|
3065
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3066
|
+
toneDeltaPair: s => new ToneDeltaPair(this.primaryContainer(), this.primary(), 10, 'nearer', false)
|
|
3067
|
+
});
|
|
3068
|
+
}
|
|
3069
|
+
onPrimaryContainer() {
|
|
3070
|
+
return DynamicColor.fromPalette({
|
|
3071
|
+
name: 'on_primary_container',
|
|
3072
|
+
palette: s => s.primaryPalette,
|
|
3073
|
+
tone: s => {
|
|
3074
|
+
if (isFidelity(s)) {
|
|
3075
|
+
return DynamicColor.foregroundTone(this.primaryContainer().tone(s), 4.5);
|
|
3076
|
+
}
|
|
3077
|
+
if (isMonochrome(s)) {
|
|
3078
|
+
return s.isDark ? 0 : 100;
|
|
3079
|
+
}
|
|
3080
|
+
return s.isDark ? 90 : 30;
|
|
3081
|
+
},
|
|
3082
|
+
background: s => this.primaryContainer(),
|
|
3083
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
3084
|
+
});
|
|
3085
|
+
}
|
|
3086
|
+
inversePrimary() {
|
|
3087
|
+
return DynamicColor.fromPalette({
|
|
3088
|
+
name: 'inverse_primary',
|
|
3089
|
+
palette: s => s.primaryPalette,
|
|
3090
|
+
tone: s => s.isDark ? 40 : 80,
|
|
3091
|
+
background: s => this.inverseSurface(),
|
|
3092
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 7)
|
|
3093
|
+
});
|
|
3094
|
+
}
|
|
3095
|
+
/////////////////////////////////////////////////////////////////
|
|
3096
|
+
// Secondary [Q]. //
|
|
3097
|
+
/////////////////////////////////////////////////////////////////
|
|
3098
|
+
secondary() {
|
|
3099
|
+
return DynamicColor.fromPalette({
|
|
3100
|
+
name: 'secondary',
|
|
3101
|
+
palette: s => s.secondaryPalette,
|
|
3102
|
+
tone: s => s.isDark ? 80 : 40,
|
|
3103
|
+
isBackground: true,
|
|
3104
|
+
background: s => this.highestSurface(s),
|
|
3105
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 7),
|
|
3106
|
+
toneDeltaPair: s => new ToneDeltaPair(this.secondaryContainer(), this.secondary(), 10, 'nearer', false)
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
secondaryDim() {
|
|
3110
|
+
return undefined;
|
|
3111
|
+
}
|
|
3112
|
+
onSecondary() {
|
|
3113
|
+
return DynamicColor.fromPalette({
|
|
3114
|
+
name: 'on_secondary',
|
|
3115
|
+
palette: s => s.secondaryPalette,
|
|
3116
|
+
tone: s => {
|
|
3117
|
+
if (isMonochrome(s)) {
|
|
3118
|
+
return s.isDark ? 10 : 100;
|
|
3119
|
+
} else {
|
|
3120
|
+
return s.isDark ? 20 : 100;
|
|
3121
|
+
}
|
|
3122
|
+
},
|
|
3123
|
+
background: s => this.secondary(),
|
|
3124
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
3125
|
+
});
|
|
3126
|
+
}
|
|
3127
|
+
secondaryContainer() {
|
|
3128
|
+
return DynamicColor.fromPalette({
|
|
3129
|
+
name: 'secondary_container',
|
|
3130
|
+
palette: s => s.secondaryPalette,
|
|
3131
|
+
tone: s => {
|
|
3132
|
+
const initialTone = s.isDark ? 30 : 90;
|
|
3133
|
+
if (isMonochrome(s)) {
|
|
3134
|
+
return s.isDark ? 30 : 85;
|
|
3135
|
+
}
|
|
3136
|
+
if (!isFidelity(s)) {
|
|
3137
|
+
return initialTone;
|
|
3138
|
+
}
|
|
3139
|
+
return findDesiredChromaByTone(s.secondaryPalette.hue, s.secondaryPalette.chroma, initialTone, s.isDark ? false : true);
|
|
3140
|
+
},
|
|
3141
|
+
isBackground: true,
|
|
3142
|
+
background: s => this.highestSurface(s),
|
|
3143
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3144
|
+
toneDeltaPair: s => new ToneDeltaPair(this.secondaryContainer(), this.secondary(), 10, 'nearer', false)
|
|
3145
|
+
});
|
|
3146
|
+
}
|
|
3147
|
+
onSecondaryContainer() {
|
|
3148
|
+
return DynamicColor.fromPalette({
|
|
3149
|
+
name: 'on_secondary_container',
|
|
3150
|
+
palette: s => s.secondaryPalette,
|
|
3151
|
+
tone: s => {
|
|
3152
|
+
if (isMonochrome(s)) {
|
|
3153
|
+
return s.isDark ? 90 : 10;
|
|
3154
|
+
}
|
|
3155
|
+
if (!isFidelity(s)) {
|
|
3156
|
+
return s.isDark ? 90 : 30;
|
|
3157
|
+
}
|
|
3158
|
+
return DynamicColor.foregroundTone(this.secondaryContainer().tone(s), 4.5);
|
|
3159
|
+
},
|
|
3160
|
+
background: s => this.secondaryContainer(),
|
|
3161
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
3162
|
+
});
|
|
3163
|
+
}
|
|
3164
|
+
/////////////////////////////////////////////////////////////////
|
|
3165
|
+
// Tertiary [T]. //
|
|
3166
|
+
/////////////////////////////////////////////////////////////////
|
|
3167
|
+
tertiary() {
|
|
3168
|
+
return DynamicColor.fromPalette({
|
|
3169
|
+
name: 'tertiary',
|
|
3170
|
+
palette: s => s.tertiaryPalette,
|
|
3171
|
+
tone: s => {
|
|
3172
|
+
if (isMonochrome(s)) {
|
|
3173
|
+
return s.isDark ? 90 : 25;
|
|
3174
|
+
}
|
|
3175
|
+
return s.isDark ? 80 : 40;
|
|
3176
|
+
},
|
|
3177
|
+
isBackground: true,
|
|
3178
|
+
background: s => this.highestSurface(s),
|
|
3179
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 7),
|
|
3180
|
+
toneDeltaPair: s => new ToneDeltaPair(this.tertiaryContainer(), this.tertiary(), 10, 'nearer', false)
|
|
3181
|
+
});
|
|
3182
|
+
}
|
|
3183
|
+
tertiaryDim() {
|
|
3184
|
+
return undefined;
|
|
3185
|
+
}
|
|
3186
|
+
onTertiary() {
|
|
3187
|
+
return DynamicColor.fromPalette({
|
|
3188
|
+
name: 'on_tertiary',
|
|
3189
|
+
palette: s => s.tertiaryPalette,
|
|
3190
|
+
tone: s => {
|
|
3191
|
+
if (isMonochrome(s)) {
|
|
3192
|
+
return s.isDark ? 10 : 90;
|
|
3193
|
+
}
|
|
3194
|
+
return s.isDark ? 20 : 100;
|
|
3195
|
+
},
|
|
3196
|
+
background: s => this.tertiary(),
|
|
3197
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
3198
|
+
});
|
|
3199
|
+
}
|
|
3200
|
+
tertiaryContainer() {
|
|
3201
|
+
return DynamicColor.fromPalette({
|
|
3202
|
+
name: 'tertiary_container',
|
|
3203
|
+
palette: s => s.tertiaryPalette,
|
|
3204
|
+
tone: s => {
|
|
3205
|
+
if (isMonochrome(s)) {
|
|
3206
|
+
return s.isDark ? 60 : 49;
|
|
3207
|
+
}
|
|
3208
|
+
if (!isFidelity(s)) {
|
|
3209
|
+
return s.isDark ? 30 : 90;
|
|
3210
|
+
}
|
|
3211
|
+
const proposedHct = s.tertiaryPalette.getHct(s.sourceColorHct.tone);
|
|
3212
|
+
return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
|
|
3213
|
+
},
|
|
3214
|
+
isBackground: true,
|
|
3215
|
+
background: s => this.highestSurface(s),
|
|
3216
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3217
|
+
toneDeltaPair: s => new ToneDeltaPair(this.tertiaryContainer(), this.tertiary(), 10, 'nearer', false)
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
onTertiaryContainer() {
|
|
3221
|
+
return DynamicColor.fromPalette({
|
|
3222
|
+
name: 'on_tertiary_container',
|
|
3223
|
+
palette: s => s.tertiaryPalette,
|
|
3224
|
+
tone: s => {
|
|
3225
|
+
if (isMonochrome(s)) {
|
|
3226
|
+
return s.isDark ? 0 : 100;
|
|
3227
|
+
}
|
|
3228
|
+
if (!isFidelity(s)) {
|
|
3229
|
+
return s.isDark ? 90 : 30;
|
|
3230
|
+
}
|
|
3231
|
+
return DynamicColor.foregroundTone(this.tertiaryContainer().tone(s), 4.5);
|
|
3232
|
+
},
|
|
3233
|
+
background: s => this.tertiaryContainer(),
|
|
3234
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
3235
|
+
});
|
|
3236
|
+
}
|
|
3237
|
+
//////////////////////////////////////////////////////////////////
|
|
3238
|
+
// Error [E]. //
|
|
3239
|
+
//////////////////////////////////////////////////////////////////
|
|
3240
|
+
error() {
|
|
3241
|
+
return DynamicColor.fromPalette({
|
|
3242
|
+
name: 'error',
|
|
3243
|
+
palette: s => s.errorPalette,
|
|
3244
|
+
tone: s => s.isDark ? 80 : 40,
|
|
3245
|
+
isBackground: true,
|
|
3246
|
+
background: s => this.highestSurface(s),
|
|
3247
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 7),
|
|
3248
|
+
toneDeltaPair: s => new ToneDeltaPair(this.errorContainer(), this.error(), 10, 'nearer', false)
|
|
3249
|
+
});
|
|
3250
|
+
}
|
|
3251
|
+
errorDim() {
|
|
3252
|
+
return undefined;
|
|
3253
|
+
}
|
|
3254
|
+
onError() {
|
|
3255
|
+
return DynamicColor.fromPalette({
|
|
3256
|
+
name: 'on_error',
|
|
3257
|
+
palette: s => s.errorPalette,
|
|
3258
|
+
tone: s => s.isDark ? 20 : 100,
|
|
3259
|
+
background: s => this.error(),
|
|
3260
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
errorContainer() {
|
|
3264
|
+
return DynamicColor.fromPalette({
|
|
3265
|
+
name: 'error_container',
|
|
3266
|
+
palette: s => s.errorPalette,
|
|
3267
|
+
tone: s => s.isDark ? 30 : 90,
|
|
3268
|
+
isBackground: true,
|
|
3269
|
+
background: s => this.highestSurface(s),
|
|
3270
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3271
|
+
toneDeltaPair: s => new ToneDeltaPair(this.errorContainer(), this.error(), 10, 'nearer', false)
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
onErrorContainer() {
|
|
3275
|
+
return DynamicColor.fromPalette({
|
|
3276
|
+
name: 'on_error_container',
|
|
3277
|
+
palette: s => s.errorPalette,
|
|
3278
|
+
tone: s => {
|
|
3279
|
+
if (isMonochrome(s)) {
|
|
3280
|
+
return s.isDark ? 90 : 10;
|
|
3281
|
+
}
|
|
3282
|
+
return s.isDark ? 90 : 30;
|
|
3283
|
+
},
|
|
3284
|
+
background: s => this.errorContainer(),
|
|
3285
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
3286
|
+
});
|
|
3287
|
+
}
|
|
3288
|
+
//////////////////////////////////////////////////////////////////
|
|
3289
|
+
// Primary Fixed [PF] //
|
|
3290
|
+
//////////////////////////////////////////////////////////////////
|
|
3291
|
+
primaryFixed() {
|
|
3292
|
+
return DynamicColor.fromPalette({
|
|
3293
|
+
name: 'primary_fixed',
|
|
3294
|
+
palette: s => s.primaryPalette,
|
|
3295
|
+
tone: s => isMonochrome(s) ? 40.0 : 90.0,
|
|
3296
|
+
isBackground: true,
|
|
3297
|
+
background: s => this.highestSurface(s),
|
|
3298
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3299
|
+
toneDeltaPair: s => new ToneDeltaPair(this.primaryFixed(), this.primaryFixedDim(), 10, 'lighter', true)
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
primaryFixedDim() {
|
|
3303
|
+
return DynamicColor.fromPalette({
|
|
3304
|
+
name: 'primary_fixed_dim',
|
|
3305
|
+
palette: s => s.primaryPalette,
|
|
3306
|
+
tone: s => isMonochrome(s) ? 30.0 : 80.0,
|
|
3307
|
+
isBackground: true,
|
|
3308
|
+
background: s => this.highestSurface(s),
|
|
3309
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3310
|
+
toneDeltaPair: s => new ToneDeltaPair(this.primaryFixed(), this.primaryFixedDim(), 10, 'lighter', true)
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
onPrimaryFixed() {
|
|
3314
|
+
return DynamicColor.fromPalette({
|
|
3315
|
+
name: 'on_primary_fixed',
|
|
3316
|
+
palette: s => s.primaryPalette,
|
|
3317
|
+
tone: s => isMonochrome(s) ? 100.0 : 10.0,
|
|
3318
|
+
background: s => this.primaryFixedDim(),
|
|
3319
|
+
secondBackground: s => this.primaryFixed(),
|
|
3320
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
3321
|
+
});
|
|
3322
|
+
}
|
|
3323
|
+
onPrimaryFixedVariant() {
|
|
3324
|
+
return DynamicColor.fromPalette({
|
|
3325
|
+
name: 'on_primary_fixed_variant',
|
|
3326
|
+
palette: s => s.primaryPalette,
|
|
3327
|
+
tone: s => isMonochrome(s) ? 90.0 : 30.0,
|
|
3328
|
+
background: s => this.primaryFixedDim(),
|
|
3329
|
+
secondBackground: s => this.primaryFixed(),
|
|
3330
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
3331
|
+
});
|
|
3332
|
+
}
|
|
3333
|
+
///////////////////////////////////////////////////////////////////
|
|
3334
|
+
// Secondary Fixed [QF] //
|
|
3335
|
+
///////////////////////////////////////////////////////////////////
|
|
3336
|
+
secondaryFixed() {
|
|
3337
|
+
return DynamicColor.fromPalette({
|
|
3338
|
+
name: 'secondary_fixed',
|
|
3339
|
+
palette: s => s.secondaryPalette,
|
|
3340
|
+
tone: s => isMonochrome(s) ? 80.0 : 90.0,
|
|
3341
|
+
isBackground: true,
|
|
3342
|
+
background: s => this.highestSurface(s),
|
|
3343
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3344
|
+
toneDeltaPair: s => new ToneDeltaPair(this.secondaryFixed(), this.secondaryFixedDim(), 10, 'lighter', true)
|
|
3345
|
+
});
|
|
3346
|
+
}
|
|
3347
|
+
secondaryFixedDim() {
|
|
3348
|
+
return DynamicColor.fromPalette({
|
|
3349
|
+
name: 'secondary_fixed_dim',
|
|
3350
|
+
palette: s => s.secondaryPalette,
|
|
3351
|
+
tone: s => isMonochrome(s) ? 70.0 : 80.0,
|
|
3352
|
+
isBackground: true,
|
|
3353
|
+
background: s => this.highestSurface(s),
|
|
3354
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3355
|
+
toneDeltaPair: s => new ToneDeltaPair(this.secondaryFixed(), this.secondaryFixedDim(), 10, 'lighter', true)
|
|
3356
|
+
});
|
|
3357
|
+
}
|
|
3358
|
+
onSecondaryFixed() {
|
|
3359
|
+
return DynamicColor.fromPalette({
|
|
3360
|
+
name: 'on_secondary_fixed',
|
|
3361
|
+
palette: s => s.secondaryPalette,
|
|
3362
|
+
tone: s => 10.0,
|
|
3363
|
+
background: s => this.secondaryFixedDim(),
|
|
3364
|
+
secondBackground: s => this.secondaryFixed(),
|
|
3365
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
3366
|
+
});
|
|
3367
|
+
}
|
|
3368
|
+
onSecondaryFixedVariant() {
|
|
3369
|
+
return DynamicColor.fromPalette({
|
|
3370
|
+
name: 'on_secondary_fixed_variant',
|
|
3371
|
+
palette: s => s.secondaryPalette,
|
|
3372
|
+
tone: s => isMonochrome(s) ? 25.0 : 30.0,
|
|
3373
|
+
background: s => this.secondaryFixedDim(),
|
|
3374
|
+
secondBackground: s => this.secondaryFixed(),
|
|
3375
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
3376
|
+
});
|
|
3377
|
+
}
|
|
3378
|
+
/////////////////////////////////////////////////////////////////
|
|
3379
|
+
// Tertiary Fixed [TF] //
|
|
3380
|
+
/////////////////////////////////////////////////////////////////
|
|
3381
|
+
tertiaryFixed() {
|
|
3382
|
+
return DynamicColor.fromPalette({
|
|
3383
|
+
name: 'tertiary_fixed',
|
|
3384
|
+
palette: s => s.tertiaryPalette,
|
|
3385
|
+
tone: s => isMonochrome(s) ? 40.0 : 90.0,
|
|
3386
|
+
isBackground: true,
|
|
3387
|
+
background: s => this.highestSurface(s),
|
|
3388
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3389
|
+
toneDeltaPair: s => new ToneDeltaPair(this.tertiaryFixed(), this.tertiaryFixedDim(), 10, 'lighter', true)
|
|
3390
|
+
});
|
|
3391
|
+
}
|
|
3392
|
+
tertiaryFixedDim() {
|
|
3393
|
+
return DynamicColor.fromPalette({
|
|
3394
|
+
name: 'tertiary_fixed_dim',
|
|
3395
|
+
palette: s => s.tertiaryPalette,
|
|
3396
|
+
tone: s => isMonochrome(s) ? 30.0 : 80.0,
|
|
3397
|
+
isBackground: true,
|
|
3398
|
+
background: s => this.highestSurface(s),
|
|
3399
|
+
contrastCurve: s => new ContrastCurve(1, 1, 3, 4.5),
|
|
3400
|
+
toneDeltaPair: s => new ToneDeltaPair(this.tertiaryFixed(), this.tertiaryFixedDim(), 10, 'lighter', true)
|
|
3401
|
+
});
|
|
3402
|
+
}
|
|
3403
|
+
onTertiaryFixed() {
|
|
3404
|
+
return DynamicColor.fromPalette({
|
|
3405
|
+
name: 'on_tertiary_fixed',
|
|
3406
|
+
palette: s => s.tertiaryPalette,
|
|
3407
|
+
tone: s => isMonochrome(s) ? 100.0 : 10.0,
|
|
3408
|
+
background: s => this.tertiaryFixedDim(),
|
|
3409
|
+
secondBackground: s => this.tertiaryFixed(),
|
|
3410
|
+
contrastCurve: s => new ContrastCurve(4.5, 7, 11, 21)
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
3413
|
+
onTertiaryFixedVariant() {
|
|
3414
|
+
return DynamicColor.fromPalette({
|
|
3415
|
+
name: 'on_tertiary_fixed_variant',
|
|
3416
|
+
palette: s => s.tertiaryPalette,
|
|
3417
|
+
tone: s => isMonochrome(s) ? 90.0 : 30.0,
|
|
3418
|
+
background: s => this.tertiaryFixedDim(),
|
|
3419
|
+
secondBackground: s => this.tertiaryFixed(),
|
|
3420
|
+
contrastCurve: s => new ContrastCurve(3, 4.5, 7, 11)
|
|
3421
|
+
});
|
|
3422
|
+
}
|
|
3423
|
+
////////////////////////////////////////////////////////////////
|
|
3424
|
+
// Other //
|
|
3425
|
+
////////////////////////////////////////////////////////////////
|
|
3426
|
+
highestSurface(s) {
|
|
3427
|
+
return s.isDark ? this.surfaceBright() : this.surfaceDim();
|
|
2164
3428
|
}
|
|
2165
3429
|
}
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
}
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
tone: s => s.isDark ? new ContrastCurve(24, 24, 29, 34).get(s.contrastLevel) : 98,
|
|
2221
|
-
isBackground: true
|
|
2222
|
-
});
|
|
2223
|
-
MaterialDynamicColors.surfaceContainerLowest = DynamicColor.fromPalette({
|
|
2224
|
-
name: 'surface_container_lowest',
|
|
2225
|
-
palette: s => s.neutralPalette,
|
|
2226
|
-
tone: s => s.isDark ? new ContrastCurve(4, 4, 2, 0).get(s.contrastLevel) : 100,
|
|
2227
|
-
isBackground: true
|
|
2228
|
-
});
|
|
2229
|
-
MaterialDynamicColors.surfaceContainerLow = DynamicColor.fromPalette({
|
|
2230
|
-
name: 'surface_container_low',
|
|
2231
|
-
palette: s => s.neutralPalette,
|
|
2232
|
-
tone: s => s.isDark ? new ContrastCurve(10, 10, 11, 12).get(s.contrastLevel) : new ContrastCurve(96, 96, 96, 95).get(s.contrastLevel),
|
|
2233
|
-
isBackground: true
|
|
2234
|
-
});
|
|
2235
|
-
MaterialDynamicColors.surfaceContainer = DynamicColor.fromPalette({
|
|
2236
|
-
name: 'surface_container',
|
|
2237
|
-
palette: s => s.neutralPalette,
|
|
2238
|
-
tone: s => s.isDark ? new ContrastCurve(12, 12, 16, 20).get(s.contrastLevel) : new ContrastCurve(94, 94, 92, 90).get(s.contrastLevel),
|
|
2239
|
-
isBackground: true
|
|
2240
|
-
});
|
|
2241
|
-
MaterialDynamicColors.surfaceContainerHigh = DynamicColor.fromPalette({
|
|
2242
|
-
name: 'surface_container_high',
|
|
2243
|
-
palette: s => s.neutralPalette,
|
|
2244
|
-
tone: s => s.isDark ? new ContrastCurve(17, 17, 21, 25).get(s.contrastLevel) : new ContrastCurve(92, 92, 88, 85).get(s.contrastLevel),
|
|
2245
|
-
isBackground: true
|
|
2246
|
-
});
|
|
2247
|
-
MaterialDynamicColors.surfaceContainerHighest = DynamicColor.fromPalette({
|
|
2248
|
-
name: 'surface_container_highest',
|
|
2249
|
-
palette: s => s.neutralPalette,
|
|
2250
|
-
tone: s => s.isDark ? new ContrastCurve(22, 22, 26, 30).get(s.contrastLevel) : new ContrastCurve(90, 90, 84, 80).get(s.contrastLevel),
|
|
2251
|
-
isBackground: true
|
|
2252
|
-
});
|
|
2253
|
-
MaterialDynamicColors.onSurface = DynamicColor.fromPalette({
|
|
2254
|
-
name: 'on_surface',
|
|
2255
|
-
palette: s => s.neutralPalette,
|
|
2256
|
-
tone: s => s.isDark ? 90 : 10,
|
|
2257
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2258
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
2259
|
-
});
|
|
2260
|
-
MaterialDynamicColors.surfaceVariant = DynamicColor.fromPalette({
|
|
2261
|
-
name: 'surface_variant',
|
|
2262
|
-
palette: s => s.neutralVariantPalette,
|
|
2263
|
-
tone: s => s.isDark ? 30 : 90,
|
|
2264
|
-
isBackground: true
|
|
2265
|
-
});
|
|
2266
|
-
MaterialDynamicColors.onSurfaceVariant = DynamicColor.fromPalette({
|
|
2267
|
-
name: 'on_surface_variant',
|
|
2268
|
-
palette: s => s.neutralVariantPalette,
|
|
2269
|
-
tone: s => s.isDark ? 80 : 30,
|
|
2270
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2271
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
2272
|
-
});
|
|
2273
|
-
MaterialDynamicColors.inverseSurface = DynamicColor.fromPalette({
|
|
2274
|
-
name: 'inverse_surface',
|
|
2275
|
-
palette: s => s.neutralPalette,
|
|
2276
|
-
tone: s => s.isDark ? 90 : 20
|
|
2277
|
-
});
|
|
2278
|
-
MaterialDynamicColors.inverseOnSurface = DynamicColor.fromPalette({
|
|
2279
|
-
name: 'inverse_on_surface',
|
|
2280
|
-
palette: s => s.neutralPalette,
|
|
2281
|
-
tone: s => s.isDark ? 20 : 95,
|
|
2282
|
-
background: s => MaterialDynamicColors.inverseSurface,
|
|
2283
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
2284
|
-
});
|
|
2285
|
-
MaterialDynamicColors.outline = DynamicColor.fromPalette({
|
|
2286
|
-
name: 'outline',
|
|
2287
|
-
palette: s => s.neutralVariantPalette,
|
|
2288
|
-
tone: s => s.isDark ? 60 : 50,
|
|
2289
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2290
|
-
contrastCurve: new ContrastCurve(1.5, 3, 4.5, 7)
|
|
2291
|
-
});
|
|
2292
|
-
MaterialDynamicColors.outlineVariant = DynamicColor.fromPalette({
|
|
2293
|
-
name: 'outline_variant',
|
|
2294
|
-
palette: s => s.neutralVariantPalette,
|
|
2295
|
-
tone: s => s.isDark ? 30 : 80,
|
|
2296
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2297
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 4.5)
|
|
2298
|
-
});
|
|
2299
|
-
MaterialDynamicColors.shadow = DynamicColor.fromPalette({
|
|
2300
|
-
name: 'shadow',
|
|
2301
|
-
palette: s => s.neutralPalette,
|
|
2302
|
-
tone: s => 0
|
|
2303
|
-
});
|
|
2304
|
-
MaterialDynamicColors.scrim = DynamicColor.fromPalette({
|
|
2305
|
-
name: 'scrim',
|
|
2306
|
-
palette: s => s.neutralPalette,
|
|
2307
|
-
tone: s => 0
|
|
2308
|
-
});
|
|
2309
|
-
MaterialDynamicColors.surfaceTint = DynamicColor.fromPalette({
|
|
2310
|
-
name: 'surface_tint',
|
|
2311
|
-
palette: s => s.primaryPalette,
|
|
2312
|
-
tone: s => s.isDark ? 80 : 40,
|
|
2313
|
-
isBackground: true
|
|
2314
|
-
});
|
|
2315
|
-
MaterialDynamicColors.primary = DynamicColor.fromPalette({
|
|
2316
|
-
name: 'primary',
|
|
2317
|
-
palette: s => s.primaryPalette,
|
|
2318
|
-
tone: s => {
|
|
2319
|
-
if (isMonochrome(s)) {
|
|
2320
|
-
return s.isDark ? 100 : 0;
|
|
2321
|
-
}
|
|
2322
|
-
return s.isDark ? 80 : 40;
|
|
2323
|
-
},
|
|
2324
|
-
isBackground: true,
|
|
2325
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2326
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 7),
|
|
2327
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryContainer, MaterialDynamicColors.primary, 10, 'nearer', false)
|
|
2328
|
-
});
|
|
2329
|
-
MaterialDynamicColors.onPrimary = DynamicColor.fromPalette({
|
|
2330
|
-
name: 'on_primary',
|
|
2331
|
-
palette: s => s.primaryPalette,
|
|
2332
|
-
tone: s => {
|
|
2333
|
-
if (isMonochrome(s)) {
|
|
2334
|
-
return s.isDark ? 10 : 90;
|
|
2335
|
-
}
|
|
2336
|
-
return s.isDark ? 20 : 100;
|
|
2337
|
-
},
|
|
2338
|
-
background: s => MaterialDynamicColors.primary,
|
|
2339
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
2340
|
-
});
|
|
2341
|
-
MaterialDynamicColors.primaryContainer = DynamicColor.fromPalette({
|
|
2342
|
-
name: 'primary_container',
|
|
2343
|
-
palette: s => s.primaryPalette,
|
|
2344
|
-
tone: s => {
|
|
2345
|
-
if (isFidelity(s)) {
|
|
2346
|
-
return s.sourceColorHct.tone;
|
|
2347
|
-
}
|
|
2348
|
-
if (isMonochrome(s)) {
|
|
2349
|
-
return s.isDark ? 85 : 25;
|
|
2350
|
-
}
|
|
2351
|
-
return s.isDark ? 30 : 90;
|
|
2352
|
-
},
|
|
2353
|
-
isBackground: true,
|
|
2354
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2355
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 4.5),
|
|
2356
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.primaryContainer, MaterialDynamicColors.primary, 10, 'nearer', false)
|
|
2357
|
-
});
|
|
2358
|
-
MaterialDynamicColors.onPrimaryContainer = DynamicColor.fromPalette({
|
|
2359
|
-
name: 'on_primary_container',
|
|
2360
|
-
palette: s => s.primaryPalette,
|
|
2361
|
-
tone: s => {
|
|
2362
|
-
if (isFidelity(s)) {
|
|
2363
|
-
return DynamicColor.foregroundTone(MaterialDynamicColors.primaryContainer.tone(s), 4.5);
|
|
2364
|
-
}
|
|
2365
|
-
if (isMonochrome(s)) {
|
|
2366
|
-
return s.isDark ? 0 : 100;
|
|
2367
|
-
}
|
|
2368
|
-
return s.isDark ? 90 : 30;
|
|
2369
|
-
},
|
|
2370
|
-
background: s => MaterialDynamicColors.primaryContainer,
|
|
2371
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
2372
|
-
});
|
|
2373
|
-
MaterialDynamicColors.inversePrimary = DynamicColor.fromPalette({
|
|
2374
|
-
name: 'inverse_primary',
|
|
2375
|
-
palette: s => s.primaryPalette,
|
|
2376
|
-
tone: s => s.isDark ? 40 : 80,
|
|
2377
|
-
background: s => MaterialDynamicColors.inverseSurface,
|
|
2378
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 7)
|
|
2379
|
-
});
|
|
2380
|
-
MaterialDynamicColors.secondary = DynamicColor.fromPalette({
|
|
2381
|
-
name: 'secondary',
|
|
2382
|
-
palette: s => s.secondaryPalette,
|
|
2383
|
-
tone: s => s.isDark ? 80 : 40,
|
|
2384
|
-
isBackground: true,
|
|
2385
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2386
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 7),
|
|
2387
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryContainer, MaterialDynamicColors.secondary, 10, 'nearer', false)
|
|
2388
|
-
});
|
|
2389
|
-
MaterialDynamicColors.onSecondary = DynamicColor.fromPalette({
|
|
2390
|
-
name: 'on_secondary',
|
|
2391
|
-
palette: s => s.secondaryPalette,
|
|
2392
|
-
tone: s => {
|
|
2393
|
-
if (isMonochrome(s)) {
|
|
2394
|
-
return s.isDark ? 10 : 100;
|
|
2395
|
-
} else {
|
|
2396
|
-
return s.isDark ? 20 : 100;
|
|
2397
|
-
}
|
|
2398
|
-
},
|
|
2399
|
-
background: s => MaterialDynamicColors.secondary,
|
|
2400
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
2401
|
-
});
|
|
2402
|
-
MaterialDynamicColors.secondaryContainer = DynamicColor.fromPalette({
|
|
2403
|
-
name: 'secondary_container',
|
|
2404
|
-
palette: s => s.secondaryPalette,
|
|
2405
|
-
tone: s => {
|
|
2406
|
-
const initialTone = s.isDark ? 30 : 90;
|
|
2407
|
-
if (isMonochrome(s)) {
|
|
2408
|
-
return s.isDark ? 30 : 85;
|
|
2409
|
-
}
|
|
2410
|
-
if (!isFidelity(s)) {
|
|
2411
|
-
return initialTone;
|
|
2412
|
-
}
|
|
2413
|
-
return findDesiredChromaByTone(s.secondaryPalette.hue, s.secondaryPalette.chroma, initialTone, s.isDark ? false : true);
|
|
2414
|
-
},
|
|
2415
|
-
isBackground: true,
|
|
2416
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2417
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 4.5),
|
|
2418
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.secondaryContainer, MaterialDynamicColors.secondary, 10, 'nearer', false)
|
|
2419
|
-
});
|
|
2420
|
-
MaterialDynamicColors.onSecondaryContainer = DynamicColor.fromPalette({
|
|
2421
|
-
name: 'on_secondary_container',
|
|
2422
|
-
palette: s => s.secondaryPalette,
|
|
2423
|
-
tone: s => {
|
|
2424
|
-
if (isMonochrome(s)) {
|
|
2425
|
-
return s.isDark ? 90 : 10;
|
|
2426
|
-
}
|
|
2427
|
-
if (!isFidelity(s)) {
|
|
2428
|
-
return s.isDark ? 90 : 30;
|
|
2429
|
-
}
|
|
2430
|
-
return DynamicColor.foregroundTone(MaterialDynamicColors.secondaryContainer.tone(s), 4.5);
|
|
2431
|
-
},
|
|
2432
|
-
background: s => MaterialDynamicColors.secondaryContainer,
|
|
2433
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 11)
|
|
2434
|
-
});
|
|
2435
|
-
MaterialDynamicColors.tertiary = DynamicColor.fromPalette({
|
|
2436
|
-
name: 'tertiary',
|
|
2437
|
-
palette: s => s.tertiaryPalette,
|
|
2438
|
-
tone: s => {
|
|
2439
|
-
if (isMonochrome(s)) {
|
|
2440
|
-
return s.isDark ? 90 : 25;
|
|
2441
|
-
}
|
|
2442
|
-
return s.isDark ? 80 : 40;
|
|
2443
|
-
},
|
|
2444
|
-
isBackground: true,
|
|
2445
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2446
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 7),
|
|
2447
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryContainer, MaterialDynamicColors.tertiary, 10, 'nearer', false)
|
|
2448
|
-
});
|
|
2449
|
-
MaterialDynamicColors.onTertiary = DynamicColor.fromPalette({
|
|
2450
|
-
name: 'on_tertiary',
|
|
2451
|
-
palette: s => s.tertiaryPalette,
|
|
2452
|
-
tone: s => {
|
|
2453
|
-
if (isMonochrome(s)) {
|
|
2454
|
-
return s.isDark ? 10 : 90;
|
|
2455
|
-
}
|
|
2456
|
-
return s.isDark ? 20 : 100;
|
|
2457
|
-
},
|
|
2458
|
-
background: s => MaterialDynamicColors.tertiary,
|
|
2459
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
2460
|
-
});
|
|
2461
|
-
MaterialDynamicColors.tertiaryContainer = DynamicColor.fromPalette({
|
|
2462
|
-
name: 'tertiary_container',
|
|
2463
|
-
palette: s => s.tertiaryPalette,
|
|
2464
|
-
tone: s => {
|
|
2465
|
-
if (isMonochrome(s)) {
|
|
2466
|
-
return s.isDark ? 60 : 49;
|
|
2467
|
-
}
|
|
2468
|
-
if (!isFidelity(s)) {
|
|
2469
|
-
return s.isDark ? 30 : 90;
|
|
2470
|
-
}
|
|
2471
|
-
const proposedHct = s.tertiaryPalette.getHct(s.sourceColorHct.tone);
|
|
2472
|
-
return DislikeAnalyzer.fixIfDisliked(proposedHct).tone;
|
|
2473
|
-
},
|
|
2474
|
-
isBackground: true,
|
|
2475
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2476
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 4.5),
|
|
2477
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.tertiaryContainer, MaterialDynamicColors.tertiary, 10, 'nearer', false)
|
|
2478
|
-
});
|
|
2479
|
-
MaterialDynamicColors.onTertiaryContainer = DynamicColor.fromPalette({
|
|
2480
|
-
name: 'on_tertiary_container',
|
|
2481
|
-
palette: s => s.tertiaryPalette,
|
|
2482
|
-
tone: s => {
|
|
2483
|
-
if (isMonochrome(s)) {
|
|
2484
|
-
return s.isDark ? 0 : 100;
|
|
2485
|
-
}
|
|
2486
|
-
if (!isFidelity(s)) {
|
|
2487
|
-
return s.isDark ? 90 : 30;
|
|
3430
|
+
|
|
3431
|
+
/**
|
|
3432
|
+
* @license
|
|
3433
|
+
* Copyright 2025 Google LLC
|
|
3434
|
+
*
|
|
3435
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3436
|
+
* you may not use this file except in compliance with the License.
|
|
3437
|
+
* You may obtain a copy of the License at
|
|
3438
|
+
*
|
|
3439
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3440
|
+
*
|
|
3441
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3442
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3443
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3444
|
+
* See the License for the specific language governing permissions and
|
|
3445
|
+
* limitations under the License.
|
|
3446
|
+
*/
|
|
3447
|
+
/**
|
|
3448
|
+
* Returns the maximum tone for a given chroma in the palette.
|
|
3449
|
+
*
|
|
3450
|
+
* @param palette The tonal palette to use.
|
|
3451
|
+
* @param lowerBound The lower bound of the tone.
|
|
3452
|
+
* @param upperBound The upper bound of the tone.
|
|
3453
|
+
*/
|
|
3454
|
+
function tMaxC(palette, lowerBound = 0, upperBound = 100, chromaMultiplier = 1) {
|
|
3455
|
+
let answer = findBestToneForChroma(palette.hue, palette.chroma * chromaMultiplier, 100, true);
|
|
3456
|
+
return clampDouble(lowerBound, upperBound, answer);
|
|
3457
|
+
}
|
|
3458
|
+
/**
|
|
3459
|
+
* Returns the minimum tone for a given chroma in the palette.
|
|
3460
|
+
*
|
|
3461
|
+
* @param palette The tonal palette to use.
|
|
3462
|
+
* @param lowerBound The lower bound of the tone.
|
|
3463
|
+
* @param upperBound The upper bound of the tone.
|
|
3464
|
+
*/
|
|
3465
|
+
function tMinC(palette, lowerBound = 0, upperBound = 100) {
|
|
3466
|
+
let answer = findBestToneForChroma(palette.hue, palette.chroma, 0, false);
|
|
3467
|
+
return clampDouble(lowerBound, upperBound, answer);
|
|
3468
|
+
}
|
|
3469
|
+
/**
|
|
3470
|
+
* Searches for the best tone with a given chroma from a given tone at a
|
|
3471
|
+
* specific hue.
|
|
3472
|
+
*
|
|
3473
|
+
* @param hue The given hue.
|
|
3474
|
+
* @param chroma The target chroma.
|
|
3475
|
+
* @param tone The tone to start with.
|
|
3476
|
+
* @param byDecreasingTone Whether to search for lower tones.
|
|
3477
|
+
*/
|
|
3478
|
+
function findBestToneForChroma(hue, chroma, tone, byDecreasingTone) {
|
|
3479
|
+
let answer = tone;
|
|
3480
|
+
let bestCandidate = Hct.from(hue, chroma, answer);
|
|
3481
|
+
while (bestCandidate.chroma < chroma) {
|
|
3482
|
+
if (tone < 0 || tone > 100) {
|
|
3483
|
+
break;
|
|
2488
3484
|
}
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
MaterialDynamicColors.error = DynamicColor.fromPalette({
|
|
2495
|
-
name: 'error',
|
|
2496
|
-
palette: s => s.errorPalette,
|
|
2497
|
-
tone: s => s.isDark ? 80 : 40,
|
|
2498
|
-
isBackground: true,
|
|
2499
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2500
|
-
contrastCurve: new ContrastCurve(3, 4.5, 7, 7),
|
|
2501
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.errorContainer, MaterialDynamicColors.error, 10, 'nearer', false)
|
|
2502
|
-
});
|
|
2503
|
-
MaterialDynamicColors.onError = DynamicColor.fromPalette({
|
|
2504
|
-
name: 'on_error',
|
|
2505
|
-
palette: s => s.errorPalette,
|
|
2506
|
-
tone: s => s.isDark ? 20 : 100,
|
|
2507
|
-
background: s => MaterialDynamicColors.error,
|
|
2508
|
-
contrastCurve: new ContrastCurve(4.5, 7, 11, 21)
|
|
2509
|
-
});
|
|
2510
|
-
MaterialDynamicColors.errorContainer = DynamicColor.fromPalette({
|
|
2511
|
-
name: 'error_container',
|
|
2512
|
-
palette: s => s.errorPalette,
|
|
2513
|
-
tone: s => s.isDark ? 30 : 90,
|
|
2514
|
-
isBackground: true,
|
|
2515
|
-
background: s => MaterialDynamicColors.highestSurface(s),
|
|
2516
|
-
contrastCurve: new ContrastCurve(1, 1, 3, 4.5),
|
|
2517
|
-
toneDeltaPair: s => new ToneDeltaPair(MaterialDynamicColors.errorContainer, MaterialDynamicColors.error, 10, 'nearer', false)
|
|
2518
|
-
});
|
|
2519
|
-
MaterialDynamicColors.onErrorContainer = DynamicColor.fromPalette({
|
|
2520
|
-
name: 'on_error_container',
|
|
2521
|
-
palette: s => s.errorPalette,
|
|
2522
|
-
tone: s => {
|
|
2523
|
-
if (isMonochrome(s)) {
|
|
2524
|
-
return s.isDark ? 90 : 10;
|
|
3485
|
+
tone += byDecreasingTone ? -1 : 1.0;
|
|
3486
|
+
const newCandidate = Hct.from(hue, chroma, tone);
|
|
3487
|
+
if (bestCandidate.chroma < newCandidate.chroma) {
|
|
3488
|
+
bestCandidate = newCandidate;
|
|
3489
|
+
answer = tone;
|
|
2525
3490
|
}
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
})
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
3491
|
+
}
|
|
3492
|
+
return answer;
|
|
3493
|
+
}
|
|
3494
|
+
/**
|
|
3495
|
+
* Returns the contrast curve for a given default contrast.
|
|
3496
|
+
*
|
|
3497
|
+
* @param defaultContrast The default contrast to use.
|
|
3498
|
+
*/
|
|
3499
|
+
function getCurve(defaultContrast) {
|
|
3500
|
+
if (defaultContrast === 1.5) {
|
|
3501
|
+
return new ContrastCurve(1.5, 1.5, 3, 5.5);
|
|
3502
|
+
} else if (defaultContrast === 3) {
|
|
3503
|
+
return new ContrastCurve(3, 3, 4.5, 7);
|
|
3504
|
+
} else if (defaultContrast === 4.5) {
|
|
3505
|
+
return new ContrastCurve(4.5, 4.5, 7, 11);
|
|
3506
|
+
} else if (defaultContrast === 6) {
|
|
3507
|
+
return new ContrastCurve(6, 6, 7, 11);
|
|
3508
|
+
} else if (defaultContrast === 7) {
|
|
3509
|
+
return new ContrastCurve(7, 7, 11, 21);
|
|
3510
|
+
} else if (defaultContrast === 9) {
|
|
3511
|
+
return new ContrastCurve(9, 9, 11, 21);
|
|
3512
|
+
} else if (defaultContrast === 11) {
|
|
3513
|
+
return new ContrastCurve(11, 11, 21, 21);
|
|
3514
|
+
} else if (defaultContrast === 21) {
|
|
3515
|
+
return new ContrastCurve(21, 21, 21, 21);
|
|
3516
|
+
} else {
|
|
3517
|
+
// Shouldn't happen.
|
|
3518
|
+
return new ContrastCurve(defaultContrast, defaultContrast, 7, 21);
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
/**
|
|
3522
|
+
* A delegate for the dynamic color spec of a DynamicScheme in the 2025 spec.
|
|
3523
|
+
*/
|
|
3524
|
+
class ColorSpecDelegateImpl2025 extends ColorSpecDelegateImpl2021 {
|
|
3525
|
+
////////////////////////////////////////////////////////////////
|
|
3526
|
+
// Surfaces [S] //
|
|
3527
|
+
////////////////////////////////////////////////////////////////
|
|
3528
|
+
surface() {
|
|
3529
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3530
|
+
name: 'surface',
|
|
3531
|
+
palette: s => s.neutralPalette,
|
|
3532
|
+
tone: s => {
|
|
3533
|
+
super.surface().tone(s);
|
|
3534
|
+
if (s.platform === 'phone') {
|
|
3535
|
+
if (s.isDark) {
|
|
3536
|
+
return 4;
|
|
3537
|
+
} else {
|
|
3538
|
+
if (Hct.isYellow(s.neutralPalette.hue)) {
|
|
3539
|
+
return 99;
|
|
3540
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3541
|
+
return 97;
|
|
3542
|
+
} else {
|
|
3543
|
+
return 98;
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
} else {
|
|
3547
|
+
return 0;
|
|
3548
|
+
}
|
|
3549
|
+
},
|
|
3550
|
+
isBackground: true
|
|
3551
|
+
});
|
|
3552
|
+
return extendSpecVersion(super.surface(), '2025', color2025);
|
|
3553
|
+
}
|
|
3554
|
+
surfaceDim() {
|
|
3555
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3556
|
+
name: 'surface_dim',
|
|
3557
|
+
palette: s => s.neutralPalette,
|
|
3558
|
+
tone: s => {
|
|
3559
|
+
if (s.isDark) {
|
|
3560
|
+
return 4;
|
|
3561
|
+
} else {
|
|
3562
|
+
if (Hct.isYellow(s.neutralPalette.hue)) {
|
|
3563
|
+
return 90;
|
|
3564
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3565
|
+
return 85;
|
|
3566
|
+
} else {
|
|
3567
|
+
return 87;
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
|
+
},
|
|
3571
|
+
isBackground: true,
|
|
3572
|
+
chromaMultiplier: s => {
|
|
3573
|
+
if (!s.isDark) {
|
|
3574
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3575
|
+
return 2.5;
|
|
3576
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3577
|
+
return 1.7;
|
|
3578
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3579
|
+
return Hct.isYellow(s.neutralPalette.hue) ? 2.7 : 1.75;
|
|
3580
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3581
|
+
return 1.36;
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
return 1;
|
|
3585
|
+
}
|
|
3586
|
+
});
|
|
3587
|
+
return extendSpecVersion(super.surfaceDim(), '2025', color2025);
|
|
3588
|
+
}
|
|
3589
|
+
surfaceBright() {
|
|
3590
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3591
|
+
name: 'surface_bright',
|
|
3592
|
+
palette: s => s.neutralPalette,
|
|
3593
|
+
tone: s => {
|
|
3594
|
+
if (s.isDark) {
|
|
3595
|
+
return 18;
|
|
3596
|
+
} else {
|
|
3597
|
+
if (Hct.isYellow(s.neutralPalette.hue)) {
|
|
3598
|
+
return 99;
|
|
3599
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3600
|
+
return 97;
|
|
3601
|
+
} else {
|
|
3602
|
+
return 98;
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
},
|
|
3606
|
+
isBackground: true,
|
|
3607
|
+
chromaMultiplier: s => {
|
|
3608
|
+
if (s.isDark) {
|
|
3609
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3610
|
+
return 2.5;
|
|
3611
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3612
|
+
return 1.7;
|
|
3613
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3614
|
+
return Hct.isYellow(s.neutralPalette.hue) ? 2.7 : 1.75;
|
|
3615
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3616
|
+
return 1.36;
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
return 1;
|
|
3620
|
+
}
|
|
3621
|
+
});
|
|
3622
|
+
return extendSpecVersion(super.surfaceBright(), '2025', color2025);
|
|
3623
|
+
}
|
|
3624
|
+
surfaceContainerLowest() {
|
|
3625
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3626
|
+
name: 'surface_container_lowest',
|
|
3627
|
+
palette: s => s.neutralPalette,
|
|
3628
|
+
tone: s => s.isDark ? 0 : 100,
|
|
3629
|
+
isBackground: true
|
|
3630
|
+
});
|
|
3631
|
+
return extendSpecVersion(super.surfaceContainerLowest(), '2025', color2025);
|
|
3632
|
+
}
|
|
3633
|
+
surfaceContainerLow() {
|
|
3634
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3635
|
+
name: 'surface_container_low',
|
|
3636
|
+
palette: s => s.neutralPalette,
|
|
3637
|
+
tone: s => {
|
|
3638
|
+
if (s.platform === 'phone') {
|
|
3639
|
+
if (s.isDark) {
|
|
3640
|
+
return 6;
|
|
3641
|
+
} else {
|
|
3642
|
+
if (Hct.isYellow(s.neutralPalette.hue)) {
|
|
3643
|
+
return 98;
|
|
3644
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3645
|
+
return 95;
|
|
3646
|
+
} else {
|
|
3647
|
+
return 96;
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
} else {
|
|
3651
|
+
return 15;
|
|
3652
|
+
}
|
|
3653
|
+
},
|
|
3654
|
+
isBackground: true,
|
|
3655
|
+
chromaMultiplier: s => {
|
|
3656
|
+
if (s.platform === 'phone') {
|
|
3657
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3658
|
+
return 1.3;
|
|
3659
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3660
|
+
return 1.25;
|
|
3661
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3662
|
+
return Hct.isYellow(s.neutralPalette.hue) ? 1.3 : 1.15;
|
|
3663
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3664
|
+
return 1.08;
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
return 1;
|
|
3668
|
+
}
|
|
3669
|
+
});
|
|
3670
|
+
return extendSpecVersion(super.surfaceContainerLow(), '2025', color2025);
|
|
3671
|
+
}
|
|
3672
|
+
surfaceContainer() {
|
|
3673
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3674
|
+
name: 'surface_container',
|
|
3675
|
+
palette: s => s.neutralPalette,
|
|
3676
|
+
tone: s => {
|
|
3677
|
+
if (s.platform === 'phone') {
|
|
3678
|
+
if (s.isDark) {
|
|
3679
|
+
return 9;
|
|
3680
|
+
} else {
|
|
3681
|
+
if (Hct.isYellow(s.neutralPalette.hue)) {
|
|
3682
|
+
return 96;
|
|
3683
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3684
|
+
return 92;
|
|
3685
|
+
} else {
|
|
3686
|
+
return 94;
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
} else {
|
|
3690
|
+
return 20;
|
|
3691
|
+
}
|
|
3692
|
+
},
|
|
3693
|
+
isBackground: true,
|
|
3694
|
+
chromaMultiplier: s => {
|
|
3695
|
+
if (s.platform === 'phone') {
|
|
3696
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3697
|
+
return 1.6;
|
|
3698
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3699
|
+
return 1.4;
|
|
3700
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3701
|
+
return Hct.isYellow(s.neutralPalette.hue) ? 1.6 : 1.3;
|
|
3702
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3703
|
+
return 1.15;
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
return 1;
|
|
3707
|
+
}
|
|
3708
|
+
});
|
|
3709
|
+
return extendSpecVersion(super.surfaceContainer(), '2025', color2025);
|
|
3710
|
+
}
|
|
3711
|
+
surfaceContainerHigh() {
|
|
3712
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3713
|
+
name: 'surface_container_high',
|
|
3714
|
+
palette: s => s.neutralPalette,
|
|
3715
|
+
tone: s => {
|
|
3716
|
+
if (s.platform === 'phone') {
|
|
3717
|
+
if (s.isDark) {
|
|
3718
|
+
return 12;
|
|
3719
|
+
} else {
|
|
3720
|
+
if (Hct.isYellow(s.neutralPalette.hue)) {
|
|
3721
|
+
return 94;
|
|
3722
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3723
|
+
return 90;
|
|
3724
|
+
} else {
|
|
3725
|
+
return 92;
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
} else {
|
|
3729
|
+
return 25;
|
|
3730
|
+
}
|
|
3731
|
+
},
|
|
3732
|
+
isBackground: true,
|
|
3733
|
+
chromaMultiplier: s => {
|
|
3734
|
+
if (s.platform === 'phone') {
|
|
3735
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3736
|
+
return 1.9;
|
|
3737
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3738
|
+
return 1.5;
|
|
3739
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3740
|
+
return Hct.isYellow(s.neutralPalette.hue) ? 1.95 : 1.45;
|
|
3741
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3742
|
+
return 1.22;
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
return 1;
|
|
3746
|
+
}
|
|
3747
|
+
});
|
|
3748
|
+
return extendSpecVersion(super.surfaceContainerHigh(), '2025', color2025);
|
|
3749
|
+
}
|
|
3750
|
+
surfaceContainerHighest() {
|
|
3751
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3752
|
+
name: 'surface_container_highest',
|
|
3753
|
+
palette: s => s.neutralPalette,
|
|
3754
|
+
tone: s => {
|
|
3755
|
+
if (s.isDark) {
|
|
3756
|
+
return 15;
|
|
3757
|
+
} else {
|
|
3758
|
+
if (Hct.isYellow(s.neutralPalette.hue)) {
|
|
3759
|
+
return 92;
|
|
3760
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3761
|
+
return 88;
|
|
3762
|
+
} else {
|
|
3763
|
+
return 90;
|
|
3764
|
+
}
|
|
3765
|
+
}
|
|
3766
|
+
},
|
|
3767
|
+
isBackground: true,
|
|
3768
|
+
chromaMultiplier: s => {
|
|
3769
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3770
|
+
return 2.2;
|
|
3771
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3772
|
+
return 1.7;
|
|
3773
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3774
|
+
return Hct.isYellow(s.neutralPalette.hue) ? 2.3 : 1.6;
|
|
3775
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
3776
|
+
return 1.29;
|
|
3777
|
+
} else {
|
|
3778
|
+
// default
|
|
3779
|
+
return 1;
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
});
|
|
3783
|
+
return extendSpecVersion(super.surfaceContainerHighest(), '2025', color2025);
|
|
3784
|
+
}
|
|
3785
|
+
onSurface() {
|
|
3786
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3787
|
+
name: 'on_surface',
|
|
3788
|
+
palette: s => s.neutralPalette,
|
|
3789
|
+
tone: s => {
|
|
3790
|
+
if (s.variant === Variant.VIBRANT) {
|
|
3791
|
+
return tMaxC(s.neutralPalette, 0, 100, 1.1);
|
|
3792
|
+
} else {
|
|
3793
|
+
// For all other variants, the initial tone should be the default
|
|
3794
|
+
// tone, which is the same as the background color.
|
|
3795
|
+
return DynamicColor.getInitialToneFromBackground(s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh())(s);
|
|
3796
|
+
}
|
|
3797
|
+
},
|
|
3798
|
+
chromaMultiplier: s => {
|
|
3799
|
+
if (s.platform === 'phone') {
|
|
3800
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3801
|
+
return 2.2;
|
|
3802
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3803
|
+
return 1.7;
|
|
3804
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3805
|
+
return Hct.isYellow(s.neutralPalette.hue) ? s.isDark ? 3.0 : 2.3 : 1.6;
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
return 1;
|
|
3809
|
+
},
|
|
3810
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
3811
|
+
contrastCurve: s => s.isDark && s.platform === 'phone' ? getCurve(11) : getCurve(9)
|
|
3812
|
+
});
|
|
3813
|
+
return extendSpecVersion(super.onSurface(), '2025', color2025);
|
|
3814
|
+
}
|
|
3815
|
+
onSurfaceVariant() {
|
|
3816
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3817
|
+
name: 'on_surface_variant',
|
|
3818
|
+
palette: s => s.neutralPalette,
|
|
3819
|
+
chromaMultiplier: s => {
|
|
3820
|
+
if (s.platform === 'phone') {
|
|
3821
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3822
|
+
return 2.2;
|
|
3823
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3824
|
+
return 1.7;
|
|
3825
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3826
|
+
return Hct.isYellow(s.neutralPalette.hue) ? s.isDark ? 3.0 : 2.3 : 1.6;
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
return 1;
|
|
3830
|
+
},
|
|
3831
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
3832
|
+
contrastCurve: s => s.platform === 'phone' ? s.isDark ? getCurve(6) : getCurve(4.5) : getCurve(7)
|
|
3833
|
+
});
|
|
3834
|
+
return extendSpecVersion(super.onSurfaceVariant(), '2025', color2025);
|
|
3835
|
+
}
|
|
3836
|
+
outline() {
|
|
3837
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3838
|
+
name: 'outline',
|
|
3839
|
+
palette: s => s.neutralPalette,
|
|
3840
|
+
chromaMultiplier: s => {
|
|
3841
|
+
if (s.platform === 'phone') {
|
|
3842
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3843
|
+
return 2.2;
|
|
3844
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3845
|
+
return 1.7;
|
|
3846
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3847
|
+
return Hct.isYellow(s.neutralPalette.hue) ? s.isDark ? 3.0 : 2.3 : 1.6;
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
return 1;
|
|
3851
|
+
},
|
|
3852
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
3853
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(3) : getCurve(4.5)
|
|
3854
|
+
});
|
|
3855
|
+
return extendSpecVersion(super.outline(), '2025', color2025);
|
|
3856
|
+
}
|
|
3857
|
+
outlineVariant() {
|
|
3858
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3859
|
+
name: 'outline_variant',
|
|
3860
|
+
palette: s => s.neutralPalette,
|
|
3861
|
+
chromaMultiplier: s => {
|
|
3862
|
+
if (s.platform === 'phone') {
|
|
3863
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3864
|
+
return 2.2;
|
|
3865
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3866
|
+
return 1.7;
|
|
3867
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3868
|
+
return Hct.isYellow(s.neutralPalette.hue) ? s.isDark ? 3.0 : 2.3 : 1.6;
|
|
3869
|
+
}
|
|
3870
|
+
}
|
|
3871
|
+
return 1;
|
|
3872
|
+
},
|
|
3873
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
3874
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(1.5) : getCurve(3)
|
|
3875
|
+
});
|
|
3876
|
+
return extendSpecVersion(super.outlineVariant(), '2025', color2025);
|
|
3877
|
+
}
|
|
3878
|
+
inverseSurface() {
|
|
3879
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3880
|
+
name: 'inverse_surface',
|
|
3881
|
+
palette: s => s.neutralPalette,
|
|
3882
|
+
tone: s => s.isDark ? 98 : 4,
|
|
3883
|
+
isBackground: true
|
|
3884
|
+
});
|
|
3885
|
+
return extendSpecVersion(super.inverseSurface(), '2025', color2025);
|
|
3886
|
+
}
|
|
3887
|
+
inverseOnSurface() {
|
|
3888
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3889
|
+
name: 'inverse_on_surface',
|
|
3890
|
+
palette: s => s.neutralPalette,
|
|
3891
|
+
background: s => this.inverseSurface(),
|
|
3892
|
+
contrastCurve: s => getCurve(7)
|
|
3893
|
+
});
|
|
3894
|
+
return extendSpecVersion(super.inverseOnSurface(), '2025', color2025);
|
|
3895
|
+
}
|
|
3896
|
+
////////////////////////////////////////////////////////////////
|
|
3897
|
+
// Primaries [P] //
|
|
3898
|
+
////////////////////////////////////////////////////////////////
|
|
3899
|
+
primary() {
|
|
3900
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3901
|
+
name: 'primary',
|
|
3902
|
+
palette: s => s.primaryPalette,
|
|
3903
|
+
tone: s => {
|
|
3904
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3905
|
+
if (s.platform === 'phone') {
|
|
3906
|
+
return s.isDark ? 80 : 40;
|
|
3907
|
+
} else {
|
|
3908
|
+
return 90;
|
|
3909
|
+
}
|
|
3910
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3911
|
+
if (s.platform === 'phone') {
|
|
3912
|
+
if (s.isDark) {
|
|
3913
|
+
return 80;
|
|
3914
|
+
} else {
|
|
3915
|
+
return tMaxC(s.primaryPalette);
|
|
3916
|
+
}
|
|
3917
|
+
} else {
|
|
3918
|
+
return tMaxC(s.primaryPalette, 0, 90);
|
|
3919
|
+
}
|
|
3920
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3921
|
+
if (s.platform === 'phone') {
|
|
3922
|
+
return tMaxC(s.primaryPalette, 0, Hct.isYellow(s.primaryPalette.hue) ? 25 : Hct.isCyan(s.primaryPalette.hue) ? 88 : 98);
|
|
3923
|
+
} else {
|
|
3924
|
+
// WATCH
|
|
3925
|
+
return tMaxC(s.primaryPalette);
|
|
3926
|
+
}
|
|
3927
|
+
} else {
|
|
3928
|
+
// VIBRANT
|
|
3929
|
+
if (s.platform === 'phone') {
|
|
3930
|
+
return tMaxC(s.primaryPalette, 0, Hct.isCyan(s.primaryPalette.hue) ? 88 : 98);
|
|
3931
|
+
} else {
|
|
3932
|
+
// WATCH
|
|
3933
|
+
return tMaxC(s.primaryPalette);
|
|
3934
|
+
}
|
|
3935
|
+
}
|
|
3936
|
+
},
|
|
3937
|
+
isBackground: true,
|
|
3938
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
3939
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(4.5) : getCurve(7),
|
|
3940
|
+
toneDeltaPair: s => s.platform === 'phone' ? new ToneDeltaPair(this.primaryContainer(), this.primary(), 5, 'relative_lighter', true, 'farther') : undefined
|
|
3941
|
+
});
|
|
3942
|
+
return extendSpecVersion(super.primary(), '2025', color2025);
|
|
3943
|
+
}
|
|
3944
|
+
primaryDim() {
|
|
3945
|
+
return DynamicColor.fromPalette({
|
|
3946
|
+
name: 'primary_dim',
|
|
3947
|
+
palette: s => s.primaryPalette,
|
|
3948
|
+
tone: s => {
|
|
3949
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
3950
|
+
return 85;
|
|
3951
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3952
|
+
return tMaxC(s.primaryPalette, 0, 90);
|
|
3953
|
+
} else {
|
|
3954
|
+
return tMaxC(s.primaryPalette);
|
|
3955
|
+
}
|
|
3956
|
+
},
|
|
3957
|
+
isBackground: true,
|
|
3958
|
+
background: s => this.surfaceContainerHigh(),
|
|
3959
|
+
contrastCurve: s => getCurve(4.5),
|
|
3960
|
+
toneDeltaPair: s => new ToneDeltaPair(this.primaryDim(), this.primary(), 5, 'darker', true, 'farther')
|
|
3961
|
+
});
|
|
3962
|
+
}
|
|
3963
|
+
onPrimary() {
|
|
3964
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3965
|
+
name: 'on_primary',
|
|
3966
|
+
palette: s => s.primaryPalette,
|
|
3967
|
+
background: s => s.platform === 'phone' ? this.primary() : this.primaryDim(),
|
|
3968
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
3969
|
+
});
|
|
3970
|
+
return extendSpecVersion(super.onPrimary(), '2025', color2025);
|
|
3971
|
+
}
|
|
3972
|
+
primaryContainer() {
|
|
3973
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3974
|
+
name: 'primary_container',
|
|
3975
|
+
palette: s => s.primaryPalette,
|
|
3976
|
+
tone: s => {
|
|
3977
|
+
if (s.platform === 'watch') {
|
|
3978
|
+
return 30;
|
|
3979
|
+
} else if (s.variant === Variant.NEUTRAL) {
|
|
3980
|
+
return s.isDark ? 30 : 90;
|
|
3981
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
3982
|
+
return s.isDark ? tMinC(s.primaryPalette, 35, 93) : tMaxC(s.primaryPalette, 0, 90);
|
|
3983
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
3984
|
+
return s.isDark ? tMaxC(s.primaryPalette, 30, 93) : tMaxC(s.primaryPalette, 78, Hct.isCyan(s.primaryPalette.hue) ? 88 : 90);
|
|
3985
|
+
} else {
|
|
3986
|
+
// VIBRANT
|
|
3987
|
+
return s.isDark ? tMinC(s.primaryPalette, 66, 93) : tMaxC(s.primaryPalette, 66, Hct.isCyan(s.primaryPalette.hue) ? 88 : 93);
|
|
3988
|
+
}
|
|
3989
|
+
},
|
|
3990
|
+
isBackground: true,
|
|
3991
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : undefined,
|
|
3992
|
+
toneDeltaPair: s => s.platform === 'phone' ? undefined : new ToneDeltaPair(this.primaryContainer(), this.primaryDim(), 10, 'darker', true, 'farther'),
|
|
3993
|
+
contrastCurve: s => s.platform === 'phone' && s.contrastLevel > 0 ? getCurve(1.5) : undefined
|
|
3994
|
+
});
|
|
3995
|
+
return extendSpecVersion(super.primaryContainer(), '2025', color2025);
|
|
3996
|
+
}
|
|
3997
|
+
onPrimaryContainer() {
|
|
3998
|
+
const color2025 = DynamicColor.fromPalette({
|
|
3999
|
+
name: 'on_primary_container',
|
|
4000
|
+
palette: s => s.primaryPalette,
|
|
4001
|
+
background: s => this.primaryContainer(),
|
|
4002
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
4003
|
+
});
|
|
4004
|
+
return extendSpecVersion(super.onPrimaryContainer(), '2025', color2025);
|
|
4005
|
+
}
|
|
4006
|
+
primaryFixed() {
|
|
4007
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4008
|
+
name: 'primary_fixed',
|
|
4009
|
+
palette: s => s.primaryPalette,
|
|
4010
|
+
tone: s => {
|
|
4011
|
+
let tempS = Object.assign({}, s, {
|
|
4012
|
+
isDark: false,
|
|
4013
|
+
contrastLevel: 0
|
|
4014
|
+
});
|
|
4015
|
+
return this.primaryContainer().getTone(tempS);
|
|
4016
|
+
},
|
|
4017
|
+
isBackground: true,
|
|
4018
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : undefined,
|
|
4019
|
+
contrastCurve: s => s.platform === 'phone' && s.contrastLevel > 0 ? getCurve(1.5) : undefined
|
|
4020
|
+
});
|
|
4021
|
+
return extendSpecVersion(super.primaryFixed(), '2025', color2025);
|
|
4022
|
+
}
|
|
4023
|
+
primaryFixedDim() {
|
|
4024
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4025
|
+
name: 'primary_fixed_dim',
|
|
4026
|
+
palette: s => s.primaryPalette,
|
|
4027
|
+
tone: s => this.primaryFixed().getTone(s),
|
|
4028
|
+
isBackground: true,
|
|
4029
|
+
toneDeltaPair: s => new ToneDeltaPair(this.primaryFixedDim(), this.primaryFixed(), 5, 'darker', true, 'exact')
|
|
4030
|
+
});
|
|
4031
|
+
return extendSpecVersion(super.primaryFixedDim(), '2025', color2025);
|
|
4032
|
+
}
|
|
4033
|
+
onPrimaryFixed() {
|
|
4034
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4035
|
+
name: 'on_primary_fixed',
|
|
4036
|
+
palette: s => s.primaryPalette,
|
|
4037
|
+
background: s => this.primaryFixedDim(),
|
|
4038
|
+
contrastCurve: s => getCurve(7)
|
|
4039
|
+
});
|
|
4040
|
+
return extendSpecVersion(super.onPrimaryFixed(), '2025', color2025);
|
|
4041
|
+
}
|
|
4042
|
+
onPrimaryFixedVariant() {
|
|
4043
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4044
|
+
name: 'on_primary_fixed_variant',
|
|
4045
|
+
palette: s => s.primaryPalette,
|
|
4046
|
+
background: s => this.primaryFixedDim(),
|
|
4047
|
+
contrastCurve: s => getCurve(4.5)
|
|
4048
|
+
});
|
|
4049
|
+
return extendSpecVersion(super.onPrimaryFixedVariant(), '2025', color2025);
|
|
4050
|
+
}
|
|
4051
|
+
inversePrimary() {
|
|
4052
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4053
|
+
name: 'inverse_primary',
|
|
4054
|
+
palette: s => s.primaryPalette,
|
|
4055
|
+
tone: s => tMaxC(s.primaryPalette),
|
|
4056
|
+
background: s => this.inverseSurface(),
|
|
4057
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
4058
|
+
});
|
|
4059
|
+
return extendSpecVersion(super.inversePrimary(), '2025', color2025);
|
|
4060
|
+
}
|
|
4061
|
+
////////////////////////////////////////////////////////////////
|
|
4062
|
+
// Secondaries [Q] //
|
|
4063
|
+
////////////////////////////////////////////////////////////////
|
|
4064
|
+
secondary() {
|
|
4065
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4066
|
+
name: 'secondary',
|
|
4067
|
+
palette: s => s.secondaryPalette,
|
|
4068
|
+
tone: s => {
|
|
4069
|
+
if (s.platform === 'watch') {
|
|
4070
|
+
return s.variant === Variant.NEUTRAL ? 90 : tMaxC(s.secondaryPalette, 0, 90);
|
|
4071
|
+
} else if (s.variant === Variant.NEUTRAL) {
|
|
4072
|
+
return s.isDark ? tMinC(s.secondaryPalette, 0, 98) : tMaxC(s.secondaryPalette);
|
|
4073
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
4074
|
+
return tMaxC(s.secondaryPalette, 0, s.isDark ? 90 : 98);
|
|
4075
|
+
} else {
|
|
4076
|
+
// EXPRESSIVE and TONAL_SPOT
|
|
4077
|
+
return s.isDark ? 80 : tMaxC(s.secondaryPalette);
|
|
4078
|
+
}
|
|
4079
|
+
},
|
|
4080
|
+
isBackground: true,
|
|
4081
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
4082
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(4.5) : getCurve(7),
|
|
4083
|
+
toneDeltaPair: s => s.platform === 'phone' ? new ToneDeltaPair(this.secondaryContainer(), this.secondary(), 5, 'relative_lighter', true, 'farther') : undefined
|
|
4084
|
+
});
|
|
4085
|
+
return extendSpecVersion(super.secondary(), '2025', color2025);
|
|
4086
|
+
}
|
|
4087
|
+
secondaryDim() {
|
|
4088
|
+
return DynamicColor.fromPalette({
|
|
4089
|
+
name: 'secondary_dim',
|
|
4090
|
+
palette: s => s.secondaryPalette,
|
|
4091
|
+
tone: s => {
|
|
4092
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
4093
|
+
return 85;
|
|
4094
|
+
} else {
|
|
4095
|
+
return tMaxC(s.secondaryPalette, 0, 90);
|
|
4096
|
+
}
|
|
4097
|
+
},
|
|
4098
|
+
isBackground: true,
|
|
4099
|
+
background: s => this.surfaceContainerHigh(),
|
|
4100
|
+
contrastCurve: s => getCurve(4.5),
|
|
4101
|
+
toneDeltaPair: s => new ToneDeltaPair(this.secondaryDim(), this.secondary(), 5, 'darker', true, 'farther')
|
|
4102
|
+
});
|
|
4103
|
+
}
|
|
4104
|
+
onSecondary() {
|
|
4105
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4106
|
+
name: 'on_secondary',
|
|
4107
|
+
palette: s => s.secondaryPalette,
|
|
4108
|
+
background: s => s.platform === 'phone' ? this.secondary() : this.secondaryDim(),
|
|
4109
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
4110
|
+
});
|
|
4111
|
+
return extendSpecVersion(super.onSecondary(), '2025', color2025);
|
|
4112
|
+
}
|
|
4113
|
+
secondaryContainer() {
|
|
4114
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4115
|
+
name: 'secondary_container',
|
|
4116
|
+
palette: s => s.secondaryPalette,
|
|
4117
|
+
tone: s => {
|
|
4118
|
+
if (s.platform === 'watch') {
|
|
4119
|
+
return 30;
|
|
4120
|
+
} else if (s.variant === Variant.VIBRANT) {
|
|
4121
|
+
return s.isDark ? tMinC(s.secondaryPalette, 30, 40) : tMaxC(s.secondaryPalette, 84, 90);
|
|
4122
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
4123
|
+
return s.isDark ? 15 : tMaxC(s.secondaryPalette, 90, 95);
|
|
4124
|
+
} else {
|
|
4125
|
+
return s.isDark ? 25 : 90;
|
|
4126
|
+
}
|
|
4127
|
+
},
|
|
4128
|
+
isBackground: true,
|
|
4129
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : undefined,
|
|
4130
|
+
toneDeltaPair: s => s.platform === 'watch' ? new ToneDeltaPair(this.secondaryContainer(), this.secondaryDim(), 10, 'darker', true, 'farther') : undefined,
|
|
4131
|
+
contrastCurve: s => s.platform === 'phone' && s.contrastLevel > 0 ? getCurve(1.5) : undefined
|
|
4132
|
+
});
|
|
4133
|
+
return extendSpecVersion(super.secondaryContainer(), '2025', color2025);
|
|
4134
|
+
}
|
|
4135
|
+
onSecondaryContainer() {
|
|
4136
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4137
|
+
name: 'on_secondary_container',
|
|
4138
|
+
palette: s => s.secondaryPalette,
|
|
4139
|
+
background: s => this.secondaryContainer(),
|
|
4140
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
4141
|
+
});
|
|
4142
|
+
return extendSpecVersion(super.onSecondaryContainer(), '2025', color2025);
|
|
4143
|
+
}
|
|
4144
|
+
secondaryFixed() {
|
|
4145
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4146
|
+
name: 'secondary_fixed',
|
|
4147
|
+
palette: s => s.secondaryPalette,
|
|
4148
|
+
tone: s => {
|
|
4149
|
+
let tempS = Object.assign({}, s, {
|
|
4150
|
+
isDark: false,
|
|
4151
|
+
contrastLevel: 0
|
|
4152
|
+
});
|
|
4153
|
+
return this.secondaryContainer().getTone(tempS);
|
|
4154
|
+
},
|
|
4155
|
+
isBackground: true,
|
|
4156
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : undefined,
|
|
4157
|
+
contrastCurve: s => s.platform === 'phone' && s.contrastLevel > 0 ? getCurve(1.5) : undefined
|
|
4158
|
+
});
|
|
4159
|
+
return extendSpecVersion(super.secondaryFixed(), '2025', color2025);
|
|
4160
|
+
}
|
|
4161
|
+
secondaryFixedDim() {
|
|
4162
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4163
|
+
name: 'secondary_fixed_dim',
|
|
4164
|
+
palette: s => s.secondaryPalette,
|
|
4165
|
+
tone: s => this.secondaryFixed().getTone(s),
|
|
4166
|
+
isBackground: true,
|
|
4167
|
+
toneDeltaPair: s => new ToneDeltaPair(this.secondaryFixedDim(), this.secondaryFixed(), 5, 'darker', true, 'exact')
|
|
4168
|
+
});
|
|
4169
|
+
return extendSpecVersion(super.secondaryFixedDim(), '2025', color2025);
|
|
4170
|
+
}
|
|
4171
|
+
onSecondaryFixed() {
|
|
4172
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4173
|
+
name: 'on_secondary_fixed',
|
|
4174
|
+
palette: s => s.secondaryPalette,
|
|
4175
|
+
background: s => this.secondaryFixedDim(),
|
|
4176
|
+
contrastCurve: s => getCurve(7)
|
|
4177
|
+
});
|
|
4178
|
+
return extendSpecVersion(super.onSecondaryFixed(), '2025', color2025);
|
|
4179
|
+
}
|
|
4180
|
+
onSecondaryFixedVariant() {
|
|
4181
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4182
|
+
name: 'on_secondary_fixed_variant',
|
|
4183
|
+
palette: s => s.secondaryPalette,
|
|
4184
|
+
background: s => this.secondaryFixedDim(),
|
|
4185
|
+
contrastCurve: s => getCurve(4.5)
|
|
4186
|
+
});
|
|
4187
|
+
return extendSpecVersion(super.onSecondaryFixedVariant(), '2025', color2025);
|
|
4188
|
+
}
|
|
4189
|
+
////////////////////////////////////////////////////////////////
|
|
4190
|
+
// Tertiaries [T] //
|
|
4191
|
+
////////////////////////////////////////////////////////////////
|
|
4192
|
+
tertiary() {
|
|
4193
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4194
|
+
name: 'tertiary',
|
|
4195
|
+
palette: s => s.tertiaryPalette,
|
|
4196
|
+
tone: s => {
|
|
4197
|
+
if (s.platform === 'watch') {
|
|
4198
|
+
return s.variant === Variant.TONAL_SPOT ? tMaxC(s.tertiaryPalette, 0, 90) : tMaxC(s.tertiaryPalette);
|
|
4199
|
+
} else if (s.variant === Variant.EXPRESSIVE || s.variant === Variant.VIBRANT) {
|
|
4200
|
+
return tMaxC(s.tertiaryPalette, 0, Hct.isCyan(s.tertiaryPalette.hue) ? 88 : s.isDark ? 98 : 100);
|
|
4201
|
+
} else {
|
|
4202
|
+
// NEUTRAL and TONAL_SPOT
|
|
4203
|
+
return s.isDark ? tMaxC(s.tertiaryPalette, 0, 98) : tMaxC(s.tertiaryPalette);
|
|
4204
|
+
}
|
|
4205
|
+
},
|
|
4206
|
+
isBackground: true,
|
|
4207
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
4208
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(4.5) : getCurve(7),
|
|
4209
|
+
toneDeltaPair: s => s.platform === 'phone' ? new ToneDeltaPair(this.tertiaryContainer(), this.tertiary(), 5, 'relative_lighter', true, 'farther') : undefined
|
|
4210
|
+
});
|
|
4211
|
+
return extendSpecVersion(super.tertiary(), '2025', color2025);
|
|
4212
|
+
}
|
|
4213
|
+
tertiaryDim() {
|
|
4214
|
+
return DynamicColor.fromPalette({
|
|
4215
|
+
name: 'tertiary_dim',
|
|
4216
|
+
palette: s => s.tertiaryPalette,
|
|
4217
|
+
tone: s => {
|
|
4218
|
+
if (s.variant === Variant.TONAL_SPOT) {
|
|
4219
|
+
return tMaxC(s.tertiaryPalette, 0, 90);
|
|
4220
|
+
} else {
|
|
4221
|
+
return tMaxC(s.tertiaryPalette);
|
|
4222
|
+
}
|
|
4223
|
+
},
|
|
4224
|
+
isBackground: true,
|
|
4225
|
+
background: s => this.surfaceContainerHigh(),
|
|
4226
|
+
contrastCurve: s => getCurve(4.5),
|
|
4227
|
+
toneDeltaPair: s => new ToneDeltaPair(this.tertiaryDim(), this.tertiary(), 5, 'darker', true, 'farther')
|
|
4228
|
+
});
|
|
4229
|
+
}
|
|
4230
|
+
onTertiary() {
|
|
4231
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4232
|
+
name: 'on_tertiary',
|
|
4233
|
+
palette: s => s.tertiaryPalette,
|
|
4234
|
+
background: s => s.platform === 'phone' ? this.tertiary() : this.tertiaryDim(),
|
|
4235
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
4236
|
+
});
|
|
4237
|
+
return extendSpecVersion(super.onTertiary(), '2025', color2025);
|
|
4238
|
+
}
|
|
4239
|
+
tertiaryContainer() {
|
|
4240
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4241
|
+
name: 'tertiary_container',
|
|
4242
|
+
palette: s => s.tertiaryPalette,
|
|
4243
|
+
tone: s => {
|
|
4244
|
+
if (s.platform === 'watch') {
|
|
4245
|
+
return s.variant === Variant.TONAL_SPOT ? tMaxC(s.tertiaryPalette, 0, 90) : tMaxC(s.tertiaryPalette);
|
|
4246
|
+
} else {
|
|
4247
|
+
if (s.variant === Variant.NEUTRAL) {
|
|
4248
|
+
return s.isDark ? tMaxC(s.tertiaryPalette, 0, 93) : tMaxC(s.tertiaryPalette, 0, 96);
|
|
4249
|
+
} else if (s.variant === Variant.TONAL_SPOT) {
|
|
4250
|
+
return tMaxC(s.tertiaryPalette, 0, s.isDark ? 93 : 100);
|
|
4251
|
+
} else if (s.variant === Variant.EXPRESSIVE) {
|
|
4252
|
+
return tMaxC(s.tertiaryPalette, 75, Hct.isCyan(s.tertiaryPalette.hue) ? 88 : s.isDark ? 93 : 100);
|
|
4253
|
+
} else {
|
|
4254
|
+
// VIBRANT
|
|
4255
|
+
return s.isDark ? tMaxC(s.tertiaryPalette, 0, 93) : tMaxC(s.tertiaryPalette, 72, 100);
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
},
|
|
4259
|
+
isBackground: true,
|
|
4260
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : undefined,
|
|
4261
|
+
toneDeltaPair: s => s.platform === 'watch' ? new ToneDeltaPair(this.tertiaryContainer(), this.tertiaryDim(), 10, 'darker', true, 'farther') : undefined,
|
|
4262
|
+
contrastCurve: s => s.platform === 'phone' && s.contrastLevel > 0 ? getCurve(1.5) : undefined
|
|
4263
|
+
});
|
|
4264
|
+
return extendSpecVersion(super.tertiaryContainer(), '2025', color2025);
|
|
4265
|
+
}
|
|
4266
|
+
onTertiaryContainer() {
|
|
4267
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4268
|
+
name: 'on_tertiary_container',
|
|
4269
|
+
palette: s => s.tertiaryPalette,
|
|
4270
|
+
background: s => this.tertiaryContainer(),
|
|
4271
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
4272
|
+
});
|
|
4273
|
+
return extendSpecVersion(super.onTertiaryContainer(), '2025', color2025);
|
|
4274
|
+
}
|
|
4275
|
+
tertiaryFixed() {
|
|
4276
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4277
|
+
name: 'tertiary_fixed',
|
|
4278
|
+
palette: s => s.tertiaryPalette,
|
|
4279
|
+
tone: s => {
|
|
4280
|
+
let tempS = Object.assign({}, s, {
|
|
4281
|
+
isDark: false,
|
|
4282
|
+
contrastLevel: 0
|
|
4283
|
+
});
|
|
4284
|
+
return this.tertiaryContainer().getTone(tempS);
|
|
4285
|
+
},
|
|
4286
|
+
isBackground: true,
|
|
4287
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : undefined,
|
|
4288
|
+
contrastCurve: s => s.platform === 'phone' && s.contrastLevel > 0 ? getCurve(1.5) : undefined
|
|
4289
|
+
});
|
|
4290
|
+
return extendSpecVersion(super.tertiaryFixed(), '2025', color2025);
|
|
4291
|
+
}
|
|
4292
|
+
tertiaryFixedDim() {
|
|
4293
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4294
|
+
name: 'tertiary_fixed_dim',
|
|
4295
|
+
palette: s => s.tertiaryPalette,
|
|
4296
|
+
tone: s => this.tertiaryFixed().getTone(s),
|
|
4297
|
+
isBackground: true,
|
|
4298
|
+
toneDeltaPair: s => new ToneDeltaPair(this.tertiaryFixedDim(), this.tertiaryFixed(), 5, 'darker', true, 'exact')
|
|
4299
|
+
});
|
|
4300
|
+
return extendSpecVersion(super.tertiaryFixedDim(), '2025', color2025);
|
|
4301
|
+
}
|
|
4302
|
+
onTertiaryFixed() {
|
|
4303
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4304
|
+
name: 'on_tertiary_fixed',
|
|
4305
|
+
palette: s => s.tertiaryPalette,
|
|
4306
|
+
background: s => this.tertiaryFixedDim(),
|
|
4307
|
+
contrastCurve: s => getCurve(7)
|
|
4308
|
+
});
|
|
4309
|
+
return extendSpecVersion(super.onTertiaryFixed(), '2025', color2025);
|
|
4310
|
+
}
|
|
4311
|
+
onTertiaryFixedVariant() {
|
|
4312
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4313
|
+
name: 'on_tertiary_fixed_variant',
|
|
4314
|
+
palette: s => s.tertiaryPalette,
|
|
4315
|
+
background: s => this.tertiaryFixedDim(),
|
|
4316
|
+
contrastCurve: s => getCurve(4.5)
|
|
4317
|
+
});
|
|
4318
|
+
return extendSpecVersion(super.onTertiaryFixedVariant(), '2025', color2025);
|
|
4319
|
+
}
|
|
4320
|
+
////////////////////////////////////////////////////////////////
|
|
4321
|
+
// Errors [E] //
|
|
4322
|
+
////////////////////////////////////////////////////////////////
|
|
4323
|
+
error() {
|
|
4324
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4325
|
+
name: 'error',
|
|
4326
|
+
palette: s => s.errorPalette,
|
|
4327
|
+
tone: s => {
|
|
4328
|
+
if (s.platform === 'phone') {
|
|
4329
|
+
return s.isDark ? tMinC(s.errorPalette, 0, 98) : tMaxC(s.errorPalette);
|
|
4330
|
+
} else {
|
|
4331
|
+
return tMinC(s.errorPalette);
|
|
4332
|
+
}
|
|
4333
|
+
},
|
|
4334
|
+
isBackground: true,
|
|
4335
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : this.surfaceContainerHigh(),
|
|
4336
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(4.5) : getCurve(7),
|
|
4337
|
+
toneDeltaPair: s => s.platform === 'phone' ? new ToneDeltaPair(this.errorContainer(), this.error(), 5, 'relative_lighter', true, 'farther') : undefined
|
|
4338
|
+
});
|
|
4339
|
+
return extendSpecVersion(super.error(), '2025', color2025);
|
|
4340
|
+
}
|
|
4341
|
+
errorDim() {
|
|
4342
|
+
return DynamicColor.fromPalette({
|
|
4343
|
+
name: 'error_dim',
|
|
4344
|
+
palette: s => s.errorPalette,
|
|
4345
|
+
tone: s => tMinC(s.errorPalette),
|
|
4346
|
+
isBackground: true,
|
|
4347
|
+
background: s => this.surfaceContainerHigh(),
|
|
4348
|
+
contrastCurve: s => getCurve(4.5),
|
|
4349
|
+
toneDeltaPair: s => new ToneDeltaPair(this.errorDim(), this.error(), 5, 'darker', true, 'farther')
|
|
4350
|
+
});
|
|
4351
|
+
}
|
|
4352
|
+
onError() {
|
|
4353
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4354
|
+
name: 'on_error',
|
|
4355
|
+
palette: s => s.errorPalette,
|
|
4356
|
+
background: s => s.platform === 'phone' ? this.error() : this.errorDim(),
|
|
4357
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(6) : getCurve(7)
|
|
4358
|
+
});
|
|
4359
|
+
return extendSpecVersion(super.onError(), '2025', color2025);
|
|
4360
|
+
}
|
|
4361
|
+
errorContainer() {
|
|
4362
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4363
|
+
name: 'error_container',
|
|
4364
|
+
palette: s => s.errorPalette,
|
|
4365
|
+
tone: s => {
|
|
4366
|
+
if (s.platform === 'watch') {
|
|
4367
|
+
return 30;
|
|
4368
|
+
} else {
|
|
4369
|
+
return s.isDark ? tMinC(s.errorPalette, 30, 93) : tMaxC(s.errorPalette, 0, 90);
|
|
4370
|
+
}
|
|
4371
|
+
},
|
|
4372
|
+
isBackground: true,
|
|
4373
|
+
background: s => s.platform === 'phone' ? this.highestSurface(s) : undefined,
|
|
4374
|
+
toneDeltaPair: s => s.platform === 'watch' ? new ToneDeltaPair(this.errorContainer(), this.errorDim(), 10, 'darker', true, 'farther') : undefined,
|
|
4375
|
+
contrastCurve: s => s.platform === 'phone' && s.contrastLevel > 0 ? getCurve(1.5) : undefined
|
|
4376
|
+
});
|
|
4377
|
+
return extendSpecVersion(super.errorContainer(), '2025', color2025);
|
|
4378
|
+
}
|
|
4379
|
+
onErrorContainer() {
|
|
4380
|
+
const color2025 = DynamicColor.fromPalette({
|
|
4381
|
+
name: 'on_error_container',
|
|
4382
|
+
palette: s => s.errorPalette,
|
|
4383
|
+
background: s => this.errorContainer(),
|
|
4384
|
+
contrastCurve: s => s.platform === 'phone' ? getCurve(4.5) : getCurve(7)
|
|
4385
|
+
});
|
|
4386
|
+
return extendSpecVersion(super.onErrorContainer(), '2025', color2025);
|
|
4387
|
+
}
|
|
4388
|
+
/////////////////////////////////////////////////////////////////
|
|
4389
|
+
// Remapped Colors //
|
|
4390
|
+
/////////////////////////////////////////////////////////////////
|
|
4391
|
+
surfaceVariant() {
|
|
4392
|
+
const color2025 = Object.assign(this.surfaceContainerHighest().clone(), {
|
|
4393
|
+
name: 'surface_variant'
|
|
4394
|
+
});
|
|
4395
|
+
return extendSpecVersion(super.surfaceVariant(), '2025', color2025);
|
|
4396
|
+
}
|
|
4397
|
+
surfaceTint() {
|
|
4398
|
+
const color2025 = Object.assign(this.primary().clone(), {
|
|
4399
|
+
name: 'surface_tint'
|
|
4400
|
+
});
|
|
4401
|
+
return extendSpecVersion(super.surfaceTint(), '2025', color2025);
|
|
4402
|
+
}
|
|
4403
|
+
background() {
|
|
4404
|
+
const color2025 = Object.assign(this.surface().clone(), {
|
|
4405
|
+
name: 'background'
|
|
4406
|
+
});
|
|
4407
|
+
return extendSpecVersion(super.background(), '2025', color2025);
|
|
4408
|
+
}
|
|
4409
|
+
onBackground() {
|
|
4410
|
+
const color2025 = Object.assign(this.onSurface().clone(), {
|
|
4411
|
+
name: 'on_background',
|
|
4412
|
+
tone: s => {
|
|
4413
|
+
return s.platform === 'watch' ? 100.0 : this.onSurface().getTone(s);
|
|
4414
|
+
}
|
|
4415
|
+
});
|
|
4416
|
+
return extendSpecVersion(super.onBackground(), '2025', color2025);
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
|
|
4420
|
+
/**
|
|
4421
|
+
* @license
|
|
4422
|
+
* Copyright 2022 Google LLC
|
|
4423
|
+
*
|
|
4424
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4425
|
+
* you may not use this file except in compliance with the License.
|
|
4426
|
+
* You may obtain a copy of the License at
|
|
4427
|
+
*
|
|
4428
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
4429
|
+
*
|
|
4430
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
4431
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
4432
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
4433
|
+
* See the License for the specific language governing permissions and
|
|
4434
|
+
* limitations under the License.
|
|
4435
|
+
*/
|
|
4436
|
+
/**
|
|
4437
|
+
* DynamicColors for the colors in the Material Design system.
|
|
4438
|
+
*/
|
|
4439
|
+
// Material Color Utilities namespaces the various utilities it provides.
|
|
4440
|
+
// tslint:disable-next-line:class-as-namespace
|
|
4441
|
+
class MaterialDynamicColors {
|
|
4442
|
+
constructor() {
|
|
4443
|
+
////////////////////////////////////////////////////////////////
|
|
4444
|
+
// All Colors //
|
|
4445
|
+
////////////////////////////////////////////////////////////////
|
|
4446
|
+
this.allColors = [this.background(), this.onBackground(), this.surface(), this.surfaceDim(), this.surfaceBright(), this.surfaceContainerLowest(), this.surfaceContainerLow(), this.surfaceContainer(), this.surfaceContainerHigh(), this.surfaceContainerHighest(), this.onSurface(), this.onSurfaceVariant(), this.outline(), this.outlineVariant(), this.inverseSurface(), this.inverseOnSurface(), this.primary(), this.primaryDim(), this.onPrimary(), this.primaryContainer(), this.onPrimaryContainer(), this.primaryFixed(), this.primaryFixedDim(), this.onPrimaryFixed(), this.onPrimaryFixedVariant(), this.inversePrimary(), this.secondary(), this.secondaryDim(), this.onSecondary(), this.secondaryContainer(), this.onSecondaryContainer(), this.secondaryFixed(), this.secondaryFixedDim(), this.onSecondaryFixed(), this.onSecondaryFixedVariant(), this.tertiary(), this.tertiaryDim(), this.onTertiary(), this.tertiaryContainer(), this.onTertiaryContainer(), this.tertiaryFixed(), this.tertiaryFixedDim(), this.onTertiaryFixed(), this.onTertiaryFixedVariant(), this.error(), this.errorDim(), this.onError(), this.errorContainer(), this.onErrorContainer()].filter(c => c !== undefined);
|
|
4447
|
+
}
|
|
4448
|
+
highestSurface(s) {
|
|
4449
|
+
return MaterialDynamicColors.colorSpec.highestSurface(s);
|
|
4450
|
+
}
|
|
4451
|
+
////////////////////////////////////////////////////////////////
|
|
4452
|
+
// Main Palettes //
|
|
4453
|
+
////////////////////////////////////////////////////////////////
|
|
4454
|
+
primaryPaletteKeyColor() {
|
|
4455
|
+
return MaterialDynamicColors.colorSpec.primaryPaletteKeyColor();
|
|
4456
|
+
}
|
|
4457
|
+
secondaryPaletteKeyColor() {
|
|
4458
|
+
return MaterialDynamicColors.colorSpec.secondaryPaletteKeyColor();
|
|
4459
|
+
}
|
|
4460
|
+
tertiaryPaletteKeyColor() {
|
|
4461
|
+
return MaterialDynamicColors.colorSpec.tertiaryPaletteKeyColor();
|
|
4462
|
+
}
|
|
4463
|
+
neutralPaletteKeyColor() {
|
|
4464
|
+
return MaterialDynamicColors.colorSpec.neutralPaletteKeyColor();
|
|
4465
|
+
}
|
|
4466
|
+
neutralVariantPaletteKeyColor() {
|
|
4467
|
+
return MaterialDynamicColors.colorSpec.neutralVariantPaletteKeyColor();
|
|
4468
|
+
}
|
|
4469
|
+
errorPaletteKeyColor() {
|
|
4470
|
+
return MaterialDynamicColors.colorSpec.errorPaletteKeyColor();
|
|
4471
|
+
}
|
|
4472
|
+
////////////////////////////////////////////////////////////////
|
|
4473
|
+
// Surfaces [S] //
|
|
4474
|
+
////////////////////////////////////////////////////////////////
|
|
4475
|
+
background() {
|
|
4476
|
+
return MaterialDynamicColors.colorSpec.background();
|
|
4477
|
+
}
|
|
4478
|
+
onBackground() {
|
|
4479
|
+
return MaterialDynamicColors.colorSpec.onBackground();
|
|
4480
|
+
}
|
|
4481
|
+
surface() {
|
|
4482
|
+
return MaterialDynamicColors.colorSpec.surface();
|
|
4483
|
+
}
|
|
4484
|
+
surfaceDim() {
|
|
4485
|
+
return MaterialDynamicColors.colorSpec.surfaceDim();
|
|
4486
|
+
}
|
|
4487
|
+
surfaceBright() {
|
|
4488
|
+
return MaterialDynamicColors.colorSpec.surfaceBright();
|
|
4489
|
+
}
|
|
4490
|
+
surfaceContainerLowest() {
|
|
4491
|
+
return MaterialDynamicColors.colorSpec.surfaceContainerLowest();
|
|
4492
|
+
}
|
|
4493
|
+
surfaceContainerLow() {
|
|
4494
|
+
return MaterialDynamicColors.colorSpec.surfaceContainerLow();
|
|
4495
|
+
}
|
|
4496
|
+
surfaceContainer() {
|
|
4497
|
+
return MaterialDynamicColors.colorSpec.surfaceContainer();
|
|
4498
|
+
}
|
|
4499
|
+
surfaceContainerHigh() {
|
|
4500
|
+
return MaterialDynamicColors.colorSpec.surfaceContainerHigh();
|
|
4501
|
+
}
|
|
4502
|
+
surfaceContainerHighest() {
|
|
4503
|
+
return MaterialDynamicColors.colorSpec.surfaceContainerHighest();
|
|
4504
|
+
}
|
|
4505
|
+
onSurface() {
|
|
4506
|
+
return MaterialDynamicColors.colorSpec.onSurface();
|
|
4507
|
+
}
|
|
4508
|
+
surfaceVariant() {
|
|
4509
|
+
return MaterialDynamicColors.colorSpec.surfaceVariant();
|
|
4510
|
+
}
|
|
4511
|
+
onSurfaceVariant() {
|
|
4512
|
+
return MaterialDynamicColors.colorSpec.onSurfaceVariant();
|
|
4513
|
+
}
|
|
4514
|
+
outline() {
|
|
4515
|
+
return MaterialDynamicColors.colorSpec.outline();
|
|
4516
|
+
}
|
|
4517
|
+
outlineVariant() {
|
|
4518
|
+
return MaterialDynamicColors.colorSpec.outlineVariant();
|
|
4519
|
+
}
|
|
4520
|
+
inverseSurface() {
|
|
4521
|
+
return MaterialDynamicColors.colorSpec.inverseSurface();
|
|
4522
|
+
}
|
|
4523
|
+
inverseOnSurface() {
|
|
4524
|
+
return MaterialDynamicColors.colorSpec.inverseOnSurface();
|
|
4525
|
+
}
|
|
4526
|
+
shadow() {
|
|
4527
|
+
return MaterialDynamicColors.colorSpec.shadow();
|
|
4528
|
+
}
|
|
4529
|
+
scrim() {
|
|
4530
|
+
return MaterialDynamicColors.colorSpec.scrim();
|
|
4531
|
+
}
|
|
4532
|
+
surfaceTint() {
|
|
4533
|
+
return MaterialDynamicColors.colorSpec.surfaceTint();
|
|
4534
|
+
}
|
|
4535
|
+
////////////////////////////////////////////////////////////////
|
|
4536
|
+
// Primaries [P] //
|
|
4537
|
+
////////////////////////////////////////////////////////////////
|
|
4538
|
+
primary() {
|
|
4539
|
+
return MaterialDynamicColors.colorSpec.primary();
|
|
4540
|
+
}
|
|
4541
|
+
primaryDim() {
|
|
4542
|
+
return MaterialDynamicColors.colorSpec.primaryDim();
|
|
4543
|
+
}
|
|
4544
|
+
onPrimary() {
|
|
4545
|
+
return MaterialDynamicColors.colorSpec.onPrimary();
|
|
4546
|
+
}
|
|
4547
|
+
primaryContainer() {
|
|
4548
|
+
return MaterialDynamicColors.colorSpec.primaryContainer();
|
|
4549
|
+
}
|
|
4550
|
+
onPrimaryContainer() {
|
|
4551
|
+
return MaterialDynamicColors.colorSpec.onPrimaryContainer();
|
|
4552
|
+
}
|
|
4553
|
+
inversePrimary() {
|
|
4554
|
+
return MaterialDynamicColors.colorSpec.inversePrimary();
|
|
4555
|
+
}
|
|
4556
|
+
/////////////////////////////////////////////////////////////////
|
|
4557
|
+
// Primary Fixed [PF] //
|
|
4558
|
+
/////////////////////////////////////////////////////////////////
|
|
4559
|
+
primaryFixed() {
|
|
4560
|
+
return MaterialDynamicColors.colorSpec.primaryFixed();
|
|
4561
|
+
}
|
|
4562
|
+
primaryFixedDim() {
|
|
4563
|
+
return MaterialDynamicColors.colorSpec.primaryFixedDim();
|
|
4564
|
+
}
|
|
4565
|
+
onPrimaryFixed() {
|
|
4566
|
+
return MaterialDynamicColors.colorSpec.onPrimaryFixed();
|
|
4567
|
+
}
|
|
4568
|
+
onPrimaryFixedVariant() {
|
|
4569
|
+
return MaterialDynamicColors.colorSpec.onPrimaryFixedVariant();
|
|
4570
|
+
}
|
|
4571
|
+
////////////////////////////////////////////////////////////////
|
|
4572
|
+
// Secondaries [Q] //
|
|
4573
|
+
////////////////////////////////////////////////////////////////
|
|
4574
|
+
secondary() {
|
|
4575
|
+
return MaterialDynamicColors.colorSpec.secondary();
|
|
4576
|
+
}
|
|
4577
|
+
secondaryDim() {
|
|
4578
|
+
return MaterialDynamicColors.colorSpec.secondaryDim();
|
|
4579
|
+
}
|
|
4580
|
+
onSecondary() {
|
|
4581
|
+
return MaterialDynamicColors.colorSpec.onSecondary();
|
|
4582
|
+
}
|
|
4583
|
+
secondaryContainer() {
|
|
4584
|
+
return MaterialDynamicColors.colorSpec.secondaryContainer();
|
|
4585
|
+
}
|
|
4586
|
+
onSecondaryContainer() {
|
|
4587
|
+
return MaterialDynamicColors.colorSpec.onSecondaryContainer();
|
|
4588
|
+
}
|
|
4589
|
+
/////////////////////////////////////////////////////////////////
|
|
4590
|
+
// Secondary Fixed [QF] //
|
|
4591
|
+
/////////////////////////////////////////////////////////////////
|
|
4592
|
+
secondaryFixed() {
|
|
4593
|
+
return MaterialDynamicColors.colorSpec.secondaryFixed();
|
|
4594
|
+
}
|
|
4595
|
+
secondaryFixedDim() {
|
|
4596
|
+
return MaterialDynamicColors.colorSpec.secondaryFixedDim();
|
|
4597
|
+
}
|
|
4598
|
+
onSecondaryFixed() {
|
|
4599
|
+
return MaterialDynamicColors.colorSpec.onSecondaryFixed();
|
|
4600
|
+
}
|
|
4601
|
+
onSecondaryFixedVariant() {
|
|
4602
|
+
return MaterialDynamicColors.colorSpec.onSecondaryFixedVariant();
|
|
4603
|
+
}
|
|
4604
|
+
////////////////////////////////////////////////////////////////
|
|
4605
|
+
// Tertiaries [T] //
|
|
4606
|
+
////////////////////////////////////////////////////////////////
|
|
4607
|
+
tertiary() {
|
|
4608
|
+
return MaterialDynamicColors.colorSpec.tertiary();
|
|
4609
|
+
}
|
|
4610
|
+
tertiaryDim() {
|
|
4611
|
+
return MaterialDynamicColors.colorSpec.tertiaryDim();
|
|
4612
|
+
}
|
|
4613
|
+
onTertiary() {
|
|
4614
|
+
return MaterialDynamicColors.colorSpec.onTertiary();
|
|
4615
|
+
}
|
|
4616
|
+
tertiaryContainer() {
|
|
4617
|
+
return MaterialDynamicColors.colorSpec.tertiaryContainer();
|
|
4618
|
+
}
|
|
4619
|
+
onTertiaryContainer() {
|
|
4620
|
+
return MaterialDynamicColors.colorSpec.onTertiaryContainer();
|
|
4621
|
+
}
|
|
4622
|
+
/////////////////////////////////////////////////////////////////
|
|
4623
|
+
// Tertiary Fixed [TF] //
|
|
4624
|
+
/////////////////////////////////////////////////////////////////
|
|
4625
|
+
tertiaryFixed() {
|
|
4626
|
+
return MaterialDynamicColors.colorSpec.tertiaryFixed();
|
|
4627
|
+
}
|
|
4628
|
+
tertiaryFixedDim() {
|
|
4629
|
+
return MaterialDynamicColors.colorSpec.tertiaryFixedDim();
|
|
4630
|
+
}
|
|
4631
|
+
onTertiaryFixed() {
|
|
4632
|
+
return MaterialDynamicColors.colorSpec.onTertiaryFixed();
|
|
4633
|
+
}
|
|
4634
|
+
onTertiaryFixedVariant() {
|
|
4635
|
+
return MaterialDynamicColors.colorSpec.onTertiaryFixedVariant();
|
|
4636
|
+
}
|
|
4637
|
+
////////////////////////////////////////////////////////////////
|
|
4638
|
+
// Errors [E] //
|
|
4639
|
+
////////////////////////////////////////////////////////////////
|
|
4640
|
+
error() {
|
|
4641
|
+
return MaterialDynamicColors.colorSpec.error();
|
|
4642
|
+
}
|
|
4643
|
+
errorDim() {
|
|
4644
|
+
return MaterialDynamicColors.colorSpec.errorDim();
|
|
4645
|
+
}
|
|
4646
|
+
onError() {
|
|
4647
|
+
return MaterialDynamicColors.colorSpec.onError();
|
|
4648
|
+
}
|
|
4649
|
+
errorContainer() {
|
|
4650
|
+
return MaterialDynamicColors.colorSpec.errorContainer();
|
|
4651
|
+
}
|
|
4652
|
+
onErrorContainer() {
|
|
4653
|
+
return MaterialDynamicColors.colorSpec.onErrorContainer();
|
|
4654
|
+
}
|
|
4655
|
+
// Static variables are deprecated. Use the instance methods to get correct
|
|
4656
|
+
// specs based on request.
|
|
4657
|
+
/** @deprecated Use highestSurface() instead. */
|
|
4658
|
+
static highestSurface(s) {
|
|
4659
|
+
return MaterialDynamicColors.colorSpec.highestSurface(s);
|
|
4660
|
+
}
|
|
4661
|
+
}
|
|
4662
|
+
MaterialDynamicColors.contentAccentToneDelta = 15.0;
|
|
4663
|
+
MaterialDynamicColors.colorSpec = new ColorSpecDelegateImpl2025();
|
|
4664
|
+
/** @deprecated Use primaryPaletteKeyColor() instead. */
|
|
4665
|
+
MaterialDynamicColors.primaryPaletteKeyColor = MaterialDynamicColors.colorSpec.primaryPaletteKeyColor();
|
|
4666
|
+
/** @deprecated Use secondaryPaletteKeyColor() instead. */
|
|
4667
|
+
MaterialDynamicColors.secondaryPaletteKeyColor = MaterialDynamicColors.colorSpec.secondaryPaletteKeyColor();
|
|
4668
|
+
/** @deprecated Use tertiaryPaletteKeyColor() instead. */
|
|
4669
|
+
MaterialDynamicColors.tertiaryPaletteKeyColor = MaterialDynamicColors.colorSpec.tertiaryPaletteKeyColor();
|
|
4670
|
+
/** @deprecated Use neutralPaletteKeyColor() instead. */
|
|
4671
|
+
MaterialDynamicColors.neutralPaletteKeyColor = MaterialDynamicColors.colorSpec.neutralPaletteKeyColor();
|
|
4672
|
+
/** @deprecated Use neutralVariantPaletteKeyColor() instead. */
|
|
4673
|
+
MaterialDynamicColors.neutralVariantPaletteKeyColor = MaterialDynamicColors.colorSpec.neutralVariantPaletteKeyColor();
|
|
4674
|
+
/** @deprecated Use background() instead. */
|
|
4675
|
+
MaterialDynamicColors.background = MaterialDynamicColors.colorSpec.background();
|
|
4676
|
+
/** @deprecated Use background() instead. */
|
|
4677
|
+
MaterialDynamicColors.onBackground = MaterialDynamicColors.colorSpec.onBackground();
|
|
4678
|
+
/** @deprecated Use surface() instead. */
|
|
4679
|
+
MaterialDynamicColors.surface = MaterialDynamicColors.colorSpec.surface();
|
|
4680
|
+
/** @deprecated Use surfaceDim() instead. */
|
|
4681
|
+
MaterialDynamicColors.surfaceDim = MaterialDynamicColors.colorSpec.surfaceDim();
|
|
4682
|
+
/** @deprecated Use surfaceBright() instead. */
|
|
4683
|
+
MaterialDynamicColors.surfaceBright = MaterialDynamicColors.colorSpec.surfaceBright();
|
|
4684
|
+
/** @deprecated Use surfaceContainerLowest() instead. */
|
|
4685
|
+
MaterialDynamicColors.surfaceContainerLowest = MaterialDynamicColors.colorSpec.surfaceContainerLowest();
|
|
4686
|
+
/** @deprecated Use surfaceContainerLow() instead. */
|
|
4687
|
+
MaterialDynamicColors.surfaceContainerLow = MaterialDynamicColors.colorSpec.surfaceContainerLow();
|
|
4688
|
+
/** @deprecated Use surfaceContainer() instead. */
|
|
4689
|
+
MaterialDynamicColors.surfaceContainer = MaterialDynamicColors.colorSpec.surfaceContainer();
|
|
4690
|
+
/** @deprecated Use surfaceContainerHigh() instead. */
|
|
4691
|
+
MaterialDynamicColors.surfaceContainerHigh = MaterialDynamicColors.colorSpec.surfaceContainerHigh();
|
|
4692
|
+
/** @deprecated Use surfaceContainerHighest() instead. */
|
|
4693
|
+
MaterialDynamicColors.surfaceContainerHighest = MaterialDynamicColors.colorSpec.surfaceContainerHighest();
|
|
4694
|
+
/** @deprecated Use onSurface() instead. */
|
|
4695
|
+
MaterialDynamicColors.onSurface = MaterialDynamicColors.colorSpec.onSurface();
|
|
4696
|
+
/** @deprecated Use surfaceVariant() instead. */
|
|
4697
|
+
MaterialDynamicColors.surfaceVariant = MaterialDynamicColors.colorSpec.surfaceVariant();
|
|
4698
|
+
/** @deprecated Use onSurfaceVariant() instead. */
|
|
4699
|
+
MaterialDynamicColors.onSurfaceVariant = MaterialDynamicColors.colorSpec.onSurfaceVariant();
|
|
4700
|
+
/** @deprecated Use inverseSurface() instead. */
|
|
4701
|
+
MaterialDynamicColors.inverseSurface = MaterialDynamicColors.colorSpec.inverseSurface();
|
|
4702
|
+
/** @deprecated Use inverseOnSurface() instead. */
|
|
4703
|
+
MaterialDynamicColors.inverseOnSurface = MaterialDynamicColors.colorSpec.inverseOnSurface();
|
|
4704
|
+
/** @deprecated Use outline() instead. */
|
|
4705
|
+
MaterialDynamicColors.outline = MaterialDynamicColors.colorSpec.outline();
|
|
4706
|
+
/** @deprecated Use outlineVariant() instead. */
|
|
4707
|
+
MaterialDynamicColors.outlineVariant = MaterialDynamicColors.colorSpec.outlineVariant();
|
|
4708
|
+
/** @deprecated Use shadow() instead. */
|
|
4709
|
+
MaterialDynamicColors.shadow = MaterialDynamicColors.colorSpec.shadow();
|
|
4710
|
+
/** @deprecated Use scrim() instead. */
|
|
4711
|
+
MaterialDynamicColors.scrim = MaterialDynamicColors.colorSpec.scrim();
|
|
4712
|
+
/** @deprecated Use surfaceTint() instead. */
|
|
4713
|
+
MaterialDynamicColors.surfaceTint = MaterialDynamicColors.colorSpec.surfaceTint();
|
|
4714
|
+
/** @deprecated Use primary() instead. */
|
|
4715
|
+
MaterialDynamicColors.primary = MaterialDynamicColors.colorSpec.primary();
|
|
4716
|
+
/** @deprecated Use onPrimary() instead. */
|
|
4717
|
+
MaterialDynamicColors.onPrimary = MaterialDynamicColors.colorSpec.onPrimary();
|
|
4718
|
+
/** @deprecated Use primaryContainer() instead. */
|
|
4719
|
+
MaterialDynamicColors.primaryContainer = MaterialDynamicColors.colorSpec.primaryContainer();
|
|
4720
|
+
/** @deprecated Use onPrimaryContainer() instead. */
|
|
4721
|
+
MaterialDynamicColors.onPrimaryContainer = MaterialDynamicColors.colorSpec.onPrimaryContainer();
|
|
4722
|
+
/** @deprecated Use inversePrimary() instead. */
|
|
4723
|
+
MaterialDynamicColors.inversePrimary = MaterialDynamicColors.colorSpec.inversePrimary();
|
|
4724
|
+
/** @deprecated Use secondary() instead. */
|
|
4725
|
+
MaterialDynamicColors.secondary = MaterialDynamicColors.colorSpec.secondary();
|
|
4726
|
+
/** @deprecated Use onSecondary() instead. */
|
|
4727
|
+
MaterialDynamicColors.onSecondary = MaterialDynamicColors.colorSpec.onSecondary();
|
|
4728
|
+
/** @deprecated Use secondaryContainer() instead. */
|
|
4729
|
+
MaterialDynamicColors.secondaryContainer = MaterialDynamicColors.colorSpec.secondaryContainer();
|
|
4730
|
+
/** @deprecated Use onSecondaryContainer() instead. */
|
|
4731
|
+
MaterialDynamicColors.onSecondaryContainer = MaterialDynamicColors.colorSpec.onSecondaryContainer();
|
|
4732
|
+
/** @deprecated Use tertiary() instead. */
|
|
4733
|
+
MaterialDynamicColors.tertiary = MaterialDynamicColors.colorSpec.tertiary();
|
|
4734
|
+
/** @deprecated Use onTertiary() instead. */
|
|
4735
|
+
MaterialDynamicColors.onTertiary = MaterialDynamicColors.colorSpec.onTertiary();
|
|
4736
|
+
/** @deprecated Use tertiaryContainer() instead. */
|
|
4737
|
+
MaterialDynamicColors.tertiaryContainer = MaterialDynamicColors.colorSpec.tertiaryContainer();
|
|
4738
|
+
/** @deprecated Use onTertiaryContainer() instead. */
|
|
4739
|
+
MaterialDynamicColors.onTertiaryContainer = MaterialDynamicColors.colorSpec.onTertiaryContainer();
|
|
4740
|
+
/** @deprecated Use error() instead. */
|
|
4741
|
+
MaterialDynamicColors.error = MaterialDynamicColors.colorSpec.error();
|
|
4742
|
+
/** @deprecated Use onError() instead. */
|
|
4743
|
+
MaterialDynamicColors.onError = MaterialDynamicColors.colorSpec.onError();
|
|
4744
|
+
/** @deprecated Use errorContainer() instead. */
|
|
4745
|
+
MaterialDynamicColors.errorContainer = MaterialDynamicColors.colorSpec.errorContainer();
|
|
4746
|
+
/** @deprecated Use onErrorContainer() instead. */
|
|
4747
|
+
MaterialDynamicColors.onErrorContainer = MaterialDynamicColors.colorSpec.onErrorContainer();
|
|
4748
|
+
/** @deprecated Use primaryFixed() instead. */
|
|
4749
|
+
MaterialDynamicColors.primaryFixed = MaterialDynamicColors.colorSpec.primaryFixed();
|
|
4750
|
+
/** @deprecated Use primaryFixedDim() instead. */
|
|
4751
|
+
MaterialDynamicColors.primaryFixedDim = MaterialDynamicColors.colorSpec.primaryFixedDim();
|
|
4752
|
+
/** @deprecated Use onPrimaryFixed() instead. */
|
|
4753
|
+
MaterialDynamicColors.onPrimaryFixed = MaterialDynamicColors.colorSpec.onPrimaryFixed();
|
|
4754
|
+
/** @deprecated Use onPrimaryFixedVariant() instead. */
|
|
4755
|
+
MaterialDynamicColors.onPrimaryFixedVariant = MaterialDynamicColors.colorSpec.onPrimaryFixedVariant();
|
|
4756
|
+
/** @deprecated Use secondaryFixed() instead. */
|
|
4757
|
+
MaterialDynamicColors.secondaryFixed = MaterialDynamicColors.colorSpec.secondaryFixed();
|
|
4758
|
+
/** @deprecated Use secondaryFixedDim() instead. */
|
|
4759
|
+
MaterialDynamicColors.secondaryFixedDim = MaterialDynamicColors.colorSpec.secondaryFixedDim();
|
|
4760
|
+
/** @deprecated Use onSecondaryFixed() instead. */
|
|
4761
|
+
MaterialDynamicColors.onSecondaryFixed = MaterialDynamicColors.colorSpec.onSecondaryFixed();
|
|
4762
|
+
/** @deprecated Use onSecondaryFixedVariant() instead. */
|
|
4763
|
+
MaterialDynamicColors.onSecondaryFixedVariant = MaterialDynamicColors.colorSpec.onSecondaryFixedVariant();
|
|
4764
|
+
/** @deprecated Use tertiaryFixed() instead. */
|
|
4765
|
+
MaterialDynamicColors.tertiaryFixed = MaterialDynamicColors.colorSpec.tertiaryFixed();
|
|
4766
|
+
/** @deprecated Use tertiaryFixedDim() instead. */
|
|
4767
|
+
MaterialDynamicColors.tertiaryFixedDim = MaterialDynamicColors.colorSpec.tertiaryFixedDim();
|
|
4768
|
+
/** @deprecated Use onTertiaryFixed() instead. */
|
|
4769
|
+
MaterialDynamicColors.onTertiaryFixed = MaterialDynamicColors.colorSpec.onTertiaryFixed();
|
|
4770
|
+
/** @deprecated Use onTertiaryFixedVariant() instead. */
|
|
4771
|
+
MaterialDynamicColors.onTertiaryFixedVariant = MaterialDynamicColors.colorSpec.onTertiaryFixedVariant();
|
|
2633
4772
|
|
|
2634
4773
|
/**
|
|
2635
4774
|
* @license
|
|
@@ -2654,218 +4793,552 @@ MaterialDynamicColors.onTertiaryFixedVariant = DynamicColor.fromPalette({
|
|
|
2654
4793
|
* with the theme style. Used by DynamicColor to resolve into a color.
|
|
2655
4794
|
*/
|
|
2656
4795
|
class DynamicScheme {
|
|
4796
|
+
static maybeFallbackSpecVersion(specVersion, variant) {
|
|
4797
|
+
switch (variant) {
|
|
4798
|
+
case Variant.EXPRESSIVE:
|
|
4799
|
+
case Variant.VIBRANT:
|
|
4800
|
+
case Variant.TONAL_SPOT:
|
|
4801
|
+
case Variant.NEUTRAL:
|
|
4802
|
+
return specVersion;
|
|
4803
|
+
default:
|
|
4804
|
+
return '2021';
|
|
4805
|
+
}
|
|
4806
|
+
}
|
|
2657
4807
|
constructor(args) {
|
|
2658
|
-
this.sourceColorArgb = args.
|
|
4808
|
+
this.sourceColorArgb = args.sourceColorHct.toInt();
|
|
2659
4809
|
this.variant = args.variant;
|
|
2660
4810
|
this.contrastLevel = args.contrastLevel;
|
|
2661
4811
|
this.isDark = args.isDark;
|
|
2662
|
-
this.
|
|
2663
|
-
this.
|
|
2664
|
-
this.
|
|
2665
|
-
this.
|
|
2666
|
-
this.
|
|
2667
|
-
this.
|
|
2668
|
-
this.
|
|
4812
|
+
this.platform = args.platform ?? 'phone';
|
|
4813
|
+
this.specVersion = DynamicScheme.maybeFallbackSpecVersion(args.specVersion ?? '2021', this.variant);
|
|
4814
|
+
this.sourceColorHct = args.sourceColorHct;
|
|
4815
|
+
this.primaryPalette = args.primaryPalette ?? getSpec(this.specVersion).getPrimaryPalette(this.variant, args.sourceColorHct, this.isDark, this.platform, this.contrastLevel);
|
|
4816
|
+
this.secondaryPalette = args.secondaryPalette ?? getSpec(this.specVersion).getSecondaryPalette(this.variant, args.sourceColorHct, this.isDark, this.platform, this.contrastLevel);
|
|
4817
|
+
this.tertiaryPalette = args.tertiaryPalette ?? getSpec(this.specVersion).getTertiaryPalette(this.variant, args.sourceColorHct, this.isDark, this.platform, this.contrastLevel);
|
|
4818
|
+
this.neutralPalette = args.neutralPalette ?? getSpec(this.specVersion).getNeutralPalette(this.variant, args.sourceColorHct, this.isDark, this.platform, this.contrastLevel);
|
|
4819
|
+
this.neutralVariantPalette = args.neutralVariantPalette ?? getSpec(this.specVersion).getNeutralVariantPalette(this.variant, args.sourceColorHct, this.isDark, this.platform, this.contrastLevel);
|
|
4820
|
+
this.errorPalette = args.errorPalette ?? getSpec(this.specVersion).getErrorPalette(this.variant, args.sourceColorHct, this.isDark, this.platform, this.contrastLevel) ?? TonalPalette.fromHueAndChroma(25.0, 84.0);
|
|
4821
|
+
this.colors = new MaterialDynamicColors();
|
|
4822
|
+
}
|
|
4823
|
+
toString() {
|
|
4824
|
+
return `Scheme: ` + `variant=${Variant[this.variant]}, ` + `mode=${this.isDark ? 'dark' : 'light'}, ` + `platform=${this.platform}, ` + `contrastLevel=${this.contrastLevel.toFixed(1)}, ` + `seed=${this.sourceColorHct.toString()}, ` + `specVersion=${this.specVersion}`;
|
|
2669
4825
|
}
|
|
2670
4826
|
/**
|
|
2671
|
-
*
|
|
2672
|
-
*
|
|
2673
|
-
*
|
|
2674
|
-
*
|
|
2675
|
-
*
|
|
2676
|
-
*
|
|
2677
|
-
*
|
|
2678
|
-
*
|
|
4827
|
+
* Returns a new hue based on a piecewise function and input color hue.
|
|
4828
|
+
*
|
|
4829
|
+
* For example, for the following function:
|
|
4830
|
+
* result = 26 if 0 <= hue < 101
|
|
4831
|
+
* result = 39 if 101 <= hue < 210
|
|
4832
|
+
* result = 28 if 210 <= hue < 360
|
|
4833
|
+
*
|
|
4834
|
+
* call the function as:
|
|
4835
|
+
*
|
|
4836
|
+
* const hueBreakpoints = [0, 101, 210, 360];
|
|
4837
|
+
* const hues = [26, 39, 28];
|
|
4838
|
+
* const result = scheme.piecewise(hue, hueBreakpoints, hues);
|
|
4839
|
+
*
|
|
4840
|
+
* @param sourceColorHct The input value.
|
|
4841
|
+
* @param hueBreakpoints The breakpoints, in sorted order. No default lower or
|
|
4842
|
+
* upper bounds are assumed.
|
|
4843
|
+
* @param hues The hues that should be applied when source color's hue is >=
|
|
4844
|
+
* the same index in hueBrakpoints array, and < the hue at the next index
|
|
4845
|
+
* in hueBrakpoints array. Otherwise, the source color's hue is returned.
|
|
2679
4846
|
*/
|
|
2680
|
-
static
|
|
2681
|
-
const
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
return sanitizeDegreesDouble(sourceColor.hue + rotations[0]);
|
|
2687
|
-
}
|
|
2688
|
-
const size = hues.length;
|
|
2689
|
-
for (let i = 0; i <= size - 2; i++) {
|
|
2690
|
-
const thisHue = hues[i];
|
|
2691
|
-
const nextHue = hues[i + 1];
|
|
2692
|
-
if (thisHue < sourceHue && sourceHue < nextHue) {
|
|
2693
|
-
return sanitizeDegreesDouble(sourceHue + rotations[i]);
|
|
4847
|
+
static getPiecewiseHue(sourceColorHct, hueBreakpoints, hues) {
|
|
4848
|
+
const size = Math.min(hueBreakpoints.length - 1, hues.length);
|
|
4849
|
+
const sourceHue = sourceColorHct.hue;
|
|
4850
|
+
for (let i = 0; i < size; i++) {
|
|
4851
|
+
if (sourceHue >= hueBreakpoints[i] && sourceHue < hueBreakpoints[i + 1]) {
|
|
4852
|
+
return sanitizeDegreesDouble(hues[i]);
|
|
2694
4853
|
}
|
|
2695
4854
|
}
|
|
2696
|
-
//
|
|
2697
|
-
// rotation found using the arrays.
|
|
4855
|
+
// No condition matched, return the source hue.
|
|
2698
4856
|
return sourceHue;
|
|
2699
4857
|
}
|
|
4858
|
+
/**
|
|
4859
|
+
* Returns a shifted hue based on a piecewise function and input color hue.
|
|
4860
|
+
*
|
|
4861
|
+
* For example, for the following function:
|
|
4862
|
+
* result = hue + 26 if 0 <= hue < 101
|
|
4863
|
+
* result = hue - 39 if 101 <= hue < 210
|
|
4864
|
+
* result = hue + 28 if 210 <= hue < 360
|
|
4865
|
+
*
|
|
4866
|
+
* call the function as:
|
|
4867
|
+
*
|
|
4868
|
+
* const hueBreakpoints = [0, 101, 210, 360];
|
|
4869
|
+
* const hues = [26, -39, 28];
|
|
4870
|
+
* const result = scheme.getRotatedHue(hue, hueBreakpoints, hues);
|
|
4871
|
+
*
|
|
4872
|
+
* @param sourceColorHct the source color of the theme, in HCT.
|
|
4873
|
+
* @param hueBreakpoints The "breakpoints", i.e. the hues at which a rotation
|
|
4874
|
+
* should be apply. No default lower or upper bounds are assumed.
|
|
4875
|
+
* @param rotations The rotation that should be applied when source color's
|
|
4876
|
+
* hue is >= the same index in hues array, and < the hue at the next
|
|
4877
|
+
* index in hues array. Otherwise, the source color's hue is returned.
|
|
4878
|
+
*/
|
|
4879
|
+
static getRotatedHue(sourceColorHct, hueBreakpoints, rotations) {
|
|
4880
|
+
let rotation = DynamicScheme.getPiecewiseHue(sourceColorHct, hueBreakpoints, rotations);
|
|
4881
|
+
if (Math.min(hueBreakpoints.length - 1, rotations.length) <= 0) {
|
|
4882
|
+
// No condition matched, return the source hue.
|
|
4883
|
+
rotation = 0;
|
|
4884
|
+
}
|
|
4885
|
+
return sanitizeDegreesDouble(sourceColorHct.hue + rotation);
|
|
4886
|
+
}
|
|
2700
4887
|
getArgb(dynamicColor) {
|
|
2701
4888
|
return dynamicColor.getArgb(this);
|
|
2702
4889
|
}
|
|
2703
4890
|
getHct(dynamicColor) {
|
|
2704
4891
|
return dynamicColor.getHct(this);
|
|
2705
4892
|
}
|
|
4893
|
+
// Palette key colors
|
|
2706
4894
|
get primaryPaletteKeyColor() {
|
|
2707
|
-
return this.getArgb(
|
|
4895
|
+
return this.getArgb(this.colors.primaryPaletteKeyColor());
|
|
2708
4896
|
}
|
|
2709
4897
|
get secondaryPaletteKeyColor() {
|
|
2710
|
-
return this.getArgb(
|
|
4898
|
+
return this.getArgb(this.colors.secondaryPaletteKeyColor());
|
|
2711
4899
|
}
|
|
2712
4900
|
get tertiaryPaletteKeyColor() {
|
|
2713
|
-
return this.getArgb(
|
|
4901
|
+
return this.getArgb(this.colors.tertiaryPaletteKeyColor());
|
|
2714
4902
|
}
|
|
2715
4903
|
get neutralPaletteKeyColor() {
|
|
2716
|
-
return this.getArgb(
|
|
4904
|
+
return this.getArgb(this.colors.neutralPaletteKeyColor());
|
|
2717
4905
|
}
|
|
2718
4906
|
get neutralVariantPaletteKeyColor() {
|
|
2719
|
-
return this.getArgb(
|
|
4907
|
+
return this.getArgb(this.colors.neutralVariantPaletteKeyColor());
|
|
4908
|
+
}
|
|
4909
|
+
get errorPaletteKeyColor() {
|
|
4910
|
+
return this.getArgb(this.colors.errorPaletteKeyColor());
|
|
2720
4911
|
}
|
|
4912
|
+
// Surface colors
|
|
2721
4913
|
get background() {
|
|
2722
|
-
return this.getArgb(
|
|
4914
|
+
return this.getArgb(this.colors.background());
|
|
2723
4915
|
}
|
|
2724
4916
|
get onBackground() {
|
|
2725
|
-
return this.getArgb(
|
|
4917
|
+
return this.getArgb(this.colors.onBackground());
|
|
2726
4918
|
}
|
|
2727
4919
|
get surface() {
|
|
2728
|
-
return this.getArgb(
|
|
4920
|
+
return this.getArgb(this.colors.surface());
|
|
2729
4921
|
}
|
|
2730
4922
|
get surfaceDim() {
|
|
2731
|
-
return this.getArgb(
|
|
4923
|
+
return this.getArgb(this.colors.surfaceDim());
|
|
2732
4924
|
}
|
|
2733
4925
|
get surfaceBright() {
|
|
2734
|
-
return this.getArgb(
|
|
4926
|
+
return this.getArgb(this.colors.surfaceBright());
|
|
2735
4927
|
}
|
|
2736
4928
|
get surfaceContainerLowest() {
|
|
2737
|
-
return this.getArgb(
|
|
4929
|
+
return this.getArgb(this.colors.surfaceContainerLowest());
|
|
2738
4930
|
}
|
|
2739
4931
|
get surfaceContainerLow() {
|
|
2740
|
-
return this.getArgb(
|
|
4932
|
+
return this.getArgb(this.colors.surfaceContainerLow());
|
|
2741
4933
|
}
|
|
2742
4934
|
get surfaceContainer() {
|
|
2743
|
-
return this.getArgb(
|
|
4935
|
+
return this.getArgb(this.colors.surfaceContainer());
|
|
2744
4936
|
}
|
|
2745
4937
|
get surfaceContainerHigh() {
|
|
2746
|
-
return this.getArgb(
|
|
4938
|
+
return this.getArgb(this.colors.surfaceContainerHigh());
|
|
2747
4939
|
}
|
|
2748
4940
|
get surfaceContainerHighest() {
|
|
2749
|
-
return this.getArgb(
|
|
4941
|
+
return this.getArgb(this.colors.surfaceContainerHighest());
|
|
2750
4942
|
}
|
|
2751
4943
|
get onSurface() {
|
|
2752
|
-
return this.getArgb(
|
|
4944
|
+
return this.getArgb(this.colors.onSurface());
|
|
2753
4945
|
}
|
|
2754
4946
|
get surfaceVariant() {
|
|
2755
|
-
return this.getArgb(
|
|
4947
|
+
return this.getArgb(this.colors.surfaceVariant());
|
|
2756
4948
|
}
|
|
2757
4949
|
get onSurfaceVariant() {
|
|
2758
|
-
return this.getArgb(
|
|
4950
|
+
return this.getArgb(this.colors.onSurfaceVariant());
|
|
2759
4951
|
}
|
|
2760
4952
|
get inverseSurface() {
|
|
2761
|
-
return this.getArgb(
|
|
4953
|
+
return this.getArgb(this.colors.inverseSurface());
|
|
2762
4954
|
}
|
|
2763
4955
|
get inverseOnSurface() {
|
|
2764
|
-
return this.getArgb(
|
|
4956
|
+
return this.getArgb(this.colors.inverseOnSurface());
|
|
2765
4957
|
}
|
|
2766
4958
|
get outline() {
|
|
2767
|
-
return this.getArgb(
|
|
4959
|
+
return this.getArgb(this.colors.outline());
|
|
2768
4960
|
}
|
|
2769
4961
|
get outlineVariant() {
|
|
2770
|
-
return this.getArgb(
|
|
4962
|
+
return this.getArgb(this.colors.outlineVariant());
|
|
2771
4963
|
}
|
|
2772
4964
|
get shadow() {
|
|
2773
|
-
return this.getArgb(
|
|
4965
|
+
return this.getArgb(this.colors.shadow());
|
|
2774
4966
|
}
|
|
2775
4967
|
get scrim() {
|
|
2776
|
-
return this.getArgb(
|
|
4968
|
+
return this.getArgb(this.colors.scrim());
|
|
2777
4969
|
}
|
|
2778
4970
|
get surfaceTint() {
|
|
2779
|
-
return this.getArgb(
|
|
4971
|
+
return this.getArgb(this.colors.surfaceTint());
|
|
2780
4972
|
}
|
|
4973
|
+
// Primary colors
|
|
2781
4974
|
get primary() {
|
|
2782
|
-
return this.getArgb(
|
|
4975
|
+
return this.getArgb(this.colors.primary());
|
|
4976
|
+
}
|
|
4977
|
+
get primaryDim() {
|
|
4978
|
+
const primaryDim = this.colors.primaryDim();
|
|
4979
|
+
if (primaryDim === undefined) {
|
|
4980
|
+
throw new Error('`primaryDim` color is undefined prior to 2025 spec.');
|
|
4981
|
+
}
|
|
4982
|
+
return this.getArgb(primaryDim);
|
|
2783
4983
|
}
|
|
2784
4984
|
get onPrimary() {
|
|
2785
|
-
return this.getArgb(
|
|
4985
|
+
return this.getArgb(this.colors.onPrimary());
|
|
2786
4986
|
}
|
|
2787
4987
|
get primaryContainer() {
|
|
2788
|
-
return this.getArgb(
|
|
4988
|
+
return this.getArgb(this.colors.primaryContainer());
|
|
2789
4989
|
}
|
|
2790
4990
|
get onPrimaryContainer() {
|
|
2791
|
-
return this.getArgb(
|
|
4991
|
+
return this.getArgb(this.colors.onPrimaryContainer());
|
|
4992
|
+
}
|
|
4993
|
+
get primaryFixed() {
|
|
4994
|
+
return this.getArgb(this.colors.primaryFixed());
|
|
4995
|
+
}
|
|
4996
|
+
get primaryFixedDim() {
|
|
4997
|
+
return this.getArgb(this.colors.primaryFixedDim());
|
|
4998
|
+
}
|
|
4999
|
+
get onPrimaryFixed() {
|
|
5000
|
+
return this.getArgb(this.colors.onPrimaryFixed());
|
|
5001
|
+
}
|
|
5002
|
+
get onPrimaryFixedVariant() {
|
|
5003
|
+
return this.getArgb(this.colors.onPrimaryFixedVariant());
|
|
2792
5004
|
}
|
|
2793
5005
|
get inversePrimary() {
|
|
2794
|
-
return this.getArgb(
|
|
5006
|
+
return this.getArgb(this.colors.inversePrimary());
|
|
2795
5007
|
}
|
|
5008
|
+
// Secondary colors
|
|
2796
5009
|
get secondary() {
|
|
2797
|
-
return this.getArgb(
|
|
5010
|
+
return this.getArgb(this.colors.secondary());
|
|
5011
|
+
}
|
|
5012
|
+
get secondaryDim() {
|
|
5013
|
+
const secondaryDim = this.colors.secondaryDim();
|
|
5014
|
+
if (secondaryDim === undefined) {
|
|
5015
|
+
throw new Error('`secondaryDim` color is undefined prior to 2025 spec.');
|
|
5016
|
+
}
|
|
5017
|
+
return this.getArgb(secondaryDim);
|
|
2798
5018
|
}
|
|
2799
5019
|
get onSecondary() {
|
|
2800
|
-
return this.getArgb(
|
|
5020
|
+
return this.getArgb(this.colors.onSecondary());
|
|
2801
5021
|
}
|
|
2802
5022
|
get secondaryContainer() {
|
|
2803
|
-
return this.getArgb(
|
|
5023
|
+
return this.getArgb(this.colors.secondaryContainer());
|
|
2804
5024
|
}
|
|
2805
5025
|
get onSecondaryContainer() {
|
|
2806
|
-
return this.getArgb(
|
|
5026
|
+
return this.getArgb(this.colors.onSecondaryContainer());
|
|
5027
|
+
}
|
|
5028
|
+
get secondaryFixed() {
|
|
5029
|
+
return this.getArgb(this.colors.secondaryFixed());
|
|
5030
|
+
}
|
|
5031
|
+
get secondaryFixedDim() {
|
|
5032
|
+
return this.getArgb(this.colors.secondaryFixedDim());
|
|
5033
|
+
}
|
|
5034
|
+
get onSecondaryFixed() {
|
|
5035
|
+
return this.getArgb(this.colors.onSecondaryFixed());
|
|
2807
5036
|
}
|
|
5037
|
+
get onSecondaryFixedVariant() {
|
|
5038
|
+
return this.getArgb(this.colors.onSecondaryFixedVariant());
|
|
5039
|
+
}
|
|
5040
|
+
// Tertiary colors
|
|
2808
5041
|
get tertiary() {
|
|
2809
|
-
return this.getArgb(
|
|
5042
|
+
return this.getArgb(this.colors.tertiary());
|
|
5043
|
+
}
|
|
5044
|
+
get tertiaryDim() {
|
|
5045
|
+
const tertiaryDim = this.colors.tertiaryDim();
|
|
5046
|
+
if (tertiaryDim === undefined) {
|
|
5047
|
+
throw new Error('`tertiaryDim` color is undefined prior to 2025 spec.');
|
|
5048
|
+
}
|
|
5049
|
+
return this.getArgb(tertiaryDim);
|
|
2810
5050
|
}
|
|
2811
5051
|
get onTertiary() {
|
|
2812
|
-
return this.getArgb(
|
|
5052
|
+
return this.getArgb(this.colors.onTertiary());
|
|
2813
5053
|
}
|
|
2814
5054
|
get tertiaryContainer() {
|
|
2815
|
-
return this.getArgb(
|
|
5055
|
+
return this.getArgb(this.colors.tertiaryContainer());
|
|
2816
5056
|
}
|
|
2817
5057
|
get onTertiaryContainer() {
|
|
2818
|
-
return this.getArgb(
|
|
5058
|
+
return this.getArgb(this.colors.onTertiaryContainer());
|
|
5059
|
+
}
|
|
5060
|
+
get tertiaryFixed() {
|
|
5061
|
+
return this.getArgb(this.colors.tertiaryFixed());
|
|
5062
|
+
}
|
|
5063
|
+
get tertiaryFixedDim() {
|
|
5064
|
+
return this.getArgb(this.colors.tertiaryFixedDim());
|
|
2819
5065
|
}
|
|
5066
|
+
get onTertiaryFixed() {
|
|
5067
|
+
return this.getArgb(this.colors.onTertiaryFixed());
|
|
5068
|
+
}
|
|
5069
|
+
get onTertiaryFixedVariant() {
|
|
5070
|
+
return this.getArgb(this.colors.onTertiaryFixedVariant());
|
|
5071
|
+
}
|
|
5072
|
+
// Error colors
|
|
2820
5073
|
get error() {
|
|
2821
|
-
return this.getArgb(
|
|
5074
|
+
return this.getArgb(this.colors.error());
|
|
5075
|
+
}
|
|
5076
|
+
get errorDim() {
|
|
5077
|
+
const errorDim = this.colors.errorDim();
|
|
5078
|
+
if (errorDim === undefined) {
|
|
5079
|
+
throw new Error('`errorDim` color is undefined prior to 2025 spec.');
|
|
5080
|
+
}
|
|
5081
|
+
return this.getArgb(errorDim);
|
|
2822
5082
|
}
|
|
2823
5083
|
get onError() {
|
|
2824
|
-
return this.getArgb(
|
|
5084
|
+
return this.getArgb(this.colors.onError());
|
|
2825
5085
|
}
|
|
2826
5086
|
get errorContainer() {
|
|
2827
|
-
return this.getArgb(
|
|
5087
|
+
return this.getArgb(this.colors.errorContainer());
|
|
2828
5088
|
}
|
|
2829
5089
|
get onErrorContainer() {
|
|
2830
|
-
return this.getArgb(
|
|
5090
|
+
return this.getArgb(this.colors.onErrorContainer());
|
|
2831
5091
|
}
|
|
2832
|
-
|
|
2833
|
-
|
|
5092
|
+
}
|
|
5093
|
+
DynamicScheme.DEFAULT_SPEC_VERSION = '2021';
|
|
5094
|
+
DynamicScheme.DEFAULT_PLATFORM = 'phone';
|
|
5095
|
+
/**
|
|
5096
|
+
* A delegate for the palettes of a DynamicScheme in the 2021 spec.
|
|
5097
|
+
*/
|
|
5098
|
+
class DynamicSchemePalettesDelegateImpl2021 {
|
|
5099
|
+
//////////////////////////////////////////////////////////////////
|
|
5100
|
+
// Scheme Palettes //
|
|
5101
|
+
//////////////////////////////////////////////////////////////////
|
|
5102
|
+
getPrimaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5103
|
+
switch (variant) {
|
|
5104
|
+
case Variant.CONTENT:
|
|
5105
|
+
case Variant.FIDELITY:
|
|
5106
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, sourceColorHct.chroma);
|
|
5107
|
+
case Variant.FRUIT_SALAD:
|
|
5108
|
+
return TonalPalette.fromHueAndChroma(sanitizeDegreesDouble(sourceColorHct.hue - 50.0), 48.0);
|
|
5109
|
+
case Variant.MONOCHROME:
|
|
5110
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 0.0);
|
|
5111
|
+
case Variant.NEUTRAL:
|
|
5112
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 12.0);
|
|
5113
|
+
case Variant.RAINBOW:
|
|
5114
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 48.0);
|
|
5115
|
+
case Variant.TONAL_SPOT:
|
|
5116
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 36.0);
|
|
5117
|
+
case Variant.EXPRESSIVE:
|
|
5118
|
+
return TonalPalette.fromHueAndChroma(sanitizeDegreesDouble(sourceColorHct.hue + 240), 40);
|
|
5119
|
+
case Variant.VIBRANT:
|
|
5120
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 200.0);
|
|
5121
|
+
default:
|
|
5122
|
+
throw new Error(`Unsupported variant: ${variant}`);
|
|
5123
|
+
}
|
|
2834
5124
|
}
|
|
2835
|
-
|
|
2836
|
-
|
|
5125
|
+
getSecondaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5126
|
+
switch (variant) {
|
|
5127
|
+
case Variant.CONTENT:
|
|
5128
|
+
case Variant.FIDELITY:
|
|
5129
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, Math.max(sourceColorHct.chroma - 32.0, sourceColorHct.chroma * 0.5));
|
|
5130
|
+
case Variant.FRUIT_SALAD:
|
|
5131
|
+
return TonalPalette.fromHueAndChroma(sanitizeDegreesDouble(sourceColorHct.hue - 50.0), 36.0);
|
|
5132
|
+
case Variant.MONOCHROME:
|
|
5133
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 0.0);
|
|
5134
|
+
case Variant.NEUTRAL:
|
|
5135
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0);
|
|
5136
|
+
case Variant.RAINBOW:
|
|
5137
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16.0);
|
|
5138
|
+
case Variant.TONAL_SPOT:
|
|
5139
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16.0);
|
|
5140
|
+
case Variant.EXPRESSIVE:
|
|
5141
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 21, 51, 121, 151, 191, 271, 321, 360], [45, 95, 45, 20, 45, 90, 45, 45, 45]), 24.0);
|
|
5142
|
+
case Variant.VIBRANT:
|
|
5143
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 41, 61, 101, 131, 181, 251, 301, 360], [18, 15, 10, 12, 15, 18, 15, 12, 12]), 24.0);
|
|
5144
|
+
default:
|
|
5145
|
+
throw new Error(`Unsupported variant: ${variant}`);
|
|
5146
|
+
}
|
|
2837
5147
|
}
|
|
2838
|
-
|
|
2839
|
-
|
|
5148
|
+
getTertiaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5149
|
+
switch (variant) {
|
|
5150
|
+
case Variant.CONTENT:
|
|
5151
|
+
return TonalPalette.fromHct(DislikeAnalyzer.fixIfDisliked(new TemperatureCache(sourceColorHct).analogous(/* count= */3, /* divisions= */6)[2]));
|
|
5152
|
+
case Variant.FIDELITY:
|
|
5153
|
+
return TonalPalette.fromHct(DislikeAnalyzer.fixIfDisliked(new TemperatureCache(sourceColorHct).complement));
|
|
5154
|
+
case Variant.FRUIT_SALAD:
|
|
5155
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 36.0);
|
|
5156
|
+
case Variant.MONOCHROME:
|
|
5157
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 0.0);
|
|
5158
|
+
case Variant.NEUTRAL:
|
|
5159
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16.0);
|
|
5160
|
+
case Variant.RAINBOW:
|
|
5161
|
+
case Variant.TONAL_SPOT:
|
|
5162
|
+
return TonalPalette.fromHueAndChroma(sanitizeDegreesDouble(sourceColorHct.hue + 60.0), 24.0);
|
|
5163
|
+
case Variant.EXPRESSIVE:
|
|
5164
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 21, 51, 121, 151, 191, 271, 321, 360], [120, 120, 20, 45, 20, 15, 20, 120, 120]), 32.0);
|
|
5165
|
+
case Variant.VIBRANT:
|
|
5166
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 41, 61, 101, 131, 181, 251, 301, 360], [35, 30, 20, 25, 30, 35, 30, 25, 25]), 32.0);
|
|
5167
|
+
default:
|
|
5168
|
+
throw new Error(`Unsupported variant: ${variant}`);
|
|
5169
|
+
}
|
|
2840
5170
|
}
|
|
2841
|
-
|
|
2842
|
-
|
|
5171
|
+
getNeutralPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5172
|
+
switch (variant) {
|
|
5173
|
+
case Variant.CONTENT:
|
|
5174
|
+
case Variant.FIDELITY:
|
|
5175
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, sourceColorHct.chroma / 8.0);
|
|
5176
|
+
case Variant.FRUIT_SALAD:
|
|
5177
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 10.0);
|
|
5178
|
+
case Variant.MONOCHROME:
|
|
5179
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 0.0);
|
|
5180
|
+
case Variant.NEUTRAL:
|
|
5181
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 2.0);
|
|
5182
|
+
case Variant.RAINBOW:
|
|
5183
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 0.0);
|
|
5184
|
+
case Variant.TONAL_SPOT:
|
|
5185
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 6.0);
|
|
5186
|
+
case Variant.EXPRESSIVE:
|
|
5187
|
+
return TonalPalette.fromHueAndChroma(sanitizeDegreesDouble(sourceColorHct.hue + 15), 8);
|
|
5188
|
+
case Variant.VIBRANT:
|
|
5189
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 10);
|
|
5190
|
+
default:
|
|
5191
|
+
throw new Error(`Unsupported variant: ${variant}`);
|
|
5192
|
+
}
|
|
2843
5193
|
}
|
|
2844
|
-
|
|
2845
|
-
|
|
5194
|
+
getNeutralVariantPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5195
|
+
switch (variant) {
|
|
5196
|
+
case Variant.CONTENT:
|
|
5197
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, sourceColorHct.chroma / 8.0 + 4.0);
|
|
5198
|
+
case Variant.FIDELITY:
|
|
5199
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, sourceColorHct.chroma / 8.0 + 4.0);
|
|
5200
|
+
case Variant.FRUIT_SALAD:
|
|
5201
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16.0);
|
|
5202
|
+
case Variant.MONOCHROME:
|
|
5203
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 0.0);
|
|
5204
|
+
case Variant.NEUTRAL:
|
|
5205
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 2.0);
|
|
5206
|
+
case Variant.RAINBOW:
|
|
5207
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 0.0);
|
|
5208
|
+
case Variant.TONAL_SPOT:
|
|
5209
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 8.0);
|
|
5210
|
+
case Variant.EXPRESSIVE:
|
|
5211
|
+
return TonalPalette.fromHueAndChroma(sanitizeDegreesDouble(sourceColorHct.hue + 15), 12);
|
|
5212
|
+
case Variant.VIBRANT:
|
|
5213
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 12);
|
|
5214
|
+
default:
|
|
5215
|
+
throw new Error(`Unsupported variant: ${variant}`);
|
|
5216
|
+
}
|
|
2846
5217
|
}
|
|
2847
|
-
|
|
2848
|
-
return
|
|
5218
|
+
getErrorPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5219
|
+
return undefined;
|
|
2849
5220
|
}
|
|
2850
|
-
|
|
2851
|
-
|
|
5221
|
+
}
|
|
5222
|
+
/**
|
|
5223
|
+
* A delegate for the palettes of a DynamicScheme in the 2025 spec.
|
|
5224
|
+
*/
|
|
5225
|
+
class DynamicSchemePalettesDelegateImpl2025 extends DynamicSchemePalettesDelegateImpl2021 {
|
|
5226
|
+
//////////////////////////////////////////////////////////////////
|
|
5227
|
+
// Scheme Palettes //
|
|
5228
|
+
//////////////////////////////////////////////////////////////////
|
|
5229
|
+
getPrimaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5230
|
+
switch (variant) {
|
|
5231
|
+
case Variant.NEUTRAL:
|
|
5232
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, platform === 'phone' ? Hct.isBlue(sourceColorHct.hue) ? 12 : 8 : Hct.isBlue(sourceColorHct.hue) ? 16 : 12);
|
|
5233
|
+
case Variant.TONAL_SPOT:
|
|
5234
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, platform === 'phone' && isDark ? 26 : 32);
|
|
5235
|
+
case Variant.EXPRESSIVE:
|
|
5236
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, platform === 'phone' ? isDark ? 36 : 48 : 40);
|
|
5237
|
+
case Variant.VIBRANT:
|
|
5238
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, platform === 'phone' ? 74 : 56);
|
|
5239
|
+
default:
|
|
5240
|
+
return super.getPrimaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel);
|
|
5241
|
+
}
|
|
2852
5242
|
}
|
|
2853
|
-
|
|
2854
|
-
|
|
5243
|
+
getSecondaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5244
|
+
switch (variant) {
|
|
5245
|
+
case Variant.NEUTRAL:
|
|
5246
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, platform === 'phone' ? Hct.isBlue(sourceColorHct.hue) ? 6 : 4 : Hct.isBlue(sourceColorHct.hue) ? 10 : 6);
|
|
5247
|
+
case Variant.TONAL_SPOT:
|
|
5248
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, 16);
|
|
5249
|
+
case Variant.EXPRESSIVE:
|
|
5250
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 105, 140, 204, 253, 278, 300, 333, 360], [-160, 155, -100, 96, -96, -156, -165, -160]), platform === 'phone' ? isDark ? 16 : 24 : 24);
|
|
5251
|
+
case Variant.VIBRANT:
|
|
5252
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 38, 105, 140, 333, 360], [-14, 10, -14, 10, -14]), platform === 'phone' ? 56 : 36);
|
|
5253
|
+
default:
|
|
5254
|
+
return super.getSecondaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel);
|
|
5255
|
+
}
|
|
2855
5256
|
}
|
|
2856
|
-
|
|
2857
|
-
|
|
5257
|
+
getTertiaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5258
|
+
switch (variant) {
|
|
5259
|
+
case Variant.NEUTRAL:
|
|
5260
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 38, 105, 161, 204, 278, 333, 360], [-32, 26, 10, -39, 24, -15, -32]), platform === 'phone' ? 20 : 36);
|
|
5261
|
+
case Variant.TONAL_SPOT:
|
|
5262
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 20, 71, 161, 333, 360], [-40, 48, -32, 40, -32]), platform === 'phone' ? 28 : 32);
|
|
5263
|
+
case Variant.EXPRESSIVE:
|
|
5264
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 105, 140, 204, 253, 278, 300, 333, 360], [-165, 160, -105, 101, -101, -160, -170, -165]), 48);
|
|
5265
|
+
case Variant.VIBRANT:
|
|
5266
|
+
return TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, [0, 38, 71, 105, 140, 161, 253, 333, 360], [-72, 35, 24, -24, 62, 50, 62, -72]), 56);
|
|
5267
|
+
default:
|
|
5268
|
+
return super.getTertiaryPalette(variant, sourceColorHct, isDark, platform, contrastLevel);
|
|
5269
|
+
}
|
|
2858
5270
|
}
|
|
2859
|
-
|
|
2860
|
-
|
|
5271
|
+
static getExpressiveNeutralHue(sourceColorHct) {
|
|
5272
|
+
const hue = DynamicScheme.getRotatedHue(sourceColorHct, [0, 71, 124, 253, 278, 300, 360], [10, 0, 10, 0, 10, 0]);
|
|
5273
|
+
return hue;
|
|
5274
|
+
}
|
|
5275
|
+
static getExpressiveNeutralChroma(sourceColorHct, isDark, platform) {
|
|
5276
|
+
const neutralHue = DynamicSchemePalettesDelegateImpl2025.getExpressiveNeutralHue(sourceColorHct);
|
|
5277
|
+
return platform === 'phone' ? isDark ? Hct.isYellow(neutralHue) ? 6 : 14 : 18 : 12;
|
|
5278
|
+
}
|
|
5279
|
+
static getVibrantNeutralHue(sourceColorHct) {
|
|
5280
|
+
return DynamicScheme.getRotatedHue(sourceColorHct, [0, 38, 105, 140, 333, 360], [-14, 10, -14, 10, -14]);
|
|
5281
|
+
}
|
|
5282
|
+
static getVibrantNeutralChroma(sourceColorHct, platform) {
|
|
5283
|
+
const neutralHue = DynamicSchemePalettesDelegateImpl2025.getVibrantNeutralHue(sourceColorHct);
|
|
5284
|
+
return platform === 'phone' ? 28 : Hct.isBlue(neutralHue) ? 28 : 20;
|
|
5285
|
+
}
|
|
5286
|
+
getNeutralPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5287
|
+
switch (variant) {
|
|
5288
|
+
case Variant.NEUTRAL:
|
|
5289
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, platform === 'phone' ? 1.4 : 6);
|
|
5290
|
+
case Variant.TONAL_SPOT:
|
|
5291
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, platform === 'phone' ? 5 : 10);
|
|
5292
|
+
case Variant.EXPRESSIVE:
|
|
5293
|
+
return TonalPalette.fromHueAndChroma(DynamicSchemePalettesDelegateImpl2025.getExpressiveNeutralHue(sourceColorHct), DynamicSchemePalettesDelegateImpl2025.getExpressiveNeutralChroma(sourceColorHct, isDark, platform));
|
|
5294
|
+
case Variant.VIBRANT:
|
|
5295
|
+
return TonalPalette.fromHueAndChroma(DynamicSchemePalettesDelegateImpl2025.getVibrantNeutralHue(sourceColorHct), DynamicSchemePalettesDelegateImpl2025.getVibrantNeutralChroma(sourceColorHct, platform));
|
|
5296
|
+
default:
|
|
5297
|
+
return super.getNeutralPalette(variant, sourceColorHct, isDark, platform, contrastLevel);
|
|
5298
|
+
}
|
|
2861
5299
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
5300
|
+
getNeutralVariantPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5301
|
+
switch (variant) {
|
|
5302
|
+
case Variant.NEUTRAL:
|
|
5303
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, (platform === 'phone' ? 1.4 : 6) * 2.2);
|
|
5304
|
+
case Variant.TONAL_SPOT:
|
|
5305
|
+
return TonalPalette.fromHueAndChroma(sourceColorHct.hue, (platform === 'phone' ? 5 : 10) * 1.7);
|
|
5306
|
+
case Variant.EXPRESSIVE:
|
|
5307
|
+
const expressiveNeutralHue = DynamicSchemePalettesDelegateImpl2025.getExpressiveNeutralHue(sourceColorHct);
|
|
5308
|
+
const expressiveNeutralChroma = DynamicSchemePalettesDelegateImpl2025.getExpressiveNeutralChroma(sourceColorHct, isDark, platform);
|
|
5309
|
+
return TonalPalette.fromHueAndChroma(expressiveNeutralHue, expressiveNeutralChroma * (expressiveNeutralHue >= 105 && expressiveNeutralHue < 125 ? 1.6 : 2.3));
|
|
5310
|
+
case Variant.VIBRANT:
|
|
5311
|
+
const vibrantNeutralHue = DynamicSchemePalettesDelegateImpl2025.getVibrantNeutralHue(sourceColorHct);
|
|
5312
|
+
const vibrantNeutralChroma = DynamicSchemePalettesDelegateImpl2025.getVibrantNeutralChroma(sourceColorHct, platform);
|
|
5313
|
+
return TonalPalette.fromHueAndChroma(vibrantNeutralHue, vibrantNeutralChroma * 1.29);
|
|
5314
|
+
default:
|
|
5315
|
+
return super.getNeutralVariantPalette(variant, sourceColorHct, isDark, platform, contrastLevel);
|
|
5316
|
+
}
|
|
2864
5317
|
}
|
|
2865
|
-
|
|
2866
|
-
|
|
5318
|
+
getErrorPalette(variant, sourceColorHct, isDark, platform, contrastLevel) {
|
|
5319
|
+
const errorHue = DynamicScheme.getPiecewiseHue(sourceColorHct, [0, 3, 13, 23, 33, 43, 153, 273, 360], [12, 22, 32, 12, 22, 32, 22, 12]);
|
|
5320
|
+
switch (variant) {
|
|
5321
|
+
case Variant.NEUTRAL:
|
|
5322
|
+
return TonalPalette.fromHueAndChroma(errorHue, platform === 'phone' ? 50 : 40);
|
|
5323
|
+
case Variant.TONAL_SPOT:
|
|
5324
|
+
return TonalPalette.fromHueAndChroma(errorHue, platform === 'phone' ? 60 : 48);
|
|
5325
|
+
case Variant.EXPRESSIVE:
|
|
5326
|
+
return TonalPalette.fromHueAndChroma(errorHue, platform === 'phone' ? 64 : 48);
|
|
5327
|
+
case Variant.VIBRANT:
|
|
5328
|
+
return TonalPalette.fromHueAndChroma(errorHue, platform === 'phone' ? 80 : 60);
|
|
5329
|
+
default:
|
|
5330
|
+
return super.getErrorPalette(variant, sourceColorHct, isDark, platform, contrastLevel);
|
|
5331
|
+
}
|
|
2867
5332
|
}
|
|
2868
5333
|
}
|
|
5334
|
+
const spec2021 = new DynamicSchemePalettesDelegateImpl2021();
|
|
5335
|
+
const spec2025 = new DynamicSchemePalettesDelegateImpl2025();
|
|
5336
|
+
/**
|
|
5337
|
+
* Returns the DynamicSchemePalettesDelegate for the given spec version.
|
|
5338
|
+
*/
|
|
5339
|
+
function getSpec(specVersion) {
|
|
5340
|
+
return specVersion === '2025' ? spec2025 : spec2021;
|
|
5341
|
+
}
|
|
2869
5342
|
|
|
2870
5343
|
/**
|
|
2871
5344
|
* @license
|
|
@@ -2887,28 +5360,43 @@ class DynamicScheme {
|
|
|
2887
5360
|
* An intermediate concept between the key color for a UI theme, and a full
|
|
2888
5361
|
* color scheme. 5 sets of tones are generated, all except one use the same hue
|
|
2889
5362
|
* as the key color, and all vary in chroma.
|
|
5363
|
+
*
|
|
5364
|
+
* @deprecated Use {@link DynamicScheme} for color scheme generation.
|
|
5365
|
+
* Use {@link CorePalettes} for core palettes container class.
|
|
2890
5366
|
*/
|
|
2891
5367
|
class CorePalette {
|
|
2892
5368
|
/**
|
|
2893
5369
|
* @param argb ARGB representation of a color
|
|
5370
|
+
*
|
|
5371
|
+
* @deprecated Use {@link DynamicScheme} for color scheme generation.
|
|
5372
|
+
* Use {@link CorePalettes} for core palettes container class.
|
|
2894
5373
|
*/
|
|
2895
5374
|
static of(argb) {
|
|
2896
5375
|
return new CorePalette(argb, false);
|
|
2897
5376
|
}
|
|
2898
5377
|
/**
|
|
2899
5378
|
* @param argb ARGB representation of a color
|
|
5379
|
+
*
|
|
5380
|
+
* @deprecated Use {@link DynamicScheme} for color scheme generation.
|
|
5381
|
+
* Use {@link CorePalettes} for core palettes container class.
|
|
2900
5382
|
*/
|
|
2901
5383
|
static contentOf(argb) {
|
|
2902
5384
|
return new CorePalette(argb, true);
|
|
2903
5385
|
}
|
|
2904
5386
|
/**
|
|
2905
5387
|
* Create a [CorePalette] from a set of colors
|
|
5388
|
+
*
|
|
5389
|
+
* @deprecated Use {@link DynamicScheme} for color scheme generation.
|
|
5390
|
+
* Use {@link CorePalettes} for core palettes container class.
|
|
2906
5391
|
*/
|
|
2907
5392
|
static fromColors(colors) {
|
|
2908
5393
|
return CorePalette.createPaletteFromColors(false, colors);
|
|
2909
5394
|
}
|
|
2910
5395
|
/**
|
|
2911
5396
|
* Create a content [CorePalette] from a set of colors
|
|
5397
|
+
*
|
|
5398
|
+
* @deprecated Use {@link DynamicScheme} for color scheme generation.
|
|
5399
|
+
* Use {@link CorePalettes} for core palettes container class.
|
|
2912
5400
|
*/
|
|
2913
5401
|
static contentFromColors(colors) {
|
|
2914
5402
|
return CorePalette.createPaletteFromColors(true, colors);
|
|
@@ -3666,7 +6154,7 @@ class QuantizerCelebi {
|
|
|
3666
6154
|
|
|
3667
6155
|
/**
|
|
3668
6156
|
* @license
|
|
3669
|
-
* Copyright
|
|
6157
|
+
* Copyright 2021 Google LLC
|
|
3670
6158
|
*
|
|
3671
6159
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3672
6160
|
* you may not use this file except in compliance with the License.
|
|
@@ -3680,90 +6168,212 @@ class QuantizerCelebi {
|
|
|
3680
6168
|
* See the License for the specific language governing permissions and
|
|
3681
6169
|
* limitations under the License.
|
|
3682
6170
|
*/
|
|
6171
|
+
// This file is automatically generated. Do not modify it.
|
|
3683
6172
|
/**
|
|
3684
|
-
*
|
|
6173
|
+
* DEPRECATED. The `Scheme` class is deprecated in favor of `DynamicScheme`.
|
|
6174
|
+
* Please see
|
|
6175
|
+
* https://github.com/material-foundation/material-color-utilities/blob/main/make_schemes.md
|
|
6176
|
+
* for migration guidance.
|
|
6177
|
+
*
|
|
6178
|
+
* Represents a Material color scheme, a mapping of color roles to colors.
|
|
3685
6179
|
*/
|
|
3686
|
-
class
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
6180
|
+
class Scheme {
|
|
6181
|
+
get primary() {
|
|
6182
|
+
return this.props.primary;
|
|
6183
|
+
}
|
|
6184
|
+
get onPrimary() {
|
|
6185
|
+
return this.props.onPrimary;
|
|
6186
|
+
}
|
|
6187
|
+
get primaryContainer() {
|
|
6188
|
+
return this.props.primaryContainer;
|
|
6189
|
+
}
|
|
6190
|
+
get onPrimaryContainer() {
|
|
6191
|
+
return this.props.onPrimaryContainer;
|
|
6192
|
+
}
|
|
6193
|
+
get secondary() {
|
|
6194
|
+
return this.props.secondary;
|
|
6195
|
+
}
|
|
6196
|
+
get onSecondary() {
|
|
6197
|
+
return this.props.onSecondary;
|
|
6198
|
+
}
|
|
6199
|
+
get secondaryContainer() {
|
|
6200
|
+
return this.props.secondaryContainer;
|
|
6201
|
+
}
|
|
6202
|
+
get onSecondaryContainer() {
|
|
6203
|
+
return this.props.onSecondaryContainer;
|
|
6204
|
+
}
|
|
6205
|
+
get tertiary() {
|
|
6206
|
+
return this.props.tertiary;
|
|
6207
|
+
}
|
|
6208
|
+
get onTertiary() {
|
|
6209
|
+
return this.props.onTertiary;
|
|
6210
|
+
}
|
|
6211
|
+
get tertiaryContainer() {
|
|
6212
|
+
return this.props.tertiaryContainer;
|
|
6213
|
+
}
|
|
6214
|
+
get onTertiaryContainer() {
|
|
6215
|
+
return this.props.onTertiaryContainer;
|
|
6216
|
+
}
|
|
6217
|
+
get error() {
|
|
6218
|
+
return this.props.error;
|
|
6219
|
+
}
|
|
6220
|
+
get onError() {
|
|
6221
|
+
return this.props.onError;
|
|
6222
|
+
}
|
|
6223
|
+
get errorContainer() {
|
|
6224
|
+
return this.props.errorContainer;
|
|
6225
|
+
}
|
|
6226
|
+
get onErrorContainer() {
|
|
6227
|
+
return this.props.onErrorContainer;
|
|
6228
|
+
}
|
|
6229
|
+
get background() {
|
|
6230
|
+
return this.props.background;
|
|
6231
|
+
}
|
|
6232
|
+
get onBackground() {
|
|
6233
|
+
return this.props.onBackground;
|
|
6234
|
+
}
|
|
6235
|
+
get surface() {
|
|
6236
|
+
return this.props.surface;
|
|
6237
|
+
}
|
|
6238
|
+
get onSurface() {
|
|
6239
|
+
return this.props.onSurface;
|
|
6240
|
+
}
|
|
6241
|
+
get surfaceVariant() {
|
|
6242
|
+
return this.props.surfaceVariant;
|
|
6243
|
+
}
|
|
6244
|
+
get onSurfaceVariant() {
|
|
6245
|
+
return this.props.onSurfaceVariant;
|
|
6246
|
+
}
|
|
6247
|
+
get outline() {
|
|
6248
|
+
return this.props.outline;
|
|
6249
|
+
}
|
|
6250
|
+
get outlineVariant() {
|
|
6251
|
+
return this.props.outlineVariant;
|
|
6252
|
+
}
|
|
6253
|
+
get shadow() {
|
|
6254
|
+
return this.props.shadow;
|
|
6255
|
+
}
|
|
6256
|
+
get scrim() {
|
|
6257
|
+
return this.props.scrim;
|
|
6258
|
+
}
|
|
6259
|
+
get inverseSurface() {
|
|
6260
|
+
return this.props.inverseSurface;
|
|
6261
|
+
}
|
|
6262
|
+
get inverseOnSurface() {
|
|
6263
|
+
return this.props.inverseOnSurface;
|
|
6264
|
+
}
|
|
6265
|
+
get inversePrimary() {
|
|
6266
|
+
return this.props.inversePrimary;
|
|
6267
|
+
}
|
|
6268
|
+
/**
|
|
6269
|
+
* @param argb ARGB representation of a color.
|
|
6270
|
+
* @return Light Material color scheme, based on the color's hue.
|
|
6271
|
+
*/
|
|
6272
|
+
static light(argb) {
|
|
6273
|
+
return Scheme.lightFromCorePalette(CorePalette.of(argb));
|
|
6274
|
+
}
|
|
6275
|
+
/**
|
|
6276
|
+
* @param argb ARGB representation of a color.
|
|
6277
|
+
* @return Dark Material color scheme, based on the color's hue.
|
|
6278
|
+
*/
|
|
6279
|
+
static dark(argb) {
|
|
6280
|
+
return Scheme.darkFromCorePalette(CorePalette.of(argb));
|
|
6281
|
+
}
|
|
6282
|
+
/**
|
|
6283
|
+
* @param argb ARGB representation of a color.
|
|
6284
|
+
* @return Light Material content color scheme, based on the color's hue.
|
|
6285
|
+
*/
|
|
6286
|
+
static lightContent(argb) {
|
|
6287
|
+
return Scheme.lightFromCorePalette(CorePalette.contentOf(argb));
|
|
6288
|
+
}
|
|
6289
|
+
/**
|
|
6290
|
+
* @param argb ARGB representation of a color.
|
|
6291
|
+
* @return Dark Material content color scheme, based on the color's hue.
|
|
6292
|
+
*/
|
|
6293
|
+
static darkContent(argb) {
|
|
6294
|
+
return Scheme.darkFromCorePalette(CorePalette.contentOf(argb));
|
|
6295
|
+
}
|
|
6296
|
+
/**
|
|
6297
|
+
* Light scheme from core palette
|
|
6298
|
+
*/
|
|
6299
|
+
static lightFromCorePalette(core) {
|
|
6300
|
+
return new Scheme({
|
|
6301
|
+
primary: core.a1.tone(40),
|
|
6302
|
+
onPrimary: core.a1.tone(100),
|
|
6303
|
+
primaryContainer: core.a1.tone(90),
|
|
6304
|
+
onPrimaryContainer: core.a1.tone(10),
|
|
6305
|
+
secondary: core.a2.tone(40),
|
|
6306
|
+
onSecondary: core.a2.tone(100),
|
|
6307
|
+
secondaryContainer: core.a2.tone(90),
|
|
6308
|
+
onSecondaryContainer: core.a2.tone(10),
|
|
6309
|
+
tertiary: core.a3.tone(40),
|
|
6310
|
+
onTertiary: core.a3.tone(100),
|
|
6311
|
+
tertiaryContainer: core.a3.tone(90),
|
|
6312
|
+
onTertiaryContainer: core.a3.tone(10),
|
|
6313
|
+
error: core.error.tone(40),
|
|
6314
|
+
onError: core.error.tone(100),
|
|
6315
|
+
errorContainer: core.error.tone(90),
|
|
6316
|
+
onErrorContainer: core.error.tone(10),
|
|
6317
|
+
background: core.n1.tone(99),
|
|
6318
|
+
onBackground: core.n1.tone(10),
|
|
6319
|
+
surface: core.n1.tone(99),
|
|
6320
|
+
onSurface: core.n1.tone(10),
|
|
6321
|
+
surfaceVariant: core.n2.tone(90),
|
|
6322
|
+
onSurfaceVariant: core.n2.tone(30),
|
|
6323
|
+
outline: core.n2.tone(50),
|
|
6324
|
+
outlineVariant: core.n2.tone(80),
|
|
6325
|
+
shadow: core.n1.tone(0),
|
|
6326
|
+
scrim: core.n1.tone(0),
|
|
6327
|
+
inverseSurface: core.n1.tone(20),
|
|
6328
|
+
inverseOnSurface: core.n1.tone(95),
|
|
6329
|
+
inversePrimary: core.a1.tone(80)
|
|
3698
6330
|
});
|
|
3699
6331
|
}
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
* A Dynamic Color theme that maxes out colorfulness at each position in the
|
|
3735
|
-
* Primary Tonal Palette.
|
|
3736
|
-
*/
|
|
3737
|
-
class SchemeVibrant extends DynamicScheme {
|
|
3738
|
-
constructor(sourceColorHct, isDark, contrastLevel) {
|
|
3739
|
-
super({
|
|
3740
|
-
sourceColorArgb: sourceColorHct.toInt(),
|
|
3741
|
-
variant: Variant.VIBRANT,
|
|
3742
|
-
contrastLevel,
|
|
3743
|
-
isDark,
|
|
3744
|
-
primaryPalette: TonalPalette.fromHueAndChroma(sourceColorHct.hue, 200.0),
|
|
3745
|
-
secondaryPalette: TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, SchemeVibrant.hues, SchemeVibrant.secondaryRotations), 24.0),
|
|
3746
|
-
tertiaryPalette: TonalPalette.fromHueAndChroma(DynamicScheme.getRotatedHue(sourceColorHct, SchemeVibrant.hues, SchemeVibrant.tertiaryRotations), 32.0),
|
|
3747
|
-
neutralPalette: TonalPalette.fromHueAndChroma(sourceColorHct.hue, 10.0),
|
|
3748
|
-
neutralVariantPalette: TonalPalette.fromHueAndChroma(sourceColorHct.hue, 12.0)
|
|
6332
|
+
/**
|
|
6333
|
+
* Dark scheme from core palette
|
|
6334
|
+
*/
|
|
6335
|
+
static darkFromCorePalette(core) {
|
|
6336
|
+
return new Scheme({
|
|
6337
|
+
primary: core.a1.tone(80),
|
|
6338
|
+
onPrimary: core.a1.tone(20),
|
|
6339
|
+
primaryContainer: core.a1.tone(30),
|
|
6340
|
+
onPrimaryContainer: core.a1.tone(90),
|
|
6341
|
+
secondary: core.a2.tone(80),
|
|
6342
|
+
onSecondary: core.a2.tone(20),
|
|
6343
|
+
secondaryContainer: core.a2.tone(30),
|
|
6344
|
+
onSecondaryContainer: core.a2.tone(90),
|
|
6345
|
+
tertiary: core.a3.tone(80),
|
|
6346
|
+
onTertiary: core.a3.tone(20),
|
|
6347
|
+
tertiaryContainer: core.a3.tone(30),
|
|
6348
|
+
onTertiaryContainer: core.a3.tone(90),
|
|
6349
|
+
error: core.error.tone(80),
|
|
6350
|
+
onError: core.error.tone(20),
|
|
6351
|
+
errorContainer: core.error.tone(30),
|
|
6352
|
+
onErrorContainer: core.error.tone(80),
|
|
6353
|
+
background: core.n1.tone(10),
|
|
6354
|
+
onBackground: core.n1.tone(90),
|
|
6355
|
+
surface: core.n1.tone(10),
|
|
6356
|
+
onSurface: core.n1.tone(90),
|
|
6357
|
+
surfaceVariant: core.n2.tone(30),
|
|
6358
|
+
onSurfaceVariant: core.n2.tone(80),
|
|
6359
|
+
outline: core.n2.tone(60),
|
|
6360
|
+
outlineVariant: core.n2.tone(30),
|
|
6361
|
+
shadow: core.n1.tone(0),
|
|
6362
|
+
scrim: core.n1.tone(0),
|
|
6363
|
+
inverseSurface: core.n1.tone(90),
|
|
6364
|
+
inverseOnSurface: core.n1.tone(20),
|
|
6365
|
+
inversePrimary: core.a1.tone(40)
|
|
3749
6366
|
});
|
|
3750
6367
|
}
|
|
6368
|
+
constructor(props) {
|
|
6369
|
+
this.props = props;
|
|
6370
|
+
}
|
|
6371
|
+
toJSON() {
|
|
6372
|
+
return {
|
|
6373
|
+
...this.props
|
|
6374
|
+
};
|
|
6375
|
+
}
|
|
3751
6376
|
}
|
|
3752
|
-
/**
|
|
3753
|
-
* Hues (in degrees) used at breakpoints such that designers can specify a
|
|
3754
|
-
* hue rotation that occurs at a given break point.
|
|
3755
|
-
*/
|
|
3756
|
-
SchemeVibrant.hues = [0.0, 41.0, 61.0, 101.0, 131.0, 181.0, 251.0, 301.0, 360.0];
|
|
3757
|
-
/**
|
|
3758
|
-
* Hue rotations (in degrees) of the Secondary [TonalPalette],
|
|
3759
|
-
* corresponding to the breakpoints in [hues].
|
|
3760
|
-
*/
|
|
3761
|
-
SchemeVibrant.secondaryRotations = [18.0, 15.0, 10.0, 12.0, 15.0, 18.0, 15.0, 12.0, 12.0];
|
|
3762
|
-
/**
|
|
3763
|
-
* Hue rotations (in degrees) of the Tertiary [TonalPalette],
|
|
3764
|
-
* corresponding to the breakpoints in [hues].
|
|
3765
|
-
*/
|
|
3766
|
-
SchemeVibrant.tertiaryRotations = [35.0, 30.0, 20.0, 25.0, 30.0, 35.0, 30.0, 25.0, 25.0];
|
|
3767
6377
|
|
|
3768
6378
|
/**
|
|
3769
6379
|
* @license
|
|
@@ -4033,6 +6643,15 @@ async function sourceColorFromImage(image) {
|
|
|
4033
6643
|
image.onerror = errorCallback;
|
|
4034
6644
|
}
|
|
4035
6645
|
});
|
|
6646
|
+
return sourceColorFromImageBytes(imageBytes);
|
|
6647
|
+
}
|
|
6648
|
+
/**
|
|
6649
|
+
* Get the source color from image bytes.
|
|
6650
|
+
*
|
|
6651
|
+
* @param imageBytes The image bytes
|
|
6652
|
+
* @return Source color - the color most suitable for creating a UI theme
|
|
6653
|
+
*/
|
|
6654
|
+
function sourceColorFromImageBytes(imageBytes) {
|
|
4036
6655
|
// Convert Image data to Pixel Array
|
|
4037
6656
|
const pixels = [];
|
|
4038
6657
|
for (let i = 0; i < imageBytes.length; i += 4) {
|
|
@@ -4053,6 +6672,84 @@ async function sourceColorFromImage(image) {
|
|
|
4053
6672
|
return top;
|
|
4054
6673
|
}
|
|
4055
6674
|
|
|
6675
|
+
/**
|
|
6676
|
+
* @license
|
|
6677
|
+
* Copyright 2021 Google LLC
|
|
6678
|
+
*
|
|
6679
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6680
|
+
* you may not use this file except in compliance with the License.
|
|
6681
|
+
* You may obtain a copy of the License at
|
|
6682
|
+
*
|
|
6683
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
6684
|
+
*
|
|
6685
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
6686
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
6687
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
6688
|
+
* See the License for the specific language governing permissions and
|
|
6689
|
+
* limitations under the License.
|
|
6690
|
+
*/
|
|
6691
|
+
/**
|
|
6692
|
+
* Generate a theme from a source color
|
|
6693
|
+
*
|
|
6694
|
+
* @param source Source color
|
|
6695
|
+
* @param customColors Array of custom colors
|
|
6696
|
+
* @return Theme object
|
|
6697
|
+
*/
|
|
6698
|
+
function themeFromSourceColor(source, customColors = []) {
|
|
6699
|
+
const palette = CorePalette.of(source);
|
|
6700
|
+
return {
|
|
6701
|
+
source,
|
|
6702
|
+
schemes: {
|
|
6703
|
+
light: Scheme.light(source),
|
|
6704
|
+
dark: Scheme.dark(source)
|
|
6705
|
+
},
|
|
6706
|
+
palettes: {
|
|
6707
|
+
primary: palette.a1,
|
|
6708
|
+
secondary: palette.a2,
|
|
6709
|
+
tertiary: palette.a3,
|
|
6710
|
+
neutral: palette.n1,
|
|
6711
|
+
neutralVariant: palette.n2,
|
|
6712
|
+
error: palette.error
|
|
6713
|
+
},
|
|
6714
|
+
customColors: customColors.map(c => customColor(source, c))
|
|
6715
|
+
};
|
|
6716
|
+
}
|
|
6717
|
+
/**
|
|
6718
|
+
* Generate custom color group from source and target color
|
|
6719
|
+
*
|
|
6720
|
+
* @param source Source color
|
|
6721
|
+
* @param color Custom color
|
|
6722
|
+
* @return Custom color group
|
|
6723
|
+
*
|
|
6724
|
+
* @link https://m3.material.io/styles/color/the-color-system/color-roles
|
|
6725
|
+
*/
|
|
6726
|
+
function customColor(source, color) {
|
|
6727
|
+
let value = color.value;
|
|
6728
|
+
const from = value;
|
|
6729
|
+
const to = source;
|
|
6730
|
+
if (color.blend) {
|
|
6731
|
+
value = Blend.harmonize(from, to);
|
|
6732
|
+
}
|
|
6733
|
+
const palette = CorePalette.of(value);
|
|
6734
|
+
const tones = palette.a1;
|
|
6735
|
+
return {
|
|
6736
|
+
color,
|
|
6737
|
+
value,
|
|
6738
|
+
light: {
|
|
6739
|
+
color: tones.tone(40),
|
|
6740
|
+
onColor: tones.tone(100),
|
|
6741
|
+
colorContainer: tones.tone(90),
|
|
6742
|
+
onColorContainer: tones.tone(10)
|
|
6743
|
+
},
|
|
6744
|
+
dark: {
|
|
6745
|
+
color: tones.tone(80),
|
|
6746
|
+
onColor: tones.tone(20),
|
|
6747
|
+
colorContainer: tones.tone(30),
|
|
6748
|
+
onColorContainer: tones.tone(90)
|
|
6749
|
+
}
|
|
6750
|
+
};
|
|
6751
|
+
}
|
|
6752
|
+
|
|
4056
6753
|
/**
|
|
4057
6754
|
* Extracts the Material source color from an image and returns it as a hex string.
|
|
4058
6755
|
* @param {HTMLImageElement} image - A fully loaded image element. Pixel data is sampled to derive the source color.
|
|
@@ -4227,26 +6924,26 @@ _M3eThemeElement_colorSchemeChangeHandler = new WeakMap();
|
|
|
4227
6924
|
_M3eThemeElement_instances = new WeakSet();
|
|
4228
6925
|
_M3eThemeElement_apply = function _M3eThemeElement_apply(forceReflow) {
|
|
4229
6926
|
const color = argbFromHex(this.color);
|
|
4230
|
-
const
|
|
6927
|
+
const theme = themeFromSourceColor(color);
|
|
4231
6928
|
const scheme = new DynamicScheme({
|
|
4232
|
-
|
|
6929
|
+
sourceColorHct: Hct.fromInt(color),
|
|
4233
6930
|
variant: 1,
|
|
4234
6931
|
contrastLevel: __classPrivateFieldGet(this, _M3eThemeElement_instances, "m", _M3eThemeElement_getContrastLevel).call(this),
|
|
4235
6932
|
isDark: this.isDark,
|
|
4236
|
-
primaryPalette:
|
|
4237
|
-
secondaryPalette:
|
|
4238
|
-
tertiaryPalette:
|
|
4239
|
-
neutralPalette:
|
|
4240
|
-
neutralVariantPalette:
|
|
6933
|
+
primaryPalette: theme.palettes.primary,
|
|
6934
|
+
secondaryPalette: theme.palettes.secondary,
|
|
6935
|
+
tertiaryPalette: theme.palettes.tertiary,
|
|
6936
|
+
neutralPalette: theme.palettes.neutral,
|
|
6937
|
+
neutralVariantPalette: theme.palettes.neutralVariant,
|
|
6938
|
+
errorPalette: theme.palettes.error
|
|
4241
6939
|
});
|
|
4242
6940
|
let css = "";
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
}
|
|
6941
|
+
const colors = new MaterialDynamicColors();
|
|
6942
|
+
const allColors = [...colors.allColors, colors.surfaceVariant(), colors.shadow(), colors.scrim(), colors.surfaceTint()];
|
|
6943
|
+
for (const color of allColors) {
|
|
6944
|
+
const token = `--md-sys-color-${color.name.replace(/_/g, "-").toLowerCase()}`;
|
|
6945
|
+
const hex = hexFromArgb(color.getArgb(scheme));
|
|
6946
|
+
css += `${token}: ${hex};`;
|
|
4250
6947
|
}
|
|
4251
6948
|
if (this.motion === "expressive") {
|
|
4252
6949
|
css += "--md-sys-motion-spring-fast-spatial: 350ms cubic-bezier(0.42, 1.67, 0.21, 0.90);";
|
|
@@ -4311,6 +7008,55 @@ _M3eThemeElement_getContrastLevel = function _M3eThemeElement_getContrastLevel()
|
|
|
4311
7008
|
return 0;
|
|
4312
7009
|
}
|
|
4313
7010
|
};
|
|
7011
|
+
(() => {
|
|
7012
|
+
if (typeof window !== "undefined") {
|
|
7013
|
+
const composeCss = token => {
|
|
7014
|
+
let css = "";
|
|
7015
|
+
for (const key in token) {
|
|
7016
|
+
const cssVar = token[key].toString();
|
|
7017
|
+
if (!cssVar.startsWith("var(")) continue;
|
|
7018
|
+
const inner = cssVar.trim().slice(4, -1); // remove "var(" and ")"
|
|
7019
|
+
const [prop, fallback] = inner.split(/,(.+)/).map(s => s.trim());
|
|
7020
|
+
if (!prop.startsWith("--") || !fallback) continue;
|
|
7021
|
+
css += `${prop}:${fallback};`;
|
|
7022
|
+
}
|
|
7023
|
+
return css;
|
|
7024
|
+
};
|
|
7025
|
+
const omitKey = (obj, key) => {
|
|
7026
|
+
const {
|
|
7027
|
+
[key]: _unused,
|
|
7028
|
+
...rest
|
|
7029
|
+
} = obj;
|
|
7030
|
+
return rest;
|
|
7031
|
+
};
|
|
7032
|
+
let css = "";
|
|
7033
|
+
css += composeCss(DesignToken.typescale.standard.display.large);
|
|
7034
|
+
css += composeCss(DesignToken.typescale.standard.display.medium);
|
|
7035
|
+
css += composeCss(DesignToken.typescale.standard.display.small);
|
|
7036
|
+
css += composeCss(DesignToken.typescale.standard.headline.large);
|
|
7037
|
+
css += composeCss(DesignToken.typescale.standard.headline.medium);
|
|
7038
|
+
css += composeCss(DesignToken.typescale.standard.headline.small);
|
|
7039
|
+
css += composeCss(DesignToken.typescale.standard.title.large);
|
|
7040
|
+
css += composeCss(DesignToken.typescale.standard.title.medium);
|
|
7041
|
+
css += composeCss(DesignToken.typescale.standard.title.small);
|
|
7042
|
+
css += composeCss(DesignToken.typescale.standard.label.large);
|
|
7043
|
+
css += composeCss(DesignToken.typescale.standard.label.medium);
|
|
7044
|
+
css += composeCss(DesignToken.typescale.standard.label.small);
|
|
7045
|
+
css += composeCss(DesignToken.typescale.standard.body.large);
|
|
7046
|
+
css += composeCss(DesignToken.typescale.standard.body.medium);
|
|
7047
|
+
css += composeCss(DesignToken.typescale.standard.body.small);
|
|
7048
|
+
css += composeCss(DesignToken.elevation);
|
|
7049
|
+
css += composeCss(DesignToken.shape.corner.value);
|
|
7050
|
+
css += composeCss(omitKey(DesignToken.shape.corner, "value"));
|
|
7051
|
+
css += composeCss(DesignToken.motion.duration);
|
|
7052
|
+
css += composeCss(DesignToken.motion.easing);
|
|
7053
|
+
css += composeCss(DesignToken.motion.spring);
|
|
7054
|
+
css += composeCss(omitKey(DesignToken.density, "calc"));
|
|
7055
|
+
css += composeCss(DesignToken.measurement);
|
|
7056
|
+
css += composeCss(DesignToken.state);
|
|
7057
|
+
registerStyleSheet(unsafeCSS(`html{${css}}`));
|
|
7058
|
+
}
|
|
7059
|
+
})();
|
|
4314
7060
|
/** The styles of the element. */
|
|
4315
7061
|
M3eThemeElement.styles = css`:host { display: contents; }`;
|
|
4316
7062
|
__decorate([property()], M3eThemeElement.prototype, "color", void 0);
|