@leafer-ui/worker 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/worker.js CHANGED
@@ -1414,14 +1414,14 @@ var LeaferUI = (function (exports) {
1414
1414
  list: {},
1415
1415
  register(UI) {
1416
1416
  const { __tag: tag } = UI.prototype;
1417
- if (list$2[tag])
1417
+ if (list$1[tag])
1418
1418
  debug$e.repeat(tag);
1419
- list$2[tag] = UI;
1419
+ list$1[tag] = UI;
1420
1420
  },
1421
1421
  get(tag, data, x, y, width, height) {
1422
- if (!list$2[tag])
1422
+ if (!list$1[tag])
1423
1423
  debug$e.error('not register ' + tag);
1424
- const ui = new list$2[tag](data);
1424
+ const ui = new list$1[tag](data);
1425
1425
  if (x !== undefined) {
1426
1426
  ui.x = x;
1427
1427
  if (y)
@@ -1434,7 +1434,7 @@ var LeaferUI = (function (exports) {
1434
1434
  return ui;
1435
1435
  }
1436
1436
  };
1437
- const { list: list$2 } = UICreator;
1437
+ const { list: list$1 } = UICreator;
1438
1438
 
1439
1439
  const debug$d = Debug.get('EventCreator');
1440
1440
  const EventCreator = {
@@ -1516,17 +1516,19 @@ var LeaferUI = (function (exports) {
1516
1516
  assign(t, defaultData);
1517
1517
  return t;
1518
1518
  },
1519
- assign(t, merge) {
1519
+ assign(t, merge, exclude) {
1520
1520
  let value;
1521
1521
  Object.keys(merge).forEach(key => {
1522
- var _a;
1522
+ var _a, _b;
1523
1523
  value = merge[key];
1524
- if ((value === null || value === void 0 ? void 0 : value.constructor) === Object) {
1525
- (((_a = t[key]) === null || _a === void 0 ? void 0 : _a.constructor) === Object) ? assign(t[key], merge[key]) : t[key] = merge[key];
1526
- }
1527
- else {
1528
- t[key] = merge[key];
1524
+ if ((value === null || value === void 0 ? void 0 : value.constructor) === Object && ((_a = t[key]) === null || _a === void 0 ? void 0 : _a.constructor) === Object)
1525
+ return assign(t[key], merge[key], exclude && exclude[key]);
1526
+ if (exclude && (key in exclude)) {
1527
+ if (((_b = exclude[key]) === null || _b === void 0 ? void 0 : _b.constructor) === Object)
1528
+ assign(t[key] = {}, merge[key], exclude[key]);
1529
+ return;
1529
1530
  }
1531
+ t[key] = merge[key];
1530
1532
  });
1531
1533
  },
1532
1534
  copyAttrs(t, from, include) {
@@ -3894,6 +3896,8 @@ var LeaferUI = (function (exports) {
3894
3896
  return decorateLeafAttr(defaultValue, (key) => attr({
3895
3897
  set(value) {
3896
3898
  this.__setAttr(key, value) && (this.__layout.opacityChanged || this.__layout.opacityChange());
3899
+ if (this.mask)
3900
+ checkMask(this);
3897
3901
  }
3898
3902
  }));
3899
3903
  }
@@ -3910,9 +3914,20 @@ var LeaferUI = (function (exports) {
3910
3914
  this.__runAnimation('in');
3911
3915
  }
3912
3916
  doVisible(this, key, value, oldValue);
3917
+ if (this.mask)
3918
+ checkMask(this);
3913
3919
  }
3914
3920
  }));
3915
3921
  }
3922
+ function checkMask(leaf) {
3923
+ const { parent } = leaf;
3924
+ if (parent) {
3925
+ const { __hasMask } = parent;
3926
+ parent.__updateMask();
3927
+ if (__hasMask !== parent.__hasMask)
3928
+ parent.forceUpdate();
3929
+ }
3930
+ }
3916
3931
  function doVisible(leaf, key, value, oldValue) {
3917
3932
  if (leaf.__setAttr(key, value)) {
3918
3933
  leaf.__layout.opacityChanged || leaf.__layout.opacityChange();
@@ -4051,11 +4066,11 @@ var LeaferUI = (function (exports) {
4051
4066
  }
4052
4067
 
4053
4068
  const debug$8 = new Debug('rewrite');
4054
- const list$1 = [];
4069
+ const list = [];
4055
4070
  const excludeNames = ['destroy', 'constructor'];
4056
4071
  function rewrite(method) {
4057
4072
  return (target, key) => {
4058
- list$1.push({ name: target.constructor.name + '.' + key, run: () => { target[key] = method; } });
4073
+ list.push({ name: target.constructor.name + '.' + key, run: () => { target[key] = method; } });
4059
4074
  };
4060
4075
  }
4061
4076
  function rewriteAble() {
@@ -4064,13 +4079,13 @@ var LeaferUI = (function (exports) {
4064
4079
  };
4065
4080
  }
4066
4081
  function doRewrite(error) {
4067
- if (list$1.length) {
4068
- list$1.forEach(item => {
4082
+ if (list.length) {
4083
+ list.forEach(item => {
4069
4084
  if (error)
4070
4085
  debug$8.error(item.name, '需在Class上装饰@rewriteAble()');
4071
4086
  item.run();
4072
4087
  });
4073
- list$1.length = 0;
4088
+ list.length = 0;
4074
4089
  }
4075
4090
  }
4076
4091
  setTimeout(() => doRewrite(true));
@@ -5437,8 +5452,8 @@ var LeaferUI = (function (exports) {
5437
5452
  canvas.clearRect(r.x, r.y, r.width, r.height);
5438
5453
  canvas.restore();
5439
5454
  }
5440
- __updateMask(value) {
5441
- this.__hasMask = value ? true : this.children.some(item => item.__.mask);
5455
+ __updateMask(_value) {
5456
+ this.__hasMask = this.children.some(item => item.__.mask && item.__.visible && item.__.opacity);
5442
5457
  }
5443
5458
  __renderMask(_canvas, _options) { }
5444
5459
  __getNowWorld(options) {
@@ -5681,6 +5696,7 @@ var LeaferUI = (function (exports) {
5681
5696
  const { setListWithFn } = BoundsHelper;
5682
5697
  const { sort } = BranchHelper;
5683
5698
  const { localBoxBounds, localStrokeBounds, localRenderBounds, maskLocalBoxBounds, maskLocalStrokeBounds, maskLocalRenderBounds } = LeafBoundsHelper;
5699
+ const debug$6 = new Debug('Branch');
5684
5700
  exports.Branch = class Branch extends exports.Leaf {
5685
5701
  __updateStrokeSpread() {
5686
5702
  const { children } = this;
@@ -5721,8 +5737,8 @@ var LeaferUI = (function (exports) {
5721
5737
  }
5722
5738
  }
5723
5739
  add(child, index) {
5724
- if (child === this)
5725
- return;
5740
+ if (child === this || child.destroyed)
5741
+ return debug$6.warn('add self or destroyed');
5726
5742
  const noIndex = index === undefined;
5727
5743
  if (!child.__) {
5728
5744
  if (child instanceof Array)
@@ -5736,8 +5752,9 @@ var LeaferUI = (function (exports) {
5736
5752
  noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5737
5753
  if (child.isBranch)
5738
5754
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5739
- child.__layout.boxChanged || child.__layout.boxChange();
5740
- child.__layout.matrixChanged || child.__layout.matrixChange();
5755
+ const childLayout = child.__layout;
5756
+ childLayout.boxChanged || childLayout.boxChange();
5757
+ childLayout.matrixChanged || childLayout.matrixChange();
5741
5758
  if (child.__bubbleMap)
5742
5759
  child.__emitLifeEvent(ChildEvent.ADD);
5743
5760
  if (this.leafer) {
@@ -5975,7 +5992,7 @@ var LeaferUI = (function (exports) {
5975
5992
  }
5976
5993
  }
5977
5994
 
5978
- const version = "1.1.0";
5995
+ const version = "1.1.1";
5979
5996
 
5980
5997
  class LeaferCanvas extends LeaferCanvasBase {
5981
5998
  get allowBackgroundColor() { return true; }
@@ -6249,7 +6266,7 @@ var LeaferUI = (function (exports) {
6249
6266
  }
6250
6267
 
6251
6268
  const { updateAllMatrix, updateAllChange } = LeafHelper;
6252
- const debug$6 = Debug.get('Layouter');
6269
+ const debug$5 = Debug.get('Layouter');
6253
6270
  class Layouter {
6254
6271
  constructor(target, userConfig) {
6255
6272
  this.totalTimes = 0;
@@ -6284,7 +6301,7 @@ var LeaferUI = (function (exports) {
6284
6301
  target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times));
6285
6302
  }
6286
6303
  catch (e) {
6287
- debug$6.error(e);
6304
+ debug$5.error(e);
6288
6305
  }
6289
6306
  this.layoutedBlocks = null;
6290
6307
  }
@@ -6298,9 +6315,9 @@ var LeaferUI = (function (exports) {
6298
6315
  }
6299
6316
  layoutOnce() {
6300
6317
  if (this.layouting)
6301
- return debug$6.warn('layouting');
6318
+ return debug$5.warn('layouting');
6302
6319
  if (this.times > 3)
6303
- return debug$6.warn('layout max times');
6320
+ return debug$5.warn('layout max times');
6304
6321
  this.times++;
6305
6322
  this.totalTimes++;
6306
6323
  this.layouting = true;
@@ -6404,7 +6421,7 @@ var LeaferUI = (function (exports) {
6404
6421
  }
6405
6422
  }
6406
6423
 
6407
- const debug$5 = Debug.get('Renderer');
6424
+ const debug$4 = Debug.get('Renderer');
6408
6425
  class Renderer {
6409
6426
  get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
6410
6427
  constructor(target, canvas, userConfig) {
@@ -6420,29 +6437,29 @@ var LeaferUI = (function (exports) {
6420
6437
  if (userConfig)
6421
6438
  this.config = DataHelper.default(userConfig, this.config);
6422
6439
  this.__listenEvents();
6423
- this.__requestRender();
6424
6440
  }
6425
6441
  start() {
6426
6442
  this.running = true;
6443
+ this.update(false);
6427
6444
  }
6428
6445
  stop() {
6429
6446
  this.running = false;
6430
6447
  }
6431
- update() {
6432
- this.changed = true;
6448
+ update(change = true) {
6449
+ if (!this.changed)
6450
+ this.changed = change;
6451
+ this.__requestRender();
6433
6452
  }
6434
6453
  requestLayout() {
6435
6454
  this.target.emit(LayoutEvent.REQUEST);
6436
6455
  }
6437
6456
  render(callback) {
6438
- if (!(this.running && this.canvas.view)) {
6439
- this.changed = true;
6440
- return;
6441
- }
6457
+ if (!(this.running && this.canvas.view))
6458
+ return this.update();
6442
6459
  const { target } = this;
6443
6460
  this.times = 0;
6444
6461
  this.totalBounds = new Bounds();
6445
- debug$5.log(target.innerName, '--->');
6462
+ debug$4.log(target.innerName, '--->');
6446
6463
  try {
6447
6464
  if (!target.isApp)
6448
6465
  target.app.emit(RenderEvent.CHILD_START, target);
@@ -6453,9 +6470,9 @@ var LeaferUI = (function (exports) {
6453
6470
  }
6454
6471
  catch (e) {
6455
6472
  this.rendering = false;
6456
- debug$5.error(e);
6473
+ debug$4.error(e);
6457
6474
  }
6458
- debug$5.log('-------------|');
6475
+ debug$4.log('-------------|');
6459
6476
  }
6460
6477
  renderAgain() {
6461
6478
  if (this.rendering) {
@@ -6467,9 +6484,9 @@ var LeaferUI = (function (exports) {
6467
6484
  }
6468
6485
  renderOnce(callback) {
6469
6486
  if (this.rendering)
6470
- return debug$5.warn('rendering');
6487
+ return debug$4.warn('rendering');
6471
6488
  if (this.times > 3)
6472
- return debug$5.warn('render max times');
6489
+ return debug$4.warn('render max times');
6473
6490
  this.times++;
6474
6491
  this.totalTimes++;
6475
6492
  this.rendering = true;
@@ -6506,7 +6523,7 @@ var LeaferUI = (function (exports) {
6506
6523
  partRender() {
6507
6524
  const { canvas, updateBlocks: list } = this;
6508
6525
  if (!list)
6509
- return debug$5.warn('PartRender: need update attr');
6526
+ return debug$4.warn('PartRender: need update attr');
6510
6527
  this.mergeBlocks();
6511
6528
  list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
6512
6529
  this.clipRender(block); });
@@ -6572,16 +6589,17 @@ var LeaferUI = (function (exports) {
6572
6589
  }
6573
6590
  }
6574
6591
  __requestRender() {
6575
- const startTime = Date.now();
6592
+ if (this.requestTime)
6593
+ return;
6594
+ const requestTime = this.requestTime = Date.now();
6576
6595
  Platform.requestRender(() => {
6577
- this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
6596
+ this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6597
+ this.requestTime = 0;
6578
6598
  if (this.running) {
6579
6599
  if (this.changed && this.canvas.view)
6580
6600
  this.render();
6581
6601
  this.target.emit(RenderEvent.NEXT);
6582
6602
  }
6583
- if (this.target)
6584
- this.__requestRender();
6585
6603
  });
6586
6604
  }
6587
6605
  __onResize(e) {
@@ -6597,7 +6615,7 @@ var LeaferUI = (function (exports) {
6597
6615
  }
6598
6616
  }
6599
6617
  this.addBlock(new Bounds(0, 0, 1, 1));
6600
- this.changed = true;
6618
+ this.update();
6601
6619
  }
6602
6620
  __onLayoutEnd(event) {
6603
6621
  if (event.data)
@@ -6608,7 +6626,7 @@ var LeaferUI = (function (exports) {
6608
6626
  empty = (!leaf.__world.width || !leaf.__world.height);
6609
6627
  if (empty) {
6610
6628
  if (!leaf.isLeafer)
6611
- debug$5.tip(leaf.innerName, ': empty');
6629
+ debug$4.tip(leaf.innerName, ': empty');
6612
6630
  empty = (!leaf.isBranch || leaf.isBranchLeaf);
6613
6631
  }
6614
6632
  return empty;
@@ -6983,7 +7001,7 @@ var LeaferUI = (function (exports) {
6983
7001
 
6984
7002
  const { parse, objectToCanvasData } = PathConvert;
6985
7003
  const emptyPaint = {};
6986
- const debug$4 = Debug.get('UIData');
7004
+ const debug$3 = Debug.get('UIData');
6987
7005
  class UIData extends LeafData {
6988
7006
  get scale() { const { scaleX, scaleY } = this; return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX; }
6989
7007
  get __strokeWidth() {
@@ -7005,7 +7023,7 @@ var LeaferUI = (function (exports) {
7005
7023
  return true;
7006
7024
  return t.fill && this.__hasStroke;
7007
7025
  }
7008
- get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
7026
+ get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
7009
7027
  get __autoWidth() { return !this._width; }
7010
7028
  get __autoHeight() { return !this._height; }
7011
7029
  get __autoSide() { return !this._width || !this._height; }
@@ -7020,7 +7038,7 @@ var LeaferUI = (function (exports) {
7020
7038
  if (value < 0) {
7021
7039
  this._width = -value;
7022
7040
  this.__leaf.scaleX *= -1;
7023
- debug$4.warn('width < 0, instead -scaleX ', this);
7041
+ debug$3.warn('width < 0, instead -scaleX ', this);
7024
7042
  }
7025
7043
  else
7026
7044
  this._width = value;
@@ -7029,7 +7047,7 @@ var LeaferUI = (function (exports) {
7029
7047
  if (value < 0) {
7030
7048
  this._height = -value;
7031
7049
  this.__leaf.scaleY *= -1;
7032
- debug$4.warn('height < 0, instead -scaleY', this);
7050
+ debug$3.warn('height < 0, instead -scaleY', this);
7033
7051
  }
7034
7052
  else
7035
7053
  this._height = value;
@@ -7119,7 +7137,7 @@ var LeaferUI = (function (exports) {
7119
7137
 
7120
7138
  class BoxData extends GroupData {
7121
7139
  get __boxStroke() { return !this.__pathInputed; }
7122
- get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
7140
+ get __drawAfterFill() { const t = this; return (t.overflow === 'hide' && (t.__clipAfterFill || t.innerShadow) && t.__leaf.children.length); }
7123
7141
  get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
7124
7142
  }
7125
7143
 
@@ -7765,7 +7783,7 @@ var LeaferUI = (function (exports) {
7765
7783
  ], exports.Group);
7766
7784
 
7767
7785
  var Leafer_1;
7768
- const debug$3 = Debug.get('Leafer');
7786
+ const debug$2 = Debug.get('Leafer');
7769
7787
  exports.Leafer = Leafer_1 = class Leafer extends exports.Group {
7770
7788
  get __tag() { return 'Leafer'; }
7771
7789
  get isApp() { return false; }
@@ -7779,20 +7797,10 @@ var LeaferUI = (function (exports) {
7779
7797
  constructor(userConfig, data) {
7780
7798
  super(data);
7781
7799
  this.config = {
7782
- type: 'design',
7783
7800
  start: true,
7784
7801
  hittable: true,
7785
7802
  smooth: true,
7786
- lazySpeard: 100,
7787
- zoom: {
7788
- min: 0.01,
7789
- max: 256
7790
- },
7791
- move: {
7792
- holdSpaceKey: true,
7793
- holdMiddleKey: true,
7794
- autoDistance: 2
7795
- }
7803
+ lazySpeard: 100
7796
7804
  };
7797
7805
  this.leafs = 0;
7798
7806
  this.__eventIds = [];
@@ -7809,23 +7817,27 @@ var LeaferUI = (function (exports) {
7809
7817
  init(userConfig, parentApp) {
7810
7818
  if (this.canvas)
7811
7819
  return;
7812
- this.__setLeafer(this);
7813
- if (userConfig)
7814
- DataHelper.assign(this.config, userConfig);
7815
7820
  let start;
7816
7821
  const { config } = this;
7817
- this.initType(config.type);
7822
+ this.__setLeafer(this);
7823
+ if (parentApp) {
7824
+ this.parentApp = parentApp;
7825
+ this.__bindApp(parentApp);
7826
+ start = parentApp.running;
7827
+ }
7828
+ if (userConfig) {
7829
+ this.parent = parentApp;
7830
+ this.initType(userConfig.type);
7831
+ this.parent = undefined;
7832
+ DataHelper.assign(config, userConfig);
7833
+ }
7818
7834
  const canvas = this.canvas = Creator.canvas(config);
7819
7835
  this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7820
7836
  if (this.isApp)
7821
7837
  this.__setApp();
7822
7838
  this.__checkAutoLayout(config, parentApp);
7823
7839
  this.view = canvas.view;
7824
- if (parentApp) {
7825
- this.__bindApp(parentApp);
7826
- start = parentApp.running;
7827
- }
7828
- else {
7840
+ if (!parentApp) {
7829
7841
  this.selector = Creator.selector(this);
7830
7842
  this.interaction = Creator.interaction(this, canvas, this.selector, config);
7831
7843
  if (this.interaction) {
@@ -7882,7 +7894,11 @@ var LeaferUI = (function (exports) {
7882
7894
  forceRender(bounds) {
7883
7895
  this.renderer.addBlock(bounds ? new Bounds(bounds) : this.canvas.bounds);
7884
7896
  if (this.viewReady)
7885
- this.renderer.update();
7897
+ this.renderer.render();
7898
+ }
7899
+ requestRender(change = false) {
7900
+ if (this.renderer)
7901
+ this.renderer.update(change);
7886
7902
  }
7887
7903
  updateCursor(cursor) {
7888
7904
  const i = this.interaction;
@@ -7929,7 +7945,7 @@ var LeaferUI = (function (exports) {
7929
7945
  if (this.canvas) {
7930
7946
  if (canvasSizeAttrs.includes(attrName)) {
7931
7947
  if (!newValue)
7932
- debug$3.warn(attrName + ' is 0');
7948
+ debug$2.warn(attrName + ' is 0');
7933
7949
  this.__changeCanvasSize(attrName, newValue);
7934
7950
  }
7935
7951
  else if (attrName === 'fill') {
@@ -7990,8 +8006,10 @@ var LeaferUI = (function (exports) {
7990
8006
  const { imageReady } = this;
7991
8007
  if (imageReady && !this.viewCompleted)
7992
8008
  this.__checkViewCompleted();
7993
- if (!imageReady)
8009
+ if (!imageReady) {
7994
8010
  this.viewCompleted = false;
8011
+ this.requestRender();
8012
+ }
7995
8013
  }
7996
8014
  }
7997
8015
  __checkViewCompleted(emit = true) {
@@ -8049,6 +8067,7 @@ var LeaferUI = (function (exports) {
8049
8067
  }
8050
8068
  else
8051
8069
  list.push(item);
8070
+ this.requestRender();
8052
8071
  }
8053
8072
  zoom(_zoomType, _padding, _fixedScale) {
8054
8073
  return needPlugin('view');
@@ -8102,14 +8121,14 @@ var LeaferUI = (function (exports) {
8102
8121
  this.canvasManager.destroy();
8103
8122
  }
8104
8123
  this.canvas.destroy();
8105
- this.config.view = this.view = null;
8124
+ this.config.view = this.view = this.parentApp = null;
8106
8125
  if (this.userConfig)
8107
8126
  this.userConfig.view = null;
8108
8127
  super.destroy();
8109
8128
  setTimeout(() => { ImageManager.clearRecycled(); }, 100);
8110
8129
  }
8111
8130
  catch (e) {
8112
- debug$3.error(e);
8131
+ debug$2.error(e);
8113
8132
  }
8114
8133
  }
8115
8134
  };
@@ -8829,9 +8848,9 @@ var LeaferUI = (function (exports) {
8829
8848
  if (ground)
8830
8849
  this.ground = this.addLeafer(ground);
8831
8850
  if (tree || editor)
8832
- this.tree = this.addLeafer(tree);
8851
+ this.tree = this.addLeafer(tree || { type: userConfig.type || 'design' });
8833
8852
  if (sky || editor)
8834
- this.sky = this.addLeafer(sky || { type: 'draw', usePartRender: false });
8853
+ this.sky = this.addLeafer(sky);
8835
8854
  if (editor)
8836
8855
  this.sky.add(this.editor = Creator.editor(editor));
8837
8856
  }
@@ -9185,184 +9204,7 @@ var LeaferUI = (function (exports) {
9185
9204
  registerUIEvent()
9186
9205
  ], exports.KeyEvent);
9187
9206
 
9188
- function addInteractionWindow(leafer) {
9189
- if (leafer.isApp)
9190
- return;
9191
- leafer.__eventIds.push(leafer.on_(exports.MoveEvent.BEFORE_MOVE, (e) => {
9192
- leafer.zoomLayer.move(leafer.getValidMove(e.moveX, e.moveY));
9193
- }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, (e) => {
9194
- const { zoomLayer } = leafer;
9195
- const changeScale = leafer.getValidScale(e.scale);
9196
- if (changeScale !== 1) {
9197
- PointHelper.scaleOf(zoomLayer, e, changeScale);
9198
- zoomLayer.scale = zoomLayer.__.scaleX * changeScale;
9199
- }
9200
- }));
9201
- }
9202
-
9203
- function document(leafer) {
9204
- addInteractionWindow(leafer);
9205
- const { move, zoom } = leafer.config;
9206
- move.scroll = 'limit';
9207
- zoom.min = 1;
9208
- }
9209
-
9210
- function block(leafer) {
9211
- const { config } = leafer;
9212
- (config.wheel || (config.wheel = {})).preventDefault = false;
9213
- (config.touch || (config.touch = {})).preventDefault = 'auto';
9214
- }
9215
-
9216
- const debug$2 = Debug.get('LeaferTypeCreator');
9217
- const LeaferTypeCreator = {
9218
- list: {},
9219
- register(name, fn) {
9220
- list[name] && debug$2.repeat(name);
9221
- list[name] = fn;
9222
- },
9223
- run(name, leafer) {
9224
- const fn = list[name];
9225
- fn && fn(leafer);
9226
- }
9227
- };
9228
- const { list, register } = LeaferTypeCreator;
9229
- register('design', addInteractionWindow);
9230
- register('document', document);
9231
- register('block', block);
9232
-
9233
- const leafer = exports.Leafer.prototype;
9234
- leafer.initType = function (type) {
9235
- LeaferTypeCreator.run(type, this);
9236
- };
9237
- leafer.getValidMove = function (moveX, moveY) {
9238
- const { scroll, disabled } = this.app.config.move;
9239
- if (scroll) {
9240
- Math.abs(moveX) > Math.abs(moveY) ? moveY = 0 : moveX = 0;
9241
- if (scroll === 'limit') {
9242
- const { x, y, width, height } = new Bounds(this.__world).addPoint(this.zoomLayer);
9243
- const right = x + width - this.width, bottom = y + height - this.height;
9244
- if (x >= 0 && right <= 0)
9245
- moveX = 0;
9246
- else if (moveX > 0) {
9247
- if (x + moveX > 0)
9248
- moveX = -x;
9249
- }
9250
- else if (moveX < 0 && right + moveX < 0)
9251
- moveX = -right;
9252
- if (y >= 0 && bottom <= 0)
9253
- moveY = 0;
9254
- else if (moveY > 0) {
9255
- if (y + moveY > 0)
9256
- moveY = -y;
9257
- }
9258
- else if (moveY < 0 && bottom + moveY < 0)
9259
- moveY = -bottom;
9260
- }
9261
- }
9262
- return { x: disabled ? 0 : moveX, y: disabled ? 0 : moveY };
9263
- };
9264
- leafer.getValidScale = function (changeScale) {
9265
- const { scaleX } = this.zoomLayer.__, { min, max, disabled } = this.app.config.zoom, absScale = Math.abs(scaleX * changeScale);
9266
- if (absScale < min)
9267
- changeScale = min / scaleX;
9268
- else if (absScale > max)
9269
- changeScale = max / scaleX;
9270
- return disabled ? 1 : changeScale;
9271
- };
9272
-
9273
- class Transformer {
9274
- get transforming() { return !!(this.moveData || this.zoomData || this.rotateData); }
9275
- constructor(interaction) {
9276
- this.interaction = interaction;
9277
- }
9278
- move(data) {
9279
- const { interaction } = this;
9280
- if (!data.moveType)
9281
- data.moveType = 'move';
9282
- if (!this.moveData) {
9283
- const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
9284
- data.path = path;
9285
- this.moveData = Object.assign(Object.assign({}, data), { moveX: 0, moveY: 0 });
9286
- interaction.cancelHover();
9287
- interaction.emit(exports.MoveEvent.START, this.moveData);
9288
- }
9289
- data.path = this.moveData.path;
9290
- interaction.emit(exports.MoveEvent.BEFORE_MOVE, data);
9291
- interaction.emit(exports.MoveEvent.MOVE, data);
9292
- this.transformEndWait();
9293
- }
9294
- zoom(data) {
9295
- const { interaction } = this;
9296
- if (!this.zoomData) {
9297
- const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
9298
- data.path = path;
9299
- this.zoomData = Object.assign(Object.assign({}, data), { scale: 1 });
9300
- interaction.cancelHover();
9301
- interaction.emit(exports.ZoomEvent.START, this.zoomData);
9302
- }
9303
- data.path = this.zoomData.path;
9304
- interaction.emit(exports.ZoomEvent.BEFORE_ZOOM, data);
9305
- interaction.emit(exports.ZoomEvent.ZOOM, data);
9306
- this.transformEndWait();
9307
- }
9308
- rotate(data) {
9309
- const { interaction } = this;
9310
- if (!this.rotateData) {
9311
- const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
9312
- data.path = path;
9313
- this.rotateData = Object.assign(Object.assign({}, data), { rotation: 0 });
9314
- interaction.cancelHover();
9315
- interaction.emit(exports.RotateEvent.START, this.rotateData);
9316
- }
9317
- data.path = this.rotateData.path;
9318
- interaction.emit(exports.RotateEvent.BEFORE_ROTATE, data);
9319
- interaction.emit(exports.RotateEvent.ROTATE, data);
9320
- this.transformEndWait();
9321
- }
9322
- transformEndWait() {
9323
- clearTimeout(this.transformTimer);
9324
- this.transformTimer = setTimeout(() => {
9325
- this.transformEnd();
9326
- }, this.interaction.config.pointer.transformTime);
9327
- }
9328
- transformEnd() {
9329
- this.moveEnd();
9330
- this.zoomEnd();
9331
- this.rotateEnd();
9332
- }
9333
- moveEnd() {
9334
- if (this.moveData) {
9335
- this.interaction.emit(exports.MoveEvent.END, this.moveData);
9336
- this.moveData = null;
9337
- }
9338
- }
9339
- zoomEnd() {
9340
- if (this.zoomData) {
9341
- this.interaction.emit(exports.ZoomEvent.END, this.zoomData);
9342
- this.zoomData = null;
9343
- }
9344
- }
9345
- rotateEnd() {
9346
- if (this.rotateData) {
9347
- this.interaction.emit(exports.RotateEvent.END, this.rotateData);
9348
- this.rotateData = null;
9349
- }
9350
- }
9351
- destroy() {
9352
- this.zoomData = this.moveData = this.rotateData = null;
9353
- }
9354
- }
9355
-
9356
9207
  const InteractionHelper = {
9357
- getMoveEventData(center, move, event) {
9358
- return Object.assign(Object.assign({}, event), { x: center.x, y: center.y, moveX: move.x, moveY: move.y });
9359
- },
9360
- getRotateEventData(center, angle, event) {
9361
- return Object.assign(Object.assign({}, event), { x: center.x, y: center.y, rotation: angle });
9362
- },
9363
- getZoomEventData(center, scale, event) {
9364
- return Object.assign(Object.assign({}, event), { x: center.x, y: center.y, scale });
9365
- },
9366
9208
  getDragEventData(startPoint, lastPoint, event) {
9367
9209
  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 });
9368
9210
  },
@@ -9371,18 +9213,14 @@ var LeaferUI = (function (exports) {
9371
9213
  data });
9372
9214
  },
9373
9215
  getSwipeDirection(angle) {
9374
- if (angle < -45 && angle > -135) {
9216
+ if (angle < -45 && angle > -135)
9375
9217
  return exports.SwipeEvent.UP;
9376
- }
9377
- else if (angle > 45 && angle < 135) {
9218
+ else if (angle > 45 && angle < 135)
9378
9219
  return exports.SwipeEvent.DOWN;
9379
- }
9380
- else if (angle <= 45 && angle >= -45) {
9220
+ else if (angle <= 45 && angle >= -45)
9381
9221
  return exports.SwipeEvent.RIGHT;
9382
- }
9383
- else {
9222
+ else
9384
9223
  return exports.SwipeEvent.LEFT;
9385
- }
9386
9224
  },
9387
9225
  getSwipeEventData(startPoint, lastDragData, event) {
9388
9226
  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)) });
@@ -9455,9 +9293,8 @@ var LeaferUI = (function (exports) {
9455
9293
  interaction.emit(exports.MoveEvent.START, this.dragData);
9456
9294
  }
9457
9295
  }
9458
- if (!this.moving) {
9296
+ if (!this.moving)
9459
9297
  this.dragStart(data, canDrag);
9460
- }
9461
9298
  this.drag(data);
9462
9299
  }
9463
9300
  dragStart(data, canDrag) {
@@ -9535,16 +9372,9 @@ var LeaferUI = (function (exports) {
9535
9372
  dragEnd(data, speed) {
9536
9373
  if (!this.dragging && !this.moving)
9537
9374
  return;
9538
- const { moveX, moveY } = this.dragData;
9539
- if (this.interaction.config.move.dragAnimate && this.canAnimate && this.moving && (Math.abs(moveX) > 1 || Math.abs(moveY) > 1)) {
9540
- data = Object.assign({}, data);
9541
- speed = (speed || (data.pointerType === 'touch' ? 2 : 1)) * 0.9;
9542
- PointHelper.move(data, moveX * speed, moveY * speed);
9543
- this.drag(data);
9544
- this.animate(() => { this.dragEnd(data, 1); });
9545
- }
9546
- else
9547
- this.dragEndReal(data);
9375
+ if (this.checkDragEndAnimate(data, speed))
9376
+ return;
9377
+ this.dragEndReal(data);
9548
9378
  }
9549
9379
  dragEndReal(data) {
9550
9380
  const { interaction, downData, dragData } = this;
@@ -9571,12 +9401,6 @@ var LeaferUI = (function (exports) {
9571
9401
  this.dragReset();
9572
9402
  this.animate(null, 'off');
9573
9403
  }
9574
- animate(func, off) {
9575
- const animateWait = func || this.animateWait;
9576
- if (animateWait)
9577
- this.interaction.target.nextRender(animateWait, null, off);
9578
- this.animateWait = func;
9579
- }
9580
9404
  swipe(data, downData, dragData, endDragData) {
9581
9405
  const { interaction } = this;
9582
9406
  if (PointHelper.getDistance(downData, data) > interaction.config.pointer.swipeDistance) {
@@ -9593,39 +9417,11 @@ var LeaferUI = (function (exports) {
9593
9417
  dragReset() {
9594
9418
  exports.DragEvent.list = exports.DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
9595
9419
  }
9596
- checkDragOut(data) {
9597
- const { interaction } = this;
9598
- this.autoMoveCancel();
9599
- if (this.dragging && !interaction.shrinkCanvasBounds.hitPoint(data))
9600
- this.autoMoveOnDragOut(data);
9601
- }
9602
- autoMoveOnDragOut(data) {
9603
- const { interaction, downData, canDragOut } = this;
9604
- const { autoDistance, dragOut } = interaction.config.move;
9605
- if (!dragOut || !canDragOut || !autoDistance)
9606
- return;
9607
- const bounds = interaction.shrinkCanvasBounds;
9608
- const { x, y } = bounds;
9609
- const right = BoundsHelper.maxX(bounds);
9610
- const bottom = BoundsHelper.maxY(bounds);
9611
- const moveX = data.x < x ? autoDistance : (right < data.x ? -autoDistance : 0);
9612
- const moveY = data.y < y ? autoDistance : (bottom < data.y ? -autoDistance : 0);
9613
- let totalX = 0, totalY = 0;
9614
- this.autoMoveTimer = setInterval(() => {
9615
- totalX += moveX;
9616
- totalY += moveY;
9617
- PointHelper.move(downData, moveX, moveY);
9618
- PointHelper.move(this.dragData, moveX, moveY);
9619
- interaction.move(Object.assign(Object.assign({}, data), { moveX, moveY, totalX, totalY, moveType: 'drag' }));
9620
- interaction.pointerMoveReal(data);
9621
- }, 10);
9622
- }
9623
- autoMoveCancel() {
9624
- if (this.autoMoveTimer) {
9625
- clearInterval(this.autoMoveTimer);
9626
- this.autoMoveTimer = 0;
9627
- }
9628
- }
9420
+ checkDragEndAnimate(_data, _speed) { return false; }
9421
+ animate(_func, _off) { }
9422
+ checkDragOut(_data) { }
9423
+ autoMoveOnDragOut(_data) { }
9424
+ autoMoveCancel() { }
9629
9425
  destroy() {
9630
9426
  this.dragReset();
9631
9427
  }
@@ -9695,28 +9491,12 @@ var LeaferUI = (function (exports) {
9695
9491
  return excludePath && excludePath.has(leaf);
9696
9492
  }
9697
9493
 
9698
- const MultiTouchHelper = {
9699
- getData(list) {
9700
- const a = list[0];
9701
- const b = list[1];
9702
- const lastCenter = PointHelper.getCenter(a.from, b.from);
9703
- const center = PointHelper.getCenter(a.to, b.to);
9704
- const move = { x: center.x - lastCenter.x, y: center.y - lastCenter.y };
9705
- const lastDistance = PointHelper.getDistance(a.from, b.from);
9706
- const distance = PointHelper.getDistance(a.to, b.to);
9707
- const scale = distance / lastDistance;
9708
- const angle = PointHelper.getRotation(a.from, b.from, a.to, b.to);
9709
- return { move, scale, angle, center };
9710
- }
9711
- };
9712
-
9713
9494
  const config = {
9714
9495
  wheel: {
9715
9496
  zoomSpeed: 0.5,
9716
9497
  moveSpeed: 0.5,
9717
9498
  rotateSpeed: 0.5,
9718
9499
  delta: { x: 80 / 4, y: 8.0 },
9719
- preventDefault: true
9720
9500
  },
9721
9501
  pointer: {
9722
9502
  hitRadius: 5,
@@ -9727,17 +9507,18 @@ var LeaferUI = (function (exports) {
9727
9507
  dragHover: true,
9728
9508
  dragDistance: 2,
9729
9509
  swipeDistance: 20,
9730
- preventDefaultMenu: true
9731
9510
  },
9732
9511
  touch: {
9733
- preventDefault: true
9512
+ preventDefault: 'auto'
9734
9513
  },
9735
9514
  multiTouch: {},
9515
+ move: { autoDistance: 2 },
9516
+ zoom: {},
9736
9517
  cursor: true,
9737
9518
  keyEvent: true
9738
9519
  };
9739
9520
 
9740
- const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag, pathHasOutside } = InteractionHelper;
9521
+ const { pathHasEventType, pathCanDrag, pathHasOutside } = InteractionHelper;
9741
9522
  class InteractionBase {
9742
9523
  get dragging() { return this.dragger.dragging; }
9743
9524
  get transforming() { return this.transformer.transforming; }
@@ -9759,7 +9540,7 @@ var LeaferUI = (function (exports) {
9759
9540
  this.canvas = canvas;
9760
9541
  this.selector = selector;
9761
9542
  this.defaultPath = new LeafList(target);
9762
- this.transformer = new Transformer(this);
9543
+ this.createTransformer();
9763
9544
  this.dragger = new Dragger(this);
9764
9545
  if (userConfig)
9765
9546
  this.config = DataHelper.default(userConfig, this.config);
@@ -9860,14 +9641,6 @@ var LeaferUI = (function (exports) {
9860
9641
  data.isCancel = true;
9861
9642
  this.pointerUp(data);
9862
9643
  }
9863
- multiTouch(data, list) {
9864
- if (this.config.multiTouch.disabled)
9865
- return;
9866
- const { move, angle, scale, center } = MultiTouchHelper.getData(list);
9867
- this.rotate(getRotateEventData(center, angle, data));
9868
- this.zoom(getZoomEventData(center, scale, data));
9869
- this.move(getMoveEventData(center, move, data));
9870
- }
9871
9644
  menu(data) {
9872
9645
  this.findPath(data);
9873
9646
  this.emit(exports.PointerEvent.MENU, data);
@@ -9881,18 +9654,13 @@ var LeaferUI = (function (exports) {
9881
9654
  this.waitRightTap = this.waitMenuTap = false;
9882
9655
  }
9883
9656
  }
9884
- move(data) {
9885
- this.transformer.move(data);
9886
- }
9887
- zoom(data) {
9888
- this.transformer.zoom(data);
9889
- }
9890
- rotate(data) {
9891
- this.transformer.rotate(data);
9892
- }
9893
- transformEnd() {
9894
- this.transformer.transformEnd();
9895
- }
9657
+ createTransformer() { }
9658
+ move(_data) { }
9659
+ zoom(_data) { }
9660
+ rotate(_data) { }
9661
+ transformEnd() { }
9662
+ wheel(_data) { }
9663
+ multiTouch(_data, _list) { }
9896
9664
  keyDown(data) {
9897
9665
  if (!this.config.keyEvent)
9898
9666
  return;
@@ -10130,8 +9898,9 @@ var LeaferUI = (function (exports) {
10130
9898
  this.longPressed = false;
10131
9899
  }
10132
9900
  __onResize() {
9901
+ const { dragOut } = this.m;
10133
9902
  this.shrinkCanvasBounds = new Bounds(this.canvas.bounds);
10134
- this.shrinkCanvasBounds.spread(-2);
9903
+ this.shrinkCanvasBounds.spread(-(typeof dragOut === 'number' ? dragOut : 2));
10135
9904
  }
10136
9905
  __listenEvents() {
10137
9906
  const { target } = this;
@@ -10151,7 +9920,8 @@ var LeaferUI = (function (exports) {
10151
9920
  this.stop();
10152
9921
  this.__removeListenEvents();
10153
9922
  this.dragger.destroy();
10154
- this.transformer.destroy();
9923
+ if (this.transformer)
9924
+ this.transformer.destroy();
10155
9925
  this.downData = this.overPath = this.enterPath = null;
10156
9926
  }
10157
9927
  }
@@ -12056,6 +11826,7 @@ var LeaferUI = (function (exports) {
12056
11826
  exports.Cursor = Cursor;
12057
11827
  exports.DataHelper = DataHelper;
12058
11828
  exports.Debug = Debug;
11829
+ exports.Dragger = Dragger;
12059
11830
  exports.Effect = Effect;
12060
11831
  exports.EllipseData = EllipseData;
12061
11832
  exports.EllipseHelper = EllipseHelper;
@@ -12092,12 +11863,10 @@ var LeaferUI = (function (exports) {
12092
11863
  exports.LeaferData = LeaferData;
12093
11864
  exports.LeaferEvent = LeaferEvent;
12094
11865
  exports.LeaferImage = LeaferImage;
12095
- exports.LeaferTypeCreator = LeaferTypeCreator;
12096
11866
  exports.LineData = LineData;
12097
11867
  exports.MathHelper = MathHelper;
12098
11868
  exports.Matrix = Matrix;
12099
11869
  exports.MatrixHelper = MatrixHelper;
12100
- exports.MultiTouchHelper = MultiTouchHelper;
12101
11870
  exports.MyDragEvent = MyDragEvent;
12102
11871
  exports.MyImage = MyImage;
12103
11872
  exports.MyPointerEvent = MyPointerEvent;
@@ -12153,7 +11922,6 @@ var LeaferUI = (function (exports) {
12153
11922
  exports.WaitHelper = WaitHelper;
12154
11923
  exports.WatchEvent = WatchEvent;
12155
11924
  exports.Watcher = Watcher;
12156
- exports.addInteractionWindow = addInteractionWindow;
12157
11925
  exports.affectRenderBoundsType = affectRenderBoundsType;
12158
11926
  exports.affectStrokeBoundsType = affectStrokeBoundsType;
12159
11927
  exports.attr = attr;