@leafer/worker 1.12.2 → 1.12.4

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.
package/dist/worker.js CHANGED
@@ -228,11 +228,13 @@ var LeaferUI = function(exports) {
228
228
  const ctx = canvas.getContext("2d");
229
229
  if (opacity) ctx.globalAlpha = opacity;
230
230
  ctx.imageSmoothingEnabled = smooth === false ? false : true;
231
- if (clip) {
232
- const scaleX = width / clip.width, scaleY = height / clip.height;
233
- ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY);
234
- ctx.drawImage(image, 0, 0, image.width, image.height);
235
- } else ctx.drawImage(image, 0, 0, width, height);
231
+ if (image) {
232
+ if (clip) {
233
+ const scaleX = width / clip.width, scaleY = height / clip.height;
234
+ ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY);
235
+ ctx.drawImage(image, 0, 0, image.width, image.height);
236
+ } else ctx.drawImage(image, 0, 0, width, height);
237
+ }
236
238
  return canvas;
237
239
  },
238
240
  setPatternTransform(pattern, transform, paint) {
@@ -3875,6 +3877,10 @@ var LeaferUI = function(exports) {
3875
3877
  get url() {
3876
3878
  return this.config.url;
3877
3879
  }
3880
+ get crossOrigin() {
3881
+ const {crossOrigin: crossOrigin} = this.config;
3882
+ return isUndefined(crossOrigin) ? Platform.image.crossOrigin : crossOrigin;
3883
+ }
3878
3884
  get completed() {
3879
3885
  return this.ready || !!this.error;
3880
3886
  }
@@ -3892,12 +3898,14 @@ var LeaferUI = function(exports) {
3892
3898
  ImageManager.isFormat("svg", config) && (this.isSVG = true);
3893
3899
  ImageManager.hasAlphaPixel(config) && (this.hasAlphaPixel = true);
3894
3900
  }
3895
- load(onSuccess, onError) {
3901
+ load(onSuccess, onError, thumbSize) {
3896
3902
  if (!this.loading) {
3897
3903
  this.loading = true;
3898
- const {crossOrigin: crossOrigin} = this.config;
3899
3904
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function*() {
3900
- return yield Platform.origin.loadImage(this.url, isUndefined(crossOrigin) ? Platform.image.crossOrigin : crossOrigin, this).then(img => this.setView(img)).catch(e => {
3905
+ return yield Platform.origin.loadImage(this.getLoadUrl(thumbSize), this.crossOrigin, this).then(img => {
3906
+ if (thumbSize) this.setThumbView(img);
3907
+ this.setView(img);
3908
+ }).catch(e => {
3901
3909
  this.error = e;
3902
3910
  this.onComplete(false);
3903
3911
  });
@@ -3918,9 +3926,11 @@ var LeaferUI = function(exports) {
3918
3926
  }
3919
3927
  setView(img) {
3920
3928
  this.ready = true;
3921
- this.width = img.naturalWidth || img.width;
3922
- this.height = img.naturalHeight || img.height;
3923
- this.view = img;
3929
+ if (!this.width) {
3930
+ this.width = img.width;
3931
+ this.height = img.height;
3932
+ this.view = img;
3933
+ }
3924
3934
  this.onComplete(true);
3925
3935
  }
3926
3936
  onComplete(isSuccess) {
@@ -3966,6 +3976,19 @@ var LeaferUI = function(exports) {
3966
3976
  Platform.image.setPatternTransform(pattern, transform, paint);
3967
3977
  return pattern;
3968
3978
  }
3979
+ getLoadUrl(_thumbSize) {
3980
+ return this.url;
3981
+ }
3982
+ setThumbView(_view) {}
3983
+ getThumbSize(_lod) {
3984
+ return undefined;
3985
+ }
3986
+ getMinLevel() {
3987
+ return undefined;
3988
+ }
3989
+ getLevelData(_level, _width, _height) {
3990
+ return undefined;
3991
+ }
3969
3992
  clearLevels(_checkUse) {}
3970
3993
  destroy() {
3971
3994
  this.clearLevels();
@@ -6526,7 +6549,7 @@ var LeaferUI = function(exports) {
6526
6549
  this.levelMap = null;
6527
6550
  }
6528
6551
  }
6529
- const version = "1.12.2";
6552
+ const version = "1.12.4";
6530
6553
  class LeaferCanvas extends LeaferCanvasBase {
6531
6554
  get allowBackgroundColor() {
6532
6555
  return true;
@@ -9416,6 +9439,8 @@ var LeaferUI = function(exports) {
9416
9439
  exports.MoveEvent.MOVE = "move";
9417
9440
  exports.MoveEvent.DRAG_ANIMATE = "move.drag_animate";
9418
9441
  exports.MoveEvent.END = "move.end";
9442
+ exports.MoveEvent.PULL_DOWN = "move.pull_down";
9443
+ exports.MoveEvent.REACH_BOTTOM = "move.reach_bottom";
9419
9444
  exports.MoveEvent = __decorate([ registerUIEvent() ], exports.MoveEvent);
9420
9445
  exports.TouchEvent = class TouchEvent extends UIEvent {};
9421
9446
  exports.TouchEvent = __decorate([ registerUIEvent() ], exports.TouchEvent);
@@ -10790,7 +10815,7 @@ var LeaferUI = function(exports) {
10790
10815
  ignoreRender(ui, false);
10791
10816
  onLoadError(ui, event, error);
10792
10817
  leafPaint.loadId = undefined;
10793
- });
10818
+ }, paint.lod && image.getThumbSize(paint.lod));
10794
10819
  if (ui.placeholderColor) {
10795
10820
  if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
10796
10821
  if (!image.ready) {
@@ -14778,15 +14803,27 @@ var LeaferUI = function(exports) {
14778
14803
  };
14779
14804
  exports.TextEditor = __decorate([ registerInnerEditor() ], exports.TextEditor);
14780
14805
  Plugin.add("text-editor", "editor");
14806
+ function getScrollType(leafer) {
14807
+ const {scroll: scroll, disabled: disabled} = leafer.app.config.move;
14808
+ return !scroll || disabled ? "" : scroll === true ? "free" : scroll;
14809
+ }
14781
14810
  function addViewport(leafer, mergeConfig, custom) {
14782
14811
  addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
14783
14812
  if (leafer.isApp || custom) return;
14784
14813
  leafer.__eventIds.push(leafer.on_(exports.MoveEvent.BEFORE_MOVE, e => {
14785
14814
  const move = leafer.getValidMove(e.moveX, e.moveY, false);
14815
+ if (getScrollType(leafer).includes("limit")) {
14816
+ const testMove = leafer.getValidMove(0, 0);
14817
+ if (testMove.x || testMove.y) {
14818
+ const maxX = 100, maxY = 200, resistance = e.moveType === "drag" ? .3 : .05;
14819
+ if (Math.abs(testMove.x) > maxX) move.x = 0; else move.x *= resistance;
14820
+ if (Math.abs(testMove.y) > maxY) move.y = 0; else move.y *= resistance;
14821
+ }
14822
+ }
14786
14823
  leafer.zoomLayer.move(move);
14787
14824
  }), leafer.on_(exports.MoveEvent.DRAG_ANIMATE, () => {
14788
- const move = leafer.getValidMove(0, 0);
14789
- if (move.x || move.y) leafer.interaction.stopDragAnimate();
14825
+ const testMove = leafer.getValidMove(0, 0);
14826
+ if (testMove.x || testMove.y) leafer.interaction.stopDragAnimate();
14790
14827
  }), leafer.on_(exports.MoveEvent.END, e => {
14791
14828
  LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY));
14792
14829
  }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, e => {
@@ -15071,15 +15108,15 @@ var LeaferUI = function(exports) {
15071
15108
  LeaferTypeCreator.run(type, this);
15072
15109
  };
15073
15110
  leafer.getValidMove = function(moveX, moveY, checkLimit = true) {
15074
- const {scroll: scroll, disabled: disabled} = this.app.config.move;
15111
+ const {disabled: disabled} = this.app.config.move;
15075
15112
  move$4.set(moveX, moveY);
15076
- if (scroll) {
15077
- const type = scroll === true ? "" : scroll;
15078
- if (type.includes("x")) move$4.y = 0; else if (type.includes("y")) move$4.x = 0; else Math.abs(move$4.x) > Math.abs(move$4.y) ? move$4.y = 0 : move$4.x = 0;
15079
- if (checkLimit && type.includes("limit")) {
15113
+ const scrollType = getScrollType(this);
15114
+ if (scrollType) {
15115
+ if (scrollType.includes("x")) move$4.y = 0; else if (scrollType.includes("y")) move$4.x = 0; else Math.abs(move$4.x) > Math.abs(move$4.y) ? move$4.y = 0 : move$4.x = 0;
15116
+ if (checkLimit && scrollType.includes("limit")) {
15080
15117
  bounds.set(this.__world).addPoint(this.zoomLayer);
15081
15118
  DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, "auto", move$4, true);
15082
- if (type.includes("x")) move$4.y = 0; else if (type.includes("y")) move$4.x = 0;
15119
+ if (scrollType.includes("x")) move$4.y = 0; else if (scrollType.includes("y")) move$4.x = 0;
15083
15120
  }
15084
15121
  }
15085
15122
  return {
@@ -16987,8 +17024,8 @@ var LeaferUI = function(exports) {
16987
17024
  this.each(item => item.stop());
16988
17025
  this.emitType(AnimateEvent.STOP);
16989
17026
  }
16990
- seek(time) {
16991
- this.each(item => item.seek(time));
17027
+ seek(time, includeDelay) {
17028
+ this.each(item => item.seek(time, includeDelay));
16992
17029
  this.emitType(AnimateEvent.SEEK);
16993
17030
  }
16994
17031
  kill(complete, killStyle) {