@tenphi/tasty 0.0.0-snapshot.d5c5a10 → 0.0.0-snapshot.d656d18
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 +197 -141
- package/dist/babel-_RVkw0iE.d.ts +83 -0
- package/dist/{ssr/async-storage.js → chunks/async-storage-DKK-wTD4.js} +17 -8
- package/dist/chunks/async-storage-DKK-wTD4.js.map +1 -0
- package/dist/chunks/collector-DBGcmUEq.js +326 -0
- package/dist/chunks/collector-DBGcmUEq.js.map +1 -0
- package/dist/chunks/css-resources-Cyl_axbI.js +149 -0
- package/dist/chunks/css-resources-Cyl_axbI.js.map +1 -0
- package/dist/{zero/extractor.js → chunks/css-writer-PFzrSPeu.js} +149 -26
- package/dist/chunks/css-writer-PFzrSPeu.js.map +1 -0
- package/dist/{debug.js → chunks/debug-BUwqo6vC.js} +193 -65
- package/dist/chunks/debug-BUwqo6vC.js.map +1 -0
- package/dist/chunks/dsl-CXvoaLnj.js +2097 -0
- package/dist/chunks/dsl-CXvoaLnj.js.map +1 -0
- package/dist/chunks/hydrate-6YoHZP6A.js +37 -0
- package/dist/chunks/hydrate-6YoHZP6A.js.map +1 -0
- package/dist/chunks/react-runtime-B3CmvDEQ.js +1525 -0
- package/dist/chunks/react-runtime-B3CmvDEQ.js.map +1 -0
- package/dist/chunks/runtime-engine-Y00VWjrS.js +4719 -0
- package/dist/chunks/runtime-engine-Y00VWjrS.js.map +1 -0
- package/dist/{utils/merge-styles.js → chunks/shared-utils-OIg0N_dp.js} +43 -6
- package/dist/chunks/shared-utils-OIg0N_dp.js.map +1 -0
- package/dist/chunks/style-engine-CqSmIlud.js +7196 -0
- package/dist/chunks/style-engine-CqSmIlud.js.map +1 -0
- package/dist/collector-CVdVIy7s.d.ts +163 -0
- package/dist/config-BI0y21JV.d.ts +1367 -0
- package/dist/core/index.d.ts +5 -34
- package/dist/core/index.js +7 -27
- package/dist/index-BzAC3p06.d.ts +1616 -0
- package/dist/index-CrT0bsiI.d.ts +1980 -0
- package/dist/index.d.ts +5 -51
- package/dist/index.js +8 -36
- package/dist/{utils/merge-styles.d.ts → merge-styles-BFktNP8J.d.ts} +3 -3
- 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-extract-static.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +18 -0
- package/dist/ssr/astro-middleware-static.js +18 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +19 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +117 -11
- package/dist/ssr/astro.js +268 -33
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/index.d.ts +37 -5
- package/dist/ssr/index.js +7 -9
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +66 -0
- package/dist/ssr/next-config.js +115 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +14 -7
- package/dist/ssr/next.js +39 -20
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -4
- package/dist/static/index.js.map +1 -0
- 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/zero/babel.d.ts +2 -167
- package/dist/zero/babel.js +160 -57
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +81 -3
- package/dist/zero/index.js +2 -4
- package/dist/zero/next.d.ts +13 -1
- package/dist/zero/next.js +6 -5
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +20 -12
- package/docs/adoption.md +59 -32
- package/docs/ai-agents.md +229 -0
- package/docs/comparison.md +76 -48
- package/docs/configuration.md +566 -69
- package/docs/debug.md +37 -23
- package/docs/design-system.md +63 -32
- package/docs/dsl.md +527 -180
- package/docs/getting-started.md +62 -41
- package/docs/injector.md +157 -51
- package/docs/methodology.md +116 -35
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +741 -0
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +681 -0
- package/docs/runtime-benchmarks.md +351 -0
- package/docs/ssr.md +356 -130
- package/docs/styles.md +127 -26
- package/docs/tasty-static.md +219 -70
- package/package.json +108 -23
- package/tasty.config.ts +6 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -78
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -259
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/renderChunk.js +0 -60
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -366
- package/dist/config.js +0 -504
- package/dist/config.js.map +0 -1
- package/dist/counter-style/index.js +0 -51
- package/dist/counter-style/index.js.map +0 -1
- package/dist/debug.d.ts +0 -89
- package/dist/debug.js.map +0 -1
- package/dist/font-face/index.js +0 -63
- package/dist/font-face/index.js.map +0 -1
- package/dist/hooks/resolve-ssr-collector.js +0 -15
- package/dist/hooks/resolve-ssr-collector.js.map +0 -1
- package/dist/hooks/useCounterStyle.d.ts +0 -50
- package/dist/hooks/useCounterStyle.js +0 -47
- package/dist/hooks/useCounterStyle.js.map +0 -1
- package/dist/hooks/useFontFace.d.ts +0 -43
- package/dist/hooks/useFontFace.js +0 -71
- package/dist/hooks/useFontFace.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -30
- package/dist/hooks/useGlobalStyles.js +0 -79
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -65
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -110
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -36
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -45
- package/dist/hooks/useStyles.js +0 -270
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -183
- package/dist/injector/index.js +0 -180
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -166
- package/dist/injector/injector.js +0 -465
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -136
- package/dist/injector/sheet-manager.js +0 -731
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -204
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -320
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -33
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -116
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -406
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -231
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -53
- package/dist/pipeline/index.js +0 -699
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1105
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -447
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -516
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/pipeline/warnings.js +0 -18
- package/dist/pipeline/warnings.js.map +0 -1
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -98
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -76
- package/dist/properties/index.js +0 -223
- package/dist/properties/index.js.map +0 -1
- package/dist/properties/property-type-resolver.d.ts +0 -24
- package/dist/properties/property-type-resolver.js +0 -91
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -40
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.d.ts +0 -102
- package/dist/ssr/collector.js +0 -227
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -14
- package/dist/ssr/context.js.map +0 -1
- package/dist/ssr/format-global-rules.js +0 -22
- package/dist/ssr/format-global-rules.js.map +0 -1
- package/dist/ssr/format-keyframes.js +0 -70
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -50
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js +0 -70
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -22
- package/dist/ssr/hydrate.js +0 -50
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -12
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -171
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -31
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.js.map +0 -1
- 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/border.d.ts +0 -25
- package/dist/styles/border.js +0 -114
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -27
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -80
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -97
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -67
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -58
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- package/dist/styles/fill.js +0 -52
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -37
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -20
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -2
- package/dist/styles/index.js +0 -9
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -52
- package/dist/styles/inset.js +0 -150
- package/dist/styles/inset.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/list.d.ts +0 -16
- package/dist/styles/list.js +0 -98
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -104
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -65
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -104
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -238
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -47
- package/dist/styles/preset.js +0 -112
- package/dist/styles/preset.js.map +0 -1
- package/dist/styles/radius.d.ts +0 -14
- package/dist/styles/radius.js +0 -51
- package/dist/styles/radius.js.map +0 -1
- package/dist/styles/scrollbar.d.ts +0 -25
- package/dist/styles/scrollbar.js +0 -48
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -24
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -158
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -545
- package/dist/styles/width.d.ts +0 -17
- package/dist/styles/width.js +0 -20
- package/dist/styles/width.js.map +0 -1
- package/dist/tasty.d.ts +0 -119
- package/dist/tasty.js +0 -232
- package/dist/tasty.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -22
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/color-math.d.ts +0 -46
- package/dist/utils/color-math.js +0 -749
- package/dist/utils/color-math.js.map +0 -1
- package/dist/utils/color-space.d.ts +0 -5
- package/dist/utils/color-space.js +0 -229
- package/dist/utils/color-space.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -11
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.js.map +0 -1
- package/dist/utils/has-keys.js +0 -13
- package/dist/utils/has-keys.js.map +0 -1
- package/dist/utils/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -8
- package/dist/utils/mod-attrs.js +0 -21
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -21
- package/dist/utils/process-tokens.js +0 -91
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js +0 -147
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/selector-transform.js +0 -32
- package/dist/utils/selector-transform.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -100
- package/dist/utils/styles.js +0 -222
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -47
- package/dist/utils/typography.js +0 -43
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -74
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js.map +0 -1
- package/docs/PIPELINE.md +0 -519
- package/docs/runtime.md +0 -485
|
@@ -1 +0,0 @@
|
|
|
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 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 * 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 * 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} from './types';\n\nexport { StyleInjector } from './injector';\nexport { SheetManager } from './sheet-manager';\n"],"mappings":";;;;;;;;AAsBA,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;;;;;;;;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;;;;;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,166 +0,0 @@
|
|
|
1
|
-
import { CacheMetrics, CounterStyleDescriptors, FontFaceDescriptors, GlobalInjectResult, InjectResult, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, StyleInjectorConfig } from "./types.js";
|
|
2
|
-
import { StyleResult } from "../pipeline/index.js";
|
|
3
|
-
import { SheetManager } from "./sheet-manager.js";
|
|
4
|
-
|
|
5
|
-
//#region src/injector/injector.d.ts
|
|
6
|
-
declare class StyleInjector {
|
|
7
|
-
private sheetManager;
|
|
8
|
-
private config;
|
|
9
|
-
private cleanupScheduled;
|
|
10
|
-
private globalRuleCounter;
|
|
11
|
-
/** @internal — exposed for debug utilities only */
|
|
12
|
-
get _sheetManager(): SheetManager;
|
|
13
|
-
constructor(config?: StyleInjectorConfig);
|
|
14
|
-
/**
|
|
15
|
-
* Allocate a className for a cacheKey without injecting styles yet.
|
|
16
|
-
* This allows separating className allocation (render phase) from style injection (insertion phase).
|
|
17
|
-
*/
|
|
18
|
-
allocateClassName(cacheKey: string, options?: {
|
|
19
|
-
root?: Document | ShadowRoot;
|
|
20
|
-
}): {
|
|
21
|
-
className: string;
|
|
22
|
-
isNewAllocation: boolean;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Inject styles from StyleResult objects
|
|
26
|
-
*/
|
|
27
|
-
inject(rules: StyleResult[], options?: {
|
|
28
|
-
root?: Document | ShadowRoot;
|
|
29
|
-
cacheKey?: string;
|
|
30
|
-
}): InjectResult;
|
|
31
|
-
/**
|
|
32
|
-
* Inject global styles (rules without a generated tasty class selector)
|
|
33
|
-
* This ensures we don't reserve a tasty class name (t{number}) for global rules,
|
|
34
|
-
* which could otherwise collide with element-level styles and break lookups.
|
|
35
|
-
*/
|
|
36
|
-
injectGlobal(rules: StyleResult[], options?: {
|
|
37
|
-
root?: Document | ShadowRoot;
|
|
38
|
-
}): GlobalInjectResult;
|
|
39
|
-
/**
|
|
40
|
-
* Inject raw CSS text directly without parsing
|
|
41
|
-
* This is a low-overhead alternative to createGlobalStyle for raw CSS
|
|
42
|
-
* The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
|
|
43
|
-
*/
|
|
44
|
-
injectRawCSS(css: string, options?: {
|
|
45
|
-
root?: Document | ShadowRoot;
|
|
46
|
-
}): RawCSSResult;
|
|
47
|
-
/**
|
|
48
|
-
* Get raw CSS text for SSR
|
|
49
|
-
*/
|
|
50
|
-
getRawCSSText(options?: {
|
|
51
|
-
root?: Document | ShadowRoot;
|
|
52
|
-
}): string;
|
|
53
|
-
/**
|
|
54
|
-
* Increment refCount for an already-injected cacheKey and return a dispose.
|
|
55
|
-
* Used by useStyles on cache hits (hydration or runtime reuse) where
|
|
56
|
-
* the pipeline was skipped but refCount tracking is still needed.
|
|
57
|
-
* Returns null if the cacheKey is not found.
|
|
58
|
-
*/
|
|
59
|
-
trackRef(cacheKey: string, options?: {
|
|
60
|
-
root?: Document | ShadowRoot;
|
|
61
|
-
}): InjectResult | null;
|
|
62
|
-
/**
|
|
63
|
-
* Dispose of a className
|
|
64
|
-
*/
|
|
65
|
-
private dispose;
|
|
66
|
-
/**
|
|
67
|
-
* Force bulk cleanup of unused styles
|
|
68
|
-
*/
|
|
69
|
-
cleanup(root?: Document | ShadowRoot): void;
|
|
70
|
-
/**
|
|
71
|
-
* Get CSS text from all sheets (for SSR)
|
|
72
|
-
*/
|
|
73
|
-
getCssText(options?: {
|
|
74
|
-
root?: Document | ShadowRoot;
|
|
75
|
-
}): string;
|
|
76
|
-
/**
|
|
77
|
-
* Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
|
|
78
|
-
*/
|
|
79
|
-
getCssTextForClasses(classNames: Iterable<string>, options?: {
|
|
80
|
-
root?: Document | ShadowRoot;
|
|
81
|
-
}): string;
|
|
82
|
-
/**
|
|
83
|
-
* Get cache performance metrics
|
|
84
|
-
*/
|
|
85
|
-
getMetrics(options?: {
|
|
86
|
-
root?: Document | ShadowRoot;
|
|
87
|
-
}): CacheMetrics | null;
|
|
88
|
-
/**
|
|
89
|
-
* Reset cache performance metrics
|
|
90
|
-
*/
|
|
91
|
-
resetMetrics(options?: {
|
|
92
|
-
root?: Document | ShadowRoot;
|
|
93
|
-
}): void;
|
|
94
|
-
/**
|
|
95
|
-
* Define a CSS @property custom property.
|
|
96
|
-
*
|
|
97
|
-
* Accepts tasty token syntax for the property name:
|
|
98
|
-
* - `$name` → defines `--name`
|
|
99
|
-
* - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
|
|
100
|
-
* - `--name` → defines `--name` (legacy format)
|
|
101
|
-
*
|
|
102
|
-
* Example:
|
|
103
|
-
* @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
|
|
104
|
-
*
|
|
105
|
-
* Note: No caching or dispose — this defines a global property.
|
|
106
|
-
*
|
|
107
|
-
* If the same property is registered with different options, a warning is emitted
|
|
108
|
-
* but the original definition is preserved (CSS @property cannot be redefined).
|
|
109
|
-
*/
|
|
110
|
-
property(name: string, options?: PropertyDefinition & {
|
|
111
|
-
root?: Document | ShadowRoot;
|
|
112
|
-
}): void;
|
|
113
|
-
/**
|
|
114
|
-
* Check whether a given @property name was already injected by this injector.
|
|
115
|
-
*
|
|
116
|
-
* Accepts tasty token syntax:
|
|
117
|
-
* - `$name` → checks `--name`
|
|
118
|
-
* - `#name` → checks `--name-color`
|
|
119
|
-
* - `--name` → checks `--name` (legacy format)
|
|
120
|
-
*/
|
|
121
|
-
isPropertyDefined(name: string, options?: {
|
|
122
|
-
root?: Document | ShadowRoot;
|
|
123
|
-
}): boolean;
|
|
124
|
-
/**
|
|
125
|
-
* Inject a CSS @font-face rule.
|
|
126
|
-
*
|
|
127
|
-
* Permanent and global — no dispose or ref-counting.
|
|
128
|
-
* Deduplicates by content hash (family + descriptors).
|
|
129
|
-
*/
|
|
130
|
-
fontFace(family: string, descriptors: FontFaceDescriptors, options?: {
|
|
131
|
-
root?: Document | ShadowRoot;
|
|
132
|
-
}): void;
|
|
133
|
-
/**
|
|
134
|
-
* Inject a CSS @counter-style rule.
|
|
135
|
-
*
|
|
136
|
-
* Permanent and global — no dispose or ref-counting.
|
|
137
|
-
* Deduplicates by name (first definition wins).
|
|
138
|
-
*/
|
|
139
|
-
counterStyle(name: string, descriptors: CounterStyleDescriptors, options?: {
|
|
140
|
-
root?: Document | ShadowRoot;
|
|
141
|
-
}): void;
|
|
142
|
-
/**
|
|
143
|
-
* Inject keyframes and return object with toString() and dispose()
|
|
144
|
-
*
|
|
145
|
-
* Keyframes are cached by content (steps). If the same content is injected
|
|
146
|
-
* multiple times with different provided names, the first injected name is reused.
|
|
147
|
-
*
|
|
148
|
-
* If the same name is provided with different content (collision), a unique
|
|
149
|
-
* name is generated to avoid overwriting the existing keyframes.
|
|
150
|
-
*/
|
|
151
|
-
keyframes(steps: KeyframesSteps, nameOrOptions?: string | {
|
|
152
|
-
root?: Document | ShadowRoot;
|
|
153
|
-
name?: string;
|
|
154
|
-
}): KeyframesResult;
|
|
155
|
-
/**
|
|
156
|
-
* Dispose keyframes
|
|
157
|
-
*/
|
|
158
|
-
private disposeKeyframes;
|
|
159
|
-
/**
|
|
160
|
-
* Destroy all resources for a root
|
|
161
|
-
*/
|
|
162
|
-
destroy(root?: Document | ShadowRoot): void;
|
|
163
|
-
}
|
|
164
|
-
//#endregion
|
|
165
|
-
export { StyleInjector };
|
|
166
|
-
//# sourceMappingURL=injector.d.ts.map
|
|
@@ -1,465 +0,0 @@
|
|
|
1
|
-
import { getEffectiveDefinition, normalizePropertyDefinition } from "../properties/index.js";
|
|
2
|
-
import { isDevEnv } from "../utils/is-dev-env.js";
|
|
3
|
-
import { parseStyle } from "../utils/styles.js";
|
|
4
|
-
import { SheetManager } from "./sheet-manager.js";
|
|
5
|
-
import { fontFaceContentHash, formatFontFaceDeclarations } from "../font-face/index.js";
|
|
6
|
-
import { formatCounterStyleDeclarations } from "../counter-style/index.js";
|
|
7
|
-
|
|
8
|
-
//#region src/injector/injector.ts
|
|
9
|
-
/**
|
|
10
|
-
* Generate sequential class name with format t{number}
|
|
11
|
-
*/
|
|
12
|
-
function generateClassName(counter) {
|
|
13
|
-
return `t${counter}`;
|
|
14
|
-
}
|
|
15
|
-
var StyleInjector = class {
|
|
16
|
-
sheetManager;
|
|
17
|
-
config;
|
|
18
|
-
cleanupScheduled = false;
|
|
19
|
-
globalRuleCounter = 0;
|
|
20
|
-
/** @internal — exposed for debug utilities only */
|
|
21
|
-
get _sheetManager() {
|
|
22
|
-
return this.sheetManager;
|
|
23
|
-
}
|
|
24
|
-
constructor(config = {}) {
|
|
25
|
-
this.config = config;
|
|
26
|
-
this.sheetManager = new SheetManager(config);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Allocate a className for a cacheKey without injecting styles yet.
|
|
30
|
-
* This allows separating className allocation (render phase) from style injection (insertion phase).
|
|
31
|
-
*/
|
|
32
|
-
allocateClassName(cacheKey, options) {
|
|
33
|
-
const root = options?.root || document;
|
|
34
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
35
|
-
if (registry.cacheKeyToClassName.has(cacheKey)) return {
|
|
36
|
-
className: registry.cacheKeyToClassName.get(cacheKey),
|
|
37
|
-
isNewAllocation: false
|
|
38
|
-
};
|
|
39
|
-
const className = generateClassName(registry.classCounter++);
|
|
40
|
-
const placeholderRuleInfo = {
|
|
41
|
-
className,
|
|
42
|
-
ruleIndex: -1,
|
|
43
|
-
sheetIndex: -1
|
|
44
|
-
};
|
|
45
|
-
registry.rules.set(className, placeholderRuleInfo);
|
|
46
|
-
registry.cacheKeyToClassName.set(cacheKey, className);
|
|
47
|
-
return {
|
|
48
|
-
className,
|
|
49
|
-
isNewAllocation: true
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Inject styles from StyleResult objects
|
|
54
|
-
*/
|
|
55
|
-
inject(rules, options) {
|
|
56
|
-
const root = options?.root || document;
|
|
57
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
58
|
-
if (rules.length === 0) return {
|
|
59
|
-
className: "",
|
|
60
|
-
dispose: () => {}
|
|
61
|
-
};
|
|
62
|
-
const cacheKey = options?.cacheKey;
|
|
63
|
-
let className;
|
|
64
|
-
let isPreAllocated = false;
|
|
65
|
-
if (cacheKey && registry.cacheKeyToClassName.has(cacheKey)) {
|
|
66
|
-
className = registry.cacheKeyToClassName.get(cacheKey);
|
|
67
|
-
const existingRuleInfo = registry.rules.get(className);
|
|
68
|
-
isPreAllocated = existingRuleInfo.ruleIndex === -1 && existingRuleInfo.sheetIndex === -1;
|
|
69
|
-
if (!isPreAllocated) {
|
|
70
|
-
const currentRefCount = registry.refCounts.get(className) || 0;
|
|
71
|
-
registry.refCounts.set(className, currentRefCount + 1);
|
|
72
|
-
if (registry.metrics) registry.metrics.hits++;
|
|
73
|
-
return {
|
|
74
|
-
className,
|
|
75
|
-
dispose: () => this.dispose(className, registry)
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
} else className = generateClassName(registry.classCounter++);
|
|
79
|
-
const rulesToInsert = rules.map((rule) => {
|
|
80
|
-
let newSelector = rule.selector;
|
|
81
|
-
if (rule.needsClassName) {
|
|
82
|
-
const selectorParts = newSelector ? newSelector.split("|||") : [""];
|
|
83
|
-
const classPrefix = `.${className}.${className}`;
|
|
84
|
-
newSelector = selectorParts.map((part) => {
|
|
85
|
-
const classSelector = part ? `${classPrefix}${part}` : classPrefix;
|
|
86
|
-
if (rule.rootPrefix) return `${rule.rootPrefix} ${classSelector}`;
|
|
87
|
-
return classSelector;
|
|
88
|
-
}).join(", ");
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
...rule,
|
|
92
|
-
selector: newSelector,
|
|
93
|
-
needsClassName: void 0,
|
|
94
|
-
rootPrefix: void 0
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
if (this.config.autoPropertyTypes !== false) {
|
|
98
|
-
const resolver = registry.propertyTypeResolver;
|
|
99
|
-
const defined = registry.injectedProperties;
|
|
100
|
-
for (const rule of rulesToInsert) {
|
|
101
|
-
if (!rule.declarations) continue;
|
|
102
|
-
resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
|
|
103
|
-
this.property(name, {
|
|
104
|
-
syntax,
|
|
105
|
-
inherits: true,
|
|
106
|
-
initialValue,
|
|
107
|
-
root
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const ruleInfo = this.sheetManager.insertRule(registry, rulesToInsert, className, root);
|
|
113
|
-
if (!ruleInfo) {
|
|
114
|
-
if (registry.metrics) registry.metrics.misses++;
|
|
115
|
-
return {
|
|
116
|
-
className,
|
|
117
|
-
dispose: () => {}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
registry.refCounts.set(className, 1);
|
|
121
|
-
if (isPreAllocated) registry.rules.set(className, ruleInfo);
|
|
122
|
-
else {
|
|
123
|
-
registry.rules.set(className, ruleInfo);
|
|
124
|
-
if (cacheKey) registry.cacheKeyToClassName.set(cacheKey, className);
|
|
125
|
-
}
|
|
126
|
-
if (registry.metrics) {
|
|
127
|
-
registry.metrics.totalInsertions++;
|
|
128
|
-
registry.metrics.misses++;
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
className,
|
|
132
|
-
dispose: () => this.dispose(className, registry)
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Inject global styles (rules without a generated tasty class selector)
|
|
137
|
-
* This ensures we don't reserve a tasty class name (t{number}) for global rules,
|
|
138
|
-
* which could otherwise collide with element-level styles and break lookups.
|
|
139
|
-
*/
|
|
140
|
-
injectGlobal(rules, options) {
|
|
141
|
-
const root = options?.root || document;
|
|
142
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
143
|
-
if (!rules || rules.length === 0) return { dispose: () => {} };
|
|
144
|
-
if (this.config.autoPropertyTypes !== false) {
|
|
145
|
-
const resolver = registry.propertyTypeResolver;
|
|
146
|
-
const defined = registry.injectedProperties;
|
|
147
|
-
for (const rule of rules) {
|
|
148
|
-
if (!rule.declarations) continue;
|
|
149
|
-
resolver.scanDeclarations(rule.declarations, (name) => defined.has(name), (name, syntax, initialValue) => {
|
|
150
|
-
this.property(name, {
|
|
151
|
-
syntax,
|
|
152
|
-
inherits: true,
|
|
153
|
-
initialValue,
|
|
154
|
-
root
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
const key = `global:${this.globalRuleCounter++}`;
|
|
160
|
-
const info = this.sheetManager.insertGlobalRule(registry, rules, key, root);
|
|
161
|
-
if (registry.metrics) registry.metrics.totalInsertions++;
|
|
162
|
-
return { dispose: () => {
|
|
163
|
-
if (info) this.sheetManager.deleteGlobalRule(registry, key);
|
|
164
|
-
} };
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Inject raw CSS text directly without parsing
|
|
168
|
-
* This is a low-overhead alternative to createGlobalStyle for raw CSS
|
|
169
|
-
* The CSS is inserted into a separate style element to avoid conflicts with tasty's chunking
|
|
170
|
-
*/
|
|
171
|
-
injectRawCSS(css, options) {
|
|
172
|
-
const root = options?.root || document;
|
|
173
|
-
return this.sheetManager.injectRawCSS(css, root);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Get raw CSS text for SSR
|
|
177
|
-
*/
|
|
178
|
-
getRawCSSText(options) {
|
|
179
|
-
const root = options?.root || document;
|
|
180
|
-
return this.sheetManager.getRawCSSText(root);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
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
|
|
203
|
-
*/
|
|
204
|
-
dispose(className, registry) {
|
|
205
|
-
const currentRefCount = registry.refCounts.get(className);
|
|
206
|
-
if (currentRefCount == null || currentRefCount <= 0) return;
|
|
207
|
-
const newRefCount = currentRefCount - 1;
|
|
208
|
-
registry.refCounts.set(className, newRefCount);
|
|
209
|
-
if (newRefCount === 0) {
|
|
210
|
-
if (registry.metrics) registry.metrics.totalUnused++;
|
|
211
|
-
this.sheetManager.checkCleanupNeeded(registry);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Force bulk cleanup of unused styles
|
|
216
|
-
*/
|
|
217
|
-
cleanup(root) {
|
|
218
|
-
const registry = this.sheetManager.getRegistry(root || document);
|
|
219
|
-
this.sheetManager.forceCleanup(registry);
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Get CSS text from all sheets (for SSR)
|
|
223
|
-
*/
|
|
224
|
-
getCssText(options) {
|
|
225
|
-
const root = options?.root || document;
|
|
226
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
227
|
-
return this.sheetManager.getCssText(registry);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Get CSS only for the provided tasty classNames (e.g., ["t0","t3"])
|
|
231
|
-
*/
|
|
232
|
-
getCssTextForClasses(classNames, options) {
|
|
233
|
-
const root = options?.root || document;
|
|
234
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
235
|
-
const cssChunks = [];
|
|
236
|
-
for (const cls of classNames) {
|
|
237
|
-
const info = registry.rules.get(cls);
|
|
238
|
-
if (info) {
|
|
239
|
-
const styleSheet = registry.sheets[info.sheetIndex]?.sheet?.sheet;
|
|
240
|
-
if (styleSheet) {
|
|
241
|
-
const start = Math.max(0, info.ruleIndex);
|
|
242
|
-
const end = Math.min(styleSheet.cssRules.length - 1, info.endRuleIndex ?? info.ruleIndex);
|
|
243
|
-
if (start >= 0 && end >= start && start < styleSheet.cssRules.length) for (let i = start; i <= end; i++) {
|
|
244
|
-
const rule = styleSheet.cssRules[i];
|
|
245
|
-
if (rule) cssChunks.push(rule.cssText);
|
|
246
|
-
}
|
|
247
|
-
} else if (info.cssText && info.cssText.length) cssChunks.push(...info.cssText);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return cssChunks.join("\n");
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Get cache performance metrics
|
|
254
|
-
*/
|
|
255
|
-
getMetrics(options) {
|
|
256
|
-
const root = options?.root || document;
|
|
257
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
258
|
-
return this.sheetManager.getMetrics(registry);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Reset cache performance metrics
|
|
262
|
-
*/
|
|
263
|
-
resetMetrics(options) {
|
|
264
|
-
const root = options?.root || document;
|
|
265
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
266
|
-
this.sheetManager.resetMetrics(registry);
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Define a CSS @property custom property.
|
|
270
|
-
*
|
|
271
|
-
* Accepts tasty token syntax for the property name:
|
|
272
|
-
* - `$name` → defines `--name`
|
|
273
|
-
* - `#name` → defines `--name-color` (auto-sets syntax: '<color>', defaults initialValue: 'transparent')
|
|
274
|
-
* - `--name` → defines `--name` (legacy format)
|
|
275
|
-
*
|
|
276
|
-
* Example:
|
|
277
|
-
* @property --rotation { syntax: "<angle>"; inherits: false; initial-value: 45deg; }
|
|
278
|
-
*
|
|
279
|
-
* Note: No caching or dispose — this defines a global property.
|
|
280
|
-
*
|
|
281
|
-
* If the same property is registered with different options, a warning is emitted
|
|
282
|
-
* but the original definition is preserved (CSS @property cannot be redefined).
|
|
283
|
-
*/
|
|
284
|
-
property(name, options) {
|
|
285
|
-
const root = options?.root || document;
|
|
286
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
287
|
-
const effectiveResult = getEffectiveDefinition(name, {
|
|
288
|
-
syntax: options?.syntax,
|
|
289
|
-
inherits: options?.inherits,
|
|
290
|
-
initialValue: options?.initialValue
|
|
291
|
-
});
|
|
292
|
-
if (!effectiveResult.isValid) {
|
|
293
|
-
if (isDevEnv()) console.warn(`[Tasty] property(): ${effectiveResult.error}. Got: "${name}"`);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const cssName = effectiveResult.cssName;
|
|
297
|
-
const definition = effectiveResult.definition;
|
|
298
|
-
const normalizedDef = normalizePropertyDefinition(definition);
|
|
299
|
-
if (registry.injectedProperties.get(cssName) !== void 0) return;
|
|
300
|
-
const parts = [];
|
|
301
|
-
if (definition.syntax != null) {
|
|
302
|
-
let syntax = String(definition.syntax).trim();
|
|
303
|
-
if (!/^['"]/u.test(syntax)) syntax = `"${syntax}"`;
|
|
304
|
-
parts.push(`syntax: ${syntax};`);
|
|
305
|
-
}
|
|
306
|
-
const inherits = definition.inherits ?? true;
|
|
307
|
-
parts.push(`inherits: ${inherits ? "true" : "false"};`);
|
|
308
|
-
if (definition.initialValue != null) {
|
|
309
|
-
let initialValueStr;
|
|
310
|
-
if (typeof definition.initialValue === "number") initialValueStr = String(definition.initialValue);
|
|
311
|
-
else initialValueStr = parseStyle(definition.initialValue).output;
|
|
312
|
-
parts.push(`initial-value: ${initialValueStr};`);
|
|
313
|
-
}
|
|
314
|
-
const declarations = parts.join(" ").trim();
|
|
315
|
-
const rule = {
|
|
316
|
-
selector: `@property ${cssName}`,
|
|
317
|
-
declarations
|
|
318
|
-
};
|
|
319
|
-
if (!this.sheetManager.insertGlobalRule(registry, [rule], `property:${name}`, root)) return;
|
|
320
|
-
registry.injectedProperties.set(cssName, normalizedDef);
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Check whether a given @property name was already injected by this injector.
|
|
324
|
-
*
|
|
325
|
-
* Accepts tasty token syntax:
|
|
326
|
-
* - `$name` → checks `--name`
|
|
327
|
-
* - `#name` → checks `--name-color`
|
|
328
|
-
* - `--name` → checks `--name` (legacy format)
|
|
329
|
-
*/
|
|
330
|
-
isPropertyDefined(name, options) {
|
|
331
|
-
const root = options?.root || document;
|
|
332
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
333
|
-
const effectiveResult = getEffectiveDefinition(name, {});
|
|
334
|
-
if (!effectiveResult.isValid) return false;
|
|
335
|
-
return registry.injectedProperties.has(effectiveResult.cssName);
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Inject a CSS @font-face rule.
|
|
339
|
-
*
|
|
340
|
-
* Permanent and global — no dispose or ref-counting.
|
|
341
|
-
* Deduplicates by content hash (family + descriptors).
|
|
342
|
-
*/
|
|
343
|
-
fontFace(family, descriptors, options) {
|
|
344
|
-
const root = options?.root || document;
|
|
345
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
346
|
-
const hash = fontFaceContentHash(family, descriptors);
|
|
347
|
-
if (registry.injectedFontFaces.has(hash)) return;
|
|
348
|
-
const rule = {
|
|
349
|
-
selector: "@font-face",
|
|
350
|
-
declarations: formatFontFaceDeclarations(family, descriptors)
|
|
351
|
-
};
|
|
352
|
-
if (this.sheetManager.insertGlobalRule(registry, [rule], `fontface:${hash}`, root)) registry.injectedFontFaces.add(hash);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Inject a CSS @counter-style rule.
|
|
356
|
-
*
|
|
357
|
-
* Permanent and global — no dispose or ref-counting.
|
|
358
|
-
* Deduplicates by name (first definition wins).
|
|
359
|
-
*/
|
|
360
|
-
counterStyle(name, descriptors, options) {
|
|
361
|
-
const root = options?.root || document;
|
|
362
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
363
|
-
if (registry.injectedCounterStyles.has(name)) return;
|
|
364
|
-
const rule = {
|
|
365
|
-
selector: `@counter-style ${name}`,
|
|
366
|
-
declarations: formatCounterStyleDeclarations(descriptors)
|
|
367
|
-
};
|
|
368
|
-
if (this.sheetManager.insertGlobalRule(registry, [rule], `counterstyle:${name}`, root)) registry.injectedCounterStyles.add(name);
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Inject keyframes and return object with toString() and dispose()
|
|
372
|
-
*
|
|
373
|
-
* Keyframes are cached by content (steps). If the same content is injected
|
|
374
|
-
* multiple times with different provided names, the first injected name is reused.
|
|
375
|
-
*
|
|
376
|
-
* If the same name is provided with different content (collision), a unique
|
|
377
|
-
* name is generated to avoid overwriting the existing keyframes.
|
|
378
|
-
*/
|
|
379
|
-
keyframes(steps, nameOrOptions) {
|
|
380
|
-
const isStringName = typeof nameOrOptions === "string";
|
|
381
|
-
const providedName = isStringName ? nameOrOptions : nameOrOptions?.name;
|
|
382
|
-
const root = isStringName ? document : nameOrOptions?.root || document;
|
|
383
|
-
const registry = this.sheetManager.getRegistry(root);
|
|
384
|
-
if (Object.keys(steps).length === 0) return {
|
|
385
|
-
toString: () => "",
|
|
386
|
-
dispose: () => {}
|
|
387
|
-
};
|
|
388
|
-
const contentHash = JSON.stringify(steps);
|
|
389
|
-
const existing = registry.keyframesCache.get(contentHash);
|
|
390
|
-
if (existing) {
|
|
391
|
-
existing.refCount++;
|
|
392
|
-
return {
|
|
393
|
-
toString: () => existing.name,
|
|
394
|
-
dispose: () => this.disposeKeyframes(contentHash, registry)
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
let actualName;
|
|
398
|
-
if (providedName) {
|
|
399
|
-
const existingContentForName = registry.keyframesNameToContent.get(providedName);
|
|
400
|
-
if (existingContentForName && existingContentForName !== contentHash) actualName = `${providedName}-k${registry.keyframesCounter++}`;
|
|
401
|
-
else {
|
|
402
|
-
actualName = providedName;
|
|
403
|
-
registry.keyframesNameToContent.set(providedName, contentHash);
|
|
404
|
-
}
|
|
405
|
-
} else actualName = `k${registry.keyframesCounter++}`;
|
|
406
|
-
const result = this.sheetManager.insertKeyframes(registry, steps, actualName, root);
|
|
407
|
-
if (!result) return {
|
|
408
|
-
toString: () => "",
|
|
409
|
-
dispose: () => {}
|
|
410
|
-
};
|
|
411
|
-
const { info, declarations } = result;
|
|
412
|
-
if (this.config.autoPropertyTypes !== false && declarations) registry.propertyTypeResolver.scanDeclarations(declarations, (name) => registry.injectedProperties.has(name), (name, syntax, initialValue) => {
|
|
413
|
-
this.property(name, {
|
|
414
|
-
syntax,
|
|
415
|
-
inherits: true,
|
|
416
|
-
initialValue,
|
|
417
|
-
root
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
registry.keyframesCache.set(contentHash, {
|
|
421
|
-
name: actualName,
|
|
422
|
-
refCount: 1,
|
|
423
|
-
info
|
|
424
|
-
});
|
|
425
|
-
if (registry.metrics) {
|
|
426
|
-
registry.metrics.totalInsertions++;
|
|
427
|
-
registry.metrics.misses++;
|
|
428
|
-
}
|
|
429
|
-
return {
|
|
430
|
-
toString: () => actualName,
|
|
431
|
-
dispose: () => this.disposeKeyframes(contentHash, registry)
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Dispose keyframes
|
|
436
|
-
*/
|
|
437
|
-
disposeKeyframes(contentHash, registry) {
|
|
438
|
-
const entry = registry.keyframesCache.get(contentHash);
|
|
439
|
-
if (!entry) return;
|
|
440
|
-
entry.refCount--;
|
|
441
|
-
if (entry.refCount <= 0) {
|
|
442
|
-
this.sheetManager.deleteKeyframes(registry, entry.info);
|
|
443
|
-
registry.keyframesCache.delete(contentHash);
|
|
444
|
-
for (const [name, hash] of registry.keyframesNameToContent.entries()) if (hash === contentHash) {
|
|
445
|
-
registry.keyframesNameToContent.delete(name);
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
if (registry.metrics) {
|
|
449
|
-
registry.metrics.totalUnused++;
|
|
450
|
-
registry.metrics.stylesCleanedUp++;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Destroy all resources for a root
|
|
456
|
-
*/
|
|
457
|
-
destroy(root) {
|
|
458
|
-
const targetRoot = root || document;
|
|
459
|
-
this.sheetManager.cleanup(targetRoot);
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
//#endregion
|
|
464
|
-
export { StyleInjector };
|
|
465
|
-
//# sourceMappingURL=injector.js.map
|