@mgcrea/react-native-tailwind 0.5.1 → 0.6.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 +108 -0
- package/dist/babel/index.cjs +362 -8
- package/dist/parser/__snapshots__/aspectRatio.test.js.snap +9 -0
- package/dist/parser/__snapshots__/borders.test.js.snap +23 -0
- package/dist/parser/__snapshots__/colors.test.js.snap +99 -0
- package/dist/parser/__snapshots__/shadows.test.js.snap +76 -0
- package/dist/parser/__snapshots__/sizing.test.js.snap +61 -0
- package/dist/parser/__snapshots__/spacing.test.js.snap +40 -0
- package/dist/parser/__snapshots__/typography.test.js.snap +30 -0
- package/dist/parser/colors.js +1 -1
- package/dist/parser/colors.test.js +1 -1
- package/dist/parser/index.d.ts +1 -0
- package/dist/parser/index.js +1 -1
- package/dist/parser/layout.js +1 -1
- package/dist/parser/layout.test.js +1 -1
- package/dist/parser/transforms.d.ts +13 -0
- package/dist/parser/transforms.js +1 -0
- package/dist/parser/transforms.test.js +1 -0
- package/dist/parser/typography.test.js +1 -1
- package/dist/react-native.d.ts +1 -1
- package/dist/types.d.ts +32 -2
- package/package.json +1 -1
- package/src/parser/colors.test.ts +10 -0
- package/src/parser/colors.ts +14 -0
- package/src/parser/index.ts +3 -0
- package/src/parser/layout.test.ts +92 -0
- package/src/parser/layout.ts +122 -16
- package/src/parser/transforms.test.ts +318 -0
- package/src/parser/transforms.ts +406 -0
- package/src/parser/typography.test.ts +2 -0
- package/src/react-native.d.ts +1 -1
- package/src/types.ts +22 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.SKEW_MAP=exports.SCALE_MAP=exports.ROTATE_MAP=exports.PERSPECTIVE_SCALE=void 0;exports.parseTransform=parseTransform;var _spacing=require("./spacing");var SCALE_MAP=exports.SCALE_MAP={0:0,50:0.5,75:0.75,90:0.9,95:0.95,100:1,105:1.05,110:1.1,125:1.25,150:1.5,200:2};var ROTATE_MAP=exports.ROTATE_MAP={0:0,1:1,2:2,3:3,6:6,12:12,45:45,90:90,180:180};var SKEW_MAP=exports.SKEW_MAP={0:0,1:1,2:2,3:3,6:6,12:12};var PERSPECTIVE_SCALE=exports.PERSPECTIVE_SCALE={0:0,100:100,200:200,300:300,400:400,500:500,600:600,700:700,800:800,900:900,1000:1000};function parseArbitraryScale(value){var scaleMatch=value.match(/^\[(-?\d+(?:\.\d+)?)\]$/);if(scaleMatch){return parseFloat(scaleMatch[1]);}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Invalid arbitrary scale value: ${value}. Only numbers are supported (e.g., [1.5], [0.75]).`);}return null;}return null;}function parseArbitraryRotation(value){var rotateMatch=value.match(/^\[(-?\d+(?:\.\d+)?)deg\]$/);if(rotateMatch){return`${rotateMatch[1]}deg`;}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Invalid arbitrary rotation value: ${value}. Only deg unit is supported (e.g., [45deg], [-15deg]).`);}return null;}return null;}function parseArbitraryTranslation(value){var pxMatch=value.match(/^\[(-?\d+)(?:px)?\]$/);if(pxMatch){return parseInt(pxMatch[1],10);}var percentMatch=value.match(/^\[(-?\d+(?:\.\d+)?)%\]$/);if(percentMatch){return`${percentMatch[1]}%`;}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Unsupported arbitrary translation unit: ${value}. Only px and % are supported.`);}return null;}return null;}function parseArbitraryPerspective(value){var perspectiveMatch=value.match(/^\[(-?\d+)\]$/);if(perspectiveMatch){return parseInt(perspectiveMatch[1],10);}if(value.startsWith("[")&&value.endsWith("]")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] Invalid arbitrary perspective value: ${value}. Only integers are supported (e.g., [1500]).`);}return null;}return null;}function parseTransform(cls){if(cls.startsWith("origin-")){if(process.env.NODE_ENV!=="production"){console.warn(`[react-native-tailwind] transform-origin is not supported in React Native. Class "${cls}" will be ignored.`);}return null;}if(cls.startsWith("scale-")){var scaleKey=cls.substring(6);var arbitraryScale=parseArbitraryScale(scaleKey);if(arbitraryScale!==null){return{transform:[{scale:arbitraryScale}]};}var scaleValue=SCALE_MAP[scaleKey];if(scaleValue!==undefined){return{transform:[{scale:scaleValue}]};}}if(cls.startsWith("scale-x-")){var _scaleKey=cls.substring(8);var _arbitraryScale=parseArbitraryScale(_scaleKey);if(_arbitraryScale!==null){return{transform:[{scaleX:_arbitraryScale}]};}var _scaleValue=SCALE_MAP[_scaleKey];if(_scaleValue!==undefined){return{transform:[{scaleX:_scaleValue}]};}}if(cls.startsWith("scale-y-")){var _scaleKey2=cls.substring(8);var _arbitraryScale2=parseArbitraryScale(_scaleKey2);if(_arbitraryScale2!==null){return{transform:[{scaleY:_arbitraryScale2}]};}var _scaleValue2=SCALE_MAP[_scaleKey2];if(_scaleValue2!==undefined){return{transform:[{scaleY:_scaleValue2}]};}}if(cls.startsWith("rotate-")||cls.startsWith("-rotate-")){var isNegative=cls.startsWith("-");var rotateKey=isNegative?cls.substring(8):cls.substring(7);var arbitraryRotate=parseArbitraryRotation(rotateKey);if(arbitraryRotate!==null){var degrees=isNegative?`-${arbitraryRotate}`:arbitraryRotate;return{transform:[{rotate:degrees}]};}var rotateValue=ROTATE_MAP[rotateKey];if(rotateValue!==undefined){var _degrees=isNegative?-rotateValue:rotateValue;return{transform:[{rotate:`${_degrees}deg`}]};}}if(cls.startsWith("rotate-x-")||cls.startsWith("-rotate-x-")){var _isNegative=cls.startsWith("-");var _rotateKey=_isNegative?cls.substring(10):cls.substring(9);var _arbitraryRotate=parseArbitraryRotation(_rotateKey);if(_arbitraryRotate!==null){var _degrees2=_isNegative?`-${_arbitraryRotate}`:_arbitraryRotate;return{transform:[{rotateX:_degrees2}]};}var _rotateValue=ROTATE_MAP[_rotateKey];if(_rotateValue!==undefined){var _degrees3=_isNegative?-_rotateValue:_rotateValue;return{transform:[{rotateX:`${_degrees3}deg`}]};}}if(cls.startsWith("rotate-y-")||cls.startsWith("-rotate-y-")){var _isNegative2=cls.startsWith("-");var _rotateKey2=_isNegative2?cls.substring(10):cls.substring(9);var _arbitraryRotate2=parseArbitraryRotation(_rotateKey2);if(_arbitraryRotate2!==null){var _degrees4=_isNegative2?`-${_arbitraryRotate2}`:_arbitraryRotate2;return{transform:[{rotateY:_degrees4}]};}var _rotateValue2=ROTATE_MAP[_rotateKey2];if(_rotateValue2!==undefined){var _degrees5=_isNegative2?-_rotateValue2:_rotateValue2;return{transform:[{rotateY:`${_degrees5}deg`}]};}}if(cls.startsWith("rotate-z-")||cls.startsWith("-rotate-z-")){var _isNegative3=cls.startsWith("-");var _rotateKey3=_isNegative3?cls.substring(10):cls.substring(9);var _arbitraryRotate3=parseArbitraryRotation(_rotateKey3);if(_arbitraryRotate3!==null){var _degrees6=_isNegative3?`-${_arbitraryRotate3}`:_arbitraryRotate3;return{transform:[{rotateZ:_degrees6}]};}var _rotateValue3=ROTATE_MAP[_rotateKey3];if(_rotateValue3!==undefined){var _degrees7=_isNegative3?-_rotateValue3:_rotateValue3;return{transform:[{rotateZ:`${_degrees7}deg`}]};}}if(cls.startsWith("translate-x-")||cls.startsWith("-translate-x-")){var _isNegative4=cls.startsWith("-");var translateKey=_isNegative4?cls.substring(13):cls.substring(12);var arbitraryTranslate=parseArbitraryTranslation(translateKey);if(arbitraryTranslate!==null){var value=typeof arbitraryTranslate==="number"?_isNegative4?-arbitraryTranslate:arbitraryTranslate:_isNegative4?`-${arbitraryTranslate}`:arbitraryTranslate;return{transform:[{translateX:value}]};}var translateValue=_spacing.SPACING_SCALE[translateKey];if(translateValue!==undefined){var _value=_isNegative4?-translateValue:translateValue;return{transform:[{translateX:_value}]};}}if(cls.startsWith("translate-y-")||cls.startsWith("-translate-y-")){var _isNegative5=cls.startsWith("-");var _translateKey=_isNegative5?cls.substring(13):cls.substring(12);var _arbitraryTranslate=parseArbitraryTranslation(_translateKey);if(_arbitraryTranslate!==null){var _value2=typeof _arbitraryTranslate==="number"?_isNegative5?-_arbitraryTranslate:_arbitraryTranslate:_isNegative5?`-${_arbitraryTranslate}`:_arbitraryTranslate;return{transform:[{translateY:_value2}]};}var _translateValue=_spacing.SPACING_SCALE[_translateKey];if(_translateValue!==undefined){var _value3=_isNegative5?-_translateValue:_translateValue;return{transform:[{translateY:_value3}]};}}if(cls.startsWith("skew-x-")||cls.startsWith("-skew-x-")){var _isNegative6=cls.startsWith("-");var skewKey=_isNegative6?cls.substring(8):cls.substring(7);var arbitrarySkew=parseArbitraryRotation(skewKey);if(arbitrarySkew!==null){var _degrees8=_isNegative6?`-${arbitrarySkew}`:arbitrarySkew;return{transform:[{skewX:_degrees8}]};}var skewValue=SKEW_MAP[skewKey];if(skewValue!==undefined){var _degrees9=_isNegative6?-skewValue:skewValue;return{transform:[{skewX:`${_degrees9}deg`}]};}}if(cls.startsWith("skew-y-")||cls.startsWith("-skew-y-")){var _isNegative7=cls.startsWith("-");var _skewKey=_isNegative7?cls.substring(8):cls.substring(7);var _arbitrarySkew=parseArbitraryRotation(_skewKey);if(_arbitrarySkew!==null){var _degrees0=_isNegative7?`-${_arbitrarySkew}`:_arbitrarySkew;return{transform:[{skewY:_degrees0}]};}var _skewValue=SKEW_MAP[_skewKey];if(_skewValue!==undefined){var _degrees1=_isNegative7?-_skewValue:_skewValue;return{transform:[{skewY:`${_degrees1}deg`}]};}}if(cls.startsWith("perspective-")){var perspectiveKey=cls.substring(12);var arbitraryPerspective=parseArbitraryPerspective(perspectiveKey);if(arbitraryPerspective!==null){return{transform:[{perspective:arbitraryPerspective}]};}var perspectiveValue=PERSPECTIVE_SCALE[perspectiveKey];if(perspectiveValue!==undefined){return{transform:[{perspective:perspectiveValue}]};}}return null;}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _vitest=require("vitest");var _transforms=require("./transforms");(0,_vitest.describe)("SCALE_MAP",function(){(0,_vitest.it)("should export complete scale map",function(){(0,_vitest.expect)(_transforms.SCALE_MAP).toMatchSnapshot();});});(0,_vitest.describe)("ROTATE_MAP",function(){(0,_vitest.it)("should export complete rotate map",function(){(0,_vitest.expect)(_transforms.ROTATE_MAP).toMatchSnapshot();});});(0,_vitest.describe)("SKEW_MAP",function(){(0,_vitest.it)("should export complete skew map",function(){(0,_vitest.expect)(_transforms.SKEW_MAP).toMatchSnapshot();});});(0,_vitest.describe)("PERSPECTIVE_SCALE",function(){(0,_vitest.it)("should export complete perspective scale",function(){(0,_vitest.expect)(_transforms.PERSPECTIVE_SCALE).toMatchSnapshot();});});(0,_vitest.describe)("parseTransform - scale utilities",function(){(0,_vitest.it)("should parse scale values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("scale-0")).toEqual({transform:[{scale:0}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-50")).toEqual({transform:[{scale:0.5}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-75")).toEqual({transform:[{scale:0.75}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-90")).toEqual({transform:[{scale:0.9}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-95")).toEqual({transform:[{scale:0.95}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-100")).toEqual({transform:[{scale:1}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-105")).toEqual({transform:[{scale:1.05}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-110")).toEqual({transform:[{scale:1.1}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-125")).toEqual({transform:[{scale:1.25}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-150")).toEqual({transform:[{scale:1.5}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-200")).toEqual({transform:[{scale:2}]});});(0,_vitest.it)("should parse scaleX values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("scale-x-0")).toEqual({transform:[{scaleX:0}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-x-50")).toEqual({transform:[{scaleX:0.5}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-x-100")).toEqual({transform:[{scaleX:1}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-x-150")).toEqual({transform:[{scaleX:1.5}]});});(0,_vitest.it)("should parse scaleY values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("scale-y-0")).toEqual({transform:[{scaleY:0}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-y-75")).toEqual({transform:[{scaleY:0.75}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-y-100")).toEqual({transform:[{scaleY:1}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-y-125")).toEqual({transform:[{scaleY:1.25}]});});(0,_vitest.it)("should parse arbitrary scale values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("scale-[1.23]")).toEqual({transform:[{scale:1.23}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-[0.5]")).toEqual({transform:[{scale:0.5}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-[2.5]")).toEqual({transform:[{scale:2.5}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-x-[1.5]")).toEqual({transform:[{scaleX:1.5}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-y-[0.8]")).toEqual({transform:[{scaleY:0.8}]});});(0,_vitest.it)("should parse negative arbitrary scale values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("scale-[-1]")).toEqual({transform:[{scale:-1}]});(0,_vitest.expect)((0,_transforms.parseTransform)("scale-x-[-0.5]")).toEqual({transform:[{scaleX:-0.5}]});});(0,_vitest.it)("should return null for invalid scale values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("scale-999")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("scale-invalid")).toBeNull();});});(0,_vitest.describe)("parseTransform - rotate utilities",function(){(0,_vitest.it)("should parse rotate values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-0")).toEqual({transform:[{rotate:"0deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-1")).toEqual({transform:[{rotate:"1deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-45")).toEqual({transform:[{rotate:"45deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-90")).toEqual({transform:[{rotate:"90deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-180")).toEqual({transform:[{rotate:"180deg"}]});});(0,_vitest.it)("should parse negative rotate values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("-rotate-45")).toEqual({transform:[{rotate:"-45deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-rotate-90")).toEqual({transform:[{rotate:"-90deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-rotate-180")).toEqual({transform:[{rotate:"-180deg"}]});});(0,_vitest.it)("should parse arbitrary rotate values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-[37deg]")).toEqual({transform:[{rotate:"37deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-[15.5deg]")).toEqual({transform:[{rotate:"15.5deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-rotate-[15deg]")).toEqual({transform:[{rotate:"-15deg"}]});});(0,_vitest.it)("should parse rotateX values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-x-45")).toEqual({transform:[{rotateX:"45deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-x-90")).toEqual({transform:[{rotateX:"90deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-rotate-x-45")).toEqual({transform:[{rotateX:"-45deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-x-[30deg]")).toEqual({transform:[{rotateX:"30deg"}]});});(0,_vitest.it)("should parse rotateY values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-y-45")).toEqual({transform:[{rotateY:"45deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-y-180")).toEqual({transform:[{rotateY:"180deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-rotate-y-90")).toEqual({transform:[{rotateY:"-90deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-y-[60deg]")).toEqual({transform:[{rotateY:"60deg"}]});});(0,_vitest.it)("should parse rotateZ values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-z-45")).toEqual({transform:[{rotateZ:"45deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-z-90")).toEqual({transform:[{rotateZ:"90deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-rotate-z-12")).toEqual({transform:[{rotateZ:"-12deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-z-[75deg]")).toEqual({transform:[{rotateZ:"75deg"}]});});(0,_vitest.it)("should return null for invalid rotate values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-999")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("rotate-invalid")).toBeNull();});});(0,_vitest.describe)("parseTransform - translate utilities",function(){(0,_vitest.it)("should parse translateX values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-0")).toEqual({transform:[{translateX:0}]});(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-4")).toEqual({transform:[{translateX:16}]});(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-8")).toEqual({transform:[{translateX:32}]});(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-16")).toEqual({transform:[{translateX:64}]});});(0,_vitest.it)("should parse negative translateX values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-x-4")).toEqual({transform:[{translateX:-16}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-x-8")).toEqual({transform:[{translateX:-32}]});});(0,_vitest.it)("should parse translateY values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("translate-y-0")).toEqual({transform:[{translateY:0}]});(0,_vitest.expect)((0,_transforms.parseTransform)("translate-y-4")).toEqual({transform:[{translateY:16}]});(0,_vitest.expect)((0,_transforms.parseTransform)("translate-y-12")).toEqual({transform:[{translateY:48}]});});(0,_vitest.it)("should parse negative translateY values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-y-4")).toEqual({transform:[{translateY:-16}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-y-10")).toEqual({transform:[{translateY:-40}]});});(0,_vitest.it)("should parse arbitrary translateX pixel values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-[123px]")).toEqual({transform:[{translateX:123}]});(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-[50]")).toEqual({transform:[{translateX:50}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-x-[100px]")).toEqual({transform:[{translateX:-100}]});});(0,_vitest.it)("should parse arbitrary translateX percentage values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-[50%]")).toEqual({transform:[{translateX:"50%"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-[33.333%]")).toEqual({transform:[{translateX:"33.333%"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-x-[25%]")).toEqual({transform:[{translateX:"-25%"}]});});(0,_vitest.it)("should parse arbitrary translateY pixel values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("translate-y-[200px]")).toEqual({transform:[{translateY:200}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-y-[75px]")).toEqual({transform:[{translateY:-75}]});});(0,_vitest.it)("should parse arbitrary translateY percentage values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("translate-y-[100%]")).toEqual({transform:[{translateY:"100%"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-translate-y-[50%]")).toEqual({transform:[{translateY:"-50%"}]});});(0,_vitest.it)("should return null for invalid translate values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("translate-x-999")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("translate-y-invalid")).toBeNull();});});(0,_vitest.describe)("parseTransform - skew utilities",function(){(0,_vitest.it)("should parse skewX values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("skew-x-0")).toEqual({transform:[{skewX:"0deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("skew-x-1")).toEqual({transform:[{skewX:"1deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("skew-x-3")).toEqual({transform:[{skewX:"3deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("skew-x-6")).toEqual({transform:[{skewX:"6deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("skew-x-12")).toEqual({transform:[{skewX:"12deg"}]});});(0,_vitest.it)("should parse negative skewX values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("-skew-x-3")).toEqual({transform:[{skewX:"-3deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-skew-x-12")).toEqual({transform:[{skewX:"-12deg"}]});});(0,_vitest.it)("should parse skewY values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("skew-y-0")).toEqual({transform:[{skewY:"0deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("skew-y-2")).toEqual({transform:[{skewY:"2deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("skew-y-6")).toEqual({transform:[{skewY:"6deg"}]});});(0,_vitest.it)("should parse negative skewY values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("-skew-y-2")).toEqual({transform:[{skewY:"-2deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-skew-y-6")).toEqual({transform:[{skewY:"-6deg"}]});});(0,_vitest.it)("should parse arbitrary skew values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("skew-x-[15deg]")).toEqual({transform:[{skewX:"15deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("skew-y-[20deg]")).toEqual({transform:[{skewY:"20deg"}]});(0,_vitest.expect)((0,_transforms.parseTransform)("-skew-x-[8deg]")).toEqual({transform:[{skewX:"-8deg"}]});});(0,_vitest.it)("should return null for invalid skew values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("skew-x-999")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("skew-y-invalid")).toBeNull();});});(0,_vitest.describe)("parseTransform - perspective utility",function(){(0,_vitest.it)("should parse perspective values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-0")).toEqual({transform:[{perspective:0}]});(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-100")).toEqual({transform:[{perspective:100}]});(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-500")).toEqual({transform:[{perspective:500}]});(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-1000")).toEqual({transform:[{perspective:1000}]});});(0,_vitest.it)("should parse arbitrary perspective values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-[1500]")).toEqual({transform:[{perspective:1500}]});(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-[2000]")).toEqual({transform:[{perspective:2000}]});(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-[250]")).toEqual({transform:[{perspective:250}]});});(0,_vitest.it)("should return null for invalid perspective values",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-99")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("perspective-invalid")).toBeNull();});});(0,_vitest.describe)("parseTransform - transform origin warning",function(){(0,_vitest.it)("should return null and warn for origin classes",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("origin-center")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("origin-top")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("origin-left")).toBeNull();});});(0,_vitest.describe)("parseTransform - edge cases",function(){(0,_vitest.it)("should return null for invalid classes",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("invalid")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("transform")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("transforms")).toBeNull();});(0,_vitest.it)("should return null for empty string",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("")).toBeNull();});(0,_vitest.it)("should return null for partial class names",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("scal")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("rotat")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("translat")).toBeNull();});(0,_vitest.it)("should handle all transform types returning arrays",function(){var scaleResult=(0,_transforms.parseTransform)("scale-110");(0,_vitest.expect)(scaleResult).toHaveProperty("transform");(0,_vitest.expect)(Array.isArray(scaleResult==null?void 0:scaleResult.transform)).toBe(true);var rotateResult=(0,_transforms.parseTransform)("rotate-45");(0,_vitest.expect)(rotateResult).toHaveProperty("transform");(0,_vitest.expect)(Array.isArray(rotateResult==null?void 0:rotateResult.transform)).toBe(true);var translateResult=(0,_transforms.parseTransform)("translate-x-4");(0,_vitest.expect)(translateResult).toHaveProperty("transform");(0,_vitest.expect)(Array.isArray(translateResult==null?void 0:translateResult.transform)).toBe(true);});});(0,_vitest.describe)("parseTransform - comprehensive coverage",function(){(0,_vitest.it)("should handle all scale variants",function(){var scaleClasses=["scale-0","scale-50","scale-100","scale-150"];scaleClasses.forEach(function(cls){(0,_vitest.expect)((0,_transforms.parseTransform)(cls)).toBeTruthy();});});(0,_vitest.it)("should handle all rotate variants",function(){var rotateClasses=["rotate-0","rotate-45","rotate-90","rotate-180"];rotateClasses.forEach(function(cls){(0,_vitest.expect)((0,_transforms.parseTransform)(cls)).toBeTruthy();});});(0,_vitest.it)("should handle all translate variants",function(){var translateClasses=["translate-x-0","translate-x-4","translate-y-8","-translate-x-2"];translateClasses.forEach(function(cls){(0,_vitest.expect)((0,_transforms.parseTransform)(cls)).toBeTruthy();});});(0,_vitest.it)("should handle all skew variants",function(){var skewClasses=["skew-x-3","skew-y-6","-skew-x-12"];skewClasses.forEach(function(cls){(0,_vitest.expect)((0,_transforms.parseTransform)(cls)).toBeTruthy();});});(0,_vitest.it)("should handle all perspective variants",function(){var perspectiveClasses=["perspective-100","perspective-500","perspective-1000"];perspectiveClasses.forEach(function(cls){(0,_vitest.expect)((0,_transforms.parseTransform)(cls)).toBeTruthy();});});});(0,_vitest.describe)("parseTransform - case sensitivity",function(){(0,_vitest.it)("should be case-sensitive",function(){(0,_vitest.expect)((0,_transforms.parseTransform)("SCALE-110")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("Scale-110")).toBeNull();(0,_vitest.expect)((0,_transforms.parseTransform)("ROTATE-45")).toBeNull();});});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var _vitest=require("vitest");var _typography=require("./typography");(0,_vitest.describe)("FONT_SIZES",function(){(0,_vitest.it)("should export complete font size scale",function(){(0,_vitest.expect)(_typography.FONT_SIZES).toMatchSnapshot();});});(0,_vitest.describe)("LETTER_SPACING_SCALE",function(){(0,_vitest.it)("should export complete letter spacing scale",function(){(0,_vitest.expect)(_typography.LETTER_SPACING_SCALE).toMatchSnapshot();});});(0,_vitest.describe)("parseTypography - font size",function(){(0,_vitest.it)("should parse font size with preset values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-xs")).toEqual({fontSize:12});(0,_vitest.expect)((0,_typography.parseTypography)("text-sm")).toEqual({fontSize:14});(0,_vitest.expect)((0,_typography.parseTypography)("text-base")).toEqual({fontSize:16});(0,_vitest.expect)((0,_typography.parseTypography)("text-lg")).toEqual({fontSize:18});(0,_vitest.expect)((0,_typography.parseTypography)("text-xl")).toEqual({fontSize:20});(0,_vitest.expect)((0,_typography.parseTypography)("text-2xl")).toEqual({fontSize:24});(0,_vitest.expect)((0,_typography.parseTypography)("text-3xl")).toEqual({fontSize:30});(0,_vitest.expect)((0,_typography.parseTypography)("text-4xl")).toEqual({fontSize:36});(0,_vitest.expect)((0,_typography.parseTypography)("text-5xl")).toEqual({fontSize:48});(0,_vitest.expect)((0,_typography.parseTypography)("text-6xl")).toEqual({fontSize:60});(0,_vitest.expect)((0,_typography.parseTypography)("text-7xl")).toEqual({fontSize:72});(0,_vitest.expect)((0,_typography.parseTypography)("text-8xl")).toEqual({fontSize:96});(0,_vitest.expect)((0,_typography.parseTypography)("text-9xl")).toEqual({fontSize:128});});(0,_vitest.it)("should parse font size with arbitrary pixel values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[18px]")).toEqual({fontSize:18});(0,_vitest.expect)((0,_typography.parseTypography)("text-[18]")).toEqual({fontSize:18});(0,_vitest.expect)((0,_typography.parseTypography)("text-[22px]")).toEqual({fontSize:22});(0,_vitest.expect)((0,_typography.parseTypography)("text-[22]")).toEqual({fontSize:22});(0,_vitest.expect)((0,_typography.parseTypography)("text-[100px]")).toEqual({fontSize:100});});});(0,_vitest.describe)("parseTypography - font weight",function(){(0,_vitest.it)("should parse font weight values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("font-thin")).toEqual({fontWeight:"100"});(0,_vitest.expect)((0,_typography.parseTypography)("font-extralight")).toEqual({fontWeight:"200"});(0,_vitest.expect)((0,_typography.parseTypography)("font-light")).toEqual({fontWeight:"300"});(0,_vitest.expect)((0,_typography.parseTypography)("font-normal")).toEqual({fontWeight:"400"});(0,_vitest.expect)((0,_typography.parseTypography)("font-medium")).toEqual({fontWeight:"500"});(0,_vitest.expect)((0,_typography.parseTypography)("font-semibold")).toEqual({fontWeight:"600"});(0,_vitest.expect)((0,_typography.parseTypography)("font-bold")).toEqual({fontWeight:"700"});(0,_vitest.expect)((0,_typography.parseTypography)("font-extrabold")).toEqual({fontWeight:"800"});(0,_vitest.expect)((0,_typography.parseTypography)("font-black")).toEqual({fontWeight:"900"});});});(0,_vitest.describe)("parseTypography - font style",function(){(0,_vitest.it)("should parse font style values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("italic")).toEqual({fontStyle:"italic"});(0,_vitest.expect)((0,_typography.parseTypography)("not-italic")).toEqual({fontStyle:"normal"});});});(0,_vitest.describe)("parseTypography - text alignment",function(){(0,_vitest.it)("should parse text alignment values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-left")).toEqual({textAlign:"left"});(0,_vitest.expect)((0,_typography.parseTypography)("text-center")).toEqual({textAlign:"center"});(0,_vitest.expect)((0,_typography.parseTypography)("text-right")).toEqual({textAlign:"right"});(0,_vitest.expect)((0,_typography.parseTypography)("text-justify")).toEqual({textAlign:"justify"});});});(0,_vitest.describe)("parseTypography - text decoration",function(){(0,_vitest.it)("should parse text decoration values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("underline")).toEqual({textDecorationLine:"underline"});(0,_vitest.expect)((0,_typography.parseTypography)("line-through")).toEqual({textDecorationLine:"line-through"});(0,_vitest.expect)((0,_typography.parseTypography)("no-underline")).toEqual({textDecorationLine:"none"});});});(0,_vitest.describe)("parseTypography - text transform",function(){(0,_vitest.it)("should parse text transform values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("uppercase")).toEqual({textTransform:"uppercase"});(0,_vitest.expect)((0,_typography.parseTypography)("lowercase")).toEqual({textTransform:"lowercase"});(0,_vitest.expect)((0,_typography.parseTypography)("capitalize")).toEqual({textTransform:"capitalize"});(0,_vitest.expect)((0,_typography.parseTypography)("normal-case")).toEqual({textTransform:"none"});});});(0,_vitest.describe)("parseTypography - line height",function(){(0,_vitest.it)("should parse line height with preset values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("leading-none")).toEqual({lineHeight:16});(0,_vitest.expect)((0,_typography.parseTypography)("leading-tight")).toEqual({lineHeight:20});(0,_vitest.expect)((0,_typography.parseTypography)("leading-snug")).toEqual({lineHeight:22});(0,_vitest.expect)((0,_typography.parseTypography)("leading-normal")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("leading-relaxed")).toEqual({lineHeight:28});(0,_vitest.expect)((0,_typography.parseTypography)("leading-loose")).toEqual({lineHeight:32});});(0,_vitest.it)("should parse line height with arbitrary pixel values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("leading-[24px]")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[24]")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[30px]")).toEqual({lineHeight:30});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[30]")).toEqual({lineHeight:30});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[50px]")).toEqual({lineHeight:50});});});(0,_vitest.describe)("parseTypography - letter spacing",function(){(0,_vitest.it)("should parse letter spacing with preset values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("tracking-tighter")).toEqual({letterSpacing:-0.8});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-tight")).toEqual({letterSpacing:-0.4});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-normal")).toEqual({letterSpacing:0});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-wide")).toEqual({letterSpacing:0.4});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-wider")).toEqual({letterSpacing:0.8});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-widest")).toEqual({letterSpacing:1.6});});});(0,_vitest.describe)("parseTypography - edge cases",function(){(0,_vitest.it)("should return null for invalid classes",function(){(0,_vitest.expect)((0,_typography.parseTypography)("invalid")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("font")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("tracking")).toBeNull();});(0,_vitest.it)("should return null for invalid font size values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-invalid")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-10xl")).toBeNull();});(0,_vitest.it)("should return null for invalid font weight values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("font-invalid")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("font-100")).toBeNull();});(0,_vitest.it)("should return null for arbitrary values with unsupported units",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[16rem]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-[2em]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-[2rem]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-[1.5em]")).toBeNull();});(0,_vitest.it)("should return null for malformed arbitrary values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[16")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-16]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-[]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-[24")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-24]")).toBeNull();});(0,_vitest.it)("should not match partial class names",function(){(0,_vitest.expect)((0,_typography.parseTypography)("mytext-lg")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("font-bold-extra")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("italic-text")).toBeNull();});});(0,_vitest.describe)("parseTypography - comprehensive coverage",function(){(0,_vitest.it)("should handle all typography categories independently",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-base")).toEqual({fontSize:16});(0,_vitest.expect)((0,_typography.parseTypography)("font-bold")).toEqual({fontWeight:"700"});(0,_vitest.expect)((0,_typography.parseTypography)("italic")).toEqual({fontStyle:"italic"});(0,_vitest.expect)((0,_typography.parseTypography)("text-center")).toEqual({textAlign:"center"});(0,_vitest.expect)((0,_typography.parseTypography)("underline")).toEqual({textDecorationLine:"underline"});(0,_vitest.expect)((0,_typography.parseTypography)("uppercase")).toEqual({textTransform:"uppercase"});(0,_vitest.expect)((0,_typography.parseTypography)("leading-normal")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-wide")).toEqual({letterSpacing:0.4});});(0,_vitest.it)("should handle arbitrary values for font size and line height",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[19px]")).toEqual({fontSize:19});(0,_vitest.expect)((0,_typography.parseTypography)("text-[19]")).toEqual({fontSize:19});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[26px]")).toEqual({lineHeight:26});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[26]")).toEqual({lineHeight:26});});(0,_vitest.it)("should handle edge case values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-xs")).toEqual({fontSize:12});(0,_vitest.expect)((0,_typography.parseTypography)("text-9xl")).toEqual({fontSize:128});(0,_vitest.expect)((0,_typography.parseTypography)("leading-none")).toEqual({lineHeight:16});(0,_vitest.expect)((0,_typography.parseTypography)("leading-loose")).toEqual({lineHeight:32});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-tighter")).toEqual({letterSpacing:-0.8});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-widest")).toEqual({letterSpacing:1.6});});});
|
|
1
|
+
var _vitest=require("vitest");var _typography=require("./typography");(0,_vitest.describe)("FONT_SIZES",function(){(0,_vitest.it)("should export complete font size scale",function(){(0,_vitest.expect)(_typography.FONT_SIZES).toMatchSnapshot();});});(0,_vitest.describe)("LETTER_SPACING_SCALE",function(){(0,_vitest.it)("should export complete letter spacing scale",function(){(0,_vitest.expect)(_typography.LETTER_SPACING_SCALE).toMatchSnapshot();});});(0,_vitest.describe)("parseTypography - font size",function(){(0,_vitest.it)("should parse font size with preset values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-xs")).toEqual({fontSize:12});(0,_vitest.expect)((0,_typography.parseTypography)("text-sm")).toEqual({fontSize:14});(0,_vitest.expect)((0,_typography.parseTypography)("text-base")).toEqual({fontSize:16});(0,_vitest.expect)((0,_typography.parseTypography)("text-lg")).toEqual({fontSize:18});(0,_vitest.expect)((0,_typography.parseTypography)("text-xl")).toEqual({fontSize:20});(0,_vitest.expect)((0,_typography.parseTypography)("text-2xl")).toEqual({fontSize:24});(0,_vitest.expect)((0,_typography.parseTypography)("text-3xl")).toEqual({fontSize:30});(0,_vitest.expect)((0,_typography.parseTypography)("text-4xl")).toEqual({fontSize:36});(0,_vitest.expect)((0,_typography.parseTypography)("text-5xl")).toEqual({fontSize:48});(0,_vitest.expect)((0,_typography.parseTypography)("text-6xl")).toEqual({fontSize:60});(0,_vitest.expect)((0,_typography.parseTypography)("text-7xl")).toEqual({fontSize:72});(0,_vitest.expect)((0,_typography.parseTypography)("text-8xl")).toEqual({fontSize:96});(0,_vitest.expect)((0,_typography.parseTypography)("text-9xl")).toEqual({fontSize:128});});(0,_vitest.it)("should parse font size with arbitrary pixel values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[13px]")).toEqual({fontSize:13});(0,_vitest.expect)((0,_typography.parseTypography)("text-[13]")).toEqual({fontSize:13});(0,_vitest.expect)((0,_typography.parseTypography)("text-[18px]")).toEqual({fontSize:18});(0,_vitest.expect)((0,_typography.parseTypography)("text-[18]")).toEqual({fontSize:18});(0,_vitest.expect)((0,_typography.parseTypography)("text-[22px]")).toEqual({fontSize:22});(0,_vitest.expect)((0,_typography.parseTypography)("text-[22]")).toEqual({fontSize:22});(0,_vitest.expect)((0,_typography.parseTypography)("text-[100px]")).toEqual({fontSize:100});});});(0,_vitest.describe)("parseTypography - font weight",function(){(0,_vitest.it)("should parse font weight values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("font-thin")).toEqual({fontWeight:"100"});(0,_vitest.expect)((0,_typography.parseTypography)("font-extralight")).toEqual({fontWeight:"200"});(0,_vitest.expect)((0,_typography.parseTypography)("font-light")).toEqual({fontWeight:"300"});(0,_vitest.expect)((0,_typography.parseTypography)("font-normal")).toEqual({fontWeight:"400"});(0,_vitest.expect)((0,_typography.parseTypography)("font-medium")).toEqual({fontWeight:"500"});(0,_vitest.expect)((0,_typography.parseTypography)("font-semibold")).toEqual({fontWeight:"600"});(0,_vitest.expect)((0,_typography.parseTypography)("font-bold")).toEqual({fontWeight:"700"});(0,_vitest.expect)((0,_typography.parseTypography)("font-extrabold")).toEqual({fontWeight:"800"});(0,_vitest.expect)((0,_typography.parseTypography)("font-black")).toEqual({fontWeight:"900"});});});(0,_vitest.describe)("parseTypography - font style",function(){(0,_vitest.it)("should parse font style values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("italic")).toEqual({fontStyle:"italic"});(0,_vitest.expect)((0,_typography.parseTypography)("not-italic")).toEqual({fontStyle:"normal"});});});(0,_vitest.describe)("parseTypography - text alignment",function(){(0,_vitest.it)("should parse text alignment values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-left")).toEqual({textAlign:"left"});(0,_vitest.expect)((0,_typography.parseTypography)("text-center")).toEqual({textAlign:"center"});(0,_vitest.expect)((0,_typography.parseTypography)("text-right")).toEqual({textAlign:"right"});(0,_vitest.expect)((0,_typography.parseTypography)("text-justify")).toEqual({textAlign:"justify"});});});(0,_vitest.describe)("parseTypography - text decoration",function(){(0,_vitest.it)("should parse text decoration values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("underline")).toEqual({textDecorationLine:"underline"});(0,_vitest.expect)((0,_typography.parseTypography)("line-through")).toEqual({textDecorationLine:"line-through"});(0,_vitest.expect)((0,_typography.parseTypography)("no-underline")).toEqual({textDecorationLine:"none"});});});(0,_vitest.describe)("parseTypography - text transform",function(){(0,_vitest.it)("should parse text transform values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("uppercase")).toEqual({textTransform:"uppercase"});(0,_vitest.expect)((0,_typography.parseTypography)("lowercase")).toEqual({textTransform:"lowercase"});(0,_vitest.expect)((0,_typography.parseTypography)("capitalize")).toEqual({textTransform:"capitalize"});(0,_vitest.expect)((0,_typography.parseTypography)("normal-case")).toEqual({textTransform:"none"});});});(0,_vitest.describe)("parseTypography - line height",function(){(0,_vitest.it)("should parse line height with preset values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("leading-none")).toEqual({lineHeight:16});(0,_vitest.expect)((0,_typography.parseTypography)("leading-tight")).toEqual({lineHeight:20});(0,_vitest.expect)((0,_typography.parseTypography)("leading-snug")).toEqual({lineHeight:22});(0,_vitest.expect)((0,_typography.parseTypography)("leading-normal")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("leading-relaxed")).toEqual({lineHeight:28});(0,_vitest.expect)((0,_typography.parseTypography)("leading-loose")).toEqual({lineHeight:32});});(0,_vitest.it)("should parse line height with arbitrary pixel values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("leading-[24px]")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[24]")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[30px]")).toEqual({lineHeight:30});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[30]")).toEqual({lineHeight:30});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[50px]")).toEqual({lineHeight:50});});});(0,_vitest.describe)("parseTypography - letter spacing",function(){(0,_vitest.it)("should parse letter spacing with preset values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("tracking-tighter")).toEqual({letterSpacing:-0.8});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-tight")).toEqual({letterSpacing:-0.4});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-normal")).toEqual({letterSpacing:0});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-wide")).toEqual({letterSpacing:0.4});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-wider")).toEqual({letterSpacing:0.8});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-widest")).toEqual({letterSpacing:1.6});});});(0,_vitest.describe)("parseTypography - edge cases",function(){(0,_vitest.it)("should return null for invalid classes",function(){(0,_vitest.expect)((0,_typography.parseTypography)("invalid")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("font")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("tracking")).toBeNull();});(0,_vitest.it)("should return null for invalid font size values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-invalid")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-10xl")).toBeNull();});(0,_vitest.it)("should return null for invalid font weight values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("font-invalid")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("font-100")).toBeNull();});(0,_vitest.it)("should return null for arbitrary values with unsupported units",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[16rem]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-[2em]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-[2rem]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-[1.5em]")).toBeNull();});(0,_vitest.it)("should return null for malformed arbitrary values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[16")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-16]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("text-[]")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-[24")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("leading-24]")).toBeNull();});(0,_vitest.it)("should not match partial class names",function(){(0,_vitest.expect)((0,_typography.parseTypography)("mytext-lg")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("font-bold-extra")).toBeNull();(0,_vitest.expect)((0,_typography.parseTypography)("italic-text")).toBeNull();});});(0,_vitest.describe)("parseTypography - comprehensive coverage",function(){(0,_vitest.it)("should handle all typography categories independently",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-base")).toEqual({fontSize:16});(0,_vitest.expect)((0,_typography.parseTypography)("font-bold")).toEqual({fontWeight:"700"});(0,_vitest.expect)((0,_typography.parseTypography)("italic")).toEqual({fontStyle:"italic"});(0,_vitest.expect)((0,_typography.parseTypography)("text-center")).toEqual({textAlign:"center"});(0,_vitest.expect)((0,_typography.parseTypography)("underline")).toEqual({textDecorationLine:"underline"});(0,_vitest.expect)((0,_typography.parseTypography)("uppercase")).toEqual({textTransform:"uppercase"});(0,_vitest.expect)((0,_typography.parseTypography)("leading-normal")).toEqual({lineHeight:24});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-wide")).toEqual({letterSpacing:0.4});});(0,_vitest.it)("should handle arbitrary values for font size and line height",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-[19px]")).toEqual({fontSize:19});(0,_vitest.expect)((0,_typography.parseTypography)("text-[19]")).toEqual({fontSize:19});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[26px]")).toEqual({lineHeight:26});(0,_vitest.expect)((0,_typography.parseTypography)("leading-[26]")).toEqual({lineHeight:26});});(0,_vitest.it)("should handle edge case values",function(){(0,_vitest.expect)((0,_typography.parseTypography)("text-xs")).toEqual({fontSize:12});(0,_vitest.expect)((0,_typography.parseTypography)("text-9xl")).toEqual({fontSize:128});(0,_vitest.expect)((0,_typography.parseTypography)("leading-none")).toEqual({lineHeight:16});(0,_vitest.expect)((0,_typography.parseTypography)("leading-loose")).toEqual({lineHeight:32});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-tighter")).toEqual({letterSpacing:-0.8});(0,_vitest.expect)((0,_typography.parseTypography)("tracking-widest")).toEqual({letterSpacing:1.6});});});
|
package/dist/react-native.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -3,10 +3,40 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { ImageStyle, TextStyle, ViewStyle } from "react-native";
|
|
5
5
|
export type RNStyle = ViewStyle | TextStyle | ImageStyle;
|
|
6
|
-
export type
|
|
6
|
+
export type TransformStyle = {
|
|
7
|
+
scale?: number;
|
|
8
|
+
} | {
|
|
9
|
+
scaleX?: number;
|
|
10
|
+
} | {
|
|
11
|
+
scaleY?: number;
|
|
12
|
+
} | {
|
|
13
|
+
rotate?: string;
|
|
14
|
+
} | {
|
|
15
|
+
rotateX?: string;
|
|
16
|
+
} | {
|
|
17
|
+
rotateY?: string;
|
|
18
|
+
} | {
|
|
19
|
+
rotateZ?: string;
|
|
20
|
+
} | {
|
|
21
|
+
translateX?: number | string;
|
|
22
|
+
} | {
|
|
23
|
+
translateY?: number | string;
|
|
24
|
+
} | {
|
|
25
|
+
skewX?: string;
|
|
26
|
+
} | {
|
|
27
|
+
skewY?: string;
|
|
28
|
+
} | {
|
|
29
|
+
perspective?: number;
|
|
30
|
+
};
|
|
31
|
+
export type ShadowOffsetStyle = {
|
|
7
32
|
width: number;
|
|
8
33
|
height: number;
|
|
9
|
-
}
|
|
34
|
+
};
|
|
35
|
+
export type StyleObject = {
|
|
36
|
+
[key: string]: string | number | ShadowOffsetStyle | TransformStyle[] | undefined;
|
|
37
|
+
shadowOffset?: ShadowOffsetStyle;
|
|
38
|
+
transform?: TransformStyle[];
|
|
39
|
+
};
|
|
10
40
|
export type SpacingValue = number;
|
|
11
41
|
export type ColorValue = string;
|
|
12
42
|
export type Parser = (className: string) => StyleObject | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mgcrea/react-native-tailwind",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Compile-time Tailwind CSS for React Native with zero runtime overhead",
|
|
5
5
|
"author": "Olivier Louvignes <olivier@mgcrea.io> (https://github.com/mgcrea)",
|
|
6
6
|
"homepage": "https://github.com/mgcrea/react-native-tailwind#readme",
|
|
@@ -192,6 +192,16 @@ describe("parseColor - edge cases", () => {
|
|
|
192
192
|
expect(parseColor("bg-[rgb(255,0,0)]")).toBeNull(); // RGB format not supported
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
+
it("should return null for non-color arbitrary values (to let other parsers handle them)", () => {
|
|
196
|
+
// These should be handled by typography parser
|
|
197
|
+
expect(parseColor("text-[13px]")).toBeNull();
|
|
198
|
+
expect(parseColor("text-[18px]")).toBeNull();
|
|
199
|
+
expect(parseColor("text-[24]")).toBeNull();
|
|
200
|
+
// These should be handled by sizing parser
|
|
201
|
+
expect(parseColor("bg-[100%]")).toBeNull();
|
|
202
|
+
expect(parseColor("bg-[50px]")).toBeNull();
|
|
203
|
+
});
|
|
204
|
+
|
|
195
205
|
it("should not match partial class names", () => {
|
|
196
206
|
expect(parseColor("background-blue-500")).toBeNull();
|
|
197
207
|
expect(parseColor("textcolor-red-500")).toBeNull();
|
package/src/parser/colors.ts
CHANGED
|
@@ -241,8 +241,13 @@ export function parseColor(cls: string, customColors?: Record<string, string>):
|
|
|
241
241
|
};
|
|
242
242
|
|
|
243
243
|
// Background color: bg-blue-500, bg-blue-500/50, bg-[#ff0000]/80
|
|
244
|
+
// Only parse arbitrary values that look like colors (start with #)
|
|
244
245
|
if (cls.startsWith("bg-")) {
|
|
245
246
|
const colorKey = cls.substring(3);
|
|
247
|
+
// Skip arbitrary values that don't look like colors (e.g., bg-[100%] is sizing)
|
|
248
|
+
if (colorKey.startsWith("[") && !colorKey.startsWith("[#")) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
246
251
|
const color = parseColorWithOpacity(colorKey);
|
|
247
252
|
if (color) {
|
|
248
253
|
return { backgroundColor: color };
|
|
@@ -250,8 +255,13 @@ export function parseColor(cls: string, customColors?: Record<string, string>):
|
|
|
250
255
|
}
|
|
251
256
|
|
|
252
257
|
// Text color: text-blue-500, text-blue-500/50, text-[#ff0000]/80
|
|
258
|
+
// Only parse arbitrary values that look like colors (start with #)
|
|
253
259
|
if (cls.startsWith("text-")) {
|
|
254
260
|
const colorKey = cls.substring(5);
|
|
261
|
+
// Skip arbitrary values that don't look like colors (e.g., text-[13px] is font size)
|
|
262
|
+
if (colorKey.startsWith("[") && !colorKey.startsWith("[#")) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
255
265
|
const color = parseColorWithOpacity(colorKey);
|
|
256
266
|
if (color) {
|
|
257
267
|
return { color: color };
|
|
@@ -261,6 +271,10 @@ export function parseColor(cls: string, customColors?: Record<string, string>):
|
|
|
261
271
|
// Border color: border-blue-500, border-blue-500/50, border-[#ff0000]/80
|
|
262
272
|
if (cls.startsWith("border-") && !cls.match(/^border-[0-9]/)) {
|
|
263
273
|
const colorKey = cls.substring(7);
|
|
274
|
+
// Skip arbitrary values that don't look like colors (e.g., border-[3px] is width)
|
|
275
|
+
if (colorKey.startsWith("[") && !colorKey.startsWith("[#")) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
264
278
|
const color = parseColorWithOpacity(colorKey);
|
|
265
279
|
if (color) {
|
|
266
280
|
return { borderColor: color };
|
package/src/parser/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { parseLayout } from "./layout";
|
|
|
11
11
|
import { parseShadow } from "./shadows";
|
|
12
12
|
import { parseSizing } from "./sizing";
|
|
13
13
|
import { parseSpacing } from "./spacing";
|
|
14
|
+
import { parseTransform } from "./transforms";
|
|
14
15
|
import { parseTypography } from "./typography";
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -50,6 +51,7 @@ export function parseClass(cls: string, customColors?: Record<string, string>):
|
|
|
50
51
|
parseSizing,
|
|
51
52
|
parseShadow,
|
|
52
53
|
parseAspectRatio,
|
|
54
|
+
parseTransform,
|
|
53
55
|
];
|
|
54
56
|
|
|
55
57
|
for (const parser of parsers) {
|
|
@@ -75,6 +77,7 @@ export { parseLayout } from "./layout";
|
|
|
75
77
|
export { parseShadow } from "./shadows";
|
|
76
78
|
export { parseSizing } from "./sizing";
|
|
77
79
|
export { parseSpacing } from "./spacing";
|
|
80
|
+
export { parseTransform } from "./transforms";
|
|
78
81
|
export { parseTypography } from "./typography";
|
|
79
82
|
|
|
80
83
|
// Re-export modifier utilities
|
|
@@ -319,6 +319,18 @@ describe("parseLayout - z-index utilities", () => {
|
|
|
319
319
|
expect(parseLayout("z-auto")).toEqual({ zIndex: 0 });
|
|
320
320
|
});
|
|
321
321
|
|
|
322
|
+
it("should parse arbitrary z-index values", () => {
|
|
323
|
+
expect(parseLayout("z-[999]")).toEqual({ zIndex: 999 });
|
|
324
|
+
expect(parseLayout("z-[100]")).toEqual({ zIndex: 100 });
|
|
325
|
+
expect(parseLayout("z-[1]")).toEqual({ zIndex: 1 });
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("should parse negative arbitrary z-index values", () => {
|
|
329
|
+
expect(parseLayout("z-[-1]")).toEqual({ zIndex: -1 });
|
|
330
|
+
expect(parseLayout("z-[-10]")).toEqual({ zIndex: -10 });
|
|
331
|
+
expect(parseLayout("z-[-999]")).toEqual({ zIndex: -999 });
|
|
332
|
+
});
|
|
333
|
+
|
|
322
334
|
it("should return null for invalid z-index values", () => {
|
|
323
335
|
expect(parseLayout("z-100")).toBeNull();
|
|
324
336
|
expect(parseLayout("z-5")).toBeNull();
|
|
@@ -369,6 +381,50 @@ describe("parseLayout - positioning utilities", () => {
|
|
|
369
381
|
expect(parseLayout("bottom-auto")).toEqual({});
|
|
370
382
|
expect(parseLayout("left-auto")).toEqual({});
|
|
371
383
|
});
|
|
384
|
+
|
|
385
|
+
it("should parse arbitrary top values with pixels", () => {
|
|
386
|
+
expect(parseLayout("top-[50px]")).toEqual({ top: 50 });
|
|
387
|
+
expect(parseLayout("top-[100px]")).toEqual({ top: 100 });
|
|
388
|
+
expect(parseLayout("top-[0px]")).toEqual({ top: 0 });
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("should parse arbitrary top values without unit (defaults to px)", () => {
|
|
392
|
+
expect(parseLayout("top-[50]")).toEqual({ top: 50 });
|
|
393
|
+
expect(parseLayout("top-[100]")).toEqual({ top: 100 });
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("should parse arbitrary top values with percentages", () => {
|
|
397
|
+
expect(parseLayout("top-[25%]")).toEqual({ top: "25%" });
|
|
398
|
+
expect(parseLayout("top-[50%]")).toEqual({ top: "50%" });
|
|
399
|
+
expect(parseLayout("top-[10.5%]")).toEqual({ top: "10.5%" });
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it("should parse negative arbitrary top values", () => {
|
|
403
|
+
expect(parseLayout("top-[-10px]")).toEqual({ top: -10 });
|
|
404
|
+
expect(parseLayout("top-[-50]")).toEqual({ top: -50 });
|
|
405
|
+
expect(parseLayout("top-[-25%]")).toEqual({ top: "-25%" });
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
it("should parse arbitrary right values", () => {
|
|
409
|
+
expect(parseLayout("right-[30px]")).toEqual({ right: 30 });
|
|
410
|
+
expect(parseLayout("right-[20]")).toEqual({ right: 20 });
|
|
411
|
+
expect(parseLayout("right-[15%]")).toEqual({ right: "15%" });
|
|
412
|
+
expect(parseLayout("right-[-10px]")).toEqual({ right: -10 });
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it("should parse arbitrary bottom values", () => {
|
|
416
|
+
expect(parseLayout("bottom-[40px]")).toEqual({ bottom: 40 });
|
|
417
|
+
expect(parseLayout("bottom-[25]")).toEqual({ bottom: 25 });
|
|
418
|
+
expect(parseLayout("bottom-[33.333%]")).toEqual({ bottom: "33.333%" });
|
|
419
|
+
expect(parseLayout("bottom-[-15px]")).toEqual({ bottom: -15 });
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it("should parse arbitrary left values", () => {
|
|
423
|
+
expect(parseLayout("left-[60px]")).toEqual({ left: 60 });
|
|
424
|
+
expect(parseLayout("left-[45]")).toEqual({ left: 45 });
|
|
425
|
+
expect(parseLayout("left-[12.5%]")).toEqual({ left: "12.5%" });
|
|
426
|
+
expect(parseLayout("left-[-20px]")).toEqual({ left: -20 });
|
|
427
|
+
});
|
|
372
428
|
});
|
|
373
429
|
|
|
374
430
|
describe("parseLayout - inset utilities", () => {
|
|
@@ -401,6 +457,42 @@ describe("parseLayout - inset utilities", () => {
|
|
|
401
457
|
expect(parseLayout("inset-x-100")).toBeNull();
|
|
402
458
|
expect(parseLayout("inset-y-100")).toBeNull();
|
|
403
459
|
});
|
|
460
|
+
|
|
461
|
+
it("should parse arbitrary inset (all sides) values with pixels", () => {
|
|
462
|
+
expect(parseLayout("inset-[10px]")).toEqual({ top: 10, right: 10, bottom: 10, left: 10 });
|
|
463
|
+
expect(parseLayout("inset-[25px]")).toEqual({ top: 25, right: 25, bottom: 25, left: 25 });
|
|
464
|
+
expect(parseLayout("inset-[0px]")).toEqual({ top: 0, right: 0, bottom: 0, left: 0 });
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("should parse arbitrary inset values without unit (defaults to px)", () => {
|
|
468
|
+
expect(parseLayout("inset-[15]")).toEqual({ top: 15, right: 15, bottom: 15, left: 15 });
|
|
469
|
+
expect(parseLayout("inset-[30]")).toEqual({ top: 30, right: 30, bottom: 30, left: 30 });
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("should parse arbitrary inset values with percentages", () => {
|
|
473
|
+
expect(parseLayout("inset-[10%]")).toEqual({ top: "10%", right: "10%", bottom: "10%", left: "10%" });
|
|
474
|
+
expect(parseLayout("inset-[25%]")).toEqual({ top: "25%", right: "25%", bottom: "25%", left: "25%" });
|
|
475
|
+
expect(parseLayout("inset-[5.5%]")).toEqual({ top: "5.5%", right: "5.5%", bottom: "5.5%", left: "5.5%" });
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("should parse arbitrary inset-x (horizontal) values", () => {
|
|
479
|
+
expect(parseLayout("inset-x-[20px]")).toEqual({ left: 20, right: 20 });
|
|
480
|
+
expect(parseLayout("inset-x-[15]")).toEqual({ left: 15, right: 15 });
|
|
481
|
+
expect(parseLayout("inset-x-[10%]")).toEqual({ left: "10%", right: "10%" });
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it("should parse arbitrary inset-y (vertical) values", () => {
|
|
485
|
+
expect(parseLayout("inset-y-[30px]")).toEqual({ top: 30, bottom: 30 });
|
|
486
|
+
expect(parseLayout("inset-y-[25]")).toEqual({ top: 25, bottom: 25 });
|
|
487
|
+
expect(parseLayout("inset-y-[15%]")).toEqual({ top: "15%", bottom: "15%" });
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it("should parse negative arbitrary inset values", () => {
|
|
491
|
+
expect(parseLayout("inset-[-5px]")).toEqual({ top: -5, right: -5, bottom: -5, left: -5 });
|
|
492
|
+
expect(parseLayout("inset-x-[-10px]")).toEqual({ left: -10, right: -10 });
|
|
493
|
+
expect(parseLayout("inset-y-[-15px]")).toEqual({ top: -15, bottom: -15 });
|
|
494
|
+
expect(parseLayout("inset-[-20%]")).toEqual({ top: "-20%", right: "-20%", bottom: "-20%", left: "-20%" });
|
|
495
|
+
});
|
|
404
496
|
});
|
|
405
497
|
|
|
406
498
|
describe("parseLayout - specific property coverage", () => {
|
package/src/parser/layout.ts
CHANGED
|
@@ -4,6 +4,60 @@
|
|
|
4
4
|
|
|
5
5
|
import type { StyleObject } from "../types";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Parse arbitrary inset value: [123px], [123], [50%], [-10px]
|
|
9
|
+
* Returns number for px values, string for % values, null for unsupported units
|
|
10
|
+
*/
|
|
11
|
+
function parseArbitraryInset(value: string): number | string | null {
|
|
12
|
+
// Match: [123px], [123], [-123px], [-123] (pixels)
|
|
13
|
+
const pxMatch = value.match(/^\[(-?\d+)(?:px)?\]$/);
|
|
14
|
+
if (pxMatch) {
|
|
15
|
+
return parseInt(pxMatch[1], 10);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Match: [50%], [-50%] (percentage)
|
|
19
|
+
const percentMatch = value.match(/^\[(-?\d+(?:\.\d+)?)%\]$/);
|
|
20
|
+
if (percentMatch) {
|
|
21
|
+
return `${percentMatch[1]}%`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Unsupported units (rem, em, vh, vw, etc.) - warn and reject
|
|
25
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
26
|
+
if (process.env.NODE_ENV !== "production") {
|
|
27
|
+
console.warn(
|
|
28
|
+
`[react-native-tailwind] Unsupported arbitrary inset unit: ${value}. Only px and % are supported.`,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Parse arbitrary z-index value: [123], [-10]
|
|
39
|
+
* Returns number for valid z-index, null otherwise
|
|
40
|
+
*/
|
|
41
|
+
function parseArbitraryZIndex(value: string): number | null {
|
|
42
|
+
// Match: [123], [-123] (integers only)
|
|
43
|
+
const zMatch = value.match(/^\[(-?\d+)\]$/);
|
|
44
|
+
if (zMatch) {
|
|
45
|
+
return parseInt(zMatch[1], 10);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Unsupported format - warn and reject
|
|
49
|
+
if (value.startsWith("[") && value.endsWith("]")) {
|
|
50
|
+
if (process.env.NODE_ENV !== "production") {
|
|
51
|
+
console.warn(
|
|
52
|
+
`[react-native-tailwind] Invalid arbitrary z-index: ${value}. Only integers are supported.`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
7
61
|
// Display utilities
|
|
8
62
|
const DISPLAY_MAP: Record<string, StyleObject> = {
|
|
9
63
|
flex: { display: "flex" },
|
|
@@ -128,16 +182,23 @@ export const INSET_SCALE: Record<string, number> = {
|
|
|
128
182
|
* Parse layout classes
|
|
129
183
|
*/
|
|
130
184
|
export function parseLayout(cls: string): StyleObject | null {
|
|
131
|
-
// Z-index: z-0, z-10, z-20, etc.
|
|
185
|
+
// Z-index: z-0, z-10, z-20, z-[999], etc.
|
|
132
186
|
if (cls.startsWith("z-")) {
|
|
133
187
|
const zKey = cls.substring(2);
|
|
188
|
+
|
|
189
|
+
// Arbitrary values: z-[123], z-[-10]
|
|
190
|
+
const arbitraryZ = parseArbitraryZIndex(zKey);
|
|
191
|
+
if (arbitraryZ !== null) {
|
|
192
|
+
return { zIndex: arbitraryZ };
|
|
193
|
+
}
|
|
194
|
+
|
|
134
195
|
const zValue = Z_INDEX_SCALE[zKey];
|
|
135
196
|
if (zValue !== undefined) {
|
|
136
197
|
return { zIndex: zValue };
|
|
137
198
|
}
|
|
138
199
|
}
|
|
139
200
|
|
|
140
|
-
// Top positioning: top-0, top-4, etc.
|
|
201
|
+
// Top positioning: top-0, top-4, top-[10px], top-[50%], etc.
|
|
141
202
|
if (cls.startsWith("top-")) {
|
|
142
203
|
const topKey = cls.substring(4);
|
|
143
204
|
|
|
@@ -146,13 +207,19 @@ export function parseLayout(cls: string): StyleObject | null {
|
|
|
146
207
|
return {};
|
|
147
208
|
}
|
|
148
209
|
|
|
210
|
+
// Arbitrary values: top-[123px], top-[50%], top-[-10px]
|
|
211
|
+
const arbitraryTop = parseArbitraryInset(topKey);
|
|
212
|
+
if (arbitraryTop !== null) {
|
|
213
|
+
return { top: arbitraryTop };
|
|
214
|
+
}
|
|
215
|
+
|
|
149
216
|
const topValue = INSET_SCALE[topKey];
|
|
150
217
|
if (topValue !== undefined) {
|
|
151
218
|
return { top: topValue };
|
|
152
219
|
}
|
|
153
220
|
}
|
|
154
221
|
|
|
155
|
-
// Right positioning: right-0, right-4, etc.
|
|
222
|
+
// Right positioning: right-0, right-4, right-[10px], right-[50%], etc.
|
|
156
223
|
if (cls.startsWith("right-")) {
|
|
157
224
|
const rightKey = cls.substring(6);
|
|
158
225
|
|
|
@@ -161,13 +228,19 @@ export function parseLayout(cls: string): StyleObject | null {
|
|
|
161
228
|
return {};
|
|
162
229
|
}
|
|
163
230
|
|
|
231
|
+
// Arbitrary values: right-[123px], right-[50%], right-[-10px]
|
|
232
|
+
const arbitraryRight = parseArbitraryInset(rightKey);
|
|
233
|
+
if (arbitraryRight !== null) {
|
|
234
|
+
return { right: arbitraryRight };
|
|
235
|
+
}
|
|
236
|
+
|
|
164
237
|
const rightValue = INSET_SCALE[rightKey];
|
|
165
238
|
if (rightValue !== undefined) {
|
|
166
239
|
return { right: rightValue };
|
|
167
240
|
}
|
|
168
241
|
}
|
|
169
242
|
|
|
170
|
-
// Bottom positioning: bottom-0, bottom-4, etc.
|
|
243
|
+
// Bottom positioning: bottom-0, bottom-4, bottom-[10px], bottom-[50%], etc.
|
|
171
244
|
if (cls.startsWith("bottom-")) {
|
|
172
245
|
const bottomKey = cls.substring(7);
|
|
173
246
|
|
|
@@ -176,13 +249,19 @@ export function parseLayout(cls: string): StyleObject | null {
|
|
|
176
249
|
return {};
|
|
177
250
|
}
|
|
178
251
|
|
|
252
|
+
// Arbitrary values: bottom-[123px], bottom-[50%], bottom-[-10px]
|
|
253
|
+
const arbitraryBottom = parseArbitraryInset(bottomKey);
|
|
254
|
+
if (arbitraryBottom !== null) {
|
|
255
|
+
return { bottom: arbitraryBottom };
|
|
256
|
+
}
|
|
257
|
+
|
|
179
258
|
const bottomValue = INSET_SCALE[bottomKey];
|
|
180
259
|
if (bottomValue !== undefined) {
|
|
181
260
|
return { bottom: bottomValue };
|
|
182
261
|
}
|
|
183
262
|
}
|
|
184
263
|
|
|
185
|
-
// Left positioning: left-0, left-4, etc.
|
|
264
|
+
// Left positioning: left-0, left-4, left-[10px], left-[50%], etc.
|
|
186
265
|
if (cls.startsWith("left-")) {
|
|
187
266
|
const leftKey = cls.substring(5);
|
|
188
267
|
|
|
@@ -191,39 +270,66 @@ export function parseLayout(cls: string): StyleObject | null {
|
|
|
191
270
|
return {};
|
|
192
271
|
}
|
|
193
272
|
|
|
273
|
+
// Arbitrary values: left-[123px], left-[50%], left-[-10px]
|
|
274
|
+
const arbitraryLeft = parseArbitraryInset(leftKey);
|
|
275
|
+
if (arbitraryLeft !== null) {
|
|
276
|
+
return { left: arbitraryLeft };
|
|
277
|
+
}
|
|
278
|
+
|
|
194
279
|
const leftValue = INSET_SCALE[leftKey];
|
|
195
280
|
if (leftValue !== undefined) {
|
|
196
281
|
return { left: leftValue };
|
|
197
282
|
}
|
|
198
283
|
}
|
|
199
284
|
|
|
200
|
-
// Inset (
|
|
201
|
-
if (cls.startsWith("inset-")) {
|
|
202
|
-
const insetKey = cls.substring(6);
|
|
203
|
-
const insetValue = INSET_SCALE[insetKey];
|
|
204
|
-
if (insetValue !== undefined) {
|
|
205
|
-
return { top: insetValue, right: insetValue, bottom: insetValue, left: insetValue };
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Inset X (left and right): inset-x-0, inset-x-4, etc.
|
|
285
|
+
// Inset X (left and right): inset-x-0, inset-x-4, inset-x-[10px], etc.
|
|
210
286
|
if (cls.startsWith("inset-x-")) {
|
|
211
287
|
const insetKey = cls.substring(8);
|
|
288
|
+
|
|
289
|
+
// Arbitrary values: inset-x-[123px], inset-x-[50%]
|
|
290
|
+
const arbitraryInset = parseArbitraryInset(insetKey);
|
|
291
|
+
if (arbitraryInset !== null) {
|
|
292
|
+
return { left: arbitraryInset, right: arbitraryInset };
|
|
293
|
+
}
|
|
294
|
+
|
|
212
295
|
const insetValue = INSET_SCALE[insetKey];
|
|
213
296
|
if (insetValue !== undefined) {
|
|
214
297
|
return { left: insetValue, right: insetValue };
|
|
215
298
|
}
|
|
216
299
|
}
|
|
217
300
|
|
|
218
|
-
// Inset Y (top and bottom): inset-y-0, inset-y-4, etc.
|
|
301
|
+
// Inset Y (top and bottom): inset-y-0, inset-y-4, inset-y-[10px], etc.
|
|
219
302
|
if (cls.startsWith("inset-y-")) {
|
|
220
303
|
const insetKey = cls.substring(8);
|
|
304
|
+
|
|
305
|
+
// Arbitrary values: inset-y-[123px], inset-y-[50%]
|
|
306
|
+
const arbitraryInset = parseArbitraryInset(insetKey);
|
|
307
|
+
if (arbitraryInset !== null) {
|
|
308
|
+
return { top: arbitraryInset, bottom: arbitraryInset };
|
|
309
|
+
}
|
|
310
|
+
|
|
221
311
|
const insetValue = INSET_SCALE[insetKey];
|
|
222
312
|
if (insetValue !== undefined) {
|
|
223
313
|
return { top: insetValue, bottom: insetValue };
|
|
224
314
|
}
|
|
225
315
|
}
|
|
226
316
|
|
|
317
|
+
// Inset (all sides): inset-0, inset-4, inset-[10px], etc.
|
|
318
|
+
if (cls.startsWith("inset-")) {
|
|
319
|
+
const insetKey = cls.substring(6);
|
|
320
|
+
|
|
321
|
+
// Arbitrary values: inset-[123px], inset-[50%]
|
|
322
|
+
const arbitraryInset = parseArbitraryInset(insetKey);
|
|
323
|
+
if (arbitraryInset !== null) {
|
|
324
|
+
return { top: arbitraryInset, right: arbitraryInset, bottom: arbitraryInset, left: arbitraryInset };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const insetValue = INSET_SCALE[insetKey];
|
|
328
|
+
if (insetValue !== undefined) {
|
|
329
|
+
return { top: insetValue, right: insetValue, bottom: insetValue, left: insetValue };
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
227
333
|
// Try each lookup table in order
|
|
228
334
|
return (
|
|
229
335
|
DISPLAY_MAP[cls] ??
|