@leafer-draw/miniapp 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.
@@ -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.1";
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;
@@ -7188,13 +7197,11 @@ class TextData extends UIData {
7188
7197
  setFontWeight(value) {
7189
7198
  if (typeof value === 'string') {
7190
7199
  this.__setInput('fontWeight', value);
7191
- this._fontWeight = fontWeightMap[value] || 400;
7192
- }
7193
- else {
7194
- if (this.__input)
7195
- this.__removeInput('fontWeight');
7196
- this._fontWeight = value;
7200
+ value = fontWeightMap[value] || 400;
7197
7201
  }
7202
+ else if (this.__input)
7203
+ this.__removeInput('fontWeight');
7204
+ this._fontWeight = value;
7198
7205
  }
7199
7206
  setBoxStyle(value) {
7200
7207
  let t = this.__leaf, box = t.__box;
@@ -7521,6 +7528,9 @@ let UI = UI_1 = class UI extends Leaf {
7521
7528
  else
7522
7529
  drawer.rect(x, y, width, height);
7523
7530
  }
7531
+ drawImagePlaceholder(canvas, _image) {
7532
+ Paint.fill(this.__.placeholderColor, this, canvas);
7533
+ }
7524
7534
  animate(_keyframe, _options, _type, _isTemp) {
7525
7535
  return Plugin.need('animate');
7526
7536
  }
@@ -7757,6 +7767,9 @@ __decorate([
7757
7767
  __decorate([
7758
7768
  effectType()
7759
7769
  ], UI.prototype, "filter", void 0);
7770
+ __decorate([
7771
+ surfaceType()
7772
+ ], UI.prototype, "placeholderColor", void 0);
7760
7773
  __decorate([
7761
7774
  dataType({})
7762
7775
  ], UI.prototype, "data", void 0);
@@ -8587,10 +8600,11 @@ let Image = class Image extends Rect {
8587
8600
  get ready() { return this.image ? this.image.ready : false; }
8588
8601
  constructor(data) {
8589
8602
  super(data);
8590
- this.on(ImageEvent.LOADED, (e) => {
8591
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8592
- this.image = e.image;
8593
- });
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;
8594
8608
  }
8595
8609
  destroy() {
8596
8610
  this.image = null;
@@ -8704,7 +8718,7 @@ let Text = class Text extends UI {
8704
8718
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8705
8719
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8706
8720
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8707
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8721
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8708
8722
  }
8709
8723
  __updateBoxBounds() {
8710
8724
  const data = this.__;
@@ -8802,6 +8816,9 @@ __decorate([
8802
8816
  __decorate([
8803
8817
  boundsType('')
8804
8818
  ], Text.prototype, "text", void 0);
8819
+ __decorate([
8820
+ boundsType('')
8821
+ ], Text.prototype, "placeholder", void 0);
8805
8822
  __decorate([
8806
8823
  boundsType('caption')
8807
8824
  ], Text.prototype, "fontFamily", void 0);
@@ -8921,8 +8938,10 @@ function penPathType() {
8921
8938
  }
8922
8939
 
8923
8940
  function fillText(ui, canvas) {
8924
- let row, data = ui.__.__textDrawData;
8925
- 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;
8926
8945
  for (let i = 0, len = rows.length; i < len; i++) {
8927
8946
  row = rows[i];
8928
8947
  if (row.text)
@@ -8931,7 +8950,7 @@ function fillText(ui, canvas) {
8931
8950
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8932
8951
  }
8933
8952
  if (decorationY) {
8934
- const { decorationColor, decorationHeight } = data;
8953
+ const { decorationColor, decorationHeight } = data.__textDrawData;
8935
8954
  if (decorationColor)
8936
8955
  canvas.fillStyle = decorationColor;
8937
8956
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -8940,38 +8959,44 @@ function fillText(ui, canvas) {
8940
8959
 
8941
8960
  function fill(fill, ui, canvas) {
8942
8961
  canvas.fillStyle = fill;
8943
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
8962
+ fillPathOrText(ui, canvas);
8944
8963
  }
8945
8964
  function fills(fills, ui, canvas) {
8946
8965
  let item;
8947
- const { windingRule, __font } = ui.__;
8948
8966
  for (let i = 0, len = fills.length; i < len; i++) {
8949
8967
  item = fills[i];
8950
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
8951
- continue;
8952
- if (item.style) {
8953
- canvas.fillStyle = item.style;
8954
- if (item.transform) {
8955
- canvas.save();
8956
- canvas.transform(item.transform);
8957
- if (item.blendMode)
8958
- canvas.blendMode = item.blendMode;
8959
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8960
- 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;
8961
8975
  }
8962
- else {
8963
- if (item.blendMode) {
8964
- canvas.saveBlendMode(item.blendMode);
8965
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8966
- canvas.restoreBlendMode();
8967
- }
8968
- else {
8969
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8970
- }
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();
8971
8991
  }
8992
+ else
8993
+ fillPathOrText(ui, canvas);
8972
8994
  }
8973
8995
  }
8974
8996
  }
8997
+ function fillPathOrText(ui, canvas) {
8998
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
8999
+ }
8975
9000
 
8976
9001
  function strokeText(stroke, ui, canvas) {
8977
9002
  const { strokeAlign } = ui.__;
@@ -9211,6 +9236,7 @@ const PaintModule = {
9211
9236
  compute,
9212
9237
  fill,
9213
9238
  fills,
9239
+ fillPathOrText,
9214
9240
  fillText,
9215
9241
  stroke,
9216
9242
  strokes,
@@ -9403,6 +9429,13 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
9403
9429
  onLoadError(ui, event, error);
9404
9430
  leafPaint.loadId = null;
9405
9431
  });
9432
+ if (ui.placeholderColor)
9433
+ setTimeout(() => {
9434
+ if (!(image.ready || image.isPlacehold)) {
9435
+ image.isPlacehold = true;
9436
+ ui.forceUpdate('surface');
9437
+ }
9438
+ }, 100);
9406
9439
  }
9407
9440
  return leafPaint;
9408
9441
  }
@@ -10440,4 +10473,3 @@ try {
10440
10473
  catch (_a) { }
10441
10474
 
10442
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 };
10443
- //# sourceMappingURL=miniapp.module.js.map