@ariaui/shadow 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-TCSURVQN.js +509 -0
- package/dist/index.cjs +559 -0
- package/dist/index.d.cts +287 -0
- package/dist/index.d.ts +287 -0
- package/dist/index.js +64 -0
- package/dist/tokens.cjs +665 -0
- package/dist/tokens.d.cts +49 -0
- package/dist/tokens.d.ts +49 -0
- package/dist/tokens.js +167 -0
- package/package.json +4 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { OklchColor } from '@ariaui/color';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A single layer of a box-shadow.
|
|
5
|
+
*
|
|
6
|
+
* Color is stored as a structured `OklchColor` from `@ariaui/color`,
|
|
7
|
+
* enabling programmatic manipulation (opacity, hue, lightness).
|
|
8
|
+
*/
|
|
9
|
+
interface ShadowLayer {
|
|
10
|
+
/** Horizontal offset, e.g. `"0px"` */
|
|
11
|
+
readonly offsetX: string;
|
|
12
|
+
/** Vertical offset, e.g. `"4px"` */
|
|
13
|
+
readonly offsetY: string;
|
|
14
|
+
/** Blur radius, e.g. `"6px"` */
|
|
15
|
+
readonly blur: string;
|
|
16
|
+
/** Spread radius, e.g. `"-1px"` */
|
|
17
|
+
readonly spread: string;
|
|
18
|
+
/** Layer color as an OKLCH color object */
|
|
19
|
+
readonly color: OklchColor;
|
|
20
|
+
/** Whether this is an inset shadow */
|
|
21
|
+
readonly inset: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A composite shadow made of one or more layers.
|
|
25
|
+
*/
|
|
26
|
+
interface Shadow {
|
|
27
|
+
readonly layers: readonly ShadowLayer[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Focus ring configuration.
|
|
31
|
+
*
|
|
32
|
+
* Produces a double box-shadow: inner gap ring (`bgColor`) +
|
|
33
|
+
* outer colored ring (`ringColor`).
|
|
34
|
+
*/
|
|
35
|
+
interface FocusRing {
|
|
36
|
+
/** Ring stroke width, e.g. `"2px"` */
|
|
37
|
+
readonly ringWidth: string;
|
|
38
|
+
/** Gap between element edge and ring, e.g. `"2px"` */
|
|
39
|
+
readonly ringOffset: string;
|
|
40
|
+
/** Ring color */
|
|
41
|
+
readonly ringColor: OklchColor;
|
|
42
|
+
/** Gap color (usually the page background) */
|
|
43
|
+
readonly bgColor: OklchColor;
|
|
44
|
+
}
|
|
45
|
+
/** Named elevation levels matching the token shadow sizes. */
|
|
46
|
+
type ElevationLevel = "none" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl";
|
|
47
|
+
/**
|
|
48
|
+
* Configuration for creating a custom elevation scale.
|
|
49
|
+
*/
|
|
50
|
+
interface ElevationConfig {
|
|
51
|
+
/** Shadow base color (default: black `{ l: 0, c: 0, h: 0, alpha: 1 }`) */
|
|
52
|
+
readonly color?: OklchColor;
|
|
53
|
+
/** Multiply all layer alphas (e.g. 1.5 for dark mode) */
|
|
54
|
+
readonly alphaMultiplier?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Parse a CSS `box-shadow` value into a `Shadow` object.
|
|
59
|
+
*
|
|
60
|
+
* Supports multiple comma-separated layers, `inset` keyword,
|
|
61
|
+
* and common color formats: `rgba()`, `oklch()`, hex, and named colors.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* parseShadow("0px 1px 2px 0px rgba(0,0,0,0.05)")
|
|
65
|
+
* parseShadow("inset 0 2px 4px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06)")
|
|
66
|
+
*/
|
|
67
|
+
declare function parseShadow(css: string): Shadow;
|
|
68
|
+
/**
|
|
69
|
+
* Parse a single box-shadow layer string into a `ShadowLayer`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* parseLayer("0px 4px 6px -1px rgba(0,0,0,0.1)")
|
|
73
|
+
* parseLayer("inset 0 2px 4px 0px oklch(0% 0 0 / 0.08)")
|
|
74
|
+
*/
|
|
75
|
+
declare function parseLayer(css: string): ShadowLayer;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create a shadow layer with sensible defaults.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* createLayer({ offsetY: "4px", blur: "6px", color: { l: 0, c: 0, h: 0, alpha: 0.1 } })
|
|
82
|
+
*/
|
|
83
|
+
declare function createLayer(config?: Partial<ShadowLayer>): ShadowLayer;
|
|
84
|
+
/**
|
|
85
|
+
* Scale a layer's geometry (offsets, blur, spread) by a factor.
|
|
86
|
+
* Color and inset are preserved.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* scaleLayer(layer, 2) // doubles all offsets, blur, and spread
|
|
90
|
+
*/
|
|
91
|
+
declare function scaleLayer(layer: ShadowLayer, factor: number): ShadowLayer;
|
|
92
|
+
/**
|
|
93
|
+
* Replace the color of a layer.
|
|
94
|
+
*/
|
|
95
|
+
declare function setLayerColor(layer: ShadowLayer, color: OklchColor): ShadowLayer;
|
|
96
|
+
/**
|
|
97
|
+
* Set the alpha (opacity) of a layer's color.
|
|
98
|
+
*/
|
|
99
|
+
declare function setLayerOpacity(layer: ShadowLayer, alpha: number): ShadowLayer;
|
|
100
|
+
/**
|
|
101
|
+
* Shift a layer's offset.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* offsetLayer(layer, { x: "2px", y: "4px" })
|
|
105
|
+
*/
|
|
106
|
+
declare function offsetLayer(layer: ShadowLayer, offset: {
|
|
107
|
+
x?: string;
|
|
108
|
+
y?: string;
|
|
109
|
+
}): ShadowLayer;
|
|
110
|
+
/**
|
|
111
|
+
* Toggle or set the inset flag.
|
|
112
|
+
*/
|
|
113
|
+
declare function insetLayer(layer: ShadowLayer, inset?: boolean): ShadowLayer;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create a `Shadow` from one or more layers.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* createShadow(
|
|
120
|
+
* createLayer({ offsetY: "1px", blur: "2px" }),
|
|
121
|
+
* createLayer({ offsetY: "4px", blur: "6px", spread: "-1px" }),
|
|
122
|
+
* )
|
|
123
|
+
*/
|
|
124
|
+
declare function createShadow(...layers: ShadowLayer[]): Shadow;
|
|
125
|
+
/**
|
|
126
|
+
* Append a layer to a shadow.
|
|
127
|
+
*/
|
|
128
|
+
declare function addLayer(shadow: Shadow, layer: ShadowLayer): Shadow;
|
|
129
|
+
/**
|
|
130
|
+
* Remove a layer by index.
|
|
131
|
+
*/
|
|
132
|
+
declare function removeLayer(shadow: Shadow, index: number): Shadow;
|
|
133
|
+
/**
|
|
134
|
+
* Merge multiple shadows by concatenating all their layers.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* mergeShadows(cardShadow, hoverShadow)
|
|
138
|
+
*/
|
|
139
|
+
declare function mergeShadows(...shadows: Shadow[]): Shadow;
|
|
140
|
+
/**
|
|
141
|
+
* Scale all layers' geometry uniformly.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* scaleShadow(shadow, 1.5) // 50% larger offsets/blur/spread
|
|
145
|
+
*/
|
|
146
|
+
declare function scaleShadow(shadow: Shadow, factor: number): Shadow;
|
|
147
|
+
/**
|
|
148
|
+
* Recolor all layers of a shadow.
|
|
149
|
+
*
|
|
150
|
+
* Preserves each layer's original alpha by default. Pass `preserveAlpha: false`
|
|
151
|
+
* to use the new color's alpha for all layers.
|
|
152
|
+
*/
|
|
153
|
+
declare function colorShadow(shadow: Shadow, color: OklchColor, preserveAlpha?: boolean): Shadow;
|
|
154
|
+
/**
|
|
155
|
+
* Multiply all layer alphas by a factor.
|
|
156
|
+
*
|
|
157
|
+
* Useful for dark-mode adjustments (e.g. `multiplyAlpha(shadow, 1.5)`).
|
|
158
|
+
*/
|
|
159
|
+
declare function multiplyAlpha(shadow: Shadow, factor: number): Shadow;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Pre-defined elevation presets matching the token shadow geometry
|
|
163
|
+
* with concrete black shadow colors (light-mode alphas).
|
|
164
|
+
*/
|
|
165
|
+
declare const ELEVATION_PRESETS: Record<ElevationLevel, Shadow>;
|
|
166
|
+
/**
|
|
167
|
+
* Create a custom elevation scale with a different base color
|
|
168
|
+
* and/or alpha multiplier.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* // Dark mode: 1.5× stronger shadows
|
|
172
|
+
* createElevationScale({ alphaMultiplier: 1.5 })
|
|
173
|
+
*
|
|
174
|
+
* // Branded shadows
|
|
175
|
+
* createElevationScale({ color: { l: 0.541, c: 0.247, h: 293, alpha: 1 } })
|
|
176
|
+
*/
|
|
177
|
+
declare function createElevationScale(config?: ElevationConfig): Record<ElevationLevel, Shadow>;
|
|
178
|
+
/**
|
|
179
|
+
* Interpolate between two shadows by index-matching layers.
|
|
180
|
+
*
|
|
181
|
+
* Only the minimum number of layers (from either shadow) is interpolated.
|
|
182
|
+
* Extra layers are dropped.
|
|
183
|
+
*
|
|
184
|
+
* Interpolates: offsets, blur, spread (px values) and color alpha.
|
|
185
|
+
* Color L/C/H are interpolated linearly.
|
|
186
|
+
*
|
|
187
|
+
* @param from - Starting shadow
|
|
188
|
+
* @param to - Ending shadow
|
|
189
|
+
* @param t - Interpolation factor, 0 = `from`, 1 = `to`
|
|
190
|
+
*/
|
|
191
|
+
declare function interpolateElevation(from: Shadow, to: Shadow, t: number): Shadow;
|
|
192
|
+
/**
|
|
193
|
+
* Step up or down one elevation level.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* stepElevation("sm", "up") // → "md"
|
|
197
|
+
* stepElevation("xs", "down") // → "none"
|
|
198
|
+
* stepElevation("3xl", "up") // → "3xl" (clamped)
|
|
199
|
+
*/
|
|
200
|
+
declare function stepElevation(current: ElevationLevel, direction: "up" | "down"): ElevationLevel;
|
|
201
|
+
/**
|
|
202
|
+
* Get the ordered list of elevation levels.
|
|
203
|
+
*/
|
|
204
|
+
declare function getElevationLevels(): readonly ElevationLevel[];
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Create a focus ring as a `Shadow` object.
|
|
208
|
+
*
|
|
209
|
+
* Produces a double box-shadow:
|
|
210
|
+
* 1. Inner gap ring (bgColor) at `ringOffset` spread
|
|
211
|
+
* 2. Outer colored ring at `ringOffset + ringWidth` spread
|
|
212
|
+
*
|
|
213
|
+
* Both use zero offset/blur (pure spread shadows) to create crisp rings.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* createFocusRing()
|
|
217
|
+
* createFocusRing({ ringColor: { l: 0.541, c: 0.247, h: 293, alpha: 1 } })
|
|
218
|
+
*/
|
|
219
|
+
declare function createFocusRing(config?: Partial<FocusRing>): Shadow;
|
|
220
|
+
/**
|
|
221
|
+
* Create an error-variant focus ring as a `Shadow` object.
|
|
222
|
+
*/
|
|
223
|
+
declare function createErrorRing(config?: Partial<FocusRing>): Shadow;
|
|
224
|
+
/**
|
|
225
|
+
* Build a focus ring `Shadow` from a complete `FocusRing` configuration.
|
|
226
|
+
*
|
|
227
|
+
* Returns a two-layer shadow:
|
|
228
|
+
* - Layer 0: background gap ring
|
|
229
|
+
* - Layer 1: colored outer ring
|
|
230
|
+
*/
|
|
231
|
+
declare function buildRing(config: FocusRing): Shadow;
|
|
232
|
+
/**
|
|
233
|
+
* Combine a shadow with a focus ring.
|
|
234
|
+
*
|
|
235
|
+
* The ring layers are prepended so they render below the shadow layers
|
|
236
|
+
* in the box-shadow stacking order.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* withFocusRing(cardShadow, createFocusRing())
|
|
240
|
+
*/
|
|
241
|
+
declare function withFocusRing(shadow: Shadow, ring: Shadow): Shadow;
|
|
242
|
+
/**
|
|
243
|
+
* Create a custom ring with arbitrary color.
|
|
244
|
+
*
|
|
245
|
+
* Shorthand for `createFocusRing({ ringColor })`.
|
|
246
|
+
*/
|
|
247
|
+
declare function colorRing(ringColor: OklchColor): Shadow;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Format a single `ShadowLayer` as a CSS box-shadow layer string.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* layerToString(layer) // → "0px 4px 6px -1px oklch(0% 0 0 / 0.102)"
|
|
254
|
+
*/
|
|
255
|
+
declare function layerToString(layer: ShadowLayer): string;
|
|
256
|
+
/**
|
|
257
|
+
* Format a `Shadow` as a CSS `box-shadow` value.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* toBoxShadow(shadow) // → "0px 1px 3px 0px oklch(...), 0px 1px 2px -1px oklch(...)"
|
|
261
|
+
*/
|
|
262
|
+
declare function toBoxShadow(shadow: Shadow): string;
|
|
263
|
+
/**
|
|
264
|
+
* Format a `Shadow` as a React `CSSProperties`-compatible object.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* toCSSProperties(shadow) // → { boxShadow: "0px 4px 6px -1px oklch(...)" }
|
|
268
|
+
*/
|
|
269
|
+
declare function toCSSProperties(shadow: Shadow): {
|
|
270
|
+
boxShadow: string;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Format a `Shadow` as a Tailwind CSS arbitrary shadow class.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* toTailwindClass(shadow) // → "shadow-[0px_4px_6px_-1px_oklch(0%_0_0/0.1)]"
|
|
277
|
+
*/
|
|
278
|
+
declare function toTailwindClass(shadow: Shadow): string;
|
|
279
|
+
/**
|
|
280
|
+
* Format a `Shadow` as a CSS declaration block.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* toCSSDeclaration(shadow) // → "box-shadow: 0px 4px 6px -1px oklch(...);"
|
|
284
|
+
*/
|
|
285
|
+
declare function toCSSDeclaration(shadow: Shadow): string;
|
|
286
|
+
|
|
287
|
+
export { ELEVATION_PRESETS, type ElevationConfig, type ElevationLevel, type FocusRing, type Shadow, type ShadowLayer, addLayer, buildRing, colorRing, colorShadow, createElevationScale, createErrorRing, createFocusRing, createLayer, createShadow, getElevationLevels, insetLayer, interpolateElevation, layerToString, mergeShadows, multiplyAlpha, offsetLayer, parseLayer, parseShadow, removeLayer, scaleLayer, scaleShadow, setLayerColor, setLayerOpacity, stepElevation, toBoxShadow, toCSSDeclaration, toCSSProperties, toTailwindClass, withFocusRing };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { OklchColor } from '@ariaui/color';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A single layer of a box-shadow.
|
|
5
|
+
*
|
|
6
|
+
* Color is stored as a structured `OklchColor` from `@ariaui/color`,
|
|
7
|
+
* enabling programmatic manipulation (opacity, hue, lightness).
|
|
8
|
+
*/
|
|
9
|
+
interface ShadowLayer {
|
|
10
|
+
/** Horizontal offset, e.g. `"0px"` */
|
|
11
|
+
readonly offsetX: string;
|
|
12
|
+
/** Vertical offset, e.g. `"4px"` */
|
|
13
|
+
readonly offsetY: string;
|
|
14
|
+
/** Blur radius, e.g. `"6px"` */
|
|
15
|
+
readonly blur: string;
|
|
16
|
+
/** Spread radius, e.g. `"-1px"` */
|
|
17
|
+
readonly spread: string;
|
|
18
|
+
/** Layer color as an OKLCH color object */
|
|
19
|
+
readonly color: OklchColor;
|
|
20
|
+
/** Whether this is an inset shadow */
|
|
21
|
+
readonly inset: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A composite shadow made of one or more layers.
|
|
25
|
+
*/
|
|
26
|
+
interface Shadow {
|
|
27
|
+
readonly layers: readonly ShadowLayer[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Focus ring configuration.
|
|
31
|
+
*
|
|
32
|
+
* Produces a double box-shadow: inner gap ring (`bgColor`) +
|
|
33
|
+
* outer colored ring (`ringColor`).
|
|
34
|
+
*/
|
|
35
|
+
interface FocusRing {
|
|
36
|
+
/** Ring stroke width, e.g. `"2px"` */
|
|
37
|
+
readonly ringWidth: string;
|
|
38
|
+
/** Gap between element edge and ring, e.g. `"2px"` */
|
|
39
|
+
readonly ringOffset: string;
|
|
40
|
+
/** Ring color */
|
|
41
|
+
readonly ringColor: OklchColor;
|
|
42
|
+
/** Gap color (usually the page background) */
|
|
43
|
+
readonly bgColor: OklchColor;
|
|
44
|
+
}
|
|
45
|
+
/** Named elevation levels matching the token shadow sizes. */
|
|
46
|
+
type ElevationLevel = "none" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl";
|
|
47
|
+
/**
|
|
48
|
+
* Configuration for creating a custom elevation scale.
|
|
49
|
+
*/
|
|
50
|
+
interface ElevationConfig {
|
|
51
|
+
/** Shadow base color (default: black `{ l: 0, c: 0, h: 0, alpha: 1 }`) */
|
|
52
|
+
readonly color?: OklchColor;
|
|
53
|
+
/** Multiply all layer alphas (e.g. 1.5 for dark mode) */
|
|
54
|
+
readonly alphaMultiplier?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Parse a CSS `box-shadow` value into a `Shadow` object.
|
|
59
|
+
*
|
|
60
|
+
* Supports multiple comma-separated layers, `inset` keyword,
|
|
61
|
+
* and common color formats: `rgba()`, `oklch()`, hex, and named colors.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* parseShadow("0px 1px 2px 0px rgba(0,0,0,0.05)")
|
|
65
|
+
* parseShadow("inset 0 2px 4px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06)")
|
|
66
|
+
*/
|
|
67
|
+
declare function parseShadow(css: string): Shadow;
|
|
68
|
+
/**
|
|
69
|
+
* Parse a single box-shadow layer string into a `ShadowLayer`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* parseLayer("0px 4px 6px -1px rgba(0,0,0,0.1)")
|
|
73
|
+
* parseLayer("inset 0 2px 4px 0px oklch(0% 0 0 / 0.08)")
|
|
74
|
+
*/
|
|
75
|
+
declare function parseLayer(css: string): ShadowLayer;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create a shadow layer with sensible defaults.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* createLayer({ offsetY: "4px", blur: "6px", color: { l: 0, c: 0, h: 0, alpha: 0.1 } })
|
|
82
|
+
*/
|
|
83
|
+
declare function createLayer(config?: Partial<ShadowLayer>): ShadowLayer;
|
|
84
|
+
/**
|
|
85
|
+
* Scale a layer's geometry (offsets, blur, spread) by a factor.
|
|
86
|
+
* Color and inset are preserved.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* scaleLayer(layer, 2) // doubles all offsets, blur, and spread
|
|
90
|
+
*/
|
|
91
|
+
declare function scaleLayer(layer: ShadowLayer, factor: number): ShadowLayer;
|
|
92
|
+
/**
|
|
93
|
+
* Replace the color of a layer.
|
|
94
|
+
*/
|
|
95
|
+
declare function setLayerColor(layer: ShadowLayer, color: OklchColor): ShadowLayer;
|
|
96
|
+
/**
|
|
97
|
+
* Set the alpha (opacity) of a layer's color.
|
|
98
|
+
*/
|
|
99
|
+
declare function setLayerOpacity(layer: ShadowLayer, alpha: number): ShadowLayer;
|
|
100
|
+
/**
|
|
101
|
+
* Shift a layer's offset.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* offsetLayer(layer, { x: "2px", y: "4px" })
|
|
105
|
+
*/
|
|
106
|
+
declare function offsetLayer(layer: ShadowLayer, offset: {
|
|
107
|
+
x?: string;
|
|
108
|
+
y?: string;
|
|
109
|
+
}): ShadowLayer;
|
|
110
|
+
/**
|
|
111
|
+
* Toggle or set the inset flag.
|
|
112
|
+
*/
|
|
113
|
+
declare function insetLayer(layer: ShadowLayer, inset?: boolean): ShadowLayer;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Create a `Shadow` from one or more layers.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* createShadow(
|
|
120
|
+
* createLayer({ offsetY: "1px", blur: "2px" }),
|
|
121
|
+
* createLayer({ offsetY: "4px", blur: "6px", spread: "-1px" }),
|
|
122
|
+
* )
|
|
123
|
+
*/
|
|
124
|
+
declare function createShadow(...layers: ShadowLayer[]): Shadow;
|
|
125
|
+
/**
|
|
126
|
+
* Append a layer to a shadow.
|
|
127
|
+
*/
|
|
128
|
+
declare function addLayer(shadow: Shadow, layer: ShadowLayer): Shadow;
|
|
129
|
+
/**
|
|
130
|
+
* Remove a layer by index.
|
|
131
|
+
*/
|
|
132
|
+
declare function removeLayer(shadow: Shadow, index: number): Shadow;
|
|
133
|
+
/**
|
|
134
|
+
* Merge multiple shadows by concatenating all their layers.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* mergeShadows(cardShadow, hoverShadow)
|
|
138
|
+
*/
|
|
139
|
+
declare function mergeShadows(...shadows: Shadow[]): Shadow;
|
|
140
|
+
/**
|
|
141
|
+
* Scale all layers' geometry uniformly.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* scaleShadow(shadow, 1.5) // 50% larger offsets/blur/spread
|
|
145
|
+
*/
|
|
146
|
+
declare function scaleShadow(shadow: Shadow, factor: number): Shadow;
|
|
147
|
+
/**
|
|
148
|
+
* Recolor all layers of a shadow.
|
|
149
|
+
*
|
|
150
|
+
* Preserves each layer's original alpha by default. Pass `preserveAlpha: false`
|
|
151
|
+
* to use the new color's alpha for all layers.
|
|
152
|
+
*/
|
|
153
|
+
declare function colorShadow(shadow: Shadow, color: OklchColor, preserveAlpha?: boolean): Shadow;
|
|
154
|
+
/**
|
|
155
|
+
* Multiply all layer alphas by a factor.
|
|
156
|
+
*
|
|
157
|
+
* Useful for dark-mode adjustments (e.g. `multiplyAlpha(shadow, 1.5)`).
|
|
158
|
+
*/
|
|
159
|
+
declare function multiplyAlpha(shadow: Shadow, factor: number): Shadow;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Pre-defined elevation presets matching the token shadow geometry
|
|
163
|
+
* with concrete black shadow colors (light-mode alphas).
|
|
164
|
+
*/
|
|
165
|
+
declare const ELEVATION_PRESETS: Record<ElevationLevel, Shadow>;
|
|
166
|
+
/**
|
|
167
|
+
* Create a custom elevation scale with a different base color
|
|
168
|
+
* and/or alpha multiplier.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* // Dark mode: 1.5× stronger shadows
|
|
172
|
+
* createElevationScale({ alphaMultiplier: 1.5 })
|
|
173
|
+
*
|
|
174
|
+
* // Branded shadows
|
|
175
|
+
* createElevationScale({ color: { l: 0.541, c: 0.247, h: 293, alpha: 1 } })
|
|
176
|
+
*/
|
|
177
|
+
declare function createElevationScale(config?: ElevationConfig): Record<ElevationLevel, Shadow>;
|
|
178
|
+
/**
|
|
179
|
+
* Interpolate between two shadows by index-matching layers.
|
|
180
|
+
*
|
|
181
|
+
* Only the minimum number of layers (from either shadow) is interpolated.
|
|
182
|
+
* Extra layers are dropped.
|
|
183
|
+
*
|
|
184
|
+
* Interpolates: offsets, blur, spread (px values) and color alpha.
|
|
185
|
+
* Color L/C/H are interpolated linearly.
|
|
186
|
+
*
|
|
187
|
+
* @param from - Starting shadow
|
|
188
|
+
* @param to - Ending shadow
|
|
189
|
+
* @param t - Interpolation factor, 0 = `from`, 1 = `to`
|
|
190
|
+
*/
|
|
191
|
+
declare function interpolateElevation(from: Shadow, to: Shadow, t: number): Shadow;
|
|
192
|
+
/**
|
|
193
|
+
* Step up or down one elevation level.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* stepElevation("sm", "up") // → "md"
|
|
197
|
+
* stepElevation("xs", "down") // → "none"
|
|
198
|
+
* stepElevation("3xl", "up") // → "3xl" (clamped)
|
|
199
|
+
*/
|
|
200
|
+
declare function stepElevation(current: ElevationLevel, direction: "up" | "down"): ElevationLevel;
|
|
201
|
+
/**
|
|
202
|
+
* Get the ordered list of elevation levels.
|
|
203
|
+
*/
|
|
204
|
+
declare function getElevationLevels(): readonly ElevationLevel[];
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Create a focus ring as a `Shadow` object.
|
|
208
|
+
*
|
|
209
|
+
* Produces a double box-shadow:
|
|
210
|
+
* 1. Inner gap ring (bgColor) at `ringOffset` spread
|
|
211
|
+
* 2. Outer colored ring at `ringOffset + ringWidth` spread
|
|
212
|
+
*
|
|
213
|
+
* Both use zero offset/blur (pure spread shadows) to create crisp rings.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* createFocusRing()
|
|
217
|
+
* createFocusRing({ ringColor: { l: 0.541, c: 0.247, h: 293, alpha: 1 } })
|
|
218
|
+
*/
|
|
219
|
+
declare function createFocusRing(config?: Partial<FocusRing>): Shadow;
|
|
220
|
+
/**
|
|
221
|
+
* Create an error-variant focus ring as a `Shadow` object.
|
|
222
|
+
*/
|
|
223
|
+
declare function createErrorRing(config?: Partial<FocusRing>): Shadow;
|
|
224
|
+
/**
|
|
225
|
+
* Build a focus ring `Shadow` from a complete `FocusRing` configuration.
|
|
226
|
+
*
|
|
227
|
+
* Returns a two-layer shadow:
|
|
228
|
+
* - Layer 0: background gap ring
|
|
229
|
+
* - Layer 1: colored outer ring
|
|
230
|
+
*/
|
|
231
|
+
declare function buildRing(config: FocusRing): Shadow;
|
|
232
|
+
/**
|
|
233
|
+
* Combine a shadow with a focus ring.
|
|
234
|
+
*
|
|
235
|
+
* The ring layers are prepended so they render below the shadow layers
|
|
236
|
+
* in the box-shadow stacking order.
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* withFocusRing(cardShadow, createFocusRing())
|
|
240
|
+
*/
|
|
241
|
+
declare function withFocusRing(shadow: Shadow, ring: Shadow): Shadow;
|
|
242
|
+
/**
|
|
243
|
+
* Create a custom ring with arbitrary color.
|
|
244
|
+
*
|
|
245
|
+
* Shorthand for `createFocusRing({ ringColor })`.
|
|
246
|
+
*/
|
|
247
|
+
declare function colorRing(ringColor: OklchColor): Shadow;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Format a single `ShadowLayer` as a CSS box-shadow layer string.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* layerToString(layer) // → "0px 4px 6px -1px oklch(0% 0 0 / 0.102)"
|
|
254
|
+
*/
|
|
255
|
+
declare function layerToString(layer: ShadowLayer): string;
|
|
256
|
+
/**
|
|
257
|
+
* Format a `Shadow` as a CSS `box-shadow` value.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* toBoxShadow(shadow) // → "0px 1px 3px 0px oklch(...), 0px 1px 2px -1px oklch(...)"
|
|
261
|
+
*/
|
|
262
|
+
declare function toBoxShadow(shadow: Shadow): string;
|
|
263
|
+
/**
|
|
264
|
+
* Format a `Shadow` as a React `CSSProperties`-compatible object.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* toCSSProperties(shadow) // → { boxShadow: "0px 4px 6px -1px oklch(...)" }
|
|
268
|
+
*/
|
|
269
|
+
declare function toCSSProperties(shadow: Shadow): {
|
|
270
|
+
boxShadow: string;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Format a `Shadow` as a Tailwind CSS arbitrary shadow class.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* toTailwindClass(shadow) // → "shadow-[0px_4px_6px_-1px_oklch(0%_0_0/0.1)]"
|
|
277
|
+
*/
|
|
278
|
+
declare function toTailwindClass(shadow: Shadow): string;
|
|
279
|
+
/**
|
|
280
|
+
* Format a `Shadow` as a CSS declaration block.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* toCSSDeclaration(shadow) // → "box-shadow: 0px 4px 6px -1px oklch(...);"
|
|
284
|
+
*/
|
|
285
|
+
declare function toCSSDeclaration(shadow: Shadow): string;
|
|
286
|
+
|
|
287
|
+
export { ELEVATION_PRESETS, type ElevationConfig, type ElevationLevel, type FocusRing, type Shadow, type ShadowLayer, addLayer, buildRing, colorRing, colorShadow, createElevationScale, createErrorRing, createFocusRing, createLayer, createShadow, getElevationLevels, insetLayer, interpolateElevation, layerToString, mergeShadows, multiplyAlpha, offsetLayer, parseLayer, parseShadow, removeLayer, scaleLayer, scaleShadow, setLayerColor, setLayerOpacity, stepElevation, toBoxShadow, toCSSDeclaration, toCSSProperties, toTailwindClass, withFocusRing };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ELEVATION_PRESETS,
|
|
3
|
+
addLayer,
|
|
4
|
+
buildRing,
|
|
5
|
+
colorRing,
|
|
6
|
+
colorShadow,
|
|
7
|
+
createElevationScale,
|
|
8
|
+
createErrorRing,
|
|
9
|
+
createFocusRing,
|
|
10
|
+
createLayer,
|
|
11
|
+
createShadow,
|
|
12
|
+
getElevationLevels,
|
|
13
|
+
insetLayer,
|
|
14
|
+
interpolateElevation,
|
|
15
|
+
layerToString,
|
|
16
|
+
mergeShadows,
|
|
17
|
+
multiplyAlpha,
|
|
18
|
+
offsetLayer,
|
|
19
|
+
parseLayer,
|
|
20
|
+
parseShadow,
|
|
21
|
+
removeLayer,
|
|
22
|
+
scaleLayer,
|
|
23
|
+
scaleShadow,
|
|
24
|
+
setLayerColor,
|
|
25
|
+
setLayerOpacity,
|
|
26
|
+
stepElevation,
|
|
27
|
+
toBoxShadow,
|
|
28
|
+
toCSSDeclaration,
|
|
29
|
+
toCSSProperties,
|
|
30
|
+
toTailwindClass,
|
|
31
|
+
withFocusRing
|
|
32
|
+
} from "./chunk-TCSURVQN.js";
|
|
33
|
+
export {
|
|
34
|
+
ELEVATION_PRESETS,
|
|
35
|
+
addLayer,
|
|
36
|
+
buildRing,
|
|
37
|
+
colorRing,
|
|
38
|
+
colorShadow,
|
|
39
|
+
createElevationScale,
|
|
40
|
+
createErrorRing,
|
|
41
|
+
createFocusRing,
|
|
42
|
+
createLayer,
|
|
43
|
+
createShadow,
|
|
44
|
+
getElevationLevels,
|
|
45
|
+
insetLayer,
|
|
46
|
+
interpolateElevation,
|
|
47
|
+
layerToString,
|
|
48
|
+
mergeShadows,
|
|
49
|
+
multiplyAlpha,
|
|
50
|
+
offsetLayer,
|
|
51
|
+
parseLayer,
|
|
52
|
+
parseShadow,
|
|
53
|
+
removeLayer,
|
|
54
|
+
scaleLayer,
|
|
55
|
+
scaleShadow,
|
|
56
|
+
setLayerColor,
|
|
57
|
+
setLayerOpacity,
|
|
58
|
+
stepElevation,
|
|
59
|
+
toBoxShadow,
|
|
60
|
+
toCSSDeclaration,
|
|
61
|
+
toCSSProperties,
|
|
62
|
+
toTailwindClass,
|
|
63
|
+
withFocusRing
|
|
64
|
+
};
|