@wordpress/theme 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -9
- package/bin/generate-default-ramps/index.ts +49 -0
- package/bin/generate-primitive-tokens/index.ts +14 -9
- package/bin/terrazzo-plugin-ds-tokens-docs/index.ts +5 -24
- package/bin/terrazzo-plugin-figma-ds-token-manager/index.ts +11 -4
- package/bin/terrazzo-plugin-inline-alias-values/index.ts +84 -0
- package/bin/terrazzo-plugin-known-wpds-css-variables/index.ts +19 -39
- package/build/color-ramps/index.js +21 -39
- package/build/color-ramps/index.js.map +3 -3
- package/build/color-ramps/lib/color-utils.js +39 -0
- package/build/color-ramps/lib/color-utils.js.map +7 -0
- package/build/color-ramps/lib/constants.js +20 -27
- package/build/color-ramps/lib/constants.js.map +3 -3
- package/build/color-ramps/lib/default-ramps.js +220 -0
- package/build/color-ramps/lib/default-ramps.js.map +7 -0
- package/build/color-ramps/lib/find-color-with-constraints.js +60 -91
- package/build/color-ramps/lib/find-color-with-constraints.js.map +3 -3
- package/build/color-ramps/lib/index.js +77 -119
- package/build/color-ramps/lib/index.js.map +3 -3
- package/build/color-ramps/lib/ramp-configs.js +15 -14
- package/build/color-ramps/lib/ramp-configs.js.map +2 -2
- package/build/color-ramps/lib/register-color-spaces.js +7 -0
- package/build/color-ramps/lib/register-color-spaces.js.map +7 -0
- package/build/color-ramps/lib/taper-chroma.js +35 -27
- package/build/color-ramps/lib/taper-chroma.js.map +3 -3
- package/build/color-ramps/lib/types.js +2 -1
- package/build/color-ramps/lib/types.js.map +1 -1
- package/build/color-ramps/lib/utils.js +75 -11
- package/build/color-ramps/lib/utils.js.map +2 -2
- package/build/context.js +3 -2
- package/build/context.js.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +3 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/prebuilt/js/design-tokens.js +19 -11
- package/build/prebuilt/js/design-tokens.js.map +2 -2
- package/build/prebuilt/json/figma.json +165 -783
- package/build/prebuilt/ts/color-tokens.js +137 -0
- package/build/prebuilt/ts/color-tokens.js.map +7 -0
- package/build/private-apis.js +3 -2
- package/build/private-apis.js.map +1 -1
- package/build/theme-provider.js +19 -17
- package/build/theme-provider.js.map +4 -4
- package/build/token-id.js +30 -0
- package/build/token-id.js.map +7 -0
- package/build/types/css-modules.d.js +0 -1
- package/build/types.js +2 -1
- package/build/types.js.map +1 -1
- package/build/use-theme-provider-styles.js +67 -62
- package/build/use-theme-provider-styles.js.map +3 -3
- package/build-module/color-ramps/index.js +20 -28
- package/build-module/color-ramps/index.js.map +2 -2
- package/build-module/color-ramps/lib/color-utils.js +19 -0
- package/build-module/color-ramps/lib/color-utils.js.map +7 -0
- package/build-module/color-ramps/lib/constants.js +14 -11
- package/build-module/color-ramps/lib/constants.js.map +2 -2
- package/build-module/color-ramps/lib/default-ramps.js +196 -0
- package/build-module/color-ramps/lib/default-ramps.js.map +7 -0
- package/build-module/color-ramps/lib/find-color-with-constraints.js +61 -87
- package/build-module/color-ramps/lib/find-color-with-constraints.js.map +2 -2
- package/build-module/color-ramps/lib/index.js +85 -109
- package/build-module/color-ramps/lib/index.js.map +3 -3
- package/build-module/color-ramps/lib/ramp-configs.js +14 -13
- package/build-module/color-ramps/lib/ramp-configs.js.map +2 -2
- package/build-module/color-ramps/lib/register-color-spaces.js +7 -0
- package/build-module/color-ramps/lib/register-color-spaces.js.map +7 -0
- package/build-module/color-ramps/lib/taper-chroma.js +40 -16
- package/build-module/color-ramps/lib/taper-chroma.js.map +2 -2
- package/build-module/color-ramps/lib/utils.js +70 -6
- package/build-module/color-ramps/lib/utils.js.map +2 -2
- package/build-module/context.js +2 -1
- package/build-module/context.js.map +1 -1
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js +2 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/prebuilt/js/design-tokens.js +18 -10
- package/build-module/prebuilt/js/design-tokens.js.map +2 -2
- package/build-module/prebuilt/json/figma.json +165 -783
- package/build-module/prebuilt/ts/color-tokens.js +117 -0
- package/build-module/prebuilt/ts/color-tokens.js.map +7 -0
- package/build-module/private-apis.js +2 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/theme-provider.js +18 -6
- package/build-module/theme-provider.js.map +3 -3
- package/build-module/token-id.js +6 -0
- package/build-module/token-id.js.map +7 -0
- package/build-module/use-theme-provider-styles.js +69 -57
- package/build-module/use-theme-provider-styles.js.map +2 -2
- package/build-types/color-ramps/index.d.ts +9 -16
- package/build-types/color-ramps/index.d.ts.map +1 -1
- package/build-types/color-ramps/lib/color-utils.d.ts +22 -0
- package/build-types/color-ramps/lib/color-utils.d.ts.map +1 -0
- package/build-types/color-ramps/lib/constants.d.ts +7 -9
- package/build-types/color-ramps/lib/constants.d.ts.map +1 -1
- package/build-types/color-ramps/lib/default-ramps.d.ts +7 -0
- package/build-types/color-ramps/lib/default-ramps.d.ts.map +1 -0
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts +8 -7
- package/build-types/color-ramps/lib/find-color-with-constraints.d.ts.map +1 -1
- package/build-types/color-ramps/lib/index.d.ts +5 -2
- package/build-types/color-ramps/lib/index.d.ts.map +1 -1
- package/build-types/color-ramps/lib/register-color-spaces.d.ts +2 -0
- package/build-types/color-ramps/lib/register-color-spaces.d.ts.map +1 -0
- package/build-types/color-ramps/lib/taper-chroma.d.ts +7 -3
- package/build-types/color-ramps/lib/taper-chroma.d.ts.map +1 -1
- package/build-types/color-ramps/lib/utils.d.ts +28 -5
- package/build-types/color-ramps/lib/utils.d.ts.map +1 -1
- package/build-types/color-ramps/stories/index.story.d.ts.map +1 -1
- package/build-types/prebuilt/ts/color-tokens.d.ts +7 -0
- package/build-types/prebuilt/ts/color-tokens.d.ts.map +1 -0
- package/build-types/stories/index.story.d.ts.map +1 -1
- package/build-types/theme-provider.d.ts.map +1 -1
- package/build-types/token-id.d.ts +9 -0
- package/build-types/token-id.d.ts.map +1 -0
- package/build-types/use-theme-provider-styles.d.ts +4 -0
- package/build-types/use-theme-provider-styles.d.ts.map +1 -1
- package/docs/ds-tokens.md +22 -156
- package/package.json +19 -9
- package/src/color-ramps/index.ts +24 -41
- package/src/color-ramps/lib/color-utils.ts +34 -0
- package/src/color-ramps/lib/constants.ts +13 -9
- package/src/color-ramps/lib/default-ramps.ts +200 -0
- package/src/color-ramps/lib/find-color-with-constraints.ts +83 -116
- package/src/color-ramps/lib/index.ts +107 -145
- package/src/color-ramps/lib/ramp-configs.ts +3 -3
- package/src/color-ramps/lib/register-color-spaces.ts +13 -0
- package/src/color-ramps/lib/taper-chroma.ts +47 -19
- package/src/color-ramps/lib/utils.ts +117 -14
- package/src/color-ramps/stories/index.story.tsx +16 -22
- package/src/color-ramps/test/__snapshots__/index.test.ts.snap +45722 -376
- package/src/color-ramps/test/index.test.ts +68 -29
- package/src/prebuilt/css/design-tokens.css +88 -355
- package/src/prebuilt/js/design-tokens.js +17 -10
- package/src/prebuilt/json/figma.json +165 -783
- package/src/prebuilt/ts/color-tokens.ts +117 -0
- package/src/stories/index.story.tsx +4 -18
- package/src/test/token-id.test.ts +12 -0
- package/src/token-id.ts +9 -0
- package/src/use-theme-provider-styles.ts +67 -60
- package/terrazzo.config.ts +15 -12
- package/tokens/color.json +221 -69
- package/tokens/dimension.json +75 -0
- package/tsconfig.bin.json +13 -0
- package/tsconfig.bin.tsbuildinfo +1 -0
- package/tsconfig.json +6 -4
- package/tsconfig.src.json +9 -0
- package/tsconfig.src.tsbuildinfo +1 -0
- package/bin/build-tokens.js +0 -83
- package/build/color-ramps/lib/cache-utils.js +0 -57
- package/build/color-ramps/lib/cache-utils.js.map +0 -7
- package/build/prebuilt/ts/design-tokens.js +0 -354
- package/build/prebuilt/ts/design-tokens.js.map +0 -7
- package/build/style.module.css.js +0 -2
- package/build-module/color-ramps/lib/cache-utils.js +0 -31
- package/build-module/color-ramps/lib/cache-utils.js.map +0 -7
- package/build-module/prebuilt/ts/design-tokens.js +0 -334
- package/build-module/prebuilt/ts/design-tokens.js.map +0 -7
- package/build-module/style.module.css.js +0 -1
- package/build-style/style.css +0 -3
- package/build-types/color-ramps/lib/cache-utils.d.ts +0 -22
- package/build-types/color-ramps/lib/cache-utils.d.ts.map +0 -1
- package/build-types/prebuilt/ts/design-tokens.d.ts +0 -7
- package/build-types/prebuilt/ts/design-tokens.d.ts.map +0 -1
- package/src/color-ramps/lib/cache-utils.ts +0 -56
- package/src/prebuilt/ts/design-tokens.ts +0 -335
- package/tokens/spacing.json +0 -45
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// packages/theme/src/color-ramps/lib/ramp-configs.ts
|
|
2
|
+
var lightnessConstraintForegroundHighContrast = (direction) => direction === "lighter" ? 0.9551 : 0.235;
|
|
3
|
+
var lightnessConstraintForegroundMediumContrast = (direction) => direction === "lighter" ? 0.77 : 0.56;
|
|
4
|
+
var lightnessConstraintBgFill = (direction) => direction === "lighter" ? 0.67 : 0.45;
|
|
5
|
+
var BG_SURFACE_TAPER_CHROMA = {
|
|
5
6
|
alpha: 0.7
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
var FG_TAPER_CHROMA = {
|
|
8
9
|
alpha: 0.6,
|
|
9
10
|
kLight: 0.2,
|
|
10
11
|
kDark: 0.2
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
+
var STROKE_TAPER_CHROMA = {
|
|
13
14
|
alpha: 0.6,
|
|
14
15
|
radiusDark: 0.01,
|
|
15
16
|
radiusLight: 0.01,
|
|
16
17
|
kLight: 0.8,
|
|
17
18
|
kDark: 0.8
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
var ACCENT_SURFACE_TAPER_CHROMA = {
|
|
20
21
|
alpha: 0.75,
|
|
21
22
|
radiusDark: 0.01,
|
|
22
23
|
radiusLight: 0.01
|
|
23
24
|
};
|
|
24
|
-
|
|
25
|
+
var fgSurface4Config = {
|
|
25
26
|
contrast: {
|
|
26
27
|
reference: "surface3",
|
|
27
28
|
followDirection: "main",
|
|
@@ -31,13 +32,13 @@ const fgSurface4Config = {
|
|
|
31
32
|
lightness: lightnessConstraintForegroundHighContrast,
|
|
32
33
|
taperChromaOptions: FG_TAPER_CHROMA
|
|
33
34
|
};
|
|
34
|
-
|
|
35
|
+
var BG_RAMP_CONFIG = {
|
|
35
36
|
// Surface
|
|
36
37
|
surface1: {
|
|
37
38
|
contrast: {
|
|
38
39
|
reference: "surface2",
|
|
39
40
|
followDirection: "opposite",
|
|
40
|
-
target: 1.
|
|
41
|
+
target: 1.06,
|
|
41
42
|
ignoreWhenAdjustingSeed: true
|
|
42
43
|
},
|
|
43
44
|
taperChromaOptions: BG_SURFACE_TAPER_CHROMA
|
|
@@ -53,7 +54,7 @@ const BG_RAMP_CONFIG = {
|
|
|
53
54
|
contrast: {
|
|
54
55
|
reference: "surface2",
|
|
55
56
|
followDirection: "main",
|
|
56
|
-
target: 1.
|
|
57
|
+
target: 1.06
|
|
57
58
|
},
|
|
58
59
|
taperChromaOptions: BG_SURFACE_TAPER_CHROMA
|
|
59
60
|
},
|
|
@@ -61,7 +62,7 @@ const BG_RAMP_CONFIG = {
|
|
|
61
62
|
contrast: {
|
|
62
63
|
reference: "surface2",
|
|
63
64
|
followDirection: "main",
|
|
64
|
-
target: 1.
|
|
65
|
+
target: 1.12
|
|
65
66
|
},
|
|
66
67
|
taperChromaOptions: BG_SURFACE_TAPER_CHROMA
|
|
67
68
|
},
|
|
@@ -211,7 +212,7 @@ const BG_RAMP_CONFIG = {
|
|
|
211
212
|
taperChromaOptions: FG_TAPER_CHROMA
|
|
212
213
|
}
|
|
213
214
|
};
|
|
214
|
-
|
|
215
|
+
var ACCENT_RAMP_CONFIG = {
|
|
215
216
|
...BG_RAMP_CONFIG,
|
|
216
217
|
surface1: {
|
|
217
218
|
...BG_RAMP_CONFIG.surface1,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/ramp-configs.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RampStepConfig, RampConfig, RampDirection } from './types';\nimport type { TaperChromaOptions } from './taper-chroma';\n\nconst lightnessConstraintForegroundHighContrast = (\n\tdirection: RampDirection\n) =>\n\tdirection === 'lighter'\n\t\t? 0.9551 // lightness of #f0f0f0 (ie $gray-100)\n\t\t: 0.235; // lightness of #1e1e1e (ie $gray-900)\nconst lightnessConstraintForegroundMediumContrast = (\n\tdirection: RampDirection\n) =>\n\tdirection === 'lighter'\n\t\t? 0.77 // lightness of #b4b4b4\n\t\t: 0.56; // lightness of #747474\nconst lightnessConstraintBgFill = ( direction: RampDirection ) =>\n\tdirection === 'lighter'\n\t\t? 0.67 // lightness of #969696 (7:1 vs black)\n\t\t: 0.45; // lightness of #555555 (7:1 vs white)\n\nconst BG_SURFACE_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.7,\n};\nconst FG_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.6,\n\tkLight: 0.2,\n\tkDark: 0.2,\n};\nconst STROKE_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.6,\n\tradiusDark: 0.01,\n\tradiusLight: 0.01,\n\tkLight: 0.8,\n\tkDark: 0.8,\n};\nconst ACCENT_SURFACE_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.75,\n\tradiusDark: 0.01,\n\tradiusLight: 0.01,\n};\n\nconst fgSurface4Config: RampStepConfig = {\n\tcontrast: {\n\t\treference: 'surface3',\n\t\tfollowDirection: 'main',\n\t\ttarget: 7,\n\t\tpreferLighter: true,\n\t},\n\tlightness: lightnessConstraintForegroundHighContrast,\n\ttaperChromaOptions: FG_TAPER_CHROMA,\n};\n\nexport const BG_RAMP_CONFIG: RampConfig = {\n\t// Surface\n\tsurface1: {\n\t\tcontrast: {\n\t\t\treference: 'surface2',\n\t\t\tfollowDirection: 'opposite',\n\t\t\ttarget: 1.
|
|
5
|
-
"mappings": "AAMA,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { RampStepConfig, RampConfig, RampDirection } from './types';\nimport type { TaperChromaOptions } from './taper-chroma';\n\nconst lightnessConstraintForegroundHighContrast = (\n\tdirection: RampDirection\n) =>\n\tdirection === 'lighter'\n\t\t? 0.9551 // lightness of #f0f0f0 (ie $gray-100)\n\t\t: 0.235; // lightness of #1e1e1e (ie $gray-900)\nconst lightnessConstraintForegroundMediumContrast = (\n\tdirection: RampDirection\n) =>\n\tdirection === 'lighter'\n\t\t? 0.77 // lightness of #b4b4b4\n\t\t: 0.56; // lightness of #747474\nconst lightnessConstraintBgFill = ( direction: RampDirection ) =>\n\tdirection === 'lighter'\n\t\t? 0.67 // lightness of #969696 (7:1 vs black)\n\t\t: 0.45; // lightness of #555555 (7:1 vs white)\n\nconst BG_SURFACE_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.7,\n};\nconst FG_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.6,\n\tkLight: 0.2,\n\tkDark: 0.2,\n};\nconst STROKE_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.6,\n\tradiusDark: 0.01,\n\tradiusLight: 0.01,\n\tkLight: 0.8,\n\tkDark: 0.8,\n};\nconst ACCENT_SURFACE_TAPER_CHROMA: TaperChromaOptions = {\n\talpha: 0.75,\n\tradiusDark: 0.01,\n\tradiusLight: 0.01,\n};\n\nconst fgSurface4Config: RampStepConfig = {\n\tcontrast: {\n\t\treference: 'surface3',\n\t\tfollowDirection: 'main',\n\t\ttarget: 7,\n\t\tpreferLighter: true,\n\t},\n\tlightness: lightnessConstraintForegroundHighContrast,\n\ttaperChromaOptions: FG_TAPER_CHROMA,\n};\n\nexport const BG_RAMP_CONFIG: RampConfig = {\n\t// Surface\n\tsurface1: {\n\t\tcontrast: {\n\t\t\treference: 'surface2',\n\t\t\tfollowDirection: 'opposite',\n\t\t\ttarget: 1.06,\n\t\t\tignoreWhenAdjustingSeed: true,\n\t\t},\n\t\ttaperChromaOptions: BG_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface2: {\n\t\tcontrast: {\n\t\t\treference: 'seed',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1,\n\t\t},\n\t},\n\tsurface3: {\n\t\tcontrast: {\n\t\t\treference: 'surface2',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1.06,\n\t\t},\n\t\ttaperChromaOptions: BG_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface4: {\n\t\tcontrast: {\n\t\t\treference: 'surface2',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1.12,\n\t\t},\n\t\ttaperChromaOptions: BG_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface5: {\n\t\tcontrast: {\n\t\t\treference: 'surface2',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1.2,\n\t\t},\n\t\ttaperChromaOptions: BG_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface6: {\n\t\tcontrast: {\n\t\t\treference: 'surface2',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1.4,\n\t\t},\n\t\ttaperChromaOptions: BG_SURFACE_TAPER_CHROMA,\n\t},\n\t// Bg fill\n\tbgFill1: {\n\t\tcontrast: {\n\t\t\treference: 'surface2',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 4,\n\t\t},\n\t\tlightness: lightnessConstraintBgFill,\n\t},\n\tbgFill2: {\n\t\tcontrast: {\n\t\t\treference: 'bgFill1',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1.2,\n\t\t},\n\t},\n\tbgFillInverted1: {\n\t\tcontrast: {\n\t\t\treference: 'bgFillInverted2',\n\t\t\tfollowDirection: 'opposite',\n\t\t\ttarget: 1.2,\n\t\t},\n\t},\n\tbgFillInverted2: fgSurface4Config,\n\tbgFillDark: {\n\t\tcontrast: {\n\t\t\treference: 'surface3',\n\t\t\tfollowDirection: 'darker', // This is what causes the token to be always dark\n\t\t\ttarget: 7,\n\t\t\tignoreWhenAdjustingSeed: true,\n\t\t},\n\t\tlightness: lightnessConstraintForegroundHighContrast,\n\t\ttaperChromaOptions: FG_TAPER_CHROMA,\n\t},\n\t// Stroke\n\tstroke1: {\n\t\tcontrast: {\n\t\t\treference: 'stroke3',\n\t\t\tfollowDirection: 'opposite',\n\t\t\ttarget: 2.2,\n\t\t},\n\t\ttaperChromaOptions: STROKE_TAPER_CHROMA,\n\t},\n\tstroke2: {\n\t\tcontrast: {\n\t\t\treference: 'stroke3',\n\t\t\tfollowDirection: 'opposite',\n\t\t\ttarget: 1.5,\n\t\t},\n\t\ttaperChromaOptions: STROKE_TAPER_CHROMA,\n\t},\n\tstroke3: {\n\t\tcontrast: {\n\t\t\treference: 'surface3',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 3,\n\t\t},\n\t\ttaperChromaOptions: STROKE_TAPER_CHROMA,\n\t},\n\tstroke4: {\n\t\tcontrast: {\n\t\t\treference: 'stroke3',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1.5,\n\t\t},\n\t\ttaperChromaOptions: STROKE_TAPER_CHROMA,\n\t},\n\t// fgSurface\n\tfgSurface1: {\n\t\tcontrast: {\n\t\t\treference: 'surface3',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 2,\n\t\t\tpreferLighter: true,\n\t\t},\n\t\ttaperChromaOptions: FG_TAPER_CHROMA,\n\t},\n\tfgSurface2: {\n\t\tcontrast: {\n\t\t\treference: 'surface3',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 3,\n\t\t\tpreferLighter: true,\n\t\t},\n\t\ttaperChromaOptions: FG_TAPER_CHROMA,\n\t},\n\tfgSurface3: {\n\t\tcontrast: {\n\t\t\treference: 'surface3',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 4.5,\n\t\t\tpreferLighter: true,\n\t\t},\n\t\tlightness: lightnessConstraintForegroundMediumContrast,\n\t\ttaperChromaOptions: FG_TAPER_CHROMA,\n\t},\n\tfgSurface4: fgSurface4Config,\n\t// fgFill\n\tfgFill: {\n\t\tcontrast: {\n\t\t\treference: 'bgFill1',\n\t\t\tfollowDirection: 'best',\n\t\t\ttarget: 4.5,\n\t\t\tpreferLighter: true,\n\t\t},\n\t\tlightness: lightnessConstraintForegroundHighContrast,\n\t\ttaperChromaOptions: FG_TAPER_CHROMA,\n\t},\n\tfgFillInverted: {\n\t\tcontrast: {\n\t\t\treference: 'bgFillInverted1',\n\t\t\tfollowDirection: 'best',\n\t\t\ttarget: 4.5,\n\t\t\tpreferLighter: true,\n\t\t},\n\t\tlightness: lightnessConstraintForegroundHighContrast,\n\t\ttaperChromaOptions: FG_TAPER_CHROMA,\n\t},\n\tfgFillDark: {\n\t\tcontrast: {\n\t\t\treference: 'bgFillDark',\n\t\t\tfollowDirection: 'best',\n\t\t\ttarget: 4.5,\n\t\t\tpreferLighter: true,\n\t\t},\n\t\tlightness: lightnessConstraintForegroundHighContrast,\n\t\ttaperChromaOptions: FG_TAPER_CHROMA,\n\t},\n};\n\n// BG_RAMP: seed => surface2 => {bgFill, surface3 => all other tokens}\n// ACCENT_RAMP: seed => bgFill1 => surface2 => surface3 => all other tokens\nexport const ACCENT_RAMP_CONFIG: RampConfig = {\n\t...BG_RAMP_CONFIG,\n\tsurface1: {\n\t\t...BG_RAMP_CONFIG.surface1,\n\t\ttaperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface2: {\n\t\tcontrast: {\n\t\t\treference: 'bgFill1',\n\t\t\tfollowDirection: 'opposite',\n\t\t\ttarget: BG_RAMP_CONFIG.bgFill1.contrast.target,\n\t\t\tignoreWhenAdjustingSeed: true,\n\t\t},\n\t\ttaperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface3: {\n\t\t...BG_RAMP_CONFIG.surface3,\n\t\ttaperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface4: {\n\t\t...BG_RAMP_CONFIG.surface4,\n\t\ttaperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface5: {\n\t\t...BG_RAMP_CONFIG.surface5,\n\t\ttaperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,\n\t},\n\tsurface6: {\n\t\t...BG_RAMP_CONFIG.surface6,\n\t\ttaperChromaOptions: ACCENT_SURFACE_TAPER_CHROMA,\n\t},\n\tbgFill1: {\n\t\tcontrast: {\n\t\t\treference: 'seed',\n\t\t\tfollowDirection: 'main',\n\t\t\ttarget: 1,\n\t\t},\n\t},\n\tstroke1: {\n\t\t...BG_RAMP_CONFIG.stroke1,\n\t},\n\tstroke2: {\n\t\t...BG_RAMP_CONFIG.stroke2,\n\t},\n\tstroke3: {\n\t\t...BG_RAMP_CONFIG.stroke3,\n\t\tsameAsIfPossible: 'fgSurface3',\n\t\ttaperChromaOptions: undefined,\n\t},\n\tstroke4: {\n\t\t...BG_RAMP_CONFIG.stroke4,\n\t\ttaperChromaOptions: undefined,\n\t},\n\t// fgSurface: do not de-saturate\n\tfgSurface1: {\n\t\t...BG_RAMP_CONFIG.fgSurface1,\n\t\ttaperChromaOptions: undefined,\n\t},\n\tfgSurface2: {\n\t\t...BG_RAMP_CONFIG.fgSurface2,\n\t\ttaperChromaOptions: undefined,\n\t},\n\tfgSurface3: {\n\t\t...BG_RAMP_CONFIG.fgSurface3,\n\t\ttaperChromaOptions: undefined,\n\t\tsameAsIfPossible: 'bgFill1',\n\t},\n\tfgSurface4: {\n\t\t...BG_RAMP_CONFIG.fgSurface4,\n\t\ttaperChromaOptions: undefined,\n\t},\n};\n"],
|
|
5
|
+
"mappings": ";AAMA,IAAM,4CAA4C,CACjD,cAEA,cAAc,YACX,SACA;AACJ,IAAM,8CAA8C,CACnD,cAEA,cAAc,YACX,OACA;AACJ,I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AoB;AAAA,EACrB;AAAA,EACA,UAAU;AAAA,IACT,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA,EACA,UAAU;AAAA,IACT,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA,EACA,UAAU;AAAA,IACT,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA,EACA,UAAU;AAAA,IACT,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA,EACA,SAAS;AAAA,IACR,UAAU;AAAA,MACT,WAAW;AAAA,MACX,iBAAiB;AAAA,MACjB,QAAQ;AAAA,IACT;AAAA,EACD;AAAA,EACA,SAAS;AAAA,IACR,GAAG,eAAe;AAAA,EACnB;AAAA,EACA,SAAS;AAAA,IACR,GAAG,eAAe;AAAA,EACnB;AAAA,EACA,SAAS;AAAA,IACR,GAAG,eAAe;AAAA,IAClB,kBAAkB;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA,EACA,SAAS;AAAA,IACR,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA;AAAA,EAEA,YAAY;AAAA,IACX,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA,EACA,YAAY;AAAA,IACX,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AAAA,EACA,YAAY;AAAA,IACX,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,IACpB,kBAAkB;AAAA,EACnB;AAAA,EACA,YAAY;AAAA,IACX,GAAG,eAAe;AAAA,IAClB,oBAAoB;AAAA,EACrB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// packages/theme/src/color-ramps/lib/register-color-spaces.ts
|
|
2
|
+
import { ColorSpace, OKLCH, P3, sRGB, HSL } from "colorjs.io/fn";
|
|
3
|
+
ColorSpace.register(sRGB);
|
|
4
|
+
ColorSpace.register(OKLCH);
|
|
5
|
+
ColorSpace.register(P3);
|
|
6
|
+
ColorSpace.register(HSL);
|
|
7
|
+
//# sourceMappingURL=register-color-spaces.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/color-ramps/lib/register-color-spaces.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { ColorSpace, OKLCH, P3, sRGB, HSL } from 'colorjs.io/fn';\n\n// Ensures that all color spaces used in color ramps are registered globally, a\n// requirement for using colorjs.io's procedural API.\n//\n// See: https://colorjs.io/docs/procedural\nColorSpace.register( sRGB );\nColorSpace.register( OKLCH );\nColorSpace.register( P3 );\nColorSpace.register( HSL );\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,YAAY,OAAO,IAAI,MAAM,WAAW;AAMjD,WAAW,SAAU,IAAK;AAC1B,WAAW,SAAU,KAAM;AAC3B,WAAW,SAAU,EAAG;AACxB,WAAW,SAAU,GAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// packages/theme/src/color-ramps/lib/taper-chroma.ts
|
|
2
|
+
import {
|
|
3
|
+
get,
|
|
4
|
+
inGamut,
|
|
5
|
+
OKLCH,
|
|
6
|
+
P3,
|
|
7
|
+
sRGB
|
|
8
|
+
} from "colorjs.io/fn";
|
|
9
|
+
import "./register-color-spaces";
|
|
2
10
|
function taperChroma(seed, lTarget, options = {}) {
|
|
3
11
|
const gamut = options.gamut ?? "p3";
|
|
12
|
+
const gamutSpace = gamut === "p3" ? P3 : sRGB;
|
|
4
13
|
const alpha = options.alpha ?? 0.65;
|
|
5
14
|
const carry = options.carry ?? 0.5;
|
|
6
15
|
const cUpperBound = options.cUpperBound ?? 0.45;
|
|
@@ -9,23 +18,31 @@ function taperChroma(seed, lTarget, options = {}) {
|
|
|
9
18
|
const kLight = options.kLight ?? 0.85;
|
|
10
19
|
const kDark = options.kDark ?? 0.85;
|
|
11
20
|
const achromaEpsilon = options.achromaEpsilon ?? 5e-3;
|
|
12
|
-
const cSeed = Math.max(0, seed
|
|
13
|
-
let hSeed = Number(seed
|
|
21
|
+
const cSeed = Math.max(0, get(seed, [OKLCH, "c"]));
|
|
22
|
+
let hSeed = Number(get(seed, [OKLCH, "h"]));
|
|
14
23
|
const chromaIsTiny = cSeed < achromaEpsilon;
|
|
15
24
|
const hueIsInvalid = !Number.isFinite(hSeed);
|
|
16
25
|
if (chromaIsTiny || hueIsInvalid) {
|
|
17
26
|
if (typeof options.hueFallback === "number") {
|
|
18
27
|
hSeed = normalizeHue(options.hueFallback);
|
|
19
28
|
} else {
|
|
20
|
-
return
|
|
29
|
+
return {
|
|
30
|
+
spaceId: "oklch",
|
|
31
|
+
coords: [clamp01(lTarget), 0, 0]
|
|
32
|
+
};
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
|
-
const lSeed = clamp01(seed
|
|
24
|
-
const cmaxSeed = getCachedMaxChromaAtLH(
|
|
35
|
+
const lSeed = clamp01(get(seed, [OKLCH, "l"]));
|
|
36
|
+
const cmaxSeed = getCachedMaxChromaAtLH(
|
|
37
|
+
lSeed,
|
|
38
|
+
hSeed,
|
|
39
|
+
gamutSpace,
|
|
40
|
+
cUpperBound
|
|
41
|
+
);
|
|
25
42
|
const cmaxTarget = getCachedMaxChromaAtLH(
|
|
26
43
|
clamp01(lTarget),
|
|
27
44
|
hSeed,
|
|
28
|
-
|
|
45
|
+
gamutSpace,
|
|
29
46
|
cUpperBound
|
|
30
47
|
);
|
|
31
48
|
let seedRelative = 0;
|
|
@@ -41,10 +58,13 @@ function taperChroma(seed, lTarget, options = {}) {
|
|
|
41
58
|
});
|
|
42
59
|
let cPlanned = cWithCarry * t;
|
|
43
60
|
const lOut = clamp01(lTarget);
|
|
44
|
-
const candidate =
|
|
45
|
-
|
|
61
|
+
const candidate = {
|
|
62
|
+
spaceId: "oklch",
|
|
63
|
+
coords: [lOut, cPlanned, hSeed]
|
|
64
|
+
};
|
|
65
|
+
if (!inGamut(candidate, gamutSpace)) {
|
|
46
66
|
const cap = Math.min(cPlanned, cUpperBound);
|
|
47
|
-
cPlanned = getCachedMaxChromaAtLH(lOut, hSeed,
|
|
67
|
+
cPlanned = getCachedMaxChromaAtLH(lOut, hSeed, gamutSpace, cap);
|
|
48
68
|
}
|
|
49
69
|
cPlanned = Math.min(cPlanned, cSeed);
|
|
50
70
|
return { l: lOut, c: cPlanned };
|
|
@@ -80,7 +100,7 @@ function continuousTaper(seedL, targetL, opts) {
|
|
|
80
100
|
const w = raisedCosine(u > 1 ? 1 : u);
|
|
81
101
|
return 1 - (1 - opts.kDark) * w;
|
|
82
102
|
}
|
|
83
|
-
|
|
103
|
+
var maxChromaCache = /* @__PURE__ */ new Map();
|
|
84
104
|
function keyMax(l, h, gamut, cap) {
|
|
85
105
|
const lq = quantize(l, 1e-3);
|
|
86
106
|
const hq = quantize(normalizeHue(h), 0.1);
|
|
@@ -91,17 +111,18 @@ function quantize(x, step) {
|
|
|
91
111
|
const k = Math.round(x / step);
|
|
92
112
|
return k * step;
|
|
93
113
|
}
|
|
94
|
-
function getCachedMaxChromaAtLH(l, h,
|
|
114
|
+
function getCachedMaxChromaAtLH(l, h, gamutSpace, cap) {
|
|
115
|
+
const gamut = gamutSpace === P3 ? "p3" : "srgb";
|
|
95
116
|
const key = keyMax(l, h, gamut, cap);
|
|
96
117
|
const hit = maxChromaCache.get(key);
|
|
97
118
|
if (typeof hit === "number") {
|
|
98
119
|
return hit;
|
|
99
120
|
}
|
|
100
|
-
const computed = maxInGamutChromaAtLH(l, h,
|
|
121
|
+
const computed = maxInGamutChromaAtLH(l, h, gamutSpace, cap);
|
|
101
122
|
maxChromaCache.set(key, computed);
|
|
102
123
|
return computed;
|
|
103
124
|
}
|
|
104
|
-
function maxInGamutChromaAtLH(l, h,
|
|
125
|
+
function maxInGamutChromaAtLH(l, h, gamutSpace, cap) {
|
|
105
126
|
let lo = 0;
|
|
106
127
|
let hi = cap;
|
|
107
128
|
let ok = 0;
|
|
@@ -109,8 +130,11 @@ function maxInGamutChromaAtLH(l, h, gamut, cap) {
|
|
|
109
130
|
const hFixed = normalizeHue(h);
|
|
110
131
|
for (let i = 0; i < 18; i++) {
|
|
111
132
|
const mid = (lo + hi) / 2;
|
|
112
|
-
const probe =
|
|
113
|
-
|
|
133
|
+
const probe = {
|
|
134
|
+
spaceId: "oklch",
|
|
135
|
+
coords: [lFixed, mid, hFixed]
|
|
136
|
+
};
|
|
137
|
+
if (inGamut(probe, gamutSpace)) {
|
|
114
138
|
ok = mid;
|
|
115
139
|
lo = mid;
|
|
116
140
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/taper-chroma.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tget,\n\tinGamut,\n\tOKLCH,\n\tP3,\n\tsRGB,\n\ttype ColorTypes,\n\ttype ColorObject,\n} from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\n\nexport interface TaperChromaOptions {\n\tgamut?: 'p3' | 'srgb'; // target gamut (default \"p3\")\n\talpha?: number; // base fraction of Cmax at target (default 0.62)\n\tcarry?: number; // seed vividness carry exponent \u03B2 in [0..1] (default 0.5)\n\tcUpperBound?: number; // hard search cap for C (default 0.45)\n\t// Continuous taper around the seed (desaturate both sides slightly)\n\tradiusLight?: number; // distance in L where kLight is reached (default 0.20)\n\tradiusDark?: number; // distance in L where kDark is reached (default 0.20)\n\tkLight?: number; // floor multiplier near lighter side (default 0.85)\n\tkDark?: number; // floor multiplier near darker side (default 0.85)\n\t// Achromatic handling\n\thueFallback?: number; // degrees: if seed is achromatic and you still want color\n\tachromaEpsilon?: number; // \u2264 this chroma \u2192 treat as achromatic (default 0.005)\n}\n\n/**\n * Given the seed and the target lightness, tapers the chroma smoothly.\n * - C_intended = Cmax(Lt,H0) * alpha * (seedRelative^carry)\n * - Continuous taper vs |Lt - Ls| to softly reduce chroma for neighbors\n * - Downward-only clamp on C (preserve L & H)\n * @param seed\n * @param lTarget\n * @param options\n */\nexport function taperChroma(\n\tseed: ColorTypes, // already OKLCH\n\tlTarget: number, // [0..1]\n\toptions: TaperChromaOptions = {}\n): { l: number; c: number } | ColorObject {\n\tconst gamut = options.gamut ?? 'p3';\n\tconst gamutSpace = gamut === 'p3' ? P3 : sRGB;\n\tconst alpha = options.alpha ?? 0.65; // 0.7-0.8 works well for accent surface\n\tconst carry = options.carry ?? 0.5;\n\tconst cUpperBound = options.cUpperBound ?? 0.45;\n\tconst radiusLight = options.radiusLight ?? 0.2;\n\tconst radiusDark = options.radiusDark ?? 0.2;\n\tconst kLight = options.kLight ?? 0.85;\n\tconst kDark = options.kDark ?? 0.85;\n\tconst achromaEpsilon = options.achromaEpsilon ?? 0.005;\n\n\tconst cSeed = Math.max( 0, get( seed, [ OKLCH, 'c' ] ) );\n\tlet hSeed = Number( get( seed, [ OKLCH, 'h' ] ) );\n\n\tconst chromaIsTiny = cSeed < achromaEpsilon;\n\tconst hueIsInvalid = ! Number.isFinite( hSeed );\n\n\tif ( chromaIsTiny || hueIsInvalid ) {\n\t\tif ( typeof options.hueFallback === 'number' ) {\n\t\t\thSeed = normalizeHue( options.hueFallback );\n\t\t} else {\n\t\t\t// Respect achromatic intent: grayscale at target L\n\t\t\treturn {\n\t\t\t\tspaceId: 'oklch',\n\t\t\t\tcoords: [ clamp01( lTarget ), 0, 0 ],\n\t\t\t};\n\t\t}\n\t}\n\n\t// Capacity at seed and target\n\tconst lSeed = clamp01( get( seed, [ OKLCH, 'l' ] ) );\n\tconst cmaxSeed = getCachedMaxChromaAtLH(\n\t\tlSeed,\n\t\thSeed,\n\t\tgamutSpace,\n\t\tcUpperBound\n\t);\n\tconst cmaxTarget = getCachedMaxChromaAtLH(\n\t\tclamp01( lTarget ),\n\t\thSeed,\n\t\tgamutSpace,\n\t\tcUpperBound\n\t);\n\n\t// Seed vividness ratio (hue-fair normalization)\n\tlet seedRelative = 0;\n\tconst denom = cmaxSeed > 0 ? cmaxSeed : 1e-6;\n\tseedRelative = clamp01( cSeed / denom );\n\n\t// Intended chroma from local capacity, tempered by seed vividness\n\tconst cIntendedBase = alpha * cmaxTarget;\n\tconst cWithCarry =\n\t\tcIntendedBase * Math.pow( seedRelative, clamp01( carry ) );\n\n\t// Gentle, symmetric desaturation vs distance in L\n\tconst t = continuousTaper( lSeed, lTarget, {\n\t\tradiusLight,\n\t\tradiusDark,\n\t\tkLight,\n\t\tkDark,\n\t} );\n\tlet cPlanned = cWithCarry * t;\n\n\t// Downward-only clamp (preserve L & H)\n\tconst lOut = clamp01( lTarget );\n\tconst candidate: ColorTypes = {\n\t\tspaceId: 'oklch',\n\t\tcoords: [ lOut, cPlanned, hSeed ],\n\t};\n\tif ( ! inGamut( candidate, gamutSpace ) ) {\n\t\tconst cap = Math.min( cPlanned, cUpperBound );\n\t\tcPlanned = getCachedMaxChromaAtLH( lOut, hSeed, gamutSpace, cap );\n\t}\n\n\tcPlanned = Math.min( cPlanned, cSeed );\n\n\treturn { l: lOut, c: cPlanned };\n}\n\n/* ---------------- helpers & caches ---------------- */\n\nfunction clamp01( x: number ): number {\n\tif ( x < 0 ) {\n\t\treturn 0;\n\t}\n\tif ( x > 1 ) {\n\t\treturn 1;\n\t}\n\treturn x;\n}\nfunction normalizeHue( h: number ): number {\n\tlet hue = h % 360;\n\tif ( hue < 0 ) {\n\t\thue += 360;\n\t}\n\treturn hue;\n}\nfunction raisedCosine( u: number ): number {\n\tconst x = clamp01( u );\n\treturn 0.5 - 0.5 * Math.cos( Math.PI * x );\n}\n\n/**\n * smooth, distance-from-seed chroma taper (raised-cosine per side)\n * @param seedL\n * @param targetL\n * @param opts\n * @param opts.radiusLight\n * @param opts.radiusDark\n * @param opts.kLight\n * @param opts.kDark\n */\nfunction continuousTaper(\n\tseedL: number,\n\ttargetL: number,\n\topts: {\n\t\tradiusLight: number;\n\t\tradiusDark: number;\n\t\tkLight: number;\n\t\tkDark: number;\n\t}\n): number {\n\tconst d = targetL - seedL;\n\tif ( d >= 0 ) {\n\t\tconst u = opts.radiusLight > 0 ? Math.abs( d ) / opts.radiusLight : 1;\n\t\tconst w = raisedCosine( u > 1 ? 1 : u );\n\t\treturn 1 - ( 1 - opts.kLight ) * w;\n\t}\n\tconst u = opts.radiusDark > 0 ? Math.abs( d ) / opts.radiusDark : 1;\n\tconst w = raisedCosine( u > 1 ? 1 : u );\n\treturn 1 - ( 1 - opts.kDark ) * w;\n}\n\n/* ---- chroma-capacity queries with small caches ---- */\n\nconst maxChromaCache = new Map< string, number >();\n\nfunction keyMax(\n\tl: number,\n\th: number,\n\tgamut: 'p3' | 'srgb',\n\tcap: number\n): string {\n\t// Quantize to keep cache compact\n\tconst lq = quantize( l, 1e-3 );\n\tconst hq = quantize( normalizeHue( h ), 1e-1 );\n\tconst cq = quantize( cap, 1e-3 );\n\treturn `${ gamut }|L:${ lq }|H:${ hq }|cap:${ cq }`;\n}\nfunction quantize( x: number, step: number ): number {\n\tconst k = Math.round( x / step );\n\treturn k * step;\n}\n\nfunction getCachedMaxChromaAtLH(\n\tl: number,\n\th: number,\n\tgamutSpace: typeof P3 | typeof sRGB,\n\tcap: number\n): number {\n\tconst gamut = gamutSpace === P3 ? 'p3' : 'srgb';\n\tconst key = keyMax( l, h, gamut, cap );\n\tconst hit = maxChromaCache.get( key );\n\tif ( typeof hit === 'number' ) {\n\t\treturn hit;\n\t}\n\n\tconst computed = maxInGamutChromaAtLH( l, h, gamutSpace, cap );\n\tmaxChromaCache.set( key, computed );\n\treturn computed;\n}\n\n/**\n * Binary-search the max in-gamut chroma at fixed (L,H) in the target gamut\n * @param l\n * @param h\n * @param gamutSpace\n * @param cap\n */\nfunction maxInGamutChromaAtLH(\n\tl: number,\n\th: number,\n\tgamutSpace: typeof P3 | typeof sRGB,\n\tcap: number\n): number {\n\tlet lo = 0;\n\tlet hi = cap;\n\tlet ok = 0;\n\n\tconst lFixed = clamp01( l );\n\tconst hFixed = normalizeHue( h );\n\n\tfor ( let i = 0; i < 18; i++ ) {\n\t\tconst mid = ( lo + hi ) / 2;\n\t\tconst probe: ColorTypes = {\n\t\t\tspaceId: 'oklch',\n\t\t\tcoords: [ lFixed, mid, hFixed ],\n\t\t};\n\t\tif ( inGamut( probe, gamutSpace ) ) {\n\t\t\tok = mid;\n\t\t\tlo = mid;\n\t\t} else {\n\t\t\thi = mid;\n\t\t}\n\t}\n\treturn ok;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AAKP,OAAO;AA0BA,SAAS,YACf,MACA,SACA,UAA8B,CAAC,GACU;AACzC,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,aAAa,UAAU,OAAO,KAAK;AACzC,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,cAAc,QAAQ,eAAe;AAC3C,QAAM,aAAa,QAAQ,cAAc;AACzC,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,iBAAiB,QAAQ,kBAAkB;AAEjD,QAAM,QAAQ,KAAK,IAAK,GAAG,IAAK,MAAM,CAAE,OAAO,GAAI,CAAE,CAAE;AACvD,MAAI,QAAQ,OAAQ,IAAK,MAAM,CAAE,OAAO,GAAI,CAAE,CAAE;AAEhD,QAAM,eAAe,QAAQ;AAC7B,QAAM,eAAe,CAAE,OAAO,SAAU,KAAM;AAE9C,MAAK,gBAAgB,cAAe;AACnC,QAAK,OAAO,QAAQ,gBAAgB,UAAW;AAC9C,cAAQ,aAAc,QAAQ,WAAY;AAAA,IAC3C,OAAO;A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,GACA,GACA,YACA,KACS;AACT,MAAI,KAAK;AACT,MAAI,KAAK;AACT,MAAI,KAAK;AAET,QAAM,SAAS,QAAS,CAAE;AAC1B,QAAM,SAAS,aAAc,CAAE;AAE/B,WAAU,IAAI,GAAG,IAAI,IAAI,KAAM;AAC9B,UAAM,OAAQ,KAAK,MAAO;AAC1B,UAAM,QAAoB;AAAA,MACzB,SAAS;AAAA,MACT,QAAQ,CAAE,QAAQ,KAAK,MAAO;AAAA,IAC/B;AACA,QAAK,QAAS,OAAO,UAAW,GAAI;AACnC,WAAK;AACL,WAAK;AAAA,IACN,OAAO;AACN,WAAK;AAAA,IACN;AAAA,EACD;AACA,SAAO;AACR;",
|
|
6
6
|
"names": ["u", "w"]
|
|
7
7
|
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
// packages/theme/src/color-ramps/lib/utils.ts
|
|
2
|
+
import { toGamut, to, P3, OKLCH } from "colorjs.io/fn";
|
|
3
|
+
import "./register-color-spaces";
|
|
1
4
|
import {
|
|
2
5
|
WHITE,
|
|
3
6
|
BLACK,
|
|
4
7
|
UNIVERSAL_CONTRAST_TOPUP,
|
|
5
8
|
WHITE_TEXT_CONTRAST_MARGIN,
|
|
6
|
-
ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS
|
|
9
|
+
ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS,
|
|
10
|
+
MAX_BISECTION_ITERATIONS,
|
|
11
|
+
CONTRAST_EPSILON
|
|
7
12
|
} from "./constants";
|
|
8
|
-
import {
|
|
9
|
-
|
|
13
|
+
import { getContrast } from "./color-utils";
|
|
14
|
+
var clampToGamut = (c) => to(toGamut(c, { space: P3, method: "css" }), OKLCH);
|
|
10
15
|
function buildDependencyGraph(config) {
|
|
11
16
|
const dependencies = /* @__PURE__ */ new Map();
|
|
12
17
|
const dependents = /* @__PURE__ */ new Map();
|
|
@@ -59,9 +64,28 @@ function sortByDependency(config) {
|
|
|
59
64
|
visit("seed");
|
|
60
65
|
return result;
|
|
61
66
|
}
|
|
67
|
+
function stepsForStep(stepName, config) {
|
|
68
|
+
const result = /* @__PURE__ */ new Set();
|
|
69
|
+
function visit(step) {
|
|
70
|
+
if (step === "seed" || result.has(step)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const stepConfig = config[step];
|
|
74
|
+
if (!stepConfig) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
visit(stepConfig.contrast.reference);
|
|
78
|
+
if (stepConfig.sameAsIfPossible) {
|
|
79
|
+
visit(stepConfig.sameAsIfPossible);
|
|
80
|
+
}
|
|
81
|
+
result.add(step);
|
|
82
|
+
}
|
|
83
|
+
visit(stepName);
|
|
84
|
+
return Array.from(result);
|
|
85
|
+
}
|
|
62
86
|
function computeBetterFgColorDirection(seed, preferLighter) {
|
|
63
|
-
const contrastAgainstBlack =
|
|
64
|
-
const contrastAgainstWhite =
|
|
87
|
+
const contrastAgainstBlack = getContrast(seed, BLACK);
|
|
88
|
+
const contrastAgainstWhite = getContrast(seed, WHITE);
|
|
65
89
|
return contrastAgainstBlack > contrastAgainstWhite + (preferLighter ? WHITE_TEXT_CONTRAST_MARGIN : 0) ? { better: "darker", worse: "lighter" } : { better: "lighter", worse: "darker" };
|
|
66
90
|
}
|
|
67
91
|
function adjustContrastTarget(target) {
|
|
@@ -74,11 +98,51 @@ function clampAccentScaleReferenceLightness(rawLightness, direction) {
|
|
|
74
98
|
const thresholds = ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS[direction];
|
|
75
99
|
return Math.max(thresholds.min, Math.min(thresholds.max, rawLightness));
|
|
76
100
|
}
|
|
101
|
+
function solveWithBisect(calculateC, calculateValue, initLowerL, initLowerValue, initUpperL, initUpperValue) {
|
|
102
|
+
let lowerL = initLowerL;
|
|
103
|
+
let lowerValue = initLowerValue;
|
|
104
|
+
let lowerReplaced = false;
|
|
105
|
+
let upperL = initUpperL;
|
|
106
|
+
let upperValue = initUpperValue;
|
|
107
|
+
let upperReplaced = false;
|
|
108
|
+
let bestC;
|
|
109
|
+
let bestValue;
|
|
110
|
+
let iterations = 0;
|
|
111
|
+
while (true) {
|
|
112
|
+
iterations++;
|
|
113
|
+
const newL = (lowerL * upperValue - upperL * lowerValue) / (upperValue - lowerValue);
|
|
114
|
+
bestC = calculateC(newL);
|
|
115
|
+
bestValue = calculateValue(bestC);
|
|
116
|
+
if (Math.abs(bestValue) <= CONTRAST_EPSILON || iterations >= MAX_BISECTION_ITERATIONS) {
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
if (bestValue <= 0) {
|
|
120
|
+
lowerL = newL;
|
|
121
|
+
lowerValue = bestValue;
|
|
122
|
+
if (lowerReplaced) {
|
|
123
|
+
upperValue /= 2;
|
|
124
|
+
}
|
|
125
|
+
lowerReplaced = true;
|
|
126
|
+
upperReplaced = false;
|
|
127
|
+
} else {
|
|
128
|
+
upperL = newL;
|
|
129
|
+
upperValue = bestValue;
|
|
130
|
+
if (upperReplaced) {
|
|
131
|
+
lowerValue /= 2;
|
|
132
|
+
}
|
|
133
|
+
upperReplaced = true;
|
|
134
|
+
lowerReplaced = false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return bestC;
|
|
138
|
+
}
|
|
77
139
|
export {
|
|
78
140
|
adjustContrastTarget,
|
|
79
141
|
clampAccentScaleReferenceLightness,
|
|
80
142
|
clampToGamut,
|
|
81
143
|
computeBetterFgColorDirection,
|
|
82
|
-
|
|
144
|
+
solveWithBisect,
|
|
145
|
+
sortByDependency,
|
|
146
|
+
stepsForStep
|
|
83
147
|
};
|
|
84
148
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/color-ramps/lib/utils.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { toGamut, to, P3, OKLCH, type ColorTypes } from 'colorjs.io/fn';\n\n/**\n * Internal dependencies\n */\nimport './register-color-spaces';\nimport {\n\tWHITE,\n\tBLACK,\n\tUNIVERSAL_CONTRAST_TOPUP,\n\tWHITE_TEXT_CONTRAST_MARGIN,\n\tACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS,\n\tMAX_BISECTION_ITERATIONS,\n\tCONTRAST_EPSILON,\n} from './constants';\nimport type { Ramp, RampConfig, RampDirection } from './types';\nimport { getContrast } from './color-utils';\n\n/**\n * Make sure that a color is valid in the p3 gamut, and converts it to oklch.\n * @param c\n */\nexport const clampToGamut = ( c: ColorTypes ) =>\n\tto( toGamut( c, { space: P3, method: 'css' } ), OKLCH ); // map into Display-P3 using CSS OKLCH method\n\n/**\n * Build a dependency graph from the steps configuration\n * @param config - The steps configuration object\n */\nfunction buildDependencyGraph( config: RampConfig ): {\n\tdependencies: Map< keyof Ramp, ( keyof Ramp | 'seed' )[] >;\n\tdependents: Map< keyof Ramp | 'seed', ( keyof Ramp )[] >;\n} {\n\tconst dependencies = new Map< keyof Ramp, ( keyof Ramp | 'seed' )[] >();\n\tconst dependents = new Map< keyof Ramp | 'seed', ( keyof Ramp )[] >();\n\n\t// Initialize maps\n\tObject.keys( config ).forEach( ( step ) => {\n\t\tdependencies.set( step as keyof Ramp, [] );\n\t} );\n\tdependents.set( 'seed', [] );\n\tObject.keys( config ).forEach( ( step ) => {\n\t\tdependents.set( step as keyof Ramp, [] );\n\t} );\n\n\t// Build the graph\n\tObject.entries( config ).forEach( ( [ stepName, stepConfig ] ) => {\n\t\tconst step = stepName as keyof Ramp;\n\t\tconst reference = stepConfig.contrast.reference;\n\n\t\tdependencies.get( step )!.push( reference );\n\t\tdependents.get( reference )!.push( step );\n\n\t\t// Add dependency for sameAsIfPossible\n\t\tif ( stepConfig.sameAsIfPossible ) {\n\t\t\tdependencies.get( step )!.push( stepConfig.sameAsIfPossible );\n\t\t\tdependents.get( stepConfig.sameAsIfPossible )!.push( step );\n\t\t}\n\t} );\n\n\treturn { dependencies, dependents };\n}\n\n/**\n * Topologically sort steps based on their dependencies\n * @param config - The steps configuration object\n */\nexport function sortByDependency( config: RampConfig ): ( keyof Ramp )[] {\n\tconst { dependents } = buildDependencyGraph( config );\n\tconst result: ( keyof Ramp )[] = [];\n\tconst visited = new Set< keyof Ramp | 'seed' >();\n\tconst visiting = new Set< keyof Ramp | 'seed' >();\n\n\tfunction visit( node: keyof Ramp | 'seed' ): void {\n\t\tif ( visiting.has( node ) ) {\n\t\t\tthrow new Error(\n\t\t\t\t`Circular dependency detected involving step: ${ String(\n\t\t\t\t\tnode\n\t\t\t\t) }`\n\t\t\t);\n\t\t}\n\t\tif ( visited.has( node ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvisiting.add( node );\n\n\t\t// Visit all dependents (steps that depend on this node)\n\t\tconst nodeDependents = dependents.get( node ) || [];\n\t\tnodeDependents.forEach( ( dependent ) => {\n\t\t\tvisit( dependent );\n\t\t} );\n\n\t\tvisiting.delete( node );\n\t\tvisited.add( node );\n\n\t\t// Add to result only if it's a step (not 'seed')\n\t\tif ( node !== 'seed' ) {\n\t\t\tresult.unshift( node ); // Add to front for correct topological order\n\t\t}\n\t}\n\n\t// Start with seed - this will recursively visit all reachable nodes\n\tvisit( 'seed' );\n\n\treturn result;\n}\n/**\n * Return minimal set of steps that are needed to calculate `stepName` from the seed.\n * @param stepName Name of the step.\n * @param config Configuration of the ramp.\n * @return Array of steps that `stepName` depends on.\n */\nexport function stepsForStep(\n\tstepName: keyof Ramp,\n\tconfig: RampConfig\n): ( keyof Ramp )[] {\n\tconst result = new Set< keyof Ramp >();\n\tfunction visit( step: keyof Ramp | 'seed' ) {\n\t\tif ( step === 'seed' || result.has( step ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst stepConfig = config[ step ];\n\t\tif ( ! stepConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tvisit( stepConfig.contrast.reference );\n\t\tif ( stepConfig.sameAsIfPossible ) {\n\t\t\tvisit( stepConfig.sameAsIfPossible );\n\t\t}\n\n\t\tresult.add( step );\n\t}\n\tvisit( stepName );\n\treturn Array.from( result );\n}\n\n/**\n * Finds out whether a lighter or a darker foreground color achieves a better\n * contrast against the seed\n * @param seed\n * @param preferLighter Whether the check should favor white foreground color\n * @return An object with \"better\" and \"worse\" properties, each holding a\n * ramp direction value.\n */\nexport function computeBetterFgColorDirection(\n\tseed: ColorTypes,\n\tpreferLighter?: boolean\n): {\n\tbetter: RampDirection;\n\tworse: RampDirection;\n} {\n\tconst contrastAgainstBlack = getContrast( seed, BLACK );\n\tconst contrastAgainstWhite = getContrast( seed, WHITE );\n\n\treturn contrastAgainstBlack >\n\t\tcontrastAgainstWhite +\n\t\t\t( preferLighter ? WHITE_TEXT_CONTRAST_MARGIN : 0 )\n\t\t? { better: 'darker', worse: 'lighter' }\n\t\t: { better: 'lighter', worse: 'darker' };\n}\n\nexport function adjustContrastTarget( target: number ) {\n\tif ( target === 1 ) {\n\t\treturn 1;\n\t}\n\n\t// Add a little top up to take into account any rounding error and algo imprecisions.\n\treturn target + UNIVERSAL_CONTRAST_TOPUP;\n}\n\n/**\n * Prevent the accent scale from referencing a lightness value that\n * would prevent the algorithm from complying with the requirements\n * and cause it to generate unexpected results.\n * @param rawLightness\n * @param direction\n * @return The clamped lightness value\n */\nexport function clampAccentScaleReferenceLightness(\n\trawLightness: number,\n\tdirection: RampDirection\n) {\n\tconst thresholds = ACCENT_SCALE_BASE_LIGHTNESS_THRESHOLDS[ direction ];\n\treturn Math.max( thresholds.min, Math.min( thresholds.max, rawLightness ) );\n}\n\n/**\n * Find the value of of `L` (luminance) that produces a `C` (color) that has a\n * `value` (contrast delta) equal to zero.\n * @param calculateC Calculate `C` from a given `L`.\n * @param calculateValue Calculate value (delta) for a given `C`.\n * @param initLowerL Initial lower value of `L`.\n * @param initLowerValue Initial lower delta (negative).\n * @param initUpperL Initial upper value of `L`.\n * @param initUpperValue Initial upper delta (positive).\n * @return Resulting value of type `C`.\n */\nexport function solveWithBisect< C >(\n\tcalculateC: ( l: number ) => C,\n\tcalculateValue: ( t: C ) => number,\n\tinitLowerL: number,\n\tinitLowerValue: number,\n\tinitUpperL: number,\n\tinitUpperValue: number\n): C {\n\tlet lowerL = initLowerL;\n\tlet lowerValue = initLowerValue;\n\tlet lowerReplaced = false;\n\n\tlet upperL = initUpperL;\n\tlet upperValue = initUpperValue;\n\tlet upperReplaced = false;\n\n\tlet bestC: C;\n\tlet bestValue: number;\n\tlet iterations = 0;\n\n\twhile ( true ) {\n\t\titerations++;\n\n\t\t// Linear interpolation: find the point where a line would cross the zero axis.\n\t\tconst newL =\n\t\t\t( lowerL * upperValue - upperL * lowerValue ) /\n\t\t\t( upperValue - lowerValue );\n\n\t\tbestC = calculateC( newL );\n\t\tbestValue = calculateValue( bestC );\n\n\t\tif (\n\t\t\tMath.abs( bestValue ) <= CONTRAST_EPSILON ||\n\t\t\titerations >= MAX_BISECTION_ITERATIONS\n\t\t) {\n\t\t\tbreak;\n\t\t}\n\n\t\t// Update the lower/upper bracket values. When only one side is repeatedly updated,\n\t\t// apply so-called \"Illinois trick\" for faster convergence: halve the opposite value.\n\t\tif ( bestValue <= 0 ) {\n\t\t\tlowerL = newL;\n\t\t\tlowerValue = bestValue;\n\t\t\tif ( lowerReplaced ) {\n\t\t\t\tupperValue /= 2;\n\t\t\t}\n\t\t\tlowerReplaced = true;\n\t\t\tupperReplaced = false;\n\t\t} else {\n\t\t\tupperL = newL;\n\t\t\tupperValue = bestValue;\n\t\t\tif ( upperReplaced ) {\n\t\t\t\tlowerValue /= 2;\n\t\t\t}\n\t\t\tupperReplaced = true;\n\t\t\tlowerReplaced = false;\n\t\t}\n\t}\n\n\treturn bestC;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,SAAS,IAAI,IAAI,aAA8B;AAKxD,OAAO;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA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,YACA,gBACA,YACA,gBACA,YACA,gBACI;AACJ,MAAI,SAAS;AACb,MAAI,aAAa;AACjB,MAAI,gBAAgB;AAEpB,MAAI,SAAS;AACb,MAAI,aAAa;AACjB,MAAI,gBAAgB;AAEpB,MAAI;AACJ,MAAI;AACJ,MAAI,aAAa;AAEjB,SAAQ,MAAO;AACd;AAGA,UAAM,QACH,SAAS,aAAa,SAAS,eAC/B,aAAa;AAEhB,YAAQ,WAAY,IAAK;AACzB,gBAAY,eAAgB,KAAM;AAElC,QACC,KAAK,IAAK,SAAU,KAAK,oBACzB,cAAc,0BACb;AACD;AAAA,IACD;AAIA,QAAK,aAAa,GAAI;AACrB,eAAS;AACT,mBAAa;AACb,UAAK,eAAgB;AACpB,sBAAc;AAAA,MACf;AACA,sBAAgB;AAChB,sBAAgB;AAAA,IACjB,OAAO;AACN,eAAS;AACT,mBAAa;AACb,UAAK,eAAgB;AACpB,sBAAc;AAAA,MACf;AACA,sBAAgB;AAChB,sBAAgB;AAAA,IACjB;AAAA,EACD;AAEA,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/context.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/context.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ThemeProviderSettings } from './types';\n\ninterface ThemeContextType {\n\tresolvedSettings: ThemeProviderSettings;\n}\n\nexport const ThemeContext = createContext< ThemeContextType >( {\n\tresolvedSettings: {\n\t\tcolor: {},\n\t},\n} );\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,qBAAqB;AAWvB,
|
|
5
|
+
"mappings": ";AAGA,SAAS,qBAAqB;AAWvB,IAAM,eAAe,cAAmC;AAAA,EAC9D,kBAAkB;AAAA,IACjB,OAAO,CAAC;AAAA,EACT;AACD,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// packages/theme/src/lock-unlock.ts
|
|
1
2
|
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
|
|
2
|
-
|
|
3
|
+
var { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
3
4
|
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
|
4
5
|
"@wordpress/theme"
|
|
5
6
|
);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/lock-unlock.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/theme'\n\t);\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,wDAAwD;AAE1D,
|
|
5
|
+
"mappings": ";AAGA,SAAS,wDAAwD;AAE1D,IAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// packages/theme/src/prebuilt/js/design-tokens.js
|
|
1
2
|
var design_tokens_default = [
|
|
2
3
|
"--wpds-border-radius-x-small",
|
|
3
4
|
"--wpds-border-radius-small",
|
|
@@ -14,6 +15,8 @@ var design_tokens_default = [
|
|
|
14
15
|
"--wpds-color-bg-surface-info-weak",
|
|
15
16
|
"--wpds-color-bg-surface-warning",
|
|
16
17
|
"--wpds-color-bg-surface-warning-weak",
|
|
18
|
+
"--wpds-color-bg-surface-caution",
|
|
19
|
+
"--wpds-color-bg-surface-caution-weak",
|
|
17
20
|
"--wpds-color-bg-surface-error",
|
|
18
21
|
"--wpds-color-bg-surface-error-weak",
|
|
19
22
|
"--wpds-color-bg-interactive-neutral",
|
|
@@ -43,6 +46,16 @@ var design_tokens_default = [
|
|
|
43
46
|
"--wpds-color-bg-thumb-brand-disabled",
|
|
44
47
|
"--wpds-color-fg-content-neutral",
|
|
45
48
|
"--wpds-color-fg-content-neutral-weak",
|
|
49
|
+
"--wpds-color-fg-content-success",
|
|
50
|
+
"--wpds-color-fg-content-success-weak",
|
|
51
|
+
"--wpds-color-fg-content-info",
|
|
52
|
+
"--wpds-color-fg-content-info-weak",
|
|
53
|
+
"--wpds-color-fg-content-warning",
|
|
54
|
+
"--wpds-color-fg-content-warning-weak",
|
|
55
|
+
"--wpds-color-fg-content-caution",
|
|
56
|
+
"--wpds-color-fg-content-caution-weak",
|
|
57
|
+
"--wpds-color-fg-content-error",
|
|
58
|
+
"--wpds-color-fg-content-error-weak",
|
|
46
59
|
"--wpds-color-fg-interactive-neutral",
|
|
47
60
|
"--wpds-color-fg-interactive-neutral-active",
|
|
48
61
|
"--wpds-color-fg-interactive-neutral-disabled",
|
|
@@ -79,20 +92,15 @@ var design_tokens_default = [
|
|
|
79
92
|
"--wpds-color-stroke-interactive-brand-disabled",
|
|
80
93
|
"--wpds-color-stroke-interactive-error-strong",
|
|
81
94
|
"--wpds-color-stroke-focus-brand",
|
|
95
|
+
"--wpds-dimension-base",
|
|
96
|
+
"--wpds-dimension-padding-surface-x-small",
|
|
97
|
+
"--wpds-dimension-padding-surface-small",
|
|
98
|
+
"--wpds-dimension-padding-surface-medium",
|
|
99
|
+
"--wpds-dimension-padding-surface-large",
|
|
82
100
|
"--wpds-elevation-x-small",
|
|
83
101
|
"--wpds-elevation-small",
|
|
84
102
|
"--wpds-elevation-medium",
|
|
85
103
|
"--wpds-elevation-large",
|
|
86
|
-
"--wpds-spacing-05",
|
|
87
|
-
"--wpds-spacing-10",
|
|
88
|
-
"--wpds-spacing-15",
|
|
89
|
-
"--wpds-spacing-20",
|
|
90
|
-
"--wpds-spacing-30",
|
|
91
|
-
"--wpds-spacing-40",
|
|
92
|
-
"--wpds-spacing-50",
|
|
93
|
-
"--wpds-spacing-60",
|
|
94
|
-
"--wpds-spacing-70",
|
|
95
|
-
"--wpds-spacing-80",
|
|
96
104
|
"--wpds-font-family-heading",
|
|
97
105
|
"--wpds-font-family-body",
|
|
98
106
|
"--wpds-font-family-mono",
|