@tenphi/tasty 0.0.0-snapshot.fafcbfe → 0.0.0-snapshot.fc19da9
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 +497 -266
- package/dist/babel-types-DpUCD2L_.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-BDLYGmKn.js +60 -0
- package/dist/chunks/build-config-BDLYGmKn.js.map +1 -0
- package/dist/chunks/collector-DqcB0UUT.js +210 -0
- package/dist/chunks/collector-DqcB0UUT.js.map +1 -0
- package/dist/chunks/config-engine-CGIMO2PV.js +272 -0
- package/dist/chunks/config-engine-CGIMO2PV.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-BibU6ZnP.js +904 -0
- package/dist/chunks/css-definitions-BibU6ZnP.js.map +1 -0
- package/dist/chunks/css-resources-P7IBUUZs.js +142 -0
- package/dist/chunks/css-resources-P7IBUUZs.js.map +1 -0
- package/dist/chunks/debug-BzYPQ0H2.js +502 -0
- package/dist/chunks/debug-BzYPQ0H2.js.map +1 -0
- package/dist/chunks/dsl-DRhFWQzo.js +1378 -0
- package/dist/chunks/dsl-DRhFWQzo.js.map +1 -0
- package/dist/chunks/hydration-TRcz5vnk.js +41 -0
- package/dist/chunks/hydration-TRcz5vnk.js.map +1 -0
- package/dist/chunks/react-runtime-B2e-Wha-.js +689 -0
- package/dist/chunks/react-runtime-B2e-Wha-.js.map +1 -0
- package/dist/chunks/runtime-engine-yeyCAx2e.js +2431 -0
- package/dist/chunks/runtime-engine-yeyCAx2e.js.map +1 -0
- package/dist/chunks/runtime-state-C0u1jp-Q.js +141 -0
- package/dist/chunks/runtime-state-C0u1jp-Q.js.map +1 -0
- package/dist/{utils/merge-styles.js → chunks/shared-utils-y-HjvPN4.js} +61 -58
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-D35rvcdB.js +5420 -0
- package/dist/chunks/style-engine-D35rvcdB.js.map +1 -0
- package/dist/chunks/zero-engine-DpkieEPZ.js +310 -0
- package/dist/chunks/zero-engine-DpkieEPZ.js.map +1 -0
- package/dist/collector-D4POJ53X.d.ts +164 -0
- package/dist/config-DvPUj4cw.d.ts +1364 -0
- package/dist/core/index.d.ts +5 -33
- package/dist/core/index.js +9 -26
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/index-DC4q-xDq.d.ts +1946 -0
- package/dist/index.d.ts +5 -40
- package/dist/index.js +11 -33
- package/dist/{utils/merge-styles.d.ts → merge-styles-Jb5iZ-Jf.d.ts} +3 -4
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +6 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware-extract-static.d.ts +10 -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 +10 -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 +17 -0
- package/dist/ssr/astro-middleware-static.js +7 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +18 -0
- package/dist/ssr/astro-middleware.js +7 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +127 -0
- package/dist/ssr/astro.js +221 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +17 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +60 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/static/index.d.ts +90 -5
- package/dist/static/index.js +31 -4
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +4 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/types-ZbF2_6LV.d.ts +1567 -0
- package/dist/zero/babel.d.ts +49 -90
- package/dist/zero/babel.js +252 -119
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +117 -3
- package/dist/zero/index.js +23 -3
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +58 -33
- package/dist/zero/next.js +89 -59
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +42 -0
- package/docs/adoption.md +331 -0
- package/docs/ai-agents.md +252 -0
- package/docs/comparison.md +449 -0
- package/docs/configuration.md +943 -0
- package/docs/debug.md +333 -0
- package/docs/design-system.md +557 -0
- package/docs/dsl.md +1093 -0
- package/docs/getting-started.md +297 -0
- package/docs/injector.md +633 -0
- package/docs/methodology.md +673 -0
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +768 -0
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +703 -0
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +630 -0
- package/docs/styles.md +725 -0
- package/docs/tasty-static.md +659 -0
- package/package.json +238 -50
- package/tasty.config.ts +6 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -70
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -260
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/renderChunk.js +0 -61
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -280
- package/dist/config.js +0 -403
- package/dist/config.js.map +0 -1
- package/dist/debug.d.ts +0 -204
- package/dist/debug.js +0 -733
- package/dist/debug.js.map +0 -1
- package/dist/hooks/useGlobalStyles.d.ts +0 -27
- package/dist/hooks/useGlobalStyles.js +0 -56
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -54
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -91
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -28
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -40
- package/dist/hooks/useStyles.js +0 -169
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -157
- package/dist/injector/index.js +0 -154
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -139
- package/dist/injector/injector.js +0 -404
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -127
- package/dist/injector/sheet-manager.js +0 -714
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -135
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -319
- 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 -400
- 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 -641
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -908
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -430
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -557
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -371
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -69
- package/dist/properties/index.js +0 -158
- package/dist/properties/index.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -416
- 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 -23
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -77
- 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 -44
- package/dist/styles/fill.js +0 -51
- 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 -73
- package/dist/styles/predefined.js +0 -241
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -47
- package/dist/styles/preset.js +0 -126
- 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 -21
- package/dist/styles/scrollbar.js +0 -105
- 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/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.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 -498
- 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 -982
- package/dist/tasty.js +0 -191
- package/dist/tasty.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -26
- 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/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -9
- 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/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.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/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -31
- package/dist/utils/process-tokens.js +0 -171
- 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/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -183
- package/dist/utils/styles.js +0 -585
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -36
- package/dist/utils/typography.js +0 -53
- 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 +0 -150
- package/dist/zero/extractor.js.map +0 -1
package/dist/zero/babel.d.ts
CHANGED
|
@@ -1,108 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StyleDetails, UnitHandler } from "../parser/types.js";
|
|
3
|
-
import { StyleHandlerDefinition } from "../utils/styles.js";
|
|
4
|
-
import { RecipeStyles } from "../styles/types.js";
|
|
5
|
-
import { TastyPlugin } from "../plugins/types.js";
|
|
6
|
-
import * as _babel_core0 from "@babel/core";
|
|
1
|
+
import { t as TastyZeroConfig } from "../babel-types-DpUCD2L_.js";
|
|
7
2
|
import { PluginPass } from "@babel/core";
|
|
8
|
-
|
|
9
3
|
//#region src/zero/babel.d.ts
|
|
10
4
|
/**
|
|
11
|
-
*
|
|
12
|
-
* Subset of TastyConfig that applies at build time.
|
|
5
|
+
* Options for the `@tenphi/tasty/babel-plugin` Babel plugin.
|
|
13
6
|
*/
|
|
14
|
-
interface
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
* Example: { '@mobile': '@media(w < 768px)', '@dark': '@root(theme=dark)' }
|
|
18
|
-
*/
|
|
19
|
-
states?: Record<string, string>;
|
|
20
|
-
/**
|
|
21
|
-
* Enable development mode features: source comments in generated CSS.
|
|
22
|
-
* Default: false
|
|
23
|
-
*/
|
|
24
|
-
devMode?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Parser LRU cache size (default: 1000).
|
|
27
|
-
* Larger values improve performance for builds with many unique style values.
|
|
28
|
-
*/
|
|
29
|
-
parserCacheSize?: number;
|
|
30
|
-
/**
|
|
31
|
-
* Custom units for the style parser (merged with built-in units).
|
|
32
|
-
* Units transform numeric values like `2x` → `calc(2 * var(--gap))`.
|
|
33
|
-
* @example { em: 'em', vw: 'vw', custom: (n) => `${n * 10}px` }
|
|
34
|
-
*/
|
|
35
|
-
units?: Record<string, string | UnitHandler>;
|
|
7
|
+
export interface TastyZeroBabelOptions {
|
|
8
|
+
/** Output path for generated CSS (default: 'tasty.css') */
|
|
9
|
+
output?: string;
|
|
36
10
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
11
|
+
* Tasty configuration for build-time processing.
|
|
12
|
+
* Can be a static object or a factory function that returns fresh config.
|
|
13
|
+
* A factory is called on each plugin invocation, enabling hot reload
|
|
14
|
+
* of config values that depend on external files (e.g. theme tokens).
|
|
40
15
|
*/
|
|
41
|
-
|
|
16
|
+
config?: TastyZeroConfig | (() => TastyZeroConfig);
|
|
42
17
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { okhslPlugin } from '@tenphi/tasty';
|
|
18
|
+
* Absolute path to a TypeScript/JavaScript module that default-exports
|
|
19
|
+
* a `TastyZeroConfig` object. The module is loaded via jiti on each
|
|
20
|
+
* plugin invocation, enabling hot reload when the file changes.
|
|
48
21
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* };
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
plugins?: TastyPlugin[];
|
|
60
|
-
/**
|
|
61
|
-
* Global keyframes definitions for static extraction.
|
|
62
|
-
* Keys are animation names, values are keyframes step definitions.
|
|
63
|
-
* @example { fadeIn: { from: { opacity: 0 }, to: { opacity: 1 } } }
|
|
22
|
+
* This option is JSON-serializable and is the primary way Turbopack
|
|
23
|
+
* passes config to the Babel plugin (since Turbopack loader options
|
|
24
|
+
* must be plain primitives/objects/arrays).
|
|
25
|
+
*
|
|
26
|
+
* When both `config` and `configFile` are set, `config` takes precedence.
|
|
27
|
+
*
|
|
28
|
+
* @example '/absolute/path/to/tasty-zero.config.ts'
|
|
64
29
|
*/
|
|
65
|
-
|
|
30
|
+
configFile?: string;
|
|
66
31
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* elevation: ({ elevation }) => ({
|
|
74
|
-
* 'box-shadow': `0 ${elevation}px ${elevation * 2}px rgba(0,0,0,0.1)`,
|
|
75
|
-
* }),
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
32
|
+
* Absolute file paths whose content affects the generated CSS.
|
|
33
|
+
* When any of these files change, babel-loader invalidates its cache
|
|
34
|
+
* and re-runs the plugin with fresh config values.
|
|
35
|
+
*
|
|
36
|
+
* Typically includes theme files that define Glaze palettes or token values.
|
|
37
|
+
* Paths must be absolute (resolved by the Next.js wrapper).
|
|
78
38
|
*/
|
|
79
|
-
|
|
39
|
+
configDeps?: string[];
|
|
80
40
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
41
|
+
* Automatically replace `@tenphi/tasty/static` imports with an import
|
|
42
|
+
* of the generated CSS file. This eliminates the need for users to
|
|
43
|
+
* manually import the CSS in their app entry point.
|
|
44
|
+
*
|
|
45
|
+
* @default true
|
|
84
46
|
*/
|
|
85
|
-
|
|
47
|
+
injectImport?: boolean;
|
|
86
48
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
49
|
+
* Output mode for extracted CSS.
|
|
50
|
+
*
|
|
51
|
+
* - `'file'` (default): CSS is written to a single output file and
|
|
52
|
+
* the `@tenphi/tasty/static` import is rewritten to import that file.
|
|
53
|
+
* - `'inject'`: CSS is embedded inline in the JS output and injected
|
|
54
|
+
* at runtime via a tiny injector from `@tenphi/tasty/static/inject`.
|
|
55
|
+
* No CSS file is written. Each `tastyStatic` call becomes
|
|
56
|
+
* self-contained. Best for reusable components and extensions.
|
|
57
|
+
*
|
|
58
|
+
* When `mode` is `'inject'`, `output` and `injectImport` are ignored.
|
|
59
|
+
*
|
|
60
|
+
* @default 'file'
|
|
96
61
|
*/
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
interface TastyZeroBabelOptions {
|
|
100
|
-
/** Output path for generated CSS (default: 'tasty.css') */
|
|
101
|
-
output?: string;
|
|
102
|
-
/** Tasty configuration for build-time processing */
|
|
103
|
-
config?: TastyZeroConfig;
|
|
62
|
+
mode?: 'file' | 'inject';
|
|
104
63
|
}
|
|
105
|
-
declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) =>
|
|
64
|
+
declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => import("@babel/core").PluginObj<PluginPass>;
|
|
106
65
|
//#endregion
|
|
107
|
-
export {
|
|
66
|
+
export { type TastyZeroConfig, _default as default };
|
|
108
67
|
//# sourceMappingURL=babel.d.ts.map
|
package/dist/zero/babel.js
CHANGED
|
@@ -1,58 +1,158 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { CSSWriter } from "
|
|
1
|
+
import { t as mergeStyles } from "../chunks/shared-utils-y-HjvPN4.js";
|
|
2
|
+
import "../chunks/css-definitions-BibU6ZnP.js";
|
|
3
|
+
import { t as resolveRecipesWith } from "../chunks/config-engine-CGIMO2PV.js";
|
|
4
|
+
import { a as resetZeroConfig, i as reapplyZeroConfig, n as functionsForExtraction, t as configureZero } from "../chunks/build-config-BDLYGmKn.js";
|
|
5
|
+
import { a as extractCounterStyleFromStyles, c as extractKeyframesFromStyles, h as setExtractorNamePrefix, i as extractConfigProperties, l as extractPropertiesFromStyles, m as replaceAnimationNamesInCSS, o as extractFontFaceFromStyles, p as renderSelectorCSS, r as extractChunks, s as extractFunctionsFromStyles, t as CSSWriter, u as extractSelectorCSS } from "../chunks/zero-engine-DpkieEPZ.js";
|
|
6
|
+
import { t as loadConfigFile } from "../chunks/config-file-DlZXJMj8.js";
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as path from "path";
|
|
6
9
|
import { declare } from "@babel/helper-plugin-utils";
|
|
7
10
|
import * as t from "@babel/types";
|
|
8
|
-
|
|
11
|
+
//#region \0rolldown/runtime.js
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
13
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
14
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/zero/writer-cache.ts
|
|
18
|
+
const writerCache = /* @__PURE__ */ new Map();
|
|
19
|
+
//#endregion
|
|
9
20
|
//#region src/zero/babel.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
function mtime(filePath) {
|
|
22
|
+
try {
|
|
23
|
+
return fs.statSync(filePath).mtimeMs;
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function clearRequireCacheTree(filePath) {
|
|
29
|
+
let resolved;
|
|
30
|
+
try {
|
|
31
|
+
resolved = __require.resolve(filePath);
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const mod = __require.cache[resolved];
|
|
36
|
+
if (!mod) return;
|
|
37
|
+
const dir = resolved.substring(0, resolved.lastIndexOf("/"));
|
|
38
|
+
if (mod.children) {
|
|
39
|
+
for (const child of mod.children) if (child.id.startsWith(dir) && !child.id.includes("node_modules")) clearRequireCacheTree(child.id);
|
|
40
|
+
}
|
|
41
|
+
delete __require.cache[resolved];
|
|
42
|
+
}
|
|
28
43
|
var babel_default = declare((api, options) => {
|
|
29
44
|
api.assertVersion(7);
|
|
45
|
+
const mode = options.mode ?? "file";
|
|
30
46
|
const outputPath = options.output || "tasty.css";
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
const resolvedOutputPath = path.resolve(outputPath);
|
|
48
|
+
const injectImport = options.injectImport ?? true;
|
|
49
|
+
if (mode === "file" && injectImport) {
|
|
50
|
+
const dir = path.dirname(resolvedOutputPath);
|
|
51
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
52
|
+
if (!fs.existsSync(resolvedOutputPath)) fs.writeFileSync(resolvedOutputPath, "/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\n");
|
|
53
|
+
}
|
|
54
|
+
const configDeps = [...options.configFile ? [options.configFile] : [], ...options.configDeps || []];
|
|
55
|
+
const configKey = configDeps.length > 0 ? configDeps.map(mtime).join(",") : "";
|
|
56
|
+
if (configDeps.length > 0) {
|
|
57
|
+
api.cache.using(() => configKey);
|
|
58
|
+
for (const dep of configDeps) try {
|
|
59
|
+
api.addExternalDependency(dep);
|
|
60
|
+
} catch {}
|
|
61
|
+
} else api.cache.forever();
|
|
62
|
+
if (configDeps.length > 0) for (const dep of configDeps) clearRequireCacheTree(dep);
|
|
63
|
+
const cached = writerCache.get(resolvedOutputPath);
|
|
64
|
+
if (!cached || cached.configKey !== configKey) {
|
|
65
|
+
const configOption = options.config;
|
|
66
|
+
let resolvedConfig;
|
|
67
|
+
if (configOption) resolvedConfig = typeof configOption === "function" ? configOption() : configOption;
|
|
68
|
+
else if (options.configFile) resolvedConfig = loadConfigFile(options.configFile);
|
|
69
|
+
else resolvedConfig = {};
|
|
70
|
+
const devMode = resolvedConfig.devMode ?? false;
|
|
71
|
+
resetZeroConfig();
|
|
72
|
+
const finalConfig = {
|
|
73
|
+
namePrefix: "ts",
|
|
74
|
+
...resolvedConfig
|
|
75
|
+
};
|
|
76
|
+
const config = configureZero(finalConfig);
|
|
77
|
+
setExtractorNamePrefix(finalConfig.namePrefix ?? "ts");
|
|
78
|
+
const newWriter = new CSSWriter(outputPath, { devMode });
|
|
79
|
+
if (mode !== "inject") {
|
|
80
|
+
for (const prop of extractConfigProperties(config.normalized.properties)) newWriter.add(`@property:${prop.name}`, prop.css);
|
|
81
|
+
const tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
82
|
+
if (tokenCSS) newWriter.add(":root:tokens", tokenCSS);
|
|
83
|
+
for (const [selector, styles] of Object.entries(config.normalized.globalStyles)) writeGlobalStyles(newWriter, selector, styles, config.normalized.keyframes);
|
|
84
|
+
}
|
|
85
|
+
writerCache.set(resolvedOutputPath, {
|
|
86
|
+
writer: newWriter,
|
|
87
|
+
configKey,
|
|
88
|
+
registry: {},
|
|
89
|
+
config
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const entry = writerCache.get(resolvedOutputPath);
|
|
93
|
+
entry.config = reapplyZeroConfig(entry.config);
|
|
94
|
+
const cssWriter = entry.writer;
|
|
95
|
+
const globalRegistry = entry.registry;
|
|
96
|
+
const config = entry.config;
|
|
97
|
+
const sourceConfig = config.source;
|
|
98
|
+
const devMode = sourceConfig.devMode ?? false;
|
|
99
|
+
setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
|
|
100
|
+
const configProperties = extractConfigProperties(config.normalized.properties);
|
|
101
|
+
const propertyOptions = {
|
|
102
|
+
autoPropertyTypes: sourceConfig.autoPropertyTypes,
|
|
103
|
+
defined: new Set(configProperties.map((prop) => prop.name))
|
|
104
|
+
};
|
|
105
|
+
let propertyCSS;
|
|
106
|
+
let tokenCSS;
|
|
107
|
+
let globalStylesCSS;
|
|
108
|
+
if (mode === "inject") {
|
|
109
|
+
propertyCSS = configProperties.map((prop) => prop.css).join("\n") || void 0;
|
|
110
|
+
tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
111
|
+
const gs = config.normalized.globalStyles;
|
|
112
|
+
if (Object.keys(gs).length > 0) {
|
|
113
|
+
globalStylesCSS = /* @__PURE__ */ new Map();
|
|
114
|
+
for (const [selector, styles] of Object.entries(gs)) {
|
|
115
|
+
const css = extractCSSFromStyles(selector, styles, config.normalized.keyframes);
|
|
116
|
+
if (css) globalStylesCSS.set(selector, css);
|
|
117
|
+
}
|
|
118
|
+
if (globalStylesCSS.size === 0) globalStylesCSS = void 0;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
36
121
|
return {
|
|
37
122
|
name: "tasty-zero",
|
|
38
123
|
pre() {
|
|
124
|
+
entry.config = reapplyZeroConfig(entry.config);
|
|
125
|
+
setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
|
|
39
126
|
this.staticStyleRegistry = {};
|
|
127
|
+
this._fileAddedCSS = false;
|
|
40
128
|
if (devMode && this.filename) this.sourceFile = this.filename.split("/").pop() || this.filename;
|
|
41
129
|
},
|
|
42
130
|
visitor: {
|
|
43
|
-
ImportDeclaration(
|
|
44
|
-
const source =
|
|
45
|
-
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static"))
|
|
131
|
+
ImportDeclaration(nodePath, state) {
|
|
132
|
+
const source = nodePath.node.source.value;
|
|
133
|
+
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) {
|
|
134
|
+
if (mode === "inject") nodePath.replaceWith(t.importDeclaration([t.importSpecifier(t.identifier("_$i"), t.identifier("injectCSS"))], t.stringLiteral("@tenphi/tasty/static/inject")));
|
|
135
|
+
else if (injectImport) {
|
|
136
|
+
let importPath = resolvedOutputPath;
|
|
137
|
+
if (state.filename) {
|
|
138
|
+
const sourceDir = path.dirname(state.filename);
|
|
139
|
+
importPath = path.relative(sourceDir, resolvedOutputPath);
|
|
140
|
+
if (!importPath.startsWith(".")) importPath = "./" + importPath;
|
|
141
|
+
}
|
|
142
|
+
nodePath.replaceWith(t.importDeclaration([], t.stringLiteral(importPath)));
|
|
143
|
+
} else nodePath.remove();
|
|
144
|
+
}
|
|
46
145
|
},
|
|
47
146
|
CallExpression(path, state) {
|
|
48
147
|
const callee = path.node.callee;
|
|
49
148
|
if (!t.isIdentifier(callee, { name: "tastyStatic" })) return;
|
|
149
|
+
state._fileAddedCSS = true;
|
|
50
150
|
const args = path.node.arguments;
|
|
51
151
|
if (args.length === 0) throw path.buildCodeFrameError("tastyStatic() requires at least one argument");
|
|
52
152
|
const firstArg = args[0];
|
|
53
|
-
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, state.sourceFile, config.keyframes);
|
|
54
|
-
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, config.keyframes);
|
|
55
|
-
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, config.keyframes);
|
|
153
|
+
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
154
|
+
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
155
|
+
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
56
156
|
else throw path.buildCodeFrameError("tastyStatic() first argument must be an object (styles), identifier (base StaticStyle), or string (selector)");
|
|
57
157
|
},
|
|
58
158
|
VariableDeclarator(path, state) {
|
|
@@ -76,55 +176,69 @@ var babel_default = declare((api, options) => {
|
|
|
76
176
|
}
|
|
77
177
|
},
|
|
78
178
|
post() {
|
|
79
|
-
if (
|
|
179
|
+
if (mode === "inject") {
|
|
180
|
+
if (this._fileAddedCSS && (propertyCSS || tokenCSS || globalStylesCSS)) {
|
|
181
|
+
const program = this.file.ast.program;
|
|
182
|
+
let insertIndex = 0;
|
|
183
|
+
for (let i = 0; i < program.body.length; i++) if (t.isImportDeclaration(program.body[i])) insertIndex = i + 1;
|
|
184
|
+
if (propertyCSS) {
|
|
185
|
+
const injectCall = createInjectCallAST("@property", propertyCSS);
|
|
186
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
187
|
+
insertIndex++;
|
|
188
|
+
}
|
|
189
|
+
if (tokenCSS) {
|
|
190
|
+
const injectCall = createInjectCallAST(":root", tokenCSS);
|
|
191
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
192
|
+
insertIndex++;
|
|
193
|
+
}
|
|
194
|
+
if (globalStylesCSS) for (const [selector, css] of globalStylesCSS) {
|
|
195
|
+
const injectCall = createInjectCallAST(selector, css);
|
|
196
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
197
|
+
insertIndex++;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (this._fileAddedCSS && cssWriter.size > 0) cssWriter.write();
|
|
80
203
|
}
|
|
81
204
|
};
|
|
82
205
|
});
|
|
83
|
-
/**
|
|
84
|
-
* Check if an object expression looks like a StaticStyle object
|
|
85
|
-
*/
|
|
86
206
|
function isStaticStyleObject(node) {
|
|
87
207
|
const hasClassName = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "className" }));
|
|
88
208
|
const hasStyles = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "styles" }));
|
|
89
209
|
return hasClassName && hasStyles;
|
|
90
210
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Extract styles object from a StaticStyle object expression
|
|
93
|
-
*/
|
|
94
211
|
function extractStylesFromStaticStyleObject(node, path) {
|
|
95
212
|
for (const prop of node.properties) if (t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "styles" }) && t.isObjectExpression(prop.value)) return evaluateObjectExpression(prop.value, path);
|
|
96
213
|
return null;
|
|
97
214
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Extract className from a StaticStyle object expression
|
|
100
|
-
*/
|
|
101
215
|
function extractClassNameFromStaticStyleObject(node) {
|
|
102
216
|
for (const prop of node.properties) if (t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "className" }) && t.isStringLiteral(prop.value)) return prop.value.value;
|
|
103
217
|
return null;
|
|
104
218
|
}
|
|
105
|
-
|
|
106
|
-
* Handle tastyStatic(styles) - returns StaticStyle object
|
|
107
|
-
*/
|
|
108
|
-
function handleStylesMode(path, args, cssWriter, state, globalRegistry, globalKeyframes) {
|
|
219
|
+
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
109
220
|
const stylesArg = args[0];
|
|
110
221
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(styles) argument must be a static object literal");
|
|
111
|
-
const
|
|
222
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
223
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
112
224
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
225
|
+
const properties = extractPropertiesFromStyles(styles, propertyOptions);
|
|
226
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
227
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
228
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
229
|
+
const chunks = extractChunks(styles);
|
|
119
230
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
120
231
|
const staticStyleObject = createStaticStyleAST(className, styles);
|
|
121
|
-
|
|
232
|
+
if (mode === "inject") {
|
|
233
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
234
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
235
|
+
} else {
|
|
236
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
237
|
+
path.replaceWith(staticStyleObject);
|
|
238
|
+
}
|
|
122
239
|
registerIfVariableDeclaration(path, className, styles, state, globalRegistry);
|
|
123
240
|
}
|
|
124
|
-
|
|
125
|
-
* Handle tastyStatic(base, styles) - extends base with additional styles
|
|
126
|
-
*/
|
|
127
|
-
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globalKeyframes) {
|
|
241
|
+
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
128
242
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(base, styles) requires two arguments");
|
|
129
243
|
const baseArg = args[0];
|
|
130
244
|
const stylesArg = args[1];
|
|
@@ -134,42 +248,94 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globa
|
|
|
134
248
|
const baseEntry = state.staticStyleRegistry[baseName] || globalRegistry[baseName];
|
|
135
249
|
if (!baseEntry) throw path.buildCodeFrameError(`Cannot find base StaticStyle '${baseName}'. Make sure it is defined before being extended.`);
|
|
136
250
|
const overrideStyles = evaluateObjectExpression(stylesArg, path);
|
|
137
|
-
const mergedStyles =
|
|
251
|
+
const mergedStyles = resolveRecipesWith(mergeStyles(baseEntry.styles, overrideStyles), globalRecipes ?? null);
|
|
138
252
|
const { keyframes, nameMap } = extractKeyframesFromStyles(mergedStyles, globalKeyframes);
|
|
139
|
-
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
253
|
+
const properties = extractPropertiesFromStyles(mergedStyles, propertyOptions);
|
|
254
|
+
const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);
|
|
255
|
+
const counterStyles = extractCounterStyleFromStyles(mergedStyles, globalCounterStyle);
|
|
256
|
+
const functions = extractFunctionsFromStyles(mergedStyles, globalFunction);
|
|
257
|
+
const chunks = extractChunks(mergedStyles);
|
|
145
258
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
146
259
|
const staticStyleObject = createStaticStyleAST(className, mergedStyles);
|
|
147
|
-
|
|
260
|
+
if (mode === "inject") {
|
|
261
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
262
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
263
|
+
} else {
|
|
264
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
265
|
+
path.replaceWith(staticStyleObject);
|
|
266
|
+
}
|
|
148
267
|
registerIfVariableDeclaration(path, className, mergedStyles, state, globalRegistry);
|
|
149
268
|
}
|
|
150
|
-
|
|
151
|
-
* Handle tastyStatic(selector, styles) - removes the call entirely
|
|
152
|
-
*/
|
|
153
|
-
function handleSelectorMode(path, args, cssWriter, sourceFile, globalKeyframes) {
|
|
269
|
+
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
154
270
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(selector, styles) requires two arguments");
|
|
155
271
|
const selectorArg = args[0];
|
|
156
272
|
const stylesArg = args[1];
|
|
157
273
|
if (!t.isStringLiteral(selectorArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) first argument must be a string literal");
|
|
158
274
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) second argument must be a static object literal");
|
|
159
275
|
const selector = selectorArg.value;
|
|
160
|
-
const
|
|
276
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
277
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
161
278
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
279
|
+
const properties = extractPropertiesFromStyles(styles, propertyOptions);
|
|
280
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
281
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
282
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
283
|
+
const css = renderSelectorCSS(selector, styles);
|
|
284
|
+
const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(css, nameMap) : css;
|
|
285
|
+
if (mode === "inject") {
|
|
286
|
+
const cssParts = [];
|
|
287
|
+
for (const kf of keyframes) cssParts.push(kf.css);
|
|
288
|
+
for (const prop of properties) cssParts.push(prop.css);
|
|
289
|
+
for (const ff of fontFaces) cssParts.push(ff.css);
|
|
290
|
+
for (const cs of counterStyles) cssParts.push(cs.css);
|
|
291
|
+
for (const fn of functions) cssParts.push(fn.css);
|
|
292
|
+
cssParts.push(selectorCSS);
|
|
293
|
+
const injectCall = createInjectCallAST(selector, cssParts.join("\n"));
|
|
294
|
+
const parent = path.parentPath;
|
|
295
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.replaceWith(t.expressionStatement(injectCall));
|
|
296
|
+
else path.replaceWith(injectCall);
|
|
297
|
+
} else {
|
|
298
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, [], nameMap, sourceFile);
|
|
299
|
+
cssWriter.add(selector, selectorCSS, sourceFile);
|
|
300
|
+
const parent = path.parentPath;
|
|
301
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.remove();
|
|
302
|
+
else path.replaceWith(t.identifier("undefined"));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap) {
|
|
306
|
+
const parts = [];
|
|
307
|
+
for (const kf of keyframes) parts.push(kf.css);
|
|
308
|
+
for (const prop of properties) parts.push(prop.css);
|
|
309
|
+
for (const ff of fontFaces) parts.push(ff.css);
|
|
310
|
+
for (const cs of counterStyles) parts.push(cs.css);
|
|
311
|
+
for (const fn of functions) parts.push(fn.css);
|
|
312
|
+
for (const chunk of chunks) parts.push(nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css);
|
|
313
|
+
return parts.join("\n");
|
|
314
|
+
}
|
|
315
|
+
function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, sourceFile) {
|
|
162
316
|
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
cssWriter.add(
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
317
|
+
for (const prop of properties) cssWriter.add(prop.css, prop.css, sourceFile);
|
|
318
|
+
for (const ff of fontFaces) cssWriter.add(ff.css, ff.css, sourceFile);
|
|
319
|
+
for (const cs of counterStyles) cssWriter.add(cs.css, cs.css, sourceFile);
|
|
320
|
+
for (const fn of functions) cssWriter.add(fn.css, fn.css, sourceFile);
|
|
321
|
+
for (const chunk of chunks) {
|
|
322
|
+
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
323
|
+
cssWriter.add(chunk.className, css, sourceFile);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function extractCSSFromStyles(selector, styles, globalKeyframes) {
|
|
327
|
+
if (!styles || Object.keys(styles).length === 0) return void 0;
|
|
328
|
+
return extractSelectorCSS(selector, styles, globalKeyframes) || void 0;
|
|
329
|
+
}
|
|
330
|
+
function writeGlobalStyles(cssWriter, selector, styles, globalKeyframes) {
|
|
331
|
+
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
332
|
+
for (const kf of keyframes) cssWriter.add(kf.css, kf.css);
|
|
333
|
+
const css = replaceAnimationNamesInCSS(renderSelectorCSS(selector, styles), nameMap);
|
|
334
|
+
if (css) cssWriter.add(`global:${selector}`, css);
|
|
335
|
+
}
|
|
336
|
+
function createInjectCallAST(id, css) {
|
|
337
|
+
return t.callExpression(t.identifier("_$i"), [t.stringLiteral(id), t.stringLiteral(css)]);
|
|
169
338
|
}
|
|
170
|
-
/**
|
|
171
|
-
* Create a StaticStyle object AST node
|
|
172
|
-
*/
|
|
173
339
|
function createStaticStyleAST(className, styles) {
|
|
174
340
|
return t.objectExpression([
|
|
175
341
|
t.objectProperty(t.identifier("className"), t.stringLiteral(className)),
|
|
@@ -177,9 +343,6 @@ function createStaticStyleAST(className, styles) {
|
|
|
177
343
|
t.objectMethod("method", t.identifier("toString"), [], t.blockStatement([t.returnStatement(t.memberExpression(t.thisExpression(), t.identifier("className")))]))
|
|
178
344
|
]);
|
|
179
345
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Register a StaticStyle in the registry if it's being assigned to a variable
|
|
182
|
-
*/
|
|
183
346
|
function registerIfVariableDeclaration(path, className, styles, state, globalRegistry) {
|
|
184
347
|
const parent = path.parentPath;
|
|
185
348
|
if (parent && t.isVariableDeclarator(parent.node)) {
|
|
@@ -197,9 +360,6 @@ function registerIfVariableDeclaration(path, className, styles, state, globalReg
|
|
|
197
360
|
}
|
|
198
361
|
}
|
|
199
362
|
}
|
|
200
|
-
/**
|
|
201
|
-
* Convert a JavaScript value to an AST node
|
|
202
|
-
*/
|
|
203
363
|
function valueToAST(value) {
|
|
204
364
|
if (value === null) return t.nullLiteral();
|
|
205
365
|
if (value === void 0) return t.identifier("undefined");
|
|
@@ -213,10 +373,6 @@ function valueToAST(value) {
|
|
|
213
373
|
}
|
|
214
374
|
return t.identifier("undefined");
|
|
215
375
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Evaluate an ObjectExpression to a plain JavaScript object.
|
|
218
|
-
* Only supports static values that can be determined at build time.
|
|
219
|
-
*/
|
|
220
376
|
function evaluateObjectExpression(node, path) {
|
|
221
377
|
const result = {};
|
|
222
378
|
for (const prop of node.properties) {
|
|
@@ -226,13 +382,11 @@ function evaluateObjectExpression(node, path) {
|
|
|
226
382
|
if (t.isIdentifier(prop.key)) key = prop.key.name;
|
|
227
383
|
else if (t.isStringLiteral(prop.key)) key = prop.key.value;
|
|
228
384
|
else throw path.buildCodeFrameError("Dynamic property keys are not supported in tastyStatic()");
|
|
229
|
-
|
|
385
|
+
const value = evaluateExpression(prop.value, path);
|
|
386
|
+
result[key] = value;
|
|
230
387
|
}
|
|
231
388
|
return result;
|
|
232
389
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Evaluate an expression to a JavaScript value.
|
|
235
|
-
*/
|
|
236
390
|
function evaluateExpression(node, path) {
|
|
237
391
|
if (t.isStringLiteral(node)) return node.value;
|
|
238
392
|
if (t.isNumericLiteral(node)) return node.value;
|
|
@@ -255,28 +409,7 @@ function evaluateExpression(node, path) {
|
|
|
255
409
|
}
|
|
256
410
|
throw path.buildCodeFrameError(`Dynamic expressions are not supported in tastyStatic() - got ${node.type}. All values must be static literals.`);
|
|
257
411
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Replace animation names in CSS string.
|
|
260
|
-
* Wraps the keyframes replaceAnimationNames to work on full CSS blocks.
|
|
261
|
-
*/
|
|
262
|
-
function replaceAnimationNamesInCSS(css, nameMap) {
|
|
263
|
-
if (nameMap.size === 0) return css;
|
|
264
|
-
return css.replace(/(animation(?:-name)?)\s*:\s*([^;}]+)/gi, (match, prop, value) => {
|
|
265
|
-
let newValue = value;
|
|
266
|
-
for (const [original, replacement] of nameMap) {
|
|
267
|
-
const pattern = new RegExp(`\\b${escapeRegex(original)}\\b`, "g");
|
|
268
|
-
newValue = newValue.replace(pattern, replacement);
|
|
269
|
-
}
|
|
270
|
-
return `${prop}: ${newValue}`;
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Escape special regex characters.
|
|
275
|
-
*/
|
|
276
|
-
function escapeRegex(str) {
|
|
277
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
278
|
-
}
|
|
279
|
-
|
|
280
412
|
//#endregion
|
|
281
413
|
export { babel_default as default };
|
|
414
|
+
|
|
282
415
|
//# sourceMappingURL=babel.js.map
|