@leafer-in/view 1.1.2 → 1.2.1

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/view.cjs CHANGED
@@ -29,6 +29,7 @@ function getFixBounds(bounds, scaleBounds) {
29
29
  return fix ? { x, y, width, height } : bounds;
30
30
  }
31
31
 
32
+ draw.Plugin.add('view');
32
33
  draw.Leafer.prototype.zoom = function (zoomType, padding, fixed) {
33
34
  const { zoomLayer } = this;
34
35
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new draw.Bounds();
package/dist/view.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Leafer, Bounds, LeafBoundsHelper } from '@leafer-ui/draw';
1
+ import { Plugin, Leafer, Bounds, LeafBoundsHelper } from '@leafer-ui/draw';
2
2
 
3
3
  function getZoomScale(scaleX, type) {
4
4
  let scale = 1;
@@ -27,6 +27,7 @@ function getFixBounds(bounds, scaleBounds) {
27
27
  return fix ? { x, y, width, height } : bounds;
28
28
  }
29
29
 
30
+ Plugin.add('view');
30
31
  Leafer.prototype.zoom = function (zoomType, padding, fixed) {
31
32
  const { zoomLayer } = this;
32
33
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
@@ -1 +1 @@
1
- import{Leafer as t,Bounds as e,LeafBoundsHelper as i}from"@leafer-ui/draw";function o(t,e){let i=1;const o="out"===e,h=Math.abs(t);if(h>1){for(;o?i<h:i<=h;)i*=2;o&&(i/=2)}else{for(;o?i>=h:i>h;)i/=2;o||(i*=2)}return i/t}t.prototype.zoom=function(t,h,s){const{zoomLayer:n}=this,a=this.canvas.bounds.clone().shrink(void 0!==h?h:30),r=new e,c={x:a.x+a.width/2,y:a.y+a.height/2};let d;const{scaleX:l}=this.__;if("string"==typeof t)switch(t){case"in":d=o(l,"in");break;case"out":d=o(l,"out");break;case"fit":t=this.boxBounds;break;case"fit-width":(t=new e(this.boxBounds)).height=0;break;case"fit-height":(t=new e(this.boxBounds)).width=0}else"number"==typeof t&&(d=t/l);if(d)1!==d&&n.scaleOfWorld(c,this.getValidScale(d));else if("object"==typeof t){const e=t instanceof Array;if(e||t.tag){const o=e?t:[t];r.setListWithFn(o,i.worldBounds)}else{const e=function(t,e){let i,{x:o,y:h,width:s,height:n}=t;return n||(n=s*(e.height/e.width),i=!0),s||(s=n*(e.width/e.height),i=!0),i?{x:o,y:h,width:s,height:n}:t}(t,a);r.set(n.getWorldBounds(e))}const{x:o,y:h,width:c,height:d}=r;let l=a.x-o,f=a.y-h;if(s)l+=Math.max((a.width-c)/2,0),f+=Math.max((a.height-d)/2,0);else{const t=this.getValidScale(Math.min(a.width/c,a.height/d));l+=(a.width-c*t)/2,f+=(a.height-d*t)/2,n.scaleOfWorld(r,t),r.scaleOf(r,t)}return n.move(l,f),r.move(l,f)}return n.worldBoxBounds};
1
+ import{Plugin as t,Leafer as e,Bounds as i,LeafBoundsHelper as o}from"@leafer-ui/draw";function h(t,e){let i=1;const o="out"===e,h=Math.abs(t);if(h>1){for(;o?i<h:i<=h;)i*=2;o&&(i/=2)}else{for(;o?i>=h:i>h;)i/=2;o||(i*=2)}return i/t}t.add("view"),e.prototype.zoom=function(t,e,s){const{zoomLayer:n}=this,a=this.canvas.bounds.clone().shrink(void 0!==e?e:30),r=new i,d={x:a.x+a.width/2,y:a.y+a.height/2};let c;const{scaleX:l}=this.__;if("string"==typeof t)switch(t){case"in":c=h(l,"in");break;case"out":c=h(l,"out");break;case"fit":t=this.boxBounds;break;case"fit-width":(t=new i(this.boxBounds)).height=0;break;case"fit-height":(t=new i(this.boxBounds)).width=0}else"number"==typeof t&&(c=t/l);if(c)1!==c&&n.scaleOfWorld(d,this.getValidScale(c));else if("object"==typeof t){const e=t instanceof Array;if(e||t.tag){const i=e?t:[t];r.setListWithFn(i,o.worldBounds)}else{const e=function(t,e){let i,{x:o,y:h,width:s,height:n}=t;return n||(n=s*(e.height/e.width),i=!0),s||(s=n*(e.width/e.height),i=!0),i?{x:o,y:h,width:s,height:n}:t}(t,a);r.set(n.getWorldBounds(e))}const{x:i,y:h,width:d,height:c}=r;let l=a.x-i,f=a.y-h;if(s)l+=Math.max((a.width-d)/2,0),f+=Math.max((a.height-c)/2,0);else{const t=this.getValidScale(Math.min(a.width/d,a.height/c));l+=(a.width-d*t)/2,f+=(a.height-c*t)/2,n.scaleOfWorld(r,t),r.scaleOf(r,t)}return n.move(l,f),r.move(l,f)}return n.worldBoxBounds};
package/dist/view.js CHANGED
@@ -28,6 +28,7 @@
28
28
  return fix ? { x, y, width, height } : bounds;
29
29
  }
30
30
 
31
+ draw.Plugin.add('view');
31
32
  draw.Leafer.prototype.zoom = function (zoomType, padding, fixed) {
32
33
  const { zoomLayer } = this;
33
34
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new draw.Bounds();
package/dist/view.min.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("@leafer-ui/draw");function e(t,e){let i=1;const s="out"===e,o=Math.abs(t);if(o>1){for(;s?i<o:i<=o;)i*=2;s&&(i/=2)}else{for(;s?i>=o:i>o;)i/=2;s||(i*=2)}return i/t}t.Leafer.prototype.zoom=function(i,s,o){const{zoomLayer:h}=this,n=this.canvas.bounds.clone().shrink(void 0!==s?s:30),a=new t.Bounds,r={x:n.x+n.width/2,y:n.y+n.height/2};let d;const{scaleX:c}=this.__;if("string"==typeof i)switch(i){case"in":d=e(c,"in");break;case"out":d=e(c,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new t.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new t.Bounds(this.boxBounds)).width=0}else"number"==typeof i&&(d=i/c);if(d)1!==d&&h.scaleOfWorld(r,this.getValidScale(d));else if("object"==typeof i){const e=i instanceof Array;if(e||i.tag){const s=e?i:[i];a.setListWithFn(s,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:s,y:o,width:h,height:n}=t;return n||(n=h*(e.height/e.width),i=!0),h||(h=n*(e.width/e.height),i=!0),i?{x:s,y:o,width:h,height:n}:t}(i,n);a.set(h.getWorldBounds(t))}const{x:s,y:r,width:d,height:c}=a;let l=n.x-s,u=n.y-r;if(o)l+=Math.max((n.width-d)/2,0),u+=Math.max((n.height-c)/2,0);else{const t=this.getValidScale(Math.min(n.width/d,n.height/c));l+=(n.width-d*t)/2,u+=(n.height-c*t)/2,h.scaleOfWorld(a,t),a.scaleOf(a,t)}return h.move(l,u),a.move(l,u)}return h.worldBoxBounds};
1
+ "use strict";var t=require("@leafer-ui/draw");function e(t,e){let i=1;const s="out"===e,o=Math.abs(t);if(o>1){for(;s?i<o:i<=o;)i*=2;s&&(i/=2)}else{for(;s?i>=o:i>o;)i/=2;s||(i*=2)}return i/t}t.Plugin.add("view"),t.Leafer.prototype.zoom=function(i,s,o){const{zoomLayer:h}=this,n=this.canvas.bounds.clone().shrink(void 0!==s?s:30),a=new t.Bounds,r={x:n.x+n.width/2,y:n.y+n.height/2};let d;const{scaleX:c}=this.__;if("string"==typeof i)switch(i){case"in":d=e(c,"in");break;case"out":d=e(c,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new t.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new t.Bounds(this.boxBounds)).width=0}else"number"==typeof i&&(d=i/c);if(d)1!==d&&h.scaleOfWorld(r,this.getValidScale(d));else if("object"==typeof i){const e=i instanceof Array;if(e||i.tag){const s=e?i:[i];a.setListWithFn(s,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:s,y:o,width:h,height:n}=t;return n||(n=h*(e.height/e.width),i=!0),h||(h=n*(e.width/e.height),i=!0),i?{x:s,y:o,width:h,height:n}:t}(i,n);a.set(h.getWorldBounds(t))}const{x:s,y:r,width:d,height:c}=a;let l=n.x-s,u=n.y-r;if(o)l+=Math.max((n.width-d)/2,0),u+=Math.max((n.height-c)/2,0);else{const t=this.getValidScale(Math.min(n.width/d,n.height/c));l+=(n.width-d*t)/2,u+=(n.height-c*t)/2,h.scaleOfWorld(a,t),a.scaleOf(a,t)}return h.move(l,u),a.move(l,u)}return h.worldBoxBounds};
package/dist/view.min.js CHANGED
@@ -1 +1 @@
1
- !function(t){"use strict";function e(t,e){let i=1;const o="out"===e,s=Math.abs(t);if(s>1){for(;o?i<s:i<=s;)i*=2;o&&(i/=2)}else{for(;o?i>=s:i>s;)i/=2;o||(i*=2)}return i/t}t.Leafer.prototype.zoom=function(i,o,s){const{zoomLayer:h}=this,n=this.canvas.bounds.clone().shrink(void 0!==o?o:30),a=new t.Bounds,d={x:n.x+n.width/2,y:n.y+n.height/2};let r;const{scaleX:c}=this.__;if("string"==typeof i)switch(i){case"in":r=e(c,"in");break;case"out":r=e(c,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new t.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new t.Bounds(this.boxBounds)).width=0}else"number"==typeof i&&(r=i/c);if(r)1!==r&&h.scaleOfWorld(d,this.getValidScale(r));else if("object"==typeof i){const e=i instanceof Array;if(e||i.tag){const o=e?i:[i];a.setListWithFn(o,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:o,y:s,width:h,height:n}=t;return n||(n=h*(e.height/e.width),i=!0),h||(h=n*(e.width/e.height),i=!0),i?{x:o,y:s,width:h,height:n}:t}(i,n);a.set(h.getWorldBounds(t))}const{x:o,y:d,width:r,height:c}=a;let f=n.x-o,l=n.y-d;if(s)f+=Math.max((n.width-r)/2,0),l+=Math.max((n.height-c)/2,0);else{const t=this.getValidScale(Math.min(n.width/r,n.height/c));f+=(n.width-r*t)/2,l+=(n.height-c*t)/2,h.scaleOfWorld(a,t),a.scaleOf(a,t)}return h.move(f,l),a.move(f,l)}return h.worldBoxBounds}}(LeaferUI);
1
+ !function(t){"use strict";function e(t,e){let i=1;const o="out"===e,s=Math.abs(t);if(s>1){for(;o?i<s:i<=s;)i*=2;o&&(i/=2)}else{for(;o?i>=s:i>s;)i/=2;o||(i*=2)}return i/t}t.Plugin.add("view"),t.Leafer.prototype.zoom=function(i,o,s){const{zoomLayer:h}=this,n=this.canvas.bounds.clone().shrink(void 0!==o?o:30),a=new t.Bounds,d={x:n.x+n.width/2,y:n.y+n.height/2};let r;const{scaleX:c}=this.__;if("string"==typeof i)switch(i){case"in":r=e(c,"in");break;case"out":r=e(c,"out");break;case"fit":i=this.boxBounds;break;case"fit-width":(i=new t.Bounds(this.boxBounds)).height=0;break;case"fit-height":(i=new t.Bounds(this.boxBounds)).width=0}else"number"==typeof i&&(r=i/c);if(r)1!==r&&h.scaleOfWorld(d,this.getValidScale(r));else if("object"==typeof i){const e=i instanceof Array;if(e||i.tag){const o=e?i:[i];a.setListWithFn(o,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:o,y:s,width:h,height:n}=t;return n||(n=h*(e.height/e.width),i=!0),h||(h=n*(e.width/e.height),i=!0),i?{x:o,y:s,width:h,height:n}:t}(i,n);a.set(h.getWorldBounds(t))}const{x:o,y:d,width:r,height:c}=a;let f=n.x-o,l=n.y-d;if(s)f+=Math.max((n.width-r)/2,0),l+=Math.max((n.height-c)/2,0);else{const t=this.getValidScale(Math.min(n.width/r,n.height/c));f+=(n.width-r*t)/2,l+=(n.height-c*t)/2,h.scaleOfWorld(a,t),a.scaleOf(a,t)}return h.move(f,l),a.move(f,l)}return h.worldBoxBounds}}(LeaferUI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/view",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "description": "@leafer-in/view",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -34,8 +34,8 @@
34
34
  "leaferjs"
35
35
  ],
36
36
  "peerDependencies": {
37
- "@leafer-ui/draw": "^1.1.2",
38
- "@leafer-ui/interface": "^1.1.2",
39
- "@leafer-in/interface": "^1.1.2"
37
+ "@leafer-ui/draw": "^1.2.1",
38
+ "@leafer-ui/interface": "^1.2.1",
39
+ "@leafer-in/interface": "^1.2.1"
40
40
  }
41
41
  }
package/src/index.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import { ILeaf, IBoundsData, IZoomType, IFourNumber, IPointData } from '@leafer-ui/interface'
2
- import { Leafer, Bounds, LeafBoundsHelper } from '@leafer-ui/draw'
2
+ import { Leafer, Bounds, LeafBoundsHelper, Plugin } from '@leafer-ui/draw'
3
3
 
4
4
  import { getFixBounds, getZoomScale } from './helper'
5
5
 
6
6
 
7
+ Plugin.add('view')
8
+
9
+
7
10
  Leafer.prototype.zoom = function (zoomType: IZoomType, padding?: IFourNumber, fixed?: boolean): IBoundsData {
8
11
 
9
12
  const { zoomLayer } = this