tailwind-styled-v4 4.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.
Files changed (194) hide show
  1. package/CHANGELOG.md +398 -0
  2. package/LICENSE +21 -0
  3. package/README.md +532 -0
  4. package/dist/analyzer.d.mts +114 -0
  5. package/dist/analyzer.d.ts +114 -0
  6. package/dist/analyzer.js +1555 -0
  7. package/dist/analyzer.js.map +1 -0
  8. package/dist/analyzer.mjs +1544 -0
  9. package/dist/analyzer.mjs.map +1 -0
  10. package/dist/animate.d.mts +46 -0
  11. package/dist/animate.d.ts +41 -112
  12. package/dist/animate.js +792 -235
  13. package/dist/animate.js.map +1 -1
  14. package/dist/animate.mjs +782 -0
  15. package/dist/animate.mjs.map +1 -0
  16. package/dist/atomic.d.mts +18 -0
  17. package/dist/atomic.d.ts +18 -0
  18. package/dist/atomic.js +191 -0
  19. package/dist/atomic.js.map +1 -0
  20. package/dist/atomic.mjs +185 -0
  21. package/dist/atomic.mjs.map +1 -0
  22. package/dist/cli.d.mts +1 -0
  23. package/dist/cli.d.ts +1 -0
  24. package/dist/cli.js +6063 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/cli.mjs +6053 -0
  27. package/dist/cli.mjs.map +1 -0
  28. package/dist/{compiler.d.cts → compiler.d.mts} +503 -210
  29. package/dist/compiler.d.ts +503 -210
  30. package/dist/compiler.js +1549 -566
  31. package/dist/compiler.js.map +1 -1
  32. package/dist/{compiler.cjs → compiler.mjs} +1476 -627
  33. package/dist/compiler.mjs.map +1 -0
  34. package/dist/dashboard.d.mts +272 -0
  35. package/dist/dashboard.d.ts +272 -0
  36. package/dist/dashboard.js +249 -0
  37. package/dist/dashboard.js.map +1 -0
  38. package/dist/dashboard.mjs +239 -0
  39. package/dist/dashboard.mjs.map +1 -0
  40. package/dist/devtools.js +336 -211
  41. package/dist/devtools.js.map +1 -1
  42. package/dist/{devtools.cjs → devtools.mjs} +331 -220
  43. package/dist/devtools.mjs.map +1 -0
  44. package/dist/engine.d.mts +84 -0
  45. package/dist/engine.d.ts +84 -0
  46. package/dist/engine.js +3014 -0
  47. package/dist/engine.js.map +1 -0
  48. package/dist/engine.mjs +3005 -0
  49. package/dist/engine.mjs.map +1 -0
  50. package/dist/{index.d.cts → index.d.mts} +75 -4
  51. package/dist/index.d.ts +75 -4
  52. package/dist/index.js +1341 -149
  53. package/dist/index.js.map +1 -1
  54. package/dist/index.mjs +2162 -0
  55. package/dist/index.mjs.map +1 -0
  56. package/dist/liveTokenEngine-DYN3Zale.d.mts +34 -0
  57. package/dist/liveTokenEngine-DYN3Zale.d.ts +34 -0
  58. package/dist/next.d.mts +55 -0
  59. package/dist/next.d.ts +30 -20
  60. package/dist/next.js +6947 -149
  61. package/dist/next.js.map +1 -1
  62. package/dist/next.mjs +7050 -0
  63. package/dist/next.mjs.map +1 -0
  64. package/dist/plugin.d.mts +90 -0
  65. package/dist/plugin.d.ts +90 -0
  66. package/dist/plugin.js +185 -0
  67. package/dist/plugin.js.map +1 -0
  68. package/dist/plugin.mjs +174 -0
  69. package/dist/plugin.mjs.map +1 -0
  70. package/dist/pluginRegistry.d.mts +83 -0
  71. package/dist/pluginRegistry.d.ts +83 -0
  72. package/dist/pluginRegistry.js +303 -0
  73. package/dist/pluginRegistry.js.map +1 -0
  74. package/dist/pluginRegistry.mjs +298 -0
  75. package/dist/pluginRegistry.mjs.map +1 -0
  76. package/dist/{preset.d.cts → preset.d.mts} +29 -2
  77. package/dist/preset.d.ts +29 -2
  78. package/dist/preset.js +318 -21
  79. package/dist/preset.js.map +1 -1
  80. package/dist/preset.mjs +414 -0
  81. package/dist/preset.mjs.map +1 -0
  82. package/dist/rspack.d.mts +33 -0
  83. package/dist/rspack.d.ts +33 -0
  84. package/dist/rspack.js +55 -0
  85. package/dist/rspack.js.map +1 -0
  86. package/dist/rspack.mjs +45 -0
  87. package/dist/rspack.mjs.map +1 -0
  88. package/dist/runtime.d.mts +62 -0
  89. package/dist/runtime.d.ts +62 -0
  90. package/dist/runtime.js +207 -0
  91. package/dist/runtime.js.map +1 -0
  92. package/dist/runtime.mjs +188 -0
  93. package/dist/runtime.mjs.map +1 -0
  94. package/dist/runtimeCss.d.mts +65 -0
  95. package/dist/runtimeCss.d.ts +65 -0
  96. package/dist/runtimeCss.js +188 -0
  97. package/dist/runtimeCss.js.map +1 -0
  98. package/dist/runtimeCss.mjs +173 -0
  99. package/dist/runtimeCss.mjs.map +1 -0
  100. package/dist/scanner.d.mts +25 -0
  101. package/dist/scanner.d.ts +25 -0
  102. package/dist/scanner.js +717 -0
  103. package/dist/scanner.js.map +1 -0
  104. package/dist/scanner.mjs +703 -0
  105. package/dist/scanner.mjs.map +1 -0
  106. package/dist/shared.d.mts +85 -0
  107. package/dist/shared.d.ts +85 -0
  108. package/dist/shared.js +255 -0
  109. package/dist/shared.js.map +1 -0
  110. package/dist/shared.mjs +233 -0
  111. package/dist/shared.mjs.map +1 -0
  112. package/dist/storybookAddon.d.mts +108 -0
  113. package/dist/storybookAddon.d.ts +108 -0
  114. package/dist/storybookAddon.js +95 -0
  115. package/dist/storybookAddon.js.map +1 -0
  116. package/dist/storybookAddon.mjs +88 -0
  117. package/dist/storybookAddon.mjs.map +1 -0
  118. package/dist/svelte.d.mts +114 -0
  119. package/dist/svelte.d.ts +114 -0
  120. package/dist/svelte.js +67 -0
  121. package/dist/svelte.js.map +1 -0
  122. package/dist/svelte.mjs +59 -0
  123. package/dist/svelte.mjs.map +1 -0
  124. package/dist/testing.d.mts +185 -0
  125. package/dist/testing.d.ts +185 -0
  126. package/dist/testing.js +173 -0
  127. package/dist/testing.js.map +1 -0
  128. package/dist/testing.mjs +158 -0
  129. package/dist/testing.mjs.map +1 -0
  130. package/dist/{theme.d.cts → theme.d.mts} +18 -11
  131. package/dist/theme.d.ts +18 -11
  132. package/dist/theme.js +205 -19
  133. package/dist/theme.js.map +1 -1
  134. package/dist/theme.mjs +311 -0
  135. package/dist/theme.mjs.map +1 -0
  136. package/dist/types-DXr2PmGP.d.mts +31 -0
  137. package/dist/types-DXr2PmGP.d.ts +31 -0
  138. package/dist/vite.d.mts +51 -0
  139. package/dist/vite.d.ts +35 -6
  140. package/dist/vite.js +4254 -57
  141. package/dist/vite.js.map +1 -1
  142. package/dist/vite.mjs +4281 -0
  143. package/dist/vite.mjs.map +1 -0
  144. package/dist/vue.d.mts +89 -0
  145. package/dist/vue.d.ts +89 -0
  146. package/dist/vue.js +104 -0
  147. package/dist/vue.js.map +1 -0
  148. package/dist/vue.mjs +96 -0
  149. package/dist/vue.mjs.map +1 -0
  150. package/package.json +173 -67
  151. package/dist/animate.cjs +0 -252
  152. package/dist/animate.cjs.map +0 -1
  153. package/dist/animate.d.cts +0 -117
  154. package/dist/astTransform-ua-eapqs.d.cts +0 -41
  155. package/dist/astTransform-ua-eapqs.d.ts +0 -41
  156. package/dist/compiler.cjs.map +0 -1
  157. package/dist/css.cjs +0 -71
  158. package/dist/css.cjs.map +0 -1
  159. package/dist/css.d.cts +0 -45
  160. package/dist/css.d.ts +0 -45
  161. package/dist/css.js +0 -62
  162. package/dist/css.js.map +0 -1
  163. package/dist/devtools.cjs.map +0 -1
  164. package/dist/index.cjs +0 -1058
  165. package/dist/index.cjs.map +0 -1
  166. package/dist/next.cjs +0 -268
  167. package/dist/next.cjs.map +0 -1
  168. package/dist/next.d.cts +0 -45
  169. package/dist/plugins.cjs +0 -396
  170. package/dist/plugins.cjs.map +0 -1
  171. package/dist/plugins.d.cts +0 -231
  172. package/dist/plugins.d.ts +0 -231
  173. package/dist/plugins.js +0 -381
  174. package/dist/plugins.js.map +0 -1
  175. package/dist/preset.cjs +0 -129
  176. package/dist/preset.cjs.map +0 -1
  177. package/dist/theme.cjs +0 -154
  178. package/dist/theme.cjs.map +0 -1
  179. package/dist/turbopackLoader.cjs +0 -2689
  180. package/dist/turbopackLoader.cjs.map +0 -1
  181. package/dist/turbopackLoader.d.cts +0 -22
  182. package/dist/turbopackLoader.d.ts +0 -22
  183. package/dist/turbopackLoader.js +0 -2681
  184. package/dist/turbopackLoader.js.map +0 -1
  185. package/dist/vite.cjs +0 -105
  186. package/dist/vite.cjs.map +0 -1
  187. package/dist/vite.d.cts +0 -22
  188. package/dist/webpackLoader.cjs +0 -2670
  189. package/dist/webpackLoader.cjs.map +0 -1
  190. package/dist/webpackLoader.d.cts +0 -24
  191. package/dist/webpackLoader.d.ts +0 -24
  192. package/dist/webpackLoader.js +0 -2662
  193. package/dist/webpackLoader.js.map +0 -1
  194. /package/dist/{devtools.d.cts → devtools.d.mts} +0 -0
@@ -0,0 +1,717 @@
1
+ 'use strict';
2
+
3
+ var module$1 = require('module');
4
+ var path4 = require('path');
5
+ var fs = require('fs');
6
+ var url = require('url');
7
+ var worker_threads = require('worker_threads');
8
+
9
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var path4__default = /*#__PURE__*/_interopDefault(path4);
13
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
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 log3 = (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) => log3("error", "stderr", a),
59
+ warn: (...a) => log3("warn", "stderr", a),
60
+ info: (...a) => log3("info", "stdout", a),
61
+ debug: (...a) => log3("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
+
75
+ // packages/shared/src/index.ts
76
+ var init_src = __esm({
77
+ "packages/shared/src/index.ts"() {
78
+ init_logger();
79
+ }
80
+ });
81
+
82
+ // packages/compiler/src/nativeBridge.ts
83
+ var nativeBridge_exports = {};
84
+ __export(nativeBridge_exports, {
85
+ adaptNativeResult: () => adaptNativeResult,
86
+ getNativeBridge: () => getNativeBridge,
87
+ resetNativeBridgeCache: () => resetNativeBridgeCache
88
+ });
89
+ function tryRequire(id) {
90
+ try {
91
+ const mod = requireFromRuntime(id);
92
+ return mod ?? null;
93
+ } catch (error) {
94
+ log.debug(
95
+ `native bridge load miss ${id}: ${error instanceof Error ? error.message : String(error)}`
96
+ );
97
+ return null;
98
+ }
99
+ }
100
+ function getNativeBridge() {
101
+ if (cachedBridge !== void 0) {
102
+ if (cachedBridge === null) {
103
+ throw new Error(
104
+ `[tailwind-styled/compiler v5] Native binding is required but not available.
105
+ Please ensure:
106
+ 1. The native module is properly installed
107
+ 2. You have run: npm run build:native (or use prebuilt binary)
108
+ 3. TWS_NO_NATIVE environment variable is not set
109
+
110
+ For help, see: https://tailwind-styled.dev/docs/install`
111
+ );
112
+ }
113
+ return cachedBridge;
114
+ }
115
+ if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
116
+ cachedBridge = null;
117
+ throw new Error(
118
+ `[tailwind-styled/compiler v5] Native binding is required.
119
+ The TWS_NO_NATIVE or TWS_NO_RUST environment variable is set, which disables native binding.
120
+ Please unset this environment variable to use the native compiler.`
121
+ );
122
+ }
123
+ const candidates = [
124
+ "@tailwind-styled/native",
125
+ path4__default.default.resolve(process.cwd(), "native", "index.mjs"),
126
+ path4__default.default.resolve(runtimeDir, "..", "..", "native", "index.mjs"),
127
+ path4__default.default.resolve(runtimeDir, "..", "..", "..", "native", "index.mjs"),
128
+ path4__default.default.resolve(process.cwd(), "native", "index.node"),
129
+ path4__default.default.resolve(runtimeDir, "..", "..", "native", "index.node"),
130
+ path4__default.default.resolve(runtimeDir, "..", "..", "..", "native", "index.node")
131
+ ];
132
+ for (const candidate of candidates) {
133
+ const bridge = tryRequire(candidate);
134
+ if (bridge) {
135
+ log.debug(`native bridge loaded from ${candidate}`);
136
+ cachedBridge = bridge;
137
+ return cachedBridge;
138
+ }
139
+ }
140
+ cachedBridge = null;
141
+ throw new Error(
142
+ `[tailwind-styled/compiler v5] Native binding not found.
143
+ Tried loading from:
144
+ ` + candidates.map((c) => ` - ${c}`).join("\n") + `
145
+
146
+ Please build the native module:
147
+ npm run build:native
148
+
149
+ Or install a prebuilt binary for your platform.`
150
+ );
151
+ }
152
+ function resetNativeBridgeCache() {
153
+ cachedBridge = void 0;
154
+ }
155
+ function adaptNativeResult(raw) {
156
+ let rsc;
157
+ if (raw.rscJson) {
158
+ try {
159
+ const parsed = JSON.parse(raw.rscJson);
160
+ rsc = {
161
+ isServer: parsed.isServer,
162
+ needsClientDirective: parsed.needsClientDirective,
163
+ clientReasons: []
164
+ };
165
+ } catch {
166
+ }
167
+ }
168
+ let metadata;
169
+ if (raw.metadataJson) {
170
+ try {
171
+ metadata = JSON.parse(raw.metadataJson);
172
+ } catch {
173
+ }
174
+ }
175
+ return {
176
+ code: raw.code,
177
+ classes: raw.classes,
178
+ changed: raw.changed,
179
+ rsc,
180
+ metadata
181
+ };
182
+ }
183
+ var runtimeDir, requireFromRuntime, cachedBridge, log;
184
+ var init_nativeBridge = __esm({
185
+ "packages/compiler/src/nativeBridge.ts"() {
186
+ init_src();
187
+ runtimeDir = typeof __dirname === "string" && __dirname.length > 0 ? __dirname : process.cwd();
188
+ requireFromRuntime = typeof module !== "undefined" && typeof module.require === "function" ? module.require.bind(module) : module$1.createRequire(path4__default.default.join(runtimeDir, "noop.cjs"));
189
+ log = createLogger("compiler:native");
190
+ }
191
+ });
192
+
193
+ // packages/scanner/src/native-bridge.ts
194
+ var native_bridge_exports = {};
195
+ __export(native_bridge_exports, {
196
+ cachePriorityNative: () => cachePriorityNative,
197
+ cacheReadNative: () => cacheReadNative,
198
+ cacheWriteNative: () => cacheWriteNative,
199
+ extractClassesNative: () => extractClassesNative,
200
+ hasNativeScannerBinding: () => hasNativeScannerBinding,
201
+ hashContentNative: () => hashContentNative,
202
+ isRustCacheAvailable: () => isRustCacheAvailable,
203
+ scanWorkspaceNative: () => scanWorkspaceNative
204
+ });
205
+ function getBinding() {
206
+ if (_binding !== void 0) {
207
+ if (_binding === null) {
208
+ throwNativeBindingError();
209
+ }
210
+ return _binding;
211
+ }
212
+ if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
213
+ _loadError = "Native loading is disabled by TWS_NO_NATIVE or TWS_NO_RUST environment variable.";
214
+ _binding = null;
215
+ _candidatePaths = [];
216
+ throwNativeBindingError();
217
+ }
218
+ const runtimeDir2 = typeof __dirname === "string" ? __dirname : process.cwd();
219
+ _candidatePaths = [
220
+ path4__default.default.resolve(process.cwd(), "native", "tailwind_styled_parser.node"),
221
+ path4__default.default.resolve(runtimeDir2, "..", "..", "..", "native", "tailwind_styled_parser.node")
222
+ ];
223
+ const req = typeof __require === "function" ? __require : module$1.createRequire(path4__default.default.join(runtimeDir2, "noop.cjs"));
224
+ for (const c of _candidatePaths) {
225
+ try {
226
+ const mod = req(c);
227
+ if (mod?.scanWorkspace || mod?.extractClassesFromSource || mod?.hashFileContent || mod?.cacheRead || mod?.cacheWrite) {
228
+ _binding = mod;
229
+ return _binding;
230
+ }
231
+ } catch (error) {
232
+ _loadError = error instanceof Error ? error.message : String(error);
233
+ }
234
+ }
235
+ _binding = null;
236
+ throwNativeBindingError();
237
+ }
238
+ function throwNativeBindingError() {
239
+ const lines = [
240
+ "FATAL: Native scanner binding not found.",
241
+ "",
242
+ "This package requires the Rust native binding 'tailwind_styled_parser.node'.",
243
+ "The binding was not found in any of these paths:",
244
+ ..._candidatePaths.map((p) => ` - ${p}`),
245
+ ""
246
+ ];
247
+ if (_loadError) {
248
+ lines.push("Load error:", ` ${_loadError}`, "");
249
+ }
250
+ lines.push(
251
+ "To fix this, run:",
252
+ " npm run build:rust",
253
+ "",
254
+ "This will build the native Rust module from the 'native/' directory.",
255
+ "If you're using this package in a CI/CD environment, ensure Rust toolchain is installed",
256
+ "and 'npm run build:rust' is executed before running tests or building."
257
+ );
258
+ throw new Error(lines.join("\n"));
259
+ }
260
+ function scanWorkspaceNative(root, extensions) {
261
+ return getBinding().scanWorkspace(root, extensions ?? null);
262
+ }
263
+ function extractClassesNative(source) {
264
+ const result = getBinding().extractClassesFromSource?.(source);
265
+ if (result === null || result === void 0) {
266
+ throw new Error("Native extractClassesFromSource returned null/undefined");
267
+ }
268
+ return result;
269
+ }
270
+ function hashContentNative(content) {
271
+ const result = getBinding().hashFileContent?.(content);
272
+ if (result === null || result === void 0) {
273
+ throw new Error("Native hashFileContent returned null/undefined");
274
+ }
275
+ return result;
276
+ }
277
+ function isRustCacheAvailable() {
278
+ return true;
279
+ }
280
+ function hasNativeScannerBinding() {
281
+ try {
282
+ getBinding();
283
+ return true;
284
+ } catch {
285
+ return false;
286
+ }
287
+ }
288
+ function cacheReadNative(cachePath) {
289
+ const result = getBinding().cacheRead?.(cachePath);
290
+ if (result === null || result === void 0) {
291
+ throw new Error("Native cacheRead returned null/undefined");
292
+ }
293
+ return result;
294
+ }
295
+ function cacheWriteNative(cachePath, entries) {
296
+ const result = getBinding().cacheWrite?.(cachePath, entries);
297
+ if (result === null || result === void 0) {
298
+ throw new Error("Native cacheWrite returned null/undefined");
299
+ }
300
+ return result;
301
+ }
302
+ function cachePriorityNative(mtimeMs, size, cachedMtimeMs, cachedSize, cachedHitCount, cachedLastSeenMs, nowMs = Date.now()) {
303
+ const result = getBinding().cachePriority?.(
304
+ mtimeMs,
305
+ size,
306
+ cachedMtimeMs,
307
+ cachedSize,
308
+ cachedHitCount,
309
+ cachedLastSeenMs,
310
+ nowMs
311
+ );
312
+ if (result === null || result === void 0) {
313
+ throw new Error("Native cachePriority returned null/undefined");
314
+ }
315
+ return result;
316
+ }
317
+ var _binding, _loadError, _candidatePaths;
318
+ var init_native_bridge = __esm({
319
+ "packages/scanner/src/native-bridge.ts"() {
320
+ _binding = void 0;
321
+ _loadError = null;
322
+ _candidatePaths = [];
323
+ }
324
+ });
325
+ function extractAllClasses(source) {
326
+ const { getNativeBridge: getNativeBridge2 } = (init_nativeBridge(), __toCommonJS(nativeBridge_exports));
327
+ const native = getNativeBridge2();
328
+ if (!native?.extractClassesFromSourceNative) {
329
+ throw new Error(
330
+ `[tailwind-styled/compiler v5] extractClassesFromSourceNative is required but not available.
331
+ Please ensure the native module is properly built.`
332
+ );
333
+ }
334
+ const result = native.extractClassesFromSourceNative(source);
335
+ if (!result || result.length < 0) {
336
+ throw new Error(
337
+ `[tailwind-styled/compiler v5] extractClassesFromSourceNative returned invalid result.`
338
+ );
339
+ }
340
+ return result.sort();
341
+ }
342
+
343
+ // packages/scanner/src/index.ts
344
+ init_src();
345
+
346
+ // packages/scanner/src/cache-native.ts
347
+ init_native_bridge();
348
+ function defaultCachePath(rootDir, cacheDir) {
349
+ const dir = cacheDir ? path4__default.default.resolve(rootDir, cacheDir) : path4__default.default.join(process.cwd(), ".cache", "tailwind-styled");
350
+ return path4__default.default.join(dir, "scanner-cache.json");
351
+ }
352
+ function readCache(rootDir, cacheDir) {
353
+ const cachePath = defaultCachePath(rootDir, cacheDir);
354
+ const result = cacheReadNative(cachePath);
355
+ return result.entries.map((e) => ({
356
+ file: e.file,
357
+ classes: e.classes,
358
+ hash: e.hash,
359
+ mtimeMs: e.mtimeMs,
360
+ size: e.size,
361
+ hitCount: e.hitCount
362
+ }));
363
+ }
364
+ function writeCache(rootDir, entries, cacheDir) {
365
+ const cachePath = defaultCachePath(rootDir, cacheDir);
366
+ const success = cacheWriteNative(cachePath, entries);
367
+ if (!success) {
368
+ throw new Error(
369
+ "Native cacheWrite failed. Run 'npm run build:rust' to rebuild native bindings."
370
+ );
371
+ }
372
+ }
373
+ function filePriority(mtimeMs, size, cached, nowMs = Date.now()) {
374
+ return cachePriorityNative(
375
+ mtimeMs,
376
+ size,
377
+ cached?.mtimeMs ?? 0,
378
+ cached?.size ?? 0,
379
+ cached?.hitCount ?? 0,
380
+ cached?.lastSeenMs ?? 0,
381
+ nowMs
382
+ );
383
+ }
384
+
385
+ // packages/scanner/src/index.ts
386
+ init_native_bridge();
387
+ var log2 = createLogger("scanner");
388
+ var SCAN_WORKER_TIMEOUT_MS = 12e4;
389
+ var SCAN_WORKER_BOOTSTRAP = `
390
+ const { parentPort, workerData } = require("node:worker_threads")
391
+ try {
392
+ const scanner = require(workerData.modulePath)
393
+ const result = scanner.scanWorkspace(workerData.rootDir, workerData.options ?? {})
394
+ parentPort.postMessage({ ok: true, result })
395
+ } catch (error) {
396
+ parentPort.postMessage({
397
+ ok: false,
398
+ error: error instanceof Error ? error.message : String(error),
399
+ })
400
+ }
401
+ `;
402
+ var nativeParserBinding;
403
+ var nativeParserInitError = null;
404
+ function canUseCjsRequire() {
405
+ return typeof __require === "function";
406
+ }
407
+ function debugNative(message) {
408
+ log2.debug(`[native] ${message}`);
409
+ }
410
+ function loadNativeParserBinding() {
411
+ if (nativeParserBinding !== void 0) return nativeParserBinding;
412
+ if (!canUseCjsRequire()) {
413
+ nativeParserBinding = null;
414
+ nativeParserInitError = "require is unavailable in current module format";
415
+ debugNative(`fallback to JS: ${nativeParserInitError}`);
416
+ return nativeParserBinding;
417
+ }
418
+ const candidates = [
419
+ path4__default.default.resolve(process.cwd(), "native/tailwind_styled_parser.node"),
420
+ path4__default.default.resolve(process.cwd(), "native/build/Release/tailwind_styled_parser.node")
421
+ ];
422
+ for (const fullPath of candidates) {
423
+ if (!fs__default.default.existsSync(fullPath)) continue;
424
+ try {
425
+ const required = __require(fullPath);
426
+ if (required && typeof required.parse_classes === "function") {
427
+ nativeParserBinding = required;
428
+ debugNative(`using native parser from ${fullPath}`);
429
+ return nativeParserBinding;
430
+ }
431
+ } catch (error) {
432
+ nativeParserInitError = error instanceof Error ? error.message : String(error);
433
+ }
434
+ }
435
+ nativeParserBinding = null;
436
+ if (!nativeParserInitError) {
437
+ nativeParserInitError = "native .node binding not found";
438
+ }
439
+ debugNative(`fallback to JS: ${nativeParserInitError}`);
440
+ return nativeParserBinding;
441
+ }
442
+ function normalizeWithNativeParser(tokens) {
443
+ const binding = loadNativeParserBinding();
444
+ if (!binding || typeof binding.parse_classes !== "function") {
445
+ throw new Error(
446
+ "Native parser binding is required but not available. Run 'npm run build:rust' to build it."
447
+ );
448
+ }
449
+ try {
450
+ const parsed = binding.parse_classes(tokens.join(" "));
451
+ const normalized = parsed.map((item) => item.raw?.trim() ?? "").filter(Boolean);
452
+ return Array.from(new Set(normalized));
453
+ } catch (error) {
454
+ const errorMessage = error instanceof Error ? error.message : String(error);
455
+ throw new Error(`Native parser failed: ${errorMessage}. Run 'npm run build:rust' to rebuild.`);
456
+ }
457
+ }
458
+ var DEFAULT_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
459
+ var DEFAULT_IGNORES = ["node_modules", ".git", ".next", "dist", "out", ".turbo", ".cache"];
460
+ function resolveScannerWorkerModulePath() {
461
+ const runtimeDir2 = typeof __dirname === "string" && __dirname.length > 0 ? __dirname : path4__default.default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('scanner.js', document.baseURI).href))));
462
+ const candidates = [
463
+ path4__default.default.resolve(runtimeDir2, "index.cjs"),
464
+ path4__default.default.resolve(runtimeDir2, "index.js"),
465
+ path4__default.default.resolve(runtimeDir2, "index.ts")
466
+ ];
467
+ for (const candidate of candidates) {
468
+ if (fs__default.default.existsSync(candidate)) return candidate;
469
+ }
470
+ return null;
471
+ }
472
+ function scanWorkspaceInWorker(rootDir, options) {
473
+ const modulePath = resolveScannerWorkerModulePath();
474
+ if (!modulePath) {
475
+ return Promise.reject(new Error("scanner worker module path could not be resolved"));
476
+ }
477
+ return new Promise((resolve, reject) => {
478
+ let settled = false;
479
+ const worker = new worker_threads.Worker(SCAN_WORKER_BOOTSTRAP, {
480
+ eval: true,
481
+ workerData: { modulePath, rootDir, options }
482
+ });
483
+ const timeout = setTimeout(() => {
484
+ if (settled) return;
485
+ settled = true;
486
+ void worker.terminate();
487
+ reject(new Error(`scanner worker timed out after ${SCAN_WORKER_TIMEOUT_MS}ms`));
488
+ }, SCAN_WORKER_TIMEOUT_MS);
489
+ const finish = (callback) => {
490
+ if (settled) return;
491
+ settled = true;
492
+ clearTimeout(timeout);
493
+ callback();
494
+ };
495
+ worker.once("message", (payload) => {
496
+ const message = payload;
497
+ finish(() => {
498
+ if (message?.ok) {
499
+ resolve(message.result);
500
+ return;
501
+ }
502
+ reject(new Error(message?.error ?? "scanner worker failed without an error message"));
503
+ });
504
+ });
505
+ worker.once("error", (error) => {
506
+ finish(() => reject(error));
507
+ });
508
+ worker.once("exit", (code) => {
509
+ if (code !== 0) {
510
+ finish(() => reject(new Error(`scanner worker exited with code ${code}`)));
511
+ }
512
+ });
513
+ });
514
+ }
515
+ function buildExtensionSet(includeExtensions) {
516
+ return new Set(includeExtensions);
517
+ }
518
+ function collectCandidates(rootDir, ignoreDirectories, extensionSet) {
519
+ const candidates = [];
520
+ const directories = [rootDir];
521
+ while (directories.length > 0) {
522
+ const currentDir = directories.pop();
523
+ if (!currentDir) continue;
524
+ let entries = [];
525
+ try {
526
+ entries = fs__default.default.readdirSync(currentDir, { withFileTypes: true });
527
+ } catch {
528
+ continue;
529
+ }
530
+ for (const entry of entries) {
531
+ const fullPath = path4__default.default.join(currentDir, entry.name);
532
+ if (entry.isDirectory()) {
533
+ if (!ignoreDirectories.has(entry.name)) directories.push(fullPath);
534
+ continue;
535
+ }
536
+ if (!entry.isFile()) continue;
537
+ if (!extensionSet.has(path4__default.default.extname(entry.name))) continue;
538
+ candidates.push(fullPath);
539
+ }
540
+ }
541
+ return candidates;
542
+ }
543
+ function toCacheSize(size) {
544
+ if (!Number.isFinite(size)) return 0;
545
+ const normalized = Math.max(0, Math.trunc(size));
546
+ return Math.min(normalized, 4294967295);
547
+ }
548
+ function extractClassesJs(source) {
549
+ return extractAllClasses(source);
550
+ }
551
+ function scanSource(source) {
552
+ const nativeBinding = loadNativeParserBinding();
553
+ if (nativeBinding && typeof nativeBinding.parse_classes === "function") {
554
+ try {
555
+ const baseClasses = extractClassesJs(source);
556
+ const nativeNormalized = normalizeWithNativeParser(baseClasses);
557
+ return nativeNormalized;
558
+ } catch (error) {
559
+ throw error;
560
+ }
561
+ }
562
+ throw new Error(
563
+ "Native parser binding is required but not available. Run 'npm run build:rust' to build it."
564
+ );
565
+ }
566
+ function isScannableFile(filePath, includeExtensions = DEFAULT_EXTENSIONS) {
567
+ return includeExtensions.includes(path4__default.default.extname(filePath));
568
+ }
569
+ function scanFile(filePath) {
570
+ const source = fs__default.default.readFileSync(filePath, "utf8");
571
+ const hash = hashContentNative(source) ?? void 0;
572
+ return {
573
+ file: filePath,
574
+ classes: scanSource(source),
575
+ ...hash ? { hash } : {}
576
+ };
577
+ }
578
+ function scanWorkspace(rootDir, options = {}) {
579
+ const includeExtensions = options.includeExtensions ?? DEFAULT_EXTENSIONS;
580
+ const extensionSet = buildExtensionSet(includeExtensions);
581
+ const ignoreDirectories = new Set(options.ignoreDirectories ?? DEFAULT_IGNORES);
582
+ const useCache = options.useCache ?? true;
583
+ options.smartInvalidation ?? true;
584
+ const files = [];
585
+ const unique = /* @__PURE__ */ new Set();
586
+ const candidates = collectCandidates(rootDir, ignoreDirectories, extensionSet);
587
+ const processResult = (result) => {
588
+ files.push(result);
589
+ for (const cls of result.classes) unique.add(cls);
590
+ };
591
+ const { scanWorkspaceNative: scanWorkspaceNative2 } = (init_native_bridge(), __toCommonJS(native_bridge_exports));
592
+ if (!options.cacheDir && !useCache) {
593
+ const nativeResult = scanWorkspaceNative2(rootDir, includeExtensions);
594
+ if (nativeResult) {
595
+ return {
596
+ files: nativeResult.files.map((f) => ({
597
+ file: f.file,
598
+ classes: f.classes
599
+ })),
600
+ totalFiles: nativeResult.totalFiles,
601
+ uniqueClasses: nativeResult.uniqueClasses
602
+ };
603
+ }
604
+ }
605
+ if (useCache && isRustCacheAvailable()) {
606
+ let cacheEntries = [];
607
+ try {
608
+ cacheEntries = readCache(rootDir, options.cacheDir);
609
+ } catch (error) {
610
+ cacheEntries = [];
611
+ log2.debug(
612
+ `cache read failed, continuing without persisted cache: ${error instanceof Error ? error.message : String(error)}`
613
+ );
614
+ }
615
+ const cacheMap = new Map(cacheEntries.map((entry) => [entry.file, entry]));
616
+ const nowMs = Date.now();
617
+ const ranked = [];
618
+ for (const filePath of candidates) {
619
+ let stat;
620
+ try {
621
+ stat = fs__default.default.statSync(filePath);
622
+ } catch {
623
+ continue;
624
+ }
625
+ const size = toCacheSize(stat.size);
626
+ const cached = cacheMap.get(filePath);
627
+ const priority = filePriority(
628
+ stat.mtimeMs,
629
+ size,
630
+ cached ? {
631
+ mtimeMs: cached.mtimeMs,
632
+ size: cached.size,
633
+ hitCount: cached.hitCount,
634
+ lastSeenMs: 0
635
+ } : void 0,
636
+ nowMs
637
+ );
638
+ ranked.push({ filePath, stat, size, cached, priority });
639
+ }
640
+ ranked.sort((a, b) => b.priority - a.priority);
641
+ const updatedEntries = [];
642
+ for (const { filePath, stat, size, cached } of ranked) {
643
+ let content;
644
+ try {
645
+ content = fs__default.default.readFileSync(filePath, "utf8");
646
+ } catch {
647
+ continue;
648
+ }
649
+ const hash = hashContentNative(content);
650
+ if (cached && cached.hash === hash && cached.mtimeMs === stat.mtimeMs && cached.size === size) {
651
+ log2.debug(`cache HIT ${filePath}`);
652
+ processResult({ file: filePath, classes: cached.classes });
653
+ updatedEntries.push({
654
+ file: filePath,
655
+ classes: cached.classes,
656
+ hash: cached.hash,
657
+ mtimeMs: stat.mtimeMs,
658
+ size,
659
+ hitCount: (cached.hitCount ?? 0) + 1
660
+ });
661
+ continue;
662
+ }
663
+ log2.debug(`cache MISS ${filePath}`);
664
+ const classes = scanSource(content);
665
+ processResult({ file: filePath, classes });
666
+ updatedEntries.push({
667
+ file: filePath,
668
+ classes,
669
+ hash,
670
+ mtimeMs: stat.mtimeMs,
671
+ size,
672
+ hitCount: 1
673
+ });
674
+ }
675
+ try {
676
+ writeCache(rootDir, updatedEntries, options.cacheDir);
677
+ } catch (error) {
678
+ log2.debug(`cache write failed: ${error instanceof Error ? error.message : String(error)}`);
679
+ }
680
+ return {
681
+ files,
682
+ totalFiles: files.length,
683
+ uniqueClasses: Array.from(unique).sort()
684
+ };
685
+ }
686
+ for (const filePath of candidates) {
687
+ processResult(scanFile(filePath));
688
+ }
689
+ return {
690
+ files,
691
+ totalFiles: files.length,
692
+ uniqueClasses: Array.from(unique).sort()
693
+ };
694
+ }
695
+ async function scanWorkspaceAsync(rootDir, options = {}) {
696
+ if (process.env.TWS_DISABLE_SCANNER_WORKER === "1") {
697
+ return scanWorkspace(rootDir, options);
698
+ }
699
+ try {
700
+ return await scanWorkspaceInWorker(rootDir, options);
701
+ } catch (error) {
702
+ log2.debug(
703
+ `worker scan failed, falling back to sync scanner: ${error instanceof Error ? error.message : String(error)}`
704
+ );
705
+ return scanWorkspace(rootDir, options);
706
+ }
707
+ }
708
+
709
+ exports.DEFAULT_EXTENSIONS = DEFAULT_EXTENSIONS;
710
+ exports.DEFAULT_IGNORES = DEFAULT_IGNORES;
711
+ exports.isScannableFile = isScannableFile;
712
+ exports.scanFile = scanFile;
713
+ exports.scanSource = scanSource;
714
+ exports.scanWorkspace = scanWorkspace;
715
+ exports.scanWorkspaceAsync = scanWorkspaceAsync;
716
+ //# sourceMappingURL=scanner.js.map
717
+ //# sourceMappingURL=scanner.js.map