@leafer-editor/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) {
@@ -14532,15 +14557,27 @@ var LeaferUI = function(exports) {
14532
14557
  exports.UI.setEditInner = function(editorName) {
14533
14558
  this.changeAttr("editInner", editorName);
14534
14559
  };
14560
+ function getScrollType(leafer) {
14561
+ const {scroll: scroll, disabled: disabled} = leafer.app.config.move;
14562
+ return !scroll || disabled ? "" : scroll === true ? "free" : scroll;
14563
+ }
14535
14564
  function addViewport(leafer, mergeConfig, custom) {
14536
14565
  addViewportConfig(leafer.parentApp ? leafer.parentApp : leafer, mergeConfig);
14537
14566
  if (leafer.isApp || custom) return;
14538
14567
  leafer.__eventIds.push(leafer.on_(exports.MoveEvent.BEFORE_MOVE, e => {
14539
14568
  const move = leafer.getValidMove(e.moveX, e.moveY, false);
14569
+ if (getScrollType(leafer).includes("limit")) {
14570
+ const testMove = leafer.getValidMove(0, 0);
14571
+ if (testMove.x || testMove.y) {
14572
+ const maxX = 100, maxY = 200, resistance = e.moveType === "drag" ? .3 : .05;
14573
+ if (Math.abs(testMove.x) > maxX) move.x = 0; else move.x *= resistance;
14574
+ if (Math.abs(testMove.y) > maxY) move.y = 0; else move.y *= resistance;
14575
+ }
14576
+ }
14540
14577
  leafer.zoomLayer.move(move);
14541
14578
  }), leafer.on_(exports.MoveEvent.DRAG_ANIMATE, () => {
14542
- const move = leafer.getValidMove(0, 0);
14543
- if (move.x || move.y) leafer.interaction.stopDragAnimate();
14579
+ const testMove = leafer.getValidMove(0, 0);
14580
+ if (testMove.x || testMove.y) leafer.interaction.stopDragAnimate();
14544
14581
  }), leafer.on_(exports.MoveEvent.END, e => {
14545
14582
  LeafHelper.animateMove(leafer.zoomLayer, leafer.getValidMove(e.moveX, e.moveY));
14546
14583
  }), leafer.on_(exports.ZoomEvent.BEFORE_ZOOM, e => {
@@ -14825,15 +14862,15 @@ var LeaferUI = function(exports) {
14825
14862
  LeaferTypeCreator.run(type, this);
14826
14863
  };
14827
14864
  leafer.getValidMove = function(moveX, moveY, checkLimit = true) {
14828
- const {scroll: scroll, disabled: disabled} = this.app.config.move;
14865
+ const {disabled: disabled} = this.app.config.move;
14829
14866
  move.set(moveX, moveY);
14830
- if (scroll) {
14831
- const type = scroll === true ? "" : scroll;
14832
- if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0; else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0;
14833
- if (checkLimit && type.includes("limit")) {
14867
+ const scrollType = getScrollType(this);
14868
+ if (scrollType) {
14869
+ if (scrollType.includes("x")) move.y = 0; else if (scrollType.includes("y")) move.x = 0; else Math.abs(move.x) > Math.abs(move.y) ? move.y = 0 : move.x = 0;
14870
+ if (checkLimit && scrollType.includes("limit")) {
14834
14871
  bounds.set(this.__world).addPoint(this.zoomLayer);
14835
14872
  DragBoundsHelper.getValidMove(bounds, this.canvas.bounds, "auto", move, true);
14836
- if (type.includes("x")) move.y = 0; else if (type.includes("y")) move.x = 0;
14873
+ if (scrollType.includes("x")) move.y = 0; else if (scrollType.includes("y")) move.x = 0;
14837
14874
  }
14838
14875
  }
14839
14876
  return {