@leafer-ui/miniapp 1.6.0 → 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.
@@ -2589,7 +2589,11 @@ const BezierHelper = {
2589
2589
  const point = {};
2590
2590
  getPointAndSet(t, fromX, fromY, x1, y1, x2, y2, toX, toY, point);
2591
2591
  return point;
2592
- }
2592
+ },
2593
+ getDerivative(t, fromV, v1, v2, toV) {
2594
+ const o = 1 - t;
2595
+ return 3 * o * o * (v1 - fromV) + 6 * o * t * (v2 - v1) + 3 * t * t * (toV - v2);
2596
+ },
2593
2597
  };
2594
2598
  const { getPointAndSet, toTwoPointBounds: toTwoPointBounds$1, ellipse: ellipse$6 } = BezierHelper;
2595
2599
 
@@ -3770,8 +3774,11 @@ class LeaferImage {
3770
3774
  load(onSuccess, onError) {
3771
3775
  if (!this.loading) {
3772
3776
  this.loading = true;
3777
+ let { loadImage, loadImageWithProgress } = Platform.origin, onProgress = this.config.showProgress && loadImageWithProgress && this.onProgress.bind(this);
3778
+ if (onProgress)
3779
+ loadImage = loadImageWithProgress;
3773
3780
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function* () {
3774
- return yield Platform.origin.loadImage(this.url).then(img => this.setView(img)).catch((e) => {
3781
+ return yield loadImage(this.url, onProgress).then(img => this.setView(img)).catch((e) => {
3775
3782
  this.error = e;
3776
3783
  this.onComplete(false);
3777
3784
  });
@@ -3796,6 +3803,9 @@ class LeaferImage {
3796
3803
  this.view = img;
3797
3804
  this.onComplete(true);
3798
3805
  }
3806
+ onProgress(progress) {
3807
+ this.progress = progress;
3808
+ }
3799
3809
  onComplete(isSuccess) {
3800
3810
  let odd;
3801
3811
  this.waitComplete.forEach((item, index) => {
@@ -4261,13 +4271,20 @@ const LeafHelper = {
4261
4271
  if (leaf.isBranch) {
4262
4272
  const { children } = leaf;
4263
4273
  for (let i = 0, len = children.length; i < len; i++) {
4264
- updateAllWorldOpacity$1(children[i]);
4274
+ updateAllWorldOpacity(children[i]);
4265
4275
  }
4266
4276
  }
4267
4277
  },
4268
- updateAllChange(leaf) {
4269
- updateAllWorldOpacity$1(leaf);
4278
+ updateChange(leaf) {
4279
+ const layout = leaf.__layout;
4280
+ if (layout.stateStyleChanged)
4281
+ leaf.updateState();
4282
+ if (layout.opacityChanged)
4283
+ updateAllWorldOpacity(leaf);
4270
4284
  leaf.__updateChange();
4285
+ },
4286
+ updateAllChange(leaf) {
4287
+ updateChange$1(leaf);
4271
4288
  if (leaf.isBranch) {
4272
4289
  const { children } = leaf;
4273
4290
  for (let i = 0, len = children.length; i < len; i++) {
@@ -4403,7 +4420,7 @@ const LeafHelper = {
4403
4420
  }
4404
4421
  };
4405
4422
  const L = LeafHelper;
4406
- const { updateAllMatrix: updateAllMatrix$3, updateMatrix: updateMatrix$2, updateAllWorldOpacity: updateAllWorldOpacity$1, updateAllChange: updateAllChange$1 } = L;
4423
+ const { updateAllMatrix: updateAllMatrix$3, updateMatrix: updateMatrix$2, updateAllWorldOpacity, updateAllChange: updateAllChange$1, updateChange: updateChange$1 } = L;
4407
4424
  function getTempLocal(t, world) {
4408
4425
  t.__layout.update();
4409
4426
  return t.parent ? PointHelper.tempToInnerOf(world, t.parent.__world) : world;
@@ -6125,7 +6142,7 @@ class LeafLevelList {
6125
6142
  }
6126
6143
  }
6127
6144
 
6128
- const version = "1.6.0";
6145
+ const version = "1.6.2";
6129
6146
 
6130
6147
  class LeaferCanvas extends LeaferCanvasBase {
6131
6148
  get allowBackgroundColor() { return false; }
@@ -6449,7 +6466,7 @@ class Watcher {
6449
6466
  }
6450
6467
  }
6451
6468
 
6452
- const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateAllWorldOpacity } = LeafHelper;
6469
+ const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateChange: updateOneChange } = LeafHelper;
6453
6470
  const { pushAllChildBranch, pushAllParent } = BranchHelper;
6454
6471
  function updateMatrix(updateList, levelList) {
6455
6472
  let layout;
@@ -6492,15 +6509,7 @@ function updateBounds(boundsList) {
6492
6509
  });
6493
6510
  }
6494
6511
  function updateChange(updateList) {
6495
- let layout;
6496
- updateList.list.forEach(leaf => {
6497
- layout = leaf.__layout;
6498
- if (layout.opacityChanged)
6499
- updateAllWorldOpacity(leaf);
6500
- if (layout.stateStyleChanged)
6501
- setTimeout(() => layout.stateStyleChanged && leaf.updateState());
6502
- leaf.__updateChange();
6503
- });
6512
+ updateList.list.forEach(updateOneChange);
6504
6513
  }
6505
6514
 
6506
6515
  const { worldBounds } = LeafBoundsHelper;
@@ -6721,6 +6730,15 @@ class Renderer {
6721
6730
  }
6722
6731
  checkRender() {
6723
6732
  if (this.running) {
6733
+ const { target } = this;
6734
+ if (target.isApp) {
6735
+ target.emit(RenderEvent.CHILD_START, target);
6736
+ target.children.forEach(leafer => {
6737
+ leafer.renderer.FPS = this.FPS;
6738
+ leafer.renderer.checkRender();
6739
+ });
6740
+ target.emit(RenderEvent.CHILD_END, target);
6741
+ }
6724
6742
  if (this.changed && this.canvas.view)
6725
6743
  this.render();
6726
6744
  this.target.emit(RenderEvent.NEXT);
@@ -6806,7 +6824,7 @@ class Renderer {
6806
6824
  bounds.spread(Renderer.clipSpread).ceil();
6807
6825
  canvas.clearWorld(bounds, true);
6808
6826
  canvas.clipWorld(bounds, true);
6809
- this.__render(bounds, block.includes(this.target.__world), realBounds);
6827
+ this.__render(bounds, realBounds);
6810
6828
  canvas.restore();
6811
6829
  Run.end(t);
6812
6830
  }
@@ -6815,12 +6833,12 @@ class Renderer {
6815
6833
  const { canvas } = this;
6816
6834
  canvas.save();
6817
6835
  canvas.clear();
6818
- this.__render(canvas.bounds, true);
6836
+ this.__render(canvas.bounds);
6819
6837
  canvas.restore();
6820
6838
  Run.end(t);
6821
6839
  }
6822
- __render(bounds, includes, realBounds) {
6823
- const { canvas } = this, options = includes ? { includes } : { bounds, includes };
6840
+ __render(bounds, realBounds) {
6841
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
6824
6842
  if (this.needFill)
6825
6843
  canvas.fillWorld(bounds, this.config.fill);
6826
6844
  if (Debug.showRepaint)
@@ -6847,22 +6865,14 @@ class Renderer {
6847
6865
  }
6848
6866
  __requestRender() {
6849
6867
  const target = this.target;
6850
- if (target.parentApp)
6851
- return target.parentApp.renderer.update(false);
6852
- if (this.requestTime)
6868
+ if (this.requestTime || !target)
6853
6869
  return;
6870
+ if (target.parentApp)
6871
+ return target.parentApp.requestRender(false);
6854
6872
  const requestTime = this.requestTime = Date.now();
6855
6873
  Platform.requestRender(() => {
6856
6874
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6857
6875
  this.requestTime = 0;
6858
- if (target.isApp) {
6859
- target.emit(RenderEvent.CHILD_START, target);
6860
- target.children.forEach(leafer => {
6861
- leafer.renderer.FPS = this.FPS;
6862
- leafer.renderer.checkRender();
6863
- });
6864
- target.emit(RenderEvent.CHILD_END, target);
6865
- }
6866
6876
  this.checkRender();
6867
6877
  });
6868
6878
  }
@@ -7344,13 +7354,11 @@ class TextData extends UIData {
7344
7354
  setFontWeight(value) {
7345
7355
  if (typeof value === 'string') {
7346
7356
  this.__setInput('fontWeight', value);
7347
- this._fontWeight = fontWeightMap[value] || 400;
7348
- }
7349
- else {
7350
- if (this.__input)
7351
- this.__removeInput('fontWeight');
7352
- this._fontWeight = value;
7357
+ value = fontWeightMap[value] || 400;
7353
7358
  }
7359
+ else if (this.__input)
7360
+ this.__removeInput('fontWeight');
7361
+ this._fontWeight = value;
7354
7362
  }
7355
7363
  setBoxStyle(value) {
7356
7364
  let t = this.__leaf, box = t.__box;
@@ -7677,6 +7685,9 @@ let UI = UI_1 = class UI extends Leaf {
7677
7685
  else
7678
7686
  drawer.rect(x, y, width, height);
7679
7687
  }
7688
+ drawImagePlaceholder(canvas, _image) {
7689
+ Paint.fill(this.__.placeholderColor, this, canvas);
7690
+ }
7680
7691
  animate(_keyframe, _options, _type, _isTemp) {
7681
7692
  return Plugin.need('animate');
7682
7693
  }
@@ -7913,6 +7924,9 @@ __decorate([
7913
7924
  __decorate([
7914
7925
  effectType()
7915
7926
  ], UI.prototype, "filter", void 0);
7927
+ __decorate([
7928
+ surfaceType()
7929
+ ], UI.prototype, "placeholderColor", void 0);
7916
7930
  __decorate([
7917
7931
  dataType({})
7918
7932
  ], UI.prototype, "data", void 0);
@@ -8743,10 +8757,11 @@ let Image = class Image extends Rect {
8743
8757
  get ready() { return this.image ? this.image.ready : false; }
8744
8758
  constructor(data) {
8745
8759
  super(data);
8746
- this.on(ImageEvent.LOADED, (e) => {
8747
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8748
- this.image = e.image;
8749
- });
8760
+ this.on_(ImageEvent.LOADED, this.__onLoaded, this);
8761
+ }
8762
+ __onLoaded(e) {
8763
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
8764
+ this.image = e.image;
8750
8765
  }
8751
8766
  destroy() {
8752
8767
  this.image = null;
@@ -8860,7 +8875,7 @@ let Text = class Text extends UI {
8860
8875
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8861
8876
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8862
8877
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8863
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8878
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8864
8879
  }
8865
8880
  __updateBoxBounds() {
8866
8881
  const data = this.__;
@@ -8958,6 +8973,9 @@ __decorate([
8958
8973
  __decorate([
8959
8974
  boundsType('')
8960
8975
  ], Text.prototype, "text", void 0);
8976
+ __decorate([
8977
+ boundsType('')
8978
+ ], Text.prototype, "placeholder", void 0);
8961
8979
  __decorate([
8962
8980
  boundsType('caption')
8963
8981
  ], Text.prototype, "fontFamily", void 0);
@@ -9833,8 +9851,7 @@ class InteractionBase {
9833
9851
  if (this.downData) {
9834
9852
  const canDrag = PointHelper.getDistance(this.downData, data) > this.p.dragDistance;
9835
9853
  if (canDrag) {
9836
- if (this.waitTap || this.longPressTimer)
9837
- this.pointerWaitCancel();
9854
+ this.pointerWaitCancel();
9838
9855
  this.waitRightTap = false;
9839
9856
  }
9840
9857
  this.dragger.checkDrag(data, canDrag);
@@ -10116,9 +10133,11 @@ class InteractionBase {
10116
10133
  this.waitTap = true;
10117
10134
  }
10118
10135
  tapWaitCancel() {
10119
- clearTimeout(this.tapTimer);
10120
- this.waitTap = false;
10121
- this.tapCount = 0;
10136
+ if (this.waitTap) {
10137
+ clearTimeout(this.tapTimer);
10138
+ this.waitTap = false;
10139
+ this.tapCount = 0;
10140
+ }
10122
10141
  }
10123
10142
  longPressWait(data) {
10124
10143
  clearTimeout(this.longPressTimer);
@@ -10138,8 +10157,10 @@ class InteractionBase {
10138
10157
  return hasLong;
10139
10158
  }
10140
10159
  longPressWaitCancel() {
10141
- clearTimeout(this.longPressTimer);
10142
- this.longPressed = false;
10160
+ if (this.longPressTimer) {
10161
+ clearTimeout(this.longPressTimer);
10162
+ this.longPressed = false;
10163
+ }
10143
10164
  }
10144
10165
  __onResize() {
10145
10166
  const { dragOut } = this.m;
@@ -10485,8 +10506,10 @@ class Interaction extends InteractionBase {
10485
10506
  }
10486
10507
 
10487
10508
  function fillText(ui, canvas) {
10488
- let row, data = ui.__.__textDrawData;
10489
- const { rows, decorationY } = data;
10509
+ const data = ui.__, { rows, decorationY } = data.__textDrawData;
10510
+ if (data.__isPlacehold && data.placeholderColor)
10511
+ canvas.fillStyle = data.placeholderColor;
10512
+ let row;
10490
10513
  for (let i = 0, len = rows.length; i < len; i++) {
10491
10514
  row = rows[i];
10492
10515
  if (row.text)
@@ -10495,7 +10518,7 @@ function fillText(ui, canvas) {
10495
10518
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
10496
10519
  }
10497
10520
  if (decorationY) {
10498
- const { decorationColor, decorationHeight } = data;
10521
+ const { decorationColor, decorationHeight } = data.__textDrawData;
10499
10522
  if (decorationColor)
10500
10523
  canvas.fillStyle = decorationColor;
10501
10524
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -10504,38 +10527,44 @@ function fillText(ui, canvas) {
10504
10527
 
10505
10528
  function fill(fill, ui, canvas) {
10506
10529
  canvas.fillStyle = fill;
10507
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10530
+ fillPathOrText(ui, canvas);
10508
10531
  }
10509
10532
  function fills(fills, ui, canvas) {
10510
10533
  let item;
10511
- const { windingRule, __font } = ui.__;
10512
10534
  for (let i = 0, len = fills.length; i < len; i++) {
10513
10535
  item = fills[i];
10514
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
10515
- continue;
10516
- if (item.style) {
10517
- canvas.fillStyle = item.style;
10518
- if (item.transform) {
10519
- canvas.save();
10520
- canvas.transform(item.transform);
10521
- if (item.blendMode)
10522
- canvas.blendMode = item.blendMode;
10523
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10524
- canvas.restore();
10536
+ if (item.image) {
10537
+ if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
10538
+ continue;
10539
+ if (!item.style) {
10540
+ if (!i && item.image.isPlacehold)
10541
+ ui.drawImagePlaceholder(canvas, item.image);
10542
+ continue;
10525
10543
  }
10526
- else {
10527
- if (item.blendMode) {
10528
- canvas.saveBlendMode(item.blendMode);
10529
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10530
- canvas.restoreBlendMode();
10531
- }
10532
- else {
10533
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10534
- }
10544
+ }
10545
+ canvas.fillStyle = item.style;
10546
+ if (item.transform) {
10547
+ canvas.save();
10548
+ canvas.transform(item.transform);
10549
+ if (item.blendMode)
10550
+ canvas.blendMode = item.blendMode;
10551
+ fillPathOrText(ui, canvas);
10552
+ canvas.restore();
10553
+ }
10554
+ else {
10555
+ if (item.blendMode) {
10556
+ canvas.saveBlendMode(item.blendMode);
10557
+ fillPathOrText(ui, canvas);
10558
+ canvas.restoreBlendMode();
10535
10559
  }
10560
+ else
10561
+ fillPathOrText(ui, canvas);
10536
10562
  }
10537
10563
  }
10538
10564
  }
10565
+ function fillPathOrText(ui, canvas) {
10566
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10567
+ }
10539
10568
 
10540
10569
  function strokeText(stroke, ui, canvas) {
10541
10570
  const { strokeAlign } = ui.__;
@@ -10775,6 +10804,7 @@ const PaintModule = {
10775
10804
  compute,
10776
10805
  fill,
10777
10806
  fills,
10807
+ fillPathOrText,
10778
10808
  fillText,
10779
10809
  stroke,
10780
10810
  strokes,
@@ -10967,6 +10997,13 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
10967
10997
  onLoadError(ui, event, error);
10968
10998
  leafPaint.loadId = null;
10969
10999
  });
11000
+ if (ui.placeholderColor)
11001
+ setTimeout(() => {
11002
+ if (!(image.ready || image.isPlacehold)) {
11003
+ image.isPlacehold = true;
11004
+ ui.forceUpdate('surface');
11005
+ }
11006
+ }, 100);
10970
11007
  }
10971
11008
  return leafPaint;
10972
11009
  }
@@ -12012,4 +12049,3 @@ try {
12012
12049
  catch (_a) { }
12013
12050
 
12014
12051
  export { AlignHelper, Answer, App, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Frame, FrameData, Group, GroupData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, MoveEvent, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, RotateEvent, Run, Selector, Star, StarData, State, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isEmptyData, isNull, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
12015
- //# sourceMappingURL=miniapp.module.js.map