typestyles 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.
@@ -0,0 +1,477 @@
1
+ import * as CSS from 'csstype';
2
+ export { g as getRegisteredCss } from './hmr-CSDtaPpU.js';
3
+
4
+ /**
5
+ * A CSS value that can be a standard value or a token reference (var() string).
6
+ */
7
+ type CSSValue = string | number;
8
+ /**
9
+ * CSS properties with support for nested selectors and at-rules.
10
+ * Extends csstype's Properties with nesting capabilities.
11
+ */
12
+ interface CSSProperties extends CSS.Properties<CSSValue> {
13
+ /** Nested selector (e.g., '&:hover', '& .child', '&::before') */
14
+ [selector: `&${string}`]: CSSProperties;
15
+ /** At-rule (e.g., '@media (max-width: 768px)', '@container', '@supports') */
16
+ [atRule: `@${string}`]: CSSProperties;
17
+ }
18
+ /**
19
+ * A map of variant names to their CSS property definitions.
20
+ */
21
+ type StyleDefinitions = Record<string, CSSProperties>;
22
+ /**
23
+ * A selector function returned by styles.create().
24
+ * Accepts variant names (or falsy values for conditional application)
25
+ * and returns a composed class name string.
26
+ */
27
+ interface SelectorFunction<K extends string = string> {
28
+ (...variants: (K | false | null | undefined)[]): string;
29
+ }
30
+ /**
31
+ * A flat map of token names to their values.
32
+ */
33
+ type TokenValues = Record<string, string>;
34
+ /**
35
+ * A typed token reference object. Property access returns var(--namespace-key).
36
+ */
37
+ type TokenRef<T extends TokenValues> = {
38
+ readonly [K in keyof T]: string;
39
+ };
40
+ /**
41
+ * Theme overrides: a map of token namespaces to partial value overrides.
42
+ */
43
+ type ThemeOverrides = Record<string, Partial<TokenValues>>;
44
+ /**
45
+ * Keyframe stops: 'from', 'to', or percentage strings mapped to CSS properties.
46
+ */
47
+ type KeyframeStops$1 = Record<string, CSSProperties>;
48
+ /**
49
+ * A map of variant dimensions to their options (each option maps to CSSProperties).
50
+ */
51
+ type VariantDefinitions = Record<string, Record<string, CSSProperties>>;
52
+ /**
53
+ * The full config object passed to styles.component().
54
+ */
55
+ type ComponentConfig<V extends VariantDefinitions> = {
56
+ base?: CSSProperties;
57
+ variants?: V;
58
+ compoundVariants?: Array<{
59
+ variants: {
60
+ [K in keyof V]?: keyof V[K];
61
+ };
62
+ style: CSSProperties;
63
+ }>;
64
+ defaultVariants?: {
65
+ [K in keyof V]?: keyof V[K];
66
+ };
67
+ };
68
+ /**
69
+ * The function returned by styles.component().
70
+ */
71
+ type ComponentFunction<V extends VariantDefinitions> = (selections?: {
72
+ [K in keyof V]?: keyof V[K] | false | null | undefined;
73
+ }) => string;
74
+ /**
75
+ * Font face property declarations.
76
+ */
77
+ type FontFaceProps = {
78
+ src: string;
79
+ fontWeight?: string | number;
80
+ fontStyle?: 'normal' | 'italic' | 'oblique' | string;
81
+ fontDisplay?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
82
+ fontStretch?: string;
83
+ unicodeRange?: string;
84
+ };
85
+
86
+ /**
87
+ * Create a style group and return a selector function.
88
+ *
89
+ * The selector function accepts variant names and returns a composed
90
+ * class name string. Class names are deterministic and human-readable:
91
+ * `{namespace}-{variant}`.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * const button = createStyles('button', {
96
+ * base: { padding: '8px 16px', fontSize: '14px' },
97
+ * primary: { backgroundColor: '#0066ff', color: '#fff' },
98
+ * large: { padding: '12px 24px', fontSize: '16px' },
99
+ * });
100
+ *
101
+ * button('base', 'primary') // "button-base button-primary"
102
+ * button('base', isLarge && 'large') // conditional application
103
+ * ```
104
+ */
105
+ declare function createStyles<K extends string>(namespace: string, definitions: StyleDefinitions & Record<K, CSSProperties>): SelectorFunction<K>;
106
+
107
+ /**
108
+ * Create design tokens as CSS custom properties.
109
+ *
110
+ * Generates a :root rule with the custom properties and returns
111
+ * a typed object where property access yields var() references.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const color = createTokens('color', {
116
+ * primary: '#0066ff',
117
+ * secondary: '#6b7280',
118
+ * });
119
+ *
120
+ * color.primary // "var(--color-primary)"
121
+ * ```
122
+ */
123
+ declare function createTokens<T extends TokenValues>(namespace: string, values: T): TokenRef<T>;
124
+ /**
125
+ * Reference tokens defined elsewhere without injecting CSS.
126
+ *
127
+ * Returns a typed proxy that produces var() references.
128
+ * Useful for consuming shared tokens from a different module.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const color = useTokens('color');
133
+ * color.primary // "var(--color-primary)"
134
+ * ```
135
+ */
136
+ declare function useTokens<T extends TokenValues = TokenValues>(namespace: string): TokenRef<T>;
137
+ /**
138
+ * Create a theme class that overrides token values.
139
+ *
140
+ * Returns a class name string. Apply it to any element to override
141
+ * token values for that subtree via CSS custom property cascading.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const dark = createTheme('dark', {
146
+ * color: { primary: '#66b3ff', surface: '#1a1a2e' },
147
+ * });
148
+ *
149
+ * <div className={dark}> // class="theme-dark"
150
+ * ```
151
+ */
152
+ declare function createTheme(name: string, overrides: ThemeOverrides): string;
153
+
154
+ /**
155
+ * A keyframe stop is either 'from', 'to', or a percentage like '50%'.
156
+ */
157
+ type KeyframeStops = Record<string, CSSProperties>;
158
+ /**
159
+ * Create a CSS @keyframes animation and return its name.
160
+ *
161
+ * The returned string is the animation name — use it directly in
162
+ * `animation` shorthand or `animationName`.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * const fadeIn = keyframes.create('fadeIn', {
167
+ * from: { opacity: 0 },
168
+ * to: { opacity: 1 },
169
+ * });
170
+ *
171
+ * const card = styles.create('card', {
172
+ * base: { animation: `${fadeIn} 300ms ease` },
173
+ * });
174
+ * ```
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * const bounce = keyframes.create('bounce', {
179
+ * '0%': { transform: 'translateY(0)' },
180
+ * '50%': { transform: 'translateY(-20px)' },
181
+ * '100%': { transform: 'translateY(0)' },
182
+ * });
183
+ * ```
184
+ */
185
+ declare function createKeyframes(name: string, stops: KeyframeStops): string;
186
+
187
+ /**
188
+ * Type-safe helpers for CSS color functions.
189
+ *
190
+ * Each function returns a plain CSS string — no runtime color math.
191
+ * Works naturally with token references since tokens are strings too.
192
+ */
193
+ type ColorValue = string | number;
194
+ /** Color spaces supported by color-mix(). */
195
+ type ColorMixSpace = 'srgb' | 'srgb-linear' | 'display-p3' | 'a98-rgb' | 'prophoto-rgb' | 'rec2020' | 'lab' | 'oklab' | 'xyz' | 'xyz-d50' | 'xyz-d65' | 'hsl' | 'hwb' | 'lch' | 'oklch';
196
+ /**
197
+ * `rgb(r g b)` or `rgb(r g b / a)`
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * color.rgb(0, 102, 255) // "rgb(0 102 255)"
202
+ * color.rgb(0, 102, 255, 0.5) // "rgb(0 102 255 / 0.5)"
203
+ * ```
204
+ */
205
+ declare function rgb(r: ColorValue, g: ColorValue, b: ColorValue, alpha?: ColorValue): string;
206
+ /**
207
+ * `hsl(h s l)` or `hsl(h s l / a)`
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * color.hsl(220, '100%', '50%') // "hsl(220 100% 50%)"
212
+ * color.hsl(220, '100%', '50%', 0.8) // "hsl(220 100% 50% / 0.8)"
213
+ * ```
214
+ */
215
+ declare function hsl(h: ColorValue, s: ColorValue, l: ColorValue, alpha?: ColorValue): string;
216
+ /**
217
+ * `oklch(L C h)` or `oklch(L C h / a)`
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * color.oklch(0.7, 0.15, 250) // "oklch(0.7 0.15 250)"
222
+ * color.oklch(0.7, 0.15, 250, 0.5) // "oklch(0.7 0.15 250 / 0.5)"
223
+ * ```
224
+ */
225
+ declare function oklch(l: ColorValue, c: ColorValue, h: ColorValue, alpha?: ColorValue): string;
226
+ /**
227
+ * `oklab(L a b)` or `oklab(L a b / alpha)`
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * color.oklab(0.7, -0.1, -0.1) // "oklab(0.7 -0.1 -0.1)"
232
+ * color.oklab(0.7, -0.1, -0.1, 0.5) // "oklab(0.7 -0.1 -0.1 / 0.5)"
233
+ * ```
234
+ */
235
+ declare function oklab(l: ColorValue, a: ColorValue, b: ColorValue, alpha?: ColorValue): string;
236
+ /**
237
+ * `lab(L a b)` or `lab(L a b / alpha)`
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * color.lab('50%', 40, -20) // "lab(50% 40 -20)"
242
+ * ```
243
+ */
244
+ declare function lab(l: ColorValue, a: ColorValue, b: ColorValue, alpha?: ColorValue): string;
245
+ /**
246
+ * `lch(L C h)` or `lch(L C h / alpha)`
247
+ *
248
+ * @example
249
+ * ```ts
250
+ * color.lch('50%', 80, 250) // "lch(50% 80 250)"
251
+ * ```
252
+ */
253
+ declare function lch(l: ColorValue, c: ColorValue, h: ColorValue, alpha?: ColorValue): string;
254
+ /**
255
+ * `hwb(h w b)` or `hwb(h w b / alpha)`
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * color.hwb(220, '10%', '0%') // "hwb(220 10% 0%)"
260
+ * ```
261
+ */
262
+ declare function hwb(h: ColorValue, w: ColorValue, b: ColorValue, alpha?: ColorValue): string;
263
+ /**
264
+ * `color-mix(in colorspace, color1 p1%, color2 p2%)`
265
+ *
266
+ * Mixes two colors in the given color space. Percentages are optional.
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * color.mix('red', 'blue') // "color-mix(in srgb, red, blue)"
271
+ * color.mix('red', 'blue', 30) // "color-mix(in srgb, red 30%, blue)"
272
+ * color.mix(theme.primary, 'white', 20) // "color-mix(in srgb, var(--theme-primary) 20%, white)"
273
+ * color.mix('red', 'blue', 50, 'oklch') // "color-mix(in oklch, red 50%, blue)"
274
+ * ```
275
+ */
276
+ declare function mix(color1: string, color2: string, percentage?: number, colorSpace?: ColorMixSpace): string;
277
+ /**
278
+ * `light-dark(lightColor, darkColor)`
279
+ *
280
+ * Uses the `light-dark()` CSS function that resolves based on
281
+ * the computed `color-scheme` of the element.
282
+ *
283
+ * @example
284
+ * ```ts
285
+ * color.lightDark('#111', '#eee') // "light-dark(#111, #eee)"
286
+ * color.lightDark(theme.textLight, theme.textDark) // "light-dark(var(--theme-textLight), var(--theme-textDark))"
287
+ * ```
288
+ */
289
+ declare function lightDark(lightColor: string, darkColor: string): string;
290
+ /**
291
+ * Adjust the alpha/opacity of any color using `color-mix()`.
292
+ *
293
+ * This is a common pattern: mixing a color with transparent to change opacity.
294
+ * Works with any color value including token references.
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * color.alpha('red', 0.5) // "color-mix(in srgb, red 50%, transparent)"
299
+ * color.alpha(theme.primary, 0.2) // "color-mix(in srgb, var(--theme-primary) 20%, transparent)"
300
+ * color.alpha('#0066ff', 0.8, 'oklch') // "color-mix(in oklch, #0066ff 80%, transparent)"
301
+ * ```
302
+ */
303
+ declare function alpha(colorValue: string, opacity: number, colorSpace?: ColorMixSpace): string;
304
+
305
+ type colorFns_ColorMixSpace = ColorMixSpace;
306
+ declare const colorFns_alpha: typeof alpha;
307
+ declare const colorFns_hsl: typeof hsl;
308
+ declare const colorFns_hwb: typeof hwb;
309
+ declare const colorFns_lab: typeof lab;
310
+ declare const colorFns_lch: typeof lch;
311
+ declare const colorFns_lightDark: typeof lightDark;
312
+ declare const colorFns_mix: typeof mix;
313
+ declare const colorFns_oklab: typeof oklab;
314
+ declare const colorFns_oklch: typeof oklch;
315
+ declare const colorFns_rgb: typeof rgb;
316
+ declare namespace colorFns {
317
+ export { type colorFns_ColorMixSpace as ColorMixSpace, colorFns_alpha as alpha, colorFns_hsl as hsl, colorFns_hwb as hwb, colorFns_lab as lab, colorFns_lch as lch, colorFns_lightDark as lightDark, colorFns_mix as mix, colorFns_oklab as oklab, colorFns_oklch as oklch, colorFns_rgb as rgb };
318
+ }
319
+
320
+ /**
321
+ * Create a multi-variant component style and return a selector function.
322
+ *
323
+ * Class naming convention:
324
+ * base → `{namespace}-base`
325
+ * variants.intent.primary → `{namespace}-intent-primary`
326
+ * compoundVariants[0] → `{namespace}-compound-0`
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * const button = styles.component('button', {
331
+ * base: { padding: '8px 16px' },
332
+ * variants: {
333
+ * intent: {
334
+ * primary: { backgroundColor: '#0066ff', color: '#fff' },
335
+ * ghost: { backgroundColor: 'transparent', border: '1px solid currentColor' },
336
+ * },
337
+ * size: {
338
+ * sm: { fontSize: '12px' },
339
+ * lg: { fontSize: '18px' },
340
+ * },
341
+ * },
342
+ * compoundVariants: [
343
+ * { variants: { intent: 'primary', size: 'lg' }, style: { fontWeight: 700 } },
344
+ * ],
345
+ * defaultVariants: { intent: 'primary', size: 'sm' },
346
+ * });
347
+ *
348
+ * button() // "button-base button-intent-primary button-size-sm"
349
+ * button({ intent: 'ghost' }) // "button-base button-intent-ghost button-size-sm"
350
+ * button({ intent: 'primary', size: 'lg' }) // includes compound class
351
+ * ```
352
+ */
353
+ declare function createComponent<V extends VariantDefinitions>(namespace: string, config: ComponentConfig<V>): ComponentFunction<V>;
354
+
355
+ /**
356
+ * Apply styles to an arbitrary CSS selector.
357
+ *
358
+ * Use for CSS resets, body/root defaults, third-party elements, or any
359
+ * selector that isn't tied to a specific component class.
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * global.style('body', { margin: 0, fontFamily: 'sans-serif' });
364
+ * global.style('a:hover', { textDecoration: 'underline' });
365
+ * global.style('*, *::before, *::after', { boxSizing: 'border-box' });
366
+ * ```
367
+ */
368
+ declare function globalStyle(selector: string, properties: CSSProperties): void;
369
+ /**
370
+ * Declare a `@font-face` rule to load a custom font.
371
+ *
372
+ * Multiple weights/styles of the same family can be registered by calling
373
+ * this function multiple times with different `src` values — each call is
374
+ * deduplicated by `family + src`.
375
+ *
376
+ * @example
377
+ * ```ts
378
+ * global.fontFace('Inter', {
379
+ * src: "url('/fonts/Inter-Regular.woff2') format('woff2')",
380
+ * fontWeight: 400,
381
+ * fontStyle: 'normal',
382
+ * fontDisplay: 'swap',
383
+ * });
384
+ *
385
+ * global.fontFace('Inter', {
386
+ * src: "url('/fonts/Inter-Bold.woff2') format('woff2')",
387
+ * fontWeight: 700,
388
+ * fontStyle: 'normal',
389
+ * fontDisplay: 'swap',
390
+ * });
391
+ * ```
392
+ */
393
+ declare function globalFontFace(family: string, props: FontFaceProps): void;
394
+
395
+ /**
396
+ * Style creation API.
397
+ *
398
+ * @example
399
+ * ```ts
400
+ * const button = styles.create('button', {
401
+ * base: { padding: '8px 16px' },
402
+ * primary: { backgroundColor: '#0066ff' },
403
+ * });
404
+ *
405
+ * <button className={button('base', 'primary')}>
406
+ * ```
407
+ */
408
+ declare const styles: {
409
+ readonly create: typeof createStyles;
410
+ readonly component: typeof createComponent;
411
+ };
412
+ /**
413
+ * Global CSS API for arbitrary selectors and font-face declarations.
414
+ *
415
+ * @example
416
+ * ```ts
417
+ * global.style('body', { margin: 0 });
418
+ * global.fontFace('Inter', { src: "url('/Inter.woff2') format('woff2')", fontWeight: 400 });
419
+ * ```
420
+ */
421
+ declare const global: {
422
+ readonly style: typeof globalStyle;
423
+ readonly fontFace: typeof globalFontFace;
424
+ };
425
+ /**
426
+ * Design token API using CSS custom properties.
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * const color = tokens.create('color', {
431
+ * primary: '#0066ff',
432
+ * });
433
+ *
434
+ * color.primary // "var(--color-primary)"
435
+ * ```
436
+ */
437
+ declare const tokens: {
438
+ readonly create: typeof createTokens;
439
+ readonly use: typeof useTokens;
440
+ readonly createTheme: typeof createTheme;
441
+ };
442
+ /**
443
+ * Keyframe animation API.
444
+ *
445
+ * @example
446
+ * ```ts
447
+ * const fadeIn = keyframes.create('fadeIn', {
448
+ * from: { opacity: 0 },
449
+ * to: { opacity: 1 },
450
+ * });
451
+ *
452
+ * const card = styles.create('card', {
453
+ * base: { animation: `${fadeIn} 300ms ease` },
454
+ * });
455
+ * ```
456
+ */
457
+ declare const keyframes: {
458
+ readonly create: typeof createKeyframes;
459
+ };
460
+ /**
461
+ * Type-safe CSS color function helpers.
462
+ *
463
+ * Each function returns a plain CSS color string — no runtime color math.
464
+ * Composes naturally with token references.
465
+ *
466
+ * @example
467
+ * ```ts
468
+ * color.rgb(0, 102, 255) // "rgb(0 102 255)"
469
+ * color.oklch(0.7, 0.15, 250) // "oklch(0.7 0.15 250)"
470
+ * color.mix(theme.primary, 'white', 20) // "color-mix(in srgb, var(--theme-primary) 20%, white)"
471
+ * color.alpha(theme.primary, 0.5) // "color-mix(in srgb, var(--theme-primary) 50%, transparent)"
472
+ * color.lightDark('#111', '#eee') // "light-dark(#111, #eee)"
473
+ * ```
474
+ */
475
+ declare const color: typeof colorFns;
476
+
477
+ export { type CSSProperties, type CSSValue, type ColorMixSpace, type ComponentConfig, type ComponentFunction, type FontFaceProps, type KeyframeStops$1 as KeyframeStops, type SelectorFunction, type StyleDefinitions, type ThemeOverrides, type TokenRef, type TokenValues, type VariantDefinitions, color, global, keyframes, styles, tokens };