leafer-game 1.6.1 → 1.6.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/web.cjs CHANGED
@@ -45,4 +45,3 @@ Object.keys(find).forEach(function (k) {
45
45
  get: function () { return find[k]; }
46
46
  });
47
47
  });
48
- //# sourceMappingURL=web.cjs.map
package/dist/web.esm.js CHANGED
@@ -4,4 +4,3 @@ export * from '@leafer-in/state';
4
4
  export * from '@leafer-in/animate';
5
5
  export * from '@leafer-in/motion-path';
6
6
  export * from '@leafer-in/find';
7
- //# sourceMappingURL=web.esm.js.map
package/dist/web.js CHANGED
@@ -2592,7 +2592,11 @@ var LeaferUI = (function (exports) {
2592
2592
  const point = {};
2593
2593
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, point);
2594
2594
  return point;
2595
- }
2595
+ },
2596
+ getDerivative(t, fromV, v1, v2, toV) {
2597
+ const o = 1 - t;
2598
+ return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
2599
+ },
2596
2600
  };
2597
2601
  const { getPointAndSet, toTwoPointBounds: toTwoPointBounds$1, ellipse: ellipse$6 } = BezierHelper;
2598
2602
 
@@ -3773,8 +3777,11 @@ var LeaferUI = (function (exports) {
3773
3777
  load(onSuccess, onError) {
3774
3778
  if (!this.loading) {
3775
3779
  this.loading = true;
3780
+ let { loadImage, loadImageWithProgress } = Platform.origin, onProgress = this.config.showProgress && loadImageWithProgress && this.onProgress.bind(this);
3781
+ if (onProgress)
3782
+ loadImage = loadImageWithProgress;
3776
3783
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function* () {
3777
- return yield Platform.origin.loadImage(this.url).then(img => this.setView(img)).catch((e) => {
3784
+ return yield loadImage(this.url, onProgress).then(img => this.setView(img)).catch((e) => {
3778
3785
  this.error = e;
3779
3786
  this.onComplete(false);
3780
3787
  });
@@ -3799,6 +3806,9 @@ var LeaferUI = (function (exports) {
3799
3806
  this.view = img;
3800
3807
  this.onComplete(true);
3801
3808
  }
3809
+ onProgress(progress) {
3810
+ this.progress = progress;
3811
+ }
3802
3812
  onComplete(isSuccess) {
3803
3813
  let odd;
3804
3814
  this.waitComplete.forEach((item, index) => {
@@ -4264,13 +4274,20 @@ var LeaferUI = (function (exports) {
4264
4274
  if (leaf.isBranch) {
4265
4275
  const { children } = leaf;
4266
4276
  for (let i = 0, len = children.length; i < len; i++) {
4267
- updateAllWorldOpacity$1(children[i]);
4277
+ updateAllWorldOpacity(children[i]);
4268
4278
  }
4269
4279
  }
4270
4280
  },
4271
- updateAllChange(leaf) {
4272
- updateAllWorldOpacity$1(leaf);
4281
+ updateChange(leaf) {
4282
+ const layout = leaf.__layout;
4283
+ if (layout.stateStyleChanged)
4284
+ leaf.updateState();
4285
+ if (layout.opacityChanged)
4286
+ updateAllWorldOpacity(leaf);
4273
4287
  leaf.__updateChange();
4288
+ },
4289
+ updateAllChange(leaf) {
4290
+ updateChange$1(leaf);
4274
4291
  if (leaf.isBranch) {
4275
4292
  const { children } = leaf;
4276
4293
  for (let i = 0, len = children.length; i < len; i++) {
@@ -4406,7 +4423,7 @@ var LeaferUI = (function (exports) {
4406
4423
  }
4407
4424
  };
4408
4425
  const L$1 = LeafHelper;
4409
- const { updateAllMatrix: updateAllMatrix$4, updateMatrix: updateMatrix$3, updateAllWorldOpacity: updateAllWorldOpacity$1, updateAllChange: updateAllChange$1 } = L$1;
4426
+ const { updateAllMatrix: updateAllMatrix$4, updateMatrix: updateMatrix$3, updateAllWorldOpacity, updateAllChange: updateAllChange$1, updateChange: updateChange$1 } = L$1;
4410
4427
  function getTempLocal(t, world) {
4411
4428
  t.__layout.update();
4412
4429
  return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world;
@@ -6128,7 +6145,7 @@ var LeaferUI = (function (exports) {
6128
6145
  }
6129
6146
  }
6130
6147
 
6131
- const version = "1.6.1";
6148
+ const version = "1.6.2";
6132
6149
 
6133
6150
  const debug$5 = Debug.get('LeaferCanvas');
6134
6151
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6494,7 +6511,7 @@ var LeaferUI = (function (exports) {
6494
6511
  }
6495
6512
  }
6496
6513
 
6497
- const { updateAllMatrix: updateAllMatrix$2, updateBounds: updateOneBounds, updateAllWorldOpacity } = LeafHelper;
6514
+ const { updateAllMatrix: updateAllMatrix$2, updateBounds: updateOneBounds, updateChange: updateOneChange } = LeafHelper;
6498
6515
  const { pushAllChildBranch, pushAllParent } = BranchHelper;
6499
6516
  function updateMatrix$1(updateList, levelList) {
6500
6517
  let layout;
@@ -6537,15 +6554,7 @@ var LeaferUI = (function (exports) {
6537
6554
  });
6538
6555
  }
6539
6556
  function updateChange(updateList) {
6540
- let layout;
6541
- updateList.list.forEach(leaf => {
6542
- layout = leaf.__layout;
6543
- if (layout.opacityChanged)
6544
- updateAllWorldOpacity(leaf);
6545
- if (layout.stateStyleChanged)
6546
- setTimeout(() => layout.stateStyleChanged && leaf.updateState());
6547
- leaf.__updateChange();
6548
- });
6557
+ updateList.list.forEach(updateOneChange);
6549
6558
  }
6550
6559
 
6551
6560
  const { worldBounds } = LeafBoundsHelper;
@@ -7390,13 +7399,11 @@ var LeaferUI = (function (exports) {
7390
7399
  setFontWeight(value) {
7391
7400
  if (typeof value === 'string') {
7392
7401
  this.__setInput('fontWeight', value);
7393
- this._fontWeight = fontWeightMap[value] || 400;
7394
- }
7395
- else {
7396
- if (this.__input)
7397
- this.__removeInput('fontWeight');
7398
- this._fontWeight = value;
7402
+ value = fontWeightMap[value] || 400;
7399
7403
  }
7404
+ else if (this.__input)
7405
+ this.__removeInput('fontWeight');
7406
+ this._fontWeight = value;
7400
7407
  }
7401
7408
  setBoxStyle(value) {
7402
7409
  let t = this.__leaf, box = t.__box;
@@ -7723,6 +7730,9 @@ var LeaferUI = (function (exports) {
7723
7730
  else
7724
7731
  drawer.rect(x, y, width, height);
7725
7732
  }
7733
+ drawImagePlaceholder(canvas, _image) {
7734
+ Paint.fill(this.__.placeholderColor, this, canvas);
7735
+ }
7726
7736
  animate(_keyframe, _options, _type, _isTemp) {
7727
7737
  return Plugin.need('animate');
7728
7738
  }
@@ -7959,6 +7969,9 @@ var LeaferUI = (function (exports) {
7959
7969
  __decorate([
7960
7970
  effectType()
7961
7971
  ], exports.UI.prototype, "filter", void 0);
7972
+ __decorate([
7973
+ surfaceType()
7974
+ ], exports.UI.prototype, "placeholderColor", void 0);
7962
7975
  __decorate([
7963
7976
  dataType({})
7964
7977
  ], exports.UI.prototype, "data", void 0);
@@ -8789,10 +8802,11 @@ var LeaferUI = (function (exports) {
8789
8802
  get ready() { return this.image ? this.image.ready : false; }
8790
8803
  constructor(data) {
8791
8804
  super(data);
8792
- this.on(ImageEvent.LOADED, (e) => {
8793
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8794
- this.image = e.image;
8795
- });
8805
+ this.on_(ImageEvent.LOADED, this.__onLoaded, this);
8806
+ }
8807
+ __onLoaded(e) {
8808
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
8809
+ this.image = e.image;
8796
8810
  }
8797
8811
  destroy() {
8798
8812
  this.image = null;
@@ -8906,7 +8920,7 @@ var LeaferUI = (function (exports) {
8906
8920
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8907
8921
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8908
8922
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8909
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8923
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8910
8924
  }
8911
8925
  __updateBoxBounds() {
8912
8926
  const data = this.__;
@@ -9004,6 +9018,9 @@ var LeaferUI = (function (exports) {
9004
9018
  __decorate([
9005
9019
  boundsType('')
9006
9020
  ], exports.Text.prototype, "text", void 0);
9021
+ __decorate([
9022
+ boundsType('')
9023
+ ], exports.Text.prototype, "placeholder", void 0);
9007
9024
  __decorate([
9008
9025
  boundsType('caption')
9009
9026
  ], exports.Text.prototype, "fontFamily", void 0);
@@ -10738,8 +10755,10 @@ var LeaferUI = (function (exports) {
10738
10755
  }
10739
10756
 
10740
10757
  function fillText(ui, canvas) {
10741
- let row, data = ui.__.__textDrawData;
10742
- const { rows, decorationY } = data;
10758
+ const data = ui.__, { rows, decorationY } = data.__textDrawData;
10759
+ if (data.__isPlacehold && data.placeholderColor)
10760
+ canvas.fillStyle = data.placeholderColor;
10761
+ let row;
10743
10762
  for (let i = 0, len = rows.length; i < len; i++) {
10744
10763
  row = rows[i];
10745
10764
  if (row.text)
@@ -10748,7 +10767,7 @@ var LeaferUI = (function (exports) {
10748
10767
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
10749
10768
  }
10750
10769
  if (decorationY) {
10751
- const { decorationColor, decorationHeight } = data;
10770
+ const { decorationColor, decorationHeight } = data.__textDrawData;
10752
10771
  if (decorationColor)
10753
10772
  canvas.fillStyle = decorationColor;
10754
10773
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -10757,38 +10776,44 @@ var LeaferUI = (function (exports) {
10757
10776
 
10758
10777
  function fill(fill, ui, canvas) {
10759
10778
  canvas.fillStyle = fill;
10760
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10779
+ fillPathOrText(ui, canvas);
10761
10780
  }
10762
10781
  function fills(fills, ui, canvas) {
10763
10782
  let item;
10764
- const { windingRule, __font } = ui.__;
10765
10783
  for (let i = 0, len = fills.length; i < len; i++) {
10766
10784
  item = fills[i];
10767
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
10768
- continue;
10769
- if (item.style) {
10770
- canvas.fillStyle = item.style;
10771
- if (item.transform) {
10772
- canvas.save();
10773
- canvas.transform(item.transform);
10774
- if (item.blendMode)
10775
- canvas.blendMode = item.blendMode;
10776
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10777
- canvas.restore();
10785
+ if (item.image) {
10786
+ if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
10787
+ continue;
10788
+ if (!item.style) {
10789
+ if (!i && item.image.isPlacehold)
10790
+ ui.drawImagePlaceholder(canvas, item.image);
10791
+ continue;
10778
10792
  }
10779
- else {
10780
- if (item.blendMode) {
10781
- canvas.saveBlendMode(item.blendMode);
10782
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10783
- canvas.restoreBlendMode();
10784
- }
10785
- else {
10786
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10787
- }
10793
+ }
10794
+ canvas.fillStyle = item.style;
10795
+ if (item.transform) {
10796
+ canvas.save();
10797
+ canvas.transform(item.transform);
10798
+ if (item.blendMode)
10799
+ canvas.blendMode = item.blendMode;
10800
+ fillPathOrText(ui, canvas);
10801
+ canvas.restore();
10802
+ }
10803
+ else {
10804
+ if (item.blendMode) {
10805
+ canvas.saveBlendMode(item.blendMode);
10806
+ fillPathOrText(ui, canvas);
10807
+ canvas.restoreBlendMode();
10788
10808
  }
10809
+ else
10810
+ fillPathOrText(ui, canvas);
10789
10811
  }
10790
10812
  }
10791
10813
  }
10814
+ function fillPathOrText(ui, canvas) {
10815
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10816
+ }
10792
10817
 
10793
10818
  function strokeText(stroke, ui, canvas) {
10794
10819
  const { strokeAlign } = ui.__;
@@ -11028,6 +11053,7 @@ var LeaferUI = (function (exports) {
11028
11053
  compute,
11029
11054
  fill,
11030
11055
  fills,
11056
+ fillPathOrText,
11031
11057
  fillText,
11032
11058
  stroke,
11033
11059
  strokes,
@@ -11220,6 +11246,13 @@ var LeaferUI = (function (exports) {
11220
11246
  onLoadError(ui, event, error);
11221
11247
  leafPaint.loadId = null;
11222
11248
  });
11249
+ if (ui.placeholderColor)
11250
+ setTimeout(() => {
11251
+ if (!(image.ready || image.isPlacehold)) {
11252
+ image.isPlacehold = true;
11253
+ ui.forceUpdate('surface');
11254
+ }
11255
+ }, 100);
11223
11256
  }
11224
11257
  return leafPaint;
11225
11258
  }
@@ -12419,7 +12452,10 @@ var LeaferUI = (function (exports) {
12419
12452
  return decorateLeafAttr(defaultValue, (key) => attr({
12420
12453
  set(value) {
12421
12454
  this.__setAttr(key, value);
12422
- this.waitLeafer(() => styleName ? State.setStyleName(this, styleName, value) : State.set(this, value));
12455
+ if (this.leaferIsReady)
12456
+ styleName ? State.setStyleName(this, styleName, value) : State.set(this, value);
12457
+ else
12458
+ this.__layout.stateStyleChanged = true;
12423
12459
  }
12424
12460
  }));
12425
12461
  }
@@ -12516,6 +12552,9 @@ var LeaferUI = (function (exports) {
12516
12552
  const selectedStyle = style.selectedStyle || leaf.selectedStyle;
12517
12553
  if (selectedStyle && State.isSelected(leaf, button))
12518
12554
  exist = assign(style, selectedStyle);
12555
+ const placeholderStyle = style.placeholderStyle || leaf.placeholderStyle;
12556
+ if (placeholderStyle && State.isPlacehold(leaf, button))
12557
+ exist = assign(style, placeholderStyle);
12519
12558
  if (State.isDisabled(leaf, button)) {
12520
12559
  const disabledStyle = style.disabledStyle || leaf.disabledStyle;
12521
12560
  if (disabledStyle)
@@ -12695,12 +12734,14 @@ var LeaferUI = (function (exports) {
12695
12734
  transitionOut: 1,
12696
12735
  states: 1,
12697
12736
  state: 1,
12737
+ placeholder: 1,
12698
12738
  normalStyle: 1,
12699
12739
  hoverStyle: 1,
12700
12740
  pressStyle: 1,
12701
12741
  focusStyle: 1,
12702
12742
  selectedStyle: 1,
12703
- disabledStyle: 1
12743
+ disabledStyle: 1,
12744
+ placeholderStyle: 1
12704
12745
  };
12705
12746
  State.isState = function (state, leaf, button) { return checkState(state, leaf, button); };
12706
12747
  State.isSelected = function (leaf, button) { return checkFixedState('selected', leaf, button); };
@@ -12708,6 +12749,7 @@ var LeaferUI = (function (exports) {
12708
12749
  State.isFocus = function (leaf, button) { return checkPointerState('isFocus', leaf, button); };
12709
12750
  State.isHover = function (leaf, button) { return checkPointerState('isHover', leaf, button); };
12710
12751
  State.isPress = function (leaf, button) { return checkPointerState('isPress', leaf, button); };
12752
+ State.isPlacehold = function (leaf, _button) { return leaf.__.__isPlacehold; };
12711
12753
  State.isDrag = function (leaf, button) { return checkPointerState('isDrag', leaf, button); };
12712
12754
  State.setStyleName = function (leaf, stateType, value) { value ? setState(leaf, stateType, leaf[stateType]) : unsetState(leaf, stateType, leaf[stateType]); };
12713
12755
  State.set = function (leaf, stateName) { const style = leaf.states[stateName]; style ? setState(leaf, stateName, style) : unsetState(leaf, stateName, style); };
@@ -12725,6 +12767,7 @@ var LeaferUI = (function (exports) {
12725
12767
  exports.UI.addAttr('focusStyle', undefined, stateStyleType);
12726
12768
  exports.UI.addAttr('selectedStyle', undefined, stateStyleType);
12727
12769
  exports.UI.addAttr('disabledStyle', undefined, stateStyleType);
12770
+ exports.UI.addAttr('placeholderStyle', undefined, stateStyleType);
12728
12771
  exports.UI.addAttr('button', false, dataType);
12729
12772
  ui$3.focus = function (value = true) {
12730
12773
  this.waitLeafer(() => {
@@ -12743,6 +12786,15 @@ var LeaferUI = (function (exports) {
12743
12786
  ui$3.updateState = function () {
12744
12787
  State.updateStyle(this, undefined, 'in');
12745
12788
  };
12789
+ const text = exports.Text.prototype, textKey = 'text';
12790
+ defineKey(text, textKey, Object.assign(Object.assign({}, getDescriptor(text, textKey)), { set(value) {
12791
+ const t = this, oldValue = t.text;
12792
+ if (t.__setAttr(textKey, value)) {
12793
+ doBoundsType(t);
12794
+ if (t.placeholderStyle && t.placeholder && (oldValue === '' || value === ''))
12795
+ t.__layout.stateStyleChanged = true;
12796
+ }
12797
+ } }));
12746
12798
 
12747
12799
  const { cos, sin, pow, sqrt: sqrt$1, abs, ceil, floor, round: round$2, PI } = Math;
12748
12800
  const PIx5 = PI * 5;
@@ -13797,6 +13849,7 @@ var LeaferUI = (function (exports) {
13797
13849
  const gaussNodes = [0.1488743389, 0.4333953941, 0.6794095682, 0.8650633666, 0.9739065285];
13798
13850
  const gaussWeights = [0.2955242247, 0.2692667193, 0.2190863625, 0.1494513491, 0.0666713443];
13799
13851
  const { sqrt } = Math;
13852
+ const { getDerivative } = BezierHelper;
13800
13853
  const HighBezierHelper = {
13801
13854
  getDistance(fromX, fromY, x1, y1, x2, y2, toX, toY, t = 1) {
13802
13855
  let distance = 0, t1, t2, d1X, d1Y, d2X, d2Y, half = t / 2;
@@ -13811,10 +13864,6 @@ var LeaferUI = (function (exports) {
13811
13864
  }
13812
13865
  return distance * half;
13813
13866
  },
13814
- getDerivative(t, fromV, v1, v2, toV) {
13815
- const o = 1 - t;
13816
- return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
13817
- },
13818
13867
  getRotation(t, fromX, fromY, x1, y1, x2, y2, toX, toY) {
13819
13868
  const dx = getDerivative(t, fromX, x1, x2, toX);
13820
13869
  const dy = getDerivative(t, fromY, y1, y2, toY);
@@ -13843,7 +13892,7 @@ var LeaferUI = (function (exports) {
13843
13892
  data.push(PathCommandMap.C, ax, ay, bx, by, cx, cy);
13844
13893
  }
13845
13894
  };
13846
- const { getDerivative, getDistance } = HighBezierHelper;
13895
+ const { getDistance } = HighBezierHelper;
13847
13896
 
13848
13897
  const { M, L, C, Z } = PathCommandMap;
13849
13898
  const tempPoint = {}, tempFrom = {};
@@ -14466,4 +14515,7 @@ var LeaferUI = (function (exports) {
14466
14515
  return exports;
14467
14516
 
14468
14517
  })({});
14469
- //# sourceMappingURL=web.js.map
14518
+
14519
+ function Leafer(opt) { return new LeaferUI.Leafer(opt); }
14520
+ Object.setPrototypeOf(Leafer, LeaferUI);
14521
+ Leafer.prototype = LeaferUI.Leafer.prototype;