Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

troika-2d

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

troika-2d - npm Package Compare versions

Comparing version 0.33.0 to 0.34.0

9

CHANGELOG.md

@@ -6,2 +6,11 @@ # Change Log

# [0.34.0](https://github.com/protectwise/troika/compare/v0.33.1...v0.34.0) (2020-10-19)
**Note:** Version bump only for package troika-2d
# [0.33.0](https://github.com/protectwise/troika/compare/v0.32.0...v0.33.0) (2020-10-02)

@@ -8,0 +17,0 @@

0

dist/troika-2d.esm.js

@@ -0,0 +0,0 @@ import { PointerEventTarget, utils, WorldBaseFacade, ReactCanvasBase } from 'troika-core';

18

dist/troika-2d.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('troika-core'), require('react'), require('prop-types')) :
typeof define === 'function' && define.amd ? define(['exports', 'troika-core', 'react', 'prop-types'], factory) :
(global = global || self, factory(global.troika_2d = {}, global.troika_core, global.React, global.PropTypes));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.troika_2d = {}, global.troika_core, global.React, global.PropTypes));
}(this, (function (exports, troikaCore, React, T) { 'use strict';
React = React && Object.prototype.hasOwnProperty.call(React, 'default') ? React['default'] : React;
T = T && Object.prototype.hasOwnProperty.call(T, 'default') ? T['default'] : T;
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var T__default = /*#__PURE__*/_interopDefaultLegacy(T);
/**

@@ -502,3 +504,3 @@ * hitTestContext

var props = ref.props;
return React.createElement(
return React__default['default'].createElement(
troikaCore.ReactCanvasBase,

@@ -518,3 +520,3 @@ troikaCore.utils.assign({}, props, {

return Canvas2D;
}(React.Component));
}(React__default['default'].Component));

@@ -525,5 +527,5 @@ Canvas2D.displayName = 'Canvas2D';

{
backgroundColor: T.any,
objects: T.oneOfType([T.array, T.object]).isRequired,
onBackgroundClick: T.func
backgroundColor: T__default['default'].any,
objects: T__default['default'].oneOfType([T__default['default'].array, T__default['default'].object]).isRequired,
onBackgroundClick: T__default['default'].func
},

@@ -530,0 +532,0 @@ troikaCore.ReactCanvasBase.commonPropTypes

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

'use strict';(function(d,e){"object"===typeof exports&&"undefined"!==typeof module?e(exports,require("troika-core"),require("react"),require("prop-types")):"function"===typeof define&&define.amd?define(["exports","troika-core","react","prop-types"],e):(d=d||self,e(d.troika_2d={},d.troika_core,d.React,d.PropTypes))})(this,function(d,e,l,g){function n(c,a){var b="\u27a4"+c;Object.defineProperty(m.prototype,c,{get:function(){return b in this?this[b]:a},set:function(a){this[b]!==a&&(this[b]=a,this._matrixChanged=
!0)}})}function x(c,a){return c.z-a.z}function r(c,a){a&&a(c);var b=[],p=!1;c.forEachChildObject2D(function(a){!p&&b.length&&a.z!==b[0].z&&(p=!0);b.push(a)});p&&b.sort(x);c=0;for(var y=b.length;c<y;c++)r(b[c],a)}l=l&&Object.prototype.hasOwnProperty.call(l,"default")?l["default"]:l;g=g&&Object.prototype.hasOwnProperty.call(g,"default")?g["default"]:g;var k=document.createElement("canvas").getContext("2d");k.save();k.startHitTesting=function(c,a){this._x=c;this._y=a;this.didHit=!1;this.restore();this.save()};
k.fill=function(){this.isPointInPath(this._x,this._y)&&(this.didHit=!0)};var z="isPointIn"+("function"===typeof CanvasRenderingContext2D.prototype.isPointInStroke?"Stroke":"Path");k.stroke=function(){this[z](this._x,this._y)&&(this.didHit=!0)};k.fillRect=function(c,a,b,p){this.beginPath();this.rect(c,a,b,p);this.fill()};k.strokeRect=function(c,a,b,p){this.beginPath();this.rect(c,a,b,p);this.stroke()};var A=0,m=function(c){function a(b){for(c.call(this,b);b&&!b.isObject2D;)b=b.parent;b&&(b._childObjects2D[this.$facadeId]=
this);this._parentObject2DFacade=b;this._childObjects2D=Object.create(null);this.transformMatrix=[1,0,0,1,0,0];this.worldTransformMatrix=[1,0,0,1,0,0]}c&&(a.__proto__=c);a.prototype=Object.create(c&&c.prototype);a.prototype.constructor=a;a.prototype.afterUpdate=function(){this.updateMatrices();c.prototype.afterUpdate.call(this)};a.prototype.render=function(b){};a.prototype.updateMatrices=function(){var b=this._parentObject2DFacade;if(this._matrixChanged){this._updateLocalMatrix();this._matrixChanged=
!1;var a=!0}else a=b&&b._worldMatrixVersion>this._worldMatrixVersion;if(a){if(b){b=b.worldTransformMatrix;var c=this.transformMatrix;a=this.worldTransformMatrix;var f=b[0],d=b[1],h=b[2],e=b[3],g=c[0],k=c[1],l=c[2],m=c[3],n=c[4];c=c[5];a[0]=f*g+h*k;a[1]=d*g+e*k;a[2]=f*l+h*m;a[3]=d*l+e*m;a[4]=f*n+h*c+b[4];a[5]=d*n+e*c+b[5]}else for(b=this.transformMatrix,a=this.worldTransformMatrix,f=0;6>f;f++)a[f]=b[f];this._worldMatrixVersion=++A}};a.prototype._updateLocalMatrix=function(){var b=this.transformMatrix,
a=this.x,c=this.y,f=this.rotate,d=this.scaleX,h=this.scaleY,e=0===f?1:Math.cos(f);f=0===f?0:Math.sin(f);b[0]=d*e;b[1]=d*f;b[2]=h*-f;b[3]=h*e;b[4]=a;b[5]=c};a.prototype.hitTest=function(b,a){k.startHitTesting(b,a);this.updateMatrices();b=this.worldTransformMatrix;k.setTransform(b[0],b[1],b[2],b[3],b[4],b[5]);this.render(k);return k.didHit};a.prototype.getProjectedPosition=function(b,a){void 0===b&&(b=0);void 0===a&&(a=0);this.updateMatrices();var c=this.worldTransformMatrix;return{x:0===b?c[4]:b*c[0]+
a*c[2]+c[4],y:0===a?c[5]:b*c[1]+a*c[3]+c[5]}};a.prototype.forEachChildObject2D=function(b){var a=this._childObjects2D,c;for(c in a)b(a[c])};a.prototype.destructor=function(){var b=this._parentObject2DFacade;b&&delete b._childObjects2D[this.$facadeId];c.prototype.destructor.call(this)};return a}(e.PointerEventTarget),q=m.prototype;q.isObject2D=!0;q.z=0;q._worldMatrixVersion=-1;n("x",0);n("y",0);n("rotate",0);n("scaleX",1);n("scaleY",1);q=function(c){function a(){c.apply(this,arguments)}c&&(a.__proto__=
c);a.prototype=Object.create(c&&c.prototype);return a.prototype.constructor=a}(m);var B=function(c){function a(b){c.call(this,b);this.html=null;this.exact=!1;this.notifyWorld("addHtmlOverlay",this)}c&&(a.__proto__=c);a.prototype=Object.create(c&&c.prototype);a.prototype.constructor=a;a.prototype.destructor=function(){this.notifyWorld("removeHtmlOverlay",this);c.prototype.destructor.call(this)};return a}(m),u=function(c){function a(){c.apply(this,arguments)}c&&(a.__proto__=c);a.prototype=Object.create(c&&
c.prototype);a.prototype.constructor=a;a.prototype.render=function(b){b.font=this.fontStyle+" "+this.fontWeight+" "+this.fontStretch+" "+this.fontSize+" "+this.fontFamily;b.textAlign=this.textAlign;b.textBaseline=this.textBaseline;b.fillStyle=this.color;b.globalAlpha=this.opacity;b.fillText(this.text,0,0)};return a}(m);e.utils.assign(u.prototype,{color:"#fff",fontFamily:"sans-serif",fontSize:"12px",fontStretch:"",fontStyle:"",fontWeight:"",textAlign:"start",textBaseline:"alphabetic",text:"",opacity:1});
var v=function(c){function a(){c.apply(this,arguments)}c&&(a.__proto__=c);a.prototype=Object.create(c&&c.prototype);a.prototype.constructor=a;a.prototype.render=function(b){null!=this.color&&(b.fillStyle=this.color,b.fillRect(0,0,this.width,this.height))};a.prototype.hitTest=function(b,a){return!0};return a}(m);v.prototype.z=-Infinity;var w=function(c){function a(b){c.call(this,b);this._context=b.getContext("2d");this._onBgClick=this._onBgClick.bind(this)}c&&(a.__proto__=c);a.prototype=Object.create(c&&
c.prototype);a.prototype.constructor=a;a.prototype.describeChildren=function(){return{key:"bg",facade:v,color:this.backgroundColor,width:this.width,height:this.height,onClick:this.onBackgroundClick?this._onBgClick:null,children:this.objects}};a.prototype.doRender=function(){var b=this._element,a=this._context,c=this.height,d=this.pixelRatio||window.devicePixelRatio||1;b.width=this.width*d;b.height=c*d;a.setTransform(d,0,0,d,0,0);b=this.getChildByKey("bg");r(b,function(b){a.save();var c=b.worldTransformMatrix;
a.transform(c[0],c[1],c[2],c[3],c[4],c[5]);b.render(a);a.restore()})};a.prototype.getFacadeUserSpaceXYZ=function(b){var a=b.getProjectedPosition(0,0);b=b.z;return{x:a.x,y:a.y,z:1<b?1/b:1-b}};a.prototype.getFacadesAtEvent=function(a,c){var b=a.target.getBoundingClientRect(),d=a.clientX-b.left,e=a.clientY-b.top,h=null,g=0;r(this.getChildByKey("bg"),function(a){c&&!c(a)||!a.hitTest(d,e)||(h||(h=Object.create(null)),h[a.$facadeId]={facade:a,distance:g--})});h&&(h=Object.keys(h).map(function(a){return h[a]}));
return h};a.prototype._onBgClick=function(a){if(a.target===a.currentTarget)this.onBackgroundClick(a)};return a}(e.WorldBaseFacade),t=function(c){function a(){c.apply(this,arguments)}c&&(a.__proto__=c);a.prototype=Object.create(c&&c.prototype);a.prototype.constructor=a;a.prototype.render=function(){var a=this.props;return l.createElement(e.ReactCanvasBase,e.utils.assign({},a,{worldFacade:a.worldFacade||w,worldProps:e.utils.assign({},{backgroundColor:a.backgroundColor,onBackgroundClick:a.onBackgroundClick,
objects:a.objects},a.worldProps)}),a.children)};return a}(l.Component);t.displayName="Canvas2D";t.propTypes=e.utils.assignIf({backgroundColor:g.any,objects:g.oneOfType([g.array,g.object]).isRequired,onBackgroundClick:g.func},e.ReactCanvasBase.commonPropTypes);Object.defineProperty(d,"Facade",{enumerable:!0,get:function(){return e.Facade}});Object.defineProperty(d,"ListFacade",{enumerable:!0,get:function(){return e.ListFacade}});Object.defineProperty(d,"ParentFacade",{enumerable:!0,get:function(){return e.ParentFacade}});
d.Canvas2D=t;d.Group2DFacade=q;d.HtmlOverlay2DFacade=B;d.Object2DFacade=m;d.Text2DFacade=u;d.World2DFacade=w;Object.defineProperty(d,"__esModule",{value:!0})})
'use strict';(function(d,e){"object"===typeof exports&&"undefined"!==typeof module?e(exports,require("troika-core"),require("react"),require("prop-types")):"function"===typeof define&&define.amd?define(["exports","troika-core","react","prop-types"],e):(d="undefined"!==typeof globalThis?globalThis:d||self,e(d.troika_2d={},d.troika_core,d.React,d.PropTypes))})(this,function(d,e,k,l){function t(b){return b&&"object"===typeof b&&"default"in b?b:{"default":b}}function n(b,a){var c="\u27a4"+b;Object.defineProperty(m.prototype,
b,{get:function(){return c in this?this[c]:a},set:function(a){this[c]!==a&&(this[c]=a,this._matrixChanged=!0)}})}function y(b,a){return b.z-a.z}function q(b,a){a&&a(b);var c=[],p=!1;b.forEachChildObject2D(function(a){!p&&c.length&&a.z!==c[0].z&&(p=!0);c.push(a)});p&&c.sort(y);b=0;for(var z=c.length;b<z;b++)q(c[b],a)}var u=t(k);k=t(l);var g=document.createElement("canvas").getContext("2d");g.save();g.startHitTesting=function(b,a){this._x=b;this._y=a;this.didHit=!1;this.restore();this.save()};g.fill=
function(){this.isPointInPath(this._x,this._y)&&(this.didHit=!0)};var A="isPointIn"+("function"===typeof CanvasRenderingContext2D.prototype.isPointInStroke?"Stroke":"Path");g.stroke=function(){this[A](this._x,this._y)&&(this.didHit=!0)};g.fillRect=function(b,a,c,p){this.beginPath();this.rect(b,a,c,p);this.fill()};g.strokeRect=function(b,a,c,p){this.beginPath();this.rect(b,a,c,p);this.stroke()};var B=0,m=function(b){function a(c){for(b.call(this,c);c&&!c.isObject2D;)c=c.parent;c&&(c._childObjects2D[this.$facadeId]=
this);this._parentObject2DFacade=c;this._childObjects2D=Object.create(null);this.transformMatrix=[1,0,0,1,0,0];this.worldTransformMatrix=[1,0,0,1,0,0]}b&&(a.__proto__=b);a.prototype=Object.create(b&&b.prototype);a.prototype.constructor=a;a.prototype.afterUpdate=function(){this.updateMatrices();b.prototype.afterUpdate.call(this)};a.prototype.render=function(c){};a.prototype.updateMatrices=function(){var c=this._parentObject2DFacade;if(this._matrixChanged){this._updateLocalMatrix();this._matrixChanged=
!1;var a=!0}else a=c&&c._worldMatrixVersion>this._worldMatrixVersion;if(a){if(c){c=c.worldTransformMatrix;var b=this.transformMatrix;a=this.worldTransformMatrix;var f=c[0],d=c[1],h=c[2],e=c[3],g=b[0],k=b[1],l=b[2],m=b[3],n=b[4];b=b[5];a[0]=f*g+h*k;a[1]=d*g+e*k;a[2]=f*l+h*m;a[3]=d*l+e*m;a[4]=f*n+h*b+c[4];a[5]=d*n+e*b+c[5]}else for(c=this.transformMatrix,a=this.worldTransformMatrix,f=0;6>f;f++)a[f]=c[f];this._worldMatrixVersion=++B}};a.prototype._updateLocalMatrix=function(){var c=this.transformMatrix,
a=this.x,b=this.y,f=this.rotate,d=this.scaleX,h=this.scaleY,e=0===f?1:Math.cos(f);f=0===f?0:Math.sin(f);c[0]=d*e;c[1]=d*f;c[2]=h*-f;c[3]=h*e;c[4]=a;c[5]=b};a.prototype.hitTest=function(c,a){g.startHitTesting(c,a);this.updateMatrices();c=this.worldTransformMatrix;g.setTransform(c[0],c[1],c[2],c[3],c[4],c[5]);this.render(g);return g.didHit};a.prototype.getProjectedPosition=function(c,a){void 0===c&&(c=0);void 0===a&&(a=0);this.updateMatrices();var b=this.worldTransformMatrix;return{x:0===c?b[4]:c*b[0]+
a*b[2]+b[4],y:0===a?b[5]:c*b[1]+a*b[3]+b[5]}};a.prototype.forEachChildObject2D=function(c){var a=this._childObjects2D,b;for(b in a)c(a[b])};a.prototype.destructor=function(){var c=this._parentObject2DFacade;c&&delete c._childObjects2D[this.$facadeId];b.prototype.destructor.call(this)};return a}(e.PointerEventTarget);l=m.prototype;l.isObject2D=!0;l.z=0;l._worldMatrixVersion=-1;n("x",0);n("y",0);n("rotate",0);n("scaleX",1);n("scaleY",1);l=function(b){function a(){b.apply(this,arguments)}b&&(a.__proto__=
b);a.prototype=Object.create(b&&b.prototype);return a.prototype.constructor=a}(m);var C=function(b){function a(c){b.call(this,c);this.html=null;this.exact=!1;this.notifyWorld("addHtmlOverlay",this)}b&&(a.__proto__=b);a.prototype=Object.create(b&&b.prototype);a.prototype.constructor=a;a.prototype.destructor=function(){this.notifyWorld("removeHtmlOverlay",this);b.prototype.destructor.call(this)};return a}(m),v=function(b){function a(){b.apply(this,arguments)}b&&(a.__proto__=b);a.prototype=Object.create(b&&
b.prototype);a.prototype.constructor=a;a.prototype.render=function(c){c.font=this.fontStyle+" "+this.fontWeight+" "+this.fontStretch+" "+this.fontSize+" "+this.fontFamily;c.textAlign=this.textAlign;c.textBaseline=this.textBaseline;c.fillStyle=this.color;c.globalAlpha=this.opacity;c.fillText(this.text,0,0)};return a}(m);e.utils.assign(v.prototype,{color:"#fff",fontFamily:"sans-serif",fontSize:"12px",fontStretch:"",fontStyle:"",fontWeight:"",textAlign:"start",textBaseline:"alphabetic",text:"",opacity:1});
var w=function(b){function a(){b.apply(this,arguments)}b&&(a.__proto__=b);a.prototype=Object.create(b&&b.prototype);a.prototype.constructor=a;a.prototype.render=function(c){null!=this.color&&(c.fillStyle=this.color,c.fillRect(0,0,this.width,this.height))};a.prototype.hitTest=function(c,a){return!0};return a}(m);w.prototype.z=-Infinity;var x=function(b){function a(c){b.call(this,c);this._context=c.getContext("2d");this._onBgClick=this._onBgClick.bind(this)}b&&(a.__proto__=b);a.prototype=Object.create(b&&
b.prototype);a.prototype.constructor=a;a.prototype.describeChildren=function(){return{key:"bg",facade:w,color:this.backgroundColor,width:this.width,height:this.height,onClick:this.onBackgroundClick?this._onBgClick:null,children:this.objects}};a.prototype.doRender=function(){var c=this._element,a=this._context,b=this.height,d=this.pixelRatio||window.devicePixelRatio||1;c.width=this.width*d;c.height=b*d;a.setTransform(d,0,0,d,0,0);c=this.getChildByKey("bg");q(c,function(c){a.save();var b=c.worldTransformMatrix;
a.transform(b[0],b[1],b[2],b[3],b[4],b[5]);c.render(a);a.restore()})};a.prototype.getFacadeUserSpaceXYZ=function(c){var a=c.getProjectedPosition(0,0);c=c.z;return{x:a.x,y:a.y,z:1<c?1/c:1-c}};a.prototype.getFacadesAtEvent=function(a,b){var c=a.target.getBoundingClientRect(),d=a.clientX-c.left,e=a.clientY-c.top,h=null,g=0;q(this.getChildByKey("bg"),function(a){b&&!b(a)||!a.hitTest(d,e)||(h||(h=Object.create(null)),h[a.$facadeId]={facade:a,distance:g--})});h&&(h=Object.keys(h).map(function(a){return h[a]}));
return h};a.prototype._onBgClick=function(a){if(a.target===a.currentTarget)this.onBackgroundClick(a)};return a}(e.WorldBaseFacade),r=function(b){function a(){b.apply(this,arguments)}b&&(a.__proto__=b);a.prototype=Object.create(b&&b.prototype);a.prototype.constructor=a;a.prototype.render=function(){var a=this.props;return u["default"].createElement(e.ReactCanvasBase,e.utils.assign({},a,{worldFacade:a.worldFacade||x,worldProps:e.utils.assign({},{backgroundColor:a.backgroundColor,onBackgroundClick:a.onBackgroundClick,
objects:a.objects},a.worldProps)}),a.children)};return a}(u["default"].Component);r.displayName="Canvas2D";r.propTypes=e.utils.assignIf({backgroundColor:k["default"].any,objects:k["default"].oneOfType([k["default"].array,k["default"].object]).isRequired,onBackgroundClick:k["default"].func},e.ReactCanvasBase.commonPropTypes);Object.defineProperty(d,"Facade",{enumerable:!0,get:function(){return e.Facade}});Object.defineProperty(d,"ListFacade",{enumerable:!0,get:function(){return e.ListFacade}});Object.defineProperty(d,
"ParentFacade",{enumerable:!0,get:function(){return e.ParentFacade}});d.Canvas2D=r;d.Group2DFacade=l;d.HtmlOverlay2DFacade=C;d.Object2DFacade=m;d.Text2DFacade=v;d.World2DFacade=x;Object.defineProperty(d,"__esModule",{value:!0})})
{
"name": "troika-2d",
"version": "0.33.0",
"version": "0.34.0",
"description": "Troika 2D",

@@ -17,5 +17,5 @@ "author": "Jason Johnston <jason.johnston@protectwise.com>",

"dependencies": {
"troika-core": "^0.33.0"
"troika-core": "^0.34.0"
},
"gitHead": "0c397b65aac6137ce1b4417e55d0deeb77b5ee5f"
"gitHead": "b19cd3aff4b0876253d76b3fc66b7e2a1f16a7e5"
}

@@ -0,0 +0,0 @@ # `troika-2d`

@@ -0,0 +0,0 @@ import Object2DFacade from './Object2DFacade.js'

@@ -0,0 +0,0 @@ import Object2DFacade from './Object2DFacade.js'

@@ -0,0 +0,0 @@ import { PointerEventTarget } from 'troika-core'

@@ -0,0 +0,0 @@ import { utils } from 'troika-core'

@@ -0,0 +0,0 @@ import { WorldBaseFacade } from 'troika-core'

@@ -0,0 +0,0 @@ /**

@@ -0,0 +0,0 @@ // Troika 2D exports

@@ -0,0 +0,0 @@ import React from 'react'

Sorry, the diff of this file is not supported yet

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