tailwind-styled-v4 5.1.22 → 5.1.24

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 (61) hide show
  1. package/README.md +216 -0
  2. package/dist/atomic.js +34 -4
  3. package/dist/atomic.js.map +1 -1
  4. package/dist/atomic.mjs +31 -2
  5. package/dist/atomic.mjs.map +1 -1
  6. package/dist/cli.js +132 -97
  7. package/dist/cli.js.map +1 -1
  8. package/dist/cli.mjs +129 -95
  9. package/dist/cli.mjs.map +1 -1
  10. package/dist/compiler.d.mts +195 -1
  11. package/dist/compiler.d.ts +195 -1
  12. package/dist/compiler.js +356 -12
  13. package/dist/compiler.js.map +1 -1
  14. package/dist/compiler.mjs +340 -10
  15. package/dist/compiler.mjs.map +1 -1
  16. package/dist/engine.js +194 -164
  17. package/dist/engine.js.map +1 -1
  18. package/dist/engine.mjs +184 -155
  19. package/dist/engine.mjs.map +1 -1
  20. package/dist/index.browser.mjs +136 -14
  21. package/dist/index.browser.mjs.map +1 -1
  22. package/dist/index.d.mts +45 -4
  23. package/dist/index.d.ts +45 -4
  24. package/dist/index.js +166 -9
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +177 -21
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/next.js +489 -158
  29. package/dist/next.js.map +1 -1
  30. package/dist/next.mjs +483 -153
  31. package/dist/next.mjs.map +1 -1
  32. package/dist/runtime-css.js +1 -1
  33. package/dist/runtime-css.js.map +1 -1
  34. package/dist/runtime-css.mjs +1 -1
  35. package/dist/runtime-css.mjs.map +1 -1
  36. package/dist/runtime.js +17 -0
  37. package/dist/runtime.js.map +1 -1
  38. package/dist/runtime.mjs +23 -0
  39. package/dist/runtime.mjs.map +1 -1
  40. package/dist/shared.js +91 -61
  41. package/dist/shared.js.map +1 -1
  42. package/dist/shared.mjs +85 -56
  43. package/dist/shared.mjs.map +1 -1
  44. package/dist/turbopackLoader.js +79 -49
  45. package/dist/turbopackLoader.js.map +1 -1
  46. package/dist/turbopackLoader.mjs +76 -47
  47. package/dist/turbopackLoader.mjs.map +1 -1
  48. package/dist/tw.js +132 -97
  49. package/dist/tw.js.map +1 -1
  50. package/dist/tw.mjs +129 -95
  51. package/dist/tw.mjs.map +1 -1
  52. package/dist/vite.js +157 -127
  53. package/dist/vite.js.map +1 -1
  54. package/dist/vite.mjs +150 -121
  55. package/dist/vite.mjs.map +1 -1
  56. package/dist/webpackLoader.js +39 -9
  57. package/dist/webpackLoader.js.map +1 -1
  58. package/dist/webpackLoader.mjs +36 -7
  59. package/dist/webpackLoader.mjs.map +1 -1
  60. package/package.json +1 -1
  61. package/CHANGELOG.md +0 -182
package/dist/compiler.mjs CHANGED
@@ -171,7 +171,7 @@ var init_nativeBridge = __esm({
171
171
  "use strict";
172
172
  init_esm_shims();
173
173
  init_src();
174
- _loadNative = (path6) => __require(path6);
174
+ _loadNative = (path7) => __require(path7);
175
175
  log = (...args) => {
176
176
  if (process.env.DEBUG?.includes("compiler:native")) {
177
177
  console.log("[compiler:native]", ...args);
@@ -2207,9 +2207,323 @@ var init_routeGraph = __esm({
2207
2207
  }
2208
2208
  });
2209
2209
 
2210
- // packages/domain/compiler/src/index.ts
2210
+ // packages/domain/compiler/src/semanticComponentAnalyzer.ts
2211
+ function inferSemanticFromTag(tag) {
2212
+ const tagLower = tag.toLowerCase();
2213
+ const semanticMap = {
2214
+ "button": "button",
2215
+ "a": "link",
2216
+ "nav": "navigation",
2217
+ "h1": "heading",
2218
+ "h2": "heading",
2219
+ "h3": "heading",
2220
+ "h4": "heading",
2221
+ "h5": "heading",
2222
+ "h6": "heading",
2223
+ "p": "paragraph",
2224
+ "ul": "list",
2225
+ "ol": "list",
2226
+ "input": "input",
2227
+ "form": "form",
2228
+ "dialog": "dialog",
2229
+ "select": "select",
2230
+ "textarea": "input"
2231
+ };
2232
+ return semanticMap[tagLower] ?? "custom";
2233
+ }
2234
+ function extractSemanticMetadata(config) {
2235
+ const metadata = {};
2236
+ for (const [key, value] of Object.entries(config)) {
2237
+ if (key.startsWith("@")) {
2238
+ metadata[key] = value;
2239
+ }
2240
+ }
2241
+ return metadata;
2242
+ }
2243
+ function analyzeComponentSemantics(componentName, config) {
2244
+ const metadata = extractSemanticMetadata(config);
2245
+ const tag = config.tag ?? "div";
2246
+ let semantic = inferSemanticFromTag(tag);
2247
+ if (metadata["@semantic"]) {
2248
+ semantic = metadata["@semantic"];
2249
+ }
2250
+ const stateProperties = /* @__PURE__ */ new Map();
2251
+ if (metadata["@state"]) {
2252
+ for (const [key, value] of Object.entries(metadata["@state"])) {
2253
+ if (typeof value === "string") {
2254
+ stateProperties.set(key, value);
2255
+ }
2256
+ }
2257
+ }
2258
+ return {
2259
+ componentName,
2260
+ tag,
2261
+ semantic,
2262
+ metadata,
2263
+ stateProperties
2264
+ };
2265
+ }
2266
+ function getAriaRoleForSemantic(semantic) {
2267
+ const roleMap = {
2268
+ "button": "button",
2269
+ "link": "link",
2270
+ "navigation": "navigation",
2271
+ "heading": "heading",
2272
+ "paragraph": void 0,
2273
+ // paragraph tidak perlu explicit role
2274
+ "list": "list",
2275
+ "input": "textbox",
2276
+ "form": "form",
2277
+ "dialog": "dialog",
2278
+ "alert": "alert",
2279
+ "tab": "tab",
2280
+ "checkbox": "checkbox",
2281
+ "radio": "radio",
2282
+ "select": "listbox",
2283
+ "custom": void 0
2284
+ };
2285
+ return roleMap[semantic];
2286
+ }
2287
+ function analyzeComponentBatch(components) {
2288
+ const results = /* @__PURE__ */ new Map();
2289
+ for (const [name, config] of components) {
2290
+ const analysis = analyzeComponentSemantics(name, config);
2291
+ results.set(name, analysis);
2292
+ }
2293
+ return results;
2294
+ }
2295
+ function validateSemanticMetadata(metadata) {
2296
+ const issues = [];
2297
+ const validSemantics = [
2298
+ "button",
2299
+ "link",
2300
+ "navigation",
2301
+ "heading",
2302
+ "paragraph",
2303
+ "list",
2304
+ "input",
2305
+ "form",
2306
+ "dialog",
2307
+ "alert",
2308
+ "tab",
2309
+ "checkbox",
2310
+ "radio",
2311
+ "select",
2312
+ "custom"
2313
+ ];
2314
+ if (metadata["@semantic"] && !validSemantics.includes(metadata["@semantic"])) {
2315
+ issues.push(`Invalid @semantic value: ${metadata["@semantic"]}`);
2316
+ }
2317
+ if (metadata["@aria"]) {
2318
+ if (typeof metadata["@aria"] !== "object" || Array.isArray(metadata["@aria"])) {
2319
+ issues.push("@aria must be object");
2320
+ }
2321
+ }
2322
+ if (metadata["@state"]) {
2323
+ if (typeof metadata["@state"] !== "object" || Array.isArray(metadata["@state"])) {
2324
+ issues.push("@state must be object");
2325
+ }
2326
+ for (const [key, value] of Object.entries(metadata["@state"])) {
2327
+ if (typeof value !== "string") {
2328
+ issues.push(`@state.${key} must be string (ARIA property name)`);
2329
+ }
2330
+ }
2331
+ }
2332
+ return issues;
2333
+ }
2334
+ var init_semanticComponentAnalyzer = __esm({
2335
+ "packages/domain/compiler/src/semanticComponentAnalyzer.ts"() {
2336
+ "use strict";
2337
+ init_esm_shims();
2338
+ }
2339
+ });
2340
+
2341
+ // packages/domain/compiler/src/typeGeneratorFromMetadata.ts
2342
+ function generateJsDocFromSemantic(analysis) {
2343
+ const lines = [
2344
+ "/**",
2345
+ ` * ${analysis.componentName}`,
2346
+ ` * `,
2347
+ ` * Semantic intent: ${analysis.semantic}`,
2348
+ ` * Tag: ${analysis.tag}`
2349
+ ];
2350
+ if (analysis.metadata["@aria"]) {
2351
+ lines.push(` * ARIA: auto-injected dari semantic metadata`);
2352
+ }
2353
+ if (analysis.stateProperties.size > 0) {
2354
+ const states = Array.from(analysis.stateProperties.entries()).map(([k, v]) => `${k} \u2192 ${v}`).join(", ");
2355
+ lines.push(` * State mappings: ${states}`);
2356
+ }
2357
+ lines.push(" */");
2358
+ return lines.join("\n");
2359
+ }
2360
+ function getBaseComponentType(analysis) {
2361
+ const tag = analysis.tag.toLowerCase();
2362
+ const tagMap = {
2363
+ "button": "React.ButtonHTMLAttributes<HTMLButtonElement>",
2364
+ "a": "React.AnchorHTMLAttributes<HTMLAnchorElement>",
2365
+ "input": "React.InputHTMLAttributes<HTMLInputElement>",
2366
+ "textarea": "React.TextareaHTMLAttributes<HTMLTextAreaElement>",
2367
+ "select": "React.SelectHTMLAttributes<HTMLSelectElement>",
2368
+ "form": "React.FormHTMLAttributes<HTMLFormElement>",
2369
+ "div": "React.HTMLAttributes<HTMLDivElement>",
2370
+ "span": "React.HTMLAttributes<HTMLSpanElement>",
2371
+ "nav": "React.HTMLAttributes<HTMLElement>",
2372
+ "dialog": "React.DialogHTMLAttributes<HTMLDialogElement>"
2373
+ };
2374
+ return tagMap[tag] ?? "React.HTMLAttributes<HTMLElement>";
2375
+ }
2376
+ function generateStateProperties(analysis) {
2377
+ const props = /* @__PURE__ */ new Map();
2378
+ for (const [stateName, ariaProp] of analysis.stateProperties) {
2379
+ props.set(stateName, {
2380
+ name: stateName,
2381
+ type: "boolean | undefined",
2382
+ description: `State mapped to ARIA property: ${ariaProp}`,
2383
+ optional: true
2384
+ });
2385
+ }
2386
+ return props;
2387
+ }
2388
+ function generateTypeDefinition(analysis, componentName) {
2389
+ const interfaceName = `${componentName}Props`;
2390
+ const baseType = getBaseComponentType(analysis);
2391
+ const stateProps = generateStateProperties(analysis);
2392
+ return {
2393
+ interfaceName,
2394
+ extendsFrom: baseType,
2395
+ properties: stateProps,
2396
+ jsDocComment: generateJsDocFromSemantic(analysis)
2397
+ };
2398
+ }
2399
+ function renderTypeDefinition(def) {
2400
+ const lines = [];
2401
+ if (def.jsDocComment) {
2402
+ lines.push(def.jsDocComment);
2403
+ }
2404
+ lines.push(`export interface ${def.interfaceName} extends ${def.extendsFrom} {`);
2405
+ for (const prop of def.properties.values()) {
2406
+ const optional = prop.optional ? "?" : "";
2407
+ if (prop.description) {
2408
+ lines.push(` /** ${prop.description} */`);
2409
+ }
2410
+ lines.push(` ${prop.name}${optional}: ${prop.type}`);
2411
+ }
2412
+ lines.push("}");
2413
+ return lines.join("\n");
2414
+ }
2415
+ function generateTypeStubFile(analyses, packageName = "tailwind-styled") {
2416
+ const lines = [
2417
+ "/**",
2418
+ ` * Auto-generated type definitions dari semantic component metadata`,
2419
+ ` * Generated at build-time dari @semantic, @aria, @state annotations`,
2420
+ ` * Package: ${packageName}`,
2421
+ ` */`,
2422
+ "",
2423
+ "import type * as React from 'react'",
2424
+ ""
2425
+ ];
2426
+ const interfaces = [];
2427
+ for (const [name, analysis] of analyses) {
2428
+ const def = generateTypeDefinition(analysis, name);
2429
+ interfaces.push(renderTypeDefinition(def));
2430
+ }
2431
+ lines.push(interfaces.join("\n\n"));
2432
+ lines.push("");
2433
+ lines.push("export namespace Components {");
2434
+ for (const analysis of analyses.values()) {
2435
+ lines.push(` export type ${analysis.componentName}Props = ${analysis.componentName}Props`);
2436
+ }
2437
+ lines.push("}");
2438
+ lines.push("");
2439
+ return lines.join("\n");
2440
+ }
2441
+ function generateTypeStubOutputPaths(outputDir, packageName) {
2442
+ return [
2443
+ {
2444
+ filePath: `${outputDir}/${packageName}.d.ts`,
2445
+ content: "",
2446
+ // Will be set by caller
2447
+ format: "dts"
2448
+ }
2449
+ ];
2450
+ }
2451
+ function generateTypeDefinitionsBatch(analyses) {
2452
+ const results = /* @__PURE__ */ new Map();
2453
+ for (const [name, analysis] of analyses) {
2454
+ const def = generateTypeDefinition(analysis, name);
2455
+ const code = renderTypeDefinition(def);
2456
+ results.set(name, code);
2457
+ }
2458
+ return results;
2459
+ }
2460
+ function combineTypeDefinitions(definitions, packageName = "tailwind-styled") {
2461
+ const lines = [
2462
+ "/**",
2463
+ ` * Auto-generated type definitions dari semantic component metadata`,
2464
+ ` * Generated at build-time dari @semantic, @aria, @state annotations`,
2465
+ ` * Package: ${packageName}`,
2466
+ " */",
2467
+ "",
2468
+ "import type * as React from 'react'",
2469
+ ""
2470
+ ];
2471
+ const defs = Array.from(definitions.values());
2472
+ lines.push(defs.join("\n\n"));
2473
+ return lines.join("\n");
2474
+ }
2475
+ var init_typeGeneratorFromMetadata = __esm({
2476
+ "packages/domain/compiler/src/typeGeneratorFromMetadata.ts"() {
2477
+ "use strict";
2478
+ init_esm_shims();
2479
+ }
2480
+ });
2481
+
2482
+ // packages/domain/compiler/src/typeGenerationPlugin.ts
2211
2483
  import fs4 from "fs";
2212
2484
  import path5 from "path";
2485
+ function createTypeGenerationPlugin(options = {}) {
2486
+ const {
2487
+ outputDir = "./dist/types",
2488
+ packageName = "tailwind-styled",
2489
+ verbose = false,
2490
+ componentRegistryPath
2491
+ } = options;
2492
+ return {
2493
+ name: "type-generation",
2494
+ async setup(build) {
2495
+ if (verbose) {
2496
+ console.log("[type-generation] Plugin loaded");
2497
+ }
2498
+ }
2499
+ };
2500
+ }
2501
+ async function generateTypesFromComponents(components, outputPath, packageName = "tailwind-styled") {
2502
+ if (components.size === 0) {
2503
+ console.warn("No components provided");
2504
+ return;
2505
+ }
2506
+ const analyses = analyzeComponentBatch(components);
2507
+ const typeContent = generateTypeStubFile(analyses, packageName);
2508
+ const dir = path5.dirname(outputPath);
2509
+ if (!fs4.existsSync(dir)) {
2510
+ fs4.mkdirSync(dir, { recursive: true });
2511
+ }
2512
+ fs4.writeFileSync(outputPath, typeContent, "utf8");
2513
+ console.log(`Generated type stubs \u2192 ${outputPath} (${components.size} components)`);
2514
+ }
2515
+ var init_typeGenerationPlugin = __esm({
2516
+ "packages/domain/compiler/src/typeGenerationPlugin.ts"() {
2517
+ "use strict";
2518
+ init_esm_shims();
2519
+ init_semanticComponentAnalyzer();
2520
+ init_typeGeneratorFromMetadata();
2521
+ }
2522
+ });
2523
+
2524
+ // packages/domain/compiler/src/index.ts
2525
+ import fs5 from "fs";
2526
+ import path6 from "path";
2213
2527
  import { createRequire as createRequire5 } from "module";
2214
2528
  function _layoutClassesToCss(classes) {
2215
2529
  const native = getNativeBridge();
@@ -2258,6 +2572,9 @@ var init_src2 = __esm({
2258
2572
  init_redis();
2259
2573
  init_watch();
2260
2574
  init_routeGraph();
2575
+ init_semanticComponentAnalyzer();
2576
+ init_typeGeneratorFromMetadata();
2577
+ init_typeGenerationPlugin();
2261
2578
  _require3 = createRequire5(
2262
2579
  typeof __require !== "undefined" ? typeof __filename !== "undefined" ? `file://${__filename}` : "file://unknown" : import.meta.url
2263
2580
  );
@@ -2352,7 +2669,7 @@ var init_src2 = __esm({
2352
2669
  };
2353
2670
  scanProjectUsage = (dirs, cwd) => {
2354
2671
  const { batchExtractClasses: batchExtractClasses2 } = _require3("./parser");
2355
- const files = dirs.map((dir) => path5.resolve(cwd, dir));
2672
+ const files = dirs.map((dir) => path6.resolve(cwd, dir));
2356
2673
  const results = batchExtractClasses2(files) || [];
2357
2674
  const combined = {};
2358
2675
  for (const result of results) {
@@ -2369,13 +2686,13 @@ var init_src2 = __esm({
2369
2686
  const classes = scanProjectUsage(scanDirs, cwd || process.cwd());
2370
2687
  const allClasses = Object.keys(classes).sort();
2371
2688
  if (outputPath) {
2372
- fs4.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2));
2689
+ fs5.writeFileSync(outputPath, JSON.stringify(allClasses, null, 2));
2373
2690
  }
2374
2691
  return allClasses;
2375
2692
  };
2376
2693
  loadSafelist = (safelistPath) => {
2377
2694
  try {
2378
- const content = fs4.readFileSync(safelistPath, "utf-8");
2695
+ const content = fs5.readFileSync(safelistPath, "utf-8");
2379
2696
  return JSON.parse(content);
2380
2697
  } catch {
2381
2698
  return [];
@@ -2389,8 +2706,8 @@ var init_src2 = __esm({
2389
2706
  "tailwind.config.cjs"
2390
2707
  ];
2391
2708
  for (const file of configFiles) {
2392
- const fullPath = path5.join(cwd, file);
2393
- if (fs4.existsSync(fullPath)) {
2709
+ const fullPath = path6.join(cwd, file);
2710
+ if (fs5.existsSync(fullPath)) {
2394
2711
  const mod = __require(fullPath);
2395
2712
  return mod.default || mod;
2396
2713
  }
@@ -2400,9 +2717,9 @@ var init_src2 = __esm({
2400
2717
  getContentPaths = (cwd = process.cwd()) => {
2401
2718
  return {
2402
2719
  content: [
2403
- path5.join(cwd, "src/**/*.{js,ts,jsx,tsx}"),
2404
- path5.join(cwd, "app/**/*.{js,ts,jsx,tsx}"),
2405
- path5.join(cwd, "pages/**/*.{js,ts,jsx,tsx}")
2720
+ path6.join(cwd, "src/**/*.{js,ts,jsx,tsx}"),
2721
+ path6.join(cwd, "app/**/*.{js,ts,jsx,tsx}"),
2722
+ path6.join(cwd, "pages/**/*.{js,ts,jsx,tsx}")
2406
2723
  ]
2407
2724
  };
2408
2725
  };
@@ -2635,6 +2952,8 @@ export {
2635
2952
  analyzeClassUsageNative,
2636
2953
  analyzeClasses,
2637
2954
  analyzeClassesNative,
2955
+ analyzeComponentBatch,
2956
+ analyzeComponentSemantics,
2638
2957
  analyzeFile,
2639
2958
  analyzeRscNative,
2640
2959
  analyzeVariantUsage,
@@ -2661,6 +2980,7 @@ export {
2661
2980
  clearResolverPool,
2662
2981
  clearThemeCache,
2663
2982
  collectFiles,
2983
+ combineTypeDefinitions,
2664
2984
  compileAnimation,
2665
2985
  compileClass,
2666
2986
  compileClasses,
@@ -2674,6 +2994,7 @@ export {
2674
2994
  compileVariantTableNative,
2675
2995
  computeIncrementalDiff,
2676
2996
  createFingerprint,
2997
+ createTypeGenerationPlugin,
2677
2998
  detectConflicts,
2678
2999
  detectDeadCode,
2679
3000
  diffClassLists,
@@ -2689,6 +3010,7 @@ export {
2689
3010
  extractClassesFromSourceNative,
2690
3011
  extractComponentUsage,
2691
3012
  extractContainerCssFromSource,
3013
+ extractSemanticMetadata,
2692
3014
  extractTwContainerConfigs,
2693
3015
  extractTwStateConfigs,
2694
3016
  extractTwStateConfigsNative,
@@ -2703,8 +3025,14 @@ export {
2703
3025
  generateStaticStateCss,
2704
3026
  generateStaticStateCssNative,
2705
3027
  generateSubComponentTypes,
3028
+ generateTypeDefinition,
3029
+ generateTypeDefinitionsBatch,
3030
+ generateTypeStubFile,
3031
+ generateTypeStubOutputPaths,
3032
+ generateTypesFromComponents,
2706
3033
  getAllRegisteredClasses,
2707
3034
  getAllRoutes,
3035
+ getAriaRoleForSemantic,
2708
3036
  getBucketEngine,
2709
3037
  getCacheOptimizationHints,
2710
3038
  getCacheStatistics,
@@ -2800,6 +3128,7 @@ export {
2800
3128
  registerPluginHook,
2801
3129
  registerPropertyName,
2802
3130
  registerValueName,
3131
+ renderTypeDefinition,
2803
3132
  resetBucketEngine,
2804
3133
  resetCacheStats,
2805
3134
  resetCompilationMetrics,
@@ -2842,6 +3171,7 @@ export {
2842
3171
  twMergeWithSeparator,
2843
3172
  unregisterPluginHook,
2844
3173
  validateCssOutput,
3174
+ validateSemanticMetadata,
2845
3175
  validateThemeConfig,
2846
3176
  valueIdToString,
2847
3177
  walkAndPrefilterSourceFiles,