@tenphi/tasty 0.0.0-snapshot.2ea241d → 0.0.0-snapshot.2f4e31d
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 +440 -372
- package/dist/babel-types-Dc5zghyE.d.ts +18 -0
- package/dist/chunks/async-storage-f9j9JRtq.js +37 -0
- package/dist/chunks/async-storage-f9j9JRtq.js.map +1 -0
- package/dist/chunks/build-config-D9Iq8QQm.js +60 -0
- package/dist/chunks/build-config-D9Iq8QQm.js.map +1 -0
- package/dist/{collector-Crs9kGJW.js → chunks/collector-Cb8ah2JF.js} +68 -101
- package/dist/chunks/collector-Cb8ah2JF.js.map +1 -0
- package/dist/chunks/config-engine-CMYFZYQh.js +272 -0
- package/dist/chunks/config-engine-CMYFZYQh.js.map +1 -0
- package/dist/chunks/config-file-DlZXJMj8.js +25 -0
- package/dist/chunks/config-file-DlZXJMj8.js.map +1 -0
- package/dist/chunks/css-definitions-B4aWBkH3.js +910 -0
- package/dist/chunks/css-definitions-B4aWBkH3.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-D2Pu7Xhy.js +502 -0
- package/dist/chunks/debug-D2Pu7Xhy.js.map +1 -0
- package/dist/chunks/dsl-CsFl9LGn.js +1458 -0
- package/dist/chunks/dsl-CsFl9LGn.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-DHiopXCu.js +691 -0
- package/dist/chunks/react-runtime-DHiopXCu.js.map +1 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js +2435 -0
- package/dist/chunks/runtime-engine-NGCofNXy.js.map +1 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js +152 -0
- package/dist/chunks/runtime-state-lZjMbvwV.js.map +1 -0
- package/dist/{merge-styles-BzQutdAK.js → chunks/shared-utils-y-HjvPN4.js} +60 -55
- package/dist/chunks/shared-utils-y-HjvPN4.js.map +1 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js +5602 -0
- package/dist/chunks/style-engine-DnkV_4Jg.js.map +1 -0
- package/dist/{css-writer-CPy_cbFJ.js → chunks/zero-engine-DcwaCvFs.js} +95 -136
- package/dist/chunks/zero-engine-DcwaCvFs.js.map +1 -0
- package/dist/{collector-osfWTeRd.d.ts → collector-D2OT6I2G.d.ts} +64 -8
- package/dist/{config-BoZDUHW5.d.ts → config-C4ftFxgI.d.ts} +514 -92
- package/dist/core/index.d.ts +5 -5
- package/dist/core/index.js +9 -6
- package/dist/hydrate-CRyjjAyl.d.ts +22 -0
- package/dist/{index-B_k47mc_.d.ts → index-DxQNRj50.d.ts} +717 -408
- package/dist/index.d.ts +5 -5
- package/dist/index.js +11 -732
- package/dist/{merge-styles-BMWcH6MF.d.ts → merge-styles-D39qBtox.d.ts} +2 -3
- package/dist/ssr/astro-client.d.ts +1 -1
- package/dist/ssr/astro-client.js +1 -14
- package/dist/ssr/astro-client.js.map +1 -1
- 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 +11 -8
- package/dist/ssr/astro-middleware.js +2 -14
- package/dist/ssr/astro-middleware.js.map +1 -1
- package/dist/ssr/astro.d.ts +40 -10
- package/dist/ssr/astro.js +163 -91
- package/dist/ssr/astro.js.map +1 -1
- package/dist/ssr/client.d.ts +2 -0
- package/dist/ssr/client.js +2 -0
- package/dist/ssr/index.d.ts +5 -32
- package/dist/ssr/index.js +6 -6
- package/dist/ssr/index.js.map +1 -1
- package/dist/ssr/next-config.d.ts +64 -0
- package/dist/ssr/next-config.js +123 -0
- package/dist/ssr/next-config.js.map +1 -0
- package/dist/ssr/next.d.ts +9 -9
- package/dist/ssr/next.js +29 -44
- package/dist/ssr/next.js.map +1 -1
- package/dist/static/index.d.ts +8 -9
- package/dist/static/index.js +4 -22
- package/dist/static/index.js.map +1 -1
- package/dist/static/inject.d.ts +1 -2
- package/dist/static/inject.js.map +1 -1
- package/dist/{index-tcHuMPFt.d.ts → types-CYQIhUg1.d.ts} +883 -600
- package/dist/zero/babel.d.ts +12 -20
- package/dist/zero/babel.js +97 -156
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/index.d.ts +76 -7
- package/dist/zero/index.js +25 -2
- package/dist/zero/index.js.map +1 -0
- package/dist/zero/next.d.ts +4 -5
- package/dist/zero/next.js +3 -38
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +20 -9
- package/docs/adoption.md +69 -36
- package/docs/ai-agents.md +259 -0
- package/docs/comparison.md +77 -47
- package/docs/configuration.md +617 -98
- package/docs/debug.md +28 -15
- package/docs/design-system.md +154 -33
- package/docs/dsl.md +715 -194
- package/docs/getting-started.md +130 -50
- package/docs/injector.md +160 -69
- package/docs/methodology.md +82 -51
- package/docs/migration-v3.md +285 -0
- package/docs/pipeline.md +102 -33
- package/docs/plugins.md +333 -0
- package/docs/react-api.md +215 -50
- package/docs/runtime-benchmarks.md +388 -0
- package/docs/ssr.md +310 -118
- package/docs/styles.md +225 -42
- package/docs/tasty-static.md +289 -136
- package/package.json +146 -41
- package/tasty.config.ts +6 -0
- package/dist/async-storage-B7_o6FKt.js +0 -44
- package/dist/async-storage-B7_o6FKt.js.map +0 -1
- package/dist/collector-Crs9kGJW.js.map +0 -1
- package/dist/config-BaxtQMS3.js +0 -10464
- package/dist/config-BaxtQMS3.js.map +0 -1
- package/dist/context-CkSg-kDT.js +0 -24
- package/dist/context-CkSg-kDT.js.map +0 -1
- package/dist/core-CmxaoZ-N.js +0 -1598
- package/dist/core-CmxaoZ-N.js.map +0 -1
- package/dist/css-writer-CPy_cbFJ.js.map +0 -1
- package/dist/format-global-rules-Dbc_1tc3.js +0 -22
- package/dist/format-global-rules-Dbc_1tc3.js.map +0 -1
- package/dist/format-rules-CPirO_Mj.js +0 -143
- package/dist/format-rules-CPirO_Mj.js.map +0 -1
- package/dist/hydrate-CVn-A_3y.js +0 -45
- package/dist/hydrate-CVn-A_3y.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/keyframes-vpzoVdUR.js +0 -588
- package/dist/keyframes-vpzoVdUR.js.map +0 -1
- package/dist/merge-styles-BzQutdAK.js.map +0 -1
- package/dist/resolve-recipes-DgH8A3Nn.js +0 -144
- package/dist/resolve-recipes-DgH8A3Nn.js.map +0 -1
package/dist/zero/babel.d.ts
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import * as _$_babel_core0 from "@babel/core";
|
|
3
|
-
import { PluginPass } from "@babel/core";
|
|
4
|
-
|
|
1
|
+
import { t as TastyZeroConfig } from "../babel-types-Dc5zghyE.js";
|
|
5
2
|
//#region src/zero/babel.d.ts
|
|
6
3
|
/**
|
|
7
|
-
*
|
|
8
|
-
* Subset of TastyConfig excluding runtime-only DOM options
|
|
9
|
-
* (`nonce`, `maxRulesPerSheet`, `forceTextInjection`, `gc`)
|
|
10
|
-
* and overriding `devMode` default to `false`.
|
|
4
|
+
* Options for the `@tenphi/tasty/babel-plugin` Babel plugin.
|
|
11
5
|
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Enable development mode features: source comments in generated CSS.
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
devMode?: boolean;
|
|
18
|
-
};
|
|
19
|
-
interface TastyZeroBabelOptions {
|
|
6
|
+
export interface TastyZeroBabelOptions {
|
|
20
7
|
/** Output path for generated CSS (default: 'tasty.css') */
|
|
21
8
|
output?: string;
|
|
22
9
|
/**
|
|
@@ -73,9 +60,14 @@ interface TastyZeroBabelOptions {
|
|
|
73
60
|
*/
|
|
74
61
|
mode?: 'file' | 'inject';
|
|
75
62
|
}
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
/**
|
|
64
|
+
* The plugin's call signature, written out rather than inferred from
|
|
65
|
+
* `declare()` so the published declaration names no Babel types: Babel 7's
|
|
66
|
+
* come from `@types/babel__core`, Babel 8 ships its own, and the two name the
|
|
67
|
+
* plugin object differently.
|
|
68
|
+
*/
|
|
69
|
+
type TastyZeroBabelPlugin = (api: object, options: TastyZeroBabelOptions | null | undefined, dirname: string) => object;
|
|
70
|
+
declare const _default: TastyZeroBabelPlugin;
|
|
79
71
|
//#endregion
|
|
80
|
-
export {
|
|
72
|
+
export { type TastyZeroConfig, _default as default };
|
|
81
73
|
//# sourceMappingURL=babel.d.ts.map
|
package/dist/zero/babel.js
CHANGED
|
@@ -1,37 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { t as
|
|
4
|
-
import { a as
|
|
1
|
+
import { t as mergeStyles } from "../chunks/shared-utils-y-HjvPN4.js";
|
|
2
|
+
import "../chunks/css-definitions-B4aWBkH3.js";
|
|
3
|
+
import { t as resolveRecipesWith } from "../chunks/config-engine-CMYFZYQh.js";
|
|
4
|
+
import { a as resetZeroConfig, i as reapplyZeroConfig, n as functionsForExtraction, t as configureZero } from "../chunks/build-config-D9Iq8QQm.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-DcwaCvFs.js";
|
|
6
|
+
import { t as loadConfigFile } from "../chunks/config-file-DlZXJMj8.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
|
-
import { createJiti } from "jiti";
|
|
10
11
|
//#region \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
|
//#endregion
|
|
17
|
+
//#region src/zero/writer-cache.ts
|
|
18
|
+
const writerCache = /* @__PURE__ */ new Map();
|
|
19
|
+
//#endregion
|
|
16
20
|
//#region src/zero/babel.ts
|
|
17
|
-
/**
|
|
18
|
-
* Babel plugin for zero-runtime tasty static site generation.
|
|
19
|
-
*
|
|
20
|
-
* Transforms:
|
|
21
|
-
* - `tastyStatic(styles)` → StaticStyle object { className, styles, toString() }
|
|
22
|
-
* - `tastyStatic(base, styles)` → StaticStyle object with merged styles
|
|
23
|
-
* - `tastyStatic(selector, styles)` → removed entirely
|
|
24
|
-
*
|
|
25
|
-
* Usage:
|
|
26
|
-
* ```javascript
|
|
27
|
-
* // babel.config.js
|
|
28
|
-
* module.exports = {
|
|
29
|
-
* plugins: [
|
|
30
|
-
* ['@tenphi/tasty/babel-plugin', { output: 'public/tasty.css' }]
|
|
31
|
-
* ]
|
|
32
|
-
* };
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
21
|
function mtime(filePath) {
|
|
36
22
|
try {
|
|
37
23
|
return fs.statSync(filePath).mtimeMs;
|
|
@@ -54,13 +40,8 @@ function clearRequireCacheTree(filePath) {
|
|
|
54
40
|
}
|
|
55
41
|
delete __require.cache[resolved];
|
|
56
42
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
function clearWriterCache() {
|
|
60
|
-
writerCache.clear();
|
|
61
|
-
}
|
|
62
|
-
var babel_default = declare((api, options) => {
|
|
63
|
-
api.assertVersion(7);
|
|
43
|
+
const plugin = declare((api, options) => {
|
|
44
|
+
api.assertVersion("^7.0.0-0 || ^8.0.0-0");
|
|
64
45
|
const mode = options.mode ?? "file";
|
|
65
46
|
const outputPath = options.output || "tasty.css";
|
|
66
47
|
const resolvedOutputPath = path.resolve(outputPath);
|
|
@@ -84,50 +65,54 @@ var babel_default = declare((api, options) => {
|
|
|
84
65
|
const configOption = options.config;
|
|
85
66
|
let resolvedConfig;
|
|
86
67
|
if (configOption) resolvedConfig = typeof configOption === "function" ? configOption() : configOption;
|
|
87
|
-
else if (options.configFile)
|
|
88
|
-
|
|
89
|
-
resolvedConfig = loaded && typeof loaded === "object" && "default" in loaded ? loaded.default : loaded;
|
|
90
|
-
} else resolvedConfig = {};
|
|
68
|
+
else if (options.configFile) resolvedConfig = loadConfigFile(options.configFile);
|
|
69
|
+
else resolvedConfig = {};
|
|
91
70
|
const devMode = resolvedConfig.devMode ?? false;
|
|
92
|
-
|
|
71
|
+
resetZeroConfig();
|
|
93
72
|
const finalConfig = {
|
|
94
73
|
namePrefix: "ts",
|
|
95
74
|
...resolvedConfig
|
|
96
75
|
};
|
|
97
|
-
|
|
76
|
+
const config = configureZero(finalConfig);
|
|
98
77
|
setExtractorNamePrefix(finalConfig.namePrefix ?? "ts");
|
|
99
78
|
const newWriter = new CSSWriter(outputPath, { devMode });
|
|
100
79
|
if (mode !== "inject") {
|
|
101
|
-
const
|
|
80
|
+
for (const prop of extractConfigProperties(config.normalized.properties)) newWriter.add(`@property:${prop.name}`, prop.css);
|
|
81
|
+
const tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
102
82
|
if (tokenCSS) newWriter.add(":root:tokens", tokenCSS);
|
|
103
|
-
const
|
|
104
|
-
if (globalStyles) for (const [selector, styles] of Object.entries(globalStyles)) {
|
|
105
|
-
const css = extractCSSFromStyles(selector, styles);
|
|
106
|
-
if (css) newWriter.add(`global:${selector}`, css);
|
|
107
|
-
}
|
|
83
|
+
for (const [selector, styles] of Object.entries(config.normalized.globalStyles)) writeGlobalStyles(newWriter, selector, styles, config.normalized.keyframes);
|
|
108
84
|
}
|
|
109
85
|
writerCache.set(resolvedOutputPath, {
|
|
110
86
|
writer: newWriter,
|
|
111
87
|
configKey,
|
|
112
88
|
registry: {},
|
|
113
|
-
config
|
|
89
|
+
config
|
|
114
90
|
});
|
|
115
91
|
}
|
|
116
92
|
const entry = writerCache.get(resolvedOutputPath);
|
|
93
|
+
entry.config = reapplyZeroConfig(entry.config);
|
|
117
94
|
const cssWriter = entry.writer;
|
|
118
95
|
const globalRegistry = entry.registry;
|
|
119
96
|
const config = entry.config;
|
|
120
|
-
const
|
|
121
|
-
|
|
97
|
+
const sourceConfig = config.source;
|
|
98
|
+
const devMode = sourceConfig.devMode ?? false;
|
|
99
|
+
setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
|
|
100
|
+
const configProperties = extractConfigProperties(config.normalized.properties);
|
|
101
|
+
const propertyOptions = {
|
|
102
|
+
autoPropertyTypes: sourceConfig.autoPropertyTypes,
|
|
103
|
+
defined: new Set(configProperties.map((prop) => prop.name))
|
|
104
|
+
};
|
|
105
|
+
let propertyCSS;
|
|
122
106
|
let tokenCSS;
|
|
123
107
|
let globalStylesCSS;
|
|
124
108
|
if (mode === "inject") {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
propertyCSS = configProperties.map((prop) => prop.css).join("\n") || void 0;
|
|
110
|
+
tokenCSS = extractCSSFromStyles(":root", config.normalized.tokens);
|
|
111
|
+
const gs = config.normalized.globalStyles;
|
|
112
|
+
if (Object.keys(gs).length > 0) {
|
|
128
113
|
globalStylesCSS = /* @__PURE__ */ new Map();
|
|
129
114
|
for (const [selector, styles] of Object.entries(gs)) {
|
|
130
|
-
const css = extractCSSFromStyles(selector, styles);
|
|
115
|
+
const css = extractCSSFromStyles(selector, styles, config.normalized.keyframes);
|
|
131
116
|
if (css) globalStylesCSS.set(selector, css);
|
|
132
117
|
}
|
|
133
118
|
if (globalStylesCSS.size === 0) globalStylesCSS = void 0;
|
|
@@ -136,6 +121,8 @@ var babel_default = declare((api, options) => {
|
|
|
136
121
|
return {
|
|
137
122
|
name: "tasty-zero",
|
|
138
123
|
pre() {
|
|
124
|
+
entry.config = reapplyZeroConfig(entry.config);
|
|
125
|
+
setExtractorNamePrefix(sourceConfig.namePrefix ?? "ts");
|
|
139
126
|
this.staticStyleRegistry = {};
|
|
140
127
|
this._fileAddedCSS = false;
|
|
141
128
|
if (devMode && this.filename) this.sourceFile = this.filename.split("/").pop() || this.filename;
|
|
@@ -143,16 +130,18 @@ var babel_default = declare((api, options) => {
|
|
|
143
130
|
visitor: {
|
|
144
131
|
ImportDeclaration(nodePath, state) {
|
|
145
132
|
const source = nodePath.node.source.value;
|
|
146
|
-
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static"))
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
133
|
+
if (source === "@tenphi/tasty/static" || source.endsWith("/tasty/static")) {
|
|
134
|
+
if (mode === "inject") nodePath.replaceWith(t.importDeclaration([t.importSpecifier(t.identifier("_$i"), t.identifier("injectCSS"))], t.stringLiteral("@tenphi/tasty/static/inject")));
|
|
135
|
+
else if (injectImport) {
|
|
136
|
+
let importPath = resolvedOutputPath;
|
|
137
|
+
if (state.filename) {
|
|
138
|
+
const sourceDir = path.dirname(state.filename);
|
|
139
|
+
importPath = path.relative(sourceDir, resolvedOutputPath);
|
|
140
|
+
if (!importPath.startsWith(".")) importPath = "./" + importPath;
|
|
141
|
+
}
|
|
142
|
+
nodePath.replaceWith(t.importDeclaration([], t.stringLiteral(importPath)));
|
|
143
|
+
} else nodePath.remove();
|
|
144
|
+
}
|
|
156
145
|
},
|
|
157
146
|
CallExpression(path, state) {
|
|
158
147
|
const callee = path.node.callee;
|
|
@@ -161,9 +150,9 @@ var babel_default = declare((api, options) => {
|
|
|
161
150
|
const args = path.node.arguments;
|
|
162
151
|
if (args.length === 0) throw path.buildCodeFrameError("tastyStatic() requires at least one argument");
|
|
163
152
|
const firstArg = args[0];
|
|
164
|
-
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.keyframes, config.
|
|
165
|
-
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.
|
|
166
|
-
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.keyframes, config.
|
|
153
|
+
if (t.isStringLiteral(firstArg)) handleSelectorMode(path, args, cssWriter, mode, state.sourceFile, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
154
|
+
else if (t.isObjectExpression(firstArg)) handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
155
|
+
else if (t.isIdentifier(firstArg)) handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, config.normalized.keyframes, propertyOptions, config.normalized.fontFaces, config.normalized.counterStyles, functionsForExtraction(config), config.normalized.recipes);
|
|
167
156
|
else throw path.buildCodeFrameError("tastyStatic() first argument must be an object (styles), identifier (base StaticStyle), or string (selector)");
|
|
168
157
|
},
|
|
169
158
|
VariableDeclarator(path, state) {
|
|
@@ -188,10 +177,15 @@ var babel_default = declare((api, options) => {
|
|
|
188
177
|
},
|
|
189
178
|
post() {
|
|
190
179
|
if (mode === "inject") {
|
|
191
|
-
if (this._fileAddedCSS && (tokenCSS || globalStylesCSS)) {
|
|
180
|
+
if (this._fileAddedCSS && (propertyCSS || tokenCSS || globalStylesCSS)) {
|
|
192
181
|
const program = this.file.ast.program;
|
|
193
182
|
let insertIndex = 0;
|
|
194
183
|
for (let i = 0; i < program.body.length; i++) if (t.isImportDeclaration(program.body[i])) insertIndex = i + 1;
|
|
184
|
+
if (propertyCSS) {
|
|
185
|
+
const injectCall = createInjectCallAST("@property", propertyCSS);
|
|
186
|
+
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
187
|
+
insertIndex++;
|
|
188
|
+
}
|
|
195
189
|
if (tokenCSS) {
|
|
196
190
|
const injectCall = createInjectCallAST(":root", tokenCSS);
|
|
197
191
|
program.body.splice(insertIndex, 0, t.expressionStatement(injectCall));
|
|
@@ -209,55 +203,42 @@ var babel_default = declare((api, options) => {
|
|
|
209
203
|
}
|
|
210
204
|
};
|
|
211
205
|
});
|
|
212
|
-
/**
|
|
213
|
-
* Check if an object expression looks like a StaticStyle object
|
|
214
|
-
*/
|
|
215
206
|
function isStaticStyleObject(node) {
|
|
216
207
|
const hasClassName = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "className" }));
|
|
217
208
|
const hasStyles = node.properties.some((p) => t.isObjectProperty(p) && t.isIdentifier(p.key, { name: "styles" }));
|
|
218
209
|
return hasClassName && hasStyles;
|
|
219
210
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Extract styles object from a StaticStyle object expression
|
|
222
|
-
*/
|
|
223
211
|
function extractStylesFromStaticStyleObject(node, path) {
|
|
224
212
|
for (const prop of node.properties) if (t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "styles" }) && t.isObjectExpression(prop.value)) return evaluateObjectExpression(prop.value, path);
|
|
225
213
|
return null;
|
|
226
214
|
}
|
|
227
|
-
/**
|
|
228
|
-
* Extract className from a StaticStyle object expression
|
|
229
|
-
*/
|
|
230
215
|
function extractClassNameFromStaticStyleObject(node) {
|
|
231
216
|
for (const prop of node.properties) if (t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "className" }) && t.isStringLiteral(prop.value)) return prop.value.value;
|
|
232
217
|
return null;
|
|
233
218
|
}
|
|
234
|
-
|
|
235
|
-
* Handle tastyStatic(styles) - returns StaticStyle object
|
|
236
|
-
*/
|
|
237
|
-
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
219
|
+
function handleStylesMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
238
220
|
const stylesArg = args[0];
|
|
239
221
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(styles) argument must be a static object literal");
|
|
240
|
-
const
|
|
222
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
223
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
241
224
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
242
|
-
const properties = extractPropertiesFromStyles(styles,
|
|
225
|
+
const properties = extractPropertiesFromStyles(styles, propertyOptions);
|
|
243
226
|
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
244
227
|
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
245
|
-
const
|
|
228
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
229
|
+
const chunks = extractChunks(styles);
|
|
246
230
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
247
231
|
const staticStyleObject = createStaticStyleAST(className, styles);
|
|
248
232
|
if (mode === "inject") {
|
|
249
|
-
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, chunks, nameMap));
|
|
233
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
250
234
|
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
251
235
|
} else {
|
|
252
|
-
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, chunks, nameMap, state.sourceFile);
|
|
236
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
253
237
|
path.replaceWith(staticStyleObject);
|
|
254
238
|
}
|
|
255
239
|
registerIfVariableDeclaration(path, className, styles, state, globalRegistry);
|
|
256
240
|
}
|
|
257
|
-
|
|
258
|
-
* Handle tastyStatic(base, styles) - extends base with additional styles
|
|
259
|
-
*/
|
|
260
|
-
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
241
|
+
function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
261
242
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(base, styles) requires two arguments");
|
|
262
243
|
const baseArg = args[0];
|
|
263
244
|
const stylesArg = args[1];
|
|
@@ -267,101 +248,94 @@ function handleExtensionMode(path, args, cssWriter, state, globalRegistry, mode,
|
|
|
267
248
|
const baseEntry = state.staticStyleRegistry[baseName] || globalRegistry[baseName];
|
|
268
249
|
if (!baseEntry) throw path.buildCodeFrameError(`Cannot find base StaticStyle '${baseName}'. Make sure it is defined before being extended.`);
|
|
269
250
|
const overrideStyles = evaluateObjectExpression(stylesArg, path);
|
|
270
|
-
const mergedStyles =
|
|
251
|
+
const mergedStyles = resolveRecipesWith(mergeStyles(baseEntry.styles, overrideStyles), globalRecipes ?? null);
|
|
271
252
|
const { keyframes, nameMap } = extractKeyframesFromStyles(mergedStyles, globalKeyframes);
|
|
272
|
-
const properties = extractPropertiesFromStyles(mergedStyles,
|
|
253
|
+
const properties = extractPropertiesFromStyles(mergedStyles, propertyOptions);
|
|
273
254
|
const fontFaces = extractFontFaceFromStyles(mergedStyles, globalFontFace);
|
|
274
255
|
const counterStyles = extractCounterStyleFromStyles(mergedStyles, globalCounterStyle);
|
|
275
|
-
const
|
|
256
|
+
const functions = extractFunctionsFromStyles(mergedStyles, globalFunction);
|
|
257
|
+
const chunks = extractChunks(mergedStyles);
|
|
276
258
|
const className = chunks.length > 0 ? chunks.map((c) => c.className).join(" ") : "";
|
|
277
259
|
const staticStyleObject = createStaticStyleAST(className, mergedStyles);
|
|
278
260
|
if (mode === "inject") {
|
|
279
|
-
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, chunks, nameMap));
|
|
261
|
+
const injectCall = createInjectCallAST(className, collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap));
|
|
280
262
|
path.replaceWith(t.sequenceExpression([injectCall, staticStyleObject]));
|
|
281
263
|
} else {
|
|
282
|
-
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, chunks, nameMap, state.sourceFile);
|
|
264
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, state.sourceFile);
|
|
283
265
|
path.replaceWith(staticStyleObject);
|
|
284
266
|
}
|
|
285
267
|
registerIfVariableDeclaration(path, className, mergedStyles, state, globalRegistry);
|
|
286
268
|
}
|
|
287
|
-
|
|
288
|
-
* Handle tastyStatic(selector, styles) - removes the call entirely
|
|
289
|
-
*/
|
|
290
|
-
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, autoPropertyTypes, globalFontFace, globalCounterStyle) {
|
|
269
|
+
function handleSelectorMode(path, args, cssWriter, mode, sourceFile, globalKeyframes, propertyOptions, globalFontFace, globalCounterStyle, globalFunction, globalRecipes) {
|
|
291
270
|
if (args.length < 2) throw path.buildCodeFrameError("tastyStatic(selector, styles) requires two arguments");
|
|
292
271
|
const selectorArg = args[0];
|
|
293
272
|
const stylesArg = args[1];
|
|
294
273
|
if (!t.isStringLiteral(selectorArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) first argument must be a string literal");
|
|
295
274
|
if (!t.isObjectExpression(stylesArg)) throw path.buildCodeFrameError("tastyStatic(selector, styles) second argument must be a static object literal");
|
|
296
275
|
const selector = selectorArg.value;
|
|
297
|
-
const
|
|
276
|
+
const rawStyles = evaluateObjectExpression(stylesArg, path);
|
|
277
|
+
const styles = resolveRecipesWith(rawStyles, globalRecipes ?? null);
|
|
298
278
|
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
299
|
-
const properties = extractPropertiesFromStyles(styles,
|
|
279
|
+
const properties = extractPropertiesFromStyles(styles, propertyOptions);
|
|
300
280
|
const fontFaces = extractFontFaceFromStyles(styles, globalFontFace);
|
|
301
281
|
const counterStyles = extractCounterStyleFromStyles(styles, globalCounterStyle);
|
|
302
|
-
const
|
|
303
|
-
const
|
|
282
|
+
const functions = extractFunctionsFromStyles(styles, globalFunction);
|
|
283
|
+
const css = renderSelectorCSS(selector, styles);
|
|
284
|
+
const selectorCSS = nameMap.size > 0 ? replaceAnimationNamesInCSS(css, nameMap) : css;
|
|
304
285
|
if (mode === "inject") {
|
|
305
286
|
const cssParts = [];
|
|
306
287
|
for (const kf of keyframes) cssParts.push(kf.css);
|
|
307
288
|
for (const prop of properties) cssParts.push(prop.css);
|
|
308
289
|
for (const ff of fontFaces) cssParts.push(ff.css);
|
|
309
290
|
for (const cs of counterStyles) cssParts.push(cs.css);
|
|
291
|
+
for (const fn of functions) cssParts.push(fn.css);
|
|
310
292
|
cssParts.push(selectorCSS);
|
|
311
293
|
const injectCall = createInjectCallAST(selector, cssParts.join("\n"));
|
|
312
294
|
const parent = path.parentPath;
|
|
313
295
|
if (parent && t.isExpressionStatement(parent.node)) parent.replaceWith(t.expressionStatement(injectCall));
|
|
314
296
|
else path.replaceWith(injectCall);
|
|
315
297
|
} else {
|
|
316
|
-
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, [], nameMap, sourceFile);
|
|
298
|
+
writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, [], nameMap, sourceFile);
|
|
317
299
|
cssWriter.add(selector, selectorCSS, sourceFile);
|
|
318
300
|
const parent = path.parentPath;
|
|
319
301
|
if (parent && t.isExpressionStatement(parent.node)) parent.remove();
|
|
320
302
|
else path.replaceWith(t.identifier("undefined"));
|
|
321
303
|
}
|
|
322
304
|
}
|
|
323
|
-
|
|
324
|
-
* Collect all extracted CSS parts into a single string (for inject mode).
|
|
325
|
-
*/
|
|
326
|
-
function collectAllCSS(keyframes, properties, fontFaces, counterStyles, chunks, nameMap) {
|
|
305
|
+
function collectAllCSS(keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap) {
|
|
327
306
|
const parts = [];
|
|
328
307
|
for (const kf of keyframes) parts.push(kf.css);
|
|
329
308
|
for (const prop of properties) parts.push(prop.css);
|
|
330
309
|
for (const ff of fontFaces) parts.push(ff.css);
|
|
331
310
|
for (const cs of counterStyles) parts.push(cs.css);
|
|
311
|
+
for (const fn of functions) parts.push(fn.css);
|
|
332
312
|
for (const chunk of chunks) parts.push(nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css);
|
|
333
313
|
return parts.join("\n");
|
|
334
314
|
}
|
|
335
|
-
|
|
336
|
-
* Write all extracted CSS parts to a CSSWriter (for file mode).
|
|
337
|
-
*/
|
|
338
|
-
function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, chunks, nameMap, sourceFile) {
|
|
315
|
+
function writeCSSToWriter(cssWriter, keyframes, properties, fontFaces, counterStyles, functions, chunks, nameMap, sourceFile) {
|
|
339
316
|
for (const kf of keyframes) cssWriter.add(kf.css, kf.css, sourceFile);
|
|
340
317
|
for (const prop of properties) cssWriter.add(prop.css, prop.css, sourceFile);
|
|
341
318
|
for (const ff of fontFaces) cssWriter.add(ff.css, ff.css, sourceFile);
|
|
342
319
|
for (const cs of counterStyles) cssWriter.add(cs.css, cs.css, sourceFile);
|
|
320
|
+
for (const fn of functions) cssWriter.add(fn.css, fn.css, sourceFile);
|
|
343
321
|
for (const chunk of chunks) {
|
|
344
322
|
const css = nameMap.size > 0 ? replaceAnimationNamesInCSS(chunk.css, nameMap) : chunk.css;
|
|
345
323
|
cssWriter.add(chunk.className, css, sourceFile);
|
|
346
324
|
}
|
|
347
325
|
}
|
|
348
|
-
|
|
349
|
-
* Extract CSS for a selector from a styles/tokens object.
|
|
350
|
-
* Returns undefined when there are no styles or no CSS output.
|
|
351
|
-
*/
|
|
352
|
-
function extractCSSFromStyles(selector, styles) {
|
|
326
|
+
function extractCSSFromStyles(selector, styles, globalKeyframes) {
|
|
353
327
|
if (!styles || Object.keys(styles).length === 0) return void 0;
|
|
354
|
-
return
|
|
328
|
+
return extractSelectorCSS(selector, styles, globalKeyframes) || void 0;
|
|
329
|
+
}
|
|
330
|
+
function writeGlobalStyles(cssWriter, selector, styles, globalKeyframes) {
|
|
331
|
+
const { keyframes, nameMap } = extractKeyframesFromStyles(styles, globalKeyframes);
|
|
332
|
+
for (const kf of keyframes) cssWriter.add(kf.css, kf.css);
|
|
333
|
+
const css = replaceAnimationNamesInCSS(renderSelectorCSS(selector, styles), nameMap);
|
|
334
|
+
if (css) cssWriter.add(`global:${selector}`, css);
|
|
355
335
|
}
|
|
356
|
-
/**
|
|
357
|
-
* Create an `_$i(id, css)` call expression AST node for inject mode.
|
|
358
|
-
*/
|
|
359
336
|
function createInjectCallAST(id, css) {
|
|
360
337
|
return t.callExpression(t.identifier("_$i"), [t.stringLiteral(id), t.stringLiteral(css)]);
|
|
361
338
|
}
|
|
362
|
-
/**
|
|
363
|
-
* Create a StaticStyle object AST node
|
|
364
|
-
*/
|
|
365
339
|
function createStaticStyleAST(className, styles) {
|
|
366
340
|
return t.objectExpression([
|
|
367
341
|
t.objectProperty(t.identifier("className"), t.stringLiteral(className)),
|
|
@@ -369,9 +343,6 @@ function createStaticStyleAST(className, styles) {
|
|
|
369
343
|
t.objectMethod("method", t.identifier("toString"), [], t.blockStatement([t.returnStatement(t.memberExpression(t.thisExpression(), t.identifier("className")))]))
|
|
370
344
|
]);
|
|
371
345
|
}
|
|
372
|
-
/**
|
|
373
|
-
* Register a StaticStyle in the registry if it's being assigned to a variable
|
|
374
|
-
*/
|
|
375
346
|
function registerIfVariableDeclaration(path, className, styles, state, globalRegistry) {
|
|
376
347
|
const parent = path.parentPath;
|
|
377
348
|
if (parent && t.isVariableDeclarator(parent.node)) {
|
|
@@ -389,14 +360,11 @@ function registerIfVariableDeclaration(path, className, styles, state, globalReg
|
|
|
389
360
|
}
|
|
390
361
|
}
|
|
391
362
|
}
|
|
392
|
-
/**
|
|
393
|
-
* Convert a JavaScript value to an AST node
|
|
394
|
-
*/
|
|
395
363
|
function valueToAST(value) {
|
|
396
364
|
if (value === null) return t.nullLiteral();
|
|
397
365
|
if (value === void 0) return t.identifier("undefined");
|
|
398
366
|
if (typeof value === "string") return t.stringLiteral(value);
|
|
399
|
-
if (typeof value === "number") return t.
|
|
367
|
+
if (typeof value === "number") return t.valueToNode(value);
|
|
400
368
|
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
401
369
|
if (Array.isArray(value)) return t.arrayExpression(value.map(valueToAST));
|
|
402
370
|
if (typeof value === "object") {
|
|
@@ -405,10 +373,6 @@ function valueToAST(value) {
|
|
|
405
373
|
}
|
|
406
374
|
return t.identifier("undefined");
|
|
407
375
|
}
|
|
408
|
-
/**
|
|
409
|
-
* Evaluate an ObjectExpression to a plain JavaScript object.
|
|
410
|
-
* Only supports static values that can be determined at build time.
|
|
411
|
-
*/
|
|
412
376
|
function evaluateObjectExpression(node, path) {
|
|
413
377
|
const result = {};
|
|
414
378
|
for (const prop of node.properties) {
|
|
@@ -418,13 +382,11 @@ function evaluateObjectExpression(node, path) {
|
|
|
418
382
|
if (t.isIdentifier(prop.key)) key = prop.key.name;
|
|
419
383
|
else if (t.isStringLiteral(prop.key)) key = prop.key.value;
|
|
420
384
|
else throw path.buildCodeFrameError("Dynamic property keys are not supported in tastyStatic()");
|
|
421
|
-
|
|
385
|
+
const value = evaluateExpression(prop.value, path);
|
|
386
|
+
result[key] = value;
|
|
422
387
|
}
|
|
423
388
|
return result;
|
|
424
389
|
}
|
|
425
|
-
/**
|
|
426
|
-
* Evaluate an expression to a JavaScript value.
|
|
427
|
-
*/
|
|
428
390
|
function evaluateExpression(node, path) {
|
|
429
391
|
if (t.isStringLiteral(node)) return node.value;
|
|
430
392
|
if (t.isNumericLiteral(node)) return node.value;
|
|
@@ -447,28 +409,7 @@ function evaluateExpression(node, path) {
|
|
|
447
409
|
}
|
|
448
410
|
throw path.buildCodeFrameError(`Dynamic expressions are not supported in tastyStatic() - got ${node.type}. All values must be static literals.`);
|
|
449
411
|
}
|
|
450
|
-
/**
|
|
451
|
-
* Replace animation names in CSS string.
|
|
452
|
-
* Wraps the keyframes replaceAnimationNames to work on full CSS blocks.
|
|
453
|
-
*/
|
|
454
|
-
function replaceAnimationNamesInCSS(css, nameMap) {
|
|
455
|
-
if (nameMap.size === 0) return css;
|
|
456
|
-
return css.replace(/(animation(?:-name)?)\s*:\s*([^;}]+)/gi, (match, prop, value) => {
|
|
457
|
-
let newValue = value;
|
|
458
|
-
for (const [original, replacement] of nameMap) {
|
|
459
|
-
const pattern = new RegExp(`\\b${escapeRegex(original)}\\b`, "g");
|
|
460
|
-
newValue = newValue.replace(pattern, replacement);
|
|
461
|
-
}
|
|
462
|
-
return `${prop}: ${newValue}`;
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Escape special regex characters.
|
|
467
|
-
*/
|
|
468
|
-
function escapeRegex(str) {
|
|
469
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
470
|
-
}
|
|
471
412
|
//#endregion
|
|
472
|
-
export {
|
|
413
|
+
export { plugin as default };
|
|
473
414
|
|
|
474
415
|
//# sourceMappingURL=babel.js.map
|