leafer-draw 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
  const debug$4 = Debug.get('LeaferCanvas');
6131
6148
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6491,7 +6508,7 @@ class Watcher {
6491
6508
  }
6492
6509
  }
6493
6510
 
6494
- const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateAllWorldOpacity } = LeafHelper;
6511
+ const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateChange: updateOneChange } = LeafHelper;
6495
6512
  const { pushAllChildBranch, pushAllParent } = BranchHelper;
6496
6513
  function updateMatrix(updateList, levelList) {
6497
6514
  let layout;
@@ -6534,15 +6551,7 @@ function updateBounds(boundsList) {
6534
6551
  });
6535
6552
  }
6536
6553
  function updateChange(updateList) {
6537
- let layout;
6538
- updateList.list.forEach(leaf => {
6539
- layout = leaf.__layout;
6540
- if (layout.opacityChanged)
6541
- updateAllWorldOpacity(leaf);
6542
- if (layout.stateStyleChanged)
6543
- setTimeout(() => layout.stateStyleChanged && leaf.updateState());
6544
- leaf.__updateChange();
6545
- });
6554
+ updateList.list.forEach(updateOneChange);
6546
6555
  }
6547
6556
 
6548
6557
  const { worldBounds } = LeafBoundsHelper;
@@ -6763,6 +6772,15 @@ class Renderer {
6763
6772
  }
6764
6773
  checkRender() {
6765
6774
  if (this.running) {
6775
+ const { target } = this;
6776
+ if (target.isApp) {
6777
+ target.emit(RenderEvent.CHILD_START, target);
6778
+ target.children.forEach(leafer => {
6779
+ leafer.renderer.FPS = this.FPS;
6780
+ leafer.renderer.checkRender();
6781
+ });
6782
+ target.emit(RenderEvent.CHILD_END, target);
6783
+ }
6766
6784
  if (this.changed && this.canvas.view)
6767
6785
  this.render();
6768
6786
  this.target.emit(RenderEvent.NEXT);
@@ -6848,7 +6866,7 @@ class Renderer {
6848
6866
  bounds.spread(Renderer.clipSpread).ceil();
6849
6867
  canvas.clearWorld(bounds, true);
6850
6868
  canvas.clipWorld(bounds, true);
6851
- this.__render(bounds, block.includes(this.target.__world), realBounds);
6869
+ this.__render(bounds, realBounds);
6852
6870
  canvas.restore();
6853
6871
  Run.end(t);
6854
6872
  }
@@ -6857,12 +6875,12 @@ class Renderer {
6857
6875
  const { canvas } = this;
6858
6876
  canvas.save();
6859
6877
  canvas.clear();
6860
- this.__render(canvas.bounds, true);
6878
+ this.__render(canvas.bounds);
6861
6879
  canvas.restore();
6862
6880
  Run.end(t);
6863
6881
  }
6864
- __render(bounds, includes, realBounds) {
6865
- const { canvas } = this, options = includes ? { includes } : { bounds, includes };
6882
+ __render(bounds, realBounds) {
6883
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
6866
6884
  if (this.needFill)
6867
6885
  canvas.fillWorld(bounds, this.config.fill);
6868
6886
  if (Debug.showRepaint)
@@ -6889,22 +6907,14 @@ class Renderer {
6889
6907
  }
6890
6908
  __requestRender() {
6891
6909
  const target = this.target;
6892
- if (target.parentApp)
6893
- return target.parentApp.renderer.update(false);
6894
- if (this.requestTime)
6910
+ if (this.requestTime || !target)
6895
6911
  return;
6912
+ if (target.parentApp)
6913
+ return target.parentApp.requestRender(false);
6896
6914
  const requestTime = this.requestTime = Date.now();
6897
6915
  Platform.requestRender(() => {
6898
6916
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6899
6917
  this.requestTime = 0;
6900
- if (target.isApp) {
6901
- target.emit(RenderEvent.CHILD_START, target);
6902
- target.children.forEach(leafer => {
6903
- leafer.renderer.FPS = this.FPS;
6904
- leafer.renderer.checkRender();
6905
- });
6906
- target.emit(RenderEvent.CHILD_END, target);
6907
- }
6908
6918
  this.checkRender();
6909
6919
  });
6910
6920
  }
@@ -7229,13 +7239,11 @@ class TextData extends UIData {
7229
7239
  setFontWeight(value) {
7230
7240
  if (typeof value === 'string') {
7231
7241
  this.__setInput('fontWeight', value);
7232
- this._fontWeight = fontWeightMap[value] || 400;
7233
- }
7234
- else {
7235
- if (this.__input)
7236
- this.__removeInput('fontWeight');
7237
- this._fontWeight = value;
7242
+ value = fontWeightMap[value] || 400;
7238
7243
  }
7244
+ else if (this.__input)
7245
+ this.__removeInput('fontWeight');
7246
+ this._fontWeight = value;
7239
7247
  }
7240
7248
  setBoxStyle(value) {
7241
7249
  let t = this.__leaf, box = t.__box;
@@ -7562,6 +7570,9 @@ let UI = UI_1 = class UI extends Leaf {
7562
7570
  else
7563
7571
  drawer.rect(x, y, width, height);
7564
7572
  }
7573
+ drawImagePlaceholder(canvas, _image) {
7574
+ Paint.fill(this.__.placeholderColor, this, canvas);
7575
+ }
7565
7576
  animate(_keyframe, _options, _type, _isTemp) {
7566
7577
  return Plugin.need('animate');
7567
7578
  }
@@ -7798,6 +7809,9 @@ __decorate([
7798
7809
  __decorate([
7799
7810
  effectType()
7800
7811
  ], UI.prototype, "filter", void 0);
7812
+ __decorate([
7813
+ surfaceType()
7814
+ ], UI.prototype, "placeholderColor", void 0);
7801
7815
  __decorate([
7802
7816
  dataType({})
7803
7817
  ], UI.prototype, "data", void 0);
@@ -8628,10 +8642,11 @@ let Image$1 = class Image extends Rect {
8628
8642
  get ready() { return this.image ? this.image.ready : false; }
8629
8643
  constructor(data) {
8630
8644
  super(data);
8631
- this.on(ImageEvent.LOADED, (e) => {
8632
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8633
- this.image = e.image;
8634
- });
8645
+ this.on_(ImageEvent.LOADED, this.__onLoaded, this);
8646
+ }
8647
+ __onLoaded(e) {
8648
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
8649
+ this.image = e.image;
8635
8650
  }
8636
8651
  destroy() {
8637
8652
  this.image = null;
@@ -8745,7 +8760,7 @@ let Text = class Text extends UI {
8745
8760
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8746
8761
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8747
8762
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8748
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8763
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8749
8764
  }
8750
8765
  __updateBoxBounds() {
8751
8766
  const data = this.__;
@@ -8843,6 +8858,9 @@ __decorate([
8843
8858
  __decorate([
8844
8859
  boundsType('')
8845
8860
  ], Text.prototype, "text", void 0);
8861
+ __decorate([
8862
+ boundsType('')
8863
+ ], Text.prototype, "placeholder", void 0);
8846
8864
  __decorate([
8847
8865
  boundsType('caption')
8848
8866
  ], Text.prototype, "fontFamily", void 0);
@@ -8962,8 +8980,10 @@ function penPathType() {
8962
8980
  }
8963
8981
 
8964
8982
  function fillText(ui, canvas) {
8965
- let row, data = ui.__.__textDrawData;
8966
- const { rows, decorationY } = data;
8983
+ const data = ui.__, { rows, decorationY } = data.__textDrawData;
8984
+ if (data.__isPlacehold && data.placeholderColor)
8985
+ canvas.fillStyle = data.placeholderColor;
8986
+ let row;
8967
8987
  for (let i = 0, len = rows.length; i < len; i++) {
8968
8988
  row = rows[i];
8969
8989
  if (row.text)
@@ -8972,7 +8992,7 @@ function fillText(ui, canvas) {
8972
8992
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8973
8993
  }
8974
8994
  if (decorationY) {
8975
- const { decorationColor, decorationHeight } = data;
8995
+ const { decorationColor, decorationHeight } = data.__textDrawData;
8976
8996
  if (decorationColor)
8977
8997
  canvas.fillStyle = decorationColor;
8978
8998
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -8981,38 +9001,44 @@ function fillText(ui, canvas) {
8981
9001
 
8982
9002
  function fill(fill, ui, canvas) {
8983
9003
  canvas.fillStyle = fill;
8984
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
9004
+ fillPathOrText(ui, canvas);
8985
9005
  }
8986
9006
  function fills(fills, ui, canvas) {
8987
9007
  let item;
8988
- const { windingRule, __font } = ui.__;
8989
9008
  for (let i = 0, len = fills.length; i < len; i++) {
8990
9009
  item = fills[i];
8991
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
8992
- continue;
8993
- if (item.style) {
8994
- canvas.fillStyle = item.style;
8995
- if (item.transform) {
8996
- canvas.save();
8997
- canvas.transform(item.transform);
8998
- if (item.blendMode)
8999
- canvas.blendMode = item.blendMode;
9000
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
9001
- canvas.restore();
9010
+ if (item.image) {
9011
+ if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
9012
+ continue;
9013
+ if (!item.style) {
9014
+ if (!i && item.image.isPlacehold)
9015
+ ui.drawImagePlaceholder(canvas, item.image);
9016
+ continue;
9002
9017
  }
9003
- else {
9004
- if (item.blendMode) {
9005
- canvas.saveBlendMode(item.blendMode);
9006
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
9007
- canvas.restoreBlendMode();
9008
- }
9009
- else {
9010
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
9011
- }
9018
+ }
9019
+ canvas.fillStyle = item.style;
9020
+ if (item.transform) {
9021
+ canvas.save();
9022
+ canvas.transform(item.transform);
9023
+ if (item.blendMode)
9024
+ canvas.blendMode = item.blendMode;
9025
+ fillPathOrText(ui, canvas);
9026
+ canvas.restore();
9027
+ }
9028
+ else {
9029
+ if (item.blendMode) {
9030
+ canvas.saveBlendMode(item.blendMode);
9031
+ fillPathOrText(ui, canvas);
9032
+ canvas.restoreBlendMode();
9012
9033
  }
9034
+ else
9035
+ fillPathOrText(ui, canvas);
9013
9036
  }
9014
9037
  }
9015
9038
  }
9039
+ function fillPathOrText(ui, canvas) {
9040
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
9041
+ }
9016
9042
 
9017
9043
  function strokeText(stroke, ui, canvas) {
9018
9044
  const { strokeAlign } = ui.__;
@@ -9252,6 +9278,7 @@ const PaintModule = {
9252
9278
  compute,
9253
9279
  fill,
9254
9280
  fills,
9281
+ fillPathOrText,
9255
9282
  fillText,
9256
9283
  stroke,
9257
9284
  strokes,
@@ -9444,6 +9471,13 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
9444
9471
  onLoadError(ui, event, error);
9445
9472
  leafPaint.loadId = null;
9446
9473
  });
9474
+ if (ui.placeholderColor)
9475
+ setTimeout(() => {
9476
+ if (!(image.ready || image.isPlacehold)) {
9477
+ image.isPlacehold = true;
9478
+ ui.forceUpdate('surface');
9479
+ }
9480
+ }, 100);
9447
9481
  }
9448
9482
  return leafPaint;
9449
9483
  }
@@ -10477,4 +10511,3 @@ Object.assign(Effect, EffectModule);
10477
10511
  useCanvas();
10478
10512
 
10479
10513
  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$1 as 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 };
10480
- //# sourceMappingURL=web.module.js.map