11import { getCommonRadius } from "../../common/commonRadius" ;
22import { commonStroke } from "../../common/commonStroke" ;
33import {
4- nearestValue ,
54 pxToBorderRadius ,
65 pxToBorderWidth ,
7- pxToRing ,
6+ pxToOutline ,
87} from "../conversionTables" ;
98import { numberToFixedString } from "../../common/numToAutoFixed" ;
109import { addWarning } from "../../common/commonConversionWarnings" ;
1110
12- const getBorder = ( weight : number , kind : string , isRing : boolean = false ) => {
13- // Use ring utilities for outside strokes
14- if ( isRing ) {
15- // Special case: ring (without width) is 3px in Tailwind
16- if ( weight === 3 ) {
17- return "ring" ;
18- }
11+ const getBorder = (
12+ weight : number ,
13+ kind : string ,
14+ useOutline : boolean = false ,
15+ isBoxShadow : boolean = false ,
16+ ) : string => {
17+ // For box-shadow (inside stroke on non-autolayout), return empty string as we'll handle separately
18+ if ( isBoxShadow ) {
19+ return "" ;
20+ }
1921
20- const ringWidth = pxToRing ( weight ) ;
21- if ( ringWidth === null ) {
22- return `ring-[${ numberToFixedString ( weight ) } px]` ;
23- } else if ( ringWidth === "3" ) {
24- // Ring is 3px
25- return `ring` ;
22+ // Use outline utilities for outside/center strokes
23+ if ( useOutline ) {
24+ const outlineWidth = pxToOutline ( weight ) ;
25+ if ( outlineWidth === null ) {
26+ return `outline-[${ numberToFixedString ( weight ) } px]` ;
2627 } else {
27- return `ring -${ ringWidth } ` ;
28+ return `outline -${ outlineWidth } ` ;
2829 }
2930 }
3031
@@ -52,41 +53,66 @@ const getBorder = (weight: number, kind: string, isRing: boolean = false) => {
5253export const tailwindBorderWidth = (
5354 node : SceneNode ,
5455) : {
55- isRing : boolean ;
56+ isOutline : boolean ;
5657 property : string ;
58+ shadowProperty ?: string ; // This can be removed if not used elsewhere
5759} => {
5860 const commonBorder = commonStroke ( node ) ;
5961 if ( ! commonBorder ) {
6062 return {
61- isRing : false ,
63+ isOutline : false ,
6264 property : "" ,
6365 } ;
6466 }
6567
66- // Check if stroke is outside
67- const isRing =
68- "strokeAlign" in node &&
69- ( node . strokeAlign === "OUTSIDE" || node . strokeAlign === "CENTER" ) ;
68+ // Check stroke alignment and layout mode
69+ const strokeAlign = "strokeAlign" in node ? node . strokeAlign : "INSIDE" ;
70+ const layoutMode = "layoutMode" in node ? node . layoutMode : "NONE" ;
7071
7172 if ( "all" in commonBorder ) {
7273 if ( commonBorder . all === 0 ) {
7374 return {
74- isRing : false ,
75+ isOutline : false ,
7576 property : "" ,
7677 } ;
7778 }
78- return {
79- isRing,
80- property : getBorder ( commonBorder . all , "" , isRing ) ,
81- } ;
79+
80+ const weight = commonBorder . all ;
81+
82+ if (
83+ strokeAlign === "CENTER" ||
84+ strokeAlign === "OUTSIDE" ||
85+ ( strokeAlign === "INSIDE" && layoutMode === "NONE" )
86+ ) {
87+ // For CENTER, OUTSIDE, or INSIDE+NONE, use outline
88+ const property = getBorder ( weight , "" , true ) ;
89+ let offsetProperty = "" ;
90+
91+ if ( strokeAlign === "CENTER" ) {
92+ offsetProperty = `outline-offset-[-${ numberToFixedString ( weight / 2 ) } px]` ;
93+ } else if ( strokeAlign === "INSIDE" ) {
94+ offsetProperty = `outline-offset-[-${ numberToFixedString ( weight ) } px]` ;
95+ }
96+
97+ return {
98+ isOutline : true ,
99+ property : offsetProperty ? `${ property } ${ offsetProperty } ` : property ,
100+ } ;
101+ } else {
102+ // Default case: use normal border (for INSIDE + AUTO_LAYOUT)
103+ return {
104+ isOutline : false ,
105+ property : getBorder ( weight , "" , false ) ,
106+ } ;
107+ }
82108 } else {
109+ // For non-uniform borders, we only support border (not outline)
83110 addWarning (
84111 'Non-uniform borders are only supported with strokeAlign set to "inside". Will paint inside.' ,
85112 ) ;
86113 }
87114
88- // If borders are non-uniform, always use border utilities for better control
89- // regardless of whether the stroke is outside or not
115+ // Handle non-uniform borders with individual border properties
90116 const comp = [ ] ;
91117 if ( commonBorder . left !== 0 ) {
92118 comp . push ( getBorder ( commonBorder . left , "-l" ) ) ;
@@ -102,7 +128,7 @@ export const tailwindBorderWidth = (
102128 }
103129
104130 return {
105- isRing ,
131+ isOutline : false ,
106132 property : comp . join ( " " ) ,
107133 } ;
108134} ;
0 commit comments