@leafer-draw/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
  }
@@ -7187,13 +7197,11 @@ class TextData extends UIData {
7187
7197
  setFontWeight(value) {
7188
7198
  if (typeof value === 'string') {
7189
7199
  this.__setInput('fontWeight', value);
7190
- this._fontWeight = fontWeightMap[value] || 400;
7191
- }
7192
- else {
7193
- if (this.__input)
7194
- this.__removeInput('fontWeight');
7195
- this._fontWeight = value;
7200
+ value = fontWeightMap[value] || 400;
7196
7201
  }
7202
+ else if (this.__input)
7203
+ this.__removeInput('fontWeight');
7204
+ this._fontWeight = value;
7197
7205
  }
7198
7206
  setBoxStyle(value) {
7199
7207
  let t = this.__leaf, box = t.__box;
@@ -7520,6 +7528,9 @@ let UI = UI_1 = class UI extends Leaf {
7520
7528
  else
7521
7529
  drawer.rect(x, y, width, height);
7522
7530
  }
7531
+ drawImagePlaceholder(canvas, _image) {
7532
+ Paint.fill(this.__.placeholderColor, this, canvas);
7533
+ }
7523
7534
  animate(_keyframe, _options, _type, _isTemp) {
7524
7535
  return Plugin.need('animate');
7525
7536
  }
@@ -7756,6 +7767,9 @@ __decorate([
7756
7767
  __decorate([
7757
7768
  effectType()
7758
7769
  ], UI.prototype, "filter", void 0);
7770
+ __decorate([
7771
+ surfaceType()
7772
+ ], UI.prototype, "placeholderColor", void 0);
7759
7773
  __decorate([
7760
7774
  dataType({})
7761
7775
  ], UI.prototype, "data", void 0);
@@ -8586,10 +8600,11 @@ let Image = class Image extends Rect {
8586
8600
  get ready() { return this.image ? this.image.ready : false; }
8587
8601
  constructor(data) {
8588
8602
  super(data);
8589
- this.on(ImageEvent.LOADED, (e) => {
8590
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8591
- this.image = e.image;
8592
- });
8603
+ this.on_(ImageEvent.LOADED, this.__onLoaded, this);
8604
+ }
8605
+ __onLoaded(e) {
8606
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
8607
+ this.image = e.image;
8593
8608
  }
8594
8609
  destroy() {
8595
8610
  this.image = null;
@@ -8703,7 +8718,7 @@ let Text = class Text extends UI {
8703
8718
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8704
8719
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8705
8720
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8706
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8721
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8707
8722
  }
8708
8723
  __updateBoxBounds() {
8709
8724
  const data = this.__;
@@ -8801,6 +8816,9 @@ __decorate([
8801
8816
  __decorate([
8802
8817
  boundsType('')
8803
8818
  ], Text.prototype, "text", void 0);
8819
+ __decorate([
8820
+ boundsType('')
8821
+ ], Text.prototype, "placeholder", void 0);
8804
8822
  __decorate([
8805
8823
  boundsType('caption')
8806
8824
  ], Text.prototype, "fontFamily", void 0);
@@ -8920,8 +8938,10 @@ function penPathType() {
8920
8938
  }
8921
8939
 
8922
8940
  function fillText(ui, canvas) {
8923
- let row, data = ui.__.__textDrawData;
8924
- const { rows, decorationY } = data;
8941
+ const data = ui.__, { rows, decorationY } = data.__textDrawData;
8942
+ if (data.__isPlacehold && data.placeholderColor)
8943
+ canvas.fillStyle = data.placeholderColor;
8944
+ let row;
8925
8945
  for (let i = 0, len = rows.length; i < len; i++) {
8926
8946
  row = rows[i];
8927
8947
  if (row.text)
@@ -8930,7 +8950,7 @@ function fillText(ui, canvas) {
8930
8950
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8931
8951
  }
8932
8952
  if (decorationY) {
8933
- const { decorationColor, decorationHeight } = data;
8953
+ const { decorationColor, decorationHeight } = data.__textDrawData;
8934
8954
  if (decorationColor)
8935
8955
  canvas.fillStyle = decorationColor;
8936
8956
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -8939,38 +8959,44 @@ function fillText(ui, canvas) {
8939
8959
 
8940
8960
  function fill(fill, ui, canvas) {
8941
8961
  canvas.fillStyle = fill;
8942
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
8962
+ fillPathOrText(ui, canvas);
8943
8963
  }
8944
8964
  function fills(fills, ui, canvas) {
8945
8965
  let item;
8946
- const { windingRule, __font } = ui.__;
8947
8966
  for (let i = 0, len = fills.length; i < len; i++) {
8948
8967
  item = fills[i];
8949
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
8950
- continue;
8951
- if (item.style) {
8952
- canvas.fillStyle = item.style;
8953
- if (item.transform) {
8954
- canvas.save();
8955
- canvas.transform(item.transform);
8956
- if (item.blendMode)
8957
- canvas.blendMode = item.blendMode;
8958
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8959
- canvas.restore();
8968
+ if (item.image) {
8969
+ if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
8970
+ continue;
8971
+ if (!item.style) {
8972
+ if (!i && item.image.isPlacehold)
8973
+ ui.drawImagePlaceholder(canvas, item.image);
8974
+ continue;
8960
8975
  }
8961
- else {
8962
- if (item.blendMode) {
8963
- canvas.saveBlendMode(item.blendMode);
8964
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8965
- canvas.restoreBlendMode();
8966
- }
8967
- else {
8968
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8969
- }
8976
+ }
8977
+ canvas.fillStyle = item.style;
8978
+ if (item.transform) {
8979
+ canvas.save();
8980
+ canvas.transform(item.transform);
8981
+ if (item.blendMode)
8982
+ canvas.blendMode = item.blendMode;
8983
+ fillPathOrText(ui, canvas);
8984
+ canvas.restore();
8985
+ }
8986
+ else {
8987
+ if (item.blendMode) {
8988
+ canvas.saveBlendMode(item.blendMode);
8989
+ fillPathOrText(ui, canvas);
8990
+ canvas.restoreBlendMode();
8970
8991
  }
8992
+ else
8993
+ fillPathOrText(ui, canvas);
8971
8994
  }
8972
8995
  }
8973
8996
  }
8997
+ function fillPathOrText(ui, canvas) {
8998
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
8999
+ }
8974
9000
 
8975
9001
  function strokeText(stroke, ui, canvas) {
8976
9002
  const { strokeAlign } = ui.__;
@@ -9210,6 +9236,7 @@ const PaintModule = {
9210
9236
  compute,
9211
9237
  fill,
9212
9238
  fills,
9239
+ fillPathOrText,
9213
9240
  fillText,
9214
9241
  stroke,
9215
9242
  strokes,
@@ -9402,6 +9429,13 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
9402
9429
  onLoadError(ui, event, error);
9403
9430
  leafPaint.loadId = null;
9404
9431
  });
9432
+ if (ui.placeholderColor)
9433
+ setTimeout(() => {
9434
+ if (!(image.ready || image.isPlacehold)) {
9435
+ image.isPlacehold = true;
9436
+ ui.forceUpdate('surface');
9437
+ }
9438
+ }, 100);
9405
9439
  }
9406
9440
  return leafPaint;
9407
9441
  }
@@ -10439,4 +10473,3 @@ try {
10439
10473
  catch (_a) { }
10440
10474
 
10441
10475
  export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, 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, MyImage, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Plugin, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, 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 };
10442
- //# sourceMappingURL=miniapp.module.js.map