@leafer-in/editor 1.0.0-rc.3 → 1.0.0-rc.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/editor.cjs +1937 -0
  2. package/dist/editor.esm.js +1822 -422
  3. package/dist/editor.esm.min.js +1 -1
  4. package/dist/editor.js +1848 -428
  5. package/dist/editor.min.cjs +1 -0
  6. package/dist/editor.min.js +1 -1
  7. package/package.json +12 -9
  8. package/src/Editor.ts +396 -145
  9. package/src/config.ts +38 -0
  10. package/src/decorator/data.ts +16 -0
  11. package/src/display/EditBox.ts +342 -0
  12. package/src/display/EditMask.ts +37 -0
  13. package/src/display/EditPoint.ts +9 -0
  14. package/src/display/EditSelect.ts +255 -0
  15. package/src/display/SelectArea.ts +30 -0
  16. package/src/display/Stroker.ts +92 -0
  17. package/src/editor/cursor.ts +45 -0
  18. package/src/editor/simulate.ts +14 -0
  19. package/src/editor/target.ts +39 -0
  20. package/src/event/EditorEvent.ts +33 -0
  21. package/src/event/EditorGroupEvent.ts +23 -0
  22. package/src/event/EditorMoveEvent.ts +17 -0
  23. package/src/event/EditorRotateEvent.ts +4 -10
  24. package/src/event/EditorScaleEvent.ts +28 -0
  25. package/src/event/EditorSkewEvent.ts +18 -0
  26. package/src/event/InnerEditorEvent.ts +23 -0
  27. package/src/helper/EditDataHelper.ts +183 -0
  28. package/src/helper/EditSelectHelper.ts +34 -0
  29. package/src/helper/EditorHelper.ts +73 -0
  30. package/src/index.ts +50 -3
  31. package/src/svg.ts +54 -0
  32. package/src/tool/EditTool.ts +99 -0
  33. package/src/tool/EditToolCreator.ts +32 -0
  34. package/src/tool/InnerEditor.ts +68 -0
  35. package/src/tool/LineEditTool.ts +135 -0
  36. package/types/index.d.ts +293 -45
  37. package/src/cursor.ts +0 -57
  38. package/src/event/EditorResizeEvent.ts +0 -34
  39. package/src/resize.ts +0 -87
  40. package/src/tool/LineTool.ts +0 -88
  41. package/src/tool/RectTool.ts +0 -139
@@ -1,139 +0,0 @@
1
- import { IUI, IUIInputData, IPointData } from '@leafer-ui/interface'
2
- import { IEditor, IEditorResizeEvent, IEditorRotateEvent, IEditorTool } from '@leafer-in/interface'
3
-
4
- import { Bounds, Matrix } from '@leafer-ui/core'
5
-
6
-
7
- export const RectTool: IEditorTool = {
8
-
9
- name: 'RectTool',
10
-
11
- getMirrorData(editor: IEditor): IPointData {
12
- const { scaleX, scaleY } = editor.target
13
- return {
14
- x: scaleX < 0 ? 1 : 0, // 1 = mirrorX
15
- y: scaleY < 0 ? 1 : 0
16
- }
17
- },
18
-
19
- resize(e: IEditorResizeEvent): void {
20
- const { target, bounds, resizeType, old } = e
21
- const { x, y, width, height } = bounds
22
- const point = { x: x - old.x, y: y - old.y }
23
-
24
- target.innerToWorld(point, null, true, target.parent)
25
- target.x += point.x
26
- target.y += point.y
27
-
28
- if (resizeType === 'scale') {
29
- target.scaleX *= width / old.width
30
- target.scaleY *= height / old.height
31
- } else {
32
- if (width < 0) {
33
- target.width = -width
34
- target.scaleX *= -1
35
- } else {
36
- if (target.width !== width) target.width = width
37
- }
38
-
39
- if (height < 0) {
40
- target.height = -height
41
- target.scaleY *= -1
42
- } else {
43
- if (target.height !== height) target.height = height // Text auto height
44
- }
45
-
46
-
47
- }
48
- },
49
-
50
- rotate(e: IEditorRotateEvent): void {
51
- const { target, rotation, origin } = e
52
- target.rotateOf(origin, rotation)
53
- },
54
-
55
- update(editor: IEditor) {
56
- const { target, config, rotatePoints, targetRect, rect, circle, resizeLines, resizePoints } = editor
57
- const { type, resizeable, rotateable, stroke, pointFill, pointSize, pointRadius } = config
58
-
59
- const defaultStyle = { fill: pointFill, stroke, width: pointSize, height: pointSize, cornerRadius: pointRadius }
60
- const pointStyles = config.point instanceof Array ? config.point : [config.point || defaultStyle]
61
-
62
- const box = new Bounds(target.boxBounds)
63
- const w = target.worldTransform, pw = editor.parent.worldTransform
64
-
65
- const matrix = new Matrix(w)
66
- matrix.divide(pw)
67
- const worldX = matrix.e, worldY = matrix.f
68
-
69
-
70
- let { scaleX, scaleY, rotation, skewX, skewY } = w
71
- scaleX /= pw.scaleX, scaleY /= pw.scaleY, rotation -= pw.rotation, skewX -= pw.skewX, skewY -= pw.skewY
72
-
73
- const { x, y, width, height } = box.scale(scaleX, scaleY) // maybe width / height < 0
74
-
75
- editor.set({ x: worldX, y: worldY, rotation, skewX, skewY })
76
- targetRect.set({ x, y, width: box.width / scaleX, height: box.height / scaleY, scaleX, scaleY, visible: true })
77
-
78
-
79
- const points: IPointData[] = [ // topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left
80
- { x, y },
81
- { x: x + width / 2, y },
82
- { x: x + width, y },
83
- { x: x + width, y: y + height / 2 },
84
- { x: x + width, y: y + height },
85
- { x: x + width / 2, y: y + height },
86
- { x, y: y + height },
87
- { x, y: y + height / 2 }
88
- ]
89
-
90
- const rectPoints: number[] = []
91
- let point: IPointData, style: IUIInputData, rotateP: IUI, resizeP: IUI, resizeL: IUI
92
-
93
- for (let i = 0; i < 8; i++) {
94
- point = points[i]
95
- style = pointStyles[i % pointStyles.length]
96
-
97
- resizeP = resizePoints[i]
98
- resizeL = resizeLines[Math.floor(i / 2)]
99
- rotateP = rotatePoints[i]
100
-
101
- resizeP.set(style)
102
- resizeP.x = rotateP.x = resizeL.x = point.x
103
- resizeP.y = rotateP.y = resizeL.y = point.y
104
-
105
- resizeP.visible = resizeL.visible = resizeable || rotateable
106
- rotateP.visible = rotateable && resizeable
107
-
108
- if (i % 2) { // top, right, bottom, left
109
- if (((i + 1) / 2) % 2) { // top, bottom
110
- resizeL.width = Math.abs(width)
111
- rotateP.width = Math.max(10, Math.abs(width) - 30) // skew
112
- } else {
113
- resizeL.height = Math.abs(height)
114
- rotateP.height = Math.max(10, Math.abs(height) - 30) // skew
115
- }
116
-
117
- resizeP.rotation = 90
118
- resizeP.visible = type === 'mobile'
119
-
120
- } else {
121
- rectPoints.push(point.x, point.y)
122
- }
123
- }
124
-
125
-
126
-
127
- style = config.rotatePoint || style
128
-
129
- circle.set(style)
130
- circle.x = x + width / 2
131
- if (!style.y) circle.y = y - (10 + (resizeP.height + circle.height) / 2) * (this.getMirrorData(editor).y ? -1 : 1)
132
- circle.visible = rotateable && type === 'mobile'
133
-
134
- rect.set(config.rect || { stroke })
135
- rect.points = rectPoints
136
- rect.visible = true
137
- }
138
-
139
- }