@tenphi/tasty 0.0.0-snapshot.bae20d4 → 0.0.0-snapshot.bbd36bd
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 +309 -293
- package/dist/astro-CeYENy2x.js +301 -0
- package/dist/astro-CeYENy2x.js.map +1 -0
- package/dist/{ssr/async-storage.js → async-storage-DKK-wTD4.js} +17 -8
- package/dist/async-storage-DKK-wTD4.js.map +1 -0
- package/dist/babel-DWCsafYw.d.ts +83 -0
- package/dist/collector-B3OsM252.js +327 -0
- package/dist/collector-B3OsM252.js.map +1 -0
- package/dist/collector-BTVXj2hS.d.ts +163 -0
- package/dist/config-B3gPdCqd.js +12421 -0
- package/dist/config-B3gPdCqd.js.map +1 -0
- package/dist/config-LfIDmVHx.d.ts +1363 -0
- package/dist/context-CA8YKeMn.js +24 -0
- package/dist/context-CA8YKeMn.js.map +1 -0
- package/dist/core/index.d.ts +5 -34
- package/dist/core/index.js +6 -27
- package/dist/core-DGm0CFHP.js +1732 -0
- package/dist/core-DGm0CFHP.js.map +1 -0
- package/dist/css-resources-Cyl_axbI.js +149 -0
- package/dist/css-resources-Cyl_axbI.js.map +1 -0
- package/dist/{zero/extractor.js → css-writer-Bgowobbx.js} +188 -13
- package/dist/css-writer-Bgowobbx.js.map +1 -0
- package/dist/{ssr/format-global-rules.js → format-global-rules-DklyaXv-.js} +3 -3
- package/dist/format-global-rules-DklyaXv-.js.map +1 -0
- package/dist/{ssr/format-rules.js → format-rules-XRw9u7d4.js} +41 -7
- package/dist/format-rules-XRw9u7d4.js.map +1 -0
- package/dist/hydrate-CNOmZprz.js +37 -0
- package/dist/hydrate-CNOmZprz.js.map +1 -0
- package/dist/index-Bm9ltvdH.d.ts +1933 -0
- package/dist/index-BmogEzTo.d.ts +1575 -0
- package/dist/index.d.ts +5 -49
- package/dist/index.js +921 -33
- package/dist/index.js.map +1 -0
- package/dist/keyframes-DE-OE76F.js +535 -0
- package/dist/keyframes-DE-OE76F.js.map +1 -0
- package/dist/{utils/merge-styles.d.ts → merge-styles-BcLl1u_d.d.ts} +3 -3
- package/dist/{utils/merge-styles.js → merge-styles-DuoZEsm9.js} +4 -6
- package/dist/merge-styles-DuoZEsm9.js.map +1 -0
- package/dist/{utils/resolve-recipes.js → resolve-recipes-H9NqOQuP.js} +5 -8
- package/dist/resolve-recipes-H9NqOQuP.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware-extract-static.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract-static.js +9 -0
- package/dist/ssr/astro-middleware-extract-static.js.map +1 -0
- package/dist/ssr/astro-middleware-extract.d.ts +11 -0
- package/dist/ssr/astro-middleware-extract.js +9 -0
- package/dist/ssr/astro-middleware-extract.js.map +1 -0
- package/dist/ssr/astro-middleware-static.d.ts +18 -0
- package/dist/ssr/astro-middleware-static.js +18 -0
- package/dist/ssr/astro-middleware-static.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +19 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +117 -11
- package/dist/ssr/astro.js +2 -65
- package/dist/ssr/index.d.ts +37 -5
- package/dist/ssr/index.js +7 -9
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +66 -0
- package/dist/ssr/next-config.js +115 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +14 -7
- package/dist/ssr/next.js +40 -20
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr-collector-ref-COs_ioWl.js +29 -0
- package/dist/ssr-collector-ref-COs_ioWl.js.map +1 -0
- package/dist/static/index.d.ts +91 -5
- package/dist/static/index.js +49 -4
- package/dist/static/index.js.map +1 -0
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/zero/babel.d.ts +2 -155
- package/dist/zero/babel.js +183 -51
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +81 -3
- package/dist/zero/index.js +2 -4
- package/dist/zero/next.d.ts +13 -1
- package/dist/zero/next.js +6 -5
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +39 -0
- package/docs/adoption.md +72 -35
- package/docs/ai-agents.md +224 -0
- package/docs/comparison.md +88 -53
- package/docs/configuration.md +623 -63
- package/docs/debug.md +172 -342
- package/docs/design-system.md +83 -29
- package/docs/dsl.md +614 -133
- package/docs/getting-started.md +80 -43
- package/docs/injector.md +159 -53
- package/docs/methodology.md +178 -31
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +741 -0
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +681 -0
- package/docs/runtime-benchmarks.md +351 -0
- package/docs/ssr.md +356 -128
- package/docs/styles.md +103 -32
- package/docs/tasty-static.md +227 -65
- package/package.json +83 -22
- package/tasty.config.ts +6 -0
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/chunks/cacheKey.js +0 -78
- package/dist/chunks/cacheKey.js.map +0 -1
- package/dist/chunks/definitions.d.ts +0 -37
- package/dist/chunks/definitions.js +0 -259
- package/dist/chunks/definitions.js.map +0 -1
- package/dist/chunks/renderChunk.js +0 -60
- package/dist/chunks/renderChunk.js.map +0 -1
- package/dist/config.d.ts +0 -323
- package/dist/config.js +0 -465
- 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 -30
- package/dist/hooks/useGlobalStyles.js +0 -83
- package/dist/hooks/useGlobalStyles.js.map +0 -1
- package/dist/hooks/useKeyframes.d.ts +0 -56
- package/dist/hooks/useKeyframes.js +0 -69
- package/dist/hooks/useKeyframes.js.map +0 -1
- package/dist/hooks/useProperty.d.ts +0 -79
- package/dist/hooks/useProperty.js +0 -114
- package/dist/hooks/useProperty.js.map +0 -1
- package/dist/hooks/useRawCSS.d.ts +0 -53
- package/dist/hooks/useRawCSS.js +0 -40
- package/dist/hooks/useRawCSS.js.map +0 -1
- package/dist/hooks/useStyles.d.ts +0 -45
- package/dist/hooks/useStyles.js +0 -249
- package/dist/hooks/useStyles.js.map +0 -1
- package/dist/injector/index.d.ts +0 -165
- package/dist/injector/index.js +0 -162
- package/dist/injector/index.js.map +0 -1
- package/dist/injector/injector.d.ts +0 -148
- package/dist/injector/injector.js +0 -430
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -136
- package/dist/injector/sheet-manager.js +0 -729
- package/dist/injector/sheet-manager.js.map +0 -1
- package/dist/injector/types.d.ts +0 -144
- package/dist/keyframes/index.js +0 -206
- package/dist/keyframes/index.js.map +0 -1
- package/dist/parser/classify.js +0 -320
- package/dist/parser/classify.js.map +0 -1
- package/dist/parser/const.js +0 -33
- package/dist/parser/const.js.map +0 -1
- package/dist/parser/lru.js +0 -109
- package/dist/parser/lru.js.map +0 -1
- package/dist/parser/parser.d.ts +0 -25
- package/dist/parser/parser.js +0 -116
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/tokenizer.js +0 -69
- package/dist/parser/tokenizer.js.map +0 -1
- package/dist/parser/types.d.ts +0 -51
- package/dist/parser/types.js +0 -46
- package/dist/parser/types.js.map +0 -1
- package/dist/pipeline/conditions.d.ts +0 -134
- package/dist/pipeline/conditions.js +0 -406
- package/dist/pipeline/conditions.js.map +0 -1
- package/dist/pipeline/exclusive.js +0 -231
- package/dist/pipeline/exclusive.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -53
- package/dist/pipeline/index.js +0 -670
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -1105
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -447
- package/dist/pipeline/parseStateKey.js.map +0 -1
- package/dist/pipeline/simplify.js +0 -516
- package/dist/pipeline/simplify.js.map +0 -1
- package/dist/pipeline/warnings.js +0 -18
- package/dist/pipeline/warnings.js.map +0 -1
- package/dist/plugins/okhsl-plugin.d.ts +0 -35
- package/dist/plugins/okhsl-plugin.js +0 -98
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -76
- package/dist/properties/index.js +0 -223
- package/dist/properties/index.js.map +0 -1
- package/dist/properties/property-type-resolver.d.ts +0 -24
- package/dist/properties/property-type-resolver.js +0 -91
- package/dist/properties/property-type-resolver.js.map +0 -1
- package/dist/ssr/astro.js.map +0 -1
- package/dist/ssr/async-storage.d.ts +0 -17
- package/dist/ssr/async-storage.js.map +0 -1
- package/dist/ssr/collect-auto-properties.js +0 -40
- package/dist/ssr/collect-auto-properties.js.map +0 -1
- package/dist/ssr/collector.d.ts +0 -85
- package/dist/ssr/collector.js +0 -183
- package/dist/ssr/collector.js.map +0 -1
- package/dist/ssr/context.d.ts +0 -8
- package/dist/ssr/context.js +0 -14
- package/dist/ssr/context.js.map +0 -1
- package/dist/ssr/format-global-rules.js.map +0 -1
- package/dist/ssr/format-keyframes.js +0 -70
- package/dist/ssr/format-keyframes.js.map +0 -1
- package/dist/ssr/format-property.js +0 -50
- package/dist/ssr/format-property.js.map +0 -1
- package/dist/ssr/format-rules.js.map +0 -1
- package/dist/ssr/hydrate.d.ts +0 -22
- package/dist/ssr/hydrate.js +0 -50
- package/dist/ssr/hydrate.js.map +0 -1
- package/dist/ssr/ssr-collector-ref.js +0 -12
- package/dist/ssr/ssr-collector-ref.js.map +0 -1
- package/dist/states/index.d.ts +0 -49
- package/dist/states/index.js +0 -169
- package/dist/states/index.js.map +0 -1
- package/dist/static/tastyStatic.d.ts +0 -46
- package/dist/static/tastyStatic.js +0 -31
- package/dist/static/tastyStatic.js.map +0 -1
- package/dist/static/types.d.ts +0 -49
- package/dist/static/types.js +0 -24
- package/dist/static/types.js.map +0 -1
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/border.d.ts +0 -25
- package/dist/styles/border.js +0 -114
- package/dist/styles/border.js.map +0 -1
- package/dist/styles/color.d.ts +0 -14
- package/dist/styles/color.js +0 -27
- package/dist/styles/color.js.map +0 -1
- package/dist/styles/createStyle.js +0 -80
- package/dist/styles/createStyle.js.map +0 -1
- package/dist/styles/dimension.js +0 -97
- package/dist/styles/dimension.js.map +0 -1
- package/dist/styles/display.d.ts +0 -37
- package/dist/styles/display.js +0 -67
- package/dist/styles/display.js.map +0 -1
- package/dist/styles/fade.d.ts +0 -15
- package/dist/styles/fade.js +0 -58
- package/dist/styles/fade.js.map +0 -1
- package/dist/styles/fill.d.ts +0 -42
- package/dist/styles/fill.js +0 -52
- package/dist/styles/fill.js.map +0 -1
- package/dist/styles/flow.d.ts +0 -16
- package/dist/styles/flow.js +0 -12
- package/dist/styles/flow.js.map +0 -1
- package/dist/styles/gap.d.ts +0 -31
- package/dist/styles/gap.js +0 -37
- package/dist/styles/gap.js.map +0 -1
- package/dist/styles/height.d.ts +0 -17
- package/dist/styles/height.js +0 -20
- package/dist/styles/height.js.map +0 -1
- package/dist/styles/index.d.ts +0 -2
- package/dist/styles/index.js +0 -9
- package/dist/styles/index.js.map +0 -1
- package/dist/styles/inset.d.ts +0 -52
- package/dist/styles/inset.js +0 -150
- package/dist/styles/inset.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/list.d.ts +0 -16
- package/dist/styles/list.js +0 -98
- package/dist/styles/list.js.map +0 -1
- package/dist/styles/margin.d.ts +0 -24
- package/dist/styles/margin.js +0 -104
- package/dist/styles/margin.js.map +0 -1
- package/dist/styles/outline.d.ts +0 -29
- package/dist/styles/outline.js +0 -65
- package/dist/styles/outline.js.map +0 -1
- package/dist/styles/padding.d.ts +0 -24
- package/dist/styles/padding.js +0 -104
- package/dist/styles/padding.js.map +0 -1
- package/dist/styles/predefined.d.ts +0 -71
- package/dist/styles/predefined.js +0 -238
- package/dist/styles/predefined.js.map +0 -1
- package/dist/styles/preset.d.ts +0 -47
- package/dist/styles/preset.js +0 -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 -25
- package/dist/styles/scrollbar.js +0 -48
- package/dist/styles/scrollbar.js.map +0 -1
- package/dist/styles/shadow.d.ts +0 -14
- package/dist/styles/shadow.js +0 -24
- package/dist/styles/shadow.js.map +0 -1
- package/dist/styles/transition.d.ts +0 -14
- package/dist/styles/transition.js +0 -158
- package/dist/styles/transition.js.map +0 -1
- package/dist/styles/types.d.ts +0 -508
- 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 -981
- package/dist/tasty.js +0 -219
- package/dist/tasty.js.map +0 -1
- package/dist/types.d.ts +0 -184
- package/dist/utils/cache-wrapper.js +0 -22
- package/dist/utils/cache-wrapper.js.map +0 -1
- package/dist/utils/case-converter.js +0 -8
- package/dist/utils/case-converter.js.map +0 -1
- package/dist/utils/color-math.d.ts +0 -45
- package/dist/utils/color-math.js +0 -749
- package/dist/utils/color-math.js.map +0 -1
- package/dist/utils/color-space.d.ts +0 -5
- package/dist/utils/color-space.js +0 -228
- package/dist/utils/color-space.js.map +0 -1
- package/dist/utils/colors.d.ts +0 -5
- package/dist/utils/colors.js +0 -11
- package/dist/utils/colors.js.map +0 -1
- package/dist/utils/css-types.d.ts +0 -7
- package/dist/utils/dotize.d.ts +0 -26
- package/dist/utils/dotize.js +0 -122
- package/dist/utils/dotize.js.map +0 -1
- package/dist/utils/filter-base-props.d.ts +0 -15
- package/dist/utils/filter-base-props.js +0 -45
- package/dist/utils/filter-base-props.js.map +0 -1
- package/dist/utils/get-display-name.d.ts +0 -7
- package/dist/utils/get-display-name.js +0 -10
- package/dist/utils/get-display-name.js.map +0 -1
- package/dist/utils/has-keys.js +0 -13
- package/dist/utils/has-keys.js.map +0 -1
- package/dist/utils/is-dev-env.js +0 -19
- package/dist/utils/is-dev-env.js.map +0 -1
- package/dist/utils/is-valid-element-type.js +0 -15
- package/dist/utils/is-valid-element-type.js.map +0 -1
- package/dist/utils/merge-styles.js.map +0 -1
- package/dist/utils/mod-attrs.d.ts +0 -8
- package/dist/utils/mod-attrs.js +0 -21
- package/dist/utils/mod-attrs.js.map +0 -1
- package/dist/utils/process-tokens.d.ts +0 -21
- package/dist/utils/process-tokens.js +0 -91
- package/dist/utils/process-tokens.js.map +0 -1
- package/dist/utils/resolve-recipes.d.ts +0 -17
- package/dist/utils/resolve-recipes.js.map +0 -1
- package/dist/utils/selector-transform.js +0 -32
- package/dist/utils/selector-transform.js.map +0 -1
- package/dist/utils/string.js +0 -8
- package/dist/utils/string.js.map +0 -1
- package/dist/utils/styles.d.ts +0 -101
- package/dist/utils/styles.js +0 -223
- package/dist/utils/styles.js.map +0 -1
- package/dist/utils/typography.d.ts +0 -47
- package/dist/utils/typography.js +0 -43
- package/dist/utils/typography.js.map +0 -1
- package/dist/utils/warnings.d.ts +0 -16
- package/dist/utils/warnings.js +0 -16
- package/dist/utils/warnings.js.map +0 -1
- package/dist/zero/css-writer.d.ts +0 -45
- package/dist/zero/css-writer.js +0 -74
- package/dist/zero/css-writer.js.map +0 -1
- package/dist/zero/extractor.d.ts +0 -24
- package/dist/zero/extractor.js.map +0 -1
- package/docs/PIPELINE.md +0 -519
- package/docs/runtime.md +0 -291
package/dist/zero/babel.d.ts
CHANGED
|
@@ -1,155 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { StyleHandlerDefinition } from "../utils/styles.js";
|
|
4
|
-
import { ConfigTokens, RecipeStyles } from "../styles/types.js";
|
|
5
|
-
import { TastyPlugin } from "../plugins/types.js";
|
|
6
|
-
import * as _babel_core0 from "@babel/core";
|
|
7
|
-
import { PluginPass } from "@babel/core";
|
|
8
|
-
|
|
9
|
-
//#region src/zero/babel.d.ts
|
|
10
|
-
/**
|
|
11
|
-
* Build-time configuration for zero-runtime mode.
|
|
12
|
-
* Subset of TastyConfig that applies at build time.
|
|
13
|
-
*/
|
|
14
|
-
interface TastyZeroConfig {
|
|
15
|
-
/**
|
|
16
|
-
* Global predefined states for advanced state mapping.
|
|
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>;
|
|
36
|
-
/**
|
|
37
|
-
* Custom functions for the style parser (merged with existing).
|
|
38
|
-
* Functions process parsed style groups and return CSS values.
|
|
39
|
-
* @example { myFunc: (groups) => groups.map(g => g.output).join(' ') }
|
|
40
|
-
*/
|
|
41
|
-
funcs?: Record<string, (groups: StyleDetails[]) => string>;
|
|
42
|
-
/**
|
|
43
|
-
* Plugins that extend tasty with custom functions, units, states, and handlers.
|
|
44
|
-
* Plugins are processed in order, with later plugins overriding earlier ones.
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { okhslPlugin } from '@tenphi/tasty';
|
|
48
|
-
*
|
|
49
|
-
* // babel.config.js
|
|
50
|
-
* module.exports = {
|
|
51
|
-
* plugins: [
|
|
52
|
-
* ['@tenphi/tasty/babel-plugin', {
|
|
53
|
-
* config: { plugins: [okhslPlugin()] }
|
|
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 } } }
|
|
64
|
-
*/
|
|
65
|
-
keyframes?: Record<string, KeyframesSteps>;
|
|
66
|
-
/**
|
|
67
|
-
* Custom style handlers that transform style properties into CSS declarations.
|
|
68
|
-
* Handlers replace built-in handlers for the same style name.
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* handlers: {
|
|
72
|
-
* fill: ({ fill }) => fill ? { 'background-color': fill } : undefined,
|
|
73
|
-
* elevation: ({ elevation }) => ({
|
|
74
|
-
* 'box-shadow': `0 ${elevation}px ${elevation * 2}px rgba(0,0,0,0.1)`,
|
|
75
|
-
* }),
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
handlers?: Record<string, StyleHandlerDefinition>;
|
|
80
|
-
/**
|
|
81
|
-
* Design tokens injected as CSS custom properties on `:root`.
|
|
82
|
-
* Values are parsed through the Tasty DSL. Supports state maps.
|
|
83
|
-
* @example { '$gap': '4px', '#primary': { '': '#purple', '@dark': '#light-purple' } }
|
|
84
|
-
*/
|
|
85
|
-
tokens?: ConfigTokens;
|
|
86
|
-
/**
|
|
87
|
-
* Predefined tokens replaced during style parsing (parse-time substitution).
|
|
88
|
-
* Use `$name` for custom properties and `#name` for color tokens.
|
|
89
|
-
* @example { $spacing: '2x', '#accent': '#purple' }
|
|
90
|
-
*/
|
|
91
|
-
replaceTokens?: Record<`$${string}` | `#${string}`, string | number>;
|
|
92
|
-
/**
|
|
93
|
-
* Predefined style recipes -- named style bundles that can be applied via `recipe` style property.
|
|
94
|
-
* Recipe values are flat tasty styles (no sub-element keys).
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* recipes: {
|
|
98
|
-
* card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
99
|
-
* elevated: { shadow: '2x 2x 4x #shadow' },
|
|
100
|
-
* }
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
recipes?: Record<string, RecipeStyles>;
|
|
104
|
-
/**
|
|
105
|
-
* Automatically infer and register CSS @property declarations from values.
|
|
106
|
-
* @default true
|
|
107
|
-
*/
|
|
108
|
-
autoPropertyTypes?: boolean;
|
|
109
|
-
}
|
|
110
|
-
interface TastyZeroBabelOptions {
|
|
111
|
-
/** Output path for generated CSS (default: 'tasty.css') */
|
|
112
|
-
output?: string;
|
|
113
|
-
/**
|
|
114
|
-
* Tasty configuration for build-time processing.
|
|
115
|
-
* Can be a static object or a factory function that returns fresh config.
|
|
116
|
-
* A factory is called on each plugin invocation, enabling hot reload
|
|
117
|
-
* of config values that depend on external files (e.g. theme tokens).
|
|
118
|
-
*/
|
|
119
|
-
config?: TastyZeroConfig | (() => TastyZeroConfig);
|
|
120
|
-
/**
|
|
121
|
-
* Absolute path to a TypeScript/JavaScript module that default-exports
|
|
122
|
-
* a `TastyZeroConfig` object. The module is loaded via jiti on each
|
|
123
|
-
* plugin invocation, enabling hot reload when the file changes.
|
|
124
|
-
*
|
|
125
|
-
* This option is JSON-serializable and is the primary way Turbopack
|
|
126
|
-
* passes config to the Babel plugin (since Turbopack loader options
|
|
127
|
-
* must be plain primitives/objects/arrays).
|
|
128
|
-
*
|
|
129
|
-
* When both `config` and `configFile` are set, `config` takes precedence.
|
|
130
|
-
*
|
|
131
|
-
* @example '/absolute/path/to/tasty-zero.config.ts'
|
|
132
|
-
*/
|
|
133
|
-
configFile?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Absolute file paths whose content affects the generated CSS.
|
|
136
|
-
* When any of these files change, babel-loader invalidates its cache
|
|
137
|
-
* and re-runs the plugin with fresh config values.
|
|
138
|
-
*
|
|
139
|
-
* Typically includes theme files that define Glaze palettes or token values.
|
|
140
|
-
* Paths must be absolute (resolved by the Next.js wrapper).
|
|
141
|
-
*/
|
|
142
|
-
configDeps?: string[];
|
|
143
|
-
/**
|
|
144
|
-
* Automatically replace `@tenphi/tasty/static` imports with an import
|
|
145
|
-
* of the generated CSS file. This eliminates the need for users to
|
|
146
|
-
* manually import the CSS in their app entry point.
|
|
147
|
-
*
|
|
148
|
-
* @default true
|
|
149
|
-
*/
|
|
150
|
-
injectImport?: boolean;
|
|
151
|
-
}
|
|
152
|
-
declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => _babel_core0.PluginObj<PluginPass>;
|
|
153
|
-
//#endregion
|
|
154
|
-
export { TastyZeroBabelOptions, TastyZeroConfig, _default as default };
|
|
155
|
-
//# sourceMappingURL=babel.d.ts.map
|
|
1
|
+
import { n as _default, r as TastyZeroConfig, t as TastyZeroBabelOptions } from "../babel-DWCsafYw.js";
|
|
2
|
+
export { TastyZeroBabelOptions, type TastyZeroConfig, _default as default };
|
package/dist/zero/babel.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { extractKeyframesFromStyles, extractPropertiesFromStyles, extractStylesForSelector, extractStylesWithChunks } from "./extractor.js";
|
|
6
|
-
import { CSSWriter } from "./css-writer.js";
|
|
1
|
+
import { b as resetConfig, d as getGlobalStyles, i as getGlobalConfigTokens, s as getGlobalFunctions, t as configure } from "../config-B3gPdCqd.js";
|
|
2
|
+
import { t as mergeStyles } from "../merge-styles-DuoZEsm9.js";
|
|
3
|
+
import { t as resolveRecipes } from "../resolve-recipes-H9NqOQuP.js";
|
|
4
|
+
import { a as extractFunctionsFromStyles, c as extractStylesForSelector, i as extractFontFaceFromStyles, l as extractStylesWithChunks, o as extractKeyframesFromStyles, r as extractCounterStyleFromStyles, s as extractPropertiesFromStyles, t as CSSWriter, u as setExtractorNamePrefix } from "../css-writer-Bgowobbx.js";
|
|
7
5
|
import * as fs from "fs";
|
|
8
6
|
import * as path from "path";
|
|
9
7
|
import { declare } from "@babel/helper-plugin-utils";
|
|
10
8
|
import * as t from "@babel/types";
|
|
11
9
|
import { createJiti } from "jiti";
|
|
12
|
-
|
|
10
|
+
//#region \0rolldown/runtime.js
|
|
11
|
+
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) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
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.");
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/zero/writer-cache.ts
|
|
17
|
+
const writerCache = /* @__PURE__ */ new Map();
|
|
18
|
+
//#endregion
|
|
13
19
|
//#region src/zero/babel.ts
|
|
14
20
|
/**
|
|
15
21
|
* Babel plugin for zero-runtime tasty static site generation.
|
|
@@ -53,46 +59,90 @@ function clearRequireCacheTree(filePath) {
|
|
|
53
59
|
}
|
|
54
60
|
var babel_default = declare((api, options) => {
|
|
55
61
|
api.assertVersion(7);
|
|
62
|
+
const mode = options.mode ?? "file";
|
|
56
63
|
const outputPath = options.output || "tasty.css";
|
|
57
64
|
const resolvedOutputPath = path.resolve(outputPath);
|
|
58
65
|
const injectImport = options.injectImport ?? true;
|
|
59
|
-
if (injectImport) {
|
|
66
|
+
if (mode === "file" && injectImport) {
|
|
60
67
|
const dir = path.dirname(resolvedOutputPath);
|
|
61
68
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
62
69
|
if (!fs.existsSync(resolvedOutputPath)) fs.writeFileSync(resolvedOutputPath, "/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\n");
|
|
63
70
|
}
|
|
64
71
|
const configDeps = [...options.configFile ? [options.configFile] : [], ...options.configDeps || []];
|
|
72
|
+
const configKey = configDeps.length > 0 ? configDeps.map(mtime).join(",") : "";
|
|
65
73
|
if (configDeps.length > 0) {
|
|
66
|
-
api.cache.using(() =>
|
|
74
|
+
api.cache.using(() => configKey);
|
|
67
75
|
for (const dep of configDeps) try {
|
|
68
76
|
api.addExternalDependency(dep);
|
|
69
77
|
} catch {}
|
|
70
78
|
} else api.cache.forever();
|
|
71
79
|
if (configDeps.length > 0) for (const dep of configDeps) clearRequireCacheTree(dep);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
80
|
+
const cached = writerCache.get(resolvedOutputPath);
|
|
81
|
+
if (!cached || cached.configKey !== configKey) {
|
|
82
|
+
const configOption = options.config;
|
|
83
|
+
let resolvedConfig;
|
|
84
|
+
if (configOption) resolvedConfig = typeof configOption === "function" ? configOption() : configOption;
|
|
85
|
+
else if (options.configFile) {
|
|
86
|
+
const loaded = createJiti(path.dirname(options.configFile), { moduleCache: false })(options.configFile);
|
|
87
|
+
resolvedConfig = loaded && typeof loaded === "object" && "default" in loaded ? loaded.default : loaded;
|
|
88
|
+
} else resolvedConfig = {};
|
|
89
|
+
const devMode = resolvedConfig.devMode ?? false;
|
|
90
|
+
if (cached) resetConfig();
|
|
91
|
+
const finalConfig = {
|
|
92
|
+
namePrefix: "ts",
|
|
93
|
+
...resolvedConfig
|
|
94
|
+
};
|
|
95
|
+
configure(finalConfig);
|
|
96
|
+
setExtractorNamePrefix(finalConfig.namePrefix ?? "ts");
|
|
97
|
+
const newWriter = new CSSWriter(outputPath, { devMode });
|
|
98
|
+
if (mode !== "inject") {
|
|
99
|
+
const tokenCSS = extractCSSFromStyles(":root", getGlobalConfigTokens());
|
|
100
|
+
if (tokenCSS) newWriter.add(":root:tokens", tokenCSS);
|
|
101
|
+
const globalStyles = getGlobalStyles();
|
|
102
|
+
if (globalStyles) for (const [selector, styles] of Object.entries(globalStyles)) {
|
|
103
|
+
const css = extractCSSFromStyles(selector, styles);
|
|
104
|
+
if (css) newWriter.add(`global:${selector}`, css);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
writerCache.set(resolvedOutputPath, {
|
|
108
|
+
writer: newWriter,
|
|
109
|
+
configKey,
|
|
110
|
+
registry: {},
|
|
111
|
+
config: finalConfig
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const entry = writerCache.get(resolvedOutputPath);
|
|
115
|
+
const cssWriter = entry.writer;
|
|
116
|
+
const globalRegistry = entry.registry;
|
|
117
|
+
const config = entry.config;
|
|
77
118
|
const devMode = config.devMode ?? false;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
setExtractorNamePrefix(config.namePrefix ?? "ts");
|
|
120
|
+
let tokenCSS;
|
|
121
|
+
let globalStylesCSS;
|
|
122
|
+
if (mode === "inject") {
|
|
123
|
+
tokenCSS = extractCSSFromStyles(":root", getGlobalConfigTokens());
|
|
124
|
+
const gs = getGlobalStyles();
|
|
125
|
+
if (gs) {
|
|
126
|
+
globalStylesCSS = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const [selector, styles] of Object.entries(gs)) {
|
|
128
|
+
const css = extractCSSFromStyles(selector, styles);
|
|
129
|
+
if (css) globalStylesCSS.set(selector, css);
|
|
130
|
+
}
|
|
131
|
+
if (globalStylesCSS.size === 0) globalStylesCSS = void 0;
|
|
132
|
+
}
|
|
84
133
|
}
|
|
85
|
-
const globalRegistry = {};
|
|
86
134
|
return {
|
|
87
135
|
name: "tasty-zero",
|
|
88
136
|
pre() {
|
|
89
137
|
this.staticStyleRegistry = {};
|
|
138
|
+
this._fileAddedCSS = false;
|
|
90
139
|
if (devMode && this.filename) this.sourceFile = this.filename.split("/").pop() || this.filename;
|
|
91
140
|
},
|
|
92
141
|
visitor: {
|
|
93
142
|
ImportDeclaration(nodePath, state) {
|
|
94
143
|
const source = nodePath.node.source.value;
|
|
95
|
-
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) if (
|
|
144
|
+
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) if (mode === "inject") nodePath.replaceWith(t.importDeclaration([t.importSpecifier(t.identifier("_$i"), t.identifier("injectCSS"))], t.stringLiteral("@tenphi/tasty/static/inject")));
|
|
145
|
+
else if (injectImport) {
|
|
96
146
|
let importPath = resolvedOutputPath;
|
|
97
147
|
if (state.filename) {
|
|
98
148
|
const sourceDir = path.dirname(state.filename);
|
|
@@ -105,12 +155,13 @@ var babel_default = declare((api, options) => {
|
|
|
105
155
|
CallExpression(path, state) {
|
|
106
156
|
const callee = path.node.callee;
|
|
107
157
|
if (!t.isIdentifier(callee, { name: "tastyStatic" })) return;
|
|
158
|
+
state._fileAddedCSS = true;
|
|
108
159
|
const args = path.node.arguments;
|
|
109
160
|
if (args.length === 0) throw path.buildCodeFrameError("tastyStatic() requires at least one argument");
|
|
110
161
|
const firstArg = args[0];
|
|
111
|
-
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, state.sourceFile, config.keyframes, config.autoPropertyTypes);
|
|
112
|
-
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, config.keyframes, config.autoPropertyTypes);
|
|
113
|
-
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, config.keyframes, config.autoPropertyTypes);
|
|
162
|
+
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.keyframes, config.autoPropertyTypes, config.fontFaces, config.counterStyles, getGlobalFunctions() ?? void 0);
|
|
163
|
+
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.autoPropertyTypes, config.fontFaces, config.counterStyles, getGlobalFunctions() ?? void 0);
|
|
164
|
+
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.autoPropertyTypes, config.fontFaces, config.counterStyles, getGlobalFunctions() ?? void 0);
|
|
114
165
|
else throw path.buildCodeFrameError("tastyStatic() first argument must be an object (styles), identifier (base StaticStyle), or string (selector)");
|
|
115
166
|
},
|
|
116
167
|
VariableDeclarator(path, state) {
|
|
@@ -134,7 +185,25 @@ var babel_default = declare((api, options) => {
|
|
|
134
185
|
}
|
|
135
186
|
},
|
|
136
187
|
post() {
|
|
137
|
-
if (
|
|
188
|
+
if (mode === "inject") {
|
|
189
|
+
if (this._fileAddedCSS && (tokenCSS || globalStylesCSS)) {
|
|
190
|
+
const program = this.file.ast.program;
|
|
191
|
+
let insertIndex = 0;
|
|
192
|
+
for (let i = 0; i < program.body.length; i++) if (t.isImportDeclaration(program.body[i])) insertIndex = i + 1;
|
|
193
|
+
if (tokenCSS) {
|
|
194
|
+
const injectCall = createInjectCallAST(":root", tokenCSS);
|
|
195
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
196
|
+
insertIndex++;
|
|
197
|
+
}
|
|
198
|
+
if (globalStylesCSS) for (const [selector, css] of globalStylesCSS) {
|
|
199
|
+
const injectCall = createInjectCallAST(selector, css);
|
|
200
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
201
|
+
insertIndex++;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (this._fileAddedCSS && cssWriter.size > 0) cssWriter.write();
|
|
138
207
|
}
|
|
139
208
|
};
|
|
140
209
|
});
|
|
@@ -163,28 +232,31 @@ function extractClassNameFromStaticStyleObject(node) {
|
|
|
163
232
|
/**
|
|
164
233
|
* Handle tastyStatic(styles) - returns StaticStyle object
|
|
165
234
|
*/
|
|
166
|
-
function handleStylesMode(path, args, cssWriter, state, globalRegistry, globalKeyframes, autoPropertyTypes) {
|
|
235
|
+
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
|
|
167
236
|
const stylesArg = args[0];
|
|
168
237
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(styles) argument must be a static object literal");
|
|
169
238
|
const styles = resolveRecipes(evaluateObjectExpression(stylesArg, path));
|
|
170
239
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
171
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, state.sourceFile);
|
|
172
240
|
const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
|
|
173
|
-
|
|
241
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
242
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
243
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
174
244
|
const chunks = extractStylesWithChunks(styles);
|
|
175
|
-
for (const chunk of chunks) {
|
|
176
|
-
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
177
|
-
cssWriter.add(chunk.className, css, state.sourceFile);
|
|
178
|
-
}
|
|
179
245
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
180
246
|
const staticStyleObject = createStaticStyleAST(className, styles);
|
|
181
|
-
|
|
247
|
+
if (mode === "inject") {
|
|
248
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
249
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
250
|
+
} else {
|
|
251
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
252
|
+
path.replaceWith(staticStyleObject);
|
|
253
|
+
}
|
|
182
254
|
registerIfVariableDeclaration(path, className, styles, state, globalRegistry);
|
|
183
255
|
}
|
|
184
256
|
/**
|
|
185
257
|
* Handle tastyStatic(base, styles) - extends base with additional styles
|
|
186
258
|
*/
|
|
187
|
-
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globalKeyframes, autoPropertyTypes) {
|
|
259
|
+
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
|
|
188
260
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(base, styles) requires two arguments");
|
|
189
261
|
const baseArg = args[0];
|
|
190
262
|
const stylesArg = args[1];
|
|
@@ -196,23 +268,26 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globa
|
|
|
196
268
|
const overrideStyles = evaluateObjectExpression(stylesArg, path);
|
|
197
269
|
const mergedStyles = resolveRecipes(mergeStyles(baseEntry.styles, overrideStyles));
|
|
198
270
|
const { keyframes, nameMap } = extractKeyframesFromStyles(mergedStyles, globalKeyframes);
|
|
199
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, state.sourceFile);
|
|
200
271
|
const properties = extractPropertiesFromStyles(mergedStyles, { autoPropertyTypes });
|
|
201
|
-
|
|
272
|
+
const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);
|
|
273
|
+
const counterStyles = extractCounterStyleFromStyles(mergedStyles, globalCounterStyle);
|
|
274
|
+
const functions = extractFunctionsFromStyles(mergedStyles, globalFunction);
|
|
202
275
|
const chunks = extractStylesWithChunks(mergedStyles);
|
|
203
|
-
for (const chunk of chunks) {
|
|
204
|
-
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
205
|
-
cssWriter.add(chunk.className, css, state.sourceFile);
|
|
206
|
-
}
|
|
207
276
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
208
277
|
const staticStyleObject = createStaticStyleAST(className, mergedStyles);
|
|
209
|
-
|
|
278
|
+
if (mode === "inject") {
|
|
279
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
280
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
281
|
+
} else {
|
|
282
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
283
|
+
path.replaceWith(staticStyleObject);
|
|
284
|
+
}
|
|
210
285
|
registerIfVariableDeclaration(path, className, mergedStyles, state, globalRegistry);
|
|
211
286
|
}
|
|
212
287
|
/**
|
|
213
288
|
* Handle tastyStatic(selector, styles) - removes the call entirely
|
|
214
289
|
*/
|
|
215
|
-
function handleSelectorMode(path, args, cssWriter, sourceFile, globalKeyframes, autoPropertyTypes) {
|
|
290
|
+
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
|
|
216
291
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(selector, styles) requires two arguments");
|
|
217
292
|
const selectorArg = args[0];
|
|
218
293
|
const stylesArg = args[1];
|
|
@@ -221,15 +296,72 @@ function handleSelectorMode(path, args, cssWriter, sourceFile, globalKeyframes,
|
|
|
221
296
|
const selector = selectorArg.value;
|
|
222
297
|
const styles = resolveRecipes(evaluateObjectExpression(stylesArg, path));
|
|
223
298
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
224
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
225
299
|
const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
|
|
226
|
-
|
|
300
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
301
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
302
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
227
303
|
const result = extractStylesForSelector(selector, styles);
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
304
|
+
const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(result.css, nameMap) : result.css;
|
|
305
|
+
if (mode === "inject") {
|
|
306
|
+
const cssParts = [];
|
|
307
|
+
for (const kf of keyframes) cssParts.push(kf.css);
|
|
308
|
+
for (const prop of properties) cssParts.push(prop.css);
|
|
309
|
+
for (const ff of fontFaces) cssParts.push(ff.css);
|
|
310
|
+
for (const cs of counterStyles) cssParts.push(cs.css);
|
|
311
|
+
for (const fn of functions) cssParts.push(fn.css);
|
|
312
|
+
cssParts.push(selectorCSS);
|
|
313
|
+
const injectCall = createInjectCallAST(selector, cssParts.join("\n"));
|
|
314
|
+
const parent = path.parentPath;
|
|
315
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.replaceWith(t.expressionStatement(injectCall));
|
|
316
|
+
else path.replaceWith(injectCall);
|
|
317
|
+
} else {
|
|
318
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, [], nameMap, sourceFile);
|
|
319
|
+
cssWriter.add(selector, selectorCSS, sourceFile);
|
|
320
|
+
const parent = path.parentPath;
|
|
321
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.remove();
|
|
322
|
+
else path.replaceWith(t.identifier("undefined"));
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Collect all extracted CSS parts into a single string (for inject mode).
|
|
327
|
+
*/
|
|
328
|
+
function collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap) {
|
|
329
|
+
const parts = [];
|
|
330
|
+
for (const kf of keyframes) parts.push(kf.css);
|
|
331
|
+
for (const prop of properties) parts.push(prop.css);
|
|
332
|
+
for (const ff of fontFaces) parts.push(ff.css);
|
|
333
|
+
for (const cs of counterStyles) parts.push(cs.css);
|
|
334
|
+
for (const fn of functions) parts.push(fn.css);
|
|
335
|
+
for (const chunk of chunks) parts.push(nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css);
|
|
336
|
+
return parts.join("\n");
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Write all extracted CSS parts to a CSSWriter (for file mode).
|
|
340
|
+
*/
|
|
341
|
+
function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, sourceFile) {
|
|
342
|
+
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
343
|
+
for (const prop of properties) cssWriter.add(prop.css, prop.css, sourceFile);
|
|
344
|
+
for (const ff of fontFaces) cssWriter.add(ff.css, ff.css, sourceFile);
|
|
345
|
+
for (const cs of counterStyles) cssWriter.add(cs.css, cs.css, sourceFile);
|
|
346
|
+
for (const fn of functions) cssWriter.add(fn.css, fn.css, sourceFile);
|
|
347
|
+
for (const chunk of chunks) {
|
|
348
|
+
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
349
|
+
cssWriter.add(chunk.className, css, sourceFile);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Extract CSS for a selector from a styles/tokens object.
|
|
354
|
+
* Returns undefined when there are no styles or no CSS output.
|
|
355
|
+
*/
|
|
356
|
+
function extractCSSFromStyles(selector, styles) {
|
|
357
|
+
if (!styles || Object.keys(styles).length === 0) return void 0;
|
|
358
|
+
return extractStylesForSelector(selector, styles).css || void 0;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Create an `_$i(id, css)` call expression AST node for inject mode.
|
|
362
|
+
*/
|
|
363
|
+
function createInjectCallAST(id, css) {
|
|
364
|
+
return t.callExpression(t.identifier("_$i"), [t.stringLiteral(id), t.stringLiteral(css)]);
|
|
233
365
|
}
|
|
234
366
|
/**
|
|
235
367
|
* Create a StaticStyle object AST node
|
|
@@ -340,7 +472,7 @@ function replaceAnimationNamesInCSS(css, nameMap) {
|
|
|
340
472
|
function escapeRegex(str) {
|
|
341
473
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
342
474
|
}
|
|
343
|
-
|
|
344
475
|
//#endregion
|
|
345
476
|
export { babel_default as default };
|
|
477
|
+
|
|
346
478
|
//# sourceMappingURL=babel.js.map
|