@tenphi/tasty 0.0.0-snapshot.ce10eff → 0.0.0-snapshot.cfcf770
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 +290 -207
- 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 +357 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +109 -30
- package/dist/config.js +144 -45
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +11 -10
- 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 +357 -637
- 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 +50 -0
- package/dist/hooks/useCounterStyle.js +45 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +43 -0
- package/dist/hooks/useFontFace.js +69 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +3 -0
- package/dist/hooks/useGlobalStyles.js +23 -2
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.js +13 -4
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.js +31 -14
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.js +8 -2
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +4 -4
- package/dist/hooks/useStyles.js +7 -147
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.js +14 -11
- package/dist/injector/index.d.ts +36 -11
- package/dist/injector/index.js +42 -11
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +60 -3
- package/dist/injector/injector.js +168 -29
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +10 -13
- package/dist/injector/sheet-manager.js +39 -70
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +101 -19
- 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 +1 -2
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +80 -32
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +381 -122
- 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 +1 -2
- 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 +9 -2
- package/dist/properties/index.js +24 -60
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.d.ts +0 -5
- package/dist/properties/property-type-resolver.js +19 -32
- package/dist/properties/property-type-resolver.js.map +1 -1
- package/dist/ssr/astro.d.ts +29 -0
- package/dist/ssr/astro.js +64 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +34 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +39 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +102 -0
- package/dist/ssr/collector.js +219 -0
- package/dist/ssr/collector.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 +22 -0
- package/dist/ssr/hydrate.js +49 -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 +43 -0
- package/dist/ssr/next.js +74 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +12 -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 +3 -4
- 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 +96 -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/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/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 -560
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +24 -13
- package/dist/utils/typography.js +15 -17
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +79 -10
- package/dist/zero/babel.js +190 -40
- 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 +54 -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/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +296 -0
- package/docs/comparison.md +420 -0
- package/docs/configuration.md +326 -0
- package/docs/debug.md +318 -0
- package/docs/design-system.md +424 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +542 -0
- package/docs/methodology.md +616 -0
- package/docs/runtime.md +572 -0
- package/docs/ssr.md +354 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +520 -0
- package/package.json +61 -35
- 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
package/dist/injector/index.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { CacheMetrics, DisposeFunction, GlobalInjectResult, InjectResult, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule } from "./types.js";
|
|
1
|
+
import { CacheMetrics, CounterStyleDescriptors, DisposeFunction, FontFaceDescriptors, FontFaceInput, GCConfig, GCOptions, GlobalInjectResult, InjectResult, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule, StyleUsage } from "./types.js";
|
|
2
2
|
import { StyleResult } from "../pipeline/index.js";
|
|
3
3
|
import { SheetManager } from "./sheet-manager.js";
|
|
4
4
|
import { StyleInjector } from "./injector.js";
|
|
5
5
|
|
|
6
6
|
//#region src/injector/index.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* Allocate a className for a cacheKey without injecting styles yet
|
|
9
|
-
*/
|
|
10
|
-
declare function allocateClassName(cacheKey: string, options?: {
|
|
11
|
-
root?: Document | ShadowRoot;
|
|
12
|
-
}): {
|
|
13
|
-
className: string;
|
|
14
|
-
isNewAllocation: boolean;
|
|
15
|
-
};
|
|
16
7
|
/**
|
|
17
8
|
* Inject styles and return className with dispose function
|
|
18
9
|
*/
|
|
@@ -117,6 +108,24 @@ declare function property(name: string, options?: PropertyOptions): void;
|
|
|
117
108
|
declare function isPropertyDefined(name: string, options?: {
|
|
118
109
|
root?: Document | ShadowRoot;
|
|
119
110
|
}): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Inject a CSS @font-face rule.
|
|
113
|
+
*
|
|
114
|
+
* Permanent and global — no dispose or ref-counting.
|
|
115
|
+
* Deduplicates by content hash (family + descriptors).
|
|
116
|
+
*/
|
|
117
|
+
declare function fontFace(family: string, descriptors: FontFaceDescriptors, options?: {
|
|
118
|
+
root?: Document | ShadowRoot;
|
|
119
|
+
}): void;
|
|
120
|
+
/**
|
|
121
|
+
* Inject a CSS @counter-style rule.
|
|
122
|
+
*
|
|
123
|
+
* Permanent and global — no dispose or ref-counting.
|
|
124
|
+
* Deduplicates by name (first definition wins).
|
|
125
|
+
*/
|
|
126
|
+
declare function counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
|
|
127
|
+
root?: Document | ShadowRoot;
|
|
128
|
+
}): void;
|
|
120
129
|
/**
|
|
121
130
|
* Get CSS text from all sheets (for SSR)
|
|
122
131
|
*/
|
|
@@ -134,6 +143,22 @@ declare function getCssTextForNode(node: ParentNode | Element | DocumentFragment
|
|
|
134
143
|
* Force cleanup of unused rules
|
|
135
144
|
*/
|
|
136
145
|
declare function cleanup(root?: Document | ShadowRoot): void;
|
|
146
|
+
/**
|
|
147
|
+
* Record a render-time usage hit for one or more classNames.
|
|
148
|
+
* Used internally by computeStyles and tasty() to track usage for GC.
|
|
149
|
+
* When the global touch counter reaches `touchInterval`, schedules GC.
|
|
150
|
+
*/
|
|
151
|
+
declare function touch(className: string, options?: {
|
|
152
|
+
root?: Document | ShadowRoot;
|
|
153
|
+
}): void;
|
|
154
|
+
/**
|
|
155
|
+
* Synchronous garbage collection of unused styles.
|
|
156
|
+
* Evicts the oldest unused styles when usageMap exceeds capacity.
|
|
157
|
+
* With `{ force: true }`, removes ALL unused styles regardless of capacity.
|
|
158
|
+
*
|
|
159
|
+
* @returns Number of styles evicted.
|
|
160
|
+
*/
|
|
161
|
+
declare function gc(options?: GCOptions): number;
|
|
137
162
|
/**
|
|
138
163
|
* Check if we're currently running in a test environment
|
|
139
164
|
*/
|
|
@@ -153,5 +178,5 @@ declare function destroy(root?: Document | ShadowRoot): void;
|
|
|
153
178
|
*/
|
|
154
179
|
declare function createInjector(config?: Partial<StyleInjectorConfig>): StyleInjector;
|
|
155
180
|
//#endregion
|
|
156
|
-
export { PropertyOptions,
|
|
181
|
+
export { PropertyOptions, cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
|
|
157
182
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/injector/index.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./sheet-manager.js";
|
|
2
2
|
import { StyleInjector } from "./injector.js";
|
|
3
3
|
import { getConfig, getGlobalInjector, isTestEnvironment, markStylesGenerated } from "../config.js";
|
|
4
|
-
|
|
5
4
|
//#region src/injector/index.ts
|
|
6
5
|
/**
|
|
7
|
-
* Allocate a className for a cacheKey without injecting styles yet
|
|
8
|
-
*/
|
|
9
|
-
function allocateClassName(cacheKey, options) {
|
|
10
|
-
return getGlobalInjector().allocateClassName(cacheKey, options);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
6
|
* Inject styles and return className with dispose function
|
|
14
7
|
*/
|
|
15
8
|
function inject(rules, options) {
|
|
9
|
+
const injector = getGlobalInjector();
|
|
16
10
|
markStylesGenerated();
|
|
17
|
-
return
|
|
11
|
+
return injector.inject(rules, options);
|
|
18
12
|
}
|
|
19
13
|
/**
|
|
20
14
|
* Inject global rules that should not reserve tasty class names
|
|
@@ -93,6 +87,24 @@ function isPropertyDefined(name, options) {
|
|
|
93
87
|
return getGlobalInjector().isPropertyDefined(name, options);
|
|
94
88
|
}
|
|
95
89
|
/**
|
|
90
|
+
* Inject a CSS @font-face rule.
|
|
91
|
+
*
|
|
92
|
+
* Permanent and global — no dispose or ref-counting.
|
|
93
|
+
* Deduplicates by content hash (family + descriptors).
|
|
94
|
+
*/
|
|
95
|
+
function fontFace(family, descriptors, options) {
|
|
96
|
+
return getGlobalInjector().fontFace(family, descriptors, options);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Inject a CSS @counter-style rule.
|
|
100
|
+
*
|
|
101
|
+
* Permanent and global — no dispose or ref-counting.
|
|
102
|
+
* Deduplicates by name (first definition wins).
|
|
103
|
+
*/
|
|
104
|
+
function counterStyle(name, descriptors, options) {
|
|
105
|
+
return getGlobalInjector().counterStyle(name, descriptors, options);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
96
108
|
* Get CSS text from all sheets (for SSR)
|
|
97
109
|
*/
|
|
98
110
|
function getCssText(options) {
|
|
@@ -121,6 +133,25 @@ function cleanup(root) {
|
|
|
121
133
|
return getGlobalInjector().cleanup(root);
|
|
122
134
|
}
|
|
123
135
|
/**
|
|
136
|
+
* Record a render-time usage hit for one or more classNames.
|
|
137
|
+
* Used internally by computeStyles and tasty() to track usage for GC.
|
|
138
|
+
* When the global touch counter reaches `touchInterval`, schedules GC.
|
|
139
|
+
*/
|
|
140
|
+
function touch(className, options) {
|
|
141
|
+
if (!getConfig().gc) return;
|
|
142
|
+
getGlobalInjector().touch(className, options);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Synchronous garbage collection of unused styles.
|
|
146
|
+
* Evicts the oldest unused styles when usageMap exceeds capacity.
|
|
147
|
+
* With `{ force: true }`, removes ALL unused styles regardless of capacity.
|
|
148
|
+
*
|
|
149
|
+
* @returns Number of styles evicted.
|
|
150
|
+
*/
|
|
151
|
+
function gc(options) {
|
|
152
|
+
return getGlobalInjector().gc(options);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
124
155
|
* Check if we're currently running in a test environment
|
|
125
156
|
*/
|
|
126
157
|
function getIsTestEnvironment() {
|
|
@@ -148,7 +179,7 @@ function createInjector(config = {}) {
|
|
|
148
179
|
...config
|
|
149
180
|
});
|
|
150
181
|
}
|
|
151
|
-
|
|
152
182
|
//#endregion
|
|
153
|
-
export {
|
|
183
|
+
export { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
|
|
184
|
+
|
|
154
185
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/injector/index.ts"],"sourcesContent":["import {\n getConfig,\n getGlobalInjector,\n isTestEnvironment,\n markStylesGenerated,\n} from '../config';\nimport type { StyleResult } from '../pipeline';\n\nimport { StyleInjector } from './injector';\nimport type {\n GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n StyleInjectorConfig,\n} from './types';\n\n/**\n * Allocate a className for a cacheKey without injecting styles yet\n */\nexport function allocateClassName(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): { className: string; isNewAllocation: boolean } {\n return getGlobalInjector().allocateClassName(cacheKey, options);\n}\n\n/**\n * Inject styles and return className with dispose function\n */\nexport function inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n): InjectResult {\n // Mark that styles have been generated (prevents configuration changes)\n markStylesGenerated();\n\n return getGlobalInjector().inject(rules, options);\n}\n\n/**\n * Inject global rules that should not reserve tasty class names\n */\nexport function injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n): GlobalInjectResult {\n return getGlobalInjector().injectGlobal(rules, options);\n}\n\n/**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.\n *\n * @example\n * ```tsx\n * // Inject raw CSS\n * const { dispose } = injectRawCSS(`\n * body { margin: 0; padding: 0; }\n * .my-class { color: red; }\n * `);\n *\n * // Later, remove the injected CSS\n * dispose();\n * ```\n */\nexport function injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n): { dispose: () => void } {\n return getGlobalInjector().injectRawCSS(css, options);\n}\n\n/**\n * Get raw CSS text for SSR\n */\nexport function getRawCSSText(options?: {\n root?: Document | ShadowRoot;\n}): string {\n return getGlobalInjector().getRawCSSText(options);\n}\n\n/**\n * Inject keyframes and return object with toString() and dispose()\n */\nexport function keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n): KeyframesResult {\n return getGlobalInjector().keyframes(steps, nameOrOptions);\n}\n\nexport interface PropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax\n */\n syntax?: string;\n /**\n * Whether the property inherits from parent elements\n * @default true\n */\n inherits?: boolean;\n /**\n * Initial value for the property\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Define a CSS @property custom property.\n * This enables advanced features like animating custom properties.\n *\n * Note: @property rules are global and persistent once defined.\n * Re-registering the same property name is a no-op.\n *\n * @param name - The custom property name (must start with --)\n * @param options - Property configuration\n *\n * @example\n * ```ts\n * // Define a color property that can be animated\n * property('--my-color', {\n * syntax: '<color>',\n * initialValue: 'red',\n * });\n *\n * // Define an angle property\n * property('--rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n * ```\n */\nexport function property(name: string, options?: PropertyOptions): void {\n return getGlobalInjector().property(name, options);\n}\n\n/**\n * Check if a CSS @property has already been defined\n *\n * @param name - The custom property name to check\n * @param options - Options including root\n */\nexport function isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n): boolean {\n return getGlobalInjector().isPropertyDefined(name, options);\n}\n\n/**\n * Get CSS text from all sheets (for SSR)\n */\nexport function getCssText(options?: { root?: Document | ShadowRoot }): string {\n return getGlobalInjector().getCssText(options);\n}\n\n/**\n * Collect only CSS used by a rendered subtree (like jest-styled-components).\n * Pass the container returned by render(...).\n */\nexport function getCssTextForNode(\n node: ParentNode | Element | DocumentFragment,\n options?: { root?: Document | ShadowRoot },\n): string {\n // Collect tasty-generated class names (t<number>) from the subtree\n const classSet = new Set<string>();\n\n const readClasses = (el: Element) => {\n const cls = el.getAttribute('class');\n if (!cls) return;\n for (const token of cls.split(/\\s+/)) {\n if (/^t\\d+$/.test(token)) classSet.add(token);\n }\n };\n\n // Include node itself if it's an Element\n if ((node as Element).getAttribute) {\n readClasses(node as Element);\n }\n // Walk descendants\n const elements = (node as ParentNode).querySelectorAll\n ? (node as ParentNode).querySelectorAll('[class]')\n : ([] as unknown as NodeListOf<Element>);\n if (elements) elements.forEach(readClasses);\n\n return getGlobalInjector().getCssTextForClasses(classSet, options);\n}\n\n/**\n * Force cleanup of unused rules\n */\nexport function cleanup(root?: Document | ShadowRoot): void {\n return getGlobalInjector().cleanup(root);\n}\n\n/**\n * Check if we're currently running in a test environment\n */\nexport function getIsTestEnvironment(): boolean {\n return isTestEnvironment();\n}\n\n/**\n * Get the global injector instance for debugging\n */\nexport const injector = {\n get instance() {\n return getGlobalInjector();\n },\n};\n\n/**\n * Destroy all resources and clean up\n */\nexport function destroy(root?: Document | ShadowRoot): void {\n return getGlobalInjector().destroy(root);\n}\n\n/**\n * Create a new isolated injector instance\n */\nexport function createInjector(\n config: Partial<StyleInjectorConfig> = {},\n): StyleInjector {\n const defaultConfig = getConfig();\n\n const fullConfig: StyleInjectorConfig = {\n ...defaultConfig,\n // Auto-enable forceTextInjection in test environments\n forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),\n ...config,\n };\n\n return new StyleInjector(fullConfig);\n}\n\n// Re-export types\nexport type {\n StyleInjectorConfig,\n InjectResult,\n DisposeFunction,\n RuleInfo,\n SheetInfo,\n RootRegistry,\n StyleRule,\n KeyframesInfo,\n KeyframesResult,\n KeyframesSteps,\n KeyframesCacheEntry,\n CacheMetrics,\n RawCSSResult,\n PropertyDefinition,\n} from './types';\n\nexport { StyleInjector } from './injector';\nexport { SheetManager } from './sheet-manager';\n"],"mappings":";;;;;;;;AAoBA,SAAgB,kBACd,UACA,SACiD;AACjD,QAAO,mBAAmB,CAAC,kBAAkB,UAAU,QAAQ;;;;;AAMjE,SAAgB,OACd,OACA,SACc;AAEd,sBAAqB;AAErB,QAAO,mBAAmB,CAAC,OAAO,OAAO,QAAQ;;;;;AAMnD,SAAgB,aACd,OACA,SACoB;AACpB,QAAO,mBAAmB,CAAC,aAAa,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;AAoBzD,SAAgB,aACd,KACA,SACyB;AACzB,QAAO,mBAAmB,CAAC,aAAa,KAAK,QAAQ;;;;;AAMvD,SAAgB,cAAc,SAEnB;AACT,QAAO,mBAAmB,CAAC,cAAc,QAAQ;;;;;AAMnD,SAAgB,UACd,OACA,eACiB;AACjB,QAAO,mBAAmB,CAAC,UAAU,OAAO,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkD5D,SAAgB,SAAS,MAAc,SAAiC;AACtE,QAAO,mBAAmB,CAAC,SAAS,MAAM,QAAQ;;;;;;;;AASpD,SAAgB,kBACd,MACA,SACS;AACT,QAAO,mBAAmB,CAAC,kBAAkB,MAAM,QAAQ;;;;;AAM7D,SAAgB,WAAW,SAAoD;AAC7E,QAAO,mBAAmB,CAAC,WAAW,QAAQ;;;;;;AAOhD,SAAgB,kBACd,MACA,SACQ;CAER,MAAM,2BAAW,IAAI,KAAa;CAElC,MAAM,eAAe,OAAgB;EACnC,MAAM,MAAM,GAAG,aAAa,QAAQ;AACpC,MAAI,CAAC,IAAK;AACV,OAAK,MAAM,SAAS,IAAI,MAAM,MAAM,CAClC,KAAI,SAAS,KAAK,MAAM,CAAE,UAAS,IAAI,MAAM;;AAKjD,KAAK,KAAiB,aACpB,aAAY,KAAgB;CAG9B,MAAM,WAAY,KAAoB,mBACjC,KAAoB,iBAAiB,UAAU,GAC/C,EAAE;AACP,KAAI,SAAU,UAAS,QAAQ,YAAY;AAE3C,QAAO,mBAAmB,CAAC,qBAAqB,UAAU,QAAQ;;;;;AAMpE,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;AAM1C,SAAgB,uBAAgC;AAC9C,QAAO,mBAAmB;;;;;AAM5B,MAAa,WAAW,EACtB,IAAI,WAAW;AACb,QAAO,mBAAmB;GAE7B;;;;AAKD,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;AAM1C,SAAgB,eACd,SAAuC,EAAE,EAC1B;AAUf,QAAO,IAAI,cAP6B;EACtC,GAHoB,WAAW;EAK/B,oBAAoB,OAAO,sBAAsB,mBAAmB;EACpE,GAAG;EACJ,CAEmC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/injector/index.ts"],"sourcesContent":["import {\n getConfig,\n getGlobalInjector,\n isTestEnvironment,\n markStylesGenerated,\n} from '../config';\nimport type { StyleResult } from '../pipeline';\n\nimport { StyleInjector } from './injector';\nimport type {\n CounterStyleDescriptors,\n FontFaceDescriptors,\n GCOptions,\n GlobalInjectResult,\n InjectResult,\n KeyframesResult,\n KeyframesSteps,\n StyleInjectorConfig,\n} from './types';\n\n/**\n * Inject styles and return className with dispose function\n */\nexport function inject(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot; cacheKey?: string },\n): InjectResult {\n const injector = getGlobalInjector();\n\n markStylesGenerated();\n\n return injector.inject(rules, options);\n}\n\n/**\n * Inject global rules that should not reserve tasty class names\n */\nexport function injectGlobal(\n rules: StyleResult[],\n options?: { root?: Document | ShadowRoot },\n): GlobalInjectResult {\n return getGlobalInjector().injectGlobal(rules, options);\n}\n\n/**\n * Inject raw CSS text directly without parsing\n * This is a low-overhead method for injecting raw CSS that doesn't need tasty processing.\n * The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking.\n *\n * @example\n * ```tsx\n * // Inject raw CSS\n * const { dispose } = injectRawCSS(`\n * body { margin: 0; padding: 0; }\n * .my-class { color: red; }\n * `);\n *\n * // Later, remove the injected CSS\n * dispose();\n * ```\n */\nexport function injectRawCSS(\n css: string,\n options?: { root?: Document | ShadowRoot },\n): { dispose: () => void } {\n return getGlobalInjector().injectRawCSS(css, options);\n}\n\n/**\n * Get raw CSS text for SSR\n */\nexport function getRawCSSText(options?: {\n root?: Document | ShadowRoot;\n}): string {\n return getGlobalInjector().getRawCSSText(options);\n}\n\n/**\n * Inject keyframes and return object with toString() and dispose()\n */\nexport function keyframes(\n steps: KeyframesSteps,\n nameOrOptions?: string | { root?: Document | ShadowRoot; name?: string },\n): KeyframesResult {\n return getGlobalInjector().keyframes(steps, nameOrOptions);\n}\n\nexport interface PropertyOptions {\n /**\n * CSS syntax string for the property (e.g., '<color>', '<length>', '<angle>')\n * @see https://developer.mozilla.org/en-US/docs/Web/CSS/@property/syntax\n */\n syntax?: string;\n /**\n * Whether the property inherits from parent elements\n * @default true\n */\n inherits?: boolean;\n /**\n * Initial value for the property\n */\n initialValue?: string | number;\n /**\n * Shadow root or document to inject into\n */\n root?: Document | ShadowRoot;\n}\n\n/**\n * Define a CSS @property custom property.\n * This enables advanced features like animating custom properties.\n *\n * Note: @property rules are global and persistent once defined.\n * Re-registering the same property name is a no-op.\n *\n * @param name - The custom property name (must start with --)\n * @param options - Property configuration\n *\n * @example\n * ```ts\n * // Define a color property that can be animated\n * property('--my-color', {\n * syntax: '<color>',\n * initialValue: 'red',\n * });\n *\n * // Define an angle property\n * property('--rotation', {\n * syntax: '<angle>',\n * inherits: false,\n * initialValue: '0deg',\n * });\n * ```\n */\nexport function property(name: string, options?: PropertyOptions): void {\n return getGlobalInjector().property(name, options);\n}\n\n/**\n * Check if a CSS @property has already been defined\n *\n * @param name - The custom property name to check\n * @param options - Options including root\n */\nexport function isPropertyDefined(\n name: string,\n options?: { root?: Document | ShadowRoot },\n): boolean {\n return getGlobalInjector().isPropertyDefined(name, options);\n}\n\n/**\n * Inject a CSS @font-face rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by content hash (family + descriptors).\n */\nexport function fontFace(\n family: string,\n descriptors: FontFaceDescriptors,\n options?: { root?: Document | ShadowRoot },\n): void {\n return getGlobalInjector().fontFace(family, descriptors, options);\n}\n\n/**\n * Inject a CSS @counter-style rule.\n *\n * Permanent and global — no dispose or ref-counting.\n * Deduplicates by name (first definition wins).\n */\nexport function counterStyle(\n name: string,\n descriptors: CounterStyleDescriptors,\n options?: { root?: Document | ShadowRoot },\n): void {\n return getGlobalInjector().counterStyle(name, descriptors, options);\n}\n\n/**\n * Get CSS text from all sheets (for SSR)\n */\nexport function getCssText(options?: { root?: Document | ShadowRoot }): string {\n return getGlobalInjector().getCssText(options);\n}\n\n/**\n * Collect only CSS used by a rendered subtree (like jest-styled-components).\n * Pass the container returned by render(...).\n */\nexport function getCssTextForNode(\n node: ParentNode | Element | DocumentFragment,\n options?: { root?: Document | ShadowRoot },\n): string {\n // Collect tasty-generated class names (t<number>) from the subtree\n const classSet = new Set<string>();\n\n const readClasses = (el: Element) => {\n const cls = el.getAttribute('class');\n if (!cls) return;\n for (const token of cls.split(/\\s+/)) {\n if (/^t\\d+$/.test(token)) classSet.add(token);\n }\n };\n\n // Include node itself if it's an Element\n if ((node as Element).getAttribute) {\n readClasses(node as Element);\n }\n // Walk descendants\n const elements = (node as ParentNode).querySelectorAll\n ? (node as ParentNode).querySelectorAll('[class]')\n : ([] as unknown as NodeListOf<Element>);\n if (elements) elements.forEach(readClasses);\n\n return getGlobalInjector().getCssTextForClasses(classSet, options);\n}\n\n/**\n * Force cleanup of unused rules\n */\nexport function cleanup(root?: Document | ShadowRoot): void {\n return getGlobalInjector().cleanup(root);\n}\n\n/**\n * Record a render-time usage hit for one or more classNames.\n * Used internally by computeStyles and tasty() to track usage for GC.\n * When the global touch counter reaches `touchInterval`, schedules GC.\n */\nexport function touch(\n className: string,\n options?: { root?: Document | ShadowRoot },\n): void {\n if (!getConfig().gc) return;\n getGlobalInjector().touch(className, options);\n}\n\n/**\n * Synchronous garbage collection of unused styles.\n * Evicts the oldest unused styles when usageMap exceeds capacity.\n * With `{ force: true }`, removes ALL unused styles regardless of capacity.\n *\n * @returns Number of styles evicted.\n */\nexport function gc(options?: GCOptions): number {\n return getGlobalInjector().gc(options);\n}\n\n/**\n * Check if we're currently running in a test environment\n */\nexport function getIsTestEnvironment(): boolean {\n return isTestEnvironment();\n}\n\n/**\n * Get the global injector instance for debugging\n */\nexport const injector = {\n get instance() {\n return getGlobalInjector();\n },\n};\n\n/**\n * Destroy all resources and clean up\n */\nexport function destroy(root?: Document | ShadowRoot): void {\n return getGlobalInjector().destroy(root);\n}\n\n/**\n * Create a new isolated injector instance\n */\nexport function createInjector(\n config: Partial<StyleInjectorConfig> = {},\n): StyleInjector {\n const defaultConfig = getConfig();\n\n const fullConfig: StyleInjectorConfig = {\n ...defaultConfig,\n // Auto-enable forceTextInjection in test environments\n forceTextInjection: config.forceTextInjection ?? isTestEnvironment(),\n ...config,\n };\n\n return new StyleInjector(fullConfig);\n}\n\n// Re-export types\nexport type {\n StyleInjectorConfig,\n InjectResult,\n DisposeFunction,\n RuleInfo,\n SheetInfo,\n RootRegistry,\n StyleRule,\n KeyframesInfo,\n KeyframesResult,\n KeyframesSteps,\n KeyframesCacheEntry,\n CacheMetrics,\n RawCSSResult,\n PropertyDefinition,\n FontFaceDescriptors,\n FontFaceInput,\n CounterStyleDescriptors,\n StyleUsage,\n GCConfig,\n GCOptions,\n} from './types';\n\nexport { StyleInjector } from './injector';\nexport { SheetManager } from './sheet-manager';\n"],"mappings":";;;;;;;AAuBA,SAAgB,OACd,OACA,SACc;CACd,MAAM,WAAW,mBAAmB;AAEpC,sBAAqB;AAErB,QAAO,SAAS,OAAO,OAAO,QAAQ;;;;;AAMxC,SAAgB,aACd,OACA,SACoB;AACpB,QAAO,mBAAmB,CAAC,aAAa,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;AAoBzD,SAAgB,aACd,KACA,SACyB;AACzB,QAAO,mBAAmB,CAAC,aAAa,KAAK,QAAQ;;;;;AAMvD,SAAgB,cAAc,SAEnB;AACT,QAAO,mBAAmB,CAAC,cAAc,QAAQ;;;;;AAMnD,SAAgB,UACd,OACA,eACiB;AACjB,QAAO,mBAAmB,CAAC,UAAU,OAAO,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkD5D,SAAgB,SAAS,MAAc,SAAiC;AACtE,QAAO,mBAAmB,CAAC,SAAS,MAAM,QAAQ;;;;;;;;AASpD,SAAgB,kBACd,MACA,SACS;AACT,QAAO,mBAAmB,CAAC,kBAAkB,MAAM,QAAQ;;;;;;;;AAS7D,SAAgB,SACd,QACA,aACA,SACM;AACN,QAAO,mBAAmB,CAAC,SAAS,QAAQ,aAAa,QAAQ;;;;;;;;AASnE,SAAgB,aACd,MACA,aACA,SACM;AACN,QAAO,mBAAmB,CAAC,aAAa,MAAM,aAAa,QAAQ;;;;;AAMrE,SAAgB,WAAW,SAAoD;AAC7E,QAAO,mBAAmB,CAAC,WAAW,QAAQ;;;;;;AAOhD,SAAgB,kBACd,MACA,SACQ;CAER,MAAM,2BAAW,IAAI,KAAa;CAElC,MAAM,eAAe,OAAgB;EACnC,MAAM,MAAM,GAAG,aAAa,QAAQ;AACpC,MAAI,CAAC,IAAK;AACV,OAAK,MAAM,SAAS,IAAI,MAAM,MAAM,CAClC,KAAI,SAAS,KAAK,MAAM,CAAE,UAAS,IAAI,MAAM;;AAKjD,KAAK,KAAiB,aACpB,aAAY,KAAgB;CAG9B,MAAM,WAAY,KAAoB,mBACjC,KAAoB,iBAAiB,UAAU,GAC/C,EAAE;AACP,KAAI,SAAU,UAAS,QAAQ,YAAY;AAE3C,QAAO,mBAAmB,CAAC,qBAAqB,UAAU,QAAQ;;;;;AAMpE,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;;;AAQ1C,SAAgB,MACd,WACA,SACM;AACN,KAAI,CAAC,WAAW,CAAC,GAAI;AACrB,oBAAmB,CAAC,MAAM,WAAW,QAAQ;;;;;;;;;AAU/C,SAAgB,GAAG,SAA6B;AAC9C,QAAO,mBAAmB,CAAC,GAAG,QAAQ;;;;;AAMxC,SAAgB,uBAAgC;AAC9C,QAAO,mBAAmB;;;;;AAM5B,MAAa,WAAW,EACtB,IAAI,WAAW;AACb,QAAO,mBAAmB;GAE7B;;;;AAKD,SAAgB,QAAQ,MAAoC;AAC1D,QAAO,mBAAmB,CAAC,QAAQ,KAAK;;;;;AAM1C,SAAgB,eACd,SAAuC,EAAE,EAC1B;AAUf,QAAO,IAAI,cAP6B;EACtC,GAHoB,WAAW;EAK/B,oBAAoB,OAAO,sBAAsB,mBAAmB;EACpE,GAAG;EACJ,CAEmC"}
|
|
@@ -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,8 +6,9 @@ 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 touchCount;
|
|
11
|
+
private pendingGCHandle;
|
|
11
12
|
/** @internal — exposed for debug utilities only */
|
|
12
13
|
get _sheetManager(): SheetManager;
|
|
13
14
|
constructor(config?: StyleInjectorConfig);
|
|
@@ -51,7 +52,16 @@ declare class StyleInjector {
|
|
|
51
52
|
root?: Document | ShadowRoot;
|
|
52
53
|
}): string;
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
+
* Increment refCount for an already-injected cacheKey and return a dispose.
|
|
56
|
+
* Used by useStyles on cache hits (hydration or runtime reuse) where
|
|
57
|
+
* the pipeline was skipped but refCount tracking is still needed.
|
|
58
|
+
* Returns null if the cacheKey is not found.
|
|
59
|
+
*/
|
|
60
|
+
trackRef(cacheKey: string, options?: {
|
|
61
|
+
root?: Document | ShadowRoot;
|
|
62
|
+
}): InjectResult | null;
|
|
63
|
+
/**
|
|
64
|
+
* Dispose of a className (decrements refCount only).
|
|
55
65
|
*/
|
|
56
66
|
private dispose;
|
|
57
67
|
/**
|
|
@@ -112,6 +122,24 @@ declare class StyleInjector {
|
|
|
112
122
|
isPropertyDefined(name: string, options?: {
|
|
113
123
|
root?: Document | ShadowRoot;
|
|
114
124
|
}): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Inject a CSS @font-face rule.
|
|
127
|
+
*
|
|
128
|
+
* Permanent and global — no dispose or ref-counting.
|
|
129
|
+
* Deduplicates by content hash (family + descriptors).
|
|
130
|
+
*/
|
|
131
|
+
fontFace(family: string, descriptors: FontFaceDescriptors, options?: {
|
|
132
|
+
root?: Document | ShadowRoot;
|
|
133
|
+
}): void;
|
|
134
|
+
/**
|
|
135
|
+
* Inject a CSS @counter-style rule.
|
|
136
|
+
*
|
|
137
|
+
* Permanent and global — no dispose or ref-counting.
|
|
138
|
+
* Deduplicates by name (first definition wins).
|
|
139
|
+
*/
|
|
140
|
+
counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
|
|
141
|
+
root?: Document | ShadowRoot;
|
|
142
|
+
}): void;
|
|
115
143
|
/**
|
|
116
144
|
* Inject keyframes and return object with toString() and dispose()
|
|
117
145
|
*
|
|
@@ -129,6 +157,35 @@ declare class StyleInjector {
|
|
|
129
157
|
* Dispose keyframes
|
|
130
158
|
*/
|
|
131
159
|
private disposeKeyframes;
|
|
160
|
+
private static readonly TASTY_CLASS_RE;
|
|
161
|
+
/**
|
|
162
|
+
* Record a render-time usage hit for one or more classNames.
|
|
163
|
+
* Handles space-separated multi-chunk classNames.
|
|
164
|
+
* When the global touch counter reaches `touchInterval`, schedules a GC
|
|
165
|
+
* via `requestIdleCallback`.
|
|
166
|
+
* No-op on the server.
|
|
167
|
+
*/
|
|
168
|
+
touch(className: string, options?: {
|
|
169
|
+
root?: Document | ShadowRoot;
|
|
170
|
+
}): void;
|
|
171
|
+
/**
|
|
172
|
+
* Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
|
|
173
|
+
* Avoids double-scheduling via `pendingGCHandle`.
|
|
174
|
+
*/
|
|
175
|
+
private scheduleGC;
|
|
176
|
+
/**
|
|
177
|
+
* Synchronous garbage collection.
|
|
178
|
+
*
|
|
179
|
+
* 1. Quick check: if non-active entries can't exceed capacity, skip entirely.
|
|
180
|
+
* 2. Scans the DOM for live tasty classNames (safety guard).
|
|
181
|
+
* 3. Collects unused entries (refCount === 0, not in DOM).
|
|
182
|
+
* 4. Checks if unused count exceeds capacity (skip if not, unless `force`).
|
|
183
|
+
* 5. Sorts unused by lastTouchedAt ascending, evicts oldest until at capacity.
|
|
184
|
+
* With `force: true`, evicts ALL unused regardless of capacity.
|
|
185
|
+
*
|
|
186
|
+
* @returns Number of styles evicted.
|
|
187
|
+
*/
|
|
188
|
+
gc(options?: GCOptions): number;
|
|
132
189
|
/**
|
|
133
190
|
* Destroy all resources for a root
|
|
134
191
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
|
|
1
2
|
import { isDevEnv } from "../utils/is-dev-env.js";
|
|
2
3
|
import { parseStyle } from "../utils/styles.js";
|
|
3
|
-
import { colorInitialValueToRgb, getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
|
|
4
4
|
import { SheetManager } from "./sheet-manager.js";
|
|
5
|
-
|
|
5
|
+
import { fontFaceContentHash, formatFontFaceDeclarations } from "../font-face/index.js";
|
|
6
|
+
import { formatCounterStyleDeclarations } from "../counter-style/index.js";
|
|
6
7
|
//#region src/injector/injector.ts
|
|
7
8
|
/**
|
|
8
9
|
* Generate sequential class name with format t{number}
|
|
@@ -10,11 +11,12 @@ import { SheetManager } from "./sheet-manager.js";
|
|
|
10
11
|
function generateClassName(counter) {
|
|
11
12
|
return `t${counter}`;
|
|
12
13
|
}
|
|
13
|
-
var StyleInjector = class {
|
|
14
|
+
var StyleInjector = class StyleInjector {
|
|
14
15
|
sheetManager;
|
|
15
16
|
config;
|
|
16
|
-
cleanupScheduled = false;
|
|
17
17
|
globalRuleCounter = 0;
|
|
18
|
+
touchCount = 0;
|
|
19
|
+
pendingGCHandle = null;
|
|
18
20
|
/** @internal — exposed for debug utilities only */
|
|
19
21
|
get _sheetManager() {
|
|
20
22
|
return this.sheetManager;
|
|
@@ -94,9 +96,10 @@ var StyleInjector = class {
|
|
|
94
96
|
});
|
|
95
97
|
if (this.config.autoPropertyTypes !== false) {
|
|
96
98
|
const resolver = registry.propertyTypeResolver;
|
|
99
|
+
const defined = registry.injectedProperties;
|
|
97
100
|
for (const rule of rulesToInsert) {
|
|
98
101
|
if (!rule.declarations) continue;
|
|
99
|
-
resolver.scanDeclarations(rule.declarations, (name) =>
|
|
102
|
+
resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
|
|
100
103
|
this.property(name, {
|
|
101
104
|
syntax,
|
|
102
105
|
inherits: true,
|
|
@@ -140,9 +143,10 @@ var StyleInjector = class {
|
|
|
140
143
|
if (!rules || rules.length === 0) return { dispose: () => {} };
|
|
141
144
|
if (this.config.autoPropertyTypes !== false) {
|
|
142
145
|
const resolver = registry.propertyTypeResolver;
|
|
146
|
+
const defined = registry.injectedProperties;
|
|
143
147
|
for (const rule of rules) {
|
|
144
148
|
if (!rule.declarations) continue;
|
|
145
|
-
resolver.scanDeclarations(rule.declarations, (name) =>
|
|
149
|
+
resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
|
|
146
150
|
this.property(name, {
|
|
147
151
|
syntax,
|
|
148
152
|
inherits: true,
|
|
@@ -176,17 +180,33 @@ var StyleInjector = class {
|
|
|
176
180
|
return this.sheetManager.getRawCSSText(root);
|
|
177
181
|
}
|
|
178
182
|
/**
|
|
179
|
-
*
|
|
183
|
+
* Increment refCount for an already-injected cacheKey and return a dispose.
|
|
184
|
+
* Used by useStyles on cache hits (hydration or runtime reuse) where
|
|
185
|
+
* the pipeline was skipped but refCount tracking is still needed.
|
|
186
|
+
* Returns null if the cacheKey is not found.
|
|
187
|
+
*/
|
|
188
|
+
trackRef(cacheKey, options) {
|
|
189
|
+
const root = options?.root || document;
|
|
190
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
191
|
+
if (!registry.cacheKeyToClassName.has(cacheKey)) return null;
|
|
192
|
+
const className = registry.cacheKeyToClassName.get(cacheKey);
|
|
193
|
+
const currentRefCount = registry.refCounts.get(className) || 0;
|
|
194
|
+
registry.refCounts.set(className, currentRefCount + 1);
|
|
195
|
+
if (registry.metrics) registry.metrics.hits++;
|
|
196
|
+
return {
|
|
197
|
+
className,
|
|
198
|
+
dispose: () => this.dispose(className, registry)
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Dispose of a className (decrements refCount only).
|
|
180
203
|
*/
|
|
181
204
|
dispose(className, registry) {
|
|
182
205
|
const currentRefCount = registry.refCounts.get(className);
|
|
183
206
|
if (currentRefCount == null || currentRefCount <= 0) return;
|
|
184
207
|
const newRefCount = currentRefCount - 1;
|
|
185
208
|
registry.refCounts.set(className, newRefCount);
|
|
186
|
-
if (newRefCount === 0)
|
|
187
|
-
if (registry.metrics) registry.metrics.totalUnused++;
|
|
188
|
-
this.sheetManager.checkCleanupNeeded(registry);
|
|
189
|
-
}
|
|
209
|
+
if (newRefCount === 0 && registry.metrics) registry.metrics.totalUnused++;
|
|
190
210
|
}
|
|
191
211
|
/**
|
|
192
212
|
* Force bulk cleanup of unused styles
|
|
@@ -273,13 +293,7 @@ var StyleInjector = class {
|
|
|
273
293
|
const cssName = effectiveResult.cssName;
|
|
274
294
|
const definition = effectiveResult.definition;
|
|
275
295
|
const normalizedDef = normalizePropertyDefinition(definition);
|
|
276
|
-
|
|
277
|
-
if (existingDef !== void 0) {
|
|
278
|
-
if (existingDef !== normalizedDef) {
|
|
279
|
-
if (isDevEnv()) console.warn(`[Tasty] @property ${cssName} was already defined with a different declaration. The new declaration will be ignored. Original: ${existingDef}, New: ${normalizedDef}`);
|
|
280
|
-
}
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
296
|
+
if (registry.injectedProperties.get(cssName) !== void 0) return;
|
|
283
297
|
const parts = [];
|
|
284
298
|
if (definition.syntax != null) {
|
|
285
299
|
let syntax = String(definition.syntax).trim();
|
|
@@ -301,15 +315,6 @@ var StyleInjector = class {
|
|
|
301
315
|
};
|
|
302
316
|
if (!this.sheetManager.insertGlobalRule(registry, [rule], `property:${name}`, root)) return;
|
|
303
317
|
registry.injectedProperties.set(cssName, normalizedDef);
|
|
304
|
-
if (effectiveResult.isColor) {
|
|
305
|
-
const rgbCssName = `${cssName}-rgb`;
|
|
306
|
-
if (!this.isPropertyDefined(rgbCssName, { root })) this.property(rgbCssName, {
|
|
307
|
-
syntax: "<number>+",
|
|
308
|
-
inherits: definition.inherits,
|
|
309
|
-
initialValue: colorInitialValueToRgb(definition.initialValue),
|
|
310
|
-
root
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
318
|
}
|
|
314
319
|
/**
|
|
315
320
|
* Check whether a given @property name was already injected by this injector.
|
|
@@ -327,6 +332,39 @@ var StyleInjector = class {
|
|
|
327
332
|
return registry.injectedProperties.has(effectiveResult.cssName);
|
|
328
333
|
}
|
|
329
334
|
/**
|
|
335
|
+
* Inject a CSS @font-face rule.
|
|
336
|
+
*
|
|
337
|
+
* Permanent and global — no dispose or ref-counting.
|
|
338
|
+
* Deduplicates by content hash (family + descriptors).
|
|
339
|
+
*/
|
|
340
|
+
fontFace(family, descriptors, options) {
|
|
341
|
+
const root = options?.root || document;
|
|
342
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
343
|
+
const hash = fontFaceContentHash(family, descriptors);
|
|
344
|
+
if (registry.injectedFontFaces.has(hash)) return;
|
|
345
|
+
const rule = {
|
|
346
|
+
selector: "@font-face",
|
|
347
|
+
declarations: formatFontFaceDeclarations(family, descriptors)
|
|
348
|
+
};
|
|
349
|
+
if (this.sheetManager.insertGlobalRule(registry, [rule], `fontface:${hash}`, root)) registry.injectedFontFaces.add(hash);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Inject a CSS @counter-style rule.
|
|
353
|
+
*
|
|
354
|
+
* Permanent and global — no dispose or ref-counting.
|
|
355
|
+
* Deduplicates by name (first definition wins).
|
|
356
|
+
*/
|
|
357
|
+
counterStyle(name, descriptors, options) {
|
|
358
|
+
const root = options?.root || document;
|
|
359
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
360
|
+
if (registry.injectedCounterStyles.has(name)) return;
|
|
361
|
+
const rule = {
|
|
362
|
+
selector: `@counter-style ${name}`,
|
|
363
|
+
declarations: formatCounterStyleDeclarations(descriptors)
|
|
364
|
+
};
|
|
365
|
+
if (this.sheetManager.insertGlobalRule(registry, [rule], `counterstyle:${name}`, root)) registry.injectedCounterStyles.add(name);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
330
368
|
* Inject keyframes and return object with toString() and dispose()
|
|
331
369
|
*
|
|
332
370
|
* Keyframes are cached by content (steps). If the same content is injected
|
|
@@ -368,7 +406,7 @@ var StyleInjector = class {
|
|
|
368
406
|
dispose: () => {}
|
|
369
407
|
};
|
|
370
408
|
const { info, declarations } = result;
|
|
371
|
-
if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) =>
|
|
409
|
+
if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
|
|
372
410
|
this.property(name, {
|
|
373
411
|
syntax,
|
|
374
412
|
inherits: true,
|
|
@@ -410,15 +448,116 @@ var StyleInjector = class {
|
|
|
410
448
|
}
|
|
411
449
|
}
|
|
412
450
|
}
|
|
451
|
+
static TASTY_CLASS_RE = /^t\d+$/;
|
|
452
|
+
/**
|
|
453
|
+
* Record a render-time usage hit for one or more classNames.
|
|
454
|
+
* Handles space-separated multi-chunk classNames.
|
|
455
|
+
* When the global touch counter reaches `touchInterval`, schedules a GC
|
|
456
|
+
* via `requestIdleCallback`.
|
|
457
|
+
* No-op on the server.
|
|
458
|
+
*/
|
|
459
|
+
touch(className, options) {
|
|
460
|
+
if (typeof document === "undefined") return;
|
|
461
|
+
if (!this.config.gc) return;
|
|
462
|
+
const root = options?.root || document;
|
|
463
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
464
|
+
const now = Date.now();
|
|
465
|
+
const parts = className.indexOf(" ") === -1 ? [className] : className.split(" ");
|
|
466
|
+
for (const cls of parts) {
|
|
467
|
+
if (!StyleInjector.TASTY_CLASS_RE.test(cls)) continue;
|
|
468
|
+
if (!registry.rules.has(cls)) continue;
|
|
469
|
+
const entry = registry.usageMap.get(cls);
|
|
470
|
+
if (entry) entry.lastTouchedAt = now;
|
|
471
|
+
else registry.usageMap.set(cls, { lastTouchedAt: now });
|
|
472
|
+
this.touchCount++;
|
|
473
|
+
}
|
|
474
|
+
const touchInterval = this.config.gc.touchInterval ?? 1e3;
|
|
475
|
+
if (this.touchCount >= touchInterval) {
|
|
476
|
+
this.touchCount = 0;
|
|
477
|
+
this.scheduleGC(root);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Schedule a GC via `requestIdleCallback` (or synchronously as fallback).
|
|
482
|
+
* Avoids double-scheduling via `pendingGCHandle`.
|
|
483
|
+
*/
|
|
484
|
+
scheduleGC(root) {
|
|
485
|
+
if (this.pendingGCHandle != null) return;
|
|
486
|
+
if (typeof requestIdleCallback !== "undefined") this.pendingGCHandle = requestIdleCallback(() => {
|
|
487
|
+
this.pendingGCHandle = null;
|
|
488
|
+
this.gc({ root });
|
|
489
|
+
});
|
|
490
|
+
else this.gc({ root });
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Synchronous garbage collection.
|
|
494
|
+
*
|
|
495
|
+
* 1. Quick check: if non-active entries can't exceed capacity, skip entirely.
|
|
496
|
+
* 2. Scans the DOM for live tasty classNames (safety guard).
|
|
497
|
+
* 3. Collects unused entries (refCount === 0, not in DOM).
|
|
498
|
+
* 4. Checks if unused count exceeds capacity (skip if not, unless `force`).
|
|
499
|
+
* 5. Sorts unused by lastTouchedAt ascending, evicts oldest until at capacity.
|
|
500
|
+
* With `force: true`, evicts ALL unused regardless of capacity.
|
|
501
|
+
*
|
|
502
|
+
* @returns Number of styles evicted.
|
|
503
|
+
*/
|
|
504
|
+
gc(options) {
|
|
505
|
+
if (typeof document === "undefined") return 0;
|
|
506
|
+
if (this.pendingGCHandle != null) {
|
|
507
|
+
if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
|
|
508
|
+
this.pendingGCHandle = null;
|
|
509
|
+
}
|
|
510
|
+
const root = options?.root || document;
|
|
511
|
+
const force = options?.force ?? false;
|
|
512
|
+
const registry = this.sheetManager.getRegistry(root);
|
|
513
|
+
const capacity = this.config.gc?.capacity ?? 1e3;
|
|
514
|
+
if (!force) {
|
|
515
|
+
let activeCount = 0;
|
|
516
|
+
for (const refCount of registry.refCounts.values()) if (refCount > 0) activeCount++;
|
|
517
|
+
if (registry.usageMap.size - activeCount <= capacity) return 0;
|
|
518
|
+
}
|
|
519
|
+
const liveClasses = /* @__PURE__ */ new Set();
|
|
520
|
+
for (const el of root.querySelectorAll("[class]")) for (const token of el.classList) if (StyleInjector.TASTY_CLASS_RE.test(token)) liveClasses.add(token);
|
|
521
|
+
const unused = [];
|
|
522
|
+
for (const [className, usage] of registry.usageMap) {
|
|
523
|
+
if (liveClasses.has(className)) continue;
|
|
524
|
+
if ((registry.refCounts.get(className) ?? 0) > 0) continue;
|
|
525
|
+
unused.push({
|
|
526
|
+
className,
|
|
527
|
+
lastTouchedAt: usage.lastTouchedAt
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
if (unused.length === 0) return 0;
|
|
531
|
+
if (!force && unused.length <= capacity) return 0;
|
|
532
|
+
let swept = 0;
|
|
533
|
+
if (force) for (const { className } of unused) {
|
|
534
|
+
registry.usageMap.delete(className);
|
|
535
|
+
swept++;
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
unused.sort((a, b) => a.lastTouchedAt - b.lastTouchedAt);
|
|
539
|
+
const toEvict = unused.length - capacity;
|
|
540
|
+
for (let i = 0; i < toEvict; i++) {
|
|
541
|
+
registry.usageMap.delete(unused[i].className);
|
|
542
|
+
swept++;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (swept > 0) this.sheetManager.forceCleanup(registry);
|
|
546
|
+
return swept;
|
|
547
|
+
}
|
|
413
548
|
/**
|
|
414
549
|
* Destroy all resources for a root
|
|
415
550
|
*/
|
|
416
551
|
destroy(root) {
|
|
417
552
|
const targetRoot = root || document;
|
|
418
553
|
this.sheetManager.cleanup(targetRoot);
|
|
554
|
+
if (this.pendingGCHandle != null && !this.sheetManager.hasActiveRoots()) {
|
|
555
|
+
if (typeof cancelIdleCallback !== "undefined") cancelIdleCallback(this.pendingGCHandle);
|
|
556
|
+
this.pendingGCHandle = null;
|
|
557
|
+
}
|
|
419
558
|
}
|
|
420
559
|
};
|
|
421
|
-
|
|
422
560
|
//#endregion
|
|
423
561
|
export { StyleInjector };
|
|
562
|
+
|
|
424
563
|
//# sourceMappingURL=injector.js.map
|