@link-foundation/ui-themes 0.0.0-stage → 0.1.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/LICENSE +24 -0
- package/README.md +121 -2
- package/package.json +52 -4
- package/src/classic/catalog.js +193 -0
- package/src/classic/effect-governor.js +199 -0
- package/src/classic/effect-quality.js +76 -0
- package/src/classic/frame-color.js +27 -0
- package/src/classic/frame-css-controls.js +65 -0
- package/src/classic/frame-css-corners.js +138 -0
- package/src/classic/frame-css-edge-geometry.js +74 -0
- package/src/classic/frame-css-edges.js +99 -0
- package/src/classic/frame-css-enums.js +65 -0
- package/src/classic/frame-css-geometry.js +133 -0
- package/src/classic/frame-css-modes.js +45 -0
- package/src/classic/frame-css-states.js +85 -0
- package/src/classic/frame-css-values.js +156 -0
- package/src/classic/frame-css.js +232 -0
- package/src/classic/frame-geometry.js +189 -0
- package/src/classic/frame-schema.js +328 -0
- package/src/classic/frame-vocabulary.js +10 -0
- package/src/classic/frames.d.ts +143 -0
- package/src/classic/frames.js +77 -0
- package/src/classic/material-visibility.js +94 -0
- package/src/classic/materials.d.ts +133 -0
- package/src/classic/materials.js +139 -0
- package/src/classic/optical-css.js +47 -0
- package/src/classic/optics.js +107 -0
- package/src/classic/refraction.js +145 -0
- package/src/fluent2/brand-aliases.js +157 -0
- package/src/fluent2/brand.js +84 -0
- package/src/fluent2/names.js +31 -0
- package/src/index.d.ts +54 -0
- package/src/index.js +79 -0
- package/src/mapping.js +135 -0
- package/src/material3/mapping.js +18 -0
- package/src/material3/mui.js +128 -0
- package/src/material3/seed.js +144 -0
- package/themes/base/theme.lino +35 -0
- package/themes/classic/README.md +90 -0
- package/themes/classic/deepcase/2025.lino +156 -0
- package/themes/classic/deepcase/classic.lino +86 -0
- package/themes/classic/deepcase/dark.lino +87 -0
- package/themes/classic/deepcase/deepcase-0.1.lino +63 -0
- package/themes/classic/deepcase/handler-windows.lino +22 -0
- package/themes/classic/deepcase/landing.lino +60 -0
- package/themes/classic/deepcase/perception.lino +88 -0
- package/themes/classic/formal-ai/chat-bubbles.lino +40 -0
- package/themes/classic/formal-ai/chat-cards.lino +40 -0
- package/themes/classic/formal-ai/chat-compact.lino +40 -0
- package/themes/classic/formal-ai/composer.lino +132 -0
- package/themes/classic/formal-ai/fa-contrast.lino +79 -0
- package/themes/classic/formal-ai/fa-flat.lino +79 -0
- package/themes/classic/formal-ai/fa-glass.lino +79 -0
- package/themes/classic/formal-ai/fa-material.lino +79 -0
- package/themes/classic/immortality/arwes.lino +59 -0
- package/themes/classic/immortality/palettes.lino +968 -0
- package/themes/classic/immortality/poseidon.lino +59 -0
- package/themes/classic/immortality/quiet.lino +59 -0
- package/themes/classic/konard/futuristic.lino +89 -0
- package/themes/classic/konard/glass.lino +89 -0
- package/themes/classic/konard/liquid.lino +89 -0
- package/themes/classic/meta-sovereign/chat-signal.lino +68 -0
- package/themes/classic/meta-sovereign/chat-t3.lino +68 -0
- package/themes/classic/meta-sovereign/chat-telegram.lino +74 -0
- package/themes/classic/meta-sovereign/chat-whatsapp.lino +68 -0
- package/themes/fluent2/LICENSE.txt +15 -0
- package/themes/fluent2/brand-aliases.lino +101 -0
- package/themes/fluent2/colors-dark.lino +1124 -0
- package/themes/fluent2/colors-high-contrast.lino +1109 -0
- package/themes/fluent2/colors.lino +1489 -0
- package/themes/fluent2/fluent-mapping.lino +120 -0
- package/themes/fluent2/motion-dark.lino +62 -0
- package/themes/fluent2/motion-high-contrast.lino +62 -0
- package/themes/fluent2/motion.lino +70 -0
- package/themes/fluent2/shadow-dark.lino +50 -0
- package/themes/fluent2/shadow-high-contrast.lino +50 -0
- package/themes/fluent2/shadow.lino +49 -0
- package/themes/fluent2/shape-dark.lino +47 -0
- package/themes/fluent2/shape-high-contrast.lino +47 -0
- package/themes/fluent2/shape.lino +46 -0
- package/themes/fluent2/spacing-dark.lino +68 -0
- package/themes/fluent2/spacing-high-contrast.lino +68 -0
- package/themes/fluent2/spacing.lino +67 -0
- package/themes/fluent2/styles.lino +511 -0
- package/themes/fluent2/templates.lino +60 -0
- package/themes/fluent2/theme.lino +31 -0
- package/themes/fluent2/type-dark.lino +83 -0
- package/themes/fluent2/type-high-contrast.lino +83 -0
- package/themes/fluent2/type.lino +82 -0
- package/themes/hig/colors.lino +54 -0
- package/themes/hig/materials.lino +7 -0
- package/themes/hig/motion.lino +13 -0
- package/themes/hig/shape.lino +5 -0
- package/themes/hig/spacing.lino +11 -0
- package/themes/hig/styles.lino +143 -0
- package/themes/hig/swiftui-mapping.lino +80 -0
- package/themes/hig/templates.lino +36 -0
- package/themes/hig/theme.lino +3 -0
- package/themes/hig/type.lino +26 -0
- package/themes/hig-ios/theme.lino +5 -0
- package/themes/hig-macos/theme.lino +5 -0
- package/themes/material3/colors.lino +320 -0
- package/themes/material3/elevation.lino +110 -0
- package/themes/material3/motion.lino +102 -0
- package/themes/material3/mui-mapping.lino +216 -0
- package/themes/material3/shape.lino +16 -0
- package/themes/material3/styles.lino +498 -0
- package/themes/material3/templates.lino +55 -0
- package/themes/material3/theme.lino +7 -0
- package/themes/material3/type.lino +336 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Generated by generate-fluent2.mjs from @fluentui/tokens.
|
|
2
|
+
// prettier-ignore
|
|
3
|
+
export const BRAND_ALIASES = {
|
|
4
|
+
"light": {
|
|
5
|
+
"colorNeutralForeground2BrandHover": 80,
|
|
6
|
+
"colorNeutralForeground2BrandPressed": 70,
|
|
7
|
+
"colorNeutralForeground2BrandSelected": 80,
|
|
8
|
+
"colorNeutralForeground3BrandHover": 80,
|
|
9
|
+
"colorNeutralForeground3BrandPressed": 70,
|
|
10
|
+
"colorNeutralForeground3BrandSelected": 80,
|
|
11
|
+
"colorBrandForegroundLink": 70,
|
|
12
|
+
"colorBrandForegroundLinkHover": 60,
|
|
13
|
+
"colorBrandForegroundLinkPressed": 40,
|
|
14
|
+
"colorBrandForegroundLinkSelected": 70,
|
|
15
|
+
"colorCompoundBrandForeground1": 80,
|
|
16
|
+
"colorCompoundBrandForeground1Hover": 70,
|
|
17
|
+
"colorCompoundBrandForeground1Pressed": 60,
|
|
18
|
+
"colorBrandForeground1": 80,
|
|
19
|
+
"colorBrandForeground2": 70,
|
|
20
|
+
"colorBrandForeground2Hover": 60,
|
|
21
|
+
"colorBrandForeground2Pressed": 30,
|
|
22
|
+
"colorBrandForegroundInverted": 100,
|
|
23
|
+
"colorBrandForegroundInvertedHover": 110,
|
|
24
|
+
"colorBrandForegroundInvertedPressed": 100,
|
|
25
|
+
"colorBrandForegroundOnLight": 80,
|
|
26
|
+
"colorBrandForegroundOnLightHover": 70,
|
|
27
|
+
"colorBrandForegroundOnLightPressed": 50,
|
|
28
|
+
"colorBrandForegroundOnLightSelected": 60,
|
|
29
|
+
"colorBrandBackground": 80,
|
|
30
|
+
"colorBrandBackgroundHover": 70,
|
|
31
|
+
"colorBrandBackgroundPressed": 40,
|
|
32
|
+
"colorBrandBackgroundSelected": 60,
|
|
33
|
+
"colorCompoundBrandBackground": 80,
|
|
34
|
+
"colorCompoundBrandBackgroundHover": 70,
|
|
35
|
+
"colorCompoundBrandBackgroundPressed": 60,
|
|
36
|
+
"colorBrandBackgroundStatic": 80,
|
|
37
|
+
"colorBrandBackground2": 160,
|
|
38
|
+
"colorBrandBackground2Hover": 150,
|
|
39
|
+
"colorBrandBackground2Pressed": 130,
|
|
40
|
+
"colorBrandBackground3Static": 60,
|
|
41
|
+
"colorBrandBackground4Static": 40,
|
|
42
|
+
"colorBrandBackgroundInvertedHover": 160,
|
|
43
|
+
"colorBrandBackgroundInvertedPressed": 140,
|
|
44
|
+
"colorBrandBackgroundInvertedSelected": 150,
|
|
45
|
+
"colorNeutralStrokeAccessibleSelected": 80,
|
|
46
|
+
"colorBrandStroke1": 80,
|
|
47
|
+
"colorBrandStroke2": 140,
|
|
48
|
+
"colorBrandStroke2Hover": 120,
|
|
49
|
+
"colorBrandStroke2Pressed": 80,
|
|
50
|
+
"colorBrandStroke2Contrast": 140,
|
|
51
|
+
"colorCompoundBrandStroke": 80,
|
|
52
|
+
"colorCompoundBrandStrokeHover": 70,
|
|
53
|
+
"colorCompoundBrandStrokePressed": 60
|
|
54
|
+
},
|
|
55
|
+
"dark": {
|
|
56
|
+
"colorNeutralForeground2BrandHover": 100,
|
|
57
|
+
"colorNeutralForeground2BrandPressed": 90,
|
|
58
|
+
"colorNeutralForeground2BrandSelected": 100,
|
|
59
|
+
"colorNeutralForeground3BrandHover": 100,
|
|
60
|
+
"colorNeutralForeground3BrandPressed": 90,
|
|
61
|
+
"colorNeutralForeground3BrandSelected": 100,
|
|
62
|
+
"colorBrandForegroundLink": 100,
|
|
63
|
+
"colorBrandForegroundLinkHover": 110,
|
|
64
|
+
"colorBrandForegroundLinkPressed": 90,
|
|
65
|
+
"colorBrandForegroundLinkSelected": 100,
|
|
66
|
+
"colorCompoundBrandForeground1": 100,
|
|
67
|
+
"colorCompoundBrandForeground1Hover": 110,
|
|
68
|
+
"colorCompoundBrandForeground1Pressed": 90,
|
|
69
|
+
"colorBrandForeground1": 100,
|
|
70
|
+
"colorBrandForeground2": 110,
|
|
71
|
+
"colorBrandForeground2Hover": 130,
|
|
72
|
+
"colorBrandForeground2Pressed": 160,
|
|
73
|
+
"colorBrandForegroundInverted": 80,
|
|
74
|
+
"colorBrandForegroundInvertedHover": 70,
|
|
75
|
+
"colorBrandForegroundInvertedPressed": 60,
|
|
76
|
+
"colorBrandForegroundOnLight": 80,
|
|
77
|
+
"colorBrandForegroundOnLightHover": 70,
|
|
78
|
+
"colorBrandForegroundOnLightPressed": 50,
|
|
79
|
+
"colorBrandForegroundOnLightSelected": 60,
|
|
80
|
+
"colorBrandBackground": 70,
|
|
81
|
+
"colorBrandBackgroundHover": 80,
|
|
82
|
+
"colorBrandBackgroundPressed": 40,
|
|
83
|
+
"colorBrandBackgroundSelected": 60,
|
|
84
|
+
"colorCompoundBrandBackground": 100,
|
|
85
|
+
"colorCompoundBrandBackgroundHover": 110,
|
|
86
|
+
"colorCompoundBrandBackgroundPressed": 90,
|
|
87
|
+
"colorBrandBackgroundStatic": 80,
|
|
88
|
+
"colorBrandBackground2": 20,
|
|
89
|
+
"colorBrandBackground2Hover": 40,
|
|
90
|
+
"colorBrandBackground2Pressed": 10,
|
|
91
|
+
"colorBrandBackground3Static": 60,
|
|
92
|
+
"colorBrandBackground4Static": 40,
|
|
93
|
+
"colorBrandBackgroundInvertedHover": 160,
|
|
94
|
+
"colorBrandBackgroundInvertedPressed": 140,
|
|
95
|
+
"colorBrandBackgroundInvertedSelected": 150,
|
|
96
|
+
"colorNeutralStrokeAccessibleSelected": 100,
|
|
97
|
+
"colorBrandStroke1": 100,
|
|
98
|
+
"colorBrandStroke2": 50,
|
|
99
|
+
"colorBrandStroke2Hover": 50,
|
|
100
|
+
"colorBrandStroke2Pressed": 30,
|
|
101
|
+
"colorBrandStroke2Contrast": 50,
|
|
102
|
+
"colorCompoundBrandStroke": 100,
|
|
103
|
+
"colorCompoundBrandStrokeHover": 110,
|
|
104
|
+
"colorCompoundBrandStrokePressed": 90
|
|
105
|
+
},
|
|
106
|
+
"high-contrast": {
|
|
107
|
+
"colorNeutralForeground2BrandHover": "#000000",
|
|
108
|
+
"colorNeutralForeground2BrandPressed": "#000000",
|
|
109
|
+
"colorNeutralForeground2BrandSelected": "#000000",
|
|
110
|
+
"colorNeutralForeground3BrandHover": "#000000",
|
|
111
|
+
"colorNeutralForeground3BrandPressed": "#000000",
|
|
112
|
+
"colorNeutralForeground3BrandSelected": "#000000",
|
|
113
|
+
"colorBrandForegroundLink": "#ffff00",
|
|
114
|
+
"colorBrandForegroundLinkHover": "#ffff00",
|
|
115
|
+
"colorBrandForegroundLinkPressed": "#ffff00",
|
|
116
|
+
"colorBrandForegroundLinkSelected": "#ffff00",
|
|
117
|
+
"colorCompoundBrandForeground1": "#1aebff",
|
|
118
|
+
"colorCompoundBrandForeground1Hover": "#1aebff",
|
|
119
|
+
"colorCompoundBrandForeground1Pressed": "#1aebff",
|
|
120
|
+
"colorBrandForeground1": "#ffffff",
|
|
121
|
+
"colorBrandForeground2": "#ffffff",
|
|
122
|
+
"colorBrandForeground2Hover": "#ffffff",
|
|
123
|
+
"colorBrandForeground2Pressed": "#ffffff",
|
|
124
|
+
"colorBrandForegroundInverted": "#ffffff",
|
|
125
|
+
"colorBrandForegroundInvertedHover": "#000000",
|
|
126
|
+
"colorBrandForegroundInvertedPressed": "#000000",
|
|
127
|
+
"colorBrandForegroundOnLight": "#000000",
|
|
128
|
+
"colorBrandForegroundOnLightHover": "#000000",
|
|
129
|
+
"colorBrandForegroundOnLightPressed": "#000000",
|
|
130
|
+
"colorBrandForegroundOnLightSelected": "#000000",
|
|
131
|
+
"colorBrandBackground": "#ffffff",
|
|
132
|
+
"colorBrandBackgroundHover": "#1aebff",
|
|
133
|
+
"colorBrandBackgroundPressed": "#1aebff",
|
|
134
|
+
"colorBrandBackgroundSelected": "#1aebff",
|
|
135
|
+
"colorCompoundBrandBackground": "#1aebff",
|
|
136
|
+
"colorCompoundBrandBackgroundHover": "#1aebff",
|
|
137
|
+
"colorCompoundBrandBackgroundPressed": "#1aebff",
|
|
138
|
+
"colorBrandBackgroundStatic": "#000000",
|
|
139
|
+
"colorBrandBackground2": "#000000",
|
|
140
|
+
"colorBrandBackground2Hover": "#000000",
|
|
141
|
+
"colorBrandBackground2Pressed": "#000000",
|
|
142
|
+
"colorBrandBackground3Static": "#000000",
|
|
143
|
+
"colorBrandBackground4Static": "#000000",
|
|
144
|
+
"colorBrandBackgroundInvertedHover": "#1aebff",
|
|
145
|
+
"colorBrandBackgroundInvertedPressed": "#1aebff",
|
|
146
|
+
"colorBrandBackgroundInvertedSelected": "#1aebff",
|
|
147
|
+
"colorNeutralStrokeAccessibleSelected": "#1aebff",
|
|
148
|
+
"colorBrandStroke1": "#ffffff",
|
|
149
|
+
"colorBrandStroke2": "#ffffff",
|
|
150
|
+
"colorBrandStroke2Hover": "#1aebff",
|
|
151
|
+
"colorBrandStroke2Pressed": "#1aebff",
|
|
152
|
+
"colorBrandStroke2Contrast": "#000000",
|
|
153
|
+
"colorCompoundBrandStroke": "#1aebff",
|
|
154
|
+
"colorCompoundBrandStrokeHover": "#1aebff",
|
|
155
|
+
"colorCompoundBrandStrokePressed": "#1aebff"
|
|
156
|
+
}
|
|
157
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { formatLinks, values } from '@link-foundation/ui-core';
|
|
2
|
+
import { fluentTokenPath } from './names.js';
|
|
3
|
+
import { BRAND_ALIASES } from './brand-aliases.js';
|
|
4
|
+
|
|
5
|
+
const stops = Array.from({ length: 16 }, (_, i) => (i + 1) * 10);
|
|
6
|
+
/** A seed fixes hue; increasing OKLCH lightness and tapered chroma keep the
|
|
7
|
+
* entire ramp in gamut without clipping that could reverse its lightness. */
|
|
8
|
+
export function fluentBrandRamp(seed) {
|
|
9
|
+
const color =
|
|
10
|
+
typeof seed === 'string' && /^#[\da-f]{6}$/iu.test(seed)
|
|
11
|
+
? values.parseColor(seed)
|
|
12
|
+
: null;
|
|
13
|
+
if (!color) {
|
|
14
|
+
throw new TypeError('Brand seed must be an opaque six-digit hex color');
|
|
15
|
+
}
|
|
16
|
+
const lch = values.srgbToOklch(color);
|
|
17
|
+
return Object.fromEntries(
|
|
18
|
+
stops.map((stop, i) => {
|
|
19
|
+
const l = 0.15 + (i * 0.8) / 15;
|
|
20
|
+
let c = lch.c * Math.sin(Math.PI * l);
|
|
21
|
+
let rgb;
|
|
22
|
+
for (let attempt = 0; attempt < 60; attempt++) {
|
|
23
|
+
rgb = values.oklchToSrgb({ ...lch, l, c });
|
|
24
|
+
if (['r', 'g', 'b'].every((key) => rgb[key] >= 0 && rgb[key] <= 1)) {
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
c *= 0.85;
|
|
28
|
+
}
|
|
29
|
+
return [stop, values.toHex(rgb).toLowerCase()];
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
/** @param {Record<number, string> | string} brand 16 stops (10..160) or seed
|
|
34
|
+
* @param {{id?: string}} [options] @returns {string} LiNo extending fluent2 */
|
|
35
|
+
export function fluentThemeFromBrand(brand, options = {}) {
|
|
36
|
+
const ramp = typeof brand === 'string' ? fluentBrandRamp(brand) : brand;
|
|
37
|
+
if (
|
|
38
|
+
!ramp ||
|
|
39
|
+
stops.some(
|
|
40
|
+
(stop) =>
|
|
41
|
+
!Object.hasOwn(ramp, stop) ||
|
|
42
|
+
typeof ramp[stop] !== 'string' ||
|
|
43
|
+
!/^#[\da-f]{6}$/iu.test(ramp[stop])
|
|
44
|
+
) ||
|
|
45
|
+
Object.keys(ramp).length !== 16
|
|
46
|
+
) {
|
|
47
|
+
throw new TypeError(
|
|
48
|
+
'Brand ramp must contain exactly 16 opaque hex stops, 10 through 160'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const id = options.id ?? 'fluent2-brand';
|
|
52
|
+
if (
|
|
53
|
+
typeof id !== 'string' ||
|
|
54
|
+
!/^[a-z][\w-]{0,79}$/iu.test(id) ||
|
|
55
|
+
id === 'fluent2'
|
|
56
|
+
) {
|
|
57
|
+
throw new TypeError('Expected a distinct theme id');
|
|
58
|
+
}
|
|
59
|
+
const aliases = (mode) =>
|
|
60
|
+
Object.entries(BRAND_ALIASES[mode]).map(([name, stop]) => [
|
|
61
|
+
'token',
|
|
62
|
+
fluentTokenPath(name),
|
|
63
|
+
ramp[stop],
|
|
64
|
+
['fluent', name],
|
|
65
|
+
]);
|
|
66
|
+
return formatLinks([
|
|
67
|
+
{
|
|
68
|
+
id,
|
|
69
|
+
values: [
|
|
70
|
+
'theme',
|
|
71
|
+
['extends', 'fluent2'],
|
|
72
|
+
...aliases('light'),
|
|
73
|
+
['mode', 'dark', ...aliases('dark')],
|
|
74
|
+
[
|
|
75
|
+
'mode',
|
|
76
|
+
'high-contrast',
|
|
77
|
+
...Object.entries(BRAND_ALIASES['high-contrast']).map(
|
|
78
|
+
([name, value]) => ['token', fluentTokenPath(name), value]
|
|
79
|
+
),
|
|
80
|
+
],
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Semantic equivalents from docs/guidelines/token-taxonomy.md. Other aliases
|
|
2
|
+
* retain a Fluent namespace, including their state suffixes. */
|
|
3
|
+
const semantic = {
|
|
4
|
+
colorNeutralBackground1: 'color.surface',
|
|
5
|
+
colorNeutralForeground1: 'color.on-surface',
|
|
6
|
+
colorNeutralForeground2: 'color.on-surface-variant',
|
|
7
|
+
colorBrandBackground: 'color.primary',
|
|
8
|
+
colorNeutralForegroundOnBrand: 'color.on-primary',
|
|
9
|
+
colorNeutralStrokeAccessible: 'color.outline',
|
|
10
|
+
borderRadiusMedium: 'shape.corner.small',
|
|
11
|
+
spacingHorizontalS: 'space.small',
|
|
12
|
+
spacingHorizontalL: 'space.medium',
|
|
13
|
+
fontSizeBase300: 'type.body.medium.size',
|
|
14
|
+
lineHeightBase300: 'type.body.medium.line-height',
|
|
15
|
+
durationFast: 'motion.duration.short',
|
|
16
|
+
curveEasyEase: 'motion.easing.standard',
|
|
17
|
+
};
|
|
18
|
+
export const fluentTokenPath = (name) =>
|
|
19
|
+
semantic[name] ??
|
|
20
|
+
`fluent.${name.replace(/[A-Z]/gu, (c) => `-${c.toLowerCase()}`)}`;
|
|
21
|
+
|
|
22
|
+
export const FLUENT_FILES = [
|
|
23
|
+
...['light', 'dark', 'high-contrast'].flatMap((mode) =>
|
|
24
|
+
['colors', 'shape', 'spacing', 'type', 'shadow', 'motion'].map(
|
|
25
|
+
(group) => group + (mode === 'light' ? '' : `-${mode}`)
|
|
26
|
+
)
|
|
27
|
+
),
|
|
28
|
+
'styles',
|
|
29
|
+
'templates',
|
|
30
|
+
'theme',
|
|
31
|
+
];
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Theme } from '@link-foundation/ui-tokens/themes';
|
|
2
|
+
export function listThemes(): string[];
|
|
3
|
+
export function loadTheme(id: string): Promise<Theme>;
|
|
4
|
+
|
|
5
|
+
export function fluentBrandRamp(seed: string): Record<number, string>;
|
|
6
|
+
export function fluentThemeFromBrand(
|
|
7
|
+
brand: Record<number, string> | string,
|
|
8
|
+
options?: { id?: string }
|
|
9
|
+
): string;
|
|
10
|
+
export interface FluentMappingRow {
|
|
11
|
+
component: string;
|
|
12
|
+
kind: string | null;
|
|
13
|
+
status: 'mapped' | 'partial' | 'unsupported' | 'none';
|
|
14
|
+
props: { name: string; value: string; target: string[] }[];
|
|
15
|
+
note: string;
|
|
16
|
+
}
|
|
17
|
+
export function loadMapping(text: string): FluentMappingRow[];
|
|
18
|
+
export function mappingMarkdown(rows: FluentMappingRow[]): string;
|
|
19
|
+
|
|
20
|
+
export function materialThemeFromSeed(
|
|
21
|
+
seed: string,
|
|
22
|
+
options?: {
|
|
23
|
+
id?: string;
|
|
24
|
+
contrast?: number;
|
|
25
|
+
variant?: 'tonal-spot' | 'vibrant' | 'neutral';
|
|
26
|
+
}
|
|
27
|
+
): string;
|
|
28
|
+
export function muiThemeToLino(
|
|
29
|
+
themeOptions: object,
|
|
30
|
+
options?: { id?: string }
|
|
31
|
+
): {
|
|
32
|
+
lino: string;
|
|
33
|
+
unmapped: string[];
|
|
34
|
+
};
|
|
35
|
+
export interface MuiMappingRow {
|
|
36
|
+
component: string;
|
|
37
|
+
kind: string | null;
|
|
38
|
+
status: 'mapped' | 'partial' | 'none';
|
|
39
|
+
props: Array<{
|
|
40
|
+
name: string;
|
|
41
|
+
value: string;
|
|
42
|
+
target: { name: string; value: string };
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
export function getMuiMapping(): Promise<MuiMappingRow[]>;
|
|
46
|
+
|
|
47
|
+
export interface MappingRow {
|
|
48
|
+
name: string;
|
|
49
|
+
kind: string | null;
|
|
50
|
+
status: 'mapped' | 'partial' | 'none';
|
|
51
|
+
props: { property: string; value: string; target: string[] }[];
|
|
52
|
+
}
|
|
53
|
+
export function readMapping(text: string): MappingRow[];
|
|
54
|
+
export function getSwiftuiMapping(): Promise<MappingRow[]>;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Shipped themes remain LiNo data, loaded in browsers or Node without a build. */
|
|
2
|
+
import { readThemeFile } from './mapping.js';
|
|
3
|
+
import { FLUENT_FILES } from './fluent2/names.js';
|
|
4
|
+
export { fluentThemeFromBrand, fluentBrandRamp } from './fluent2/brand.js';
|
|
5
|
+
export { loadMapping, mappingMarkdown } from './mapping.js';
|
|
6
|
+
export { readMapping } from './mapping.js';
|
|
7
|
+
export { getMuiMapping } from './material3/mapping.js';
|
|
8
|
+
export { materialThemeFromSeed } from './material3/seed.js';
|
|
9
|
+
export { muiThemeToLino } from './material3/mui.js';
|
|
10
|
+
import { classicThemes } from './classic/catalog.js';
|
|
11
|
+
import { loadThemes, resolveTheme } from '@link-foundation/ui-tokens/themes';
|
|
12
|
+
|
|
13
|
+
export function listThemes() {
|
|
14
|
+
return [
|
|
15
|
+
'base',
|
|
16
|
+
'material3',
|
|
17
|
+
'fluent2',
|
|
18
|
+
'hig',
|
|
19
|
+
'hig-ios',
|
|
20
|
+
'hig-macos',
|
|
21
|
+
...classicThemes.map((t) => t.id),
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Share source reads within one runtime, while resolving a fresh theme per caller.
|
|
26
|
+
let registryPromise;
|
|
27
|
+
async function registry() {
|
|
28
|
+
const paths = [
|
|
29
|
+
'base/theme.lino',
|
|
30
|
+
...FLUENT_FILES.map((name) => `fluent2/${name}.lino`),
|
|
31
|
+
...[
|
|
32
|
+
'colors',
|
|
33
|
+
'type',
|
|
34
|
+
'shape',
|
|
35
|
+
'elevation',
|
|
36
|
+
'motion',
|
|
37
|
+
'styles',
|
|
38
|
+
'templates',
|
|
39
|
+
'theme',
|
|
40
|
+
].map((name) => `material3/${name}.lino`),
|
|
41
|
+
...[
|
|
42
|
+
'colors',
|
|
43
|
+
'type',
|
|
44
|
+
'shape',
|
|
45
|
+
'spacing',
|
|
46
|
+
'motion',
|
|
47
|
+
'materials',
|
|
48
|
+
'styles',
|
|
49
|
+
'templates',
|
|
50
|
+
'theme',
|
|
51
|
+
].map((name) => `hig/${name}.lino`),
|
|
52
|
+
'hig-ios/theme.lino',
|
|
53
|
+
'hig-macos/theme.lino',
|
|
54
|
+
...new Set(classicThemes.map((t) => t.path)),
|
|
55
|
+
];
|
|
56
|
+
const texts = await Promise.all(paths.map(readThemeFile));
|
|
57
|
+
const { themes, diagnostics } = loadThemes(texts.join('\n'));
|
|
58
|
+
if (diagnostics.some((d) => d.severity === 'error')) {
|
|
59
|
+
throw new Error(diagnostics.map((d) => d.message).join('; '));
|
|
60
|
+
}
|
|
61
|
+
return new Map(themes.map((t) => [t.id, t]));
|
|
62
|
+
}
|
|
63
|
+
/** @param {string} id @returns {Promise<import('@link-foundation/ui-tokens/themes').Theme>} */
|
|
64
|
+
export async function loadTheme(id) {
|
|
65
|
+
if (!listThemes().includes(id)) {
|
|
66
|
+
throw new RangeError(`Unknown theme: ${id}`);
|
|
67
|
+
}
|
|
68
|
+
registryPromise ??= registry().catch((error) => {
|
|
69
|
+
registryPromise = undefined;
|
|
70
|
+
throw error;
|
|
71
|
+
});
|
|
72
|
+
return resolveTheme(await registryPromise, id);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** SwiftUI view/modifier rows in the shared mapping format. */
|
|
76
|
+
export async function getSwiftuiMapping() {
|
|
77
|
+
const { readMapping } = await import('./mapping.js');
|
|
78
|
+
return readMapping(await readThemeFile('hig/swiftui-mapping.lino'));
|
|
79
|
+
}
|
package/src/mapping.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* global URL */
|
|
2
|
+
import { parseNested } from '@link-foundation/ui-core';
|
|
3
|
+
/** Read package data in browsers and Node without a build. */
|
|
4
|
+
export async function readThemeFile(path) {
|
|
5
|
+
const url = new URL(`../themes/${path}`, import.meta.url);
|
|
6
|
+
if (url.protocol === 'file:') {
|
|
7
|
+
return (await import('node:fs/promises')).readFile(url, 'utf8');
|
|
8
|
+
}
|
|
9
|
+
const response = await fetch(url);
|
|
10
|
+
if (!response.ok) {
|
|
11
|
+
throw new Error(`Cannot load theme data: ${response.status} ${path}`);
|
|
12
|
+
}
|
|
13
|
+
return response.text();
|
|
14
|
+
}
|
|
15
|
+
const raw = (link) => (link.values.length ? link.values.map(raw) : link.id);
|
|
16
|
+
|
|
17
|
+
const fieldValue = (fields, name) =>
|
|
18
|
+
fields.find((field) => field[0] === name)?.[1];
|
|
19
|
+
|
|
20
|
+
function validKind(kind, status, fields) {
|
|
21
|
+
const count = fields.filter((field) => field[0] === 'kind').length;
|
|
22
|
+
return typeof kind === 'string'
|
|
23
|
+
? count === 1
|
|
24
|
+
: kind === null && status === 'none' && count === 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function validProps(props) {
|
|
28
|
+
return props.every(
|
|
29
|
+
({ property, value, target }) =>
|
|
30
|
+
typeof property === 'string' &&
|
|
31
|
+
typeof value === 'string' &&
|
|
32
|
+
Array.isArray(target) &&
|
|
33
|
+
target.length >= 2 &&
|
|
34
|
+
target.every((atom) => typeof atom === 'string')
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Read the shared #48 table format without interpreting source-language code. */
|
|
39
|
+
function parseMapping(text, extended = false) {
|
|
40
|
+
const names = new Set();
|
|
41
|
+
const fieldNames = ['kind', 'status', 'prop', ...(extended ? ['note'] : [])];
|
|
42
|
+
const statuses = [
|
|
43
|
+
'mapped',
|
|
44
|
+
'partial',
|
|
45
|
+
'none',
|
|
46
|
+
...(extended ? ['unsupported'] : []),
|
|
47
|
+
];
|
|
48
|
+
return parseNested(text)
|
|
49
|
+
.map(raw)
|
|
50
|
+
.map((row) => {
|
|
51
|
+
if (!Array.isArray(row)) {
|
|
52
|
+
throw new TypeError('Invalid mapping row');
|
|
53
|
+
}
|
|
54
|
+
const [head, name, ...fields] = row;
|
|
55
|
+
if (
|
|
56
|
+
!fields.every(
|
|
57
|
+
(field) =>
|
|
58
|
+
Array.isArray(field) &&
|
|
59
|
+
fieldNames.includes(field[0]) &&
|
|
60
|
+
field.length === (field[0] === 'prop' ? 4 : 2)
|
|
61
|
+
)
|
|
62
|
+
) {
|
|
63
|
+
throw new TypeError('Invalid mapping field');
|
|
64
|
+
}
|
|
65
|
+
const kind = fieldValue(fields, 'kind') ?? null;
|
|
66
|
+
const status = fieldValue(fields, 'status');
|
|
67
|
+
const props = fields
|
|
68
|
+
.filter((field) => field[0] === 'prop')
|
|
69
|
+
.map(([, property, value, target]) => ({ property, value, target }));
|
|
70
|
+
if (
|
|
71
|
+
head !== 'map' ||
|
|
72
|
+
typeof name !== 'string' ||
|
|
73
|
+
!validKind(kind, status, fields) ||
|
|
74
|
+
names.has(name) ||
|
|
75
|
+
fields.filter((field) => field[0] === 'status').length !== 1 ||
|
|
76
|
+
!validProps(props) ||
|
|
77
|
+
!statuses.includes(status)
|
|
78
|
+
) {
|
|
79
|
+
throw new TypeError('Invalid mapping row');
|
|
80
|
+
}
|
|
81
|
+
names.add(name);
|
|
82
|
+
return {
|
|
83
|
+
name,
|
|
84
|
+
kind,
|
|
85
|
+
status,
|
|
86
|
+
props,
|
|
87
|
+
...(extended ? { note: fieldValue(fields, 'note') ?? '' } : {}),
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Preserve the shared SwiftUI/MUI row API. */
|
|
93
|
+
export function readMapping(text) {
|
|
94
|
+
return parseMapping(text);
|
|
95
|
+
}
|
|
96
|
+
/** Fluent mappings add explanatory notes and an unsupported status. */
|
|
97
|
+
export function loadMapping(text) {
|
|
98
|
+
return parseMapping(text, true).map(
|
|
99
|
+
({ name, kind, status, props, note }) => ({
|
|
100
|
+
component: name,
|
|
101
|
+
kind,
|
|
102
|
+
status,
|
|
103
|
+
note,
|
|
104
|
+
props: props.map(({ property, value, target }) => ({
|
|
105
|
+
name: property,
|
|
106
|
+
value,
|
|
107
|
+
target,
|
|
108
|
+
})),
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const cell = (text) => String(text).replaceAll('*', '\\*');
|
|
113
|
+
/** Shared table writer; callers can retain their own columns and inline markup. */
|
|
114
|
+
export function mappingTable(headers, rows) {
|
|
115
|
+
const row = (cells) =>
|
|
116
|
+
`| ${cells.map((value) => String(value).replaceAll('|', '\\|').replaceAll('\n', ' ')).join(' | ')} |`;
|
|
117
|
+
return `${[row(headers), row(headers.map(() => '---')), ...rows.map(row)].join('\n')}\n`;
|
|
118
|
+
}
|
|
119
|
+
/** Deterministic Markdown used by design-system mappings. */
|
|
120
|
+
export function mappingMarkdown(rows) {
|
|
121
|
+
return mappingTable(
|
|
122
|
+
['Component', 'Kind', 'Props', 'Status', 'Notes'],
|
|
123
|
+
rows.map((row) =>
|
|
124
|
+
[
|
|
125
|
+
row.component,
|
|
126
|
+
row.kind ?? '—',
|
|
127
|
+
row.props
|
|
128
|
+
.map((p) => `${p.name}=${p.value} → ${p.target.join(' ')}`)
|
|
129
|
+
.join('; '),
|
|
130
|
+
row.status,
|
|
131
|
+
row.note,
|
|
132
|
+
].map((text) => cell(text))
|
|
133
|
+
)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { loadMapping, readThemeFile } from '../mapping.js';
|
|
2
|
+
export { readThemeFile } from '../mapping.js';
|
|
3
|
+
|
|
4
|
+
/** Preserve the MUI adapter's public target objects over the shared LiNo loader. */
|
|
5
|
+
export async function getMuiMapping() {
|
|
6
|
+
return loadMapping(await readThemeFile('material3/mui-mapping.lino')).map(
|
|
7
|
+
({ component, kind, status, props }) => ({
|
|
8
|
+
component,
|
|
9
|
+
kind,
|
|
10
|
+
status,
|
|
11
|
+
props: props.map(({ name, value, target }) => ({
|
|
12
|
+
name,
|
|
13
|
+
value,
|
|
14
|
+
target: { name: target[0], value: target[1] },
|
|
15
|
+
})),
|
|
16
|
+
})
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { formatLinks, values } from '@link-foundation/ui-core';
|
|
2
|
+
|
|
3
|
+
const record = (value) =>
|
|
4
|
+
value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
+
const finite = (value) =>
|
|
6
|
+
typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
7
|
+
const kebab = (text) => text.replace(/[A-Z]/gu, (c) => `-${c.toLowerCase()}`);
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert plain createTheme options without importing MUI. Unmapped paths
|
|
11
|
+
* include unsupported values as well as unknown leaf fields (empty objects too).
|
|
12
|
+
* @param {object} themeOptions
|
|
13
|
+
* @param {{id?: string}} [options]
|
|
14
|
+
* @returns {{lino: string, unmapped: string[]}}
|
|
15
|
+
*/
|
|
16
|
+
export function muiThemeToLino(themeOptions, options = {}) {
|
|
17
|
+
if (!record(themeOptions)) {
|
|
18
|
+
throw new TypeError('Expected a plain theme options object');
|
|
19
|
+
}
|
|
20
|
+
const tokens = [],
|
|
21
|
+
unmapped = [];
|
|
22
|
+
const add = (path, value, type) =>
|
|
23
|
+
tokens.push([
|
|
24
|
+
'token',
|
|
25
|
+
path,
|
|
26
|
+
String(value),
|
|
27
|
+
...(type ? [['type', type]] : []),
|
|
28
|
+
]);
|
|
29
|
+
let dark = false;
|
|
30
|
+
const convertColor = (path, value) => {
|
|
31
|
+
const palette =
|
|
32
|
+
/^palette\.(primary|secondary|error|warning|info|success)\.(main|contrastText)$/u.exec(
|
|
33
|
+
path
|
|
34
|
+
);
|
|
35
|
+
if (
|
|
36
|
+
palette &&
|
|
37
|
+
typeof value === 'string' &&
|
|
38
|
+
values.parseColor(value) !== null
|
|
39
|
+
) {
|
|
40
|
+
add(
|
|
41
|
+
`color.${palette[2] === 'contrastText' ? 'on-' : ''}${palette[1]}`,
|
|
42
|
+
value
|
|
43
|
+
);
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
const colors = {
|
|
47
|
+
'palette.background.default': 'background',
|
|
48
|
+
'palette.background.paper': 'surface',
|
|
49
|
+
'palette.text.primary': 'on-surface',
|
|
50
|
+
'palette.text.secondary': 'on-surface-variant',
|
|
51
|
+
};
|
|
52
|
+
if (
|
|
53
|
+
Object.hasOwn(colors, path) &&
|
|
54
|
+
typeof value === 'string' &&
|
|
55
|
+
values.parseColor(value) !== null
|
|
56
|
+
) {
|
|
57
|
+
add(`color.${colors[path]}`, value);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
const convert = (path, value) => {
|
|
63
|
+
if (path === 'palette.mode' && ['light', 'dark'].includes(value)) {
|
|
64
|
+
dark = value === 'dark';
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (convertColor(path, value)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (['shape.borderRadius', 'spacing'].includes(path) && finite(value)) {
|
|
71
|
+
add(
|
|
72
|
+
path === 'spacing' ? 'space.unit' : 'shape.corner.small',
|
|
73
|
+
`${value}px`
|
|
74
|
+
);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (path === 'typography.fontFamily' && typeof value === 'string') {
|
|
78
|
+
add('type.font-family', value, 'fontFamily');
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (
|
|
82
|
+
path.startsWith('breakpoints.values.') &&
|
|
83
|
+
path.split('.').length === 3 &&
|
|
84
|
+
finite(value)
|
|
85
|
+
) {
|
|
86
|
+
add(`breakpoint.${kebab(path.split('.')[2])}`, `${value}px`);
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (
|
|
90
|
+
path.startsWith('transitions.duration.') &&
|
|
91
|
+
path.split('.').length === 3 &&
|
|
92
|
+
finite(value)
|
|
93
|
+
) {
|
|
94
|
+
add(`motion.duration.${kebab(path.split('.')[2])}`, `${value}ms`);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
};
|
|
99
|
+
const visit = (value, path) => {
|
|
100
|
+
if (convert(path, value)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (record(value) && Object.keys(value).length) {
|
|
104
|
+
for (const [key, child] of Object.entries(value)) {
|
|
105
|
+
visit(child, path ? `${path}.${key}` : key);
|
|
106
|
+
}
|
|
107
|
+
} else if (path) {
|
|
108
|
+
unmapped.push(path);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
visit(themeOptions, '');
|
|
112
|
+
// Palette colors belong to the MUI options object's selected scheme.
|
|
113
|
+
const body = dark ? [['mode', 'dark', ...tokens]] : tokens;
|
|
114
|
+
return {
|
|
115
|
+
lino: formatLinks([
|
|
116
|
+
{
|
|
117
|
+
id: options.id ?? 'mui-import',
|
|
118
|
+
values: [
|
|
119
|
+
'theme',
|
|
120
|
+
['extends', 'material3'],
|
|
121
|
+
['scheme', dark ? 'dark' : 'light'],
|
|
122
|
+
...body,
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
]),
|
|
126
|
+
unmapped: unmapped.sort(),
|
|
127
|
+
};
|
|
128
|
+
}
|