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