@leafer-in/view 1.12.1 → 1.12.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.
package/dist/view.cjs CHANGED
@@ -31,7 +31,6 @@ function getFixBounds(bounds, scaleBounds) {
31
31
  draw.Plugin.add("view");
32
32
 
33
33
  draw.Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition) {
34
- this.killAnimate();
35
34
  let padding;
36
35
  if (draw.isData(optionsOrPadding)) {
37
36
  padding = optionsOrPadding.padding;
@@ -44,8 +43,9 @@ draw.Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transi
44
43
  x: limitBounds.x + limitBounds.width / 2,
45
44
  y: limitBounds.y + limitBounds.height / 2
46
45
  };
46
+ zoomLayer.killAnimate();
47
47
  let changeScale;
48
- const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
48
+ const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__, {boxBounds: boxBounds} = zoomLayer;
49
49
  if (draw.isString(zoomType)) {
50
50
  switch (zoomType) {
51
51
  case "in":
@@ -57,16 +57,16 @@ draw.Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transi
57
57
  break;
58
58
 
59
59
  case "fit":
60
- zoomType = this.boxBounds;
60
+ zoomType = boxBounds;
61
61
  break;
62
62
 
63
63
  case "fit-width":
64
- zoomType = new draw.Bounds(this.boxBounds);
64
+ zoomType = new draw.Bounds(boxBounds);
65
65
  zoomType.height = 0;
66
66
  break;
67
67
 
68
68
  case "fit-height":
69
- zoomType = new draw.Bounds(this.boxBounds);
69
+ zoomType = new draw.Bounds(boxBounds);
70
70
  zoomType.width = 0;
71
71
  break;
72
72
  }
package/dist/view.esm.js CHANGED
@@ -29,7 +29,6 @@ function getFixBounds(bounds, scaleBounds) {
29
29
  Plugin.add("view");
30
30
 
31
31
  Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition) {
32
- this.killAnimate();
33
32
  let padding;
34
33
  if (isData(optionsOrPadding)) {
35
34
  padding = optionsOrPadding.padding;
@@ -42,8 +41,9 @@ Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition)
42
41
  x: limitBounds.x + limitBounds.width / 2,
43
42
  y: limitBounds.y + limitBounds.height / 2
44
43
  };
44
+ zoomLayer.killAnimate();
45
45
  let changeScale;
46
- const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
46
+ const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__, {boxBounds: boxBounds} = zoomLayer;
47
47
  if (isString(zoomType)) {
48
48
  switch (zoomType) {
49
49
  case "in":
@@ -55,16 +55,16 @@ Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition)
55
55
  break;
56
56
 
57
57
  case "fit":
58
- zoomType = this.boxBounds;
58
+ zoomType = boxBounds;
59
59
  break;
60
60
 
61
61
  case "fit-width":
62
- zoomType = new Bounds(this.boxBounds);
62
+ zoomType = new Bounds(boxBounds);
63
63
  zoomType.height = 0;
64
64
  break;
65
65
 
66
66
  case "fit-height":
67
- zoomType = new Bounds(this.boxBounds);
67
+ zoomType = new Bounds(boxBounds);
68
68
  zoomType.width = 0;
69
69
  break;
70
70
  }
@@ -1,2 +1,2 @@
1
- import{Plugin as t,Leafer as e,isData as i,isNull as s,Bounds as h,isString as o,isNumber as a,isObject as n,isArray as l,LeafBoundsHelper as c,PointHelper as d}from"@leafer-ui/draw";function r(t,e){let i=1;const s="out"===e,h=Math.abs(t);if(h>1){for(;s?i<h:i<=h;)i*=2;s&&(i/=2)}else{for(;s?i>=h:i>h;)i/=2;s||(i*=2)}return i/t}t.add("view"),e.prototype.zoom=function(t,e,w,f){let u;this.killAnimate(),i(e)?(u=e.padding,w=e.scroll,f=e.transition):u=e;const{zoomLayer:g}=this,x=this.canvas.bounds.clone().shrink(s(u)?30:u),y=new h,m={x:x.x+x.width/2,y:x.y+x.height/2};let b;const{x:B,y:k,scaleX:p,scaleY:v}=g.__;if(o(t))switch(t){case"in":b=r(p,"in");break;case"out":b=r(p,"out");break;case"fit":t=this.boxBounds;break;case"fit-width":(t=new h(this.boxBounds)).height=0;break;case"fit-height":(t=new h(this.boxBounds)).width=0}else a(t)&&(b=t/p);if(b)b=this.getValidScale(b),g.scaleOfWorld(m,b,b,!1,f);else if(n(t)){const e={x:B,y:k,scaleX:p,scaleY:v},i=l(t);if(i||t.tag){const e=i?t:[t];y.setListWithFn(e,c.worldBounds)}else{const e=function(t,e){let i,{x:s,y:h,width:o,height:a}=t;return a||(a=o*(e.height/e.width),i=!0),o||(o=a*(e.width/e.height),i=!0),i?{x:s,y:h,width:o,height:a}:t}(t,x);y.set(g.getWorldBounds(e))}const{width:s,height:h}=y;let o=x.x-y.x,a=x.y-y.y;return w?(o+=Math.max((x.width-s)/2,0),a+=Math.max((x.height-h)/2,0)):(b=this.getValidScale(Math.min(x.width/s,x.height/h)),o+=(x.width-s*b)/2,a+=(x.height-h*b)/2,d.scaleOf(e,y,b),y.scaleOf(y,b),e.scaleX*=b,e.scaleY*=b),"x"===w?a=0:"y"===w&&(o=0),d.move(e,o,a),y.move(o,a),g.set(e,f),y}return g.worldBoxBounds};
1
+ import{Plugin as t,Leafer as e,isData as i,isNull as h,Bounds as s,isString as a,isNumber as o,isObject as n,isArray as l,LeafBoundsHelper as c,PointHelper as d}from"@leafer-ui/draw";function r(t,e){let i=1;const h="out"===e,s=Math.abs(t);if(s>1){for(;h?i<s:i<=s;)i*=2;h&&(i/=2)}else{for(;h?i>=s:i>s;)i/=2;h||(i*=2)}return i/t}t.add("view"),e.prototype.zoom=function(t,e,w,f){let g;i(e)?(g=e.padding,w=e.scroll,f=e.transition):g=e;const{zoomLayer:u}=this,x=this.canvas.bounds.clone().shrink(h(g)?30:g),y=new s,m={x:x.x+x.width/2,y:x.y+x.height/2};let b;u.killAnimate();const{x:k,y:B,scaleX:p,scaleY:v}=u.__,{boxBounds:M}=u;if(a(t))switch(t){case"in":b=r(p,"in");break;case"out":b=r(p,"out");break;case"fit":t=M;break;case"fit-width":(t=new s(M)).height=0;break;case"fit-height":(t=new s(M)).width=0}else o(t)&&(b=t/p);if(b)b=this.getValidScale(b),u.scaleOfWorld(m,b,b,!1,f);else if(n(t)){const e={x:k,y:B,scaleX:p,scaleY:v},i=l(t);if(i||t.tag){const e=i?t:[t];y.setListWithFn(e,c.worldBounds)}else{const e=function(t,e){let i,{x:h,y:s,width:a,height:o}=t;return o||(o=a*(e.height/e.width),i=!0),a||(a=o*(e.width/e.height),i=!0),i?{x:h,y:s,width:a,height:o}:t}(t,x);y.set(u.getWorldBounds(e))}const{width:h,height:s}=y;let a=x.x-y.x,o=x.y-y.y;return w?(a+=Math.max((x.width-h)/2,0),o+=Math.max((x.height-s)/2,0)):(b=this.getValidScale(Math.min(x.width/h,x.height/s)),a+=(x.width-h*b)/2,o+=(x.height-s*b)/2,d.scaleOf(e,y,b),y.scaleOf(y,b),e.scaleX*=b,e.scaleY*=b),"x"===w?o=0:"y"===w&&(a=0),d.move(e,a,o),y.move(a,o),u.set(e,f),y}return u.worldBoxBounds};
2
2
  //# sourceMappingURL=view.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.esm.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","isData","zoomLayer","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","scaleY","__","isString","boxBounds","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"uLAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,K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AErB"}
1
+ {"version":3,"file":"view.esm.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n zoomLayer.killAnimate()\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__, { boxBounds } = zoomLayer\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","isData","zoomLayer","this","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","killAnimate","scaleY","__","boxBounds","isString","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"uLAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,EACvB,CACA,OAAOA,EAAQF,CACnB,CCRAO,EAAOC,IAAI,QAGXC,EAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAEhI,IAAIC,EAEAC,EAAqBJ,IACrBG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OAC1BC,EAAaF,EAAiBE,YAC3BC,EAAUH,EAEjB,MAAMK,UAAEA,GAAcC,KAChBC,EAAcD,KAAKE,OAAOC,OAAOC,QAAQC,OAAOC,EAAOT,GAAW,GAAKA,GAAUM,EAAS,IAAII,EAC9FC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAI/G,IAAIC,EAFJd,EAAUe,cAGV,MAAML,EAAEA,EAACE,EAAEA,EAAC9B,OAAEA,EAAMkC,OAAEA,GAAWhB,EAAUiB,IAAIC,UAAEA,GAAclB,EAE/D,GAAImB,EAASzB,GAET,OAAQA,GACJ,IAAK,KACDoB,EAAcjC,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AAU,EAAG,KAIrDC,EAAcb,KAAKoB,cAAclC,KAAKsD,IAAIvC,EAAYS,MAAQA,EAAOT,EAAYW,OAASA,IAC1FyB,IAAUpC,EAAYS,MAAQA,EAAQG,GAAe,EACrDyB,IAAUrC,EAAYW,OAASA,EAASC,GAAe,EAEvD4B,EAAYC,QAAQnB,EAAMpB,EAAQU,GAClCV,EAAOuC,QAAQvC,EAAQU,GAEvBU,EAAK1C,QAAUgC,EACfU,EAAKR,QAAUF,GAGJ,MAAXlB,EAAgB2C,EAAQ,EACR,MAAX3C,IAAgB0C,EAAQ,GAEjCI,EAAYE,KAAKpB,EAAMc,EAAOC,GAC9BnC,EAAOwC,KAAKN,EAAOC,GAEnBvC,EAAUoC,IAAIZ,EAAM3B,GAEbO,CAEX,CAEA,OAAOJ,EAAU6C,cAErB"}
package/dist/view.js CHANGED
@@ -26,7 +26,6 @@
26
26
  }
27
27
  draw.Plugin.add("view");
28
28
  draw.Leafer.prototype.zoom = function(zoomType, optionsOrPadding, scroll, transition) {
29
- this.killAnimate();
30
29
  let padding;
31
30
  if (draw.isData(optionsOrPadding)) {
32
31
  padding = optionsOrPadding.padding;
@@ -39,8 +38,9 @@
39
38
  x: limitBounds.x + limitBounds.width / 2,
40
39
  y: limitBounds.y + limitBounds.height / 2
41
40
  };
41
+ zoomLayer.killAnimate();
42
42
  let changeScale;
43
- const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__;
43
+ const {x: x, y: y, scaleX: scaleX, scaleY: scaleY} = zoomLayer.__, {boxBounds: boxBounds} = zoomLayer;
44
44
  if (draw.isString(zoomType)) {
45
45
  switch (zoomType) {
46
46
  case "in":
@@ -52,16 +52,16 @@
52
52
  break;
53
53
 
54
54
  case "fit":
55
- zoomType = this.boxBounds;
55
+ zoomType = boxBounds;
56
56
  break;
57
57
 
58
58
  case "fit-width":
59
- zoomType = new draw.Bounds(this.boxBounds);
59
+ zoomType = new draw.Bounds(boxBounds);
60
60
  zoomType.height = 0;
61
61
  break;
62
62
 
63
63
  case "fit-height":
64
- zoomType = new draw.Bounds(this.boxBounds);
64
+ zoomType = new draw.Bounds(boxBounds);
65
65
  zoomType.width = 0;
66
66
  break;
67
67
  }
package/dist/view.min.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("@leafer-ui/draw");function e(t,e){let i=1;const s="out"===e,h=Math.abs(t);if(h>1){for(;s?i<h:i<=h;)i*=2;s&&(i/=2)}else{for(;s?i>=h:i>h;)i/=2;s||(i*=2)}return i/t}t.Plugin.add("view"),t.Leafer.prototype.zoom=function(i,s,h,o){let n;this.killAnimate(),t.isData(s)?(n=s.padding,h=s.scroll,o=s.transition):n=s;const{zoomLayer:a}=this,l=this.canvas.bounds.clone().shrink(t.isNull(n)?30:n),r=new t.Bounds,d={x:l.x+l.width/2,y:l.y+l.height/2};let c;const{x:u,y:f,scaleX:w,scaleY:g}=a.__;if(t.isString(i))switch(i){case"in":c=e(w,"in");break;case"out":c=e(w,"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 t.isNumber(i)&&(c=i/w);if(c)c=this.getValidScale(c),a.scaleOfWorld(d,c,c,!1,o);else if(t.isObject(i)){const e={x:u,y:f,scaleX:w,scaleY:g},s=t.isArray(i);if(s||i.tag){const e=s?i:[i];r.setListWithFn(e,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:s,y:h,width:o,height:n}=t;return n||(n=o*(e.height/e.width),i=!0),o||(o=n*(e.width/e.height),i=!0),i?{x:s,y:h,width:o,height:n}:t}(i,l);r.set(a.getWorldBounds(t))}const{width:n,height:d}=r;let x=l.x-r.x,y=l.y-r.y;return h?(x+=Math.max((l.width-n)/2,0),y+=Math.max((l.height-d)/2,0)):(c=this.getValidScale(Math.min(l.width/n,l.height/d)),x+=(l.width-n*c)/2,y+=(l.height-d*c)/2,t.PointHelper.scaleOf(e,r,c),r.scaleOf(r,c),e.scaleX*=c,e.scaleY*=c),"x"===h?y=0:"y"===h&&(x=0),t.PointHelper.move(e,x,y),r.move(x,y),a.set(e,o),r}return a.worldBoxBounds};
1
+ "use strict";var e=require("@leafer-ui/draw");function t(e,t){let i=1;const s="out"===t,a=Math.abs(e);if(a>1){for(;s?i<a:i<=a;)i*=2;s&&(i/=2)}else{for(;s?i>=a:i>a;)i/=2;s||(i*=2)}return i/e}e.Plugin.add("view"),e.Leafer.prototype.zoom=function(i,s,a,h){let n;e.isData(s)?(n=s.padding,a=s.scroll,h=s.transition):n=s;const{zoomLayer:o}=this,l=this.canvas.bounds.clone().shrink(e.isNull(n)?30:n),r=new e.Bounds,c={x:l.x+l.width/2,y:l.y+l.height/2};let d;o.killAnimate();const{x:u,y:f,scaleX:w,scaleY:g}=o.__,{boxBounds:x}=o;if(e.isString(i))switch(i){case"in":d=t(w,"in");break;case"out":d=t(w,"out");break;case"fit":i=x;break;case"fit-width":(i=new e.Bounds(x)).height=0;break;case"fit-height":(i=new e.Bounds(x)).width=0}else e.isNumber(i)&&(d=i/w);if(d)d=this.getValidScale(d),o.scaleOfWorld(c,d,d,!1,h);else if(e.isObject(i)){const t={x:u,y:f,scaleX:w,scaleY:g},s=e.isArray(i);if(s||i.tag){const t=s?i:[i];r.setListWithFn(t,e.LeafBoundsHelper.worldBounds)}else{const e=function(e,t){let i,{x:s,y:a,width:h,height:n}=e;return n||(n=h*(t.height/t.width),i=!0),h||(h=n*(t.width/t.height),i=!0),i?{x:s,y:a,width:h,height:n}:e}(i,l);r.set(o.getWorldBounds(e))}const{width:n,height:c}=r;let x=l.x-r.x,y=l.y-r.y;return a?(x+=Math.max((l.width-n)/2,0),y+=Math.max((l.height-c)/2,0)):(d=this.getValidScale(Math.min(l.width/n,l.height/c)),x+=(l.width-n*d)/2,y+=(l.height-c*d)/2,e.PointHelper.scaleOf(t,r,d),r.scaleOf(r,d),t.scaleX*=d,t.scaleY*=d),"x"===a?y=0:"y"===a&&(x=0),e.PointHelper.move(t,x,y),r.move(x,y),o.set(t,h),r}return o.worldBoxBounds};
2
2
  //# sourceMappingURL=view.min.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.min.cjs","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","isData","zoomLayer","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","scaleY","__","isString","boxBounds","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"8CAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,EACvB,CACA,OAAOA,EAAQF,CACnB,CCRAO,EAAAA,OAAOC,IAAI,QAGXC,EAAAA,OAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAIhI,IAAIC,EAFJC,KAAKC,cAIDC,EAAAA,OAAqBN,IACrBG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OAC1BC,EAAaF,EAAiBE,YAC3BC,EAAUH,EAEjB,MAAMO,UAAEA,GAAcH,KAChBI,EAAcJ,KAAKK,OAAOC,OAAOC,QAAQC,OAAOC,EAAAA,OAAOV,GAAW,GAAKA,GAAUO,EAAS,IAAII,EAAAA,OAC9FC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAE/G,IAAIC,EACJ,MAAMJ,EAAEA,EAACE,EAAEA,EAAC/B,OA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AAIN,EAAOM,EAAG4B,EAAQpC,EAAYU,EAAIR,EAAOQ,EA4BrE,OA1BIjB,GAEA0C,GAASnD,KAAKqD,KAAKrC,EAAYS,MAAQA,GAAS,EAAG,GACnD2B,GAASpD,KAAKqD,KAAKrC,EAAYW,OAASA,GAAU,EAAG,KAIrDC,EAAchB,KAAKsB,cAAclC,KAAKsD,IAAItC,EAAYS,MAAQA,EAAOT,EAAYW,OAASA,IAC1FwB,IAAUnC,EAAYS,MAAQA,EAAQG,GAAe,EACrDwB,IAAUpC,EAAYW,OAASA,EAASC,GAAe,EAEvD2B,EAAAA,YAAYC,QAAQnB,EAAMnB,EAAQU,GAClCV,EAAOsC,QAAQtC,EAAQU,GAEvBS,EAAK1C,QAAUiC,EACfS,EAAKR,QAAUD,GAGJ,MAAXnB,EAAgB2C,EAAQ,EACR,MAAX3C,IAAgB0C,EAAQ,GAEjCI,EAAAA,YAAYE,KAAKpB,EAAMc,EAAOC,GAC9BlC,EAAOuC,KAAKN,EAAOC,GAEnBrC,EAAUkC,IAAIZ,EAAM3B,GAEbQ,CAEX,CAEA,OAAOH,EAAU2C,cAErB"}
1
+ {"version":3,"file":"view.min.cjs","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n zoomLayer.killAnimate()\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__, { boxBounds } = zoomLayer\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","isData","zoomLayer","this","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","killAnimate","scaleY","__","boxBounds","isString","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"8CAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GA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EnBvC,EAAUoC,IAAIZ,EAAM3B,GAEbO,CAEX,CAEA,OAAOJ,EAAU6C,cAErB"}
package/dist/view.min.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(t){"use strict";function e(t,e){let i=1;const s="out"===e,h=Math.abs(t);if(h>1){for(;s?i<h:i<=h;)i*=2;s&&(i/=2)}else{for(;s?i>=h:i>h;)i/=2;s||(i*=2)}return i/t}t.Plugin.add("view"),t.Leafer.prototype.zoom=function(i,s,h,n){let o;this.killAnimate(),t.isData(s)?(o=s.padding,h=s.scroll,n=s.transition):o=s;const{zoomLayer:a}=this,l=this.canvas.bounds.clone().shrink(t.isNull(o)?30:o),c=new t.Bounds,r={x:l.x+l.width/2,y:l.y+l.height/2};let d;const{x:u,y:f,scaleX:g,scaleY:w}=a.__;if(t.isString(i))switch(i){case"in":d=e(g,"in");break;case"out":d=e(g,"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 t.isNumber(i)&&(d=i/g);if(d)d=this.getValidScale(d),a.scaleOfWorld(r,d,d,!1,n);else if(t.isObject(i)){const e={x:u,y:f,scaleX:g,scaleY:w},s=t.isArray(i);if(s||i.tag){const e=s?i:[i];c.setListWithFn(e,t.LeafBoundsHelper.worldBounds)}else{const t=function(t,e){let i,{x:s,y:h,width:n,height:o}=t;return o||(o=n*(e.height/e.width),i=!0),n||(n=o*(e.width/e.height),i=!0),i?{x:s,y:h,width:n,height:o}:t}(i,l);c.set(a.getWorldBounds(t))}const{width:o,height:r}=c;let x=l.x-c.x,y=l.y-c.y;return h?(x+=Math.max((l.width-o)/2,0),y+=Math.max((l.height-r)/2,0)):(d=this.getValidScale(Math.min(l.width/o,l.height/r)),x+=(l.width-o*d)/2,y+=(l.height-r*d)/2,t.PointHelper.scaleOf(e,c,d),c.scaleOf(c,d),e.scaleX*=d,e.scaleY*=d),"x"===h?y=0:"y"===h&&(x=0),t.PointHelper.move(e,x,y),c.move(x,y),a.set(e,n),c}return a.worldBoxBounds}}(LeaferUI);
1
+ !function(e){"use strict";function t(e,t){let i=1;const s="out"===t,n=Math.abs(e);if(n>1){for(;s?i<n:i<=n;)i*=2;s&&(i/=2)}else{for(;s?i>=n:i>n;)i/=2;s||(i*=2)}return i/e}e.Plugin.add("view"),e.Leafer.prototype.zoom=function(i,s,n,h){let o;e.isData(s)?(o=s.padding,n=s.scroll,h=s.transition):o=s;const{zoomLayer:a}=this,l=this.canvas.bounds.clone().shrink(e.isNull(o)?30:o),c=new e.Bounds,r={x:l.x+l.width/2,y:l.y+l.height/2};let d;a.killAnimate();const{x:u,y:f,scaleX:g,scaleY:w}=a.__,{boxBounds:x}=a;if(e.isString(i))switch(i){case"in":d=t(g,"in");break;case"out":d=t(g,"out");break;case"fit":i=x;break;case"fit-width":(i=new e.Bounds(x)).height=0;break;case"fit-height":(i=new e.Bounds(x)).width=0}else e.isNumber(i)&&(d=i/g);if(d)d=this.getValidScale(d),a.scaleOfWorld(r,d,d,!1,h);else if(e.isObject(i)){const t={x:u,y:f,scaleX:g,scaleY:w},s=e.isArray(i);if(s||i.tag){const t=s?i:[i];c.setListWithFn(t,e.LeafBoundsHelper.worldBounds)}else{const e=function(e,t){let i,{x:s,y:n,width:h,height:o}=e;return o||(o=h*(t.height/t.width),i=!0),h||(h=o*(t.width/t.height),i=!0),i?{x:s,y:n,width:h,height:o}:e}(i,l);c.set(a.getWorldBounds(e))}const{width:o,height:r}=c;let x=l.x-c.x,y=l.y-c.y;return n?(x+=Math.max((l.width-o)/2,0),y+=Math.max((l.height-r)/2,0)):(d=this.getValidScale(Math.min(l.width/o,l.height/r)),x+=(l.width-o*d)/2,y+=(l.height-r*d)/2,e.PointHelper.scaleOf(t,c,d),c.scaleOf(c,d),t.scaleX*=d,t.scaleY*=d),"x"===n?y=0:"y"===n&&(x=0),e.PointHelper.move(t,x,y),c.move(x,y),a.set(t,h),c}return a.worldBoxBounds}}(LeaferUI);
2
2
  //# sourceMappingURL=view.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n this.killAnimate()\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = this.boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(this.boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(this.boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","this","killAnimate","isData","zoomLayer","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","scaleY","__","isString","boxBounds","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"0BAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,EACvB,CACA,OAAOA,EAAQF,CACnB,CCRAO,EAAAA,OAAOC,IAAI,QAGXC,EAAAA,OAAOC,UAAUC,KAAO,SAAUC,EAAqBC,EAA+CC,EAA8BC,GAIhI,IAAIC,EAFJC,KAAKC,cAIDC,EAAAA,OAAqBN,IACrBG,EAAUH,EAAiBG,QAC3BF,EAASD,EAAiBC,OAC1BC,EAAaF,EAAiBE,YAC3BC,EAAUH,EAEjB,MAAMO,UAAEA,GAAcH,KAChBI,EAAcJ,KAAKK,OAAOC,OAAOC,QAAQC,OAAOC,EAAAA,OAAOV,GAAW,GAAKA,GAAUO,EAAS,IAAII,EAAAA,OAC9FC,EAAqB,CAAEC,EAAGR,EAAYQ,EAAIR,EAAYS,MAAQ,EAAGC,EAAGV,EAAYU,EAAIV,EAAYW,OAAS,GAE/G,IAAIC,EACJ,MAAMJ,EAAEA,EAACE,EAAEA,EAAC/B,OAAEA,EAAMkC,OAAEA,GAAWd,EAAUe,GAE3C,GAAIC,EAAAA,SAASxB,GAET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jB,GAEA0C,GAASnD,KAAKqD,KAAKrC,EAAYS,MAAQA,GAAS,EAAG,GACnD2B,GAASpD,KAAKqD,KAAKrC,EAAYW,OAASA,GAAU,EAAG,KAIrDC,EAAchB,KAAKsB,cAAclC,KAAKsD,IAAItC,EAAYS,MAAQA,EAAOT,EAAYW,OAASA,IAC1FwB,IAAUnC,EAAYS,MAAQA,EAAQG,GAAe,EACrDwB,IAAUpC,EAAYW,OAASA,EAASC,GAAe,EAEvD2B,EAAAA,YAAYC,QAAQnB,EAAMnB,EAAQU,GAClCV,EAAOsC,QAAQtC,EAAQU,GAEvBS,EAAK1C,QAAUiC,EACfS,EAAKR,QAAUD,GAGJ,MAAXnB,EAAgB2C,EAAQ,EACR,MAAX3C,IAAgB0C,EAAQ,GAEjCI,EAAAA,YAAYE,KAAKpB,EAAMc,EAAOC,GAC9BlC,EAAOuC,KAAKN,EAAOC,GAEnBrC,EAAUkC,IAAIZ,EAAM3B,GAEbQ,CAEX,CAEA,OAAOH,EAAU2C,cAErB"}
1
+ {"version":3,"file":"view.min.js","sources":["../../../../../../src/in/packages/view/src/helper.ts","../../../../../../src/in/packages/view/src/index.ts"],"sourcesContent":["import { IBoundsData } from '@leafer-ui/interface'\n\n\nexport function getZoomScale(scaleX: number, type: 'in' | 'out'): number {\n let scale = 1\n const out = type === 'out', absScale = Math.abs(scaleX)\n if (absScale > 1) {\n while (out ? scale < absScale : scale <= absScale) scale *= 2\n if (out) scale /= 2\n } else {\n while (out ? scale >= absScale : scale > absScale) scale /= 2\n if (!out) scale *= 2\n }\n return scale / scaleX\n}\n\nexport function getFixBounds(bounds: IBoundsData, scaleBounds: IBoundsData): IBoundsData {\n let { x, y, width, height } = bounds\n let fix: boolean\n if (!height) height = width * (scaleBounds.height / scaleBounds.width), fix = true\n if (!width) width = height * (scaleBounds.width / scaleBounds.height), fix = true\n return fix ? { x, y, width, height } : bounds\n}","import { ILeaf, IBoundsData, IZoomType, IZoomOptions, IFourNumber, IPointData, ITransition } from '@leafer-ui/interface'\nimport { Leafer, Bounds, LeafBoundsHelper, Plugin, PointHelper, isNull, isData, isObject, isArray, isString, isNumber } from '@leafer-ui/draw'\n\nimport { getFixBounds, getZoomScale } from './helper'\n\n\nPlugin.add('view')\n\n\nLeafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {\n\n let padding: IFourNumber\n\n if (isData<IZoomOptions>(optionsOrPadding)) {\n padding = optionsOrPadding.padding\n scroll = optionsOrPadding.scroll\n transition = optionsOrPadding.transition\n } else padding = optionsOrPadding\n\n const { zoomLayer } = this\n const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()\n const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }\n\n zoomLayer.killAnimate()\n\n let changeScale: number\n const { x, y, scaleX, scaleY } = zoomLayer.__, { boxBounds } = zoomLayer\n\n if (isString(zoomType)) {\n\n switch (zoomType) {\n case 'in':\n changeScale = getZoomScale(scaleX, 'in')\n break\n case 'out':\n changeScale = getZoomScale(scaleX, 'out')\n break\n case 'fit':\n zoomType = boxBounds\n break\n case 'fit-width':\n zoomType = new Bounds(boxBounds)\n zoomType.height = 0\n break\n case 'fit-height':\n zoomType = new Bounds(boxBounds)\n zoomType.width = 0\n break\n }\n\n } else if (isNumber(zoomType)) {\n changeScale = zoomType / scaleX\n }\n\n\n if (changeScale) {\n\n changeScale = this.getValidScale(changeScale)\n zoomLayer.scaleOfWorld(center, changeScale, changeScale, false, transition)\n\n } else if (isObject(zoomType)) {\n\n const data = { x, y, scaleX, scaleY }\n const isArr = isArray(zoomType)\n\n if (isArr || (zoomType as ILeaf).tag) {\n const list: ILeaf[] = isArr ? zoomType as ILeaf[] : [zoomType as ILeaf]\n bounds.setListWithFn(list, LeafBoundsHelper.worldBounds)\n } else {\n const innerBounds = getFixBounds(zoomType as IBoundsData, limitBounds)\n bounds.set(zoomLayer.getWorldBounds(innerBounds))\n }\n\n const { width, height } = bounds\n let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y\n\n if (scroll) {\n\n moveX += Math.max((limitBounds.width - width) / 2, 0)\n moveY += Math.max((limitBounds.height - height) / 2, 0)\n\n } else {\n\n changeScale = this.getValidScale(Math.min(limitBounds.width / width, limitBounds.height / height))\n moveX += (limitBounds.width - width * changeScale) / 2\n moveY += (limitBounds.height - height * changeScale) / 2\n\n PointHelper.scaleOf(data, bounds, changeScale)\n bounds.scaleOf(bounds, changeScale)\n\n data.scaleX *= changeScale\n data.scaleY *= changeScale\n }\n\n if (scroll === 'x') moveY = 0\n else if (scroll === 'y') moveX = 0\n\n PointHelper.move(data, moveX, moveY)\n bounds.move(moveX, moveY)\n\n zoomLayer.set(data, transition)\n\n return bounds\n\n }\n\n return zoomLayer.worldBoxBounds\n\n}"],"names":["getZoomScale","scaleX","type","scale","out","absScale","Math","abs","Plugin","add","Leafer","prototype","zoom","zoomType","optionsOrPadding","scroll","transition","padding","isData","zoomLayer","this","limitBounds","canvas","bounds","clone","shrink","isNull","Bounds","center","x","width","y","height","changeScale","killAnimate","scaleY","__","boxBounds","isString","isNumber","getValidScale","scaleOfWorld","isObject","data","isArr","isArray","tag","list","setListWithFn","LeafBoundsHelper","worldBounds","innerBounds","scaleBounds","fix","getFixBounds","set","getWorldBounds","moveX","moveY","max","min","PointHelper","scaleOf","move","worldBoxBounds"],"mappings":"0BAGM,SAAUA,EAAaC,EAAgBC,GACzC,IAAIC,EAAQ,EACZ,MAAMC,EAAe,QAATF,EAAgBG,EAAWC,KAAKC,IAAIN,GAChD,GAAII,EAAW,EAAG,CACd,KAAOD,EAAMD,EAAQE,EAAWF,GAASE,GAAUF,GAAS,EACxDC,IAAKD,GAAS,EACtB,KAAO,CACH,KAAOC,EAAMD,GAASE,EAAWF,EAAQE,GAAUF,GAAS,EACvDC,IAAKD,GAAS,EACvB,CACA,OAAOA,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AErB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-in/view",
3
- "version": "1.12.1",
3
+ "version": "1.12.2",
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.12.1",
38
- "@leafer-ui/interface": "^1.12.1",
39
- "@leafer-in/interface": "^1.12.1"
37
+ "@leafer-ui/draw": "^1.12.2",
38
+ "@leafer-ui/interface": "^1.12.2",
39
+ "@leafer-in/interface": "^1.12.2"
40
40
  }
41
41
  }
package/src/index.ts CHANGED
@@ -9,8 +9,6 @@ Plugin.add('view')
9
9
 
10
10
  Leafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomOptions | IFourNumber, scroll?: 'x' | 'y' | boolean, transition?: ITransition): IBoundsData {
11
11
 
12
- this.killAnimate()
13
-
14
12
  let padding: IFourNumber
15
13
 
16
14
  if (isData<IZoomOptions>(optionsOrPadding)) {
@@ -23,8 +21,10 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomO
23
21
  const limitBounds = this.canvas.bounds.clone().shrink(isNull(padding) ? 30 : padding), bounds = new Bounds()
24
22
  const center: IPointData = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 }
25
23
 
24
+ zoomLayer.killAnimate()
25
+
26
26
  let changeScale: number
27
- const { x, y, scaleX, scaleY } = zoomLayer.__
27
+ const { x, y, scaleX, scaleY } = zoomLayer.__, { boxBounds } = zoomLayer
28
28
 
29
29
  if (isString(zoomType)) {
30
30
 
@@ -36,14 +36,14 @@ Leafer.prototype.zoom = function (zoomType: IZoomType, optionsOrPadding?: IZoomO
36
36
  changeScale = getZoomScale(scaleX, 'out')
37
37
  break
38
38
  case 'fit':
39
- zoomType = this.boxBounds
39
+ zoomType = boxBounds
40
40
  break
41
41
  case 'fit-width':
42
- zoomType = new Bounds(this.boxBounds)
42
+ zoomType = new Bounds(boxBounds)
43
43
  zoomType.height = 0
44
44
  break
45
45
  case 'fit-height':
46
- zoomType = new Bounds(this.boxBounds)
46
+ zoomType = new Bounds(boxBounds)
47
47
  zoomType.width = 0
48
48
  break
49
49
  }