@tenphi/tasty 0.0.0-snapshot.ef8cc29 → 0.0.0-snapshot.efb24cc
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 +65 -215
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +1 -2
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +2 -3
- 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 +1 -2
- 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 +105 -21
- package/dist/config.js +175 -49
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +7 -7
- package/dist/core/index.js +8 -8
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.js +5 -6
- 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 +18 -2
- package/dist/hooks/useGlobalStyles.js +52 -47
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +43 -57
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +30 -48
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +13 -44
- package/dist/hooks/useRawCSS.js +91 -28
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +3 -8
- package/dist/hooks/useStyles.js +7 -225
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.js +11 -9
- package/dist/injector/index.d.ts +36 -19
- package/dist/injector/index.js +43 -20
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +53 -3
- package/dist/injector/injector.js +235 -14
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +9 -13
- package/dist/injector/sheet-manager.js +41 -71
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +112 -21
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +4 -5
- 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 +1 -2
- 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 +2 -0
- package/dist/pipeline/index.js +39 -12
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +57 -5
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.js +5 -6
- 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 +1 -2
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +12 -1
- package/dist/properties/index.js +2 -3
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +1 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- 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 +89 -10
- package/dist/ssr/astro.js +113 -29
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/async-storage.js +15 -6
- package/dist/ssr/async-storage.js.map +1 -1
- package/dist/ssr/collect-auto-properties.js +29 -11
- package/dist/ssr/collect-auto-properties.js.map +1 -1
- package/dist/ssr/collector.d.ts +26 -13
- package/dist/ssr/collector.js +84 -32
- package/dist/ssr/collector.js.map +1 -1
- package/dist/ssr/context.js +4 -2
- package/dist/ssr/context.js.map +1 -1
- package/dist/ssr/format-global-rules.js +1 -1
- package/dist/ssr/format-keyframes.js +1 -2
- package/dist/ssr/format-keyframes.js.map +1 -1
- package/dist/ssr/format-property.js +1 -2
- package/dist/ssr/format-property.js.map +1 -1
- package/dist/ssr/format-rules.js +8 -5
- package/dist/ssr/format-rules.js.map +1 -1
- package/dist/ssr/hydrate.d.ts +20 -13
- package/dist/ssr/hydrate.js +25 -30
- package/dist/ssr/hydrate.js.map +1 -1
- package/dist/ssr/index.d.ts +3 -4
- package/dist/ssr/index.js +5 -7
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +6 -5
- package/dist/ssr/next.js +14 -10
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr/ssr-collector-ref.js +20 -3
- package/dist/ssr/ssr-collector-ref.js.map +1 -1
- package/dist/states/index.js +3 -2
- 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 +2 -3
- 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 +4 -5
- 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 -4
- package/dist/styles/predefined.js +8 -9
- 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 +1 -1
- package/dist/styles/scrollbar.js +8 -5
- 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 +5 -4
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +52 -11
- 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 -893
- package/dist/tasty.js +96 -67
- package/dist/tasty.js.map +1 -1
- package/dist/utils/cache-wrapper.js +1 -2
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.js +1 -1
- package/dist/utils/color-math.js.map +1 -1
- package/dist/utils/color-space.js +1 -2
- package/dist/utils/color-space.js.map +1 -1
- package/dist/utils/colors.js +1 -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 +1 -1
- 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 +1 -2
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +1 -5
- package/dist/utils/process-tokens.js +3 -11
- 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 +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +1 -3
- package/dist/utils/styles.js +2 -5
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +21 -10
- package/dist/utils/typography.js +10 -2
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +27 -101
- package/dist/zero/babel.js +164 -48
- 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 +12 -0
- package/dist/zero/next.js +5 -4
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +2 -2
- package/docs/adoption.md +5 -3
- package/docs/comparison.md +24 -25
- package/docs/configuration.md +130 -1
- package/docs/design-system.md +47 -12
- package/docs/dsl.md +115 -9
- package/docs/getting-started.md +10 -10
- package/docs/injector.md +41 -25
- package/docs/methodology.md +119 -6
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +141 -81
- package/docs/styles.md +45 -23
- package/docs/tasty-static.md +103 -2
- package/package.json +20 -9
- package/dist/ssr/context.d.ts +0 -8
- 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/docs/runtime.md +0 -317
package/dist/index.js
CHANGED
|
@@ -10,25 +10,27 @@ import { StyleInjector } from "./injector/injector.js";
|
|
|
10
10
|
import { createStateParserContext, getGlobalPredefinedStates, setGlobalPredefinedStates } from "./states/index.js";
|
|
11
11
|
import { parseStateKey } from "./pipeline/parseStateKey.js";
|
|
12
12
|
import { isSelector, renderStyles } from "./pipeline/index.js";
|
|
13
|
-
import {
|
|
13
|
+
import { generateTypographyTokens } from "./utils/typography.js";
|
|
14
|
+
import { configure, getConfig, getGlobalCounterStyle, getGlobalFontFace, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig } from "./config.js";
|
|
14
15
|
import { CHUNK_NAMES, STYLE_TO_CHUNK, categorizeStyleKeys } from "./chunks/definitions.js";
|
|
15
16
|
import { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, COLOR_STYLES, CONTAINER_STYLES, DIMENSION_STYLES, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, TEXT_STYLES } from "./styles/list.js";
|
|
16
|
-
import {
|
|
17
|
+
import { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch } from "./injector/index.js";
|
|
18
|
+
import { mergeStyles } from "./utils/merge-styles.js";
|
|
19
|
+
import { resolveRecipes } from "./utils/resolve-recipes.js";
|
|
20
|
+
import { computeStyles } from "./compute-styles.js";
|
|
17
21
|
import { filterBaseProps } from "./utils/filter-base-props.js";
|
|
18
22
|
import { color } from "./utils/colors.js";
|
|
19
23
|
import { _modAttrs } from "./utils/mod-attrs.js";
|
|
20
24
|
import { dotize } from "./utils/dotize.js";
|
|
21
|
-
import {
|
|
22
|
-
import { resolveRecipes } from "./utils/resolve-recipes.js";
|
|
23
|
-
import { processTokens, stringifyTokens } from "./utils/process-tokens.js";
|
|
24
|
-
import { generateTypographyTokens } from "./utils/typography.js";
|
|
25
|
+
import { processTokens } from "./utils/process-tokens.js";
|
|
25
26
|
import { tastyDebug } from "./debug.js";
|
|
26
|
-
import { useStyles } from "./hooks/useStyles.js";
|
|
27
27
|
import { getDisplayName } from "./utils/get-display-name.js";
|
|
28
28
|
import { Element, tasty } from "./tasty.js";
|
|
29
|
+
import { useStyles } from "./hooks/useStyles.js";
|
|
29
30
|
import { useGlobalStyles } from "./hooks/useGlobalStyles.js";
|
|
30
31
|
import { useRawCSS } from "./hooks/useRawCSS.js";
|
|
31
32
|
import { useKeyframes } from "./hooks/useKeyframes.js";
|
|
32
33
|
import { useProperty } from "./hooks/useProperty.js";
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
import { useFontFace } from "./hooks/useFontFace.js";
|
|
35
|
+
import { useCounterStyle } from "./hooks/useCounterStyle.js";
|
|
36
|
+
export { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, Bucket, CHUNK_NAMES, COLOR_STYLES, CONTAINER_STYLES, CUSTOM_UNITS, DIMENSION_STYLES, DIRECTIONS, Element, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, categorizeStyleKeys, cleanup, color, computeStyles, configure, counterStyle, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, filterBaseProps, filterMods, fontFace, gc, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalCounterStyle, getGlobalFontFace, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getNamedColorHex, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleHandlers, tasty, tastyDebug, touch, useCounterStyle, useFontFace, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
|
package/dist/injector/index.d.ts
CHANGED
|
@@ -1,26 +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
|
-
/**
|
|
17
|
-
* Track a reference to an already-injected cacheKey (refCount + dispose).
|
|
18
|
-
* Used on cache hits (SSR hydration or runtime reuse) where the pipeline
|
|
19
|
-
* was skipped. Returns null if the cacheKey is not in the cache.
|
|
20
|
-
*/
|
|
21
|
-
declare function trackRef(cacheKey: string, options?: {
|
|
22
|
-
root?: Document | ShadowRoot;
|
|
23
|
-
}): InjectResult | null;
|
|
24
7
|
/**
|
|
25
8
|
* Inject styles and return className with dispose function
|
|
26
9
|
*/
|
|
@@ -125,6 +108,24 @@ declare function property(name: string, options?: PropertyOptions): void;
|
|
|
125
108
|
declare function isPropertyDefined(name: string, options?: {
|
|
126
109
|
root?: Document | ShadowRoot;
|
|
127
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;
|
|
128
129
|
/**
|
|
129
130
|
* Get CSS text from all sheets (for SSR)
|
|
130
131
|
*/
|
|
@@ -142,6 +143,22 @@ declare function getCssTextForNode(node: ParentNode | Element | DocumentFragment
|
|
|
142
143
|
* Force cleanup of unused rules
|
|
143
144
|
*/
|
|
144
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;
|
|
145
162
|
/**
|
|
146
163
|
* Check if we're currently running in a test environment
|
|
147
164
|
*/
|
|
@@ -161,5 +178,5 @@ declare function destroy(root?: Document | ShadowRoot): void;
|
|
|
161
178
|
*/
|
|
162
179
|
declare function createInjector(config?: Partial<StyleInjectorConfig>): StyleInjector;
|
|
163
180
|
//#endregion
|
|
164
|
-
export { PropertyOptions,
|
|
181
|
+
export { PropertyOptions, cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
|
|
165
182
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/injector/index.js
CHANGED
|
@@ -1,28 +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
|
-
* Track a reference to an already-injected cacheKey (refCount + dispose).
|
|
14
|
-
* Used on cache hits (SSR hydration or runtime reuse) where the pipeline
|
|
15
|
-
* was skipped. Returns null if the cacheKey is not in the cache.
|
|
16
|
-
*/
|
|
17
|
-
function trackRef(cacheKey, options) {
|
|
18
|
-
return getGlobalInjector().trackRef(cacheKey, options);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
6
|
* Inject styles and return className with dispose function
|
|
22
7
|
*/
|
|
23
8
|
function inject(rules, options) {
|
|
9
|
+
const injector = getGlobalInjector();
|
|
24
10
|
markStylesGenerated();
|
|
25
|
-
return
|
|
11
|
+
return injector.inject(rules, options);
|
|
26
12
|
}
|
|
27
13
|
/**
|
|
28
14
|
* Inject global rules that should not reserve tasty class names
|
|
@@ -101,6 +87,24 @@ function isPropertyDefined(name, options) {
|
|
|
101
87
|
return getGlobalInjector().isPropertyDefined(name, options);
|
|
102
88
|
}
|
|
103
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
|
+
/**
|
|
104
108
|
* Get CSS text from all sheets (for SSR)
|
|
105
109
|
*/
|
|
106
110
|
function getCssText(options) {
|
|
@@ -115,7 +119,7 @@ function getCssTextForNode(node, options) {
|
|
|
115
119
|
const readClasses = (el) => {
|
|
116
120
|
const cls = el.getAttribute("class");
|
|
117
121
|
if (!cls) return;
|
|
118
|
-
for (const token of cls.split(/\s+/)) if (/^t
|
|
122
|
+
for (const token of cls.split(/\s+/)) if (/^t[a-z0-9]+$/.test(token)) classSet.add(token);
|
|
119
123
|
};
|
|
120
124
|
if (node.getAttribute) readClasses(node);
|
|
121
125
|
const elements = node.querySelectorAll ? node.querySelectorAll("[class]") : [];
|
|
@@ -129,6 +133,25 @@ function cleanup(root) {
|
|
|
129
133
|
return getGlobalInjector().cleanup(root);
|
|
130
134
|
}
|
|
131
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
|
+
/**
|
|
132
155
|
* Check if we're currently running in a test environment
|
|
133
156
|
*/
|
|
134
157
|
function getIsTestEnvironment() {
|
|
@@ -156,7 +179,7 @@ function createInjector(config = {}) {
|
|
|
156
179
|
...config
|
|
157
180
|
});
|
|
158
181
|
}
|
|
159
|
-
|
|
160
182
|
//#endregion
|
|
161
|
-
export {
|
|
183
|
+
export { cleanup, counterStyle, createInjector, destroy, fontFace, gc, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, touch };
|
|
184
|
+
|
|
162
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 * Track a reference to an already-injected cacheKey (refCount + dispose).\n * Used on cache hits (SSR hydration or runtime reuse) where the pipeline\n * was skipped. Returns null if the cacheKey is not in the cache.\n */\nexport function trackRef(\n cacheKey: string,\n options?: { root?: Document | ShadowRoot },\n): InjectResult | null {\n return getGlobalInjector().trackRef(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;;;;;;;AAQjE,SAAgB,SACd,UACA,SACqB;AACrB,QAAO,mBAAmB,CAAC,SAAS,UAAU,QAAQ;;;;;AAMxD,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[a-z0-9]+$/.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,eAAe,KAAK,MAAM,CAAE,UAAS,IAAI,MAAM;;AAKvD,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,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).
|
|
@@ -60,7 +65,7 @@ declare class StyleInjector {
|
|
|
60
65
|
root?: Document | ShadowRoot;
|
|
61
66
|
}): InjectResult | null;
|
|
62
67
|
/**
|
|
63
|
-
* Dispose of a className
|
|
68
|
+
* Dispose of a className (decrements refCount only).
|
|
64
69
|
*/
|
|
65
70
|
private dispose;
|
|
66
71
|
/**
|
|
@@ -121,6 +126,24 @@ declare class StyleInjector {
|
|
|
121
126
|
isPropertyDefined(name: string, options?: {
|
|
122
127
|
root?: Document | ShadowRoot;
|
|
123
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;
|
|
124
147
|
/**
|
|
125
148
|
* Inject keyframes and return object with toString() and dispose()
|
|
126
149
|
*
|
|
@@ -138,6 +161,33 @@ declare class StyleInjector {
|
|
|
138
161
|
* Dispose keyframes
|
|
139
162
|
*/
|
|
140
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;
|
|
141
191
|
/**
|
|
142
192
|
* Destroy all resources for a root
|
|
143
193
|
*/
|