@tenphi/tasty 0.0.0-snapshot.1c5dff6 → 0.0.0-snapshot.1f1c00a
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 +377 -238
- package/dist/babel-rZcEwPLM.d.ts +82 -0
- package/dist/chunks/async-storage-CG5HnUT5.js +20 -0
- package/dist/chunks/async-storage-CG5HnUT5.js.map +1 -0
- package/dist/chunks/build-config-CL4eRu2z.js +42 -0
- package/dist/chunks/build-config-CL4eRu2z.js.map +1 -0
- package/dist/chunks/collector-D2ARGT2L.js +208 -0
- package/dist/chunks/collector-D2ARGT2L.js.map +1 -0
- package/dist/chunks/config-engine-DEmmPPdp.js +272 -0
- package/dist/chunks/config-engine-DEmmPPdp.js.map +1 -0
- package/dist/chunks/css-definitions-DotDkIXt.js +876 -0
- package/dist/chunks/css-definitions-DotDkIXt.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-D8pg9RGI.js +502 -0
- package/dist/chunks/debug-D8pg9RGI.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-BpxlOTbO.js +562 -0
- package/dist/chunks/react-runtime-BpxlOTbO.js.map +1 -0
- package/dist/chunks/runtime-engine-CKFXUH-A.js +2416 -0
- package/dist/chunks/runtime-engine-CKFXUH-A.js.map +1 -0
- package/dist/chunks/runtime-state-BxaLhVdP.js +127 -0
- package/dist/chunks/runtime-state-BxaLhVdP.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-BBbBuSkT.js +5260 -0
- package/dist/chunks/style-engine-BBbBuSkT.js.map +1 -0
- package/dist/{zero/extractor.js → chunks/zero-engine-gJrKBRiw.js} +126 -66
- package/dist/chunks/zero-engine-gJrKBRiw.js.map +1 -0
- package/dist/collector-w4mBj5gd.d.ts +164 -0
- package/dist/config-CZWCzBr6.d.ts +1349 -0
- package/dist/core/index.d.ts +5 -33
- package/dist/core/index.js +9 -26
- package/dist/index-G9JuwM9p.d.ts +1920 -0
- package/dist/index.d.ts +5 -48
- package/dist/index.js +11 -33
- package/dist/{utils/merge-styles.d.ts → merge-styles-VXwJ0Frr.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/index.d.ts +36 -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 +128 -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-JEY8PVYP.d.ts +1567 -0
- package/dist/zero/babel.d.ts +2 -113
- package/dist/zero/babel.js +230 -106
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +80 -3
- package/dist/zero/index.js +2 -4
- package/dist/zero/next.d.ts +57 -33
- package/dist/zero/next.js +93 -59
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +39 -0
- package/docs/adoption.md +323 -0
- package/docs/ai-agents.md +250 -0
- package/docs/comparison.md +448 -0
- package/docs/configuration.md +684 -56
- package/docs/debug.md +170 -343
- package/docs/design-system.md +455 -0
- package/docs/dsl.md +1065 -0
- package/docs/getting-started.md +240 -0
- package/docs/injector.md +159 -53
- package/docs/methodology.md +648 -0
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +765 -0
- package/docs/plugins.md +353 -0
- package/docs/react-api.md +683 -0
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +610 -0
- package/docs/styles.md +211 -63
- package/docs/tasty-static.md +273 -67
- package/package.json +182 -58
- 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 -288
- 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 -417
- package/dist/injector/injector.js.map +0 -1
- package/dist/injector/sheet-manager.d.ts +0 -135
- package/dist/injector/sheet-manager.js +0 -728
- 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 -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 -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 -660
- package/dist/pipeline/index.js.map +0 -1
- package/dist/pipeline/materialize.js +0 -856
- package/dist/pipeline/materialize.js.map +0 -1
- package/dist/pipeline/parseStateKey.d.ts +0 -15
- package/dist/pipeline/parseStateKey.js +0 -451
- 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 -371
- package/dist/plugins/okhsl-plugin.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -69
- package/dist/properties/index.js +0 -221
- 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 -83
- package/dist/properties/property-type-resolver.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 -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 -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 -23
- package/dist/styles/scrollbar.js +0 -34
- 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 -206
- 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/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 -177
- package/dist/utils/styles.js +0 -730
- 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.map +0 -1
- package/docs/usage.md +0 -695
package/dist/zero/babel.d.ts
CHANGED
|
@@ -1,113 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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";
|
|
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, handlers, or tokens.
|
|
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
|
-
* Predefined tokens that are replaced during style parsing.
|
|
82
|
-
* Use `$name` for custom properties and `#name` for color tokens.
|
|
83
|
-
* @example { $spacing: '2x', '#accent': '#purple' }
|
|
84
|
-
*/
|
|
85
|
-
tokens?: Record<`$${string}` | `#${string}`, string | number>;
|
|
86
|
-
/**
|
|
87
|
-
* Predefined style recipes -- named style bundles that can be applied via `recipe` style property.
|
|
88
|
-
* Recipe values are flat tasty styles (no sub-element keys).
|
|
89
|
-
* @example
|
|
90
|
-
* ```ts
|
|
91
|
-
* recipes: {
|
|
92
|
-
* card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
93
|
-
* elevated: { shadow: '2x 2x 4x #shadow' },
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
recipes?: Record<string, RecipeStyles>;
|
|
98
|
-
/**
|
|
99
|
-
* Automatically infer and register CSS @property declarations from values.
|
|
100
|
-
* @default true
|
|
101
|
-
*/
|
|
102
|
-
autoPropertyTypes?: boolean;
|
|
103
|
-
}
|
|
104
|
-
interface TastyZeroBabelOptions {
|
|
105
|
-
/** Output path for generated CSS (default: 'tasty.css') */
|
|
106
|
-
output?: string;
|
|
107
|
-
/** Tasty configuration for build-time processing */
|
|
108
|
-
config?: TastyZeroConfig;
|
|
109
|
-
}
|
|
110
|
-
declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => _babel_core0.PluginObj<PluginPass>;
|
|
111
|
-
//#endregion
|
|
112
|
-
export { TastyZeroBabelOptions, TastyZeroConfig, _default as default };
|
|
113
|
-
//# sourceMappingURL=babel.d.ts.map
|
|
1
|
+
import { n as _default, r as TastyZeroConfig, t as TastyZeroBabelOptions } from "../babel-rZcEwPLM.js";
|
|
2
|
+
export { TastyZeroBabelOptions, type TastyZeroConfig, _default as default };
|
package/dist/zero/babel.js
CHANGED
|
@@ -1,58 +1,152 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { extractKeyframesFromStyles, extractPropertiesFromStyles,
|
|
5
|
-
import {
|
|
1
|
+
import { t as mergeStyles } from "../chunks/shared-utils-y-HjvPN4.js";
|
|
2
|
+
import "../chunks/css-definitions-DotDkIXt.js";
|
|
3
|
+
import { t as resolveRecipesWith } from "../chunks/config-engine-DEmmPPdp.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 "../chunks/zero-engine-gJrKBRiw.js";
|
|
5
|
+
import { n as functionsForExtraction, r as resetZeroConfig, t as configureZero } from "../chunks/build-config-CL4eRu2z.js";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import * as path from "path";
|
|
6
8
|
import { declare } from "@babel/helper-plugin-utils";
|
|
7
9
|
import * as t from "@babel/types";
|
|
8
|
-
|
|
10
|
+
import { createJiti } from "jiti";
|
|
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) {
|
|
69
|
+
const loaded = createJiti(path.dirname(options.configFile), { moduleCache: false })(options.configFile);
|
|
70
|
+
resolvedConfig = loaded && typeof loaded === "object" && "default" in loaded ? loaded.default : loaded;
|
|
71
|
+
} else resolvedConfig = {};
|
|
72
|
+
const devMode = resolvedConfig.devMode ?? false;
|
|
73
|
+
resetZeroConfig();
|
|
74
|
+
const finalConfig = {
|
|
75
|
+
namePrefix: "ts",
|
|
76
|
+
...resolvedConfig
|
|
77
|
+
};
|
|
78
|
+
const config = configureZero(finalConfig);
|
|
79
|
+
setExtractorNamePrefix(finalConfig.namePrefix ?? "ts");
|
|
80
|
+
const newWriter = new CSSWriter(outputPath, { devMode });
|
|
81
|
+
if (mode !== "inject") {
|
|
82
|
+
const tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
83
|
+
if (tokenCSS) newWriter.add(":root:tokens", tokenCSS);
|
|
84
|
+
for (const [selector, styles] of Object.entries(config.normalized.globalStyles)) {
|
|
85
|
+
const css = extractCSSFromStyles(selector, styles);
|
|
86
|
+
if (css) newWriter.add(`global:${selector}`, css);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
writerCache.set(resolvedOutputPath, {
|
|
90
|
+
writer: newWriter,
|
|
91
|
+
configKey,
|
|
92
|
+
registry: {},
|
|
93
|
+
config
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const entry = writerCache.get(resolvedOutputPath);
|
|
97
|
+
const cssWriter = entry.writer;
|
|
98
|
+
const globalRegistry = entry.registry;
|
|
99
|
+
const config = entry.config;
|
|
100
|
+
const sourceConfig = config.source;
|
|
101
|
+
const devMode = sourceConfig.devMode ?? false;
|
|
102
|
+
setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
|
|
103
|
+
let tokenCSS;
|
|
104
|
+
let globalStylesCSS;
|
|
105
|
+
if (mode === "inject") {
|
|
106
|
+
tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
107
|
+
const gs = config.normalized.globalStyles;
|
|
108
|
+
if (Object.keys(gs).length > 0) {
|
|
109
|
+
globalStylesCSS = /* @__PURE__ */ new Map();
|
|
110
|
+
for (const [selector, styles] of Object.entries(gs)) {
|
|
111
|
+
const css = extractCSSFromStyles(selector, styles);
|
|
112
|
+
if (css) globalStylesCSS.set(selector, css);
|
|
113
|
+
}
|
|
114
|
+
if (globalStylesCSS.size === 0) globalStylesCSS = void 0;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
36
117
|
return {
|
|
37
118
|
name: "tasty-zero",
|
|
38
119
|
pre() {
|
|
39
120
|
this.staticStyleRegistry = {};
|
|
121
|
+
this._fileAddedCSS = false;
|
|
40
122
|
if (devMode && this.filename) this.sourceFile = this.filename.split("/").pop() || this.filename;
|
|
41
123
|
},
|
|
42
124
|
visitor: {
|
|
43
|
-
ImportDeclaration(
|
|
44
|
-
const source =
|
|
45
|
-
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static"))
|
|
125
|
+
ImportDeclaration(nodePath, state) {
|
|
126
|
+
const source = nodePath.node.source.value;
|
|
127
|
+
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) {
|
|
128
|
+
if (mode === "inject") nodePath.replaceWith(t.importDeclaration([t.importSpecifier(t.identifier("_$i"), t.identifier("injectCSS"))], t.stringLiteral("@tenphi/tasty/static/inject")));
|
|
129
|
+
else if (injectImport) {
|
|
130
|
+
let importPath = resolvedOutputPath;
|
|
131
|
+
if (state.filename) {
|
|
132
|
+
const sourceDir = path.dirname(state.filename);
|
|
133
|
+
importPath = path.relative(sourceDir, resolvedOutputPath);
|
|
134
|
+
if (!importPath.startsWith(".")) importPath = "./" + importPath;
|
|
135
|
+
}
|
|
136
|
+
nodePath.replaceWith(t.importDeclaration([], t.stringLiteral(importPath)));
|
|
137
|
+
} else nodePath.remove();
|
|
138
|
+
}
|
|
46
139
|
},
|
|
47
140
|
CallExpression(path, state) {
|
|
48
141
|
const callee = path.node.callee;
|
|
49
142
|
if (!t.isIdentifier(callee, { name: "tastyStatic" })) return;
|
|
143
|
+
state._fileAddedCSS = true;
|
|
50
144
|
const args = path.node.arguments;
|
|
51
145
|
if (args.length === 0) throw path.buildCodeFrameError("tastyStatic() requires at least one argument");
|
|
52
146
|
const firstArg = args[0];
|
|
53
|
-
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, state.sourceFile, config.keyframes, config.
|
|
54
|
-
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, config.keyframes, config.
|
|
55
|
-
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, config.keyframes, config.
|
|
147
|
+
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.normalized.keyframes, sourceConfig.autoPropertyTypes, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
148
|
+
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, sourceConfig.autoPropertyTypes, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
149
|
+
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, sourceConfig.autoPropertyTypes, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
56
150
|
else throw path.buildCodeFrameError("tastyStatic() first argument must be an object (styles), identifier (base StaticStyle), or string (selector)");
|
|
57
151
|
},
|
|
58
152
|
VariableDeclarator(path, state) {
|
|
@@ -76,57 +170,64 @@ var babel_default = declare((api, options) => {
|
|
|
76
170
|
}
|
|
77
171
|
},
|
|
78
172
|
post() {
|
|
79
|
-
if (
|
|
173
|
+
if (mode === "inject") {
|
|
174
|
+
if (this._fileAddedCSS && (tokenCSS || globalStylesCSS)) {
|
|
175
|
+
const program = this.file.ast.program;
|
|
176
|
+
let insertIndex = 0;
|
|
177
|
+
for (let i = 0; i < program.body.length; i++) if (t.isImportDeclaration(program.body[i])) insertIndex = i + 1;
|
|
178
|
+
if (tokenCSS) {
|
|
179
|
+
const injectCall = createInjectCallAST(":root", tokenCSS);
|
|
180
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
181
|
+
insertIndex++;
|
|
182
|
+
}
|
|
183
|
+
if (globalStylesCSS) for (const [selector, css] of globalStylesCSS) {
|
|
184
|
+
const injectCall = createInjectCallAST(selector, css);
|
|
185
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
186
|
+
insertIndex++;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (this._fileAddedCSS && cssWriter.size > 0) cssWriter.write();
|
|
80
192
|
}
|
|
81
193
|
};
|
|
82
194
|
});
|
|
83
|
-
/**
|
|
84
|
-
* Check if an object expression looks like a StaticStyle object
|
|
85
|
-
*/
|
|
86
195
|
function isStaticStyleObject(node) {
|
|
87
196
|
const hasClassName = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "className" }));
|
|
88
197
|
const hasStyles = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "styles" }));
|
|
89
198
|
return hasClassName && hasStyles;
|
|
90
199
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Extract styles object from a StaticStyle object expression
|
|
93
|
-
*/
|
|
94
200
|
function extractStylesFromStaticStyleObject(node, path) {
|
|
95
201
|
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
202
|
return null;
|
|
97
203
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Extract className from a StaticStyle object expression
|
|
100
|
-
*/
|
|
101
204
|
function extractClassNameFromStaticStyleObject(node) {
|
|
102
205
|
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
206
|
return null;
|
|
104
207
|
}
|
|
105
|
-
|
|
106
|
-
* Handle tastyStatic(styles) - returns StaticStyle object
|
|
107
|
-
*/
|
|
108
|
-
function handleStylesMode(path, args, cssWriter, state, globalRegistry, globalKeyframes, autoPropertyTypes) {
|
|
208
|
+
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
109
209
|
const stylesArg = args[0];
|
|
110
210
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(styles) argument must be a static object literal");
|
|
111
|
-
const
|
|
211
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
212
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
112
213
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
113
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, state.sourceFile);
|
|
114
214
|
const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
|
|
115
|
-
|
|
215
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
216
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
217
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
116
218
|
const chunks = extractStylesWithChunks(styles);
|
|
117
|
-
for (const chunk of chunks) {
|
|
118
|
-
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
119
|
-
cssWriter.add(chunk.className, css, state.sourceFile);
|
|
120
|
-
}
|
|
121
219
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
122
220
|
const staticStyleObject = createStaticStyleAST(className, styles);
|
|
123
|
-
|
|
221
|
+
if (mode === "inject") {
|
|
222
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
223
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
224
|
+
} else {
|
|
225
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
226
|
+
path.replaceWith(staticStyleObject);
|
|
227
|
+
}
|
|
124
228
|
registerIfVariableDeclaration(path, className, styles, state, globalRegistry);
|
|
125
229
|
}
|
|
126
|
-
|
|
127
|
-
* Handle tastyStatic(base, styles) - extends base with additional styles
|
|
128
|
-
*/
|
|
129
|
-
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globalKeyframes, autoPropertyTypes) {
|
|
230
|
+
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
130
231
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(base, styles) requires two arguments");
|
|
131
232
|
const baseArg = args[0];
|
|
132
233
|
const stylesArg = args[1];
|
|
@@ -136,46 +237,88 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globa
|
|
|
136
237
|
const baseEntry = state.staticStyleRegistry[baseName] || globalRegistry[baseName];
|
|
137
238
|
if (!baseEntry) throw path.buildCodeFrameError(`Cannot find base StaticStyle '${baseName}'. Make sure it is defined before being extended.`);
|
|
138
239
|
const overrideStyles = evaluateObjectExpression(stylesArg, path);
|
|
139
|
-
const mergedStyles =
|
|
240
|
+
const mergedStyles = resolveRecipesWith(mergeStyles(baseEntry.styles, overrideStyles), globalRecipes ?? null);
|
|
140
241
|
const { keyframes, nameMap } = extractKeyframesFromStyles(mergedStyles, globalKeyframes);
|
|
141
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, state.sourceFile);
|
|
142
242
|
const properties = extractPropertiesFromStyles(mergedStyles, { autoPropertyTypes });
|
|
143
|
-
|
|
243
|
+
const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);
|
|
244
|
+
const counterStyles = extractCounterStyleFromStyles(mergedStyles, globalCounterStyle);
|
|
245
|
+
const functions = extractFunctionsFromStyles(mergedStyles, globalFunction);
|
|
144
246
|
const chunks = extractStylesWithChunks(mergedStyles);
|
|
145
|
-
for (const chunk of chunks) {
|
|
146
|
-
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
147
|
-
cssWriter.add(chunk.className, css, state.sourceFile);
|
|
148
|
-
}
|
|
149
247
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
150
248
|
const staticStyleObject = createStaticStyleAST(className, mergedStyles);
|
|
151
|
-
|
|
249
|
+
if (mode === "inject") {
|
|
250
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
251
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
252
|
+
} else {
|
|
253
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
254
|
+
path.replaceWith(staticStyleObject);
|
|
255
|
+
}
|
|
152
256
|
registerIfVariableDeclaration(path, className, mergedStyles, state, globalRegistry);
|
|
153
257
|
}
|
|
154
|
-
|
|
155
|
-
* Handle tastyStatic(selector, styles) - removes the call entirely
|
|
156
|
-
*/
|
|
157
|
-
function handleSelectorMode(path, args, cssWriter, sourceFile, globalKeyframes, autoPropertyTypes) {
|
|
258
|
+
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
158
259
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(selector, styles) requires two arguments");
|
|
159
260
|
const selectorArg = args[0];
|
|
160
261
|
const stylesArg = args[1];
|
|
161
262
|
if (!t.isStringLiteral(selectorArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) first argument must be a string literal");
|
|
162
263
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) second argument must be a static object literal");
|
|
163
264
|
const selector = selectorArg.value;
|
|
164
|
-
const
|
|
265
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
266
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
165
267
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
166
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
167
268
|
const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
|
|
168
|
-
|
|
269
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
270
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
271
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
169
272
|
const result = extractStylesForSelector(selector, styles);
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
273
|
+
const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(result.css, nameMap) : result.css;
|
|
274
|
+
if (mode === "inject") {
|
|
275
|
+
const cssParts = [];
|
|
276
|
+
for (const kf of keyframes) cssParts.push(kf.css);
|
|
277
|
+
for (const prop of properties) cssParts.push(prop.css);
|
|
278
|
+
for (const ff of fontFaces) cssParts.push(ff.css);
|
|
279
|
+
for (const cs of counterStyles) cssParts.push(cs.css);
|
|
280
|
+
for (const fn of functions) cssParts.push(fn.css);
|
|
281
|
+
cssParts.push(selectorCSS);
|
|
282
|
+
const injectCall = createInjectCallAST(selector, cssParts.join("\n"));
|
|
283
|
+
const parent = path.parentPath;
|
|
284
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.replaceWith(t.expressionStatement(injectCall));
|
|
285
|
+
else path.replaceWith(injectCall);
|
|
286
|
+
} else {
|
|
287
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, [], nameMap, sourceFile);
|
|
288
|
+
cssWriter.add(selector, selectorCSS, sourceFile);
|
|
289
|
+
const parent = path.parentPath;
|
|
290
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.remove();
|
|
291
|
+
else path.replaceWith(t.identifier("undefined"));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
function collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap) {
|
|
295
|
+
const parts = [];
|
|
296
|
+
for (const kf of keyframes) parts.push(kf.css);
|
|
297
|
+
for (const prop of properties) parts.push(prop.css);
|
|
298
|
+
for (const ff of fontFaces) parts.push(ff.css);
|
|
299
|
+
for (const cs of counterStyles) parts.push(cs.css);
|
|
300
|
+
for (const fn of functions) parts.push(fn.css);
|
|
301
|
+
for (const chunk of chunks) parts.push(nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css);
|
|
302
|
+
return parts.join("\n");
|
|
303
|
+
}
|
|
304
|
+
function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, sourceFile) {
|
|
305
|
+
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
306
|
+
for (const prop of properties) cssWriter.add(prop.css, prop.css, sourceFile);
|
|
307
|
+
for (const ff of fontFaces) cssWriter.add(ff.css, ff.css, sourceFile);
|
|
308
|
+
for (const cs of counterStyles) cssWriter.add(cs.css, cs.css, sourceFile);
|
|
309
|
+
for (const fn of functions) cssWriter.add(fn.css, fn.css, sourceFile);
|
|
310
|
+
for (const chunk of chunks) {
|
|
311
|
+
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
312
|
+
cssWriter.add(chunk.className, css, sourceFile);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function extractCSSFromStyles(selector, styles) {
|
|
316
|
+
if (!styles || Object.keys(styles).length === 0) return void 0;
|
|
317
|
+
return extractStylesForSelector(selector, styles).css || void 0;
|
|
318
|
+
}
|
|
319
|
+
function createInjectCallAST(id, css) {
|
|
320
|
+
return t.callExpression(t.identifier("_$i"), [t.stringLiteral(id), t.stringLiteral(css)]);
|
|
175
321
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Create a StaticStyle object AST node
|
|
178
|
-
*/
|
|
179
322
|
function createStaticStyleAST(className, styles) {
|
|
180
323
|
return t.objectExpression([
|
|
181
324
|
t.objectProperty(t.identifier("className"), t.stringLiteral(className)),
|
|
@@ -183,9 +326,6 @@ function createStaticStyleAST(className, styles) {
|
|
|
183
326
|
t.objectMethod("method", t.identifier("toString"), [], t.blockStatement([t.returnStatement(t.memberExpression(t.thisExpression(), t.identifier("className")))]))
|
|
184
327
|
]);
|
|
185
328
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Register a StaticStyle in the registry if it's being assigned to a variable
|
|
188
|
-
*/
|
|
189
329
|
function registerIfVariableDeclaration(path, className, styles, state, globalRegistry) {
|
|
190
330
|
const parent = path.parentPath;
|
|
191
331
|
if (parent && t.isVariableDeclarator(parent.node)) {
|
|
@@ -203,9 +343,6 @@ function registerIfVariableDeclaration(path, className, styles, state, globalReg
|
|
|
203
343
|
}
|
|
204
344
|
}
|
|
205
345
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Convert a JavaScript value to an AST node
|
|
208
|
-
*/
|
|
209
346
|
function valueToAST(value) {
|
|
210
347
|
if (value === null) return t.nullLiteral();
|
|
211
348
|
if (value === void 0) return t.identifier("undefined");
|
|
@@ -219,10 +356,6 @@ function valueToAST(value) {
|
|
|
219
356
|
}
|
|
220
357
|
return t.identifier("undefined");
|
|
221
358
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Evaluate an ObjectExpression to a plain JavaScript object.
|
|
224
|
-
* Only supports static values that can be determined at build time.
|
|
225
|
-
*/
|
|
226
359
|
function evaluateObjectExpression(node, path) {
|
|
227
360
|
const result = {};
|
|
228
361
|
for (const prop of node.properties) {
|
|
@@ -232,13 +365,11 @@ function evaluateObjectExpression(node, path) {
|
|
|
232
365
|
if (t.isIdentifier(prop.key)) key = prop.key.name;
|
|
233
366
|
else if (t.isStringLiteral(prop.key)) key = prop.key.value;
|
|
234
367
|
else throw path.buildCodeFrameError("Dynamic property keys are not supported in tastyStatic()");
|
|
235
|
-
|
|
368
|
+
const value = evaluateExpression(prop.value, path);
|
|
369
|
+
result[key] = value;
|
|
236
370
|
}
|
|
237
371
|
return result;
|
|
238
372
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Evaluate an expression to a JavaScript value.
|
|
241
|
-
*/
|
|
242
373
|
function evaluateExpression(node, path) {
|
|
243
374
|
if (t.isStringLiteral(node)) return node.value;
|
|
244
375
|
if (t.isNumericLiteral(node)) return node.value;
|
|
@@ -261,10 +392,6 @@ function evaluateExpression(node, path) {
|
|
|
261
392
|
}
|
|
262
393
|
throw path.buildCodeFrameError(`Dynamic expressions are not supported in tastyStatic() - got ${node.type}. All values must be static literals.`);
|
|
263
394
|
}
|
|
264
|
-
/**
|
|
265
|
-
* Replace animation names in CSS string.
|
|
266
|
-
* Wraps the keyframes replaceAnimationNames to work on full CSS blocks.
|
|
267
|
-
*/
|
|
268
395
|
function replaceAnimationNamesInCSS(css, nameMap) {
|
|
269
396
|
if (nameMap.size === 0) return css;
|
|
270
397
|
return css.replace(/(animation(?:-name)?)\s*:\s*([^;}]+)/gi, (match, prop, value) => {
|
|
@@ -276,13 +403,10 @@ function replaceAnimationNamesInCSS(css, nameMap) {
|
|
|
276
403
|
return `${prop}: ${newValue}`;
|
|
277
404
|
});
|
|
278
405
|
}
|
|
279
|
-
/**
|
|
280
|
-
* Escape special regex characters.
|
|
281
|
-
*/
|
|
282
406
|
function escapeRegex(str) {
|
|
283
407
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
284
408
|
}
|
|
285
|
-
|
|
286
409
|
//#endregion
|
|
287
410
|
export { babel_default as default };
|
|
411
|
+
|
|
288
412
|
//# sourceMappingURL=babel.js.map
|