tailwind-styled-v4 5.0.7 → 5.0.9

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 (46) hide show
  1. package/CHANGELOG.md +184 -410
  2. package/README.md +45 -15
  3. package/dist/cli.js +62 -52
  4. package/dist/cli.js.map +1 -1
  5. package/dist/cli.mjs +62 -52
  6. package/dist/cli.mjs.map +1 -1
  7. package/dist/compiler.d.mts +8 -3
  8. package/dist/compiler.d.ts +8 -3
  9. package/dist/compiler.js +214 -127
  10. package/dist/compiler.js.map +1 -1
  11. package/dist/compiler.mjs +195 -103
  12. package/dist/compiler.mjs.map +1 -1
  13. package/dist/engine.js +146 -66
  14. package/dist/engine.js.map +1 -1
  15. package/dist/engine.mjs +146 -66
  16. package/dist/engine.mjs.map +1 -1
  17. package/dist/index.d.mts +26 -8
  18. package/dist/index.d.ts +26 -8
  19. package/dist/index.js +72 -19
  20. package/dist/index.js.map +1 -1
  21. package/dist/index.mjs +72 -19
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/next.d.mts +12 -40
  24. package/dist/next.d.ts +12 -40
  25. package/dist/next.js +27 -320
  26. package/dist/next.js.map +1 -1
  27. package/dist/next.mjs +27 -320
  28. package/dist/next.mjs.map +1 -1
  29. package/dist/turbopackLoader.js +137 -88
  30. package/dist/turbopackLoader.js.map +1 -1
  31. package/dist/turbopackLoader.mjs +137 -88
  32. package/dist/turbopackLoader.mjs.map +1 -1
  33. package/dist/tw.js +62 -52
  34. package/dist/tw.js.map +1 -1
  35. package/dist/tw.mjs +62 -52
  36. package/dist/tw.mjs.map +1 -1
  37. package/dist/vite.js +146 -66
  38. package/dist/vite.js.map +1 -1
  39. package/dist/vite.mjs +146 -66
  40. package/dist/vite.mjs.map +1 -1
  41. package/dist/webpackLoader.js +92 -83
  42. package/dist/webpackLoader.js.map +1 -1
  43. package/dist/webpackLoader.mjs +92 -83
  44. package/dist/webpackLoader.mjs.map +1 -1
  45. package/native/tailwind-styled-native.node +0 -0
  46. package/package.json +3 -3
@@ -3,16 +3,18 @@ import fs from 'fs';
3
3
  import path from 'path';
4
4
 
5
5
  /* tailwind-styled-v4 v5.0.4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
7
8
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
8
9
  }) : x)(function(x) {
9
10
  if (typeof require !== "undefined") return require.apply(this, arguments);
10
11
  throw Error('Dynamic require of "' + x + '" is not supported');
11
12
  });
13
+ var __esm = (fn, res) => function __init() {
14
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
+ };
12
16
 
13
17
  // packages/domain/shared/src/native-resolution.ts
14
- var isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
15
- var nodeModuleRef = null;
16
18
  function getNodeModuleRef() {
17
19
  if (isBrowser) return null;
18
20
  if (nodeModuleRef !== null) return nodeModuleRef;
@@ -25,9 +27,6 @@ function getNodeModuleRef() {
25
27
  return null;
26
28
  }
27
29
  }
28
- var _nodeFs = null;
29
- var _nodePath = null;
30
- var _require = null;
31
30
  function getNodeFs() {
32
31
  if (isBrowser) return { existsSync: () => false };
33
32
  const nodeRequire = getNodeModuleRef();
@@ -53,14 +52,6 @@ function getRequire(_importMetaUrl) {
53
52
  if (!_require) _require = nodeRequire.createRequire(_importMetaUrl);
54
53
  return _require;
55
54
  }
56
- var PLATFORM_MAP = {
57
- "linux-x64": ["@tailwind-styled/native-linux-x64"],
58
- "linux-arm64": ["@tailwind-styled/native-linux-arm64"],
59
- "darwin-x64": ["@tailwind-styled/native-darwin-x64"],
60
- "darwin-arm64": ["@tailwind-styled/native-darwin-arm64"],
61
- "win32-x64": ["@tailwind-styled/native-win32-x64"],
62
- "win32-arm64": ["@tailwind-styled/native-win32-arm64"]
63
- };
64
55
  function platformKey() {
65
56
  if (isBrowser) return "browser";
66
57
  return `${process.platform}-${process.arch}`;
@@ -114,10 +105,26 @@ function resolveNativeBinary(runtimeDir) {
114
105
  }
115
106
  return { path: null, source: "not-found", platform, tried };
116
107
  }
108
+ var isBrowser, nodeModuleRef, _nodeFs, _nodePath, _require, PLATFORM_MAP;
109
+ var init_native_resolution = __esm({
110
+ "packages/domain/shared/src/native-resolution.ts"() {
111
+ isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
112
+ nodeModuleRef = null;
113
+ _nodeFs = null;
114
+ _nodePath = null;
115
+ _require = null;
116
+ PLATFORM_MAP = {
117
+ "linux-x64": ["@tailwind-styled/native-linux-x64"],
118
+ "linux-arm64": ["@tailwind-styled/native-linux-arm64"],
119
+ "darwin-x64": ["@tailwind-styled/native-darwin-x64"],
120
+ "darwin-arm64": ["@tailwind-styled/native-darwin-arm64"],
121
+ "win32-x64": ["@tailwind-styled/native-win32-x64"],
122
+ "win32-arm64": ["@tailwind-styled/native-win32-arm64"]
123
+ };
124
+ }
125
+ });
117
126
 
118
127
  // packages/domain/shared/src/index.ts
119
- var isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
120
- var nodeModuleRef2 = null;
121
128
  function getNodeModuleRef2() {
122
129
  if (isBrowser2) return null;
123
130
  if (nodeModuleRef2 !== null) return nodeModuleRef2;
@@ -130,7 +137,6 @@ function getNodeModuleRef2() {
130
137
  return null;
131
138
  }
132
139
  }
133
- var _nodeUrl = null;
134
140
  function getNodeUrl() {
135
141
  if (isBrowser2) throw new Error("node:url not available in browser");
136
142
  const nodeRequire = getNodeModuleRef2();
@@ -148,7 +154,6 @@ function getRequire2() {
148
154
  });
149
155
  return nodeRequire.createRequire(import.meta.url);
150
156
  }
151
- getRequire2();
152
157
  function resolveRuntimeDir(dir, importMetaUrl) {
153
158
  if (isBrowser2) return "";
154
159
  try {
@@ -157,57 +162,80 @@ function resolveRuntimeDir(dir, importMetaUrl) {
157
162
  return process.cwd();
158
163
  }
159
164
  }
160
- var log = (...args) => {
161
- if (process.env.DEBUG?.includes("compiler:native")) {
162
- console.log("[compiler:native]", ...args);
163
- }
164
- };
165
- var NATIVE_UNAVAILABLE_MESSAGE = "[tailwind-styled/compiler v5] Native binding is required but not available.\nThis package requires native Rust bindings. There is no JavaScript fallback.\nPlease ensure:\n 1. The native module is properly installed\n 2. You have run: npm run build:rust (or use prebuilt binary)\n\nFor help, see: https://tailwind-styled.dev/docs/install";
166
- var nativeBridge = null;
167
- var bridgeLoadAttempted = false;
168
- var bridgeLoadError = null;
169
- var isValidNativeBridge = (mod) => {
170
- const m = mod;
171
- return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
172
- };
173
- var getNativeBridge = () => {
174
- if (nativeBridge) {
175
- return nativeBridge;
176
- }
177
- if (bridgeLoadAttempted) {
178
- if (bridgeLoadError) {
179
- throw bridgeLoadError;
180
- }
181
- throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
165
+ var isBrowser2, nodeModuleRef2, _nodeUrl;
166
+ var init_src = __esm({
167
+ "packages/domain/shared/src/index.ts"() {
168
+ init_native_resolution();
169
+ isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
170
+ nodeModuleRef2 = null;
171
+ _nodeUrl = null;
172
+ getRequire2();
182
173
  }
183
- bridgeLoadAttempted = true;
184
- try {
185
- const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
186
- const require2 = createRequire(import.meta.url);
187
- const result = resolveNativeBinary(runtimeDir);
188
- if (result.path && result.path.endsWith(".node")) {
189
- try {
190
- const binding = require2(result.path);
191
- if (isValidNativeBridge(binding)) {
192
- nativeBridge = binding;
193
- log("Native bridge loaded successfully from:", result.path);
194
- return nativeBridge;
174
+ });
175
+ var log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge;
176
+ var init_nativeBridge = __esm({
177
+ "packages/domain/compiler/src/nativeBridge.ts"() {
178
+ init_src();
179
+ log = (...args) => {
180
+ if (process.env.DEBUG?.includes("compiler:native")) {
181
+ console.log("[compiler:native]", ...args);
182
+ }
183
+ };
184
+ NATIVE_UNAVAILABLE_MESSAGE = "[tailwind-styled/compiler v5] Native binding is required but not available.\nThis package requires native Rust bindings. There is no JavaScript fallback.\nPlease ensure:\n 1. The native module is properly installed\n 2. You have run: npm run build:rust (or use prebuilt binary)\n\nFor help, see: https://tailwind-styled.dev/docs/install";
185
+ nativeBridge = null;
186
+ bridgeLoadAttempted = false;
187
+ bridgeLoadError = null;
188
+ isValidNativeBridge = (mod) => {
189
+ const m = mod;
190
+ return !!(typeof m.transformSource === "function" || typeof m.extractAllClasses === "function" || typeof m.hasTwUsage === "function");
191
+ };
192
+ getNativeBridge = () => {
193
+ if (nativeBridge) {
194
+ return nativeBridge;
195
+ }
196
+ if (bridgeLoadAttempted) {
197
+ if (bridgeLoadError) {
198
+ throw bridgeLoadError;
195
199
  }
196
- } catch (e) {
197
- log("Failed to require native binding:", e);
200
+ throw new Error(NATIVE_UNAVAILABLE_MESSAGE);
198
201
  }
199
- }
200
- throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
202
+ bridgeLoadAttempted = true;
203
+ try {
204
+ const runtimeDir = resolveRuntimeDir(void 0, import.meta.url);
205
+ const require2 = createRequire(import.meta.url);
206
+ const result = resolveNativeBinary(runtimeDir);
207
+ if (result.path && result.path.endsWith(".node")) {
208
+ try {
209
+ const binding = require2(result.path);
210
+ if (isValidNativeBridge(binding)) {
211
+ nativeBridge = binding;
212
+ log("Native bridge loaded successfully from:", result.path);
213
+ return nativeBridge;
214
+ }
215
+ } catch (e) {
216
+ log("Failed to require native binding:", e);
217
+ }
218
+ }
219
+ throw new Error(`${NATIVE_UNAVAILABLE_MESSAGE}
201
220
 
202
221
  Tried paths: ${result.tried.join("\n")}`);
203
- } catch (err) {
204
- bridgeLoadError = err instanceof Error ? err : new Error(String(err));
205
- log("Failed to load native bridge:", bridgeLoadError.message);
206
- throw bridgeLoadError;
222
+ } catch (err) {
223
+ bridgeLoadError = err instanceof Error ? err : new Error(String(err));
224
+ log("Failed to load native bridge:", bridgeLoadError.message);
225
+ throw bridgeLoadError;
226
+ }
227
+ };
228
+ if (typeof process !== "undefined" && !bridgeLoadAttempted) {
229
+ try {
230
+ getNativeBridge();
231
+ } catch {
232
+ }
233
+ }
207
234
  }
208
- };
235
+ });
209
236
 
210
237
  // packages/domain/compiler/src/index.ts
238
+ init_nativeBridge();
211
239
  var transformSource = (source, opts) => {
212
240
  const native = getNativeBridge();
213
241
  if (!native?.transformSource) {
@@ -228,30 +256,7 @@ var runLoaderTransform = (ctx) => {
228
256
  classes: result?.classes || []
229
257
  };
230
258
  };
231
- var fileToRoute = (filepath) => {
232
- const normalized = filepath.replace(/\\/g, "/");
233
- if (normalized.includes("/layout.") || normalized.includes("/loading.") || normalized.includes("/error.")) {
234
- return "__global";
235
- }
236
- const appPageMatch = normalized.match(/\/app\/(.+?)\/page\.[tj]sx?$/);
237
- if (appPageMatch) return `/${appPageMatch[1]}`;
238
- const appRootPage = normalized.match(/\/app\/page\.[tj]sx?$/);
239
- if (appRootPage) return "/";
240
- const pagesMatch = normalized.match(/\/pages\/(.+?)\.[tj]sx?$/);
241
- if (pagesMatch) {
242
- const pagePath = pagesMatch[1];
243
- if (pagePath.startsWith("_") || pagePath.startsWith("api/")) return "__global";
244
- return pagePath === "index" ? "/" : `/${pagePath}`;
245
- }
246
- return null;
247
- };
248
- var _routeClassMap = /* @__PURE__ */ new Map();
249
259
  var registerFileClasses = (filepath, classes) => {
250
- if (!classes.length) return;
251
- const route = fileToRoute(filepath) ?? "__global";
252
- const existing = _routeClassMap.get(route) ?? /* @__PURE__ */ new Set();
253
- for (const cls of classes) existing.add(cls);
254
- _routeClassMap.set(route, existing);
255
260
  };
256
261
  function parseBool(val, fallback = false) {
257
262
  if (typeof val === "boolean") return val;
@@ -269,10 +274,13 @@ function detectRouter(resourcePath) {
269
274
  if (/\/pages\//.test(normalized)) return "pages";
270
275
  return "unknown";
271
276
  }
277
+ var NEXT_RSC_ENTRIES = /(?:^|[\\/])(?:layout|page|loading|error|not-found|template|default)\.[jt]sx?$/;
272
278
  function isSkippable(resourcePath) {
273
279
  const normalized = resourcePath.replace(/\\/g, "/");
274
280
  return normalized.includes("/node_modules/") || normalized.endsWith(".d.ts") || normalized.endsWith(".d.mts") || normalized.endsWith(".d.cts") || // Skip CSS/assets
275
- /\.(css|scss|sass|less|svg|png|jpg|jpeg|gif|webp|ico|woff|woff2|ttf|eot)$/.test(normalized);
281
+ /\.(css|scss|sass|less|svg|png|jpg|jpeg|gif|webp|ico|woff|woff2|ttf|eot)$/.test(normalized) || // Skip Next.js RSC entry files — Turbopack tidak punya exclude di rule level,
282
+ // jadi guard ini menggantikan NEXT_RSC_ENTRIES exclude yang ada di webpack path.
283
+ NEXT_RSC_ENTRIES.test(normalized);
276
284
  }
277
285
  function extractDirective(source) {
278
286
  const match = source.match(/^(\s*["'](use client|use server)["']\s*;?\s*\n?)/);
@@ -281,6 +289,37 @@ function extractDirective(source) {
281
289
  const stripped = source.slice(match[0].length);
282
290
  return { directive, stripped };
283
291
  }
292
+ var CYCLE_SENTINEL = "_cycle.txt";
293
+ var START_SENTINEL = "_start.txt";
294
+ var _workerCache = /* @__PURE__ */ new Map();
295
+ function getTwClassesDir(safelistPath) {
296
+ return path.join(path.dirname(safelistPath), "tw-classes");
297
+ }
298
+ function readSentinel(filePath) {
299
+ try {
300
+ return fs.readFileSync(filePath, "utf-8").trim();
301
+ } catch {
302
+ return "";
303
+ }
304
+ }
305
+ function clearAndMarkCycle(twClassesDir, startId) {
306
+ try {
307
+ if (fs.existsSync(twClassesDir)) {
308
+ for (const file of fs.readdirSync(twClassesDir)) {
309
+ if (file === START_SENTINEL || file === "_webpack-merged.css") continue;
310
+ try {
311
+ fs.unlinkSync(path.join(twClassesDir, file));
312
+ } catch {
313
+ }
314
+ }
315
+ } else {
316
+ fs.mkdirSync(twClassesDir, { recursive: true });
317
+ }
318
+ fs.writeFileSync(path.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
319
+ _workerCache.set(twClassesDir, startId);
320
+ } catch {
321
+ }
322
+ }
284
323
  function getPerFileSafelistPath(safelistDir, resourcePath) {
285
324
  const normalized = resourcePath.replace(/\\/g, "/");
286
325
  const slug = normalized.replace(/^.*\/src\//, "").replace(/\.[tj]sx?$/, "").replace(/[^a-zA-Z0-9]/g, "_").slice(0, 80);
@@ -289,9 +328,15 @@ function getPerFileSafelistPath(safelistDir, resourcePath) {
289
328
  function writePerFileSafelist(safelistPath, resourcePath, classes) {
290
329
  if (!safelistPath || classes.length === 0) return;
291
330
  try {
292
- const safelistDir = path.join(path.dirname(safelistPath), "tw-classes");
293
- const outPath = getPerFileSafelistPath(safelistDir, resourcePath);
294
- if (!fs.existsSync(safelistDir)) fs.mkdirSync(safelistDir, { recursive: true });
331
+ const twClassesDir = getTwClassesDir(safelistPath);
332
+ const startId = readSentinel(path.join(twClassesDir, START_SENTINEL));
333
+ const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(path.join(twClassesDir, CYCLE_SENTINEL));
334
+ if (startId && cachedCycle !== startId) {
335
+ clearAndMarkCycle(twClassesDir, startId);
336
+ } else if (!fs.existsSync(twClassesDir)) {
337
+ fs.mkdirSync(twClassesDir, { recursive: true });
338
+ }
339
+ const outPath = getPerFileSafelistPath(twClassesDir, resourcePath);
295
340
  const sorted = [...new Set(classes)].sort();
296
341
  const css = [
297
342
  `/* tw-safelist: ${path.basename(resourcePath)} \u2014 auto-generated */`,
@@ -299,6 +344,10 @@ function writePerFileSafelist(safelistPath, resourcePath, classes) {
299
344
  sorted.map((cls) => `.${cls.replace(/([^a-zA-Z0-9_-])/g, "\\$1")} {}`).join("\n"),
300
345
  "}"
301
346
  ].join("\n");
347
+ try {
348
+ if (fs.readFileSync(outPath, "utf-8") === css) return;
349
+ } catch {
350
+ }
302
351
  fs.writeFileSync(outPath, css, "utf-8");
303
352
  } catch {
304
353
  }
@@ -329,7 +378,7 @@ function turbopackLoader(source, options = {}) {
329
378
  source: stripped,
330
379
  options: effective
331
380
  });
332
- if (!output.changed && !output.code.length) return source;
381
+ if (!output.changed) return source;
333
382
  if (output.classes.length > 0) {
334
383
  registerFileClasses(this.resourcePath, output.classes);
335
384
  writePerFileSafelist(options.safelistPath, this.resourcePath, output.classes);