@leafer-ui/core 1.7.0 → 1.9.0

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/lib/core.esm.js CHANGED
@@ -1,63 +1,46 @@
1
- import { Leafer, State, UI, Rect, Box, Text, Group, emptyData } from '@leafer-ui/draw';
2
- export * from '@leafer-ui/draw';
3
- import { registerUI, Creator, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, registerUIEvent, LeafList, PointHelper, BoundsHelper, Debug, Platform, Bounds, ResizeEvent, LeaferEvent, CanvasManager, Leaf, Matrix, tempBounds, ImageManager, LeaferCanvasBase } from '@leafer/core';
4
-
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
20
-
21
-
22
- function __decorate(decorators, target, key, desc) {
23
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
26
- return c > 3 && r && Object.defineProperty(target, key, r), r;
27
- }
28
-
29
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
30
- var e = new Error(message);
31
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1
+ import { Leafer, State, UI, Rect, Box, Text, Group, emptyData } from "@leafer-ui/draw";
2
+
3
+ export * from "@leafer-ui/draw";
4
+
5
+ import { registerUI, Creator, isUndefined, DataHelper, canvasSizeAttrs, LayoutEvent, RenderEvent, Event, EventCreator, registerUIEvent, LeafList, PointHelper, BoundsHelper, LeafHelper, isNumber, Debug, Platform, Bounds, ResizeEvent, LeaferEvent, CanvasManager, Leaf, Matrix, tempBounds, ImageManager, LeaferCanvasBase } from "@leafer/core";
6
+
7
+ function __decorate(decorators, target, key, desc) {
8
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
10
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
11
+ }
12
+
13
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
14
+ var e = new Error(message);
15
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
32
16
  };
33
17
 
34
18
  let App = class App extends Leafer {
35
- get __tag() { return 'App'; }
36
- get isApp() { return true; }
19
+ get __tag() {
20
+ return "App";
21
+ }
22
+ get isApp() {
23
+ return true;
24
+ }
37
25
  constructor(userConfig, data) {
38
26
  super(userConfig, data);
39
27
  }
40
28
  init(userConfig, parentApp) {
41
29
  super.init(userConfig, parentApp);
42
30
  if (userConfig) {
43
- const { ground, tree, sky, editor } = userConfig;
44
- if (ground)
45
- this.ground = this.addLeafer(ground);
46
- if (tree || editor)
47
- this.tree = this.addLeafer(tree || { type: userConfig.type || 'design' });
48
- if (sky || editor)
49
- this.sky = this.addLeafer(sky);
50
- if (editor)
51
- Creator.editor(editor, this);
31
+ const {ground: ground, tree: tree, sky: sky, editor: editor} = userConfig;
32
+ if (ground) this.ground = this.addLeafer(ground);
33
+ if (tree || editor) this.tree = this.addLeafer(tree || {
34
+ type: userConfig.type || "design"
35
+ });
36
+ if (sky || editor) this.sky = this.addLeafer(sky);
37
+ if (editor) Creator.editor(editor, this);
52
38
  }
53
39
  }
54
40
  __setApp() {
55
- const { canvas } = this;
56
- const { realCanvas, view } = this.config;
57
- if (realCanvas || view === this.canvas.view || !canvas.parentView)
58
- this.realCanvas = true;
59
- else
60
- canvas.unrealCanvas();
41
+ const {canvas: canvas} = this;
42
+ const {realCanvas: realCanvas, view: view} = this.config;
43
+ if (realCanvas || view === this.canvas.view || !canvas.parentView) this.realCanvas = true; else canvas.unrealCanvas();
61
44
  this.leafer = this;
62
45
  this.watcher.disable();
63
46
  this.layouter.disable();
@@ -99,8 +82,7 @@ let App = class App extends Leafer {
99
82
  leafer.init(this.__getChildConfig(leafer.userConfig), this);
100
83
  }
101
84
  super.add(leafer, index);
102
- if (index !== undefined)
103
- leafer.canvas.childIndex = index;
85
+ if (!isUndefined(index)) leafer.canvas.childIndex = index;
104
86
  this.__listenChildEvents(leafer);
105
87
  }
106
88
  forEach(fn) {
@@ -110,21 +92,17 @@ let App = class App extends Leafer {
110
92
  this.created = this.children.every(child => child.created);
111
93
  }
112
94
  __onReady() {
113
- if (this.children.every(child => child.ready))
114
- super.__onReady();
95
+ if (this.children.every(child => child.ready)) super.__onReady();
115
96
  }
116
97
  __onViewReady() {
117
- if (this.children.every(child => child.viewReady))
118
- super.__onViewReady();
98
+ if (this.children.every(child => child.viewReady)) super.__onViewReady();
119
99
  }
120
100
  __onChildRenderEnd(e) {
121
101
  this.renderer.addBlock(e.renderBounds);
122
- if (this.viewReady)
123
- this.renderer.update();
102
+ if (this.viewReady) this.renderer.update();
124
103
  }
125
104
  __render(canvas, options) {
126
- if (canvas.context)
127
- this.forEach(leafer => options.matrix ? leafer.__render(canvas, options) : canvas.copyWorld(leafer.canvas, options && options.bounds));
105
+ if (canvas.context) this.forEach(leafer => options.matrix ? leafer.__render(canvas, options) : canvas.copyWorld(leafer.canvas, options && options.bounds));
128
106
  }
129
107
  __onResize(event) {
130
108
  this.forEach(leafer => leafer.resize(event));
@@ -136,39 +114,34 @@ let App = class App extends Leafer {
136
114
  __getChildConfig(userConfig) {
137
115
  const config = Object.assign({}, this.config);
138
116
  config.hittable = config.realCanvas = undefined;
139
- if (userConfig)
140
- DataHelper.assign(config, userConfig);
141
- if (this.autoLayout)
142
- DataHelper.copyAttrs(config, this, canvasSizeAttrs);
117
+ if (userConfig) DataHelper.assign(config, userConfig);
118
+ if (this.autoLayout) DataHelper.copyAttrs(config, this, canvasSizeAttrs);
143
119
  config.view = this.realCanvas ? undefined : this.view;
144
120
  config.fill = undefined;
145
121
  return config;
146
122
  }
147
123
  __listenChildEvents(leafer) {
148
- leafer.once([
149
- [LayoutEvent.END, this.__onReady, this],
150
- [RenderEvent.START, this.__onCreated, this],
151
- [RenderEvent.END, this.__onViewReady, this]
152
- ]);
153
- if (this.realCanvas)
154
- this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this));
124
+ leafer.once([ [ LayoutEvent.END, this.__onReady, this ], [ RenderEvent.START, this.__onCreated, this ], [ RenderEvent.END, this.__onViewReady, this ] ]);
125
+ if (this.realCanvas) this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this));
155
126
  }
156
127
  };
157
- App = __decorate([
158
- registerUI()
159
- ], App);
128
+
129
+ App = __decorate([ registerUI() ], App);
160
130
 
161
131
  const downKeyMap = {};
132
+
162
133
  const Keyboard = {
163
134
  isHoldSpaceKey() {
164
- return Keyboard.isHold('Space');
135
+ return Keyboard.isHold("Space");
165
136
  },
166
137
  isHold(code) {
167
138
  return downKeyMap[code];
168
139
  },
140
+ isHoldKeys(shortcutKeys, e) {
141
+ return e ? shortcutKeys(e) : undefined;
142
+ },
169
143
  setDownCode(code) {
170
- if (!downKeyMap[code])
171
- downKeyMap[code] = true;
144
+ if (!downKeyMap[code]) downKeyMap[code] = true;
172
145
  },
173
146
  setUpCode(code) {
174
147
  downKeyMap[code] = false;
@@ -179,23 +152,41 @@ const PointerButton = {
179
152
  LEFT: 1,
180
153
  RIGHT: 2,
181
154
  MIDDLE: 4,
182
- defaultLeft(event) { if (!event.buttons)
183
- event.buttons = 1; },
184
- left(event) { return event.buttons === 1; },
185
- right(event) { return event.buttons === 2; },
186
- middle(event) { return event.buttons === 4; }
155
+ defaultLeft(event) {
156
+ if (!event.buttons) event.buttons = 1;
157
+ },
158
+ left(event) {
159
+ return event.buttons === 1;
160
+ },
161
+ right(event) {
162
+ return event.buttons === 2;
163
+ },
164
+ middle(event) {
165
+ return event.buttons === 4;
166
+ }
187
167
  };
188
168
 
189
169
  class UIEvent extends Event {
190
- get spaceKey() { return Keyboard.isHoldSpaceKey(); }
191
- get left() { return PointerButton.left(this); }
192
- get right() { return PointerButton.right(this); }
193
- get middle() { return PointerButton.middle(this); }
170
+ get spaceKey() {
171
+ return Keyboard.isHoldSpaceKey();
172
+ }
173
+ get left() {
174
+ return PointerButton.left(this);
175
+ }
176
+ get right() {
177
+ return PointerButton.right(this);
178
+ }
179
+ get middle() {
180
+ return PointerButton.middle(this);
181
+ }
194
182
  constructor(params) {
195
183
  super(params.type);
196
184
  this.bubbles = true;
197
185
  Object.assign(this, params);
198
186
  }
187
+ isHoldKeys(shortcutKeys) {
188
+ return Keyboard.isHoldKeys(shortcutKeys, this);
189
+ }
199
190
  getBoxPoint(relative) {
200
191
  return (relative || this.current).getBoxPoint(this);
201
192
  }
@@ -208,41 +199,66 @@ class UIEvent extends Event {
208
199
  getPagePoint() {
209
200
  return this.current.getPagePoint(this);
210
201
  }
211
- getInner(relative) { return this.getInnerPoint(relative); }
212
- getLocal(relative) { return this.getLocalPoint(relative); }
213
- getPage() { return this.getPagePoint(); }
202
+ getInner(relative) {
203
+ return this.getInnerPoint(relative);
204
+ }
205
+ getLocal(relative) {
206
+ return this.getLocalPoint(relative);
207
+ }
208
+ getPage() {
209
+ return this.getPagePoint();
210
+ }
214
211
  static changeName(oldName, newName) {
215
212
  EventCreator.changeName(oldName, newName);
216
213
  }
217
214
  }
218
215
 
219
- let PointerEvent = class PointerEvent extends UIEvent {
220
- };
221
- PointerEvent.POINTER = 'pointer';
222
- PointerEvent.BEFORE_DOWN = 'pointer.before_down';
223
- PointerEvent.BEFORE_MOVE = 'pointer.before_move';
224
- PointerEvent.BEFORE_UP = 'pointer.before_up';
225
- PointerEvent.DOWN = 'pointer.down';
226
- PointerEvent.MOVE = 'pointer.move';
227
- PointerEvent.UP = 'pointer.up';
228
- PointerEvent.OVER = 'pointer.over';
229
- PointerEvent.OUT = 'pointer.out';
230
- PointerEvent.ENTER = 'pointer.enter';
231
- PointerEvent.LEAVE = 'pointer.leave';
232
- PointerEvent.TAP = 'tap';
233
- PointerEvent.DOUBLE_TAP = 'double_tap';
234
- PointerEvent.CLICK = 'click';
235
- PointerEvent.DOUBLE_CLICK = 'double_click';
236
- PointerEvent.LONG_PRESS = 'long_press';
237
- PointerEvent.LONG_TAP = 'long_tap';
238
- PointerEvent.MENU = 'pointer.menu';
239
- PointerEvent.MENU_TAP = 'pointer.menu_tap';
240
- PointerEvent = __decorate([
241
- registerUIEvent()
242
- ], PointerEvent);
216
+ let PointerEvent = class PointerEvent extends UIEvent {};
217
+
218
+ PointerEvent.POINTER = "pointer";
219
+
220
+ PointerEvent.BEFORE_DOWN = "pointer.before_down";
221
+
222
+ PointerEvent.BEFORE_MOVE = "pointer.before_move";
223
+
224
+ PointerEvent.BEFORE_UP = "pointer.before_up";
225
+
226
+ PointerEvent.DOWN = "pointer.down";
227
+
228
+ PointerEvent.MOVE = "pointer.move";
229
+
230
+ PointerEvent.UP = "pointer.up";
231
+
232
+ PointerEvent.OVER = "pointer.over";
233
+
234
+ PointerEvent.OUT = "pointer.out";
235
+
236
+ PointerEvent.ENTER = "pointer.enter";
237
+
238
+ PointerEvent.LEAVE = "pointer.leave";
239
+
240
+ PointerEvent.TAP = "tap";
241
+
242
+ PointerEvent.DOUBLE_TAP = "double_tap";
243
+
244
+ PointerEvent.CLICK = "click";
245
+
246
+ PointerEvent.DOUBLE_CLICK = "double_click";
247
+
248
+ PointerEvent.LONG_PRESS = "long_press";
249
+
250
+ PointerEvent.LONG_TAP = "long_tap";
251
+
252
+ PointerEvent.MENU = "pointer.menu";
253
+
254
+ PointerEvent.MENU_TAP = "pointer.menu_tap";
255
+
256
+ PointerEvent = __decorate([ registerUIEvent() ], PointerEvent);
257
+
243
258
  const MyPointerEvent = PointerEvent;
244
259
 
245
260
  const tempMove = {};
261
+
246
262
  let DragEvent = class DragEvent extends PointerEvent {
247
263
  static setList(data) {
248
264
  this.list = data instanceof LeafList ? data : new LeafList(data);
@@ -250,41 +266,28 @@ let DragEvent = class DragEvent extends PointerEvent {
250
266
  static setData(data) {
251
267
  this.data = data;
252
268
  }
253
- static getValidMove(leaf, start, total) {
254
- const { draggable, dragBounds } = leaf, move = leaf.getLocalPoint(total, null, true);
269
+ static getValidMove(leaf, start, total, checkLimit = true) {
270
+ const move = leaf.getLocalPoint(total, null, true);
255
271
  PointHelper.move(move, start.x - leaf.x, start.y - leaf.y);
256
- if (dragBounds)
257
- this.getMoveInDragBounds(leaf.__localBoxBounds, dragBounds === 'parent' ? leaf.parent.boxBounds : dragBounds, move, true);
258
- if (draggable === 'x')
259
- move.y = 0;
260
- if (draggable === 'y')
261
- move.x = 0;
272
+ if (checkLimit) this.limitMove(leaf, move);
262
273
  return move;
263
274
  }
275
+ static limitMove(leaf, move) {
276
+ const {draggable: draggable, dragBounds: dragBounds} = leaf;
277
+ if (dragBounds) this.getMoveInDragBounds(leaf.__localBoxBounds, dragBounds === "parent" ? leaf.parent.boxBounds : dragBounds, move, true);
278
+ if (draggable === "x") move.y = 0;
279
+ if (draggable === "y") move.x = 0;
280
+ }
264
281
  static getMoveInDragBounds(childBox, dragBounds, move, change) {
265
282
  const x = childBox.x + move.x, y = childBox.y + move.y, right = x + childBox.width, bottom = y + childBox.height;
266
283
  const boundsRight = dragBounds.x + dragBounds.width, boundsBottom = dragBounds.y + dragBounds.height;
267
- if (!change)
268
- move = Object.assign({}, move);
284
+ if (!change) move = Object.assign({}, move);
269
285
  if (BoundsHelper.includes(childBox, dragBounds)) {
270
- if (x > dragBounds.x)
271
- move.x += dragBounds.x - x;
272
- else if (right < boundsRight)
273
- move.x += boundsRight - right;
274
- if (y > dragBounds.y)
275
- move.y += dragBounds.y - y;
276
- else if (bottom < boundsBottom)
277
- move.y += boundsBottom - bottom;
278
- }
279
- else {
280
- if (x < dragBounds.x)
281
- move.x += dragBounds.x - x;
282
- else if (right > boundsRight)
283
- move.x += boundsRight - right;
284
- if (y < dragBounds.y)
285
- move.y += dragBounds.y - y;
286
- else if (bottom > boundsBottom)
287
- move.y += boundsBottom - bottom;
286
+ if (x > dragBounds.x) move.x += dragBounds.x - x; else if (right < boundsRight) move.x += boundsRight - right;
287
+ if (y > dragBounds.y) move.y += dragBounds.y - y; else if (bottom < boundsBottom) move.y += boundsBottom - bottom;
288
+ } else {
289
+ if (x < dragBounds.x) move.x += dragBounds.x - x; else if (right > boundsRight) move.x += boundsRight - right;
290
+ if (y < dragBounds.y) move.y += dragBounds.y - y; else if (bottom > boundsBottom) move.y += boundsBottom - bottom;
288
291
  }
289
292
  return move;
290
293
  }
@@ -293,14 +296,12 @@ let DragEvent = class DragEvent extends PointerEvent {
293
296
  return this.current.getPagePoint(tempMove, null, true);
294
297
  }
295
298
  getInnerMove(relative, total) {
296
- if (!relative)
297
- relative = this.current;
299
+ if (!relative) relative = this.current;
298
300
  this.assignMove(total);
299
301
  return relative.getInnerPoint(tempMove, null, true);
300
302
  }
301
303
  getLocalMove(relative, total) {
302
- if (!relative)
303
- relative = this.current;
304
+ if (!relative) relative = this.current;
304
305
  this.assignMove(total);
305
306
  return relative.getLocalPoint(tempMove, null, true);
306
307
  }
@@ -324,17 +325,25 @@ let DragEvent = class DragEvent extends PointerEvent {
324
325
  tempMove.y = total ? this.totalY : this.moveY;
325
326
  }
326
327
  };
327
- DragEvent.BEFORE_DRAG = 'drag.before_drag';
328
- DragEvent.START = 'drag.start';
329
- DragEvent.DRAG = 'drag';
330
- DragEvent.END = 'drag.end';
331
- DragEvent.OVER = 'drag.over';
332
- DragEvent.OUT = 'drag.out';
333
- DragEvent.ENTER = 'drag.enter';
334
- DragEvent.LEAVE = 'drag.leave';
335
- DragEvent = __decorate([
336
- registerUIEvent()
337
- ], DragEvent);
328
+
329
+ DragEvent.BEFORE_DRAG = "drag.before_drag";
330
+
331
+ DragEvent.START = "drag.start";
332
+
333
+ DragEvent.DRAG = "drag";
334
+
335
+ DragEvent.END = "drag.end";
336
+
337
+ DragEvent.OVER = "drag.over";
338
+
339
+ DragEvent.OUT = "drag.out";
340
+
341
+ DragEvent.ENTER = "drag.enter";
342
+
343
+ DragEvent.LEAVE = "drag.leave";
344
+
345
+ DragEvent = __decorate([ registerUIEvent() ], DragEvent);
346
+
338
347
  const MyDragEvent = DragEvent;
339
348
 
340
349
  let DropEvent = class DropEvent extends PointerEvent {
@@ -345,81 +354,103 @@ let DropEvent = class DropEvent extends PointerEvent {
345
354
  DragEvent.setData(data);
346
355
  }
347
356
  };
348
- DropEvent.DROP = 'drop';
349
- DropEvent = __decorate([
350
- registerUIEvent()
351
- ], DropEvent);
352
357
 
353
- let MoveEvent = class MoveEvent extends DragEvent {
354
- };
355
- MoveEvent.BEFORE_MOVE = 'move.before_move';
356
- MoveEvent.START = 'move.start';
357
- MoveEvent.MOVE = 'move';
358
- MoveEvent.END = 'move.end';
359
- MoveEvent = __decorate([
360
- registerUIEvent()
361
- ], MoveEvent);
362
-
363
- let RotateEvent = class RotateEvent extends PointerEvent {
364
- };
365
- RotateEvent.BEFORE_ROTATE = 'rotate.before_rotate';
366
- RotateEvent.START = 'rotate.start';
367
- RotateEvent.ROTATE = 'rotate';
368
- RotateEvent.END = 'rotate.end';
369
- RotateEvent = __decorate([
370
- registerUIEvent()
371
- ], RotateEvent);
372
-
373
- let SwipeEvent = class SwipeEvent extends DragEvent {
374
- };
375
- SwipeEvent.SWIPE = 'swipe';
376
- SwipeEvent.LEFT = 'swipe.left';
377
- SwipeEvent.RIGHT = 'swipe.right';
378
- SwipeEvent.UP = 'swipe.up';
379
- SwipeEvent.DOWN = 'swipe.down';
380
- SwipeEvent = __decorate([
381
- registerUIEvent()
382
- ], SwipeEvent);
383
-
384
- let ZoomEvent = class ZoomEvent extends PointerEvent {
385
- };
386
- ZoomEvent.BEFORE_ZOOM = 'zoom.before_zoom';
387
- ZoomEvent.START = 'zoom.start';
388
- ZoomEvent.ZOOM = 'zoom';
389
- ZoomEvent.END = 'zoom.end';
390
- ZoomEvent = __decorate([
391
- registerUIEvent()
392
- ], ZoomEvent);
393
-
394
- let KeyEvent = class KeyEvent extends UIEvent {
395
- };
396
- KeyEvent.DOWN = 'key.down';
397
- KeyEvent.HOLD = 'key.hold';
398
- KeyEvent.UP = 'key.up';
399
- KeyEvent = __decorate([
400
- registerUIEvent()
401
- ], KeyEvent);
358
+ DropEvent.DROP = "drop";
359
+
360
+ DropEvent = __decorate([ registerUIEvent() ], DropEvent);
361
+
362
+ let MoveEvent = class MoveEvent extends DragEvent {};
363
+
364
+ MoveEvent.BEFORE_MOVE = "move.before_move";
365
+
366
+ MoveEvent.START = "move.start";
367
+
368
+ MoveEvent.MOVE = "move";
369
+
370
+ MoveEvent.END = "move.end";
371
+
372
+ MoveEvent = __decorate([ registerUIEvent() ], MoveEvent);
373
+
374
+ let RotateEvent = class RotateEvent extends PointerEvent {};
375
+
376
+ RotateEvent.BEFORE_ROTATE = "rotate.before_rotate";
377
+
378
+ RotateEvent.START = "rotate.start";
379
+
380
+ RotateEvent.ROTATE = "rotate";
381
+
382
+ RotateEvent.END = "rotate.end";
383
+
384
+ RotateEvent = __decorate([ registerUIEvent() ], RotateEvent);
385
+
386
+ let SwipeEvent = class SwipeEvent extends DragEvent {};
387
+
388
+ SwipeEvent.SWIPE = "swipe";
389
+
390
+ SwipeEvent.LEFT = "swipe.left";
391
+
392
+ SwipeEvent.RIGHT = "swipe.right";
393
+
394
+ SwipeEvent.UP = "swipe.up";
395
+
396
+ SwipeEvent.DOWN = "swipe.down";
397
+
398
+ SwipeEvent = __decorate([ registerUIEvent() ], SwipeEvent);
399
+
400
+ let ZoomEvent = class ZoomEvent extends PointerEvent {};
401
+
402
+ ZoomEvent.BEFORE_ZOOM = "zoom.before_zoom";
403
+
404
+ ZoomEvent.START = "zoom.start";
405
+
406
+ ZoomEvent.ZOOM = "zoom";
407
+
408
+ ZoomEvent.END = "zoom.end";
409
+
410
+ ZoomEvent = __decorate([ registerUIEvent() ], ZoomEvent);
411
+
412
+ let KeyEvent = class KeyEvent extends UIEvent {};
413
+
414
+ KeyEvent.BEFORE_DOWN = "key.before_down";
415
+
416
+ KeyEvent.BEFORE_UP = "key.before_up";
417
+
418
+ KeyEvent.DOWN = "key.down";
419
+
420
+ KeyEvent.HOLD = "key.hold";
421
+
422
+ KeyEvent.UP = "key.up";
423
+
424
+ KeyEvent = __decorate([ registerUIEvent() ], KeyEvent);
402
425
 
403
426
  const InteractionHelper = {
404
427
  getDragEventData(startPoint, lastPoint, event) {
405
- return Object.assign(Object.assign({}, event), { x: event.x, y: event.y, moveX: event.x - lastPoint.x, moveY: event.y - lastPoint.y, totalX: event.x - startPoint.x, totalY: event.y - startPoint.y });
428
+ return Object.assign(Object.assign({}, event), {
429
+ x: event.x,
430
+ y: event.y,
431
+ moveX: event.x - lastPoint.x,
432
+ moveY: event.y - lastPoint.y,
433
+ totalX: event.x - startPoint.x,
434
+ totalY: event.y - startPoint.y
435
+ });
406
436
  },
407
437
  getDropEventData(event, list, data) {
408
- return Object.assign(Object.assign({}, event), { list,
409
- data });
438
+ return Object.assign(Object.assign({}, event), {
439
+ list: list,
440
+ data: data
441
+ });
410
442
  },
411
443
  getSwipeDirection(angle) {
412
- if (angle < -45 && angle > -135)
413
- return SwipeEvent.UP;
414
- else if (angle > 45 && angle < 135)
415
- return SwipeEvent.DOWN;
416
- else if (angle <= 45 && angle >= -45)
417
- return SwipeEvent.RIGHT;
418
- else
419
- return SwipeEvent.LEFT;
444
+ if (angle < -45 && angle > -135) return SwipeEvent.UP; else if (angle > 45 && angle < 135) return SwipeEvent.DOWN; else if (angle <= 45 && angle >= -45) return SwipeEvent.RIGHT; else return SwipeEvent.LEFT;
420
445
  },
421
446
  getSwipeEventData(startPoint, lastDragData, event) {
422
- return Object.assign(Object.assign({}, event), { moveX: lastDragData.moveX, moveY: lastDragData.moveY, totalX: event.x - startPoint.x, totalY: event.y - startPoint.y, type: I.getSwipeDirection(PointHelper.getAngle(startPoint, event)) });
447
+ return Object.assign(Object.assign({}, event), {
448
+ moveX: lastDragData.moveX,
449
+ moveY: lastDragData.moveY,
450
+ totalX: event.x - startPoint.x,
451
+ totalY: event.y - startPoint.y,
452
+ type: I.getSwipeDirection(PointHelper.getAngle(startPoint, event))
453
+ });
423
454
  },
424
455
  getBase(e) {
425
456
  const pointerUpButtons = e.button === 1 ? 4 : e.button;
@@ -428,56 +459,56 @@ const InteractionHelper = {
428
459
  ctrlKey: e.ctrlKey,
429
460
  shiftKey: e.shiftKey,
430
461
  metaKey: e.metaKey,
431
- buttons: e.buttons === undefined ? 1 : (e.buttons === 0 ? pointerUpButtons : e.buttons),
462
+ buttons: isUndefined(e.buttons) ? 1 : e.buttons === 0 ? pointerUpButtons : e.buttons,
432
463
  origin: e
433
464
  };
434
465
  },
435
466
  pathHasEventType(path, type) {
436
- const { list } = path;
467
+ const {list: list} = path;
437
468
  for (let i = 0, len = list.length; i < len; i++) {
438
- if (list[i].hasEvent(type))
439
- return true;
469
+ if (list[i].hasEvent(type)) return true;
440
470
  }
441
471
  return false;
442
472
  },
443
473
  filterPathByEventType(path, type) {
444
- const find = new LeafList();
445
- const { list } = path;
474
+ const find = new LeafList;
475
+ const {list: list} = path;
446
476
  for (let i = 0, len = list.length; i < len; i++) {
447
- if (list[i].hasEvent(type))
448
- find.add(list[i]);
477
+ if (list[i].hasEvent(type)) find.add(list[i]);
449
478
  }
450
479
  return find;
451
480
  },
452
481
  pathCanDrag(path) {
453
- return path && path.list.some(item => item.draggable || item.editable || (!item.isLeafer && item.hasEvent(DragEvent.DRAG)));
482
+ return path && path.list.some(item => LeafHelper.draggable(item) || !item.isLeafer && item.hasEvent(DragEvent.DRAG));
454
483
  },
455
484
  pathHasOutside(path) {
456
485
  return path && path.list.some(item => item.isOutside);
457
- },
486
+ }
458
487
  };
488
+
459
489
  const I = InteractionHelper;
460
490
 
461
- const emptyList = new LeafList();
462
- const { getDragEventData, getDropEventData, getSwipeEventData } = InteractionHelper;
491
+ const emptyList = new LeafList;
492
+
493
+ const {getDragEventData: getDragEventData, getDropEventData: getDropEventData, getSwipeEventData: getSwipeEventData} = InteractionHelper;
494
+
463
495
  class Dragger {
464
496
  constructor(interaction) {
465
497
  this.interaction = interaction;
466
498
  }
467
499
  setDragData(data) {
468
- if (this.animateWait)
469
- this.dragEndReal();
500
+ if (this.animateWait) this.dragEndReal();
470
501
  this.downData = this.interaction.downData;
471
502
  this.dragData = getDragEventData(data, data, data);
472
503
  this.canAnimate = this.canDragOut = true;
473
504
  }
474
505
  getList(realDraggable, hover) {
475
- const { proxy } = this.interaction.selector;
506
+ const {proxy: proxy} = this.interaction.selector;
476
507
  const hasProxyList = proxy && proxy.list.length, dragList = DragEvent.list || this.draggableList || emptyList;
477
- return this.dragging && (hasProxyList ? (realDraggable ? emptyList : new LeafList(hover ? [...proxy.list, ...proxy.dragHoverExclude] : proxy.list)) : dragList);
508
+ return this.dragging && (hasProxyList ? realDraggable ? emptyList : new LeafList(hover ? [ ...proxy.list, ...proxy.dragHoverExclude ] : proxy.list) : dragList);
478
509
  }
479
510
  checkDrag(data, canDrag) {
480
- const { interaction } = this;
511
+ const {interaction: interaction} = this;
481
512
  if (this.moving && data.buttons < 1) {
482
513
  this.canAnimate = false;
483
514
  interaction.pointerCancel();
@@ -485,12 +516,11 @@ class Dragger {
485
516
  }
486
517
  if (!this.moving && canDrag) {
487
518
  if (this.moving = interaction.canMove(this.downData) || interaction.isHoldRightKey || interaction.isMobileDragEmpty) {
488
- this.dragData.moveType = 'drag';
519
+ this.dragData.moveType = "drag";
489
520
  interaction.emit(MoveEvent.START, this.dragData);
490
521
  }
491
522
  }
492
- if (!this.moving)
493
- this.dragStart(data, canDrag);
523
+ if (!this.moving) this.dragStart(data, canDrag);
494
524
  this.drag(data);
495
525
  }
496
526
  dragStart(data, canDrag) {
@@ -505,100 +535,105 @@ class Dragger {
505
535
  }
506
536
  setDragStartPoints(list) {
507
537
  this.dragStartPoints = {};
508
- list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
538
+ list.forEach(leaf => this.dragStartPoints[leaf.innerId] = {
539
+ x: leaf.x,
540
+ y: leaf.y
541
+ });
509
542
  }
510
543
  getDraggableList(path) {
511
544
  let leaf;
512
545
  for (let i = 0, len = path.length; i < len; i++) {
513
546
  leaf = path.list[i];
514
- if ((leaf.draggable || leaf.editable) && leaf.hitSelf && !leaf.locked) {
547
+ if (LeafHelper.draggable(leaf)) {
515
548
  this.draggableList = new LeafList(leaf);
516
549
  break;
517
550
  }
518
551
  }
519
552
  }
520
553
  drag(data) {
521
- const { interaction, dragData, downData } = this;
522
- const { path, throughPath } = downData;
554
+ const {interaction: interaction, dragData: dragData, downData: downData} = this;
555
+ const {path: path, throughPath: throughPath} = downData;
523
556
  this.dragData = getDragEventData(downData, dragData, data);
524
- if (throughPath)
525
- this.dragData.throughPath = throughPath;
557
+ if (throughPath) this.dragData.throughPath = throughPath;
526
558
  this.dragData.path = path;
527
559
  if (this.moving) {
528
- this.dragData.moveType = 'drag';
560
+ this.dragData.moveType = "drag";
529
561
  interaction.emit(MoveEvent.BEFORE_MOVE, this.dragData);
530
562
  interaction.emit(MoveEvent.MOVE, this.dragData);
531
- }
532
- else if (this.dragging) {
563
+ } else if (this.dragging) {
533
564
  this.dragReal();
534
565
  interaction.emit(DragEvent.BEFORE_DRAG, this.dragData);
535
566
  interaction.emit(DragEvent.DRAG, this.dragData);
536
567
  }
537
568
  }
538
- dragReal() {
539
- const { running } = this.interaction;
569
+ dragReal(isDragEnd) {
570
+ const {interaction: interaction} = this, {running: running} = interaction;
540
571
  const list = this.realDraggableList;
541
572
  if (list.length && running) {
542
- const { totalX, totalY } = this.dragData;
543
- list.forEach(leaf => leaf.draggable && leaf.move(DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
573
+ const {totalX: totalX, totalY: totalY} = this.dragData, {dragLimitAnimate: dragLimitAnimate} = interaction.p;
574
+ const checkLimitMove = !dragLimitAnimate || !!isDragEnd;
575
+ list.forEach(leaf => {
576
+ if (leaf.draggable) {
577
+ const move = DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], {
578
+ x: totalX,
579
+ y: totalY
580
+ }, checkLimitMove);
581
+ if (dragLimitAnimate && isDragEnd) LeafHelper.animateMove(leaf, move, isNumber(dragLimitAnimate) ? dragLimitAnimate : .3); else leaf.move(move);
582
+ }
583
+ });
544
584
  }
545
585
  }
546
586
  dragOverOrOut(data) {
547
- const { interaction } = this;
548
- const { dragOverPath } = this;
549
- const { path } = data;
587
+ const {interaction: interaction} = this;
588
+ const {dragOverPath: dragOverPath} = this;
589
+ const {path: path} = data;
550
590
  this.dragOverPath = path;
551
591
  if (dragOverPath) {
552
592
  if (path.indexAt(0) !== dragOverPath.indexAt(0)) {
553
593
  interaction.emit(DragEvent.OUT, data, dragOverPath);
554
594
  interaction.emit(DragEvent.OVER, data, path);
555
595
  }
556
- }
557
- else
558
- interaction.emit(DragEvent.OVER, data, path);
596
+ } else interaction.emit(DragEvent.OVER, data, path);
559
597
  }
560
598
  dragEnterOrLeave(data) {
561
- const { interaction } = this;
562
- const { dragEnterPath } = this;
563
- const { path } = data;
599
+ const {interaction: interaction} = this;
600
+ const {dragEnterPath: dragEnterPath} = this;
601
+ const {path: path} = data;
564
602
  interaction.emit(DragEvent.LEAVE, data, dragEnterPath, path);
565
603
  interaction.emit(DragEvent.ENTER, data, path, dragEnterPath);
566
604
  this.dragEnterPath = path;
567
605
  }
568
606
  dragEnd(data, speed) {
569
- if (!this.dragging && !this.moving)
570
- return;
571
- if (this.checkDragEndAnimate(data, speed))
572
- return;
607
+ if (!this.dragging && !this.moving) return;
608
+ if (this.checkDragEndAnimate(data, speed)) return;
573
609
  this.dragEndReal(data);
574
610
  }
575
611
  dragEndReal(data) {
576
- const { interaction, downData, dragData } = this;
577
- if (!data)
578
- data = dragData;
579
- const { path, throughPath } = downData;
612
+ const {interaction: interaction, downData: downData, dragData: dragData} = this;
613
+ if (!data) data = dragData;
614
+ const {path: path, throughPath: throughPath} = downData;
580
615
  const endDragData = getDragEventData(downData, data, data);
581
- if (throughPath)
582
- endDragData.throughPath = throughPath;
616
+ if (throughPath) endDragData.throughPath = throughPath;
583
617
  endDragData.path = path;
584
618
  if (this.moving) {
585
619
  this.moving = false;
586
- endDragData.moveType = 'drag';
620
+ endDragData.moveType = "drag";
587
621
  interaction.emit(MoveEvent.END, endDragData);
588
622
  }
589
623
  if (this.dragging) {
590
624
  const dropList = this.getList();
591
625
  this.dragging = false;
626
+ if (interaction.p.dragLimitAnimate) this.dragReal(true);
592
627
  interaction.emit(DragEvent.END, endDragData);
593
628
  this.swipe(data, downData, dragData, endDragData);
594
629
  this.drop(data, dropList, this.dragEnterPath);
595
630
  }
596
631
  this.autoMoveCancel();
597
632
  this.dragReset();
598
- this.animate(null, 'off');
633
+ this.animate(null, "off");
599
634
  }
600
635
  swipe(data, downData, dragData, endDragData) {
601
- const { interaction } = this;
636
+ const {interaction: interaction} = this;
602
637
  if (PointHelper.getDistance(downData, data) > interaction.config.pointer.swipeDistance) {
603
638
  const swipeData = getSwipeEventData(downData, dragData, endDragData);
604
639
  this.interaction.emit(swipeData.type, swipeData);
@@ -613,89 +648,90 @@ class Dragger {
613
648
  dragReset() {
614
649
  DragEvent.list = DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
615
650
  }
616
- checkDragEndAnimate(_data, _speed) { return false; }
617
- animate(_func, _off) { }
618
- checkDragOut(_data) { }
619
- autoMoveOnDragOut(_data) { }
620
- autoMoveCancel() { }
651
+ checkDragEndAnimate(_data, _speed) {
652
+ return false;
653
+ }
654
+ animate(_func, _off) {}
655
+ checkDragOut(_data) {}
656
+ autoMoveOnDragOut(_data) {}
657
+ autoMoveCancel() {}
621
658
  destroy() {
622
659
  this.dragReset();
623
660
  }
624
661
  }
625
662
 
626
- const debug = Debug.get('emit');
663
+ const debug = Debug.get("emit");
664
+
627
665
  function emit(type, data, path, excludePath) {
628
- if (!path && !data.path)
629
- return;
666
+ if (!path && !data.path) return;
630
667
  let leaf;
631
668
  data.type = type;
632
669
  if (path) {
633
- data = Object.assign(Object.assign({}, data), { path });
634
- }
635
- else {
670
+ data = Object.assign(Object.assign({}, data), {
671
+ path: path
672
+ });
673
+ } else {
636
674
  path = data.path;
637
675
  }
638
676
  data.target = path.indexAt(0);
639
677
  try {
640
678
  for (let i = path.length - 1; i > -1; i--) {
641
679
  leaf = path.list[i];
642
- if (emitEvent(leaf, type, data, true, excludePath))
643
- return;
644
- if (leaf.isApp)
645
- emitAppChildren(leaf, type, data, true, excludePath);
680
+ if (emitEvent(leaf, type, data, true, excludePath)) return;
681
+ if (leaf.isApp) emitAppChildren(leaf, type, data, true, excludePath);
646
682
  }
647
683
  for (let i = 0, len = path.length; i < len; i++) {
648
684
  leaf = path.list[i];
649
- if (leaf.isApp)
650
- emitAppChildren(leaf, type, data, false, excludePath);
651
- if (emitEvent(leaf, type, data, false, excludePath))
652
- return;
685
+ if (leaf.isApp) emitAppChildren(leaf, type, data, false, excludePath);
686
+ if (emitEvent(leaf, type, data, false, excludePath)) return;
653
687
  }
654
- }
655
- catch (e) {
688
+ } catch (e) {
656
689
  debug.error(e);
657
690
  }
658
691
  }
659
- const allowTypes = ['move', 'zoom', 'rotate', 'key'];
692
+
693
+ const allowTypes = [ "move", "zoom", "rotate", "key" ];
694
+
660
695
  function emitAppChildren(leaf, type, data, capture, excludePath) {
661
696
  if (allowTypes.some(name => type.startsWith(name)) && leaf.__.hitChildren && !exclude(leaf, excludePath)) {
662
697
  let child;
663
698
  for (let i = 0, len = leaf.children.length; i < len; i++) {
664
699
  child = leaf.children[i];
665
- if (!data.path.has(child) && child.__.hittable)
666
- emitEvent(child, type, data, capture, excludePath);
700
+ if (!data.path.has(child) && child.__.hittable) emitEvent(child, type, data, capture, excludePath);
667
701
  }
668
702
  }
669
703
  }
704
+
670
705
  function emitEvent(leaf, type, data, capture, excludePath) {
671
- if (leaf.destroyed)
672
- return false;
706
+ if (leaf.destroyed) return false;
673
707
  if (leaf.__.hitSelf && !exclude(leaf, excludePath)) {
674
- if (State.updateEventStyle && !capture)
675
- State.updateEventStyle(leaf, type);
708
+ if (State.updateEventStyle && !capture) State.updateEventStyle(leaf, type);
676
709
  if (leaf.hasEvent(type, capture)) {
677
- data.phase = capture ? 1 : ((leaf === data.target) ? 2 : 3);
710
+ data.phase = capture ? 1 : leaf === data.target ? 2 : 3;
678
711
  const event = EventCreator.get(type, data);
679
712
  leaf.emitEvent(event, capture);
680
- if (event.isStop)
681
- return true;
713
+ if (event.isStop) return true;
682
714
  }
683
715
  }
684
716
  return false;
685
717
  }
718
+
686
719
  function exclude(leaf, excludePath) {
687
720
  return excludePath && excludePath.has(leaf);
688
721
  }
689
722
 
690
723
  const config = {
691
724
  wheel: {
692
- zoomSpeed: 0.5,
693
- moveSpeed: 0.5,
694
- rotateSpeed: 0.5,
695
- delta: { x: 80 / 4, y: 8.0 },
725
+ zoomSpeed: .5,
726
+ moveSpeed: .5,
727
+ rotateSpeed: .5,
728
+ delta: {
729
+ x: 80 / 4,
730
+ y: 8
731
+ }
696
732
  },
697
733
  pointer: {
698
- type: 'pointer',
734
+ type: "pointer",
699
735
  snap: true,
700
736
  hitRadius: 5,
701
737
  tapTime: 120,
@@ -704,32 +740,59 @@ const config = {
704
740
  hover: true,
705
741
  dragHover: true,
706
742
  dragDistance: 2,
707
- swipeDistance: 20,
743
+ swipeDistance: 20
708
744
  },
709
745
  touch: {
710
- preventDefault: 'auto'
746
+ preventDefault: "auto"
711
747
  },
712
748
  multiTouch: {},
713
- move: { autoDistance: 2 },
749
+ move: {
750
+ autoDistance: 2
751
+ },
714
752
  zoom: {},
715
753
  cursor: true,
716
754
  keyEvent: true
717
755
  };
718
756
 
719
- const { pathHasEventType, pathCanDrag, pathHasOutside } = InteractionHelper;
757
+ const {pathHasEventType: pathHasEventType, pathCanDrag: pathCanDrag, pathHasOutside: pathHasOutside} = InteractionHelper;
758
+
720
759
  class InteractionBase {
721
- get dragging() { return this.dragger.dragging; }
722
- get transforming() { return this.transformer.transforming; }
723
- get moveMode() { return this.m.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
724
- get canHover() { return this.p.hover && !this.config.mobile; }
725
- get isDragEmpty() { return this.m.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)); }
726
- get isMobileDragEmpty() { return this.m.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData); }
727
- get isHoldMiddleKey() { return this.m.holdMiddleKey && this.downData && PointerButton.middle(this.downData); }
728
- get isHoldRightKey() { return this.m.holdRightKey && this.downData && PointerButton.right(this.downData); }
729
- get isHoldSpaceKey() { return this.m.holdSpaceKey && Keyboard.isHoldSpaceKey(); }
730
- get m() { return this.config.move; }
731
- get p() { return this.config.pointer; }
732
- get hitRadius() { return this.p.hitRadius; }
760
+ get dragging() {
761
+ return this.dragger.dragging;
762
+ }
763
+ get transforming() {
764
+ return this.transformer.transforming;
765
+ }
766
+ get moveMode() {
767
+ return this.m.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || this.isHoldRightKey && this.dragger.moving || this.isDragEmpty;
768
+ }
769
+ get canHover() {
770
+ return this.p.hover && !this.config.mobile;
771
+ }
772
+ get isDragEmpty() {
773
+ return this.m.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData));
774
+ }
775
+ get isMobileDragEmpty() {
776
+ return this.m.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData);
777
+ }
778
+ get isHoldMiddleKey() {
779
+ return this.m.holdMiddleKey && this.downData && PointerButton.middle(this.downData);
780
+ }
781
+ get isHoldRightKey() {
782
+ return this.m.holdRightKey && this.downData && PointerButton.right(this.downData);
783
+ }
784
+ get isHoldSpaceKey() {
785
+ return this.m.holdSpaceKey && Keyboard.isHoldSpaceKey();
786
+ }
787
+ get m() {
788
+ return this.config.move;
789
+ }
790
+ get p() {
791
+ return this.config.pointer;
792
+ }
793
+ get hitRadius() {
794
+ return this.p.hitRadius;
795
+ }
733
796
  constructor(target, canvas, selector, userConfig) {
734
797
  this.config = DataHelper.clone(config);
735
798
  this.tapCount = 0;
@@ -740,8 +803,7 @@ class InteractionBase {
740
803
  this.defaultPath = new LeafList(target);
741
804
  this.createTransformer();
742
805
  this.dragger = new Dragger(this);
743
- if (userConfig)
744
- this.config = DataHelper.default(userConfig, this.config);
806
+ if (userConfig) this.config = DataHelper.default(userConfig, this.config);
745
807
  this.__listenEvents();
746
808
  }
747
809
  start() {
@@ -750,12 +812,10 @@ class InteractionBase {
750
812
  stop() {
751
813
  this.running = false;
752
814
  }
753
- receive(_event) { }
815
+ receive(_event) {}
754
816
  pointerDown(data, useDefaultPath) {
755
- if (!data)
756
- data = this.hoverData;
757
- if (!data)
758
- return;
817
+ if (!data) data = this.hoverData;
818
+ if (!data) return;
759
819
  PointerButton.defaultLeft(data);
760
820
  this.updateDownData(data);
761
821
  this.checkPath(data, useDefaultPath);
@@ -768,22 +828,17 @@ class InteractionBase {
768
828
  }
769
829
  this.waitRightTap = PointerButton.right(data);
770
830
  this.dragger.setDragData(data);
771
- if (!this.isHoldRightKey)
772
- this.updateCursor(data);
831
+ if (!this.isHoldRightKey) this.updateCursor(data);
773
832
  }
774
833
  pointerMove(data) {
775
- if (!data)
776
- data = this.hoverData;
777
- if (!data)
778
- return;
779
- const { downData } = this;
780
- if (downData)
781
- PointerButton.defaultLeft(data);
834
+ if (!data) data = this.hoverData;
835
+ if (!data) return;
836
+ const {downData: downData} = this;
837
+ if (downData) PointerButton.defaultLeft(data);
782
838
  const hit = this.canvas.bounds.hitPoint(data);
783
839
  if (hit || downData) {
784
840
  this.pointerMoveReal(data);
785
- if (downData)
786
- this.dragger.checkDragOut(data);
841
+ if (downData) this.dragger.checkDragOut(data);
787
842
  }
788
843
  }
789
844
  pointerMoveReal(data) {
@@ -809,15 +864,15 @@ class InteractionBase {
809
864
  this.updateCursor(this.downData || data);
810
865
  }
811
866
  pointerUp(data) {
812
- const { downData } = this;
813
- if (!data)
814
- data = downData;
815
- if (!downData)
816
- return;
867
+ const {downData: downData} = this;
868
+ if (!data) data = downData;
869
+ if (!downData) return;
817
870
  PointerButton.defaultLeft(data);
818
871
  data.multiTouch = downData.multiTouch;
819
872
  this.findPath(data);
820
- const upData = Object.assign(Object.assign({}, data), { path: data.path.clone() });
873
+ const upData = Object.assign(Object.assign({}, data), {
874
+ path: data.path.clone()
875
+ });
821
876
  data.path.addList(downData.path.list);
822
877
  this.checkPath(data);
823
878
  this.downData = null;
@@ -840,8 +895,7 @@ class InteractionBase {
840
895
  this.findPath(data);
841
896
  this.emit(PointerEvent.MENU, data);
842
897
  this.waitMenuTap = true;
843
- if (!this.downData && this.waitRightTap)
844
- this.menuTap(data);
898
+ if (!this.downData && this.waitRightTap) this.menuTap(data);
845
899
  }
846
900
  menuTap(data) {
847
901
  if (this.waitRightTap && this.waitMenuTap) {
@@ -849,17 +903,17 @@ class InteractionBase {
849
903
  this.waitRightTap = this.waitMenuTap = false;
850
904
  }
851
905
  }
852
- createTransformer() { }
853
- move(_data) { }
854
- zoom(_data) { }
855
- rotate(_data) { }
856
- transformEnd() { }
857
- wheel(_data) { }
858
- multiTouch(_data, _list) { }
906
+ createTransformer() {}
907
+ move(_data) {}
908
+ zoom(_data) {}
909
+ rotate(_data) {}
910
+ transformEnd() {}
911
+ wheel(_data) {}
912
+ multiTouch(_data, _list) {}
859
913
  keyDown(data) {
860
- if (!this.config.keyEvent)
861
- return;
862
- const { code } = data;
914
+ if (!this.config.keyEvent) return;
915
+ this.emit(KeyEvent.BEFORE_DOWN, data, this.defaultPath);
916
+ const {code: code} = data;
863
917
  if (!this.downKeyMap[code]) {
864
918
  this.downKeyMap[code] = true;
865
919
  Keyboard.setDownCode(code);
@@ -872,74 +926,67 @@ class InteractionBase {
872
926
  this.emit(KeyEvent.DOWN, data, this.defaultPath);
873
927
  }
874
928
  keyUp(data) {
875
- if (!this.config.keyEvent)
876
- return;
877
- const { code } = data;
929
+ if (!this.config.keyEvent) return;
930
+ this.emit(KeyEvent.BEFORE_UP, data, this.defaultPath);
931
+ const {code: code} = data;
878
932
  this.downKeyMap[code] = false;
879
933
  Keyboard.setUpCode(code);
880
934
  this.emit(KeyEvent.UP, data, this.defaultPath);
881
- if (this.cursor === 'grab')
882
- this.updateCursor();
935
+ if (this.cursor === "grab") this.updateCursor();
883
936
  }
884
937
  pointerHover(data) {
885
938
  if (this.canHover && !(this.dragging && !this.p.dragHover)) {
886
- data.path || (data.path = new LeafList());
939
+ data.path || (data.path = new LeafList);
887
940
  this.pointerOverOrOut(data);
888
941
  this.pointerEnterOrLeave(data);
889
942
  }
890
943
  }
891
944
  pointerOverOrOut(data) {
892
- const { path } = data;
893
- const { overPath } = this;
945
+ const {path: path} = data;
946
+ const {overPath: overPath} = this;
894
947
  this.overPath = path;
895
948
  if (overPath) {
896
949
  if (path.indexAt(0) !== overPath.indexAt(0)) {
897
950
  this.emit(PointerEvent.OUT, data, overPath);
898
951
  this.emit(PointerEvent.OVER, data, path);
899
952
  }
900
- }
901
- else {
953
+ } else {
902
954
  this.emit(PointerEvent.OVER, data, path);
903
955
  }
904
956
  }
905
957
  pointerEnterOrLeave(data) {
906
- let { path } = data;
958
+ let {path: path} = data;
907
959
  if (this.downData && !this.moveMode) {
908
960
  path = path.clone();
909
961
  this.downData.path.forEach(leaf => path.add(leaf));
910
962
  }
911
- const { enterPath } = this;
963
+ const {enterPath: enterPath} = this;
912
964
  this.enterPath = path;
913
965
  this.emit(PointerEvent.LEAVE, data, enterPath, path);
914
966
  this.emit(PointerEvent.ENTER, data, path, enterPath);
915
967
  }
916
968
  touchLeave(data) {
917
- if (data.pointerType === 'touch') {
969
+ if (data.pointerType === "touch") {
918
970
  if (this.enterPath) {
919
971
  this.emit(PointerEvent.LEAVE, data);
920
- if (this.dragger.dragging)
921
- this.emit(DropEvent.LEAVE, data);
972
+ if (this.dragger.dragging) this.emit(DropEvent.LEAVE, data);
922
973
  }
923
974
  }
924
975
  }
925
976
  tap(data) {
926
- const { pointer } = this.config;
977
+ const {pointer: pointer} = this.config;
927
978
  const hasLong = this.longTap(data);
928
- if (!pointer.tapMore && hasLong)
929
- return;
930
- if (!this.waitTap)
931
- return;
932
- if (pointer.tapMore)
933
- this.emitTap(data);
979
+ if (!pointer.tapMore && hasLong) return;
980
+ if (!this.waitTap) return;
981
+ if (pointer.tapMore) this.emitTap(data);
934
982
  const useTime = Date.now() - this.downTime;
935
- const hasDouble = [PointerEvent.DOUBLE_TAP, PointerEvent.DOUBLE_CLICK].some(type => pathHasEventType(data.path, type));
983
+ const hasDouble = [ PointerEvent.DOUBLE_TAP, PointerEvent.DOUBLE_CLICK ].some(type => pathHasEventType(data.path, type));
936
984
  if (useTime < pointer.tapTime + 50 && hasDouble) {
937
985
  this.tapCount++;
938
986
  if (this.tapCount === 2) {
939
987
  this.tapWaitCancel();
940
988
  this.emitDoubleTap(data);
941
- }
942
- else {
989
+ } else {
943
990
  clearTimeout(this.tapTimer);
944
991
  this.tapTimer = setTimeout(() => {
945
992
  if (!pointer.tapMore) {
@@ -948,8 +995,7 @@ class InteractionBase {
948
995
  }
949
996
  }, pointer.tapTime);
950
997
  }
951
- }
952
- else {
998
+ } else {
953
999
  if (!pointer.tapMore) {
954
1000
  this.tapWaitCancel();
955
1001
  this.emitTap(data);
@@ -957,13 +1003,16 @@ class InteractionBase {
957
1003
  }
958
1004
  }
959
1005
  findPath(data, options) {
960
- const { hitRadius, through } = this.p;
961
- const { bottomList, target } = this;
962
- if (!Platform.backgrounder && !data.origin)
963
- target && target.updateLayout();
964
- const find = this.selector.getByPoint(data, hitRadius, Object.assign({ bottomList, name: data.type }, (options || { through })));
965
- if (find.throughPath)
966
- data.throughPath = find.throughPath;
1006
+ const {hitRadius: hitRadius, through: through} = this.p;
1007
+ const {bottomList: bottomList, target: target} = this;
1008
+ if (!Platform.backgrounder && !data.origin) target && target.updateLayout();
1009
+ const find = this.selector.getByPoint(data, hitRadius, Object.assign({
1010
+ bottomList: bottomList,
1011
+ name: data.type
1012
+ }, options || {
1013
+ through: through
1014
+ }));
1015
+ if (find.throughPath) data.throughPath = find.throughPath;
967
1016
  data.path = find.path;
968
1017
  return find.path;
969
1018
  }
@@ -972,16 +1021,14 @@ class InteractionBase {
972
1021
  }
973
1022
  isTreePath(data) {
974
1023
  const app = this.target.app;
975
- if (!app || !app.isApp)
976
- return false;
1024
+ if (!app || !app.isApp) return false;
977
1025
  return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
978
1026
  }
979
1027
  checkPath(data, useDefaultPath) {
980
- if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path)))
981
- data.path = this.defaultPath;
1028
+ if (useDefaultPath || this.moveMode && !pathHasOutside(data.path)) data.path = this.defaultPath;
982
1029
  }
983
1030
  canMove(data) {
984
- return data && (this.moveMode || (this.m.drag === 'auto' && !pathCanDrag(data.path))) && !pathHasOutside(data.path);
1031
+ return data && (this.moveMode || this.m.drag === "auto" && !pathCanDrag(data.path)) && !pathHasOutside(data.path);
985
1032
  }
986
1033
  isDrag(leaf) {
987
1034
  return this.dragger.getList().has(leaf);
@@ -996,53 +1043,46 @@ class InteractionBase {
996
1043
  return this.focusData === leaf;
997
1044
  }
998
1045
  cancelHover() {
999
- const { hoverData } = this;
1046
+ const {hoverData: hoverData} = this;
1000
1047
  if (hoverData) {
1001
1048
  hoverData.path = this.defaultPath;
1002
1049
  this.pointerHover(hoverData);
1003
1050
  }
1004
1051
  }
1005
1052
  updateDownData(data, options, merge) {
1006
- const { downData } = this;
1007
- if (!data && downData)
1008
- data = downData;
1009
- if (!data)
1010
- return;
1053
+ const {downData: downData} = this;
1054
+ if (!data && downData) data = downData;
1055
+ if (!data) return;
1011
1056
  this.findPath(data, options);
1012
- if (merge && downData)
1013
- data.path.addList(downData.path.list);
1057
+ if (merge && downData) data.path.addList(downData.path.list);
1014
1058
  this.downData = data;
1015
1059
  }
1016
1060
  updateHoverData(data) {
1017
- if (!data)
1018
- data = this.hoverData;
1019
- if (!data)
1020
- return;
1021
- this.findPath(data, { exclude: this.dragger.getList(false, true), name: PointerEvent.MOVE });
1061
+ if (!data) data = this.hoverData;
1062
+ if (!data) return;
1063
+ this.findPath(data, {
1064
+ exclude: this.dragger.getList(false, true),
1065
+ name: PointerEvent.MOVE
1066
+ });
1022
1067
  this.hoverData = data;
1023
1068
  }
1024
1069
  updateCursor(data) {
1025
- if (!this.config.cursor || !this.canHover)
1026
- return;
1070
+ if (!this.config.cursor || !this.canHover) return;
1027
1071
  if (!data) {
1028
1072
  this.updateHoverData();
1029
1073
  data = this.downData || this.hoverData;
1030
1074
  }
1031
1075
  if (this.dragger.moving) {
1032
- return this.setCursor('grabbing');
1033
- }
1034
- else if (this.canMove(data)) {
1035
- return this.setCursor(this.downData ? 'grabbing' : 'grab');
1036
- }
1037
- else if (!data)
1038
- return;
1076
+ return this.setCursor("grabbing");
1077
+ } else if (this.canMove(data)) {
1078
+ return this.setCursor(this.downData ? "grabbing" : "grab");
1079
+ } else if (!data) return;
1039
1080
  let leaf, cursor;
1040
- const { path } = data;
1081
+ const {path: path} = data;
1041
1082
  for (let i = 0, len = path.length; i < len; i++) {
1042
1083
  leaf = path.list[i];
1043
- cursor = (leaf.syncEventer && leaf.syncEventer.cursor) || leaf.cursor;
1044
- if (cursor)
1045
- break;
1084
+ cursor = leaf.syncEventer && leaf.syncEventer.cursor || leaf.cursor;
1085
+ if (cursor) break;
1046
1086
  }
1047
1087
  this.setCursor(cursor);
1048
1088
  }
@@ -1051,9 +1091,14 @@ class InteractionBase {
1051
1091
  }
1052
1092
  getLocal(clientPoint, updateClient) {
1053
1093
  const clientBounds = this.canvas.getClientBounds(updateClient);
1054
- const point = { x: clientPoint.clientX - clientBounds.x, y: clientPoint.clientY - clientBounds.y };
1055
- if (this.p.snap)
1056
- PointHelper.round(point);
1094
+ const point = {
1095
+ x: clientPoint.clientX - clientBounds.x,
1096
+ y: clientPoint.clientY - clientBounds.y
1097
+ };
1098
+ const {bounds: bounds} = this.canvas;
1099
+ point.x *= bounds.width / clientBounds.width;
1100
+ point.y *= bounds.height / clientBounds.height;
1101
+ if (this.p.snap) PointHelper.round(point);
1057
1102
  return point;
1058
1103
  }
1059
1104
  emitTap(data) {
@@ -1090,8 +1135,7 @@ class InteractionBase {
1090
1135
  let hasLong;
1091
1136
  if (this.longPressed) {
1092
1137
  this.emit(PointerEvent.LONG_TAP, data);
1093
- if (pathHasEventType(data.path, PointerEvent.LONG_TAP) || pathHasEventType(data.path, PointerEvent.LONG_PRESS))
1094
- hasLong = true;
1138
+ if (pathHasEventType(data.path, PointerEvent.LONG_TAP) || pathHasEventType(data.path, PointerEvent.LONG_PRESS)) hasLong = true;
1095
1139
  }
1096
1140
  this.longPressWaitCancel();
1097
1141
  return hasLong;
@@ -1103,13 +1147,13 @@ class InteractionBase {
1103
1147
  }
1104
1148
  }
1105
1149
  __onResize() {
1106
- const { dragOut } = this.m;
1150
+ const {dragOut: dragOut} = this.m;
1107
1151
  this.shrinkCanvasBounds = new Bounds(this.canvas.bounds);
1108
- this.shrinkCanvasBounds.spread(-(typeof dragOut === 'number' ? dragOut : 2));
1152
+ this.shrinkCanvasBounds.spread(-(isNumber(dragOut) ? dragOut : 2));
1109
1153
  }
1110
1154
  __listenEvents() {
1111
- const { target } = this;
1112
- this.__eventIds = [target.on_(ResizeEvent.RESIZE, this.__onResize, this)];
1155
+ const {target: target} = this;
1156
+ this.__eventIds = [ target.on_(ResizeEvent.RESIZE, this.__onResize, this) ];
1113
1157
  target.once(LeaferEvent.READY, () => this.__onResize());
1114
1158
  }
1115
1159
  __removeListenEvents() {
@@ -1117,16 +1161,14 @@ class InteractionBase {
1117
1161
  this.__eventIds.length = 0;
1118
1162
  }
1119
1163
  emit(type, data, path, excludePath) {
1120
- if (this.running)
1121
- emit(type, data, path, excludePath);
1164
+ if (this.running) emit(type, data, path, excludePath);
1122
1165
  }
1123
1166
  destroy() {
1124
1167
  if (this.__eventIds.length) {
1125
1168
  this.stop();
1126
1169
  this.__removeListenEvents();
1127
1170
  this.dragger.destroy();
1128
- if (this.transformer)
1129
- this.transformer.destroy();
1171
+ if (this.transformer) this.transformer.destroy();
1130
1172
  this.downData = this.overPath = this.enterPath = null;
1131
1173
  }
1132
1174
  }
@@ -1140,14 +1182,15 @@ class Cursor {
1140
1182
  return this.custom[name];
1141
1183
  }
1142
1184
  }
1185
+
1143
1186
  Cursor.custom = {};
1144
1187
 
1145
1188
  class HitCanvasManager extends CanvasManager {
1146
1189
  constructor() {
1147
1190
  super(...arguments);
1148
- this.maxTotal = 1000;
1149
- this.pathList = new LeafList();
1150
- this.pixelList = new LeafList();
1191
+ this.maxTotal = 1e3;
1192
+ this.pathList = new LeafList;
1193
+ this.pixelList = new LeafList;
1151
1194
  }
1152
1195
  getPixelType(leaf, config) {
1153
1196
  this.__autoClear();
@@ -1177,8 +1220,7 @@ class HitCanvasManager extends CanvasManager {
1177
1220
  }
1178
1221
  }
1179
1222
  __autoClear() {
1180
- if (this.pathList.length + this.pixelList.length > this.maxTotal)
1181
- this.clear();
1223
+ if (this.pathList.length + this.pixelList.length > this.maxTotal) this.clear();
1182
1224
  }
1183
1225
  clear() {
1184
1226
  this.clearPathType();
@@ -1186,13 +1228,32 @@ class HitCanvasManager extends CanvasManager {
1186
1228
  }
1187
1229
  }
1188
1230
 
1189
- const { toInnerRadiusPointOf, copy, setRadius } = PointHelper;
1190
- const inner = {};
1231
+ Platform.getSelector = function(leaf) {
1232
+ return leaf.leafer ? leaf.leafer.selector : Platform.selector || (Platform.selector = Creator.selector());
1233
+ };
1234
+
1235
+ const {toInnerRadiusPointOf: toInnerRadiusPointOf, copy: copy, setRadius: setRadius} = PointHelper;
1236
+
1237
+ const {hitRadiusPoint: hitRadiusPoint, hitPoint: hitPoint} = BoundsHelper;
1238
+
1239
+ const inner = {}, worldRadiusPoint = {};
1240
+
1191
1241
  const leaf = Leaf.prototype;
1192
- leaf.__hitWorld = function (point) {
1242
+
1243
+ leaf.hit = function(worldPoint, hitRadius = 0) {
1244
+ this.updateLayout();
1245
+ copy(worldRadiusPoint, worldPoint);
1246
+ setRadius(worldRadiusPoint, hitRadius);
1247
+ const world = this.__world;
1248
+ if (hitRadius ? !hitRadiusPoint(world, worldRadiusPoint) : !hitPoint(world, worldRadiusPoint)) return false;
1249
+ return this.isBranch ? Platform.getSelector(this).hitPoint(Object.assign({}, worldRadiusPoint), hitRadius, {
1250
+ target: this
1251
+ }) : this.__hitWorld(worldRadiusPoint);
1252
+ };
1253
+
1254
+ leaf.__hitWorld = function(point) {
1193
1255
  const data = this.__;
1194
- if (!data.hitSelf)
1195
- return false;
1256
+ if (!data.hitSelf) return false;
1196
1257
  const world = this.__world, layout = this.__layout;
1197
1258
  const isSmall = world.width < 10 && world.height < 10;
1198
1259
  if (data.hitRadius) {
@@ -1201,141 +1262,158 @@ leaf.__hitWorld = function (point) {
1201
1262
  }
1202
1263
  toInnerRadiusPointOf(point, world, inner);
1203
1264
  if (data.hitBox || isSmall) {
1204
- if (BoundsHelper.hitRadiusPoint(layout.boxBounds, inner))
1205
- return true;
1206
- if (isSmall)
1207
- return false;
1265
+ if (BoundsHelper.hitRadiusPoint(layout.boxBounds, inner)) return true;
1266
+ if (isSmall) return false;
1208
1267
  }
1209
1268
  if (layout.hitCanvasChanged || !this.__hitCanvas) {
1210
1269
  this.__updateHitCanvas();
1211
- if (!layout.boundsChanged)
1212
- layout.hitCanvasChanged = false;
1270
+ if (!layout.boundsChanged) layout.hitCanvasChanged = false;
1213
1271
  }
1214
1272
  return this.__hit(inner);
1215
1273
  };
1216
- leaf.__hitFill = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, this.__.windingRule); };
1217
- leaf.__hitStroke = function (inner, strokeWidth) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth); };
1218
- leaf.__hitPixel = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitPixel(inner, this.__layout.renderBounds, this.__hitCanvas.hitScale); };
1219
- leaf.__drawHitPath = function (canvas) { if (canvas)
1220
- this.__drawRenderPath(canvas); };
1221
1274
 
1222
- const matrix = new Matrix();
1275
+ leaf.__hitFill = function(inner) {
1276
+ const h = this.__hitCanvas;
1277
+ return h && h.hitFill(inner, this.__.windingRule);
1278
+ };
1279
+
1280
+ leaf.__hitStroke = function(inner, strokeWidth) {
1281
+ const h = this.__hitCanvas;
1282
+ return h && h.hitStroke(inner, strokeWidth);
1283
+ };
1284
+
1285
+ leaf.__hitPixel = function(inner) {
1286
+ const h = this.__hitCanvas;
1287
+ return h && h.hitPixel(inner, this.__layout.renderBounds, h.hitScale);
1288
+ };
1289
+
1290
+ leaf.__drawHitPath = function(canvas) {
1291
+ canvas && this.__drawRenderPath(canvas);
1292
+ };
1293
+
1294
+ const matrix = new Matrix;
1295
+
1223
1296
  const ui$1 = UI.prototype;
1224
- ui$1.__updateHitCanvas = function () {
1225
- if (this.__box)
1226
- this.__box.__updateHitCanvas();
1227
- const data = this.__, { hitCanvasManager } = this.leafer || this.parent.leafer;
1228
- const isHitPixelFill = (data.__isAlphaPixelFill || data.__isCanvas) && data.hitFill === 'pixel';
1229
- const isHitPixelStroke = data.__isAlphaPixelStroke && data.hitStroke === 'pixel';
1297
+
1298
+ ui$1.__updateHitCanvas = function() {
1299
+ if (this.__box) this.__box.__updateHitCanvas();
1300
+ const leafer = this.leafer || this.parent && this.parent.leafer;
1301
+ if (!leafer) return;
1302
+ const data = this.__, {hitCanvasManager: hitCanvasManager} = leafer;
1303
+ const isHitPixelFill = (data.__isAlphaPixelFill || data.__isCanvas) && data.hitFill === "pixel";
1304
+ const isHitPixelStroke = data.__isAlphaPixelStroke && data.hitStroke === "pixel";
1230
1305
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
1231
- if (!this.__hitCanvas)
1232
- this.__hitCanvas = isHitPixel ? hitCanvasManager.getPixelType(this, { contextSettings: { willReadFrequently: true } }) : hitCanvasManager.getPathType(this);
1306
+ if (!this.__hitCanvas) this.__hitCanvas = isHitPixel ? hitCanvasManager.getPixelType(this, {
1307
+ contextSettings: {
1308
+ willReadFrequently: true
1309
+ }
1310
+ }) : hitCanvasManager.getPathType(this);
1233
1311
  const h = this.__hitCanvas;
1234
1312
  if (isHitPixel) {
1235
- const { renderBounds } = this.__layout;
1313
+ const {renderBounds: renderBounds} = this.__layout;
1236
1314
  const size = Platform.image.hitCanvasSize;
1237
1315
  const scale = h.hitScale = tempBounds.set(0, 0, size, size).getFitMatrix(renderBounds).a;
1238
- const { x, y, width, height } = tempBounds.set(renderBounds).scale(scale);
1239
- h.resize({ width, height, pixelRatio: 1 });
1316
+ const {x: x, y: y, width: width, height: height} = tempBounds.set(renderBounds).scale(scale);
1317
+ h.resize({
1318
+ width: width,
1319
+ height: height,
1320
+ pixelRatio: 1
1321
+ });
1240
1322
  h.clear();
1241
1323
  ImageManager.patternLocked = true;
1242
- this.__renderShape(h, { matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y), ignoreFill: !isHitPixelFill, ignoreStroke: !isHitPixelStroke });
1324
+ this.__renderShape(h, {
1325
+ matrix: matrix.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y),
1326
+ ignoreFill: !isHitPixelFill,
1327
+ ignoreStroke: !isHitPixelStroke
1328
+ });
1243
1329
  ImageManager.patternLocked = false;
1244
1330
  h.resetTransform();
1245
1331
  data.__isHitPixel = true;
1246
- }
1247
- else {
1332
+ } else {
1248
1333
  data.__isHitPixel && (data.__isHitPixel = false);
1249
1334
  }
1250
1335
  this.__drawHitPath(h);
1251
1336
  h.setStrokeOptions(data);
1252
1337
  };
1253
- ui$1.__hit = function (inner) {
1254
- if (this.__box && this.__box.__hit(inner))
1255
- return true;
1338
+
1339
+ ui$1.__hit = function(inner) {
1340
+ if (this.__box && this.__box.__hit(inner)) return true;
1256
1341
  const data = this.__;
1257
- if (data.__isHitPixel && this.__hitPixel(inner))
1258
- return true;
1259
- const { hitFill } = data;
1260
- const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__isAlphaPixelFill || data.__isCanvas)))) || hitFill === 'all';
1261
- if (needHitFillPath && this.__hitFill(inner))
1262
- return true;
1263
- const { hitStroke, __strokeWidth } = data;
1264
- const needHitStrokePath = (data.stroke && (hitStroke === 'path' || (hitStroke === 'pixel' && !data.__isAlphaPixelStroke))) || hitStroke === 'all';
1265
- if (!needHitFillPath && !needHitStrokePath)
1266
- return false;
1342
+ if (data.__isHitPixel && this.__hitPixel(inner)) return true;
1343
+ const {hitFill: hitFill} = data;
1344
+ const needHitFillPath = (data.fill || data.__isCanvas) && (hitFill === "path" || hitFill === "pixel" && !(data.__isAlphaPixelFill || data.__isCanvas)) || hitFill === "all";
1345
+ if (needHitFillPath && this.__hitFill(inner)) return true;
1346
+ const {hitStroke: hitStroke, __maxStrokeWidth: strokeWidth} = data;
1347
+ const needHitStrokePath = data.stroke && (hitStroke === "path" || hitStroke === "pixel" && !data.__isAlphaPixelStroke) || hitStroke === "all";
1348
+ if (!needHitFillPath && !needHitStrokePath) return false;
1267
1349
  const radiusWidth = inner.radiusX * 2;
1268
1350
  let hitWidth = radiusWidth;
1269
1351
  if (needHitStrokePath) {
1270
1352
  switch (data.strokeAlign) {
1271
- case 'inside':
1272
- hitWidth += __strokeWidth * 2;
1273
- if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth))
1274
- return true;
1353
+ case "inside":
1354
+ hitWidth += strokeWidth * 2;
1355
+ if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth)) return true;
1356
+ hitWidth = radiusWidth;
1357
+ break;
1358
+
1359
+ case "center":
1360
+ hitWidth += strokeWidth;
1361
+ break;
1362
+
1363
+ case "outside":
1364
+ hitWidth += strokeWidth * 2;
1365
+ if (!needHitFillPath) {
1366
+ if (!this.__hitFill(inner) && this.__hitStroke(inner, hitWidth)) return true;
1275
1367
  hitWidth = radiusWidth;
1276
- break;
1277
- case 'center':
1278
- hitWidth += __strokeWidth;
1279
- break;
1280
- case 'outside':
1281
- hitWidth += __strokeWidth * 2;
1282
- if (!needHitFillPath) {
1283
- if (!this.__hitFill(inner) && this.__hitStroke(inner, hitWidth))
1284
- return true;
1285
- hitWidth = radiusWidth;
1286
- }
1287
- break;
1368
+ }
1369
+ break;
1288
1370
  }
1289
1371
  }
1290
1372
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
1291
1373
  };
1292
1374
 
1293
1375
  const ui = UI.prototype, rect = Rect.prototype, box = Box.prototype;
1294
- rect.__updateHitCanvas = box.__updateHitCanvas = function () {
1295
- if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
1296
- ui.__updateHitCanvas.call(this);
1297
- else if (this.__hitCanvas)
1298
- this.__hitCanvas = null;
1376
+
1377
+ rect.__updateHitCanvas = box.__updateHitCanvas = function() {
1378
+ if (this.stroke || this.cornerRadius || (this.fill || this.__.__isCanvas) && this.hitFill === "pixel" || this.hitStroke === "all") ui.__updateHitCanvas.call(this); else if (this.__hitCanvas) this.__hitCanvas = null;
1299
1379
  };
1300
- rect.__hitFill = box.__hitFill = function (inner) {
1380
+
1381
+ rect.__hitFill = box.__hitFill = function(inner) {
1301
1382
  return this.__hitCanvas ? ui.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
1302
1383
  };
1303
1384
 
1304
- Text.prototype.__drawHitPath = function (canvas) {
1305
- const { __lineHeight, fontSize, __baseLine, __letterSpacing, __textDrawData: data } = this.__;
1385
+ Text.prototype.__drawHitPath = function(canvas) {
1386
+ const {__lineHeight: __lineHeight, fontSize: fontSize, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __textDrawData: data} = this.__;
1306
1387
  canvas.beginPath();
1307
- if (__letterSpacing < 0)
1308
- this.__drawPathByBox(canvas);
1309
- else
1310
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
1388
+ if (__letterSpacing < 0) this.__drawPathByBox(canvas); else data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
1311
1389
  };
1312
1390
 
1313
- function getSelector(ui) {
1314
- return ui.leafer ? ui.leafer.selector : (Platform.selector || (Platform.selector = Creator.selector()));
1315
- }
1316
- Group.prototype.pick = function (hitPoint, options) {
1391
+ Group.prototype.pick = function(hitPoint, options) {
1317
1392
  options || (options = emptyData);
1318
1393
  this.updateLayout();
1319
- return getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), { target: this }));
1394
+ return Platform.getSelector(this).getByPoint(hitPoint, options.hitRadius || 0, Object.assign(Object.assign({}, options), {
1395
+ target: this
1396
+ }));
1320
1397
  };
1321
1398
 
1322
1399
  const canvas = LeaferCanvasBase.prototype;
1323
- canvas.hitFill = function (point, fillRule) {
1400
+
1401
+ canvas.hitFill = function(point, fillRule) {
1324
1402
  return fillRule ? this.context.isPointInPath(point.x, point.y, fillRule) : this.context.isPointInPath(point.x, point.y);
1325
1403
  };
1326
- canvas.hitStroke = function (point, strokeWidth) {
1404
+
1405
+ canvas.hitStroke = function(point, strokeWidth) {
1327
1406
  this.strokeWidth = strokeWidth;
1328
1407
  return this.context.isPointInStroke(point.x, point.y);
1329
1408
  };
1330
- canvas.hitPixel = function (radiusPoint, offset, scale = 1) {
1331
- let { x, y, radiusX, radiusY } = radiusPoint;
1332
- if (offset)
1333
- x -= offset.x, y -= offset.y;
1409
+
1410
+ canvas.hitPixel = function(radiusPoint, offset, scale = 1) {
1411
+ let {x: x, y: y, radiusX: radiusX, radiusY: radiusY} = radiusPoint;
1412
+ if (offset) x -= offset.x, y -= offset.y;
1334
1413
  tempBounds.set(x - radiusX, y - radiusY, radiusX * 2, radiusY * 2).scale(scale).ceil();
1335
- const { data } = this.context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width || 1, tempBounds.height || 1);
1414
+ const {data: data} = this.context.getImageData(tempBounds.x, tempBounds.y, tempBounds.width || 1, tempBounds.height || 1);
1336
1415
  for (let i = 0, len = data.length; i < len; i += 4) {
1337
- if (data[i + 3] > 0)
1338
- return true;
1416
+ if (data[i + 3] > 0) return true;
1339
1417
  }
1340
1418
  return data[3] > 0;
1341
1419
  };