tailwind-styled-v4 5.0.0 → 5.0.1
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/CHANGELOG.md +398 -0
- package/LICENSE +21 -0
- package/README.md +532 -0
- package/dist/analyzer.d.mts +114 -0
- package/dist/analyzer.d.ts +114 -0
- package/dist/analyzer.js +1555 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/analyzer.mjs +1544 -0
- package/dist/analyzer.mjs.map +1 -0
- package/dist/{animate.d.cts → animate.d.mts} +3 -30
- package/dist/animate.d.ts +3 -30
- package/dist/animate.js +149 -99
- package/dist/animate.js.map +1 -1
- package/dist/{animate.cjs → animate.mjs} +130 -119
- package/dist/animate.mjs.map +1 -0
- package/dist/atomic.d.mts +18 -0
- package/dist/atomic.d.ts +18 -0
- package/dist/atomic.js +191 -0
- package/dist/atomic.js.map +1 -0
- package/dist/atomic.mjs +185 -0
- package/dist/atomic.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +6063 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +6053 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/compiler.d.mts +1009 -0
- package/dist/compiler.d.ts +1009 -0
- package/dist/compiler.js +4518 -0
- package/dist/compiler.js.map +1 -0
- package/dist/compiler.mjs +4443 -0
- package/dist/compiler.mjs.map +1 -0
- package/dist/dashboard.d.mts +272 -0
- package/dist/dashboard.d.ts +272 -0
- package/dist/dashboard.js +249 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/dashboard.mjs +239 -0
- package/dist/dashboard.mjs.map +1 -0
- package/dist/devtools.js +170 -157
- package/dist/devtools.js.map +1 -1
- package/dist/{devtools.cjs → devtools.mjs} +165 -166
- package/dist/devtools.mjs.map +1 -0
- package/dist/engine.d.mts +84 -0
- package/dist/engine.d.ts +84 -0
- package/dist/engine.js +3014 -0
- package/dist/engine.js.map +1 -0
- package/dist/engine.mjs +3005 -0
- package/dist/engine.mjs.map +1 -0
- package/dist/{index.d.cts → index.d.mts} +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +945 -36
- package/dist/index.js.map +1 -1
- package/dist/{index.cjs → index.mjs} +899 -90
- package/dist/index.mjs.map +1 -0
- package/dist/liveTokenEngine-DYN3Zale.d.mts +34 -0
- package/dist/liveTokenEngine-DYN3Zale.d.ts +34 -0
- package/dist/{next.d.cts → next.d.mts} +2 -1
- package/dist/next.d.ts +2 -1
- package/dist/next.js +6853 -35
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +7050 -0
- package/dist/next.mjs.map +1 -0
- package/dist/plugin.d.mts +90 -0
- package/dist/plugin.d.ts +90 -0
- package/dist/plugin.js +185 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.mjs +174 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/pluginRegistry.d.mts +83 -0
- package/dist/pluginRegistry.d.ts +83 -0
- package/dist/pluginRegistry.js +303 -0
- package/dist/pluginRegistry.js.map +1 -0
- package/dist/pluginRegistry.mjs +298 -0
- package/dist/pluginRegistry.mjs.map +1 -0
- package/dist/preset.js +9 -4
- package/dist/preset.js.map +1 -1
- package/dist/{preset.cjs → preset.mjs} +5 -14
- package/dist/preset.mjs.map +1 -0
- package/dist/rspack.d.mts +33 -0
- package/dist/rspack.d.ts +33 -0
- package/dist/rspack.js +55 -0
- package/dist/rspack.js.map +1 -0
- package/dist/rspack.mjs +45 -0
- package/dist/rspack.mjs.map +1 -0
- package/dist/runtime.d.mts +62 -0
- package/dist/runtime.d.ts +62 -0
- package/dist/runtime.js +207 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +188 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/runtimeCss.d.mts +65 -0
- package/dist/runtimeCss.d.ts +65 -0
- package/dist/{css.cjs → runtimeCss.js} +71 -4
- package/dist/runtimeCss.js.map +1 -0
- package/dist/{css.js → runtimeCss.mjs} +66 -5
- package/dist/runtimeCss.mjs.map +1 -0
- package/dist/scanner.d.mts +25 -0
- package/dist/scanner.d.ts +25 -0
- package/dist/scanner.js +717 -0
- package/dist/scanner.js.map +1 -0
- package/dist/scanner.mjs +703 -0
- package/dist/scanner.mjs.map +1 -0
- package/dist/shared.d.mts +85 -0
- package/dist/shared.d.ts +85 -0
- package/dist/shared.js +255 -0
- package/dist/shared.js.map +1 -0
- package/dist/shared.mjs +233 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/storybookAddon.d.mts +108 -0
- package/dist/storybookAddon.d.ts +108 -0
- package/dist/storybookAddon.js +95 -0
- package/dist/storybookAddon.js.map +1 -0
- package/dist/storybookAddon.mjs +88 -0
- package/dist/storybookAddon.mjs.map +1 -0
- package/dist/svelte.d.mts +114 -0
- package/dist/svelte.d.ts +114 -0
- package/dist/svelte.js +67 -0
- package/dist/svelte.js.map +1 -0
- package/dist/svelte.mjs +59 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/testing.d.mts +185 -0
- package/dist/testing.d.ts +185 -0
- package/dist/testing.js +173 -0
- package/dist/testing.js.map +1 -0
- package/dist/testing.mjs +158 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/theme.d.mts +188 -0
- package/dist/theme.d.ts +188 -0
- package/dist/theme.js +334 -0
- package/dist/theme.js.map +1 -0
- package/dist/theme.mjs +311 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/types-DXr2PmGP.d.mts +31 -0
- package/dist/types-DXr2PmGP.d.ts +31 -0
- package/dist/vite.js +4181 -16
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +4281 -0
- package/dist/vite.mjs.map +1 -0
- package/dist/vue.d.mts +89 -0
- package/dist/vue.d.ts +89 -0
- package/dist/vue.js +104 -0
- package/dist/vue.js.map +1 -0
- package/dist/vue.mjs +96 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +168 -65
- package/dist/animate.cjs.map +0 -1
- package/dist/chunk-VZEJV27B.js +0 -11
- package/dist/chunk-VZEJV27B.js.map +0 -1
- package/dist/chunk-Y5D3E72P.cjs +0 -13
- package/dist/chunk-Y5D3E72P.cjs.map +0 -1
- package/dist/css.cjs.map +0 -1
- package/dist/css.d.cts +0 -30
- package/dist/css.d.ts +0 -30
- package/dist/css.js.map +0 -1
- package/dist/devtools.cjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/next.cjs +0 -248
- package/dist/next.cjs.map +0 -1
- package/dist/preset.cjs.map +0 -1
- package/dist/turbopackLoader.cjs +0 -37
- package/dist/turbopackLoader.cjs.map +0 -1
- package/dist/turbopackLoader.d.cts +0 -12
- package/dist/turbopackLoader.d.ts +0 -12
- package/dist/turbopackLoader.js +0 -35
- package/dist/turbopackLoader.js.map +0 -1
- package/dist/vite.cjs +0 -138
- package/dist/vite.cjs.map +0 -1
- package/dist/webpackLoader.cjs +0 -51
- package/dist/webpackLoader.cjs.map +0 -1
- package/dist/webpackLoader.d.cts +0 -17
- package/dist/webpackLoader.d.ts +0 -17
- package/dist/webpackLoader.js +0 -49
- package/dist/webpackLoader.js.map +0 -1
- /package/dist/{devtools.d.cts → devtools.d.mts} +0 -0
- /package/dist/{preset.d.cts → preset.d.mts} +0 -0
- /package/dist/{vite.d.cts → vite.d.mts} +0 -0
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,4518 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var crypto = require('crypto');
|
|
4
|
+
var fs3 = require('fs');
|
|
5
|
+
var module$1 = require('module');
|
|
6
|
+
var path7 = require('path');
|
|
7
|
+
var tailwindMerge = require('tailwind-merge');
|
|
8
|
+
|
|
9
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var fs3__default = /*#__PURE__*/_interopDefault(fs3);
|
|
13
|
+
var path7__default = /*#__PURE__*/_interopDefault(path7);
|
|
14
|
+
|
|
15
|
+
/* tailwind-styled-v4 v5.0.1 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
|
|
16
|
+
var __defProp = Object.defineProperty;
|
|
17
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
18
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
19
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
20
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
21
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
22
|
+
}) : x)(function(x) {
|
|
23
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
24
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
25
|
+
});
|
|
26
|
+
var __esm = (fn, res) => function __init() {
|
|
27
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
28
|
+
};
|
|
29
|
+
var __export = (target, all) => {
|
|
30
|
+
for (var name in all)
|
|
31
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
32
|
+
};
|
|
33
|
+
var __copyProps = (to, from, except, desc) => {
|
|
34
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
35
|
+
for (let key of __getOwnPropNames(from))
|
|
36
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
37
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
38
|
+
}
|
|
39
|
+
return to;
|
|
40
|
+
};
|
|
41
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
+
|
|
43
|
+
// packages/shared/src/logger.ts
|
|
44
|
+
function getEnvLevel() {
|
|
45
|
+
const env = process.env.TWS_LOG_LEVEL?.toLowerCase();
|
|
46
|
+
if (env && env in LEVELS) return env;
|
|
47
|
+
return process.env.TWS_DEBUG_SCANNER === "1" ? "debug" : "info";
|
|
48
|
+
}
|
|
49
|
+
function createLogger(prefix, level) {
|
|
50
|
+
let currentLevel = getEnvLevel();
|
|
51
|
+
const log2 = (msgLevel, stream, args) => {
|
|
52
|
+
if (LEVELS[msgLevel] > LEVELS[currentLevel]) return;
|
|
53
|
+
const line = `[${prefix}] ${args.map(String).join(" ")}
|
|
54
|
+
`;
|
|
55
|
+
process[stream].write(line);
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
error: (...a) => log2("error", "stderr", a),
|
|
59
|
+
warn: (...a) => log2("warn", "stderr", a),
|
|
60
|
+
info: (...a) => log2("info", "stdout", a),
|
|
61
|
+
debug: (...a) => log2("debug", "stderr", a),
|
|
62
|
+
setLevel: (l) => {
|
|
63
|
+
currentLevel = l;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
var LEVELS;
|
|
68
|
+
var init_logger = __esm({
|
|
69
|
+
"packages/shared/src/logger.ts"() {
|
|
70
|
+
LEVELS = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
71
|
+
createLogger("tailwind-styled");
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
function hashContent(content, algorithm = "md5", length = 8) {
|
|
75
|
+
return crypto.createHash(algorithm).update(content).digest("hex").slice(0, length);
|
|
76
|
+
}
|
|
77
|
+
var init_hash = __esm({
|
|
78
|
+
"packages/shared/src/hash.ts"() {
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// packages/shared/src/index.ts
|
|
83
|
+
var init_src = __esm({
|
|
84
|
+
"packages/shared/src/index.ts"() {
|
|
85
|
+
init_logger();
|
|
86
|
+
init_hash();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// packages/compiler/src/nativeBridge.ts
|
|
91
|
+
var nativeBridge_exports = {};
|
|
92
|
+
__export(nativeBridge_exports, {
|
|
93
|
+
adaptNativeResult: () => adaptNativeResult,
|
|
94
|
+
getNativeBridge: () => getNativeBridge,
|
|
95
|
+
resetNativeBridgeCache: () => resetNativeBridgeCache
|
|
96
|
+
});
|
|
97
|
+
function tryRequire(id) {
|
|
98
|
+
try {
|
|
99
|
+
const mod = requireFromRuntime(id);
|
|
100
|
+
return mod ?? null;
|
|
101
|
+
} catch (error) {
|
|
102
|
+
log.debug(
|
|
103
|
+
`native bridge load miss ${id}: ${error instanceof Error ? error.message : String(error)}`
|
|
104
|
+
);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function getNativeBridge() {
|
|
109
|
+
if (cachedBridge !== void 0) {
|
|
110
|
+
if (cachedBridge === null) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`[tailwind-styled/compiler v5] Native binding is required but not available.
|
|
113
|
+
Please ensure:
|
|
114
|
+
1. The native module is properly installed
|
|
115
|
+
2. You have run: npm run build:native (or use prebuilt binary)
|
|
116
|
+
3. TWS_NO_NATIVE environment variable is not set
|
|
117
|
+
|
|
118
|
+
For help, see: https://tailwind-styled.dev/docs/install`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return cachedBridge;
|
|
122
|
+
}
|
|
123
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
124
|
+
cachedBridge = null;
|
|
125
|
+
throw new Error(
|
|
126
|
+
`[tailwind-styled/compiler v5] Native binding is required.
|
|
127
|
+
The TWS_NO_NATIVE or TWS_NO_RUST environment variable is set, which disables native binding.
|
|
128
|
+
Please unset this environment variable to use the native compiler.`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const candidates = [
|
|
132
|
+
"@tailwind-styled/native",
|
|
133
|
+
path7__default.default.resolve(process.cwd(), "native", "index.mjs"),
|
|
134
|
+
path7__default.default.resolve(runtimeDir, "..", "..", "native", "index.mjs"),
|
|
135
|
+
path7__default.default.resolve(runtimeDir, "..", "..", "..", "native", "index.mjs"),
|
|
136
|
+
path7__default.default.resolve(process.cwd(), "native", "index.node"),
|
|
137
|
+
path7__default.default.resolve(runtimeDir, "..", "..", "native", "index.node"),
|
|
138
|
+
path7__default.default.resolve(runtimeDir, "..", "..", "..", "native", "index.node")
|
|
139
|
+
];
|
|
140
|
+
for (const candidate of candidates) {
|
|
141
|
+
const bridge = tryRequire(candidate);
|
|
142
|
+
if (bridge) {
|
|
143
|
+
log.debug(`native bridge loaded from ${candidate}`);
|
|
144
|
+
cachedBridge = bridge;
|
|
145
|
+
return cachedBridge;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
cachedBridge = null;
|
|
149
|
+
throw new Error(
|
|
150
|
+
`[tailwind-styled/compiler v5] Native binding not found.
|
|
151
|
+
Tried loading from:
|
|
152
|
+
` + candidates.map((c) => ` - ${c}`).join("\n") + `
|
|
153
|
+
|
|
154
|
+
Please build the native module:
|
|
155
|
+
npm run build:native
|
|
156
|
+
|
|
157
|
+
Or install a prebuilt binary for your platform.`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
function resetNativeBridgeCache() {
|
|
161
|
+
cachedBridge = void 0;
|
|
162
|
+
}
|
|
163
|
+
function adaptNativeResult(raw) {
|
|
164
|
+
let rsc;
|
|
165
|
+
if (raw.rscJson) {
|
|
166
|
+
try {
|
|
167
|
+
const parsed = JSON.parse(raw.rscJson);
|
|
168
|
+
rsc = {
|
|
169
|
+
isServer: parsed.isServer,
|
|
170
|
+
needsClientDirective: parsed.needsClientDirective,
|
|
171
|
+
clientReasons: []
|
|
172
|
+
};
|
|
173
|
+
} catch {
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
let metadata;
|
|
177
|
+
if (raw.metadataJson) {
|
|
178
|
+
try {
|
|
179
|
+
metadata = JSON.parse(raw.metadataJson);
|
|
180
|
+
} catch {
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
code: raw.code,
|
|
185
|
+
classes: raw.classes,
|
|
186
|
+
changed: raw.changed,
|
|
187
|
+
rsc,
|
|
188
|
+
metadata
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
var runtimeDir, requireFromRuntime, cachedBridge, log;
|
|
192
|
+
var init_nativeBridge = __esm({
|
|
193
|
+
"packages/compiler/src/nativeBridge.ts"() {
|
|
194
|
+
init_src();
|
|
195
|
+
runtimeDir = typeof __dirname === "string" && __dirname.length > 0 ? __dirname : process.cwd();
|
|
196
|
+
requireFromRuntime = typeof module !== "undefined" && typeof module.require === "function" ? module.require.bind(module) : module$1.createRequire(path7__default.default.join(runtimeDir, "noop.cjs"));
|
|
197
|
+
log = createLogger("compiler:native");
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
function requireNative() {
|
|
201
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
202
|
+
try {
|
|
203
|
+
return require2(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
204
|
+
} catch (err) {
|
|
205
|
+
loadErrors.push(err);
|
|
206
|
+
}
|
|
207
|
+
} else if (process.platform === "android") {
|
|
208
|
+
if (process.arch === "arm64") {
|
|
209
|
+
try {
|
|
210
|
+
return require2("./parser.android-arm64.node");
|
|
211
|
+
} catch (e) {
|
|
212
|
+
loadErrors.push(e);
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const binding = require2("@oxc-parser/binding-android-arm64");
|
|
216
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-android-arm64/package.json").version;
|
|
217
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
219
|
+
}
|
|
220
|
+
return binding;
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadErrors.push(e);
|
|
223
|
+
}
|
|
224
|
+
} else if (process.arch === "arm") {
|
|
225
|
+
try {
|
|
226
|
+
return require2("./parser.android-arm-eabi.node");
|
|
227
|
+
} catch (e) {
|
|
228
|
+
loadErrors.push(e);
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const binding = require2("@oxc-parser/binding-android-arm-eabi");
|
|
232
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-android-arm-eabi/package.json").version;
|
|
233
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
234
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
235
|
+
}
|
|
236
|
+
return binding;
|
|
237
|
+
} catch (e) {
|
|
238
|
+
loadErrors.push(e);
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`));
|
|
242
|
+
}
|
|
243
|
+
} else if (process.platform === "win32") {
|
|
244
|
+
if (process.arch === "x64") {
|
|
245
|
+
if (process.config?.variables?.shlib_suffix === "dll.a" || process.config?.variables?.node_target_type === "shared_library") {
|
|
246
|
+
try {
|
|
247
|
+
return require2("./parser.win32-x64-gnu.node");
|
|
248
|
+
} catch (e) {
|
|
249
|
+
loadErrors.push(e);
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const binding = require2("@oxc-parser/binding-win32-x64-gnu");
|
|
253
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-win32-x64-gnu/package.json").version;
|
|
254
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
255
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
256
|
+
}
|
|
257
|
+
return binding;
|
|
258
|
+
} catch (e) {
|
|
259
|
+
loadErrors.push(e);
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
try {
|
|
263
|
+
return require2("./parser.win32-x64-msvc.node");
|
|
264
|
+
} catch (e) {
|
|
265
|
+
loadErrors.push(e);
|
|
266
|
+
}
|
|
267
|
+
try {
|
|
268
|
+
const binding = require2("@oxc-parser/binding-win32-x64-msvc");
|
|
269
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-win32-x64-msvc/package.json").version;
|
|
270
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
271
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
272
|
+
}
|
|
273
|
+
return binding;
|
|
274
|
+
} catch (e) {
|
|
275
|
+
loadErrors.push(e);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} else if (process.arch === "ia32") {
|
|
279
|
+
try {
|
|
280
|
+
return require2("./parser.win32-ia32-msvc.node");
|
|
281
|
+
} catch (e) {
|
|
282
|
+
loadErrors.push(e);
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const binding = require2("@oxc-parser/binding-win32-ia32-msvc");
|
|
286
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-win32-ia32-msvc/package.json").version;
|
|
287
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
288
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
289
|
+
}
|
|
290
|
+
return binding;
|
|
291
|
+
} catch (e) {
|
|
292
|
+
loadErrors.push(e);
|
|
293
|
+
}
|
|
294
|
+
} else if (process.arch === "arm64") {
|
|
295
|
+
try {
|
|
296
|
+
return require2("./parser.win32-arm64-msvc.node");
|
|
297
|
+
} catch (e) {
|
|
298
|
+
loadErrors.push(e);
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
const binding = require2("@oxc-parser/binding-win32-arm64-msvc");
|
|
302
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-win32-arm64-msvc/package.json").version;
|
|
303
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
304
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
305
|
+
}
|
|
306
|
+
return binding;
|
|
307
|
+
} catch (e) {
|
|
308
|
+
loadErrors.push(e);
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));
|
|
312
|
+
}
|
|
313
|
+
} else if (process.platform === "darwin") {
|
|
314
|
+
try {
|
|
315
|
+
return require2("./parser.darwin-universal.node");
|
|
316
|
+
} catch (e) {
|
|
317
|
+
loadErrors.push(e);
|
|
318
|
+
}
|
|
319
|
+
try {
|
|
320
|
+
const binding = require2("@oxc-parser/binding-darwin-universal");
|
|
321
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-darwin-universal/package.json").version;
|
|
322
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
323
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
324
|
+
}
|
|
325
|
+
return binding;
|
|
326
|
+
} catch (e) {
|
|
327
|
+
loadErrors.push(e);
|
|
328
|
+
}
|
|
329
|
+
if (process.arch === "x64") {
|
|
330
|
+
try {
|
|
331
|
+
return require2("./parser.darwin-x64.node");
|
|
332
|
+
} catch (e) {
|
|
333
|
+
loadErrors.push(e);
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
const binding = require2("@oxc-parser/binding-darwin-x64");
|
|
337
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-darwin-x64/package.json").version;
|
|
338
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
339
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
340
|
+
}
|
|
341
|
+
return binding;
|
|
342
|
+
} catch (e) {
|
|
343
|
+
loadErrors.push(e);
|
|
344
|
+
}
|
|
345
|
+
} else if (process.arch === "arm64") {
|
|
346
|
+
try {
|
|
347
|
+
return require2("./parser.darwin-arm64.node");
|
|
348
|
+
} catch (e) {
|
|
349
|
+
loadErrors.push(e);
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
const binding = require2("@oxc-parser/binding-darwin-arm64");
|
|
353
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-darwin-arm64/package.json").version;
|
|
354
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
355
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
356
|
+
}
|
|
357
|
+
return binding;
|
|
358
|
+
} catch (e) {
|
|
359
|
+
loadErrors.push(e);
|
|
360
|
+
}
|
|
361
|
+
} else {
|
|
362
|
+
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`));
|
|
363
|
+
}
|
|
364
|
+
} else if (process.platform === "freebsd") {
|
|
365
|
+
if (process.arch === "x64") {
|
|
366
|
+
try {
|
|
367
|
+
return require2("./parser.freebsd-x64.node");
|
|
368
|
+
} catch (e) {
|
|
369
|
+
loadErrors.push(e);
|
|
370
|
+
}
|
|
371
|
+
try {
|
|
372
|
+
const binding = require2("@oxc-parser/binding-freebsd-x64");
|
|
373
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-freebsd-x64/package.json").version;
|
|
374
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
375
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
376
|
+
}
|
|
377
|
+
return binding;
|
|
378
|
+
} catch (e) {
|
|
379
|
+
loadErrors.push(e);
|
|
380
|
+
}
|
|
381
|
+
} else if (process.arch === "arm64") {
|
|
382
|
+
try {
|
|
383
|
+
return require2("./parser.freebsd-arm64.node");
|
|
384
|
+
} catch (e) {
|
|
385
|
+
loadErrors.push(e);
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
const binding = require2("@oxc-parser/binding-freebsd-arm64");
|
|
389
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-freebsd-arm64/package.json").version;
|
|
390
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
391
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
392
|
+
}
|
|
393
|
+
return binding;
|
|
394
|
+
} catch (e) {
|
|
395
|
+
loadErrors.push(e);
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));
|
|
399
|
+
}
|
|
400
|
+
} else if (process.platform === "linux") {
|
|
401
|
+
if (process.arch === "x64") {
|
|
402
|
+
if (isMusl()) {
|
|
403
|
+
try {
|
|
404
|
+
return require2("./parser.linux-x64-musl.node");
|
|
405
|
+
} catch (e) {
|
|
406
|
+
loadErrors.push(e);
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
const binding = require2("@oxc-parser/binding-linux-x64-musl");
|
|
410
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-x64-musl/package.json").version;
|
|
411
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
412
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
413
|
+
}
|
|
414
|
+
return binding;
|
|
415
|
+
} catch (e) {
|
|
416
|
+
loadErrors.push(e);
|
|
417
|
+
}
|
|
418
|
+
} else {
|
|
419
|
+
try {
|
|
420
|
+
return require2("./parser.linux-x64-gnu.node");
|
|
421
|
+
} catch (e) {
|
|
422
|
+
loadErrors.push(e);
|
|
423
|
+
}
|
|
424
|
+
try {
|
|
425
|
+
const binding = require2("@oxc-parser/binding-linux-x64-gnu");
|
|
426
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-x64-gnu/package.json").version;
|
|
427
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
428
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
429
|
+
}
|
|
430
|
+
return binding;
|
|
431
|
+
} catch (e) {
|
|
432
|
+
loadErrors.push(e);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
} else if (process.arch === "arm64") {
|
|
436
|
+
if (isMusl()) {
|
|
437
|
+
try {
|
|
438
|
+
return require2("./parser.linux-arm64-musl.node");
|
|
439
|
+
} catch (e) {
|
|
440
|
+
loadErrors.push(e);
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
const binding = require2("@oxc-parser/binding-linux-arm64-musl");
|
|
444
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm64-musl/package.json").version;
|
|
445
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
446
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
447
|
+
}
|
|
448
|
+
return binding;
|
|
449
|
+
} catch (e) {
|
|
450
|
+
loadErrors.push(e);
|
|
451
|
+
}
|
|
452
|
+
} else {
|
|
453
|
+
try {
|
|
454
|
+
return require2("./parser.linux-arm64-gnu.node");
|
|
455
|
+
} catch (e) {
|
|
456
|
+
loadErrors.push(e);
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
const binding = require2("@oxc-parser/binding-linux-arm64-gnu");
|
|
460
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm64-gnu/package.json").version;
|
|
461
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
462
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
463
|
+
}
|
|
464
|
+
return binding;
|
|
465
|
+
} catch (e) {
|
|
466
|
+
loadErrors.push(e);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} else if (process.arch === "arm") {
|
|
470
|
+
if (isMusl()) {
|
|
471
|
+
try {
|
|
472
|
+
return require2("./parser.linux-arm-musleabihf.node");
|
|
473
|
+
} catch (e) {
|
|
474
|
+
loadErrors.push(e);
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
const binding = require2("@oxc-parser/binding-linux-arm-musleabihf");
|
|
478
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm-musleabihf/package.json").version;
|
|
479
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
481
|
+
}
|
|
482
|
+
return binding;
|
|
483
|
+
} catch (e) {
|
|
484
|
+
loadErrors.push(e);
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
try {
|
|
488
|
+
return require2("./parser.linux-arm-gnueabihf.node");
|
|
489
|
+
} catch (e) {
|
|
490
|
+
loadErrors.push(e);
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
const binding = require2("@oxc-parser/binding-linux-arm-gnueabihf");
|
|
494
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-arm-gnueabihf/package.json").version;
|
|
495
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
497
|
+
}
|
|
498
|
+
return binding;
|
|
499
|
+
} catch (e) {
|
|
500
|
+
loadErrors.push(e);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
} else if (process.arch === "loong64") {
|
|
504
|
+
if (isMusl()) {
|
|
505
|
+
try {
|
|
506
|
+
return require2("./parser.linux-loong64-musl.node");
|
|
507
|
+
} catch (e) {
|
|
508
|
+
loadErrors.push(e);
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
const binding = require2("@oxc-parser/binding-linux-loong64-musl");
|
|
512
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-loong64-musl/package.json").version;
|
|
513
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
514
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
515
|
+
}
|
|
516
|
+
return binding;
|
|
517
|
+
} catch (e) {
|
|
518
|
+
loadErrors.push(e);
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
try {
|
|
522
|
+
return require2("./parser.linux-loong64-gnu.node");
|
|
523
|
+
} catch (e) {
|
|
524
|
+
loadErrors.push(e);
|
|
525
|
+
}
|
|
526
|
+
try {
|
|
527
|
+
const binding = require2("@oxc-parser/binding-linux-loong64-gnu");
|
|
528
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-loong64-gnu/package.json").version;
|
|
529
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
530
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
531
|
+
}
|
|
532
|
+
return binding;
|
|
533
|
+
} catch (e) {
|
|
534
|
+
loadErrors.push(e);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
} else if (process.arch === "riscv64") {
|
|
538
|
+
if (isMusl()) {
|
|
539
|
+
try {
|
|
540
|
+
return require2("./parser.linux-riscv64-musl.node");
|
|
541
|
+
} catch (e) {
|
|
542
|
+
loadErrors.push(e);
|
|
543
|
+
}
|
|
544
|
+
try {
|
|
545
|
+
const binding = require2("@oxc-parser/binding-linux-riscv64-musl");
|
|
546
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-riscv64-musl/package.json").version;
|
|
547
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
548
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
549
|
+
}
|
|
550
|
+
return binding;
|
|
551
|
+
} catch (e) {
|
|
552
|
+
loadErrors.push(e);
|
|
553
|
+
}
|
|
554
|
+
} else {
|
|
555
|
+
try {
|
|
556
|
+
return require2("./parser.linux-riscv64-gnu.node");
|
|
557
|
+
} catch (e) {
|
|
558
|
+
loadErrors.push(e);
|
|
559
|
+
}
|
|
560
|
+
try {
|
|
561
|
+
const binding = require2("@oxc-parser/binding-linux-riscv64-gnu");
|
|
562
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-riscv64-gnu/package.json").version;
|
|
563
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
564
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
565
|
+
}
|
|
566
|
+
return binding;
|
|
567
|
+
} catch (e) {
|
|
568
|
+
loadErrors.push(e);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
} else if (process.arch === "ppc64") {
|
|
572
|
+
try {
|
|
573
|
+
return require2("./parser.linux-ppc64-gnu.node");
|
|
574
|
+
} catch (e) {
|
|
575
|
+
loadErrors.push(e);
|
|
576
|
+
}
|
|
577
|
+
try {
|
|
578
|
+
const binding = require2("@oxc-parser/binding-linux-ppc64-gnu");
|
|
579
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-ppc64-gnu/package.json").version;
|
|
580
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
581
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
582
|
+
}
|
|
583
|
+
return binding;
|
|
584
|
+
} catch (e) {
|
|
585
|
+
loadErrors.push(e);
|
|
586
|
+
}
|
|
587
|
+
} else if (process.arch === "s390x") {
|
|
588
|
+
try {
|
|
589
|
+
return require2("./parser.linux-s390x-gnu.node");
|
|
590
|
+
} catch (e) {
|
|
591
|
+
loadErrors.push(e);
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
const binding = require2("@oxc-parser/binding-linux-s390x-gnu");
|
|
595
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-linux-s390x-gnu/package.json").version;
|
|
596
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
597
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
598
|
+
}
|
|
599
|
+
return binding;
|
|
600
|
+
} catch (e) {
|
|
601
|
+
loadErrors.push(e);
|
|
602
|
+
}
|
|
603
|
+
} else {
|
|
604
|
+
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));
|
|
605
|
+
}
|
|
606
|
+
} else if (process.platform === "openharmony") {
|
|
607
|
+
if (process.arch === "arm64") {
|
|
608
|
+
try {
|
|
609
|
+
return require2("./parser.openharmony-arm64.node");
|
|
610
|
+
} catch (e) {
|
|
611
|
+
loadErrors.push(e);
|
|
612
|
+
}
|
|
613
|
+
try {
|
|
614
|
+
const binding = require2("@oxc-parser/binding-openharmony-arm64");
|
|
615
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-openharmony-arm64/package.json").version;
|
|
616
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
617
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
618
|
+
}
|
|
619
|
+
return binding;
|
|
620
|
+
} catch (e) {
|
|
621
|
+
loadErrors.push(e);
|
|
622
|
+
}
|
|
623
|
+
} else if (process.arch === "x64") {
|
|
624
|
+
try {
|
|
625
|
+
return require2("./parser.openharmony-x64.node");
|
|
626
|
+
} catch (e) {
|
|
627
|
+
loadErrors.push(e);
|
|
628
|
+
}
|
|
629
|
+
try {
|
|
630
|
+
const binding = require2("@oxc-parser/binding-openharmony-x64");
|
|
631
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-openharmony-x64/package.json").version;
|
|
632
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
633
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
634
|
+
}
|
|
635
|
+
return binding;
|
|
636
|
+
} catch (e) {
|
|
637
|
+
loadErrors.push(e);
|
|
638
|
+
}
|
|
639
|
+
} else if (process.arch === "arm") {
|
|
640
|
+
try {
|
|
641
|
+
return require2("./parser.openharmony-arm.node");
|
|
642
|
+
} catch (e) {
|
|
643
|
+
loadErrors.push(e);
|
|
644
|
+
}
|
|
645
|
+
try {
|
|
646
|
+
const binding = require2("@oxc-parser/binding-openharmony-arm");
|
|
647
|
+
const bindingPackageVersion = require2("@oxc-parser/binding-openharmony-arm/package.json").version;
|
|
648
|
+
if (bindingPackageVersion !== "0.120.0" && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== "0") {
|
|
649
|
+
throw new Error(`Native binding package version mismatch, expected 0.120.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`);
|
|
650
|
+
}
|
|
651
|
+
return binding;
|
|
652
|
+
} catch (e) {
|
|
653
|
+
loadErrors.push(e);
|
|
654
|
+
}
|
|
655
|
+
} else {
|
|
656
|
+
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`));
|
|
657
|
+
}
|
|
658
|
+
} else {
|
|
659
|
+
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`));
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
var require2, readFileSync, nativeBinding, loadErrors, isMusl, isFileMusl, isMuslFromFilesystem, isMuslFromReport, isMuslFromChildProcess, Severity, ParseResult, ExportExportNameKind, ExportImportNameKind, ExportLocalNameKind, ImportNameKind, parse, parseSync, rawTransferSupported, getBufferOffset, parseRaw, parseRawSync;
|
|
663
|
+
var init_bindings = __esm({
|
|
664
|
+
"node_modules/oxc-parser/src-js/bindings.js"() {
|
|
665
|
+
require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('compiler.js', document.baseURI).href)));
|
|
666
|
+
new URL(".", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('compiler.js', document.baseURI).href))).pathname;
|
|
667
|
+
({ readFileSync } = require2("node:fs"));
|
|
668
|
+
nativeBinding = null;
|
|
669
|
+
loadErrors = [];
|
|
670
|
+
isMusl = () => {
|
|
671
|
+
let musl = false;
|
|
672
|
+
if (process.platform === "linux") {
|
|
673
|
+
musl = isMuslFromFilesystem();
|
|
674
|
+
if (musl === null) {
|
|
675
|
+
musl = isMuslFromReport();
|
|
676
|
+
}
|
|
677
|
+
if (musl === null) {
|
|
678
|
+
musl = isMuslFromChildProcess();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return musl;
|
|
682
|
+
};
|
|
683
|
+
isFileMusl = (f) => f.includes("libc.musl-") || f.includes("ld-musl-");
|
|
684
|
+
isMuslFromFilesystem = () => {
|
|
685
|
+
try {
|
|
686
|
+
return readFileSync("/usr/bin/ldd", "utf-8").includes("musl");
|
|
687
|
+
} catch {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
isMuslFromReport = () => {
|
|
692
|
+
let report = null;
|
|
693
|
+
if (typeof process.report?.getReport === "function") {
|
|
694
|
+
process.report.excludeNetwork = true;
|
|
695
|
+
report = process.report.getReport();
|
|
696
|
+
}
|
|
697
|
+
if (!report) {
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
if (report.header && report.header.glibcVersionRuntime) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
if (Array.isArray(report.sharedObjects)) {
|
|
704
|
+
if (report.sharedObjects.some(isFileMusl)) {
|
|
705
|
+
return true;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return false;
|
|
709
|
+
};
|
|
710
|
+
isMuslFromChildProcess = () => {
|
|
711
|
+
try {
|
|
712
|
+
return require2("child_process").execSync("ldd --version", { encoding: "utf8" }).includes("musl");
|
|
713
|
+
} catch (e) {
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
nativeBinding = requireNative();
|
|
718
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
719
|
+
let wasiBinding = null;
|
|
720
|
+
let wasiBindingError = null;
|
|
721
|
+
try {
|
|
722
|
+
wasiBinding = require2("./parser.wasi.cjs");
|
|
723
|
+
nativeBinding = wasiBinding;
|
|
724
|
+
} catch (err) {
|
|
725
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
726
|
+
wasiBindingError = err;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
730
|
+
try {
|
|
731
|
+
wasiBinding = require2("@oxc-parser/binding-wasm32-wasi");
|
|
732
|
+
nativeBinding = wasiBinding;
|
|
733
|
+
} catch (err) {
|
|
734
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
735
|
+
if (!wasiBindingError) {
|
|
736
|
+
wasiBindingError = err;
|
|
737
|
+
} else {
|
|
738
|
+
wasiBindingError.cause = err;
|
|
739
|
+
}
|
|
740
|
+
loadErrors.push(err);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
if (process.env.NAPI_RS_FORCE_WASI === "error" && !wasiBinding) {
|
|
745
|
+
const error = new Error("WASI binding not found and NAPI_RS_FORCE_WASI is set to error");
|
|
746
|
+
error.cause = wasiBindingError;
|
|
747
|
+
throw error;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (!nativeBinding && globalThis.process?.versions?.["webcontainer"]) {
|
|
751
|
+
try {
|
|
752
|
+
nativeBinding = require2("./webcontainer-fallback.cjs");
|
|
753
|
+
} catch (err) {
|
|
754
|
+
loadErrors.push(err);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (!nativeBinding) {
|
|
758
|
+
if (loadErrors.length > 0) {
|
|
759
|
+
throw new Error(
|
|
760
|
+
`Cannot find native binding. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try \`npm i\` again after removing both package-lock.json and node_modules directory.`,
|
|
761
|
+
{
|
|
762
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
763
|
+
cur.cause = err;
|
|
764
|
+
return cur;
|
|
765
|
+
})
|
|
766
|
+
}
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
throw new Error(`Failed to load native binding`);
|
|
770
|
+
}
|
|
771
|
+
({ Severity, ParseResult, ExportExportNameKind, ExportImportNameKind, ExportLocalNameKind, ImportNameKind, parse, parseSync, rawTransferSupported } = nativeBinding);
|
|
772
|
+
({ getBufferOffset, parseRaw, parseRawSync } = nativeBinding);
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
// node_modules/oxc-parser/src-js/wrap.js
|
|
777
|
+
function wrap(result) {
|
|
778
|
+
let program, module2, comments, errors;
|
|
779
|
+
return {
|
|
780
|
+
get program() {
|
|
781
|
+
if (!program) program = jsonParseAst(result.program);
|
|
782
|
+
return program;
|
|
783
|
+
},
|
|
784
|
+
get module() {
|
|
785
|
+
if (!module2) module2 = result.module;
|
|
786
|
+
return module2;
|
|
787
|
+
},
|
|
788
|
+
get comments() {
|
|
789
|
+
if (!comments) comments = result.comments;
|
|
790
|
+
return comments;
|
|
791
|
+
},
|
|
792
|
+
get errors() {
|
|
793
|
+
if (!errors) errors = result.errors;
|
|
794
|
+
return errors;
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
function jsonParseAst(programJson) {
|
|
799
|
+
const { node: program, fixes } = JSON.parse(programJson);
|
|
800
|
+
for (const fixPath of fixes) {
|
|
801
|
+
applyFix(program, fixPath);
|
|
802
|
+
}
|
|
803
|
+
return program;
|
|
804
|
+
}
|
|
805
|
+
function applyFix(program, fixPath) {
|
|
806
|
+
let node = program;
|
|
807
|
+
for (const key of fixPath) {
|
|
808
|
+
node = node[key];
|
|
809
|
+
}
|
|
810
|
+
if (node.bigint) {
|
|
811
|
+
node.value = BigInt(node.bigint);
|
|
812
|
+
} else {
|
|
813
|
+
try {
|
|
814
|
+
node.value = RegExp(node.regex.pattern, node.regex.flags);
|
|
815
|
+
} catch {
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
var init_wrap = __esm({
|
|
820
|
+
"node_modules/oxc-parser/src-js/wrap.js"() {
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
// node_modules/oxc-parser/src-js/generated/visit/keys.js
|
|
825
|
+
var freeze, $EMPTY, DECORATORS__KEY__TYPE_ANNOTATION__VALUE, LEFT__RIGHT, ARGUMENT, BODY, LABEL, CALLEE__TYPE_ARGUMENTS__ARGUMENTS, EXPRESSION, DECORATORS__ID__TYPE_PARAMETERS__SUPER_CLASS__SUPER_TYPE_ARGUMENTS__IMPLEMENTS__BODY, TEST__CONSEQUENT__ALTERNATE, LEFT__RIGHT__BODY, ID__TYPE_PARAMETERS__PARAMS__RETURN_TYPE__BODY, KEY__VALUE, LOCAL, OBJECT__PROPERTY, DECORATORS__KEY__TYPE_ANNOTATION, EXPRESSION__TYPE_ANNOTATION, TYPE_PARAMETERS__PARAMS__RETURN_TYPE, EXPRESSION__TYPE_ARGUMENTS, MEMBERS, ID__BODY, TYPES, TYPE_ANNOTATION, PARAMS, keys_default;
|
|
826
|
+
var init_keys = __esm({
|
|
827
|
+
"node_modules/oxc-parser/src-js/generated/visit/keys.js"() {
|
|
828
|
+
({ freeze } = Object);
|
|
829
|
+
$EMPTY = freeze([]);
|
|
830
|
+
DECORATORS__KEY__TYPE_ANNOTATION__VALUE = freeze([
|
|
831
|
+
"decorators",
|
|
832
|
+
"key",
|
|
833
|
+
"typeAnnotation",
|
|
834
|
+
"value"
|
|
835
|
+
]);
|
|
836
|
+
LEFT__RIGHT = freeze(["left", "right"]);
|
|
837
|
+
ARGUMENT = freeze(["argument"]);
|
|
838
|
+
BODY = freeze(["body"]);
|
|
839
|
+
LABEL = freeze(["label"]);
|
|
840
|
+
CALLEE__TYPE_ARGUMENTS__ARGUMENTS = freeze(["callee", "typeArguments", "arguments"]);
|
|
841
|
+
EXPRESSION = freeze(["expression"]);
|
|
842
|
+
DECORATORS__ID__TYPE_PARAMETERS__SUPER_CLASS__SUPER_TYPE_ARGUMENTS__IMPLEMENTS__BODY = freeze([
|
|
843
|
+
"decorators",
|
|
844
|
+
"id",
|
|
845
|
+
"typeParameters",
|
|
846
|
+
"superClass",
|
|
847
|
+
"superTypeArguments",
|
|
848
|
+
"implements",
|
|
849
|
+
"body"
|
|
850
|
+
]);
|
|
851
|
+
TEST__CONSEQUENT__ALTERNATE = freeze(["test", "consequent", "alternate"]);
|
|
852
|
+
LEFT__RIGHT__BODY = freeze(["left", "right", "body"]);
|
|
853
|
+
ID__TYPE_PARAMETERS__PARAMS__RETURN_TYPE__BODY = freeze([
|
|
854
|
+
"id",
|
|
855
|
+
"typeParameters",
|
|
856
|
+
"params",
|
|
857
|
+
"returnType",
|
|
858
|
+
"body"
|
|
859
|
+
]);
|
|
860
|
+
KEY__VALUE = freeze(["key", "value"]);
|
|
861
|
+
LOCAL = freeze(["local"]);
|
|
862
|
+
OBJECT__PROPERTY = freeze(["object", "property"]);
|
|
863
|
+
DECORATORS__KEY__TYPE_ANNOTATION = freeze(["decorators", "key", "typeAnnotation"]);
|
|
864
|
+
EXPRESSION__TYPE_ANNOTATION = freeze(["expression", "typeAnnotation"]);
|
|
865
|
+
TYPE_PARAMETERS__PARAMS__RETURN_TYPE = freeze(["typeParameters", "params", "returnType"]);
|
|
866
|
+
EXPRESSION__TYPE_ARGUMENTS = freeze(["expression", "typeArguments"]);
|
|
867
|
+
MEMBERS = freeze(["members"]);
|
|
868
|
+
ID__BODY = freeze(["id", "body"]);
|
|
869
|
+
TYPES = freeze(["types"]);
|
|
870
|
+
TYPE_ANNOTATION = freeze(["typeAnnotation"]);
|
|
871
|
+
PARAMS = freeze(["params"]);
|
|
872
|
+
keys_default = freeze({
|
|
873
|
+
// Leaf nodes
|
|
874
|
+
DebuggerStatement: $EMPTY,
|
|
875
|
+
EmptyStatement: $EMPTY,
|
|
876
|
+
Literal: $EMPTY,
|
|
877
|
+
PrivateIdentifier: $EMPTY,
|
|
878
|
+
Super: $EMPTY,
|
|
879
|
+
TemplateElement: $EMPTY,
|
|
880
|
+
ThisExpression: $EMPTY,
|
|
881
|
+
JSXClosingFragment: $EMPTY,
|
|
882
|
+
JSXEmptyExpression: $EMPTY,
|
|
883
|
+
JSXIdentifier: $EMPTY,
|
|
884
|
+
JSXOpeningFragment: $EMPTY,
|
|
885
|
+
JSXText: $EMPTY,
|
|
886
|
+
TSAnyKeyword: $EMPTY,
|
|
887
|
+
TSBigIntKeyword: $EMPTY,
|
|
888
|
+
TSBooleanKeyword: $EMPTY,
|
|
889
|
+
TSIntrinsicKeyword: $EMPTY,
|
|
890
|
+
TSJSDocUnknownType: $EMPTY,
|
|
891
|
+
TSNeverKeyword: $EMPTY,
|
|
892
|
+
TSNullKeyword: $EMPTY,
|
|
893
|
+
TSNumberKeyword: $EMPTY,
|
|
894
|
+
TSObjectKeyword: $EMPTY,
|
|
895
|
+
TSStringKeyword: $EMPTY,
|
|
896
|
+
TSSymbolKeyword: $EMPTY,
|
|
897
|
+
TSThisType: $EMPTY,
|
|
898
|
+
TSUndefinedKeyword: $EMPTY,
|
|
899
|
+
TSUnknownKeyword: $EMPTY,
|
|
900
|
+
TSVoidKeyword: $EMPTY,
|
|
901
|
+
// Non-leaf nodes
|
|
902
|
+
AccessorProperty: DECORATORS__KEY__TYPE_ANNOTATION__VALUE,
|
|
903
|
+
ArrayExpression: freeze(["elements"]),
|
|
904
|
+
ArrayPattern: freeze(["decorators", "elements", "typeAnnotation"]),
|
|
905
|
+
ArrowFunctionExpression: freeze(["typeParameters", "params", "returnType", "body"]),
|
|
906
|
+
AssignmentExpression: LEFT__RIGHT,
|
|
907
|
+
AssignmentPattern: freeze(["decorators", "left", "right", "typeAnnotation"]),
|
|
908
|
+
AwaitExpression: ARGUMENT,
|
|
909
|
+
BinaryExpression: LEFT__RIGHT,
|
|
910
|
+
BlockStatement: BODY,
|
|
911
|
+
BreakStatement: LABEL,
|
|
912
|
+
CallExpression: CALLEE__TYPE_ARGUMENTS__ARGUMENTS,
|
|
913
|
+
CatchClause: freeze(["param", "body"]),
|
|
914
|
+
ChainExpression: EXPRESSION,
|
|
915
|
+
ClassBody: BODY,
|
|
916
|
+
ClassDeclaration: DECORATORS__ID__TYPE_PARAMETERS__SUPER_CLASS__SUPER_TYPE_ARGUMENTS__IMPLEMENTS__BODY,
|
|
917
|
+
ClassExpression: DECORATORS__ID__TYPE_PARAMETERS__SUPER_CLASS__SUPER_TYPE_ARGUMENTS__IMPLEMENTS__BODY,
|
|
918
|
+
ConditionalExpression: TEST__CONSEQUENT__ALTERNATE,
|
|
919
|
+
ContinueStatement: LABEL,
|
|
920
|
+
Decorator: EXPRESSION,
|
|
921
|
+
DoWhileStatement: freeze(["body", "test"]),
|
|
922
|
+
ExportAllDeclaration: freeze(["exported", "source", "attributes"]),
|
|
923
|
+
ExportDefaultDeclaration: freeze(["declaration"]),
|
|
924
|
+
ExportNamedDeclaration: freeze(["declaration", "specifiers", "source", "attributes"]),
|
|
925
|
+
ExportSpecifier: freeze(["local", "exported"]),
|
|
926
|
+
ExpressionStatement: EXPRESSION,
|
|
927
|
+
ForInStatement: LEFT__RIGHT__BODY,
|
|
928
|
+
ForOfStatement: LEFT__RIGHT__BODY,
|
|
929
|
+
ForStatement: freeze(["init", "test", "update", "body"]),
|
|
930
|
+
FunctionDeclaration: ID__TYPE_PARAMETERS__PARAMS__RETURN_TYPE__BODY,
|
|
931
|
+
FunctionExpression: ID__TYPE_PARAMETERS__PARAMS__RETURN_TYPE__BODY,
|
|
932
|
+
Identifier: freeze(["decorators", "typeAnnotation"]),
|
|
933
|
+
IfStatement: TEST__CONSEQUENT__ALTERNATE,
|
|
934
|
+
ImportAttribute: KEY__VALUE,
|
|
935
|
+
ImportDeclaration: freeze(["specifiers", "source", "attributes"]),
|
|
936
|
+
ImportDefaultSpecifier: LOCAL,
|
|
937
|
+
ImportExpression: freeze(["source", "options"]),
|
|
938
|
+
ImportNamespaceSpecifier: LOCAL,
|
|
939
|
+
ImportSpecifier: freeze(["imported", "local"]),
|
|
940
|
+
LabeledStatement: freeze(["label", "body"]),
|
|
941
|
+
LogicalExpression: LEFT__RIGHT,
|
|
942
|
+
MemberExpression: OBJECT__PROPERTY,
|
|
943
|
+
MetaProperty: freeze(["meta", "property"]),
|
|
944
|
+
MethodDefinition: freeze(["decorators", "key", "value"]),
|
|
945
|
+
NewExpression: CALLEE__TYPE_ARGUMENTS__ARGUMENTS,
|
|
946
|
+
ObjectExpression: freeze(["properties"]),
|
|
947
|
+
ObjectPattern: freeze(["decorators", "properties", "typeAnnotation"]),
|
|
948
|
+
ParenthesizedExpression: EXPRESSION,
|
|
949
|
+
Program: BODY,
|
|
950
|
+
Property: KEY__VALUE,
|
|
951
|
+
PropertyDefinition: DECORATORS__KEY__TYPE_ANNOTATION__VALUE,
|
|
952
|
+
RestElement: freeze(["decorators", "argument", "typeAnnotation"]),
|
|
953
|
+
ReturnStatement: ARGUMENT,
|
|
954
|
+
SequenceExpression: freeze(["expressions"]),
|
|
955
|
+
SpreadElement: ARGUMENT,
|
|
956
|
+
StaticBlock: BODY,
|
|
957
|
+
SwitchCase: freeze(["test", "consequent"]),
|
|
958
|
+
SwitchStatement: freeze(["discriminant", "cases"]),
|
|
959
|
+
TaggedTemplateExpression: freeze(["tag", "typeArguments", "quasi"]),
|
|
960
|
+
TemplateLiteral: freeze(["quasis", "expressions"]),
|
|
961
|
+
ThrowStatement: ARGUMENT,
|
|
962
|
+
TryStatement: freeze(["block", "handler", "finalizer"]),
|
|
963
|
+
UnaryExpression: ARGUMENT,
|
|
964
|
+
UpdateExpression: ARGUMENT,
|
|
965
|
+
V8IntrinsicExpression: freeze(["name", "arguments"]),
|
|
966
|
+
VariableDeclaration: freeze(["declarations"]),
|
|
967
|
+
VariableDeclarator: freeze(["id", "init"]),
|
|
968
|
+
WhileStatement: freeze(["test", "body"]),
|
|
969
|
+
WithStatement: freeze(["object", "body"]),
|
|
970
|
+
YieldExpression: ARGUMENT,
|
|
971
|
+
JSXAttribute: freeze(["name", "value"]),
|
|
972
|
+
JSXClosingElement: freeze(["name"]),
|
|
973
|
+
JSXElement: freeze(["openingElement", "children", "closingElement"]),
|
|
974
|
+
JSXExpressionContainer: EXPRESSION,
|
|
975
|
+
JSXFragment: freeze(["openingFragment", "children", "closingFragment"]),
|
|
976
|
+
JSXMemberExpression: OBJECT__PROPERTY,
|
|
977
|
+
JSXNamespacedName: freeze(["namespace", "name"]),
|
|
978
|
+
JSXOpeningElement: freeze(["name", "typeArguments", "attributes"]),
|
|
979
|
+
JSXSpreadAttribute: ARGUMENT,
|
|
980
|
+
JSXSpreadChild: EXPRESSION,
|
|
981
|
+
TSAbstractAccessorProperty: DECORATORS__KEY__TYPE_ANNOTATION,
|
|
982
|
+
TSAbstractMethodDefinition: KEY__VALUE,
|
|
983
|
+
TSAbstractPropertyDefinition: DECORATORS__KEY__TYPE_ANNOTATION,
|
|
984
|
+
TSArrayType: freeze(["elementType"]),
|
|
985
|
+
TSAsExpression: EXPRESSION__TYPE_ANNOTATION,
|
|
986
|
+
TSCallSignatureDeclaration: TYPE_PARAMETERS__PARAMS__RETURN_TYPE,
|
|
987
|
+
TSClassImplements: EXPRESSION__TYPE_ARGUMENTS,
|
|
988
|
+
TSConditionalType: freeze(["checkType", "extendsType", "trueType", "falseType"]),
|
|
989
|
+
TSConstructSignatureDeclaration: TYPE_PARAMETERS__PARAMS__RETURN_TYPE,
|
|
990
|
+
TSConstructorType: TYPE_PARAMETERS__PARAMS__RETURN_TYPE,
|
|
991
|
+
TSDeclareFunction: ID__TYPE_PARAMETERS__PARAMS__RETURN_TYPE__BODY,
|
|
992
|
+
TSEmptyBodyFunctionExpression: freeze(["id", "typeParameters", "params", "returnType"]),
|
|
993
|
+
TSEnumBody: MEMBERS,
|
|
994
|
+
TSEnumDeclaration: ID__BODY,
|
|
995
|
+
TSEnumMember: freeze(["id", "initializer"]),
|
|
996
|
+
TSExportAssignment: EXPRESSION,
|
|
997
|
+
TSExternalModuleReference: EXPRESSION,
|
|
998
|
+
TSFunctionType: TYPE_PARAMETERS__PARAMS__RETURN_TYPE,
|
|
999
|
+
TSImportEqualsDeclaration: freeze(["id", "moduleReference"]),
|
|
1000
|
+
TSImportType: freeze(["source", "options", "qualifier", "typeArguments"]),
|
|
1001
|
+
TSIndexSignature: freeze(["parameters", "typeAnnotation"]),
|
|
1002
|
+
TSIndexedAccessType: freeze(["objectType", "indexType"]),
|
|
1003
|
+
TSInferType: freeze(["typeParameter"]),
|
|
1004
|
+
TSInstantiationExpression: EXPRESSION__TYPE_ARGUMENTS,
|
|
1005
|
+
TSInterfaceBody: BODY,
|
|
1006
|
+
TSInterfaceDeclaration: freeze(["id", "typeParameters", "extends", "body"]),
|
|
1007
|
+
TSInterfaceHeritage: EXPRESSION__TYPE_ARGUMENTS,
|
|
1008
|
+
TSIntersectionType: TYPES,
|
|
1009
|
+
TSJSDocNonNullableType: TYPE_ANNOTATION,
|
|
1010
|
+
TSJSDocNullableType: TYPE_ANNOTATION,
|
|
1011
|
+
TSLiteralType: freeze(["literal"]),
|
|
1012
|
+
TSMappedType: freeze(["key", "constraint", "nameType", "typeAnnotation"]),
|
|
1013
|
+
TSMethodSignature: freeze(["key", "typeParameters", "params", "returnType"]),
|
|
1014
|
+
TSModuleBlock: BODY,
|
|
1015
|
+
TSModuleDeclaration: ID__BODY,
|
|
1016
|
+
TSNamedTupleMember: freeze(["label", "elementType"]),
|
|
1017
|
+
TSNamespaceExportDeclaration: freeze(["id"]),
|
|
1018
|
+
TSNonNullExpression: EXPRESSION,
|
|
1019
|
+
TSOptionalType: TYPE_ANNOTATION,
|
|
1020
|
+
TSParameterProperty: freeze(["decorators", "parameter"]),
|
|
1021
|
+
TSParenthesizedType: TYPE_ANNOTATION,
|
|
1022
|
+
TSPropertySignature: freeze(["key", "typeAnnotation"]),
|
|
1023
|
+
TSQualifiedName: LEFT__RIGHT,
|
|
1024
|
+
TSRestType: TYPE_ANNOTATION,
|
|
1025
|
+
TSSatisfiesExpression: EXPRESSION__TYPE_ANNOTATION,
|
|
1026
|
+
TSTemplateLiteralType: freeze(["quasis", "types"]),
|
|
1027
|
+
TSTupleType: freeze(["elementTypes"]),
|
|
1028
|
+
TSTypeAliasDeclaration: freeze(["id", "typeParameters", "typeAnnotation"]),
|
|
1029
|
+
TSTypeAnnotation: TYPE_ANNOTATION,
|
|
1030
|
+
TSTypeAssertion: freeze(["typeAnnotation", "expression"]),
|
|
1031
|
+
TSTypeLiteral: MEMBERS,
|
|
1032
|
+
TSTypeOperator: TYPE_ANNOTATION,
|
|
1033
|
+
TSTypeParameter: freeze(["name", "constraint", "default"]),
|
|
1034
|
+
TSTypeParameterDeclaration: PARAMS,
|
|
1035
|
+
TSTypeParameterInstantiation: PARAMS,
|
|
1036
|
+
TSTypePredicate: freeze(["parameterName", "typeAnnotation"]),
|
|
1037
|
+
TSTypeQuery: freeze(["exprName", "typeArguments"]),
|
|
1038
|
+
TSTypeReference: freeze(["typeName", "typeArguments"]),
|
|
1039
|
+
TSUnionType: TYPES
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
var walkProgram, addVisitorToCompiled, createCompiledVisitor, finalizeCompiledVisitor, Visitor;
|
|
1044
|
+
var init_visit = __esm({
|
|
1045
|
+
"node_modules/oxc-parser/src-js/visit/index.js"() {
|
|
1046
|
+
walkProgram = null;
|
|
1047
|
+
Visitor = class {
|
|
1048
|
+
#compiledVisitor = null;
|
|
1049
|
+
constructor(visitor) {
|
|
1050
|
+
if (walkProgram === null) {
|
|
1051
|
+
const require4 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('compiler.js', document.baseURI).href)));
|
|
1052
|
+
({ walkProgram } = require4("../generated/visit/walk.js"));
|
|
1053
|
+
({
|
|
1054
|
+
addVisitorToCompiled,
|
|
1055
|
+
createCompiledVisitor,
|
|
1056
|
+
finalizeCompiledVisitor
|
|
1057
|
+
} = require4("./visitor.js"));
|
|
1058
|
+
}
|
|
1059
|
+
const compiledVisitor = createCompiledVisitor();
|
|
1060
|
+
addVisitorToCompiled(visitor);
|
|
1061
|
+
const needsVisit = finalizeCompiledVisitor();
|
|
1062
|
+
if (needsVisit) this.#compiledVisitor = compiledVisitor;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Visit AST.
|
|
1066
|
+
* @param program - The AST to visit.
|
|
1067
|
+
* @returns {undefined}
|
|
1068
|
+
*/
|
|
1069
|
+
visit(program) {
|
|
1070
|
+
const compiledVisitor = this.#compiledVisitor;
|
|
1071
|
+
if (compiledVisitor !== null) walkProgram(program, compiledVisitor);
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
// node_modules/oxc-parser/src-js/raw-transfer/supported.js
|
|
1078
|
+
function rawTransferSupported2() {
|
|
1079
|
+
if (rawTransferIsSupported === null) {
|
|
1080
|
+
rawTransferIsSupported = rawTransferRuntimeSupported() && rawTransferSupported();
|
|
1081
|
+
}
|
|
1082
|
+
return rawTransferIsSupported;
|
|
1083
|
+
}
|
|
1084
|
+
function rawTransferRuntimeSupported() {
|
|
1085
|
+
let global;
|
|
1086
|
+
try {
|
|
1087
|
+
global = globalThis;
|
|
1088
|
+
} catch {
|
|
1089
|
+
return false;
|
|
1090
|
+
}
|
|
1091
|
+
const isBun = !!global.Bun || !!global.process?.versions?.bun;
|
|
1092
|
+
if (isBun) return false;
|
|
1093
|
+
const isDeno = !!global.Deno;
|
|
1094
|
+
if (isDeno) {
|
|
1095
|
+
const match2 = Deno.version?.deno?.match(/^(\d+)\./);
|
|
1096
|
+
return !!match2 && match2[1] * 1 >= 2;
|
|
1097
|
+
}
|
|
1098
|
+
const isNode = global.process?.release?.name === "node";
|
|
1099
|
+
if (!isNode) return false;
|
|
1100
|
+
const match = process.version?.match(/^v(\d+)\./);
|
|
1101
|
+
return !!match && match[1] * 1 >= 22;
|
|
1102
|
+
}
|
|
1103
|
+
var rawTransferIsSupported;
|
|
1104
|
+
var init_supported = __esm({
|
|
1105
|
+
"node_modules/oxc-parser/src-js/raw-transfer/supported.js"() {
|
|
1106
|
+
init_bindings();
|
|
1107
|
+
rawTransferIsSupported = null;
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
// node_modules/oxc-parser/src-js/index.js
|
|
1112
|
+
var src_js_exports = {};
|
|
1113
|
+
__export(src_js_exports, {
|
|
1114
|
+
ExportExportNameKind: () => ExportExportNameKind,
|
|
1115
|
+
ExportImportNameKind: () => ExportImportNameKind,
|
|
1116
|
+
ExportLocalNameKind: () => ExportLocalNameKind,
|
|
1117
|
+
ImportNameKind: () => ImportNameKind,
|
|
1118
|
+
ParseResult: () => ParseResult,
|
|
1119
|
+
Severity: () => Severity,
|
|
1120
|
+
Visitor: () => Visitor,
|
|
1121
|
+
experimentalGetLazyVisitor: () => experimentalGetLazyVisitor,
|
|
1122
|
+
parse: () => parse2,
|
|
1123
|
+
parseSync: () => parseSync2,
|
|
1124
|
+
rawTransferSupported: () => rawTransferSupported2,
|
|
1125
|
+
visitorKeys: () => keys_default
|
|
1126
|
+
});
|
|
1127
|
+
function loadRawTransfer() {
|
|
1128
|
+
if (parseSyncRaw === null) {
|
|
1129
|
+
({ parseSyncRaw, parse: parseRaw2 } = require3("./raw-transfer/eager.js"));
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
function loadRawTransferLazy() {
|
|
1133
|
+
if (parseSyncLazy === null) {
|
|
1134
|
+
({ parseSyncLazy, parse: parseLazy, Visitor: LazyVisitor } = require3("./raw-transfer/lazy.js"));
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
function parseSync2(filename, sourceText, options) {
|
|
1138
|
+
if (options?.experimentalRawTransfer) {
|
|
1139
|
+
loadRawTransfer();
|
|
1140
|
+
return parseSyncRaw(filename, sourceText, options);
|
|
1141
|
+
}
|
|
1142
|
+
if (options?.experimentalLazy) {
|
|
1143
|
+
loadRawTransferLazy();
|
|
1144
|
+
return parseSyncLazy(filename, sourceText, options);
|
|
1145
|
+
}
|
|
1146
|
+
return wrap(parseSync(filename, sourceText, options));
|
|
1147
|
+
}
|
|
1148
|
+
async function parse2(filename, sourceText, options) {
|
|
1149
|
+
if (options?.experimentalRawTransfer) {
|
|
1150
|
+
loadRawTransfer();
|
|
1151
|
+
return await parseRaw2(filename, sourceText, options);
|
|
1152
|
+
}
|
|
1153
|
+
if (options?.experimentalLazy) {
|
|
1154
|
+
loadRawTransferLazy();
|
|
1155
|
+
return await parseLazy(filename, sourceText, options);
|
|
1156
|
+
}
|
|
1157
|
+
return wrap(await parse(filename, sourceText, options));
|
|
1158
|
+
}
|
|
1159
|
+
function experimentalGetLazyVisitor() {
|
|
1160
|
+
loadRawTransferLazy();
|
|
1161
|
+
return LazyVisitor;
|
|
1162
|
+
}
|
|
1163
|
+
var require3, parseSyncRaw, parseRaw2, parseSyncLazy, parseLazy, LazyVisitor;
|
|
1164
|
+
var init_src_js = __esm({
|
|
1165
|
+
"node_modules/oxc-parser/src-js/index.js"() {
|
|
1166
|
+
init_bindings();
|
|
1167
|
+
init_wrap();
|
|
1168
|
+
init_keys();
|
|
1169
|
+
init_visit();
|
|
1170
|
+
init_bindings();
|
|
1171
|
+
init_supported();
|
|
1172
|
+
require3 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('compiler.js', document.baseURI).href)));
|
|
1173
|
+
parseSyncRaw = null;
|
|
1174
|
+
parseSyncLazy = null;
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
// packages/compiler/src/cssCompiler.ts
|
|
1179
|
+
var cssCompiler_exports = {};
|
|
1180
|
+
__export(cssCompiler_exports, {
|
|
1181
|
+
buildStyleTag: () => buildStyleTag,
|
|
1182
|
+
compileCssFromClasses: () => compileCssFromClasses
|
|
1183
|
+
});
|
|
1184
|
+
function getBinding() {
|
|
1185
|
+
if (_binding !== void 0) {
|
|
1186
|
+
if (_binding === null) {
|
|
1187
|
+
throw new Error(
|
|
1188
|
+
`[tailwind-styled/compiler v5] Native CSS binding is required but not available.
|
|
1189
|
+
Please ensure the native module is properly built.`
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
return _binding;
|
|
1193
|
+
}
|
|
1194
|
+
if (process.env.TWS_NO_NATIVE === "1") {
|
|
1195
|
+
_binding = null;
|
|
1196
|
+
throw new Error(
|
|
1197
|
+
`[tailwind-styled/compiler v5] Native binding is required.
|
|
1198
|
+
The TWS_NO_NATIVE environment variable is set, which disables native binding.`
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
const req = typeof __require === "function" ? __require : module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('compiler.js', document.baseURI).href)));
|
|
1202
|
+
const candidates = [
|
|
1203
|
+
path7__default.default.resolve(process.cwd(), "native", "tailwind_styled_parser.node"),
|
|
1204
|
+
path7__default.default.resolve(__dirname, "..", "..", "..", "..", "native", "tailwind_styled_parser.node")
|
|
1205
|
+
];
|
|
1206
|
+
for (const c of candidates) {
|
|
1207
|
+
try {
|
|
1208
|
+
const mod = req(c);
|
|
1209
|
+
if (mod?.compileCss) {
|
|
1210
|
+
_binding = mod;
|
|
1211
|
+
return _binding;
|
|
1212
|
+
}
|
|
1213
|
+
} catch {
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
_binding = null;
|
|
1217
|
+
throw new Error(
|
|
1218
|
+
`[tailwind-styled/compiler v5] Native CSS binding not found.
|
|
1219
|
+
Tried loading from:
|
|
1220
|
+
` + candidates.map((c) => ` - ${c}`).join("\n") + `
|
|
1221
|
+
|
|
1222
|
+
Please build the native module.`
|
|
1223
|
+
);
|
|
1224
|
+
}
|
|
1225
|
+
function compileCssFromClasses(classes, options = {}) {
|
|
1226
|
+
const binding = getBinding();
|
|
1227
|
+
const prefix = options.prefix ?? null;
|
|
1228
|
+
const r = binding.compileCss(classes, prefix);
|
|
1229
|
+
return {
|
|
1230
|
+
css: r.css,
|
|
1231
|
+
resolvedClasses: r.resolvedClasses,
|
|
1232
|
+
unknownClasses: r.unknownClasses,
|
|
1233
|
+
sizeBytes: r.sizeBytes,
|
|
1234
|
+
engine: "rust"
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
function buildStyleTag(classes) {
|
|
1238
|
+
const { css } = compileCssFromClasses(classes);
|
|
1239
|
+
return css ? `<style data-tailwind-styled>${css}</style>` : "";
|
|
1240
|
+
}
|
|
1241
|
+
var _binding;
|
|
1242
|
+
var init_cssCompiler = __esm({
|
|
1243
|
+
"packages/compiler/src/cssCompiler.ts"() {
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
// packages/compiler/src/atomicCss.ts
|
|
1248
|
+
var atomicCss_exports = {};
|
|
1249
|
+
__export(atomicCss_exports, {
|
|
1250
|
+
clearAtomicRegistry: () => clearAtomicRegistry,
|
|
1251
|
+
generateAtomicCss: () => generateAtomicCss,
|
|
1252
|
+
getAtomicRegistry: () => getAtomicRegistry,
|
|
1253
|
+
parseAtomicClass: () => parseAtomicClass,
|
|
1254
|
+
toAtomicClasses: () => toAtomicClasses
|
|
1255
|
+
});
|
|
1256
|
+
function sizeValue(v) {
|
|
1257
|
+
const num = Number(v);
|
|
1258
|
+
if (!Number.isNaN(num)) return `${num * 0.25}rem`;
|
|
1259
|
+
const special = {
|
|
1260
|
+
full: "100%",
|
|
1261
|
+
screen: "100vw",
|
|
1262
|
+
auto: "auto",
|
|
1263
|
+
min: "min-content",
|
|
1264
|
+
max: "max-content",
|
|
1265
|
+
fit: "fit-content",
|
|
1266
|
+
svw: "100svw",
|
|
1267
|
+
svh: "100svh"
|
|
1268
|
+
};
|
|
1269
|
+
return special[v] ?? v;
|
|
1270
|
+
}
|
|
1271
|
+
function textSize(v) {
|
|
1272
|
+
const map = {
|
|
1273
|
+
xs: "0.75rem",
|
|
1274
|
+
sm: "0.875rem",
|
|
1275
|
+
base: "1rem",
|
|
1276
|
+
lg: "1.125rem",
|
|
1277
|
+
xl: "1.25rem",
|
|
1278
|
+
"2xl": "1.5rem",
|
|
1279
|
+
"3xl": "1.875rem",
|
|
1280
|
+
"4xl": "2.25rem",
|
|
1281
|
+
"5xl": "3rem",
|
|
1282
|
+
"6xl": "3.75rem",
|
|
1283
|
+
"7xl": "4.5rem",
|
|
1284
|
+
"8xl": "6rem",
|
|
1285
|
+
"9xl": "8rem"
|
|
1286
|
+
};
|
|
1287
|
+
return map[v] ?? v;
|
|
1288
|
+
}
|
|
1289
|
+
function fontWeight(v) {
|
|
1290
|
+
const map = {
|
|
1291
|
+
thin: "100",
|
|
1292
|
+
extralight: "200",
|
|
1293
|
+
light: "300",
|
|
1294
|
+
normal: "400",
|
|
1295
|
+
medium: "500",
|
|
1296
|
+
semibold: "600",
|
|
1297
|
+
bold: "700",
|
|
1298
|
+
extrabold: "800",
|
|
1299
|
+
black: "900"
|
|
1300
|
+
};
|
|
1301
|
+
return map[v] ?? v;
|
|
1302
|
+
}
|
|
1303
|
+
function leadingValue(v) {
|
|
1304
|
+
const map = {
|
|
1305
|
+
none: "1",
|
|
1306
|
+
tight: "1.25",
|
|
1307
|
+
snug: "1.375",
|
|
1308
|
+
normal: "1.5",
|
|
1309
|
+
relaxed: "1.625",
|
|
1310
|
+
loose: "2"
|
|
1311
|
+
};
|
|
1312
|
+
return map[v] ?? v;
|
|
1313
|
+
}
|
|
1314
|
+
function roundedValue(v) {
|
|
1315
|
+
const map = {
|
|
1316
|
+
"": "0.25rem",
|
|
1317
|
+
sm: "0.125rem",
|
|
1318
|
+
md: "0.375rem",
|
|
1319
|
+
lg: "0.5rem",
|
|
1320
|
+
xl: "0.75rem",
|
|
1321
|
+
"2xl": "1rem",
|
|
1322
|
+
"3xl": "1.5rem",
|
|
1323
|
+
full: "9999px",
|
|
1324
|
+
none: "0"
|
|
1325
|
+
};
|
|
1326
|
+
return map[v] ?? `${v}rem`;
|
|
1327
|
+
}
|
|
1328
|
+
function sanitizeClassName(cls) {
|
|
1329
|
+
return cls.replace(/[/:[\].!%]/g, "_");
|
|
1330
|
+
}
|
|
1331
|
+
function parseAtomicClass(twClass) {
|
|
1332
|
+
if (REGISTRY.has(twClass)) return REGISTRY.get(twClass);
|
|
1333
|
+
const colonIdx = twClass.lastIndexOf(":");
|
|
1334
|
+
const modifier = colonIdx > -1 ? twClass.slice(0, colonIdx) : void 0;
|
|
1335
|
+
const base = colonIdx > -1 ? twClass.slice(colonIdx + 1) : twClass;
|
|
1336
|
+
const dashIdx = base.indexOf("-");
|
|
1337
|
+
if (dashIdx === -1) return null;
|
|
1338
|
+
const prefix = base.slice(0, dashIdx);
|
|
1339
|
+
const value = base.slice(dashIdx + 1);
|
|
1340
|
+
const mapping = TW_PROPERTY_MAP[prefix];
|
|
1341
|
+
if (!mapping) return null;
|
|
1342
|
+
const cssValue = mapping.transform ? mapping.transform(value) : value;
|
|
1343
|
+
const atomicName = `_tw_${sanitizeClassName(twClass)}`;
|
|
1344
|
+
const rule = {
|
|
1345
|
+
twClass,
|
|
1346
|
+
atomicName,
|
|
1347
|
+
property: mapping.prop,
|
|
1348
|
+
value: cssValue,
|
|
1349
|
+
modifier
|
|
1350
|
+
};
|
|
1351
|
+
REGISTRY.set(twClass, rule);
|
|
1352
|
+
return rule;
|
|
1353
|
+
}
|
|
1354
|
+
function generateAtomicCss(rules) {
|
|
1355
|
+
const lines = [];
|
|
1356
|
+
for (const rule of rules) {
|
|
1357
|
+
const selector = `.${rule.atomicName}`;
|
|
1358
|
+
if (rule.modifier) {
|
|
1359
|
+
const breakpoints = {
|
|
1360
|
+
sm: "640px",
|
|
1361
|
+
md: "768px",
|
|
1362
|
+
lg: "1024px",
|
|
1363
|
+
xl: "1280px",
|
|
1364
|
+
"2xl": "1536px"
|
|
1365
|
+
};
|
|
1366
|
+
if (breakpoints[rule.modifier]) {
|
|
1367
|
+
lines.push(
|
|
1368
|
+
`@media (min-width: ${breakpoints[rule.modifier]}) {`,
|
|
1369
|
+
` ${selector} { ${rule.property}: ${rule.value}; }`,
|
|
1370
|
+
`}`
|
|
1371
|
+
);
|
|
1372
|
+
continue;
|
|
1373
|
+
}
|
|
1374
|
+
lines.push(`${selector}:${rule.modifier} { ${rule.property}: ${rule.value}; }`);
|
|
1375
|
+
} else {
|
|
1376
|
+
lines.push(`${selector} { ${rule.property}: ${rule.value}; }`);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
return lines.join("\n");
|
|
1380
|
+
}
|
|
1381
|
+
function toAtomicClasses(twClasses) {
|
|
1382
|
+
const parts = twClasses.split(/\s+/).filter(Boolean);
|
|
1383
|
+
const atomicNames = [];
|
|
1384
|
+
const rules = [];
|
|
1385
|
+
const unknownClasses = [];
|
|
1386
|
+
for (const cls of parts) {
|
|
1387
|
+
const rule = parseAtomicClass(cls);
|
|
1388
|
+
if (rule) {
|
|
1389
|
+
atomicNames.push(rule.atomicName);
|
|
1390
|
+
rules.push(rule);
|
|
1391
|
+
} else {
|
|
1392
|
+
unknownClasses.push(cls);
|
|
1393
|
+
atomicNames.push(cls);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
return {
|
|
1397
|
+
atomicClasses: atomicNames.join(" "),
|
|
1398
|
+
rules,
|
|
1399
|
+
unknownClasses
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
function getAtomicRegistry() {
|
|
1403
|
+
return REGISTRY;
|
|
1404
|
+
}
|
|
1405
|
+
function clearAtomicRegistry() {
|
|
1406
|
+
REGISTRY.clear();
|
|
1407
|
+
}
|
|
1408
|
+
var REGISTRY, TW_PROPERTY_MAP;
|
|
1409
|
+
var init_atomicCss = __esm({
|
|
1410
|
+
"packages/compiler/src/atomicCss.ts"() {
|
|
1411
|
+
REGISTRY = /* @__PURE__ */ new Map();
|
|
1412
|
+
TW_PROPERTY_MAP = {
|
|
1413
|
+
// Spacing
|
|
1414
|
+
p: { prop: "padding", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1415
|
+
px: { prop: "padding-inline", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1416
|
+
py: { prop: "padding-block", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1417
|
+
pt: { prop: "padding-top", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1418
|
+
pb: { prop: "padding-bottom", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1419
|
+
pl: { prop: "padding-left", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1420
|
+
pr: { prop: "padding-right", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1421
|
+
m: { prop: "margin", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1422
|
+
mx: { prop: "margin-inline", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1423
|
+
my: { prop: "margin-block", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1424
|
+
mt: { prop: "margin-top", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1425
|
+
mb: { prop: "margin-bottom", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1426
|
+
ml: { prop: "margin-left", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1427
|
+
mr: { prop: "margin-right", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1428
|
+
gap: { prop: "gap", transform: (v) => `${Number(v) * 0.25}rem` },
|
|
1429
|
+
// Sizing
|
|
1430
|
+
w: { prop: "width", transform: sizeValue },
|
|
1431
|
+
h: { prop: "height", transform: sizeValue },
|
|
1432
|
+
// Typography
|
|
1433
|
+
text: { prop: "font-size", transform: textSize },
|
|
1434
|
+
font: { prop: "font-weight", transform: fontWeight },
|
|
1435
|
+
leading: { prop: "line-height", transform: leadingValue },
|
|
1436
|
+
// Misc
|
|
1437
|
+
opacity: { prop: "opacity", transform: (v) => String(Number(v) / 100) },
|
|
1438
|
+
z: { prop: "z-index" },
|
|
1439
|
+
rounded: { prop: "border-radius", transform: (v) => roundedValue(v) }
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
|
|
1444
|
+
// packages/preset/src/defaultPreset.ts
|
|
1445
|
+
var defaultPreset_exports = {};
|
|
1446
|
+
__export(defaultPreset_exports, {
|
|
1447
|
+
defaultGlobalCss: () => defaultGlobalCss,
|
|
1448
|
+
defaultPreset: () => defaultPreset,
|
|
1449
|
+
defaultThemeCss: () => defaultThemeCss,
|
|
1450
|
+
designTokens: () => designTokens,
|
|
1451
|
+
generateTailwindConfig: () => generateTailwindConfig,
|
|
1452
|
+
generateTailwindCss: () => generateTailwindCss
|
|
1453
|
+
});
|
|
1454
|
+
function generateTailwindCss(contentPaths = STANDARD_CONTENT_PATHS) {
|
|
1455
|
+
return `@import "tailwindcss";
|
|
1456
|
+
|
|
1457
|
+
@theme {
|
|
1458
|
+
/* colors */
|
|
1459
|
+
--color-primary: #3b82f6;
|
|
1460
|
+
--color-primary-hover: #2563eb;
|
|
1461
|
+
--color-primary-active: #1d4ed8;
|
|
1462
|
+
--color-primary-foreground: #ffffff;
|
|
1463
|
+
--color-secondary: #6366f1;
|
|
1464
|
+
--color-secondary-hover: #4f46e5;
|
|
1465
|
+
--color-secondary-active: #4338ca;
|
|
1466
|
+
--color-secondary-foreground: #ffffff;
|
|
1467
|
+
--color-accent: #f59e0b;
|
|
1468
|
+
--color-accent-hover: #d97706;
|
|
1469
|
+
--color-accent-active: #b45309;
|
|
1470
|
+
--color-accent-foreground: #000000;
|
|
1471
|
+
--color-success: #10b981;
|
|
1472
|
+
--color-success-foreground: #ffffff;
|
|
1473
|
+
--color-warning: #f59e0b;
|
|
1474
|
+
--color-warning-foreground: #000000;
|
|
1475
|
+
--color-danger: #ef4444;
|
|
1476
|
+
--color-danger-foreground: #ffffff;
|
|
1477
|
+
--color-info: #3b82f6;
|
|
1478
|
+
--color-info-foreground: #ffffff;
|
|
1479
|
+
--color-surface: #18181b;
|
|
1480
|
+
--color-border: #27272a;
|
|
1481
|
+
--color-muted: #71717a;
|
|
1482
|
+
--color-subtle: #3f3f46;
|
|
1483
|
+
|
|
1484
|
+
/* fonts */
|
|
1485
|
+
--font-sans: InterVariable, Inter, system-ui, sans-serif;
|
|
1486
|
+
--font-mono: JetBrains Mono, Fira Code, Consolas, monospace;
|
|
1487
|
+
|
|
1488
|
+
/* spacing */
|
|
1489
|
+
--spacing-1: 0.25rem;
|
|
1490
|
+
--spacing-2: 0.5rem;
|
|
1491
|
+
--spacing-3: 0.75rem;
|
|
1492
|
+
--spacing-4: 1rem;
|
|
1493
|
+
--spacing-5: 1.25rem;
|
|
1494
|
+
--spacing-6: 1.5rem;
|
|
1495
|
+
--spacing-8: 2rem;
|
|
1496
|
+
--spacing-10: 2.5rem;
|
|
1497
|
+
--spacing-12: 3rem;
|
|
1498
|
+
--spacing-16: 4rem;
|
|
1499
|
+
|
|
1500
|
+
/* breakpoints */
|
|
1501
|
+
--breakpoint-sm: 40rem;
|
|
1502
|
+
--breakpoint-md: 48rem;
|
|
1503
|
+
--breakpoint-lg: 64rem;
|
|
1504
|
+
--breakpoint-xl: 80rem;
|
|
1505
|
+
--breakpoint-2xl: 96rem;
|
|
1506
|
+
|
|
1507
|
+
/* border radius */
|
|
1508
|
+
--radius-sm: 0.25rem;
|
|
1509
|
+
--radius-md: 0.5rem;
|
|
1510
|
+
--radius-lg: 0.75rem;
|
|
1511
|
+
--radius-xl: 1rem;
|
|
1512
|
+
--radius-2xl: 1.5rem;
|
|
1513
|
+
--radius-full: 9999px;
|
|
1514
|
+
|
|
1515
|
+
/* animations */
|
|
1516
|
+
--animate-fade-in: fadeIn 0.2s ease-out;
|
|
1517
|
+
--animate-fade-out: fadeOut 0.2s ease-in;
|
|
1518
|
+
--animate-slide-up: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1519
|
+
--animate-slide-down: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1520
|
+
--animate-scale-in: scaleIn 0.2s ease-out;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
@keyframes fadeIn {
|
|
1524
|
+
from { opacity: 0; }
|
|
1525
|
+
to { opacity: 1; }
|
|
1526
|
+
}
|
|
1527
|
+
@keyframes fadeOut {
|
|
1528
|
+
from { opacity: 1; }
|
|
1529
|
+
to { opacity: 0; }
|
|
1530
|
+
}
|
|
1531
|
+
@keyframes slideUp {
|
|
1532
|
+
from { transform: translateY(8px); opacity: 0; }
|
|
1533
|
+
to { transform: translateY(0); opacity: 1; }
|
|
1534
|
+
}
|
|
1535
|
+
@keyframes slideDown {
|
|
1536
|
+
from { transform: translateY(-8px); opacity: 0; }
|
|
1537
|
+
to { transform: translateY(0); opacity: 1; }
|
|
1538
|
+
}
|
|
1539
|
+
@keyframes scaleIn {
|
|
1540
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
1541
|
+
to { transform: scale(1); opacity: 1; }
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
@source ${contentPaths.join("\n@source ")}
|
|
1545
|
+
`;
|
|
1546
|
+
}
|
|
1547
|
+
function generateTailwindConfig(safelistPath = ".tailwind-styled-safelist.json", contentPaths = STANDARD_CONTENT_PATHS) {
|
|
1548
|
+
return `import type { Config } from "tailwindcss"
|
|
1549
|
+
import { defaultPreset } from "tailwind-styled-v4/preset"
|
|
1550
|
+
|
|
1551
|
+
// Auto-generated safelist dari tailwind-styled-v4 compiler
|
|
1552
|
+
const safelist = (() => {
|
|
1553
|
+
try { return require(${JSON.stringify(safelistPath)}) as string[] }
|
|
1554
|
+
catch { return [] }
|
|
1555
|
+
})()
|
|
1556
|
+
|
|
1557
|
+
export default {
|
|
1558
|
+
presets: [defaultPreset],
|
|
1559
|
+
content: ${JSON.stringify(contentPaths, null, 2)},
|
|
1560
|
+
safelist,
|
|
1561
|
+
} satisfies Config
|
|
1562
|
+
`;
|
|
1563
|
+
}
|
|
1564
|
+
var STANDARD_CONTENT_PATHS, designTokens, defaultPreset, defaultThemeCss, defaultGlobalCss;
|
|
1565
|
+
var init_defaultPreset = __esm({
|
|
1566
|
+
"packages/preset/src/defaultPreset.ts"() {
|
|
1567
|
+
STANDARD_CONTENT_PATHS = [
|
|
1568
|
+
// Next.js App Router
|
|
1569
|
+
"./src/**/*.{tsx,ts,jsx,js,mdx}",
|
|
1570
|
+
"./app/**/*.{tsx,ts,jsx,js,mdx}",
|
|
1571
|
+
"./pages/**/*.{tsx,ts,jsx,js,mdx}",
|
|
1572
|
+
"./components/**/*.{tsx,ts,jsx,js,mdx}",
|
|
1573
|
+
// Vite / React
|
|
1574
|
+
"./src/**/*.{tsx,ts,jsx,js}",
|
|
1575
|
+
"./index.html",
|
|
1576
|
+
// Monorepo
|
|
1577
|
+
"../../packages/**/src/**/*.{tsx,ts,jsx,js}"
|
|
1578
|
+
];
|
|
1579
|
+
designTokens = {
|
|
1580
|
+
colors: {
|
|
1581
|
+
primary: { DEFAULT: "#3b82f6", hover: "#2563eb", active: "#1d4ed8", foreground: "#ffffff" },
|
|
1582
|
+
secondary: { DEFAULT: "#6366f1", hover: "#4f46e5", active: "#4338ca", foreground: "#ffffff" },
|
|
1583
|
+
accent: { DEFAULT: "#f59e0b", hover: "#d97706", active: "#b45309", foreground: "#000000" },
|
|
1584
|
+
success: { DEFAULT: "#10b981", foreground: "#ffffff" },
|
|
1585
|
+
warning: { DEFAULT: "#f59e0b", foreground: "#000000" },
|
|
1586
|
+
danger: { DEFAULT: "#ef4444", foreground: "#ffffff" },
|
|
1587
|
+
info: { DEFAULT: "#3b82f6", foreground: "#ffffff" },
|
|
1588
|
+
surface: "#18181b",
|
|
1589
|
+
border: "#27272a",
|
|
1590
|
+
muted: "#71717a",
|
|
1591
|
+
subtle: "#3f3f46"
|
|
1592
|
+
},
|
|
1593
|
+
spacing: {
|
|
1594
|
+
1: "0.25rem",
|
|
1595
|
+
2: "0.5rem",
|
|
1596
|
+
3: "0.75rem",
|
|
1597
|
+
4: "1rem",
|
|
1598
|
+
5: "1.25rem",
|
|
1599
|
+
6: "1.5rem",
|
|
1600
|
+
8: "2rem",
|
|
1601
|
+
10: "2.5rem",
|
|
1602
|
+
12: "3rem",
|
|
1603
|
+
16: "4rem"
|
|
1604
|
+
},
|
|
1605
|
+
breakpoints: {
|
|
1606
|
+
sm: "40rem",
|
|
1607
|
+
md: "48rem",
|
|
1608
|
+
lg: "64rem",
|
|
1609
|
+
xl: "80rem",
|
|
1610
|
+
"2xl": "96rem"
|
|
1611
|
+
},
|
|
1612
|
+
fontWeight: {
|
|
1613
|
+
normal: "400",
|
|
1614
|
+
medium: "500",
|
|
1615
|
+
semibold: "600",
|
|
1616
|
+
bold: "700"
|
|
1617
|
+
},
|
|
1618
|
+
fontFamily: {
|
|
1619
|
+
sans: ["InterVariable", "Inter", "system-ui", "sans-serif"],
|
|
1620
|
+
mono: ["JetBrains Mono", "Fira Code", "Consolas", "monospace"]
|
|
1621
|
+
},
|
|
1622
|
+
borderRadius: {
|
|
1623
|
+
sm: "0.25rem",
|
|
1624
|
+
DEFAULT: "0.5rem",
|
|
1625
|
+
md: "0.5rem",
|
|
1626
|
+
lg: "0.75rem",
|
|
1627
|
+
xl: "1rem",
|
|
1628
|
+
"2xl": "1.5rem",
|
|
1629
|
+
full: "9999px"
|
|
1630
|
+
},
|
|
1631
|
+
animation: {
|
|
1632
|
+
"fade-in": "fadeIn 0.2s ease-out",
|
|
1633
|
+
"fade-out": "fadeOut 0.2s ease-in",
|
|
1634
|
+
"slide-up": "slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1)",
|
|
1635
|
+
"slide-down": "slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1)",
|
|
1636
|
+
"scale-in": "scaleIn 0.2s ease-out"
|
|
1637
|
+
},
|
|
1638
|
+
keyframes: {
|
|
1639
|
+
fadeIn: { from: { opacity: "0" }, to: { opacity: "1" } },
|
|
1640
|
+
fadeOut: { from: { opacity: "1" }, to: { opacity: "0" } },
|
|
1641
|
+
slideUp: {
|
|
1642
|
+
from: { transform: "translateY(8px)", opacity: "0" },
|
|
1643
|
+
to: { transform: "translateY(0)", opacity: "1" }
|
|
1644
|
+
},
|
|
1645
|
+
slideDown: {
|
|
1646
|
+
from: { transform: "translateY(-8px)", opacity: "0" },
|
|
1647
|
+
to: { transform: "translateY(0)", opacity: "1" }
|
|
1648
|
+
},
|
|
1649
|
+
scaleIn: {
|
|
1650
|
+
from: { transform: "scale(0.95)", opacity: "0" },
|
|
1651
|
+
to: { transform: "scale(1)", opacity: "1" }
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
};
|
|
1655
|
+
defaultPreset = {
|
|
1656
|
+
content: STANDARD_CONTENT_PATHS,
|
|
1657
|
+
darkMode: "class",
|
|
1658
|
+
theme: {
|
|
1659
|
+
extend: {
|
|
1660
|
+
colors: designTokens.colors,
|
|
1661
|
+
fontFamily: designTokens.fontFamily,
|
|
1662
|
+
borderRadius: designTokens.borderRadius,
|
|
1663
|
+
animation: designTokens.animation,
|
|
1664
|
+
keyframes: designTokens.keyframes
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
plugins: []
|
|
1668
|
+
};
|
|
1669
|
+
defaultThemeCss = `@import "tailwindcss";
|
|
1670
|
+
|
|
1671
|
+
@theme {
|
|
1672
|
+
/* colors */
|
|
1673
|
+
--color-primary: #3b82f6;
|
|
1674
|
+
--color-primary-hover: #2563eb;
|
|
1675
|
+
--color-primary-active: #1d4ed8;
|
|
1676
|
+
--color-primary-foreground: #ffffff;
|
|
1677
|
+
--color-secondary: #6366f1;
|
|
1678
|
+
--color-secondary-hover: #4f46e5;
|
|
1679
|
+
--color-secondary-active: #4338ca;
|
|
1680
|
+
--color-secondary-foreground: #ffffff;
|
|
1681
|
+
--color-accent: #f59e0b;
|
|
1682
|
+
--color-accent-hover: #d97706;
|
|
1683
|
+
--color-accent-active: #b45309;
|
|
1684
|
+
--color-accent-foreground: #000000;
|
|
1685
|
+
--color-success: #10b981;
|
|
1686
|
+
--color-success-foreground: #ffffff;
|
|
1687
|
+
--color-warning: #f59e0b;
|
|
1688
|
+
--color-warning-foreground: #000000;
|
|
1689
|
+
--color-danger: #ef4444;
|
|
1690
|
+
--color-danger-foreground: #ffffff;
|
|
1691
|
+
--color-info: #3b82f6;
|
|
1692
|
+
--color-info-foreground: #ffffff;
|
|
1693
|
+
--color-surface: #18181b;
|
|
1694
|
+
--color-border: #27272a;
|
|
1695
|
+
--color-muted: #71717a;
|
|
1696
|
+
--color-subtle: #3f3f46;
|
|
1697
|
+
|
|
1698
|
+
/* fonts */
|
|
1699
|
+
--font-sans: InterVariable, Inter, system-ui, sans-serif;
|
|
1700
|
+
--font-mono: JetBrains Mono, Fira Code, Consolas, monospace;
|
|
1701
|
+
|
|
1702
|
+
/* spacing */
|
|
1703
|
+
--spacing-1: 0.25rem;
|
|
1704
|
+
--spacing-2: 0.5rem;
|
|
1705
|
+
--spacing-3: 0.75rem;
|
|
1706
|
+
--spacing-4: 1rem;
|
|
1707
|
+
--spacing-5: 1.25rem;
|
|
1708
|
+
--spacing-6: 1.5rem;
|
|
1709
|
+
--spacing-8: 2rem;
|
|
1710
|
+
--spacing-10: 2.5rem;
|
|
1711
|
+
--spacing-12: 3rem;
|
|
1712
|
+
--spacing-16: 4rem;
|
|
1713
|
+
|
|
1714
|
+
/* breakpoints */
|
|
1715
|
+
--breakpoint-sm: 40rem;
|
|
1716
|
+
--breakpoint-md: 48rem;
|
|
1717
|
+
--breakpoint-lg: 64rem;
|
|
1718
|
+
--breakpoint-xl: 80rem;
|
|
1719
|
+
--breakpoint-2xl: 96rem;
|
|
1720
|
+
|
|
1721
|
+
/* border radius */
|
|
1722
|
+
--radius-sm: 0.25rem;
|
|
1723
|
+
--radius-md: 0.5rem;
|
|
1724
|
+
--radius-lg: 0.75rem;
|
|
1725
|
+
--radius-xl: 1rem;
|
|
1726
|
+
--radius-2xl: 1.5rem;
|
|
1727
|
+
--radius-full: 9999px;
|
|
1728
|
+
|
|
1729
|
+
/* animations */
|
|
1730
|
+
--animate-fade-in: fadeIn 0.2s ease-out;
|
|
1731
|
+
--animate-fade-out: fadeOut 0.2s ease-in;
|
|
1732
|
+
--animate-slide-up: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1733
|
+
--animate-slide-down: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1734
|
+
--animate-scale-in: scaleIn 0.2s ease-out;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
@keyframes fadeIn {
|
|
1738
|
+
from { opacity: 0; }
|
|
1739
|
+
to { opacity: 1; }
|
|
1740
|
+
}
|
|
1741
|
+
@keyframes fadeOut {
|
|
1742
|
+
from { opacity: 1; }
|
|
1743
|
+
to { opacity: 0; }
|
|
1744
|
+
}
|
|
1745
|
+
@keyframes slideUp {
|
|
1746
|
+
from { transform: translateY(8px); opacity: 0; }
|
|
1747
|
+
to { transform: translateY(0); opacity: 1; }
|
|
1748
|
+
}
|
|
1749
|
+
@keyframes slideDown {
|
|
1750
|
+
from { transform: translateY(-8px); opacity: 0; }
|
|
1751
|
+
to { transform: translateY(0); opacity: 1; }
|
|
1752
|
+
}
|
|
1753
|
+
@keyframes scaleIn {
|
|
1754
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
1755
|
+
to { transform: scale(1); opacity: 1; }
|
|
1756
|
+
}`;
|
|
1757
|
+
defaultGlobalCss = `@import "tailwindcss";
|
|
1758
|
+
|
|
1759
|
+
@theme {
|
|
1760
|
+
/* colors */
|
|
1761
|
+
--color-primary: #3b82f6;
|
|
1762
|
+
--color-primary-hover: #2563eb;
|
|
1763
|
+
--color-primary-active: #1d4ed8;
|
|
1764
|
+
--color-primary-foreground: #ffffff;
|
|
1765
|
+
--color-secondary: #6366f1;
|
|
1766
|
+
--color-secondary-hover: #4f46e5;
|
|
1767
|
+
--color-secondary-active: #4338ca;
|
|
1768
|
+
--color-secondary-foreground: #ffffff;
|
|
1769
|
+
--color-accent: #f59e0b;
|
|
1770
|
+
--color-accent-hover: #d97706;
|
|
1771
|
+
--color-accent-active: #b45309;
|
|
1772
|
+
--color-accent-foreground: #000000;
|
|
1773
|
+
--color-success: #10b981;
|
|
1774
|
+
--color-success-foreground: #ffffff;
|
|
1775
|
+
--color-warning: #f59e0b;
|
|
1776
|
+
--color-warning-foreground: #000000;
|
|
1777
|
+
--color-danger: #ef4444;
|
|
1778
|
+
--color-danger-foreground: #ffffff;
|
|
1779
|
+
--color-info: #3b82f6;
|
|
1780
|
+
--color-info-foreground: #ffffff;
|
|
1781
|
+
--color-surface: #18181b;
|
|
1782
|
+
--color-border: #27272a;
|
|
1783
|
+
--color-muted: #71717a;
|
|
1784
|
+
--color-subtle: #3f3f46;
|
|
1785
|
+
|
|
1786
|
+
/* fonts */
|
|
1787
|
+
--font-sans: InterVariable, Inter, system-ui, sans-serif;
|
|
1788
|
+
--font-mono: JetBrains Mono, Fira Code, Consolas, monospace;
|
|
1789
|
+
|
|
1790
|
+
/* spacing */
|
|
1791
|
+
--spacing-1: 0.25rem;
|
|
1792
|
+
--spacing-2: 0.5rem;
|
|
1793
|
+
--spacing-3: 0.75rem;
|
|
1794
|
+
--spacing-4: 1rem;
|
|
1795
|
+
--spacing-5: 1.25rem;
|
|
1796
|
+
--spacing-6: 1.5rem;
|
|
1797
|
+
--spacing-8: 2rem;
|
|
1798
|
+
--spacing-10: 2.5rem;
|
|
1799
|
+
--spacing-12: 3rem;
|
|
1800
|
+
--spacing-16: 4rem;
|
|
1801
|
+
|
|
1802
|
+
/* breakpoints */
|
|
1803
|
+
--breakpoint-sm: 40rem;
|
|
1804
|
+
--breakpoint-md: 48rem;
|
|
1805
|
+
--breakpoint-lg: 64rem;
|
|
1806
|
+
--breakpoint-xl: 80rem;
|
|
1807
|
+
--breakpoint-2xl: 96rem;
|
|
1808
|
+
|
|
1809
|
+
/* border radius */
|
|
1810
|
+
--radius-sm: 0.25rem;
|
|
1811
|
+
--radius-md: 0.5rem;
|
|
1812
|
+
--radius-lg: 0.75rem;
|
|
1813
|
+
--radius-xl: 1rem;
|
|
1814
|
+
--radius-2xl: 1.5rem;
|
|
1815
|
+
--radius-full: 9999px;
|
|
1816
|
+
|
|
1817
|
+
/* animations */
|
|
1818
|
+
--animate-fade-in: fadeIn 0.2s ease-out;
|
|
1819
|
+
--animate-fade-out: fadeOut 0.2s ease-in;
|
|
1820
|
+
--animate-slide-up: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1821
|
+
--animate-slide-down: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1822
|
+
--animate-scale-in: scaleIn 0.2s ease-out;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
@keyframes fadeIn {
|
|
1826
|
+
from { opacity: 0; }
|
|
1827
|
+
to { opacity: 1; }
|
|
1828
|
+
}
|
|
1829
|
+
@keyframes fadeOut {
|
|
1830
|
+
from { opacity: 1; }
|
|
1831
|
+
to { opacity: 0; }
|
|
1832
|
+
}
|
|
1833
|
+
@keyframes slideUp {
|
|
1834
|
+
from { transform: translateY(8px); opacity: 0; }
|
|
1835
|
+
to { transform: translateY(0); opacity: 1; }
|
|
1836
|
+
}
|
|
1837
|
+
@keyframes slideDown {
|
|
1838
|
+
from { transform: translateY(-8px); opacity: 0; }
|
|
1839
|
+
to { transform: translateY(0); opacity: 1; }
|
|
1840
|
+
}
|
|
1841
|
+
@keyframes scaleIn {
|
|
1842
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
1843
|
+
to { transform: scale(1); opacity: 1; }
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
/* tailwind-styled-v4 \u2014 zero-config base styles */
|
|
1847
|
+
*, *::before, *::after {
|
|
1848
|
+
box-sizing: border-box;
|
|
1849
|
+
}
|
|
1850
|
+
|
|
1851
|
+
html {
|
|
1852
|
+
-webkit-font-smoothing: antialiased;
|
|
1853
|
+
-moz-osx-font-smoothing: grayscale;
|
|
1854
|
+
text-rendering: optimizeLegibility;
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
body {
|
|
1858
|
+
margin: 0;
|
|
1859
|
+
font-family: var(--font-sans, system-ui, sans-serif);
|
|
1860
|
+
background: var(--color-surface, #18181b);
|
|
1861
|
+
color: var(--color-foreground, #fafafa);
|
|
1862
|
+
}
|
|
1863
|
+
`;
|
|
1864
|
+
}
|
|
1865
|
+
});
|
|
1866
|
+
|
|
1867
|
+
// packages/plugin/src/index.ts
|
|
1868
|
+
var globalRegistry = {
|
|
1869
|
+
transforms: [],
|
|
1870
|
+
tokens: {}
|
|
1871
|
+
};
|
|
1872
|
+
function getGlobalRegistry() {
|
|
1873
|
+
return globalRegistry;
|
|
1874
|
+
}
|
|
1875
|
+
function mergeClassesStatic(classes) {
|
|
1876
|
+
return tailwindMerge.twMerge(classes);
|
|
1877
|
+
}
|
|
1878
|
+
function normalizeClasses(raw) {
|
|
1879
|
+
return raw.split("\n").map((l) => l.trim()).filter(Boolean).join(" ").replace(/\s+/g, " ").trim();
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
// packages/compiler/src/componentHoister.ts
|
|
1883
|
+
var INDENTED_TW_DECL_RE = /^([ \t]+)(const|let)\s+([A-Z]\w*)\s*=\s*tw\.[\w]+[`(]/gm;
|
|
1884
|
+
function hoistComponents(source) {
|
|
1885
|
+
const hoisted = [];
|
|
1886
|
+
const warnings = [];
|
|
1887
|
+
const indentedDecls = [];
|
|
1888
|
+
let m;
|
|
1889
|
+
const re = new RegExp(INDENTED_TW_DECL_RE.source, "gm");
|
|
1890
|
+
while ((m = re.exec(source)) !== null) {
|
|
1891
|
+
const indent = m[1];
|
|
1892
|
+
const keyword = m[2];
|
|
1893
|
+
const name = m[3];
|
|
1894
|
+
if (!/^[A-Z]/.test(name)) continue;
|
|
1895
|
+
if (indent.length === 0) continue;
|
|
1896
|
+
indentedDecls.push({
|
|
1897
|
+
fullMatch: m[0],
|
|
1898
|
+
indent,
|
|
1899
|
+
keyword,
|
|
1900
|
+
name,
|
|
1901
|
+
startIndex: m.index
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
if (indentedDecls.length === 0) {
|
|
1905
|
+
return { code: source, hoisted: [], warnings: [] };
|
|
1906
|
+
}
|
|
1907
|
+
let code = source;
|
|
1908
|
+
const hoistedDecls = [];
|
|
1909
|
+
for (const decl of [...indentedDecls].reverse()) {
|
|
1910
|
+
const { startIndex, indent, name } = decl;
|
|
1911
|
+
const lineStart = code.lastIndexOf("\n", startIndex) + 1;
|
|
1912
|
+
const restFromDecl = code.slice(lineStart);
|
|
1913
|
+
const fullStmt = extractFullStatement(restFromDecl);
|
|
1914
|
+
if (!fullStmt) continue;
|
|
1915
|
+
const dedented = fullStmt.split("\n").map((line) => line.startsWith(indent) ? line.slice(indent.length) : line).join("\n").trim();
|
|
1916
|
+
code = code.slice(0, lineStart) + code.slice(lineStart + fullStmt.length);
|
|
1917
|
+
hoistedDecls.unshift(dedented);
|
|
1918
|
+
hoisted.push(name);
|
|
1919
|
+
warnings.push(
|
|
1920
|
+
`[tw-hoist] '${name}' moved to module scope for better performance. Avoid defining tw components inside render functions.`
|
|
1921
|
+
);
|
|
1922
|
+
}
|
|
1923
|
+
if (hoistedDecls.length > 0) {
|
|
1924
|
+
const insertPoint = findAfterImports(code);
|
|
1925
|
+
const hoistBlock = `
|
|
1926
|
+
${hoistedDecls.join("\n\n")}
|
|
1927
|
+
`;
|
|
1928
|
+
code = code.slice(0, insertPoint) + hoistBlock + code.slice(insertPoint);
|
|
1929
|
+
}
|
|
1930
|
+
return { code, hoisted, warnings };
|
|
1931
|
+
}
|
|
1932
|
+
function extractFullStatement(source) {
|
|
1933
|
+
const templateRe = /^[ \t]*(const|let)\s+\w+\s*=\s*tw\.\w+`[^`]*`.*\n?/;
|
|
1934
|
+
const templateMatch = source.match(templateRe);
|
|
1935
|
+
if (templateMatch) return templateMatch[0];
|
|
1936
|
+
const objStart = source.indexOf("tw.");
|
|
1937
|
+
if (objStart === -1) return null;
|
|
1938
|
+
const parenStart = source.indexOf("(", objStart);
|
|
1939
|
+
if (parenStart === -1) return null;
|
|
1940
|
+
let depth = 0;
|
|
1941
|
+
let i = parenStart;
|
|
1942
|
+
while (i < source.length) {
|
|
1943
|
+
if (source[i] === "(") depth++;
|
|
1944
|
+
if (source[i] === ")") {
|
|
1945
|
+
depth--;
|
|
1946
|
+
if (depth === 0) {
|
|
1947
|
+
const end = source.indexOf("\n", i);
|
|
1948
|
+
return source.slice(0, end === -1 ? i + 1 : end + 1);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
i++;
|
|
1952
|
+
}
|
|
1953
|
+
return null;
|
|
1954
|
+
}
|
|
1955
|
+
function findAfterImports(source) {
|
|
1956
|
+
const lines = source.split("\n");
|
|
1957
|
+
let lastImportLine = 0;
|
|
1958
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1959
|
+
const line = lines[i].trim();
|
|
1960
|
+
if (line.startsWith("import ") || line.startsWith("'use client'") || line.startsWith('"use client"')) {
|
|
1961
|
+
lastImportLine = i;
|
|
1962
|
+
} else if (line && !line.startsWith("//") && !line.startsWith("/*") && lastImportLine > 0) {
|
|
1963
|
+
break;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return lines.slice(0, lastImportLine + 1).join("\n").length + 1;
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// packages/compiler/src/rscAnalyzer.ts
|
|
1970
|
+
var CSS_INTERACTIVE_OK = [
|
|
1971
|
+
/^hover:/,
|
|
1972
|
+
// CSS :hover — no JS needed
|
|
1973
|
+
/^focus:/,
|
|
1974
|
+
// CSS :focus — no JS needed
|
|
1975
|
+
/^focus-within:/,
|
|
1976
|
+
// CSS :focus-within
|
|
1977
|
+
/^focus-visible:/,
|
|
1978
|
+
// CSS :focus-visible
|
|
1979
|
+
/^active:/,
|
|
1980
|
+
// CSS :active
|
|
1981
|
+
/^group-hover:/,
|
|
1982
|
+
// Tailwind group variant — CSS only
|
|
1983
|
+
/^group-focus:/,
|
|
1984
|
+
// CSS only
|
|
1985
|
+
/^peer-/,
|
|
1986
|
+
// Tailwind peer — CSS only
|
|
1987
|
+
/^first:/,
|
|
1988
|
+
// CSS :first-child
|
|
1989
|
+
/^last:/,
|
|
1990
|
+
// CSS :last-child
|
|
1991
|
+
/^odd:/,
|
|
1992
|
+
// CSS :nth-child(odd)
|
|
1993
|
+
/^even:/,
|
|
1994
|
+
// CSS :nth-child(even)
|
|
1995
|
+
/^disabled:/,
|
|
1996
|
+
// CSS :disabled
|
|
1997
|
+
/^placeholder:/,
|
|
1998
|
+
// CSS ::placeholder
|
|
1999
|
+
/^dark:/,
|
|
2000
|
+
// CSS @media prefers-color-scheme
|
|
2001
|
+
/^print:/,
|
|
2002
|
+
// CSS @media print
|
|
2003
|
+
/^md:|^sm:|^lg:|^xl:|^2xl:/
|
|
2004
|
+
// Responsive breakpoints — CSS only
|
|
2005
|
+
];
|
|
2006
|
+
var REQUIRES_JS_PATTERNS = [
|
|
2007
|
+
// React hooks
|
|
2008
|
+
/\buseState\b/,
|
|
2009
|
+
/\buseEffect\b/,
|
|
2010
|
+
/\buseRef\b/,
|
|
2011
|
+
/\buseCallback\b/,
|
|
2012
|
+
/\buseMemo\b/,
|
|
2013
|
+
/\buseReducer\b/,
|
|
2014
|
+
/\buseContext\b/,
|
|
2015
|
+
// Event handlers
|
|
2016
|
+
/\bon[A-Z][a-zA-Z]+\s*[=:]/,
|
|
2017
|
+
// onClick=, onMouseEnter:, etc.
|
|
2018
|
+
// Browser APIs
|
|
2019
|
+
/\bwindow\./,
|
|
2020
|
+
/\bdocument\./,
|
|
2021
|
+
/\blocalStorage\b/,
|
|
2022
|
+
/\bsessionStorage\b/,
|
|
2023
|
+
// Dynamic imports
|
|
2024
|
+
/import\s*\(/
|
|
2025
|
+
];
|
|
2026
|
+
function analyzeFile(source, _filename = "") {
|
|
2027
|
+
const clientReasons = [];
|
|
2028
|
+
const interactiveClasses = [];
|
|
2029
|
+
const hasClientDirective = source.trimStart().startsWith('"use client"') || source.trimStart().startsWith("'use client'");
|
|
2030
|
+
if (hasClientDirective) {
|
|
2031
|
+
clientReasons.push("explicit 'use client' directive");
|
|
2032
|
+
}
|
|
2033
|
+
for (const pattern of REQUIRES_JS_PATTERNS) {
|
|
2034
|
+
if (pattern.test(source)) {
|
|
2035
|
+
const match = source.match(pattern);
|
|
2036
|
+
if (match) clientReasons.push(`uses ${match[0].trim()}`);
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
const hasServerMarker = source.includes("tw.server.");
|
|
2040
|
+
const templateRe = /\btw\.(?:server\.)?(\w+)`((?:[^`\\]|\\.)*)`/g;
|
|
2041
|
+
let m;
|
|
2042
|
+
while ((m = templateRe.exec(source)) !== null) {
|
|
2043
|
+
const classes = m[2];
|
|
2044
|
+
const parts = classes.split(/\s+/).filter(Boolean);
|
|
2045
|
+
for (const cls of parts) {
|
|
2046
|
+
const isOk = CSS_INTERACTIVE_OK.some((re) => re.test(cls));
|
|
2047
|
+
if (!isOk && /^[a-z-]+:/.test(cls)) {
|
|
2048
|
+
interactiveClasses.push(cls);
|
|
2049
|
+
clientReasons.push(`uses JS-interactive class: ${cls}`);
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
const needsClientDirective = !hasServerMarker && (hasClientDirective || clientReasons.length > 0);
|
|
2054
|
+
const isServer = !needsClientDirective || hasServerMarker;
|
|
2055
|
+
return {
|
|
2056
|
+
isServer,
|
|
2057
|
+
needsClientDirective,
|
|
2058
|
+
clientReasons: [...new Set(clientReasons)],
|
|
2059
|
+
interactiveClasses: [...new Set(interactiveClasses)],
|
|
2060
|
+
canStaticResolveVariants: isServer
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
function analyzeVariantUsage(source, componentName, variantKeys) {
|
|
2064
|
+
const resolved = {};
|
|
2065
|
+
const dynamic = [];
|
|
2066
|
+
for (const key of variantKeys) {
|
|
2067
|
+
const staticRe = new RegExp(`<${componentName}[^>]*\\b${key}=["']([^"']+)["'][^>]*>`, "g");
|
|
2068
|
+
const dynamicRe = new RegExp(`<${componentName}[^>]*\\b${key}=\\{[^"'][^}]*\\}[^>]*>`, "g");
|
|
2069
|
+
const staticMatch = source.match(staticRe);
|
|
2070
|
+
const dynamicMatch = source.match(dynamicRe);
|
|
2071
|
+
if (dynamicMatch) {
|
|
2072
|
+
dynamic.push(key);
|
|
2073
|
+
} else if (staticMatch) {
|
|
2074
|
+
const valMatch = staticMatch[0].match(new RegExp(`${key}=["']([^"']+)["']`));
|
|
2075
|
+
if (valMatch) resolved[key] = valMatch[1];
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return { resolved, dynamic };
|
|
2079
|
+
}
|
|
2080
|
+
function resolveServerVariant(base, table, defaults, resolved) {
|
|
2081
|
+
const parts = [base];
|
|
2082
|
+
for (const key in table) {
|
|
2083
|
+
const val = resolved[key] ?? defaults[key];
|
|
2084
|
+
if (val && table[key][val]) {
|
|
2085
|
+
parts.push(table[key][val]);
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2089
|
+
for (const part of parts) {
|
|
2090
|
+
for (const cls of part.split(/\s+/).filter(Boolean)) {
|
|
2091
|
+
const prefix = cls.replace(/^(?:[\w-]+:)*/, "").split("-")[0];
|
|
2092
|
+
seen.set(prefix, cls);
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
return Array.from(seen.values()).join(" ");
|
|
2096
|
+
}
|
|
2097
|
+
function injectClientDirective(code) {
|
|
2098
|
+
if (code.startsWith('"use client"') || code.startsWith("'use client'")) {
|
|
2099
|
+
return code;
|
|
2100
|
+
}
|
|
2101
|
+
return `"use client";
|
|
2102
|
+
${code}`;
|
|
2103
|
+
}
|
|
2104
|
+
function injectServerOnlyComment(code) {
|
|
2105
|
+
return `/* @tw-server-only */
|
|
2106
|
+
${code}`;
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
// packages/compiler/src/twDetector.ts
|
|
2110
|
+
init_nativeBridge();
|
|
2111
|
+
var IMPORT_RE = /from\s*["']tailwind-styled-v4["']/;
|
|
2112
|
+
var TRANSFORM_MARKER = "/* @tw-transformed */";
|
|
2113
|
+
function hasTwUsage(source) {
|
|
2114
|
+
const native = getNativeBridge();
|
|
2115
|
+
if (native?.hasTwUsageNative) {
|
|
2116
|
+
const result = native.hasTwUsageNative(source);
|
|
2117
|
+
if (result !== null && result !== void 0) return result;
|
|
2118
|
+
}
|
|
2119
|
+
return IMPORT_RE.test(source) || source.includes("tw.");
|
|
2120
|
+
}
|
|
2121
|
+
function isAlreadyTransformed(source) {
|
|
2122
|
+
const native = getNativeBridge();
|
|
2123
|
+
if (native?.isAlreadyTransformedNative) {
|
|
2124
|
+
const result = native.isAlreadyTransformedNative(source);
|
|
2125
|
+
if (result !== null && result !== void 0) return result;
|
|
2126
|
+
}
|
|
2127
|
+
return source.includes(TRANSFORM_MARKER);
|
|
2128
|
+
}
|
|
2129
|
+
function isDynamic(content) {
|
|
2130
|
+
return content.includes("${");
|
|
2131
|
+
}
|
|
2132
|
+
function isServerComponent(source) {
|
|
2133
|
+
return !source.includes('"use client"') && !source.includes("'use client'");
|
|
2134
|
+
}
|
|
2135
|
+
function hasInteractiveFeatures(content) {
|
|
2136
|
+
return /\b(hover:|focus:|active:|group-hover:|peer-|on[A-Z]|useState|useEffect|useRef)\b/.test(
|
|
2137
|
+
content
|
|
2138
|
+
);
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
// packages/compiler/src/astParser.ts
|
|
2142
|
+
function oxcKey(node) {
|
|
2143
|
+
if (!node) return null;
|
|
2144
|
+
if (node.type === "Identifier") return node.name;
|
|
2145
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
2146
|
+
return null;
|
|
2147
|
+
}
|
|
2148
|
+
function oxcStringVal(node) {
|
|
2149
|
+
if (!node) return null;
|
|
2150
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
2151
|
+
if (node.type === "TemplateLiteral" && node.expressions?.length === 0) {
|
|
2152
|
+
return node.quasis.map((q) => q.value?.cooked ?? q.value?.raw ?? "").join("");
|
|
2153
|
+
}
|
|
2154
|
+
return null;
|
|
2155
|
+
}
|
|
2156
|
+
function oxcWalkObject(node) {
|
|
2157
|
+
const result = {};
|
|
2158
|
+
if (node?.type !== "ObjectExpression") return result;
|
|
2159
|
+
for (const prop of node.properties ?? []) {
|
|
2160
|
+
if (prop.type !== "Property") continue;
|
|
2161
|
+
const key = oxcKey(prop.key);
|
|
2162
|
+
if (!key) continue;
|
|
2163
|
+
const val = prop.value;
|
|
2164
|
+
const strVal = oxcStringVal(val);
|
|
2165
|
+
if (strVal !== null) {
|
|
2166
|
+
result[key] = strVal;
|
|
2167
|
+
} else if (val?.type === "ObjectExpression") {
|
|
2168
|
+
result[key] = oxcWalkObject(val);
|
|
2169
|
+
} else if (val?.type === "ArrayExpression") {
|
|
2170
|
+
result[key] = val.elements.filter((el) => el?.type === "ObjectExpression").map((el) => oxcWalkObject(el));
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
return result;
|
|
2174
|
+
}
|
|
2175
|
+
function parseWithOxc(objectStr) {
|
|
2176
|
+
let parseSync3;
|
|
2177
|
+
try {
|
|
2178
|
+
parseSync3 = (init_src_js(), __toCommonJS(src_js_exports)).parseSync;
|
|
2179
|
+
} catch {
|
|
2180
|
+
return null;
|
|
2181
|
+
}
|
|
2182
|
+
try {
|
|
2183
|
+
const source = `const __c = ${objectStr}`;
|
|
2184
|
+
const { program, errors } = parseSync3("config.ts", source, { sourceType: "script" });
|
|
2185
|
+
if (errors?.length > 0 || !program?.body?.[0]) return null;
|
|
2186
|
+
const varDecl = program.body[0];
|
|
2187
|
+
if (varDecl.type !== "VariableDeclaration") return null;
|
|
2188
|
+
const init = varDecl.declarations?.[0]?.init;
|
|
2189
|
+
if (init?.type !== "ObjectExpression") return null;
|
|
2190
|
+
const raw = oxcWalkObject(init);
|
|
2191
|
+
const base = typeof raw.base === "string" ? raw.base.trim() : "";
|
|
2192
|
+
const variants = {};
|
|
2193
|
+
const rawVariants = raw.variants;
|
|
2194
|
+
if (rawVariants && typeof rawVariants === "object" && !Array.isArray(rawVariants)) {
|
|
2195
|
+
for (const [vName, vMap] of Object.entries(rawVariants)) {
|
|
2196
|
+
if (vMap && typeof vMap === "object" && !Array.isArray(vMap)) {
|
|
2197
|
+
variants[vName] = {};
|
|
2198
|
+
for (const [vVal, cls] of Object.entries(vMap)) {
|
|
2199
|
+
if (typeof cls === "string") variants[vName][vVal] = cls.trim();
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
const compounds = [];
|
|
2205
|
+
const rawCompounds = raw.compoundVariants;
|
|
2206
|
+
if (Array.isArray(rawCompounds)) {
|
|
2207
|
+
for (const item of rawCompounds) {
|
|
2208
|
+
if (item && typeof item.class === "string") {
|
|
2209
|
+
compounds.push(item);
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
const defaults = {};
|
|
2214
|
+
const rawDefaults = raw.defaultVariants;
|
|
2215
|
+
if (rawDefaults && typeof rawDefaults === "object" && !Array.isArray(rawDefaults)) {
|
|
2216
|
+
for (const [k, v] of Object.entries(rawDefaults)) {
|
|
2217
|
+
if (typeof v === "string") defaults[k] = v;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
return { base, variants, compounds, defaults };
|
|
2221
|
+
} catch {
|
|
2222
|
+
return null;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
function tokenize(src) {
|
|
2226
|
+
const tokens = [];
|
|
2227
|
+
let i = 0;
|
|
2228
|
+
while (i < src.length) {
|
|
2229
|
+
const ch = src[i];
|
|
2230
|
+
if (/\s/.test(ch)) {
|
|
2231
|
+
i++;
|
|
2232
|
+
continue;
|
|
2233
|
+
}
|
|
2234
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
2235
|
+
const quote = ch;
|
|
2236
|
+
let j = i + 1;
|
|
2237
|
+
let str = ch;
|
|
2238
|
+
while (j < src.length) {
|
|
2239
|
+
if (src[j] === "\\" && quote !== "`") {
|
|
2240
|
+
str += src[j] + src[j + 1];
|
|
2241
|
+
j += 2;
|
|
2242
|
+
continue;
|
|
2243
|
+
}
|
|
2244
|
+
if (src[j] === "\\" && quote === "`") {
|
|
2245
|
+
str += src[j] + src[j + 1];
|
|
2246
|
+
j += 2;
|
|
2247
|
+
continue;
|
|
2248
|
+
}
|
|
2249
|
+
str += src[j];
|
|
2250
|
+
if (src[j] === quote) {
|
|
2251
|
+
j++;
|
|
2252
|
+
break;
|
|
2253
|
+
}
|
|
2254
|
+
j++;
|
|
2255
|
+
}
|
|
2256
|
+
tokens.push({ type: "string", value: str.slice(1, -1), pos: i });
|
|
2257
|
+
i = j;
|
|
2258
|
+
continue;
|
|
2259
|
+
}
|
|
2260
|
+
if (ch === ":") {
|
|
2261
|
+
tokens.push({ type: "colon", value: ":", pos: i });
|
|
2262
|
+
i++;
|
|
2263
|
+
continue;
|
|
2264
|
+
}
|
|
2265
|
+
if (ch === ",") {
|
|
2266
|
+
tokens.push({ type: "comma", value: ",", pos: i });
|
|
2267
|
+
i++;
|
|
2268
|
+
continue;
|
|
2269
|
+
}
|
|
2270
|
+
if (ch === "{") {
|
|
2271
|
+
tokens.push({ type: "lbrace", value: "{", pos: i });
|
|
2272
|
+
i++;
|
|
2273
|
+
continue;
|
|
2274
|
+
}
|
|
2275
|
+
if (ch === "}") {
|
|
2276
|
+
tokens.push({ type: "rbrace", value: "}", pos: i });
|
|
2277
|
+
i++;
|
|
2278
|
+
continue;
|
|
2279
|
+
}
|
|
2280
|
+
if (ch === "[") {
|
|
2281
|
+
tokens.push({ type: "lbracket", value: "[", pos: i });
|
|
2282
|
+
i++;
|
|
2283
|
+
continue;
|
|
2284
|
+
}
|
|
2285
|
+
if (ch === "]") {
|
|
2286
|
+
tokens.push({ type: "rbracket", value: "]", pos: i });
|
|
2287
|
+
i++;
|
|
2288
|
+
continue;
|
|
2289
|
+
}
|
|
2290
|
+
if (/[\w$]/.test(ch)) {
|
|
2291
|
+
let j = i;
|
|
2292
|
+
while (j < src.length && /[\w$]/.test(src[j])) j++;
|
|
2293
|
+
tokens.push({ type: "key", value: src.slice(i, j), pos: i });
|
|
2294
|
+
i = j;
|
|
2295
|
+
continue;
|
|
2296
|
+
}
|
|
2297
|
+
tokens.push({ type: "other", value: ch, pos: i });
|
|
2298
|
+
i++;
|
|
2299
|
+
}
|
|
2300
|
+
return tokens;
|
|
2301
|
+
}
|
|
2302
|
+
function parseObject(tokens, startIdx) {
|
|
2303
|
+
const obj = {};
|
|
2304
|
+
let i = startIdx;
|
|
2305
|
+
if (tokens[i]?.type !== "lbrace") return { obj, endIdx: i };
|
|
2306
|
+
i++;
|
|
2307
|
+
while (i < tokens.length && tokens[i]?.type !== "rbrace") {
|
|
2308
|
+
if (tokens[i]?.type === "comma") {
|
|
2309
|
+
i++;
|
|
2310
|
+
continue;
|
|
2311
|
+
}
|
|
2312
|
+
let key = null;
|
|
2313
|
+
if (tokens[i]?.type === "string") {
|
|
2314
|
+
key = tokens[i].value;
|
|
2315
|
+
i++;
|
|
2316
|
+
} else if (tokens[i]?.type === "key") {
|
|
2317
|
+
key = tokens[i].value;
|
|
2318
|
+
i++;
|
|
2319
|
+
} else {
|
|
2320
|
+
i++;
|
|
2321
|
+
continue;
|
|
2322
|
+
}
|
|
2323
|
+
if (tokens[i]?.type !== "colon") continue;
|
|
2324
|
+
i++;
|
|
2325
|
+
if (tokens[i]?.type === "lbrace") {
|
|
2326
|
+
const { obj: nested, endIdx } = parseObject(tokens, i);
|
|
2327
|
+
obj[key] = nested;
|
|
2328
|
+
i = endIdx + 1;
|
|
2329
|
+
} else if (tokens[i]?.type === "lbracket") {
|
|
2330
|
+
const { arr, endIdx } = parseArray(tokens, i);
|
|
2331
|
+
obj[key] = arr;
|
|
2332
|
+
i = endIdx + 1;
|
|
2333
|
+
} else if (tokens[i]?.type === "string") {
|
|
2334
|
+
obj[key] = tokens[i].value;
|
|
2335
|
+
i++;
|
|
2336
|
+
} else if (tokens[i]?.type === "key") {
|
|
2337
|
+
obj[key] = tokens[i].value;
|
|
2338
|
+
i++;
|
|
2339
|
+
} else {
|
|
2340
|
+
i++;
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
return { obj, endIdx: i };
|
|
2344
|
+
}
|
|
2345
|
+
function parseArray(tokens, startIdx) {
|
|
2346
|
+
const arr = [];
|
|
2347
|
+
let i = startIdx;
|
|
2348
|
+
if (tokens[i]?.type !== "lbracket") return { arr, endIdx: i };
|
|
2349
|
+
i++;
|
|
2350
|
+
while (i < tokens.length && tokens[i]?.type !== "rbracket") {
|
|
2351
|
+
if (tokens[i]?.type === "comma") {
|
|
2352
|
+
i++;
|
|
2353
|
+
continue;
|
|
2354
|
+
}
|
|
2355
|
+
if (tokens[i]?.type === "lbrace") {
|
|
2356
|
+
const { obj, endIdx } = parseObject(tokens, i);
|
|
2357
|
+
arr.push(obj);
|
|
2358
|
+
i = endIdx + 1;
|
|
2359
|
+
} else {
|
|
2360
|
+
i++;
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
return { arr, endIdx: i };
|
|
2364
|
+
}
|
|
2365
|
+
function parseComponentConfigFallback(objectStr) {
|
|
2366
|
+
const tokens = tokenize(objectStr);
|
|
2367
|
+
const { obj } = parseObject(tokens, 0);
|
|
2368
|
+
const base = typeof obj.base === "string" ? obj.base.trim() : "";
|
|
2369
|
+
const variants = {};
|
|
2370
|
+
const rawVariants = obj.variants;
|
|
2371
|
+
if (rawVariants && typeof rawVariants === "object" && !Array.isArray(rawVariants)) {
|
|
2372
|
+
for (const [variantName, variantValues] of Object.entries(rawVariants)) {
|
|
2373
|
+
if (typeof variantValues === "object" && !Array.isArray(variantValues)) {
|
|
2374
|
+
variants[variantName] = {};
|
|
2375
|
+
for (const [valueName, cls] of Object.entries(variantValues)) {
|
|
2376
|
+
if (typeof cls === "string") variants[variantName][valueName] = cls.trim();
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
const compounds = [];
|
|
2382
|
+
const rawCompounds = obj.compoundVariants;
|
|
2383
|
+
if (Array.isArray(rawCompounds)) {
|
|
2384
|
+
for (const item of rawCompounds) {
|
|
2385
|
+
if (item && typeof item.class === "string") compounds.push(item);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
const defaults = {};
|
|
2389
|
+
const rawDefaults = obj.defaultVariants;
|
|
2390
|
+
if (rawDefaults && typeof rawDefaults === "object" && !Array.isArray(rawDefaults)) {
|
|
2391
|
+
for (const [k, v] of Object.entries(rawDefaults)) {
|
|
2392
|
+
if (typeof v === "string") defaults[k] = v;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
return { base, variants, compounds, defaults };
|
|
2396
|
+
}
|
|
2397
|
+
function parseComponentConfig(objectStr) {
|
|
2398
|
+
const oxcResult = parseWithOxc(objectStr);
|
|
2399
|
+
if (oxcResult !== null) return oxcResult;
|
|
2400
|
+
return parseComponentConfigFallback(objectStr);
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
// packages/compiler/src/variantCompiler.ts
|
|
2404
|
+
function compileVariants(base, variants, compounds = [], defaults = {}) {
|
|
2405
|
+
const table = {};
|
|
2406
|
+
for (const key in variants) {
|
|
2407
|
+
table[key] = {};
|
|
2408
|
+
for (const val in variants[key]) {
|
|
2409
|
+
table[key][val] = normalizeClasses(variants[key][val]);
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
return { base, table, compounds, defaults };
|
|
2413
|
+
}
|
|
2414
|
+
function generateVariantCode(id, compiled) {
|
|
2415
|
+
const { table, compounds, defaults } = compiled;
|
|
2416
|
+
const tableJson = JSON.stringify(table, null, 2);
|
|
2417
|
+
const compoundsJson = JSON.stringify(compounds, null, 2);
|
|
2418
|
+
const defaultsJson = JSON.stringify(defaults, null, 2);
|
|
2419
|
+
return `const __vt_${id} = ${tableJson};
|
|
2420
|
+
const __vc_${id} = ${compoundsJson};
|
|
2421
|
+
const __vd_${id} = ${defaultsJson};`;
|
|
2422
|
+
}
|
|
2423
|
+
function parseObjectConfig(objectStr) {
|
|
2424
|
+
return parseComponentConfig(objectStr);
|
|
2425
|
+
}
|
|
2426
|
+
|
|
2427
|
+
// packages/compiler/src/astTransform.ts
|
|
2428
|
+
var TEMPLATE_RE2 = /\btw\.(server\.)?(\w+)`((?:[^`\\]|\\.)*)`/g;
|
|
2429
|
+
var OBJECT_RE2 = /\btw\.(server\.)?(\w+)\(\s*(\{[\s\S]*?\})\s*\)/g;
|
|
2430
|
+
var EXTEND_RE2 = /(\w+)\.extend`((?:[^`\\]|\\.)*)`/g;
|
|
2431
|
+
var WRAP_RE = /\btw\((\w+)\)`((?:[^`\\]|\\.)*)`/g;
|
|
2432
|
+
var _idCounter = 0;
|
|
2433
|
+
function genId() {
|
|
2434
|
+
return `c${(++_idCounter).toString(36)}`;
|
|
2435
|
+
}
|
|
2436
|
+
function renderStaticComponent(tag, classes, opts) {
|
|
2437
|
+
const { addDataAttr, compName } = opts;
|
|
2438
|
+
const fnName = compName ? `_Tw_${compName}` : `_Tw_${tag}`;
|
|
2439
|
+
const dataAttr = addDataAttr ? `, "data-tw": "${fnName}:${classes.split(" ").slice(0, 3).join(" ")}${classes.split(" ").length > 3 ? "..." : ""}"` : "";
|
|
2440
|
+
return `React.forwardRef(function ${fnName}(props, ref) {
|
|
2441
|
+
var _c = props.className;
|
|
2442
|
+
var _r = Object.assign({}, props);
|
|
2443
|
+
delete _r.className;
|
|
2444
|
+
return React.createElement("${tag}", Object.assign({ ref }, _r${dataAttr}, { className: [${JSON.stringify(classes)}, _c].filter(Boolean).join(" ") }));
|
|
2445
|
+
})`;
|
|
2446
|
+
}
|
|
2447
|
+
function renderVariantComponent(tag, id, base, variantKeys, defaults, opts) {
|
|
2448
|
+
const { addDataAttr } = opts;
|
|
2449
|
+
const fnName = `_TwV_${tag}_${id}`;
|
|
2450
|
+
const dataAttr = addDataAttr ? `, "data-tw": "${fnName}"` : "";
|
|
2451
|
+
const vKeys = variantKeys.map((k) => `"${k}"`).join(", ");
|
|
2452
|
+
const destructure = variantKeys.length > 0 ? `var _vp = {}; [${vKeys}].forEach(function(k){ _vp[k] = props[k]; delete _rest[k]; });` : "";
|
|
2453
|
+
const variantLookup = variantKeys.length > 0 ? variantKeys.map(
|
|
2454
|
+
(k) => `(__vt_${id}["${k}"] && __vt_${id}["${k}"][_vp["${k}"] ?? ${JSON.stringify(defaults[k] ?? "")}] || "")`
|
|
2455
|
+
).join(", ") : "";
|
|
2456
|
+
const classParts = variantKeys.length > 0 ? `[${JSON.stringify(base)}, ${variantLookup}, _rest.className]` : `[${JSON.stringify(base)}, _rest.className]`;
|
|
2457
|
+
return `React.forwardRef(function ${fnName}(props, ref) {
|
|
2458
|
+
var _rest = Object.assign({}, props);
|
|
2459
|
+
delete _rest.className;
|
|
2460
|
+
${destructure}
|
|
2461
|
+
return React.createElement("${tag}", Object.assign({ ref }, _rest${dataAttr}, { className: ${classParts}.filter(Boolean).join(" ") }));
|
|
2462
|
+
})`;
|
|
2463
|
+
}
|
|
2464
|
+
var SUB_BLOCK_RE = /\b([a-z][a-zA-Z0-9_]*)\s*\{([^}]*)\}/g;
|
|
2465
|
+
function shortHash(input) {
|
|
2466
|
+
let h = 5381;
|
|
2467
|
+
for (let i = 0; i < input.length; i++) {
|
|
2468
|
+
h = Math.imul(h, 33) + input.charCodeAt(i) >>> 0;
|
|
2469
|
+
}
|
|
2470
|
+
return (h & 16777215).toString(16).padStart(6, "0");
|
|
2471
|
+
}
|
|
2472
|
+
function parseSubcomponentBlocks(template, componentName) {
|
|
2473
|
+
const subComponents = [];
|
|
2474
|
+
let stripped = template;
|
|
2475
|
+
SUB_BLOCK_RE.lastIndex = 0;
|
|
2476
|
+
let match;
|
|
2477
|
+
while ((match = SUB_BLOCK_RE.exec(template)) !== null) {
|
|
2478
|
+
const [fullMatch, subName, subClassesRaw] = match;
|
|
2479
|
+
const subClasses = subClassesRaw.trim();
|
|
2480
|
+
if (!subClasses) continue;
|
|
2481
|
+
const subTag = (() => {
|
|
2482
|
+
switch (subName) {
|
|
2483
|
+
case "label":
|
|
2484
|
+
return "label";
|
|
2485
|
+
case "input":
|
|
2486
|
+
return "input";
|
|
2487
|
+
case "img":
|
|
2488
|
+
case "image":
|
|
2489
|
+
return "img";
|
|
2490
|
+
case "header":
|
|
2491
|
+
return "header";
|
|
2492
|
+
case "footer":
|
|
2493
|
+
return "footer";
|
|
2494
|
+
default:
|
|
2495
|
+
return "span";
|
|
2496
|
+
}
|
|
2497
|
+
})();
|
|
2498
|
+
const hash = shortHash(`${componentName}_${subName}_${subClasses}`);
|
|
2499
|
+
const scopedClass = `${componentName}_${subName}_${hash}`;
|
|
2500
|
+
subComponents.push({ name: subName, tag: subTag, classes: subClasses, scopedClass });
|
|
2501
|
+
stripped = stripped.replace(fullMatch, "");
|
|
2502
|
+
}
|
|
2503
|
+
return { baseContent: stripped.trim(), subComponents };
|
|
2504
|
+
}
|
|
2505
|
+
function renderCompoundComponent(tag, baseClasses, componentName, subComponents, opts) {
|
|
2506
|
+
const fnName = `_Tw_${componentName}`;
|
|
2507
|
+
const dataAttr = opts.addDataAttr ? `, "data-tw": "${fnName}"` : "";
|
|
2508
|
+
const baseBody = `React.forwardRef(function ${fnName}(props, ref) {
|
|
2509
|
+
var _c = props.className;
|
|
2510
|
+
var _r = Object.assign({}, props);
|
|
2511
|
+
delete _r.className;
|
|
2512
|
+
return React.createElement("${tag}", Object.assign({ ref }, _r${dataAttr}, { className: [${JSON.stringify(baseClasses)}, _c].filter(Boolean).join(" ") }));
|
|
2513
|
+
})`;
|
|
2514
|
+
if (subComponents.length === 0) return baseBody;
|
|
2515
|
+
const subAssignments = subComponents.map((sub) => {
|
|
2516
|
+
const subFn = `_Tw_${componentName}_${sub.name}`;
|
|
2517
|
+
return ` _base.${sub.name} = React.forwardRef(function ${subFn}(props, ref) {
|
|
2518
|
+
var _c = props.className;
|
|
2519
|
+
var _r = Object.assign({}, props);
|
|
2520
|
+
delete _r.className;
|
|
2521
|
+
return React.createElement("${sub.tag}", Object.assign({ ref }, _r, { className: [${JSON.stringify(sub.scopedClass)}, _c].filter(Boolean).join(" ") }));
|
|
2522
|
+
});`;
|
|
2523
|
+
}).join("\n");
|
|
2524
|
+
return `(function() {
|
|
2525
|
+
var _base = ${baseBody};
|
|
2526
|
+
${subAssignments}
|
|
2527
|
+
return _base;
|
|
2528
|
+
})()`;
|
|
2529
|
+
}
|
|
2530
|
+
function transformSource(source, opts = {}) {
|
|
2531
|
+
const {
|
|
2532
|
+
mode = "zero-runtime",
|
|
2533
|
+
// v5: always zero-runtime, parameter kept for backward compat
|
|
2534
|
+
autoClientBoundary = true,
|
|
2535
|
+
addDataAttr = false,
|
|
2536
|
+
hoist = true,
|
|
2537
|
+
filename = "",
|
|
2538
|
+
preserveImports = false
|
|
2539
|
+
} = opts;
|
|
2540
|
+
if (!hasTwUsage(source)) {
|
|
2541
|
+
return { code: source, classes: [], changed: false };
|
|
2542
|
+
}
|
|
2543
|
+
if (isAlreadyTransformed(source)) {
|
|
2544
|
+
return { code: source, classes: [], changed: false };
|
|
2545
|
+
}
|
|
2546
|
+
if (mode && mode !== "zero-runtime") {
|
|
2547
|
+
console.warn(
|
|
2548
|
+
"[tailwind-styled] Warning: mode option is deprecated in v5. Only zero-runtime is supported."
|
|
2549
|
+
);
|
|
2550
|
+
}
|
|
2551
|
+
const rscAnalysis = analyzeFile(source, filename);
|
|
2552
|
+
let code = source;
|
|
2553
|
+
if (hoist) {
|
|
2554
|
+
const hoistResult = hoistComponents(source);
|
|
2555
|
+
if (hoistResult.hoisted.length > 0) {
|
|
2556
|
+
code = hoistResult.code;
|
|
2557
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2558
|
+
for (const w of hoistResult.warnings) {
|
|
2559
|
+
console.warn(w);
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
let changed = false;
|
|
2565
|
+
const allClasses = [];
|
|
2566
|
+
const prelude = [];
|
|
2567
|
+
let needsReact = false;
|
|
2568
|
+
{
|
|
2569
|
+
const snap = code;
|
|
2570
|
+
const replacements = [];
|
|
2571
|
+
const ASSIGN_RE = /(?:const|let|var)\s+(\w+)\s*=\s*tw\.(?:server\.)?(\w+)`/g;
|
|
2572
|
+
const assignMap = /* @__PURE__ */ new Map();
|
|
2573
|
+
let am;
|
|
2574
|
+
while ((am = ASSIGN_RE.exec(snap)) !== null) {
|
|
2575
|
+
const twPos = am.index + am[0].indexOf("tw.");
|
|
2576
|
+
assignMap.set(twPos, am[1]);
|
|
2577
|
+
}
|
|
2578
|
+
TEMPLATE_RE2.lastIndex = 0;
|
|
2579
|
+
let m;
|
|
2580
|
+
while ((m = TEMPLATE_RE2.exec(snap)) !== null) {
|
|
2581
|
+
const [fullMatch, serverMark, tag, content] = m;
|
|
2582
|
+
if (isDynamic(content)) continue;
|
|
2583
|
+
const isServerOnly = !!serverMark;
|
|
2584
|
+
const compName = assignMap.get(m.index) ?? null;
|
|
2585
|
+
const { baseContent, subComponents } = compName ? parseSubcomponentBlocks(content, compName) : { baseContent: content, subComponents: [] };
|
|
2586
|
+
const classes = normalizeClasses(baseContent);
|
|
2587
|
+
if (!classes && subComponents.length === 0) continue;
|
|
2588
|
+
allClasses.push(...(classes ?? "").split(/\s+/).filter(Boolean));
|
|
2589
|
+
for (const sub of subComponents) {
|
|
2590
|
+
allClasses.push(...sub.classes.split(/\s+/).filter(Boolean));
|
|
2591
|
+
}
|
|
2592
|
+
changed = true;
|
|
2593
|
+
needsReact = true;
|
|
2594
|
+
let rendered;
|
|
2595
|
+
if (subComponents.length > 0 && compName) {
|
|
2596
|
+
rendered = renderCompoundComponent(tag, classes ?? "", compName, subComponents, {
|
|
2597
|
+
addDataAttr
|
|
2598
|
+
});
|
|
2599
|
+
} else {
|
|
2600
|
+
rendered = renderStaticComponent(tag, classes ?? "", {
|
|
2601
|
+
addDataAttr,
|
|
2602
|
+
isServer: rscAnalysis.isServer || isServerOnly,
|
|
2603
|
+
compName: compName ?? void 0
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
replacements.push({
|
|
2607
|
+
match: fullMatch,
|
|
2608
|
+
replacement: isServerOnly ? `/* @server-only */ ${rendered}` : rendered
|
|
2609
|
+
});
|
|
2610
|
+
}
|
|
2611
|
+
for (const { match, replacement } of replacements) {
|
|
2612
|
+
code = code.replace(match, replacement);
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
code = code.replace(
|
|
2616
|
+
OBJECT_RE2,
|
|
2617
|
+
(match, serverMark, tag, objectStr) => {
|
|
2618
|
+
const { base, variants, compounds, defaults } = parseObjectConfig(objectStr);
|
|
2619
|
+
let config = {
|
|
2620
|
+
base,
|
|
2621
|
+
variants,
|
|
2622
|
+
compoundVariants: compounds,
|
|
2623
|
+
defaultVariants: defaults
|
|
2624
|
+
};
|
|
2625
|
+
const registry = getGlobalRegistry();
|
|
2626
|
+
if (registry.transforms.length > 0) {
|
|
2627
|
+
const componentName = `Tw${tag}`;
|
|
2628
|
+
for (const transform of registry.transforms) {
|
|
2629
|
+
try {
|
|
2630
|
+
const transformed = transform(config, { componentName, tag });
|
|
2631
|
+
if (transformed && typeof transformed === "object") {
|
|
2632
|
+
config = {
|
|
2633
|
+
base: typeof transformed.base === "string" ? transformed.base : config.base,
|
|
2634
|
+
variants: isVariantRecord(transformed.variants) ? transformed.variants : config.variants,
|
|
2635
|
+
compoundVariants: isCompoundVariantsArray(transformed.compoundVariants) ? transformed.compoundVariants : config.compoundVariants,
|
|
2636
|
+
defaultVariants: isStringRecord(transformed.defaultVariants) ? transformed.defaultVariants : config.defaultVariants
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
} catch (error) {
|
|
2640
|
+
if (process.env.NODE_ENV !== "production") {
|
|
2641
|
+
console.warn("[tailwind-styled] plugin transform error:", error);
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
const nextBase = normalizeClasses(config.base) ?? "";
|
|
2647
|
+
const nextVariants = config.variants;
|
|
2648
|
+
const nextCompounds = config.compoundVariants;
|
|
2649
|
+
const nextDefaults = config.defaultVariants;
|
|
2650
|
+
if (!nextBase && Object.keys(nextVariants).length === 0) return match;
|
|
2651
|
+
const isServerOnly = !!serverMark;
|
|
2652
|
+
allClasses.push(...nextBase.split(/\s+/).filter(Boolean));
|
|
2653
|
+
for (const vMap of Object.values(nextVariants)) {
|
|
2654
|
+
for (const cls of Object.values(vMap)) {
|
|
2655
|
+
allClasses.push(...cls.split(/\s+/).filter(Boolean));
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
changed = true;
|
|
2659
|
+
needsReact = true;
|
|
2660
|
+
const id = genId();
|
|
2661
|
+
const compiled = compileVariants(nextBase, nextVariants, nextCompounds, nextDefaults);
|
|
2662
|
+
prelude.push(generateVariantCode(id, compiled));
|
|
2663
|
+
const variantKeys = Object.keys(nextVariants);
|
|
2664
|
+
const rendered = renderVariantComponent(tag, id, nextBase, variantKeys, nextDefaults, {
|
|
2665
|
+
addDataAttr,
|
|
2666
|
+
isServer: rscAnalysis.isServer || isServerOnly
|
|
2667
|
+
});
|
|
2668
|
+
return isServerOnly ? `/* @server-only */ ${rendered}` : rendered;
|
|
2669
|
+
}
|
|
2670
|
+
);
|
|
2671
|
+
code = code.replace(WRAP_RE, (match, compName, content) => {
|
|
2672
|
+
if (isDynamic(content)) return match;
|
|
2673
|
+
const classes = normalizeClasses(content);
|
|
2674
|
+
if (!classes) return match;
|
|
2675
|
+
allClasses.push(...classes.split(/\s+/).filter(Boolean));
|
|
2676
|
+
changed = true;
|
|
2677
|
+
needsReact = true;
|
|
2678
|
+
return `React.forwardRef(function _TwWrap_${compName}(props, ref) {
|
|
2679
|
+
var _c = [${JSON.stringify(classes)}, props.className].filter(Boolean).join(" ");
|
|
2680
|
+
return React.createElement(${compName}, Object.assign({}, props, { ref, className: _c }));
|
|
2681
|
+
})`;
|
|
2682
|
+
});
|
|
2683
|
+
code = code.replace(EXTEND_RE2, (match, compName, content) => {
|
|
2684
|
+
if (isDynamic(content)) return match;
|
|
2685
|
+
const extra = normalizeClasses(content);
|
|
2686
|
+
if (!extra) return match;
|
|
2687
|
+
allClasses.push(...extra.split(/\s+/).filter(Boolean));
|
|
2688
|
+
changed = true;
|
|
2689
|
+
needsReact = true;
|
|
2690
|
+
return `React.forwardRef(function _TwExt_${compName}(props, ref) {
|
|
2691
|
+
var _c = [${JSON.stringify(extra)}, props.className].filter(Boolean).join(" ");
|
|
2692
|
+
return React.createElement(${compName}, Object.assign({}, props, { ref, className: _c }));
|
|
2693
|
+
})`;
|
|
2694
|
+
});
|
|
2695
|
+
if (!changed) {
|
|
2696
|
+
return { code: source, classes: [], rsc: rscAnalysis, changed: false };
|
|
2697
|
+
}
|
|
2698
|
+
if (prelude.length > 0) {
|
|
2699
|
+
const importEnd = findAfterImports2(code);
|
|
2700
|
+
code = `${code.slice(0, importEnd)}
|
|
2701
|
+
${prelude.join("\n")}
|
|
2702
|
+
${code.slice(importEnd)}`;
|
|
2703
|
+
}
|
|
2704
|
+
if (needsReact && !hasReactImport(source)) {
|
|
2705
|
+
code = `import React from "react";
|
|
2706
|
+
${code}`;
|
|
2707
|
+
}
|
|
2708
|
+
if (autoClientBoundary && rscAnalysis.needsClientDirective) {
|
|
2709
|
+
code = injectClientDirective(code);
|
|
2710
|
+
}
|
|
2711
|
+
if (!preserveImports) {
|
|
2712
|
+
const stillUsesTw = /\btw\.(server\.)?\w+[`(]/.test(code) || /\btw\(\w+\)/.test(code);
|
|
2713
|
+
if (!stillUsesTw) {
|
|
2714
|
+
code = code.replace(
|
|
2715
|
+
/import\s*\{[^}]*\btw\b[^}]*\}\s*from\s*["']tailwind-styled-v4["'];?\n?/g,
|
|
2716
|
+
""
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
code = `${TRANSFORM_MARKER}
|
|
2721
|
+
${code}`;
|
|
2722
|
+
return {
|
|
2723
|
+
code,
|
|
2724
|
+
classes: Array.from(new Set(allClasses)),
|
|
2725
|
+
rsc: {
|
|
2726
|
+
isServer: rscAnalysis.isServer,
|
|
2727
|
+
needsClientDirective: rscAnalysis.needsClientDirective,
|
|
2728
|
+
clientReasons: rscAnalysis.clientReasons
|
|
2729
|
+
},
|
|
2730
|
+
changed: true
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
function isObjectRecord(value) {
|
|
2734
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2735
|
+
}
|
|
2736
|
+
function isStringRecord(value) {
|
|
2737
|
+
return isObjectRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
2738
|
+
}
|
|
2739
|
+
function isVariantRecord(value) {
|
|
2740
|
+
return isObjectRecord(value) && Object.values(value).every((entry) => isStringRecord(entry));
|
|
2741
|
+
}
|
|
2742
|
+
function isCompoundVariantsArray(value) {
|
|
2743
|
+
return Array.isArray(value) && value.every((entry) => isObjectRecord(entry) && typeof entry.class === "string");
|
|
2744
|
+
}
|
|
2745
|
+
function hasReactImport(source) {
|
|
2746
|
+
return source.includes("import React") || source.includes("from 'react'") || source.includes('from "react"');
|
|
2747
|
+
}
|
|
2748
|
+
function findAfterImports2(source) {
|
|
2749
|
+
const lines = source.split("\n");
|
|
2750
|
+
let lastImportIdx = 0;
|
|
2751
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2752
|
+
const line = lines[i].trim();
|
|
2753
|
+
if (line.startsWith("import ") || line.startsWith('"use client"') || line.startsWith("'use client'") || line.startsWith(TRANSFORM_MARKER) || line === "") {
|
|
2754
|
+
lastImportIdx = i;
|
|
2755
|
+
} else if (line && !line.startsWith("//") && !line.startsWith("/*")) {
|
|
2756
|
+
break;
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
return lines.slice(0, lastImportIdx + 1).join("\n").length + 1;
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
// packages/compiler/src/index.ts
|
|
2763
|
+
init_cssCompiler();
|
|
2764
|
+
function extractAllClasses(source) {
|
|
2765
|
+
const { getNativeBridge: getNativeBridge2 } = (init_nativeBridge(), __toCommonJS(nativeBridge_exports));
|
|
2766
|
+
const native = getNativeBridge2();
|
|
2767
|
+
if (!native?.extractClassesFromSourceNative) {
|
|
2768
|
+
throw new Error(
|
|
2769
|
+
`[tailwind-styled/compiler v5] extractClassesFromSourceNative is required but not available.
|
|
2770
|
+
Please ensure the native module is properly built.`
|
|
2771
|
+
);
|
|
2772
|
+
}
|
|
2773
|
+
const result = native.extractClassesFromSourceNative(source);
|
|
2774
|
+
if (!result || result.length < 0) {
|
|
2775
|
+
throw new Error(
|
|
2776
|
+
`[tailwind-styled/compiler v5] extractClassesFromSourceNative returned invalid result.`
|
|
2777
|
+
);
|
|
2778
|
+
}
|
|
2779
|
+
return result.sort();
|
|
2780
|
+
}
|
|
2781
|
+
function extractComponentUsage(source) {
|
|
2782
|
+
const usage = {};
|
|
2783
|
+
const jsxRe = /<([A-Z][A-Za-z0-9]*)\s([^>]*?)(?:\/?>)/g;
|
|
2784
|
+
let m;
|
|
2785
|
+
while ((m = jsxRe.exec(source)) !== null) {
|
|
2786
|
+
const compName = m[1];
|
|
2787
|
+
const propsStr = m[2];
|
|
2788
|
+
if (!usage[compName]) usage[compName] = {};
|
|
2789
|
+
const propRe = /(\w+)=["']([^"']+)["']/g;
|
|
2790
|
+
let p;
|
|
2791
|
+
while ((p = propRe.exec(propsStr)) !== null) {
|
|
2792
|
+
const [, propName, propValue] = p;
|
|
2793
|
+
if (["className", "style", "id", "href", "src", "alt", "type"].includes(propName)) continue;
|
|
2794
|
+
if (!usage[compName][propName]) {
|
|
2795
|
+
usage[compName][propName] = /* @__PURE__ */ new Set();
|
|
2796
|
+
}
|
|
2797
|
+
usage[compName][propName].add(propValue);
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
return usage;
|
|
2801
|
+
}
|
|
2802
|
+
var SCAN_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js"];
|
|
2803
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".next", "dist", ".git", "out"]);
|
|
2804
|
+
function scanFiles(dir) {
|
|
2805
|
+
const files = [];
|
|
2806
|
+
function walk(current) {
|
|
2807
|
+
if (!fs3__default.default.existsSync(current)) return;
|
|
2808
|
+
const entries = fs3__default.default.readdirSync(current, { withFileTypes: true });
|
|
2809
|
+
for (const entry of entries) {
|
|
2810
|
+
if (SKIP_DIRS.has(entry.name)) continue;
|
|
2811
|
+
const fullPath = path7__default.default.join(current, entry.name);
|
|
2812
|
+
if (entry.isDirectory()) {
|
|
2813
|
+
walk(fullPath);
|
|
2814
|
+
} else if (SCAN_EXTENSIONS.some((ext) => entry.name.endsWith(ext))) {
|
|
2815
|
+
files.push(fullPath);
|
|
2816
|
+
}
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
walk(dir);
|
|
2820
|
+
return files;
|
|
2821
|
+
}
|
|
2822
|
+
function scanProjectUsage(dirs, cwd = process.cwd()) {
|
|
2823
|
+
const combined = {};
|
|
2824
|
+
for (const dir of dirs) {
|
|
2825
|
+
const absDir = path7__default.default.isAbsolute(dir) ? dir : path7__default.default.resolve(cwd, dir);
|
|
2826
|
+
const files = scanFiles(absDir);
|
|
2827
|
+
for (const file of files) {
|
|
2828
|
+
try {
|
|
2829
|
+
const source = fs3__default.default.readFileSync(file, "utf-8");
|
|
2830
|
+
const usage = extractComponentUsage(source);
|
|
2831
|
+
for (const [comp, props] of Object.entries(usage)) {
|
|
2832
|
+
if (!combined[comp]) combined[comp] = {};
|
|
2833
|
+
for (const [prop, values] of Object.entries(props)) {
|
|
2834
|
+
if (!combined[comp][prop]) combined[comp][prop] = /* @__PURE__ */ new Set();
|
|
2835
|
+
values.forEach((v) => combined[comp][prop].add(v));
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
} catch {
|
|
2839
|
+
}
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
return combined;
|
|
2843
|
+
}
|
|
2844
|
+
function findDeadVariants(registered, projectUsage) {
|
|
2845
|
+
const report = {
|
|
2846
|
+
unusedCount: 0,
|
|
2847
|
+
bytesSaved: 0,
|
|
2848
|
+
components: {}
|
|
2849
|
+
};
|
|
2850
|
+
for (const component of registered) {
|
|
2851
|
+
const usage = projectUsage[component.name] ?? {};
|
|
2852
|
+
const usedVariants = {};
|
|
2853
|
+
const unusedVariants = {};
|
|
2854
|
+
for (const [variantKey, variantValues] of Object.entries(component.variants)) {
|
|
2855
|
+
usedVariants[variantKey] = [];
|
|
2856
|
+
unusedVariants[variantKey] = [];
|
|
2857
|
+
const usedValueSet = usage[variantKey] ?? /* @__PURE__ */ new Set();
|
|
2858
|
+
for (const [valueName, classes] of Object.entries(variantValues)) {
|
|
2859
|
+
if (usedValueSet.has(valueName)) {
|
|
2860
|
+
usedVariants[variantKey].push(valueName);
|
|
2861
|
+
} else {
|
|
2862
|
+
unusedVariants[variantKey].push(valueName);
|
|
2863
|
+
report.unusedCount++;
|
|
2864
|
+
report.bytesSaved += classes.split(/\s+/).length * 20;
|
|
2865
|
+
}
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
if (report.unusedCount > 0) {
|
|
2869
|
+
report.components[component.name] = { usedVariants, unusedVariants };
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
return report;
|
|
2873
|
+
}
|
|
2874
|
+
function eliminateDeadCss(css, deadClasses) {
|
|
2875
|
+
if (deadClasses.size === 0) return css;
|
|
2876
|
+
const lines = css.split("\n");
|
|
2877
|
+
const kept = [];
|
|
2878
|
+
let inBlock = false;
|
|
2879
|
+
let removeBlock = false;
|
|
2880
|
+
let depth = 0;
|
|
2881
|
+
for (const line of lines) {
|
|
2882
|
+
if (!inBlock) {
|
|
2883
|
+
const isDead = Array.from(deadClasses).some((cls) => {
|
|
2884
|
+
const escaped = cls.replace(/[:/[\].!%]/g, "\\$&");
|
|
2885
|
+
return line.includes(`.${escaped}`) || line.includes(`.${cls}`);
|
|
2886
|
+
});
|
|
2887
|
+
if (isDead && line.includes("{")) {
|
|
2888
|
+
removeBlock = true;
|
|
2889
|
+
inBlock = true;
|
|
2890
|
+
depth = 1;
|
|
2891
|
+
continue;
|
|
2892
|
+
} else if (line.includes("{") && !line.trim().startsWith("@")) {
|
|
2893
|
+
inBlock = true;
|
|
2894
|
+
depth = 1;
|
|
2895
|
+
removeBlock = false;
|
|
2896
|
+
}
|
|
2897
|
+
} else {
|
|
2898
|
+
if (line.includes("{")) depth++;
|
|
2899
|
+
if (line.includes("}")) {
|
|
2900
|
+
depth--;
|
|
2901
|
+
if (depth <= 0) {
|
|
2902
|
+
inBlock = false;
|
|
2903
|
+
if (removeBlock) {
|
|
2904
|
+
removeBlock = false;
|
|
2905
|
+
continue;
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
if (removeBlock) continue;
|
|
2910
|
+
}
|
|
2911
|
+
kept.push(line);
|
|
2912
|
+
}
|
|
2913
|
+
return kept.join("\n");
|
|
2914
|
+
}
|
|
2915
|
+
function optimizeCss(css) {
|
|
2916
|
+
const ruleMap = /* @__PURE__ */ new Map();
|
|
2917
|
+
const ruleRe = /^(\.[\w-]+)\s*\{([^}]+)\}$/gm;
|
|
2918
|
+
const mediaRe = /@media[^{]+\{[\s\S]*?\}\s*\}/g;
|
|
2919
|
+
let m;
|
|
2920
|
+
let remaining = css;
|
|
2921
|
+
const mediaBlocks = [];
|
|
2922
|
+
remaining = remaining.replace(mediaRe, (block) => {
|
|
2923
|
+
mediaBlocks.push(block);
|
|
2924
|
+
return "";
|
|
2925
|
+
});
|
|
2926
|
+
while ((m = ruleRe.exec(remaining)) !== null) {
|
|
2927
|
+
const selector = m[1].trim();
|
|
2928
|
+
const declaration = m[2].trim();
|
|
2929
|
+
if (!ruleMap.has(declaration)) {
|
|
2930
|
+
ruleMap.set(declaration, /* @__PURE__ */ new Set());
|
|
2931
|
+
}
|
|
2932
|
+
ruleMap.get(declaration).add(selector);
|
|
2933
|
+
}
|
|
2934
|
+
const lines = [];
|
|
2935
|
+
for (const [declaration, selectors] of ruleMap) {
|
|
2936
|
+
lines.push(`${Array.from(selectors).join(",")} { ${declaration} }`);
|
|
2937
|
+
}
|
|
2938
|
+
lines.push(...mediaBlocks);
|
|
2939
|
+
return lines.join("\n");
|
|
2940
|
+
}
|
|
2941
|
+
function runElimination(opts) {
|
|
2942
|
+
const { dirs = ["src"], cwd = process.cwd(), registered = [], inputCss, verbose = false } = opts;
|
|
2943
|
+
const usage = scanProjectUsage(dirs, cwd);
|
|
2944
|
+
const report = findDeadVariants(registered, usage);
|
|
2945
|
+
const deadClasses = /* @__PURE__ */ new Set();
|
|
2946
|
+
for (const [, { unusedVariants }] of Object.entries(report.components)) {
|
|
2947
|
+
for (const values of Object.values(unusedVariants)) {
|
|
2948
|
+
values.forEach((v) => deadClasses.add(v));
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2951
|
+
let css = eliminateDeadCss(inputCss, deadClasses);
|
|
2952
|
+
css = optimizeCss(css);
|
|
2953
|
+
if (verbose) {
|
|
2954
|
+
const saved = (report.bytesSaved / 1024).toFixed(1);
|
|
2955
|
+
console.log(`[tailwind-styled-v4] Dead style elimination:`);
|
|
2956
|
+
console.log(` Unused variants: ${report.unusedCount}`);
|
|
2957
|
+
console.log(` Estimated savings: ~${saved}KB`);
|
|
2958
|
+
for (const [comp, { unusedVariants }] of Object.entries(report.components)) {
|
|
2959
|
+
for (const [variant, values] of Object.entries(unusedVariants)) {
|
|
2960
|
+
if (values.length > 0) {
|
|
2961
|
+
console.log(` ${comp}.${variant}: ${values.join(", ")} (unused)`);
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
return { css, report };
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
// packages/compiler/src/incrementalEngine.ts
|
|
2970
|
+
init_src();
|
|
2971
|
+
var CACHE_DIR = ".tw-cache";
|
|
2972
|
+
var HASH_CACHE_FILE = path7__default.default.join(CACHE_DIR, "file-hashes.json");
|
|
2973
|
+
var GRAPH_CACHE_FILE = path7__default.default.join(CACHE_DIR, "dep-graph.json");
|
|
2974
|
+
function ensureCacheDir() {
|
|
2975
|
+
if (!fs3__default.default.existsSync(CACHE_DIR)) {
|
|
2976
|
+
fs3__default.default.mkdirSync(CACHE_DIR, { recursive: true });
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
function loadHashCache() {
|
|
2980
|
+
try {
|
|
2981
|
+
if (fs3__default.default.existsSync(HASH_CACHE_FILE)) {
|
|
2982
|
+
const raw = fs3__default.default.readFileSync(HASH_CACHE_FILE, "utf-8");
|
|
2983
|
+
return new Map(Object.entries(JSON.parse(raw)));
|
|
2984
|
+
}
|
|
2985
|
+
} catch {
|
|
2986
|
+
}
|
|
2987
|
+
return /* @__PURE__ */ new Map();
|
|
2988
|
+
}
|
|
2989
|
+
function saveHashCache(cache) {
|
|
2990
|
+
try {
|
|
2991
|
+
ensureCacheDir();
|
|
2992
|
+
const obj = Object.fromEntries(cache);
|
|
2993
|
+
fs3__default.default.writeFileSync(HASH_CACHE_FILE, JSON.stringify(obj, null, 2));
|
|
2994
|
+
} catch {
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
function loadGraphCache() {
|
|
2998
|
+
try {
|
|
2999
|
+
if (fs3__default.default.existsSync(GRAPH_CACHE_FILE)) {
|
|
3000
|
+
const raw = fs3__default.default.readFileSync(GRAPH_CACHE_FILE, "utf-8");
|
|
3001
|
+
const data = JSON.parse(raw);
|
|
3002
|
+
return new Map(Object.entries(data));
|
|
3003
|
+
}
|
|
3004
|
+
} catch {
|
|
3005
|
+
}
|
|
3006
|
+
return /* @__PURE__ */ new Map();
|
|
3007
|
+
}
|
|
3008
|
+
function saveGraphCache(graph) {
|
|
3009
|
+
try {
|
|
3010
|
+
ensureCacheDir();
|
|
3011
|
+
const obj = Object.fromEntries(graph);
|
|
3012
|
+
fs3__default.default.writeFileSync(GRAPH_CACHE_FILE, JSON.stringify(obj, null, 2));
|
|
3013
|
+
} catch {
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
function fnv1a(str) {
|
|
3017
|
+
let h = 2166136261;
|
|
3018
|
+
for (let i = 0; i < str.length; i++) {
|
|
3019
|
+
h ^= str.charCodeAt(i);
|
|
3020
|
+
h = h * 16777619 >>> 0;
|
|
3021
|
+
}
|
|
3022
|
+
return h;
|
|
3023
|
+
}
|
|
3024
|
+
function toBase36(n, len = 4) {
|
|
3025
|
+
const chars = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
3026
|
+
let result = "";
|
|
3027
|
+
let num = n;
|
|
3028
|
+
for (let i = 0; i < len; i++) {
|
|
3029
|
+
result = chars[num % 36] + result;
|
|
3030
|
+
num = Math.floor(num / 36);
|
|
3031
|
+
}
|
|
3032
|
+
return result;
|
|
3033
|
+
}
|
|
3034
|
+
function hashFileContent(content) {
|
|
3035
|
+
return hashContent(content, "md5", 8);
|
|
3036
|
+
}
|
|
3037
|
+
function makeAtomicClass(declaration, modifier) {
|
|
3038
|
+
const key = modifier ? `${declaration}::${modifier}` : declaration;
|
|
3039
|
+
return `tw-${toBase36(fnv1a(key))}`;
|
|
3040
|
+
}
|
|
3041
|
+
function computeDiff(oldNodes, newNodes) {
|
|
3042
|
+
const oldMap = new Map(oldNodes.map((n) => [n.atomicClass, n]));
|
|
3043
|
+
const newMap = new Map(newNodes.map((n) => [n.atomicClass, n]));
|
|
3044
|
+
const added = [];
|
|
3045
|
+
const removed = [];
|
|
3046
|
+
for (const [cls, node] of newMap) {
|
|
3047
|
+
if (!oldMap.has(cls)) added.push(node);
|
|
3048
|
+
}
|
|
3049
|
+
for (const cls of oldMap.keys()) {
|
|
3050
|
+
if (!newMap.has(cls)) removed.push(cls);
|
|
3051
|
+
}
|
|
3052
|
+
return {
|
|
3053
|
+
added,
|
|
3054
|
+
removed,
|
|
3055
|
+
noChange: added.length === 0 && removed.length === 0
|
|
3056
|
+
};
|
|
3057
|
+
}
|
|
3058
|
+
var GlobalAtomicRegistry = class {
|
|
3059
|
+
constructor() {
|
|
3060
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
3061
|
+
}
|
|
3062
|
+
/** Tambah node dari file tertentu */
|
|
3063
|
+
add(filepath, node) {
|
|
3064
|
+
const existing = this.entries.get(node.atomicClass);
|
|
3065
|
+
if (existing) {
|
|
3066
|
+
existing.sources.add(filepath);
|
|
3067
|
+
} else {
|
|
3068
|
+
this.entries.set(node.atomicClass, {
|
|
3069
|
+
node,
|
|
3070
|
+
sources: /* @__PURE__ */ new Set([filepath])
|
|
3071
|
+
});
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
/** Hapus referensi dari file tertentu; jika tidak ada source lain, rule dihapus */
|
|
3075
|
+
remove(filepath, atomicClass) {
|
|
3076
|
+
const entry = this.entries.get(atomicClass);
|
|
3077
|
+
if (!entry) return false;
|
|
3078
|
+
entry.sources.delete(filepath);
|
|
3079
|
+
if (entry.sources.size === 0) {
|
|
3080
|
+
this.entries.delete(atomicClass);
|
|
3081
|
+
return true;
|
|
3082
|
+
}
|
|
3083
|
+
return false;
|
|
3084
|
+
}
|
|
3085
|
+
/** Cek apakah rule ada di registry global */
|
|
3086
|
+
has(atomicClass) {
|
|
3087
|
+
return this.entries.has(atomicClass);
|
|
3088
|
+
}
|
|
3089
|
+
/** Semua entries untuk CSS generation */
|
|
3090
|
+
all() {
|
|
3091
|
+
return Array.from(this.entries.values()).map((e) => e.node);
|
|
3092
|
+
}
|
|
3093
|
+
/** Total unique rules */
|
|
3094
|
+
size() {
|
|
3095
|
+
return this.entries.size;
|
|
3096
|
+
}
|
|
3097
|
+
};
|
|
3098
|
+
function nodeToCSS(node) {
|
|
3099
|
+
const { atomicClass, declaration, modifier } = node;
|
|
3100
|
+
if (!modifier) {
|
|
3101
|
+
return `.${atomicClass}{${declaration}}`;
|
|
3102
|
+
}
|
|
3103
|
+
if (modifier.startsWith("@")) {
|
|
3104
|
+
return `${modifier}{.${atomicClass}{${declaration}}}`;
|
|
3105
|
+
}
|
|
3106
|
+
return `.${atomicClass}${modifier}{${declaration}}`;
|
|
3107
|
+
}
|
|
3108
|
+
var CssDiffWriter = class {
|
|
3109
|
+
constructor(outputPath) {
|
|
3110
|
+
this.ruleMap = /* @__PURE__ */ new Map();
|
|
3111
|
+
this.dirty = false;
|
|
3112
|
+
this.outputPath = outputPath;
|
|
3113
|
+
this.loadFromDisk();
|
|
3114
|
+
}
|
|
3115
|
+
loadFromDisk() {
|
|
3116
|
+
try {
|
|
3117
|
+
if (fs3__default.default.existsSync(this.outputPath)) {
|
|
3118
|
+
const css = fs3__default.default.readFileSync(this.outputPath, "utf-8");
|
|
3119
|
+
const ruleRe = /(\.tw-[a-z0-9]+(?::[\w-]+)?)\{([^}]+)\}|(@[^{]+)\{(\.tw-[a-z0-9]+)\{([^}]+)\}\}/g;
|
|
3120
|
+
let m;
|
|
3121
|
+
while ((m = ruleRe.exec(css)) !== null) {
|
|
3122
|
+
if (m[1]) {
|
|
3123
|
+
const cls = m[1].replace(/\.[^:]+:.*/, (match) => match.split(".")[1].split(":")[0]);
|
|
3124
|
+
this.ruleMap.set(cls, m[0]);
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
} catch {
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
/** Apply diff ke internal map */
|
|
3132
|
+
applyDiff(diff) {
|
|
3133
|
+
if (diff.noChange) return;
|
|
3134
|
+
for (const node of diff.added) {
|
|
3135
|
+
this.ruleMap.set(node.atomicClass, nodeToCSS(node));
|
|
3136
|
+
}
|
|
3137
|
+
for (const cls of diff.removed) {
|
|
3138
|
+
this.ruleMap.delete(cls);
|
|
3139
|
+
}
|
|
3140
|
+
this.dirty = true;
|
|
3141
|
+
}
|
|
3142
|
+
/** Write ke disk jika ada perubahan. Async untuk tidak block loader. */
|
|
3143
|
+
async flush() {
|
|
3144
|
+
if (!this.dirty) return;
|
|
3145
|
+
try {
|
|
3146
|
+
ensureCacheDir();
|
|
3147
|
+
const css = Array.from(this.ruleMap.values()).join("\n");
|
|
3148
|
+
await fs3__default.default.promises.writeFile(this.outputPath, css, "utf-8");
|
|
3149
|
+
this.dirty = false;
|
|
3150
|
+
} catch {
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
/** Sync flush untuk build end */
|
|
3154
|
+
flushSync() {
|
|
3155
|
+
if (!this.dirty) return;
|
|
3156
|
+
try {
|
|
3157
|
+
ensureCacheDir();
|
|
3158
|
+
const css = Array.from(this.ruleMap.values()).join("\n");
|
|
3159
|
+
fs3__default.default.writeFileSync(this.outputPath, css, "utf-8");
|
|
3160
|
+
this.dirty = false;
|
|
3161
|
+
} catch {
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
size() {
|
|
3165
|
+
return this.ruleMap.size;
|
|
3166
|
+
}
|
|
3167
|
+
};
|
|
3168
|
+
var IncrementalEngine = class {
|
|
3169
|
+
constructor(opts = {}) {
|
|
3170
|
+
// Stats untuk current build session
|
|
3171
|
+
this.stats = {
|
|
3172
|
+
totalFiles: 0,
|
|
3173
|
+
changedFiles: 0,
|
|
3174
|
+
skippedFiles: 0,
|
|
3175
|
+
addedRules: 0,
|
|
3176
|
+
removedRules: 0,
|
|
3177
|
+
buildTimeMs: 0
|
|
3178
|
+
};
|
|
3179
|
+
this.sessionStart = Date.now();
|
|
3180
|
+
this.opts = {
|
|
3181
|
+
outputPath: opts.outputPath ?? path7__default.default.join(CACHE_DIR, "atomic.css"),
|
|
3182
|
+
persistCache: opts.persistCache ?? true,
|
|
3183
|
+
verbose: opts.verbose ?? false
|
|
3184
|
+
};
|
|
3185
|
+
this.hashCache = this.opts.persistCache ? loadHashCache() : /* @__PURE__ */ new Map();
|
|
3186
|
+
this.depGraph = this.opts.persistCache ? loadGraphCache() : /* @__PURE__ */ new Map();
|
|
3187
|
+
this.globalReg = new GlobalAtomicRegistry();
|
|
3188
|
+
this.cssWriter = new CssDiffWriter(this.opts.outputPath);
|
|
3189
|
+
for (const [filepath, nodes] of this.depGraph) {
|
|
3190
|
+
for (const node of nodes) {
|
|
3191
|
+
this.globalReg.add(filepath, node);
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
3195
|
+
/**
|
|
3196
|
+
* Proses satu file. Core method dipanggil oleh webpack/turbopack loader.
|
|
3197
|
+
*
|
|
3198
|
+
* @param filepath - Absolute path ke file
|
|
3199
|
+
* @param source - Source code file (untuk hashing)
|
|
3200
|
+
* @param extractedNodes - Style nodes yang di-extract compiler dari file ini
|
|
3201
|
+
* @returns ProcessResult dengan diff dan stats
|
|
3202
|
+
*/
|
|
3203
|
+
processFile(filepath, source, extractedNodes) {
|
|
3204
|
+
const t0 = Date.now();
|
|
3205
|
+
this.stats.totalFiles++;
|
|
3206
|
+
const currentHash = hashFileContent(source);
|
|
3207
|
+
const cachedHash = this.hashCache.get(filepath);
|
|
3208
|
+
if (cachedHash === currentHash) {
|
|
3209
|
+
this.stats.skippedFiles++;
|
|
3210
|
+
this.log(`[skip] ${path7__default.default.relative(process.cwd(), filepath)}`);
|
|
3211
|
+
return {
|
|
3212
|
+
filepath,
|
|
3213
|
+
changed: false,
|
|
3214
|
+
diff: { added: [], removed: [], noChange: true },
|
|
3215
|
+
durationMs: Date.now() - t0
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
this.hashCache.set(filepath, currentHash);
|
|
3219
|
+
this.stats.changedFiles++;
|
|
3220
|
+
this.log(`[change] ${path7__default.default.relative(process.cwd(), filepath)}`);
|
|
3221
|
+
const oldNodes = this.depGraph.get(filepath) ?? [];
|
|
3222
|
+
const diff = computeDiff(oldNodes, extractedNodes);
|
|
3223
|
+
this.depGraph.set(filepath, extractedNodes);
|
|
3224
|
+
const trulyRemoved = [];
|
|
3225
|
+
for (const cls of diff.removed) {
|
|
3226
|
+
const wasRemoved = this.globalReg.remove(filepath, cls);
|
|
3227
|
+
if (wasRemoved) trulyRemoved.push(cls);
|
|
3228
|
+
}
|
|
3229
|
+
const trulyAdded = [];
|
|
3230
|
+
for (const node of diff.added) {
|
|
3231
|
+
if (!this.globalReg.has(node.atomicClass)) {
|
|
3232
|
+
trulyAdded.push(node);
|
|
3233
|
+
}
|
|
3234
|
+
this.globalReg.add(filepath, node);
|
|
3235
|
+
}
|
|
3236
|
+
const finalDiff = {
|
|
3237
|
+
added: trulyAdded,
|
|
3238
|
+
removed: trulyRemoved,
|
|
3239
|
+
noChange: trulyAdded.length === 0 && trulyRemoved.length === 0
|
|
3240
|
+
};
|
|
3241
|
+
this.cssWriter.applyDiff(finalDiff);
|
|
3242
|
+
this.stats.addedRules += trulyAdded.length;
|
|
3243
|
+
this.stats.removedRules += trulyRemoved.length;
|
|
3244
|
+
return {
|
|
3245
|
+
filepath,
|
|
3246
|
+
changed: true,
|
|
3247
|
+
diff: finalDiff,
|
|
3248
|
+
durationMs: Date.now() - t0
|
|
3249
|
+
};
|
|
3250
|
+
}
|
|
3251
|
+
/**
|
|
3252
|
+
* Dipanggil di akhir build. Flush CSS ke disk, persist cache.
|
|
3253
|
+
*/
|
|
3254
|
+
async buildEnd() {
|
|
3255
|
+
this.stats.buildTimeMs = Date.now() - this.sessionStart;
|
|
3256
|
+
await this.cssWriter.flush();
|
|
3257
|
+
if (this.opts.persistCache) {
|
|
3258
|
+
saveHashCache(this.hashCache);
|
|
3259
|
+
saveGraphCache(this.depGraph);
|
|
3260
|
+
}
|
|
3261
|
+
this.log(
|
|
3262
|
+
`[build] done in ${this.stats.buildTimeMs}ms | changed: ${this.stats.changedFiles}/${this.stats.totalFiles} files | +${this.stats.addedRules} -${this.stats.removedRules} rules | total rules: ${this.cssWriter.size()}`
|
|
3263
|
+
);
|
|
3264
|
+
}
|
|
3265
|
+
/** Sync version untuk webpack buildEnd hook */
|
|
3266
|
+
buildEndSync() {
|
|
3267
|
+
this.stats.buildTimeMs = Date.now() - this.sessionStart;
|
|
3268
|
+
this.cssWriter.flushSync();
|
|
3269
|
+
if (this.opts.persistCache) {
|
|
3270
|
+
saveHashCache(this.hashCache);
|
|
3271
|
+
saveGraphCache(this.depGraph);
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
/**
|
|
3275
|
+
* Invalidate satu file (untuk hot reload — file dihapus atau renamed).
|
|
3276
|
+
*/
|
|
3277
|
+
invalidateFile(filepath) {
|
|
3278
|
+
const oldNodes = this.depGraph.get(filepath) ?? [];
|
|
3279
|
+
for (const node of oldNodes) {
|
|
3280
|
+
this.globalReg.remove(filepath, node.atomicClass);
|
|
3281
|
+
}
|
|
3282
|
+
this.depGraph.delete(filepath);
|
|
3283
|
+
this.hashCache.delete(filepath);
|
|
3284
|
+
this.log(`[invalidate] ${path7__default.default.relative(process.cwd(), filepath)}`);
|
|
3285
|
+
}
|
|
3286
|
+
/** Get all active style nodes — untuk full CSS generation */
|
|
3287
|
+
getAllNodes() {
|
|
3288
|
+
return this.globalReg.all();
|
|
3289
|
+
}
|
|
3290
|
+
/** Get stats untuk current build session */
|
|
3291
|
+
getStats() {
|
|
3292
|
+
return { ...this.stats, buildTimeMs: Date.now() - this.sessionStart };
|
|
3293
|
+
}
|
|
3294
|
+
/** Get output CSS path */
|
|
3295
|
+
getOutputPath() {
|
|
3296
|
+
return this.opts.outputPath;
|
|
3297
|
+
}
|
|
3298
|
+
/** Reset stats untuk build session baru */
|
|
3299
|
+
resetStats() {
|
|
3300
|
+
this.stats = {
|
|
3301
|
+
totalFiles: 0,
|
|
3302
|
+
changedFiles: 0,
|
|
3303
|
+
skippedFiles: 0,
|
|
3304
|
+
addedRules: 0,
|
|
3305
|
+
removedRules: 0,
|
|
3306
|
+
buildTimeMs: 0
|
|
3307
|
+
};
|
|
3308
|
+
this.sessionStart = Date.now();
|
|
3309
|
+
}
|
|
3310
|
+
/** Reset semua cache — untuk clean build */
|
|
3311
|
+
reset() {
|
|
3312
|
+
this.hashCache.clear();
|
|
3313
|
+
this.depGraph.clear();
|
|
3314
|
+
this.globalReg = new GlobalAtomicRegistry();
|
|
3315
|
+
this.cssWriter = new CssDiffWriter(this.opts.outputPath);
|
|
3316
|
+
this.resetStats();
|
|
3317
|
+
this.log("[reset] incremental cache cleared");
|
|
3318
|
+
}
|
|
3319
|
+
log(msg) {
|
|
3320
|
+
if (this.opts.verbose) {
|
|
3321
|
+
console.log(`[tailwind-styled/incremental] ${msg}`);
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
};
|
|
3325
|
+
function parseClassesToNodes(classes) {
|
|
3326
|
+
const nodes = [];
|
|
3327
|
+
for (const cls of classes) {
|
|
3328
|
+
const node = parseOneClass(cls);
|
|
3329
|
+
if (node) nodes.push(node);
|
|
3330
|
+
}
|
|
3331
|
+
return nodes;
|
|
3332
|
+
}
|
|
3333
|
+
function parseOneClass(cls) {
|
|
3334
|
+
const colonIdx = cls.lastIndexOf(":");
|
|
3335
|
+
let modifier;
|
|
3336
|
+
let utility;
|
|
3337
|
+
if (colonIdx > 0) {
|
|
3338
|
+
const modStr = cls.slice(0, colonIdx);
|
|
3339
|
+
utility = cls.slice(colonIdx + 1);
|
|
3340
|
+
modifier = resolveModifier(modStr);
|
|
3341
|
+
} else {
|
|
3342
|
+
utility = cls;
|
|
3343
|
+
}
|
|
3344
|
+
const declaration = twToDeclaration(utility);
|
|
3345
|
+
if (!declaration) return null;
|
|
3346
|
+
const atomicClass = makeAtomicClass(declaration, modifier);
|
|
3347
|
+
return { twClass: cls, declaration, modifier, atomicClass };
|
|
3348
|
+
}
|
|
3349
|
+
function resolveModifier(mod) {
|
|
3350
|
+
const pseudoMap = {
|
|
3351
|
+
hover: ":hover",
|
|
3352
|
+
focus: ":focus",
|
|
3353
|
+
active: ":active",
|
|
3354
|
+
disabled: ":disabled",
|
|
3355
|
+
visited: ":visited",
|
|
3356
|
+
checked: ":checked",
|
|
3357
|
+
first: ":first-child",
|
|
3358
|
+
last: ":last-child",
|
|
3359
|
+
odd: ":nth-child(odd)",
|
|
3360
|
+
even: ":nth-child(even)"
|
|
3361
|
+
};
|
|
3362
|
+
const mediaMap = {
|
|
3363
|
+
sm: "@media (min-width: 640px)",
|
|
3364
|
+
md: "@media (min-width: 768px)",
|
|
3365
|
+
lg: "@media (min-width: 1024px)",
|
|
3366
|
+
xl: "@media (min-width: 1280px)",
|
|
3367
|
+
"2xl": "@media (min-width: 1536px)",
|
|
3368
|
+
dark: "@media (prefers-color-scheme: dark)",
|
|
3369
|
+
print: "@media print"
|
|
3370
|
+
};
|
|
3371
|
+
return pseudoMap[mod] ?? mediaMap[mod] ?? `:${mod}`;
|
|
3372
|
+
}
|
|
3373
|
+
function twToDeclaration(cls) {
|
|
3374
|
+
const sp = cls.match(/^(p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|gap)-([\d.]+)$/);
|
|
3375
|
+
if (sp) {
|
|
3376
|
+
const propMap = {
|
|
3377
|
+
p: "padding",
|
|
3378
|
+
px: "padding-inline",
|
|
3379
|
+
py: "padding-block",
|
|
3380
|
+
pt: "padding-top",
|
|
3381
|
+
pb: "padding-bottom",
|
|
3382
|
+
pl: "padding-left",
|
|
3383
|
+
pr: "padding-right",
|
|
3384
|
+
m: "margin",
|
|
3385
|
+
mx: "margin-inline",
|
|
3386
|
+
my: "margin-block",
|
|
3387
|
+
mt: "margin-top",
|
|
3388
|
+
mb: "margin-bottom",
|
|
3389
|
+
ml: "margin-left",
|
|
3390
|
+
mr: "margin-right",
|
|
3391
|
+
gap: "gap"
|
|
3392
|
+
};
|
|
3393
|
+
return `${propMap[sp[1]]}: ${parseFloat(sp[2]) * 0.25}rem`;
|
|
3394
|
+
}
|
|
3395
|
+
const w = cls.match(/^w-(.+)$/);
|
|
3396
|
+
if (w) return `width: ${sizeVal(w[1])}`;
|
|
3397
|
+
const h = cls.match(/^h-(.+)$/);
|
|
3398
|
+
if (h) return `height: ${sizeVal(h[1])}`;
|
|
3399
|
+
const op = cls.match(/^opacity-(\d+)$/);
|
|
3400
|
+
if (op) return `opacity: ${parseInt(op[1], 10) / 100}`;
|
|
3401
|
+
const z = cls.match(/^z-(\d+)$/);
|
|
3402
|
+
if (z) return `z-index: ${z[1]}`;
|
|
3403
|
+
const map = {
|
|
3404
|
+
block: "display: block",
|
|
3405
|
+
"inline-block": "display: inline-block",
|
|
3406
|
+
flex: "display: flex",
|
|
3407
|
+
"inline-flex": "display: inline-flex",
|
|
3408
|
+
grid: "display: grid",
|
|
3409
|
+
hidden: "display: none",
|
|
3410
|
+
relative: "position: relative",
|
|
3411
|
+
absolute: "position: absolute",
|
|
3412
|
+
fixed: "position: fixed",
|
|
3413
|
+
sticky: "position: sticky",
|
|
3414
|
+
"flex-row": "flex-direction: row",
|
|
3415
|
+
"flex-col": "flex-direction: column",
|
|
3416
|
+
"items-center": "align-items: center",
|
|
3417
|
+
"items-start": "align-items: flex-start",
|
|
3418
|
+
"items-end": "align-items: flex-end",
|
|
3419
|
+
"justify-center": "justify-content: center",
|
|
3420
|
+
"justify-between": "justify-content: space-between",
|
|
3421
|
+
"justify-start": "justify-content: flex-start",
|
|
3422
|
+
"justify-end": "justify-content: flex-end",
|
|
3423
|
+
"font-thin": "font-weight: 100",
|
|
3424
|
+
"font-light": "font-weight: 300",
|
|
3425
|
+
"font-normal": "font-weight: 400",
|
|
3426
|
+
"font-medium": "font-weight: 500",
|
|
3427
|
+
"font-semibold": "font-weight: 600",
|
|
3428
|
+
"font-bold": "font-weight: 700",
|
|
3429
|
+
"font-extrabold": "font-weight: 800",
|
|
3430
|
+
"text-xs": "font-size: 0.75rem",
|
|
3431
|
+
"text-sm": "font-size: 0.875rem",
|
|
3432
|
+
"text-base": "font-size: 1rem",
|
|
3433
|
+
"text-lg": "font-size: 1.125rem",
|
|
3434
|
+
"text-xl": "font-size: 1.25rem",
|
|
3435
|
+
"text-2xl": "font-size: 1.5rem",
|
|
3436
|
+
"text-3xl": "font-size: 1.875rem",
|
|
3437
|
+
"text-4xl": "font-size: 2.25rem",
|
|
3438
|
+
rounded: "border-radius: 0.25rem",
|
|
3439
|
+
"rounded-md": "border-radius: 0.375rem",
|
|
3440
|
+
"rounded-lg": "border-radius: 0.5rem",
|
|
3441
|
+
"rounded-xl": "border-radius: 0.75rem",
|
|
3442
|
+
"rounded-full": "border-radius: 9999px",
|
|
3443
|
+
"overflow-hidden": "overflow: hidden",
|
|
3444
|
+
"overflow-auto": "overflow: auto",
|
|
3445
|
+
"cursor-pointer": "cursor: pointer",
|
|
3446
|
+
"cursor-default": "cursor: default",
|
|
3447
|
+
"select-none": "user-select: none",
|
|
3448
|
+
"pointer-events-none": "pointer-events: none",
|
|
3449
|
+
truncate: "overflow: hidden; text-overflow: ellipsis; white-space: nowrap",
|
|
3450
|
+
transition: "transition-property: color,background-color,border-color,opacity,box-shadow,transform; transition-duration: 150ms"
|
|
3451
|
+
};
|
|
3452
|
+
return map[cls] ?? null;
|
|
3453
|
+
}
|
|
3454
|
+
function sizeVal(v) {
|
|
3455
|
+
const num = parseFloat(v);
|
|
3456
|
+
if (!Number.isNaN(num)) return `${num * 0.25}rem`;
|
|
3457
|
+
const special = {
|
|
3458
|
+
full: "100%",
|
|
3459
|
+
screen: "100vw",
|
|
3460
|
+
auto: "auto",
|
|
3461
|
+
min: "min-content",
|
|
3462
|
+
max: "max-content",
|
|
3463
|
+
fit: "fit-content"
|
|
3464
|
+
};
|
|
3465
|
+
return special[v] ?? v;
|
|
3466
|
+
}
|
|
3467
|
+
var _engine = null;
|
|
3468
|
+
function getIncrementalEngine(opts) {
|
|
3469
|
+
if (!_engine) {
|
|
3470
|
+
_engine = new IncrementalEngine(opts);
|
|
3471
|
+
}
|
|
3472
|
+
return _engine;
|
|
3473
|
+
}
|
|
3474
|
+
function resetIncrementalEngine() {
|
|
3475
|
+
_engine = null;
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
// packages/compiler/src/styleBucketSystem.ts
|
|
3479
|
+
var BUCKET_ORDER = [
|
|
3480
|
+
"reset",
|
|
3481
|
+
"layout",
|
|
3482
|
+
"spacing",
|
|
3483
|
+
"sizing",
|
|
3484
|
+
"typography",
|
|
3485
|
+
"visual",
|
|
3486
|
+
"interaction",
|
|
3487
|
+
"responsive",
|
|
3488
|
+
"unknown"
|
|
3489
|
+
];
|
|
3490
|
+
var PROPERTY_BUCKET_MAP = {
|
|
3491
|
+
// Layout
|
|
3492
|
+
display: "layout",
|
|
3493
|
+
position: "layout",
|
|
3494
|
+
flex: "layout",
|
|
3495
|
+
"flex-direction": "layout",
|
|
3496
|
+
"flex-wrap": "layout",
|
|
3497
|
+
"flex-grow": "layout",
|
|
3498
|
+
"flex-shrink": "layout",
|
|
3499
|
+
"flex-basis": "layout",
|
|
3500
|
+
grid: "layout",
|
|
3501
|
+
"grid-template": "layout",
|
|
3502
|
+
"grid-column": "layout",
|
|
3503
|
+
"grid-row": "layout",
|
|
3504
|
+
"align-items": "layout",
|
|
3505
|
+
"align-self": "layout",
|
|
3506
|
+
"align-content": "layout",
|
|
3507
|
+
"justify-content": "layout",
|
|
3508
|
+
"justify-items": "layout",
|
|
3509
|
+
"justify-self": "layout",
|
|
3510
|
+
"place-items": "layout",
|
|
3511
|
+
"place-content": "layout",
|
|
3512
|
+
overflow: "layout",
|
|
3513
|
+
"overflow-x": "layout",
|
|
3514
|
+
"overflow-y": "layout",
|
|
3515
|
+
"z-index": "layout",
|
|
3516
|
+
float: "layout",
|
|
3517
|
+
clear: "layout",
|
|
3518
|
+
visibility: "layout",
|
|
3519
|
+
// Spacing
|
|
3520
|
+
padding: "spacing",
|
|
3521
|
+
"padding-top": "spacing",
|
|
3522
|
+
"padding-bottom": "spacing",
|
|
3523
|
+
"padding-left": "spacing",
|
|
3524
|
+
"padding-right": "spacing",
|
|
3525
|
+
"padding-inline": "spacing",
|
|
3526
|
+
"padding-block": "spacing",
|
|
3527
|
+
margin: "spacing",
|
|
3528
|
+
"margin-top": "spacing",
|
|
3529
|
+
"margin-bottom": "spacing",
|
|
3530
|
+
"margin-left": "spacing",
|
|
3531
|
+
"margin-right": "spacing",
|
|
3532
|
+
"margin-inline": "spacing",
|
|
3533
|
+
"margin-block": "spacing",
|
|
3534
|
+
gap: "spacing",
|
|
3535
|
+
"column-gap": "spacing",
|
|
3536
|
+
"row-gap": "spacing",
|
|
3537
|
+
inset: "spacing",
|
|
3538
|
+
"inset-inline": "spacing",
|
|
3539
|
+
"inset-block": "spacing",
|
|
3540
|
+
top: "spacing",
|
|
3541
|
+
bottom: "spacing",
|
|
3542
|
+
left: "spacing",
|
|
3543
|
+
right: "spacing",
|
|
3544
|
+
// Sizing
|
|
3545
|
+
width: "sizing",
|
|
3546
|
+
height: "sizing",
|
|
3547
|
+
"max-width": "sizing",
|
|
3548
|
+
"min-width": "sizing",
|
|
3549
|
+
"max-height": "sizing",
|
|
3550
|
+
"min-height": "sizing",
|
|
3551
|
+
"aspect-ratio": "sizing",
|
|
3552
|
+
// Typography
|
|
3553
|
+
"font-size": "typography",
|
|
3554
|
+
"font-weight": "typography",
|
|
3555
|
+
"font-family": "typography",
|
|
3556
|
+
"font-style": "typography",
|
|
3557
|
+
"line-height": "typography",
|
|
3558
|
+
"letter-spacing": "typography",
|
|
3559
|
+
"text-align": "typography",
|
|
3560
|
+
"text-decoration": "typography",
|
|
3561
|
+
"text-transform": "typography",
|
|
3562
|
+
"text-overflow": "typography",
|
|
3563
|
+
"white-space": "typography",
|
|
3564
|
+
"word-break": "typography",
|
|
3565
|
+
"word-wrap": "typography",
|
|
3566
|
+
"vertical-align": "typography",
|
|
3567
|
+
// Visual
|
|
3568
|
+
color: "visual",
|
|
3569
|
+
background: "visual",
|
|
3570
|
+
"background-color": "visual",
|
|
3571
|
+
"background-image": "visual",
|
|
3572
|
+
"background-size": "visual",
|
|
3573
|
+
"background-position": "visual",
|
|
3574
|
+
"background-repeat": "visual",
|
|
3575
|
+
border: "visual",
|
|
3576
|
+
"border-top": "visual",
|
|
3577
|
+
"border-bottom": "visual",
|
|
3578
|
+
"border-left": "visual",
|
|
3579
|
+
"border-right": "visual",
|
|
3580
|
+
"border-inline": "visual",
|
|
3581
|
+
"border-block": "visual",
|
|
3582
|
+
"border-color": "visual",
|
|
3583
|
+
"border-width": "visual",
|
|
3584
|
+
"border-style": "visual",
|
|
3585
|
+
"border-radius": "visual",
|
|
3586
|
+
"box-shadow": "visual",
|
|
3587
|
+
opacity: "visual",
|
|
3588
|
+
outline: "visual",
|
|
3589
|
+
"outline-color": "visual",
|
|
3590
|
+
"outline-width": "visual",
|
|
3591
|
+
fill: "visual",
|
|
3592
|
+
stroke: "visual",
|
|
3593
|
+
"text-shadow": "visual",
|
|
3594
|
+
"mix-blend-mode": "visual",
|
|
3595
|
+
"object-fit": "visual",
|
|
3596
|
+
"object-position": "visual",
|
|
3597
|
+
// Interaction
|
|
3598
|
+
cursor: "interaction",
|
|
3599
|
+
"pointer-events": "interaction",
|
|
3600
|
+
"user-select": "interaction",
|
|
3601
|
+
transition: "interaction",
|
|
3602
|
+
"transition-property": "interaction",
|
|
3603
|
+
"transition-duration": "interaction",
|
|
3604
|
+
"transition-timing-function": "interaction",
|
|
3605
|
+
"transition-delay": "interaction",
|
|
3606
|
+
transform: "interaction",
|
|
3607
|
+
translate: "interaction",
|
|
3608
|
+
rotate: "interaction",
|
|
3609
|
+
scale: "interaction",
|
|
3610
|
+
animation: "interaction",
|
|
3611
|
+
"will-change": "interaction",
|
|
3612
|
+
"scroll-behavior": "interaction",
|
|
3613
|
+
"scroll-snap-type": "interaction",
|
|
3614
|
+
// Reset (jarang dipakai langsung tapi handle untuk completeness)
|
|
3615
|
+
"box-sizing": "reset",
|
|
3616
|
+
appearance: "reset",
|
|
3617
|
+
all: "reset"
|
|
3618
|
+
};
|
|
3619
|
+
function classifyNode(node) {
|
|
3620
|
+
if (node.modifier?.startsWith("@")) return "responsive";
|
|
3621
|
+
const declarations = node.declaration.split(";").map((d) => d.trim()).filter(Boolean);
|
|
3622
|
+
const firstProp = declarations[0]?.split(":")[0]?.trim();
|
|
3623
|
+
if (!firstProp) return "unknown";
|
|
3624
|
+
if (PROPERTY_BUCKET_MAP[firstProp]) return PROPERTY_BUCKET_MAP[firstProp];
|
|
3625
|
+
for (const [prefix, bucket] of Object.entries(PROPERTY_BUCKET_MAP)) {
|
|
3626
|
+
if (firstProp.startsWith(prefix)) return bucket;
|
|
3627
|
+
}
|
|
3628
|
+
return "unknown";
|
|
3629
|
+
}
|
|
3630
|
+
var BucketEngine = class {
|
|
3631
|
+
constructor() {
|
|
3632
|
+
this.buckets = /* @__PURE__ */ new Map();
|
|
3633
|
+
for (const b of BUCKET_ORDER) {
|
|
3634
|
+
this.buckets.set(b, /* @__PURE__ */ new Map());
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
/**
|
|
3638
|
+
* Tambah StyleNode ke bucket yang tepat.
|
|
3639
|
+
* Idempotent — atomic class yang sama tidak akan duplikat.
|
|
3640
|
+
*/
|
|
3641
|
+
add(node) {
|
|
3642
|
+
const bucket = classifyNode(node);
|
|
3643
|
+
this.buckets.get(bucket).set(node.atomicClass, node);
|
|
3644
|
+
}
|
|
3645
|
+
/**
|
|
3646
|
+
* Hapus node dari bucket (untuk incremental update).
|
|
3647
|
+
*/
|
|
3648
|
+
remove(atomicClass) {
|
|
3649
|
+
for (const bucket of this.buckets.values()) {
|
|
3650
|
+
if (bucket.delete(atomicClass)) break;
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
/**
|
|
3654
|
+
* Apply CssDiff dari incremental engine.
|
|
3655
|
+
*/
|
|
3656
|
+
applyDiff(diff) {
|
|
3657
|
+
for (const node of diff.added) this.add(node);
|
|
3658
|
+
for (const cls of diff.removed) this.remove(cls);
|
|
3659
|
+
}
|
|
3660
|
+
/**
|
|
3661
|
+
* Emit seluruh CSS dalam urutan bucket yang deterministic.
|
|
3662
|
+
*
|
|
3663
|
+
* @param comments - Tambahkan komentar section per bucket. Default: true
|
|
3664
|
+
* @returns CSS string yang siap di-write ke file
|
|
3665
|
+
*/
|
|
3666
|
+
emit(comments = true) {
|
|
3667
|
+
const sections = [];
|
|
3668
|
+
for (const bucketName of BUCKET_ORDER) {
|
|
3669
|
+
const nodes = this.buckets.get(bucketName);
|
|
3670
|
+
if (nodes.size === 0) continue;
|
|
3671
|
+
const rules = [];
|
|
3672
|
+
for (const node of nodes.values()) {
|
|
3673
|
+
rules.push(nodeToCSS2(node));
|
|
3674
|
+
}
|
|
3675
|
+
if (rules.length === 0) continue;
|
|
3676
|
+
if (comments) {
|
|
3677
|
+
sections.push(`/* \u2500\u2500 ${bucketName} \u2500\u2500 */`);
|
|
3678
|
+
}
|
|
3679
|
+
sections.push(...rules);
|
|
3680
|
+
}
|
|
3681
|
+
return sections.join("\n");
|
|
3682
|
+
}
|
|
3683
|
+
/**
|
|
3684
|
+
* Emit dengan @layer CSS untuk native browser layering.
|
|
3685
|
+
* Lebih powerful — browser respects layer order untuk specificity.
|
|
3686
|
+
*
|
|
3687
|
+
* @example output:
|
|
3688
|
+
* @layer tw-layout, tw-spacing, tw-visual, tw-responsive;
|
|
3689
|
+
* @layer tw-layout { .tw-a1 { display: flex } }
|
|
3690
|
+
*/
|
|
3691
|
+
emitLayered() {
|
|
3692
|
+
const layerNames = BUCKET_ORDER.filter(
|
|
3693
|
+
(b) => b !== "unknown" && this.buckets.get(b).size > 0
|
|
3694
|
+
).map((b) => `tw-${b}`);
|
|
3695
|
+
if (layerNames.length === 0) return "";
|
|
3696
|
+
const parts = [`@layer ${layerNames.join(", ")};`, ""];
|
|
3697
|
+
for (const bucketName of BUCKET_ORDER) {
|
|
3698
|
+
const nodes = this.buckets.get(bucketName);
|
|
3699
|
+
if (nodes.size === 0) continue;
|
|
3700
|
+
const rules = Array.from(nodes.values()).map(nodeToCSS2).join("\n ");
|
|
3701
|
+
parts.push(`@layer tw-${bucketName} {
|
|
3702
|
+
${rules}
|
|
3703
|
+
}`);
|
|
3704
|
+
}
|
|
3705
|
+
return parts.join("\n");
|
|
3706
|
+
}
|
|
3707
|
+
/** Semua nodes dari semua bucket (untuk full registry access) */
|
|
3708
|
+
allNodes() {
|
|
3709
|
+
const all = [];
|
|
3710
|
+
for (const bucket of this.buckets.values()) {
|
|
3711
|
+
for (const node of bucket.values()) {
|
|
3712
|
+
all.push(node);
|
|
3713
|
+
}
|
|
3714
|
+
}
|
|
3715
|
+
return all;
|
|
3716
|
+
}
|
|
3717
|
+
/** Stats per bucket */
|
|
3718
|
+
stats() {
|
|
3719
|
+
const perBucket = {};
|
|
3720
|
+
let total = 0;
|
|
3721
|
+
for (const [name, nodes] of this.buckets) {
|
|
3722
|
+
perBucket[name] = nodes.size;
|
|
3723
|
+
total += nodes.size;
|
|
3724
|
+
}
|
|
3725
|
+
return { totalNodes: total, perBucket };
|
|
3726
|
+
}
|
|
3727
|
+
/** Clear semua bucket */
|
|
3728
|
+
clear() {
|
|
3729
|
+
for (const bucket of this.buckets.values()) {
|
|
3730
|
+
bucket.clear();
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
};
|
|
3734
|
+
function bucketSort(nodes) {
|
|
3735
|
+
const bucketIndex = Object.fromEntries(BUCKET_ORDER.map((b, i) => [b, i]));
|
|
3736
|
+
return [...nodes].sort((a, b) => {
|
|
3737
|
+
const ai = bucketIndex[classifyNode(a)];
|
|
3738
|
+
const bi = bucketIndex[classifyNode(b)];
|
|
3739
|
+
return ai - bi;
|
|
3740
|
+
});
|
|
3741
|
+
}
|
|
3742
|
+
function nodeToCSS2(node) {
|
|
3743
|
+
const { atomicClass, declaration, modifier } = node;
|
|
3744
|
+
if (!modifier) {
|
|
3745
|
+
return `.${atomicClass}{${declaration}}`;
|
|
3746
|
+
}
|
|
3747
|
+
if (modifier.startsWith("@")) {
|
|
3748
|
+
return `${modifier}{.${atomicClass}{${declaration}}}`;
|
|
3749
|
+
}
|
|
3750
|
+
return `.${atomicClass}${modifier}{${declaration}}`;
|
|
3751
|
+
}
|
|
3752
|
+
function detectConflicts(nodes) {
|
|
3753
|
+
const seen = /* @__PURE__ */ new Map();
|
|
3754
|
+
const warnings = [];
|
|
3755
|
+
for (const node of nodes) {
|
|
3756
|
+
if (node.modifier?.startsWith("@")) continue;
|
|
3757
|
+
const firstProp = node.declaration.split(":")[0]?.trim();
|
|
3758
|
+
if (!firstProp) continue;
|
|
3759
|
+
const key = `${firstProp}::${node.modifier ?? ""}`;
|
|
3760
|
+
const prev = seen.get(key);
|
|
3761
|
+
if (prev) {
|
|
3762
|
+
warnings.push({
|
|
3763
|
+
property: firstProp,
|
|
3764
|
+
classes: [prev.twClass, node.twClass],
|
|
3765
|
+
bucket: classifyNode(node),
|
|
3766
|
+
message: `Possible conflict: "${prev.twClass}" and "${node.twClass}" both set "${firstProp}"`
|
|
3767
|
+
});
|
|
3768
|
+
} else {
|
|
3769
|
+
seen.set(key, node);
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
return warnings;
|
|
3773
|
+
}
|
|
3774
|
+
var _bucketEngine = null;
|
|
3775
|
+
function getBucketEngine() {
|
|
3776
|
+
if (!_bucketEngine) _bucketEngine = new BucketEngine();
|
|
3777
|
+
return _bucketEngine;
|
|
3778
|
+
}
|
|
3779
|
+
function resetBucketEngine() {
|
|
3780
|
+
_bucketEngine = null;
|
|
3781
|
+
}
|
|
3782
|
+
|
|
3783
|
+
// packages/compiler/src/index.ts
|
|
3784
|
+
init_atomicCss();
|
|
3785
|
+
|
|
3786
|
+
// packages/compiler/src/context.ts
|
|
3787
|
+
var CompileContext = class {
|
|
3788
|
+
constructor(input) {
|
|
3789
|
+
this.filepath = input.filepath;
|
|
3790
|
+
this.source = input.source;
|
|
3791
|
+
this.options = input.options;
|
|
3792
|
+
this.result = null;
|
|
3793
|
+
this.done = false;
|
|
3794
|
+
this.engine = "none";
|
|
3795
|
+
}
|
|
3796
|
+
};
|
|
3797
|
+
init_nativeBridge();
|
|
3798
|
+
|
|
3799
|
+
// packages/compiler/src/pipeline.ts
|
|
3800
|
+
var Pipeline = class {
|
|
3801
|
+
constructor() {
|
|
3802
|
+
this.steps = [];
|
|
3803
|
+
}
|
|
3804
|
+
use(step) {
|
|
3805
|
+
this.steps.push(step);
|
|
3806
|
+
return this;
|
|
3807
|
+
}
|
|
3808
|
+
run(ctx) {
|
|
3809
|
+
for (const step of this.steps) {
|
|
3810
|
+
step(ctx);
|
|
3811
|
+
if (ctx.done) break;
|
|
3812
|
+
}
|
|
3813
|
+
return ctx;
|
|
3814
|
+
}
|
|
3815
|
+
};
|
|
3816
|
+
|
|
3817
|
+
// packages/compiler/src/coreCompiler.ts
|
|
3818
|
+
var MAX_CACHE_ENTRIES = 512;
|
|
3819
|
+
var compileCache = /* @__PURE__ */ new Map();
|
|
3820
|
+
function makeCacheKey(input) {
|
|
3821
|
+
const options = {
|
|
3822
|
+
mode: input.options.mode,
|
|
3823
|
+
autoClientBoundary: input.options.autoClientBoundary,
|
|
3824
|
+
addDataAttr: input.options.addDataAttr,
|
|
3825
|
+
hoist: input.options.hoist,
|
|
3826
|
+
filename: input.options.filename ?? input.filepath,
|
|
3827
|
+
deadStyleElimination: input.options.deadStyleElimination
|
|
3828
|
+
};
|
|
3829
|
+
return crypto.createHash("sha1").update(input.filepath).update("").update(input.source).update("").update(JSON.stringify(options)).digest("hex");
|
|
3830
|
+
}
|
|
3831
|
+
function cloneTransformResult(result) {
|
|
3832
|
+
return {
|
|
3833
|
+
code: result.code,
|
|
3834
|
+
classes: [...result.classes],
|
|
3835
|
+
changed: result.changed,
|
|
3836
|
+
rsc: result.rsc ? {
|
|
3837
|
+
isServer: result.rsc.isServer,
|
|
3838
|
+
needsClientDirective: result.rsc.needsClientDirective,
|
|
3839
|
+
clientReasons: [...result.rsc.clientReasons]
|
|
3840
|
+
} : void 0
|
|
3841
|
+
};
|
|
3842
|
+
}
|
|
3843
|
+
function cloneCoreCompileResult(result) {
|
|
3844
|
+
return {
|
|
3845
|
+
result: cloneTransformResult(result.result),
|
|
3846
|
+
engine: result.engine,
|
|
3847
|
+
cacheHit: result.cacheHit,
|
|
3848
|
+
metadata: result.metadata ? result.metadata.map((m) => ({ ...m })) : void 0,
|
|
3849
|
+
css: result.css
|
|
3850
|
+
};
|
|
3851
|
+
}
|
|
3852
|
+
function persistCache(key, value) {
|
|
3853
|
+
compileCache.set(key, { ...value, cacheHit: false });
|
|
3854
|
+
if (compileCache.size <= MAX_CACHE_ENTRIES) return;
|
|
3855
|
+
const oldestKey = compileCache.keys().next().value;
|
|
3856
|
+
if (oldestKey) compileCache.delete(oldestKey);
|
|
3857
|
+
}
|
|
3858
|
+
function createPassthrough(source) {
|
|
3859
|
+
return { code: source, classes: [], changed: false };
|
|
3860
|
+
}
|
|
3861
|
+
var CompilerCore = class {
|
|
3862
|
+
constructor() {
|
|
3863
|
+
this.pipeline = new Pipeline().use((ctx) => this.nativeStep(ctx));
|
|
3864
|
+
}
|
|
3865
|
+
compile(input) {
|
|
3866
|
+
const cacheKey = makeCacheKey(input);
|
|
3867
|
+
const cached = compileCache.get(cacheKey);
|
|
3868
|
+
if (cached) {
|
|
3869
|
+
const hit = cloneCoreCompileResult(cached);
|
|
3870
|
+
hit.cacheHit = true;
|
|
3871
|
+
return hit;
|
|
3872
|
+
}
|
|
3873
|
+
const ctx = new CompileContext(input);
|
|
3874
|
+
this.pipeline.run(ctx);
|
|
3875
|
+
const result = ctx.result ?? createPassthrough(input.source);
|
|
3876
|
+
let cssOutput;
|
|
3877
|
+
if (ctx.options.deadStyleElimination && result.classes.length > 0) {
|
|
3878
|
+
cssOutput = this.runDeadStyleElimination(result.classes, input.options);
|
|
3879
|
+
}
|
|
3880
|
+
const compiled = {
|
|
3881
|
+
result,
|
|
3882
|
+
engine: ctx.engine,
|
|
3883
|
+
cacheHit: false,
|
|
3884
|
+
metadata: ctx.metadata,
|
|
3885
|
+
css: cssOutput
|
|
3886
|
+
};
|
|
3887
|
+
persistCache(cacheKey, compiled);
|
|
3888
|
+
return cloneCoreCompileResult(compiled);
|
|
3889
|
+
}
|
|
3890
|
+
runDeadStyleElimination(classes, options) {
|
|
3891
|
+
if (classes.length === 0) return "";
|
|
3892
|
+
const native = getNativeBridge();
|
|
3893
|
+
if (native?.analyzeClassesNative) {
|
|
3894
|
+
try {
|
|
3895
|
+
const filesJson = JSON.stringify([{ file: "compiled", classes }]);
|
|
3896
|
+
const analysis = native.analyzeClassesNative(filesJson, process.cwd(), 0);
|
|
3897
|
+
if (analysis && analysis.safelist) {
|
|
3898
|
+
const deadClasses = /* @__PURE__ */ new Set();
|
|
3899
|
+
const safelistSet = new Set(analysis.safelist);
|
|
3900
|
+
for (const cls of classes) {
|
|
3901
|
+
if (!safelistSet.has(cls)) {
|
|
3902
|
+
deadClasses.add(cls);
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
if (deadClasses.size > 0) {
|
|
3906
|
+
return "";
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
3909
|
+
} catch {
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
return "";
|
|
3913
|
+
}
|
|
3914
|
+
/**
|
|
3915
|
+
* v5: Native step now THROWS if native binding is unavailable.
|
|
3916
|
+
* Previously returned early to allow JS fallback.
|
|
3917
|
+
*/
|
|
3918
|
+
nativeStep(ctx) {
|
|
3919
|
+
const native = getNativeBridge();
|
|
3920
|
+
if (!native?.transformSourceNative) {
|
|
3921
|
+
throw new Error(
|
|
3922
|
+
`[tailwind-styled/compiler v5] transformSourceNative is required but not available.
|
|
3923
|
+
Please ensure the native module is properly built with transform support.`
|
|
3924
|
+
);
|
|
3925
|
+
}
|
|
3926
|
+
const opts = {};
|
|
3927
|
+
if (ctx.options.mode) opts.mode = ctx.options.mode;
|
|
3928
|
+
if (ctx.options.filename ?? ctx.filepath) opts.filename = ctx.options.filename ?? ctx.filepath;
|
|
3929
|
+
const raw = native.transformSourceNative(ctx.source, opts);
|
|
3930
|
+
if (raw === null) {
|
|
3931
|
+
throw new Error(
|
|
3932
|
+
`[tailwind-styled/compiler v5] Native transform returned null for: ${ctx.filepath}
|
|
3933
|
+
This indicates an issue with the native module.`
|
|
3934
|
+
);
|
|
3935
|
+
}
|
|
3936
|
+
const adapted = adaptNativeResult(raw);
|
|
3937
|
+
ctx.result = adapted;
|
|
3938
|
+
ctx.metadata = adapted.metadata;
|
|
3939
|
+
ctx.engine = "native";
|
|
3940
|
+
ctx.done = true;
|
|
3941
|
+
}
|
|
3942
|
+
/**
|
|
3943
|
+
* v5: JS pipeline has been removed.
|
|
3944
|
+
* Previously used as fallback when native was unavailable.
|
|
3945
|
+
*
|
|
3946
|
+
* @throws Error always - JS pipeline is no longer supported in v5
|
|
3947
|
+
* @deprecated JS pipeline was removed in v5
|
|
3948
|
+
*/
|
|
3949
|
+
jsStep(ctx) {
|
|
3950
|
+
throw new Error(
|
|
3951
|
+
`[tailwind-styled/compiler v5] JS pipeline is no longer supported.
|
|
3952
|
+
The native binding is required for all transformations.`
|
|
3953
|
+
);
|
|
3954
|
+
}
|
|
3955
|
+
};
|
|
3956
|
+
var compilerCore = new CompilerCore();
|
|
3957
|
+
function compileWithCore(input) {
|
|
3958
|
+
return compilerCore.compile(input);
|
|
3959
|
+
}
|
|
3960
|
+
function resetCompileCache() {
|
|
3961
|
+
compileCache.clear();
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3964
|
+
// packages/compiler/src/routeCssCollector.ts
|
|
3965
|
+
var _collector = {
|
|
3966
|
+
files: /* @__PURE__ */ new Map(),
|
|
3967
|
+
routes: /* @__PURE__ */ new Map(),
|
|
3968
|
+
global: /* @__PURE__ */ new Set()
|
|
3969
|
+
};
|
|
3970
|
+
function registerFileClasses(filepath, classes) {
|
|
3971
|
+
if (!_collector.files.has(filepath)) {
|
|
3972
|
+
_collector.files.set(filepath, /* @__PURE__ */ new Set());
|
|
3973
|
+
}
|
|
3974
|
+
const fileSet = _collector.files.get(filepath);
|
|
3975
|
+
classes.forEach((c) => fileSet.add(c));
|
|
3976
|
+
const route = fileToRoute(filepath);
|
|
3977
|
+
if (route) {
|
|
3978
|
+
if (!_collector.routes.has(route)) {
|
|
3979
|
+
_collector.routes.set(route, /* @__PURE__ */ new Set());
|
|
3980
|
+
}
|
|
3981
|
+
_collector.routes.get(route).add(filepath);
|
|
3982
|
+
}
|
|
3983
|
+
}
|
|
3984
|
+
function registerGlobalClasses(classes) {
|
|
3985
|
+
classes.forEach((c) => _collector.global.add(c));
|
|
3986
|
+
}
|
|
3987
|
+
function getRouteClasses(route) {
|
|
3988
|
+
const result = new Set(_collector.global);
|
|
3989
|
+
const routeFiles = _collector.routes.get(route) ?? /* @__PURE__ */ new Set();
|
|
3990
|
+
for (const filepath of routeFiles) {
|
|
3991
|
+
const fileClasses = _collector.files.get(filepath) ?? /* @__PURE__ */ new Set();
|
|
3992
|
+
fileClasses.forEach((c) => result.add(c));
|
|
3993
|
+
}
|
|
3994
|
+
return result;
|
|
3995
|
+
}
|
|
3996
|
+
function getAllRoutes() {
|
|
3997
|
+
return Array.from(_collector.routes.keys()).sort();
|
|
3998
|
+
}
|
|
3999
|
+
function getCollector() {
|
|
4000
|
+
return _collector;
|
|
4001
|
+
}
|
|
4002
|
+
function resetCollector() {
|
|
4003
|
+
_collector = {
|
|
4004
|
+
files: /* @__PURE__ */ new Map(),
|
|
4005
|
+
routes: /* @__PURE__ */ new Map(),
|
|
4006
|
+
global: /* @__PURE__ */ new Set()
|
|
4007
|
+
};
|
|
4008
|
+
}
|
|
4009
|
+
function fileToRoute(filepath) {
|
|
4010
|
+
const normalized = filepath.replace(/\\/g, "/");
|
|
4011
|
+
if (normalized.includes("/layout.") || normalized.includes("/loading.") || normalized.includes("/error.")) {
|
|
4012
|
+
return "__global";
|
|
4013
|
+
}
|
|
4014
|
+
const pageMatch = normalized.match(/\/app\/(.+?)\/page\.[tj]sx?$/);
|
|
4015
|
+
if (pageMatch) return `/${pageMatch[1]}`;
|
|
4016
|
+
const rootPage = normalized.match(/\/app\/page\.[tj]sx?$/);
|
|
4017
|
+
if (rootPage) return "/";
|
|
4018
|
+
const pagesMatch = normalized.match(/\/pages\/(.+?)\.[tj]sx?$/);
|
|
4019
|
+
if (pagesMatch) {
|
|
4020
|
+
const route = pagesMatch[1].replace(/\/index$/, "");
|
|
4021
|
+
return `/${route}`;
|
|
4022
|
+
}
|
|
4023
|
+
if (normalized.includes("/components/") || normalized.includes("/ui/") || normalized.includes("/shared/")) {
|
|
4024
|
+
return "__global";
|
|
4025
|
+
}
|
|
4026
|
+
return null;
|
|
4027
|
+
}
|
|
4028
|
+
function getCollectorSummary() {
|
|
4029
|
+
const routes = getAllRoutes();
|
|
4030
|
+
const totalFiles = _collector.files.size;
|
|
4031
|
+
const totalGlobal = _collector.global.size;
|
|
4032
|
+
const lines = [
|
|
4033
|
+
`[tailwind-styled-v4] Route CSS Summary:`,
|
|
4034
|
+
` Files processed: ${totalFiles}`,
|
|
4035
|
+
` Global classes: ${totalGlobal}`,
|
|
4036
|
+
` Routes found: ${routes.length}`,
|
|
4037
|
+
...routes.map((r) => {
|
|
4038
|
+
const cls = getRouteClasses(r).size;
|
|
4039
|
+
return ` ${r} \u2192 ${cls} classes`;
|
|
4040
|
+
})
|
|
4041
|
+
];
|
|
4042
|
+
return lines.join("\n");
|
|
4043
|
+
}
|
|
4044
|
+
|
|
4045
|
+
// packages/compiler/src/loaderCore.ts
|
|
4046
|
+
var SKIP_PATHS = ["node_modules", ".next", ".rspack-dist", ".turbo", "dist/", "out/"];
|
|
4047
|
+
function shouldSkipFile(filepath) {
|
|
4048
|
+
return SKIP_PATHS.some((p) => filepath.includes(p)) || !/\.[jt]sx?$/.test(filepath);
|
|
4049
|
+
}
|
|
4050
|
+
function runLoaderTransform(ctx) {
|
|
4051
|
+
const { filepath, source, options } = ctx;
|
|
4052
|
+
const passthrough = { code: source, changed: false, classes: [] };
|
|
4053
|
+
if (shouldSkipFile(filepath)) return passthrough;
|
|
4054
|
+
try {
|
|
4055
|
+
if (options.incremental !== false) {
|
|
4056
|
+
const engine = getIncrementalEngine({ verbose: options.verbose });
|
|
4057
|
+
const precheck = engine.processFile(filepath, source, []);
|
|
4058
|
+
if (!precheck.changed) return passthrough;
|
|
4059
|
+
}
|
|
4060
|
+
const compiled = compileWithCore({
|
|
4061
|
+
filepath,
|
|
4062
|
+
source,
|
|
4063
|
+
options: { ...options, filename: filepath }
|
|
4064
|
+
});
|
|
4065
|
+
if (!compiled.result.changed) return passthrough;
|
|
4066
|
+
return finalize(
|
|
4067
|
+
compiled.result,
|
|
4068
|
+
filepath,
|
|
4069
|
+
options,
|
|
4070
|
+
compiled.engine,
|
|
4071
|
+
compiled.cacheHit,
|
|
4072
|
+
compiled.metadata
|
|
4073
|
+
);
|
|
4074
|
+
} catch (err) {
|
|
4075
|
+
if (process.env.NODE_ENV !== "production") {
|
|
4076
|
+
const name = filepath.split(/[/\\]/).pop();
|
|
4077
|
+
console.warn(`[tailwind-styled] Transform failed for ${name}:`, err);
|
|
4078
|
+
}
|
|
4079
|
+
return passthrough;
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
function finalize(result, filepath, options, engine, cacheHit, metadata) {
|
|
4083
|
+
if (!result.changed) {
|
|
4084
|
+
return { code: result.code, changed: false, classes: [] };
|
|
4085
|
+
}
|
|
4086
|
+
if (options.routeCss && result.classes.length > 0) {
|
|
4087
|
+
registerFileClasses(filepath, result.classes);
|
|
4088
|
+
}
|
|
4089
|
+
if (options.incremental !== false) {
|
|
4090
|
+
try {
|
|
4091
|
+
const engineInst = getIncrementalEngine({ verbose: options.verbose });
|
|
4092
|
+
const nodes = parseClassesToNodes(result.classes);
|
|
4093
|
+
const diff = engineInst.processFile(filepath, result.code, nodes);
|
|
4094
|
+
getBucketEngine().applyDiff(diff.diff);
|
|
4095
|
+
} catch {
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
if (options.verbose) {
|
|
4099
|
+
const env = result.rsc?.isServer ? "server" : "client";
|
|
4100
|
+
const name = filepath.split(/[/\\]/).pop();
|
|
4101
|
+
const pathHint = result.rsc ? ` (${env})` : "";
|
|
4102
|
+
const cacheText = cacheHit ? " cache-hit" : "";
|
|
4103
|
+
const metaText = metadata?.length ? ` [${metadata.length} compound]` : "";
|
|
4104
|
+
console.log(
|
|
4105
|
+
`[tailwind-styled] ${name} -> ${result.classes.length} classes${pathHint} [${engine}${cacheText}]${metaText}`
|
|
4106
|
+
);
|
|
4107
|
+
}
|
|
4108
|
+
return {
|
|
4109
|
+
code: result.code,
|
|
4110
|
+
changed: result.changed,
|
|
4111
|
+
classes: result.classes,
|
|
4112
|
+
rsc: result.rsc,
|
|
4113
|
+
engine,
|
|
4114
|
+
cacheHit,
|
|
4115
|
+
metadata
|
|
4116
|
+
};
|
|
4117
|
+
}
|
|
4118
|
+
var CONFIG_FILES = [
|
|
4119
|
+
"tailwind.config.ts",
|
|
4120
|
+
"tailwind.config.js",
|
|
4121
|
+
"tailwind.config.mjs",
|
|
4122
|
+
"tailwind.config.cjs"
|
|
4123
|
+
];
|
|
4124
|
+
var _cachedConfig = null;
|
|
4125
|
+
var _cachedCwd = "";
|
|
4126
|
+
function loadTailwindConfig(cwd = process.cwd()) {
|
|
4127
|
+
if (_cachedConfig && _cachedCwd === cwd) return _cachedConfig;
|
|
4128
|
+
_cachedCwd = cwd;
|
|
4129
|
+
for (const file of CONFIG_FILES) {
|
|
4130
|
+
const fullPath = path7__default.default.join(cwd, file);
|
|
4131
|
+
if (fs3__default.default.existsSync(fullPath)) {
|
|
4132
|
+
try {
|
|
4133
|
+
const mod = __require(fullPath);
|
|
4134
|
+
const config = mod.default ?? mod;
|
|
4135
|
+
_cachedConfig = config;
|
|
4136
|
+
console.log(`[tailwind-styled-v4] Using config: ${file}`);
|
|
4137
|
+
return config;
|
|
4138
|
+
} catch {
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
}
|
|
4142
|
+
console.log("[tailwind-styled-v4] No tailwind config found \u2192 using built-in preset");
|
|
4143
|
+
const { defaultPreset: defaultPreset2 } = (init_defaultPreset(), __toCommonJS(defaultPreset_exports));
|
|
4144
|
+
_cachedConfig = defaultPreset2;
|
|
4145
|
+
return defaultPreset2;
|
|
4146
|
+
}
|
|
4147
|
+
function getContentPaths(config, cwd = process.cwd()) {
|
|
4148
|
+
const paths = [];
|
|
4149
|
+
if (Array.isArray(config.content)) {
|
|
4150
|
+
for (const item of config.content) {
|
|
4151
|
+
if (typeof item === "string") paths.push(item);
|
|
4152
|
+
else if (typeof item === "object" && item.raw) ;
|
|
4153
|
+
}
|
|
4154
|
+
return paths;
|
|
4155
|
+
}
|
|
4156
|
+
if (config.content?.files) {
|
|
4157
|
+
return config.content.files.filter((f) => typeof f === "string");
|
|
4158
|
+
}
|
|
4159
|
+
return ["src", "app", "pages", "components"].filter((d) => fs3__default.default.existsSync(path7__default.default.join(cwd, d))).map((d) => `./${d}/**/*.{tsx,ts,jsx,js}`);
|
|
4160
|
+
}
|
|
4161
|
+
function invalidateConfigCache() {
|
|
4162
|
+
_cachedConfig = null;
|
|
4163
|
+
_cachedCwd = "";
|
|
4164
|
+
}
|
|
4165
|
+
function isZeroConfig(cwd = process.cwd()) {
|
|
4166
|
+
return !CONFIG_FILES.some((f) => fs3__default.default.existsSync(path7__default.default.join(cwd, f)));
|
|
4167
|
+
}
|
|
4168
|
+
function bootstrapZeroConfig(cwd = process.cwd()) {
|
|
4169
|
+
let generatedConfig = false;
|
|
4170
|
+
let generatedCss = false;
|
|
4171
|
+
generatedConfig = false;
|
|
4172
|
+
const cssPaths = [
|
|
4173
|
+
"src/app/globals.css",
|
|
4174
|
+
"app/globals.css",
|
|
4175
|
+
"src/index.css",
|
|
4176
|
+
"src/styles/globals.css"
|
|
4177
|
+
];
|
|
4178
|
+
const hasGlobalCss = cssPaths.some((p) => fs3__default.default.existsSync(path7__default.default.join(cwd, p)));
|
|
4179
|
+
if (!hasGlobalCss) {
|
|
4180
|
+
const { defaultGlobalCss: defaultGlobalCss2 } = (init_defaultPreset(), __toCommonJS(defaultPreset_exports));
|
|
4181
|
+
const appDir = fs3__default.default.existsSync(path7__default.default.join(cwd, "src/app")) ? "src/app" : fs3__default.default.existsSync(path7__default.default.join(cwd, "app")) ? "app" : "src";
|
|
4182
|
+
const cssPath = path7__default.default.join(cwd, appDir, "globals.css");
|
|
4183
|
+
if (fs3__default.default.existsSync(path7__default.default.dirname(cssPath))) {
|
|
4184
|
+
fs3__default.default.writeFileSync(cssPath, defaultGlobalCss2);
|
|
4185
|
+
generatedCss = true;
|
|
4186
|
+
console.log(`[tailwind-styled-v4] Generated ${cssPath}`);
|
|
4187
|
+
}
|
|
4188
|
+
}
|
|
4189
|
+
return { generatedConfig, generatedCss };
|
|
4190
|
+
}
|
|
4191
|
+
|
|
4192
|
+
// packages/compiler/src/index.ts
|
|
4193
|
+
init_nativeBridge();
|
|
4194
|
+
var _binding2;
|
|
4195
|
+
function getBinding2() {
|
|
4196
|
+
if (_binding2 !== void 0) {
|
|
4197
|
+
if (_binding2 === null) {
|
|
4198
|
+
throw new Error(
|
|
4199
|
+
`[tailwind-styled/compiler v5] Native CSS binding is required but not available.
|
|
4200
|
+
Please ensure the native module is properly built.`
|
|
4201
|
+
);
|
|
4202
|
+
}
|
|
4203
|
+
return _binding2;
|
|
4204
|
+
}
|
|
4205
|
+
if (process.env.TWS_NO_NATIVE === "1") {
|
|
4206
|
+
_binding2 = null;
|
|
4207
|
+
throw new Error(
|
|
4208
|
+
`[tailwind-styled/compiler v5] Native binding is required.
|
|
4209
|
+
The TWS_NO_NATIVE environment variable is set, which disables native binding.`
|
|
4210
|
+
);
|
|
4211
|
+
}
|
|
4212
|
+
const req = typeof __require === "function" ? __require : module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('compiler.js', document.baseURI).href)));
|
|
4213
|
+
const candidates = [
|
|
4214
|
+
path7__default.default.resolve(process.cwd(), "native", "tailwind_styled_parser.node"),
|
|
4215
|
+
path7__default.default.resolve(__dirname, "..", "..", "..", "native", "tailwind_styled_parser.node"),
|
|
4216
|
+
path7__default.default.resolve(__dirname, "..", "..", "..", "..", "native", "tailwind_styled_parser.node")
|
|
4217
|
+
];
|
|
4218
|
+
for (const c of candidates) {
|
|
4219
|
+
try {
|
|
4220
|
+
const mod = req(c);
|
|
4221
|
+
if (mod?.compileCss) {
|
|
4222
|
+
_binding2 = mod;
|
|
4223
|
+
return _binding2;
|
|
4224
|
+
}
|
|
4225
|
+
} catch {
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
_binding2 = null;
|
|
4229
|
+
throw new Error(
|
|
4230
|
+
`[tailwind-styled/compiler v5] Native CSS binding not found.
|
|
4231
|
+
Tried loading from:
|
|
4232
|
+
` + candidates.map((c) => ` - ${c}`).join("\n") + `
|
|
4233
|
+
|
|
4234
|
+
Please build the native module.`
|
|
4235
|
+
);
|
|
4236
|
+
}
|
|
4237
|
+
function compileCssNative(classes, prefix = null) {
|
|
4238
|
+
const binding = getBinding2();
|
|
4239
|
+
const r = binding.compileCss(classes, prefix);
|
|
4240
|
+
return { ...r, engine: "rust" };
|
|
4241
|
+
}
|
|
4242
|
+
function astExtractClassesNative(source, filename) {
|
|
4243
|
+
const binding = getBinding2();
|
|
4244
|
+
const r = binding.astExtractClasses(source, filename);
|
|
4245
|
+
return { ...r, engine: "rust" };
|
|
4246
|
+
}
|
|
4247
|
+
var SCAN_EXTENSIONS2 = [".tsx", ".ts", ".jsx", ".js"];
|
|
4248
|
+
function scanDir(dir, files = []) {
|
|
4249
|
+
if (!fs3__default.default.existsSync(dir)) return files;
|
|
4250
|
+
const entries = fs3__default.default.readdirSync(dir, { withFileTypes: true });
|
|
4251
|
+
for (const entry of entries) {
|
|
4252
|
+
if (entry.name === "node_modules" || entry.name === ".next" || entry.name === "dist") continue;
|
|
4253
|
+
const fullPath = path7__default.default.join(dir, entry.name);
|
|
4254
|
+
if (entry.isDirectory()) {
|
|
4255
|
+
scanDir(fullPath, files);
|
|
4256
|
+
} else if (SCAN_EXTENSIONS2.some((ext) => entry.name.endsWith(ext))) {
|
|
4257
|
+
files.push(fullPath);
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
return files;
|
|
4261
|
+
}
|
|
4262
|
+
function generateSafelist(scanDirs, outputPath = ".tailwind-styled-safelist.json", cwd = process.cwd()) {
|
|
4263
|
+
const allClasses = /* @__PURE__ */ new Set();
|
|
4264
|
+
for (const dir of scanDirs) {
|
|
4265
|
+
const absDir = path7__default.default.isAbsolute(dir) ? dir : path7__default.default.resolve(cwd, dir);
|
|
4266
|
+
const files = scanDir(absDir);
|
|
4267
|
+
for (const file of files) {
|
|
4268
|
+
try {
|
|
4269
|
+
const source = fs3__default.default.readFileSync(file, "utf-8");
|
|
4270
|
+
const classes = extractAllClasses(source);
|
|
4271
|
+
classes.forEach((c) => allClasses.add(c));
|
|
4272
|
+
} catch {
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
const sorted = Array.from(allClasses).sort();
|
|
4277
|
+
const absOutput = path7__default.default.isAbsolute(outputPath) ? outputPath : path7__default.default.resolve(cwd, outputPath);
|
|
4278
|
+
fs3__default.default.writeFileSync(absOutput, JSON.stringify(sorted, null, 2));
|
|
4279
|
+
console.log(`[tailwind-styled-v4] Safelist: ${sorted.length} classes \u2192 ${absOutput}`);
|
|
4280
|
+
return sorted;
|
|
4281
|
+
}
|
|
4282
|
+
function loadSafelist(safelistPath) {
|
|
4283
|
+
try {
|
|
4284
|
+
const content = fs3__default.default.readFileSync(safelistPath, "utf-8");
|
|
4285
|
+
return JSON.parse(content);
|
|
4286
|
+
} catch {
|
|
4287
|
+
return [];
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
function generateSafelistCss(scanDirs, outputPath = "src/app/__tw-safelist.css", cwd = process.cwd()) {
|
|
4291
|
+
const allClasses = /* @__PURE__ */ new Set();
|
|
4292
|
+
for (const dir of scanDirs) {
|
|
4293
|
+
const absDir = path7__default.default.isAbsolute(dir) ? dir : path7__default.default.resolve(cwd, dir);
|
|
4294
|
+
const files = scanDir(absDir);
|
|
4295
|
+
for (const file of files) {
|
|
4296
|
+
try {
|
|
4297
|
+
const source = fs3__default.default.readFileSync(file, "utf-8");
|
|
4298
|
+
const classes = extractAllClasses(source);
|
|
4299
|
+
classes.forEach((c) => allClasses.add(c));
|
|
4300
|
+
} catch {
|
|
4301
|
+
}
|
|
4302
|
+
}
|
|
4303
|
+
}
|
|
4304
|
+
const sorted = Array.from(allClasses).sort();
|
|
4305
|
+
const absOutput = path7__default.default.isAbsolute(outputPath) ? outputPath : path7__default.default.resolve(cwd, outputPath);
|
|
4306
|
+
fs3__default.default.mkdirSync(path7__default.default.dirname(absOutput), { recursive: true });
|
|
4307
|
+
const css = sorted.length > 0 ? `/* Auto-generated by tailwind-styled-v4 \u2014 DO NOT EDIT */
|
|
4308
|
+
@source inline("${sorted.join(" ")}");
|
|
4309
|
+
` : `/* Auto-generated by tailwind-styled-v4 \u2014 DO NOT EDIT */
|
|
4310
|
+
/* No safelist classes found */
|
|
4311
|
+
`;
|
|
4312
|
+
fs3__default.default.writeFileSync(absOutput, css);
|
|
4313
|
+
console.log(`[tailwind-styled-v4] Safelist: ${sorted.length} classes \u2192 ${absOutput}`);
|
|
4314
|
+
return sorted;
|
|
4315
|
+
}
|
|
4316
|
+
async function generateCssForClasses(classes, config, cwd = process.cwd()) {
|
|
4317
|
+
try {
|
|
4318
|
+
const { compileCssFromClasses: compileCssFromClasses2 } = (init_cssCompiler(), __toCommonJS(cssCompiler_exports));
|
|
4319
|
+
const result = compileCssFromClasses2(classes);
|
|
4320
|
+
if (result?.css && result.resolvedClasses.length > 0) {
|
|
4321
|
+
const resolveRate = result.resolvedClasses.length / classes.length;
|
|
4322
|
+
if (resolveRate >= 0.5) return result.css;
|
|
4323
|
+
}
|
|
4324
|
+
} catch {
|
|
4325
|
+
}
|
|
4326
|
+
const twConfig = config ?? loadTailwindConfig(cwd);
|
|
4327
|
+
try {
|
|
4328
|
+
return await generateViaTailwindV4(classes, twConfig, cwd);
|
|
4329
|
+
} catch {
|
|
4330
|
+
}
|
|
4331
|
+
return generateManualCss(classes);
|
|
4332
|
+
}
|
|
4333
|
+
async function generateViaTailwindV4(classes, _config, cwd) {
|
|
4334
|
+
const virtualCss = [
|
|
4335
|
+
`@import "tailwindcss";`,
|
|
4336
|
+
`@layer utilities {`,
|
|
4337
|
+
` /* Generated by tailwind-styled-v4 */`,
|
|
4338
|
+
`}`
|
|
4339
|
+
].join("\n");
|
|
4340
|
+
const postcss = __require("postcss");
|
|
4341
|
+
const tailwindcss = __require("@tailwindcss/postcss");
|
|
4342
|
+
const result = await postcss([
|
|
4343
|
+
tailwindcss({
|
|
4344
|
+
optimize: { minify: false }
|
|
4345
|
+
})
|
|
4346
|
+
]).process(virtualCss, {
|
|
4347
|
+
from: path7__default.default.join(cwd, "virtual.css")
|
|
4348
|
+
});
|
|
4349
|
+
return filterCssForClasses(result.css, classes);
|
|
4350
|
+
}
|
|
4351
|
+
function generateManualCss(classes) {
|
|
4352
|
+
const { generateAtomicCss: generateAtomicCss2, parseAtomicClass: parseAtomicClass2 } = (init_atomicCss(), __toCommonJS(atomicCss_exports));
|
|
4353
|
+
const rules = classes.map((c) => parseAtomicClass2(c)).filter(Boolean);
|
|
4354
|
+
if (rules.length === 0) return "";
|
|
4355
|
+
const header = `/* Generated by tailwind-styled-v4 \u2014 ${(/* @__PURE__ */ new Date()).toISOString()} */
|
|
4356
|
+
`;
|
|
4357
|
+
return header + generateAtomicCss2(rules);
|
|
4358
|
+
}
|
|
4359
|
+
function filterCssForClasses(fullCss, classes) {
|
|
4360
|
+
new Set(classes);
|
|
4361
|
+
const lines = fullCss.split("\n");
|
|
4362
|
+
const kept = [];
|
|
4363
|
+
let inBlock = false;
|
|
4364
|
+
let keepBlock = false;
|
|
4365
|
+
let braceDepth = 0;
|
|
4366
|
+
for (const line of lines) {
|
|
4367
|
+
if (line.includes("@layer base") || line.includes("*, *::before")) {
|
|
4368
|
+
kept.push(line);
|
|
4369
|
+
continue;
|
|
4370
|
+
}
|
|
4371
|
+
if (!inBlock) {
|
|
4372
|
+
const isOurClass = classes.some((cls) => {
|
|
4373
|
+
const escaped = cls.replace(/[:/[\].!%]/g, "\\$&");
|
|
4374
|
+
return line.includes(`.${escaped}`) || line.includes(`.${cls}`);
|
|
4375
|
+
});
|
|
4376
|
+
if (isOurClass) {
|
|
4377
|
+
keepBlock = true;
|
|
4378
|
+
inBlock = true;
|
|
4379
|
+
braceDepth = 0;
|
|
4380
|
+
}
|
|
4381
|
+
}
|
|
4382
|
+
if (inBlock) {
|
|
4383
|
+
if (keepBlock) kept.push(line);
|
|
4384
|
+
if (line.includes("{")) braceDepth++;
|
|
4385
|
+
if (line.includes("}")) {
|
|
4386
|
+
braceDepth--;
|
|
4387
|
+
if (braceDepth <= 0) {
|
|
4388
|
+
inBlock = false;
|
|
4389
|
+
keepBlock = false;
|
|
4390
|
+
}
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4394
|
+
return kept.join("\n");
|
|
4395
|
+
}
|
|
4396
|
+
async function generateAllRouteCss(opts = {}) {
|
|
4397
|
+
const { cwd = process.cwd(), outputDir, config, minify = true } = opts;
|
|
4398
|
+
const results = [];
|
|
4399
|
+
const routes = getAllRoutes();
|
|
4400
|
+
const twConfig = config ?? loadTailwindConfig(cwd);
|
|
4401
|
+
for (const route of routes) {
|
|
4402
|
+
const classes = Array.from(getRouteClasses(route));
|
|
4403
|
+
if (classes.length === 0) continue;
|
|
4404
|
+
try {
|
|
4405
|
+
let css = await generateCssForClasses(classes, twConfig, cwd);
|
|
4406
|
+
if (minify) {
|
|
4407
|
+
css = minifyCss(css);
|
|
4408
|
+
}
|
|
4409
|
+
results.push({
|
|
4410
|
+
route,
|
|
4411
|
+
css,
|
|
4412
|
+
classes,
|
|
4413
|
+
sizeBytes: Buffer.byteLength(css, "utf8")
|
|
4414
|
+
});
|
|
4415
|
+
} catch (e) {
|
|
4416
|
+
console.warn(`[tailwind-styled-v4] CSS generation failed for route ${route}:`, e);
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
if (outputDir) {
|
|
4420
|
+
const fs6 = __require("fs");
|
|
4421
|
+
fs6.mkdirSync(outputDir, { recursive: true });
|
|
4422
|
+
for (const result of results) {
|
|
4423
|
+
const filename = routeToFilename(result.route);
|
|
4424
|
+
const filepath = path7__default.default.join(outputDir, filename);
|
|
4425
|
+
fs6.mkdirSync(path7__default.default.dirname(filepath), { recursive: true });
|
|
4426
|
+
fs6.writeFileSync(filepath, result.css);
|
|
4427
|
+
}
|
|
4428
|
+
const totalSize = results.reduce((sum, r) => sum + r.sizeBytes, 0);
|
|
4429
|
+
console.log(
|
|
4430
|
+
`[tailwind-styled-v4] Route CSS generated: ${results.length} routes, ${formatBytes(totalSize)} total`
|
|
4431
|
+
);
|
|
4432
|
+
}
|
|
4433
|
+
return results;
|
|
4434
|
+
}
|
|
4435
|
+
function routeToFilename(route) {
|
|
4436
|
+
if (route === "/") return "index.css";
|
|
4437
|
+
if (route === "__global") return "_global.css";
|
|
4438
|
+
return `${route.replace(/^\//, "").replace(/\//g, "_")}.css`;
|
|
4439
|
+
}
|
|
4440
|
+
function minifyCss(css) {
|
|
4441
|
+
return css.replace(/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g, "").replace(/\s+/g, " ").replace(/\s*{\s*/g, "{").replace(/\s*}\s*/g, "}").replace(/\s*:\s*/g, ":").replace(/\s*;\s*/g, ";").trim();
|
|
4442
|
+
}
|
|
4443
|
+
function formatBytes(bytes) {
|
|
4444
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
4445
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
4446
|
+
return `${(bytes / 1024 / 1024).toFixed(1)}MB`;
|
|
4447
|
+
}
|
|
4448
|
+
|
|
4449
|
+
exports.BucketEngine = BucketEngine;
|
|
4450
|
+
exports.CompileContext = CompileContext;
|
|
4451
|
+
exports.IncrementalEngine = IncrementalEngine;
|
|
4452
|
+
exports.Pipeline = Pipeline;
|
|
4453
|
+
exports.adaptNativeResult = adaptNativeResult;
|
|
4454
|
+
exports.analyzeFile = analyzeFile;
|
|
4455
|
+
exports.analyzeVariantUsage = analyzeVariantUsage;
|
|
4456
|
+
exports.astExtractClassesNative = astExtractClassesNative;
|
|
4457
|
+
exports.bootstrapZeroConfig = bootstrapZeroConfig;
|
|
4458
|
+
exports.bucketSort = bucketSort;
|
|
4459
|
+
exports.buildStyleTag = buildStyleTag;
|
|
4460
|
+
exports.classifyNode = classifyNode;
|
|
4461
|
+
exports.clearAtomicRegistry = clearAtomicRegistry;
|
|
4462
|
+
exports.compileCssFromClasses = compileCssFromClasses;
|
|
4463
|
+
exports.compileCssNative = compileCssNative;
|
|
4464
|
+
exports.compileVariants = compileVariants;
|
|
4465
|
+
exports.compileWithCore = compileWithCore;
|
|
4466
|
+
exports.detectConflicts = detectConflicts;
|
|
4467
|
+
exports.eliminateDeadCss = eliminateDeadCss;
|
|
4468
|
+
exports.extractAllClasses = extractAllClasses;
|
|
4469
|
+
exports.extractComponentUsage = extractComponentUsage;
|
|
4470
|
+
exports.fileToRoute = fileToRoute;
|
|
4471
|
+
exports.findDeadVariants = findDeadVariants;
|
|
4472
|
+
exports.generateAllRouteCss = generateAllRouteCss;
|
|
4473
|
+
exports.generateAtomicCss = generateAtomicCss;
|
|
4474
|
+
exports.generateCssForClasses = generateCssForClasses;
|
|
4475
|
+
exports.generateSafelist = generateSafelist;
|
|
4476
|
+
exports.generateSafelistCss = generateSafelistCss;
|
|
4477
|
+
exports.getAllRoutes = getAllRoutes;
|
|
4478
|
+
exports.getAtomicRegistry = getAtomicRegistry;
|
|
4479
|
+
exports.getBucketEngine = getBucketEngine;
|
|
4480
|
+
exports.getCollector = getCollector;
|
|
4481
|
+
exports.getCollectorSummary = getCollectorSummary;
|
|
4482
|
+
exports.getContentPaths = getContentPaths;
|
|
4483
|
+
exports.getIncrementalEngine = getIncrementalEngine;
|
|
4484
|
+
exports.getNativeBridge = getNativeBridge;
|
|
4485
|
+
exports.getRouteClasses = getRouteClasses;
|
|
4486
|
+
exports.hasInteractiveFeatures = hasInteractiveFeatures;
|
|
4487
|
+
exports.hasTwUsage = hasTwUsage;
|
|
4488
|
+
exports.hoistComponents = hoistComponents;
|
|
4489
|
+
exports.injectClientDirective = injectClientDirective;
|
|
4490
|
+
exports.injectServerOnlyComment = injectServerOnlyComment;
|
|
4491
|
+
exports.invalidateConfigCache = invalidateConfigCache;
|
|
4492
|
+
exports.isDynamic = isDynamic;
|
|
4493
|
+
exports.isServerComponent = isServerComponent;
|
|
4494
|
+
exports.isZeroConfig = isZeroConfig;
|
|
4495
|
+
exports.loadSafelist = loadSafelist;
|
|
4496
|
+
exports.loadTailwindConfig = loadTailwindConfig;
|
|
4497
|
+
exports.mergeClassesStatic = mergeClassesStatic;
|
|
4498
|
+
exports.normalizeClasses = normalizeClasses;
|
|
4499
|
+
exports.optimizeCss = optimizeCss;
|
|
4500
|
+
exports.parseAtomicClass = parseAtomicClass;
|
|
4501
|
+
exports.parseClassesToNodes = parseClassesToNodes;
|
|
4502
|
+
exports.registerFileClasses = registerFileClasses;
|
|
4503
|
+
exports.registerGlobalClasses = registerGlobalClasses;
|
|
4504
|
+
exports.resetBucketEngine = resetBucketEngine;
|
|
4505
|
+
exports.resetCollector = resetCollector;
|
|
4506
|
+
exports.resetCompileCache = resetCompileCache;
|
|
4507
|
+
exports.resetIncrementalEngine = resetIncrementalEngine;
|
|
4508
|
+
exports.resetNativeBridgeCache = resetNativeBridgeCache;
|
|
4509
|
+
exports.resolveServerVariant = resolveServerVariant;
|
|
4510
|
+
exports.runElimination = runElimination;
|
|
4511
|
+
exports.runLoaderTransform = runLoaderTransform;
|
|
4512
|
+
exports.scanProjectUsage = scanProjectUsage;
|
|
4513
|
+
exports.shouldProcess = hasTwUsage;
|
|
4514
|
+
exports.shouldSkipFile = shouldSkipFile;
|
|
4515
|
+
exports.toAtomicClasses = toAtomicClasses;
|
|
4516
|
+
exports.transformSource = transformSource;
|
|
4517
|
+
//# sourceMappingURL=compiler.js.map
|
|
4518
|
+
//# sourceMappingURL=compiler.js.map
|