@csszyx/compiler 0.1.0 → 0.1.1
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/LICENSE +21 -0
- package/dist/index.cjs +51 -3
- package/dist/index.d.cts +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/index.js +51 -3
- package/package.json +10 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 csszyx contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -355,7 +355,6 @@ var PROPERTY_MAP = {
|
|
|
355
355
|
color: "text",
|
|
356
356
|
text: "text",
|
|
357
357
|
fontWeight: "font",
|
|
358
|
-
font: "font",
|
|
359
358
|
fontFamily: "font",
|
|
360
359
|
fontStretch: "font-stretch",
|
|
361
360
|
textAlign: "text",
|
|
@@ -416,6 +415,7 @@ var PROPERTY_MAP = {
|
|
|
416
415
|
shadow: "shadow",
|
|
417
416
|
shadowColor: "shadow",
|
|
418
417
|
insetShadow: "inset-shadow",
|
|
418
|
+
insetShadowColor: "inset-shadow",
|
|
419
419
|
textShadow: "text-shadow",
|
|
420
420
|
textShadowColor: "text-shadow",
|
|
421
421
|
opacity: "opacity",
|
|
@@ -515,6 +515,11 @@ var PROPERTY_MAP = {
|
|
|
515
515
|
// Overflow
|
|
516
516
|
overflow: "overflow"
|
|
517
517
|
};
|
|
518
|
+
var CSS_VAR_TYPE_HINTS = {
|
|
519
|
+
fontFamily: "family-name",
|
|
520
|
+
fontWeight: "weight",
|
|
521
|
+
text: "length"
|
|
522
|
+
};
|
|
518
523
|
var SUGGESTION_MAP = {
|
|
519
524
|
// Background
|
|
520
525
|
backgroundColor: "bg",
|
|
@@ -561,6 +566,7 @@ var SUGGESTION_MAP = {
|
|
|
561
566
|
objectPosition: "objectPos",
|
|
562
567
|
zIndex: "z",
|
|
563
568
|
// Typography
|
|
569
|
+
font: "fontWeight (for weight) or fontFamily (for family)",
|
|
564
570
|
fontStyle: "italic/notItalic (boolean)",
|
|
565
571
|
weight: "fontWeight",
|
|
566
572
|
textDecoration: "decoration or underline/lineThrough/noUnderline (boolean)",
|
|
@@ -1680,6 +1686,14 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1680
1686
|
}
|
|
1681
1687
|
continue;
|
|
1682
1688
|
}
|
|
1689
|
+
if (rawKey === "insetShadowColor") {
|
|
1690
|
+
if (String(value).startsWith("--")) {
|
|
1691
|
+
classes.push(`${prefix}inset-shadow-(color:${value})`);
|
|
1692
|
+
} else {
|
|
1693
|
+
classes.push(`${prefix}inset-shadow-${value}`);
|
|
1694
|
+
}
|
|
1695
|
+
continue;
|
|
1696
|
+
}
|
|
1683
1697
|
if (rawKey === "brightness" || rawKey === "contrast" || rawKey === "saturate" || rawKey === "scale" || rawKey === "backdropBrightness" || rawKey === "backdropContrast" || rawKey === "backdropSaturate") {
|
|
1684
1698
|
const prop = rawKey.startsWith("backdrop") ? `backdrop-${rawKey.slice(8).toLowerCase()}` : rawKey;
|
|
1685
1699
|
const sValue = String(value);
|
|
@@ -1952,7 +1966,12 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1952
1966
|
}
|
|
1953
1967
|
const isAspectRatio = key === "aspect" && /^\d+\/\d+$/.test(finalValue);
|
|
1954
1968
|
if (finalValue.startsWith("--")) {
|
|
1955
|
-
|
|
1969
|
+
const typeHint = CSS_VAR_TYPE_HINTS[rawKey];
|
|
1970
|
+
if (typeHint) {
|
|
1971
|
+
finalValue = `(${typeHint}:${finalValue})`;
|
|
1972
|
+
} else {
|
|
1973
|
+
finalValue = `(${finalValue})`;
|
|
1974
|
+
}
|
|
1956
1975
|
} else if (finalValue.startsWith("var(")) {
|
|
1957
1976
|
finalValue = `[${normalizeArbitraryValue(finalValue)}]`;
|
|
1958
1977
|
} else if (/^\d+\/\d+$/.test(finalValue)) {
|
|
@@ -1969,7 +1988,36 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1969
1988
|
classes.push(className);
|
|
1970
1989
|
}
|
|
1971
1990
|
}
|
|
1972
|
-
|
|
1991
|
+
let mergedClasses = classes;
|
|
1992
|
+
const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(.+)$/;
|
|
1993
|
+
const leadingPattern = /^((?:[a-z0-9\-[\]@/:]*:)*)leading-(.+)$/;
|
|
1994
|
+
const textEntries = [];
|
|
1995
|
+
const leadingEntries = [];
|
|
1996
|
+
for (let i = 0; i < classes.length; i++) {
|
|
1997
|
+
const cls = classes[i];
|
|
1998
|
+
const tm = textSizePattern.exec(cls);
|
|
1999
|
+
if (tm) {
|
|
2000
|
+
textEntries.push({ index: i, prefix: tm[1], size: tm[2] });
|
|
2001
|
+
}
|
|
2002
|
+
const lm = leadingPattern.exec(cls);
|
|
2003
|
+
if (lm) {
|
|
2004
|
+
leadingEntries.push({ index: i, prefix: lm[1], value: lm[2] });
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
if (textEntries.length > 0 && leadingEntries.length > 0) {
|
|
2008
|
+
const removeIndices = /* @__PURE__ */ new Set();
|
|
2009
|
+
for (const te of textEntries) {
|
|
2010
|
+
const matchingLeading = leadingEntries.find((le) => le.prefix === te.prefix);
|
|
2011
|
+
if (matchingLeading) {
|
|
2012
|
+
mergedClasses[te.index] = `${te.prefix}text-${te.size}/${matchingLeading.value}`;
|
|
2013
|
+
removeIndices.add(matchingLeading.index);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
if (removeIndices.size > 0) {
|
|
2017
|
+
mergedClasses = mergedClasses.filter((_, i) => !removeIndices.has(i));
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
const finalClasses = mergedClasses.filter(Boolean);
|
|
1973
2021
|
if (mangleMap) {
|
|
1974
2022
|
const mangledClasses = finalClasses.map((cls) => mangleMap[cls] || cls);
|
|
1975
2023
|
return {
|
package/dist/index.d.cts
CHANGED
|
@@ -779,17 +779,15 @@ interface SizingProps {
|
|
|
779
779
|
*
|
|
780
780
|
*/
|
|
781
781
|
interface TypographyProps {
|
|
782
|
-
/** @see https://tailwindcss.com/docs/font-size */
|
|
783
|
-
text?: 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl' | '8xl' | '9xl' |
|
|
782
|
+
/** @see https://tailwindcss.com/docs/font-size — use `color` for text color, `textAlign` for alignment */
|
|
783
|
+
text?: 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl' | '8xl' | '9xl' | (string & {});
|
|
784
784
|
/** @see https://tailwindcss.com/docs/font-smoothing */
|
|
785
785
|
antialiased?: boolean;
|
|
786
786
|
subpixelAntialiased?: boolean;
|
|
787
787
|
/** @see https://tailwindcss.com/docs/font-style */
|
|
788
788
|
italic?: boolean;
|
|
789
789
|
notItalic?: boolean;
|
|
790
|
-
/** @see https://tailwindcss.com/docs/font-weight
|
|
791
|
-
font?: 'thin' | 'extralight' | 'light' | 'normal' | 'medium' | 'semibold' | 'bold' | 'extrabold' | 'black' | 'sans' | 'serif' | 'mono' | (string & {});
|
|
792
|
-
/** Explicit font-weight key. Use `font` for the short form */
|
|
790
|
+
/** @see https://tailwindcss.com/docs/font-weight */
|
|
793
791
|
fontWeight?: 'thin' | 'extralight' | 'light' | 'normal' | 'medium' | 'semibold' | 'bold' | 'extrabold' | 'black' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | (string & {});
|
|
794
792
|
/** Explicit font-family key. Use `font` for the short form */
|
|
795
793
|
fontFamily?: 'sans' | 'serif' | 'mono' | (string & {});
|
|
@@ -918,8 +916,8 @@ interface BorderProps {
|
|
|
918
916
|
roundedSe?: BorderRadiusValue;
|
|
919
917
|
roundedEs?: BorderRadiusValue;
|
|
920
918
|
roundedEe?: BorderRadiusValue;
|
|
921
|
-
/** @see https://tailwindcss.com/docs/border-width */
|
|
922
|
-
border?: boolean | 0 | 2 | 4 | 8 |
|
|
919
|
+
/** @see https://tailwindcss.com/docs/border-width — use `borderColor` for border color */
|
|
920
|
+
border?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
|
923
921
|
borderX?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
|
924
922
|
borderY?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
|
925
923
|
borderT?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
package/dist/index.d.ts
CHANGED
|
@@ -779,17 +779,15 @@ interface SizingProps {
|
|
|
779
779
|
*
|
|
780
780
|
*/
|
|
781
781
|
interface TypographyProps {
|
|
782
|
-
/** @see https://tailwindcss.com/docs/font-size */
|
|
783
|
-
text?: 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl' | '8xl' | '9xl' |
|
|
782
|
+
/** @see https://tailwindcss.com/docs/font-size — use `color` for text color, `textAlign` for alignment */
|
|
783
|
+
text?: 'xs' | 'sm' | 'base' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | '6xl' | '7xl' | '8xl' | '9xl' | (string & {});
|
|
784
784
|
/** @see https://tailwindcss.com/docs/font-smoothing */
|
|
785
785
|
antialiased?: boolean;
|
|
786
786
|
subpixelAntialiased?: boolean;
|
|
787
787
|
/** @see https://tailwindcss.com/docs/font-style */
|
|
788
788
|
italic?: boolean;
|
|
789
789
|
notItalic?: boolean;
|
|
790
|
-
/** @see https://tailwindcss.com/docs/font-weight
|
|
791
|
-
font?: 'thin' | 'extralight' | 'light' | 'normal' | 'medium' | 'semibold' | 'bold' | 'extrabold' | 'black' | 'sans' | 'serif' | 'mono' | (string & {});
|
|
792
|
-
/** Explicit font-weight key. Use `font` for the short form */
|
|
790
|
+
/** @see https://tailwindcss.com/docs/font-weight */
|
|
793
791
|
fontWeight?: 'thin' | 'extralight' | 'light' | 'normal' | 'medium' | 'semibold' | 'bold' | 'extrabold' | 'black' | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | (string & {});
|
|
794
792
|
/** Explicit font-family key. Use `font` for the short form */
|
|
795
793
|
fontFamily?: 'sans' | 'serif' | 'mono' | (string & {});
|
|
@@ -918,8 +916,8 @@ interface BorderProps {
|
|
|
918
916
|
roundedSe?: BorderRadiusValue;
|
|
919
917
|
roundedEs?: BorderRadiusValue;
|
|
920
918
|
roundedEe?: BorderRadiusValue;
|
|
921
|
-
/** @see https://tailwindcss.com/docs/border-width */
|
|
922
|
-
border?: boolean | 0 | 2 | 4 | 8 |
|
|
919
|
+
/** @see https://tailwindcss.com/docs/border-width — use `borderColor` for border color */
|
|
920
|
+
border?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
|
923
921
|
borderX?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
|
924
922
|
borderY?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
|
925
923
|
borderT?: boolean | 0 | 2 | 4 | 8 | (string & {});
|
package/dist/index.js
CHANGED
|
@@ -303,7 +303,6 @@ var PROPERTY_MAP = {
|
|
|
303
303
|
color: "text",
|
|
304
304
|
text: "text",
|
|
305
305
|
fontWeight: "font",
|
|
306
|
-
font: "font",
|
|
307
306
|
fontFamily: "font",
|
|
308
307
|
fontStretch: "font-stretch",
|
|
309
308
|
textAlign: "text",
|
|
@@ -364,6 +363,7 @@ var PROPERTY_MAP = {
|
|
|
364
363
|
shadow: "shadow",
|
|
365
364
|
shadowColor: "shadow",
|
|
366
365
|
insetShadow: "inset-shadow",
|
|
366
|
+
insetShadowColor: "inset-shadow",
|
|
367
367
|
textShadow: "text-shadow",
|
|
368
368
|
textShadowColor: "text-shadow",
|
|
369
369
|
opacity: "opacity",
|
|
@@ -463,6 +463,11 @@ var PROPERTY_MAP = {
|
|
|
463
463
|
// Overflow
|
|
464
464
|
overflow: "overflow"
|
|
465
465
|
};
|
|
466
|
+
var CSS_VAR_TYPE_HINTS = {
|
|
467
|
+
fontFamily: "family-name",
|
|
468
|
+
fontWeight: "weight",
|
|
469
|
+
text: "length"
|
|
470
|
+
};
|
|
466
471
|
var SUGGESTION_MAP = {
|
|
467
472
|
// Background
|
|
468
473
|
backgroundColor: "bg",
|
|
@@ -509,6 +514,7 @@ var SUGGESTION_MAP = {
|
|
|
509
514
|
objectPosition: "objectPos",
|
|
510
515
|
zIndex: "z",
|
|
511
516
|
// Typography
|
|
517
|
+
font: "fontWeight (for weight) or fontFamily (for family)",
|
|
512
518
|
fontStyle: "italic/notItalic (boolean)",
|
|
513
519
|
weight: "fontWeight",
|
|
514
520
|
textDecoration: "decoration or underline/lineThrough/noUnderline (boolean)",
|
|
@@ -1628,6 +1634,14 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1628
1634
|
}
|
|
1629
1635
|
continue;
|
|
1630
1636
|
}
|
|
1637
|
+
if (rawKey === "insetShadowColor") {
|
|
1638
|
+
if (String(value).startsWith("--")) {
|
|
1639
|
+
classes.push(`${prefix}inset-shadow-(color:${value})`);
|
|
1640
|
+
} else {
|
|
1641
|
+
classes.push(`${prefix}inset-shadow-${value}`);
|
|
1642
|
+
}
|
|
1643
|
+
continue;
|
|
1644
|
+
}
|
|
1631
1645
|
if (rawKey === "brightness" || rawKey === "contrast" || rawKey === "saturate" || rawKey === "scale" || rawKey === "backdropBrightness" || rawKey === "backdropContrast" || rawKey === "backdropSaturate") {
|
|
1632
1646
|
const prop = rawKey.startsWith("backdrop") ? `backdrop-${rawKey.slice(8).toLowerCase()}` : rawKey;
|
|
1633
1647
|
const sValue = String(value);
|
|
@@ -1900,7 +1914,12 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1900
1914
|
}
|
|
1901
1915
|
const isAspectRatio = key === "aspect" && /^\d+\/\d+$/.test(finalValue);
|
|
1902
1916
|
if (finalValue.startsWith("--")) {
|
|
1903
|
-
|
|
1917
|
+
const typeHint = CSS_VAR_TYPE_HINTS[rawKey];
|
|
1918
|
+
if (typeHint) {
|
|
1919
|
+
finalValue = `(${typeHint}:${finalValue})`;
|
|
1920
|
+
} else {
|
|
1921
|
+
finalValue = `(${finalValue})`;
|
|
1922
|
+
}
|
|
1904
1923
|
} else if (finalValue.startsWith("var(")) {
|
|
1905
1924
|
finalValue = `[${normalizeArbitraryValue(finalValue)}]`;
|
|
1906
1925
|
} else if (/^\d+\/\d+$/.test(finalValue)) {
|
|
@@ -1917,7 +1936,36 @@ function transform(szProp, prefix = "", mangleMap) {
|
|
|
1917
1936
|
classes.push(className);
|
|
1918
1937
|
}
|
|
1919
1938
|
}
|
|
1920
|
-
|
|
1939
|
+
let mergedClasses = classes;
|
|
1940
|
+
const textSizePattern = /^((?:[a-z0-9\-[\]@/:]*:)*)text-(.+)$/;
|
|
1941
|
+
const leadingPattern = /^((?:[a-z0-9\-[\]@/:]*:)*)leading-(.+)$/;
|
|
1942
|
+
const textEntries = [];
|
|
1943
|
+
const leadingEntries = [];
|
|
1944
|
+
for (let i = 0; i < classes.length; i++) {
|
|
1945
|
+
const cls = classes[i];
|
|
1946
|
+
const tm = textSizePattern.exec(cls);
|
|
1947
|
+
if (tm) {
|
|
1948
|
+
textEntries.push({ index: i, prefix: tm[1], size: tm[2] });
|
|
1949
|
+
}
|
|
1950
|
+
const lm = leadingPattern.exec(cls);
|
|
1951
|
+
if (lm) {
|
|
1952
|
+
leadingEntries.push({ index: i, prefix: lm[1], value: lm[2] });
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
if (textEntries.length > 0 && leadingEntries.length > 0) {
|
|
1956
|
+
const removeIndices = /* @__PURE__ */ new Set();
|
|
1957
|
+
for (const te of textEntries) {
|
|
1958
|
+
const matchingLeading = leadingEntries.find((le) => le.prefix === te.prefix);
|
|
1959
|
+
if (matchingLeading) {
|
|
1960
|
+
mergedClasses[te.index] = `${te.prefix}text-${te.size}/${matchingLeading.value}`;
|
|
1961
|
+
removeIndices.add(matchingLeading.index);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
if (removeIndices.size > 0) {
|
|
1965
|
+
mergedClasses = mergedClasses.filter((_, i) => !removeIndices.has(i));
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
const finalClasses = mergedClasses.filter(Boolean);
|
|
1921
1969
|
if (mangleMap) {
|
|
1922
1970
|
const mangledClasses = finalClasses.map((cls) => mangleMap[cls] || cls);
|
|
1923
1971
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csszyx/compiler",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Core compiler and transformation logic for csszyx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"csszyx",
|
|
@@ -34,18 +34,11 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
39
|
-
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
40
|
-
"test": "vitest run",
|
|
41
|
-
"test:watch": "vitest",
|
|
42
|
-
"type-check": "tsc --noEmit"
|
|
43
|
-
},
|
|
44
37
|
"dependencies": {
|
|
45
38
|
"@babel/core": "^7.23.7",
|
|
46
39
|
"@babel/types": "^7.23.6",
|
|
47
40
|
"@babel/traverse": "^7.23.7",
|
|
48
|
-
"@csszyx/core": "
|
|
41
|
+
"@csszyx/core": "0.1.1"
|
|
49
42
|
},
|
|
50
43
|
"devDependencies": {
|
|
51
44
|
"@types/babel__core": "^7.20.5",
|
|
@@ -54,5 +47,12 @@
|
|
|
54
47
|
"tsup": "^8.0.0",
|
|
55
48
|
"typescript": "^5.3.3",
|
|
56
49
|
"vitest": "^1.2.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
53
|
+
"dev": "tsup src/index.ts --format esm --dts --watch",
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"test:watch": "vitest",
|
|
56
|
+
"type-check": "tsc --noEmit"
|
|
57
57
|
}
|
|
58
|
-
}
|
|
58
|
+
}
|