typewritingclass-compiler 0.1.2 → 0.1.4

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,114 @@
1
+ // src/loadTheme.ts
2
+ async function loadTheme() {
3
+ const [colorsModule, spacingModule, typographyModule, sizesModule, shadowsModule, bordersModule] = await Promise.all([
4
+ import("typewritingclass/theme/colors"),
5
+ import("typewritingclass/theme"),
6
+ import("typewritingclass/theme/typography"),
7
+ import("typewritingclass/theme/sizes"),
8
+ import("typewritingclass/theme/shadows"),
9
+ import("typewritingclass/theme/borders")
10
+ ]);
11
+ const colorScaleNames = [
12
+ "slate",
13
+ "gray",
14
+ "zinc",
15
+ "neutral",
16
+ "stone",
17
+ "red",
18
+ "orange",
19
+ "amber",
20
+ "yellow",
21
+ "lime",
22
+ "green",
23
+ "emerald",
24
+ "teal",
25
+ "cyan",
26
+ "sky",
27
+ "blue",
28
+ "indigo",
29
+ "violet",
30
+ "purple",
31
+ "fuchsia",
32
+ "pink",
33
+ "rose"
34
+ ];
35
+ const colors = {};
36
+ for (const name of colorScaleNames) {
37
+ const scale = colorsModule[name];
38
+ if (scale && typeof scale === "object") {
39
+ colors[name] = {};
40
+ for (const [shade, hex] of Object.entries(scale)) {
41
+ colors[name][String(shade)] = hex;
42
+ }
43
+ }
44
+ }
45
+ const namedColors = {
46
+ white: colorsModule.white,
47
+ black: colorsModule.black,
48
+ transparent: colorsModule.transparent,
49
+ currentColor: colorsModule.currentColor
50
+ };
51
+ const { spacing: spacingNs } = spacingModule;
52
+ const spacing = {};
53
+ if (spacingNs && spacingNs.spacingScale) {
54
+ for (const [key, val] of Object.entries(spacingNs.spacingScale)) {
55
+ spacing[String(key)] = val;
56
+ }
57
+ }
58
+ const textSizeNames = ["xs", "sm", "base", "lg", "xl", "_2xl", "_3xl", "_4xl", "_5xl", "_6xl", "_7xl", "_8xl", "_9xl"];
59
+ const textSizes = {};
60
+ for (const name of textSizeNames) {
61
+ const token = typographyModule[name];
62
+ if (token && typeof token === "object" && "fontSize" in token) {
63
+ textSizes[name] = { fontSize: token.fontSize, lineHeight: token.lineHeight };
64
+ }
65
+ }
66
+ const weightNames = ["thin", "extralight", "light", "normal", "medium", "semibold", "bold", "extrabold", "black_"];
67
+ const fontWeights = {};
68
+ for (const name of weightNames) {
69
+ const val = typographyModule[name];
70
+ if (typeof val === "string") {
71
+ fontWeights[name] = val;
72
+ }
73
+ }
74
+ const radiusNames = ["none", "sm", "DEFAULT", "md", "lg", "xl", "_2xl", "_3xl", "full"];
75
+ const radii = {};
76
+ for (const name of radiusNames) {
77
+ const val = bordersModule[name];
78
+ if (typeof val === "string") {
79
+ radii[name] = val;
80
+ }
81
+ }
82
+ const shadowNames = ["sm", "DEFAULT", "md", "lg", "xl", "_2xl", "inner", "none"];
83
+ const shadows = {};
84
+ for (const name of shadowNames) {
85
+ const val = shadowsModule[name];
86
+ if (typeof val === "string") {
87
+ shadows[name] = val;
88
+ }
89
+ }
90
+ const sizeNames = ["full", "screen", "screenH", "min", "max", "fit", "auto"];
91
+ const sizes = {};
92
+ for (const name of sizeNames) {
93
+ const val = sizesModule[name];
94
+ if (typeof val === "string") {
95
+ sizes[name] = val;
96
+ }
97
+ }
98
+ return {
99
+ colors: JSON.stringify(colors),
100
+ namedColors: JSON.stringify(namedColors),
101
+ spacing: JSON.stringify(spacing),
102
+ textSizes: JSON.stringify(textSizes),
103
+ fontWeights: JSON.stringify(fontWeights),
104
+ radii: JSON.stringify(radii),
105
+ shadows: JSON.stringify(shadows),
106
+ sizes: JSON.stringify(sizes),
107
+ defaultRadius: radii["DEFAULT"] ?? "0.25rem",
108
+ defaultShadow: shadows["DEFAULT"] ?? "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)"
109
+ };
110
+ }
111
+
112
+ export {
113
+ loadTheme
114
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ default: () => twcPlugin,
34
+ generateCss: () => generateCss,
35
+ nativeTransform: () => nativeTransform
36
+ });
37
+ module.exports = __toCommonJS(src_exports);
38
+
39
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.6_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
40
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
41
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
42
+
43
+ // src/index.ts
44
+ var import_magic_string = __toESM(require("magic-string"), 1);
45
+ var import_module = require("module");
46
+ var import_path = require("path");
47
+ var import_url = require("url");
48
+
49
+ // src/loadTheme.ts
50
+ async function loadTheme() {
51
+ const [colorsModule, spacingModule, typographyModule, sizesModule, shadowsModule, bordersModule] = await Promise.all([
52
+ import("typewritingclass/theme/colors"),
53
+ import("typewritingclass/theme"),
54
+ import("typewritingclass/theme/typography"),
55
+ import("typewritingclass/theme/sizes"),
56
+ import("typewritingclass/theme/shadows"),
57
+ import("typewritingclass/theme/borders")
58
+ ]);
59
+ const colorScaleNames = [
60
+ "slate",
61
+ "gray",
62
+ "zinc",
63
+ "neutral",
64
+ "stone",
65
+ "red",
66
+ "orange",
67
+ "amber",
68
+ "yellow",
69
+ "lime",
70
+ "green",
71
+ "emerald",
72
+ "teal",
73
+ "cyan",
74
+ "sky",
75
+ "blue",
76
+ "indigo",
77
+ "violet",
78
+ "purple",
79
+ "fuchsia",
80
+ "pink",
81
+ "rose"
82
+ ];
83
+ const colors = {};
84
+ for (const name of colorScaleNames) {
85
+ const scale = colorsModule[name];
86
+ if (scale && typeof scale === "object") {
87
+ colors[name] = {};
88
+ for (const [shade, hex] of Object.entries(scale)) {
89
+ colors[name][String(shade)] = hex;
90
+ }
91
+ }
92
+ }
93
+ const namedColors = {
94
+ white: colorsModule.white,
95
+ black: colorsModule.black,
96
+ transparent: colorsModule.transparent,
97
+ currentColor: colorsModule.currentColor
98
+ };
99
+ const { spacing: spacingNs } = spacingModule;
100
+ const spacing = {};
101
+ if (spacingNs && spacingNs.spacingScale) {
102
+ for (const [key, val] of Object.entries(spacingNs.spacingScale)) {
103
+ spacing[String(key)] = val;
104
+ }
105
+ }
106
+ const textSizeNames = ["xs", "sm", "base", "lg", "xl", "_2xl", "_3xl", "_4xl", "_5xl", "_6xl", "_7xl", "_8xl", "_9xl"];
107
+ const textSizes = {};
108
+ for (const name of textSizeNames) {
109
+ const token = typographyModule[name];
110
+ if (token && typeof token === "object" && "fontSize" in token) {
111
+ textSizes[name] = { fontSize: token.fontSize, lineHeight: token.lineHeight };
112
+ }
113
+ }
114
+ const weightNames = ["thin", "extralight", "light", "normal", "medium", "semibold", "bold", "extrabold", "black_"];
115
+ const fontWeights = {};
116
+ for (const name of weightNames) {
117
+ const val = typographyModule[name];
118
+ if (typeof val === "string") {
119
+ fontWeights[name] = val;
120
+ }
121
+ }
122
+ const radiusNames = ["none", "sm", "DEFAULT", "md", "lg", "xl", "_2xl", "_3xl", "full"];
123
+ const radii = {};
124
+ for (const name of radiusNames) {
125
+ const val = bordersModule[name];
126
+ if (typeof val === "string") {
127
+ radii[name] = val;
128
+ }
129
+ }
130
+ const shadowNames = ["sm", "DEFAULT", "md", "lg", "xl", "_2xl", "inner", "none"];
131
+ const shadows = {};
132
+ for (const name of shadowNames) {
133
+ const val = shadowsModule[name];
134
+ if (typeof val === "string") {
135
+ shadows[name] = val;
136
+ }
137
+ }
138
+ const sizeNames = ["full", "screen", "screenH", "min", "max", "fit", "auto"];
139
+ const sizes = {};
140
+ for (const name of sizeNames) {
141
+ const val = sizesModule[name];
142
+ if (typeof val === "string") {
143
+ sizes[name] = val;
144
+ }
145
+ }
146
+ return {
147
+ colors: JSON.stringify(colors),
148
+ namedColors: JSON.stringify(namedColors),
149
+ spacing: JSON.stringify(spacing),
150
+ textSizes: JSON.stringify(textSizes),
151
+ fontWeights: JSON.stringify(fontWeights),
152
+ radii: JSON.stringify(radii),
153
+ shadows: JSON.stringify(shadows),
154
+ sizes: JSON.stringify(sizes),
155
+ defaultRadius: radii["DEFAULT"] ?? "0.25rem",
156
+ defaultShadow: shadows["DEFAULT"] ?? "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)"
157
+ };
158
+ }
159
+
160
+ // src/index.ts
161
+ var require2 = (0, import_module.createRequire)(importMetaUrl);
162
+ var __dirname = (0, import_path.dirname)((0, import_url.fileURLToPath)(importMetaUrl));
163
+ var native = require2((0, import_path.resolve)(__dirname, "..", "index.node"));
164
+ var { transform: nativeTransform, generateCss } = native;
165
+ var VIRTUAL_CSS_ID = "virtual:twc.css";
166
+ var RESOLVED_VIRTUAL_CSS_ID = "\0" + VIRTUAL_CSS_ID;
167
+ function twcPlugin(options) {
168
+ const strict = options?.strict ?? true;
169
+ let themeInput;
170
+ let layer = 0;
171
+ const fileRules = /* @__PURE__ */ new Map();
172
+ let devServer = null;
173
+ return {
174
+ name: "typewritingclass",
175
+ configureServer(server) {
176
+ devServer = server;
177
+ },
178
+ async buildStart() {
179
+ themeInput = await loadTheme();
180
+ },
181
+ resolveId(id) {
182
+ if (id === VIRTUAL_CSS_ID) {
183
+ return RESOLVED_VIRTUAL_CSS_ID;
184
+ }
185
+ },
186
+ load(id) {
187
+ if (id === RESOLVED_VIRTUAL_CSS_ID) {
188
+ return generateAllCss();
189
+ }
190
+ },
191
+ transform(code, id) {
192
+ if (!id.match(/\.[jt]sx?$/) || id.includes("node_modules")) return;
193
+ if (!code.includes("typewritingclass")) return;
194
+ try {
195
+ const result = native.transform(code, id, layer, themeInput, strict);
196
+ layer = result.nextLayer;
197
+ for (const diag of result.diagnostics) {
198
+ if (diag.severity === "error") {
199
+ this.error({
200
+ message: diag.message,
201
+ id,
202
+ pos: diag.line
203
+ });
204
+ } else {
205
+ this.warn({
206
+ message: diag.message,
207
+ id,
208
+ pos: diag.line
209
+ });
210
+ }
211
+ }
212
+ if (result.rules.length > 0) {
213
+ fileRules.set(
214
+ id,
215
+ result.rules.map((r) => r.cssText)
216
+ );
217
+ if (devServer) {
218
+ const mod = devServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_ID);
219
+ if (mod) {
220
+ devServer.moduleGraph.invalidateModule(mod);
221
+ }
222
+ }
223
+ }
224
+ const s = new import_magic_string.default(code);
225
+ if (result.code !== code) {
226
+ s.overwrite(0, code.length, result.code);
227
+ }
228
+ if (!result.code.includes(VIRTUAL_CSS_ID)) {
229
+ s.prepend(`import '${VIRTUAL_CSS_ID}';
230
+ `);
231
+ }
232
+ return {
233
+ code: s.toString(),
234
+ map: s.generateMap({ source: id, includeContent: true })
235
+ };
236
+ } catch {
237
+ if (!code.includes("typewritingclass/inject")) {
238
+ const s = new import_magic_string.default(code);
239
+ s.prepend(`import 'typewritingclass/inject';
240
+ `);
241
+ return {
242
+ code: s.toString(),
243
+ map: s.generateMap({ source: id, includeContent: true })
244
+ };
245
+ }
246
+ }
247
+ },
248
+ // Production builds: inject CSS into the output after all files are
249
+ // transformed. This fixes the timing issue where virtual:twc.css is
250
+ // loaded by Rollup before component files have been processed.
251
+ generateBundle(_, bundle) {
252
+ const css = generateAllCss();
253
+ if (!css) return;
254
+ for (const chunk of Object.values(bundle)) {
255
+ if (chunk.type === "asset" && chunk.fileName.endsWith(".css")) {
256
+ const existing = typeof chunk.source === "string" ? chunk.source : "";
257
+ chunk.source = existing ? existing + "\n" + css : css;
258
+ return;
259
+ }
260
+ }
261
+ this.emitFile({
262
+ type: "asset",
263
+ fileName: "assets/twc.css",
264
+ source: css
265
+ });
266
+ },
267
+ handleHotUpdate({ file, server }) {
268
+ if (file.match(/\.[jt]sx?$/) && fileRules.has(file)) {
269
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_ID);
270
+ if (mod) {
271
+ server.moduleGraph.invalidateModule(mod);
272
+ return [mod];
273
+ }
274
+ }
275
+ }
276
+ };
277
+ function generateAllCss() {
278
+ const allRules = [];
279
+ for (const rules of fileRules.values()) {
280
+ allRules.push(...rules);
281
+ }
282
+ if (allRules.length === 0) return "";
283
+ return native.generateCss(JSON.stringify(allRules));
284
+ }
285
+ }
286
+ // Annotate the CommonJS export names for ESM import in node:
287
+ 0 && (module.exports = {
288
+ generateCss,
289
+ nativeTransform
290
+ });
@@ -0,0 +1,52 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ interface Diagnostic {
4
+ message: string
5
+ line: number
6
+ column: number
7
+ severity: string
8
+ }
9
+
10
+ interface ExtractedRule {
11
+ className: string
12
+ cssText: string
13
+ layer: number
14
+ }
15
+
16
+ declare function generateCss(rulesJson: string): string
17
+
18
+ /** Theme data passed from the Vite plugin (loaded from the TS theme package) */
19
+ interface ThemeInput {
20
+ /** JSON: { "blue": { "50": "#eff6ff", ... }, ... } */
21
+ colors: string
22
+ /** JSON: { "white": "#ffffff", ... } */
23
+ namedColors: string
24
+ /** JSON: { "0": "0px", "0.5": "0.125rem", ... } */
25
+ spacing: string
26
+ /** JSON: { "xs": { "fontSize": "0.75rem", "lineHeight": "1rem" }, ... } */
27
+ textSizes: string
28
+ /** JSON: { "thin": "100", "light": "300", ... } */
29
+ fontWeights: string
30
+ /** JSON: { "none": "0px", "sm": "0.125rem", "DEFAULT": "0.25rem", ... } */
31
+ radii: string
32
+ /** JSON: { "sm": "0 1px 2px ...", "DEFAULT": "0 1px 3px ...", ... } */
33
+ shadows: string
34
+ /** JSON: { "full": "100%", "screen": "100vw", ... } */
35
+ sizes: string
36
+ /** Default border-radius value */
37
+ defaultRadius: string
38
+ /** Default shadow value */
39
+ defaultShadow: string
40
+ }
41
+
42
+ declare function transform(code: string, filename: string, layerOffset: number, themeInput: ThemeInput, strict?: boolean | undefined | null): TransformOutput
43
+
44
+ interface TransformOutput {
45
+ code: string
46
+ rules: Array<ExtractedRule>
47
+ nextLayer: number
48
+ hasDynamic: boolean
49
+ diagnostics: Array<Diagnostic>
50
+ }
51
+
52
+ export { type Diagnostic as D, type ExtractedRule as E, type ThemeInput as T, type TransformOutput as a, generateCss as g, transform as t };
@@ -0,0 +1,52 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ interface Diagnostic {
4
+ message: string
5
+ line: number
6
+ column: number
7
+ severity: string
8
+ }
9
+
10
+ interface ExtractedRule {
11
+ className: string
12
+ cssText: string
13
+ layer: number
14
+ }
15
+
16
+ declare function generateCss(rulesJson: string): string
17
+
18
+ /** Theme data passed from the Vite plugin (loaded from the TS theme package) */
19
+ interface ThemeInput {
20
+ /** JSON: { "blue": { "50": "#eff6ff", ... }, ... } */
21
+ colors: string
22
+ /** JSON: { "white": "#ffffff", ... } */
23
+ namedColors: string
24
+ /** JSON: { "0": "0px", "0.5": "0.125rem", ... } */
25
+ spacing: string
26
+ /** JSON: { "xs": { "fontSize": "0.75rem", "lineHeight": "1rem" }, ... } */
27
+ textSizes: string
28
+ /** JSON: { "thin": "100", "light": "300", ... } */
29
+ fontWeights: string
30
+ /** JSON: { "none": "0px", "sm": "0.125rem", "DEFAULT": "0.25rem", ... } */
31
+ radii: string
32
+ /** JSON: { "sm": "0 1px 2px ...", "DEFAULT": "0 1px 3px ...", ... } */
33
+ shadows: string
34
+ /** JSON: { "full": "100%", "screen": "100vw", ... } */
35
+ sizes: string
36
+ /** Default border-radius value */
37
+ defaultRadius: string
38
+ /** Default shadow value */
39
+ defaultShadow: string
40
+ }
41
+
42
+ declare function transform(code: string, filename: string, layerOffset: number, themeInput: ThemeInput, strict?: boolean | undefined | null): TransformOutput
43
+
44
+ interface TransformOutput {
45
+ code: string
46
+ rules: Array<ExtractedRule>
47
+ nextLayer: number
48
+ hasDynamic: boolean
49
+ diagnostics: Array<Diagnostic>
50
+ }
51
+
52
+ export { type Diagnostic as D, type ExtractedRule as E, type ThemeInput as T, type TransformOutput as a, generateCss as g, transform as t };
@@ -0,0 +1,13 @@
1
+ import { g as generateCss$1, t as transform } from './index.d-BP-BhWXf.cjs';
2
+ export { D as Diagnostic, E as ExtractedRule, T as ThemeInput, a as TransformOutput } from './index.d-BP-BhWXf.cjs';
3
+ import { Plugin } from 'vite';
4
+
5
+ declare const nativeTransform: typeof transform;
6
+ declare const generateCss: typeof generateCss$1;
7
+
8
+ interface TwcPluginOptions {
9
+ strict?: boolean;
10
+ }
11
+ declare function twcPlugin(options?: TwcPluginOptions): Plugin;
12
+
13
+ export { type TwcPluginOptions, twcPlugin as default, generateCss, nativeTransform };
@@ -0,0 +1,13 @@
1
+ import { g as generateCss$1, t as transform } from './index.d-BP-BhWXf.js';
2
+ export { D as Diagnostic, E as ExtractedRule, T as ThemeInput, a as TransformOutput } from './index.d-BP-BhWXf.js';
3
+ import { Plugin } from 'vite';
4
+
5
+ declare const nativeTransform: typeof transform;
6
+ declare const generateCss: typeof generateCss$1;
7
+
8
+ interface TwcPluginOptions {
9
+ strict?: boolean;
10
+ }
11
+ declare function twcPlugin(options?: TwcPluginOptions): Plugin;
12
+
13
+ export { type TwcPluginOptions, twcPlugin as default, generateCss, nativeTransform };
package/dist/index.js ADDED
@@ -0,0 +1,139 @@
1
+ import {
2
+ loadTheme
3
+ } from "./chunk-Y33BZFTH.js";
4
+
5
+ // src/index.ts
6
+ import MagicString from "magic-string";
7
+ import { createRequire } from "module";
8
+ import { resolve, dirname } from "path";
9
+ import { fileURLToPath } from "url";
10
+ var require2 = createRequire(import.meta.url);
11
+ var __dirname = dirname(fileURLToPath(import.meta.url));
12
+ var native = require2(resolve(__dirname, "..", "index.node"));
13
+ var { transform: nativeTransform, generateCss } = native;
14
+ var VIRTUAL_CSS_ID = "virtual:twc.css";
15
+ var RESOLVED_VIRTUAL_CSS_ID = "\0" + VIRTUAL_CSS_ID;
16
+ function twcPlugin(options) {
17
+ const strict = options?.strict ?? true;
18
+ let themeInput;
19
+ let layer = 0;
20
+ const fileRules = /* @__PURE__ */ new Map();
21
+ let devServer = null;
22
+ return {
23
+ name: "typewritingclass",
24
+ configureServer(server) {
25
+ devServer = server;
26
+ },
27
+ async buildStart() {
28
+ themeInput = await loadTheme();
29
+ },
30
+ resolveId(id) {
31
+ if (id === VIRTUAL_CSS_ID) {
32
+ return RESOLVED_VIRTUAL_CSS_ID;
33
+ }
34
+ },
35
+ load(id) {
36
+ if (id === RESOLVED_VIRTUAL_CSS_ID) {
37
+ return generateAllCss();
38
+ }
39
+ },
40
+ transform(code, id) {
41
+ if (!id.match(/\.[jt]sx?$/) || id.includes("node_modules")) return;
42
+ if (!code.includes("typewritingclass")) return;
43
+ try {
44
+ const result = native.transform(code, id, layer, themeInput, strict);
45
+ layer = result.nextLayer;
46
+ for (const diag of result.diagnostics) {
47
+ if (diag.severity === "error") {
48
+ this.error({
49
+ message: diag.message,
50
+ id,
51
+ pos: diag.line
52
+ });
53
+ } else {
54
+ this.warn({
55
+ message: diag.message,
56
+ id,
57
+ pos: diag.line
58
+ });
59
+ }
60
+ }
61
+ if (result.rules.length > 0) {
62
+ fileRules.set(
63
+ id,
64
+ result.rules.map((r) => r.cssText)
65
+ );
66
+ if (devServer) {
67
+ const mod = devServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_ID);
68
+ if (mod) {
69
+ devServer.moduleGraph.invalidateModule(mod);
70
+ }
71
+ }
72
+ }
73
+ const s = new MagicString(code);
74
+ if (result.code !== code) {
75
+ s.overwrite(0, code.length, result.code);
76
+ }
77
+ if (!result.code.includes(VIRTUAL_CSS_ID)) {
78
+ s.prepend(`import '${VIRTUAL_CSS_ID}';
79
+ `);
80
+ }
81
+ return {
82
+ code: s.toString(),
83
+ map: s.generateMap({ source: id, includeContent: true })
84
+ };
85
+ } catch {
86
+ if (!code.includes("typewritingclass/inject")) {
87
+ const s = new MagicString(code);
88
+ s.prepend(`import 'typewritingclass/inject';
89
+ `);
90
+ return {
91
+ code: s.toString(),
92
+ map: s.generateMap({ source: id, includeContent: true })
93
+ };
94
+ }
95
+ }
96
+ },
97
+ // Production builds: inject CSS into the output after all files are
98
+ // transformed. This fixes the timing issue where virtual:twc.css is
99
+ // loaded by Rollup before component files have been processed.
100
+ generateBundle(_, bundle) {
101
+ const css = generateAllCss();
102
+ if (!css) return;
103
+ for (const chunk of Object.values(bundle)) {
104
+ if (chunk.type === "asset" && chunk.fileName.endsWith(".css")) {
105
+ const existing = typeof chunk.source === "string" ? chunk.source : "";
106
+ chunk.source = existing ? existing + "\n" + css : css;
107
+ return;
108
+ }
109
+ }
110
+ this.emitFile({
111
+ type: "asset",
112
+ fileName: "assets/twc.css",
113
+ source: css
114
+ });
115
+ },
116
+ handleHotUpdate({ file, server }) {
117
+ if (file.match(/\.[jt]sx?$/) && fileRules.has(file)) {
118
+ const mod = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_CSS_ID);
119
+ if (mod) {
120
+ server.moduleGraph.invalidateModule(mod);
121
+ return [mod];
122
+ }
123
+ }
124
+ }
125
+ };
126
+ function generateAllCss() {
127
+ const allRules = [];
128
+ for (const rules of fileRules.values()) {
129
+ allRules.push(...rules);
130
+ }
131
+ if (allRules.length === 0) return "";
132
+ return native.generateCss(JSON.stringify(allRules));
133
+ }
134
+ }
135
+ export {
136
+ twcPlugin as default,
137
+ generateCss,
138
+ nativeTransform
139
+ };