leafer-ui 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
  const debug$5 = 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;
@@ -7387,13 +7396,11 @@ class TextData extends UIData {
7387
7396
  setFontWeight(value) {
7388
7397
  if (typeof value === 'string') {
7389
7398
  this.__setInput('fontWeight', value);
7390
- this._fontWeight = fontWeightMap[value] || 400;
7391
- }
7392
- else {
7393
- if (this.__input)
7394
- this.__removeInput('fontWeight');
7395
- this._fontWeight = value;
7399
+ value = fontWeightMap[value] || 400;
7396
7400
  }
7401
+ else if (this.__input)
7402
+ this.__removeInput('fontWeight');
7403
+ this._fontWeight = value;
7397
7404
  }
7398
7405
  setBoxStyle(value) {
7399
7406
  let t = this.__leaf, box = t.__box;
@@ -7720,6 +7727,9 @@ let UI = UI_1 = class UI extends Leaf {
7720
7727
  else
7721
7728
  drawer.rect(x, y, width, height);
7722
7729
  }
7730
+ drawImagePlaceholder(canvas, _image) {
7731
+ Paint.fill(this.__.placeholderColor, this, canvas);
7732
+ }
7723
7733
  animate(_keyframe, _options, _type, _isTemp) {
7724
7734
  return Plugin.need('animate');
7725
7735
  }
@@ -7956,6 +7966,9 @@ __decorate([
7956
7966
  __decorate([
7957
7967
  effectType()
7958
7968
  ], UI.prototype, "filter", void 0);
7969
+ __decorate([
7970
+ surfaceType()
7971
+ ], UI.prototype, "placeholderColor", void 0);
7959
7972
  __decorate([
7960
7973
  dataType({})
7961
7974
  ], UI.prototype, "data", void 0);
@@ -8786,10 +8799,11 @@ let Image$1 = class Image extends Rect {
8786
8799
  get ready() { return this.image ? this.image.ready : false; }
8787
8800
  constructor(data) {
8788
8801
  super(data);
8789
- this.on(ImageEvent.LOADED, (e) => {
8790
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8791
- this.image = e.image;
8792
- });
8802
+ this.on_(ImageEvent.LOADED, this.__onLoaded, this);
8803
+ }
8804
+ __onLoaded(e) {
8805
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
8806
+ this.image = e.image;
8793
8807
  }
8794
8808
  destroy() {
8795
8809
  this.image = null;
@@ -8903,7 +8917,7 @@ let Text = class Text extends UI {
8903
8917
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8904
8918
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8905
8919
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8906
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8920
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8907
8921
  }
8908
8922
  __updateBoxBounds() {
8909
8923
  const data = this.__;
@@ -9001,6 +9015,9 @@ __decorate([
9001
9015
  __decorate([
9002
9016
  boundsType('')
9003
9017
  ], Text.prototype, "text", void 0);
9018
+ __decorate([
9019
+ boundsType('')
9020
+ ], Text.prototype, "placeholder", void 0);
9004
9021
  __decorate([
9005
9022
  boundsType('caption')
9006
9023
  ], Text.prototype, "fontFamily", void 0);
@@ -10735,8 +10752,10 @@ class Interaction extends InteractionBase {
10735
10752
  }
10736
10753
 
10737
10754
  function fillText(ui, canvas) {
10738
- let row, data = ui.__.__textDrawData;
10739
- const { rows, decorationY } = data;
10755
+ const data = ui.__, { rows, decorationY } = data.__textDrawData;
10756
+ if (data.__isPlacehold && data.placeholderColor)
10757
+ canvas.fillStyle = data.placeholderColor;
10758
+ let row;
10740
10759
  for (let i = 0, len = rows.length; i < len; i++) {
10741
10760
  row = rows[i];
10742
10761
  if (row.text)
@@ -10745,7 +10764,7 @@ function fillText(ui, canvas) {
10745
10764
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
10746
10765
  }
10747
10766
  if (decorationY) {
10748
- const { decorationColor, decorationHeight } = data;
10767
+ const { decorationColor, decorationHeight } = data.__textDrawData;
10749
10768
  if (decorationColor)
10750
10769
  canvas.fillStyle = decorationColor;
10751
10770
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -10754,38 +10773,44 @@ function fillText(ui, canvas) {
10754
10773
 
10755
10774
  function fill(fill, ui, canvas) {
10756
10775
  canvas.fillStyle = fill;
10757
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10776
+ fillPathOrText(ui, canvas);
10758
10777
  }
10759
10778
  function fills(fills, ui, canvas) {
10760
10779
  let item;
10761
- const { windingRule, __font } = ui.__;
10762
10780
  for (let i = 0, len = fills.length; i < len; i++) {
10763
10781
  item = fills[i];
10764
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
10765
- continue;
10766
- if (item.style) {
10767
- canvas.fillStyle = item.style;
10768
- if (item.transform) {
10769
- canvas.save();
10770
- canvas.transform(item.transform);
10771
- if (item.blendMode)
10772
- canvas.blendMode = item.blendMode;
10773
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10774
- canvas.restore();
10782
+ if (item.image) {
10783
+ if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
10784
+ continue;
10785
+ if (!item.style) {
10786
+ if (!i && item.image.isPlacehold)
10787
+ ui.drawImagePlaceholder(canvas, item.image);
10788
+ continue;
10775
10789
  }
10776
- else {
10777
- if (item.blendMode) {
10778
- canvas.saveBlendMode(item.blendMode);
10779
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10780
- canvas.restoreBlendMode();
10781
- }
10782
- else {
10783
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10784
- }
10790
+ }
10791
+ canvas.fillStyle = item.style;
10792
+ if (item.transform) {
10793
+ canvas.save();
10794
+ canvas.transform(item.transform);
10795
+ if (item.blendMode)
10796
+ canvas.blendMode = item.blendMode;
10797
+ fillPathOrText(ui, canvas);
10798
+ canvas.restore();
10799
+ }
10800
+ else {
10801
+ if (item.blendMode) {
10802
+ canvas.saveBlendMode(item.blendMode);
10803
+ fillPathOrText(ui, canvas);
10804
+ canvas.restoreBlendMode();
10785
10805
  }
10806
+ else
10807
+ fillPathOrText(ui, canvas);
10786
10808
  }
10787
10809
  }
10788
10810
  }
10811
+ function fillPathOrText(ui, canvas) {
10812
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10813
+ }
10789
10814
 
10790
10815
  function strokeText(stroke, ui, canvas) {
10791
10816
  const { strokeAlign } = ui.__;
@@ -11025,6 +11050,7 @@ const PaintModule = {
11025
11050
  compute,
11026
11051
  fill,
11027
11052
  fills,
11053
+ fillPathOrText,
11028
11054
  fillText,
11029
11055
  stroke,
11030
11056
  strokes,
@@ -11217,6 +11243,13 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
11217
11243
  onLoadError(ui, event, error);
11218
11244
  leafPaint.loadId = null;
11219
11245
  });
11246
+ if (ui.placeholderColor)
11247
+ setTimeout(() => {
11248
+ if (!(image.ready || image.isPlacehold)) {
11249
+ image.isPlacehold = true;
11250
+ ui.forceUpdate('surface');
11251
+ }
11252
+ }, 100);
11220
11253
  }
11221
11254
  return leafPaint;
11222
11255
  }
@@ -12255,4 +12288,3 @@ Object.assign(Creator, {
12255
12288
  useCanvas();
12256
12289
 
12257
12290
  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$1 as DragEvent, Dragger, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Frame, FrameData, Group, GroupData, HitCanvasManager, Image$1 as 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$1 as 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 };
12258
- //# sourceMappingURL=web.module.js.map