tailwind-styled-v4 5.0.7 → 5.0.8

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.
@@ -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;
@@ -281,6 +286,37 @@ function extractDirective(source) {
281
286
  const stripped = source.slice(match[0].length);
282
287
  return { directive, stripped };
283
288
  }
289
+ var CYCLE_SENTINEL = "_cycle.txt";
290
+ var START_SENTINEL = "_start.txt";
291
+ var _workerCache = /* @__PURE__ */ new Map();
292
+ function getTwClassesDir(safelistPath) {
293
+ return path.join(path.dirname(safelistPath), "tw-classes");
294
+ }
295
+ function readSentinel(filePath) {
296
+ try {
297
+ return fs.readFileSync(filePath, "utf-8").trim();
298
+ } catch {
299
+ return "";
300
+ }
301
+ }
302
+ function clearAndMarkCycle(twClassesDir, startId) {
303
+ try {
304
+ if (fs.existsSync(twClassesDir)) {
305
+ for (const file of fs.readdirSync(twClassesDir)) {
306
+ if (file === START_SENTINEL || file === "_webpack-merged.css") continue;
307
+ try {
308
+ fs.unlinkSync(path.join(twClassesDir, file));
309
+ } catch {
310
+ }
311
+ }
312
+ } else {
313
+ fs.mkdirSync(twClassesDir, { recursive: true });
314
+ }
315
+ fs.writeFileSync(path.join(twClassesDir, CYCLE_SENTINEL), startId, "utf-8");
316
+ _workerCache.set(twClassesDir, startId);
317
+ } catch {
318
+ }
319
+ }
284
320
  function getPerFileSafelistPath(safelistDir, resourcePath) {
285
321
  const normalized = resourcePath.replace(/\\/g, "/");
286
322
  const slug = normalized.replace(/^.*\/src\//, "").replace(/\.[tj]sx?$/, "").replace(/[^a-zA-Z0-9]/g, "_").slice(0, 80);
@@ -289,9 +325,15 @@ function getPerFileSafelistPath(safelistDir, resourcePath) {
289
325
  function writePerFileSafelist(safelistPath, resourcePath, classes) {
290
326
  if (!safelistPath || classes.length === 0) return;
291
327
  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 });
328
+ const twClassesDir = getTwClassesDir(safelistPath);
329
+ const startId = readSentinel(path.join(twClassesDir, START_SENTINEL));
330
+ const cachedCycle = _workerCache.get(twClassesDir) ?? readSentinel(path.join(twClassesDir, CYCLE_SENTINEL));
331
+ if (startId && cachedCycle !== startId) {
332
+ clearAndMarkCycle(twClassesDir, startId);
333
+ } else if (!fs.existsSync(twClassesDir)) {
334
+ fs.mkdirSync(twClassesDir, { recursive: true });
335
+ }
336
+ const outPath = getPerFileSafelistPath(twClassesDir, resourcePath);
295
337
  const sorted = [...new Set(classes)].sort();
296
338
  const css = [
297
339
  `/* tw-safelist: ${path.basename(resourcePath)} \u2014 auto-generated */`,
@@ -299,6 +341,10 @@ function writePerFileSafelist(safelistPath, resourcePath, classes) {
299
341
  sorted.map((cls) => `.${cls.replace(/([^a-zA-Z0-9_-])/g, "\\$1")} {}`).join("\n"),
300
342
  "}"
301
343
  ].join("\n");
344
+ try {
345
+ if (fs.readFileSync(outPath, "utf-8") === css) return;
346
+ } catch {
347
+ }
302
348
  fs.writeFileSync(outPath, css, "utf-8");
303
349
  } catch {
304
350
  }