|
@@ -10,15 +10,28 @@ import { CustomStyleProps, withClampedStyles } from './style-props'
|
|
|
import { getTextLabelSize } from '@tldraw/core'
|
|
|
import { LabelMask } from './text/LabelMask'
|
|
|
import { TextLabel } from './text/TextLabel'
|
|
|
+import type { SizeLevel } from '.'
|
|
|
+import { action, computed } from 'mobx'
|
|
|
|
|
|
interface LineShapeProps extends CustomStyleProps, TLLineShapeProps {
|
|
|
type: 'line'
|
|
|
label: string
|
|
|
+ fontSize: number
|
|
|
fontWeight: number
|
|
|
italic: boolean
|
|
|
+ scaleLevel?: SizeLevel
|
|
|
}
|
|
|
|
|
|
-const font = '18px / 1 var(--ls-font-family)'
|
|
|
+const font = '20px / 1 var(--ls-font-family)'
|
|
|
+
|
|
|
+const levelToScale = {
|
|
|
+ xs: 10,
|
|
|
+ sm: 16,
|
|
|
+ md: 20,
|
|
|
+ lg: 32,
|
|
|
+ xl: 48,
|
|
|
+ xxl: 60,
|
|
|
+}
|
|
|
|
|
|
export class LineShape extends TLLineShape<LineShapeProps> {
|
|
|
static id = 'line'
|
|
@@ -36,6 +49,7 @@ export class LineShape extends TLLineShape<LineShapeProps> {
|
|
|
fill: '',
|
|
|
noFill: true,
|
|
|
fontWeight: 400,
|
|
|
+ fontSize: 20,
|
|
|
italic: false,
|
|
|
strokeType: 'line',
|
|
|
strokeWidth: 1,
|
|
@@ -57,9 +71,17 @@ export class LineShape extends TLLineShape<LineShapeProps> {
|
|
|
label,
|
|
|
italic,
|
|
|
fontWeight,
|
|
|
+ fontSize,
|
|
|
id,
|
|
|
} = this.props
|
|
|
- const labelSize = label || isEditing ? getTextLabelSize(label, font, 6) : [0, 0]
|
|
|
+ const labelSize =
|
|
|
+ label || isEditing
|
|
|
+ ? getTextLabelSize(
|
|
|
+ label,
|
|
|
+ { fontFamily: 'var(--ls-font-family)', fontSize, lineHeight: 1, fontWeight },
|
|
|
+ 6
|
|
|
+ )
|
|
|
+ : [0, 0]
|
|
|
const midPoint = Vec.med(start.point, end.point)
|
|
|
const dist = Vec.dist(start.point, end.point)
|
|
|
const scale = Math.max(
|
|
@@ -81,6 +103,7 @@ export class LineShape extends TLLineShape<LineShapeProps> {
|
|
|
<TextLabel
|
|
|
font={font}
|
|
|
text={label}
|
|
|
+ fontSize={fontSize}
|
|
|
color={getComputedColor(stroke, 'text')}
|
|
|
offsetX={offset[0]}
|
|
|
offsetY={offset[1]}
|
|
@@ -102,16 +125,37 @@ export class LineShape extends TLLineShape<LineShapeProps> {
|
|
|
)
|
|
|
})
|
|
|
|
|
|
+ @computed get scaleLevel() {
|
|
|
+ return this.props.scaleLevel ?? 'md'
|
|
|
+ }
|
|
|
+
|
|
|
+ @action setScaleLevel = async (v?: SizeLevel) => {
|
|
|
+ this.update({
|
|
|
+ scaleLevel: v,
|
|
|
+ fontSize: levelToScale[v ?? 'md'],
|
|
|
+ })
|
|
|
+ this.onResetBounds()
|
|
|
+ }
|
|
|
+
|
|
|
ReactIndicator = observer(({ isEditing }: TLComponentProps) => {
|
|
|
const {
|
|
|
id,
|
|
|
decorations,
|
|
|
label,
|
|
|
strokeWidth,
|
|
|
+ fontSize,
|
|
|
+ fontWeight,
|
|
|
handles: { start, end },
|
|
|
} = this.props
|
|
|
const bounds = this.getBounds()
|
|
|
- const labelSize = label ? getTextLabelSize(label, font, 6) : [0, 0]
|
|
|
+ const labelSize =
|
|
|
+ label || isEditing
|
|
|
+ ? getTextLabelSize(
|
|
|
+ label,
|
|
|
+ { fontFamily: 'var(--ls-font-family)', fontSize, lineHeight: 1, fontWeight },
|
|
|
+ 6
|
|
|
+ )
|
|
|
+ : [0, 0]
|
|
|
const midPoint = Vec.med(start.point, end.point)
|
|
|
const dist = Vec.dist(start.point, end.point)
|
|
|
const scale = Math.max(
|
|
@@ -160,6 +204,7 @@ export class LineShape extends TLLineShape<LineShapeProps> {
|
|
|
strokeType,
|
|
|
decorations,
|
|
|
label,
|
|
|
+ scaleLevel,
|
|
|
handles: { start, end },
|
|
|
} = this.props
|
|
|
const midPoint = Vec.med(start.point, end.point)
|
|
@@ -172,6 +217,7 @@ export class LineShape extends TLLineShape<LineShapeProps> {
|
|
|
strokeWidth,
|
|
|
strokeType,
|
|
|
}}
|
|
|
+ scaleLevel={scaleLevel}
|
|
|
start={start.point}
|
|
|
end={end.point}
|
|
|
decorationStart={decorations?.start}
|