@mochi-css/vanilla 3.0.0 → 4.0.0

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.
@@ -0,0 +1,78 @@
1
+ import { OnDiagnostic, StyleExtractor, StyleGenerator } from "@mochi-css/builder";
2
+ import { Config, styledIdPlugin } from "@mochi-css/config";
3
+ import * as SWC from "@swc/core";
4
+ import { CallExpression, Expression } from "@swc/core";
5
+
6
+ //#region src/config/VanillaCssExtractor.d.ts
7
+ declare class VanillaCssExtractor implements StyleExtractor {
8
+ private readonly extractor;
9
+ readonly importPath: string;
10
+ readonly symbolName: string;
11
+ constructor(importPath: string, symbolName: string, extractor: (call: CallExpression) => Expression[]);
12
+ extractStaticArgs(call: CallExpression): Expression[];
13
+ startGeneration(onDiagnostic?: OnDiagnostic): StyleGenerator;
14
+ }
15
+ declare const mochiCssFunctionExtractor: VanillaCssExtractor;
16
+ //#endregion
17
+ //#region src/config/VanillaKeyframesExtractor.d.ts
18
+ declare class VanillaKeyframesExtractor implements StyleExtractor {
19
+ readonly importPath = "@mochi-css/vanilla";
20
+ readonly symbolName = "keyframes";
21
+ extractStaticArgs(call: CallExpression): Expression[];
22
+ startGeneration(onDiagnostic?: OnDiagnostic): StyleGenerator;
23
+ }
24
+ declare const mochiKeyframesFunctionExtractor: VanillaKeyframesExtractor;
25
+ //#endregion
26
+ //#region src/config/VanillaGlobalCssExtractor.d.ts
27
+ declare class VanillaGlobalCssExtractor implements StyleExtractor {
28
+ readonly importPath = "@mochi-css/vanilla";
29
+ readonly symbolName = "globalCss";
30
+ extractStaticArgs(call: CallExpression): Expression[];
31
+ startGeneration(onDiagnostic?: OnDiagnostic): StyleGenerator;
32
+ }
33
+ declare const mochiGlobalCssFunctionExtractor: VanillaGlobalCssExtractor;
34
+ //#endregion
35
+ //#region src/config/VanillaCssGenerator.d.ts
36
+ declare class VanillaCssGenerator implements StyleGenerator {
37
+ private readonly onDiagnostic?;
38
+ private readonly collectedStyles;
39
+ private generatedMochiCss;
40
+ constructor(onDiagnostic?: OnDiagnostic | undefined);
41
+ collectArgs(source: string, args: unknown[]): void;
42
+ generateStyles(): Promise<{
43
+ files: Record<string, string>;
44
+ }>;
45
+ getArgReplacements(): {
46
+ source: string;
47
+ expression: SWC.Expression;
48
+ }[];
49
+ }
50
+ //#endregion
51
+ //#region src/config/VanillaKeyframesGenerator.d.ts
52
+ declare class VanillaKeyframesGenerator implements StyleGenerator {
53
+ private readonly onDiagnostic?;
54
+ private readonly collectedStyles;
55
+ constructor(onDiagnostic?: OnDiagnostic | undefined);
56
+ collectArgs(source: string, args: unknown[]): void;
57
+ generateStyles(): Promise<{
58
+ files: Record<string, string>;
59
+ }>;
60
+ }
61
+ //#endregion
62
+ //#region src/config/VanillaGlobalCssGenerator.d.ts
63
+ declare class VanillaGlobalCssGenerator implements StyleGenerator {
64
+ private readonly onDiagnostic?;
65
+ private readonly collectedStyles;
66
+ constructor(onDiagnostic?: OnDiagnostic | undefined);
67
+ collectArgs(source: string, args: unknown[]): void;
68
+ generateStyles(): Promise<{
69
+ global: string;
70
+ }>;
71
+ }
72
+ //#endregion
73
+ //#region src/config/index.d.ts
74
+ declare function defineConfig(config: Partial<Config> & {
75
+ extractors?: StyleExtractor[];
76
+ }): Partial<Config>;
77
+ //#endregion
78
+ export { VanillaCssExtractor, VanillaCssGenerator, VanillaGlobalCssExtractor, VanillaGlobalCssGenerator, VanillaKeyframesExtractor, VanillaKeyframesGenerator, defineConfig, mochiCssFunctionExtractor, mochiGlobalCssFunctionExtractor, mochiKeyframesFunctionExtractor, styledIdPlugin };
@@ -0,0 +1,78 @@
1
+ import { OnDiagnostic, StyleExtractor, StyleGenerator } from "@mochi-css/builder";
2
+ import { Config, styledIdPlugin } from "@mochi-css/config";
3
+ import * as SWC from "@swc/core";
4
+ import { CallExpression, Expression } from "@swc/core";
5
+
6
+ //#region src/config/VanillaCssExtractor.d.ts
7
+ declare class VanillaCssExtractor implements StyleExtractor {
8
+ private readonly extractor;
9
+ readonly importPath: string;
10
+ readonly symbolName: string;
11
+ constructor(importPath: string, symbolName: string, extractor: (call: CallExpression) => Expression[]);
12
+ extractStaticArgs(call: CallExpression): Expression[];
13
+ startGeneration(onDiagnostic?: OnDiagnostic): StyleGenerator;
14
+ }
15
+ declare const mochiCssFunctionExtractor: VanillaCssExtractor;
16
+ //#endregion
17
+ //#region src/config/VanillaKeyframesExtractor.d.ts
18
+ declare class VanillaKeyframesExtractor implements StyleExtractor {
19
+ readonly importPath = "@mochi-css/vanilla";
20
+ readonly symbolName = "keyframes";
21
+ extractStaticArgs(call: CallExpression): Expression[];
22
+ startGeneration(onDiagnostic?: OnDiagnostic): StyleGenerator;
23
+ }
24
+ declare const mochiKeyframesFunctionExtractor: VanillaKeyframesExtractor;
25
+ //#endregion
26
+ //#region src/config/VanillaGlobalCssExtractor.d.ts
27
+ declare class VanillaGlobalCssExtractor implements StyleExtractor {
28
+ readonly importPath = "@mochi-css/vanilla";
29
+ readonly symbolName = "globalCss";
30
+ extractStaticArgs(call: CallExpression): Expression[];
31
+ startGeneration(onDiagnostic?: OnDiagnostic): StyleGenerator;
32
+ }
33
+ declare const mochiGlobalCssFunctionExtractor: VanillaGlobalCssExtractor;
34
+ //#endregion
35
+ //#region src/config/VanillaCssGenerator.d.ts
36
+ declare class VanillaCssGenerator implements StyleGenerator {
37
+ private readonly onDiagnostic?;
38
+ private readonly collectedStyles;
39
+ private generatedMochiCss;
40
+ constructor(onDiagnostic?: OnDiagnostic | undefined);
41
+ collectArgs(source: string, args: unknown[]): void;
42
+ generateStyles(): Promise<{
43
+ files: Record<string, string>;
44
+ }>;
45
+ getArgReplacements(): {
46
+ source: string;
47
+ expression: SWC.Expression;
48
+ }[];
49
+ }
50
+ //#endregion
51
+ //#region src/config/VanillaKeyframesGenerator.d.ts
52
+ declare class VanillaKeyframesGenerator implements StyleGenerator {
53
+ private readonly onDiagnostic?;
54
+ private readonly collectedStyles;
55
+ constructor(onDiagnostic?: OnDiagnostic | undefined);
56
+ collectArgs(source: string, args: unknown[]): void;
57
+ generateStyles(): Promise<{
58
+ files: Record<string, string>;
59
+ }>;
60
+ }
61
+ //#endregion
62
+ //#region src/config/VanillaGlobalCssGenerator.d.ts
63
+ declare class VanillaGlobalCssGenerator implements StyleGenerator {
64
+ private readonly onDiagnostic?;
65
+ private readonly collectedStyles;
66
+ constructor(onDiagnostic?: OnDiagnostic | undefined);
67
+ collectArgs(source: string, args: unknown[]): void;
68
+ generateStyles(): Promise<{
69
+ global: string;
70
+ }>;
71
+ }
72
+ //#endregion
73
+ //#region src/config/index.d.ts
74
+ declare function defineConfig(config: Partial<Config> & {
75
+ extractors?: StyleExtractor[];
76
+ }): Partial<Config>;
77
+ //#endregion
78
+ export { VanillaCssExtractor, VanillaCssGenerator, VanillaGlobalCssExtractor, VanillaGlobalCssGenerator, VanillaKeyframesExtractor, VanillaKeyframesGenerator, defineConfig, mochiCssFunctionExtractor, mochiGlobalCssFunctionExtractor, mochiKeyframesFunctionExtractor, styledIdPlugin };
@@ -0,0 +1,302 @@
1
+ const require_src = require('../src-CGK_rB-l.js');
2
+ let __mochi_css_plugins = require("@mochi-css/plugins");
3
+ __mochi_css_plugins = require_src.__toESM(__mochi_css_plugins);
4
+ let __mochi_css_builder = require("@mochi-css/builder");
5
+ __mochi_css_builder = require_src.__toESM(__mochi_css_builder);
6
+ let __mochi_css_config = require("@mochi-css/config");
7
+ __mochi_css_config = require_src.__toESM(__mochi_css_config);
8
+
9
+ //#region src/config/VanillaCssGenerator.ts
10
+ const emptySpan = {
11
+ start: 0,
12
+ end: 0,
13
+ ctxt: 0
14
+ };
15
+ function strLit(value) {
16
+ return {
17
+ type: "StringLiteral",
18
+ span: emptySpan,
19
+ value,
20
+ raw: void 0
21
+ };
22
+ }
23
+ function arrExpr(elements) {
24
+ return {
25
+ type: "ArrayExpression",
26
+ span: emptySpan,
27
+ elements: elements.map((e) => ({ expression: e }))
28
+ };
29
+ }
30
+ function objExpr(properties) {
31
+ return {
32
+ type: "ObjectExpression",
33
+ span: emptySpan,
34
+ properties: properties.map(([key, value]) => ({
35
+ type: "KeyValueProperty",
36
+ key: strLit(key),
37
+ value
38
+ }))
39
+ };
40
+ }
41
+ function mochiCssNode(instance) {
42
+ const classNamesNode = arrExpr(instance.classNames.map(strLit));
43
+ const variantClassNamesNode = objExpr(Object.entries(instance.variantClassNames).map(([varKey, opts]) => [varKey, objExpr(Object.entries(opts).map(([optKey, cls]) => [optKey, strLit(cls)]))]));
44
+ const defaultVariantsNode = objExpr(Object.entries(instance.defaultVariants).filter(([, v]) => v != null).map(([k, v]) => [k, strLit(String(v))]));
45
+ return {
46
+ type: "NewExpression",
47
+ span: emptySpan,
48
+ ctxt: 0,
49
+ callee: {
50
+ type: "Identifier",
51
+ span: emptySpan,
52
+ ctxt: 0,
53
+ value: "MochiCSS",
54
+ optional: false
55
+ },
56
+ arguments: [
57
+ { expression: classNamesNode },
58
+ { expression: variantClassNamesNode },
59
+ { expression: defaultVariantsNode }
60
+ ]
61
+ };
62
+ }
63
+ var VanillaCssGenerator = class {
64
+ collectedStyles = [];
65
+ generatedMochiCss = [];
66
+ constructor(onDiagnostic) {
67
+ this.onDiagnostic = onDiagnostic;
68
+ }
69
+ collectArgs(source, args) {
70
+ const validArgs = [];
71
+ let stableId;
72
+ for (const arg of args) {
73
+ if (typeof arg === "string") {
74
+ stableId = arg;
75
+ continue;
76
+ }
77
+ if (arg == null || typeof arg !== "object") {
78
+ this.onDiagnostic?.({
79
+ code: "MOCHI_INVALID_STYLE_ARG",
80
+ message: `Expected style object, got ${arg === null ? "null" : typeof arg}`,
81
+ severity: "warning",
82
+ file: source
83
+ });
84
+ continue;
85
+ }
86
+ if (require_src.isMochiCSS(arg)) continue;
87
+ validArgs.push(arg);
88
+ }
89
+ if (validArgs.length > 0) this.collectedStyles.push({
90
+ source,
91
+ args: validArgs,
92
+ stableId
93
+ });
94
+ }
95
+ async generateStyles() {
96
+ this.generatedMochiCss = [];
97
+ const filesCss = /* @__PURE__ */ new Map();
98
+ for (const { source, args, stableId } of this.collectedStyles) {
99
+ let css = filesCss.get(source);
100
+ if (!css) {
101
+ css = /* @__PURE__ */ new Set();
102
+ filesCss.set(source, css);
103
+ }
104
+ const mochiInstances = [];
105
+ for (const style of args) try {
106
+ const cssObj = new require_src.CSSObject(style, stableId);
107
+ css.add(cssObj.asCssString());
108
+ mochiInstances.push(require_src.MochiCSS.from(cssObj));
109
+ } catch (err) {
110
+ const message = (0, __mochi_css_builder.getErrorMessage)(err);
111
+ this.onDiagnostic?.({
112
+ code: "MOCHI_STYLE_GENERATION",
113
+ message: `Failed to generate CSS: ${message}`,
114
+ severity: "warning",
115
+ file: source
116
+ });
117
+ }
118
+ if (mochiInstances.length > 0) this.generatedMochiCss.push({
119
+ source,
120
+ instance: require_src.mergeMochiCss(mochiInstances)
121
+ });
122
+ }
123
+ const files = {};
124
+ for (const [source, css] of filesCss) files[source] = [...css.values()].sort().join("\n\n");
125
+ return { files };
126
+ }
127
+ getArgReplacements() {
128
+ return this.generatedMochiCss.map(({ source, instance }) => ({
129
+ source,
130
+ expression: mochiCssNode(instance)
131
+ }));
132
+ }
133
+ };
134
+
135
+ //#endregion
136
+ //#region src/config/VanillaCssExtractor.ts
137
+ var VanillaCssExtractor = class {
138
+ importPath;
139
+ symbolName;
140
+ constructor(importPath, symbolName, extractor) {
141
+ this.extractor = extractor;
142
+ this.importPath = importPath;
143
+ this.symbolName = symbolName;
144
+ }
145
+ extractStaticArgs(call) {
146
+ return this.extractor(call);
147
+ }
148
+ startGeneration(onDiagnostic) {
149
+ return new VanillaCssGenerator(onDiagnostic);
150
+ }
151
+ };
152
+ const mochiCssFunctionExtractor = new VanillaCssExtractor("@mochi-css/vanilla", "css", (call) => call.arguments.map((a) => a.expression));
153
+
154
+ //#endregion
155
+ //#region src/config/VanillaKeyframesGenerator.ts
156
+ var VanillaKeyframesGenerator = class {
157
+ collectedStyles = [];
158
+ constructor(onDiagnostic) {
159
+ this.onDiagnostic = onDiagnostic;
160
+ }
161
+ collectArgs(source, args) {
162
+ if (args.length === 0 || args[0] == null || typeof args[0] !== "object") {
163
+ this.onDiagnostic?.({
164
+ code: "MOCHI_INVALID_STYLE_ARG",
165
+ message: `Expected keyframe stops object, got ${args[0] === null ? "null" : typeof args[0]}`,
166
+ severity: "warning",
167
+ file: source
168
+ });
169
+ return;
170
+ }
171
+ this.collectedStyles.push({
172
+ source,
173
+ stops: args[0]
174
+ });
175
+ }
176
+ async generateStyles() {
177
+ const filesCss = /* @__PURE__ */ new Map();
178
+ for (const { source, stops } of this.collectedStyles) {
179
+ let css = filesCss.get(source);
180
+ if (!css) {
181
+ css = /* @__PURE__ */ new Set();
182
+ filesCss.set(source, css);
183
+ }
184
+ try {
185
+ const obj = new require_src.KeyframesObject(stops);
186
+ css.add(obj.asCssString());
187
+ } catch (err) {
188
+ const message = (0, __mochi_css_builder.getErrorMessage)(err);
189
+ this.onDiagnostic?.({
190
+ code: "MOCHI_STYLE_GENERATION",
191
+ message: `Failed to generate keyframes CSS: ${message}`,
192
+ severity: "warning",
193
+ file: source
194
+ });
195
+ }
196
+ }
197
+ const files = {};
198
+ for (const [source, css] of filesCss) files[source] = [...css.values()].sort().join("\n\n");
199
+ return { files };
200
+ }
201
+ };
202
+
203
+ //#endregion
204
+ //#region src/config/VanillaKeyframesExtractor.ts
205
+ var VanillaKeyframesExtractor = class {
206
+ importPath = "@mochi-css/vanilla";
207
+ symbolName = "keyframes";
208
+ extractStaticArgs(call) {
209
+ return call.arguments.slice(0, 1).map((a) => a.expression);
210
+ }
211
+ startGeneration(onDiagnostic) {
212
+ return new VanillaKeyframesGenerator(onDiagnostic);
213
+ }
214
+ };
215
+ const mochiKeyframesFunctionExtractor = new VanillaKeyframesExtractor();
216
+
217
+ //#endregion
218
+ //#region src/config/VanillaGlobalCssGenerator.ts
219
+ var VanillaGlobalCssGenerator = class {
220
+ collectedStyles = [];
221
+ constructor(onDiagnostic) {
222
+ this.onDiagnostic = onDiagnostic;
223
+ }
224
+ collectArgs(source, args) {
225
+ if (args.length === 0 || args[0] == null || typeof args[0] !== "object") {
226
+ this.onDiagnostic?.({
227
+ code: "MOCHI_INVALID_STYLE_ARG",
228
+ message: `Expected global CSS styles object, got ${args[0] === null ? "null" : typeof args[0]}`,
229
+ severity: "warning",
230
+ file: source
231
+ });
232
+ return;
233
+ }
234
+ this.collectedStyles.push({
235
+ source,
236
+ styles: args[0]
237
+ });
238
+ }
239
+ async generateStyles() {
240
+ const allCss = /* @__PURE__ */ new Set();
241
+ for (const { source, styles } of this.collectedStyles) try {
242
+ const obj = new require_src.GlobalCssObject(styles);
243
+ allCss.add(obj.asCssString());
244
+ } catch (err) {
245
+ const message = (0, __mochi_css_builder.getErrorMessage)(err);
246
+ this.onDiagnostic?.({
247
+ code: "MOCHI_STYLE_GENERATION",
248
+ message: `Failed to generate global CSS: ${message}`,
249
+ severity: "warning",
250
+ file: source
251
+ });
252
+ }
253
+ return { global: [...allCss].sort().join("\n\n") };
254
+ }
255
+ };
256
+
257
+ //#endregion
258
+ //#region src/config/VanillaGlobalCssExtractor.ts
259
+ var VanillaGlobalCssExtractor = class {
260
+ importPath = "@mochi-css/vanilla";
261
+ symbolName = "globalCss";
262
+ extractStaticArgs(call) {
263
+ return call.arguments.slice(0, 1).map((a) => a.expression);
264
+ }
265
+ startGeneration(onDiagnostic) {
266
+ return new VanillaGlobalCssGenerator(onDiagnostic);
267
+ }
268
+ };
269
+ const mochiGlobalCssFunctionExtractor = new VanillaGlobalCssExtractor();
270
+
271
+ //#endregion
272
+ //#region src/config/index.ts
273
+ const defaultVanillaExtractors = [
274
+ mochiCssFunctionExtractor,
275
+ mochiKeyframesFunctionExtractor,
276
+ mochiGlobalCssFunctionExtractor
277
+ ];
278
+ function defineConfig(config) {
279
+ const { extractors = [],...rest } = config;
280
+ return {
281
+ ...rest,
282
+ plugins: [(0, __mochi_css_plugins.createExtractorsPlugin)([...defaultVanillaExtractors, ...extractors]), ...rest.plugins ?? []]
283
+ };
284
+ }
285
+
286
+ //#endregion
287
+ exports.VanillaCssExtractor = VanillaCssExtractor;
288
+ exports.VanillaCssGenerator = VanillaCssGenerator;
289
+ exports.VanillaGlobalCssExtractor = VanillaGlobalCssExtractor;
290
+ exports.VanillaGlobalCssGenerator = VanillaGlobalCssGenerator;
291
+ exports.VanillaKeyframesExtractor = VanillaKeyframesExtractor;
292
+ exports.VanillaKeyframesGenerator = VanillaKeyframesGenerator;
293
+ exports.defineConfig = defineConfig;
294
+ exports.mochiCssFunctionExtractor = mochiCssFunctionExtractor;
295
+ exports.mochiGlobalCssFunctionExtractor = mochiGlobalCssFunctionExtractor;
296
+ exports.mochiKeyframesFunctionExtractor = mochiKeyframesFunctionExtractor;
297
+ Object.defineProperty(exports, 'styledIdPlugin', {
298
+ enumerable: true,
299
+ get: function () {
300
+ return __mochi_css_config.styledIdPlugin;
301
+ }
302
+ });