@gild-ui/core 0.0.0 → 0.1.0-alpha.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.
@@ -0,0 +1,411 @@
1
+ import { t as BreakpointHelpers } from "./index-BVkniYfB.mjs";
2
+ /**
3
+ * Re-opens a named scale interface as an anonymous mapped type. Named
4
+ * interfaces have no implicit index signature, which styled-system's
5
+ * Record-based `Theme` constraint requires - the mapped copy restores it
6
+ * while keeping the literal keys (and any consumer-augmented keys).
7
+ */
8
+ type OpenScale<T> = { [K in keyof T]: T[K]; };
9
+ /** One semantic color of `theme.palette`. */
10
+ interface PaletteEntry {
11
+ main: string;
12
+ light: string;
13
+ dark: string;
14
+ contrastText: string;
15
+ }
16
+ interface ThemePalette {
17
+ default: PaletteEntry;
18
+ primary: PaletteEntry;
19
+ secondary: PaletteEntry;
20
+ success: PaletteEntry;
21
+ error: PaletteEntry;
22
+ info: PaletteEntry;
23
+ warning: PaletteEntry;
24
+ }
25
+ interface ThemeText {
26
+ inherit: string;
27
+ initial: string;
28
+ primary: string;
29
+ secondary: string;
30
+ disabled: string;
31
+ error: string;
32
+ success: string;
33
+ info: string;
34
+ warning: string;
35
+ }
36
+ interface ThemeBackground {
37
+ backdrop: string;
38
+ /** App bar / sticky header surface. Light in light theme; `backdrop` stays dark for scrims. */
39
+ appBar: string;
40
+ glass: string;
41
+ modal: string;
42
+ default: string;
43
+ primary: string;
44
+ secondary?: string;
45
+ paper: string;
46
+ terminal: string;
47
+ grid: string;
48
+ transparent: string;
49
+ /** The thumb of a drawn scrollbar (`ScrollArea`). */
50
+ scrollbar: string;
51
+ /** The track of a drawn scrollbar, while it is hovered or dragged. */
52
+ scrollbarTrack: string;
53
+ }
54
+ interface ThemeBorder {
55
+ default?: string;
56
+ light?: string;
57
+ primary: string;
58
+ dark?: string;
59
+ }
60
+ interface ThemeFonts {
61
+ body: string;
62
+ heading: string;
63
+ mono: string;
64
+ }
65
+ /** Skeleton placeholder tokens. `highlight` is the wave-animation shimmer band. */
66
+ interface ThemeSkeleton {
67
+ highlight: string;
68
+ }
69
+ /** Switch control tokens. The thumb stays light in both modes so it reads on any track. */
70
+ interface ThemeSwitch {
71
+ /** Thumb fill. Its elevation shadow composites from `theme.shadow.color`. */
72
+ thumb: string;
73
+ }
74
+ /**
75
+ * Shadow tokens - the single base color every shadow composites from
76
+ * (the `theme.shadows` elevation array and component shadows alike).
77
+ */
78
+ interface ThemeShadow {
79
+ /** Opaque base color of all shadows. */
80
+ color: string;
81
+ /** Alpha applied per elevation step in the default `theme.shadows` array. */
82
+ opacity: number;
83
+ }
84
+ /** Stacking order for layered UI - ascending: appBar < drawer < modal. */
85
+ interface ThemeZOrder {
86
+ appBar: number;
87
+ drawer: number;
88
+ modal: number;
89
+ snackbar: number;
90
+ tooltip: number;
91
+ }
92
+ /** The durations of `theme.transitions.duration`, in milliseconds. */
93
+ interface ThemeTransitionDuration {
94
+ short: number;
95
+ standard: number;
96
+ long: number;
97
+ }
98
+ /** The easings of `theme.transitions.easing` - CSS timing functions. */
99
+ interface ThemeTransitionEasing {
100
+ standard: string;
101
+ enter: string;
102
+ exit: string;
103
+ }
104
+ /** How long and how smoothly things move - read by `Collapse`, `Fade`, `Grow`, `Slide` and `Zoom`. */
105
+ interface ThemeTransitions {
106
+ duration: OpenScale<ThemeTransitionDuration>;
107
+ easing: OpenScale<ThemeTransitionEasing>;
108
+ }
109
+ interface ThemeRadii {
110
+ sq: string;
111
+ sm: string;
112
+ md: string;
113
+ lg: string;
114
+ }
115
+ interface ThemeBorderWidths {
116
+ none: string;
117
+ thin: string;
118
+ base: string;
119
+ thick: string;
120
+ }
121
+ interface ThemeAvatarSizes {
122
+ sm: string;
123
+ md: string;
124
+ lg: string;
125
+ xl: string;
126
+ }
127
+ interface ThemeFontWeights {
128
+ thin: number;
129
+ extraLight: number;
130
+ light: number;
131
+ normal: number;
132
+ medium: number;
133
+ semiBold: number;
134
+ bold: number;
135
+ extraBold: number;
136
+ black: number;
137
+ }
138
+ interface ThemeLineHeights {
139
+ none: number;
140
+ tight: number;
141
+ snug: number;
142
+ base: number;
143
+ relaxed: number;
144
+ loose: number;
145
+ }
146
+ interface ThemeLetterSpacings {
147
+ tighter: string;
148
+ tight: string;
149
+ normal: string;
150
+ wide: string;
151
+ wider: string;
152
+ widest: string;
153
+ }
154
+ interface ThemeSpace {
155
+ auto: string;
156
+ 0: number | string;
157
+ 0.125: number | string;
158
+ 0.25: number | string;
159
+ 0.5: number | string;
160
+ 0.75: number | string;
161
+ 1: number | string;
162
+ 1.25: number | string;
163
+ 1.5: number | string;
164
+ 1.75: number | string;
165
+ 2: number | string;
166
+ 3: number | string;
167
+ 4: number | string;
168
+ 5: number | string;
169
+ 6: number | string;
170
+ 7: number | string;
171
+ 8: number | string;
172
+ 9: number | string;
173
+ 10: number | string;
174
+ }
175
+ /** One padding/font preset of `theme.sizes`. */
176
+ interface SizeEntry {
177
+ paddingTop: Exclude<keyof ThemeSpace, 'auto'>;
178
+ paddingBottom: Exclude<keyof ThemeSpace, 'auto'>;
179
+ paddingLeft: Exclude<keyof ThemeSpace, 'auto'>;
180
+ paddingRight: Exclude<keyof ThemeSpace, 'auto'>;
181
+ /** Index into `theme.fontSizes`. */
182
+ fontSize: number;
183
+ }
184
+ interface ThemeSizes {
185
+ sm: SizeEntry;
186
+ md: SizeEntry;
187
+ lg: SizeEntry;
188
+ }
189
+ /**
190
+ * Square glyph dimension per density key - Icon token sizes and the
191
+ * Checkbox/Radio glyphs. Mapped over `ThemeSizes` so augmenting a size key
192
+ * forces the matching icon size to be supplied.
193
+ */
194
+ type ThemeIconSizes = { [K in keyof ThemeSizes]: string; };
195
+ /** The default breakpoint names - Material 3's window classes. */
196
+ interface DefaultBreakpoints {
197
+ /** compact: 0-599px - the base, applies everywhere until `sm` overrides it. */
198
+ xs: true;
199
+ /** medium: 600-839px. */
200
+ sm: true;
201
+ /** expanded: 840-1199px. */
202
+ md: true;
203
+ /** large: 1200-1599px. */
204
+ lg: true;
205
+ /** extra-large: 1600px and up. */
206
+ xl: true;
207
+ }
208
+ /**
209
+ * Add, rename or remove breakpoints by augmenting this interface: `true` adds a name, `false`
210
+ * removes a default one.
211
+ *
212
+ * declare module '@gild-ui/core/theme' {
213
+ * interface BreakpointOverrides { mobile: true; tablet: true; xs: false; sm: false }
214
+ * }
215
+ */
216
+ interface BreakpointOverrides {}
217
+ type RemovedBreakpoints = keyof { [K in keyof BreakpointOverrides as BreakpointOverrides[K] extends false ? K : never]: true; };
218
+ /** The theme's breakpoint names: the defaults, plus every override set to `true`, minus every one set to `false`. */
219
+ type BreakpointKey = Exclude<keyof (Omit<DefaultBreakpoints, keyof BreakpointOverrides> & BreakpointOverrides), RemovedBreakpoints>;
220
+ /**
221
+ * `theme.breakpoints`: where each window class starts, ascending, in declared order. A key holds
222
+ * from its value until the next key, so `xs: '0px'` applies everywhere until `sm` overrides it;
223
+ * media queries are min-width, which is why the theme writes the start of each range. Responsive
224
+ * props map onto the keys by name, or by position for an array. A value is a CSS length; a
225
+ * media condition or a full `@media` rule is passed through, without the range helpers.
226
+ * `createTheme` appends a breakpoint you add after the existing ones, so it must be larger.
227
+ */
228
+ type ThemeBreakpoints = { [K in BreakpointKey]: string; };
229
+ /** A `theme.space` key - layout margins and gutters step on the spacing scale. */
230
+ type LayoutSpace = Exclude<keyof ThemeSpace, 'auto'>;
231
+ /** A `theme.space` key or a CSS length (a 280px panel is a size, not a spacing step). */
232
+ type LayoutLength = LayoutSpace | string;
233
+ /** Bar heights at the top and bottom of the page; `0` removes an inherited bar. */
234
+ interface LayoutBars {
235
+ top?: LayoutLength;
236
+ bottom?: LayoutLength;
237
+ }
238
+ /** A side panel: a track (`inline`), over the content (`overlay`), its rail (`collapsed`) or absent (`hidden`). */
239
+ interface LayoutPanel {
240
+ mode: 'inline' | 'overlay' | 'collapsed' | 'hidden';
241
+ /** Open width. */
242
+ width: LayoutLength;
243
+ /** Collapsed width. */
244
+ railWidth: LayoutLength;
245
+ }
246
+ /** Side panels by logical side - `start` and `end` flip in RTL. */
247
+ interface LayoutPanels {
248
+ start?: LayoutPanel;
249
+ end?: LayoutPanel;
250
+ }
251
+ /** The content columns, measured in the space the bars and inline panels leave. */
252
+ interface LayoutContent {
253
+ columns: number;
254
+ /** Inline padding of the content. */
255
+ margin: LayoutSpace;
256
+ /** Gap between columns. */
257
+ gutter: LayoutSpace;
258
+ /** `fluid` spans the space; `fixed` is a container centred at `maxWidth`. */
259
+ mode: 'fluid' | 'fixed';
260
+ maxWidth?: LayoutLength;
261
+ }
262
+ /** The page layout at one breakpoint. */
263
+ interface LayoutEntry {
264
+ bars: LayoutBars;
265
+ panels: LayoutPanels;
266
+ content: LayoutContent;
267
+ }
268
+ /**
269
+ * `theme.layout`: layout tokens per breakpoint, merged mobile-first in breakpoint order. The
270
+ * first breakpoint's entry (`xs`) is complete; every later one lists only what changes. A panel
271
+ * first declared at a later breakpoint needs its `mode`, `width` and `railWidth` there. These
272
+ * are tokens: apps (and the studio) read them; nothing in the design system lays a page out.
273
+ */
274
+ type ThemeLayout = { [K in BreakpointKey]?: {
275
+ bars?: LayoutBars;
276
+ panels?: { [P in keyof LayoutPanels]?: Partial<LayoutPanel>; };
277
+ content?: Partial<LayoutContent>;
278
+ }; };
279
+ /** The values of the CSS `text-transform` property. */
280
+ type TextTransform = 'none' | 'capitalize' | 'uppercase' | 'lowercase' | 'full-width' | 'full-size-kana' | 'inherit' | 'initial' | 'revert' | 'revert-layer' | 'unset';
281
+ /** Style of one typography variant. */
282
+ interface TypographyVariantStyle {
283
+ /** The tag name the variant renders as - `'h1'`, `'span'`. */
284
+ element: string;
285
+ fontSize?: number;
286
+ fontWeight?: string;
287
+ letterSpacing?: string;
288
+ textTransform?: TextTransform;
289
+ }
290
+ interface ThemeTypographyVariants {
291
+ h1: TypographyVariantStyle;
292
+ h2: TypographyVariantStyle;
293
+ h3: TypographyVariantStyle;
294
+ h4: TypographyVariantStyle;
295
+ h5: TypographyVariantStyle;
296
+ h6: TypographyVariantStyle;
297
+ subtitle1: TypographyVariantStyle;
298
+ subtitle2: TypographyVariantStyle;
299
+ body1: TypographyVariantStyle;
300
+ body2: TypographyVariantStyle;
301
+ caption: TypographyVariantStyle;
302
+ overline: TypographyVariantStyle;
303
+ button: TypographyVariantStyle;
304
+ inherit: TypographyVariantStyle;
305
+ }
306
+ /**
307
+ * Optional theme-driven component defaults. Components carry their own
308
+ * literal fallbacks (`size = 'md'`, `variant = 'outside'`, ...) and resolve
309
+ * them through `themeDefault(theme, key, fallback)` - set any key here (or
310
+ * via `ThemeProvider`'s `defaults` prop) to override that fallback globally,
311
+ * e.g. when your theme uses entirely different size or palette keys.
312
+ */
313
+ interface ThemeDefaults {
314
+ /** Density token for sized components. Fallback: `'md'`. */
315
+ size?: keyof ThemeSizes;
316
+ /** Compact density for dense secondary UI (table pagination actions). Fallback: `'sm'`. */
317
+ compactSize?: keyof ThemeSizes;
318
+ /** Accent palette color (buttons, links, progress, pagination...). Fallback: `'primary'`. */
319
+ color?: keyof ThemePalette;
320
+ /** Neutral palette color for toggle controls (checkbox, radio, switch...). Fallback: `'default'`. */
321
+ neutralColor?: keyof ThemePalette;
322
+ /** Body text color. Fallback: `'initial'`. */
323
+ textColor?: keyof ThemeText;
324
+ /** Accent text color (icons, input labels). Fallback: `'primary'`. */
325
+ accentTextColor?: keyof ThemeText;
326
+ /** General control background (switch track). Fallback: `'default'`. */
327
+ bg?: keyof ThemeBackground;
328
+ /** Elevated surface background (paper, cards). Fallback: `'paper'`. */
329
+ surfaceBg?: keyof ThemeBackground;
330
+ /** Input surface background (selects, text inputs). Fallback: `'terminal'`. */
331
+ inputBg?: keyof ThemeBackground;
332
+ /** Corner radius for grouped controls. Fallback: `'md'`. */
333
+ borderRadius?: keyof ThemeRadii;
334
+ /** Corner radius for surfaces. Fallback: `'sq'`. */
335
+ surfaceRadius?: keyof ThemeRadii;
336
+ /** Avatar size step. Fallback: `'md'`. */
337
+ avatarSize?: keyof ThemeAvatarSizes;
338
+ /** Icon glyph size step. Fallback: `'lg'`. */
339
+ iconSize?: keyof ThemeIconSizes;
340
+ /** Least width of an input that does not fill its row (text, number, select, autocomplete) - a CSS length. Fallback: `'12rem'`. */
341
+ inputMinWidth?: string;
342
+ /** Border/ring color. Fallback: `'primary'`. */
343
+ borderColor?: keyof ThemeBorder;
344
+ /** Border/ring width. Fallback: `'thin'`. */
345
+ borderWidth?: keyof ThemeBorderWidths;
346
+ /** Button visual variant. Fallback: `'contained'`. */
347
+ buttonVariant?: keyof ButtonVariants;
348
+ /** Switch thumb/track layout. Fallback: `'outside'`. */
349
+ switchVariant?: 'outside' | 'inside';
350
+ /** Input frame style (TextInput, Select, NativeSelect). Fallback: `'default'`. */
351
+ inputVariant?: InputVariantKey;
352
+ /** Avatar shape. Fallback: `'circular'`. */
353
+ avatarVariant?: 'circular' | 'rounded' | 'square';
354
+ /** Link underline behavior. Fallback: `'always'`. */
355
+ linkUnderline?: 'always' | 'hover' | 'none';
356
+ /** Card surface treatment. Fallback: `'paper'`. */
357
+ cardVariant?: 'paper' | 'bracketBox' | 'interactive';
358
+ /** Pagination item visual variant. Fallback: `'text'`. */
359
+ paginationVariant?: 'text' | 'outlined';
360
+ /** Pagination item shape. Fallback: `'circular'`. */
361
+ paginationShape?: 'circular' | 'rounded';
362
+ }
363
+ /** The frames a form input is drawn in. */
364
+ type InputVariantKey = 'default' | 'outlined' | 'text' | 'underline';
365
+ /** Button's variant values - augment to register new ones (then style them via `variants`). */
366
+ interface ButtonVariants {
367
+ contained: true;
368
+ outlined: true;
369
+ text: true;
370
+ }
371
+ interface Theme {
372
+ name: string;
373
+ /** Optional overrides for component default token/variant keys - see `ThemeDefaults`. */
374
+ defaults?: OpenScale<ThemeDefaults>;
375
+ space: OpenScale<ThemeSpace>;
376
+ breakpoints: OpenScale<ThemeBreakpoints & BreakpointHelpers>;
377
+ layout: ThemeLayout;
378
+ border: OpenScale<ThemeBorder>;
379
+ text: OpenScale<ThemeText>;
380
+ background: OpenScale<ThemeBackground>;
381
+ typography: OpenScale<ThemeTypographyVariants>;
382
+ fonts: OpenScale<ThemeFonts>;
383
+ lineHeights: OpenScale<ThemeLineHeights>;
384
+ letterSpacings: OpenScale<ThemeLetterSpacings>;
385
+ fontSizes: number[];
386
+ radii: OpenScale<ThemeRadii>;
387
+ borderWidths: OpenScale<ThemeBorderWidths>;
388
+ avatar: OpenScale<ThemeAvatarSizes>;
389
+ icon: ThemeIconSizes;
390
+ skeleton: OpenScale<ThemeSkeleton>;
391
+ switch: OpenScale<ThemeSwitch>;
392
+ shadow: OpenScale<ThemeShadow>;
393
+ sizes: { [K in keyof ThemeSizes]: OpenScale<ThemeSizes[K]>; };
394
+ colorScheme: 'light' | 'dark';
395
+ blur: string;
396
+ logoFilter: string;
397
+ /** mix-blend-mode for the AboutHero portrait - screen on dark, multiply on light. */
398
+ portraitBlend: string;
399
+ /** opacity for the AboutHero portrait. */
400
+ portraitOpacity: number;
401
+ shadows: string[];
402
+ fontWeights: OpenScale<ThemeFontWeights>;
403
+ palette: OpenScale<ThemePalette>;
404
+ zOrder: OpenScale<ThemeZOrder>;
405
+ transitions: ThemeTransitions;
406
+ }
407
+ /** The semantic color keys of `theme.palette`. */
408
+ type PaletteColor = keyof ThemePalette;
409
+ /** The variant keys of `theme.typography`. */
410
+ type TypographyVariant = keyof ThemeTypographyVariants;
411
+ export { ThemeLineHeights as A, ThemeTransitionEasing as B, ThemeBreakpoints as C, ThemeIconSizes as D, ThemeFonts as E, ThemeSkeleton as F, TypographyVariantStyle as G, ThemeTypographyVariants as H, ThemeSpace as I, ThemeSwitch as L, ThemeRadii as M, ThemeShadow as N, ThemeLayout as O, ThemeSizes as P, ThemeText as R, ThemeBorderWidths as S, ThemeFontWeights as T, ThemeZOrder as U, ThemeTransitions as V, TypographyVariant as W, TextTransform as _, InputVariantKey as a, ThemeBackground as b, LayoutEntry as c, LayoutPanels as d, LayoutSpace as f, SizeEntry as g, PaletteEntry as h, DefaultBreakpoints as i, ThemePalette as j, ThemeLetterSpacings as k, LayoutLength as l, PaletteColor as m, BreakpointOverrides as n, LayoutBars as o, OpenScale as p, ButtonVariants as r, LayoutContent as s, BreakpointKey as t, LayoutPanel as u, Theme as v, ThemeDefaults as w, ThemeBorder as x, ThemeAvatarSizes as y, ThemeTransitionDuration as z };
package/dist/utils.cjs ADDED
@@ -0,0 +1,63 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_themeDefault = require("./themeDefault-CjYwGUsb.cjs");
3
+ // src/utils/getAnchorRel.ts
4
+ /**
5
+ * The `rel` of an anchor: as given, else `noopener noreferrer` when it opens a new tab, so the
6
+ * page it opens can't reach back to this one through `window.opener`.
7
+ */
8
+ const getAnchorRel = (target, rel) => target === "_blank" && rel === void 0 ? "noopener noreferrer" : rel;
9
+ // src/utils/getShapeRadius.ts
10
+ /**
11
+ * The corner radius of a shape. Only `rounded` takes a radius - `rounded` is the one the
12
+ * `borderRadius` prop and the theme's radii set; `square` is none and `pill` is a full round.
13
+ */
14
+ const getShapeRadius = (shape, rounded) => {
15
+ if (shape === "square") return 0;
16
+ if (shape === "pill") return "9999px";
17
+ return rounded;
18
+ };
19
+ // src/utils/getSurfaceRadius.ts
20
+ /** The corner radius of a surface: the one asked for, else `theme.defaults.surfaceRadius`, else square. */
21
+ const getSurfaceRadius = (theme, borderRadius) => theme.radii[borderRadius ?? require_themeDefault.themeDefault(theme, "surfaceRadius", "sq")];
22
+ // src/utils/luminance.ts
23
+ function luminance(hex) {
24
+ const r = Number.parseInt(hex.slice(1, 3), 16);
25
+ const g = Number.parseInt(hex.slice(3, 5), 16);
26
+ const b = Number.parseInt(hex.slice(5, 7), 16);
27
+ return (.299 * r + .587 * g + .114 * b) / 255;
28
+ }
29
+ // src/utils/precision.ts
30
+ /** How many decimals a step has - `1e-8` has eight, `0.5` one, `1` none. */
31
+ function getDecimalPrecision(step) {
32
+ const [mantissa, exponent] = step.toExponential().split("e");
33
+ const decimals = (mantissa.split(".")[1] ?? "").length;
34
+ return Math.max(0, decimals - Number(exponent));
35
+ }
36
+ /** The value rounded to the nearest step of `precision` - `null` stays `null`. */
37
+ function roundToPrecision(value, precision) {
38
+ if (value === null) return null;
39
+ const nearest = Math.round(value / precision) * precision;
40
+ return Number(nearest.toFixed(getDecimalPrecision(precision)));
41
+ }
42
+ /** The number moved by `delta`, with no float noise - `0.1 + 0.2` is `0.3`. */
43
+ function addExact(value, delta) {
44
+ const decimals = Math.max(getDecimalPrecision(value), getDecimalPrecision(delta));
45
+ return Number((value + delta).toFixed(decimals));
46
+ }
47
+ /** The nearest number on the grid of `step`, counted from `origin`. */
48
+ function snapToStep(value, step, origin) {
49
+ const decimals = Math.max(getDecimalPrecision(step), getDecimalPrecision(origin));
50
+ return Number((Math.round((value - origin) / step) * step + origin).toFixed(decimals));
51
+ }
52
+ exports.addExact = addExact;
53
+ exports.alpha = require_themeDefault.alpha;
54
+ exports.clamp = require_themeDefault.clamp;
55
+ exports.deepMerge = require_themeDefault.deepMerge;
56
+ exports.generateBoxShadow = require_themeDefault.generateBoxShadow;
57
+ exports.getAnchorRel = getAnchorRel;
58
+ exports.getDecimalPrecision = getDecimalPrecision;
59
+ exports.getShapeRadius = getShapeRadius;
60
+ exports.getSurfaceRadius = getSurfaceRadius;
61
+ exports.luminance = luminance;
62
+ exports.roundToPrecision = roundToPrecision;
63
+ exports.snapToStep = snapToStep;
@@ -0,0 +1,40 @@
1
+ import { v as Theme } from "./types-DIyGsvvF.cjs";
2
+ /**
3
+ * Appends an alpha channel to a 6-digit hex color, producing an 8-digit `#RRGGBBAA` hex.
4
+ * @param color - 6-digit hex string, e.g. `'#4ade80'`
5
+ * @param opacity - alpha from `0` (transparent) to `1` (opaque)
6
+ * @returns 8-digit hex string, e.g. `'#4ade801A'`
7
+ * @example alpha('#4ade80', 0.1) // '#4ade801A'
8
+ */
9
+ export declare const alpha: (color: string, opacity: number) => string;
10
+ /** Clamps `value` to the inclusive range `[min, max]`. */
11
+ export declare function clamp(value: number, min: number, max: number): number;
12
+ /**
13
+ * Merges `overrides` onto `base`, recursing only where both sides are plain objects; arrays and
14
+ * functions replace wholesale and `undefined` values are ignored. Neither argument is mutated.
15
+ */
16
+ export declare const deepMerge: (base: Record<string, unknown>, overrides: Record<string, unknown>) => Record<string, unknown>;
17
+ export declare const generateBoxShadow: (elevation: number, shadowColor: string) => string;
18
+ /**
19
+ * The `rel` of an anchor: as given, else `noopener noreferrer` when it opens a new tab, so the
20
+ * page it opens can't reach back to this one through `window.opener`.
21
+ */
22
+ export declare const getAnchorRel: (target: string | undefined, rel: string | undefined) => string | undefined;
23
+ /** The corner shapes of a control or a surface: square, rounded by a radius, or a full pill. */
24
+ export type Shape = 'square' | 'rounded' | 'pill';
25
+ /**
26
+ * The corner radius of a shape. Only `rounded` takes a radius - `rounded` is the one the
27
+ * `borderRadius` prop and the theme's radii set; `square` is none and `pill` is a full round.
28
+ */
29
+ export declare const getShapeRadius: (shape: Shape, rounded: string | number) => string | number;
30
+ /** The corner radius of a surface: the one asked for, else `theme.defaults.surfaceRadius`, else square. */
31
+ export declare const getSurfaceRadius: (theme: Theme, borderRadius?: keyof Theme['radii']) => string;
32
+ export declare function luminance(hex: string): number;
33
+ /** How many decimals a step has - `1e-8` has eight, `0.5` one, `1` none. */
34
+ export declare function getDecimalPrecision(step: number): number;
35
+ /** The value rounded to the nearest step of `precision` - `null` stays `null`. */
36
+ export declare function roundToPrecision(value: number | null, precision: number): number | null;
37
+ /** The number moved by `delta`, with no float noise - `0.1 + 0.2` is `0.3`. */
38
+ export declare function addExact(value: number, delta: number): number;
39
+ /** The nearest number on the grid of `step`, counted from `origin`. */
40
+ export declare function snapToStep(value: number, step: number, origin: number): number;
@@ -0,0 +1,40 @@
1
+ import { v as Theme } from "./types-DRIGCQQY.mjs";
2
+ /**
3
+ * Appends an alpha channel to a 6-digit hex color, producing an 8-digit `#RRGGBBAA` hex.
4
+ * @param color - 6-digit hex string, e.g. `'#4ade80'`
5
+ * @param opacity - alpha from `0` (transparent) to `1` (opaque)
6
+ * @returns 8-digit hex string, e.g. `'#4ade801A'`
7
+ * @example alpha('#4ade80', 0.1) // '#4ade801A'
8
+ */
9
+ export declare const alpha: (color: string, opacity: number) => string;
10
+ /** Clamps `value` to the inclusive range `[min, max]`. */
11
+ export declare function clamp(value: number, min: number, max: number): number;
12
+ /**
13
+ * Merges `overrides` onto `base`, recursing only where both sides are plain objects; arrays and
14
+ * functions replace wholesale and `undefined` values are ignored. Neither argument is mutated.
15
+ */
16
+ export declare const deepMerge: (base: Record<string, unknown>, overrides: Record<string, unknown>) => Record<string, unknown>;
17
+ export declare const generateBoxShadow: (elevation: number, shadowColor: string) => string;
18
+ /**
19
+ * The `rel` of an anchor: as given, else `noopener noreferrer` when it opens a new tab, so the
20
+ * page it opens can't reach back to this one through `window.opener`.
21
+ */
22
+ export declare const getAnchorRel: (target: string | undefined, rel: string | undefined) => string | undefined;
23
+ /** The corner shapes of a control or a surface: square, rounded by a radius, or a full pill. */
24
+ export type Shape = 'square' | 'rounded' | 'pill';
25
+ /**
26
+ * The corner radius of a shape. Only `rounded` takes a radius - `rounded` is the one the
27
+ * `borderRadius` prop and the theme's radii set; `square` is none and `pill` is a full round.
28
+ */
29
+ export declare const getShapeRadius: (shape: Shape, rounded: string | number) => string | number;
30
+ /** The corner radius of a surface: the one asked for, else `theme.defaults.surfaceRadius`, else square. */
31
+ export declare const getSurfaceRadius: (theme: Theme, borderRadius?: keyof Theme['radii']) => string;
32
+ export declare function luminance(hex: string): number;
33
+ /** How many decimals a step has - `1e-8` has eight, `0.5` one, `1` none. */
34
+ export declare function getDecimalPrecision(step: number): number;
35
+ /** The value rounded to the nearest step of `precision` - `null` stays `null`. */
36
+ export declare function roundToPrecision(value: number | null, precision: number): number | null;
37
+ /** The number moved by `delta`, with no float noise - `0.1 + 0.2` is `0.3`. */
38
+ export declare function addExact(value: number, delta: number): number;
39
+ /** The nearest number on the grid of `step`, counted from `origin`. */
40
+ export declare function snapToStep(value: number, step: number, origin: number): number;
package/dist/utils.mjs ADDED
@@ -0,0 +1,51 @@
1
+ import { a as clamp, i as alpha, n as deepMerge, r as generateBoxShadow, t as themeDefault } from "./themeDefault-DBAILYB-.mjs";
2
+ // src/utils/getAnchorRel.ts
3
+ /**
4
+ * The `rel` of an anchor: as given, else `noopener noreferrer` when it opens a new tab, so the
5
+ * page it opens can't reach back to this one through `window.opener`.
6
+ */
7
+ const getAnchorRel = (target, rel) => target === "_blank" && rel === void 0 ? "noopener noreferrer" : rel;
8
+ // src/utils/getShapeRadius.ts
9
+ /**
10
+ * The corner radius of a shape. Only `rounded` takes a radius - `rounded` is the one the
11
+ * `borderRadius` prop and the theme's radii set; `square` is none and `pill` is a full round.
12
+ */
13
+ const getShapeRadius = (shape, rounded) => {
14
+ if (shape === "square") return 0;
15
+ if (shape === "pill") return "9999px";
16
+ return rounded;
17
+ };
18
+ // src/utils/getSurfaceRadius.ts
19
+ /** The corner radius of a surface: the one asked for, else `theme.defaults.surfaceRadius`, else square. */
20
+ const getSurfaceRadius = (theme, borderRadius) => theme.radii[borderRadius ?? themeDefault(theme, "surfaceRadius", "sq")];
21
+ // src/utils/luminance.ts
22
+ function luminance(hex) {
23
+ const r = Number.parseInt(hex.slice(1, 3), 16);
24
+ const g = Number.parseInt(hex.slice(3, 5), 16);
25
+ const b = Number.parseInt(hex.slice(5, 7), 16);
26
+ return (.299 * r + .587 * g + .114 * b) / 255;
27
+ }
28
+ // src/utils/precision.ts
29
+ /** How many decimals a step has - `1e-8` has eight, `0.5` one, `1` none. */
30
+ function getDecimalPrecision(step) {
31
+ const [mantissa, exponent] = step.toExponential().split("e");
32
+ const decimals = (mantissa.split(".")[1] ?? "").length;
33
+ return Math.max(0, decimals - Number(exponent));
34
+ }
35
+ /** The value rounded to the nearest step of `precision` - `null` stays `null`. */
36
+ function roundToPrecision(value, precision) {
37
+ if (value === null) return null;
38
+ const nearest = Math.round(value / precision) * precision;
39
+ return Number(nearest.toFixed(getDecimalPrecision(precision)));
40
+ }
41
+ /** The number moved by `delta`, with no float noise - `0.1 + 0.2` is `0.3`. */
42
+ function addExact(value, delta) {
43
+ const decimals = Math.max(getDecimalPrecision(value), getDecimalPrecision(delta));
44
+ return Number((value + delta).toFixed(decimals));
45
+ }
46
+ /** The nearest number on the grid of `step`, counted from `origin`. */
47
+ function snapToStep(value, step, origin) {
48
+ const decimals = Math.max(getDecimalPrecision(step), getDecimalPrecision(origin));
49
+ return Number((Math.round((value - origin) / step) * step + origin).toFixed(decimals));
50
+ }
51
+ export { addExact, alpha, clamp, deepMerge, generateBoxShadow, getAnchorRel, getDecimalPrecision, getShapeRadius, getSurfaceRadius, luminance, roundToPrecision, snapToStep };