@tenphi/tasty 0.0.0-snapshot.a85ade8 → 0.0.0-snapshot.a8a2a5d
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 +418 -381
- package/dist/babel-types-BOABQvEI.d.ts +16 -0
- package/dist/chunks/async-storage-CzSKAyrI.js +36 -0
- package/dist/chunks/async-storage-CzSKAyrI.js.map +1 -0
- package/dist/chunks/build-config-DQkT3Wru.js +59 -0
- package/dist/chunks/build-config-DQkT3Wru.js.map +1 -0
- package/dist/{collector-C6TtL8HJ.js → chunks/collector-Df9zcabl.js} +11 -129
- package/dist/chunks/collector-Df9zcabl.js.map +1 -0
- package/dist/chunks/config-engine-C7OUmM1J.js +269 -0
- package/dist/chunks/config-engine-C7OUmM1J.js.map +1 -0
- package/dist/chunks/config-file-BX3F_61U.js +24 -0
- package/dist/chunks/config-file-BX3F_61U.js.map +1 -0
- package/dist/chunks/css-definitions-BkdTqT7G.js +896 -0
- package/dist/chunks/css-definitions-BkdTqT7G.js.map +1 -0
- package/dist/chunks/css-resources-C0zT36nQ.js +141 -0
- package/dist/chunks/css-resources-C0zT36nQ.js.map +1 -0
- package/dist/chunks/debug-CwGMB2RI.js +501 -0
- package/dist/chunks/debug-CwGMB2RI.js.map +1 -0
- package/dist/chunks/dsl-BAwiOznp.js +1442 -0
- package/dist/chunks/dsl-BAwiOznp.js.map +1 -0
- package/dist/chunks/hydration-DEmoq1sQ.js +39 -0
- package/dist/chunks/hydration-DEmoq1sQ.js.map +1 -0
- package/dist/chunks/react-runtime-B8YqpFx7.js +678 -0
- package/dist/chunks/react-runtime-B8YqpFx7.js.map +1 -0
- package/dist/chunks/runtime-engine-CHNH2nGy.js +2418 -0
- package/dist/chunks/runtime-engine-CHNH2nGy.js.map +1 -0
- package/dist/chunks/runtime-state-BxLKsQzs.js +150 -0
- package/dist/chunks/runtime-state-BxLKsQzs.js.map +1 -0
- package/dist/{merge-styles-DuoZEsm9.js → chunks/shared-utils-CYgOs2mp.js} +58 -57
- package/dist/chunks/shared-utils-CYgOs2mp.js.map +1 -0
- package/dist/chunks/style-engine-DkKH-TqL.js +5573 -0
- package/dist/chunks/style-engine-DkKH-TqL.js.map +1 -0
- package/dist/{css-writer-Bgowobbx.js → chunks/zero-engine-C-0ar_PT.js} +67 -149
- package/dist/chunks/zero-engine-C-0ar_PT.js.map +1 -0
- package/dist/{collector-BTVXj2hS.d.ts → collector-BN6hCWIx.d.ts} +3 -6
- package/dist/{config-LfIDmVHx.d.ts → config-Chmu-PnP.d.ts} +49 -63
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CTh8SGd9.d.ts +20 -0
- package/dist/{index-Bm9ltvdH.d.ts → index-szujmf6W.d.ts} +263 -348
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -922
- package/dist/merge-styles-Cx25bpax.d.ts +4 -0
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +2 -16
- package/dist/ssr/astro-client.js.map +1 -1
- package/dist/ssr/astro-middleware-extract-static.d.ts +1 -4
- package/dist/ssr/astro-middleware-extract-static.js +1 -2
- package/dist/ssr/astro-middleware-extract.d.ts +1 -4
- package/dist/ssr/astro-middleware-extract.js +1 -2
- package/dist/ssr/astro-middleware-static.d.ts +1 -4
- package/dist/ssr/astro-middleware-static.js +2 -14
- package/dist/ssr/astro-middleware-static.js.map +1 -1
- package/dist/ssr/astro-middleware.d.ts +1 -4
- package/dist/ssr/astro-middleware.js +2 -15
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +17 -19
- package/dist/ssr/astro.js +218 -1
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +1 -0
- package/dist/ssr/index.d.ts +5 -27
- package/dist/ssr/index.js +6 -7
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +63 -0
- package/dist/ssr/next-config.js +122 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -10
- package/dist/ssr/next.js +30 -45
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -13
- package/dist/static/index.js +6 -26
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -4
- package/dist/static/inject.js +1 -2
- package/dist/{index-BmogEzTo.d.ts → types-DbMN-Yyn.d.ts} +1013 -1043
- package/dist/zero/babel.d.ts +71 -2
- package/dist/zero/babel.js +84 -150
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +61 -12
- package/dist/zero/index.js +24 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +5 -7
- package/dist/zero/next.js +4 -40
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +4 -1
- package/docs/adoption.md +25 -17
- package/docs/ai-agents.md +69 -34
- package/docs/comparison.md +9 -8
- package/docs/configuration.md +204 -70
- package/docs/debug.md +18 -7
- package/docs/design-system.md +129 -15
- package/docs/dsl.md +327 -117
- package/docs/getting-started.md +81 -22
- package/docs/injector.md +41 -40
- package/docs/llms.txt +31 -0
- package/docs/methodology.md +48 -23
- package/docs/migration-v3.md +3 -3
- package/docs/pipeline.md +55 -28
- package/docs/plugins.md +22 -42
- package/docs/react-api.md +76 -11
- package/docs/runtime-benchmarks.md +257 -47
- package/docs/ssr.md +226 -80
- package/docs/styles.md +169 -33
- package/docs/tasty-static.md +176 -58
- package/harness/dev.harnesspm/rules/usage.md +12 -0
- package/harness/dev.harnesspm/scripts/render.mjs +320 -0
- package/harness/dev.harnesspm/scripts/styles.mjs +299 -0
- package/harness/plugin.json +20 -0
- package/package.json +116 -48
- package/tasty.config.ts +1 -0
- package/dist/astro-ib7E7V4Y.js +0 -307
- package/dist/astro-ib7E7V4Y.js.map +0 -1
- package/dist/async-storage-DKK-wTD4.js +0 -44
- package/dist/async-storage-DKK-wTD4.js.map +0 -1
- package/dist/babel-DWCsafYw.d.ts +0 -83
- package/dist/collector-C6TtL8HJ.js.map +0 -1
- package/dist/config-B3gPdCqd.js +0 -12421
- package/dist/config-B3gPdCqd.js.map +0 -1
- package/dist/context-CA8YKeMn.js +0 -24
- package/dist/context-CA8YKeMn.js.map +0 -1
- package/dist/core-Bq7w2kti.js +0 -1686
- package/dist/core-Bq7w2kti.js.map +0 -1
- package/dist/css-writer-Bgowobbx.js.map +0 -1
- package/dist/format-global-rules-DklyaXv-.js +0 -22
- package/dist/format-global-rules-DklyaXv-.js.map +0 -1
- package/dist/format-rules-rCZ37rqY.js +0 -130
- package/dist/format-rules-rCZ37rqY.js.map +0 -1
- package/dist/hydrate-CNOmZprz.js +0 -37
- package/dist/hydrate-CNOmZprz.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-DE-OE76F.js +0 -535
- package/dist/keyframes-DE-OE76F.js.map +0 -1
- package/dist/merge-styles-BcLl1u_d.d.ts +0 -7
- package/dist/merge-styles-DuoZEsm9.js.map +0 -1
- package/dist/resolve-recipes-H9NqOQuP.js +0 -144
- package/dist/resolve-recipes-H9NqOQuP.js.map +0 -1
package/dist/zero/babel.d.ts
CHANGED
|
@@ -1,2 +1,71 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { t as TastyZeroConfig } from "../babel-types-BOABQvEI.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the `@tenphi/tasty/babel-plugin` Babel plugin.
|
|
4
|
+
*/
|
|
5
|
+
export interface TastyZeroBabelOptions {
|
|
6
|
+
/** Output path for generated CSS (default: 'tasty.css') */
|
|
7
|
+
output?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Tasty configuration for build-time processing.
|
|
10
|
+
* Can be a static object or a factory function that returns fresh config.
|
|
11
|
+
* A factory is called on each plugin invocation, enabling hot reload
|
|
12
|
+
* of config values that depend on external files (e.g. theme tokens).
|
|
13
|
+
*/
|
|
14
|
+
config?: TastyZeroConfig | (() => TastyZeroConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Absolute path to a TypeScript/JavaScript module that default-exports
|
|
17
|
+
* a `TastyZeroConfig` object. The module is loaded via jiti on each
|
|
18
|
+
* plugin invocation, enabling hot reload when the file changes.
|
|
19
|
+
*
|
|
20
|
+
* This option is JSON-serializable and is the primary way Turbopack
|
|
21
|
+
* passes config to the Babel plugin (since Turbopack loader options
|
|
22
|
+
* must be plain primitives/objects/arrays).
|
|
23
|
+
*
|
|
24
|
+
* When both `config` and `configFile` are set, `config` takes precedence.
|
|
25
|
+
*
|
|
26
|
+
* @example '/absolute/path/to/tasty-zero.config.ts'
|
|
27
|
+
*/
|
|
28
|
+
configFile?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Absolute file paths whose content affects the generated CSS.
|
|
31
|
+
* When any of these files change, babel-loader invalidates its cache
|
|
32
|
+
* and re-runs the plugin with fresh config values.
|
|
33
|
+
*
|
|
34
|
+
* Typically includes theme files that define Glaze palettes or token values.
|
|
35
|
+
* Paths must be absolute (resolved by the Next.js wrapper).
|
|
36
|
+
*/
|
|
37
|
+
configDeps?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Automatically replace `@tenphi/tasty/static` imports with an import
|
|
40
|
+
* of the generated CSS file. This eliminates the need for users to
|
|
41
|
+
* manually import the CSS in their app entry point.
|
|
42
|
+
*
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
injectImport?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Output mode for extracted CSS.
|
|
48
|
+
*
|
|
49
|
+
* - `'file'` (default): CSS is written to a single output file and
|
|
50
|
+
* the `@tenphi/tasty/static` import is rewritten to import that file.
|
|
51
|
+
* - `'inject'`: CSS is embedded inline in the JS output and injected
|
|
52
|
+
* at runtime via a tiny injector from `@tenphi/tasty/static/inject`.
|
|
53
|
+
* No CSS file is written. Each `tastyStatic` call becomes
|
|
54
|
+
* self-contained. Best for reusable components and extensions.
|
|
55
|
+
*
|
|
56
|
+
* When `mode` is `'inject'`, `output` and `injectImport` are ignored.
|
|
57
|
+
*
|
|
58
|
+
* @default 'file'
|
|
59
|
+
*/
|
|
60
|
+
mode?: 'file' | 'inject';
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The plugin's call signature, written out rather than inferred from
|
|
64
|
+
* `declare()` so the published declaration names no Babel types: Babel 7's
|
|
65
|
+
* come from `@types/babel__core`, Babel 8 ships its own, and the two name the
|
|
66
|
+
* plugin object differently.
|
|
67
|
+
*/
|
|
68
|
+
type TastyZeroBabelPlugin = (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => object;
|
|
69
|
+
declare const _default: TastyZeroBabelPlugin;
|
|
70
|
+
export { type TastyZeroConfig, _default as default };
|
|
71
|
+
//# sourceMappingURL=babel.d.ts.map
|
package/dist/zero/babel.js
CHANGED
|
@@ -1,40 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
1
|
+
import { t as mergeStyles } from "../chunks/shared-utils-CYgOs2mp.js";
|
|
2
|
+
import "../chunks/css-definitions-BkdTqT7G.js";
|
|
3
|
+
import { t as resolveRecipesWith } from "../chunks/config-engine-C7OUmM1J.js";
|
|
4
|
+
import { t as loadConfigFile } from "../chunks/config-file-BX3F_61U.js";
|
|
5
|
+
import { a as extractCounterStyleFromStyles, c as extractKeyframesFromStyles, h as setExtractorNamePrefix, i as extractConfigProperties, l as extractPropertiesFromStyles, m as replaceAnimationNamesInCSS, o as extractFontFaceFromStyles, p as renderSelectorCSS, r as extractChunks, s as extractFunctionsFromStyles, t as CSSWriter, u as extractSelectorCSS } from "../chunks/zero-engine-C-0ar_PT.js";
|
|
6
|
+
import { a as resetZeroConfig, i as reapplyZeroConfig, n as functionsForExtraction, t as configureZero } from "../chunks/build-config-DQkT3Wru.js";
|
|
5
7
|
import * as fs from "fs";
|
|
6
8
|
import * as path from "path";
|
|
7
9
|
import { declare } from "@babel/helper-plugin-utils";
|
|
8
10
|
import * as t from "@babel/types";
|
|
9
|
-
|
|
10
|
-
//#region \0rolldown/runtime.js
|
|
11
|
+
// \0rolldown/runtime.js
|
|
11
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) {
|
|
12
13
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
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.");
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
-
//#region src/zero/writer-cache.ts
|
|
16
|
+
// src/zero/writer-cache.ts
|
|
17
17
|
const writerCache = /* @__PURE__ */ new Map();
|
|
18
|
-
|
|
19
|
-
//#region src/zero/babel.ts
|
|
20
|
-
/**
|
|
21
|
-
* Babel plugin for zero-runtime tasty static site generation.
|
|
22
|
-
*
|
|
23
|
-
* Transforms:
|
|
24
|
-
* - `tastyStatic(styles)` → StaticStyle object { className, styles, toString() }
|
|
25
|
-
* - `tastyStatic(base, styles)` → StaticStyle object with merged styles
|
|
26
|
-
* - `tastyStatic(selector, styles)` → removed entirely
|
|
27
|
-
*
|
|
28
|
-
* Usage:
|
|
29
|
-
* ```javascript
|
|
30
|
-
* // babel.config.js
|
|
31
|
-
* module.exports = {
|
|
32
|
-
* plugins: [
|
|
33
|
-
* ['@tenphi/tasty/babel-plugin', { output: 'public/tasty.css' }]
|
|
34
|
-
* ]
|
|
35
|
-
* };
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
18
|
+
// src/zero/babel.ts
|
|
38
19
|
function mtime(filePath) {
|
|
39
20
|
try {
|
|
40
21
|
return fs.statSync(filePath).mtimeMs;
|
|
@@ -57,8 +38,8 @@ function clearRequireCacheTree(filePath) {
|
|
|
57
38
|
}
|
|
58
39
|
delete __require.cache[resolved];
|
|
59
40
|
}
|
|
60
|
-
|
|
61
|
-
api.assertVersion(7);
|
|
41
|
+
const plugin = declare((api, options) => {
|
|
42
|
+
api.assertVersion("^7.0.0-0 || ^8.0.0-0");
|
|
62
43
|
const mode = options.mode ?? "file";
|
|
63
44
|
const outputPath = options.output || "tasty.css";
|
|
64
45
|
const resolvedOutputPath = path.resolve(outputPath);
|
|
@@ -82,50 +63,54 @@ var babel_default = declare((api, options) => {
|
|
|
82
63
|
const configOption = options.config;
|
|
83
64
|
let resolvedConfig;
|
|
84
65
|
if (configOption) resolvedConfig = typeof configOption === "function" ? configOption() : configOption;
|
|
85
|
-
else if (options.configFile)
|
|
86
|
-
|
|
87
|
-
resolvedConfig = loaded && typeof loaded === "object" && "default" in loaded ? loaded.default : loaded;
|
|
88
|
-
} else resolvedConfig = {};
|
|
66
|
+
else if (options.configFile) resolvedConfig = loadConfigFile(options.configFile);
|
|
67
|
+
else resolvedConfig = {};
|
|
89
68
|
const devMode = resolvedConfig.devMode ?? false;
|
|
90
|
-
|
|
69
|
+
resetZeroConfig();
|
|
91
70
|
const finalConfig = {
|
|
92
71
|
namePrefix: "ts",
|
|
93
72
|
...resolvedConfig
|
|
94
73
|
};
|
|
95
|
-
|
|
74
|
+
const config = configureZero(finalConfig);
|
|
96
75
|
setExtractorNamePrefix(finalConfig.namePrefix ?? "ts");
|
|
97
76
|
const newWriter = new CSSWriter(outputPath, { devMode });
|
|
98
77
|
if (mode !== "inject") {
|
|
99
|
-
const
|
|
78
|
+
for (const prop of extractConfigProperties(config.normalized.properties)) newWriter.add(`@property:${prop.name}`, prop.css);
|
|
79
|
+
const tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
100
80
|
if (tokenCSS) newWriter.add(":root:tokens", tokenCSS);
|
|
101
|
-
const
|
|
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
|
-
}
|
|
81
|
+
for (const [selector, styles] of Object.entries(config.normalized.globalStyles)) writeGlobalStyles(newWriter, selector, styles, config.normalized.keyframes);
|
|
106
82
|
}
|
|
107
83
|
writerCache.set(resolvedOutputPath, {
|
|
108
84
|
writer: newWriter,
|
|
109
85
|
configKey,
|
|
110
86
|
registry: {},
|
|
111
|
-
config
|
|
87
|
+
config
|
|
112
88
|
});
|
|
113
89
|
}
|
|
114
90
|
const entry = writerCache.get(resolvedOutputPath);
|
|
91
|
+
entry.config = reapplyZeroConfig(entry.config);
|
|
115
92
|
const cssWriter = entry.writer;
|
|
116
93
|
const globalRegistry = entry.registry;
|
|
117
94
|
const config = entry.config;
|
|
118
|
-
const
|
|
119
|
-
|
|
95
|
+
const sourceConfig = config.source;
|
|
96
|
+
const devMode = sourceConfig.devMode ?? false;
|
|
97
|
+
setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
|
|
98
|
+
const configProperties = extractConfigProperties(config.normalized.properties);
|
|
99
|
+
const propertyOptions = {
|
|
100
|
+
autoPropertyTypes: sourceConfig.autoPropertyTypes,
|
|
101
|
+
defined: new Set(configProperties.map((prop) => prop.name))
|
|
102
|
+
};
|
|
103
|
+
let propertyCSS;
|
|
120
104
|
let tokenCSS;
|
|
121
105
|
let globalStylesCSS;
|
|
122
106
|
if (mode === "inject") {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
107
|
+
propertyCSS = configProperties.map((prop) => prop.css).join("\n") || void 0;
|
|
108
|
+
tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
109
|
+
const gs = config.normalized.globalStyles;
|
|
110
|
+
if (Object.keys(gs).length > 0) {
|
|
126
111
|
globalStylesCSS = /* @__PURE__ */ new Map();
|
|
127
112
|
for (const [selector, styles] of Object.entries(gs)) {
|
|
128
|
-
const css = extractCSSFromStyles(selector, styles);
|
|
113
|
+
const css = extractCSSFromStyles(selector, styles, config.normalized.keyframes);
|
|
129
114
|
if (css) globalStylesCSS.set(selector, css);
|
|
130
115
|
}
|
|
131
116
|
if (globalStylesCSS.size === 0) globalStylesCSS = void 0;
|
|
@@ -134,6 +119,8 @@ var babel_default = declare((api, options) => {
|
|
|
134
119
|
return {
|
|
135
120
|
name: "tasty-zero",
|
|
136
121
|
pre() {
|
|
122
|
+
entry.config = reapplyZeroConfig(entry.config);
|
|
123
|
+
setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
|
|
137
124
|
this.staticStyleRegistry = {};
|
|
138
125
|
this._fileAddedCSS = false;
|
|
139
126
|
if (devMode && this.filename) this.sourceFile = this.filename.split("/").pop() || this.filename;
|
|
@@ -141,16 +128,18 @@ var babel_default = declare((api, options) => {
|
|
|
141
128
|
visitor: {
|
|
142
129
|
ImportDeclaration(nodePath, state) {
|
|
143
130
|
const source = nodePath.node.source.value;
|
|
144
|
-
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static"))
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
131
|
+
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) {
|
|
132
|
+
if (mode === "inject") nodePath.replaceWith(t.importDeclaration([t.importSpecifier(t.identifier("_$i"), t.identifier("injectCSS"))], t.stringLiteral("@tenphi/tasty/static/inject")));
|
|
133
|
+
else if (injectImport) {
|
|
134
|
+
let importPath = resolvedOutputPath;
|
|
135
|
+
if (state.filename) {
|
|
136
|
+
const sourceDir = path.dirname(state.filename);
|
|
137
|
+
importPath = path.relative(sourceDir, resolvedOutputPath);
|
|
138
|
+
if (!importPath.startsWith(".")) importPath = "./" + importPath;
|
|
139
|
+
}
|
|
140
|
+
nodePath.replaceWith(t.importDeclaration([], t.stringLiteral(importPath)));
|
|
141
|
+
} else nodePath.remove();
|
|
142
|
+
}
|
|
154
143
|
},
|
|
155
144
|
CallExpression(path, state) {
|
|
156
145
|
const callee = path.node.callee;
|
|
@@ -159,9 +148,9 @@ var babel_default = declare((api, options) => {
|
|
|
159
148
|
const args = path.node.arguments;
|
|
160
149
|
if (args.length === 0) throw path.buildCodeFrameError("tastyStatic() requires at least one argument");
|
|
161
150
|
const firstArg = args[0];
|
|
162
|
-
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.keyframes,
|
|
163
|
-
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes,
|
|
164
|
-
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes,
|
|
151
|
+
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
152
|
+
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
153
|
+
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
165
154
|
else throw path.buildCodeFrameError("tastyStatic() first argument must be an object (styles), identifier (base StaticStyle), or string (selector)");
|
|
166
155
|
},
|
|
167
156
|
VariableDeclarator(path, state) {
|
|
@@ -186,10 +175,15 @@ var babel_default = declare((api, options) => {
|
|
|
186
175
|
},
|
|
187
176
|
post() {
|
|
188
177
|
if (mode === "inject") {
|
|
189
|
-
if (this._fileAddedCSS && (tokenCSS || globalStylesCSS)) {
|
|
178
|
+
if (this._fileAddedCSS && (propertyCSS || tokenCSS || globalStylesCSS)) {
|
|
190
179
|
const program = this.file.ast.program;
|
|
191
180
|
let insertIndex = 0;
|
|
192
181
|
for (let i = 0; i < program.body.length; i++) if (t.isImportDeclaration(program.body[i])) insertIndex = i + 1;
|
|
182
|
+
if (propertyCSS) {
|
|
183
|
+
const injectCall = createInjectCallAST("@property", propertyCSS);
|
|
184
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
185
|
+
insertIndex++;
|
|
186
|
+
}
|
|
193
187
|
if (tokenCSS) {
|
|
194
188
|
const injectCall = createInjectCallAST(":root", tokenCSS);
|
|
195
189
|
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
@@ -207,41 +201,30 @@ var babel_default = declare((api, options) => {
|
|
|
207
201
|
}
|
|
208
202
|
};
|
|
209
203
|
});
|
|
210
|
-
/**
|
|
211
|
-
* Check if an object expression looks like a StaticStyle object
|
|
212
|
-
*/
|
|
213
204
|
function isStaticStyleObject(node) {
|
|
214
205
|
const hasClassName = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "className" }));
|
|
215
206
|
const hasStyles = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "styles" }));
|
|
216
207
|
return hasClassName && hasStyles;
|
|
217
208
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Extract styles object from a StaticStyle object expression
|
|
220
|
-
*/
|
|
221
209
|
function extractStylesFromStaticStyleObject(node, path) {
|
|
222
210
|
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);
|
|
223
211
|
return null;
|
|
224
212
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Extract className from a StaticStyle object expression
|
|
227
|
-
*/
|
|
228
213
|
function extractClassNameFromStaticStyleObject(node) {
|
|
229
214
|
for (const prop of node.properties) if (t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "className" }) && t.isStringLiteral(prop.value)) return prop.value.value;
|
|
230
215
|
return null;
|
|
231
216
|
}
|
|
232
|
-
|
|
233
|
-
* Handle tastyStatic(styles) - returns StaticStyle object
|
|
234
|
-
*/
|
|
235
|
-
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
|
|
217
|
+
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
236
218
|
const stylesArg = args[0];
|
|
237
219
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(styles) argument must be a static object literal");
|
|
238
|
-
const
|
|
220
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
221
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
239
222
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
240
|
-
const properties = extractPropertiesFromStyles(styles,
|
|
223
|
+
const properties = extractPropertiesFromStyles(styles, propertyOptions);
|
|
241
224
|
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
242
225
|
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
243
226
|
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
244
|
-
const chunks =
|
|
227
|
+
const chunks = extractChunks(styles);
|
|
245
228
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
246
229
|
const staticStyleObject = createStaticStyleAST(className, styles);
|
|
247
230
|
if (mode === "inject") {
|
|
@@ -253,10 +236,7 @@ function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, gl
|
|
|
253
236
|
}
|
|
254
237
|
registerIfVariableDeclaration(path, className, styles, state, globalRegistry);
|
|
255
238
|
}
|
|
256
|
-
|
|
257
|
-
* Handle tastyStatic(base, styles) - extends base with additional styles
|
|
258
|
-
*/
|
|
259
|
-
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
|
|
239
|
+
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
260
240
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(base, styles) requires two arguments");
|
|
261
241
|
const baseArg = args[0];
|
|
262
242
|
const stylesArg = args[1];
|
|
@@ -266,13 +246,13 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode,
|
|
|
266
246
|
const baseEntry = state.staticStyleRegistry[baseName] || globalRegistry[baseName];
|
|
267
247
|
if (!baseEntry) throw path.buildCodeFrameError(`Cannot find base StaticStyle '${baseName}'. Make sure it is defined before being extended.`);
|
|
268
248
|
const overrideStyles = evaluateObjectExpression(stylesArg, path);
|
|
269
|
-
const mergedStyles =
|
|
249
|
+
const mergedStyles = resolveRecipesWith(mergeStyles(baseEntry.styles, overrideStyles), globalRecipes ?? null);
|
|
270
250
|
const { keyframes, nameMap } = extractKeyframesFromStyles(mergedStyles, globalKeyframes);
|
|
271
|
-
const properties = extractPropertiesFromStyles(mergedStyles,
|
|
251
|
+
const properties = extractPropertiesFromStyles(mergedStyles, propertyOptions);
|
|
272
252
|
const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);
|
|
273
253
|
const counterStyles = extractCounterStyleFromStyles(mergedStyles, globalCounterStyle);
|
|
274
254
|
const functions = extractFunctionsFromStyles(mergedStyles, globalFunction);
|
|
275
|
-
const chunks =
|
|
255
|
+
const chunks = extractChunks(mergedStyles);
|
|
276
256
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
277
257
|
const staticStyleObject = createStaticStyleAST(className, mergedStyles);
|
|
278
258
|
if (mode === "inject") {
|
|
@@ -284,24 +264,22 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode,
|
|
|
284
264
|
}
|
|
285
265
|
registerIfVariableDeclaration(path, className, mergedStyles, state, globalRegistry);
|
|
286
266
|
}
|
|
287
|
-
|
|
288
|
-
* Handle tastyStatic(selector, styles) - removes the call entirely
|
|
289
|
-
*/
|
|
290
|
-
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle, globalFunction) {
|
|
267
|
+
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
291
268
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(selector, styles) requires two arguments");
|
|
292
269
|
const selectorArg = args[0];
|
|
293
270
|
const stylesArg = args[1];
|
|
294
271
|
if (!t.isStringLiteral(selectorArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) first argument must be a string literal");
|
|
295
272
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) second argument must be a static object literal");
|
|
296
273
|
const selector = selectorArg.value;
|
|
297
|
-
const
|
|
274
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
275
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
298
276
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
299
|
-
const properties = extractPropertiesFromStyles(styles,
|
|
277
|
+
const properties = extractPropertiesFromStyles(styles, propertyOptions);
|
|
300
278
|
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
301
279
|
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
302
280
|
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
303
|
-
const
|
|
304
|
-
const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(
|
|
281
|
+
const css = renderSelectorCSS(selector, styles);
|
|
282
|
+
const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(css, nameMap) : css;
|
|
305
283
|
if (mode === "inject") {
|
|
306
284
|
const cssParts = [];
|
|
307
285
|
for (const kf of keyframes) cssParts.push(kf.css);
|
|
@@ -322,9 +300,6 @@ function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyfr
|
|
|
322
300
|
else path.replaceWith(t.identifier("undefined"));
|
|
323
301
|
}
|
|
324
302
|
}
|
|
325
|
-
/**
|
|
326
|
-
* Collect all extracted CSS parts into a single string (for inject mode).
|
|
327
|
-
*/
|
|
328
303
|
function collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap) {
|
|
329
304
|
const parts = [];
|
|
330
305
|
for (const kf of keyframes) parts.push(kf.css);
|
|
@@ -335,9 +310,6 @@ function collectAllCSS(keyframes, properties, fontFaces, counterStyles, function
|
|
|
335
310
|
for (const chunk of chunks) parts.push(nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css);
|
|
336
311
|
return parts.join("\n");
|
|
337
312
|
}
|
|
338
|
-
/**
|
|
339
|
-
* Write all extracted CSS parts to a CSSWriter (for file mode).
|
|
340
|
-
*/
|
|
341
313
|
function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, sourceFile) {
|
|
342
314
|
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
343
315
|
for (const prop of properties) cssWriter.add(prop.css, prop.css, sourceFile);
|
|
@@ -349,23 +321,19 @@ function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterSt
|
|
|
349
321
|
cssWriter.add(chunk.className, css, sourceFile);
|
|
350
322
|
}
|
|
351
323
|
}
|
|
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) {
|
|
324
|
+
function extractCSSFromStyles(selector, styles, globalKeyframes) {
|
|
357
325
|
if (!styles || Object.keys(styles).length === 0) return void 0;
|
|
358
|
-
return
|
|
326
|
+
return extractSelectorCSS(selector, styles, globalKeyframes) || void 0;
|
|
327
|
+
}
|
|
328
|
+
function writeGlobalStyles(cssWriter, selector, styles, globalKeyframes) {
|
|
329
|
+
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
330
|
+
for (const kf of keyframes) cssWriter.add(kf.css, kf.css);
|
|
331
|
+
const css = replaceAnimationNamesInCSS(renderSelectorCSS(selector, styles), nameMap);
|
|
332
|
+
if (css) cssWriter.add(`global:${selector}`, css);
|
|
359
333
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Create an `_$i(id, css)` call expression AST node for inject mode.
|
|
362
|
-
*/
|
|
363
334
|
function createInjectCallAST(id, css) {
|
|
364
335
|
return t.callExpression(t.identifier("_$i"), [t.stringLiteral(id), t.stringLiteral(css)]);
|
|
365
336
|
}
|
|
366
|
-
/**
|
|
367
|
-
* Create a StaticStyle object AST node
|
|
368
|
-
*/
|
|
369
337
|
function createStaticStyleAST(className, styles) {
|
|
370
338
|
return t.objectExpression([
|
|
371
339
|
t.objectProperty(t.identifier("className"), t.stringLiteral(className)),
|
|
@@ -373,9 +341,6 @@ function createStaticStyleAST(className, styles) {
|
|
|
373
341
|
t.objectMethod("method", t.identifier("toString"), [], t.blockStatement([t.returnStatement(t.memberExpression(t.thisExpression(), t.identifier("className")))]))
|
|
374
342
|
]);
|
|
375
343
|
}
|
|
376
|
-
/**
|
|
377
|
-
* Register a StaticStyle in the registry if it's being assigned to a variable
|
|
378
|
-
*/
|
|
379
344
|
function registerIfVariableDeclaration(path, className, styles, state, globalRegistry) {
|
|
380
345
|
const parent = path.parentPath;
|
|
381
346
|
if (parent && t.isVariableDeclarator(parent.node)) {
|
|
@@ -393,14 +358,11 @@ function registerIfVariableDeclaration(path, className, styles, state, globalReg
|
|
|
393
358
|
}
|
|
394
359
|
}
|
|
395
360
|
}
|
|
396
|
-
/**
|
|
397
|
-
* Convert a JavaScript value to an AST node
|
|
398
|
-
*/
|
|
399
361
|
function valueToAST(value) {
|
|
400
362
|
if (value === null) return t.nullLiteral();
|
|
401
363
|
if (value === void 0) return t.identifier("undefined");
|
|
402
364
|
if (typeof value === "string") return t.stringLiteral(value);
|
|
403
|
-
if (typeof value === "number") return t.
|
|
365
|
+
if (typeof value === "number") return t.valueToNode(value);
|
|
404
366
|
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
405
367
|
if (Array.isArray(value)) return t.arrayExpression(value.map(valueToAST));
|
|
406
368
|
if (typeof value === "object") {
|
|
@@ -409,10 +371,6 @@ function valueToAST(value) {
|
|
|
409
371
|
}
|
|
410
372
|
return t.identifier("undefined");
|
|
411
373
|
}
|
|
412
|
-
/**
|
|
413
|
-
* Evaluate an ObjectExpression to a plain JavaScript object.
|
|
414
|
-
* Only supports static values that can be determined at build time.
|
|
415
|
-
*/
|
|
416
374
|
function evaluateObjectExpression(node, path) {
|
|
417
375
|
const result = {};
|
|
418
376
|
for (const prop of node.properties) {
|
|
@@ -422,13 +380,11 @@ function evaluateObjectExpression(node, path) {
|
|
|
422
380
|
if (t.isIdentifier(prop.key)) key = prop.key.name;
|
|
423
381
|
else if (t.isStringLiteral(prop.key)) key = prop.key.value;
|
|
424
382
|
else throw path.buildCodeFrameError("Dynamic property keys are not supported in tastyStatic()");
|
|
425
|
-
|
|
383
|
+
const value = evaluateExpression(prop.value, path);
|
|
384
|
+
result[key] = value;
|
|
426
385
|
}
|
|
427
386
|
return result;
|
|
428
387
|
}
|
|
429
|
-
/**
|
|
430
|
-
* Evaluate an expression to a JavaScript value.
|
|
431
|
-
*/
|
|
432
388
|
function evaluateExpression(node, path) {
|
|
433
389
|
if (t.isStringLiteral(node)) return node.value;
|
|
434
390
|
if (t.isNumericLiteral(node)) return node.value;
|
|
@@ -451,28 +407,6 @@ function evaluateExpression(node, path) {
|
|
|
451
407
|
}
|
|
452
408
|
throw path.buildCodeFrameError(`Dynamic expressions are not supported in tastyStatic() - got ${node.type}. All values must be static literals.`);
|
|
453
409
|
}
|
|
454
|
-
|
|
455
|
-
* Replace animation names in CSS string.
|
|
456
|
-
* Wraps the keyframes replaceAnimationNames to work on full CSS blocks.
|
|
457
|
-
*/
|
|
458
|
-
function replaceAnimationNamesInCSS(css, nameMap) {
|
|
459
|
-
if (nameMap.size === 0) return css;
|
|
460
|
-
return css.replace(/(animation(?:-name)?)\s*:\s*([^;}]+)/gi, (match, prop, value) => {
|
|
461
|
-
let newValue = value;
|
|
462
|
-
for (const [original, replacement] of nameMap) {
|
|
463
|
-
const pattern = new RegExp(`\\b${escapeRegex(original)}\\b`, "g");
|
|
464
|
-
newValue = newValue.replace(pattern, replacement);
|
|
465
|
-
}
|
|
466
|
-
return `${prop}: ${newValue}`;
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Escape special regex characters.
|
|
471
|
-
*/
|
|
472
|
-
function escapeRegex(str) {
|
|
473
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
474
|
-
}
|
|
475
|
-
//#endregion
|
|
476
|
-
export { babel_default as default };
|
|
410
|
+
export { plugin as default };
|
|
477
411
|
|
|
478
412
|
//# sourceMappingURL=babel.js.map
|