@tenphi/tasty 0.0.0-snapshot.c8bdaeb → 0.0.0-snapshot.c8c7b2a
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 +309 -159
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +17 -10
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +3 -5
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +32 -34
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +322 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +157 -30
- package/dist/config.js +233 -45
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +12 -11
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +359 -639
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +36 -0
- package/dist/hooks/useCounterStyle.js +65 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +45 -0
- package/dist/hooks/useFontFace.js +66 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +21 -2
- package/dist/hooks/useGlobalStyles.js +60 -28
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +44 -43
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +36 -31
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +13 -44
- package/dist/hooks/useRawCSS.js +91 -16
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +3 -3
- package/dist/hooks/useStyles.js +8 -146
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.js +15 -12
- package/dist/injector/index.d.ts +36 -11
- package/dist/injector/index.js +43 -12
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +62 -3
- package/dist/injector/injector.js +293 -46
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +22 -17
- package/dist/injector/sheet-manager.js +64 -79
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +121 -21
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +6 -6
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +2 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +58 -4
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +82 -34
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +436 -123
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +21 -13
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +181 -7
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +3 -277
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +20 -2
- package/dist/properties/index.js +83 -19
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +90 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/rsc-cache.js +79 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +108 -0
- package/dist/ssr/astro.js +149 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +44 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +58 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +98 -0
- package/dist/ssr/collector.js +235 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.js +16 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +69 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +49 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +29 -0
- package/dist/ssr/hydrate.js +45 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +4 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +75 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +29 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.js +13 -259
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- package/dist/styles/color.js +11 -8
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +28 -26
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +9 -9
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -6
- package/dist/styles/predefined.js +9 -13
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -3
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +31 -92
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +6 -5
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +94 -28
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -894
- package/dist/tasty.js +101 -59
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/cache-wrapper.js +4 -9
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.js +3 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +3 -4
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -17
- package/dist/utils/process-tokens.js +19 -107
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +3 -82
- package/dist/utils/styles.js +29 -399
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +35 -13
- package/dist/utils/typography.js +16 -18
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +57 -84
- package/dist/zero/babel.js +217 -37
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +119 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +56 -30
- package/dist/zero/next.js +105 -40
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +394 -0
- package/docs/debug.md +320 -0
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +544 -0
- package/docs/methodology.md +616 -0
- package/docs/pipeline.md +519 -0
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +442 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +68 -36
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CacheMetrics, GlobalInjectResult, InjectResult, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, StyleInjectorConfig } from "./types.js";
|
|
1
|
+
import { CacheMetrics, CounterStyleDescriptors, FontFaceDescriptors, GCOptions, GlobalInjectResult, InjectResult, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, StyleInjectorConfig } from "./types.js";
|
|
2
2
|
import { StyleResult } from "../pipeline/index.js";
|
|
3
3
|
import { SheetManager } from "./sheet-manager.js";
|
|
4
4
|
|
|
@@ -6,11 +6,16 @@ import { SheetManager } from "./sheet-manager.js";
|
|
|
6
6
|
declare class StyleInjector {
|
|
7
7
|
private sheetManager;
|
|
8
8
|
private config;
|
|
9
|
-
private cleanupScheduled;
|
|
10
9
|
private globalRuleCounter;
|
|
10
|
+
private pendingGCHandle;
|
|
11
11
|
/** @internal — exposed for debug utilities only */
|
|
12
12
|
get _sheetManager(): SheetManager;
|
|
13
13
|
constructor(config?: StyleInjectorConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Check if `className` was hydrated from server-rendered styles and,
|
|
16
|
+
* if so, wire the cacheKey mapping. Returns true on hit.
|
|
17
|
+
*/
|
|
18
|
+
private tryHydratedHit;
|
|
14
19
|
/**
|
|
15
20
|
* Allocate a className for a cacheKey without injecting styles yet.
|
|
16
21
|
* This allows separating className allocation (render phase) from style injection (insertion phase).
|
|
@@ -51,7 +56,16 @@ declare class StyleInjector {
|
|
|
51
56
|
root?: Document | ShadowRoot;
|
|
52
57
|
}): string;
|
|
53
58
|
/**
|
|
54
|
-
*
|
|
59
|
+
* Increment refCount for an already-injected cacheKey and return a dispose.
|
|
60
|
+
* Used by useStyles on cache hits (hydration or runtime reuse) where
|
|
61
|
+
* the pipeline was skipped but refCount tracking is still needed.
|
|
62
|
+
* Returns null if the cacheKey is not found.
|
|
63
|
+
*/
|
|
64
|
+
trackRef(cacheKey: string, options?: {
|
|
65
|
+
root?: Document | ShadowRoot;
|
|
66
|
+
}): InjectResult | null;
|
|
67
|
+
/**
|
|
68
|
+
* Dispose of a className (decrements refCount only).
|
|
55
69
|
*/
|
|
56
70
|
private dispose;
|
|
57
71
|
/**
|
|
@@ -112,6 +126,24 @@ declare class StyleInjector {
|
|
|
112
126
|
isPropertyDefined(name: string, options?: {
|
|
113
127
|
root?: Document | ShadowRoot;
|
|
114
128
|
}): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Inject a CSS @font-face rule.
|
|
131
|
+
*
|
|
132
|
+
* Permanent and global — no dispose or ref-counting.
|
|
133
|
+
* Deduplicates by content hash (family + descriptors).
|
|
134
|
+
*/
|
|
135
|
+
fontFace(family: string, descriptors: FontFaceDescriptors, options?: {
|
|
136
|
+
root?: Document | ShadowRoot;
|
|
137
|
+
}): void;
|
|
138
|
+
/**
|
|
139
|
+
* Inject a CSS @counter-style rule.
|
|
140
|
+
*
|
|
141
|
+
* Permanent and global — no dispose or ref-counting.
|
|
142
|
+
* Deduplicates by name (first definition wins).
|
|
143
|
+
*/
|
|
144
|
+
counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
|
|
145
|
+
root?: Document | ShadowRoot;
|
|
146
|
+
}): void;
|
|
115
147
|
/**
|
|
116
148
|
* Inject keyframes and return object with toString() and dispose()
|
|
117
149
|
*
|
|
@@ -129,6 +161,33 @@ declare class StyleInjector {
|
|
|
129
161
|
* Dispose keyframes
|
|
130
162
|
*/
|
|
131
163
|
private disposeKeyframes;
|
|
164
|
+
private static readonly TASTY_CLASS_RE;
|
|
165
|
+
/**
|
|
166
|
+
* Record a render-time usage hit for one or more classNames.
|
|
167
|
+
* Handles space-separated multi-chunk classNames.
|
|
168
|
+
* When the global touch counter reaches `touchInterval`, schedules a GC
|
|
169
|
+
* via `requestIdleCallback`.
|
|
170
|
+
* No-op on the server.
|
|
171
|
+
*/
|
|
172
|
+
touch(className: string, options?: {
|
|
173
|
+
root?: Document | ShadowRoot;
|
|
174
|
+
}): void;
|
|
175
|
+
/**
|
|
176
|
+
* Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
|
|
177
|
+
* Runs GC on all active roots. Avoids double-scheduling via `pendingGCHandle`.
|
|
178
|
+
*/
|
|
179
|
+
private scheduleGC;
|
|
180
|
+
/**
|
|
181
|
+
* Synchronous garbage collection.
|
|
182
|
+
*
|
|
183
|
+
* 1. Quick upper-bound check: skip if unused count can't exceed capacity.
|
|
184
|
+
* 2. Scans the DOM for live tasty classNames (safety guard).
|
|
185
|
+
* 3. With `force: true`: deletes all unused entries inline.
|
|
186
|
+
* Without `force`: collects unused, sorts oldest-first, evicts over capacity.
|
|
187
|
+
*
|
|
188
|
+
* @returns Number of styles evicted.
|
|
189
|
+
*/
|
|
190
|
+
gc(options?: GCOptions): number;
|
|
132
191
|
/**
|
|
133
192
|
* Destroy all resources for a root
|
|
134
193
|
*/
|
|
@@ -1,20 +1,73 @@
|
|
|
1
|
+
import { getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
|
|
2
|
+
import { hashString } from "../utils/hash.js";
|
|
1
3
|
import { isDevEnv } from "../utils/is-dev-env.js";
|
|
2
4
|
import { parseStyle } from "../utils/styles.js";
|
|
3
|
-
import { colorInitialValueToRgb, getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
|
|
4
5
|
import { SheetManager } from "./sheet-manager.js";
|
|
5
|
-
|
|
6
|
+
import { fontFaceContentHash, formatFontFaceDeclarations } from "../font-face/index.js";
|
|
7
|
+
import { formatCounterStyleDeclarations } from "../counter-style/index.js";
|
|
6
8
|
//#region src/injector/injector.ts
|
|
7
9
|
/**
|
|
8
|
-
* Generate
|
|
10
|
+
* Generate a deterministic class name from a cache key using content hash.
|
|
11
|
+
* The same cache key always produces the same class name across environments.
|
|
9
12
|
*/
|
|
10
|
-
function generateClassName(
|
|
11
|
-
return `t${
|
|
13
|
+
function generateClassName(cacheKey) {
|
|
14
|
+
return `t${hashString(cacheKey)}`;
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
const RSC_CLASS_RE = /\.(t[a-z0-9]+)\.\1/g;
|
|
17
|
+
/**
|
|
18
|
+
* Extract class names from `<style data-tasty-rsc>` tags.
|
|
19
|
+
* The doubled-specificity pattern `.tXXX.tXXX` makes extraction reliable.
|
|
20
|
+
*/
|
|
21
|
+
function extractRSCClassNames() {
|
|
22
|
+
if (typeof document === "undefined") return [];
|
|
23
|
+
const styles = document.querySelectorAll("style[data-tasty-rsc]");
|
|
24
|
+
if (styles.length === 0) return [];
|
|
25
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
26
|
+
for (const style of styles) {
|
|
27
|
+
const text = style.textContent;
|
|
28
|
+
if (!text) continue;
|
|
29
|
+
let match;
|
|
30
|
+
RSC_CLASS_RE.lastIndex = 0;
|
|
31
|
+
while ((match = RSC_CLASS_RE.exec(text)) !== null) classSet.add(match[1]);
|
|
32
|
+
}
|
|
33
|
+
return Array.from(classSet);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Lazily sync server-rendered class names into the client registry.
|
|
37
|
+
*
|
|
38
|
+
* Sources:
|
|
39
|
+
* 1. `window.__TASTY__` — pushed by SSR/RSC streaming scripts
|
|
40
|
+
* 2. `<style data-tasty-rsc>` tags — inline CSS emitted by RSC components
|
|
41
|
+
*
|
|
42
|
+
* Called inside `inject()` / `allocateClassName()` to pick up
|
|
43
|
+
* class names rendered on the server (including during SPA navigation).
|
|
44
|
+
*/
|
|
45
|
+
function syncServerClasses(registry) {
|
|
46
|
+
if (typeof window === "undefined") return;
|
|
47
|
+
const classes = window.__TASTY__;
|
|
48
|
+
if (classes && classes.length > registry.serverClassSyncIndex) {
|
|
49
|
+
for (let i = registry.serverClassSyncIndex; i < classes.length; i++) registerHydratedClass(registry, classes[i]);
|
|
50
|
+
registry.serverClassSyncIndex = classes.length;
|
|
51
|
+
}
|
|
52
|
+
if (!registry.rscStylesScanned) {
|
|
53
|
+
registry.rscStylesScanned = true;
|
|
54
|
+
for (const cls of extractRSCClassNames()) registerHydratedClass(registry, cls);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function registerHydratedClass(registry, className) {
|
|
58
|
+
if (registry.rules.has(className)) return;
|
|
59
|
+
registry.rules.set(className, {
|
|
60
|
+
className,
|
|
61
|
+
ruleIndex: -2,
|
|
62
|
+
sheetIndex: -2
|
|
63
|
+
});
|
|
64
|
+
registry.refCounts.set(className, 0);
|
|
65
|
+
}
|
|
66
|
+
var StyleInjector = class StyleInjector {
|
|
14
67
|
sheetManager;
|
|
15
68
|
config;
|
|
16
|
-
cleanupScheduled = false;
|
|
17
69
|
globalRuleCounter = 0;
|
|
70
|
+
pendingGCHandle = null;
|
|
18
71
|
/** @internal — exposed for debug utilities only */
|
|
19
72
|
get _sheetManager() {
|
|
20
73
|
return this.sheetManager;
|
|
@@ -24,6 +77,19 @@ var StyleInjector = class {
|
|
|
24
77
|
this.sheetManager = new SheetManager(config);
|
|
25
78
|
}
|
|
26
79
|
/**
|
|
80
|
+
* Check if `className` was hydrated from server-rendered styles and,
|
|
81
|
+
* if so, wire the cacheKey mapping. Returns true on hit.
|
|
82
|
+
*/
|
|
83
|
+
tryHydratedHit(registry, cacheKey, className) {
|
|
84
|
+
syncServerClasses(registry);
|
|
85
|
+
const rule = registry.rules.get(className);
|
|
86
|
+
if (rule && rule.ruleIndex === -2 && rule.sheetIndex === -2) {
|
|
87
|
+
registry.cacheKeyToClassName.set(cacheKey, className);
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
27
93
|
* Allocate a className for a cacheKey without injecting styles yet.
|
|
28
94
|
* This allows separating className allocation (render phase) from style injection (insertion phase).
|
|
29
95
|
*/
|
|
@@ -34,7 +100,19 @@ var StyleInjector = class {
|
|
|
34
100
|
className: registry.cacheKeyToClassName.get(cacheKey),
|
|
35
101
|
isNewAllocation: false
|
|
36
102
|
};
|
|
37
|
-
const className = generateClassName(
|
|
103
|
+
const className = generateClassName(cacheKey);
|
|
104
|
+
if (this.tryHydratedHit(registry, cacheKey, className)) return {
|
|
105
|
+
className,
|
|
106
|
+
isNewAllocation: false
|
|
107
|
+
};
|
|
108
|
+
if (registry.rules.get(className)) {
|
|
109
|
+
if (isDevEnv()) console.warn(`[tasty] Hash collision: cache keys produce the same class "${className}". Styles may be incorrect.`);
|
|
110
|
+
registry.cacheKeyToClassName.set(cacheKey, className);
|
|
111
|
+
return {
|
|
112
|
+
className,
|
|
113
|
+
isNewAllocation: false
|
|
114
|
+
};
|
|
115
|
+
}
|
|
38
116
|
const placeholderRuleInfo = {
|
|
39
117
|
className,
|
|
40
118
|
ruleIndex: -1,
|
|
@@ -73,7 +151,17 @@ var StyleInjector = class {
|
|
|
73
151
|
dispose: () => this.dispose(className, registry)
|
|
74
152
|
};
|
|
75
153
|
}
|
|
76
|
-
} else
|
|
154
|
+
} else if (cacheKey) {
|
|
155
|
+
className = generateClassName(cacheKey);
|
|
156
|
+
if (this.tryHydratedHit(registry, cacheKey, className)) {
|
|
157
|
+
registry.refCounts.set(className, (registry.refCounts.get(className) || 0) + 1);
|
|
158
|
+
if (registry.metrics) registry.metrics.hits++;
|
|
159
|
+
return {
|
|
160
|
+
className,
|
|
161
|
+
dispose: () => this.dispose(className, registry)
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
} else className = `t${hashString(rules.map((r) => `${r.selector}\0${r.declarations}`).join("\n"))}`;
|
|
77
165
|
const rulesToInsert = rules.map((rule) => {
|
|
78
166
|
let newSelector = rule.selector;
|
|
79
167
|
if (rule.needsClassName) {
|
|
@@ -92,21 +180,19 @@ var StyleInjector = class {
|
|
|
92
180
|
rootPrefix: void 0
|
|
93
181
|
};
|
|
94
182
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
syntax: "<color>",
|
|
106
|
-
initialValue: "transparent",
|
|
183
|
+
if (this.config.autoPropertyTypes !== false) {
|
|
184
|
+
const resolver = registry.propertyTypeResolver;
|
|
185
|
+
const defined = registry.injectedProperties;
|
|
186
|
+
for (const rule of rulesToInsert) {
|
|
187
|
+
if (!rule.declarations) continue;
|
|
188
|
+
resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
|
|
189
|
+
this.property(name, {
|
|
190
|
+
syntax,
|
|
191
|
+
inherits: true,
|
|
192
|
+
initialValue,
|
|
107
193
|
root
|
|
108
194
|
});
|
|
109
|
-
}
|
|
195
|
+
});
|
|
110
196
|
}
|
|
111
197
|
}
|
|
112
198
|
const ruleInfo = this.sheetManager.insertRule(registry, rulesToInsert, className, root);
|
|
@@ -141,6 +227,21 @@ var StyleInjector = class {
|
|
|
141
227
|
const root = options?.root || document;
|
|
142
228
|
const registry = this.sheetManager.getRegistry(root);
|
|
143
229
|
if (!rules || rules.length === 0) return { dispose: () => {} };
|
|
230
|
+
if (this.config.autoPropertyTypes !== false) {
|
|
231
|
+
const resolver = registry.propertyTypeResolver;
|
|
232
|
+
const defined = registry.injectedProperties;
|
|
233
|
+
for (const rule of rules) {
|
|
234
|
+
if (!rule.declarations) continue;
|
|
235
|
+
resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
|
|
236
|
+
this.property(name, {
|
|
237
|
+
syntax,
|
|
238
|
+
inherits: true,
|
|
239
|
+
initialValue,
|
|
240
|
+
root
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
144
245
|
const key = `global:${this.globalRuleCounter++}`;
|
|
145
246
|
const info = this.sheetManager.insertGlobalRule(registry, rules, key, root);
|
|
146
247
|
if (registry.metrics) registry.metrics.totalInsertions++;
|
|
@@ -165,17 +266,33 @@ var StyleInjector = class {
|
|
|
165
266
|
return this.sheetManager.getRawCSSText(root);
|
|
166
267
|
}
|
|
167
268
|
/**
|
|
168
|
-
*
|
|
269
|
+
* Increment refCount for an already-injected cacheKey and return a dispose.
|
|
270
|
+
* Used by useStyles on cache hits (hydration or runtime reuse) where
|
|
271
|
+
* the pipeline was skipped but refCount tracking is still needed.
|
|
272
|
+
* Returns null if the cacheKey is not found.
|
|
273
|
+
*/
|
|
274
|
+
trackRef(cacheKey, options) {
|
|
275
|
+
const root = options?.root || document;
|
|
276
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
277
|
+
if (!registry.cacheKeyToClassName.has(cacheKey)) return null;
|
|
278
|
+
const className = registry.cacheKeyToClassName.get(cacheKey);
|
|
279
|
+
const currentRefCount = registry.refCounts.get(className) || 0;
|
|
280
|
+
registry.refCounts.set(className, currentRefCount + 1);
|
|
281
|
+
if (registry.metrics) registry.metrics.hits++;
|
|
282
|
+
return {
|
|
283
|
+
className,
|
|
284
|
+
dispose: () => this.dispose(className, registry)
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Dispose of a className (decrements refCount only).
|
|
169
289
|
*/
|
|
170
290
|
dispose(className, registry) {
|
|
171
291
|
const currentRefCount = registry.refCounts.get(className);
|
|
172
292
|
if (currentRefCount == null || currentRefCount <= 0) return;
|
|
173
293
|
const newRefCount = currentRefCount - 1;
|
|
174
294
|
registry.refCounts.set(className, newRefCount);
|
|
175
|
-
if (newRefCount === 0)
|
|
176
|
-
if (registry.metrics) registry.metrics.totalUnused++;
|
|
177
|
-
this.sheetManager.checkCleanupNeeded(registry);
|
|
178
|
-
}
|
|
295
|
+
if (newRefCount === 0 && registry.metrics) registry.metrics.totalUnused++;
|
|
179
296
|
}
|
|
180
297
|
/**
|
|
181
298
|
* Force bulk cleanup of unused styles
|
|
@@ -262,13 +379,7 @@ var StyleInjector = class {
|
|
|
262
379
|
const cssName = effectiveResult.cssName;
|
|
263
380
|
const definition = effectiveResult.definition;
|
|
264
381
|
const normalizedDef = normalizePropertyDefinition(definition);
|
|
265
|
-
|
|
266
|
-
if (existingDef !== void 0) {
|
|
267
|
-
if (existingDef !== normalizedDef) {
|
|
268
|
-
if (isDevEnv()) console.warn(`[Tasty] @property ${cssName} was already defined with a different declaration. The new declaration will be ignored. Original: ${existingDef}, New: ${normalizedDef}`);
|
|
269
|
-
}
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
382
|
+
if (registry.injectedProperties.get(cssName) !== void 0) return;
|
|
272
383
|
const parts = [];
|
|
273
384
|
if (definition.syntax != null) {
|
|
274
385
|
let syntax = String(definition.syntax).trim();
|
|
@@ -290,15 +401,6 @@ var StyleInjector = class {
|
|
|
290
401
|
};
|
|
291
402
|
if (!this.sheetManager.insertGlobalRule(registry, [rule], `property:${name}`, root)) return;
|
|
292
403
|
registry.injectedProperties.set(cssName, normalizedDef);
|
|
293
|
-
if (effectiveResult.isColor) {
|
|
294
|
-
const rgbCssName = `${cssName}-rgb`;
|
|
295
|
-
if (!this.isPropertyDefined(rgbCssName, { root })) this.property(rgbCssName, {
|
|
296
|
-
syntax: "<number>+",
|
|
297
|
-
inherits: definition.inherits,
|
|
298
|
-
initialValue: colorInitialValueToRgb(definition.initialValue),
|
|
299
|
-
root
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
404
|
}
|
|
303
405
|
/**
|
|
304
406
|
* Check whether a given @property name was already injected by this injector.
|
|
@@ -316,6 +418,39 @@ var StyleInjector = class {
|
|
|
316
418
|
return registry.injectedProperties.has(effectiveResult.cssName);
|
|
317
419
|
}
|
|
318
420
|
/**
|
|
421
|
+
* Inject a CSS @font-face rule.
|
|
422
|
+
*
|
|
423
|
+
* Permanent and global — no dispose or ref-counting.
|
|
424
|
+
* Deduplicates by content hash (family + descriptors).
|
|
425
|
+
*/
|
|
426
|
+
fontFace(family, descriptors, options) {
|
|
427
|
+
const root = options?.root || document;
|
|
428
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
429
|
+
const hash = fontFaceContentHash(family, descriptors);
|
|
430
|
+
if (registry.injectedFontFaces.has(hash)) return;
|
|
431
|
+
const rule = {
|
|
432
|
+
selector: "@font-face",
|
|
433
|
+
declarations: formatFontFaceDeclarations(family, descriptors)
|
|
434
|
+
};
|
|
435
|
+
if (this.sheetManager.insertGlobalRule(registry, [rule], `fontface:${hash}`, root)) registry.injectedFontFaces.add(hash);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Inject a CSS @counter-style rule.
|
|
439
|
+
*
|
|
440
|
+
* Permanent and global — no dispose or ref-counting.
|
|
441
|
+
* Deduplicates by name (first definition wins).
|
|
442
|
+
*/
|
|
443
|
+
counterStyle(name, descriptors, options) {
|
|
444
|
+
const root = options?.root || document;
|
|
445
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
446
|
+
if (registry.injectedCounterStyles.has(name)) return;
|
|
447
|
+
const rule = {
|
|
448
|
+
selector: `@counter-style ${name}`,
|
|
449
|
+
declarations: formatCounterStyleDeclarations(descriptors)
|
|
450
|
+
};
|
|
451
|
+
if (this.sheetManager.insertGlobalRule(registry, [rule], `counterstyle:${name}`, root)) registry.injectedCounterStyles.add(name);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
319
454
|
* Inject keyframes and return object with toString() and dispose()
|
|
320
455
|
*
|
|
321
456
|
* Keyframes are cached by content (steps). If the same content is injected
|
|
@@ -351,11 +486,20 @@ var StyleInjector = class {
|
|
|
351
486
|
registry.keyframesNameToContent.set(providedName, contentHash);
|
|
352
487
|
}
|
|
353
488
|
} else actualName = `k${registry.keyframesCounter++}`;
|
|
354
|
-
const
|
|
355
|
-
if (!
|
|
489
|
+
const result = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
|
|
490
|
+
if (!result) return {
|
|
356
491
|
toString: () => "",
|
|
357
492
|
dispose: () => {}
|
|
358
493
|
};
|
|
494
|
+
const { info, declarations } = result;
|
|
495
|
+
if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
|
|
496
|
+
this.property(name, {
|
|
497
|
+
syntax,
|
|
498
|
+
inherits: true,
|
|
499
|
+
initialValue,
|
|
500
|
+
root
|
|
501
|
+
});
|
|
502
|
+
});
|
|
359
503
|
registry.keyframesCache.set(contentHash, {
|
|
360
504
|
name: actualName,
|
|
361
505
|
refCount: 1,
|
|
@@ -390,15 +534,118 @@ var StyleInjector = class {
|
|
|
390
534
|
}
|
|
391
535
|
}
|
|
392
536
|
}
|
|
537
|
+
static TASTY_CLASS_RE = /^t[a-z0-9]+$/;
|
|
538
|
+
/**
|
|
539
|
+
* Record a render-time usage hit for one or more classNames.
|
|
540
|
+
* Handles space-separated multi-chunk classNames.
|
|
541
|
+
* When the global touch counter reaches `touchInterval`, schedules a GC
|
|
542
|
+
* via `requestIdleCallback`.
|
|
543
|
+
* No-op on the server.
|
|
544
|
+
*/
|
|
545
|
+
touch(className, options) {
|
|
546
|
+
if (typeof document === "undefined") return;
|
|
547
|
+
if (!this.config.gc) return;
|
|
548
|
+
const root = options?.root || document;
|
|
549
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
550
|
+
const now = Date.now();
|
|
551
|
+
const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
|
|
552
|
+
for (const cls of parts) {
|
|
553
|
+
if (!StyleInjector.TASTY_CLASS_RE.test(cls)) continue;
|
|
554
|
+
if (!registry.rules.has(cls)) continue;
|
|
555
|
+
const entry = registry.usageMap.get(cls);
|
|
556
|
+
if (entry) entry.lastTouchedAt = now;
|
|
557
|
+
else registry.usageMap.set(cls, { lastTouchedAt: now });
|
|
558
|
+
registry.touchCount++;
|
|
559
|
+
}
|
|
560
|
+
const touchInterval = this.config.gc.touchInterval ?? 1e3;
|
|
561
|
+
if (registry.touchCount >= touchInterval) {
|
|
562
|
+
registry.touchCount = 0;
|
|
563
|
+
this.scheduleGC();
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
|
|
568
|
+
* Runs GC on all active roots. Avoids double-scheduling via `pendingGCHandle`.
|
|
569
|
+
*/
|
|
570
|
+
scheduleGC() {
|
|
571
|
+
if (this.pendingGCHandle != null) return;
|
|
572
|
+
const runGC = () => {
|
|
573
|
+
this.pendingGCHandle = null;
|
|
574
|
+
this.sheetManager.pruneDisconnectedRoots();
|
|
575
|
+
for (const root of this.sheetManager.getActiveRoots()) this.gc({ root });
|
|
576
|
+
};
|
|
577
|
+
if (typeof requestIdleCallback !== "undefined") this.pendingGCHandle = requestIdleCallback(() => runGC());
|
|
578
|
+
else runGC();
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Synchronous garbage collection.
|
|
582
|
+
*
|
|
583
|
+
* 1. Quick upper-bound check: skip if unused count can't exceed capacity.
|
|
584
|
+
* 2. Scans the DOM for live tasty classNames (safety guard).
|
|
585
|
+
* 3. With `force: true`: deletes all unused entries inline.
|
|
586
|
+
* Without `force`: collects unused, sorts oldest-first, evicts over capacity.
|
|
587
|
+
*
|
|
588
|
+
* @returns Number of styles evicted.
|
|
589
|
+
*/
|
|
590
|
+
gc(options) {
|
|
591
|
+
if (typeof document === "undefined") return 0;
|
|
592
|
+
if (this.pendingGCHandle != null) {
|
|
593
|
+
if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
|
|
594
|
+
this.pendingGCHandle = null;
|
|
595
|
+
}
|
|
596
|
+
const root = options?.root || document;
|
|
597
|
+
const force = options?.force ?? false;
|
|
598
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
599
|
+
const capacity = this.config.gc?.capacity ?? 1e3;
|
|
600
|
+
if (!force) {
|
|
601
|
+
let activeCount = 0;
|
|
602
|
+
for (const refCount of registry.refCounts.values()) if (refCount > 0) activeCount++;
|
|
603
|
+
if (registry.usageMap.size - activeCount <= capacity) return 0;
|
|
604
|
+
}
|
|
605
|
+
const liveClasses = /* @__PURE__ */ new Set();
|
|
606
|
+
for (const el of root.querySelectorAll("[class]")) for (const token of el.classList) if (StyleInjector.TASTY_CLASS_RE.test(token)) liveClasses.add(token);
|
|
607
|
+
let swept = 0;
|
|
608
|
+
if (force) for (const [className] of registry.usageMap) {
|
|
609
|
+
if (liveClasses.has(className)) continue;
|
|
610
|
+
if ((registry.refCounts.get(className) ?? 0) > 0) continue;
|
|
611
|
+
registry.usageMap.delete(className);
|
|
612
|
+
swept++;
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
const unused = [];
|
|
616
|
+
for (const [className, usage] of registry.usageMap) {
|
|
617
|
+
if (liveClasses.has(className)) continue;
|
|
618
|
+
if ((registry.refCounts.get(className) ?? 0) > 0) continue;
|
|
619
|
+
unused.push({
|
|
620
|
+
className,
|
|
621
|
+
lastTouchedAt: usage.lastTouchedAt
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
if (unused.length > capacity) {
|
|
625
|
+
unused.sort((a, b) => a.lastTouchedAt - b.lastTouchedAt);
|
|
626
|
+
const toEvict = unused.length - capacity;
|
|
627
|
+
for (let i = 0; i < toEvict; i++) {
|
|
628
|
+
registry.usageMap.delete(unused[i].className);
|
|
629
|
+
swept++;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (swept > 0) this.sheetManager.forceCleanup(registry);
|
|
634
|
+
return swept;
|
|
635
|
+
}
|
|
393
636
|
/**
|
|
394
637
|
* Destroy all resources for a root
|
|
395
638
|
*/
|
|
396
639
|
destroy(root) {
|
|
397
640
|
const targetRoot = root || document;
|
|
398
641
|
this.sheetManager.cleanup(targetRoot);
|
|
642
|
+
if (this.pendingGCHandle != null && !this.sheetManager.hasActiveRoots()) {
|
|
643
|
+
if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
|
|
644
|
+
this.pendingGCHandle = null;
|
|
645
|
+
}
|
|
399
646
|
}
|
|
400
647
|
};
|
|
401
|
-
|
|
402
648
|
//#endregion
|
|
403
649
|
export { StyleInjector };
|
|
650
|
+
|
|
404
651
|
//# sourceMappingURL=injector.js.map
|