New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

canvas-camera-2d

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-camera-2d - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

4

CHANGELOG.md

@@ -0,1 +1,5 @@

**v0.5.2**
- Remove `camera.getGlPos()` as the base application should handle this since it typically involves a projection + model transformation
**v0.5.1**

@@ -2,0 +6,0 @@

16

dist/canvas-camera-2d.js

@@ -29,4 +29,2 @@ (function (global, factory) {

var scratch = new Float32Array(16);
var camera = createCamera(target, distance, rotation);

@@ -43,15 +41,2 @@ var isChanged = false;

var getGlPos = function (x, y, w, h) {
// Get relative WebGL position
var relX = -1 + (x / w) * 2;
var relY = 1 + (y / h) * -2;
// Homogeneous vector
var v = [relX, relY, 1, 1];
// Compute inverse view matrix
var viewInv = glMatrix.mat4.invert(scratch, camera.view);
// Translate vector
glMatrix.vec4.transformMat4(v, v, viewInv);
return v.slice(0, 2);
};
var tick = function () {

@@ -152,3 +137,2 @@ if (isFixed) { return false; }

camera.dispose = dispose;
camera.getGlPos = getGlPos;
camera.refresh = refresh;

@@ -155,0 +139,0 @@ camera.tick = tick;

@@ -1,1 +0,1 @@

!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("camera-2d-simple"),require("gl-matrix"),require("key-pressed"),require("mouse-position"),require("mouse-pressed"),require("scroll-speed")):"function"==typeof define&&define.amd?define(["camera-2d-simple","gl-matrix","key-pressed","mouse-position","mouse-pressed","scroll-speed"],i):e.canvasCamera2d=i(e.createCamera2d,e.glMatrix,e.createKeyPressed,e.createMousePosition,e.createMousePressed,e.createScroll)}(this,function(e,i,t,r,o,a){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t,r=r&&r.hasOwnProperty("default")?r.default:r,o=o&&o.hasOwnProperty("default")?o.default:o,a=a&&a.hasOwnProperty("default")?a.default:a;return function(d,s){void 0===s&&(s={});var n=s.distance;void 0===n&&(n=1);var u=s.target;void 0===u&&(u=[0,0]);var v=s.rotation;void 0===v&&(v=0);var l=s.isFixed;void 0===l&&(l=!1);var f=s.isPan;void 0===f&&(f=!0);var p=s.panSpeed;void 0===p&&(p=1);var c=s.isRotate;void 0===c&&(c=!0);var m=s.rotateSpeed;void 0===m&&(m=1);var h=s.isZoom;void 0===h&&(h=!0);var w=s.zoomSpeed;void 0===w&&(w=1);var P=new Float32Array(16),x=e(u,n,v),y=!1,g=r(d),M=o(d),S=a(d,h),q=d.height/window.devicePixelRatio,R=d.width/window.devicePixelRatio,O=R/q,k=!1;return x.config=function(e){void 0===e&&(e={});var i=e.isFixed,t=e.isPan,r=e.isRotate,o=e.isZoom,a=e.panSpeed,d=e.rotateSpeed,s=e.zoomSpeed;l=i||l,f=t||f,c=r||c,h=o||h,p=+a>0?a:p,m=+d>0?d:m,w=+s>0?s:w},x.dispose=function(){S.dispose(),M.dispose(),g.dispose(),x=void 0,S=void 0,M=void 0,g=void 0},x.getGlPos=function(e,t,r,o){var a=[e/r*2-1,1+t/o*-2,1,1],d=i.mat4.invert(P,x.view);return i.vec4.transformMat4(a,a,d),a.slice(0,2)},x.refresh=function(){q=d.height/window.devicePixelRatio,R=d.width/window.devicePixelRatio,O=R/q},x.tick=function(){if(l)return!1;k=t("<alt>"),y=!1;var e=g[0],r=g[1],o=g.prev,a=o[0],d=o[1];if(f&&M.left&&!k&&(x.pan([p*(e-a)/R*2*Math.max(O,1),p*(d-r)/q*2/Math.min(O,1)]),y=!0),h&&S[1]){var s=w*Math.exp(S[1]/q),n=(e/R*2-1)*Math.max(O,1),u=(1-r/q*2)/Math.min(O,1);x.scale(1/s,[n,u]),y=!0}if(c&&M.left&&k){var v=R/2,P=q/2,F=a-v,z=P-d,C=e-v,Z=P-r,b=i.vec2.angle([F,z],[C,Z]),j=F*Z-C*z;x.rotate(m*b*Math.sign(j)),y=!0}return S.flush(),g.flush(),y},x}});
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("camera-2d-simple"),require("gl-matrix"),require("key-pressed"),require("mouse-position"),require("mouse-pressed"),require("scroll-speed")):"function"==typeof define&&define.amd?define(["camera-2d-simple","gl-matrix","key-pressed","mouse-position","mouse-pressed","scroll-speed"],i):e.canvasCamera2d=i(e.createCamera2d,e.glMatrix,e.createKeyPressed,e.createMousePosition,e.createMousePressed,e.createScroll)}(this,function(e,i,o,t,a,r){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e,o=o&&o.hasOwnProperty("default")?o.default:o,t=t&&t.hasOwnProperty("default")?t.default:t,a=a&&a.hasOwnProperty("default")?a.default:a,r=r&&r.hasOwnProperty("default")?r.default:r;return function(d,s){void 0===s&&(s={});var n=s.distance;void 0===n&&(n=1);var u=s.target;void 0===u&&(u=[0,0]);var v=s.rotation;void 0===v&&(v=0);var p=s.isFixed;void 0===p&&(p=!1);var f=s.isPan;void 0===f&&(f=!0);var l=s.panSpeed;void 0===l&&(l=1);var c=s.isRotate;void 0===c&&(c=!0);var m=s.rotateSpeed;void 0===m&&(m=1);var h=s.isZoom;void 0===h&&(h=!0);var w=s.zoomSpeed;void 0===w&&(w=1);var x=e(u,n,v),P=!1,y=t(d),g=a(d),M=r(d,h),S=d.height/window.devicePixelRatio,q=d.width/window.devicePixelRatio,R=q/S,O=!1;return x.config=function(e){void 0===e&&(e={});var i=e.isFixed,o=e.isPan,t=e.isRotate,a=e.isZoom,r=e.panSpeed,d=e.rotateSpeed,s=e.zoomSpeed;p=i||p,f=o||f,c=t||c,h=a||h,l=+r>0?r:l,m=+d>0?d:m,w=+s>0?s:w},x.dispose=function(){M.dispose(),g.dispose(),y.dispose(),x=void 0,M=void 0,g=void 0,y=void 0},x.refresh=function(){S=d.height/window.devicePixelRatio,q=d.width/window.devicePixelRatio,R=q/S},x.tick=function(){if(p)return!1;O=o("<alt>"),P=!1;var e=y[0],t=y[1],a=y.prev,r=a[0],d=a[1];if(f&&g.left&&!O&&(x.pan([l*(e-r)/q*2*Math.max(R,1),l*(d-t)/S*2/Math.min(R,1)]),P=!0),h&&M[1]){var s=w*Math.exp(M[1]/S),n=(e/q*2-1)*Math.max(R,1),u=(1-t/S*2)/Math.min(R,1);x.scale(1/s,[n,u]),P=!0}if(c&&g.left&&O){var v=q/2,k=S/2,z=r-v,C=k-d,F=e-v,Z=k-t,b=i.vec2.angle([z,C],[F,Z]),j=z*Z-F*C;x.rotate(m*b*Math.sign(j)),P=!0}return M.flush(),y.flush(),P},x}});
{
"name": "canvas-camera-2d",
"version": "0.5.1",
"version": "0.5.2",
"description": "A canvas wrapper for a 2D camera",

@@ -5,0 +5,0 @@ "author": "Fritz Lekschas",

@@ -65,13 +65,4 @@ # Canvas Warpper for 2D Camera

_Note: the camera does not update the width and height unless you tell it to using this function!_
_Note: the camera does **not** update the width and height unless you tell it to using this function!_
#### `camera.getGlPos(x, y, w, h)`
Computes the WebGL position of `x` and `y` given the width `w` and height `h` of the canvas object.
- `x`: relative x position in pixel coordinates.
- `y`: relative y position in pixel coordinates.
- `w`: width of the canvas object.
- `h`: height of the canvas object.
**Returns** `[relX, relY]` the WebGL position of `x` and `y`.

@@ -78,0 +69,0 @@

import createCamera from "camera-2d-simple";
import { vec2, vec4, mat4 } from "gl-matrix";
import { vec2 } from "gl-matrix";
import isKeyPressed from "key-pressed";

@@ -23,4 +23,2 @@ import createMousePosition from "mouse-position";

) => {
const scratch = new Float32Array(16);
let camera = createCamera(target, distance, rotation);

@@ -37,15 +35,2 @@ let isChanged = false;

const getGlPos = (x, y, w, h) => {
// Get relative WebGL position
const relX = -1 + (x / w) * 2;
const relY = 1 + (y / h) * -2;
// Homogeneous vector
const v = [relX, relY, 1, 1];
// Compute inverse view matrix
const viewInv = mat4.invert(scratch, camera.view);
// Translate vector
vec4.transformMat4(v, v, viewInv);
return v.slice(0, 2);
};
const tick = () => {

@@ -142,3 +127,2 @@ if (isFixed) return false;

camera.dispose = dispose;
camera.getGlPos = getGlPos;
camera.refresh = refresh;

@@ -145,0 +129,0 @@ camera.tick = tick;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc