leafer-draw 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web.js CHANGED
@@ -1377,7 +1377,7 @@ var LeaferUI = (function (exports) {
1377
1377
  }
1378
1378
  const D$4 = Debug;
1379
1379
 
1380
- const debug$e = Debug.get('RunTime');
1380
+ const debug$f = Debug.get('RunTime');
1381
1381
  const Run = {
1382
1382
  currentId: 0,
1383
1383
  currentName: '',
@@ -1395,7 +1395,7 @@ var LeaferUI = (function (exports) {
1395
1395
  const time = R.idMap[id], name = R.nameMap[id];
1396
1396
  const duration = microsecond ? (performance.now() - time) / 1000 : Date.now() - time;
1397
1397
  R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined;
1398
- debug$e.log(name, duration, 'ms');
1398
+ debug$f.log(name, duration, 'ms');
1399
1399
  },
1400
1400
  endOfName(name, microsecond) {
1401
1401
  const id = R.nameToIdMap[name];
@@ -1409,18 +1409,18 @@ var LeaferUI = (function (exports) {
1409
1409
  console.error('need plugin: @leafer-in/' + name);
1410
1410
  }
1411
1411
 
1412
- const debug$d = Debug.get('UICreator');
1412
+ const debug$e = Debug.get('UICreator');
1413
1413
  const UICreator = {
1414
1414
  list: {},
1415
1415
  register(UI) {
1416
1416
  const { __tag: tag } = UI.prototype;
1417
1417
  if (list$1[tag])
1418
- debug$d.repeat(tag);
1418
+ debug$e.repeat(tag);
1419
1419
  list$1[tag] = UI;
1420
1420
  },
1421
1421
  get(tag, data, x, y, width, height) {
1422
1422
  if (!list$1[tag])
1423
- debug$d.error('not register ' + tag);
1423
+ debug$e.error('not register ' + tag);
1424
1424
  const ui = new list$1[tag](data);
1425
1425
  if (x !== undefined) {
1426
1426
  ui.x = x;
@@ -1436,7 +1436,7 @@ var LeaferUI = (function (exports) {
1436
1436
  };
1437
1437
  const { list: list$1 } = UICreator;
1438
1438
 
1439
- const debug$c = Debug.get('EventCreator');
1439
+ const debug$d = Debug.get('EventCreator');
1440
1440
  const EventCreator = {
1441
1441
  nameList: {},
1442
1442
  register(Event) {
@@ -1444,7 +1444,7 @@ var LeaferUI = (function (exports) {
1444
1444
  Object.keys(Event).forEach(key => {
1445
1445
  name = Event[key];
1446
1446
  if (typeof name === 'string')
1447
- nameList[name] && debug$c.repeat(name), nameList[name] = Event;
1447
+ nameList[name] && debug$d.repeat(name), nameList[name] = Event;
1448
1448
  });
1449
1449
  },
1450
1450
  changeName(oldName, newName) {
@@ -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) {
@@ -2598,7 +2600,7 @@ var LeaferUI = (function (exports) {
2598
2600
  const { M: M$4, m, L: L$5, l, H, h, V, v, C: C$4, c, S, s, Q: Q$3, q, T, t, A, a, Z: Z$4, z, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$3, P: P$3, U: U$3 } = PathCommandMap;
2599
2601
  const { rect: rect$2, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$4, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2600
2602
  const { ellipticalArc } = EllipseHelper;
2601
- const debug$b = Debug.get('PathConvert');
2603
+ const debug$c = Debug.get('PathConvert');
2602
2604
  const setEndPoint$1 = {};
2603
2605
  const PathConvert = {
2604
2606
  current: { dot: 0 },
@@ -2839,7 +2841,7 @@ var LeaferUI = (function (exports) {
2839
2841
  i += 6;
2840
2842
  break;
2841
2843
  default:
2842
- debug$b.error(`command: ${command} [index:${i}]`, old);
2844
+ debug$c.error(`command: ${command} [index:${i}]`, old);
2843
2845
  return data;
2844
2846
  }
2845
2847
  lastCommand = command;
@@ -3064,7 +3066,7 @@ var LeaferUI = (function (exports) {
3064
3066
  }
3065
3067
 
3066
3068
  const { M: M$2, L: L$3, C: C$2, Q: Q$1, Z: Z$2, N: N$1, D: D$1, X: X$1, G: G$1, F: F$2, O: O$1, P: P$1, U: U$1 } = PathCommandMap;
3067
- const debug$a = Debug.get('PathDrawer');
3069
+ const debug$b = Debug.get('PathDrawer');
3068
3070
  const PathDrawer = {
3069
3071
  drawPathByData(drawer, data) {
3070
3072
  if (!data)
@@ -3127,7 +3129,7 @@ var LeaferUI = (function (exports) {
3127
3129
  i += 6;
3128
3130
  break;
3129
3131
  default:
3130
- debug$a.error(`command: ${command} [index:${i}]`, data);
3132
+ debug$b.error(`command: ${command} [index:${i}]`, data);
3131
3133
  return;
3132
3134
  }
3133
3135
  }
@@ -3137,7 +3139,7 @@ var LeaferUI = (function (exports) {
3137
3139
  const { M: M$1, L: L$2, C: C$1, Q, Z: Z$1, N, D, X, G, F: F$1, O, P, U } = PathCommandMap;
3138
3140
  const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc, ellipse: ellipse$1 } = BezierHelper;
3139
3141
  const { addPointBounds, copy: copy$7, addPoint: addPoint$1, setPoint: setPoint$1, addBounds, toBounds: toBounds$3 } = TwoPointBoundsHelper;
3140
- const debug$9 = Debug.get('PathBounds');
3142
+ const debug$a = Debug.get('PathBounds');
3141
3143
  let radius, radiusX, radiusY;
3142
3144
  const tempPointBounds = {};
3143
3145
  const setPointBounds = {};
@@ -3245,7 +3247,7 @@ var LeaferUI = (function (exports) {
3245
3247
  i += 6;
3246
3248
  break;
3247
3249
  default:
3248
- debug$9.error(`command: ${command} [index:${i}]`, data);
3250
+ debug$a.error(`command: ${command} [index:${i}]`, data);
3249
3251
  return;
3250
3252
  }
3251
3253
  }
@@ -3361,7 +3363,7 @@ var LeaferUI = (function (exports) {
3361
3363
  const F = FileHelper;
3362
3364
  F.opacityTypes.forEach(type => F.upperCaseTypeMap[type] = type.toUpperCase());
3363
3365
 
3364
- const debug$8 = Debug.get('TaskProcessor');
3366
+ const debug$9 = Debug.get('TaskProcessor');
3365
3367
  class TaskItem {
3366
3368
  constructor(task) {
3367
3369
  this.parallel = true;
@@ -3376,7 +3378,7 @@ var LeaferUI = (function (exports) {
3376
3378
  yield this.task();
3377
3379
  }
3378
3380
  catch (error) {
3379
- debug$8.error(error);
3381
+ debug$9.error(error);
3380
3382
  }
3381
3383
  });
3382
3384
  }
@@ -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();
@@ -4050,7 +4065,7 @@ var LeaferUI = (function (exports) {
4050
4065
  defineKey(data, key, property);
4051
4066
  }
4052
4067
 
4053
- const debug$7 = new Debug('rewrite');
4068
+ const debug$8 = new Debug('rewrite');
4054
4069
  const list = [];
4055
4070
  const excludeNames = ['destroy', 'constructor'];
4056
4071
  function rewrite(method) {
@@ -4067,7 +4082,7 @@ var LeaferUI = (function (exports) {
4067
4082
  if (list.length) {
4068
4083
  list.forEach(item => {
4069
4084
  if (error)
4070
- debug$7.error(item.name, '需在Class上装饰@rewriteAble()');
4085
+ debug$8.error(item.name, '需在Class上装饰@rewriteAble()');
4071
4086
  item.run();
4072
4087
  });
4073
4088
  list.length = 0;
@@ -4975,13 +4990,13 @@ var LeaferUI = (function (exports) {
4975
4990
  const LeafEventer = { on, on_, off, off_, once, emit: emit$1, emitEvent, hasEvent, destroyEventer: destroy };
4976
4991
 
4977
4992
  const { isFinite } = Number;
4978
- const debug$6 = Debug.get('setAttr');
4993
+ const debug$7 = Debug.get('setAttr');
4979
4994
  const LeafDataProxy = {
4980
4995
  __setAttr(name, newValue, checkFiniteNumber) {
4981
4996
  if (this.leaferIsCreated) {
4982
4997
  const oldValue = this.__.__getInput(name);
4983
4998
  if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) {
4984
- debug$6.warn(this.innerName, name, newValue);
4999
+ debug$7.warn(this.innerName, name, newValue);
4985
5000
  newValue = undefined;
4986
5001
  }
4987
5002
  if (typeof newValue === 'object' || oldValue !== newValue) {
@@ -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
  const debug$5 = Debug.get('LeaferCanvas');
5981
5998
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6593,25 +6610,25 @@ var LeaferUI = (function (exports) {
6593
6610
  if (userConfig)
6594
6611
  this.config = DataHelper.default(userConfig, this.config);
6595
6612
  this.__listenEvents();
6596
- this.__requestRender();
6597
6613
  }
6598
6614
  start() {
6599
6615
  this.running = true;
6616
+ this.update(false);
6600
6617
  }
6601
6618
  stop() {
6602
6619
  this.running = false;
6603
6620
  }
6604
- update() {
6605
- this.changed = true;
6621
+ update(change = true) {
6622
+ if (!this.changed)
6623
+ this.changed = change;
6624
+ this.__requestRender();
6606
6625
  }
6607
6626
  requestLayout() {
6608
6627
  this.target.emit(LayoutEvent.REQUEST);
6609
6628
  }
6610
6629
  render(callback) {
6611
- if (!(this.running && this.canvas.view)) {
6612
- this.changed = true;
6613
- return;
6614
- }
6630
+ if (!(this.running && this.canvas.view))
6631
+ return this.update();
6615
6632
  const { target } = this;
6616
6633
  this.times = 0;
6617
6634
  this.totalBounds = new Bounds();
@@ -6745,16 +6762,17 @@ var LeaferUI = (function (exports) {
6745
6762
  }
6746
6763
  }
6747
6764
  __requestRender() {
6748
- const startTime = Date.now();
6765
+ if (this.requestTime)
6766
+ return;
6767
+ const requestTime = this.requestTime = Date.now();
6749
6768
  Platform.requestRender(() => {
6750
- this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - startTime)));
6769
+ this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6770
+ this.requestTime = 0;
6751
6771
  if (this.running) {
6752
6772
  if (this.changed && this.canvas.view)
6753
6773
  this.render();
6754
6774
  this.target.emit(RenderEvent.NEXT);
6755
6775
  }
6756
- if (this.target)
6757
- this.__requestRender();
6758
6776
  });
6759
6777
  }
6760
6778
  __onResize(e) {
@@ -6770,7 +6788,7 @@ var LeaferUI = (function (exports) {
6770
6788
  }
6771
6789
  }
6772
6790
  this.addBlock(new Bounds(0, 0, 1, 1));
6773
- this.changed = true;
6791
+ this.update();
6774
6792
  }
6775
6793
  __onLayoutEnd(event) {
6776
6794
  if (event.data)
@@ -6905,7 +6923,7 @@ var LeaferUI = (function (exports) {
6905
6923
  return true;
6906
6924
  return t.fill && this.__hasStroke;
6907
6925
  }
6908
- get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6926
+ get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
6909
6927
  get __autoWidth() { return !this._width; }
6910
6928
  get __autoHeight() { return !this._height; }
6911
6929
  get __autoSide() { return !this._width || !this._height; }
@@ -7019,7 +7037,7 @@ var LeaferUI = (function (exports) {
7019
7037
 
7020
7038
  class BoxData extends GroupData {
7021
7039
  get __boxStroke() { return !this.__pathInputed; }
7022
- get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
7040
+ get __drawAfterFill() { const t = this; return (t.overflow === 'hide' && (t.__clipAfterFill || t.innerShadow) && t.__leaf.children.length); }
7023
7041
  get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
7024
7042
  }
7025
7043
 
@@ -7679,20 +7697,10 @@ var LeaferUI = (function (exports) {
7679
7697
  constructor(userConfig, data) {
7680
7698
  super(data);
7681
7699
  this.config = {
7682
- type: 'design',
7683
7700
  start: true,
7684
7701
  hittable: true,
7685
7702
  smooth: true,
7686
- lazySpeard: 100,
7687
- zoom: {
7688
- min: 0.01,
7689
- max: 256
7690
- },
7691
- move: {
7692
- holdSpaceKey: true,
7693
- holdMiddleKey: true,
7694
- autoDistance: 2
7695
- }
7703
+ lazySpeard: 100
7696
7704
  };
7697
7705
  this.leafs = 0;
7698
7706
  this.__eventIds = [];
@@ -7709,23 +7717,27 @@ var LeaferUI = (function (exports) {
7709
7717
  init(userConfig, parentApp) {
7710
7718
  if (this.canvas)
7711
7719
  return;
7712
- this.__setLeafer(this);
7713
- if (userConfig)
7714
- DataHelper.assign(this.config, userConfig);
7715
7720
  let start;
7716
7721
  const { config } = this;
7717
- this.initType(config.type);
7722
+ this.__setLeafer(this);
7723
+ if (parentApp) {
7724
+ this.parentApp = parentApp;
7725
+ this.__bindApp(parentApp);
7726
+ start = parentApp.running;
7727
+ }
7728
+ if (userConfig) {
7729
+ this.parent = parentApp;
7730
+ this.initType(userConfig.type);
7731
+ this.parent = undefined;
7732
+ DataHelper.assign(config, userConfig);
7733
+ }
7718
7734
  const canvas = this.canvas = Creator.canvas(config);
7719
7735
  this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7720
7736
  if (this.isApp)
7721
7737
  this.__setApp();
7722
7738
  this.__checkAutoLayout(config, parentApp);
7723
7739
  this.view = canvas.view;
7724
- if (parentApp) {
7725
- this.__bindApp(parentApp);
7726
- start = parentApp.running;
7727
- }
7728
- else {
7740
+ if (!parentApp) {
7729
7741
  this.selector = Creator.selector(this);
7730
7742
  this.interaction = Creator.interaction(this, canvas, this.selector, config);
7731
7743
  if (this.interaction) {
@@ -7782,7 +7794,11 @@ var LeaferUI = (function (exports) {
7782
7794
  forceRender(bounds) {
7783
7795
  this.renderer.addBlock(bounds ? new Bounds(bounds) : this.canvas.bounds);
7784
7796
  if (this.viewReady)
7785
- this.renderer.update();
7797
+ this.renderer.render();
7798
+ }
7799
+ requestRender(change = false) {
7800
+ if (this.renderer)
7801
+ this.renderer.update(change);
7786
7802
  }
7787
7803
  updateCursor(cursor) {
7788
7804
  const i = this.interaction;
@@ -7890,8 +7906,10 @@ var LeaferUI = (function (exports) {
7890
7906
  const { imageReady } = this;
7891
7907
  if (imageReady && !this.viewCompleted)
7892
7908
  this.__checkViewCompleted();
7893
- if (!imageReady)
7909
+ if (!imageReady) {
7894
7910
  this.viewCompleted = false;
7911
+ this.requestRender();
7912
+ }
7895
7913
  }
7896
7914
  }
7897
7915
  __checkViewCompleted(emit = true) {
@@ -7949,6 +7967,7 @@ var LeaferUI = (function (exports) {
7949
7967
  }
7950
7968
  else
7951
7969
  list.push(item);
7970
+ this.requestRender();
7952
7971
  }
7953
7972
  zoom(_zoomType, _padding, _fixedScale) {
7954
7973
  return needPlugin('view');
@@ -8002,7 +8021,7 @@ var LeaferUI = (function (exports) {
8002
8021
  this.canvasManager.destroy();
8003
8022
  }
8004
8023
  this.canvas.destroy();
8005
- this.config.view = this.view = null;
8024
+ this.config.view = this.view = this.parentApp = null;
8006
8025
  if (this.userConfig)
8007
8026
  this.userConfig.view = null;
8008
8027
  super.destroy();