@ -1,3 +1,4 @@
import { ROUNDNESS } from "../constants" ;
import { AppState } from "../types" ;
import {
ExcalidrawElement ,
@ -10,6 +11,7 @@ import {
ExcalidrawImageElement ,
ExcalidrawTextElementWithContainer ,
ExcalidrawTextContainer ,
RoundnessType ,
} from "./types" ;
export const isGenericElement = (
@ -154,3 +156,51 @@ export const isBoundToContainer = (
} ;
export const isUsingAdaptiveRadius = ( type : string ) = > type === "rectangle" ;
export const isUsingProportionalRadius = ( type : string ) = >
type === "line" || type === "arrow" || type === "diamond" ;
export const canApplyRoundnessTypeToElement = (
roundnessType : RoundnessType ,
element : ExcalidrawElement ,
) = > {
if (
( roundnessType === ROUNDNESS . ADAPTIVE_RADIUS ||
// if legacy roundness, it can be applied to elements that currently
// use adaptive radius
roundnessType === ROUNDNESS . LEGACY ) &&
isUsingAdaptiveRadius ( element . type )
) {
return true ;
}
if (
roundnessType === ROUNDNESS . PROPORTIONAL_RADIUS &&
isUsingProportionalRadius ( element . type )
) {
return true ;
}
return false ;
} ;
export const getDefaultRoundnessTypeForElement = (
element : ExcalidrawElement ,
) = > {
if (
element . type === "arrow" ||
element . type === "line" ||
element . type === "diamond"
) {
return {
type : ROUNDNESS . PROPORTIONAL_RADIUS ,
} ;
}
if ( element . type === "rectangle" ) {
return {
type : ROUNDNESS . ADAPTIVE_RADIUS ,
} ;
}
return null ;
} ;