@gild-ui/core 0.0.0 → 0.1.0-alpha.1
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 +21 -0
- package/README.md +122 -1
- package/dist/View-CL3vORfe.mjs +4914 -0
- package/dist/View-DOvf12An.cjs +6017 -0
- package/dist/breakpoints.cjs +110 -0
- package/dist/breakpoints.d.cts +65 -0
- package/dist/breakpoints.d.mts +2 -0
- package/dist/breakpoints.mjs +103 -0
- package/dist/catalog/entries.cjs +186 -0
- package/dist/catalog/entries.d.cts +4428 -0
- package/dist/catalog/entries.d.mts +4428 -0
- package/dist/catalog/entries.mjs +1 -0
- package/dist/catalog.cjs +1198 -0
- package/dist/catalog.d.cts +2 -0
- package/dist/catalog.d.mts +2 -0
- package/dist/catalog.mjs +1196 -0
- package/dist/index-BVkniYfB.d.mts +66 -0
- package/dist/index-CfaKnMOm.d.cts +106 -0
- package/dist/index-wAxAZHia.d.mts +106 -0
- package/dist/theme.cjs +478 -0
- package/dist/theme.d.cts +246 -0
- package/dist/theme.d.mts +246 -0
- package/dist/theme.mjs +451 -0
- package/dist/themeDefault-CjYwGUsb.cjs +74 -0
- package/dist/themeDefault-DBAILYB-.mjs +45 -0
- package/dist/types-DIyGsvvF.d.cts +411 -0
- package/dist/types-DRIGCQQY.d.mts +411 -0
- package/dist/utils.cjs +63 -0
- package/dist/utils.d.cts +40 -0
- package/dist/utils.d.mts +40 -0
- package/dist/utils.mjs +51 -0
- package/package.json +119 -3
package/dist/theme.mjs
ADDED
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { withBreakpointHelpers } from "./breakpoints.mjs";
|
|
2
|
+
import { i as alpha, n as deepMerge, r as generateBoxShadow, t as themeDefault } from "./themeDefault-DBAILYB-.mjs";
|
|
3
|
+
import { asIs, defineTheme } from "@umber-style/core";
|
|
4
|
+
// src/theme/spacing.ts
|
|
5
|
+
const spacing = (units) => units === 0 ? "0px" : `${Math.max(1, Math.round(8 * units))}px`;
|
|
6
|
+
// src/theme/baseTheme.ts
|
|
7
|
+
const shadow = {
|
|
8
|
+
color: "#000000",
|
|
9
|
+
opacity: .4
|
|
10
|
+
};
|
|
11
|
+
const shadows = Array.from({ length: 25 }, (_, elevation) => generateBoxShadow(elevation, alpha(shadow.color, shadow.opacity)));
|
|
12
|
+
const radii = {
|
|
13
|
+
sq: "0",
|
|
14
|
+
sm: "4px",
|
|
15
|
+
md: "8px",
|
|
16
|
+
lg: "16px"
|
|
17
|
+
};
|
|
18
|
+
const borderWidths = {
|
|
19
|
+
none: "0",
|
|
20
|
+
thin: "1px",
|
|
21
|
+
base: "2px",
|
|
22
|
+
thick: "4px"
|
|
23
|
+
};
|
|
24
|
+
const zOrder = {
|
|
25
|
+
appBar: 1100,
|
|
26
|
+
drawer: 1200,
|
|
27
|
+
modal: 1300,
|
|
28
|
+
snackbar: 1400,
|
|
29
|
+
tooltip: 1500
|
|
30
|
+
};
|
|
31
|
+
const transitions = {
|
|
32
|
+
duration: {
|
|
33
|
+
short: 150,
|
|
34
|
+
standard: 250,
|
|
35
|
+
long: 375
|
|
36
|
+
},
|
|
37
|
+
easing: {
|
|
38
|
+
standard: "cubic-bezier(0.4, 0, 0.2, 1)",
|
|
39
|
+
enter: "cubic-bezier(0, 0, 0.2, 1)",
|
|
40
|
+
exit: "cubic-bezier(0.4, 0, 1, 1)"
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const fontSizes = [
|
|
44
|
+
12,
|
|
45
|
+
14,
|
|
46
|
+
16,
|
|
47
|
+
20,
|
|
48
|
+
24,
|
|
49
|
+
32,
|
|
50
|
+
48
|
|
51
|
+
];
|
|
52
|
+
const lineHeights = {
|
|
53
|
+
none: 1,
|
|
54
|
+
tight: 1.2,
|
|
55
|
+
snug: 1.35,
|
|
56
|
+
base: 1.5,
|
|
57
|
+
relaxed: 1.625,
|
|
58
|
+
loose: 2
|
|
59
|
+
};
|
|
60
|
+
const letterSpacings = {
|
|
61
|
+
tighter: "-0.05em",
|
|
62
|
+
tight: "-0.025em",
|
|
63
|
+
normal: "0em",
|
|
64
|
+
wide: "0.05em",
|
|
65
|
+
wider: "0.1em",
|
|
66
|
+
widest: "0.2em"
|
|
67
|
+
};
|
|
68
|
+
const fonts = {
|
|
69
|
+
body: "'Space Grotesk Variable', 'Space Grotesk', sans-serif",
|
|
70
|
+
heading: "'Space Grotesk Variable', 'Space Grotesk', sans-serif",
|
|
71
|
+
mono: "'JetBrains Mono Variable', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace"
|
|
72
|
+
};
|
|
73
|
+
const fontWeights = {
|
|
74
|
+
thin: 100,
|
|
75
|
+
extraLight: 200,
|
|
76
|
+
light: 300,
|
|
77
|
+
normal: 400,
|
|
78
|
+
medium: 500,
|
|
79
|
+
semiBold: 600,
|
|
80
|
+
bold: 700,
|
|
81
|
+
extraBold: 800,
|
|
82
|
+
black: 900
|
|
83
|
+
};
|
|
84
|
+
const avatar = {
|
|
85
|
+
sm: spacing(4),
|
|
86
|
+
md: spacing(5),
|
|
87
|
+
lg: spacing(6),
|
|
88
|
+
xl: spacing(7)
|
|
89
|
+
};
|
|
90
|
+
const icon = {
|
|
91
|
+
sm: "1rem",
|
|
92
|
+
md: "1.25rem",
|
|
93
|
+
lg: "1.5rem"
|
|
94
|
+
};
|
|
95
|
+
const sizes = {
|
|
96
|
+
sm: {
|
|
97
|
+
paddingTop: .5,
|
|
98
|
+
paddingBottom: .5,
|
|
99
|
+
paddingLeft: 1.5,
|
|
100
|
+
paddingRight: 1.5,
|
|
101
|
+
fontSize: 0
|
|
102
|
+
},
|
|
103
|
+
md: {
|
|
104
|
+
paddingTop: 1,
|
|
105
|
+
paddingBottom: 1,
|
|
106
|
+
paddingLeft: 2,
|
|
107
|
+
paddingRight: 2,
|
|
108
|
+
fontSize: 1
|
|
109
|
+
},
|
|
110
|
+
lg: {
|
|
111
|
+
paddingTop: 1.5,
|
|
112
|
+
paddingBottom: 1.5,
|
|
113
|
+
paddingLeft: 3,
|
|
114
|
+
paddingRight: 3,
|
|
115
|
+
fontSize: 1
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const space = {
|
|
119
|
+
0: 0,
|
|
120
|
+
.125: spacing(.125),
|
|
121
|
+
.25: spacing(.25),
|
|
122
|
+
.5: spacing(.5),
|
|
123
|
+
.75: spacing(.75),
|
|
124
|
+
1: spacing(1),
|
|
125
|
+
1.25: spacing(1.25),
|
|
126
|
+
1.5: spacing(1.5),
|
|
127
|
+
1.75: spacing(1.75),
|
|
128
|
+
2: spacing(2),
|
|
129
|
+
3: spacing(3),
|
|
130
|
+
4: spacing(4),
|
|
131
|
+
5: spacing(5),
|
|
132
|
+
6: spacing(6),
|
|
133
|
+
7: spacing(7),
|
|
134
|
+
8: spacing(8),
|
|
135
|
+
9: spacing(9),
|
|
136
|
+
10: spacing(10),
|
|
137
|
+
auto: "auto"
|
|
138
|
+
};
|
|
139
|
+
const breakpoints = withBreakpointHelpers({
|
|
140
|
+
xs: "0px",
|
|
141
|
+
sm: "600px",
|
|
142
|
+
md: "840px",
|
|
143
|
+
lg: "1200px",
|
|
144
|
+
xl: "1600px"
|
|
145
|
+
});
|
|
146
|
+
const layout = {
|
|
147
|
+
xs: {
|
|
148
|
+
bars: { top: 8 },
|
|
149
|
+
panels: {
|
|
150
|
+
start: {
|
|
151
|
+
mode: "hidden",
|
|
152
|
+
width: "280px",
|
|
153
|
+
railWidth: 9
|
|
154
|
+
},
|
|
155
|
+
end: {
|
|
156
|
+
mode: "hidden",
|
|
157
|
+
width: "360px",
|
|
158
|
+
railWidth: 9
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
content: {
|
|
162
|
+
columns: 4,
|
|
163
|
+
margin: 2,
|
|
164
|
+
gutter: 2,
|
|
165
|
+
mode: "fluid"
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
sm: {
|
|
169
|
+
panels: { start: { mode: "collapsed" } },
|
|
170
|
+
content: {
|
|
171
|
+
columns: 8,
|
|
172
|
+
margin: 4
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
md: {
|
|
176
|
+
panels: { end: { mode: "overlay" } },
|
|
177
|
+
content: {
|
|
178
|
+
columns: 12,
|
|
179
|
+
margin: 3,
|
|
180
|
+
gutter: 3
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
lg: {
|
|
184
|
+
panels: { end: { width: "412px" } },
|
|
185
|
+
content: {
|
|
186
|
+
mode: "fixed",
|
|
187
|
+
maxWidth: "1200px"
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
xl: {
|
|
191
|
+
panels: {
|
|
192
|
+
start: { mode: "inline" },
|
|
193
|
+
end: { mode: "inline" }
|
|
194
|
+
},
|
|
195
|
+
content: { maxWidth: "1600px" }
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const typography = {
|
|
199
|
+
h1: {
|
|
200
|
+
element: "h1",
|
|
201
|
+
fontSize: 6,
|
|
202
|
+
fontWeight: "bold"
|
|
203
|
+
},
|
|
204
|
+
h2: {
|
|
205
|
+
element: "h2",
|
|
206
|
+
fontSize: 5,
|
|
207
|
+
fontWeight: "bold"
|
|
208
|
+
},
|
|
209
|
+
h3: {
|
|
210
|
+
element: "h3",
|
|
211
|
+
fontSize: 4,
|
|
212
|
+
fontWeight: "bold"
|
|
213
|
+
},
|
|
214
|
+
h4: {
|
|
215
|
+
element: "h4",
|
|
216
|
+
fontSize: 3,
|
|
217
|
+
fontWeight: "bold"
|
|
218
|
+
},
|
|
219
|
+
h5: {
|
|
220
|
+
element: "h5",
|
|
221
|
+
fontSize: 2,
|
|
222
|
+
fontWeight: "bold"
|
|
223
|
+
},
|
|
224
|
+
h6: {
|
|
225
|
+
element: "h6",
|
|
226
|
+
fontSize: 1,
|
|
227
|
+
fontWeight: "semiBold"
|
|
228
|
+
},
|
|
229
|
+
subtitle1: {
|
|
230
|
+
element: "h6",
|
|
231
|
+
fontSize: 2,
|
|
232
|
+
fontWeight: "medium"
|
|
233
|
+
},
|
|
234
|
+
subtitle2: {
|
|
235
|
+
element: "h6",
|
|
236
|
+
fontSize: 1,
|
|
237
|
+
fontWeight: "medium"
|
|
238
|
+
},
|
|
239
|
+
body1: {
|
|
240
|
+
element: "p",
|
|
241
|
+
fontSize: 2,
|
|
242
|
+
fontWeight: "normal"
|
|
243
|
+
},
|
|
244
|
+
body2: {
|
|
245
|
+
element: "p",
|
|
246
|
+
fontSize: 1,
|
|
247
|
+
fontWeight: "normal"
|
|
248
|
+
},
|
|
249
|
+
caption: {
|
|
250
|
+
element: "span",
|
|
251
|
+
fontSize: 0,
|
|
252
|
+
fontWeight: "normal"
|
|
253
|
+
},
|
|
254
|
+
overline: {
|
|
255
|
+
element: "span",
|
|
256
|
+
fontSize: 0,
|
|
257
|
+
fontWeight: "medium",
|
|
258
|
+
textTransform: "uppercase",
|
|
259
|
+
letterSpacing: "wider"
|
|
260
|
+
},
|
|
261
|
+
button: {
|
|
262
|
+
element: "span",
|
|
263
|
+
fontSize: 1,
|
|
264
|
+
fontWeight: "medium",
|
|
265
|
+
textTransform: "uppercase",
|
|
266
|
+
letterSpacing: "wide"
|
|
267
|
+
},
|
|
268
|
+
inherit: { element: "span" }
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* The package's complete default theme (dark-schemed). Raw hex only - palettes
|
|
272
|
+
* belong to the consumer, who builds brand themes with `createTheme(baseTheme, ...)`.
|
|
273
|
+
*
|
|
274
|
+
* What is not a CSS value stays what it is (`asIs`, which `defineTheme` writes into the theme's
|
|
275
|
+
* `$modes`): breakpoints, transitions, sizes, typography, layout, and `components` and
|
|
276
|
+
* `defaults`, which an app's themes fill. Every other token is a CSS variable.
|
|
277
|
+
*/
|
|
278
|
+
const baseTheme = defineTheme({
|
|
279
|
+
name: "base",
|
|
280
|
+
switch: { thumb: "#FFFFFF" },
|
|
281
|
+
radii,
|
|
282
|
+
borderWidths,
|
|
283
|
+
fontSizes,
|
|
284
|
+
lineHeights,
|
|
285
|
+
typography: asIs(typography),
|
|
286
|
+
letterSpacings,
|
|
287
|
+
fontWeights,
|
|
288
|
+
fonts,
|
|
289
|
+
avatar,
|
|
290
|
+
icon,
|
|
291
|
+
sizes: asIs(sizes),
|
|
292
|
+
space,
|
|
293
|
+
breakpoints: asIs(breakpoints),
|
|
294
|
+
layout: asIs(layout),
|
|
295
|
+
zOrder,
|
|
296
|
+
transitions: asIs(transitions),
|
|
297
|
+
blur: "12px",
|
|
298
|
+
colorScheme: "dark",
|
|
299
|
+
palette: {
|
|
300
|
+
default: {
|
|
301
|
+
main: "#262626",
|
|
302
|
+
light: "#363636",
|
|
303
|
+
dark: "#0E0E0E",
|
|
304
|
+
contrastText: "#F2F3F4"
|
|
305
|
+
},
|
|
306
|
+
primary: {
|
|
307
|
+
main: "#00FC40",
|
|
308
|
+
light: "#9CFF93",
|
|
309
|
+
dark: "#006413",
|
|
310
|
+
contrastText: "#000000"
|
|
311
|
+
},
|
|
312
|
+
secondary: {
|
|
313
|
+
main: "#b3eeb1",
|
|
314
|
+
light: "#d4f9d2",
|
|
315
|
+
dark: "#5acc57",
|
|
316
|
+
contrastText: "#000000"
|
|
317
|
+
},
|
|
318
|
+
success: {
|
|
319
|
+
main: "#009928",
|
|
320
|
+
light: "#00FC40",
|
|
321
|
+
dark: "#006413",
|
|
322
|
+
contrastText: "#FFFFFF"
|
|
323
|
+
},
|
|
324
|
+
error: {
|
|
325
|
+
main: "#FF3B30",
|
|
326
|
+
light: "#FF9590",
|
|
327
|
+
dark: "#E0251A",
|
|
328
|
+
contrastText: "#FFFFFF"
|
|
329
|
+
},
|
|
330
|
+
info: {
|
|
331
|
+
main: "#00B8D9",
|
|
332
|
+
light: "#33D9FF",
|
|
333
|
+
dark: "#0099CC",
|
|
334
|
+
contrastText: "#000000"
|
|
335
|
+
},
|
|
336
|
+
warning: {
|
|
337
|
+
main: "#FFD930",
|
|
338
|
+
light: "#FFF0A0",
|
|
339
|
+
dark: "#CCA800",
|
|
340
|
+
contrastText: "#000000"
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
background: {
|
|
344
|
+
backdrop: "#000000B3",
|
|
345
|
+
appBar: "#000000B3",
|
|
346
|
+
glass: "#0000004D",
|
|
347
|
+
modal: "#131313",
|
|
348
|
+
default: "#262626",
|
|
349
|
+
primary: "#0E0E0E",
|
|
350
|
+
secondary: "#1A1A1A",
|
|
351
|
+
paper: "#131313",
|
|
352
|
+
terminal: "#000000",
|
|
353
|
+
grid: alpha("#00FC40", .06),
|
|
354
|
+
transparent: "#00000000",
|
|
355
|
+
scrollbar: "#B3B3B380",
|
|
356
|
+
scrollbarTrack: "#38383880"
|
|
357
|
+
},
|
|
358
|
+
text: {
|
|
359
|
+
inherit: "inherit",
|
|
360
|
+
initial: "#FFFFFF",
|
|
361
|
+
primary: "#00FC40",
|
|
362
|
+
secondary: "#9C9C9C",
|
|
363
|
+
disabled: "#363636",
|
|
364
|
+
error: "#D70015",
|
|
365
|
+
success: "#009928",
|
|
366
|
+
info: "#00B8D9",
|
|
367
|
+
warning: "#8C6D00"
|
|
368
|
+
},
|
|
369
|
+
border: {
|
|
370
|
+
default: "#262626",
|
|
371
|
+
light: alpha("#E8FFE5", .1),
|
|
372
|
+
primary: "#00FC40",
|
|
373
|
+
dark: "#006413"
|
|
374
|
+
},
|
|
375
|
+
skeleton: { highlight: alpha("#363636", .65) },
|
|
376
|
+
logoFilter: "brightness(0) invert(1)",
|
|
377
|
+
portraitBlend: "screen",
|
|
378
|
+
portraitOpacity: .8,
|
|
379
|
+
shadow,
|
|
380
|
+
shadows,
|
|
381
|
+
components: asIs({}),
|
|
382
|
+
defaults: asIs({})
|
|
383
|
+
});
|
|
384
|
+
/**
|
|
385
|
+
* The query helpers for `baseTheme`'s breakpoints, as plain functions. A theme with its own
|
|
386
|
+
* breakpoints has the same helpers on `theme.breakpoints`.
|
|
387
|
+
*/
|
|
388
|
+
const { up, down, only, between, not, containerQueries } = breakpoints;
|
|
389
|
+
// src/theme/createTheme.ts
|
|
390
|
+
/**
|
|
391
|
+
* Builds a theme by deep-merging sparse `overrides` onto `base`.
|
|
392
|
+
*
|
|
393
|
+
* - Recurses only where both sides are plain objects; arrays (`shadows`,
|
|
394
|
+
* `fontSizes`) and functions replace wholesale.
|
|
395
|
+
* - `undefined` override values are ignored - a key can be added or replaced,
|
|
396
|
+
* never removed.
|
|
397
|
+
* - Neither argument is mutated; untouched branches keep referential identity.
|
|
398
|
+
* - `breakpoints` gets its query helpers back, built from the merged sizes.
|
|
399
|
+
* - The returned type keeps what the overrides add - see `ThemeMerge`.
|
|
400
|
+
*/
|
|
401
|
+
const createTheme = (base, overrides) => {
|
|
402
|
+
const theme = deepMerge(base, overrides);
|
|
403
|
+
return withHelpers(theme);
|
|
404
|
+
};
|
|
405
|
+
/** A theme whose `breakpoints` carry the query helpers - added when a hand-built theme lacks them. */
|
|
406
|
+
const withHelpers = (theme) => theme.breakpoints && !("up" in theme.breakpoints) ? {
|
|
407
|
+
...theme,
|
|
408
|
+
breakpoints: withBreakpointHelpers(theme.breakpoints)
|
|
409
|
+
} : theme;
|
|
410
|
+
// src/theme/defineThemes.ts
|
|
411
|
+
const rawPaths = (theme) => "$modes" in theme && typeof theme.$modes === "object" && theme.$modes ? Object.entries(theme.$modes).filter(([path, mode]) => (mode === "asIs" || mode === "raw") && path !== "components").map(([path]) => path) : [];
|
|
412
|
+
const at = (value, path) => path.split(".").reduce((from, key) => from?.[key], value);
|
|
413
|
+
/** The path of the first difference between two values, or `undefined` when there is none. */
|
|
414
|
+
const firstDifference = (a, b, path) => {
|
|
415
|
+
if (typeof a !== "object" || typeof b !== "object" || !a || !b) return Object.is(a, b) ? void 0 : path;
|
|
416
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
417
|
+
const found = firstDifference(a[key], b[key], `${path}.${key}`);
|
|
418
|
+
if (found) return found;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
const warnAboutRawTokens = (themes) => {
|
|
422
|
+
const [[firstName, base] = []] = Object.entries(themes);
|
|
423
|
+
if (!base) return;
|
|
424
|
+
for (const [name, theme] of Object.entries(themes)) for (const path of rawPaths(base)) {
|
|
425
|
+
const found = firstDifference(at(base, path), at(theme, path), path);
|
|
426
|
+
if (!found) continue;
|
|
427
|
+
console.warn(`[soroush] Theme "${name}" and "${firstName}" differ at ${found}: server components always render with the serverTheme you pass to configure. Keep raw tokens (breakpoints, sizes, typography, layout, transitions, defaults) the same in every theme; colours, spacing and font sizes may differ.`);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* Defines an app's themes: every theme in `themes` gets the one `components` object - the
|
|
433
|
+
* customization of the components, the same in every theme - and the types check that all themes
|
|
434
|
+
* have exactly the same keys, at every depth, so one theme cannot lack a color another has (the
|
|
435
|
+
* error names the theme and the key). The values may differ.
|
|
436
|
+
*
|
|
437
|
+
* Check `components` where it is written, with `satisfies ThemeComponents` from the React library
|
|
438
|
+
* (this package cannot know a framework's slots); it is kept as written, so a look such as
|
|
439
|
+
* `variant: 'pill'` is known to the types once the themes are registered (see `Register`).
|
|
440
|
+
*
|
|
441
|
+
* Returns new objects: neither the themes nor `components` is changed, as the styling engine
|
|
442
|
+
* requires a theme object not to change once it is in use.
|
|
443
|
+
*/
|
|
444
|
+
const defineThemes = (themes, components = {}) => {
|
|
445
|
+
if (process.env.NODE_ENV !== "production") warnAboutRawTokens(themes);
|
|
446
|
+
return Object.fromEntries(Object.entries(themes).map(([name, theme]) => [name, {
|
|
447
|
+
...theme,
|
|
448
|
+
components
|
|
449
|
+
}]));
|
|
450
|
+
};
|
|
451
|
+
export { avatar, baseTheme, between, borderWidths, breakpoints, containerQueries, createTheme, defineThemes, down, fontSizes, fontWeights, fonts, icon, layout, letterSpacings, lineHeights, not, only, radii, sizes, space, spacing, themeDefault, transitions, typography, up, zOrder };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/utils/clamp.ts
|
|
2
|
+
/** Clamps `value` to the inclusive range `[min, max]`. */
|
|
3
|
+
function clamp(value, min, max) {
|
|
4
|
+
return Math.min(Math.max(value, min), max);
|
|
5
|
+
}
|
|
6
|
+
// src/utils/alpha.ts
|
|
7
|
+
/**
|
|
8
|
+
* Appends an alpha channel to a 6-digit hex color, producing an 8-digit `#RRGGBBAA` hex.
|
|
9
|
+
* @param color - 6-digit hex string, e.g. `'#4ade80'`
|
|
10
|
+
* @param opacity - alpha from `0` (transparent) to `1` (opaque)
|
|
11
|
+
* @returns 8-digit hex string, e.g. `'#4ade801A'`
|
|
12
|
+
* @example alpha('#4ade80', 0.1) // '#4ade801A'
|
|
13
|
+
*/
|
|
14
|
+
const alpha = (color, opacity) => {
|
|
15
|
+
return `${color}${Math.round(clamp(opacity, 0, 1) * 255).toString(16).padStart(2, "0").toUpperCase()}`;
|
|
16
|
+
};
|
|
17
|
+
// src/utils/generateBoxShadow.ts
|
|
18
|
+
const generateBoxShadow = (elevation, shadowColor) => {
|
|
19
|
+
return `0 ${elevation}px ${elevation * 2}px ${shadowColor}`;
|
|
20
|
+
};
|
|
21
|
+
// src/utils/deepMerge.ts
|
|
22
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
/**
|
|
24
|
+
* Merges `overrides` onto `base`, recursing only where both sides are plain objects; arrays and
|
|
25
|
+
* functions replace wholesale and `undefined` values are ignored. Neither argument is mutated.
|
|
26
|
+
*/
|
|
27
|
+
const deepMerge = (base, overrides) => {
|
|
28
|
+
const merged = { ...base };
|
|
29
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
30
|
+
if (value === void 0) continue;
|
|
31
|
+
const baseValue = merged[key];
|
|
32
|
+
merged[key] = isPlainObject(baseValue) && isPlainObject(value) ? deepMerge(baseValue, value) : value;
|
|
33
|
+
}
|
|
34
|
+
return merged;
|
|
35
|
+
};
|
|
36
|
+
// src/theme/themeDefault.ts
|
|
37
|
+
/**
|
|
38
|
+
* Resolves a component's default token/variant key: the theme's optional
|
|
39
|
+
* `defaults` override wins, otherwise the component's literal `fallback`.
|
|
40
|
+
* Components call this in their prop defaults (`size = themeDefault(theme,
|
|
41
|
+
* 'size', 'md')`) so every built-in default stays visible in the component
|
|
42
|
+
* yet overridable per theme or via `ThemeProvider`'s `defaults` prop.
|
|
43
|
+
*/
|
|
44
|
+
const themeDefault = (theme, key, fallback) => theme.defaults?.[key] ?? fallback;
|
|
45
|
+
Object.defineProperty(exports, "alpha", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function() {
|
|
48
|
+
return alpha;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "clamp", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return clamp;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, "deepMerge", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function() {
|
|
60
|
+
return deepMerge;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(exports, "generateBoxShadow", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
get: function() {
|
|
66
|
+
return generateBoxShadow;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "themeDefault", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function() {
|
|
72
|
+
return themeDefault;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/utils/clamp.ts
|
|
2
|
+
/** Clamps `value` to the inclusive range `[min, max]`. */
|
|
3
|
+
function clamp(value, min, max) {
|
|
4
|
+
return Math.min(Math.max(value, min), max);
|
|
5
|
+
}
|
|
6
|
+
// src/utils/alpha.ts
|
|
7
|
+
/**
|
|
8
|
+
* Appends an alpha channel to a 6-digit hex color, producing an 8-digit `#RRGGBBAA` hex.
|
|
9
|
+
* @param color - 6-digit hex string, e.g. `'#4ade80'`
|
|
10
|
+
* @param opacity - alpha from `0` (transparent) to `1` (opaque)
|
|
11
|
+
* @returns 8-digit hex string, e.g. `'#4ade801A'`
|
|
12
|
+
* @example alpha('#4ade80', 0.1) // '#4ade801A'
|
|
13
|
+
*/
|
|
14
|
+
const alpha = (color, opacity) => {
|
|
15
|
+
return `${color}${Math.round(clamp(opacity, 0, 1) * 255).toString(16).padStart(2, "0").toUpperCase()}`;
|
|
16
|
+
};
|
|
17
|
+
// src/utils/generateBoxShadow.ts
|
|
18
|
+
const generateBoxShadow = (elevation, shadowColor) => {
|
|
19
|
+
return `0 ${elevation}px ${elevation * 2}px ${shadowColor}`;
|
|
20
|
+
};
|
|
21
|
+
// src/utils/deepMerge.ts
|
|
22
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23
|
+
/**
|
|
24
|
+
* Merges `overrides` onto `base`, recursing only where both sides are plain objects; arrays and
|
|
25
|
+
* functions replace wholesale and `undefined` values are ignored. Neither argument is mutated.
|
|
26
|
+
*/
|
|
27
|
+
const deepMerge = (base, overrides) => {
|
|
28
|
+
const merged = { ...base };
|
|
29
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
30
|
+
if (value === void 0) continue;
|
|
31
|
+
const baseValue = merged[key];
|
|
32
|
+
merged[key] = isPlainObject(baseValue) && isPlainObject(value) ? deepMerge(baseValue, value) : value;
|
|
33
|
+
}
|
|
34
|
+
return merged;
|
|
35
|
+
};
|
|
36
|
+
// src/theme/themeDefault.ts
|
|
37
|
+
/**
|
|
38
|
+
* Resolves a component's default token/variant key: the theme's optional
|
|
39
|
+
* `defaults` override wins, otherwise the component's literal `fallback`.
|
|
40
|
+
* Components call this in their prop defaults (`size = themeDefault(theme,
|
|
41
|
+
* 'size', 'md')`) so every built-in default stays visible in the component
|
|
42
|
+
* yet overridable per theme or via `ThemeProvider`'s `defaults` prop.
|
|
43
|
+
*/
|
|
44
|
+
const themeDefault = (theme, key, fallback) => theme.defaults?.[key] ?? fallback;
|
|
45
|
+
export { clamp as a, alpha as i, deepMerge as n, generateBoxShadow as r, themeDefault as t };
|