@tenphi/tasty 0.0.0-snapshot.2705ab9 → 0.0.0-snapshot.275370e
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 +26 -20
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +1 -2
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.js +1 -2
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +1 -2
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +322 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +61 -20
- package/dist/config.js +119 -32
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +6 -6
- package/dist/core/index.js +7 -7
- package/dist/counter-style/index.js +1 -1
- package/dist/counter-style/index.js.map +1 -1
- package/dist/debug.js +5 -6
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +1 -1
- package/dist/font-face/index.js.map +1 -1
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +3 -17
- package/dist/hooks/useCounterStyle.js +56 -38
- package/dist/hooks/useCounterStyle.js.map +1 -1
- package/dist/hooks/useFontFace.d.ts +3 -1
- package/dist/hooks/useFontFace.js +22 -27
- package/dist/hooks/useFontFace.js.map +1 -1
- package/dist/hooks/useGlobalStyles.d.ts +18 -2
- package/dist/hooks/useGlobalStyles.js +52 -43
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +43 -53
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +30 -44
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +13 -44
- package/dist/hooks/useRawCSS.js +91 -24
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +3 -8
- package/dist/hooks/useStyles.js +7 -214
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +8 -8
- package/dist/injector/index.d.ts +18 -19
- package/dist/injector/index.js +25 -20
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +35 -3
- package/dist/injector/injector.js +200 -14
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +9 -13
- package/dist/injector/sheet-manager.js +34 -69
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +52 -21
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +1 -2
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +14 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +1 -2
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +58 -4
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.js +4 -5
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js +57 -4
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.js +5 -6
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +181 -7
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +1 -2
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +12 -1
- package/dist/properties/index.js +2 -3
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +1 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- package/dist/rsc-cache.js +79 -0
- package/dist/rsc-cache.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.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +89 -10
- package/dist/ssr/astro.js +113 -29
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/async-storage.js +15 -6
- package/dist/ssr/async-storage.js.map +1 -1
- package/dist/ssr/collect-auto-properties.js +29 -11
- package/dist/ssr/collect-auto-properties.js.map +1 -1
- package/dist/ssr/collector.d.ts +9 -13
- package/dist/ssr/collector.js +35 -27
- package/dist/ssr/collector.js.map +1 -1
- package/dist/ssr/context.js +4 -2
- package/dist/ssr/context.js.map +1 -1
- package/dist/ssr/format-global-rules.js +1 -1
- package/dist/ssr/format-keyframes.js +1 -2
- package/dist/ssr/format-keyframes.js.map +1 -1
- package/dist/ssr/format-property.js +1 -2
- package/dist/ssr/format-property.js.map +1 -1
- package/dist/ssr/format-rules.js +1 -1
- package/dist/ssr/hydrate.d.ts +20 -13
- package/dist/ssr/hydrate.js +25 -30
- package/dist/ssr/hydrate.js.map +1 -1
- package/dist/ssr/index.d.ts +3 -4
- package/dist/ssr/index.js +5 -7
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next.d.ts +6 -5
- package/dist/ssr/next.js +14 -10
- package/dist/ssr/next.js.map +1 -1
- package/dist/ssr/ssr-collector-ref.js +20 -3
- package/dist/ssr/ssr-collector-ref.js.map +1 -1
- package/dist/states/index.js +1 -2
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- 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/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +28 -22
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- package/dist/styles/color.js +2 -3
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +4 -5
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +3 -4
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -4
- package/dist/styles/predefined.js +8 -9
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +1 -1
- package/dist/styles/preset.js +7 -7
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -3
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +1 -1
- package/dist/styles/scrollbar.js +8 -5
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +5 -4
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +24 -7
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +29 -14
- package/dist/tasty.js +78 -62
- package/dist/tasty.js.map +1 -1
- package/dist/utils/cache-wrapper.js +1 -2
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.js +1 -1
- package/dist/utils/color-math.js.map +1 -1
- package/dist/utils/color-space.js +1 -2
- package/dist/utils/color-space.js.map +1 -1
- package/dist/utils/colors.js +1 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +1 -1
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +1 -2
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +1 -5
- package/dist/utils/process-tokens.js +3 -11
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +1 -1
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +1 -1
- package/dist/utils/styles.js +2 -3
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +21 -10
- package/dist/utils/typography.js +2 -2
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +24 -110
- package/dist/zero/babel.js +130 -42
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +1 -2
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +12 -0
- package/dist/zero/next.js +5 -4
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +2 -2
- package/docs/adoption.md +5 -3
- package/docs/comparison.md +24 -25
- package/docs/configuration.md +69 -1
- package/docs/design-system.md +22 -10
- package/docs/dsl.md +23 -8
- package/docs/getting-started.md +10 -10
- package/docs/injector.md +41 -25
- package/docs/methodology.md +52 -3
- package/docs/{runtime.md → react-api.md} +104 -32
- package/docs/ssr.md +139 -81
- package/docs/styles.md +17 -0
- package/docs/tasty-static.md +101 -2
- package/package.json +20 -9
- package/dist/hooks/resolve-ssr-collector.js +0 -15
- package/dist/hooks/resolve-ssr-collector.js.map +0 -1
- package/dist/ssr/context.d.ts +0 -8
- 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/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
package/dist/utils/typography.js
CHANGED
|
@@ -35,7 +35,7 @@ function generateTypographyTokens(presets) {
|
|
|
35
35
|
if (RESERVED_PRESET_NAMES.has(name)) throw new Error(`Invalid typography preset name "${name}". This name is reserved as a preset modifier.`);
|
|
36
36
|
tokens[`$${name}-font-size`] = preset.fontSize;
|
|
37
37
|
tokens[`$${name}-line-height`] = preset.lineHeight;
|
|
38
|
-
tokens[`$${name}-letter-spacing`] = preset.letterSpacing ?? "
|
|
38
|
+
tokens[`$${name}-letter-spacing`] = preset.letterSpacing ?? "normal";
|
|
39
39
|
tokens[`$${name}-font-weight`] = preset.fontWeight;
|
|
40
40
|
if (preset.boldFontWeight !== void 0) tokens[`$${name}-bold-font-weight`] = preset.boldFontWeight;
|
|
41
41
|
if (preset.iconSize !== void 0) tokens[`$${name}-icon-size`] = preset.iconSize;
|
|
@@ -45,7 +45,7 @@ function generateTypographyTokens(presets) {
|
|
|
45
45
|
}
|
|
46
46
|
return tokens;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
48
|
//#endregion
|
|
50
49
|
export { generateTypographyTokens };
|
|
50
|
+
|
|
51
51
|
//# sourceMappingURL=typography.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typography.js","names":[],"sources":["../../src/utils/typography.ts"],"sourcesContent":["import type { ConfigTokens } from '../styles/types';\n\nconst RESERVED_PRESET_NAMES = new Set([\n 'strong',\n 'bold',\n 'italic',\n 'icon',\n 'tight',\n]);\n\n/**\n * Typography preset configuration.\n * Each preset defines font properties that get expanded into CSS custom properties.\n *\n * Use with `generateTypographyTokens()` to create typography tokens for your design system.\n */\nexport interface TypographyPreset {\n fontSize:
|
|
1
|
+
{"version":3,"file":"typography.js","names":[],"sources":["../../src/utils/typography.ts"],"sourcesContent":["import type { ConfigTokens } from '../styles/types';\n\nconst RESERVED_PRESET_NAMES = new Set([\n 'strong',\n 'bold',\n 'italic',\n 'icon',\n 'tight',\n]);\n\n/**\n * A typography token value: plain value or a state map for responsive/theme-aware presets.\n *\n * @example\n * // Plain value\n * fontWeight: '400'\n * // State map\n * fontWeight: { '': '400', '@dark': '300' }\n */\nexport type TypographyTokenValue =\n | string\n | number\n | Record<string, string | number | undefined | null | '@inherit'>;\n\n/**\n * Typography preset configuration.\n * Each preset defines font properties that get expanded into CSS custom properties.\n * All fields accept plain values or state maps for responsive/theme-aware tokens.\n *\n * Use with `generateTypographyTokens()` to create typography tokens for your design system.\n */\nexport interface TypographyPreset {\n fontSize: TypographyTokenValue;\n lineHeight: TypographyTokenValue;\n letterSpacing?: TypographyTokenValue;\n fontWeight: TypographyTokenValue;\n boldFontWeight?: TypographyTokenValue;\n iconSize?: TypographyTokenValue;\n textTransform?: TypographyTokenValue;\n fontFamily?: TypographyTokenValue;\n fontStyle?: TypographyTokenValue;\n}\n\n/**\n * Generate typography tokens with $ prefix for CSS custom properties.\n *\n * Each preset generates the following CSS custom properties:\n * - `${name}-font-size`\n * - `${name}-line-height`\n * - `${name}-letter-spacing`\n * - `${name}-font-weight`\n * - `${name}-bold-font-weight` (if defined)\n * - `${name}-icon-size` (if defined)\n * - `${name}-text-transform` (if defined)\n * - `${name}-font-family` (if defined)\n * - `${name}-font-style` (if defined)\n *\n * @param presets - Typography presets object\n * @returns ConfigTokens object with $ prefixed keys\n *\n * @example\n * const customTokens = generateTypographyTokens({\n * myHeading: { fontSize: '24px', lineHeight: '32px', fontWeight: '700' },\n * body: { fontSize: '16px', lineHeight: '24px', fontWeight: '400' },\n * });\n */\nexport function generateTypographyTokens(\n presets: Record<string, TypographyPreset>,\n): ConfigTokens {\n const tokens: ConfigTokens = {} as ConfigTokens;\n\n for (const [name, preset] of Object.entries(presets)) {\n if (RESERVED_PRESET_NAMES.has(name)) {\n throw new Error(\n `Invalid typography preset name \"${name}\". This name is reserved as a preset modifier.`,\n );\n }\n\n tokens[`$${name}-font-size`] = preset.fontSize;\n tokens[`$${name}-line-height`] = preset.lineHeight;\n tokens[`$${name}-letter-spacing`] = preset.letterSpacing ?? 'normal';\n tokens[`$${name}-font-weight`] = preset.fontWeight;\n\n if (preset.boldFontWeight !== undefined) {\n tokens[`$${name}-bold-font-weight`] = preset.boldFontWeight;\n }\n\n if (preset.iconSize !== undefined) {\n tokens[`$${name}-icon-size`] = preset.iconSize;\n }\n\n if (preset.textTransform !== undefined) {\n tokens[`$${name}-text-transform`] = preset.textTransform;\n }\n\n if (preset.fontFamily !== undefined) {\n tokens[`$${name}-font-family`] = preset.fontFamily;\n }\n\n if (preset.fontStyle !== undefined) {\n tokens[`$${name}-font-style`] = preset.fontStyle;\n }\n }\n\n return tokens;\n}\n"],"mappings":";AAEA,MAAM,wBAAwB,IAAI,IAAI;CACpC;CACA;CACA;CACA;CACA;CACD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;AA0DF,SAAgB,yBACd,SACc;CACd,MAAM,SAAuB,EAAE;AAE/B,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,QAAQ,EAAE;AACpD,MAAI,sBAAsB,IAAI,KAAK,CACjC,OAAM,IAAI,MACR,mCAAmC,KAAK,gDACzC;AAGH,SAAO,IAAI,KAAK,eAAe,OAAO;AACtC,SAAO,IAAI,KAAK,iBAAiB,OAAO;AACxC,SAAO,IAAI,KAAK,oBAAoB,OAAO,iBAAiB;AAC5D,SAAO,IAAI,KAAK,iBAAiB,OAAO;AAExC,MAAI,OAAO,mBAAmB,KAAA,EAC5B,QAAO,IAAI,KAAK,sBAAsB,OAAO;AAG/C,MAAI,OAAO,aAAa,KAAA,EACtB,QAAO,IAAI,KAAK,eAAe,OAAO;AAGxC,MAAI,OAAO,kBAAkB,KAAA,EAC3B,QAAO,IAAI,KAAK,oBAAoB,OAAO;AAG7C,MAAI,OAAO,eAAe,KAAA,EACxB,QAAO,IAAI,KAAK,iBAAiB,OAAO;AAG1C,MAAI,OAAO,cAAc,KAAA,EACvB,QAAO,IAAI,KAAK,gBAAgB,OAAO;;AAI3C,QAAO"}
|
package/dist/utils/warnings.js
CHANGED
|
@@ -10,7 +10,7 @@ function deprecationWarning(condition, { property, name, betterAlternative, reas
|
|
|
10
10
|
if (reason) warn(`Reason: ${typeof reason === "function" ? reason() : reason}`);
|
|
11
11
|
console.groupEnd();
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
//#endregion
|
|
15
14
|
export { deprecationWarning, warn };
|
|
15
|
+
|
|
16
16
|
//# sourceMappingURL=warnings.js.map
|
package/dist/zero/babel.d.ts
CHANGED
|
@@ -1,122 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
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";
|
|
1
|
+
import { TastyConfig } from "../config.js";
|
|
2
|
+
import * as _$_babel_core0 from "@babel/core";
|
|
7
3
|
import { PluginPass } from "@babel/core";
|
|
8
4
|
|
|
9
5
|
//#region src/zero/babel.d.ts
|
|
10
6
|
/**
|
|
11
7
|
* Build-time configuration for zero-runtime mode.
|
|
12
|
-
* Subset of TastyConfig
|
|
8
|
+
* Subset of TastyConfig excluding runtime-only DOM options
|
|
9
|
+
* (`nonce`, `maxRulesPerSheet`, `forceTextInjection`, `gc`)
|
|
10
|
+
* and overriding `devMode` default to `false`.
|
|
13
11
|
*/
|
|
14
|
-
|
|
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>;
|
|
12
|
+
type TastyZeroConfig = Omit<TastyConfig, 'nonce' | 'maxRulesPerSheet' | 'forceTextInjection' | 'gc' | 'devMode'> & {
|
|
20
13
|
/**
|
|
21
14
|
* Enable development mode features: source comments in generated CSS.
|
|
22
|
-
*
|
|
15
|
+
* @default false
|
|
23
16
|
*/
|
|
24
17
|
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
|
-
* Global @font-face definitions for static extraction.
|
|
68
|
-
* Keys are font-family names, values are descriptors or arrays of descriptors.
|
|
69
|
-
*/
|
|
70
|
-
fontFace?: Record<string, FontFaceInput>;
|
|
71
|
-
/**
|
|
72
|
-
* Global @counter-style definitions for static extraction.
|
|
73
|
-
* Keys are counter-style names, values are descriptor objects.
|
|
74
|
-
*/
|
|
75
|
-
counterStyle?: Record<string, CounterStyleDescriptors>;
|
|
76
|
-
/**
|
|
77
|
-
* Custom style handlers that transform style properties into CSS declarations.
|
|
78
|
-
* Handlers replace built-in handlers for the same style name.
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* handlers: {
|
|
82
|
-
* fill: ({ fill }) => fill ? { 'background-color': fill } : undefined,
|
|
83
|
-
* elevation: ({ elevation }) => ({
|
|
84
|
-
* 'box-shadow': `0 ${elevation}px ${elevation * 2}px rgba(0,0,0,0.1)`,
|
|
85
|
-
* }),
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
handlers?: Record<string, StyleHandlerDefinition>;
|
|
90
|
-
/**
|
|
91
|
-
* Design tokens injected as CSS custom properties on `:root`.
|
|
92
|
-
* Values are parsed through the Tasty DSL. Supports state maps.
|
|
93
|
-
* @example { '$gap': '4px', '#primary': { '': '#purple', '@dark': '#light-purple' } }
|
|
94
|
-
*/
|
|
95
|
-
tokens?: ConfigTokens;
|
|
96
|
-
/**
|
|
97
|
-
* Predefined tokens replaced during style parsing (parse-time substitution).
|
|
98
|
-
* Use `$name` for custom properties and `#name` for color tokens.
|
|
99
|
-
* @example { $spacing: '2x', '#accent': '#purple' }
|
|
100
|
-
*/
|
|
101
|
-
replaceTokens?: Record<`$${string}` | `#${string}`, string | number>;
|
|
102
|
-
/**
|
|
103
|
-
* Predefined style recipes -- named style bundles that can be applied via `recipe` style property.
|
|
104
|
-
* Recipe values are flat tasty styles (no sub-element keys).
|
|
105
|
-
* @example
|
|
106
|
-
* ```ts
|
|
107
|
-
* recipes: {
|
|
108
|
-
* card: { padding: '4x', fill: '#surface', radius: '1r', border: true },
|
|
109
|
-
* elevated: { shadow: '2x 2x 4x #shadow' },
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
recipes?: Record<string, RecipeStyles>;
|
|
114
|
-
/**
|
|
115
|
-
* Automatically infer and register CSS @property declarations from values.
|
|
116
|
-
* @default true
|
|
117
|
-
*/
|
|
118
|
-
autoPropertyTypes?: boolean;
|
|
119
|
-
}
|
|
18
|
+
};
|
|
120
19
|
interface TastyZeroBabelOptions {
|
|
121
20
|
/** Output path for generated CSS (default: 'tasty.css') */
|
|
122
21
|
output?: string;
|
|
@@ -158,10 +57,25 @@ interface TastyZeroBabelOptions {
|
|
|
158
57
|
* @default true
|
|
159
58
|
*/
|
|
160
59
|
injectImport?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Output mode for extracted CSS.
|
|
62
|
+
*
|
|
63
|
+
* - `'file'` (default): CSS is written to a single output file and
|
|
64
|
+
* the `@tenphi/tasty/static` import is rewritten to import that file.
|
|
65
|
+
* - `'inject'`: CSS is embedded inline in the JS output and injected
|
|
66
|
+
* at runtime via a tiny injector from `@tenphi/tasty/static/inject`.
|
|
67
|
+
* No CSS file is written. Each `tastyStatic` call becomes
|
|
68
|
+
* self-contained. Best for reusable components and extensions.
|
|
69
|
+
*
|
|
70
|
+
* When `mode` is `'inject'`, `output` and `injectImport` are ignored.
|
|
71
|
+
*
|
|
72
|
+
* @default 'file'
|
|
73
|
+
*/
|
|
74
|
+
mode?: 'file' | 'inject';
|
|
161
75
|
}
|
|
162
76
|
/** Clear the shared CSSWriter cache. Exposed for testing. */
|
|
163
77
|
declare function clearWriterCache(): void;
|
|
164
|
-
declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => _babel_core0.PluginObj<PluginPass>;
|
|
78
|
+
declare const _default: (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => _$_babel_core0.PluginObj<PluginPass>;
|
|
165
79
|
//#endregion
|
|
166
80
|
export { TastyZeroBabelOptions, TastyZeroConfig, clearWriterCache, _default as default };
|
|
167
81
|
//# sourceMappingURL=babel.d.ts.map
|
package/dist/zero/babel.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __require } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
-
import { configure, getGlobalConfigTokens, resetConfig } from "../config.js";
|
|
2
|
+
import { configure, getGlobalConfigTokens, getGlobalStyles, resetConfig } from "../config.js";
|
|
3
3
|
import { mergeStyles } from "../utils/merge-styles.js";
|
|
4
4
|
import { resolveRecipes } from "../utils/resolve-recipes.js";
|
|
5
5
|
import { extractCounterStyleFromStyles, extractFontFaceFromStyles, extractKeyframesFromStyles, extractPropertiesFromStyles, extractStylesForSelector, extractStylesWithChunks } from "./extractor.js";
|
|
@@ -9,7 +9,6 @@ import * as path from "path";
|
|
|
9
9
|
import { declare } from "@babel/helper-plugin-utils";
|
|
10
10
|
import * as t from "@babel/types";
|
|
11
11
|
import { createJiti } from "jiti";
|
|
12
|
-
|
|
13
12
|
//#region src/zero/babel.ts
|
|
14
13
|
/**
|
|
15
14
|
* Babel plugin for zero-runtime tasty static site generation.
|
|
@@ -58,10 +57,11 @@ function clearWriterCache() {
|
|
|
58
57
|
}
|
|
59
58
|
var babel_default = declare((api, options) => {
|
|
60
59
|
api.assertVersion(7);
|
|
60
|
+
const mode = options.mode ?? "file";
|
|
61
61
|
const outputPath = options.output || "tasty.css";
|
|
62
62
|
const resolvedOutputPath = path.resolve(outputPath);
|
|
63
63
|
const injectImport = options.injectImport ?? true;
|
|
64
|
-
if (injectImport) {
|
|
64
|
+
if (mode === "file" && injectImport) {
|
|
65
65
|
const dir = path.dirname(resolvedOutputPath);
|
|
66
66
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
67
67
|
if (!fs.existsSync(resolvedOutputPath)) fs.writeFileSync(resolvedOutputPath, "/* Generated by @tenphi/tasty/zero - DO NOT EDIT */\n");
|
|
@@ -86,10 +86,14 @@ var babel_default = declare((api, options) => {
|
|
|
86
86
|
if (cached) resetConfig();
|
|
87
87
|
configure(resolvedConfig);
|
|
88
88
|
const newWriter = new CSSWriter(outputPath, { devMode });
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
if (mode !== "inject") {
|
|
90
|
+
const tokenCSS = extractCSSFromStyles(":root", getGlobalConfigTokens());
|
|
91
|
+
if (tokenCSS) newWriter.add(":root:tokens", tokenCSS);
|
|
92
|
+
const globalStyles = getGlobalStyles();
|
|
93
|
+
if (globalStyles) for (const [selector, styles] of Object.entries(globalStyles)) {
|
|
94
|
+
const css = extractCSSFromStyles(selector, styles);
|
|
95
|
+
if (css) newWriter.add(`global:${selector}`, css);
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
98
|
writerCache.set(resolvedOutputPath, {
|
|
95
99
|
writer: newWriter,
|
|
@@ -103,6 +107,20 @@ var babel_default = declare((api, options) => {
|
|
|
103
107
|
const globalRegistry = entry.registry;
|
|
104
108
|
const config = entry.config;
|
|
105
109
|
const devMode = config.devMode ?? false;
|
|
110
|
+
let tokenCSS;
|
|
111
|
+
let globalStylesCSS;
|
|
112
|
+
if (mode === "inject") {
|
|
113
|
+
tokenCSS = extractCSSFromStyles(":root", getGlobalConfigTokens());
|
|
114
|
+
const gs = getGlobalStyles();
|
|
115
|
+
if (gs) {
|
|
116
|
+
globalStylesCSS = /* @__PURE__ */ new Map();
|
|
117
|
+
for (const [selector, styles] of Object.entries(gs)) {
|
|
118
|
+
const css = extractCSSFromStyles(selector, styles);
|
|
119
|
+
if (css) globalStylesCSS.set(selector, css);
|
|
120
|
+
}
|
|
121
|
+
if (globalStylesCSS.size === 0) globalStylesCSS = void 0;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
106
124
|
return {
|
|
107
125
|
name: "tasty-zero",
|
|
108
126
|
pre() {
|
|
@@ -113,7 +131,8 @@ var babel_default = declare((api, options) => {
|
|
|
113
131
|
visitor: {
|
|
114
132
|
ImportDeclaration(nodePath, state) {
|
|
115
133
|
const source = nodePath.node.source.value;
|
|
116
|
-
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) if (
|
|
134
|
+
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")));
|
|
135
|
+
else if (injectImport) {
|
|
117
136
|
let importPath = resolvedOutputPath;
|
|
118
137
|
if (state.filename) {
|
|
119
138
|
const sourceDir = path.dirname(state.filename);
|
|
@@ -130,9 +149,9 @@ var babel_default = declare((api, options) => {
|
|
|
130
149
|
const args = path.node.arguments;
|
|
131
150
|
if (args.length === 0) throw path.buildCodeFrameError("tastyStatic() requires at least one argument");
|
|
132
151
|
const firstArg = args[0];
|
|
133
|
-
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, state.sourceFile, config.keyframes, config.autoPropertyTypes, config.fontFace, config.counterStyle);
|
|
134
|
-
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, config.keyframes, config.autoPropertyTypes, config.fontFace, config.counterStyle);
|
|
135
|
-
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, config.keyframes, config.autoPropertyTypes, config.fontFace, config.counterStyle);
|
|
152
|
+
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.keyframes, config.autoPropertyTypes, config.fontFace, config.counterStyle);
|
|
153
|
+
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.autoPropertyTypes, config.fontFace, config.counterStyle);
|
|
154
|
+
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.autoPropertyTypes, config.fontFace, config.counterStyle);
|
|
136
155
|
else throw path.buildCodeFrameError("tastyStatic() first argument must be an object (styles), identifier (base StaticStyle), or string (selector)");
|
|
137
156
|
},
|
|
138
157
|
VariableDeclarator(path, state) {
|
|
@@ -156,6 +175,24 @@ var babel_default = declare((api, options) => {
|
|
|
156
175
|
}
|
|
157
176
|
},
|
|
158
177
|
post() {
|
|
178
|
+
if (mode === "inject") {
|
|
179
|
+
if (this._fileAddedCSS && (tokenCSS || globalStylesCSS)) {
|
|
180
|
+
const program = this.file.ast.program;
|
|
181
|
+
let insertIndex = 0;
|
|
182
|
+
for (let i = 0; i < program.body.length; i++) if (t.isImportDeclaration(program.body[i])) insertIndex = i + 1;
|
|
183
|
+
if (tokenCSS) {
|
|
184
|
+
const injectCall = createInjectCallAST(":root", tokenCSS);
|
|
185
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
186
|
+
insertIndex++;
|
|
187
|
+
}
|
|
188
|
+
if (globalStylesCSS) for (const [selector, css] of globalStylesCSS) {
|
|
189
|
+
const injectCall = createInjectCallAST(selector, css);
|
|
190
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
191
|
+
insertIndex++;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
159
196
|
if (this._fileAddedCSS && cssWriter.size > 0) cssWriter.write();
|
|
160
197
|
}
|
|
161
198
|
};
|
|
@@ -185,30 +222,30 @@ function extractClassNameFromStaticStyleObject(node) {
|
|
|
185
222
|
/**
|
|
186
223
|
* Handle tastyStatic(styles) - returns StaticStyle object
|
|
187
224
|
*/
|
|
188
|
-
function handleStylesMode(path, args, cssWriter, state, globalRegistry, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
225
|
+
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
189
226
|
const stylesArg = args[0];
|
|
190
227
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(styles) argument must be a static object literal");
|
|
191
228
|
const styles = resolveRecipes(evaluateObjectExpression(stylesArg, path));
|
|
192
229
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
193
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, state.sourceFile);
|
|
194
230
|
const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
for (const cs of extractCounterStyleFromStyles(styles, globalCounterStyle)) cssWriter.add(cs.css, cs.css, state.sourceFile);
|
|
231
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
232
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
198
233
|
const chunks = extractStylesWithChunks(styles);
|
|
199
|
-
for (const chunk of chunks) {
|
|
200
|
-
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
201
|
-
cssWriter.add(chunk.className, css, state.sourceFile);
|
|
202
|
-
}
|
|
203
234
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
204
235
|
const staticStyleObject = createStaticStyleAST(className, styles);
|
|
205
|
-
|
|
236
|
+
if (mode === "inject") {
|
|
237
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, chunks, nameMap));
|
|
238
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
239
|
+
} else {
|
|
240
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, chunks, nameMap, state.sourceFile);
|
|
241
|
+
path.replaceWith(staticStyleObject);
|
|
242
|
+
}
|
|
206
243
|
registerIfVariableDeclaration(path, className, styles, state, globalRegistry);
|
|
207
244
|
}
|
|
208
245
|
/**
|
|
209
246
|
* Handle tastyStatic(base, styles) - extends base with additional styles
|
|
210
247
|
*/
|
|
211
|
-
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
248
|
+
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
212
249
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(base, styles) requires two arguments");
|
|
213
250
|
const baseArg = args[0];
|
|
214
251
|
const stylesArg = args[1];
|
|
@@ -220,25 +257,25 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, globa
|
|
|
220
257
|
const overrideStyles = evaluateObjectExpression(stylesArg, path);
|
|
221
258
|
const mergedStyles = resolveRecipes(mergeStyles(baseEntry.styles, overrideStyles));
|
|
222
259
|
const { keyframes, nameMap } = extractKeyframesFromStyles(mergedStyles, globalKeyframes);
|
|
223
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, state.sourceFile);
|
|
224
260
|
const properties = extractPropertiesFromStyles(mergedStyles, { autoPropertyTypes });
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
for (const cs of extractCounterStyleFromStyles(mergedStyles, globalCounterStyle)) cssWriter.add(cs.css, cs.css, state.sourceFile);
|
|
261
|
+
const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);
|
|
262
|
+
const counterStyles = extractCounterStyleFromStyles(mergedStyles, globalCounterStyle);
|
|
228
263
|
const chunks = extractStylesWithChunks(mergedStyles);
|
|
229
|
-
for (const chunk of chunks) {
|
|
230
|
-
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
231
|
-
cssWriter.add(chunk.className, css, state.sourceFile);
|
|
232
|
-
}
|
|
233
264
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
234
265
|
const staticStyleObject = createStaticStyleAST(className, mergedStyles);
|
|
235
|
-
|
|
266
|
+
if (mode === "inject") {
|
|
267
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, chunks, nameMap));
|
|
268
|
+
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
269
|
+
} else {
|
|
270
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, chunks, nameMap, state.sourceFile);
|
|
271
|
+
path.replaceWith(staticStyleObject);
|
|
272
|
+
}
|
|
236
273
|
registerIfVariableDeclaration(path, className, mergedStyles, state, globalRegistry);
|
|
237
274
|
}
|
|
238
275
|
/**
|
|
239
276
|
* Handle tastyStatic(selector, styles) - removes the call entirely
|
|
240
277
|
*/
|
|
241
|
-
function handleSelectorMode(path, args, cssWriter, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
278
|
+
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
242
279
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(selector, styles) requires two arguments");
|
|
243
280
|
const selectorArg = args[0];
|
|
244
281
|
const stylesArg = args[1];
|
|
@@ -247,17 +284,68 @@ function handleSelectorMode(path, args, cssWriter, sourceFile, globalKeyframes,
|
|
|
247
284
|
const selector = selectorArg.value;
|
|
248
285
|
const styles = resolveRecipes(evaluateObjectExpression(stylesArg, path));
|
|
249
286
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
250
|
-
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
251
287
|
const properties = extractPropertiesFromStyles(styles, { autoPropertyTypes });
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
for (const cs of extractCounterStyleFromStyles(styles, globalCounterStyle)) cssWriter.add(cs.css, cs.css, sourceFile);
|
|
288
|
+
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
289
|
+
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
255
290
|
const result = extractStylesForSelector(selector, styles);
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
291
|
+
const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(result.css, nameMap) : result.css;
|
|
292
|
+
if (mode === "inject") {
|
|
293
|
+
const cssParts = [];
|
|
294
|
+
for (const kf of keyframes) cssParts.push(kf.css);
|
|
295
|
+
for (const prop of properties) cssParts.push(prop.css);
|
|
296
|
+
for (const ff of fontFaces) cssParts.push(ff.css);
|
|
297
|
+
for (const cs of counterStyles) cssParts.push(cs.css);
|
|
298
|
+
cssParts.push(selectorCSS);
|
|
299
|
+
const injectCall = createInjectCallAST(selector, cssParts.join("\n"));
|
|
300
|
+
const parent = path.parentPath;
|
|
301
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.replaceWith(t.expressionStatement(injectCall));
|
|
302
|
+
else path.replaceWith(injectCall);
|
|
303
|
+
} else {
|
|
304
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, [], nameMap, sourceFile);
|
|
305
|
+
cssWriter.add(selector, selectorCSS, sourceFile);
|
|
306
|
+
const parent = path.parentPath;
|
|
307
|
+
if (parent && t.isExpressionStatement(parent.node)) parent.remove();
|
|
308
|
+
else path.replaceWith(t.identifier("undefined"));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Collect all extracted CSS parts into a single string (for inject mode).
|
|
313
|
+
*/
|
|
314
|
+
function collectAllCSS(keyframes, properties, fontFaces, counterStyles, chunks, nameMap) {
|
|
315
|
+
const parts = [];
|
|
316
|
+
for (const kf of keyframes) parts.push(kf.css);
|
|
317
|
+
for (const prop of properties) parts.push(prop.css);
|
|
318
|
+
for (const ff of fontFaces) parts.push(ff.css);
|
|
319
|
+
for (const cs of counterStyles) parts.push(cs.css);
|
|
320
|
+
for (const chunk of chunks) parts.push(nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css);
|
|
321
|
+
return parts.join("\n");
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Write all extracted CSS parts to a CSSWriter (for file mode).
|
|
325
|
+
*/
|
|
326
|
+
function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, chunks, nameMap, sourceFile) {
|
|
327
|
+
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
328
|
+
for (const prop of properties) cssWriter.add(prop.css, prop.css, sourceFile);
|
|
329
|
+
for (const ff of fontFaces) cssWriter.add(ff.css, ff.css, sourceFile);
|
|
330
|
+
for (const cs of counterStyles) cssWriter.add(cs.css, cs.css, sourceFile);
|
|
331
|
+
for (const chunk of chunks) {
|
|
332
|
+
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
333
|
+
cssWriter.add(chunk.className, css, sourceFile);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Extract CSS for a selector from a styles/tokens object.
|
|
338
|
+
* Returns undefined when there are no styles or no CSS output.
|
|
339
|
+
*/
|
|
340
|
+
function extractCSSFromStyles(selector, styles) {
|
|
341
|
+
if (!styles || Object.keys(styles).length === 0) return void 0;
|
|
342
|
+
return extractStylesForSelector(selector, styles).css || void 0;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Create an `_$i(id, css)` call expression AST node for inject mode.
|
|
346
|
+
*/
|
|
347
|
+
function createInjectCallAST(id, css) {
|
|
348
|
+
return t.callExpression(t.identifier("_$i"), [t.stringLiteral(id), t.stringLiteral(css)]);
|
|
261
349
|
}
|
|
262
350
|
/**
|
|
263
351
|
* Create a StaticStyle object AST node
|
|
@@ -368,7 +456,7 @@ function replaceAnimationNamesInCSS(css, nameMap) {
|
|
|
368
456
|
function escapeRegex(str) {
|
|
369
457
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
370
458
|
}
|
|
371
|
-
|
|
372
459
|
//#endregion
|
|
373
460
|
export { clearWriterCache, babel_default as default };
|
|
461
|
+
|
|
374
462
|
//# sourceMappingURL=babel.js.map
|