@leafer-draw/worker 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 true; }
@@ -6310,7 +6327,7 @@ class Watcher {
6310
6327
  }
6311
6328
  }
6312
6329
 
6313
- const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateAllWorldOpacity } = LeafHelper;
6330
+ const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateChange: updateOneChange } = LeafHelper;
6314
6331
  const { pushAllChildBranch, pushAllParent } = BranchHelper;
6315
6332
  function updateMatrix(updateList, levelList) {
6316
6333
  let layout;
@@ -6353,15 +6370,7 @@ function updateBounds(boundsList) {
6353
6370
  });
6354
6371
  }
6355
6372
  function updateChange(updateList) {
6356
- let layout;
6357
- updateList.list.forEach(leaf => {
6358
- layout = leaf.__layout;
6359
- if (layout.opacityChanged)
6360
- updateAllWorldOpacity(leaf);
6361
- if (layout.stateStyleChanged)
6362
- setTimeout(() => layout.stateStyleChanged && leaf.updateState());
6363
- leaf.__updateChange();
6364
- });
6373
+ updateList.list.forEach(updateOneChange);
6365
6374
  }
6366
6375
 
6367
6376
  const { worldBounds } = LeafBoundsHelper;
@@ -6582,6 +6591,15 @@ class Renderer {
6582
6591
  }
6583
6592
  checkRender() {
6584
6593
  if (this.running) {
6594
+ const { target } = this;
6595
+ if (target.isApp) {
6596
+ target.emit(RenderEvent.CHILD_START, target);
6597
+ target.children.forEach(leafer => {
6598
+ leafer.renderer.FPS = this.FPS;
6599
+ leafer.renderer.checkRender();
6600
+ });
6601
+ target.emit(RenderEvent.CHILD_END, target);
6602
+ }
6585
6603
  if (this.changed && this.canvas.view)
6586
6604
  this.render();
6587
6605
  this.target.emit(RenderEvent.NEXT);
@@ -6667,7 +6685,7 @@ class Renderer {
6667
6685
  bounds.spread(Renderer.clipSpread).ceil();
6668
6686
  canvas.clearWorld(bounds, true);
6669
6687
  canvas.clipWorld(bounds, true);
6670
- this.__render(bounds, block.includes(this.target.__world), realBounds);
6688
+ this.__render(bounds, realBounds);
6671
6689
  canvas.restore();
6672
6690
  Run.end(t);
6673
6691
  }
@@ -6676,12 +6694,12 @@ class Renderer {
6676
6694
  const { canvas } = this;
6677
6695
  canvas.save();
6678
6696
  canvas.clear();
6679
- this.__render(canvas.bounds, true);
6697
+ this.__render(canvas.bounds);
6680
6698
  canvas.restore();
6681
6699
  Run.end(t);
6682
6700
  }
6683
- __render(bounds, includes, realBounds) {
6684
- const { canvas } = this, options = includes ? { includes } : { bounds, includes };
6701
+ __render(bounds, realBounds) {
6702
+ const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
6685
6703
  if (this.needFill)
6686
6704
  canvas.fillWorld(bounds, this.config.fill);
6687
6705
  if (Debug.showRepaint)
@@ -6708,22 +6726,14 @@ class Renderer {
6708
6726
  }
6709
6727
  __requestRender() {
6710
6728
  const target = this.target;
6711
- if (target.parentApp)
6712
- return target.parentApp.renderer.update(false);
6713
- if (this.requestTime)
6729
+ if (this.requestTime || !target)
6714
6730
  return;
6731
+ if (target.parentApp)
6732
+ return target.parentApp.requestRender(false);
6715
6733
  const requestTime = this.requestTime = Date.now();
6716
6734
  Platform.requestRender(() => {
6717
6735
  this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
6718
6736
  this.requestTime = 0;
6719
- if (target.isApp) {
6720
- target.emit(RenderEvent.CHILD_START, target);
6721
- target.children.forEach(leafer => {
6722
- leafer.renderer.FPS = this.FPS;
6723
- leafer.renderer.checkRender();
6724
- });
6725
- target.emit(RenderEvent.CHILD_END, target);
6726
- }
6727
6737
  this.checkRender();
6728
6738
  });
6729
6739
  }
@@ -7048,13 +7058,11 @@ class TextData extends UIData {
7048
7058
  setFontWeight(value) {
7049
7059
  if (typeof value === 'string') {
7050
7060
  this.__setInput('fontWeight', value);
7051
- this._fontWeight = fontWeightMap[value] || 400;
7052
- }
7053
- else {
7054
- if (this.__input)
7055
- this.__removeInput('fontWeight');
7056
- this._fontWeight = value;
7061
+ value = fontWeightMap[value] || 400;
7057
7062
  }
7063
+ else if (this.__input)
7064
+ this.__removeInput('fontWeight');
7065
+ this._fontWeight = value;
7058
7066
  }
7059
7067
  setBoxStyle(value) {
7060
7068
  let t = this.__leaf, box = t.__box;
@@ -7381,6 +7389,9 @@ let UI = UI_1 = class UI extends Leaf {
7381
7389
  else
7382
7390
  drawer.rect(x, y, width, height);
7383
7391
  }
7392
+ drawImagePlaceholder(canvas, _image) {
7393
+ Paint.fill(this.__.placeholderColor, this, canvas);
7394
+ }
7384
7395
  animate(_keyframe, _options, _type, _isTemp) {
7385
7396
  return Plugin.need('animate');
7386
7397
  }
@@ -7617,6 +7628,9 @@ __decorate([
7617
7628
  __decorate([
7618
7629
  effectType()
7619
7630
  ], UI.prototype, "filter", void 0);
7631
+ __decorate([
7632
+ surfaceType()
7633
+ ], UI.prototype, "placeholderColor", void 0);
7620
7634
  __decorate([
7621
7635
  dataType({})
7622
7636
  ], UI.prototype, "data", void 0);
@@ -8447,10 +8461,11 @@ let Image = class Image extends Rect {
8447
8461
  get ready() { return this.image ? this.image.ready : false; }
8448
8462
  constructor(data) {
8449
8463
  super(data);
8450
- this.on(ImageEvent.LOADED, (e) => {
8451
- if (e.attrName === 'fill' && e.attrValue.url === this.url)
8452
- this.image = e.image;
8453
- });
8464
+ this.on_(ImageEvent.LOADED, this.__onLoaded, this);
8465
+ }
8466
+ __onLoaded(e) {
8467
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
8468
+ this.image = e.image;
8454
8469
  }
8455
8470
  destroy() {
8456
8471
  this.image = null;
@@ -8564,7 +8579,7 @@ let Text = class Text extends UI {
8564
8579
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8565
8580
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8566
8581
  data.__clipText = textOverflow !== 'show' && !data.__autoSize;
8567
- data.__textDrawData = TextConvert.getDrawData(data.text, this.__);
8582
+ data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === '') ? data.placeholder : data.text, this.__);
8568
8583
  }
8569
8584
  __updateBoxBounds() {
8570
8585
  const data = this.__;
@@ -8662,6 +8677,9 @@ __decorate([
8662
8677
  __decorate([
8663
8678
  boundsType('')
8664
8679
  ], Text.prototype, "text", void 0);
8680
+ __decorate([
8681
+ boundsType('')
8682
+ ], Text.prototype, "placeholder", void 0);
8665
8683
  __decorate([
8666
8684
  boundsType('caption')
8667
8685
  ], Text.prototype, "fontFamily", void 0);
@@ -8781,8 +8799,10 @@ function penPathType() {
8781
8799
  }
8782
8800
 
8783
8801
  function fillText(ui, canvas) {
8784
- let row, data = ui.__.__textDrawData;
8785
- const { rows, decorationY } = data;
8802
+ const data = ui.__, { rows, decorationY } = data.__textDrawData;
8803
+ if (data.__isPlacehold && data.placeholderColor)
8804
+ canvas.fillStyle = data.placeholderColor;
8805
+ let row;
8786
8806
  for (let i = 0, len = rows.length; i < len; i++) {
8787
8807
  row = rows[i];
8788
8808
  if (row.text)
@@ -8791,7 +8811,7 @@ function fillText(ui, canvas) {
8791
8811
  row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
8792
8812
  }
8793
8813
  if (decorationY) {
8794
- const { decorationColor, decorationHeight } = data;
8814
+ const { decorationColor, decorationHeight } = data.__textDrawData;
8795
8815
  if (decorationColor)
8796
8816
  canvas.fillStyle = decorationColor;
8797
8817
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
@@ -8800,38 +8820,44 @@ function fillText(ui, canvas) {
8800
8820
 
8801
8821
  function fill(fill, ui, canvas) {
8802
8822
  canvas.fillStyle = fill;
8803
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
8823
+ fillPathOrText(ui, canvas);
8804
8824
  }
8805
8825
  function fills(fills, ui, canvas) {
8806
8826
  let item;
8807
- const { windingRule, __font } = ui.__;
8808
8827
  for (let i = 0, len = fills.length; i < len; i++) {
8809
8828
  item = fills[i];
8810
- if (item.image && PaintImage.checkImage(ui, canvas, item, !__font))
8811
- continue;
8812
- if (item.style) {
8813
- canvas.fillStyle = item.style;
8814
- if (item.transform) {
8815
- canvas.save();
8816
- canvas.transform(item.transform);
8817
- if (item.blendMode)
8818
- canvas.blendMode = item.blendMode;
8819
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8820
- canvas.restore();
8829
+ if (item.image) {
8830
+ if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
8831
+ continue;
8832
+ if (!item.style) {
8833
+ if (!i && item.image.isPlacehold)
8834
+ ui.drawImagePlaceholder(canvas, item.image);
8835
+ continue;
8821
8836
  }
8822
- else {
8823
- if (item.blendMode) {
8824
- canvas.saveBlendMode(item.blendMode);
8825
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8826
- canvas.restoreBlendMode();
8827
- }
8828
- else {
8829
- __font ? fillText(ui, canvas) : (windingRule ? canvas.fill(windingRule) : canvas.fill());
8830
- }
8837
+ }
8838
+ canvas.fillStyle = item.style;
8839
+ if (item.transform) {
8840
+ canvas.save();
8841
+ canvas.transform(item.transform);
8842
+ if (item.blendMode)
8843
+ canvas.blendMode = item.blendMode;
8844
+ fillPathOrText(ui, canvas);
8845
+ canvas.restore();
8846
+ }
8847
+ else {
8848
+ if (item.blendMode) {
8849
+ canvas.saveBlendMode(item.blendMode);
8850
+ fillPathOrText(ui, canvas);
8851
+ canvas.restoreBlendMode();
8831
8852
  }
8853
+ else
8854
+ fillPathOrText(ui, canvas);
8832
8855
  }
8833
8856
  }
8834
8857
  }
8858
+ function fillPathOrText(ui, canvas) {
8859
+ ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
8860
+ }
8835
8861
 
8836
8862
  function strokeText(stroke, ui, canvas) {
8837
8863
  const { strokeAlign } = ui.__;
@@ -9071,6 +9097,7 @@ const PaintModule = {
9071
9097
  compute,
9072
9098
  fill,
9073
9099
  fills,
9100
+ fillPathOrText,
9074
9101
  fillText,
9075
9102
  stroke,
9076
9103
  strokes,
@@ -9263,6 +9290,13 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
9263
9290
  onLoadError(ui, event, error);
9264
9291
  leafPaint.loadId = null;
9265
9292
  });
9293
+ if (ui.placeholderColor)
9294
+ setTimeout(() => {
9295
+ if (!(image.ready || image.isPlacehold)) {
9296
+ image.isPlacehold = true;
9297
+ ui.forceUpdate('surface');
9298
+ }
9299
+ }, 100);
9266
9300
  }
9267
9301
  return leafPaint;
9268
9302
  }
@@ -10296,4 +10330,3 @@ Object.assign(Effect, EffectModule);
10296
10330
  useCanvas();
10297
10331
 
10298
10332
  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 };
10299
- //# sourceMappingURL=worker.module.js.map