|
|
@@ -1,6 +1,6 @@
|
|
1
|
1
|
import { uniqueId } from 'utils/utils'
|
|
2
|
2
|
import vec from 'utils/vec'
|
|
3
|
|
-import { TextShape, ShapeType, FontSize } from 'types'
|
|
|
3
|
+import { TextShape, ShapeType, FontSize, SizeStyle } from 'types'
|
|
4
|
4
|
import { registerShapeUtils } from './index'
|
|
5
|
5
|
import { defaultStyle, getFontStyle, getShapeStyle } from 'lib/shape-styles'
|
|
6
|
6
|
import styled from 'styles'
|
|
|
@@ -71,7 +71,7 @@ const text = registerShapeUtils<TextShape>({
|
|
71
|
71
|
render(shape, { isEditing, ref }) {
|
|
72
|
72
|
const { id, text, style } = shape
|
|
73
|
73
|
const styles = getShapeStyle(style)
|
|
74
|
|
- const font = getFontStyle(shape.fontSize, shape.scale, shape.style)
|
|
|
74
|
+ const font = getFontStyle(shape.scale, shape.style)
|
|
75
|
75
|
|
|
76
|
76
|
const bounds = this.getBounds(shape)
|
|
77
|
77
|
|
|
|
@@ -140,7 +140,7 @@ const text = registerShapeUtils<TextShape>({
|
|
140
|
140
|
getBounds(shape) {
|
|
141
|
141
|
if (!this.boundsCache.has(shape)) {
|
|
142
|
142
|
mdiv.innerHTML = shape.text + '‍'
|
|
143
|
|
- mdiv.style.font = getFontStyle(shape.fontSize, shape.scale, shape.style)
|
|
|
143
|
+ mdiv.style.font = getFontStyle(shape.scale, shape.style)
|
|
144
|
144
|
|
|
145
|
145
|
const [minX, minY] = shape.point
|
|
146
|
146
|
const [width, height] = [mdiv.offsetWidth, mdiv.offsetHeight]
|
|
|
@@ -183,11 +183,35 @@ const text = registerShapeUtils<TextShape>({
|
|
183
|
183
|
transformSingle(shape, bounds, { initialShape, scaleX }) {
|
|
184
|
184
|
shape.point = [bounds.minX, bounds.minY]
|
|
185
|
185
|
shape.scale = initialShape.scale * Math.abs(scaleX)
|
|
|
186
|
+
|
|
186
|
187
|
return this
|
|
187
|
188
|
},
|
|
188
|
189
|
|
|
189
|
190
|
onBoundsReset(shape) {
|
|
190
|
|
- shape.size = 'auto'
|
|
|
191
|
+ const center = this.getCenter(shape)
|
|
|
192
|
+
|
|
|
193
|
+ this.boundsCache.delete(shape)
|
|
|
194
|
+
|
|
|
195
|
+ shape.scale = 1
|
|
|
196
|
+
|
|
|
197
|
+ const newCenter = this.getCenter(shape)
|
|
|
198
|
+
|
|
|
199
|
+ shape.point = vec.add(shape.point, vec.sub(center, newCenter))
|
|
|
200
|
+
|
|
|
201
|
+ return this
|
|
|
202
|
+ },
|
|
|
203
|
+
|
|
|
204
|
+ applyStyles(shape, style) {
|
|
|
205
|
+ const center = this.getCenter(shape)
|
|
|
206
|
+
|
|
|
207
|
+ this.boundsCache.delete(shape)
|
|
|
208
|
+
|
|
|
209
|
+ Object.assign(shape.style, style)
|
|
|
210
|
+
|
|
|
211
|
+ const newCenter = this.getCenter(shape)
|
|
|
212
|
+
|
|
|
213
|
+ shape.point = vec.add(shape.point, vec.sub(center, newCenter))
|
|
|
214
|
+
|
|
191
|
215
|
return this
|
|
192
|
216
|
},
|
|
193
|
217
|
|