@tenphi/tasty 0.0.0-snapshot.08a6610
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/LICENSE +21 -0
- package/README.md +666 -0
- package/dist/_virtual/_rolldown/runtime.js +8 -0
- package/dist/chunks/cacheKey.js +70 -0
- package/dist/chunks/cacheKey.js.map +1 -0
- package/dist/chunks/definitions.d.ts +37 -0
- package/dist/chunks/definitions.js +259 -0
- package/dist/chunks/definitions.js.map +1 -0
- package/dist/chunks/renderChunk.js +61 -0
- package/dist/chunks/renderChunk.js.map +1 -0
- package/dist/config.d.ts +311 -0
- package/dist/config.js +458 -0
- package/dist/config.js.map +1 -0
- package/dist/core/index.d.ts +32 -0
- package/dist/core/index.js +26 -0
- package/dist/debug.d.ts +204 -0
- package/dist/debug.js +733 -0
- package/dist/debug.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +30 -0
- package/dist/hooks/useGlobalStyles.js +83 -0
- package/dist/hooks/useGlobalStyles.js.map +1 -0
- package/dist/hooks/useKeyframes.d.ts +56 -0
- package/dist/hooks/useKeyframes.js +69 -0
- package/dist/hooks/useKeyframes.js.map +1 -0
- package/dist/hooks/useProperty.d.ts +79 -0
- package/dist/hooks/useProperty.js +114 -0
- package/dist/hooks/useProperty.js.map +1 -0
- package/dist/hooks/useRawCSS.d.ts +53 -0
- package/dist/hooks/useRawCSS.js +40 -0
- package/dist/hooks/useRawCSS.js.map +1 -0
- package/dist/hooks/useStyles.d.ts +45 -0
- package/dist/hooks/useStyles.js +248 -0
- package/dist/hooks/useStyles.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +33 -0
- package/dist/injector/index.d.ts +165 -0
- package/dist/injector/index.js +162 -0
- package/dist/injector/index.js.map +1 -0
- package/dist/injector/injector.d.ts +148 -0
- package/dist/injector/injector.js +430 -0
- package/dist/injector/injector.js.map +1 -0
- package/dist/injector/sheet-manager.d.ts +136 -0
- package/dist/injector/sheet-manager.js +729 -0
- package/dist/injector/sheet-manager.js.map +1 -0
- package/dist/injector/types.d.ts +144 -0
- package/dist/keyframes/index.js +206 -0
- package/dist/keyframes/index.js.map +1 -0
- package/dist/parser/classify.js +319 -0
- package/dist/parser/classify.js.map +1 -0
- package/dist/parser/const.js +33 -0
- package/dist/parser/const.js.map +1 -0
- package/dist/parser/lru.js +109 -0
- package/dist/parser/lru.js.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +116 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/tokenizer.js +69 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/types.d.ts +51 -0
- package/dist/parser/types.js +46 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/pipeline/conditions.d.ts +134 -0
- package/dist/pipeline/conditions.js +406 -0
- package/dist/pipeline/conditions.js.map +1 -0
- package/dist/pipeline/exclusive.js +231 -0
- package/dist/pipeline/exclusive.js.map +1 -0
- package/dist/pipeline/index.d.ts +53 -0
- package/dist/pipeline/index.js +660 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/materialize.js +856 -0
- package/dist/pipeline/materialize.js.map +1 -0
- package/dist/pipeline/parseStateKey.d.ts +15 -0
- package/dist/pipeline/parseStateKey.js +451 -0
- package/dist/pipeline/parseStateKey.js.map +1 -0
- package/dist/pipeline/simplify.js +516 -0
- package/dist/pipeline/simplify.js.map +1 -0
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.map +1 -0
- package/dist/plugins/okhsl-plugin.d.ts +35 -0
- package/dist/plugins/okhsl-plugin.js +371 -0
- package/dist/plugins/okhsl-plugin.js.map +1 -0
- package/dist/plugins/types.d.ts +76 -0
- package/dist/properties/index.js +236 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +91 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/ssr/astro.d.ts +29 -0
- package/dist/ssr/astro.js +65 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +35 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +40 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +85 -0
- package/dist/ssr/collector.js +183 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.d.ts +8 -0
- package/dist/ssr/context.js +14 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +70 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +48 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +70 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +22 -0
- package/dist/ssr/hydrate.js +50 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +5 -0
- package/dist/ssr/index.js +12 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +45 -0
- package/dist/ssr/next.js +71 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +12 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.d.ts +49 -0
- package/dist/states/index.js +416 -0
- package/dist/states/index.js.map +1 -0
- package/dist/static/index.d.ts +5 -0
- package/dist/static/index.js +5 -0
- package/dist/static/tastyStatic.d.ts +46 -0
- package/dist/static/tastyStatic.js +31 -0
- package/dist/static/tastyStatic.js.map +1 -0
- package/dist/static/types.d.ts +49 -0
- package/dist/static/types.js +24 -0
- package/dist/static/types.js.map +1 -0
- package/dist/styles/align.d.ts +15 -0
- package/dist/styles/align.js +14 -0
- package/dist/styles/align.js.map +1 -0
- package/dist/styles/border.d.ts +25 -0
- package/dist/styles/border.js +114 -0
- package/dist/styles/border.js.map +1 -0
- package/dist/styles/color.d.ts +14 -0
- package/dist/styles/color.js +23 -0
- package/dist/styles/color.js.map +1 -0
- package/dist/styles/createStyle.js +77 -0
- package/dist/styles/createStyle.js.map +1 -0
- package/dist/styles/dimension.js +97 -0
- package/dist/styles/dimension.js.map +1 -0
- package/dist/styles/display.d.ts +37 -0
- package/dist/styles/display.js +67 -0
- package/dist/styles/display.js.map +1 -0
- package/dist/styles/fade.d.ts +15 -0
- package/dist/styles/fade.js +58 -0
- package/dist/styles/fade.js.map +1 -0
- package/dist/styles/fill.d.ts +42 -0
- package/dist/styles/fill.js +52 -0
- package/dist/styles/fill.js.map +1 -0
- package/dist/styles/flow.d.ts +16 -0
- package/dist/styles/flow.js +12 -0
- package/dist/styles/flow.js.map +1 -0
- package/dist/styles/gap.d.ts +31 -0
- package/dist/styles/gap.js +37 -0
- package/dist/styles/gap.js.map +1 -0
- package/dist/styles/height.d.ts +17 -0
- package/dist/styles/height.js +20 -0
- package/dist/styles/height.js.map +1 -0
- package/dist/styles/index.d.ts +2 -0
- package/dist/styles/index.js +9 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/inset.d.ts +52 -0
- package/dist/styles/inset.js +150 -0
- package/dist/styles/inset.js.map +1 -0
- package/dist/styles/justify.d.ts +15 -0
- package/dist/styles/justify.js +14 -0
- package/dist/styles/justify.js.map +1 -0
- package/dist/styles/list.d.ts +16 -0
- package/dist/styles/list.js +98 -0
- package/dist/styles/list.js.map +1 -0
- package/dist/styles/margin.d.ts +24 -0
- package/dist/styles/margin.js +104 -0
- package/dist/styles/margin.js.map +1 -0
- package/dist/styles/outline.d.ts +29 -0
- package/dist/styles/outline.js +65 -0
- package/dist/styles/outline.js.map +1 -0
- package/dist/styles/padding.d.ts +24 -0
- package/dist/styles/padding.js +104 -0
- package/dist/styles/padding.js.map +1 -0
- package/dist/styles/predefined.d.ts +71 -0
- package/dist/styles/predefined.js +238 -0
- package/dist/styles/predefined.js.map +1 -0
- package/dist/styles/preset.d.ts +47 -0
- package/dist/styles/preset.js +126 -0
- package/dist/styles/preset.js.map +1 -0
- package/dist/styles/radius.d.ts +14 -0
- package/dist/styles/radius.js +51 -0
- package/dist/styles/radius.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +25 -0
- package/dist/styles/scrollbar.js +48 -0
- package/dist/styles/scrollbar.js.map +1 -0
- package/dist/styles/shadow.d.ts +14 -0
- package/dist/styles/shadow.js +24 -0
- package/dist/styles/shadow.js.map +1 -0
- package/dist/styles/transition.d.ts +14 -0
- package/dist/styles/transition.js +158 -0
- package/dist/styles/transition.js.map +1 -0
- package/dist/styles/types.d.ts +508 -0
- package/dist/styles/width.d.ts +17 -0
- package/dist/styles/width.js +20 -0
- package/dist/styles/width.js.map +1 -0
- package/dist/tasty.d.ts +981 -0
- package/dist/tasty.js +206 -0
- package/dist/tasty.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/utils/cache-wrapper.js +26 -0
- package/dist/utils/cache-wrapper.js.map +1 -0
- package/dist/utils/case-converter.js +8 -0
- package/dist/utils/case-converter.js.map +1 -0
- package/dist/utils/colors.d.ts +5 -0
- package/dist/utils/colors.js +9 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/css-types.d.ts +7 -0
- package/dist/utils/dotize.d.ts +26 -0
- package/dist/utils/dotize.js +122 -0
- package/dist/utils/dotize.js.map +1 -0
- package/dist/utils/filter-base-props.d.ts +15 -0
- package/dist/utils/filter-base-props.js +45 -0
- package/dist/utils/filter-base-props.js.map +1 -0
- package/dist/utils/get-display-name.d.ts +7 -0
- package/dist/utils/get-display-name.js +10 -0
- package/dist/utils/get-display-name.js.map +1 -0
- package/dist/utils/hsl-to-rgb.js +38 -0
- package/dist/utils/hsl-to-rgb.js.map +1 -0
- package/dist/utils/is-dev-env.js +19 -0
- package/dist/utils/is-dev-env.js.map +1 -0
- package/dist/utils/is-valid-element-type.js +15 -0
- package/dist/utils/is-valid-element-type.js.map +1 -0
- package/dist/utils/merge-styles.d.ts +7 -0
- package/dist/utils/merge-styles.js +146 -0
- package/dist/utils/merge-styles.js.map +1 -0
- package/dist/utils/mod-attrs.d.ts +8 -0
- package/dist/utils/mod-attrs.js +21 -0
- package/dist/utils/mod-attrs.js.map +1 -0
- package/dist/utils/okhsl-to-rgb.js +296 -0
- package/dist/utils/okhsl-to-rgb.js.map +1 -0
- package/dist/utils/process-tokens.d.ts +31 -0
- package/dist/utils/process-tokens.js +171 -0
- package/dist/utils/process-tokens.js.map +1 -0
- package/dist/utils/resolve-recipes.d.ts +17 -0
- package/dist/utils/resolve-recipes.js +147 -0
- package/dist/utils/resolve-recipes.js.map +1 -0
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/styles.d.ts +177 -0
- package/dist/utils/styles.js +730 -0
- package/dist/utils/styles.js.map +1 -0
- package/dist/utils/typography.d.ts +47 -0
- package/dist/utils/typography.js +43 -0
- package/dist/utils/typography.js.map +1 -0
- package/dist/utils/warnings.d.ts +16 -0
- package/dist/utils/warnings.js +16 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/zero/babel.d.ts +147 -0
- package/dist/zero/babel.js +331 -0
- package/dist/zero/babel.js.map +1 -0
- package/dist/zero/css-writer.d.ts +45 -0
- package/dist/zero/css-writer.js +74 -0
- package/dist/zero/css-writer.js.map +1 -0
- package/dist/zero/extractor.d.ts +24 -0
- package/dist/zero/extractor.js +215 -0
- package/dist/zero/extractor.js.map +1 -0
- package/dist/zero/index.d.ts +3 -0
- package/dist/zero/index.js +4 -0
- package/dist/zero/next.d.ts +74 -0
- package/dist/zero/next.js +129 -0
- package/dist/zero/next.js.map +1 -0
- package/docs/adoption.md +286 -0
- package/docs/comparison.md +413 -0
- package/docs/configuration.md +242 -0
- package/docs/debug.md +505 -0
- package/docs/design-system.md +401 -0
- package/docs/dsl.md +540 -0
- package/docs/getting-started.md +201 -0
- package/docs/injector.md +528 -0
- package/docs/methodology.md +501 -0
- package/docs/runtime.md +291 -0
- package/docs/ssr.md +382 -0
- package/docs/styles.md +574 -0
- package/docs/tasty-static.md +421 -0
- package/package.json +209 -0
- package/tasty.config.ts +14 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/hooks/useRawCSS.d.ts
|
|
2
|
+
interface UseRawCSSOptions {
|
|
3
|
+
root?: Document | ShadowRoot;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Hook to inject raw CSS text directly without parsing.
|
|
7
|
+
* This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.
|
|
8
|
+
*
|
|
9
|
+
* The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts
|
|
10
|
+
* with tasty's chunked style sheets.
|
|
11
|
+
*
|
|
12
|
+
* @example Static CSS string
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function GlobalStyles() {
|
|
15
|
+
* useRawCSS(`
|
|
16
|
+
* body {
|
|
17
|
+
* margin: 0;
|
|
18
|
+
* padding: 0;
|
|
19
|
+
* font-family: sans-serif;
|
|
20
|
+
* }
|
|
21
|
+
* `);
|
|
22
|
+
*
|
|
23
|
+
* return null;
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example Factory function with dependencies (like useMemo)
|
|
28
|
+
* ```tsx
|
|
29
|
+
* function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {
|
|
30
|
+
* useRawCSS(() => `
|
|
31
|
+
* :root {
|
|
32
|
+
* --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};
|
|
33
|
+
* --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};
|
|
34
|
+
* }
|
|
35
|
+
* `, [theme]);
|
|
36
|
+
*
|
|
37
|
+
* return null;
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example With options
|
|
42
|
+
* ```tsx
|
|
43
|
+
* function ShadowStyles({ shadowRoot }) {
|
|
44
|
+
* useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });
|
|
45
|
+
* return null;
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
declare function useRawCSS(css: string, options?: UseRawCSSOptions): void;
|
|
50
|
+
declare function useRawCSS(factory: () => string, deps: readonly unknown[], options?: UseRawCSSOptions): void;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { useRawCSS };
|
|
53
|
+
//# sourceMappingURL=useRawCSS.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { injectRawCSS } from "../injector/index.js";
|
|
2
|
+
import { TastySSRContext } from "../ssr/context.js";
|
|
3
|
+
import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
|
|
4
|
+
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/hooks/useRawCSS.ts
|
|
7
|
+
function resolveSSRCollector(reactContext) {
|
|
8
|
+
if (reactContext) return reactContext;
|
|
9
|
+
return getRegisteredSSRCollector();
|
|
10
|
+
}
|
|
11
|
+
function useRawCSS(cssOrFactory, depsOrOptions, options) {
|
|
12
|
+
const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
|
|
13
|
+
const isFactory = typeof cssOrFactory === "function";
|
|
14
|
+
const deps = isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : void 0;
|
|
15
|
+
const opts = isFactory ? options : depsOrOptions;
|
|
16
|
+
const css = useMemo(() => isFactory ? cssOrFactory() : cssOrFactory, isFactory ? deps ?? [] : [cssOrFactory]);
|
|
17
|
+
useMemo(() => {
|
|
18
|
+
if (!ssrCollector || !css.trim()) return;
|
|
19
|
+
const key = `raw:${css.length}:${css.slice(0, 64)}`;
|
|
20
|
+
ssrCollector.collectRawCSS(key, css);
|
|
21
|
+
}, [ssrCollector, css]);
|
|
22
|
+
const disposeRef = useRef(null);
|
|
23
|
+
useInsertionEffect(() => {
|
|
24
|
+
disposeRef.current?.();
|
|
25
|
+
if (!css.trim()) {
|
|
26
|
+
disposeRef.current = null;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const { dispose } = injectRawCSS(css, opts);
|
|
30
|
+
disposeRef.current = dispose;
|
|
31
|
+
return () => {
|
|
32
|
+
disposeRef.current?.();
|
|
33
|
+
disposeRef.current = null;
|
|
34
|
+
};
|
|
35
|
+
}, [css, opts?.root]);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { useRawCSS };
|
|
40
|
+
//# sourceMappingURL=useRawCSS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRawCSS.js","names":[],"sources":["../../src/hooks/useRawCSS.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport { injectRawCSS } from '../injector';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\n\ninterface UseRawCSSOptions {\n root?: Document | ShadowRoot;\n}\n\nfunction resolveSSRCollector(\n reactContext: ServerStyleCollector | null,\n): ServerStyleCollector | null {\n if (reactContext) return reactContext;\n return getRegisteredSSRCollector();\n}\n\n/**\n * Hook to inject raw CSS text directly without parsing.\n * This is a low-overhead alternative for injecting global CSS that doesn't need tasty processing.\n *\n * The CSS is inserted into a separate style element (data-tasty-raw) to avoid conflicts\n * with tasty's chunked style sheets.\n *\n * @example Static CSS string\n * ```tsx\n * function GlobalStyles() {\n * useRawCSS(`\n * body {\n * margin: 0;\n * padding: 0;\n * font-family: sans-serif;\n * }\n * `);\n *\n * return null;\n * }\n * ```\n *\n * @example Factory function with dependencies (like useMemo)\n * ```tsx\n * function ThemeStyles({ theme }: { theme: 'light' | 'dark' }) {\n * useRawCSS(() => `\n * :root {\n * --bg-color: ${theme === 'dark' ? '#1a1a1a' : '#ffffff'};\n * --text-color: ${theme === 'dark' ? '#ffffff' : '#1a1a1a'};\n * }\n * `, [theme]);\n *\n * return null;\n * }\n * ```\n *\n * @example With options\n * ```tsx\n * function ShadowStyles({ shadowRoot }) {\n * useRawCSS(() => `.scoped { color: red; }`, [], { root: shadowRoot });\n * return null;\n * }\n * ```\n */\n\n// Overload 1: Static CSS string\nexport function useRawCSS(css: string, options?: UseRawCSSOptions): void;\n\n// Overload 2: Factory function with dependencies\nexport function useRawCSS(\n factory: () => string,\n deps: readonly unknown[],\n options?: UseRawCSSOptions,\n): void;\n\n// Implementation\nexport function useRawCSS(\n cssOrFactory: string | (() => string),\n depsOrOptions?: readonly unknown[] | UseRawCSSOptions,\n options?: UseRawCSSOptions,\n): void {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Detect which overload is being used\n const isFactory = typeof cssOrFactory === 'function';\n\n // Parse arguments based on overload\n const deps =\n isFactory && Array.isArray(depsOrOptions) ? depsOrOptions : undefined;\n const opts = isFactory\n ? options\n : (depsOrOptions as UseRawCSSOptions | undefined);\n\n // Memoize CSS - for factory functions, use provided deps; for strings, use the string itself\n const css = useMemo(\n () =>\n isFactory ? (cssOrFactory as () => string)() : (cssOrFactory as string),\n\n isFactory ? (deps ?? []) : [cssOrFactory],\n );\n\n // SSR path: collect raw CSS during render\n useMemo(() => {\n if (!ssrCollector || !css.trim()) return;\n\n const key = `raw:${css.length}:${css.slice(0, 64)}`;\n ssrCollector.collectRawCSS(key, css);\n }, [ssrCollector, css]);\n\n const disposeRef = useRef<(() => void) | null>(null);\n\n // Client path: inject via DOM\n useInsertionEffect(() => {\n disposeRef.current?.();\n\n if (!css.trim()) {\n disposeRef.current = null;\n return;\n }\n\n const { dispose } = injectRawCSS(css, opts);\n disposeRef.current = dispose;\n\n return () => {\n disposeRef.current?.();\n disposeRef.current = null;\n };\n }, [css, opts?.root]);\n}\n"],"mappings":";;;;;;AAWA,SAAS,oBACP,cAC6B;AAC7B,KAAI,aAAc,QAAO;AACzB,QAAO,2BAA2B;;AA2DpC,SAAgB,UACd,cACA,eACA,SACM;CAEN,MAAM,eAAe,oBADG,WAAW,gBAAgB,CACM;CAGzD,MAAM,YAAY,OAAO,iBAAiB;CAG1C,MAAM,OACJ,aAAa,MAAM,QAAQ,cAAc,GAAG,gBAAgB;CAC9D,MAAM,OAAO,YACT,UACC;CAGL,MAAM,MAAM,cAER,YAAa,cAA+B,GAAI,cAElD,YAAa,QAAQ,EAAE,GAAI,CAAC,aAAa,CAC1C;AAGD,eAAc;AACZ,MAAI,CAAC,gBAAgB,CAAC,IAAI,MAAM,CAAE;EAElC,MAAM,MAAM,OAAO,IAAI,OAAO,GAAG,IAAI,MAAM,GAAG,GAAG;AACjD,eAAa,cAAc,KAAK,IAAI;IACnC,CAAC,cAAc,IAAI,CAAC;CAEvB,MAAM,aAAa,OAA4B,KAAK;AAGpD,0BAAyB;AACvB,aAAW,WAAW;AAEtB,MAAI,CAAC,IAAI,MAAM,EAAE;AACf,cAAW,UAAU;AACrB;;EAGF,MAAM,EAAE,YAAY,aAAa,KAAK,KAAK;AAC3C,aAAW,UAAU;AAErB,eAAa;AACX,cAAW,WAAW;AACtB,cAAW,UAAU;;IAEtB,CAAC,KAAK,MAAM,KAAK,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Styles } from "../styles/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/useStyles.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Tasty styles object to generate CSS classes for.
|
|
6
|
+
* Can be undefined or empty object for no styles.
|
|
7
|
+
*/
|
|
8
|
+
type UseStylesOptions = Styles | undefined;
|
|
9
|
+
interface UseStylesResult {
|
|
10
|
+
/**
|
|
11
|
+
* Generated className(s) to apply to the element.
|
|
12
|
+
* Can be empty string if no styles are provided.
|
|
13
|
+
* With chunking enabled, may contain multiple space-separated class names.
|
|
14
|
+
*/
|
|
15
|
+
className: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Hook to generate CSS classes from Tasty styles.
|
|
19
|
+
* Handles style rendering, className allocation, and CSS injection.
|
|
20
|
+
*
|
|
21
|
+
* SSR-aware: when a ServerStyleCollector is available (via React context
|
|
22
|
+
* or AsyncLocalStorage), CSS is collected during the render phase instead
|
|
23
|
+
* of being injected into the DOM. useInsertionEffect does not run on the
|
|
24
|
+
* server, so the collector path is the only active path during SSR.
|
|
25
|
+
*
|
|
26
|
+
* Uses chunking to split styles into logical groups for better caching
|
|
27
|
+
* and CSS reuse across components.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* function MyComponent() {
|
|
32
|
+
* const { className } = useStyles({
|
|
33
|
+
* padding: '2x',
|
|
34
|
+
* fill: '#purple',
|
|
35
|
+
* radius: '1r',
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* return <div className={className}>Styled content</div>;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function useStyles(styles: UseStylesOptions): UseStylesResult;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { UseStylesOptions, UseStylesResult, useStyles };
|
|
45
|
+
//# sourceMappingURL=useStyles.d.ts.map
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { extractLocalProperties, hasLocalProperties } from "../properties/index.js";
|
|
2
|
+
import { stringifyStyles } from "../utils/styles.js";
|
|
3
|
+
import { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from "../config.js";
|
|
4
|
+
import { CHUNK_NAMES, categorizeStyleKeys } from "../chunks/definitions.js";
|
|
5
|
+
import { generateChunkCacheKey } from "../chunks/cacheKey.js";
|
|
6
|
+
import { renderStylesForChunk } from "../chunks/renderChunk.js";
|
|
7
|
+
import { allocateClassName, inject, keyframes, property } from "../injector/index.js";
|
|
8
|
+
import { resolveRecipes } from "../utils/resolve-recipes.js";
|
|
9
|
+
import { extractAnimationNamesFromStyles, extractLocalKeyframes, filterUsedKeyframes, hasLocalKeyframes, mergeKeyframes, replaceAnimationNames } from "../keyframes/index.js";
|
|
10
|
+
import { formatPropertyCSS } from "../ssr/format-property.js";
|
|
11
|
+
import { collectAutoInferredProperties } from "../ssr/collect-auto-properties.js";
|
|
12
|
+
import { TastySSRContext } from "../ssr/context.js";
|
|
13
|
+
import { formatKeyframesCSS } from "../ssr/format-keyframes.js";
|
|
14
|
+
import { getRegisteredSSRCollector } from "../ssr/ssr-collector-ref.js";
|
|
15
|
+
import { useContext, useInsertionEffect, useMemo, useRef } from "react";
|
|
16
|
+
|
|
17
|
+
//#region src/hooks/useStyles.ts
|
|
18
|
+
/**
|
|
19
|
+
* Check if styles contain @starting-style rules.
|
|
20
|
+
*
|
|
21
|
+
* @starting-style CSS cannot be applied via multiple class names because
|
|
22
|
+
* of cascade - later rules override earlier ones. When @starting is detected,
|
|
23
|
+
* we combine top-level styles into a single chunk but keep sub-element styles
|
|
24
|
+
* in their own chunk for better caching.
|
|
25
|
+
*/
|
|
26
|
+
function containsStartingStyle(styleKey) {
|
|
27
|
+
return styleKey.includes("@starting");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Render, cache-key, and allocate a className for a single chunk.
|
|
31
|
+
* Returns a ProcessedChunk, or null if the chunk produces no CSS rules.
|
|
32
|
+
*
|
|
33
|
+
* Always runs the pipeline and calls allocateClassName. The inject()
|
|
34
|
+
* call in useInsertionEffect handles all edge cases: placeholders from
|
|
35
|
+
* abandoned concurrent renders, hydration hits (ruleIndex -2), and
|
|
36
|
+
* runtime cache hits (already injected). The pipeline's own LRU cache
|
|
37
|
+
* makes repeated calls for identical styles cheap.
|
|
38
|
+
*/
|
|
39
|
+
function processChunk(styles, chunkName, styleKeys) {
|
|
40
|
+
if (styleKeys.length === 0) return null;
|
|
41
|
+
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
|
|
42
|
+
if (renderResult.rules.length === 0) return null;
|
|
43
|
+
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
44
|
+
const { className } = allocateClassName(cacheKey);
|
|
45
|
+
return {
|
|
46
|
+
name: chunkName,
|
|
47
|
+
styleKeys,
|
|
48
|
+
cacheKey,
|
|
49
|
+
renderResult,
|
|
50
|
+
className
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Merge chunk map entries for @starting-style partial chunking.
|
|
55
|
+
*
|
|
56
|
+
* All non-subcomponent chunks are merged into a single COMBINED entry,
|
|
57
|
+
* while SUBCOMPONENTS stays separate. This preserves CSS cascade for
|
|
58
|
+
* @starting-style while still allowing sub-element styles to cache independently.
|
|
59
|
+
*/
|
|
60
|
+
function mergeChunksForStartingStyle(chunkMap) {
|
|
61
|
+
const merged = /* @__PURE__ */ new Map();
|
|
62
|
+
const combinedKeys = [];
|
|
63
|
+
for (const [chunkName, keys] of chunkMap) if (chunkName === CHUNK_NAMES.SUBCOMPONENTS) merged.set(CHUNK_NAMES.SUBCOMPONENTS, keys);
|
|
64
|
+
else combinedKeys.push(...keys);
|
|
65
|
+
if (combinedKeys.length > 0) {
|
|
66
|
+
const result = /* @__PURE__ */ new Map();
|
|
67
|
+
result.set(CHUNK_NAMES.COMBINED, combinedKeys);
|
|
68
|
+
for (const [k, v] of merged) result.set(k, v);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
return merged;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get keyframes that are actually used in styles.
|
|
75
|
+
* Returns null if no keyframes are used (fast path for zero overhead).
|
|
76
|
+
*
|
|
77
|
+
* Optimization order:
|
|
78
|
+
* 1. Check if any keyframes are defined (local or global) - if not, return null
|
|
79
|
+
* 2. Extract animation names from styles - if none, return null
|
|
80
|
+
* 3. Merge and filter keyframes to only used ones
|
|
81
|
+
*/
|
|
82
|
+
function getUsedKeyframes(styles) {
|
|
83
|
+
const hasLocal = hasLocalKeyframes(styles);
|
|
84
|
+
const hasGlobal = hasGlobalKeyframes();
|
|
85
|
+
if (!hasLocal && !hasGlobal) return null;
|
|
86
|
+
const usedNames = extractAnimationNamesFromStyles(styles);
|
|
87
|
+
if (usedNames.size === 0) return null;
|
|
88
|
+
return filterUsedKeyframes(mergeKeyframes(hasLocal ? extractLocalKeyframes(styles) : null, hasGlobal ? getGlobalKeyframes() : null), usedNames);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Resolve the SSR collector from React context or AsyncLocalStorage.
|
|
92
|
+
* Returns null on the client (no collector available).
|
|
93
|
+
*/
|
|
94
|
+
function resolveSSRCollector(reactContext) {
|
|
95
|
+
if (reactContext) return reactContext;
|
|
96
|
+
const alsCollector = getRegisteredSSRCollector();
|
|
97
|
+
if (alsCollector) return alsCollector;
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Process a chunk on the SSR path: allocate via collector, render, collect CSS.
|
|
102
|
+
* Returns null if the chunk produces no CSS rules.
|
|
103
|
+
*/
|
|
104
|
+
function processChunkSSR(collector, styles, chunkName, styleKeys) {
|
|
105
|
+
if (styleKeys.length === 0) return null;
|
|
106
|
+
const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);
|
|
107
|
+
const { className, isNewAllocation } = collector.allocateClassName(cacheKey);
|
|
108
|
+
if (isNewAllocation) {
|
|
109
|
+
const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);
|
|
110
|
+
if (renderResult.rules.length > 0) {
|
|
111
|
+
collector.collectChunk(cacheKey, className, renderResult.rules);
|
|
112
|
+
return {
|
|
113
|
+
name: chunkName,
|
|
114
|
+
styleKeys,
|
|
115
|
+
cacheKey,
|
|
116
|
+
renderResult,
|
|
117
|
+
className
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
name: chunkName,
|
|
124
|
+
styleKeys,
|
|
125
|
+
cacheKey,
|
|
126
|
+
renderResult: { rules: [] },
|
|
127
|
+
className
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Hook to generate CSS classes from Tasty styles.
|
|
132
|
+
* Handles style rendering, className allocation, and CSS injection.
|
|
133
|
+
*
|
|
134
|
+
* SSR-aware: when a ServerStyleCollector is available (via React context
|
|
135
|
+
* or AsyncLocalStorage), CSS is collected during the render phase instead
|
|
136
|
+
* of being injected into the DOM. useInsertionEffect does not run on the
|
|
137
|
+
* server, so the collector path is the only active path during SSR.
|
|
138
|
+
*
|
|
139
|
+
* Uses chunking to split styles into logical groups for better caching
|
|
140
|
+
* and CSS reuse across components.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```tsx
|
|
144
|
+
* function MyComponent() {
|
|
145
|
+
* const { className } = useStyles({
|
|
146
|
+
* padding: '2x',
|
|
147
|
+
* fill: '#purple',
|
|
148
|
+
* radius: '1r',
|
|
149
|
+
* });
|
|
150
|
+
*
|
|
151
|
+
* return <div className={className}>Styled content</div>;
|
|
152
|
+
* }
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
function useStyles(styles) {
|
|
156
|
+
const ssrCollector = resolveSSRCollector(useContext(TastySSRContext));
|
|
157
|
+
const disposeRef = useRef([]);
|
|
158
|
+
const stylesRef = useRef({
|
|
159
|
+
key: "",
|
|
160
|
+
styles: void 0
|
|
161
|
+
});
|
|
162
|
+
const resolvedStyles = useMemo(() => {
|
|
163
|
+
if (!styles) return styles;
|
|
164
|
+
return resolveRecipes(styles);
|
|
165
|
+
}, [styles]);
|
|
166
|
+
const styleKey = useMemo(() => {
|
|
167
|
+
if (!resolvedStyles || Object.keys(resolvedStyles).length === 0) return "";
|
|
168
|
+
return stringifyStyles(resolvedStyles);
|
|
169
|
+
}, [resolvedStyles]);
|
|
170
|
+
if (stylesRef.current.key !== styleKey) stylesRef.current = {
|
|
171
|
+
key: styleKey,
|
|
172
|
+
styles: resolvedStyles
|
|
173
|
+
};
|
|
174
|
+
const processedChunks = useMemo(() => {
|
|
175
|
+
const currentStyles = stylesRef.current.styles;
|
|
176
|
+
if (!styleKey || !currentStyles) return [];
|
|
177
|
+
let chunkMap = categorizeStyleKeys(currentStyles);
|
|
178
|
+
if (containsStartingStyle(styleKey)) chunkMap = mergeChunksForStartingStyle(chunkMap);
|
|
179
|
+
const chunks = [];
|
|
180
|
+
if (ssrCollector) {
|
|
181
|
+
ssrCollector.collectInternals();
|
|
182
|
+
for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
183
|
+
const chunk = processChunkSSR(ssrCollector, currentStyles, chunkName, chunkStyleKeys);
|
|
184
|
+
if (chunk) chunks.push(chunk);
|
|
185
|
+
}
|
|
186
|
+
const usedKeyframes = getUsedKeyframes(currentStyles);
|
|
187
|
+
if (usedKeyframes) for (const [name, steps] of Object.entries(usedKeyframes)) {
|
|
188
|
+
const css = formatKeyframesCSS(name, steps);
|
|
189
|
+
ssrCollector.collectKeyframes(name, css);
|
|
190
|
+
}
|
|
191
|
+
if (hasLocalProperties(currentStyles)) {
|
|
192
|
+
const localProperties = extractLocalProperties(currentStyles);
|
|
193
|
+
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) {
|
|
194
|
+
const css = formatPropertyCSS(token, definition);
|
|
195
|
+
if (css) ssrCollector.collectProperty(token, css);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (getConfig().autoPropertyTypes !== false) {
|
|
199
|
+
const allRules = chunks.flatMap((c) => c.renderResult.rules);
|
|
200
|
+
if (allRules.length > 0) collectAutoInferredProperties(allRules, ssrCollector, currentStyles);
|
|
201
|
+
}
|
|
202
|
+
} else for (const [chunkName, chunkStyleKeys] of chunkMap) {
|
|
203
|
+
const chunk = processChunk(currentStyles, chunkName, chunkStyleKeys);
|
|
204
|
+
if (chunk) chunks.push(chunk);
|
|
205
|
+
}
|
|
206
|
+
return chunks;
|
|
207
|
+
}, [styleKey]);
|
|
208
|
+
useInsertionEffect(() => {
|
|
209
|
+
disposeRef.current.forEach((dispose) => dispose?.());
|
|
210
|
+
disposeRef.current = [];
|
|
211
|
+
if (processedChunks.length === 0) return;
|
|
212
|
+
const currentStyles = stylesRef.current.styles;
|
|
213
|
+
if (currentStyles && hasLocalProperties(currentStyles)) {
|
|
214
|
+
const localProperties = extractLocalProperties(currentStyles);
|
|
215
|
+
if (localProperties) for (const [token, definition] of Object.entries(localProperties)) property(token, definition);
|
|
216
|
+
}
|
|
217
|
+
const usedKeyframes = currentStyles ? getUsedKeyframes(currentStyles) : null;
|
|
218
|
+
let nameMap = null;
|
|
219
|
+
if (usedKeyframes) {
|
|
220
|
+
nameMap = /* @__PURE__ */ new Map();
|
|
221
|
+
for (const [name, steps] of Object.entries(usedKeyframes)) {
|
|
222
|
+
const result = keyframes(steps, { name });
|
|
223
|
+
const injectedName = result.toString();
|
|
224
|
+
if (injectedName !== name) nameMap.set(name, injectedName);
|
|
225
|
+
disposeRef.current.push(result.dispose);
|
|
226
|
+
}
|
|
227
|
+
if (nameMap.size === 0) nameMap = null;
|
|
228
|
+
}
|
|
229
|
+
for (const chunk of processedChunks) if (chunk.renderResult.rules.length > 0) {
|
|
230
|
+
const { dispose } = inject(nameMap ? chunk.renderResult.rules.map((rule) => ({
|
|
231
|
+
...rule,
|
|
232
|
+
declarations: replaceAnimationNames(rule.declarations, nameMap)
|
|
233
|
+
})) : chunk.renderResult.rules, { cacheKey: chunk.cacheKey });
|
|
234
|
+
disposeRef.current.push(dispose);
|
|
235
|
+
}
|
|
236
|
+
return () => {
|
|
237
|
+
disposeRef.current.forEach((dispose) => dispose?.());
|
|
238
|
+
disposeRef.current = [];
|
|
239
|
+
};
|
|
240
|
+
}, [processedChunks]);
|
|
241
|
+
return { className: useMemo(() => {
|
|
242
|
+
return processedChunks.map((chunk) => chunk.className).join(" ");
|
|
243
|
+
}, [processedChunks]) };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
export { useStyles };
|
|
248
|
+
//# sourceMappingURL=useStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStyles.js","names":[],"sources":["../../src/hooks/useStyles.ts"],"sourcesContent":["import { useContext, useInsertionEffect, useMemo, useRef } from 'react';\n\nimport {\n categorizeStyleKeys,\n CHUNK_NAMES,\n generateChunkCacheKey,\n renderStylesForChunk,\n} from '../chunks';\nimport { getConfig, getGlobalKeyframes, hasGlobalKeyframes } from '../config';\nimport { allocateClassName, inject, keyframes, property } from '../injector';\nimport type { KeyframesSteps } from '../injector/types';\nimport {\n extractAnimationNamesFromStyles,\n extractLocalKeyframes,\n filterUsedKeyframes,\n hasLocalKeyframes,\n mergeKeyframes,\n replaceAnimationNames,\n} from '../keyframes';\nimport type { RenderResult } from '../pipeline';\nimport { extractLocalProperties, hasLocalProperties } from '../properties';\nimport { collectAutoInferredProperties } from '../ssr/collect-auto-properties';\nimport type { ServerStyleCollector } from '../ssr/collector';\nimport { TastySSRContext } from '../ssr/context';\nimport { formatKeyframesCSS } from '../ssr/format-keyframes';\nimport { formatPropertyCSS } from '../ssr/format-property';\nimport { getRegisteredSSRCollector } from '../ssr/ssr-collector-ref';\nimport type { Styles } from '../styles/types';\nimport { resolveRecipes } from '../utils/resolve-recipes';\nimport { stringifyStyles } from '../utils/styles';\n\n/**\n * Check if styles contain @starting-style rules.\n *\n * @starting-style CSS cannot be applied via multiple class names because\n * of cascade - later rules override earlier ones. When @starting is detected,\n * we combine top-level styles into a single chunk but keep sub-element styles\n * in their own chunk for better caching.\n */\nfunction containsStartingStyle(styleKey: string): boolean {\n return styleKey.includes('@starting');\n}\n\n/**\n * Tasty styles object to generate CSS classes for.\n * Can be undefined or empty object for no styles.\n */\nexport type UseStylesOptions = Styles | undefined;\n\nexport interface UseStylesResult {\n /**\n * Generated className(s) to apply to the element.\n * Can be empty string if no styles are provided.\n * With chunking enabled, may contain multiple space-separated class names.\n */\n className: string;\n}\n\n/**\n * Information about a processed chunk\n */\ninterface ProcessedChunk {\n name: string;\n styleKeys: string[];\n cacheKey: string;\n renderResult: RenderResult;\n className: string;\n}\n\n/**\n * Render, cache-key, and allocate a className for a single chunk.\n * Returns a ProcessedChunk, or null if the chunk produces no CSS rules.\n *\n * Always runs the pipeline and calls allocateClassName. The inject()\n * call in useInsertionEffect handles all edge cases: placeholders from\n * abandoned concurrent renders, hydration hits (ruleIndex -2), and\n * runtime cache hits (already injected). The pipeline's own LRU cache\n * makes repeated calls for identical styles cheap.\n */\nfunction processChunk(\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);\n if (renderResult.rules.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const { className } = allocateClassName(cacheKey);\n\n return { name: chunkName, styleKeys, cacheKey, renderResult, className };\n}\n\n/**\n * Merge chunk map entries for @starting-style partial chunking.\n *\n * All non-subcomponent chunks are merged into a single COMBINED entry,\n * while SUBCOMPONENTS stays separate. This preserves CSS cascade for\n * @starting-style while still allowing sub-element styles to cache independently.\n */\nfunction mergeChunksForStartingStyle(\n chunkMap: Map<string, string[]>,\n): Map<string, string[]> {\n const merged = new Map<string, string[]>();\n const combinedKeys: string[] = [];\n\n for (const [chunkName, keys] of chunkMap) {\n if (chunkName === CHUNK_NAMES.SUBCOMPONENTS) {\n merged.set(CHUNK_NAMES.SUBCOMPONENTS, keys);\n } else {\n combinedKeys.push(...keys);\n }\n }\n\n if (combinedKeys.length > 0) {\n // Insert COMBINED first so it appears before SUBCOMPONENTS\n const result = new Map<string, string[]>();\n result.set(CHUNK_NAMES.COMBINED, combinedKeys);\n for (const [k, v] of merged) {\n result.set(k, v);\n }\n return result;\n }\n\n return merged;\n}\n\n/**\n * Get keyframes that are actually used in styles.\n * Returns null if no keyframes are used (fast path for zero overhead).\n *\n * Optimization order:\n * 1. Check if any keyframes are defined (local or global) - if not, return null\n * 2. Extract animation names from styles - if none, return null\n * 3. Merge and filter keyframes to only used ones\n */\nfunction getUsedKeyframes(\n styles: Styles,\n): Record<string, KeyframesSteps> | null {\n // Fast path: no keyframes defined anywhere\n const hasLocal = hasLocalKeyframes(styles);\n const hasGlobal = hasGlobalKeyframes();\n if (!hasLocal && !hasGlobal) return null;\n\n // Extract animation names from styles (not from rendered CSS - faster)\n const usedNames = extractAnimationNamesFromStyles(styles);\n if (usedNames.size === 0) return null;\n\n // Merge local and global keyframes\n const local = hasLocal ? extractLocalKeyframes(styles) : null;\n const global = hasGlobal ? getGlobalKeyframes() : null;\n const allKeyframes = mergeKeyframes(local, global);\n\n // Filter to only used keyframes\n return filterUsedKeyframes(allKeyframes, usedNames);\n}\n\n/**\n * Resolve the SSR collector from React context or AsyncLocalStorage.\n * Returns null on the client (no collector available).\n */\nfunction resolveSSRCollector(\n reactContext: ServerStyleCollector | null,\n): ServerStyleCollector | null {\n if (reactContext) return reactContext;\n\n const alsCollector = getRegisteredSSRCollector();\n if (alsCollector) return alsCollector;\n\n return null;\n}\n\n/**\n * Process a chunk on the SSR path: allocate via collector, render, collect CSS.\n * Returns null if the chunk produces no CSS rules.\n */\nfunction processChunkSSR(\n collector: ServerStyleCollector,\n styles: Styles,\n chunkName: string,\n styleKeys: string[],\n): ProcessedChunk | null {\n if (styleKeys.length === 0) return null;\n\n const cacheKey = generateChunkCacheKey(styles, chunkName, styleKeys);\n const { className, isNewAllocation } = collector.allocateClassName(cacheKey);\n\n if (isNewAllocation) {\n const renderResult = renderStylesForChunk(styles, chunkName, styleKeys);\n if (renderResult.rules.length > 0) {\n collector.collectChunk(cacheKey, className, renderResult.rules);\n return {\n name: chunkName,\n styleKeys,\n cacheKey,\n renderResult,\n className,\n };\n }\n return null;\n }\n\n return {\n name: chunkName,\n styleKeys,\n cacheKey,\n renderResult: { rules: [] },\n className,\n };\n}\n\n/**\n * Hook to generate CSS classes from Tasty styles.\n * Handles style rendering, className allocation, and CSS injection.\n *\n * SSR-aware: when a ServerStyleCollector is available (via React context\n * or AsyncLocalStorage), CSS is collected during the render phase instead\n * of being injected into the DOM. useInsertionEffect does not run on the\n * server, so the collector path is the only active path during SSR.\n *\n * Uses chunking to split styles into logical groups for better caching\n * and CSS reuse across components.\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { className } = useStyles({\n * padding: '2x',\n * fill: '#purple',\n * radius: '1r',\n * });\n *\n * return <div className={className}>Styled content</div>;\n * }\n * ```\n */\nexport function useStyles(styles: UseStylesOptions): UseStylesResult {\n const ssrContextValue = useContext(TastySSRContext);\n const ssrCollector = resolveSSRCollector(ssrContextValue);\n\n // Array of dispose functions for each chunk\n const disposeRef = useRef<(() => void)[]>([]);\n\n // Store styles by their stringified key to avoid recomputing when only reference changes\n const stylesRef = useRef<{ key: string; styles: Styles | undefined }>({\n key: '',\n styles: undefined,\n });\n\n // Resolve recipes before any processing (zero overhead if no recipes configured)\n const resolvedStyles = useMemo(() => {\n if (!styles) return styles;\n return resolveRecipes(styles);\n }, [styles]);\n\n // Compute style key - this is a primitive string that captures style content\n const styleKey = useMemo(() => {\n if (!resolvedStyles || Object.keys(resolvedStyles).length === 0) {\n return '';\n }\n return stringifyStyles(resolvedStyles);\n }, [resolvedStyles]);\n\n // Update ref when styleKey changes (content actually changed)\n if (stylesRef.current.key !== styleKey) {\n stylesRef.current = { key: styleKey, styles: resolvedStyles };\n }\n\n // Process chunks: categorize, generate cache keys, render, and allocate classNames\n // Only depends on styleKey (primitive), not styles object reference\n const processedChunks: ProcessedChunk[] = useMemo(() => {\n const currentStyles = stylesRef.current.styles;\n if (!styleKey || !currentStyles) {\n return [];\n }\n\n // Categorize style keys into chunks\n let chunkMap = categorizeStyleKeys(\n currentStyles as Record<string, unknown>,\n );\n\n // Partial chunking for styles containing @starting-style rules.\n // @starting-style CSS cannot work with multiple class names due to cascade,\n // so we merge all top-level chunks into one but keep sub-element styles separate.\n if (containsStartingStyle(styleKey)) {\n chunkMap = mergeChunksForStartingStyle(chunkMap);\n }\n\n const chunks: ProcessedChunk[] = [];\n\n if (ssrCollector) {\n // Ensure internal @property and :root token CSS is included\n ssrCollector.collectInternals();\n\n // SERVER PATH: allocate via collector, collect CSS\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunkSSR(\n ssrCollector,\n currentStyles,\n chunkName,\n chunkStyleKeys,\n );\n if (chunk) chunks.push(chunk);\n }\n\n // Collect keyframes on the server\n const usedKeyframes = getUsedKeyframes(currentStyles);\n if (usedKeyframes) {\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const css = formatKeyframesCSS(name, steps);\n ssrCollector.collectKeyframes(name, css);\n }\n }\n\n // Collect explicit @property rules on the server\n if (hasLocalProperties(currentStyles)) {\n const localProperties = extractLocalProperties(currentStyles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n const css = formatPropertyCSS(token, definition);\n if (css) {\n ssrCollector.collectProperty(token, css);\n }\n }\n }\n }\n\n // Auto-infer @property types from rendered declarations (SSR).\n // On the client this happens inside StyleInjector.inject(), which\n // runs in useInsertionEffect and therefore never executes on the server.\n if (getConfig().autoPropertyTypes !== false) {\n const allRules = chunks.flatMap((c) => c.renderResult.rules);\n if (allRules.length > 0) {\n collectAutoInferredProperties(allRules, ssrCollector, currentStyles);\n }\n }\n } else {\n // CLIENT PATH: unchanged behavior\n for (const [chunkName, chunkStyleKeys] of chunkMap) {\n const chunk = processChunk(currentStyles, chunkName, chunkStyleKeys);\n if (chunk) chunks.push(chunk);\n }\n }\n\n return chunks;\n }, [styleKey]);\n\n // Inject styles in insertion effect (avoids render phase side effects).\n // Does NOT run on the server — the SSR path above handles collection.\n useInsertionEffect(() => {\n // Cleanup all previous disposals\n disposeRef.current.forEach((dispose) => dispose?.());\n disposeRef.current = [];\n\n // Fast path: no chunks to inject\n if (processedChunks.length === 0) {\n return;\n }\n\n const currentStyles = stylesRef.current.styles;\n\n // Register explicit @properties first so they take precedence over auto-inference\n // that happens during keyframe and style chunk injection.\n // Token formats: $name → --name, #name → --name-color (with auto syntax: '<color>')\n // Note: Global properties are injected once when styles are first generated (see markStylesGenerated)\n if (currentStyles && hasLocalProperties(currentStyles)) {\n const localProperties = extractLocalProperties(currentStyles);\n if (localProperties) {\n for (const [token, definition] of Object.entries(localProperties)) {\n property(token, definition);\n }\n }\n }\n\n // Get keyframes that are actually used (returns null if none - zero overhead)\n const usedKeyframes = currentStyles\n ? getUsedKeyframes(currentStyles)\n : null;\n\n // Inject keyframes and build name map (only if we have keyframes)\n let nameMap: Map<string, string> | null = null;\n\n if (usedKeyframes) {\n nameMap = new Map();\n for (const [name, steps] of Object.entries(usedKeyframes)) {\n const result = keyframes(steps, { name });\n const injectedName = result.toString();\n // Only add to map if name differs (optimization for replacement check)\n if (injectedName !== name) {\n nameMap.set(name, injectedName);\n }\n disposeRef.current.push(result.dispose);\n }\n // Clear map if no replacements needed\n if (nameMap.size === 0) {\n nameMap = null;\n }\n }\n\n // Inject each chunk\n for (const chunk of processedChunks) {\n if (chunk.renderResult.rules.length > 0) {\n // Replace animation names only if needed\n const rulesToInject = nameMap\n ? chunk.renderResult.rules.map((rule) => ({\n ...rule,\n declarations: replaceAnimationNames(rule.declarations, nameMap!),\n }))\n : chunk.renderResult.rules;\n\n const { dispose } = inject(rulesToInject, {\n cacheKey: chunk.cacheKey,\n });\n disposeRef.current.push(dispose);\n }\n }\n\n return () => {\n disposeRef.current.forEach((dispose) => dispose?.());\n disposeRef.current = [];\n };\n }, [processedChunks]);\n\n // Combine all chunk classNames\n const className = useMemo(() => {\n return processedChunks.map((chunk) => chunk.className).join(' ');\n }, [processedChunks]);\n\n return {\n className,\n };\n}\n"],"mappings":"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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { CacheMetrics, DisposeFunction, InjectResult, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, PropertyDefinition, RawCSSResult, RootRegistry, RuleInfo, SheetInfo, StyleInjectorConfig, StyleRule } from "./injector/types.js";
|
|
2
|
+
import { CSSProperties } from "./utils/css-types.js";
|
|
3
|
+
import { Bucket, ParserOptions, ProcessedStyle, StyleDetails, StyleDetailsPart, UnitHandler } from "./parser/types.js";
|
|
4
|
+
import { StyleParser } from "./parser/parser.js";
|
|
5
|
+
import { AtRuleContext, ParsedAdvancedState, StateParserContext, createStateParserContext, getGlobalPredefinedStates, setGlobalPredefinedStates } from "./states/index.js";
|
|
6
|
+
import { COMPUTE_FUNC_MAP, CSSMap, CUSTOM_UNITS, ComputeModel, DIRECTIONS, ParsedColor, RawStyleHandler, STATE_OPERATORS, STATE_OPERATOR_LIST, StyleHandler, StyleHandlerDefinition, StyleHandlerResult, StyleMap, StylePropValue, StyleStateData, StyleStateDataList, StyleStateDataListMap, StyleStateMap, StyleValue, StyleValueStateMap, buildAtRuleContext, computeState, customFunc, extendStyles, extractStyles, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, getRgbValuesFromRgbaString, hexToRgb, isAdvancedStateToken, normalizeColorTokenValue, parseColor, parseStateNotation, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleStateMapToStyleStateDataList } from "./utils/styles.js";
|
|
7
|
+
import { ConfigTokenValue, ConfigTokens, NoType, NotSelector, RecipeStyles, Selector, Styles, StylesInterface, StylesWithoutSelectors, SuffixForSelector, TastyNamedColors, TastyPresetNames } from "./styles/types.js";
|
|
8
|
+
import { ConditionNode } from "./pipeline/conditions.js";
|
|
9
|
+
import { ParseStateKeyOptions, parseStateKey } from "./pipeline/parseStateKey.js";
|
|
10
|
+
import { RenderResult, StyleResult, isSelector, renderStyles } from "./pipeline/index.js";
|
|
11
|
+
import { SheetManager } from "./injector/sheet-manager.js";
|
|
12
|
+
import { StyleInjector } from "./injector/injector.js";
|
|
13
|
+
import { TastyPlugin, TastyPluginFactory } from "./plugins/types.js";
|
|
14
|
+
import { TastyConfig, configure, getConfig, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig } from "./config.js";
|
|
15
|
+
import { okhslFunc, okhslPlugin } from "./plugins/okhsl-plugin.js";
|
|
16
|
+
import { CHUNK_NAMES, ChunkInfo, ChunkName, STYLE_TO_CHUNK, categorizeStyleKeys } from "./chunks/definitions.js";
|
|
17
|
+
import { PropertyOptions, allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef } from "./injector/index.js";
|
|
18
|
+
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";
|
|
19
|
+
import { AllBaseProps, BaseProps, BasePropsWithoutChildren, BaseStyleProps, BlockInnerStyleProps, BlockOuterStyleProps, BlockStyleProps, ColorStyleProps, ContainerStyleProps, DimensionStyleProps, FlowStyleProps, GlobalStyledProps, InnerStyleProps, ModValue, Mods, OuterStyleProps, PositionStyleProps, Props, ShortGridStyles, TagName, TastyExtensionConfig, TastyThemeNames, TextStyleProps, TokenValue, Tokens } from "./types.js";
|
|
20
|
+
import { AllBasePropsWithMods, Element, ElementsDefinition, SubElementDefinition, SubElementProps, TastyElementOptions, TastyElementProps, TastyProps, VariantMap, WithVariant, tasty } from "./tasty.js";
|
|
21
|
+
import { UseStylesOptions, UseStylesResult, useStyles } from "./hooks/useStyles.js";
|
|
22
|
+
import { useGlobalStyles } from "./hooks/useGlobalStyles.js";
|
|
23
|
+
import { useRawCSS } from "./hooks/useRawCSS.js";
|
|
24
|
+
import { useKeyframes } from "./hooks/useKeyframes.js";
|
|
25
|
+
import { UsePropertyOptions, useProperty } from "./hooks/useProperty.js";
|
|
26
|
+
import { getDisplayName } from "./utils/get-display-name.js";
|
|
27
|
+
import { styleHandlers } from "./styles/predefined.js";
|
|
28
|
+
import { filterBaseProps } from "./utils/filter-base-props.js";
|
|
29
|
+
import { color } from "./utils/colors.js";
|
|
30
|
+
import { _modAttrs } from "./utils/mod-attrs.js";
|
|
31
|
+
import { dotize } from "./utils/dotize.js";
|
|
32
|
+
import { mergeStyles } from "./utils/merge-styles.js";
|
|
33
|
+
import { resolveRecipes } from "./utils/resolve-recipes.js";
|
|
34
|
+
import { deprecationWarning, warn } from "./utils/warnings.js";
|
|
35
|
+
import { hslToRgbValues, processTokens, stringifyTokens } from "./utils/process-tokens.js";
|
|
36
|
+
import { TypographyPreset, generateTypographyTokens } from "./utils/typography.js";
|
|
37
|
+
import { tastyDebug } from "./debug.js";
|
|
38
|
+
import "./core/index.js";
|
|
39
|
+
import { CSSProperties as CSSProperties$1 } from "react";
|
|
40
|
+
|
|
41
|
+
//#region src/index.d.ts
|
|
42
|
+
declare module './utils/css-types' {
|
|
43
|
+
interface CSSProperties extends CSSProperties$1 {}
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { type AllBaseProps, type AllBasePropsWithMods, AtRuleContext, BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, type BaseProps, type BasePropsWithoutChildren, BaseStyleProps, BlockInnerStyleProps, BlockOuterStyleProps, BlockStyleProps, Bucket, CHUNK_NAMES, COLOR_STYLES, COMPUTE_FUNC_MAP, CONTAINER_STYLES, CSSMap, CSSProperties, CUSTOM_UNITS, CacheMetrics, ChunkInfo, ChunkName, ColorStyleProps, ComputeModel, ConditionNode, ConfigTokenValue, ConfigTokens, ContainerStyleProps, DIMENSION_STYLES, DIRECTIONS, DimensionStyleProps, DisposeFunction, Element, type ElementsDefinition, FLOW_STYLES, FlowStyleProps, GlobalStyledProps, INNER_STYLES, InjectResult, InnerStyleProps, KeyframesCacheEntry, KeyframesInfo, KeyframesResult, KeyframesSteps, ModValue, Mods, NoType, NotSelector, OUTER_STYLES, OuterStyleProps, POSITION_STYLES, ParseStateKeyOptions, ParsedAdvancedState, ParsedColor, ParserOptions, PositionStyleProps, ProcessedStyle, PropertyDefinition, PropertyOptions, Props, RawCSSResult, RawStyleHandler, RecipeStyles, RenderResult, RootRegistry, RuleInfo, STATE_OPERATORS, STATE_OPERATOR_LIST, STYLE_TO_CHUNK, Selector, SheetInfo, SheetManager, ShortGridStyles, StateParserContext, StyleDetails, StyleDetailsPart, StyleHandler, StyleHandlerDefinition, StyleHandlerResult, StyleInjector, StyleInjectorConfig, StyleMap, StyleParser, StylePropValue, StyleResult, StyleRule, StyleStateData, StyleStateDataList, StyleStateDataListMap, StyleStateMap, StyleValue, StyleValueStateMap, Styles, StylesInterface, StylesWithoutSelectors, type SubElementDefinition, type SubElementProps, SuffixForSelector, TEXT_STYLES, TagName, TastyConfig, type TastyElementOptions, type TastyElementProps, TastyExtensionConfig, TastyNamedColors, TastyPlugin, TastyPluginFactory, TastyPresetNames, type TastyProps, TastyThemeNames, TextStyleProps, TokenValue, Tokens, TypographyPreset, UnitHandler, type UsePropertyOptions, type UseStylesOptions, type UseStylesResult, type VariantMap, type WithVariant, allocateClassName, buildAtRuleContext, categorizeStyleKeys, cleanup, color, computeState, configure, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, extendStyles, extractStyles, filterBaseProps, filterMods, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isAdvancedStateToken, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStateNotation, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, stringifyTokens, styleHandlers, styleStateMapToStyleStateDataList, tasty, tastyDebug, trackRef, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Bucket } from "./parser/types.js";
|
|
2
|
+
import { StyleParser } from "./parser/parser.js";
|
|
3
|
+
import { okhslFunc, okhslPlugin } from "./plugins/okhsl-plugin.js";
|
|
4
|
+
import { createStateParserContext, getGlobalPredefinedStates, setGlobalPredefinedStates } from "./states/index.js";
|
|
5
|
+
import { hslToRgbValues, processTokens, stringifyTokens } from "./utils/process-tokens.js";
|
|
6
|
+
import { COMPUTE_FUNC_MAP, CUSTOM_UNITS, DIRECTIONS, STATE_OPERATORS, STATE_OPERATOR_LIST, buildAtRuleContext, computeState, customFunc, extendStyles, extractStyles, filterMods, getGlobalFuncs, getGlobalParser, getGlobalPredefinedTokens, getRgbValuesFromRgbaString, hexToRgb, isAdvancedStateToken, normalizeColorTokenValue, parseColor, parseStateNotation, parseStyle, resetGlobalPredefinedTokens, setGlobalPredefinedTokens, strToRgb, stringifyStyles, styleStateMapToStyleStateDataList } from "./utils/styles.js";
|
|
7
|
+
import { deprecationWarning, warn } from "./utils/warnings.js";
|
|
8
|
+
import { styleHandlers } from "./styles/predefined.js";
|
|
9
|
+
import { SheetManager } from "./injector/sheet-manager.js";
|
|
10
|
+
import { StyleInjector } from "./injector/injector.js";
|
|
11
|
+
import { parseStateKey } from "./pipeline/parseStateKey.js";
|
|
12
|
+
import { isSelector, renderStyles } from "./pipeline/index.js";
|
|
13
|
+
import { configure, getConfig, getGlobalKeyframes, getGlobalRecipes, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, isConfigLocked, isTestEnvironment, resetConfig } from "./config.js";
|
|
14
|
+
import { CHUNK_NAMES, STYLE_TO_CHUNK, categorizeStyleKeys } from "./chunks/definitions.js";
|
|
15
|
+
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 { allocateClassName, cleanup, createInjector, destroy, getCssText, getCssTextForNode, getIsTestEnvironment, getRawCSSText, inject, injectGlobal, injectRawCSS, injector, isPropertyDefined, keyframes, property, trackRef } from "./injector/index.js";
|
|
17
|
+
import { filterBaseProps } from "./utils/filter-base-props.js";
|
|
18
|
+
import { color } from "./utils/colors.js";
|
|
19
|
+
import { _modAttrs } from "./utils/mod-attrs.js";
|
|
20
|
+
import { dotize } from "./utils/dotize.js";
|
|
21
|
+
import { mergeStyles } from "./utils/merge-styles.js";
|
|
22
|
+
import { resolveRecipes } from "./utils/resolve-recipes.js";
|
|
23
|
+
import { generateTypographyTokens } from "./utils/typography.js";
|
|
24
|
+
import { tastyDebug } from "./debug.js";
|
|
25
|
+
import { useStyles } from "./hooks/useStyles.js";
|
|
26
|
+
import { getDisplayName } from "./utils/get-display-name.js";
|
|
27
|
+
import { Element, tasty } from "./tasty.js";
|
|
28
|
+
import { useGlobalStyles } from "./hooks/useGlobalStyles.js";
|
|
29
|
+
import { useRawCSS } from "./hooks/useRawCSS.js";
|
|
30
|
+
import { useKeyframes } from "./hooks/useKeyframes.js";
|
|
31
|
+
import { useProperty } from "./hooks/useProperty.js";
|
|
32
|
+
|
|
33
|
+
export { BASE_STYLES, BLOCK_INNER_STYLES, BLOCK_OUTER_STYLES, BLOCK_STYLES, Bucket, CHUNK_NAMES, COLOR_STYLES, COMPUTE_FUNC_MAP, CONTAINER_STYLES, CUSTOM_UNITS, DIMENSION_STYLES, DIRECTIONS, Element, FLOW_STYLES, INNER_STYLES, OUTER_STYLES, POSITION_STYLES, STATE_OPERATORS, STATE_OPERATOR_LIST, STYLE_TO_CHUNK, SheetManager, StyleInjector, StyleParser, TEXT_STYLES, allocateClassName, buildAtRuleContext, categorizeStyleKeys, cleanup, color, computeState, configure, createInjector, createStateParserContext, customFunc, deprecationWarning, destroy, dotize, extendStyles, extractStyles, filterBaseProps, filterMods, generateTypographyTokens, getConfig, getCssText, getCssTextForNode, getDisplayName, getGlobalFuncs, getGlobalKeyframes, getGlobalParser, getGlobalPredefinedStates, getGlobalPredefinedTokens, getGlobalRecipes, getIsTestEnvironment, getRawCSSText, getRgbValuesFromRgbaString, hasGlobalKeyframes, hasGlobalRecipes, hasStylesGenerated, hexToRgb, hslToRgbValues, inject, injectGlobal, injectRawCSS, injector, isAdvancedStateToken, isConfigLocked, isPropertyDefined, isSelector, isTestEnvironment, keyframes, mergeStyles, _modAttrs as modAttrs, normalizeColorTokenValue, okhslFunc, okhslPlugin, parseColor, parseStateKey, parseStateNotation, parseStyle, processTokens, property, renderStyles, resetConfig, resetGlobalPredefinedTokens, resolveRecipes, setGlobalPredefinedStates, setGlobalPredefinedTokens, strToRgb, stringifyStyles, stringifyTokens, styleHandlers, styleStateMapToStyleStateDataList, tasty, tastyDebug, trackRef, useGlobalStyles, useKeyframes, useProperty, useRawCSS, useStyles, warn };
|