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

fxsvg

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fxsvg - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

src/isSVGTransform/isSVGTransform.index.js

2

dist/fxsvg.js

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

!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([,function(t,e,r){"use strict";r.r(e);const n=t=>{if(!(t instanceof SVGTransform))return!1;const{type:e,SVG_TRANSFORM_ROTATE:r}=t;return e===r},o=({angle:t=0}={})=>e=>{if(!n(e))return e;const{angle:r}=e;return e.setRotate(r+t,0,0),e},a=t=>{if(!(t instanceof SVGTransform))return!1;const{type:e,SVG_TRANSFORM_TRANSLATE:r}=t;return e===r},i=({tx:t=0,ty:e=0}={})=>r=>{if(!a(r))return r;const{e:n,f:o}=r.matrix;return r.setTranslate(n+t,o+e),r};let s;const c=t=>(s=t,s),m=()=>(s||c(document.createElementNS("http://www.w3.org/2000/svg","svg")),s),f=(t=m())=>t.createSVGTransform(),u=({angle:t=0,cx:e=0,cy:r=0}={})=>(n=m())=>{const o=f(n);return o.setRotate(t,e,r),o},l=({tx:t=0,ty:e=0}={})=>(r=m())=>{const n=f(r);return n.setTranslate(t,e),n};function x(t){return(e,...r)=>r.length?t(e,...r):(...r)=>t(e,...r)}var d=Array.isArray.bind(Array);const y=function*(){}();function g(t){return t&&t[Symbol.iterator]?t[Symbol.iterator]():y}var _=(t,e)=>t instanceof Promise?t.then(e):e(t);var h=Symbol.for("nop");function p(t,e,r){return e instanceof Promise?e.then(e=>r(t,e),e=>e==h?t:Promise.reject(e)):r(t,e)}var T=x((function(t,e){if(t<1)return[];let r=[];return e=g(e),function n(){let o;for(;!(o=e.next()).done;){const e=o.value;if(e instanceof Promise)return e.then(e=>(r.push(e),r).length==t?r:n()).catch(t=>t==h?n():Promise.reject(t));if(r.push(e),r.length==t)return r}return r}()}));function S(t){return _(T(1,t),([t])=>t)}function b(t,e,r){return 1==arguments.length?(...e)=>b(t,...e):2==arguments.length?b(t,S(r=g(e)),r):(r=g(r),_(e,(function e(n){let o;for(;!(o=r.next()).done;)if((n=p(n,o.value,t))instanceof Promise)return n.then(e);return n})))}var v=x((function*(t,e){for(const r of g(e)){const e=_(r,t);e instanceof Promise?yield e.then(t=>t?r:Promise.reject(h)):e&&(yield r)}})),V=x((function(t,e){return S(v(t,e))})),I=(t,e)=>e(t);function G(...t){return b(I,t)}function M(t){return!t}var R=x((function*(t,e){for(const r of g(e))yield _(r,t)}));function w(){}var P=x((function*(t,e){let r=null,n=!1;for(const o of g(e)){const e=n||_(o,t);if(e instanceof Promise?(e.catch(w),yield r=(r||Promise.resolve()).then(t=>e).then(t=>n?Promise.reject(h):(n=t,o)),r=r.catch(w)):(n=e,yield o),n)break}})),O=x((function(t,e){return G(R(t,e),P(M),b((t,e)=>t&&e),(t=!1)=>t,Boolean)}));var A,B=x((function(t,e){return"function"==typeof t?!!t(e):d(t)&&d(e)?O(t=>e.includes(t),t):e&&"object"==typeof e?O(([t,r])=>e[t]==r,function*(t){for(const e in t)yield[e,t[e]]}(t)):t instanceof RegExp?e.match(t):t==e})),N=x((function(t,e){return V(B(t),e)})),j=(A=".",x((function t(e,r){return e?d(e)?b((e,r)=>t(r,e),r,e):"object"==typeof e||"function"==typeof e?N(e,r):b((t,e,r=e[0])=>t?"#"==r?N({id:e.substr(1)},t):"["==r||"{"==r?N(JSON.parse(e),t):t[e]:void 0,r,e.split(A)):r})));const L=t=>j("transform.baseVal",t),F=({angle:t=0,cx:e=0,cy:r=0,index:n=0}={})=>(o,a=m())=>{const i=L(o),s=l({tx:e,ty:r})(a),c=l({tx:-e,ty:-r})(a),f=u({angle:t})(a);return i.insertItemBefore(c,n),i.insertItemBefore(f,n),i.insertItemBefore(s,n),f};function*E(t=0,e=t,r=1){if(1===arguments.length&&(t=0),arguments.length<3&&t>e&&(r*=-1),t<e)for(;t<e;)yield t,t+=r;else for(;t>e;)yield t,t+=r}var $=x((function(t,e){return function(t){return T(1/0,t)}(R(t,e))})),C=x((function(t,e){return $(e=>_(t(e),t=>e),e)}));const H=({index:t=1}={})=>(e,r=m())=>{const o=L(e);if(!(({index:t})=>e=>{if(t>e.numberOfItems-2||t<1)return!1;const[r,o,i]=G(E(3),R(e=>t-1+e),R(t=>e.getItem(t)));return a(r)&&n(o)&&a(i)&&0===o.matrix.e&&0===o.matrix.f&&1===r.matrix.a&&0===r.matrix.b&&0===r.matrix.c&&1===r.matrix.d&&1===i.matrix.a&&0===i.matrix.b&&0===i.matrix.c&&1===i.matrix.d&&r.matrix.e+i.matrix.e===0&&r.matrix.f+i.matrix.f===0})({index:t})(o))return e;const{angle:i}=o.getItem(t),{e:s,f:c}=o.getItem(t-1).matrix;C(()=>o.removeItem(t-1),E(3));const f=u({angle:i,cx:s,cy:c})(r);return o.insertItemBefore(f,t-1),e};var k=x((function(t,e){return null==e||Number.isNaN(e)?t:e}));const z=({angle:t,cx:e=0,cy:r=0}={})=>o=>n(o)?(o.setRotate(k(o.angle,t),e,r),o):o,J=({sx:t=1,sy:e=1}={})=>(r=m())=>{const n=f(r);return n.setScale(t,e),n},X=({sx:t=1,sy:e=1,cx:r=0,cy:n=0,index:o=0}={})=>(a,i=m())=>{const s=L(a),c=l({tx:r,ty:n})(i),f=l({tx:-r,ty:-n})(i),u=J({sx:t,sy:e})(i);return s.insertItemBefore(f,o),s.insertItemBefore(u,o),s.insertItemBefore(c,o),u},q=({a:t=1,b:e=0,c:r=0,d:n=1,e:o=0,f:a=0}={})=>(i=m())=>{const s=i.createSVGMatrix();return s.a=t,s.b=e,s.c=r,s.d=n,s.e=o,s.f=a,s},D=({matrix:t}={})=>(e=m())=>{const r=f(e);return r.setMatrix(k(q()(e),t)),r},K=t=>{if(!(t instanceof SVGTransform))return!1;const{type:e,SVG_TRANSFORM_SCALE:r}=t;return e===r},Q=({index:t=0}={})=>e=>{if(t<=0||t>=e.numberOfItems-1)return!1;const[r,n,o]=G(E(3),R(e=>t-1+e),R(t=>e.getItem(t)));return a(r)&&K(n)&&a(o)&&1===r.matrix.a&&0===r.matrix.b&&0===r.matrix.c&&1===r.matrix.d&&1===o.matrix.a&&0===o.matrix.b&&0===o.matrix.c&&1===o.matrix.d&&r.matrix.e+o.matrix.e===0&&r.matrix.f+o.matrix.f===0},U=({index:t=1}={})=>(e,r=m())=>{const n=L(e);if(!Q({index:t})(n))return e;const o=G(E(3),R(e=>t-1+e),R(t=>n.getItem(t)),R(({matrix:t})=>t),b((t,e)=>t.multiply(e)),t=>D({matrix:t})(r));return C(()=>n.removeItem(t-1),E(3)),n.insertItemBefore(o,t-1),e};var W=t=>t,Y=x((function(t,e){return G(R(t,e),P(W),b((t,e)=>t||e),(t=!1)=>t,Boolean)}));const Z=new Set(["n","ne","e","se","s","sw","w","nw"]),tt=({index:t=1,is_need_correction:e=!0,x_name:r="x",y_name:n="y",width_name:o="width",height_name:a="height",direction:i}={})=>s=>{const c=L(s);if(!Q({index:t})(c)||!Z.has(i))return s;const[{e:m,f:f},{a:u,d:l},{e:x,f:d}]=G(E(3),R(e=>t-1+e),R(t=>c.getItem(t)),R(({matrix:t})=>t)),[y,g,h,p]=G([r,n,o,a],R(t=>s.getAttributeNS(null,t)),R(parseFloat));return G([[y,u,x,m,h,["e","w"]],[g,l,d,f,p,["n","s"]]],R(([t,r,n,o,a,s])=>G(s,Y(t=>i.includes(t)),i=>i?_((t+n)*r+o,t=>r<0&&e?t+a*r:t):t)),([t,e])=>[[r,t],[n,e],[o,h*Math.abs(u)],[a,p*Math.abs(l)]],R(([t,e])=>[t,""+e]),C(([t,e])=>s.setAttributeNS(null,t,e))),C(()=>c.removeItem(t-1),E(3)),s},et=({sx:t,sy:e}={})=>r=>K(r)?(r.setScale(k(r.matrix.a,t),k(r.matrix.d,e)),r):r,rt=({tx:t=0,ty:e=0,index:r=0}={})=>(n,o=m())=>{const a=l({tx:t,ty:e})(o);return L(n).insertItemBefore(a,r),a},nt=({index:t=0,x_name:e="x",y_name:r="y"}={})=>(n,o=m())=>{const i=L(n);if(t>i.numberOfItems-1||t<0)return n;const s=i.getItem(t);if(!a(s))return n;const{e:c,f:f}=s.matrix;return G([{name:e,value:c},{name:r,value:f}],R(({name:t,value:e})=>({name:t,value:""+(parseFloat(n.getAttributeNS(null,t))+e)})),C(({name:t,value:e})=>n.setAttributeNS(null,t,e))),i.removeItem(t),G(E(i.numberOfItems),R(t=>i.getItem(t)),R(t=>[l({tx:c,ty:f})(o),t,l({tx:-c,ty:-f})(o)]),C(([t,e,r])=>{const n=t.matrix.multiply(e.matrix).multiply(r.matrix);e.setMatrix(n)})),n},ot=({tx:t,ty:e}={})=>r=>a(r)?(r.setTranslate(k(r.matrix.e,t),k(r.matrix.f,e)),r):r,at=({x:t=0,y:e=0}={})=>(r=m())=>{const n=r.createSVGPoint();return n.x=t,n.y=e,n},it=(t="")=>(e=m())=>{t=t.trim(),e.innerHTML=t;const r=C(t=>e.removeChild(t),[...e.children]);return e.innerHTML="",r},st=(t,e=m())=>{const r=((t,e=m())=>{const{x:r,y:n,width:o,height:a}=t.getBBox();return{top_left:at({x:r,y:n})(e),top_right:at({x:r+o,y:n})(e),bottom_left:at({x:r,y:n+a})(e),bottom_right:at({x:r+o,y:n+a})(e)}})(t,e),n=(({top_left:t,top_right:e,bottom_right:r,bottom_left:n})=>(o,a=m())=>{const i=L(o),[s,c,f,u]=G([t,e,n,r],R(t=>at(t)(a)),R(t=>G(E(i.numberOfItems),R(t=>i.getItem(t)),R(({matrix:t})=>t),e=>b((t,e)=>t.matrixTransform(e),t,e))));return{top_left:s,top_right:c,bottom_left:f,bottom_right:u}})(r)(t,e);return{original:r,transformed:n,bounding:(({top_left:t,top_right:e,bottom_right:r,bottom_left:n})=>(o,a=m())=>{const i=[t,e,n,r],[s,c]=_($(({x:t})=>t,i),t=>[Math.min(...t),Math.max(...t)]),[f,u]=_($(({y:t})=>t,i),t=>[Math.min(...t),Math.max(...t)]);return{min:at({x:s,y:f})(a),max:at({x:c,y:u})(a)}})(n)(t,e)}};var ct=x((t,e)=>R(function(t,...e){return(r,...n)=>_(b(I,t(r,...n),e),t=>r)}(t),e));const mt=(t,e)=>t+e,ft=t=>{let e=0;const r=G(t,ct(()=>e++),b(mt));return e?r/e:0},ut=t=>{if(!(t instanceof SVGTransform))return!1;const{type:e,SVG_TRANSFORM_MATRIX:r}=t;return e===r},lt={appendRotateTransform:o,appendTranslateTransform:i,consolidateTransformList:t=>{const e=t.consolidate();return e?(t.initialize(e),t):t},controlRotateTransform:({angle:t,cx:e,cy:r,index:n=0}={})=>(a,i=m())=>{const s=F({angle:t,cx:e,cy:r,index:n})(a,i),c={update:({angle:t}={})=>(z({angle:t,cx:0,cy:0})(s),c),append:({angle:t}={})=>(o({angle:t})(s),c),end:()=>(H({index:n+1})(a,i),a)};return{$el:a,transform:s,controller:c}},controlScaleTransform:({cx:t,cy:e,sx:r,sy:n,index:o=0,is_need_correction:a=!0,merge_type:i=1,x_name:s,y_name:c,width_name:f,height_name:u,direction:l}={})=>(x,d=m())=>{const y=X({cx:t,cy:e,sx:r,sy:n,index:o})(x,d),g={update:({sx:t,sy:e}={})=>(et({sx:t,sy:e})(y),g),end:({is_need_correction:t=a,merge_type:e=i,x_name:r=s,y_name:n=c,width_name:m=f,height_name:y=u,direction:g=l}={})=>(2===e?tt({index:o+1,is_need_correction:t,x_name:r,y_name:n,width_name:m,height_name:y,direction:g})(x):U({index:o+1})(x,d),x)};return{$el:x,transform:y,controller:g}},controlTranslateTransform:({index:t=0,tx:e,ty:r,x_name:n,y_name:o}={})=>(a,s=m())=>{const c=rt({tx:e,ty:r,index:t})(a,s),f={update:({tx:t,ty:e}={})=>(ot({tx:t,ty:e})(c),f),append:({tx:t,ty:e}={})=>(i({tx:t,ty:e})(c),f),end:()=>(n&&o&&nt({index:t,x_name:n,y_name:o})(a,s),a)};return{$el:a,controller:f,transform:c}},createSVGMatrix:q,createSVGPoint:at,createSVGRect:({x:t=0,y:e=0,width:r=0,height:n=0}={})=>(o=m())=>{const a=o.createSVGRect();return a.x=t,a.y=e,a.width=r,a.height=n,a},createSVGTransform:f,createSVGTransformMatrix:D,createSVGTransformRotate:u,createSVGTransformScale:J,createSVGTransformTranslate:l,el:t=>(e=m())=>S(it(t)(e)),els:it,getAnimTransformList:t=>j("transform.animVal",t),getBaseTransformList:L,getBoxPoints:st,getCenterPoint:(t,e=m())=>{const{original:r,transformed:n}=st(t,e),[o,a]=R(t=>(({top_left:t,top_right:e,bottom_left:r,bottom_right:n})=>(o=m())=>{const a=[t,e,r,n],i=ft(R(({x:t})=>t,a)),s=ft(R(({y:t})=>t,a));return at({x:i,y:s})(o)})(t)(e),[r,n]);return{original:o,transformed:a}},getSVG:m,setSVG:c,initMatrixTransform:({matrix:t,index:e=0}={})=>(r,n=m())=>{const o=D({matrix:k(q()(n),t)})(n);return L(r).insertItemBefore(o,e),o},initRotateTransform:F,initScaleTransform:X,initTranslateTransform:rt,isMatrixSVGTransform:ut,isRotateSVGTransform:n,isScaleSVGTransform:K,isTranslateSVGTransform:a,isValidFxScaleSVGTransformList:Q,mergeRotateTransform:H,mergeScaleTransform:U,mergeScaleTransform2:tt,mergeTranslateTransform:nt,updateMatrixTransform:({matrix:t}={})=>e=>ut(e)?(e.setMatrix(k(e.matrix,t)),e):e,updateRotateTransform:z,updateScaleTransform:et,updateTranslateTransform:ot};window.$$=lt}]);
!function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([,function(t,e,r){"use strict";r.r(e);const n=t=>t instanceof SVGTransform,o=t=>{if(!n(t))return!1;const{type:e,SVG_TRANSFORM_ROTATE:r}=t;return e===r},i=({angle:t=0}={})=>e=>{if(!o(e))return e;const{angle:r}=e;return e.setRotate(r+t,0,0),e},a=t=>{if(!n(t))return!1;const{type:e,SVG_TRANSFORM_TRANSLATE:r}=t;return e===r},s=({tx:t=0,ty:e=0}={})=>r=>{if(!a(r))return r;const{e:n,f:o}=r.matrix;return r.setTranslate(n+t,o+e),r};let c;const m=t=>(c=t,c),u=()=>(c||m(document.createElementNS("http://www.w3.org/2000/svg","svg")),c),f=(t=u())=>t.createSVGTransform(),x=({angle:t=0,cx:e=0,cy:r=0}={})=>(n=u())=>{const o=f(n);return o.setRotate(t,e,r),o},l=({tx:t=0,ty:e=0}={})=>(r=u())=>{const n=f(r);return n.setTranslate(t,e),n};function d(t){return(e,...r)=>r.length?t(e,...r):(...r)=>t(e,...r)}var y=Array.isArray.bind(Array);const g=function*(){}();function _(t){return t&&t[Symbol.iterator]?t[Symbol.iterator]():g}var h=(t,e)=>t instanceof Promise?t.then(e):e(t);var p=Symbol.for("nop");function T(t,e,r){return e instanceof Promise?e.then(e=>r(t,e),e=>e==p?t:Promise.reject(e)):r(t,e)}var S=d((function(t,e){if(t<1)return[];let r=[];return e=_(e),function n(){let o;for(;!(o=e.next()).done;){const e=o.value;if(e instanceof Promise)return e.then(e=>(r.push(e),r).length==t?r:n()).catch(t=>t==p?n():Promise.reject(t));if(r.push(e),r.length==t)return r}return r}()}));function b(t){return h(S(1,t),([t])=>t)}function v(t,e,r){return 1==arguments.length?(...e)=>v(t,...e):2==arguments.length?v(t,b(r=_(e)),r):(r=_(r),h(e,(function e(n){let o;for(;!(o=r.next()).done;)if((n=T(n,o.value,t))instanceof Promise)return n.then(e);return n})))}var I=d((function*(t,e){for(const r of _(e)){const e=h(r,t);e instanceof Promise?yield e.then(t=>t?r:Promise.reject(p)):e&&(yield r)}})),V=d((function(t,e){return b(I(t,e))})),M=(t,e)=>e(t);function G(...t){return v(M,t)}function R(t){return!t}var w=d((function*(t,e){for(const r of _(e))yield h(r,t)}));function P(){}var O=d((function*(t,e){let r=null,n=!1;for(const o of _(e)){const e=n||h(o,t);if(e instanceof Promise?(e.catch(P),yield r=(r||Promise.resolve()).then(t=>e).then(t=>n?Promise.reject(p):(n=t,o)),r=r.catch(P)):(n=e,yield o),n)break}})),A=d((function(t,e){return G(w(t,e),O(R),v((t,e)=>t&&e),(t=!1)=>t,Boolean)}));var B,N=d((function(t,e){return"function"==typeof t?!!t(e):y(t)&&y(e)?A(t=>e.includes(t),t):e&&"object"==typeof e?A(([t,r])=>e[t]==r,function*(t){for(const e in t)yield[e,t[e]]}(t)):t instanceof RegExp?e.match(t):t==e})),j=d((function(t,e){return V(N(t),e)})),L=(B=".",d((function t(e,r){return e?y(e)?v((e,r)=>t(r,e),r,e):"object"==typeof e||"function"==typeof e?j(e,r):v((t,e,r=e[0])=>t?"#"==r?j({id:e.substr(1)},t):"["==r||"{"==r?j(JSON.parse(e),t):t[e]:void 0,r,e.split(B)):r})));const F=t=>L("transform.baseVal",t),E=({angle:t=0,cx:e=0,cy:r=0,index:n=0}={})=>(o,i=u())=>{const a=F(o),s=l({tx:e,ty:r})(i),c=l({tx:-e,ty:-r})(i),m=x({angle:t})(i);return a.insertItemBefore(c,n),a.insertItemBefore(m,n),a.insertItemBefore(s,n),m};function*C(t=0,e=t,r=1){if(1===arguments.length&&(t=0),arguments.length<3&&t>e&&(r*=-1),t<e)for(;t<e;)yield t,t+=r;else for(;t>e;)yield t,t+=r}var H=d((function(t,e){return function(t){return S(1/0,t)}(w(t,e))})),$=d((function(t,e){return H(e=>h(t(e),t=>e),e)}));const k=({index:t=1}={})=>(e,r=u())=>{const n=F(e);if(!(({index:t})=>e=>{if(t>e.numberOfItems-2||t<1)return!1;const[r,n,i]=G(C(3),w(e=>t-1+e),w(t=>e.getItem(t)));return a(r)&&o(n)&&a(i)&&0===n.matrix.e&&0===n.matrix.f&&1===r.matrix.a&&0===r.matrix.b&&0===r.matrix.c&&1===r.matrix.d&&1===i.matrix.a&&0===i.matrix.b&&0===i.matrix.c&&1===i.matrix.d&&r.matrix.e+i.matrix.e===0&&r.matrix.f+i.matrix.f===0})({index:t})(n))return e;const{angle:i}=n.getItem(t),{e:s,f:c}=n.getItem(t-1).matrix;$(()=>n.removeItem(t-1),C(3));const m=x({angle:i,cx:s,cy:c})(r);return n.insertItemBefore(m,t-1),e};var z=d((function(t,e){return null==e||Number.isNaN(e)?t:e}));const J=({angle:t,cx:e=0,cy:r=0}={})=>n=>o(n)?(n.setRotate(z(n.angle,t),e,r),n):n,X=({sx:t=1,sy:e=1}={})=>(r=u())=>{const n=f(r);return n.setScale(t,e),n},q=({sx:t=1,sy:e=1,cx:r=0,cy:n=0,index:o=0}={})=>(i,a=u())=>{const s=F(i),c=l({tx:r,ty:n})(a),m=l({tx:-r,ty:-n})(a),f=X({sx:t,sy:e})(a);return s.insertItemBefore(m,o),s.insertItemBefore(f,o),s.insertItemBefore(c,o),f},D=({a:t=1,b:e=0,c:r=0,d:n=1,e:o=0,f:i=0}={})=>(a=u())=>{const s=a.createSVGMatrix();return s.a=t,s.b=e,s.c=r,s.d=n,s.e=o,s.f=i,s},K=({matrix:t}={})=>(e=u())=>{const r=f(e);return r.setMatrix(z(D()(e),t)),r},Q=t=>{if(!n(t))return!1;const{type:e,SVG_TRANSFORM_SCALE:r}=t;return e===r},U=({index:t=0}={})=>e=>{if(t<=0||t>=e.numberOfItems-1)return!1;const[r,n,o]=G(C(3),w(e=>t-1+e),w(t=>e.getItem(t)));return a(r)&&Q(n)&&a(o)&&1===r.matrix.a&&0===r.matrix.b&&0===r.matrix.c&&1===r.matrix.d&&1===o.matrix.a&&0===o.matrix.b&&0===o.matrix.c&&1===o.matrix.d&&r.matrix.e+o.matrix.e===0&&r.matrix.f+o.matrix.f===0},W=({index:t=1}={})=>(e,r=u())=>{const n=F(e);if(!U({index:t})(n))return e;const o=G(C(3),w(e=>t-1+e),w(t=>n.getItem(t)),w(({matrix:t})=>t),v((t,e)=>t.multiply(e)),t=>K({matrix:t})(r));return $(()=>n.removeItem(t-1),C(3)),n.insertItemBefore(o,t-1),e};var Y=t=>t,Z=d((function(t,e){return G(w(t,e),O(Y),v((t,e)=>t||e),(t=!1)=>t,Boolean)}));const tt=new Set(["n","ne","e","se","s","sw","w","nw"]),et=({index:t=1,is_need_correction:e=!0,x_name:r="x",y_name:n="y",width_name:o="width",height_name:i="height",direction:a}={})=>s=>{const c=F(s);if(!U({index:t})(c)||!tt.has(a))return s;const[{e:m,f:u},{a:f,d:x},{e:l,f:d}]=G(C(3),w(e=>t-1+e),w(t=>c.getItem(t)),w(({matrix:t})=>t)),[y,g,_,p]=G([r,n,o,i],w(t=>s.getAttributeNS(null,t)),w(parseFloat));return G([[y,f,l,m,_,["e","w"]],[g,x,d,u,p,["n","s"]]],w(([t,r,n,o,i,s])=>G(s,Z(t=>a.includes(t)),a=>a?h((t+n)*r+o,t=>r<0&&e?t+i*r:t):t)),([t,e])=>[[r,t],[n,e],[o,_*Math.abs(f)],[i,p*Math.abs(x)]],w(([t,e])=>[t,""+e]),$(([t,e])=>s.setAttributeNS(null,t,e))),$(()=>c.removeItem(t-1),C(3)),s},rt=({sx:t,sy:e}={})=>r=>Q(r)?(r.setScale(z(r.matrix.a,t),z(r.matrix.d,e)),r):r,nt=({tx:t=0,ty:e=0,index:r=0}={})=>(n,o=u())=>{const i=l({tx:t,ty:e})(o);return F(n).insertItemBefore(i,r),i},ot=({index:t=0,x_name:e="x",y_name:r="y"}={})=>(n,o=u())=>{const i=F(n);if(t>i.numberOfItems-1||t<0)return n;const s=i.getItem(t);if(!a(s))return n;const{e:c,f:m}=s.matrix;return G([{name:e,value:c},{name:r,value:m}],w(({name:t,value:e})=>({name:t,value:""+(parseFloat(n.getAttributeNS(null,t))+e)})),$(({name:t,value:e})=>n.setAttributeNS(null,t,e))),i.removeItem(t),G(C(i.numberOfItems),w(t=>i.getItem(t)),w(t=>[l({tx:c,ty:m})(o),t,l({tx:-c,ty:-m})(o)]),$(([t,e,r])=>{const n=t.matrix.multiply(e.matrix).multiply(r.matrix);e.setMatrix(n)})),n},it=({tx:t,ty:e}={})=>r=>a(r)?(r.setTranslate(z(r.matrix.e,t),z(r.matrix.f,e)),r):r,at=({x:t=0,y:e=0}={})=>(r=u())=>{const n=r.createSVGPoint();return n.x=t,n.y=e,n},st=(t="")=>(e=u())=>{t=t.trim(),e.innerHTML=t;const r=$(t=>e.removeChild(t),[...e.children]);return e.innerHTML="",r},ct=(t,e=u())=>{const r=((t,e=u())=>{const{x:r,y:n,width:o,height:i}=t.getBBox();return{top_left:at({x:r,y:n})(e),top_right:at({x:r+o,y:n})(e),bottom_left:at({x:r,y:n+i})(e),bottom_right:at({x:r+o,y:n+i})(e)}})(t,e),n=(({top_left:t,top_right:e,bottom_right:r,bottom_left:n})=>(o,i=u())=>{const a=F(o),[s,c,m,f]=G([t,e,n,r],w(t=>at(t)(i)),w(t=>G(C(a.numberOfItems),w(t=>a.getItem(t)),w(({matrix:t})=>t),e=>v((t,e)=>t.matrixTransform(e),t,e))));return{top_left:s,top_right:c,bottom_left:m,bottom_right:f}})(r)(t,e);return{original:r,transformed:n,bounding:(({top_left:t,top_right:e,bottom_right:r,bottom_left:n})=>(o,i=u())=>{const a=[t,e,n,r],[s,c]=h(H(({x:t})=>t,a),t=>[Math.min(...t),Math.max(...t)]),[m,f]=h(H(({y:t})=>t,a),t=>[Math.min(...t),Math.max(...t)]);return{min:at({x:s,y:m})(i),max:at({x:c,y:f})(i)}})(n)(t,e)}};var mt=d((t,e)=>w(function(t,...e){return(r,...n)=>h(v(M,t(r,...n),e),t=>r)}(t),e));const ut=(t,e)=>t+e,ft=t=>{let e=0;const r=G(t,mt(()=>e++),v(ut));return e?r/e:0},xt=t=>{if(!n(t))return!1;const{type:e,SVG_TRANSFORM_MATRIX:r}=t;return e===r},lt={appendRotateTransform:i,appendTranslateTransform:s,consolidateTransformList:t=>{const e=t.consolidate();return e?(t.initialize(e),t):t},controlRotateTransform:({angle:t,cx:e,cy:r,index:n=0}={})=>(o,a=u())=>{const s=E({angle:t,cx:e,cy:r,index:n})(o,a),c={update:({angle:t}={})=>(J({angle:t,cx:0,cy:0})(s),c),append:({angle:t}={})=>(i({angle:t})(s),c),end:()=>(k({index:n+1})(o,a),o)};return c},controlScaleTransform:({cx:t,cy:e,sx:r,sy:n,index:o=0,is_need_correction:i=!0,merge_type:a=1,x_name:s,y_name:c,width_name:m,height_name:f,direction:x}={})=>(l,d=u())=>{const y=q({cx:t,cy:e,sx:r,sy:n,index:o})(l,d),g={update:({sx:t,sy:e}={})=>(rt({sx:t,sy:e})(y),g),end:({is_need_correction:t=i,merge_type:e=a,x_name:r=s,y_name:n=c,width_name:u=m,height_name:y=f,direction:g=x}={})=>(2===e?et({index:o+1,is_need_correction:t,x_name:r,y_name:n,width_name:u,height_name:y,direction:g})(l):W({index:o+1})(l,d),l)};return g},controlTranslateTransform:({index:t=0,tx:e,ty:r,x_name:n,y_name:o}={})=>(i,a=u())=>{const c=nt({tx:e,ty:r,index:t})(i,a),m={update:({tx:t,ty:e}={})=>(it({tx:t,ty:e})(c),m),append:({tx:t,ty:e}={})=>(s({tx:t,ty:e})(c),m),end:()=>(n&&o&&ot({index:t,x_name:n,y_name:o})(i,a),i)};return m},createSVGMatrix:D,createSVGPoint:at,createSVGRect:({x:t=0,y:e=0,width:r=0,height:n=0}={})=>(o=u())=>{const i=o.createSVGRect();return i.x=t,i.y=e,i.width=r,i.height=n,i},createSVGTransform:f,createSVGTransformMatrix:K,createSVGTransformRotate:x,createSVGTransformScale:X,createSVGTransformTranslate:l,el:t=>(e=u())=>b(st(t)(e)),els:st,getAnimTransformList:t=>L("transform.animVal",t),getBaseTransformList:F,getBoxPoints:ct,getCenterPoint:(t,e=u())=>{const{original:r,transformed:n}=ct(t,e),[o,i]=w(t=>(({top_left:t,top_right:e,bottom_left:r,bottom_right:n})=>(o=u())=>{const i=[t,e,r,n],a=ft(w(({x:t})=>t,i)),s=ft(w(({y:t})=>t,i));return at({x:a,y:s})(o)})(t)(e),[r,n]);return{original:o,transformed:i}},getSVG:u,setSVG:m,initMatrixTransform:({matrix:t,index:e=0}={})=>(r,n=u())=>{const o=K({matrix:z(D()(n),t)})(n);return F(r).insertItemBefore(o,e),o},initRotateTransform:E,initScaleTransform:q,initTranslateTransform:nt,isMatrixSVGTransform:xt,isRotateSVGTransform:o,isScaleSVGTransform:Q,isSVGTransform:n,isTranslateSVGTransform:a,isValidFxScaleSVGTransformList:U,mergeRotateTransform:k,mergeScaleTransform:W,mergeScaleTransform2:et,mergeTranslateTransform:ot,updateMatrixTransform:({matrix:t}={})=>e=>xt(e)?(e.setMatrix(z(e.matrix,t)),e):e,updateRotateTransform:J,updateScaleTransform:rt,updateTranslateTransform:it};window.$$=lt}]);
{
"name": "fxsvg",
"version": "0.4.0",
"version": "0.4.1",
"description": "Functional SVG Handling Library",

@@ -5,0 +5,0 @@ "type": "module",

@@ -27,3 +27,3 @@ import { $$appendRotateTransform } from "../appendRotateTransform/appendRotateTransform.index.js";

return { $el, transform, controller };
return controller;
};

@@ -10,2 +10,3 @@ import { expect } from "chai";

mapL,
rangeL,
rejectL,

@@ -20,5 +21,7 @@ zipL,

makeRandomInt,
makeRandomNumber,
makeRandomTransformAttributeValue,
} from "../../test/utils/index.js";
import { $$createSVGTransformRotate } from "../createSVGTransformRotate/createSVGTransformRotate.index.js";
import { $$createSVGTransformTranslate } from "../createSVGTransformTranslate/createSVGTransformTranslate.index.js";
import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js";

@@ -34,4 +37,7 @@ import { $$controlRotateTransform } from "./controlRotateTransform.index.js";

} = {}) => {
const angle = defaultTo(makeRandomInt(-700, 700), _angle);
const [cx, cy] = mapL(defaultTo(makeRandomInt(-100, 100)), [_cx, _cy]);
const angle = defaultTo(makeRandomNumber(-700, 700), _angle);
const [cx, cy] = mapL((a) => defaultTo(makeRandomNumber(-100, 100), a), [
_cx,
_cy,
]);
const transform = isUndefined(_transform)

@@ -50,29 +56,6 @@ ? makeRandomTransformAttributeValue()

describe(`$$controlRotateTransform`, function () {
it(`The return object has "$el", "controller", "transform" properties.`, function () {
it(`The return object has "update", "append", "end" methods.`, function () {
const { angle, cx, cy, index, $el } = setupMock();
const result = $$controlRotateTransform({ angle, cx, cy, index })($el);
const keys = new Set(Object.keys(result));
expect(keys.size).equal(3);
each((k) => expect(keys.has(k)).true, ["$el", "controller", "transform"]);
});
it(`The return element is same with the input element.`, function () {
const { angle, cx, cy, index, $el: $input } = setupMock();
const { $el: $output } = $$controlRotateTransform({
angle,
cx,
cy,
index,
})($input);
expect($output).equal($input);
});
it(`The return controller object has "update", "append", "end" methods.`, function () {
const { angle, cx, cy, index, $el } = setupMock();
const { controller } = $$controlRotateTransform({ angle, cx, cy, index })(
const controller = $$controlRotateTransform({ angle, cx, cy, index })(
$el

@@ -92,24 +75,35 @@ );

it(`The return transform object is a rotate transform whose angle is the input angle and cx, cy are 0.`, function () {
it(`The function initiates rotate transform to the input element with the input angle, cx, cy, index.`, function () {
const { angle, cx, cy, index, $el } = setupMock();
const { transform: receive_transform } = $$controlRotateTransform({
angle,
cx,
cy,
index,
})($el);
$$controlRotateTransform({ angle, cx, cy, index })($el);
const expect_transform = $$createSVGTransformRotate({
angle,
cx: 0,
cy: 0,
})();
expectSameValueSVGTransform(receive_transform, expect_transform);
const transform_list = $$getBaseTransformList($el);
const [
positive_translate_transform,
rotate_transform,
negative_translate_transform,
] = go(
rangeL(3),
mapL((i) => index + i),
mapL((i) => transform_list.getItem(i))
);
expectSameValueSVGTransform(
positive_translate_transform,
$$createSVGTransformTranslate({ tx: cx, ty: cy })()
);
expectSameValueSVGTransform(
rotate_transform,
$$createSVGTransformRotate({ angle, cx: 0, cy: 0 })()
);
expectSameValueSVGTransform(
negative_translate_transform,
$$createSVGTransformTranslate({ tx: -cx, ty: -cy })()
);
});
it(`The return transform object is the transform at the input index + 1.`, function () {
it(`The controller.update method update the transform with the input angle.`, function () {
const { angle, cx, cy, index, $el } = setupMock();
const { transform: receive_transform } = $$controlRotateTransform({
const controller = $$controlRotateTransform({
angle,

@@ -120,21 +114,5 @@ cx,

})($el);
const receive_transform = $$getBaseTransformList($el).getItem(index + 1);
const update_angle = makeRandomNumber(-700, 700);
const expect_transform = $$getBaseTransformList($el).getItem(index + 1);
expectSameValueSVGTransform(receive_transform, expect_transform);
});
it(`The controller.update method update the return transform with the input angle.`, function () {
const { angle, cx, cy, index, $el } = setupMock();
const {
transform: receive_transform,
controller,
} = $$controlRotateTransform({
angle,
cx,
cy,
index,
})($el);
const update_angle = makeRandomInt(-700, 700);
controller.update({ angle: update_angle });

@@ -150,9 +128,6 @@

it(`The controller.append method add the input angle to the return transform.`, function () {
it(`The controller.append method add the input angle to the transform.`, function () {
const { angle: angle1, cx, cy, index, $el } = setupMock();
const {
transform: receive_transform,
controller,
} = $$controlRotateTransform({
const controller = $$controlRotateTransform({
angle: angle1,

@@ -163,4 +138,5 @@ cx,

})($el);
const receive_transform = $$getBaseTransformList($el).getItem(index + 1);
const angle2 = makeRandomNumber(-700, 700);
const angle2 = makeRandomInt(-700, 700);
controller.append({ angle: angle2 });

@@ -173,3 +149,2 @@

})();
expectSameValueSVGTransform(receive_transform, expect_transform);

@@ -179,5 +154,5 @@ });

it(`The controller.end method merge the transforms from index to index + 2 to a rotate transform.`, function () {
const { angle, cx, cy, index, $el: $input } = setupMock();
const { angle, cx, cy, index, $el } = setupMock();
const { controller, $el: $output } = $$controlRotateTransform({
const controller = $$controlRotateTransform({
angle,

@@ -187,6 +162,6 @@ cx,

index,
})($input);
})($el);
const before_transform_list = deepCopyTransformList(
$$getBaseTransformList($output)
$$getBaseTransformList($el)
);

@@ -197,3 +172,3 @@

const after_transform_list = deepCopyTransformList(
$$getBaseTransformList($output)
$$getBaseTransformList($el)
);

@@ -200,0 +175,0 @@ const rotate_transform = $$createSVGTransformRotate({ angle, cx, cy })();

@@ -14,3 +14,3 @@ # \$\$controlRotateTransform

const $el = $$el(str)();
const { controller } = $$controlTranslateTransform({
const controller = $$controlTranslateTransform({
cx: 10,

@@ -17,0 +17,0 @@ cy: 20,

@@ -57,3 +57,3 @@ import { $$getSVG } from "../getSetSVG/getSetSVG.index.js";

return { $el, transform, controller };
return controller;
};

@@ -9,6 +9,4 @@ import { expect } from "chai";

go,
isNil,
isUndefined,
mapL,
object,
rangeL,

@@ -26,2 +24,3 @@ reduce,

import { makeRandomNumber } from "../../test/utils/makeRandomNumber.js";
import { makeRandomNumberExcept } from "../../test/utils/makeRandomNumberExcept.js";
import { makeRandomTransformAttributeValue } from "../../test/utils/makeRandomTransformAttributeValue.js";

@@ -54,14 +53,11 @@ import { $$createSVGTransformMatrix } from "../createSVGTransformMatrix/createSVGTransformMatrix.index.js";

: _transform;
const $el = go(
[
["x", _x],
["y", _y],
["width", _width],
["height", _height],
["transform", transform],
],
rejectL(([, v]) => isNil(v)),
object,
makeMockRect
const [sx, sy, cx, cy, x, y] = mapL(
(a) => defaultTo(makeRandomNumber(-100, 100), a),
[_sx, _sy, _cx, _cy, _x, _y]
);
const [width, height] = mapL(
(a) => defaultTo(makeRandomNumberExcept(0, 1000, [0]), a),
[_width, _height]
);
const $el = makeMockRect({ x, y, width, height, transform });
const index = defaultTo(

@@ -77,44 +73,8 @@ makeRandomInt(0, $$getBaseTransformList($el).numberOfItems + 1),

);
const result = go(
rangeL(4),
mapL(() => makeRandomNumber(-100, 100)),
([sx, sy, cx, cy]) => [
[_sx, sx],
[_sy, sy],
[_cx, cx],
[_cy, cy],
],
mapL(([a, b]) => defaultTo(b, a)),
([sx, sy, cx, cy]) =>
$$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
merge_type,
is_need_correction,
x_name: "x",
y_name: "y",
width_name: "width",
height_name: "height",
direction,
})($el)
);
const [x, y, width, height] = go(
["x", "y", "width", "height"],
mapL((k) => result.$el.getAttributeNS(null, k)),
mapL(parseFloat)
);
const [{ e: cx, f: cy }, { a: sx, d: sy }] = go(
rangeL(2),
mapL((i) => index + i),
mapL((i) => $$getBaseTransformList(result.$el).getItem(i)),
mapL(({ matrix: m }) => m)
);
return {
x,
y,
width,
height,
x_name: "x",
y_name: "y",
width_name: "width",
height_name: "height",
cx,

@@ -130,42 +90,60 @@ cy,

$el,
result,
};
};
const getAttributesFromElement = (index, $el) => {
const [x, y, width, height] = go(
["x", "y", "width", "height"],
mapL((k) => $el.getAttributeNS(null, k)),
mapL(parseFloat)
);
const [{ e: cx, f: cy }, { a: sx, d: sy }] = go(
rangeL(2),
mapL((i) => index + i),
mapL((i) => $$getBaseTransformList($el).getItem(i)),
mapL(({ matrix: m }) => m)
);
return { x, y, width, height, cx, cy, sx, sy };
};
export default ({ describe, it }) => [
describe(`$$controlScaleTransform`, function () {
it(`The return object has "$el", "controller", "transform" properties.`, function () {
const { result } = setupMock();
const keys = new Set(Object.keys(result));
expect(keys.size).to.equal(3);
each((k) => expect(keys.has(k)).to.be.true, [
"$el",
"controller",
"transform",
]);
});
it(`The return element is same with the input element.`, function () {
it(`The return object has "update", "end" methods.`, function () {
const {
result: { $el: $receive },
$el: $expect,
x_name,
y_name,
width_name,
height_name,
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
direction,
$el,
} = setupMock();
expect($receive).to.equal($expect);
});
const controller = $$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
it(`The return controller object has "update", "end" methods.`, function () {
const {
result: { controller },
} = setupMock();
const entries = new Map(Object.entries(controller));
expect(entries.size).to.equal(2);
expect(entries.size).equal(2);
each(
(k) => {
expect(entries.has(k)).to.be.true;
expect(entries.get(k)).is.a("function");
expect(entries.has(k)).true;
expect(entries.get(k)).a("function");
},

@@ -176,23 +154,56 @@ ["update", "end"]

it(`The return transform object is a scale transform whose sx, sy are the input sx, sy.`, function () {
it(`The function initiates scale transforms to the input element with the input sx, sy, cx, cy, index.`, function () {
const {
result: { transform: receive_transform },
x_name,
y_name,
width_name,
height_name,
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
direction,
$el,
} = setupMock();
const expect_transform = $$createSVGTransformScale({ sx, sy })();
expectSameValueSVGTransform(receive_transform, expect_transform);
});
it(`The return transform object is the transform at the input index + 1.`, function () {
const {
result: { transform: receive_transform },
$el,
$$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
} = setupMock();
const expect_transform = $$getBaseTransformList($el).getItem(index + 1);
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
expectSameValueSVGTransform(receive_transform, expect_transform);
const transform_list = $$getBaseTransformList($el);
const [
positive_translate_transform,
scale_transform,
negative_translate_transform,
] = go(
rangeL(3),
mapL((i) => index + i),
mapL((i) => transform_list.getItem(i))
);
expectSameValueSVGTransform(
positive_translate_transform,
$$createSVGTransformTranslate({ tx: cx, ty: cy })()
);
expectSameValueSVGTransform(
scale_transform,
$$createSVGTransformScale({ sx, sy })()
);
expectSameValueSVGTransform(
negative_translate_transform,
$$createSVGTransformTranslate({ tx: -cx, ty: -cy })()
);
});

@@ -202,10 +213,42 @@

const {
result: { transform: receive_transform, controller },
x_name,
y_name,
width_name,
height_name,
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
direction,
$el,
} = setupMock();
const controller = $$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const [update_sx, update_sy] = mapL(
() => makeRandomInt(-100, 100),
rangeL(2)
);
const [sx, sy] = mapL(() => makeRandomInt(-100, 100), rangeL(2));
controller.update({ sx, sy });
controller.update({ sx: update_sx, sy: update_sy });
const expect_transform = $$createSVGTransformScale({ sx, sy })();
const receive_transform = $$getBaseTransformList($el).getItem(index + 1);
const expect_transform = $$createSVGTransformScale({
sx: update_sx,
sy: update_sy,
})();
expectSameValueSVGTransform(receive_transform, expect_transform);

@@ -217,3 +260,3 @@ });

const {
result: { $el, controller },
$el,
index,

@@ -224,3 +267,26 @@ sx,

cy,
} = setupMock({ merge_type: 1 });
merge_type,
is_need_correction,
x_name,
y_name,
width_name,
height_name,
direction,
} = setupMock({
merge_type: 1,
});
const controller = $$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const before_transform_list = deepCopyTransformList(

@@ -235,7 +301,6 @@ $$getBaseTransformList($el)

);
expect(after_transform_list.length).equal(
before_transform_list.length - 2
);
go(
const merged_transform = go(
[

@@ -248,18 +313,16 @@ $$createSVGTransformTranslate({ tx: cx, ty: cy })(),

reduce((m1, m2) => m1.multiply(m2)),
(matrix) => $$createSVGTransformMatrix({ matrix })(),
(merged_transform) =>
go(
before_transform_list,
zipWithIndexL,
rejectL(([i]) => i >= index + 1 && i <= index + 2),
mapL(([i, transform]) =>
equals2(i, index) ? merged_transform : transform
),
mapL(({ type, matrix }) => ({ type, matrix }))
),
zipL(after_transform_list),
each(([receive_transform, expect_transform]) =>
expectSameValueSVGTransform(receive_transform, expect_transform)
)
(matrix) => $$createSVGTransformMatrix({ matrix })()
);
const pairs = go(
before_transform_list,
zipWithIndexL,
rejectL(([i]) => i >= index + 1 && i <= index + 2),
mapL(([i, transform]) =>
equals2(i, index) ? merged_transform : transform
),
zipL(after_transform_list)
);
for (const [receive_transform, expect_transform] of pairs) {
expectSameValueSVGTransform(receive_transform, expect_transform);
}
});

@@ -269,5 +332,32 @@

const {
result: { $el, controller },
$el,
index,
} = setupMock({ merge_type: 2 });
sx,
sy,
cx,
cy,
merge_type,
is_need_correction,
x_name,
y_name,
width_name,
height_name,
direction,
} = setupMock({
merge_type: 2,
});
const controller = $$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const before_transform_list = deepCopyTransformList(

@@ -282,7 +372,6 @@ $$getBaseTransformList($el)

);
expect(after_transform_list.length).equal(
before_transform_list.length - 3
);
go(
const pairs = go(
before_transform_list,

@@ -292,18 +381,45 @@ zipWithIndexL,

mapL(([, transform]) => transform),
zipL(after_transform_list),
each(([receive_transform, expect_transform]) =>
expectSameValueSVGTransform(receive_transform, expect_transform)
)
zipL(after_transform_list)
);
for (const [receive_transform, expect_transform] of pairs) {
expectSameValueSVGTransform(receive_transform, expect_transform);
}
});
it(`The controller.end method scales the width, height of the element by sx, sy
when the merge_type is 2.`, function () {
it(`The controller.end method scales the width, height of the element by sx, sy when the merge_type is 2.`, function () {
const {
result: { $el, controller },
$el,
index,
sx: _sx,
sy: _sy,
cx,
cy,
merge_type,
is_need_correction,
x_name,
y_name,
width_name,
height_name,
direction,
} = setupMock({ merge_type: 2 });
const controller = $$controlScaleTransform({
cx,
cy,
sx: _sx,
sy: _sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const {
width: before_width,
height: before_height,
sx,
sy,
width: before_width,
height: before_height,
} = setupMock({ merge_type: 2 });
} = getAttributesFromElement(index, $el);

@@ -322,4 +438,3 @@ controller.end();

it(`The controller.end method scales the x, y of the element by sx, sy, cx, cy
when the merge_type is 2.`, function () {
it(`The controller.end method scales the x, y of the element by sx, sy, cx, cy when the merge_type is 2.`, function () {
this.slow(3000);

@@ -339,9 +454,40 @@

),
each(({ result: { $el, controller }, x: before_x }) => {
controller.end();
each(
({
$el,
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
}) => {
const controller = $$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const { x: before_x } = getAttributesFromElement(index, $el);
const after_x = parseFloat($el.getAttributeNS(null, "x"));
controller.end();
expect(after_x).equal(before_x);
})
const after_x = parseFloat($el.getAttributeNS(null, "x"));
expect(after_x).equal(before_x);
}
)
);

@@ -361,9 +507,40 @@

),
each(({ result: { $el, controller }, y: before_y }) => {
controller.end();
each(
({
$el,
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
}) => {
const controller = $$controlScaleTransform({
cx,
cy,
sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const { y: before_y } = getAttributesFromElement(index, $el);
const after_y = parseFloat($el.getAttributeNS(null, "y"));
controller.end();
expect(after_y).equal(before_y);
})
const after_y = parseFloat($el.getAttributeNS(null, "y"));
expect(after_y).equal(before_y);
}
)
);

@@ -387,3 +564,3 @@

direction,
sx: -makeRandomNumber(1),
sx: -makeRandomNumberExcept(0, 1000, [0]),
})

@@ -395,9 +572,43 @@ )

),
each(({ result: { $el, controller }, x: before_x, cx, sx }) => {
controller.end();
each(
({
$el,
cx: _cx,
cy,
sx: _sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
}) => {
const controller = $$controlScaleTransform({
cx: _cx,
cy,
sx: _sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const { x: before_x, cx, sx } = getAttributesFromElement(
index,
$el
);
const after_x = parseFloat($el.getAttributeNS(null, "x"));
controller.end();
expect(after_x).equal((before_x - cx) * sx + cx);
})
const after_x = parseFloat($el.getAttributeNS(null, "x"));
expect(after_x).equal((before_x - cx) * sx + cx);
}
)
);

@@ -421,3 +632,3 @@

direction,
sy: -makeRandomNumber(1),
sy: -makeRandomNumberExcept(0, 1000, [0]),
})

@@ -429,9 +640,43 @@ )

),
each(({ result: { $el, controller }, y: before_y, cy, sy }) => {
controller.end();
each(
({
$el,
cx,
cy: _cy,
sx,
sy: _sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
}) => {
const controller = $$controlScaleTransform({
cx,
cy: _cy,
sx,
sy: _sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const { y: before_y, cy, sy } = getAttributesFromElement(
index,
$el
);
const after_y = parseFloat($el.getAttributeNS(null, "y"));
controller.end();
expect(after_y).equal((before_y - cy) * sy + cy);
})
const after_y = parseFloat($el.getAttributeNS(null, "y"));
expect(after_y).equal((before_y - cy) * sy + cy);
}
)
);

@@ -444,13 +689,50 @@

["ne", "e", "se", "sw", "w", "nw"],
mapL((direction) => ({ direction, sx: -makeRandomNumber() })),
mapL((direction) => ({
direction,
sx: -makeRandomNumberExcept(0, 1000, [0]),
})),
mapL(({ direction, sx }) =>
setupMock({ direction, sx, is_need_correction: true, merge_type: 2 })
),
each(({ result: { $el, controller }, x: before_x, sx, cx, width }) => {
controller.end();
each(
({
$el,
cx: _cx,
cy,
sx: _sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
}) => {
const controller = $$controlScaleTransform({
cx: _cx,
cy,
sx: _sx,
sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const { x: before_x, width, sx, cx } = getAttributesFromElement(
index,
$el
);
const after_x = parseFloat($el.getAttributeNS(null, "x"));
controller.end();
expect(after_x).equal((before_x - cx) * sx + cx + width * sx);
})
const after_x = parseFloat($el.getAttributeNS(null, "x"));
expect(after_x).equal((before_x - cx) * sx + cx + width * sx);
}
)
);

@@ -463,13 +745,50 @@

["n", "ne", "se", "s", "sw", "nw"],
mapL((direction) => ({ direction, sy: -makeRandomNumber() })),
mapL((direction) => ({
direction,
sy: -makeRandomNumberExcept(0, 1000, [0]),
})),
mapL(({ direction, sy }) =>
setupMock({ direction, sy, is_need_correction: true, merge_type: 2 })
),
each(({ result: { $el, controller }, y: before_y, sy, cy, height }) => {
controller.end();
each(
({
$el,
cx,
cy: _cy,
sx,
sy: _sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
}) => {
const controller = $$controlScaleTransform({
cx,
cy: _cy,
sx,
sy: _sy,
index,
is_need_correction,
merge_type,
x_name,
y_name,
width_name,
height_name,
direction,
})($el);
const { y: before_y, height, cy, sy } = getAttributesFromElement(
index,
$el
);
const after_y = parseFloat($el.getAttributeNS(null, "y"));
controller.end();
expect(after_y).equal((before_y - cy) * sy + cy + height * sy);
})
const after_y = parseFloat($el.getAttributeNS(null, "y"));
expect(after_y).equal((before_y - cy) * sy + cy + height * sy);
}
)
);

@@ -476,0 +795,0 @@ });

@@ -32,3 +32,3 @@ import { $$appendTranslateTransform } from "../appendTranslateTransform/appendTranslateTransform.index.js";

return { $el, controller, transform };
return controller;
};

@@ -19,2 +19,3 @@ import { expect } from "chai";

makeRandomInt,
makeRandomNumber,
makeRandomTransformAttributeValue,

@@ -35,8 +36,6 @@ } from "../../test/utils/index.js";

} = {}) => {
const [x, y, tx, ty] = mapL(defaultTo(makeRandomInt(-100, 100)), [
_x,
_y,
_tx,
_ty,
]);
const [x, y, tx, ty] = mapL(
(a) => defaultTo(makeRandomNumber(-100, 100), a),
[_x, _y, _tx, _ty]
);
const transform = isUndefined(_transform)

@@ -50,48 +49,34 @@ ? makeRandomTransformAttributeValue()

);
const result = $$controlTranslateTransform({
tx,
ty,
x_name: "x",
y_name: "y",
index,
})($el);
return { x, y, tx, ty, index, $el, result };
return { tx, ty, index, $el, x_name: "x", y_name: "y" };
};
const getAttributesFromElement = ({ index, x_name, y_name }) => ($el) => {
const [x, y] = go(
[x_name, y_name],
mapL((k) => $el.getAttributeNS(null, k)),
mapL(parseFloat)
);
const { e: tx, f: ty } = $$getBaseTransformList($el).getItem(index).matrix;
return { x, y, tx, ty };
};
export default ({ describe, it }) => [
describe(`$$controlTranslateTransform`, function () {
it(`The return object has "$el", "controller", "transform" properties.`, function () {
const { result } = setupMock();
it(`The return object has "update", "append", "end" methods.`, function () {
const { tx, ty, x_name, y_name, index, $el } = setupMock();
const keys = new Set(Object.keys(result));
const controller = $$controlTranslateTransform({
index,
tx,
ty,
x_name,
y_name,
})($el);
expect(keys.size).to.equal(3);
each((k) => expect(keys.has(k)).to.be.true, [
"$el",
"controller",
"transform",
]);
});
it(`The return element is same with the input element.`, function () {
const {
result: { $el: $receive },
$el: $expect,
} = setupMock();
expect($receive).to.equal($expect);
});
it(`The return controller object has "update", "append", "end" methods.`, function () {
const {
result: { controller },
} = setupMock();
const entries = new Map(Object.entries(controller));
expect(entries.size).to.equal(3);
expect(entries.size).equal(3);
each(
(k) => {
expect(entries.has(k)).to.be.true;
expect(entries.get(k)).is.a("function");
expect(entries.has(k)).true;
expect(entries.get(k)).a("function");
},

@@ -102,46 +87,50 @@ ["update", "append", "end"]

it(`The return transform object is a translate transform whose tx, ty are the input tx, ty.`, function () {
const {
result: { transform: receive_transform },
tx,
ty,
} = setupMock();
it(`The function initiates a translate transform to the input element with the input tx, ty, index.`, function () {
const { $el, index, x_name, y_name, tx, ty } = setupMock();
const expect_transform = $$createSVGTransformTranslate({ tx, ty })();
$$controlTranslateTransform({ index, tx, ty, x_name, y_name })($el);
expectSameValueSVGTransform(receive_transform, expect_transform);
const translate_transform = $$getBaseTransformList($el).getItem(index);
expectSameValueSVGTransform(
translate_transform,
$$createSVGTransformTranslate({ tx, ty })()
);
});
it(`The return transform object is the transform at the input index.`, function () {
const {
result: { transform: receive_transform },
$el,
it(`The controller.update method update the transform with the input tx, ty.`, function () {
const { $el, index, x_name, y_name, tx, ty } = setupMock();
const controller = $$controlTranslateTransform({
index,
} = setupMock();
const expect_transform = $$getBaseTransformList($el).getItem(index);
tx,
ty,
x_name,
y_name,
})($el);
const receive_transform = $$getBaseTransformList($el).getItem(index);
const [update_tx, update_ty] = mapL(
() => makeRandomNumber(-100, 100),
rangeL(2)
);
expectSameValueSVGTransform(receive_transform, expect_transform);
});
controller.update({ tx: update_tx, ty: update_ty });
it(`The controller.update method update the return transform with the input tx, ty.`, function () {
const {
result: { transform: receive_transform, controller },
} = setupMock();
const [tx, ty] = mapL(() => makeRandomInt(-100, 100), rangeL(2));
controller.update({ tx, ty });
const expect_transform = $$createSVGTransformTranslate({ tx, ty })();
const expect_transform = $$createSVGTransformTranslate({
tx: update_tx,
ty: update_ty,
})();
expectSameValueSVGTransform(receive_transform, expect_transform);
});
it(`The controller.append method add the input tx, ty to the return transform.`, function () {
const {
result: { transform: receive_transform, controller },
it(`The controller.append method add the input tx, ty to the transform.`, function () {
const { x_name, y_name, index, tx: tx1, ty: ty1, $el } = setupMock();
const controller = $$controlTranslateTransform({
index,
tx: tx1,
ty: ty1,
} = setupMock();
x_name,
y_name,
})($el);
const receive_transform = $$getBaseTransformList($el).getItem(index);
const [tx2, ty2] = mapL(() => makeRandomNumber(-100, 100), rangeL(2));
const [tx2, ty2] = mapL(() => makeRandomInt(-100, 100), rangeL(2));
controller.append({ tx: tx2, ty: ty2 });

@@ -153,28 +142,71 @@

})();
expectSameValueSVGTransform(receive_transform, expect_transform);
});
it(`The controller.end method update x, y of the element.`, function () {
const {
result: { $el, controller },
x,
y,
tx,
ty,
} = setupMock();
it(`The controller.end method update x, y of the element if there are x_name and y_name.`, function () {
const { index, $el, tx: _tx, ty: _ty, x_name, y_name } = setupMock();
const controller = $$controlTranslateTransform({
index,
tx: _tx,
ty: _ty,
x_name,
y_name,
})($el);
const { x, y, tx, ty } = getAttributesFromElement({
index,
x_name,
y_name,
})($el);
controller.end();
expect($el.getAttributeNS(null, "x")).to.equal(`${x + tx}`);
expect($el.getAttributeNS(null, "y")).to.equal(`${y + ty}`);
expect($el.getAttributeNS(null, "x")).equal(`${x + tx}`);
expect($el.getAttributeNS(null, "y")).equal(`${y + ty}`);
});
it(`The controller.end method remove the translate transform.`, function () {
const {
result: { $el, controller },
it(`The controller.end method do nothing to the element and the transform list
if there is no x_name or y_name.`, function () {
const cases = [
[true, false],
[false, true],
[false, false],
];
for (const [is_x_name, is_y_name] of cases) {
const { index, $el, tx, ty, x_name, y_name } = setupMock();
const controller = $$controlTranslateTransform({
index,
tx,
ty,
x_name: is_x_name ? x_name : undefined,
y_name: is_y_name ? y_name : undefined,
})($el);
const $before = $el.cloneNode(true);
const before_transform_list = deepCopyTransformList(
$$getBaseTransformList($el)
);
controller.end();
const $after = $el.cloneNode(true);
const after_transform_list = deepCopyTransformList(
$$getBaseTransformList($el)
);
expect($after).deep.equal($before);
expect(after_transform_list.length).equal(before_transform_list.length);
const pairs = zipL(after_transform_list, before_transform_list);
for (const [receive_transform, expect_transform] of pairs) {
expectSameValueSVGTransform(receive_transform, expect_transform);
}
}
});
it(`The controller.end method remove the translate transform if there are x_name and y_name.`, function () {
const { index, tx, ty, x_name, y_name, $el } = setupMock();
const controller = $$controlTranslateTransform({
index,
tx,
ty,
} = setupMock();
x_name,
y_name,
})($el);
const before_transform_list = deepCopyTransformList(

@@ -193,3 +225,3 @@ $$getBaseTransformList($el)

);
go(
const [positive_translate_matrix, negative_translate_matrix] = go(
[

@@ -200,22 +232,23 @@ { tx, ty },

mapL((values) => $$createSVGTransformTranslate(values)()),
mapL(({ matrix: m }) => m),
([plus_matrix, minus_matrix]) =>
go(
before_transform_list,
zipWithIndexL,
rejectL(([i]) => equals2(i, index)),
mapL(([, transform]) => transform),
mapL(({ matrix }) =>
$$createSVGTransformMatrix({
matrix: plus_matrix.multiply(matrix).multiply(minus_matrix),
})()
),
zipL(after_transform_list)
),
each(([after_transform, before_transform]) =>
expectSameValueSVGTransform(after_transform, before_transform)
)
mapL(({ matrix: m }) => m)
);
const pairs = go(
before_transform_list,
zipWithIndexL,
rejectL(([i]) => equals2(i, index)),
mapL(([, transform]) => transform),
mapL(({ matrix }) =>
$$createSVGTransformMatrix({
matrix: positive_translate_matrix
.multiply(matrix)
.multiply(negative_translate_matrix),
})()
),
zipL(after_transform_list)
);
for (const [receive_transform, expect_transform] of pairs) {
expectSameValueSVGTransform(receive_transform, expect_transform);
}
});
}),
];

@@ -16,3 +16,3 @@ # \$\$controlTranslateTransform

const $el = $$el(str)();
const { controller } = $$controlTranslateTransform({
const controller = $$controlTranslateTransform({
x_name: "cx",

@@ -19,0 +19,0 @@ y_name: "cy",

@@ -5,2 +5,3 @@ import { expect } from "chai";

import { $$isMatrixSVGTransform } from "../isMatrixSVGTransform/isMatrixSVGTransform.index.js";
import { $$isSVGTransform } from "../isSVGTransform/isSVGTransform.index.js";
import { $$createSVGTransform } from "./createSVGTransform.index.js";

@@ -20,3 +21,3 @@

for (const transform of makeCases()) {
expect(transform).instanceof(SVGTransform);
expect($$isSVGTransform(transform)).true;
}

@@ -23,0 +24,0 @@ });

@@ -10,2 +10,3 @@ import { expect } from "chai";

import { $$isRotateSVGTransform } from "../isRotateSVGTransform/isRotateSVGTransform.index.js";
import { $$isSVGTransform } from "../isSVGTransform/isSVGTransform.index.js";
import { $$createSVGTransformRotate } from "./createSVGTransformRotate.index.js";

@@ -33,3 +34,3 @@

for (const { transform } of makeCases()) {
expect(transform).instanceof(SVGTransform);
expect($$isSVGTransform(transform)).true;
}

@@ -36,0 +37,0 @@ });

@@ -7,2 +7,3 @@ import { expect } from "chai";

import { $$isScaleSVGTransform } from "../isScaleSVGTransform/isScaleSVGTransform.index.js";
import { $$isSVGTransform } from "../isSVGTransform/isSVGTransform.index.js";
import { $$createSVGTransformScale } from "./createSVGTransformScale.index.js";

@@ -30,3 +31,3 @@

for (const { transform } of makeCases()) {
expect(transform).instanceof(SVGTransform);
expect($$isSVGTransform(transform)).true;
}

@@ -33,0 +34,0 @@ });

@@ -29,2 +29,3 @@ import { $$appendRotateTransform } from "./appendRotateTransform/appendRotateTransform.index.js";

import { $$isScaleSVGTransform } from "./isScaleSVGTransform/isScaleSVGTransform.index.js";
import { $$isSVGTransform } from "./isSVGTransform/isSVGTransform.index.js";
import { $$isTranslateSVGTransform } from "./isTranslateSVGTransform/isTranslateSVGTransform.index.js";

@@ -71,2 +72,3 @@ import { $$isValidFxScaleSVGTransformList } from "./isValidFxScaleSVGTransformList/isValidFxScaleSVGTransformList.index.js";

isScaleSVGTransform: $$isScaleSVGTransform,
isSVGTransform: $$isSVGTransform,
isTranslateSVGTransform: $$isTranslateSVGTransform,

@@ -73,0 +75,0 @@ isValidFxScaleSVGTransformList: $$isValidFxScaleSVGTransformList,

@@ -29,2 +29,3 @@ export { $$appendRotateTransform } from "./appendRotateTransform/appendRotateTransform.index.js";

export { $$isScaleSVGTransform } from "./isScaleSVGTransform/isScaleSVGTransform.index.js";
export { $$isSVGTransform } from "./isSVGTransform/isSVGTransform.index.js";
export { $$isTranslateSVGTransform } from "./isTranslateSVGTransform/isTranslateSVGTransform.index.js";

@@ -31,0 +32,0 @@ export { $$isValidFxScaleSVGTransformList } from "./isValidFxScaleSVGTransformList/isValidFxScaleSVGTransformList.index.js";

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

import { $$isSVGTransform } from "../isSVGTransform/isSVGTransform.index.js";
export const $$isMatrixSVGTransform = (transform) => {
if (!(transform instanceof SVGTransform)) {
if (!$$isSVGTransform(transform)) {
return false;

@@ -4,0 +6,0 @@ }

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

import { $$isSVGTransform } from "../isSVGTransform/isSVGTransform.index.js";
export const $$isRotateSVGTransform = (transform) => {
if (!(transform instanceof SVGTransform)) {
if (!$$isSVGTransform(transform)) {
return false;

@@ -4,0 +6,0 @@ }

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

import { $$isSVGTransform } from "../isSVGTransform/isSVGTransform.index.js";
export const $$isScaleSVGTransform = (transform) => {
if (!(transform instanceof SVGTransform)) {
if (!$$isSVGTransform(transform)) {
return false;

@@ -4,0 +6,0 @@ }

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

import { $$isSVGTransform } from "../isSVGTransform/isSVGTransform.index.js";
export const $$isTranslateSVGTransform = (transform) => {
if (!(transform instanceof SVGTransform)) {
if (!$$isSVGTransform(transform)) {
return false;

@@ -4,0 +6,0 @@ }

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