UNPKG

5.58 kBJavaScriptView Raw
1import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _assertThisInitialized from"@babel/runtime/helpers/assertThisInitialized";import _inherits from"@babel/runtime/helpers/inherits";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import{Component}from'react';import SvgTouchableMixin from'../lib/SvgTouchableMixin';import{NativeModules,findNodeHandle}from'react-native';var RNSVGRenderableManager=NativeModules.RNSVGRenderableManager;export function multiply_matrices(l,r){var al=l.a,bl=l.b,cl=l.c,dl=l.d,el=l.e,fl=l.f;var ar=r.a,br=r.b,cr=r.c,dr=r.d,er=r.e,fr=r.f;var a=al*ar+cl*br;var c=al*cr+cl*dr;var e=al*er+cl*fr+el;var b=bl*ar+dl*br;var d=bl*cr+dl*dr;var f=bl*er+dl*fr+fl;return{a:a,c:c,e:e,b:b,d:d,f:f};}export function invert(_ref){var a=_ref.a,b=_ref.b,c=_ref.c,d=_ref.d,e=_ref.e,f=_ref.f;var n=a*d-b*c;return{a:d/n,b:-b/n,c:-c/n,d:a/n,e:(c*f-d*e)/n,f:-(a*f-b*e)/n};}var deg2rad=Math.PI/180;export var SVGMatrix=function(){function SVGMatrix(matrix){_classCallCheck(this,SVGMatrix);if(matrix){var a=matrix.a,b=matrix.b,c=matrix.c,d=matrix.d,e=matrix.e,f=matrix.f;this.a=a;this.b=b;this.c=c;this.d=d;this.e=e;this.f=f;}else{this.a=1;this.b=0;this.c=0;this.d=1;this.e=0;this.f=0;}}_createClass(SVGMatrix,[{key:"multiply",value:function multiply(secondMatrix){return new SVGMatrix(multiply_matrices(this,secondMatrix));}},{key:"inverse",value:function inverse(){return new SVGMatrix(invert(this));}},{key:"translate",value:function translate(x,y){return new SVGMatrix(multiply_matrices(this,{a:1,b:0,c:0,d:1,e:x,f:y}));}},{key:"scale",value:function scale(scaleFactor){return new SVGMatrix(multiply_matrices(this,{a:scaleFactor,b:0,c:0,d:scaleFactor,e:0,f:0}));}},{key:"scaleNonUniform",value:function scaleNonUniform(scaleFactorX,scaleFactorY){return new SVGMatrix(multiply_matrices(this,{a:scaleFactorX,b:0,c:0,d:scaleFactorY,e:0,f:0}));}},{key:"rotate",value:function rotate(angle){var cos=Math.cos(deg2rad*angle);var sin=Math.sin(deg2rad*angle);return new SVGMatrix(multiply_matrices(this,{a:cos,b:sin,c:-sin,d:cos,e:0,f:0}));}},{key:"rotateFromVector",value:function rotateFromVector(x,y){var angle=Math.atan2(y,x);var cos=Math.cos(deg2rad*angle);var sin=Math.sin(deg2rad*angle);return new SVGMatrix(multiply_matrices(this,{a:cos,b:sin,c:-sin,d:cos,e:0,f:0}));}},{key:"flipX",value:function flipX(){return new SVGMatrix(multiply_matrices(this,{a:-1,b:0,c:0,d:1,e:0,f:0}));}},{key:"flipY",value:function flipY(){return new SVGMatrix(multiply_matrices(this,{a:1,b:0,c:0,d:-1,e:0,f:0}));}},{key:"skewX",value:function skewX(angle){return new SVGMatrix(multiply_matrices(this,{a:1,b:0,c:Math.tan(deg2rad*angle),d:1,e:0,f:0}));}},{key:"skewY",value:function skewY(angle){return new SVGMatrix(multiply_matrices(this,{a:1,b:Math.tan(deg2rad*angle),c:0,d:1,e:0,f:0}));}}]);return SVGMatrix;}();function _matrixTransform(matrix,point){var a=matrix.a,b=matrix.b,c=matrix.c,d=matrix.d,e=matrix.e,f=matrix.f;var x=point.x,y=point.y;return{x:a*x+c*y+e,y:b*x+d*y+f};}export{_matrixTransform as matrixTransform};export var SVGPoint=function(){function SVGPoint(point){_classCallCheck(this,SVGPoint);if(point){var _x=point.x,_y=point.y;this.x=_x;this.y=_y;}else{this.x=0;this.y=0;}}_createClass(SVGPoint,[{key:"matrixTransform",value:function matrixTransform(matrix){return new SVGPoint(_matrixTransform(matrix,this));}}]);return SVGPoint;}();export var ownerSVGElement={createSVGPoint:function createSVGPoint(){return new SVGPoint();},createSVGMatrix:function createSVGMatrix(){return new SVGMatrix();}};var Shape=function(_Component){_inherits(Shape,_Component);function Shape(_props,context){var _this;_classCallCheck(this,Shape);_this=_possibleConstructorReturn(this,_getPrototypeOf(Shape).call(this,_props,context));_this.root=null;_this.refMethod=function(instance){_this.root=instance;};_this.setNativeProps=function(props){_this.root&&_this.root.setNativeProps(props);};_this.getBBox=function(options){var _ref2=options||{},_ref2$fill=_ref2.fill,fill=_ref2$fill===void 0?true:_ref2$fill,_ref2$stroke=_ref2.stroke,stroke=_ref2$stroke===void 0?true:_ref2$stroke,_ref2$markers=_ref2.markers,markers=_ref2$markers===void 0?true:_ref2$markers,_ref2$clipped=_ref2.clipped,clipped=_ref2$clipped===void 0?true:_ref2$clipped;var handle=findNodeHandle(_this.root);return RNSVGRenderableManager.getBBox(handle,{fill:fill,stroke:stroke,markers:markers,clipped:clipped});};_this.getCTM=function(){var handle=findNodeHandle(_this.root);return new SVGMatrix(RNSVGRenderableManager.getCTM(handle));};_this.getScreenCTM=function(){var handle=findNodeHandle(_this.root);return new SVGMatrix(RNSVGRenderableManager.getScreenCTM(handle));};_this.isPointInFill=function(options){var handle=findNodeHandle(_this.root);return RNSVGRenderableManager.isPointInFill(handle,options);};_this.isPointInStroke=function(options){var handle=findNodeHandle(_this.root);return RNSVGRenderableManager.isPointInStroke(handle,options);};_this.getTotalLength=function(){var handle=findNodeHandle(_this.root);return RNSVGRenderableManager.getTotalLength(handle);};_this.getPointAtLength=function(length){var handle=findNodeHandle(_this.root);return new SVGPoint(RNSVGRenderableManager.getPointAtLength(handle,{length:length}));};SvgTouchableMixin(_assertThisInitialized(_this));return _this;}return Shape;}(Component);export{Shape as default};Shape.prototype.ownerSVGElement=ownerSVGElement;
2//# sourceMappingURL=Shape.js.map
\No newline at end of file