@leafer-in/editor 1.9.12 → 1.10.1
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.
- package/dist/editor.cjs +59 -17
- package/dist/editor.esm.js +60 -18
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +59 -17
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +6 -6
- package/src/Editor.ts +13 -2
- package/src/display/EditBox.ts +29 -22
- package/src/display/Stroker.ts +2 -2
- package/src/helper/EditDataHelper.ts +3 -0
- package/types/index.d.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-in/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.1",
|
|
4
4
|
"description": "@leafer-in/editor",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"leaferjs"
|
|
35
35
|
],
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@leafer-ui/draw": "^1.
|
|
38
|
-
"@leafer-ui/core": "^1.
|
|
39
|
-
"@leafer-in/resize": "^1.
|
|
40
|
-
"@leafer-ui/interface": "^1.
|
|
41
|
-
"@leafer-in/interface": "^1.
|
|
37
|
+
"@leafer-ui/draw": "^1.10.1",
|
|
38
|
+
"@leafer-ui/core": "^1.10.1",
|
|
39
|
+
"@leafer-in/resize": "^1.10.1",
|
|
40
|
+
"@leafer-ui/interface": "^1.10.1",
|
|
41
|
+
"@leafer-in/interface": "^1.10.1"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/Editor.ts
CHANGED
|
@@ -153,6 +153,13 @@ export class Editor extends Group implements IEditor {
|
|
|
153
153
|
this.update()
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
+
|
|
157
|
+
// editTool
|
|
158
|
+
|
|
159
|
+
public getEditTool(name: string): IEditTool {
|
|
160
|
+
return this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this)
|
|
161
|
+
}
|
|
162
|
+
|
|
156
163
|
public updateEditTool(): void {
|
|
157
164
|
this.unloadEditTool()
|
|
158
165
|
|
|
@@ -168,7 +175,7 @@ export class Editor extends Group implements IEditor {
|
|
|
168
175
|
}
|
|
169
176
|
|
|
170
177
|
if (EditToolCreator.list[name]) {
|
|
171
|
-
const tool = this.editTool = this.
|
|
178
|
+
const tool = this.editTool = this.getEditTool(name)
|
|
172
179
|
this.editBox.load()
|
|
173
180
|
tool.load()
|
|
174
181
|
this.update()
|
|
@@ -293,6 +300,10 @@ export class Editor extends Group implements IEditor {
|
|
|
293
300
|
|
|
294
301
|
// inner
|
|
295
302
|
|
|
303
|
+
public getInnerEditor(name: string): IInnerEditor {
|
|
304
|
+
return this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this)
|
|
305
|
+
}
|
|
306
|
+
|
|
296
307
|
public openInnerEditor(target?: IUI, nameOrSelect?: string | boolean, select?: boolean): void {
|
|
297
308
|
let name: string
|
|
298
309
|
if (isString(nameOrSelect)) name = nameOrSelect
|
|
@@ -314,7 +325,7 @@ export class Editor extends Group implements IEditor {
|
|
|
314
325
|
if (EditToolCreator.list[name]) {
|
|
315
326
|
this.editTool.unload()
|
|
316
327
|
this.innerEditing = true
|
|
317
|
-
this.innerEditor = this.
|
|
328
|
+
this.innerEditor = this.getInnerEditor(name)
|
|
318
329
|
this.innerEditor.editTarget = target
|
|
319
330
|
|
|
320
331
|
this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN)
|
package/src/display/EditBox.ts
CHANGED
|
@@ -111,10 +111,11 @@ export class EditBox extends Group implements IEditBox {
|
|
|
111
111
|
|
|
112
112
|
public load(): void {
|
|
113
113
|
const { target, mergeConfig, single, rect, circle, resizePoints, resizeLines } = this
|
|
114
|
-
const { stroke, strokeWidth,
|
|
114
|
+
const { stroke, strokeWidth, ignorePixelSnap } = mergeConfig
|
|
115
115
|
|
|
116
116
|
const pointsStyle = this.getPointsStyle()
|
|
117
117
|
const middlePointsStyle = this.getMiddlePointsStyle()
|
|
118
|
+
const resizeLinesStyle = this.getResizeLinesStyle()
|
|
118
119
|
|
|
119
120
|
this.visible = !target.locked
|
|
120
121
|
|
|
@@ -124,14 +125,14 @@ export class EditBox extends Group implements IEditBox {
|
|
|
124
125
|
resizeP = resizePoints[i]
|
|
125
126
|
resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]))
|
|
126
127
|
resizeP.rotation = ((i - (i % 2 ? 1 : 0)) / 2) * 90
|
|
127
|
-
if (i % 2) resizeLines[(i - 1) / 2].set({ pointType: 'resize', rotation: (i - 1) / 2 * 90, ...(
|
|
128
|
+
if (i % 2) resizeLines[(i - 1) / 2].set({ pointType: 'resize', rotation: (i - 1) / 2 * 90, ...(resizeLinesStyle[((i - 1) / 2) % resizeLinesStyle.length] || {}) } as IEditPointInputData)
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
// rotate
|
|
131
132
|
circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]))
|
|
132
133
|
|
|
133
134
|
// rect
|
|
134
|
-
rect.set({ stroke, strokeWidth, editConfig, ...(mergeConfig.rect || {}) })
|
|
135
|
+
rect.set({ stroke, strokeWidth, opacity: 1, editConfig, ...(mergeConfig.rect || {}) })
|
|
135
136
|
|
|
136
137
|
// 编辑框作为底部虚拟元素, 在 unload() 中重置
|
|
137
138
|
const rectThrough = isNull(mergeConfig.rectThrough) ? single : mergeConfig.rectThrough
|
|
@@ -271,7 +272,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
271
272
|
|
|
272
273
|
public getPointStyle(userStyle?: IBoxInputData): IBoxInputData {
|
|
273
274
|
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig
|
|
274
|
-
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig } as IBoxInputData
|
|
275
|
+
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', opacity: 1, width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig } as IBoxInputData
|
|
275
276
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle
|
|
276
277
|
}
|
|
277
278
|
|
|
@@ -285,6 +286,11 @@ export class EditBox extends Group implements IEditBox {
|
|
|
285
286
|
return isArray(middlePoint) ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle())
|
|
286
287
|
}
|
|
287
288
|
|
|
289
|
+
public getResizeLinesStyle(): IBoxInputData[] {
|
|
290
|
+
const { resizeLine } = this.mergedConfig
|
|
291
|
+
return isArray(resizeLine) ? resizeLine : [resizeLine]
|
|
292
|
+
}
|
|
293
|
+
|
|
288
294
|
|
|
289
295
|
// drag
|
|
290
296
|
|
|
@@ -330,7 +336,7 @@ export class EditBox extends Group implements IEditBox {
|
|
|
330
336
|
// 操作事件共用
|
|
331
337
|
|
|
332
338
|
public onTransformStart(e: IUIEvent): void {
|
|
333
|
-
if (this.moving) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1 // move
|
|
339
|
+
if (this.moving || this.gesturing) this.editor.opacity = this.mergedConfig.hideOnMove ? 0 : 1 // move
|
|
334
340
|
if (this.resizing) ResizeEvent.resizingKeys = this.editor.leafList.keys // 记录正在resize中的元素列表
|
|
335
341
|
|
|
336
342
|
const { dragStartData, target } = this
|
|
@@ -358,7 +364,11 @@ export class EditBox extends Group implements IEditBox {
|
|
|
358
364
|
e.stop()
|
|
359
365
|
if (isString(this.mergedConfig.moveable)) {
|
|
360
366
|
this.gesturing = this.moving = true
|
|
361
|
-
e.type
|
|
367
|
+
switch (e.type) {
|
|
368
|
+
case MoveEvent.START: this.onTransformStart(e); break
|
|
369
|
+
case MoveEvent.END: this.onTransformEnd(e); break
|
|
370
|
+
default: this.transformTool.onMove(e)
|
|
371
|
+
}
|
|
362
372
|
}
|
|
363
373
|
}
|
|
364
374
|
}
|
|
@@ -368,7 +378,11 @@ export class EditBox extends Group implements IEditBox {
|
|
|
368
378
|
e.stop()
|
|
369
379
|
if (isString(this.mergedConfig.resizeable)) {
|
|
370
380
|
this.gesturing = this.resizing = true
|
|
371
|
-
e.type
|
|
381
|
+
switch (e.type) {
|
|
382
|
+
case ZoomEvent.START: this.onTransformStart(e); break
|
|
383
|
+
case ZoomEvent.END: this.onTransformEnd(e); break
|
|
384
|
+
default: this.transformTool.onScale(e)
|
|
385
|
+
}
|
|
372
386
|
}
|
|
373
387
|
}
|
|
374
388
|
}
|
|
@@ -378,19 +392,15 @@ export class EditBox extends Group implements IEditBox {
|
|
|
378
392
|
e.stop()
|
|
379
393
|
if (isString(this.mergedConfig.rotateable)) {
|
|
380
394
|
this.gesturing = this.rotating = true
|
|
381
|
-
e.type
|
|
395
|
+
switch (e.type) {
|
|
396
|
+
case ZoomEvent.START: this.onTransformStart(e); break
|
|
397
|
+
case ZoomEvent.END: this.onTransformEnd(e); break
|
|
398
|
+
default: this.transformTool.onRotate(e)
|
|
399
|
+
}
|
|
382
400
|
}
|
|
383
401
|
}
|
|
384
402
|
}
|
|
385
403
|
|
|
386
|
-
public onGestureStart(e: IUIEvent): void {
|
|
387
|
-
if (this.canGesture && (e as MoveEvent).moveType !== 'drag') this.onTransformStart(e)
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
public onGestureEnd(e: IUIEvent): void {
|
|
391
|
-
if (this.canGesture && (e as MoveEvent).moveType !== 'drag') this.onTransformEnd(e)
|
|
392
|
-
}
|
|
393
|
-
|
|
394
404
|
// 键盘
|
|
395
405
|
|
|
396
406
|
public isHoldRotateKey(e: IUIEvent): boolean { // 按住ctrl在控制点上变旋转功能
|
|
@@ -487,12 +497,9 @@ export class EditBox extends Group implements IEditBox {
|
|
|
487
497
|
[[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
|
|
488
498
|
[KeyEvent.DOWN, this.onArrow, this],
|
|
489
499
|
|
|
490
|
-
[MoveEvent.BEFORE_MOVE, this.onMove, this, true],
|
|
491
|
-
[ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
|
|
492
|
-
[RotateEvent.BEFORE_ROTATE, this.onRotate, this, true]
|
|
493
|
-
|
|
494
|
-
[[MoveEvent.START, ZoomEvent.START, RotateEvent.START], this.onGestureStart, this],
|
|
495
|
-
[[MoveEvent.END, ZoomEvent.END, RotateEvent.END], this.onGestureEnd, this],
|
|
500
|
+
[[MoveEvent.START, MoveEvent.BEFORE_MOVE, MoveEvent.END], this.onMove, this, true],
|
|
501
|
+
[[ZoomEvent.START, ZoomEvent.BEFORE_ZOOM, ZoomEvent.END], this.onScale, this, true],
|
|
502
|
+
[[RotateEvent.START, RotateEvent.BEFORE_ROTATE, RotateEvent.END], this.onRotate, this, true]
|
|
496
503
|
])
|
|
497
504
|
)
|
|
498
505
|
})
|
package/src/display/Stroker.ts
CHANGED
|
@@ -84,8 +84,8 @@ export class Stroker extends UI implements IStroker {
|
|
|
84
84
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas) : Paint.strokes(stroke, this, canvas)
|
|
88
|
-
if (fill) isString(fill) ? Paint.fill(fill, this, canvas) : Paint.fills(fill, this, canvas)
|
|
87
|
+
if (stroke) isString(stroke) ? Paint.stroke(stroke, this, canvas, options) : Paint.strokes(stroke, this, canvas, options)
|
|
88
|
+
if (fill) isString(fill) ? Paint.fill(fill, this, canvas, options) : Paint.fills(fill, this, canvas, options)
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
package/types/index.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ declare class Editor extends Group implements IEditor {
|
|
|
96
96
|
setBright(value: boolean): void;
|
|
97
97
|
update(): void;
|
|
98
98
|
updateEditBox(): void;
|
|
99
|
+
getEditTool(name: string): IEditTool;
|
|
99
100
|
updateEditTool(): void;
|
|
100
101
|
unloadEditTool(): void;
|
|
101
102
|
getEditSize(_ui: IUI): IEditSize;
|
|
@@ -119,6 +120,7 @@ declare class Editor extends Group implements IEditor {
|
|
|
119
120
|
checkOpenedGroups(): void;
|
|
120
121
|
checkDeepSelect(): void;
|
|
121
122
|
emitGroupEvent(type: string, group?: IGroup): void;
|
|
123
|
+
getInnerEditor(name: string): IInnerEditor;
|
|
122
124
|
openInnerEditor(target?: IUI, nameOrSelect?: string | boolean, select?: boolean): void;
|
|
123
125
|
closeInnerEditor(onlyInnerEditor?: boolean): void;
|
|
124
126
|
emitInnerEvent(type: string): void;
|
|
@@ -182,6 +184,7 @@ declare class EditBox extends Group implements IEditBox {
|
|
|
182
184
|
getPointStyle(userStyle?: IBoxInputData): IBoxInputData;
|
|
183
185
|
getPointsStyle(): IBoxInputData[];
|
|
184
186
|
getMiddlePointsStyle(): IBoxInputData[];
|
|
187
|
+
getResizeLinesStyle(): IBoxInputData[];
|
|
185
188
|
onDragStart(e: DragEvent): void;
|
|
186
189
|
onDrag(e: DragEvent): void;
|
|
187
190
|
onDragEnd(e: DragEvent): void;
|
|
@@ -190,8 +193,6 @@ declare class EditBox extends Group implements IEditBox {
|
|
|
190
193
|
onMove(e: MoveEvent): void;
|
|
191
194
|
onScale(e: ZoomEvent): void;
|
|
192
195
|
onRotate(e: RotateEvent): void;
|
|
193
|
-
onGestureStart(e: IUIEvent): void;
|
|
194
|
-
onGestureEnd(e: IUIEvent): void;
|
|
195
196
|
isHoldRotateKey(e: IUIEvent): boolean;
|
|
196
197
|
protected onKey(e: KeyEvent): void;
|
|
197
198
|
onArrow(e: IKeyEvent): void;
|