@motion-proto/live-tokens 0.60.0 → 0.61.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/CHANGELOG.md +46 -0
- package/dist-plugin/{chunk-XWXIMTWZ.js → chunk-7TQQTHI6.js} +10 -1
- package/dist-plugin/{chunk-LW4SR7AZ.js → chunk-O6GQ6GBH.js} +1 -1
- package/dist-plugin/{chunk-E5QYON4L.js → chunk-OIOXU7FR.js} +33 -2
- package/dist-plugin/generateColorsAndType/index.js +2 -2
- package/dist-plugin/index.cjs +135 -1
- package/dist-plugin/index.js +99 -4
- package/dist-plugin/tokensCssMigrations/index.cjs +32 -1
- package/dist-plugin/tokensCssMigrations/index.js +2 -2
- package/package.json +6 -1
- package/src/editor/component-editor/ImageLightboxEditor.svelte +2 -1
- package/src/editor/docs/Docs.svelte +1 -0
- package/src/editor/docs/chapters.ts +1 -0
- package/src/editor/docs/content/light-and-dark.md +90 -0
- package/src/editor/docs/content.generated.ts +1 -0
- package/src/live-tokens/data/themes/autumn.json +1 -0
- package/src/live-tokens/data/themes/halloween.json +1 -0
- package/src/live-tokens/data/themes/midnight-study.json +1 -0
- package/src/live-tokens/data/themes/ocean.json +1 -0
- package/src/live-tokens/data/themes/royal-velvet.json +1 -0
- package/src/live-tokens/data/themes/sketchy.json +1 -0
- package/src/live-tokens/data/themes/spring-meadow.json +1 -0
- package/src/live-tokens/data/themes/sunset.json +1 -0
- package/src/live-tokens/data/tokens.generated.css +5 -0
- package/src/system/backdrop/backdrop.ts +197 -0
- package/src/system/backdrop/index.ts +16 -0
- package/src/system/backdrop/watch.ts +139 -0
- package/src/system/components/FloatingTokenTags.svelte +1 -1
- package/src/system/components/ImageLightbox.svelte +4 -3
- package/src/system/components/SectionDivider.svelte +3 -2
- package/src/system/styles/tokens.css +20 -0
- package/src/system/internal/backgroundContrast.ts +0 -62
|
@@ -6,6 +6,26 @@
|
|
|
6
6
|
font-family: var(--font-sans);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/* BACKDROP POLARITY — one attribute says which way a surface leans. State it
|
|
10
|
+
in markup (`<section data-backdrop="dark">`) or let `use:backdrop` measure
|
|
11
|
+
and stamp it. Either way `light-dark()` inside resolves the right half, and
|
|
12
|
+
a rule can key on the attribute for what colour alone cannot carry. */
|
|
13
|
+
|
|
14
|
+
[data-backdrop='light'] {
|
|
15
|
+
color-scheme: light;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
[data-backdrop='dark'] {
|
|
19
|
+
color-scheme: dark;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* The look this file ships is dark. Zero specificity: it is the answer before
|
|
23
|
+
a theme is baked and before `use:backdrop` has measured anything, and it
|
|
24
|
+
must lose to both. */
|
|
25
|
+
:where(:root) {
|
|
26
|
+
color-scheme: dark;
|
|
27
|
+
}
|
|
28
|
+
|
|
9
29
|
:root {
|
|
10
30
|
/* Invariants. Never themed; not part of any ramp. */
|
|
11
31
|
--color-white: oklch(1 0 0);
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { parseOklchCss, oklchToRgb255 } from './oklch';
|
|
2
|
-
|
|
3
|
-
export type ContrastColorToken = '--color-black' | '--color-white';
|
|
4
|
-
|
|
5
|
-
type Rgb = { r: number; g: number; b: number };
|
|
6
|
-
|
|
7
|
-
const HEX_RE = /#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})\b/gi;
|
|
8
|
-
const OKLCH_RE = /oklch\(\s*[\d.]+%?\s+[\d.]+%?\s+[\d.]+(?:deg)?\s*\)/gi;
|
|
9
|
-
const RGB_RE = /rgba?\(\s*([\d.]+%?)\s*[, ]\s*([\d.]+%?)\s*[, ]\s*([\d.]+%?)(?:\s*[,/]\s*[\d.]+%?)?\s*\)/gi;
|
|
10
|
-
|
|
11
|
-
function channel(value: string): number {
|
|
12
|
-
const parsed = Number.parseFloat(value);
|
|
13
|
-
return value.endsWith('%') ? parsed * 2.55 : parsed;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function parseHex(hex: string): Rgb {
|
|
17
|
-
const full = hex.length <= 4
|
|
18
|
-
? hex.slice(1).split('').map(part => part + part).join('')
|
|
19
|
-
: hex.slice(1, 7);
|
|
20
|
-
return {
|
|
21
|
-
r: Number.parseInt(full.slice(0, 2), 16),
|
|
22
|
-
g: Number.parseInt(full.slice(2, 4), 16),
|
|
23
|
-
b: Number.parseInt(full.slice(4, 6), 16),
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function colorsIn(background: string): Rgb[] {
|
|
28
|
-
const colors: Rgb[] = [];
|
|
29
|
-
for (const match of background.matchAll(HEX_RE)) colors.push(parseHex(match[0]));
|
|
30
|
-
for (const match of background.matchAll(OKLCH_RE)) {
|
|
31
|
-
const parsed = parseOklchCss(match[0]);
|
|
32
|
-
if (parsed) colors.push(oklchToRgb255(parsed.l, parsed.c, parsed.h));
|
|
33
|
-
}
|
|
34
|
-
for (const match of background.matchAll(RGB_RE)) {
|
|
35
|
-
colors.push({ r: channel(match[1]), g: channel(match[2]), b: channel(match[3]) });
|
|
36
|
-
}
|
|
37
|
-
return colors;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function linearChannel(value: number): number {
|
|
41
|
-
const srgb = Math.max(0, Math.min(255, value)) / 255;
|
|
42
|
-
return srgb <= 0.04045 ? srgb / 12.92 : ((srgb + 0.055) / 1.055) ** 2.4;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function luminance({ r, g, b }: Rgb): number {
|
|
46
|
-
return 0.2126 * linearChannel(r) + 0.7152 * linearChannel(g) + 0.0722 * linearChannel(b);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Pick the invariant black/white token with the stronger minimum contrast
|
|
51
|
-
* against every explicit colour in a solid or gradient page background —
|
|
52
|
-
* the rule FloatingTokenTags uses for its kite strings.
|
|
53
|
-
*/
|
|
54
|
-
export function contrastTokenForBackground(background: string): ContrastColorToken {
|
|
55
|
-
const colors = colorsIn(background);
|
|
56
|
-
if (colors.length === 0) return '--color-white';
|
|
57
|
-
|
|
58
|
-
const luminances = colors.map(luminance);
|
|
59
|
-
const blackMinimum = Math.min(...luminances.map(value => (value + 0.05) / 0.05));
|
|
60
|
-
const whiteMinimum = Math.min(...luminances.map(value => 1.05 / (value + 0.05)));
|
|
61
|
-
return blackMinimum >= whiteMinimum ? '--color-black' : '--color-white';
|
|
62
|
-
}
|