@csszyx/compiler 0.6.2 → 0.8.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.
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const transformCore = require('./shared/compiler.C6jT0mcT.cjs');
4
+
5
+
6
+
7
+ exports.BOOLEAN_SHORTHANDS = transformCore.BOOLEAN_SHORTHANDS;
8
+ exports.KNOWN_VARIANTS = transformCore.KNOWN_VARIANTS;
9
+ exports.PROPERTY_MAP = transformCore.PROPERTY_MAP;
10
+ exports.SUGGESTION_MAP = transformCore.SUGGESTION_MAP;
11
+ exports.VARIANT_MAP = transformCore.VARIANT_MAP;
12
+ exports.getVariantPrefix = transformCore.getVariantPrefix;
13
+ exports.isValidSzProp = transformCore.isValidSzProp;
14
+ exports.normalizeArbitraryValue = transformCore.normalizeArbitraryValue;
15
+ exports.normalizeArbitraryVariant = transformCore.normalizeArbitraryVariant;
16
+ exports.normalizeClassName = transformCore.normalizeClassName;
17
+ exports.transform = transformCore.transform;
@@ -0,0 +1,86 @@
1
+ /**
2
+ * JSX Transform - Converts sz prop to className string.
3
+ *
4
+ * This module handles the transformation of csszyx object syntax into
5
+ * Tailwind CSS class strings. It processes nested objects for variants
6
+ * like hover, focus, etc.
7
+ */
8
+ /**
9
+ * Represents a value in the sz object.
10
+ * Can be a string, number, boolean, or nested object for variants.
11
+ */
12
+ type SzValue = string | number | boolean | SzObject;
13
+ /**
14
+ * Represents the sz object structure.
15
+ * Keys are CSS property abbreviations, values can be primitives or nested objects.
16
+ */
17
+ interface SzObject {
18
+ [key: string]: SzValue;
19
+ }
20
+ /**
21
+ * Readonly variant of SzValue — accepts values from `as const` objects.
22
+ */
23
+ type ReadonlySzValue = string | number | boolean | ReadonlySzObject;
24
+ /**
25
+ * Readonly variant of SzObject — accepts `as const` objects without requiring `as any`.
26
+ * Use this as the parameter type for functions that accept but do not mutate sz objects.
27
+ */
28
+ interface ReadonlySzObject {
29
+ readonly [key: string]: ReadonlySzValue;
30
+ }
31
+ declare const PROPERTY_MAP: Record<string, string>;
32
+ declare const SUGGESTION_MAP: Record<string, string>;
33
+ declare const VARIANT_MAP: Record<string, string>;
34
+ declare const KNOWN_VARIANTS: Set<string>;
35
+ declare const BOOLEAN_SHORTHANDS: Set<string>;
36
+ /**
37
+ * Represents the result of a transformation.
38
+ */
39
+ interface TransformResult {
40
+ className: string;
41
+ attributes: Record<string, string>;
42
+ }
43
+ /**
44
+ * Normalizes arbitrary variant selectors (removes extra whitespace)
45
+ * @param key - the arbitrary variant key to normalize
46
+ * @returns normalized variant string with whitespace removed
47
+ */
48
+ declare function normalizeArbitraryVariant(key: string): string;
49
+ /**
50
+ * Normalizes arbitrary values for Tailwind
51
+ * @param value - the arbitrary value to normalize
52
+ * @returns normalized value with spaces replaced by underscores
53
+ */
54
+ declare function normalizeArbitraryValue(value: string): string;
55
+ /**
56
+ * Gets the variant prefix from a camelCase key
57
+ * @param key - the camelCase variant key
58
+ * @returns the mapped or kebab-cased variant prefix
59
+ */
60
+ declare function getVariantPrefix(key: string): string;
61
+ /**
62
+ * Transforms a csszyx sz object into a Tailwind CSS className string and extracted attributes.
63
+ *
64
+ * @param {SzObject} szProp - The sz object from JSX
65
+ * @param {string} prefix - Variant prefix for nested properties
66
+ * @param {Record<string, string>} [mangleMap] - Optional map for property name mangling
67
+ * @returns {TransformResult} The transformation result
68
+ */
69
+ declare function transform(szProp: SzObject, prefix?: string, mangleMap?: Record<string, string>): TransformResult;
70
+ /**
71
+ * Validates that an sz prop object is valid.
72
+ *
73
+ * @param {unknown} szProp - The value to validate
74
+ * @returns {boolean} True if valid, false otherwise
75
+ */
76
+ declare function isValidSzProp(szProp: unknown): szProp is SzObject;
77
+ /**
78
+ * Normalizes a className string by removing extra whitespace.
79
+ *
80
+ * @param {string} className - The className string to normalize
81
+ * @returns {string} The normalized className string
82
+ */
83
+ declare function normalizeClassName(className: string): string;
84
+
85
+ export { BOOLEAN_SHORTHANDS, KNOWN_VARIANTS, PROPERTY_MAP, SUGGESTION_MAP, VARIANT_MAP, getVariantPrefix, isValidSzProp, normalizeArbitraryValue, normalizeArbitraryVariant, normalizeClassName, transform };
86
+ export type { ReadonlySzObject, ReadonlySzValue, SzObject, SzValue, TransformResult };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * JSX Transform - Converts sz prop to className string.
3
+ *
4
+ * This module handles the transformation of csszyx object syntax into
5
+ * Tailwind CSS class strings. It processes nested objects for variants
6
+ * like hover, focus, etc.
7
+ */
8
+ /**
9
+ * Represents a value in the sz object.
10
+ * Can be a string, number, boolean, or nested object for variants.
11
+ */
12
+ type SzValue = string | number | boolean | SzObject;
13
+ /**
14
+ * Represents the sz object structure.
15
+ * Keys are CSS property abbreviations, values can be primitives or nested objects.
16
+ */
17
+ interface SzObject {
18
+ [key: string]: SzValue;
19
+ }
20
+ /**
21
+ * Readonly variant of SzValue — accepts values from `as const` objects.
22
+ */
23
+ type ReadonlySzValue = string | number | boolean | ReadonlySzObject;
24
+ /**
25
+ * Readonly variant of SzObject — accepts `as const` objects without requiring `as any`.
26
+ * Use this as the parameter type for functions that accept but do not mutate sz objects.
27
+ */
28
+ interface ReadonlySzObject {
29
+ readonly [key: string]: ReadonlySzValue;
30
+ }
31
+ declare const PROPERTY_MAP: Record<string, string>;
32
+ declare const SUGGESTION_MAP: Record<string, string>;
33
+ declare const VARIANT_MAP: Record<string, string>;
34
+ declare const KNOWN_VARIANTS: Set<string>;
35
+ declare const BOOLEAN_SHORTHANDS: Set<string>;
36
+ /**
37
+ * Represents the result of a transformation.
38
+ */
39
+ interface TransformResult {
40
+ className: string;
41
+ attributes: Record<string, string>;
42
+ }
43
+ /**
44
+ * Normalizes arbitrary variant selectors (removes extra whitespace)
45
+ * @param key - the arbitrary variant key to normalize
46
+ * @returns normalized variant string with whitespace removed
47
+ */
48
+ declare function normalizeArbitraryVariant(key: string): string;
49
+ /**
50
+ * Normalizes arbitrary values for Tailwind
51
+ * @param value - the arbitrary value to normalize
52
+ * @returns normalized value with spaces replaced by underscores
53
+ */
54
+ declare function normalizeArbitraryValue(value: string): string;
55
+ /**
56
+ * Gets the variant prefix from a camelCase key
57
+ * @param key - the camelCase variant key
58
+ * @returns the mapped or kebab-cased variant prefix
59
+ */
60
+ declare function getVariantPrefix(key: string): string;
61
+ /**
62
+ * Transforms a csszyx sz object into a Tailwind CSS className string and extracted attributes.
63
+ *
64
+ * @param {SzObject} szProp - The sz object from JSX
65
+ * @param {string} prefix - Variant prefix for nested properties
66
+ * @param {Record<string, string>} [mangleMap] - Optional map for property name mangling
67
+ * @returns {TransformResult} The transformation result
68
+ */
69
+ declare function transform(szProp: SzObject, prefix?: string, mangleMap?: Record<string, string>): TransformResult;
70
+ /**
71
+ * Validates that an sz prop object is valid.
72
+ *
73
+ * @param {unknown} szProp - The value to validate
74
+ * @returns {boolean} True if valid, false otherwise
75
+ */
76
+ declare function isValidSzProp(szProp: unknown): szProp is SzObject;
77
+ /**
78
+ * Normalizes a className string by removing extra whitespace.
79
+ *
80
+ * @param {string} className - The className string to normalize
81
+ * @returns {string} The normalized className string
82
+ */
83
+ declare function normalizeClassName(className: string): string;
84
+
85
+ export { BOOLEAN_SHORTHANDS, KNOWN_VARIANTS, PROPERTY_MAP, SUGGESTION_MAP, VARIANT_MAP, getVariantPrefix, isValidSzProp, normalizeArbitraryValue, normalizeArbitraryVariant, normalizeClassName, transform };
86
+ export type { ReadonlySzObject, ReadonlySzValue, SzObject, SzValue, TransformResult };
@@ -0,0 +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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csszyx/compiler",
3
- "version": "0.6.2",
3
+ "version": "0.8.0",
4
4
  "description": "Core compiler and transformation logic for csszyx",
5
5
  "keywords": [
6
6
  "csszyx",
@@ -21,23 +21,39 @@
21
21
  "url": "https://github.com/nguyennhutien/csszyx/issues"
22
22
  },
23
23
  "type": "module",
24
- "main": "./dist/index.js",
25
- "module": "./dist/index.js",
26
- "types": "./dist/index.d.ts",
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.mts",
27
27
  "exports": {
28
28
  ".": {
29
- "types": "./dist/index.d.ts",
30
- "import": "./dist/index.js",
31
- "require": "./dist/index.cjs"
29
+ "import": {
30
+ "types": "./dist/index.d.mts",
31
+ "default": "./dist/index.mjs"
32
+ },
33
+ "require": {
34
+ "types": "./dist/index.d.cts",
35
+ "default": "./dist/index.cjs"
36
+ }
32
37
  },
33
38
  "./browser": {
34
- "import": "./src/transform-core.ts",
35
- "types": "./src/transform-core.ts"
39
+ "import": {
40
+ "types": "./dist/transform-core.d.mts",
41
+ "default": "./dist/transform-core.mjs"
42
+ },
43
+ "require": {
44
+ "types": "./dist/transform-core.d.cts",
45
+ "default": "./dist/transform-core.cjs"
46
+ }
36
47
  },
37
48
  "./color-var": {
38
- "types": "./dist/color-var.d.ts",
39
- "import": "./dist/color-var.js",
40
- "require": "./dist/color-var.cjs"
49
+ "import": {
50
+ "types": "./dist/color-var.d.mts",
51
+ "default": "./dist/color-var.mjs"
52
+ },
53
+ "require": {
54
+ "types": "./dist/color-var.d.cts",
55
+ "default": "./dist/color-var.cjs"
56
+ }
41
57
  }
42
58
  },
43
59
  "files": [
@@ -45,22 +61,28 @@
45
61
  ],
46
62
  "dependencies": {
47
63
  "@babel/core": "^7.23.7",
48
- "@babel/types": "^7.23.6",
49
64
  "@babel/traverse": "^7.23.7",
50
- "@csszyx/core": "0.6.2"
65
+ "@babel/types": "^7.23.6",
66
+ "magic-string": "0.30.21",
67
+ "oxc-parser": "0.131.0",
68
+ "@csszyx/core": "0.8.0"
51
69
  },
52
70
  "devDependencies": {
53
71
  "@types/babel__core": "^7.20.5",
54
72
  "@types/babel__traverse": "^7.20.5",
55
73
  "@types/node": "^20.11.0",
56
74
  "csstype": "^3.0.0",
57
- "tsup": "^8.0.0",
58
- "typescript": "^5.3.3",
59
- "vitest": "^1.2.0"
75
+ "typescript": "^6.0.3",
76
+ "unbuild": "^3.6.1",
77
+ "vitest": "^4.1.6"
78
+ },
79
+ "sideEffects": false,
80
+ "engines": {
81
+ "node": ">=22.12.0"
60
82
  },
61
83
  "scripts": {
62
- "build": "tsup src/index.ts src/color-var.ts --format esm,cjs --dts",
63
- "dev": "tsup src/index.ts src/color-var.ts --format esm --dts --watch",
84
+ "build": "unbuild",
85
+ "dev": "unbuild --stub",
64
86
  "test": "vitest run",
65
87
  "test:watch": "vitest",
66
88
  "type-check": "tsc --noEmit"
@@ -1,10 +0,0 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- export {
9
- __require
10
- };