@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.
- package/dist/chunks/definitions.js +1 -1
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/config.d.ts +45 -2
- package/dist/config.js +59 -22
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +4 -4
- package/dist/core/index.js +3 -3
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/resolve-ssr-collector.js +15 -0
- package/dist/hooks/resolve-ssr-collector.js.map +1 -0
- package/dist/hooks/useCounterStyle.d.ts +50 -0
- package/dist/hooks/useCounterStyle.js +47 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +43 -0
- package/dist/hooks/useFontFace.js +71 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.js +1 -5
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.js +1 -5
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.js +1 -5
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.js +1 -5
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.js +33 -12
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +5 -3
- package/dist/injector/index.d.ts +20 -2
- package/dist/injector/index.js +19 -1
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +19 -1
- package/dist/injector/injector.js +35 -0
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.js +2 -0
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +61 -1
- package/dist/ssr/collector.d.ts +17 -0
- package/dist/ssr/collector.js +50 -6
- package/dist/ssr/collector.js.map +1 -1
- package/dist/ssr/index.js +1 -1
- package/dist/states/index.js +2 -0
- package/dist/states/index.js.map +1 -1
- package/dist/styles/border.js +2 -2
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/preset.js +23 -37
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/types.d.ts +25 -3
- package/dist/tasty.d.ts +1 -1
- package/dist/utils/styles.d.ts +0 -1
- package/dist/utils/styles.js +0 -1
- package/dist/utils/styles.js.map +1 -1
- package/dist/zero/babel.d.ts +11 -1
- package/dist/zero/babel.js +13 -7
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/extractor.js +53 -1
- package/dist/zero/extractor.js.map +1 -1
- package/docs/configuration.md +61 -0
- package/docs/design-system.md +17 -0
- package/docs/dsl.md +91 -1
- package/docs/runtime.md +88 -0
- package/docs/ssr.md +2 -0
- package/docs/tasty-static.md +2 -0
- package/package.json +2 -2
package/docs/configuration.md
CHANGED
|
@@ -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()`:
|
package/docs/design-system.md
CHANGED
|
@@ -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. |
|
package/docs/tasty-static.md
CHANGED
|
@@ -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.
|
|
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": "
|
|
182
|
+
"limit": "40 kB"
|
|
183
183
|
}
|
|
184
184
|
],
|
|
185
185
|
"scripts": {
|