dom-2d-camera
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -503,2 +503,4 @@ import { mat4, vec4, vec2 } from 'gl-matrix'; | ||
refresh(); | ||
return camera; | ||
@@ -505,0 +507,0 @@ }; |
@@ -525,2 +525,4 @@ (function (global, factory) { | ||
refresh(); | ||
return camera; | ||
@@ -527,0 +529,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("gl-matrix")):"function"==typeof define&&define.amd?define(["gl-matrix"],n):(e=e||self).createDom2dCamera=n(e.glMatrix)}(this,(function(e){"use strict";var n=function(n,t,o,r,a,i){void 0===n&&(n=[0,0]),void 0===t&&(t=1),void 0===o&&(o=0),void 0===r&&(r=[0,0]),void 0===a&&(a=[[0,1/0],[0,1/0]]),void 0===i&&(i=[[-1/0,1/0],[-1/0,1/0]]);var v=new Float32Array(16),u=new Float32Array(16),c=new Float32Array(16),s=e.mat4.create(),d=r.slice(0,2).concat([0],[1]),l=Array.isArray(a[0])?[].concat(a[0]):[].concat(a),f=Array.isArray(a[0])?[].concat(a[1]):[].concat(a),m=Array.isArray(i[0])?[].concat(i[0]):[].concat(i),y=Array.isArray(i[0])?[].concat(i[1]):[].concat(i),p=function(){return e.mat4.getScaling(v,s).slice(0,2)},w=function(){var e=p();return Math.min(e[0],e[1])},g=function(){var e=p();return Math.max(e[0],e[1])},A=function(n,t,o){void 0===n&&(n=[]);var r=n[0];void 0===r&&(r=0);var a=n[1];void 0===a&&(a=0),void 0===t&&(t=1),void 0===o&&(o=0),s=e.mat4.create(),M([-r,-a]),E(o),h(1/t)},M=function(n){void 0===n&&(n=[]);var t=n[0];void 0===t&&(t=0);var o=n[1];void 0===o&&(o=0),v[0]=t,v[1]=o,v[2]=0;var r=e.mat4.fromTranslation(u,v);e.mat4.multiply(s,r,s)},h=function(n,t){var o=Array.isArray(n),r=o?n[0]:n,a=o?n[1]:n;if(!(r<=0||a<=0||1===r&&1===a)){var i=p(),m=i[0]*r,y=i[1]*a;if(r=Math.max(l[0],Math.min(m,l[1]))/i[0],a=Math.max(f[0],Math.min(y,f[1]))/i[1],1!==r||1!==a){v[0]=r,v[1]=a,v[2]=1;var w=e.mat4.fromScaling(u,v),g=t?t.concat([0]):d,A=e.mat4.fromTranslation(v,g);e.mat4.multiply(s,A,e.mat4.multiply(s,w,e.mat4.multiply(s,e.mat4.invert(c,A),s)))}}},E=function(n){var t=e.mat4.create();e.mat4.fromRotation(t,n,[0,0,1]),e.mat4.multiply(s,t,s)},x=function(e){!e||e.length<16||(s=e)};return A(n,t,o),{get translation(){return e.mat4.getTranslation(v,s).slice(0,2)},get target(){return e.vec4.transformMat4(v,d,e.mat4.invert(c,s)).slice(0,2)},get scaling(){return p()},get minScaling(){return w()},get maxScaling(){return g()},get scaleBounds(){return[[].concat(l),[].concat(f)]},get translationBounds(){return[[].concat(m),[].concat(y)]},get distance(){return[1/(e=p())[0],1/e[1]];var e},get minDistance(){return 1/w()},get maxDistance(){return 1/g()},get rotation(){return Math.acos(s[0]/g())},get view(){return s},get viewCenter(){return d.slice(0,2)},lookAt:A,translate:M,pan:M,rotate:E,scale:h,zoom:h,reset:function(){A(n,t,o)},set:function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return console.warn("`set()` is deprecated. Please use `setView()` instead."),x.apply(void 0,e)},setScaleBounds:function(e){var n=Array.isArray(e[0]);l[0]=n?e[0][0]:e[0],l[1]=n?e[0][1]:e[1],f[0]=n?e[1][0]:e[0],f[1]=n?e[1][1]:e[1]},setTranslationBounds:function(e){var n=Array.isArray(e[0]);m[0]=n?e[0][0]:e[0],m[1]=n?e[0][1]:e[1],y[0]=n?e[1][0]:e[0],y[1]=n?e[1][1]:e[1]},setView:x,setViewCenter:function(e){d=e.slice(0,2).concat([0],[1])}}},t=["pan","rotate"],o={alt:"altKey",cmd:"metaKey",ctrl:"ctrlKey",meta:"metaKey",shift:"shiftKey"};return function(r,a){void 0===a&&(a={});var i=a.distance;void 0===i&&(i=1);var v=a.target;void 0===v&&(v=[0,0]);var u=a.rotation;void 0===u&&(u=0);var c=a.isNdc;void 0===c&&(c=!0);var s=a.isFixed;void 0===s&&(s=!1);var d=a.isPan;void 0===d&&(d=!0);var l=a.panSpeed;void 0===l&&(l=1);var f=a.isRotate;void 0===f&&(f=!0);var m=a.rotateSpeed;void 0===m&&(m=1);var y=a.defaultMouseDownMoveAction;void 0===y&&(y="pan");var p=a.mouseDownMoveModKey;void 0===p&&(p="alt");var w=a.isZoom;void 0===w&&(w=!0);var g=a.zoomSpeed;void 0===g&&(g=1);var A=a.viewCenter,M=a.scaleBounds,h=a.translationBounds,E=a.onKeyDown;void 0===E&&(E=function(){});var x=a.onKeyUp;void 0===x&&(x=function(){});var B=a.onMouseDown;void 0===B&&(B=function(){});var L=a.onMouseUp;void 0===L&&(L=function(){});var S=a.onMouseMove;void 0===S&&(S=function(){});var D=a.onWheel;void 0===D&&(D=function(){});var K=n(v,i,u,A,M,h),k=0,C=0,F=0,R=0,T=!1,b=0,z=1,P=1,V=1,X=!1,Y=!1,j=Array.isArray(d)?Boolean(d[0]):d,U=Array.isArray(d)?Boolean(d[1]):d,Z=Array.isArray(w)?Boolean(w[0]):w,q=Array.isArray(w)?Boolean(w[1]):w,N="pan"===y,O=c?function(e){return e/z*2*V}:function(e){return e},W=c?function(e){return e/P*2}:function(e){return-e},G=c?function(e){return(e/z*2-1)*V}:function(e){return e},H=c?function(e){return 1-e/P*2}:function(e){return e},I=function(e){Y=!1,x(e)},J=function(e){Y=e[o[p]],E(e)},Q=function(e){T=!1,L(e)},$=function(e){T=1===e.buttons,B(e)},_=void 0!==document.createEvent("MouseEvent").offsetX?function(e){k=e.offsetX,C=e.offsetY}:function(e){var n=r.getBoundingClientRect();k=e.clientX-n.left,C=e.clientY-n.top},ee=function(e){_(e),S(e)},ne=function(e){e.preventDefault(),_(e);var n=1===e.deltaMode?12:1;b+=n*(e.deltaY||0),D(e)};return window.addEventListener("keydown",J,{passive:!0}),window.addEventListener("keyup",I,{passive:!0}),r.addEventListener("mousedown",$,{passive:!0}),window.addEventListener("mouseup",Q,{passive:!0}),window.addEventListener("mousemove",ee,{passive:!0}),r.addEventListener("wheel",ne,{passive:!1}),K.config=function(e){void 0===e&&(e={});var n=e.defaultMouseDownMoveAction;void 0===n&&(n=null);var r=e.isFixed;void 0===r&&(r=null);var a=e.isPan;void 0===a&&(a=null);var i=e.isRotate;void 0===i&&(i=null);var v=e.isZoom;void 0===v&&(v=null);var u=e.panSpeed;void 0===u&&(u=null);var c=e.rotateSpeed;void 0===c&&(c=null);var A=e.zoomSpeed;void 0===A&&(A=null);var M=e.mouseDownMoveModKey;void 0===M&&(M=null),y=null!==n&&t.includes(n)?n:y,N="pan"===y,s=null!==r?r:s,d=null!==a?a:d,f=null!==i?i:f,w=null!==v?v:w,l=+u>0?u:l,m=+c>0?c:m,g=+A>0?A:g,p=null!==M&&Object.keys(o).includes(M)?M:p},K.dispose=function(){K=void 0,window.removeEventListener("keydown",J),window.removeEventListener("keyup",I),r.removeEventListener("mousedown",$),window.removeEventListener("mouseup",Q),window.removeEventListener("mousemove",ee),r.removeEventListener("wheel",ne)},K.refresh=function(){var e=r.getBoundingClientRect();z=e.width,P=e.height,V=z/P},K.tick=function(){if(s)return!1;X=!1;var n=k,t=C;if((j||U)&&T&&(N&&!Y||!N&&Y)){var o=j?O(l*(n-F)):0,r=U?W(l*(t-R)):0;K.pan([o,r]),X=!0}if(w&&b){var a=g*Math.exp(b/P),i=G(n),v=H(t);K.scale([Z?1/a:1,q?1/a:1],[i,v]),X=!0}if(f&&T&&(N&&Y||!N&&!Y)){var u=z/2,c=P/2,d=F-u,y=c-R,p=n-u,A=c-t,M=e.vec2.angle([d,y],[p,A]),h=d*A-p*y;K.rotate(m*M*Math.sign(h)),X=!0}return b=0,F=n,R=t,X},K}})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("gl-matrix")):"function"==typeof define&&define.amd?define(["gl-matrix"],n):(e=e||self).createDom2dCamera=n(e.glMatrix)}(this,(function(e){"use strict";var n=function(n,t,o,r,a,i){void 0===n&&(n=[0,0]),void 0===t&&(t=1),void 0===o&&(o=0),void 0===r&&(r=[0,0]),void 0===a&&(a=[[0,1/0],[0,1/0]]),void 0===i&&(i=[[-1/0,1/0],[-1/0,1/0]]);var v=new Float32Array(16),u=new Float32Array(16),c=new Float32Array(16),s=e.mat4.create(),d=r.slice(0,2).concat([0],[1]),l=Array.isArray(a[0])?[].concat(a[0]):[].concat(a),f=Array.isArray(a[0])?[].concat(a[1]):[].concat(a),m=Array.isArray(i[0])?[].concat(i[0]):[].concat(i),y=Array.isArray(i[0])?[].concat(i[1]):[].concat(i),p=function(){return e.mat4.getScaling(v,s).slice(0,2)},w=function(){var e=p();return Math.min(e[0],e[1])},g=function(){var e=p();return Math.max(e[0],e[1])},A=function(n,t,o){void 0===n&&(n=[]);var r=n[0];void 0===r&&(r=0);var a=n[1];void 0===a&&(a=0),void 0===t&&(t=1),void 0===o&&(o=0),s=e.mat4.create(),M([-r,-a]),E(o),h(1/t)},M=function(n){void 0===n&&(n=[]);var t=n[0];void 0===t&&(t=0);var o=n[1];void 0===o&&(o=0),v[0]=t,v[1]=o,v[2]=0;var r=e.mat4.fromTranslation(u,v);e.mat4.multiply(s,r,s)},h=function(n,t){var o=Array.isArray(n),r=o?n[0]:n,a=o?n[1]:n;if(!(r<=0||a<=0||1===r&&1===a)){var i=p(),m=i[0]*r,y=i[1]*a;if(r=Math.max(l[0],Math.min(m,l[1]))/i[0],a=Math.max(f[0],Math.min(y,f[1]))/i[1],1!==r||1!==a){v[0]=r,v[1]=a,v[2]=1;var w=e.mat4.fromScaling(u,v),g=t?t.concat([0]):d,A=e.mat4.fromTranslation(v,g);e.mat4.multiply(s,A,e.mat4.multiply(s,w,e.mat4.multiply(s,e.mat4.invert(c,A),s)))}}},E=function(n){var t=e.mat4.create();e.mat4.fromRotation(t,n,[0,0,1]),e.mat4.multiply(s,t,s)},x=function(e){!e||e.length<16||(s=e)};return A(n,t,o),{get translation(){return e.mat4.getTranslation(v,s).slice(0,2)},get target(){return e.vec4.transformMat4(v,d,e.mat4.invert(c,s)).slice(0,2)},get scaling(){return p()},get minScaling(){return w()},get maxScaling(){return g()},get scaleBounds(){return[[].concat(l),[].concat(f)]},get translationBounds(){return[[].concat(m),[].concat(y)]},get distance(){return[1/(e=p())[0],1/e[1]];var e},get minDistance(){return 1/w()},get maxDistance(){return 1/g()},get rotation(){return Math.acos(s[0]/g())},get view(){return s},get viewCenter(){return d.slice(0,2)},lookAt:A,translate:M,pan:M,rotate:E,scale:h,zoom:h,reset:function(){A(n,t,o)},set:function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return console.warn("`set()` is deprecated. Please use `setView()` instead."),x.apply(void 0,e)},setScaleBounds:function(e){var n=Array.isArray(e[0]);l[0]=n?e[0][0]:e[0],l[1]=n?e[0][1]:e[1],f[0]=n?e[1][0]:e[0],f[1]=n?e[1][1]:e[1]},setTranslationBounds:function(e){var n=Array.isArray(e[0]);m[0]=n?e[0][0]:e[0],m[1]=n?e[0][1]:e[1],y[0]=n?e[1][0]:e[0],y[1]=n?e[1][1]:e[1]},setView:x,setViewCenter:function(e){d=e.slice(0,2).concat([0],[1])}}},t=["pan","rotate"],o={alt:"altKey",cmd:"metaKey",ctrl:"ctrlKey",meta:"metaKey",shift:"shiftKey"};return function(r,a){void 0===a&&(a={});var i=a.distance;void 0===i&&(i=1);var v=a.target;void 0===v&&(v=[0,0]);var u=a.rotation;void 0===u&&(u=0);var c=a.isNdc;void 0===c&&(c=!0);var s=a.isFixed;void 0===s&&(s=!1);var d=a.isPan;void 0===d&&(d=!0);var l=a.panSpeed;void 0===l&&(l=1);var f=a.isRotate;void 0===f&&(f=!0);var m=a.rotateSpeed;void 0===m&&(m=1);var y=a.defaultMouseDownMoveAction;void 0===y&&(y="pan");var p=a.mouseDownMoveModKey;void 0===p&&(p="alt");var w=a.isZoom;void 0===w&&(w=!0);var g=a.zoomSpeed;void 0===g&&(g=1);var A=a.viewCenter,M=a.scaleBounds,h=a.translationBounds,E=a.onKeyDown;void 0===E&&(E=function(){});var x=a.onKeyUp;void 0===x&&(x=function(){});var B=a.onMouseDown;void 0===B&&(B=function(){});var L=a.onMouseUp;void 0===L&&(L=function(){});var S=a.onMouseMove;void 0===S&&(S=function(){});var D=a.onWheel;void 0===D&&(D=function(){});var K=n(v,i,u,A,M,h),k=0,C=0,F=0,R=0,T=!1,b=0,z=1,P=1,V=1,X=!1,Y=!1,j=Array.isArray(d)?Boolean(d[0]):d,U=Array.isArray(d)?Boolean(d[1]):d,Z=Array.isArray(w)?Boolean(w[0]):w,q=Array.isArray(w)?Boolean(w[1]):w,N="pan"===y,O=c?function(e){return e/z*2*V}:function(e){return e},W=c?function(e){return e/P*2}:function(e){return-e},G=c?function(e){return(e/z*2-1)*V}:function(e){return e},H=c?function(e){return 1-e/P*2}:function(e){return e},I=function(){var e=r.getBoundingClientRect();z=e.width,P=e.height,V=z/P},J=function(e){Y=!1,x(e)},Q=function(e){Y=e[o[p]],E(e)},$=function(e){T=!1,L(e)},_=function(e){T=1===e.buttons,B(e)},ee=void 0!==document.createEvent("MouseEvent").offsetX?function(e){k=e.offsetX,C=e.offsetY}:function(e){var n=r.getBoundingClientRect();k=e.clientX-n.left,C=e.clientY-n.top},ne=function(e){ee(e),S(e)},te=function(e){e.preventDefault(),ee(e);var n=1===e.deltaMode?12:1;b+=n*(e.deltaY||0),D(e)};return window.addEventListener("keydown",Q,{passive:!0}),window.addEventListener("keyup",J,{passive:!0}),r.addEventListener("mousedown",_,{passive:!0}),window.addEventListener("mouseup",$,{passive:!0}),window.addEventListener("mousemove",ne,{passive:!0}),r.addEventListener("wheel",te,{passive:!1}),K.config=function(e){void 0===e&&(e={});var n=e.defaultMouseDownMoveAction;void 0===n&&(n=null);var r=e.isFixed;void 0===r&&(r=null);var a=e.isPan;void 0===a&&(a=null);var i=e.isRotate;void 0===i&&(i=null);var v=e.isZoom;void 0===v&&(v=null);var u=e.panSpeed;void 0===u&&(u=null);var c=e.rotateSpeed;void 0===c&&(c=null);var A=e.zoomSpeed;void 0===A&&(A=null);var M=e.mouseDownMoveModKey;void 0===M&&(M=null),y=null!==n&&t.includes(n)?n:y,N="pan"===y,s=null!==r?r:s,d=null!==a?a:d,f=null!==i?i:f,w=null!==v?v:w,l=+u>0?u:l,m=+c>0?c:m,g=+A>0?A:g,p=null!==M&&Object.keys(o).includes(M)?M:p},K.dispose=function(){K=void 0,window.removeEventListener("keydown",Q),window.removeEventListener("keyup",J),r.removeEventListener("mousedown",_),window.removeEventListener("mouseup",$),window.removeEventListener("mousemove",ne),r.removeEventListener("wheel",te)},K.refresh=I,K.tick=function(){if(s)return!1;X=!1;var n=k,t=C;if((j||U)&&T&&(N&&!Y||!N&&Y)){var o=j?O(l*(n-F)):0,r=U?W(l*(t-R)):0;K.pan([o,r]),X=!0}if(w&&b){var a=g*Math.exp(b/P),i=G(n),v=H(t);K.scale([Z?1/a:1,q?1/a:1],[i,v]),X=!0}if(f&&T&&(N&&Y||!N&&!Y)){var u=z/2,c=P/2,d=F-u,y=c-R,p=n-u,A=c-t,M=e.vec2.angle([d,y],[p,A]),h=d*A-p*y;K.rotate(m*M*Math.sign(h)),X=!0}return b=0,F=n,R=t,X},I(),K}})); |
{ | ||
"name": "dom-2d-camera", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "A wrapper for attaching a 2D camera to a DOM element", | ||
@@ -5,0 +5,0 @@ "author": "Fritz Lekschas", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46432
892