Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import CodeShape from './index'
  2. import { uniqueId } from 'utils'
  3. import { TextShape, ShapeProps, ShapeType } from 'types'
  4. import { defaultStyle } from 'state/shape-styles'
  5. import { getShapeUtils } from 'state/shape-utils'
  6. /* ----------------- Start Copy Here ---------------- */
  7. export default class Text extends CodeShape<TextShape> {
  8. constructor(props = {} as ShapeProps<TextShape>) {
  9. super({
  10. id: uniqueId(),
  11. parentId: (window as any).currentPageId,
  12. type: ShapeType.Text,
  13. isGenerated: true,
  14. name: 'Text',
  15. childIndex: 0,
  16. point: [0, 0],
  17. rotation: 0,
  18. isAspectRatioLocked: false,
  19. isLocked: false,
  20. isHidden: false,
  21. text: 'Text',
  22. scale: 1,
  23. ...props,
  24. style: {
  25. ...defaultStyle,
  26. ...props.style,
  27. },
  28. })
  29. }
  30. /**
  31. * The text shape's text content.
  32. *
  33. * ```ts
  34. * const shapeText = shape.text
  35. *
  36. * shape.text = "Hello world!"
  37. * ```
  38. */
  39. get text(): string {
  40. return this.shape.text
  41. }
  42. set text(text: string) {
  43. getShapeUtils(this.shape).setProperty(this.shape, 'text', text)
  44. }
  45. /**
  46. * The text's scale.
  47. *
  48. * ```ts
  49. * const shapeScale = shape.scale
  50. *
  51. * shape.scale = 2
  52. * ```
  53. */
  54. get scale(): number {
  55. return this.shape.scale
  56. }
  57. set scale(scale: number) {
  58. getShapeUtils(this.shape).setProperty(this.shape, 'scale', scale)
  59. }
  60. }