leafer-ui 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$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;
@@ -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
  }
@@ -7386,13 +7396,11 @@ class TextData extends UIData {
7386
7396
  setFontWeight(value) {
7387
7397
  if (typeof value === 'string') {
7388
7398
  this.__setInput('fontWeight', value);
7389
- this._fontWeight = fontWeightMap[value] || 400;
7390
- }
7391
- else {
7392
- if (this.__input)
7393
- this.__removeInput('fontWeight');
7394
- this._fontWeight = value;
7399
+ value = fontWeightMap[value] || 400;
7395
7400
  }
7401
+ else if (this.__input)
7402
+ this.__removeInput('fontWeight');
7403
+ this._fontWeight = value;
7396
7404
  }
7397
7405
  setBoxStyle(value) {
7398
7406
  let t = this.__leaf, box = t.__box;
@@ -7719,6 +7727,9 @@ let UI = UI_1 = class UI extends Leaf {
7719
7727
  else
7720
7728
  drawer.rect(x, y, width, height);
7721
7729
  }
7730
+ drawImagePlaceholder(canvas, _image) {
7731
+ Paint.fill(this.__.placeholderColor, this, canvas);
7732
+ }
7722
7733
  animate(_keyframe, _options, _type, _isTemp) {
7723
7734
  return Plugin.need('animate');
7724
7735
  }
@@ -7955,6 +7966,9 @@ __decorate([
7955
7966
  __decorate([
7956
7967
  effectType()
7957
7968
  ], UI.prototype, "filter", void 0);
7969
+ __decorate([
7970
+ surfaceType()
7971
+ ], UI.prototype, "placeholderColor", void 0);
7958
7972
  __decorate([
7959
7973
  dataType({})
7960
7974
  ], UI.prototype, "data", void 0);
@@ -8785,10 +8799,11 @@ let Image$1 = class Image extends Rect {
8785
8799
  get ready() { return this.image ? this.image.ready : false; }
8786
8800
  constructor(data) {
8787
8801
  super(data);
8788
- this.on(ImageEvent.LOADED, (e) => {
8789
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8790
- this.image = e.image;
8791
- });
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;
8792
8807
  }
8793
8808
  destroy() {
8794
8809
  this.image = null;
@@ -8902,7 +8917,7 @@ let Text = class Text extends UI {
8902
8917
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8903
8918
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8904
8919
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8905
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8920
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8906
8921
  }
8907
8922
  __updateBoxBounds() {
8908
8923
  const data = this.__;
@@ -9000,6 +9015,9 @@ __decorate([
9000
9015
  __decorate([
9001
9016
  boundsType('')
9002
9017
  ], Text.prototype, "text", void 0);
9018
+ __decorate([
9019
+ boundsType('')
9020
+ ], Text.prototype, "placeholder", void 0);
9003
9021
  __decorate([
9004
9022
  boundsType('caption')
9005
9023
  ], Text.prototype, "fontFamily", void 0);
@@ -9875,8 +9893,7 @@ class InteractionBase {
9875
9893
  if (this.downData) {
9876
9894
  const canDrag = PointHelper.getDistance(this.downData, data) > this.p.dragDistance;
9877
9895
  if (canDrag) {
9878
- if (this.waitTap || this.longPressTimer)
9879
- this.pointerWaitCancel();
9896
+ this.pointerWaitCancel();
9880
9897
  this.waitRightTap = false;
9881
9898
  }
9882
9899
  this.dragger.checkDrag(data, canDrag);
@@ -10158,9 +10175,11 @@ class InteractionBase {
10158
10175
  this.waitTap = true;
10159
10176
  }
10160
10177
  tapWaitCancel() {
10161
- clearTimeout(this.tapTimer);
10162
- this.waitTap = false;
10163
- this.tapCount = 0;
10178
+ if (this.waitTap) {
10179
+ clearTimeout(this.tapTimer);
10180
+ this.waitTap = false;
10181
+ this.tapCount = 0;
10182
+ }
10164
10183
  }
10165
10184
  longPressWait(data) {
10166
10185
  clearTimeout(this.longPressTimer);
@@ -10180,8 +10199,10 @@ class InteractionBase {
10180
10199
  return hasLong;
10181
10200
  }
10182
10201
  longPressWaitCancel() {
10183
- clearTimeout(this.longPressTimer);
10184
- this.longPressed = false;
10202
+ if (this.longPressTimer) {
10203
+ clearTimeout(this.longPressTimer);
10204
+ this.longPressed = false;
10205
+ }
10185
10206
  }
10186
10207
  __onResize() {
10187
10208
  const { dragOut } = this.m;
@@ -10731,8 +10752,10 @@ class Interaction extends InteractionBase {
10731
10752
  }
10732
10753
 
10733
10754
  function fillText(ui, canvas) {
10734
- let row, data = ui.__.__textDrawData;
10735
- 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;
10736
10759
  for (let i = 0, len = rows.length; i < len; i++) {
10737
10760
  row = rows[i];
10738
10761
  if (row.text)
@@ -10741,7 +10764,7 @@ function fillText(ui, canvas) {
10741
10764
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
10742
10765
  }
10743
10766
  if (decorationY) {
10744
- const { decorationColor, decorationHeight } = data;
10767
+ const { decorationColor, decorationHeight } = data.__textDrawData;
10745
10768
  if (decorationColor)
10746
10769
  canvas.fillStyle = decorationColor;
10747
10770
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -10750,38 +10773,44 @@ function fillText(ui, canvas) {
10750
10773
 
10751
10774
  function fill(fill, ui, canvas) {
10752
10775
  canvas.fillStyle = fill;
10753
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10776
+ fillPathOrText(ui, canvas);
10754
10777
  }
10755
10778
  function fills(fills, ui, canvas) {
10756
10779
  let item;
10757
- const { windingRule, __font } = ui.__;
10758
10780
  for (let i = 0, len = fills.length; i < len; i++) {
10759
10781
  item = fills[i];
10760
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
10761
- continue;
10762
- if (item.style) {
10763
- canvas.fillStyle = item.style;
10764
- if (item.transform) {
10765
- canvas.save();
10766
- canvas.transform(item.transform);
10767
- if (item.blendMode)
10768
- canvas.blendMode = item.blendMode;
10769
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10770
- 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;
10771
10789
  }
10772
- else {
10773
- if (item.blendMode) {
10774
- canvas.saveBlendMode(item.blendMode);
10775
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10776
- canvas.restoreBlendMode();
10777
- }
10778
- else {
10779
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
10780
- }
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();
10781
10805
  }
10806
+ else
10807
+ fillPathOrText(ui, canvas);
10782
10808
  }
10783
10809
  }
10784
10810
  }
10811
+ function fillPathOrText(ui, canvas) {
10812
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
10813
+ }
10785
10814
 
10786
10815
  function strokeText(stroke, ui, canvas) {
10787
10816
  const { strokeAlign } = ui.__;
@@ -11021,6 +11050,7 @@ const PaintModule = {
11021
11050
  compute,
11022
11051
  fill,
11023
11052
  fills,
11053
+ fillPathOrText,
11024
11054
  fillText,
11025
11055
  stroke,
11026
11056
  strokes,
@@ -11213,6 +11243,13 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
11213
11243
  onLoadError(ui, event, error);
11214
11244
  leafPaint.loadId = null;
11215
11245
  });
11246
+ if (ui.placeholderColor)
11247
+ setTimeout(() => {
11248
+ if (!(image.ready || image.isPlacehold)) {
11249
+ image.isPlacehold = true;
11250
+ ui.forceUpdate('surface');
11251
+ }
11252
+ }, 100);
11216
11253
  }
11217
11254
  return leafPaint;
11218
11255
  }
@@ -12251,4 +12288,3 @@ Object.assign(Creator, {
12251
12288
  useCanvas();
12252
12289
 
12253
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 };
12254
- //# sourceMappingURL=web.module.js.map