@bug-on/md3-tokens 3.0.0 → 3.0.3
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/.turbo/turbo-build.log +12 -14
- package/CHANGELOG.md +11 -0
- package/dist/colors.css.d.ts +2 -0
- package/dist/index.d.mts +448 -45
- package/dist/index.d.ts +448 -45
- package/dist/index.js +258 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -9
- package/dist/index.mjs.map +1 -1
- package/dist/shape.css +9 -0
- package/dist/shape.css.d.ts +2 -0
- package/package.json +14 -10
- package/scripts/copy-css.js +1 -1
- package/src/index.ts +47 -1
- package/src/motion.ts +280 -9
- package/src/shape.css +9 -0
- package/src/shape.ts +162 -0
- package/tsup.config.ts +0 -1
package/src/shape.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MD3 Expressive Shape Tokens
|
|
3
|
+
*
|
|
4
|
+
* TypeScript counterpart to `shape.css`. Provides numeric corner radius values,
|
|
5
|
+
* CSS custom property names, and asymmetric corner helpers.
|
|
6
|
+
*
|
|
7
|
+
* Updated for M3 Expressive (May 2025): 10-level corner radius scale.
|
|
8
|
+
*
|
|
9
|
+
* @see https://m3.material.io/styles/shape/corner-radius-scale
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
13
|
+
// Corner radius scale — numeric values in pixels
|
|
14
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Numeric corner radius values (px) for all 10 shape scale levels.
|
|
18
|
+
* Map directly to `--md-sys-shape-corner-*` CSS custom properties.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* element.style.borderRadius = `${cornerRadius.medium}px`; // 12px
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const cornerRadius = {
|
|
26
|
+
none: 0,
|
|
27
|
+
extraSmall: 4,
|
|
28
|
+
small: 8,
|
|
29
|
+
medium: 12,
|
|
30
|
+
large: 16,
|
|
31
|
+
/** New in M3 Expressive (May 2025) */
|
|
32
|
+
largeIncreased: 20,
|
|
33
|
+
extraLarge: 28,
|
|
34
|
+
/** New in M3 Expressive (May 2025) */
|
|
35
|
+
extraLargeIncreased: 32,
|
|
36
|
+
/** New in M3 Expressive (May 2025) */
|
|
37
|
+
extraExtraLarge: 48,
|
|
38
|
+
full: 9999,
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
export type CornerRadiusKey = keyof typeof cornerRadius;
|
|
42
|
+
|
|
43
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
44
|
+
// CSS custom property names
|
|
45
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Maps each corner radius key to its CSS custom property name.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const cssVar = cornerCssVar.medium; // "--md-sys-shape-corner-medium"
|
|
53
|
+
* element.style.borderRadius = `var(${cssVar})`;
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const cornerCssVar: Record<CornerRadiusKey, string> = {
|
|
57
|
+
none: "--md-sys-shape-corner-none",
|
|
58
|
+
extraSmall: "--md-sys-shape-corner-extra-small",
|
|
59
|
+
small: "--md-sys-shape-corner-small",
|
|
60
|
+
medium: "--md-sys-shape-corner-medium",
|
|
61
|
+
large: "--md-sys-shape-corner-large",
|
|
62
|
+
largeIncreased: "--md-sys-shape-corner-large-increased",
|
|
63
|
+
extraLarge: "--md-sys-shape-corner-extra-large",
|
|
64
|
+
extraLargeIncreased: "--md-sys-shape-corner-extra-large-increased",
|
|
65
|
+
extraExtraLarge: "--md-sys-shape-corner-extra-extra-large",
|
|
66
|
+
full: "--md-sys-shape-corner-full",
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
70
|
+
// Asymmetric corner helpers
|
|
71
|
+
// Used for inner-corner components (menus, split buttons, grouped items).
|
|
72
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Describes per-corner rounding for asymmetric shapes.
|
|
76
|
+
* Follows CSS `border-radius` shorthand order:
|
|
77
|
+
* top-left, top-right, bottom-right, bottom-left.
|
|
78
|
+
*/
|
|
79
|
+
export interface AsymmetricCorners {
|
|
80
|
+
topLeft: number;
|
|
81
|
+
topRight: number;
|
|
82
|
+
bottomRight: number;
|
|
83
|
+
bottomLeft: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Shorthand presets for common asymmetric corner patterns. */
|
|
87
|
+
export const asymmetricCorners = {
|
|
88
|
+
/** Fully rounded top, square bottom — e.g. menu at top of screen. */
|
|
89
|
+
topFull: (r = cornerRadius.extraLarge): AsymmetricCorners => ({
|
|
90
|
+
topLeft: r,
|
|
91
|
+
topRight: r,
|
|
92
|
+
bottomRight: 0,
|
|
93
|
+
bottomLeft: 0,
|
|
94
|
+
}),
|
|
95
|
+
/** Square top, fully rounded bottom — e.g. menu at bottom of screen. */
|
|
96
|
+
bottomFull: (r = cornerRadius.extraLarge): AsymmetricCorners => ({
|
|
97
|
+
topLeft: 0,
|
|
98
|
+
topRight: 0,
|
|
99
|
+
bottomRight: r,
|
|
100
|
+
bottomLeft: r,
|
|
101
|
+
}),
|
|
102
|
+
/** Rounded start edge only — e.g. left item in a grouped set. */
|
|
103
|
+
startFull: (r = cornerRadius.full): AsymmetricCorners => ({
|
|
104
|
+
topLeft: r,
|
|
105
|
+
topRight: 0,
|
|
106
|
+
bottomRight: 0,
|
|
107
|
+
bottomLeft: r,
|
|
108
|
+
}),
|
|
109
|
+
/** Rounded end edge only — e.g. right item in a grouped set. */
|
|
110
|
+
endFull: (r = cornerRadius.full): AsymmetricCorners => ({
|
|
111
|
+
topLeft: 0,
|
|
112
|
+
topRight: r,
|
|
113
|
+
bottomRight: r,
|
|
114
|
+
bottomLeft: 0,
|
|
115
|
+
}),
|
|
116
|
+
} as const;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Converts an `AsymmetricCorners` object to a CSS `border-radius` string.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* element.style.borderRadius = toCSS(asymmetricCorners.topFull());
|
|
124
|
+
* // "28px 28px 0px 0px"
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export function asymmetricCornersToCSS(corners: AsymmetricCorners): string {
|
|
128
|
+
return `${corners.topLeft}px ${corners.topRight}px ${corners.bottomRight}px ${corners.bottomLeft}px`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
132
|
+
// Optical roundness helper
|
|
133
|
+
// When nesting rounded objects: inner radius = outer radius - padding
|
|
134
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Calculates the inner border-radius that maintains optical roundness
|
|
138
|
+
* when nesting one rounded container inside another.
|
|
139
|
+
*
|
|
140
|
+
* Formula: `inner = outer - padding`
|
|
141
|
+
*
|
|
142
|
+
* @see https://m3.material.io/styles/shape/corner-radius-scale#adjust-for-optical-roundness
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* // Container has extraExtraLarge (48px), padding is 14px
|
|
147
|
+
* const inner = opticalRadius(cornerRadius.extraExtraLarge, 14); // 34
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export function opticalRadius(outerRadius: number, padding: number): number {
|
|
151
|
+
return Math.max(0, outerRadius - padding);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
155
|
+
// Aggregate export
|
|
156
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
157
|
+
|
|
158
|
+
export const shapeTokens = {
|
|
159
|
+
cornerRadius,
|
|
160
|
+
cornerCssVar,
|
|
161
|
+
asymmetricCorners,
|
|
162
|
+
} as const;
|