@tenphi/tasty 0.15.3 → 0.16.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.
Files changed (67) hide show
  1. package/dist/chunks/definitions.js +1 -1
  2. package/dist/chunks/definitions.js.map +1 -1
  3. package/dist/config.d.ts +45 -2
  4. package/dist/config.js +59 -22
  5. package/dist/config.js.map +1 -1
  6. package/dist/core/index.d.ts +4 -4
  7. package/dist/core/index.js +3 -3
  8. package/dist/counter-style/index.js +51 -0
  9. package/dist/counter-style/index.js.map +1 -0
  10. package/dist/font-face/index.js +63 -0
  11. package/dist/font-face/index.js.map +1 -0
  12. package/dist/hooks/resolve-ssr-collector.js +15 -0
  13. package/dist/hooks/resolve-ssr-collector.js.map +1 -0
  14. package/dist/hooks/useCounterStyle.d.ts +50 -0
  15. package/dist/hooks/useCounterStyle.js +47 -0
  16. package/dist/hooks/useCounterStyle.js.map +1 -0
  17. package/dist/hooks/useFontFace.d.ts +43 -0
  18. package/dist/hooks/useFontFace.js +71 -0
  19. package/dist/hooks/useFontFace.js.map +1 -0
  20. package/dist/hooks/useGlobalStyles.js +1 -5
  21. package/dist/hooks/useGlobalStyles.js.map +1 -1
  22. package/dist/hooks/useKeyframes.js +1 -5
  23. package/dist/hooks/useKeyframes.js.map +1 -1
  24. package/dist/hooks/useProperty.js +1 -5
  25. package/dist/hooks/useProperty.js.map +1 -1
  26. package/dist/hooks/useRawCSS.js +1 -5
  27. package/dist/hooks/useRawCSS.js.map +1 -1
  28. package/dist/hooks/useStyles.js +33 -12
  29. package/dist/hooks/useStyles.js.map +1 -1
  30. package/dist/index.d.ts +6 -4
  31. package/dist/index.js +5 -3
  32. package/dist/injector/index.d.ts +20 -2
  33. package/dist/injector/index.js +19 -1
  34. package/dist/injector/index.js.map +1 -1
  35. package/dist/injector/injector.d.ts +19 -1
  36. package/dist/injector/injector.js +35 -0
  37. package/dist/injector/injector.js.map +1 -1
  38. package/dist/injector/sheet-manager.js +2 -0
  39. package/dist/injector/sheet-manager.js.map +1 -1
  40. package/dist/injector/types.d.ts +61 -1
  41. package/dist/ssr/collector.d.ts +17 -0
  42. package/dist/ssr/collector.js +50 -6
  43. package/dist/ssr/collector.js.map +1 -1
  44. package/dist/ssr/index.js +1 -1
  45. package/dist/states/index.js +2 -0
  46. package/dist/states/index.js.map +1 -1
  47. package/dist/styles/border.js +2 -2
  48. package/dist/styles/border.js.map +1 -1
  49. package/dist/styles/preset.js +23 -37
  50. package/dist/styles/preset.js.map +1 -1
  51. package/dist/styles/types.d.ts +25 -3
  52. package/dist/tasty.d.ts +1 -1
  53. package/dist/utils/styles.d.ts +0 -1
  54. package/dist/utils/styles.js +0 -1
  55. package/dist/utils/styles.js.map +1 -1
  56. package/dist/zero/babel.d.ts +11 -1
  57. package/dist/zero/babel.js +13 -7
  58. package/dist/zero/babel.js.map +1 -1
  59. package/dist/zero/extractor.js +53 -1
  60. package/dist/zero/extractor.js.map +1 -1
  61. package/docs/configuration.md +61 -0
  62. package/docs/design-system.md +17 -0
  63. package/docs/dsl.md +91 -1
  64. package/docs/runtime.md +88 -0
  65. package/docs/ssr.md +2 -0
  66. package/docs/tasty-static.md +2 -0
  67. package/package.json +2 -2
@@ -54,6 +54,8 @@ These docs use `data-schema="dark"` in examples. If your app already standardize
54
54
  | `replaceTokens` | `Record<string, string \| number>` | - | Parse-time token substitution (inline replacement) |
55
55
  | `keyframes` | `Record<string, KeyframesSteps>` | - | Global keyframes for animations |
56
56
  | `properties` | `Record<string, PropertyDefinition>` | - | Global CSS @property definitions |
57
+ | `fontFace` | `Record<string, FontFaceInput>` | - | Global @font-face definitions |
58
+ | `counterStyle` | `Record<string, CounterStyleDescriptors>` | - | Global @counter-style definitions |
57
59
  | `autoPropertyTypes` | `boolean` | `true` | Auto-infer and register `@property` types from values |
58
60
  | `recipes` | `Record<string, RecipeStyles>` | - | Predefined style recipes (named style bundles) |
59
61
  | `colorSpace` | `'rgb' \| 'hsl' \| 'oklch'` | `'oklch'` | Color space for decomposed color token companion variables |
@@ -133,6 +135,65 @@ See [Replace Tokens](dsl.md#replace-tokens) in the Style DSL reference.
133
135
 
134
136
  ---
135
137
 
138
+ ## Font Face
139
+
140
+ Register custom fonts globally so every component can reference them by family name. Values are descriptor objects or arrays (for multiple weights/styles). Rules are injected eagerly when styles are first generated.
141
+
142
+ ```ts
143
+ configure({
144
+ fontFace: {
145
+ 'Brand Sans': [
146
+ {
147
+ src: 'url("/fonts/brand-regular.woff2") format("woff2")',
148
+ fontWeight: 400,
149
+ fontDisplay: 'swap',
150
+ },
151
+ {
152
+ src: 'url("/fonts/brand-bold.woff2") format("woff2")',
153
+ fontWeight: 700,
154
+ fontDisplay: 'swap',
155
+ },
156
+ ],
157
+ Icons: {
158
+ src: 'url("/fonts/icons.woff2") format("woff2")',
159
+ fontDisplay: 'block',
160
+ },
161
+ },
162
+ });
163
+ ```
164
+
165
+ Now any component can use `fontFamily: '"Brand Sans", sans-serif'` and the browser will already have the `@font-face` rules in the stylesheet.
166
+
167
+ See [Font Face (`@fontFace`)](dsl.md#font-face-fontface) for inline usage inside component styles and the full list of supported descriptors.
168
+
169
+ ---
170
+
171
+ ## Counter Style
172
+
173
+ Define custom list-marker algorithms globally. Rules are injected eagerly when styles are first generated.
174
+
175
+ ```ts
176
+ configure({
177
+ counterStyle: {
178
+ thumbs: {
179
+ system: 'cyclic',
180
+ symbols: '"👍"',
181
+ suffix: '" "',
182
+ },
183
+ 'lower-roman-parens': {
184
+ system: 'extends lower-roman',
185
+ suffix: '") "',
186
+ },
187
+ },
188
+ });
189
+ ```
190
+
191
+ Components can then reference `listStyleType: 'thumbs'` directly.
192
+
193
+ See [Counter Style (`@counterStyle`)](dsl.md#counter-style-counterstyle) for inline usage inside component styles and the full list of supported descriptors.
194
+
195
+ ---
196
+
136
197
  ## Recipes
137
198
 
138
199
  Recipes are predefined, named style bundles. Define them globally via `configure()`:
@@ -103,6 +103,23 @@ configure({
103
103
 
104
104
  Then use `preset: 'h1'` or `preset: 't2'` in any component's styles.
105
105
 
106
+ ### Registering brand fonts
107
+
108
+ Register your design system's custom fonts via `configure({ fontFace })` so every component can reference them:
109
+
110
+ ```ts
111
+ configure({
112
+ fontFace: {
113
+ 'Brand Sans': [
114
+ { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
115
+ { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
116
+ ],
117
+ },
118
+ });
119
+ ```
120
+
121
+ See [Font Face](configuration.md#font-face) for the full configuration reference.
122
+
106
123
  ---
107
124
 
108
125
  ## Defining state aliases
package/docs/dsl.md CHANGED
@@ -119,7 +119,6 @@ color: '(#primary, #secondary)', // Fallback syntax
119
119
  | `cr` | Card border radius | `1cr` | `var(--card-radius)` |
120
120
  | `bw` | Border width | `2bw` | `calc(var(--border-width) * 2)` |
121
121
  | `ow` | Outline width | `1ow` | `var(--outline-width)` |
122
- | `fs` | Font size | `1fs` | `var(--font-size)` |
123
122
  | `lh` | Line height | `1lh` | `var(--line-height)` |
124
123
  | `sf` | Stable fraction | `1sf` | `minmax(0, 1fr)` |
125
124
 
@@ -569,6 +568,97 @@ Use explicit `@properties` when you need non-default settings like `inherits: fa
569
568
 
570
569
  ---
571
570
 
571
+ ## Font Face (`@fontFace`)
572
+
573
+ Register custom fonts directly inside a `styles` object. Keys are font-family names, values are descriptor objects (or arrays of them for multiple weights/styles).
574
+
575
+ ```ts
576
+ const Heading = tasty({
577
+ styles: {
578
+ '@fontFace': {
579
+ 'Brand Sans': {
580
+ src: 'url("/fonts/brand-sans.woff2") format("woff2")',
581
+ fontDisplay: 'swap',
582
+ },
583
+ },
584
+ fontFamily: '"Brand Sans", sans-serif',
585
+ },
586
+ });
587
+ ```
588
+
589
+ ### Multiple weights
590
+
591
+ Supply an array to register several variants of the same family:
592
+
593
+ ```ts
594
+ '@fontFace': {
595
+ 'Brand Sans': [
596
+ { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
597
+ { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
598
+ ],
599
+ }
600
+ ```
601
+
602
+ ### Supported descriptors
603
+
604
+ | Descriptor | CSS property | Type |
605
+ |---|---|---|
606
+ | `src` (required) | `src` | `string` |
607
+ | `fontWeight` | `font-weight` | `string \| number` |
608
+ | `fontStyle` | `font-style` | `string` |
609
+ | `fontStretch` | `font-stretch` | `string` |
610
+ | `fontDisplay` | `font-display` | `'auto' \| 'block' \| 'swap' \| 'fallback' \| 'optional'` |
611
+ | `unicodeRange` | `unicode-range` | `string` |
612
+ | `ascentOverride` | `ascent-override` | `string` |
613
+ | `descentOverride` | `descent-override` | `string` |
614
+ | `lineGapOverride` | `line-gap-override` | `string` |
615
+ | `sizeAdjust` | `size-adjust` | `string` |
616
+ | `fontFeatureSettings` | `font-feature-settings` | `string` |
617
+ | `fontVariationSettings` | `font-variation-settings` | `string` |
618
+
619
+ > Font-face rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@font-face`.
620
+
621
+ ---
622
+
623
+ ## Counter Style (`@counterStyle`)
624
+
625
+ Define custom list markers via the CSS `@counter-style` at-rule. Keys are counter-style names, values are descriptor objects.
626
+
627
+ ```ts
628
+ const EmojiList = tasty({
629
+ tag: 'ol',
630
+ styles: {
631
+ '@counterStyle': {
632
+ thumbs: {
633
+ system: 'cyclic',
634
+ symbols: '"👍"',
635
+ suffix: '" "',
636
+ },
637
+ },
638
+ listStyleType: 'thumbs',
639
+ },
640
+ });
641
+ ```
642
+
643
+ ### Supported descriptors
644
+
645
+ | Descriptor | CSS property | Type |
646
+ |---|---|---|
647
+ | `system` (required) | `system` | `'cyclic' \| 'numeric' \| 'alphabetic' \| 'symbolic' \| 'additive' \| 'fixed' \| string` |
648
+ | `symbols` | `symbols` | `string` |
649
+ | `additiveSymbols` | `additive-symbols` | `string` |
650
+ | `prefix` | `prefix` | `string` |
651
+ | `suffix` | `suffix` | `string` |
652
+ | `negative` | `negative` | `string` |
653
+ | `range` | `range` | `string` |
654
+ | `pad` | `pad` | `string` |
655
+ | `fallback` | `fallback` | `string` |
656
+ | `speakAs` | `speak-as` | `string` |
657
+
658
+ > Counter-style rules are permanent — they are injected once and never cleaned up, matching how browsers handle `@counter-style`.
659
+
660
+ ---
661
+
572
662
  ## Style Properties
573
663
 
574
664
  For a complete reference of all enhanced style properties — syntax, values, modifiers, and recommendations — see **[Style Properties Reference](styles.md)**.
package/docs/runtime.md CHANGED
@@ -378,6 +378,94 @@ function Spinner() {
378
378
  - `#name` defines `--name-color` and auto-infers `<color>`
379
379
  - `--name` is also supported for existing CSS variables
380
380
 
381
+ ### useFontFace
382
+
383
+ Inject `@font-face` rules for custom fonts. Permanent — no cleanup on unmount. Deduplicates by content.
384
+
385
+ ```tsx
386
+ import { useFontFace } from '@tenphi/tasty';
387
+
388
+ function App() {
389
+ useFontFace('Brand Sans', {
390
+ src: 'url("/fonts/brand-sans.woff2") format("woff2")',
391
+ fontWeight: '400 700',
392
+ fontDisplay: 'swap',
393
+ });
394
+
395
+ return <div style={{ fontFamily: '"Brand Sans", sans-serif' }}>Hello</div>;
396
+ }
397
+ ```
398
+
399
+ For multiple weights/styles, pass an array:
400
+
401
+ ```tsx
402
+ useFontFace('Brand Sans', [
403
+ { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
404
+ { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
405
+ ]);
406
+ ```
407
+
408
+ Signature:
409
+
410
+ ```ts
411
+ function useFontFace(family: string, input: FontFaceInput): void;
412
+ ```
413
+
414
+ ### useCounterStyle
415
+
416
+ Inject a `@counter-style` rule and get back the counter style name. Permanent — no cleanup on unmount. Deduplicates by name.
417
+
418
+ ```tsx
419
+ import { useCounterStyle } from '@tenphi/tasty';
420
+
421
+ function EmojiList() {
422
+ const styleName = useCounterStyle({
423
+ system: 'cyclic',
424
+ symbols: '"👍"',
425
+ suffix: '" "',
426
+ }, { name: 'thumbs' });
427
+
428
+ return (
429
+ <ol style={{ listStyleType: styleName }}>
430
+ <li>First</li>
431
+ <li>Second</li>
432
+ </ol>
433
+ );
434
+ }
435
+ ```
436
+
437
+ Factory form with dependencies:
438
+
439
+ ```tsx
440
+ function DynamicList({ marker }: { marker: string }) {
441
+ const styleName = useCounterStyle(
442
+ () => ({
443
+ system: 'cyclic',
444
+ symbols: `"${marker}"`,
445
+ suffix: '" "',
446
+ }),
447
+ [marker],
448
+ );
449
+
450
+ return <ol style={{ listStyleType: styleName }}>...</ol>;
451
+ }
452
+ ```
453
+
454
+ Signatures:
455
+
456
+ ```ts
457
+ function useCounterStyle(
458
+ descriptors: CounterStyleDescriptors,
459
+ options?: { name?: string; root?: Document | ShadowRoot },
460
+ ): string;
461
+
462
+ function useCounterStyle(
463
+ factory: () => CounterStyleDescriptors,
464
+ deps: readonly unknown[],
465
+ options?: { name?: string; root?: Document | ShadowRoot },
466
+ ): string;
467
+ ```
468
+
381
469
  ### Troubleshooting
382
470
 
383
471
  - Styles are not updating: make sure `configure()` runs before first render, and verify the generated class name or global rule with [Debug Utilities](debug.md).
package/docs/ssr.md CHANGED
@@ -317,6 +317,8 @@ Server-safe style collector. One instance per request.
317
317
  | `collectChunk(cacheKey, className, rules)` | Record CSS rules for a chunk. Deduplicated by `cacheKey`. |
318
318
  | `collectKeyframes(name, css)` | Record a `@keyframes` rule. Deduplicated by name. |
319
319
  | `collectProperty(name, css)` | Record a `@property` rule. Deduplicated by name. |
320
+ | `collectFontFace(key, css)` | Record a `@font-face` rule. Deduplicated by content hash. |
321
+ | `collectCounterStyle(name, css)` | Record a `@counter-style` rule. Deduplicated by name. |
320
322
  | `getCSS()` | Get all collected CSS as a single string. For non-streaming SSR. |
321
323
  | `flushCSS()` | Get only CSS collected since the last flush. For streaming SSR. |
322
324
  | `getCacheState()` | Serialize `{ entries: Record<cacheKey, className>, classCounter }` for client hydration. |
@@ -163,6 +163,8 @@ module.exports = {
163
163
  | `config.states` | `Record<string, string>` | `{}` | Predefined state aliases |
164
164
  | `config.devMode` | `boolean` | `false` | Add source comments to CSS |
165
165
  | `config.recipes` | `Record<string, RecipeStyles>` | `{}` | Predefined style recipes |
166
+ | `config.fontFace` | `Record<string, FontFaceInput>` | — | Global `@font-face` definitions |
167
+ | `config.counterStyle` | `Record<string, CounterStyleDescriptors>` | — | Global `@counter-style` definitions |
166
168
 
167
169
  ---
168
170
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenphi/tasty",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "description": "A design-system-integrated styling system and DSL for concise, state-aware UI styling",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -179,7 +179,7 @@
179
179
  "path",
180
180
  "crypto"
181
181
  ],
182
- "limit": "39 kB"
182
+ "limit": "40 kB"
183
183
  }
184
184
  ],
185
185
  "scripts": {