@tenphi/tasty 0.0.0-snapshot.de81152 → 0.0.0-snapshot.dfef2a5
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/README.md +60 -28
- package/dist/{async-storage-B7_o6FKt.js → async-storage-DKK-wTD4.js} +1 -1
- package/dist/{async-storage-B7_o6FKt.js.map → async-storage-DKK-wTD4.js.map} +1 -1
- package/dist/babel-BUQGeOXA.d.ts +83 -0
- package/dist/{collector-DrgDE7QB.js → collector-DTahQUiV.js} +97 -23
- package/dist/collector-DTahQUiV.js.map +1 -0
- package/dist/{collector-LuU1vZ68.d.ts → collector-DUaHCcTS.d.ts} +54 -7
- package/dist/{config-_aQ_PZ-P.js → config-B5kHzuNz.js} +5162 -3024
- package/dist/config-B5kHzuNz.js.map +1 -0
- package/dist/{config-vuCRkBWX.d.ts → config-YsxGv4tq.d.ts} +412 -33
- package/dist/{context-CkSg-kDT.js → context-CA8YKeMn.js} +1 -1
- package/dist/{context-CkSg-kDT.js.map → context-CA8YKeMn.js.map} +1 -1
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +6 -6
- package/dist/{core-BqO8pplb.js → core-CTP5hhqP.js} +152 -179
- package/dist/core-CTP5hhqP.js.map +1 -0
- package/dist/{css-writer-D--REwtp.js → css-writer-BrQjOLNY.js} +78 -17
- package/dist/css-writer-BrQjOLNY.js.map +1 -0
- package/dist/{format-global-rules-Dbc_1tc3.js → format-global-rules-DklyaXv-.js} +1 -1
- package/dist/{format-global-rules-Dbc_1tc3.js.map → format-global-rules-DklyaXv-.js.map} +1 -1
- package/dist/{format-rules-xwteB7a1.js → format-rules-DKOA-6qu.js} +4 -17
- package/dist/format-rules-DKOA-6qu.js.map +1 -0
- package/dist/{hydrate-BvPT4ndL.js → hydrate-OeMX99We.js} +3 -11
- package/dist/{hydrate-BvPT4ndL.js.map → hydrate-OeMX99We.js.map} +1 -1
- package/dist/{index-dUtwpOux.d.ts → index-Cd45t5NM.d.ts} +319 -64
- package/dist/{index-D7qPUGRG.d.ts → index-DhhUI0yi.d.ts} +491 -189
- package/dist/index.d.ts +5 -5
- package/dist/index.js +251 -62
- package/dist/index.js.map +1 -1
- package/dist/{keyframes-ClPFWy33.js → keyframes-CoBy6OgI.js} +10 -173
- package/dist/keyframes-CoBy6OgI.js.map +1 -0
- package/dist/{merge-styles-CtDJMhpJ.d.ts → merge-styles-CU7JbEwg.d.ts} +2 -2
- package/dist/{merge-styles-BUQsEpbv.js → merge-styles-oklji0KB.js} +2 -2
- package/dist/{merge-styles-BUQsEpbv.js.map → merge-styles-oklji0KB.js.map} +1 -1
- package/dist/{resolve-recipes-C0-AMzCz.js → resolve-recipes-DTG81rzl.js} +3 -3
- package/dist/{resolve-recipes-C0-AMzCz.js.map → resolve-recipes-DTG81rzl.js.map} +1 -1
- package/dist/ssr/astro-client.js +1 -1
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-static.d.ts +16 -0
- package/dist/ssr/astro-middleware-static.js +18 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +8 -6
- package/dist/ssr/astro-middleware.js +10 -10
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +2 -17
- package/dist/ssr/astro.js +29 -21
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -9
- package/dist/ssr/index.js +5 -5
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +2 -3
- package/dist/ssr/next.js +6 -7
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +2 -2
- package/dist/static/index.js +4 -4
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.js.map +1 -1
- package/dist/zero/babel.d.ts +2 -81
- package/dist/zero/babel.js +39 -27
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +16 -2
- package/dist/zero/index.js +2 -2
- package/dist/zero/next.d.ts +1 -1
- package/dist/zero/next.js +1 -1
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +4 -1
- package/docs/ai-agents.md +223 -0
- package/docs/configuration.md +457 -38
- package/docs/debug.md +7 -7
- package/docs/design-system.md +2 -2
- package/docs/dsl.md +326 -23
- package/docs/injector.md +57 -4
- package/docs/methodology.md +28 -2
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +93 -25
- package/docs/plugins.md +349 -0
- package/docs/react-api.md +107 -4
- package/docs/ssr.md +45 -35
- package/docs/styles.md +64 -15
- package/docs/tasty-static.md +23 -6
- package/package.json +43 -21
- package/tasty.config.ts +6 -0
- package/dist/collector-DrgDE7QB.js.map +0 -1
- package/dist/config-_aQ_PZ-P.js.map +0 -1
- package/dist/core-BqO8pplb.js.map +0 -1
- package/dist/css-writer-D--REwtp.js.map +0 -1
- package/dist/format-rules-xwteB7a1.js.map +0 -1
- package/dist/keyframes-ClPFWy33.js.map +0 -1
|
@@ -1,5 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dt as SheetInfo, Et as RuleInfo, Ot as StyleInjectorConfig, P as StyleHandlerDefinition, St as PropertyDefinition, Tt as RootRegistry, b as Styles, bt as KeyframesResult, dt as FunctionDefinition, gt as InjectResult, h as ConfigTokens, ht as GlobalInjectResult, it as UnitHandler, kt as StyleRule, lt as FontFaceDescriptors, mt as GCOptions, n as StyleResult, nt as StyleDetails, ot as CacheMetrics, pt as GCConfig, st as CounterStyleDescriptors, ut as FontFaceInput, v as RecipeStyles, wt as RawCSSResult, xt as KeyframesSteps, yt as KeyframesInfo } from "./index-Cd45t5NM.js";
|
|
2
2
|
|
|
3
|
+
//#region src/prop-handlers.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Props middleware for tasty components.
|
|
6
|
+
*
|
|
7
|
+
* A prop handler receives a component's props and returns them, changed or not.
|
|
8
|
+
* That makes it the extension point for props that are *not* style properties:
|
|
9
|
+
* it can read a custom prop, strip it so it never reaches the DOM, and fold its
|
|
10
|
+
* meaning into `styles`, `mods`, `tokens`, `variant`, or `as`.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* configure({
|
|
14
|
+
* propHandlers: {
|
|
15
|
+
* glaze: (props) => {
|
|
16
|
+
* const { glaze, ...rest } = props;
|
|
17
|
+
* if (!glaze) return rest;
|
|
18
|
+
* return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
|
|
19
|
+
* },
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Handlers run on every render of every tasty component, so the registry is a
|
|
25
|
+
* pre-composed chain that is `null` while nothing is registered — the cost when
|
|
26
|
+
* unused is one property load and one branch.
|
|
27
|
+
*/
|
|
28
|
+
/** Props object handed to a prop handler. Deliberately untyped: handlers see everything. */
|
|
29
|
+
type PropHandlerProps = Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Props middleware: props in, props out. Returning nothing means "unchanged".
|
|
32
|
+
*
|
|
33
|
+
* Must be a **pure function** and must not mutate its input. Style values are
|
|
34
|
+
* cached by object identity, so mutating a value object in place produces a stale
|
|
35
|
+
* class name and stale CSS. Return fresh (ideally frozen, ideally memoized)
|
|
36
|
+
* objects instead.
|
|
37
|
+
*/
|
|
38
|
+
type PropHandler = (props: PropHandlerProps) => PropHandlerProps | void | null;
|
|
39
|
+
/**
|
|
40
|
+
* How a prop handler is declared. The map key is both its name and, by default,
|
|
41
|
+
* the prop that triggers it.
|
|
42
|
+
*
|
|
43
|
+
* - `fn` — triggered when a prop matching the key is present
|
|
44
|
+
* - `['glaze', fn]` — triggered by the named prop
|
|
45
|
+
* - `[['glaze', 'tone'], fn]` — triggered by any of them
|
|
46
|
+
* - `['*', fn]` — unconditional; runs on every render of every component
|
|
47
|
+
*/
|
|
48
|
+
type PropHandlerDefinition = PropHandler | [string, PropHandler] | [string[], PropHandler];
|
|
49
|
+
//#endregion
|
|
3
50
|
//#region src/injector/sheet-manager.d.ts
|
|
4
51
|
declare class SheetManager {
|
|
5
52
|
private rootRegistries;
|
|
@@ -20,6 +67,19 @@ declare class SheetManager {
|
|
|
20
67
|
* abstracting away adopted vs style-element modes.
|
|
21
68
|
*/
|
|
22
69
|
getCSSSheet(sheetInfo: SheetInfo): CSSStyleSheet | null;
|
|
70
|
+
/**
|
|
71
|
+
* Record an inserted rule text at its rule index (text mode only).
|
|
72
|
+
*
|
|
73
|
+
* `textRules` mirrors the sheet's rule order. `textContent` cannot be edited
|
|
74
|
+
* rule-by-rule the way CSSOM can, so keeping the texts is what makes
|
|
75
|
+
* deletion possible at all in this mode.
|
|
76
|
+
*/
|
|
77
|
+
private trackTextRule;
|
|
78
|
+
/**
|
|
79
|
+
* Remove rule indices from a text-mode sheet and rewrite the element's text.
|
|
80
|
+
* Returns the indices that were actually removed.
|
|
81
|
+
*/
|
|
82
|
+
private deleteTextRules;
|
|
23
83
|
/**
|
|
24
84
|
* Determine the injection mode for a root.
|
|
25
85
|
* ShadowRoot uses adopted stylesheets when supported; Document uses <style> elements.
|
|
@@ -73,6 +133,23 @@ declare class SheetManager {
|
|
|
73
133
|
* Find an available rule index in the sheet
|
|
74
134
|
*/
|
|
75
135
|
findAvailableRuleIndex(sheet: SheetInfo): number;
|
|
136
|
+
/**
|
|
137
|
+
* Probe whether the underlying CSS engine supports `@property` at-rules.
|
|
138
|
+
* Result is cached per registry on `registry.atPropertySupported`.
|
|
139
|
+
*
|
|
140
|
+
* The probe inserts and immediately deletes a minimal known-valid rule
|
|
141
|
+
* (`@property --__tasty_probe__ { syntax: "*"; inherits: true; }`).
|
|
142
|
+
* Engines that lack `@property` support (jsdom, happy-dom) reject any
|
|
143
|
+
* `@property` rule including this one, so a probe failure is a reliable
|
|
144
|
+
* signal that further `@property` rejections are environmental noise and
|
|
145
|
+
* not user-authored bugs.
|
|
146
|
+
*
|
|
147
|
+
* The probe is intentionally a separate operation from the user's failing
|
|
148
|
+
* insertion: we don't want to leak `--__tasty_probe__` into the sheet, so
|
|
149
|
+
* on success we delete the probe rule immediately, leaving `ruleCount`
|
|
150
|
+
* and `cssRules.length` unchanged.
|
|
151
|
+
*/
|
|
152
|
+
private engineSupportsAtProperty;
|
|
76
153
|
/**
|
|
77
154
|
* Force cleanup of unused styles
|
|
78
155
|
*/
|
|
@@ -88,7 +165,7 @@ declare class SheetManager {
|
|
|
88
165
|
/**
|
|
89
166
|
* Get CSS text from all sheets (for SSR)
|
|
90
167
|
*/
|
|
91
|
-
|
|
168
|
+
getCSSText(registry: RootRegistry): string;
|
|
92
169
|
/**
|
|
93
170
|
* Get cache performance metrics
|
|
94
171
|
*/
|
|
@@ -161,9 +238,48 @@ declare class StyleInjector {
|
|
|
161
238
|
private config;
|
|
162
239
|
private globalRuleCounter;
|
|
163
240
|
private pendingGCHandle;
|
|
241
|
+
private namePrefix;
|
|
242
|
+
private classRegex;
|
|
243
|
+
private rscClassRegex;
|
|
164
244
|
/** @internal — exposed for debug utilities only */
|
|
165
245
|
get _sheetManager(): SheetManager;
|
|
246
|
+
/**
|
|
247
|
+
* Whether sheet writes should be queued instead of applied immediately.
|
|
248
|
+
*
|
|
249
|
+
* Only ever true on the client: SSR collects CSS as text and the RSC path
|
|
250
|
+
* returns it as strings, so neither has a live sheet to batch writes against.
|
|
251
|
+
*
|
|
252
|
+
* In the default `true` mode a write is only queued inside an open batch
|
|
253
|
+
* window — a commit in which `<TastyBatchProvider>` rendered and will
|
|
254
|
+
* therefore flush in its insertion effect, before any layout effect can
|
|
255
|
+
* measure. Everything else falls through to a synchronous write, so enabling
|
|
256
|
+
* the flag cannot make a `useLayoutEffect` read an unstyled element.
|
|
257
|
+
* `'always'` drops the gate and accepts that trade for wider coverage.
|
|
258
|
+
*/
|
|
259
|
+
private get batching();
|
|
260
|
+
/**
|
|
261
|
+
* Apply a sheet write now, or queue it when batching is on.
|
|
262
|
+
* Returns the queue handle when deferred, so the caller can cancel it if it
|
|
263
|
+
* disposes before the flush.
|
|
264
|
+
*/
|
|
265
|
+
private writeSheet;
|
|
266
|
+
/**
|
|
267
|
+
* Insert a global (non-class) rule, honouring batching.
|
|
268
|
+
*
|
|
269
|
+
* `onApplied` records the caller's dedupe bookkeeping. When the write is
|
|
270
|
+
* queued it runs eagerly, so a repeat call before the flush bails out instead
|
|
271
|
+
* of queueing the same rule twice — the same reasoning as
|
|
272
|
+
* `insertPropertyRule`'s eager marking. When written synchronously it runs
|
|
273
|
+
* only on success, preserving the existing retry-on-failure behaviour.
|
|
274
|
+
*/
|
|
275
|
+
private writeGlobalRule;
|
|
166
276
|
constructor(config?: StyleInjectorConfig);
|
|
277
|
+
/**
|
|
278
|
+
* Generate a deterministic class name from a cache key using content hash.
|
|
279
|
+
* The same cache key always produces the same class name across environments
|
|
280
|
+
* with the same `namePrefix`.
|
|
281
|
+
*/
|
|
282
|
+
private generateClassName;
|
|
167
283
|
/**
|
|
168
284
|
* Check if `className` was hydrated from server-rendered styles and,
|
|
169
285
|
* if so, wire the cacheKey mapping. Returns true on hit.
|
|
@@ -228,13 +344,13 @@ declare class StyleInjector {
|
|
|
228
344
|
/**
|
|
229
345
|
* Get CSS text from all sheets (for SSR)
|
|
230
346
|
*/
|
|
231
|
-
|
|
347
|
+
getCSSText(options?: {
|
|
232
348
|
root?: Document | ShadowRoot;
|
|
233
349
|
}): string;
|
|
234
350
|
/**
|
|
235
351
|
* Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
|
|
236
352
|
*/
|
|
237
|
-
|
|
353
|
+
getCSSTextForClasses(classNames: Iterable<string>, options?: {
|
|
238
354
|
root?: Document | ShadowRoot;
|
|
239
355
|
}): string;
|
|
240
356
|
/**
|
|
@@ -268,6 +384,11 @@ declare class StyleInjector {
|
|
|
268
384
|
property(name: string, options?: PropertyDefinition & {
|
|
269
385
|
root?: Document | ShadowRoot;
|
|
270
386
|
}): void;
|
|
387
|
+
/**
|
|
388
|
+
* Build and insert a single `@property` rule into the given registry.
|
|
389
|
+
* No-op if the property was already injected.
|
|
390
|
+
*/
|
|
391
|
+
private insertPropertyRule;
|
|
271
392
|
/**
|
|
272
393
|
* Check whether a given @property name was already injected by this injector.
|
|
273
394
|
*
|
|
@@ -291,11 +412,28 @@ declare class StyleInjector {
|
|
|
291
412
|
/**
|
|
292
413
|
* Inject a CSS @counter-style rule.
|
|
293
414
|
*
|
|
294
|
-
* Permanent and global — no dispose or ref-counting.
|
|
295
|
-
*
|
|
415
|
+
* Permanent and global — no dispose or ref-counting. Deduplicates by name.
|
|
416
|
+
* By default a definition overrides a previously injected one of the same
|
|
417
|
+
* name. Pass `weak: true` for global `configure()` definitions, which must
|
|
418
|
+
* never clobber an existing rule (so component-local definitions win
|
|
419
|
+
* regardless of injection order).
|
|
296
420
|
*/
|
|
297
421
|
counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
|
|
298
422
|
root?: Document | ShadowRoot;
|
|
423
|
+
weak?: boolean;
|
|
424
|
+
}): void;
|
|
425
|
+
/**
|
|
426
|
+
* Inject a CSS @function rule (custom function).
|
|
427
|
+
*
|
|
428
|
+
* Permanent and global — no dispose or ref-counting. Deduplicates by function
|
|
429
|
+
* name. By default a definition overrides a previously injected one of the
|
|
430
|
+
* same name. Pass `weak: true` for global `configure()` definitions, which
|
|
431
|
+
* must never clobber an existing rule (so component-local definitions win
|
|
432
|
+
* regardless of injection order).
|
|
433
|
+
*/
|
|
434
|
+
func(name: string, definition: FunctionDefinition, options?: {
|
|
435
|
+
root?: Document | ShadowRoot;
|
|
436
|
+
weak?: boolean;
|
|
299
437
|
}): void;
|
|
300
438
|
/**
|
|
301
439
|
* Inject keyframes and return object with toString() and dispose()
|
|
@@ -314,7 +452,6 @@ declare class StyleInjector {
|
|
|
314
452
|
* Dispose keyframes
|
|
315
453
|
*/
|
|
316
454
|
private disposeKeyframes;
|
|
317
|
-
private static readonly TASTY_CLASS_RE;
|
|
318
455
|
/**
|
|
319
456
|
* Record a render-time usage hit for one or more classNames.
|
|
320
457
|
* Handles space-separated multi-chunk classNames.
|
|
@@ -347,7 +484,38 @@ declare class StyleInjector {
|
|
|
347
484
|
destroy(root?: Document | ShadowRoot): void;
|
|
348
485
|
}
|
|
349
486
|
//#endregion
|
|
487
|
+
//#region src/functions/index.d.ts
|
|
488
|
+
/**
|
|
489
|
+
* A parse-time function: receives the parsed (comma-separated) argument groups
|
|
490
|
+
* and returns a CSS value string. This is the JS flavor of the unified
|
|
491
|
+
* `functions` config (bare-name keys), distinct from declarative `@function`
|
|
492
|
+
* definitions (`$$`-prefixed keys).
|
|
493
|
+
*/
|
|
494
|
+
type ParseFunction = (groups: StyleDetails[]) => string;
|
|
495
|
+
/**
|
|
496
|
+
* The unified `functions` map: keys are either bare names (parse functions,
|
|
497
|
+
* value is a function) or `$$name`/`$name`/`--name` (declarative CSS functions,
|
|
498
|
+
* value is a {@link FunctionDefinition} object).
|
|
499
|
+
*/
|
|
500
|
+
type FunctionsConfig = Record<string, FunctionDefinition | ParseFunction>;
|
|
501
|
+
//#endregion
|
|
350
502
|
//#region src/utils/color-space.d.ts
|
|
503
|
+
/**
|
|
504
|
+
* Color handling that survives into the emitted CSS.
|
|
505
|
+
*
|
|
506
|
+
* Tasty does not rewrite a color into a particular color space: opacity is
|
|
507
|
+
* applied with CSS relative color syntax, which reads the channels off whatever
|
|
508
|
+
* the browser resolves a value to, so a color is emitted exactly as authored.
|
|
509
|
+
* What is left here is how an alpha gets applied, and the one distinction that
|
|
510
|
+
* matters — replacing a token's alpha versus composing onto an inherited one.
|
|
511
|
+
*/
|
|
512
|
+
/**
|
|
513
|
+
* The color space a `#name` token's value used to be rewritten into.
|
|
514
|
+
*
|
|
515
|
+
* @deprecated Kept for the `colorSpace` config option, which no longer has any
|
|
516
|
+
* effect. Colors are emitted as authored and opacity is always applied in
|
|
517
|
+
* `oklch` through relative color syntax.
|
|
518
|
+
*/
|
|
351
519
|
type ColorSpace = 'rgb' | 'hsl' | 'oklch';
|
|
352
520
|
//#endregion
|
|
353
521
|
//#region src/utils/typography.d.ts
|
|
@@ -411,8 +579,12 @@ declare function generateTypographyTokens(presets: Record<string, TypographyPres
|
|
|
411
579
|
interface TastyPlugin {
|
|
412
580
|
/** Unique name for the plugin (used for debugging and conflict detection) */
|
|
413
581
|
name: string;
|
|
414
|
-
/**
|
|
415
|
-
|
|
582
|
+
/**
|
|
583
|
+
* Custom functions (unified map). Bare keys map to parse functions
|
|
584
|
+
* `(groups) => string`; `$$name` keys map to declarative CSS `@function`
|
|
585
|
+
* definitions. See {@link FunctionsConfig}.
|
|
586
|
+
*/
|
|
587
|
+
functions?: FunctionsConfig;
|
|
416
588
|
/** Custom units that transform numeric values (e.g., `2x` → `calc(2 * var(--gap))`) */
|
|
417
589
|
units?: Record<string, string | UnitHandler>;
|
|
418
590
|
/** Custom state aliases (e.g., `'@mobile': '@media(w < 768px)'`) */
|
|
@@ -431,11 +603,37 @@ interface TastyPlugin {
|
|
|
431
603
|
* ```
|
|
432
604
|
*/
|
|
433
605
|
handlers?: Record<string, StyleHandlerDefinition>;
|
|
606
|
+
/**
|
|
607
|
+
* Props middleware for every tasty component — props in, props out. The
|
|
608
|
+
* extension point for props that are not style properties: read a custom prop,
|
|
609
|
+
* strip it so it never reaches the DOM, and fold its meaning into `styles`,
|
|
610
|
+
* `mods`, `tokens`, `variant`, or `as`.
|
|
611
|
+
*
|
|
612
|
+
* Must be pure and must not mutate its input.
|
|
613
|
+
* See {@link TastyConfig.propHandlers}.
|
|
614
|
+
* @example
|
|
615
|
+
* ```ts
|
|
616
|
+
* propHandlers: {
|
|
617
|
+
* glaze: (props) => {
|
|
618
|
+
* const { glaze, ...rest } = props;
|
|
619
|
+
* if (!glaze) return rest;
|
|
620
|
+
* return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
|
|
621
|
+
* },
|
|
622
|
+
* }
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
propHandlers?: Record<string, PropHandlerDefinition>;
|
|
626
|
+
/**
|
|
627
|
+
* Style properties exposed as top-level props on every tasty component, in
|
|
628
|
+
* addition to the built-in base styles.
|
|
629
|
+
* See {@link TastyConfig.baseStyleProps}.
|
|
630
|
+
*/
|
|
631
|
+
baseStyleProps?: readonly string[];
|
|
434
632
|
/**
|
|
435
633
|
* Design tokens injected as CSS custom properties on `:root`.
|
|
436
634
|
* Values are parsed through the Tasty DSL. Supports state maps.
|
|
437
635
|
* - `$name` → `--name` CSS custom property
|
|
438
|
-
* - `#name` → `--name-color`
|
|
636
|
+
* - `#name` → `--name-color`
|
|
439
637
|
*/
|
|
440
638
|
tokens?: ConfigTokens;
|
|
441
639
|
/** Predefined tokens replaced during style parsing (`$name` or `#name`) */
|
|
@@ -462,6 +660,19 @@ interface TastyPlugin {
|
|
|
462
660
|
* Supports the full Tasty style syntax.
|
|
463
661
|
*/
|
|
464
662
|
globalStyles?: Record<string, Styles>;
|
|
663
|
+
/**
|
|
664
|
+
* Global CSS `@property` definitions. A plugin whose handler or prop handler
|
|
665
|
+
* emits a custom property usually wants one, so the property animates and
|
|
666
|
+
* inherits correctly instead of being treated as an untyped string.
|
|
667
|
+
* See {@link TastyConfig.properties}.
|
|
668
|
+
*/
|
|
669
|
+
properties?: Record<string, PropertyDefinition>;
|
|
670
|
+
/** Global keyframes, injected only when referenced. See {@link TastyConfig.keyframes}. */
|
|
671
|
+
keyframes?: Record<string, KeyframesSteps>;
|
|
672
|
+
/** Global `@font-face` definitions. See {@link TastyConfig.fontFaces}. */
|
|
673
|
+
fontFaces?: Record<string, FontFaceInput>;
|
|
674
|
+
/** Global `@counter-style` definitions. See {@link TastyConfig.counterStyles}. */
|
|
675
|
+
counterStyles?: Record<string, CounterStyleDescriptors>;
|
|
465
676
|
}
|
|
466
677
|
/**
|
|
467
678
|
* A factory function that creates a TastyPlugin.
|
|
@@ -472,13 +683,13 @@ interface TastyPlugin {
|
|
|
472
683
|
* // Plugin without options
|
|
473
684
|
* const okhslPlugin: TastyPluginFactory = () => ({
|
|
474
685
|
* name: 'okhsl',
|
|
475
|
-
*
|
|
686
|
+
* functions: { okhsl: okhslFunction },
|
|
476
687
|
* });
|
|
477
688
|
*
|
|
478
689
|
* // Plugin with options
|
|
479
690
|
* const debugPlugin: TastyPluginFactory<{ verbose: boolean }> = (options) => ({
|
|
480
691
|
* name: 'debug',
|
|
481
|
-
*
|
|
692
|
+
* functions: { debug: createDebugFunc(options.verbose) },
|
|
482
693
|
* });
|
|
483
694
|
* ```
|
|
484
695
|
*/
|
|
@@ -515,30 +726,92 @@ interface TastyConfig {
|
|
|
515
726
|
*/
|
|
516
727
|
units?: Record<string, string | UnitHandler>;
|
|
517
728
|
/**
|
|
518
|
-
* Custom functions
|
|
519
|
-
*
|
|
520
|
-
*
|
|
729
|
+
* Custom functions (merged with existing). A single map holds both flavors,
|
|
730
|
+
* discriminated by value type:
|
|
731
|
+
*
|
|
732
|
+
* - **Bare key + function value** — a parse-time function that processes the
|
|
733
|
+
* parsed argument groups and returns a CSS value. Called as `name(...)`.
|
|
734
|
+
* - **`$$name` key + object value** — a declarative CSS `@function`
|
|
735
|
+
* definition. Called as `$$name(...)` (→ native `--name(...)`).
|
|
736
|
+
*
|
|
737
|
+
* A key whose prefix does not match its value type (object under a bare key,
|
|
738
|
+
* or function under a `$$` key) is ignored with a dev warning.
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
* ```ts
|
|
742
|
+
* configure({
|
|
743
|
+
* functions: {
|
|
744
|
+
* double: (groups) => `calc(2 * ${groups[0].output})`, // parse function
|
|
745
|
+
* $$negative: { args: ['$value'], result: '(-1 * $value)' }, // CSS function
|
|
746
|
+
* },
|
|
747
|
+
* });
|
|
748
|
+
* ```
|
|
521
749
|
*/
|
|
522
|
-
|
|
750
|
+
functions?: FunctionsConfig;
|
|
523
751
|
/**
|
|
524
|
-
*
|
|
525
|
-
*
|
|
752
|
+
* @deprecated No longer has any effect; will be removed in the next major.
|
|
753
|
+
* Setting it warns in development.
|
|
526
754
|
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
755
|
+
* A `#name` token's value used to be rewritten into this color space so an
|
|
756
|
+
* opacity suffix had numeric channels to write an alpha into. Opacity now uses
|
|
757
|
+
* relative color syntax — `oklch(from var(--name-color) l c h / .5)` — which
|
|
758
|
+
* has the browser read the channels, so a color is emitted exactly as
|
|
759
|
+
* authored and there is nothing left for the setting to decide.
|
|
530
760
|
*
|
|
531
|
-
*
|
|
761
|
+
* To address a token's channels yourself, write relative color syntax against
|
|
762
|
+
* the token: `oklch(from var(--brand-color) calc(l * 1.2) c h)`. It works on
|
|
763
|
+
* every `<color>`, including the ones no conversion could evaluate.
|
|
532
764
|
*/
|
|
533
765
|
colorSpace?: ColorSpace;
|
|
534
766
|
/**
|
|
535
767
|
* Automatically infer and register CSS @property declarations
|
|
536
768
|
* from custom property values found in styles, keyframes, and global config.
|
|
537
769
|
* Covers all types: \<color\>, \<number\>, \<length\>, \<angle\>, \<percentage\>, \<time\>.
|
|
538
|
-
* When false, only explicitly declared @
|
|
770
|
+
* When false, only explicitly declared @property are registered.
|
|
539
771
|
* @default true
|
|
540
772
|
*/
|
|
541
773
|
autoPropertyTypes?: boolean;
|
|
774
|
+
/**
|
|
775
|
+
* Defer stylesheet writes and apply them in one batch instead of performing
|
|
776
|
+
* one `insertRule()` per component during render.
|
|
777
|
+
*
|
|
778
|
+
* Each `insertRule()` on a live sheet invalidates style for that sheet's
|
|
779
|
+
* scope. When components inject during React's render phase while other
|
|
780
|
+
* components read layout in the same pass, the two interleave and the browser
|
|
781
|
+
* is forced to recalculate style between every injection. Batching collapses
|
|
782
|
+
* that into one invalidation per flush.
|
|
783
|
+
*
|
|
784
|
+
* - `false` (default) — inject synchronously, one write per component.
|
|
785
|
+
* - `true` — batch, but only inside a *batch window*: a commit in which
|
|
786
|
+
* `<TastyBatchProvider>` rendered and will therefore flush in its
|
|
787
|
+
* `useInsertionEffect`, before any `useLayoutEffect` runs. Any injection
|
|
788
|
+
* outside a window — a deep update the provider did not re-render for, an
|
|
789
|
+
* injection from a layout effect, an event handler, an async callback — is
|
|
790
|
+
* written straight through. Enabling this can never make a layout effect
|
|
791
|
+
* measure an unstyled element. Requires `<TastyBatchProvider>`; without it
|
|
792
|
+
* nothing is batched (and dev mode says so once).
|
|
793
|
+
* - `'always'` — batch every injection, flushing on a microtask when no
|
|
794
|
+
* window is open. Wins on more commits, but a `useLayoutEffect` that
|
|
795
|
+
* measures a freshly mounted element can read its unstyled box, because
|
|
796
|
+
* microtasks run after the layout phase. Paint is unaffected: microtasks
|
|
797
|
+
* always drain before the browser paints.
|
|
798
|
+
*
|
|
799
|
+
* No effect during SSR or RSC: styles are collected as text there, the
|
|
800
|
+
* runtime injector never runs, and the provider is inert without a
|
|
801
|
+
* `document`. No effect on zero-runtime `tastyStatic` styles either — those
|
|
802
|
+
* are extracted at build time and never reach the injector.
|
|
803
|
+
*
|
|
804
|
+
* @default false
|
|
805
|
+
* @example
|
|
806
|
+
* ```tsx
|
|
807
|
+
* configure({ batchInjection: true });
|
|
808
|
+
*
|
|
809
|
+
* <TastyBatchProvider>
|
|
810
|
+
* <App />
|
|
811
|
+
* </TastyBatchProvider>
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
batchInjection?: boolean | 'always';
|
|
542
815
|
/**
|
|
543
816
|
* Garbage collection configuration for unused styles.
|
|
544
817
|
* GC is triggered by touch count: every `touchInterval` touches, the
|
|
@@ -551,6 +824,28 @@ interface TastyConfig {
|
|
|
551
824
|
* ```
|
|
552
825
|
*/
|
|
553
826
|
gc?: GCConfig;
|
|
827
|
+
/**
|
|
828
|
+
* Prefix prepended to every generated identifier (class names,
|
|
829
|
+
* keyframe names, counter-style names). The hash is appended verbatim,
|
|
830
|
+
* so include any separator inside the prefix itself (e.g. `'myapp-'`).
|
|
831
|
+
*
|
|
832
|
+
* Discriminator letters are inserted between the prefix and the hash
|
|
833
|
+
* for non-class names so the three kinds stay visually distinct:
|
|
834
|
+
* - class: `${namePrefix}${hash}` — e.g. `t1a2b3`
|
|
835
|
+
* - keyframe: `${namePrefix}k${hash}` — e.g. `tk1a2b3`
|
|
836
|
+
* - counter-style: `${namePrefix}c${hash}` — e.g. `tc1a2b3`
|
|
837
|
+
*
|
|
838
|
+
* The runtime, SSR, and RSC paths must agree on this value or
|
|
839
|
+
* hydration will mismatch. The zero-runtime build path defaults to
|
|
840
|
+
* `'ts'` (overridable via the same option) so its classes can't
|
|
841
|
+
* collide with runtime classes when both are loaded on the same page.
|
|
842
|
+
*
|
|
843
|
+
* Must match `^[a-zA-Z_][a-zA-Z0-9_-]{0,31}$`. Locked once styles
|
|
844
|
+
* have been generated.
|
|
845
|
+
*
|
|
846
|
+
* @default 't'
|
|
847
|
+
*/
|
|
848
|
+
namePrefix?: string;
|
|
554
849
|
/**
|
|
555
850
|
* Plugins that extend tasty with custom functions, units, or states.
|
|
556
851
|
* Plugins are processed in order, with later plugins overriding earlier ones.
|
|
@@ -621,7 +916,7 @@ interface TastyConfig {
|
|
|
621
916
|
* @example
|
|
622
917
|
* ```ts
|
|
623
918
|
* configure({
|
|
624
|
-
*
|
|
919
|
+
* fontFaces: {
|
|
625
920
|
* 'Brand Sans': [
|
|
626
921
|
* { src: 'url("/fonts/brand-regular.woff2") format("woff2")', fontWeight: 400, fontDisplay: 'swap' },
|
|
627
922
|
* { src: 'url("/fonts/brand-bold.woff2") format("woff2")', fontWeight: 700, fontDisplay: 'swap' },
|
|
@@ -631,7 +926,7 @@ interface TastyConfig {
|
|
|
631
926
|
* });
|
|
632
927
|
* ```
|
|
633
928
|
*/
|
|
634
|
-
|
|
929
|
+
fontFaces?: Record<string, FontFaceInput>;
|
|
635
930
|
/**
|
|
636
931
|
* Global @counter-style definitions.
|
|
637
932
|
* Keys are counter-style names, values are descriptor objects.
|
|
@@ -639,13 +934,32 @@ interface TastyConfig {
|
|
|
639
934
|
* @example
|
|
640
935
|
* ```ts
|
|
641
936
|
* configure({
|
|
642
|
-
*
|
|
937
|
+
* counterStyles: {
|
|
643
938
|
* thumbs: { system: 'cyclic', symbols: '"👍"', suffix: '" "' },
|
|
644
939
|
* },
|
|
645
940
|
* });
|
|
646
941
|
* ```
|
|
647
942
|
*/
|
|
648
|
-
|
|
943
|
+
counterStyles?: Record<string, CounterStyleDescriptors>;
|
|
944
|
+
/**
|
|
945
|
+
* Opt-in polyfills for not-yet-baseline CSS features. Each key toggles a
|
|
946
|
+
* feature polyfill; all default to `false`.
|
|
947
|
+
*
|
|
948
|
+
* - `functions` — polyfill CSS `@function` by inlining every `$$name(...)`
|
|
949
|
+
* call into plain CSS (calc/var/color-mix) at parse time instead of
|
|
950
|
+
* emitting the native `@function` at-rule. Enables `@function` usage in
|
|
951
|
+
* browsers that don't support it yet (Firefox/Safari). Note this is the
|
|
952
|
+
* `functions` *feature toggle*, distinct from the top-level `functions`
|
|
953
|
+
* definitions map.
|
|
954
|
+
*
|
|
955
|
+
* @example
|
|
956
|
+
* ```ts
|
|
957
|
+
* configure({ polyfills: { functions: true } });
|
|
958
|
+
* ```
|
|
959
|
+
*/
|
|
960
|
+
polyfills?: {
|
|
961
|
+
functions?: boolean;
|
|
962
|
+
};
|
|
649
963
|
/**
|
|
650
964
|
* Custom style handlers that transform style properties into CSS declarations.
|
|
651
965
|
* Handlers replace built-in handlers for the same style name.
|
|
@@ -675,13 +989,63 @@ interface TastyConfig {
|
|
|
675
989
|
* ```
|
|
676
990
|
*/
|
|
677
991
|
handlers?: Record<string, StyleHandlerDefinition>;
|
|
992
|
+
/**
|
|
993
|
+
* Props middleware for every tasty component. A prop handler receives the
|
|
994
|
+
* component's props and returns them, changed or not — the extension point for
|
|
995
|
+
* props that are not style properties.
|
|
996
|
+
*
|
|
997
|
+
* The map key is the handler's name and, by default, the prop that triggers it.
|
|
998
|
+
* Use `['*', fn]` for an unconditional handler, or `[['a', 'b'], fn]` to trigger
|
|
999
|
+
* on any of several props.
|
|
1000
|
+
*
|
|
1001
|
+
* Handlers must be pure and must not mutate their input: style values are cached
|
|
1002
|
+
* by object identity, so mutating one in place yields stale CSS. Memoize the
|
|
1003
|
+
* styles you build per input value.
|
|
1004
|
+
*
|
|
1005
|
+
* Not applicable to zero-runtime mode — `tastyStatic()` takes styles objects, not
|
|
1006
|
+
* props, so there is nothing for middleware to run on. Components rendered
|
|
1007
|
+
* through `tasty()` are unaffected and keep the runtime injector.
|
|
1008
|
+
*
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```ts
|
|
1011
|
+
* configure({
|
|
1012
|
+
* propHandlers: {
|
|
1013
|
+
* glaze: (props) => {
|
|
1014
|
+
* const { glaze, ...rest } = props;
|
|
1015
|
+
* if (!glaze) return rest;
|
|
1016
|
+
* return { ...rest, styles: mergeStyles(glazeStyles(glaze), rest.styles) };
|
|
1017
|
+
* },
|
|
1018
|
+
* },
|
|
1019
|
+
* });
|
|
1020
|
+
*
|
|
1021
|
+
* <Element glaze="purple" />
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
propHandlers?: Record<string, PropHandlerDefinition>;
|
|
1025
|
+
/**
|
|
1026
|
+
* Style properties exposed as top-level props on **every** tasty component, in
|
|
1027
|
+
* addition to the built-in base styles, without each component listing them in
|
|
1028
|
+
* `styleProps`.
|
|
1029
|
+
*
|
|
1030
|
+
* Augment `TastyBaseStylePropNames` to type them. Each name costs one property
|
|
1031
|
+
* check per render of every component, so keep the list short; the effect is
|
|
1032
|
+
* app-global and cannot be scoped to a subtree.
|
|
1033
|
+
*
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```ts
|
|
1036
|
+
* configure({ baseStyleProps: ['radius', 'shadow'] });
|
|
1037
|
+
*
|
|
1038
|
+
* <Card radius="1r" shadow />
|
|
1039
|
+
* ```
|
|
1040
|
+
*/
|
|
1041
|
+
baseStyleProps?: readonly string[];
|
|
678
1042
|
/**
|
|
679
1043
|
* Design tokens injected as CSS custom properties on `:root`.
|
|
680
1044
|
* Values are parsed through the Tasty DSL. Supports state maps
|
|
681
1045
|
* for responsive/theme-aware tokens.
|
|
682
1046
|
*
|
|
683
1047
|
* - `$name` keys become `--name` CSS custom properties
|
|
684
|
-
* - `#name` keys become `--name-color`
|
|
1048
|
+
* - `#name` keys become `--name-color` properties
|
|
685
1049
|
*
|
|
686
1050
|
* Tokens are injected once when the first style is rendered.
|
|
687
1051
|
*
|
|
@@ -730,7 +1094,7 @@ interface TastyConfig {
|
|
|
730
1094
|
/**
|
|
731
1095
|
* Predefined style recipes -- named style bundles that can be applied via `recipe` style property.
|
|
732
1096
|
* Recipe values are flat tasty styles (no sub-element keys). They may contain base styles,
|
|
733
|
-
* tokens (`$name`/`#name` definitions), local states, `@keyframes`, and `@
|
|
1097
|
+
* tokens (`$name`/`#name` definitions), local states, `@keyframes`, and `@property`.
|
|
734
1098
|
*
|
|
735
1099
|
* Components reference recipes via: `recipe: 'name1 name2'` in their styles.
|
|
736
1100
|
* Use `/` to separate base recipes from post recipes: `recipe: 'base1 base2 / post1'`.
|
|
@@ -826,13 +1190,19 @@ declare function getGlobalKeyframes(): Record<string, KeyframesSteps> | null;
|
|
|
826
1190
|
* Returns null if no font faces configured.
|
|
827
1191
|
* Reads from globalThis first for cross-module SSR support.
|
|
828
1192
|
*/
|
|
829
|
-
declare function
|
|
1193
|
+
declare function getGlobalFontFaces(): Record<string, FontFaceInput> | null;
|
|
830
1194
|
/**
|
|
831
1195
|
* Get global counter-style configuration.
|
|
832
1196
|
* Returns null if no counter styles configured.
|
|
833
1197
|
* Reads from globalThis first for cross-module SSR support.
|
|
834
1198
|
*/
|
|
835
|
-
declare function
|
|
1199
|
+
declare function getGlobalCounterStyles(): Record<string, CounterStyleDescriptors> | null;
|
|
1200
|
+
/**
|
|
1201
|
+
* Get global @function configuration.
|
|
1202
|
+
* Returns null if no functions configured.
|
|
1203
|
+
* Reads from globalThis first for cross-module SSR support.
|
|
1204
|
+
*/
|
|
1205
|
+
declare function getGlobalFunctions(): Record<string, FunctionDefinition> | null;
|
|
836
1206
|
/**
|
|
837
1207
|
* Check if any global recipes are configured.
|
|
838
1208
|
* Fast path: returns false if no recipes were ever set.
|
|
@@ -874,11 +1244,20 @@ declare function configure(config?: Partial<TastyConfig>): void;
|
|
|
874
1244
|
* If not configured, returns default configuration.
|
|
875
1245
|
*/
|
|
876
1246
|
declare function getConfig(): TastyConfig;
|
|
1247
|
+
/**
|
|
1248
|
+
* Get the configured prefix used for every generated identifier
|
|
1249
|
+
* (class names, keyframe names, counter-style names).
|
|
1250
|
+
*
|
|
1251
|
+
* Falls back to the default prefix (`'t'`) when `configure()` has not
|
|
1252
|
+
* been called yet — this matches the auto-configuration behavior used
|
|
1253
|
+
* by the rest of the system.
|
|
1254
|
+
*/
|
|
1255
|
+
declare function getNamePrefix(): string;
|
|
877
1256
|
/**
|
|
878
1257
|
* Reset configuration (for testing only).
|
|
879
1258
|
* Clears the global injector and allows reconfiguration.
|
|
880
1259
|
*/
|
|
881
1260
|
declare function resetConfig(): void;
|
|
882
1261
|
//#endregion
|
|
883
|
-
export {
|
|
884
|
-
//# sourceMappingURL=config-
|
|
1262
|
+
export { ParseFunction as C, PropHandlerDefinition as D, PropHandler as E, PropHandlerProps as O, FunctionsConfig as S, SheetManager as T, TastyPluginFactory as _, getGlobalFontFaces as a, generateTypographyTokens as b, getGlobalRecipes as c, hasGlobalRecipes as d, hasStylesGenerated as f, TastyPlugin as g, resetConfig as h, getGlobalCounterStyles as i, getNamePrefix as l, isTestEnvironment as m, configure as n, getGlobalFunctions as o, isConfigLocked as p, getConfig as r, getGlobalKeyframes as s, TastyConfig as t, hasGlobalKeyframes as u, TypographyPreset as v, StyleInjector as w, ColorSpace as x, TypographyTokenValue as y };
|
|
1263
|
+
//# sourceMappingURL=config-YsxGv4tq.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-
|
|
1
|
+
{"version":3,"file":"context-CA8YKeMn.js","names":[],"sources":["../src/ssr/context.ts"],"sourcesContent":["/**\n * React context for SSR collector discovery.\n *\n * Used by Next.js TastyRegistry to provide the ServerStyleCollector\n * to useStyles() via React context (the streaming-compatible path).\n *\n * This avoids relying on globalThis for cross-layer communication,\n * which leaks between RSC and SSR module graphs in Next.js App Router.\n *\n * The context is created lazily to avoid calling createContext() at\n * module evaluation time, which would break Server Components that\n * import from `@tenphi/tasty` without using any React hooks.\n */\n\nimport { createContext, type Context } from 'react';\n\nimport type { ServerStyleCollector } from './collector';\n\nlet _ctx: Context<ServerStyleCollector | null> | undefined;\n\nexport function getTastySSRContext(): Context<ServerStyleCollector | null> {\n if (!_ctx) {\n _ctx = createContext<ServerStyleCollector | null>(null);\n }\n return _ctx;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,IAAI;AAEJ,SAAgB,qBAA2D;CACzE,IAAI,CAAC,MACH,OAAO,cAA2C,IAAI;CAExD,OAAO;AACT"}
|