2021-06-25 11:24:08 +00:00
|
|
|
import CodeShape from './index'
|
2021-07-01 14:03:02 +00:00
|
|
|
import { uniqueId } from 'utils/utils'
|
2021-06-25 12:21:33 +00:00
|
|
|
import { TextShape, ShapeProps, ShapeType } from 'types'
|
2021-06-25 11:24:08 +00:00
|
|
|
import { defaultStyle } from 'state/shape-styles'
|
2021-06-25 12:21:33 +00:00
|
|
|
import { getShapeUtils } from 'state/shape-utils'
|
2021-06-25 11:24:08 +00:00
|
|
|
|
|
|
|
/* ----------------- Start Copy Here ---------------- */
|
|
|
|
|
|
|
|
export default class Text extends CodeShape<TextShape> {
|
|
|
|
constructor(props = {} as ShapeProps<TextShape>) {
|
|
|
|
super({
|
|
|
|
id: uniqueId(),
|
|
|
|
parentId: (window as any).currentPageId,
|
|
|
|
type: ShapeType.Text,
|
|
|
|
isGenerated: true,
|
|
|
|
name: 'Text',
|
|
|
|
childIndex: 0,
|
|
|
|
point: [0, 0],
|
|
|
|
rotation: 0,
|
|
|
|
text: 'Text',
|
|
|
|
scale: 1,
|
|
|
|
...props,
|
|
|
|
style: {
|
|
|
|
...defaultStyle,
|
|
|
|
...props.style,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2021-06-25 12:21:33 +00:00
|
|
|
|
2021-06-27 11:58:08 +00:00
|
|
|
/**
|
|
|
|
* The text shape's text content.
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const shapeText = shape.text
|
|
|
|
*
|
|
|
|
* shape.text = "Hello world!"
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
get text(): string {
|
|
|
|
return this.shape.text
|
|
|
|
}
|
|
|
|
|
|
|
|
set text(text: string) {
|
|
|
|
getShapeUtils(this.shape).setProperty(this.shape, 'text', text)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The text's scale.
|
|
|
|
*
|
|
|
|
* ```ts
|
|
|
|
* const shapeScale = shape.scale
|
|
|
|
*
|
|
|
|
* shape.scale = 2
|
|
|
|
* ```
|
|
|
|
*/
|
2021-06-25 12:21:33 +00:00
|
|
|
get scale(): number {
|
|
|
|
return this.shape.scale
|
|
|
|
}
|
|
|
|
|
|
|
|
set scale(scale: number) {
|
|
|
|
getShapeUtils(this.shape).setProperty(this.shape, 'scale', scale)
|
|
|
|
}
|
2021-06-25 11:24:08 +00:00
|
|
|
}
|