@csszyx/compiler 0.8.0 → 0.9.0

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/README.md CHANGED
@@ -95,20 +95,24 @@ runtime consumers like `@csszyx/dynamic`.
95
95
 
96
96
  Babel-based source transform. Parses TSX/JSX, walks the AST, rewrites
97
97
  `sz`/`szRecover`/`_sz` constructs, emits the new source via Babel's
98
- code generator. Source of truth before v0.8.0; retained as the fallback
99
- path in v0.8.0+.
98
+ code generator. Retained as the final compatibility fallback.
100
99
 
101
100
  #### `transformOxc(source: string, filename?: string, options?: TransformSourceCodeOptions): TransformOxcResult` _(since v0.8.0)_
102
101
 
103
102
  oxc-parser + magic-string source transform. Same return shape as
104
103
  `transformSourceCode` so consumers (and the parity harness) can diff
105
- both implementations cleanly. Throws `OxcNotImplementedError` only for
106
- patterns that fall outside the curated Phase D coverage; the unplugin
107
- catches that error and routes to `transformSourceCode` as the fallback.
104
+ both implementations cleanly. JavaScript fallback when the native Rust
105
+ engine is unavailable (e.g. unsupported platform). Set
106
+ `build.parser: 'oxc'` to use this path.
108
107
 
109
- Surgical edits preserve every byte the user wrote outside the touched
110
- `sz`/`szRecover` ranges — Babel's pretty-printer would have collapsed
111
- or expanded surrounding whitespace.
108
+ #### `transformRust(source: string, filename?: string, options?: TransformSourceCodeOptions): TransformRustResult` _(default since v0.9.0)_
109
+
110
+ Native Rust engine via napi-rs. Fastest parser path. Requires the
111
+ matching optional `@csszyx/core-*` platform package. Missing native
112
+ packages surface `CsszyxNativeUnavailableError`.
113
+
114
+ All three transform paths preserve every byte the user wrote outside the
115
+ touched `sz`/`szRecover` ranges.
112
116
 
113
117
  #### `isValidSzProp(szProp: unknown): boolean`
114
118
 
@@ -7,6 +7,7 @@ function __szColorVar(v) {
7
7
  if (v.startsWith("--")) {
8
8
  return `var(${v})`;
9
9
  }
10
+ if (/[);\s\\]/.test(v)) return v;
10
11
  return `var(--color-${v})`;
11
12
  }
12
13
 
@@ -5,6 +5,7 @@ function __szColorVar(v) {
5
5
  if (v.startsWith("--")) {
6
6
  return `var(${v})`;
7
7
  }
8
+ if (/[);\s\\]/.test(v)) return v;
8
9
  return `var(--color-${v})`;
9
10
  }
10
11
 
package/dist/index.cjs CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
3
  const core = require('@csszyx/core');
4
- const transformCore = require('./shared/compiler.C6jT0mcT.cjs');
4
+ const transformCore = require('./shared/compiler.DZgazEy8.cjs');
5
5
  const t = require('@babel/types');
6
6
  const node_crypto = require('node:crypto');
7
7
  const babel = require('@babel/core');
8
8
  const MagicString = require('magic-string');
9
9
  const oxcParser = require('oxc-parser');
10
+ const native = require('@csszyx/core/native');
10
11
 
11
12
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
12
13
 
@@ -2709,6 +2710,80 @@ function walk(node, visit) {
2709
2710
  }
2710
2711
  }
2711
2712
 
2713
+ class OxcRustNotImplementedError extends Error {
2714
+ /**
2715
+ * @param detail Native loader or transform failure detail.
2716
+ */
2717
+ constructor(detail) {
2718
+ super(`transformRust: native engine unavailable - ${detail}`);
2719
+ this.name = "OxcRustNotImplementedError";
2720
+ }
2721
+ }
2722
+ function transformRust(source, filename, options) {
2723
+ const [result] = transformRustBatch([{ filename, source }]);
2724
+ if (!result) {
2725
+ throw new OxcRustNotImplementedError("native transform returned no result");
2726
+ }
2727
+ return result;
2728
+ }
2729
+ function ensureRustTransformAvailable() {
2730
+ try {
2731
+ native.transformBatch([]);
2732
+ } catch (err) {
2733
+ if (err instanceof OxcRustNotImplementedError) {
2734
+ throw err;
2735
+ }
2736
+ if (err instanceof native.CsszyxNativeUnavailableError) {
2737
+ throw new OxcRustNotImplementedError(
2738
+ `${err.message}; native package: ${err.packageName ?? "unsupported platform"}`
2739
+ );
2740
+ }
2741
+ throw err;
2742
+ }
2743
+ }
2744
+ function transformRustBatch(files, options) {
2745
+ try {
2746
+ return native.transformBatch(
2747
+ files.map((file, index) => ({
2748
+ filename: file.filename ?? `file-${index}.tsx`,
2749
+ source: file.source
2750
+ }))
2751
+ ).map(fromNativeResult);
2752
+ } catch (err) {
2753
+ if (err instanceof OxcRustNotImplementedError) {
2754
+ throw err;
2755
+ }
2756
+ if (err instanceof native.CsszyxNativeUnavailableError) {
2757
+ throw new OxcRustNotImplementedError(
2758
+ `${err.message}; native package: ${err.packageName ?? "unsupported platform"}`
2759
+ );
2760
+ }
2761
+ throw err;
2762
+ }
2763
+ }
2764
+ function fromNativeResult(result) {
2765
+ return {
2766
+ code: result.code,
2767
+ transformed: result.metadata.transformed,
2768
+ usesRuntime: result.metadata.usesRuntime,
2769
+ usesMerge: result.metadata.usesMerge,
2770
+ usesColorVar: result.metadata.usesColorVar,
2771
+ classes: new Set(result.classes),
2772
+ rawClassNames: new Set(result.rawClassNames),
2773
+ diagnostics: result.diagnostics,
2774
+ recoveryTokens: new Map(
2775
+ result.recoveryTokens.map(({ token, ...data }) => [
2776
+ token,
2777
+ {
2778
+ mode: data.mode,
2779
+ component: data.component,
2780
+ path: data.path
2781
+ }
2782
+ ])
2783
+ )
2784
+ };
2785
+ }
2786
+
2712
2787
  const VERSION = "0.0.0";
2713
2788
  const DEFAULT_COMPILER_OPTIONS = {
2714
2789
  buildId: Date.now().toString(),
@@ -2738,9 +2813,11 @@ exports.CsszyxCompiler = CsszyxCompiler;
2738
2813
  exports.DEFAULT_COMPILER_OPTIONS = DEFAULT_COMPILER_OPTIONS;
2739
2814
  exports.ManifestBuilder = ManifestBuilder;
2740
2815
  exports.OxcNotImplementedError = OxcNotImplementedError;
2816
+ exports.OxcRustNotImplementedError = OxcRustNotImplementedError;
2741
2817
  exports.VERSION = VERSION;
2742
2818
  exports.buildParentMap = buildParentMap;
2743
2819
  exports.createRecoveryToken = createRecoveryToken;
2820
+ exports.ensureRustTransformAvailable = ensureRustTransformAvailable;
2744
2821
  exports.generateRecoveryToken = generateRecoveryToken;
2745
2822
  exports.hoistCSSVariables = hoistCSSVariables;
2746
2823
  exports.injectRecoveryToken = injectRecoveryToken;
@@ -2749,6 +2826,8 @@ exports.mergeOptions = mergeOptions;
2749
2826
  exports.parseManifest = parseManifest;
2750
2827
  exports.serializeManifest = serializeManifest;
2751
2828
  exports.transformOxc = transformOxc;
2829
+ exports.transformRust = transformRust;
2830
+ exports.transformRustBatch = transformRustBatch;
2752
2831
  exports.transformSourceCode = transformSourceCode;
2753
2832
  exports.validateManifest = validateManifest;
2754
2833
  exports.validateSzRecover = validateSzRecover;
package/dist/index.d.cts CHANGED
@@ -309,6 +309,29 @@ interface TransformSourceCodeOptions {
309
309
  */
310
310
  astBudget?: number;
311
311
  }
312
+ /**
313
+ * Source transform result shared by the Babel and oxc parser paths.
314
+ */
315
+ interface SourceTransformResult {
316
+ /** Rewritten source code. */
317
+ code: string;
318
+ /** Whether csszyx changed the source. */
319
+ transformed: boolean;
320
+ /** Whether the source needs the _sz runtime helper. */
321
+ usesRuntime: boolean;
322
+ /** Whether the source needs the _szMerge runtime helper. */
323
+ usesMerge: boolean;
324
+ /** Whether the source needs the color-var runtime helper. */
325
+ usesColorVar: boolean;
326
+ /** Classes generated from sz syntax. */
327
+ classes: Set<string>;
328
+ /** Raw className/class strings collected for Tailwind discovery only. */
329
+ rawClassNames: Set<string>;
330
+ /** Compiler diagnostics to emit in development. */
331
+ diagnostics: string[];
332
+ /** Recovery tokens emitted by szRecover attributes. */
333
+ recoveryTokens: Map<string, TokenData>;
334
+ }
312
335
  /**
313
336
  * Transforms all sz props in a source code string into Tailwind classNames.
314
337
  *
@@ -321,17 +344,7 @@ interface TransformSourceCodeOptions {
321
344
  * @throws {ASTBudgetExceededError} when the file's AST exceeds the
322
345
  * effective budget (`options.astBudget` or {@link AST_BUDGET}).
323
346
  */
324
- declare function transformSourceCode(source: string, filename?: string, options?: TransformSourceCodeOptions): {
325
- code: string;
326
- transformed: boolean;
327
- usesRuntime: boolean;
328
- usesMerge: boolean;
329
- usesColorVar: boolean;
330
- classes: Set<string>;
331
- rawClassNames: Set<string>;
332
- diagnostics: string[];
333
- recoveryTokens: Map<string, TokenData>;
334
- };
347
+ declare function transformSourceCode(source: string, filename?: string, options?: TransformSourceCodeOptions): SourceTransformResult;
335
348
 
336
349
  /**
337
350
  * Core Compiler class for csszyx.
@@ -516,31 +529,8 @@ declare function getCSSVariableName(property: string, variantPrefix?: string): s
516
529
  * API mapping referenced throughout this file.
517
530
  */
518
531
 
519
- /**
520
- * Result shape returned by both `transformSourceCode` (Babel) and the
521
- * future `transformOxc`. Kept in lock-step so the parity harness can
522
- * diff results without conditional logic.
523
- */
524
- interface TransformOxcResult {
525
- /** Rewritten source — equal to input when `transformed === false`. */
526
- code: string;
527
- /** True when at least one sz/szRecover/_sz mutation was applied. */
528
- transformed: boolean;
529
- /** Did the file pull in `_sz` runtime helper? */
530
- usesRuntime: boolean;
531
- /** Did the file pull in `_szMerge` runtime helper? */
532
- usesMerge: boolean;
533
- /** Did the file use color-var helpers? */
534
- usesColorVar: boolean;
535
- /** Class names emitted by the compiler — drives the mangle map. */
536
- classes: Set<string>;
537
- /** Hand-written `className="..."` strings — TW JIT safelist only. */
538
- rawClassNames: Set<string>;
539
- /** Dev-mode warnings emitted during transform. */
540
- diagnostics: string[];
541
- /** Recovery tokens emitted by szRecover attributes. */
542
- recoveryTokens: Map<string, TokenData>;
543
- }
532
+ /** Result shape returned by the oxc parser path. */
533
+ type TransformOxcResult = SourceTransformResult;
544
534
  /**
545
535
  * Thrown when a caller hits a code path the current slice does not yet
546
536
  * implement. The parity harness catches this and reports the fixture
@@ -564,6 +554,62 @@ declare class OxcNotImplementedError extends Error {
564
554
  */
565
555
  declare function transformOxc(source: string, filename?: string, options?: TransformSourceCodeOptions): TransformOxcResult;
566
556
 
557
+ /**
558
+ * Source file passed to the Rust native batch transform.
559
+ */
560
+ interface TransformRustFile {
561
+ /** Source filename for diagnostics and recovery-token stability. */
562
+ filename?: string;
563
+ /** Source module contents. */
564
+ source: string;
565
+ }
566
+ /**
567
+ * Thrown when the Rust native transform cannot execute for the current host.
568
+ *
569
+ * The class name is kept for compatibility with earlier scaffold-era callers.
570
+ */
571
+ declare class OxcRustNotImplementedError extends Error {
572
+ /**
573
+ * @param detail Native loader or transform failure detail.
574
+ */
575
+ constructor(detail: string);
576
+ }
577
+ /**
578
+ * Transform source through the Rust native engine.
579
+ *
580
+ * @param source Source module contents.
581
+ * @param filename Source filename for diagnostics.
582
+ * @param options Compiler options.
583
+ * @returns Transform result.
584
+ * @throws {OxcRustNotImplementedError} when the native addon is unavailable.
585
+ */
586
+ declare function transformRust(source: string, filename?: string, options?: TransformSourceCodeOptions): SourceTransformResult;
587
+ /**
588
+ * Verify that the native Rust transform binding can be loaded.
589
+ *
590
+ * This is intentionally separate from `transformRust()` so build integrations
591
+ * can validate the explicit `rust` parser contract before serving cached
592
+ * output. If the native addon is missing, `rust` must fail loudly instead of
593
+ * returning a stale cache entry.
594
+ *
595
+ * @throws {OxcRustNotImplementedError} when the native addon is unavailable.
596
+ */
597
+ declare function ensureRustTransformAvailable(): void;
598
+ /**
599
+ * Transform a batch of files through the Rust native engine in one napi call.
600
+ *
601
+ * This is the compiler-level wrapper around `@csszyx/core/native`'s batch API.
602
+ * It keeps JS callers on the normal `SourceTransformResult` contract while
603
+ * preserving the Rust core's FFI amortization for benchmarks and future build
604
+ * integrations.
605
+ *
606
+ * @param files Source files to transform.
607
+ * @param options Compiler options reserved for future native config plumbing.
608
+ * @returns One transform result per input file, in input order.
609
+ * @throws {OxcRustNotImplementedError} when the native addon is unavailable.
610
+ */
611
+ declare function transformRustBatch(files: readonly TransformRustFile[], options?: TransformSourceCodeOptions): SourceTransformResult[];
612
+
567
613
  interface StandardLonghandProperties<TLength = (string & {}) | 0, TTime = string & {}> {
568
614
  /**
569
615
  * This feature is not Baseline because it does not work in some of the most widely-used browsers.
@@ -13480,5 +13526,5 @@ declare const DEFAULT_COMPILER_OPTIONS: Required<CompilerOptions>;
13480
13526
  */
13481
13527
  declare function mergeOptions(options?: Partial<CompilerOptions>): Required<CompilerOptions>;
13482
13528
 
13483
- export { COLOR_PROPERTIES, CsszyxCompiler, DEFAULT_COMPILER_OPTIONS, ManifestBuilder, OxcNotImplementedError, PROPERTY_CATEGORY_MAP, PropertyCategory, SzObject, VERSION, buildParentMap, createRecoveryToken, generateRecoveryToken, getCSSVariableName, getPropertyCategory, hoistCSSVariables, injectRecoveryToken, isValidRecoveryMode, mergeOptions, parseManifest, serializeManifest, transformOxc, transformSourceCode, validateManifest, validateSzRecover };
13484
- export type { BackgroundProps, BorderProps, BorderRadiusValue, CSSVarUsage, ColorName, ColorObjectValue, ColorPropValue, ColorShade, ColorValue, CompilerOptions, ContainerSize, CustomTheme, EffectsProps, FilterProps, FlexboxGridProps, FractionValue, InteractivityProps, LayoutProps, NegativeSpacingValue, RecoveryManifest, RecoveryMode, RecoveryToken, ShadowValue, SizingProps, SpacingProps, SpacingScale, SpacingValue, SvgProps, SzPropValue, SzProps, SzPropsBase, TableProps, TokenData, TokenMetadata, TransformOxcResult, TransformProps, TransitionAnimationProps, TypographyProps, VariantModifiers };
13529
+ export { COLOR_PROPERTIES, CsszyxCompiler, DEFAULT_COMPILER_OPTIONS, ManifestBuilder, OxcNotImplementedError, OxcRustNotImplementedError, PROPERTY_CATEGORY_MAP, PropertyCategory, SzObject, VERSION, buildParentMap, createRecoveryToken, ensureRustTransformAvailable, generateRecoveryToken, getCSSVariableName, getPropertyCategory, hoistCSSVariables, injectRecoveryToken, isValidRecoveryMode, mergeOptions, parseManifest, serializeManifest, transformOxc, transformRust, transformRustBatch, transformSourceCode, validateManifest, validateSzRecover };
13530
+ export type { BackgroundProps, BorderProps, BorderRadiusValue, CSSVarUsage, ColorName, ColorObjectValue, ColorPropValue, ColorShade, ColorValue, CompilerOptions, ContainerSize, CustomTheme, EffectsProps, FilterProps, FlexboxGridProps, FractionValue, InteractivityProps, LayoutProps, NegativeSpacingValue, RecoveryManifest, RecoveryMode, RecoveryToken, ShadowValue, SizingProps, SourceTransformResult, SpacingProps, SpacingScale, SpacingValue, SvgProps, SzPropValue, SzProps, SzPropsBase, TableProps, TokenData, TokenMetadata, TransformOxcResult, TransformProps, TransformRustFile, TransitionAnimationProps, TypographyProps, VariantModifiers };
package/dist/index.d.mts CHANGED
@@ -309,6 +309,29 @@ interface TransformSourceCodeOptions {
309
309
  */
310
310
  astBudget?: number;
311
311
  }
312
+ /**
313
+ * Source transform result shared by the Babel and oxc parser paths.
314
+ */
315
+ interface SourceTransformResult {
316
+ /** Rewritten source code. */
317
+ code: string;
318
+ /** Whether csszyx changed the source. */
319
+ transformed: boolean;
320
+ /** Whether the source needs the _sz runtime helper. */
321
+ usesRuntime: boolean;
322
+ /** Whether the source needs the _szMerge runtime helper. */
323
+ usesMerge: boolean;
324
+ /** Whether the source needs the color-var runtime helper. */
325
+ usesColorVar: boolean;
326
+ /** Classes generated from sz syntax. */
327
+ classes: Set<string>;
328
+ /** Raw className/class strings collected for Tailwind discovery only. */
329
+ rawClassNames: Set<string>;
330
+ /** Compiler diagnostics to emit in development. */
331
+ diagnostics: string[];
332
+ /** Recovery tokens emitted by szRecover attributes. */
333
+ recoveryTokens: Map<string, TokenData>;
334
+ }
312
335
  /**
313
336
  * Transforms all sz props in a source code string into Tailwind classNames.
314
337
  *
@@ -321,17 +344,7 @@ interface TransformSourceCodeOptions {
321
344
  * @throws {ASTBudgetExceededError} when the file's AST exceeds the
322
345
  * effective budget (`options.astBudget` or {@link AST_BUDGET}).
323
346
  */
324
- declare function transformSourceCode(source: string, filename?: string, options?: TransformSourceCodeOptions): {
325
- code: string;
326
- transformed: boolean;
327
- usesRuntime: boolean;
328
- usesMerge: boolean;
329
- usesColorVar: boolean;
330
- classes: Set<string>;
331
- rawClassNames: Set<string>;
332
- diagnostics: string[];
333
- recoveryTokens: Map<string, TokenData>;
334
- };
347
+ declare function transformSourceCode(source: string, filename?: string, options?: TransformSourceCodeOptions): SourceTransformResult;
335
348
 
336
349
  /**
337
350
  * Core Compiler class for csszyx.
@@ -516,31 +529,8 @@ declare function getCSSVariableName(property: string, variantPrefix?: string): s
516
529
  * API mapping referenced throughout this file.
517
530
  */
518
531
 
519
- /**
520
- * Result shape returned by both `transformSourceCode` (Babel) and the
521
- * future `transformOxc`. Kept in lock-step so the parity harness can
522
- * diff results without conditional logic.
523
- */
524
- interface TransformOxcResult {
525
- /** Rewritten source — equal to input when `transformed === false`. */
526
- code: string;
527
- /** True when at least one sz/szRecover/_sz mutation was applied. */
528
- transformed: boolean;
529
- /** Did the file pull in `_sz` runtime helper? */
530
- usesRuntime: boolean;
531
- /** Did the file pull in `_szMerge` runtime helper? */
532
- usesMerge: boolean;
533
- /** Did the file use color-var helpers? */
534
- usesColorVar: boolean;
535
- /** Class names emitted by the compiler — drives the mangle map. */
536
- classes: Set<string>;
537
- /** Hand-written `className="..."` strings — TW JIT safelist only. */
538
- rawClassNames: Set<string>;
539
- /** Dev-mode warnings emitted during transform. */
540
- diagnostics: string[];
541
- /** Recovery tokens emitted by szRecover attributes. */
542
- recoveryTokens: Map<string, TokenData>;
543
- }
532
+ /** Result shape returned by the oxc parser path. */
533
+ type TransformOxcResult = SourceTransformResult;
544
534
  /**
545
535
  * Thrown when a caller hits a code path the current slice does not yet
546
536
  * implement. The parity harness catches this and reports the fixture
@@ -564,6 +554,62 @@ declare class OxcNotImplementedError extends Error {
564
554
  */
565
555
  declare function transformOxc(source: string, filename?: string, options?: TransformSourceCodeOptions): TransformOxcResult;
566
556
 
557
+ /**
558
+ * Source file passed to the Rust native batch transform.
559
+ */
560
+ interface TransformRustFile {
561
+ /** Source filename for diagnostics and recovery-token stability. */
562
+ filename?: string;
563
+ /** Source module contents. */
564
+ source: string;
565
+ }
566
+ /**
567
+ * Thrown when the Rust native transform cannot execute for the current host.
568
+ *
569
+ * The class name is kept for compatibility with earlier scaffold-era callers.
570
+ */
571
+ declare class OxcRustNotImplementedError extends Error {
572
+ /**
573
+ * @param detail Native loader or transform failure detail.
574
+ */
575
+ constructor(detail: string);
576
+ }
577
+ /**
578
+ * Transform source through the Rust native engine.
579
+ *
580
+ * @param source Source module contents.
581
+ * @param filename Source filename for diagnostics.
582
+ * @param options Compiler options.
583
+ * @returns Transform result.
584
+ * @throws {OxcRustNotImplementedError} when the native addon is unavailable.
585
+ */
586
+ declare function transformRust(source: string, filename?: string, options?: TransformSourceCodeOptions): SourceTransformResult;
587
+ /**
588
+ * Verify that the native Rust transform binding can be loaded.
589
+ *
590
+ * This is intentionally separate from `transformRust()` so build integrations
591
+ * can validate the explicit `rust` parser contract before serving cached
592
+ * output. If the native addon is missing, `rust` must fail loudly instead of
593
+ * returning a stale cache entry.
594
+ *
595
+ * @throws {OxcRustNotImplementedError} when the native addon is unavailable.
596
+ */
597
+ declare function ensureRustTransformAvailable(): void;
598
+ /**
599
+ * Transform a batch of files through the Rust native engine in one napi call.
600
+ *
601
+ * This is the compiler-level wrapper around `@csszyx/core/native`'s batch API.
602
+ * It keeps JS callers on the normal `SourceTransformResult` contract while
603
+ * preserving the Rust core's FFI amortization for benchmarks and future build
604
+ * integrations.
605
+ *
606
+ * @param files Source files to transform.
607
+ * @param options Compiler options reserved for future native config plumbing.
608
+ * @returns One transform result per input file, in input order.
609
+ * @throws {OxcRustNotImplementedError} when the native addon is unavailable.
610
+ */
611
+ declare function transformRustBatch(files: readonly TransformRustFile[], options?: TransformSourceCodeOptions): SourceTransformResult[];
612
+
567
613
  interface StandardLonghandProperties<TLength = (string & {}) | 0, TTime = string & {}> {
568
614
  /**
569
615
  * This feature is not Baseline because it does not work in some of the most widely-used browsers.
@@ -13480,5 +13526,5 @@ declare const DEFAULT_COMPILER_OPTIONS: Required<CompilerOptions>;
13480
13526
  */
13481
13527
  declare function mergeOptions(options?: Partial<CompilerOptions>): Required<CompilerOptions>;
13482
13528
 
13483
- export { COLOR_PROPERTIES, CsszyxCompiler, DEFAULT_COMPILER_OPTIONS, ManifestBuilder, OxcNotImplementedError, PROPERTY_CATEGORY_MAP, PropertyCategory, SzObject, VERSION, buildParentMap, createRecoveryToken, generateRecoveryToken, getCSSVariableName, getPropertyCategory, hoistCSSVariables, injectRecoveryToken, isValidRecoveryMode, mergeOptions, parseManifest, serializeManifest, transformOxc, transformSourceCode, validateManifest, validateSzRecover };
13484
- export type { BackgroundProps, BorderProps, BorderRadiusValue, CSSVarUsage, ColorName, ColorObjectValue, ColorPropValue, ColorShade, ColorValue, CompilerOptions, ContainerSize, CustomTheme, EffectsProps, FilterProps, FlexboxGridProps, FractionValue, InteractivityProps, LayoutProps, NegativeSpacingValue, RecoveryManifest, RecoveryMode, RecoveryToken, ShadowValue, SizingProps, SpacingProps, SpacingScale, SpacingValue, SvgProps, SzPropValue, SzProps, SzPropsBase, TableProps, TokenData, TokenMetadata, TransformOxcResult, TransformProps, TransitionAnimationProps, TypographyProps, VariantModifiers };
13529
+ export { COLOR_PROPERTIES, CsszyxCompiler, DEFAULT_COMPILER_OPTIONS, ManifestBuilder, OxcNotImplementedError, OxcRustNotImplementedError, PROPERTY_CATEGORY_MAP, PropertyCategory, SzObject, VERSION, buildParentMap, createRecoveryToken, ensureRustTransformAvailable, generateRecoveryToken, getCSSVariableName, getPropertyCategory, hoistCSSVariables, injectRecoveryToken, isValidRecoveryMode, mergeOptions, parseManifest, serializeManifest, transformOxc, transformRust, transformRustBatch, transformSourceCode, validateManifest, validateSzRecover };
13530
+ export type { BackgroundProps, BorderProps, BorderRadiusValue, CSSVarUsage, ColorName, ColorObjectValue, ColorPropValue, ColorShade, ColorValue, CompilerOptions, ContainerSize, CustomTheme, EffectsProps, FilterProps, FlexboxGridProps, FractionValue, InteractivityProps, LayoutProps, NegativeSpacingValue, RecoveryManifest, RecoveryMode, RecoveryToken, ShadowValue, SizingProps, SourceTransformResult, SpacingProps, SpacingScale, SpacingValue, SvgProps, SzPropValue, SzProps, SzPropsBase, TableProps, TokenData, TokenMetadata, TransformOxcResult, TransformProps, TransformRustFile, TransitionAnimationProps, TypographyProps, VariantModifiers };
package/dist/index.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  import { init, version, transform_sz } from '@csszyx/core';
2
- import { t as transform, C as COLOR_PROPERTIES, P as PROPERTY_MAP, g as getCSSVariableName, a as PropertyCategory, K as KNOWN_VARIANTS, b as getVariantPrefix, c as getPropertyCategory, s as stripInvalidColorStrings } from './shared/compiler.BIUVmI0H.mjs';
3
- export { B as BOOLEAN_SHORTHANDS, d as PROPERTY_CATEGORY_MAP, S as SUGGESTION_MAP, i as isValidSzProp, n as normalizeClassName } from './shared/compiler.BIUVmI0H.mjs';
2
+ import { t as transform, C as COLOR_PROPERTIES, P as PROPERTY_MAP, g as getCSSVariableName, a as PropertyCategory, K as KNOWN_VARIANTS, b as getVariantPrefix, c as getPropertyCategory, s as stripInvalidColorStrings } from './shared/compiler.CUn8HGmA.mjs';
3
+ export { B as BOOLEAN_SHORTHANDS, d as PROPERTY_CATEGORY_MAP, S as SUGGESTION_MAP, i as isValidSzProp, n as normalizeClassName } from './shared/compiler.CUn8HGmA.mjs';
4
4
  import * as t from '@babel/types';
5
5
  import { createHash } from 'node:crypto';
6
6
  import * as babel from '@babel/core';
7
7
  import MagicString from 'magic-string';
8
8
  import { parseSync } from 'oxc-parser';
9
+ import { transformBatch, CsszyxNativeUnavailableError } from '@csszyx/core/native';
9
10
 
10
11
  const AST_BUDGET = 5e4;
11
12
  class ASTBudgetExceededError extends Error {
@@ -2690,6 +2691,80 @@ function walk(node, visit) {
2690
2691
  }
2691
2692
  }
2692
2693
 
2694
+ class OxcRustNotImplementedError extends Error {
2695
+ /**
2696
+ * @param detail Native loader or transform failure detail.
2697
+ */
2698
+ constructor(detail) {
2699
+ super(`transformRust: native engine unavailable - ${detail}`);
2700
+ this.name = "OxcRustNotImplementedError";
2701
+ }
2702
+ }
2703
+ function transformRust(source, filename, options) {
2704
+ const [result] = transformRustBatch([{ filename, source }]);
2705
+ if (!result) {
2706
+ throw new OxcRustNotImplementedError("native transform returned no result");
2707
+ }
2708
+ return result;
2709
+ }
2710
+ function ensureRustTransformAvailable() {
2711
+ try {
2712
+ transformBatch([]);
2713
+ } catch (err) {
2714
+ if (err instanceof OxcRustNotImplementedError) {
2715
+ throw err;
2716
+ }
2717
+ if (err instanceof CsszyxNativeUnavailableError) {
2718
+ throw new OxcRustNotImplementedError(
2719
+ `${err.message}; native package: ${err.packageName ?? "unsupported platform"}`
2720
+ );
2721
+ }
2722
+ throw err;
2723
+ }
2724
+ }
2725
+ function transformRustBatch(files, options) {
2726
+ try {
2727
+ return transformBatch(
2728
+ files.map((file, index) => ({
2729
+ filename: file.filename ?? `file-${index}.tsx`,
2730
+ source: file.source
2731
+ }))
2732
+ ).map(fromNativeResult);
2733
+ } catch (err) {
2734
+ if (err instanceof OxcRustNotImplementedError) {
2735
+ throw err;
2736
+ }
2737
+ if (err instanceof CsszyxNativeUnavailableError) {
2738
+ throw new OxcRustNotImplementedError(
2739
+ `${err.message}; native package: ${err.packageName ?? "unsupported platform"}`
2740
+ );
2741
+ }
2742
+ throw err;
2743
+ }
2744
+ }
2745
+ function fromNativeResult(result) {
2746
+ return {
2747
+ code: result.code,
2748
+ transformed: result.metadata.transformed,
2749
+ usesRuntime: result.metadata.usesRuntime,
2750
+ usesMerge: result.metadata.usesMerge,
2751
+ usesColorVar: result.metadata.usesColorVar,
2752
+ classes: new Set(result.classes),
2753
+ rawClassNames: new Set(result.rawClassNames),
2754
+ diagnostics: result.diagnostics,
2755
+ recoveryTokens: new Map(
2756
+ result.recoveryTokens.map(({ token, ...data }) => [
2757
+ token,
2758
+ {
2759
+ mode: data.mode,
2760
+ component: data.component,
2761
+ path: data.path
2762
+ }
2763
+ ])
2764
+ )
2765
+ };
2766
+ }
2767
+
2693
2768
  const VERSION = "0.0.0";
2694
2769
  const DEFAULT_COMPILER_OPTIONS = {
2695
2770
  buildId: Date.now().toString(),
@@ -2703,4 +2778,4 @@ function mergeOptions(options = {}) {
2703
2778
  };
2704
2779
  }
2705
2780
 
2706
- export { COLOR_PROPERTIES, CsszyxCompiler, DEFAULT_COMPILER_OPTIONS, KNOWN_VARIANTS, ManifestBuilder, OxcNotImplementedError, PROPERTY_MAP, PropertyCategory, VERSION, buildParentMap, createRecoveryToken, generateRecoveryToken, getCSSVariableName, getPropertyCategory, hoistCSSVariables, injectRecoveryToken, isValidRecoveryMode, mergeOptions, parseManifest, serializeManifest, transform, transformOxc, transformSourceCode, validateManifest, validateSzRecover };
2781
+ export { COLOR_PROPERTIES, CsszyxCompiler, DEFAULT_COMPILER_OPTIONS, KNOWN_VARIANTS, ManifestBuilder, OxcNotImplementedError, OxcRustNotImplementedError, PROPERTY_MAP, PropertyCategory, VERSION, buildParentMap, createRecoveryToken, ensureRustTransformAvailable, generateRecoveryToken, getCSSVariableName, getPropertyCategory, hoistCSSVariables, injectRecoveryToken, isValidRecoveryMode, mergeOptions, parseManifest, serializeManifest, transform, transformOxc, transformRust, transformRustBatch, transformSourceCode, validateManifest, validateSzRecover };
@@ -208,10 +208,10 @@ function isValidColorString(value) {
208
208
  if (/^(rgb|hsl|oklch|color|hwb|lab|lch|oklab)\(/.test(value)) {
209
209
  return true;
210
210
  }
211
- if (/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*-\d+$/.test(value)) {
211
+ if (/^[a-z][a-z0-9]*(-[a-z0-9]+)*-\d+$/i.test(value)) {
212
212
  return true;
213
213
  }
214
- if (/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z][a-zA-Z0-9]*)*$/.test(value)) {
214
+ if (/^[a-z][a-z0-9]*(-[a-z][a-z0-9]*)*$/i.test(value)) {
215
215
  return true;
216
216
  }
217
217
  return false;
@@ -2197,7 +2197,7 @@ function transform(szProp, prefix = "", mangleMap) {
2197
2197
  if (!FRACTION_SUPPORTED_PROPS.has(rawKey)) {
2198
2198
  finalValue = `[${finalValue}]`;
2199
2199
  }
2200
- } else if (key === "aspect" && /^[0-9]+(?:\.[0-9]+)?\/[0-9]+(?:\.[0-9]+)?$/.test(finalValue)) {
2200
+ } else if (key === "aspect" && /^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/.test(finalValue)) {
2201
2201
  if (finalValue === "auto" || finalValue === "square" || finalValue === "video" || /^\d+\/\d+$/.test(finalValue)) ; else {
2202
2202
  finalValue = `[${finalValue}]`;
2203
2203
  }
@@ -2216,19 +2216,22 @@ function transform(szProp, prefix = "", mangleMap) {
2216
2216
  }
2217
2217
  }
2218
2218
  let mergedClasses = classes;
2219
- const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(xs|sm|base|lg|[2-9]?xl|\[.+\]|\(.+\))$/;
2220
- const leadingPattern = /^((?:[a-z0-9\-[\]@/:]*:)*)leading-(.+)$/;
2219
+ const textSizeBaseRe = /^text-(xs|sm|base|lg|[2-9]?xl|\[[^\]]+\]|\([^)]+\))$/;
2220
+ const leadingBaseRe = /^leading-(.+)$/;
2221
2221
  const textEntries = [];
2222
2222
  const leadingEntries = [];
2223
2223
  for (let i = 0; i < classes.length; i++) {
2224
2224
  const cls = classes[i];
2225
- const tm = textSizePattern.exec(cls);
2225
+ const lastColon = cls.lastIndexOf(":");
2226
+ const prefix2 = lastColon === -1 ? "" : cls.slice(0, lastColon + 1);
2227
+ const base = lastColon === -1 ? cls : cls.slice(lastColon + 1);
2228
+ const tm = textSizeBaseRe.exec(base);
2226
2229
  if (tm) {
2227
- textEntries.push({ index: i, prefix: tm[1], size: tm[2] });
2230
+ textEntries.push({ index: i, prefix: prefix2, size: tm[1] });
2228
2231
  }
2229
- const lm = leadingPattern.exec(cls);
2232
+ const lm = leadingBaseRe.exec(base);
2230
2233
  if (lm) {
2231
- leadingEntries.push({ index: i, prefix: lm[1], value: lm[2] });
2234
+ leadingEntries.push({ index: i, prefix: prefix2, value: lm[1] });
2232
2235
  }
2233
2236
  }
2234
2237
  if (textEntries.length > 0 && leadingEntries.length > 0) {
@@ -210,10 +210,10 @@ function isValidColorString(value) {
210
210
  if (/^(rgb|hsl|oklch|color|hwb|lab|lch|oklab)\(/.test(value)) {
211
211
  return true;
212
212
  }
213
- if (/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z0-9]+)*-\d+$/.test(value)) {
213
+ if (/^[a-z][a-z0-9]*(-[a-z0-9]+)*-\d+$/i.test(value)) {
214
214
  return true;
215
215
  }
216
- if (/^[a-zA-Z][a-zA-Z0-9]*(-[a-zA-Z][a-zA-Z0-9]*)*$/.test(value)) {
216
+ if (/^[a-z][a-z0-9]*(-[a-z][a-z0-9]*)*$/i.test(value)) {
217
217
  return true;
218
218
  }
219
219
  return false;
@@ -2199,7 +2199,7 @@ function transform(szProp, prefix = "", mangleMap) {
2199
2199
  if (!FRACTION_SUPPORTED_PROPS.has(rawKey)) {
2200
2200
  finalValue = `[${finalValue}]`;
2201
2201
  }
2202
- } else if (key === "aspect" && /^[0-9]+(?:\.[0-9]+)?\/[0-9]+(?:\.[0-9]+)?$/.test(finalValue)) {
2202
+ } else if (key === "aspect" && /^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/.test(finalValue)) {
2203
2203
  if (finalValue === "auto" || finalValue === "square" || finalValue === "video" || /^\d+\/\d+$/.test(finalValue)) ; else {
2204
2204
  finalValue = `[${finalValue}]`;
2205
2205
  }
@@ -2218,19 +2218,22 @@ function transform(szProp, prefix = "", mangleMap) {
2218
2218
  }
2219
2219
  }
2220
2220
  let mergedClasses = classes;
2221
- const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(xs|sm|base|lg|[2-9]?xl|\[.+\]|\(.+\))$/;
2222
- const leadingPattern = /^((?:[a-z0-9\-[\]@/:]*:)*)leading-(.+)$/;
2221
+ const textSizeBaseRe = /^text-(xs|sm|base|lg|[2-9]?xl|\[[^\]]+\]|\([^)]+\))$/;
2222
+ const leadingBaseRe = /^leading-(.+)$/;
2223
2223
  const textEntries = [];
2224
2224
  const leadingEntries = [];
2225
2225
  for (let i = 0; i < classes.length; i++) {
2226
2226
  const cls = classes[i];
2227
- const tm = textSizePattern.exec(cls);
2227
+ const lastColon = cls.lastIndexOf(":");
2228
+ const prefix2 = lastColon === -1 ? "" : cls.slice(0, lastColon + 1);
2229
+ const base = lastColon === -1 ? cls : cls.slice(lastColon + 1);
2230
+ const tm = textSizeBaseRe.exec(base);
2228
2231
  if (tm) {
2229
- textEntries.push({ index: i, prefix: tm[1], size: tm[2] });
2232
+ textEntries.push({ index: i, prefix: prefix2, size: tm[1] });
2230
2233
  }
2231
- const lm = leadingPattern.exec(cls);
2234
+ const lm = leadingBaseRe.exec(base);
2232
2235
  if (lm) {
2233
- leadingEntries.push({ index: i, prefix: lm[1], value: lm[2] });
2236
+ leadingEntries.push({ index: i, prefix: prefix2, value: lm[1] });
2234
2237
  }
2235
2238
  }
2236
2239
  if (textEntries.length > 0 && leadingEntries.length > 0) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const transformCore = require('./shared/compiler.C6jT0mcT.cjs');
3
+ const transformCore = require('./shared/compiler.DZgazEy8.cjs');
4
4
 
5
5
 
6
6
 
@@ -1 +1 @@
1
- export { B as BOOLEAN_SHORTHANDS, K as KNOWN_VARIANTS, P as PROPERTY_MAP, S as SUGGESTION_MAP, V as VARIANT_MAP, b as getVariantPrefix, i as isValidSzProp, e as normalizeArbitraryValue, f as normalizeArbitraryVariant, n as normalizeClassName, t as transform } from './shared/compiler.BIUVmI0H.mjs';
1
+ export { B as BOOLEAN_SHORTHANDS, K as KNOWN_VARIANTS, P as PROPERTY_MAP, S as SUGGESTION_MAP, V as VARIANT_MAP, b as getVariantPrefix, i as isValidSzProp, e as normalizeArbitraryValue, f as normalizeArbitraryVariant, n as normalizeClassName, t as transform } from './shared/compiler.CUn8HGmA.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csszyx/compiler",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Core compiler and transformation logic for csszyx",
5
5
  "keywords": [
6
6
  "csszyx",
@@ -65,7 +65,7 @@
65
65
  "@babel/types": "^7.23.6",
66
66
  "magic-string": "0.30.21",
67
67
  "oxc-parser": "0.131.0",
68
- "@csszyx/core": "0.8.0"
68
+ "@csszyx/core": "0.9.0"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/babel__core": "^7.20.5",