Comparing version 0.2.0 to 0.2.1
@@ -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))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_ROTATE:r}=t;return e===r},o=(t,{angle:e=0})=>{if(!n(t))return t;const{angle:r}=t;return t.setRotate(r+e,0,0),t},a=t=>{if(!(t instanceof SVGTransform))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_TRANSLATE:r}=t;return e===r},i=(t,{tx:e=0,ty:r=0})=>{if(!a(t))return t;const{e:n,f:o}=t.matrix;return t.setTranslate(n+e,o+r),t},s=t=>{const e=t.consolidate();return e?(t.initialize(e),t):t},m=({transform:{baseVal:t}})=>t;let f;const c=t=>(f=t,f),u=()=>(f||c(document.createElementNS("http://www.w3.org/2000/svg","svg")),f),l=(t=u())=>t.createSVGTransform(),x=(t=u())=>({angle:e=0,cx:r=0,cy:n=0}={})=>{const o=l(t);return o.setRotate(e,r,n),o},y=(t=u())=>({tx:e=0,ty:r=0}={})=>{const n=l(t);return n.setTranslate(e,r),n},g=(t=u())=>(e,{angle:r=0,cx:n=0,cy:o=0,index:a=0}={})=>{const i=m(e);i.insertItemBefore(y(t)({tx:-n,ty:-o}),a);const s=i.insertItemBefore(x(t)({angle:r}),a);return i.insertItemBefore(y(t)({tx:n,ty:o}),a),s};function T(t){return(e,...r)=>r.length?t(e,...r):(...r)=>t(e,...r)}var d=(t,e)=>t instanceof Promise?t.then(e):e(t);const S=function*(){}();function p(t){return t&&t[Symbol.iterator]?t[Symbol.iterator]():S}var h=T((function*(t,e){for(const r of p(e))yield d(r,t)}));function*_(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 b=Symbol.for("nop"),V=T((function(t,e){if(t<1)return[];let r=[];return e=p(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==b?n():Promise.reject(t));if(r.push(e),r.length==t)return r}return r}()}));var G=T((function(t,e){return function(t){return V(1/0,t)}(h(t,e))})),v=T((function(t,e){return G(e=>d(t(e),t=>e),e)}));const I=(t=u())=>e=>{const r=m(e);if(r.numberOfItems<3)return e;const[o,i,s]=h(t=>r.getItem(t),_(3));return a(o)&&n(i)&&a(s)&&0===i.matrix.e&&0===i.matrix.f&&1===o.matrix.a&&0===o.matrix.b&&0===o.matrix.c&&1===o.matrix.d&&1===s.matrix.a&&0===s.matrix.b&&0===s.matrix.c&&1===s.matrix.d&&o.matrix.e+s.matrix.e===0&&o.matrix.f+s.matrix.f===0?(v(()=>r.removeItem(0),_(3)),r.insertItemBefore(x(t)({angle:i.angle,cx:o.matrix.e,cy:o.matrix.f}),0),e):e},M=(t,{angle:e=t.angle,cx:r=0,cy:o=0}={})=>n(t)?(t.setRotate(e,r,o),t):t,R=(t=u())=>(e,{tx:r=0,ty:n=0,index:o=0}={})=>m(e).insertItemBefore(y(t)({tx:r,ty:n}),o);function w(t,e,r){return e instanceof Promise?e.then(e=>r(t,e),e=>e==b?t:Promise.reject(e)):r(t,e)}function O(t){return d(V(1,t),([t])=>t)}function P(t,e,r){return 1==arguments.length?(...e)=>P(t,...e):2==arguments.length?P(t,O(r=p(e)),r):(r=p(r),d(e,(function e(n){let o;for(;!(o=r.next()).done;)if((n=w(n,o.value,t))instanceof Promise)return n.then(e);return n})))}var B=(t,e)=>e(t);function A(...t){return P(B,t)}const j=(t=u())=>(e,{x_name:r="x",y_name:n="y"}={})=>{const o=m(e);if(o.numberOfItems<1)return e;const i=o.getItem(0);if(!a(i))return e;const{e:s,f:f}=i.matrix;return A([{name:r,value:s},{name:n,value:f}],h(({name:t,value:r})=>({name:t,value:""+(parseFloat(e.getAttributeNS(null,t))+r)})),v(({name:t,value:r})=>e.setAttributeNS(null,t,r))),o.removeItem(0),A(_(o.numberOfItems),h(t=>o.getItem(t)),h(e=>[y(t)({tx:s,ty:f}),e,y(t)({tx:-s,ty:-f})]),v(([t,e,r])=>{const n=t.matrix.multiply(e.matrix).multiply(r.matrix);e.setMatrix(n)})),e},E=(t,{tx:e=t.matrix.e,ty:r=t.matrix.f}={})=>a(t)?(t.setTranslate(e,r),t):t,N=(t=u())=>({a:e=1,b:r=0,c:n=0,d:o=1,e:a=0,f:i=0}={})=>{const s=t.createSVGMatrix();return s.a=e,s.b=r,s.c=n,s.d=o,s.e=a,s.f=i,s},L=(t=u())=>({x:e=0,y:r=0}={})=>{const n=t.createSVGPoint();return n.x=e,n.y=r,n},F=(t=u())=>({matrix:e=N(t)()}={})=>{const r=l(t);return r.setMatrix(e),r},$=(t=u())=>({sx:e=1,sy:r=1}={})=>{const n=l(t);return n.setScale(e,r),n},C=(t=u())=>e=>{e=e.trim(),t.innerHTML=e;const r=v(e=>t.removeChild(e),[...t.children]);return t.innerHTML="",r},H=(t=u())=>e=>{const r=((t=u())=>e=>{const r=e.getBBox(),[n,o,a,i]=h(L(t),[{x:r.x,y:r.y},{x:r.x+r.width,y:r.y},{x:r.x,y:r.y+r.height},{x:r.x+r.width,y:r.y+r.height}]);return{top_left:n,top_right:o,bottom_left:a,bottom_right:i}})(t)(e),n=((t=u())=>(e,r)=>{const n=m(e),[o,a,i,s]=A([r.top_left,r.top_right,r.bottom_left,r.bottom_right],h(L(t)),h(t=>A(_(n.numberOfItems),h(t=>n.getItem(t)),h(({matrix:t})=>t),e=>P((t,e)=>t.matrixTransform(e),t,e))));return{top_left:o,top_right:a,bottom_left:i,bottom_right:s}})(t)(e,r);return{original:r,transformed:n,bounding:((t=u())=>(e,r)=>{const n=[r.top_left,r.top_right,r.bottom_left,r.bottom_right],[o,a]=d(G(({x:t})=>t,n),t=>[Math.min(...t),Math.max(...t)]),[i,s]=d(G(({y:t})=>t,n),t=>[Math.min(...t),Math.max(...t)]),[m,f]=h(L(t),[{x:o,y:i},{x:a,y:s}]);return{min:m,max:f}})(t)(e,n)}},z=t=>{if(!(t instanceof SVGTransform))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_MATRIX:r}=t;return e===r},X=t=>{if(!(t instanceof SVGTransform))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_SCALE:r}=t;return e===r},k={appendRotateTransform:o,appendTranslateTransform:i,consolidateTransformList:s,controlRotateTransform:(t=u())=>(e,{angle:r=0,cx:n=0,cy:a=0}={})=>{const i=g(t)(e,{angle:r,cx:n,cy:a}),f={update:({angle:t})=>(M(i,{angle:t,cx:0,cy:0}),f),append:({angle:t})=>(o(i,{angle:t}),f),end:()=>(I(t)(e),s(m(e)),e)};return{$el:e,transform:i,controller:f}},controlTranslateTransform:(t=u())=>(e,{tx:r=0,ty:n=0,x_name:o,y_name:a}={})=>{const f=R(t)(e,{tx:r,ty:n}),c={update:({tx:t,ty:e})=>(E(f,{tx:t,ty:e}),c),append:({tx:t,ty:e})=>(i(f,{tx:t,ty:e}),c),end:()=>(o&&a&&j(t)(e,{x_name:o,y_name:a}),s(m(e)),e)};return{$el:e,controller:c,transform:f}},createSVGMatrix:N,createSVGPoint:L,createSVGRect:(t=u())=>({x:e=0,y:r=0,width:n=0,height:o=0}={})=>{const a=t.createSVGRect();return a.x=e,a.y=r,a.width=n,a.height=o,a},createSVGTransform:l,createSVGTransformMatrix:F,createSVGTransformRotate:x,createSVGTransformScale:$,createSVGTransformTranslate:y,el:(t=u())=>e=>O(C(t)(e)),els:C,getAnimTransformList:({transform:{animVal:t}})=>t,getBaseTransformList:m,getBoxPoints:H,getCenterPoint:(t=u())=>e=>A(H(t)(e),({original:t,transformed:e})=>[t,e],h(((t=u())=>e=>{const r=[e.top_left,e.top_right,e.bottom_left,e.bottom_right],n=A(r,h(({x:t})=>t),P((t,e)=>t+e),t=>t/4),o=A(r,h(({y:t})=>t),P((t,e)=>t+e),t=>t/4);return L(t)({x:n,y:o})})(t)),([t,e])=>({original:t,transformed:e})),getSVG:u,setSVG:c,initMatrixTransform:(t=u())=>(e,{matrix:r=N()(),index:n=0}={})=>m(e).insertItemBefore(F(t)({matrix:r}),n),initRotateTransform:g,initScaleTransform:(t=u())=>(e,{sx:r=1,sy:n=1,cx:o=0,cy:a=0,index:i=0}={})=>{const s=m(e);s.insertItemBefore(y(t)({tx:-o,ty:-a}),i);const f=s.insertItemBefore($(t)({sx:r,sy:n}),i);return s.insertItemBefore(y(t)({tx:o,ty:a}),i),f},initTranslateTransform:R,isMatrixSVGTransform:z,isRotateSVGTransform:n,isScaleSVGTransform:X,isTranslateSVGTransform:a,mergeRotateTransform:I,mergeTranslateTransform:j,updateMatrixTransform:(t,{matrix:e}={})=>z(t)?(e&&t.setMatrix(e),t):t,updateRotateTransform:M,updateScaleTransform:(t,{sx:e=t.matrix.a,sy:r=t.matrix.d}={})=>X(t)?(t.setScale(e,r),t):t,updateTranslateTransform:E};window.$$=k}]); | ||
!function(t){var e={};function r(n){if(e[n])return e[n].exports;var a=e[n]={i:n,l:!1,exports:{}};return t[n].call(a.exports,a,a.exports,r),a.l=!0,a.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 a in t)r.d(n,a,function(e){return t[e]}.bind(null,a));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))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_ROTATE:r}=t;return e===r},a=(t,{angle:e=0})=>{if(!n(t))return t;const{angle:r}=t;return t.setRotate(r+e,0,0),t},o=t=>{if(!(t instanceof SVGTransform))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_TRANSLATE:r}=t;return e===r},i=(t,{tx:e=0,ty:r=0})=>{if(!o(t))return t;const{e:n,f:a}=t.matrix;return t.setTranslate(n+e,a+r),t},s=t=>{const e=t.consolidate();return e?(t.initialize(e),t):t},m=({transform:{baseVal:t}})=>t;let f;const c=t=>(f=t,f),x=()=>(f||c(document.createElementNS("http://www.w3.org/2000/svg","svg")),f),u=(t=x())=>t.createSVGTransform(),l=(t=x())=>({angle:e=0,cx:r=0,cy:n=0}={})=>{const a=u(t);return a.setRotate(e,r,n),a},d=(t=x())=>({tx:e=0,ty:r=0}={})=>{const n=u(t);return n.setTranslate(e,r),n},y=(t=x())=>(e,{angle:r=0,cx:n=0,cy:a=0,index:o=0}={})=>{const i=m(e);i.insertItemBefore(d(t)({tx:-n,ty:-a}),o);const s=i.insertItemBefore(l(t)({angle:r}),o);return i.insertItemBefore(d(t)({tx:n,ty:a}),o),s},g=function*(){}();function T(t){return t&&t[Symbol.iterator]?t[Symbol.iterator]():g}var S=(t,e)=>t instanceof Promise?t.then(e):e(t);var p=Symbol.for("nop");function h(t,e,r){return e instanceof Promise?e.then(e=>r(t,e),e=>e==p?t:Promise.reject(e)):r(t,e)}function b(t){return(e,...r)=>r.length?t(e,...r):(...r)=>t(e,...r)}var _=b((function(t,e){if(t<1)return[];let r=[];return e=T(e),function n(){let a;for(;!(a=e.next()).done;){const e=a.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 V(t){return S(_(1,t),([t])=>t)}function I(t,e,r){return 1==arguments.length?(...e)=>I(t,...e):2==arguments.length?I(t,V(r=T(e)),r):(r=T(r),S(e,(function e(n){let a;for(;!(a=r.next()).done;)if((n=h(n,a.value,t))instanceof Promise)return n.then(e);return n})))}var G=(t,e)=>e(t);function v(...t){return I(G,t)}function*M(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 w=b((function*(t,e){for(const r of T(e))yield S(r,t)}));var R=b((function(t,e){return function(t){return _(1/0,t)}(w(t,e))})),O=b((function(t,e){return R(e=>S(t(e),t=>e),e)}));const P=(t=x())=>(e,{index:r=1}={})=>{const a=m(e);if(!((t,{index:e})=>!(e>t.numberOfItems-2)&&v(M(3),w(t=>e-1+t),w(e=>t.getItem(e)),([t,e,r])=>o(t)&&n(e)&&o(r)&&0===e.matrix.e&&0===e.matrix.f&&1===t.matrix.a&&0===t.matrix.b&&0===t.matrix.c&&1===t.matrix.d&&1===r.matrix.a&&0===r.matrix.b&&0===r.matrix.c&&1===r.matrix.d&&t.matrix.e+r.matrix.e===0&&t.matrix.f+r.matrix.f===0))(a,{index:r}))return e;const{angle:i}=a.getItem(r),{e:s,f:f}=a.getItem(r-1).matrix;return O(()=>a.removeItem(r-1),M(3)),a.insertItemBefore(l(t)({angle:i,cx:s,cy:f}),r-1),e},A=(t,{angle:e=t.angle,cx:r=0,cy:a=0}={})=>n(t)?(t.setRotate(e,r,a),t):t,B=(t=x())=>(e,{tx:r=0,ty:n=0,index:a=0}={})=>m(e).insertItemBefore(d(t)({tx:r,ty:n}),a),N=(t=x())=>(e,{index:r=0,x_name:n="x",y_name:a="y"}={})=>{const i=m(e);if(r>i.numberOfItems-1)return e;const s=i.getItem(r);if(!o(s))return e;const{e:f,f:c}=s.matrix;return v([{name:n,value:f},{name:a,value:c}],w(({name:t,value:r})=>({name:t,value:""+(parseFloat(e.getAttributeNS(null,t))+r)})),O(({name:t,value:r})=>e.setAttributeNS(null,t,r))),i.removeItem(r),v(M(i.numberOfItems),w(t=>i.getItem(t)),w(e=>[d(t)({tx:f,ty:c}),e,d(t)({tx:-f,ty:-c})]),O(([t,e,r])=>{const n=t.matrix.multiply(e.matrix).multiply(r.matrix);e.setMatrix(n)})),e},j=(t,{tx:e=t.matrix.e,ty:r=t.matrix.f}={})=>o(t)?(t.setTranslate(e,r),t):t,E=(t=x())=>({a:e=1,b:r=0,c:n=0,d:a=1,e:o=0,f:i=0}={})=>{const s=t.createSVGMatrix();return s.a=e,s.b=r,s.c=n,s.d=a,s.e=o,s.f=i,s},L=(t=x())=>({x:e=0,y:r=0}={})=>{const n=t.createSVGPoint();return n.x=e,n.y=r,n},F=(t=x())=>({matrix:e=E(t)()}={})=>{const r=u(t);return r.setMatrix(e),r},$=(t=x())=>({sx:e=1,sy:r=1}={})=>{const n=u(t);return n.setScale(e,r),n},C=(t=x())=>e=>{e=e.trim(),t.innerHTML=e;const r=O(e=>t.removeChild(e),[...t.children]);return t.innerHTML="",r},H=(t=x())=>e=>{const r=((t=x())=>e=>{const r=e.getBBox(),[n,a,o,i]=w(L(t),[{x:r.x,y:r.y},{x:r.x+r.width,y:r.y},{x:r.x,y:r.y+r.height},{x:r.x+r.width,y:r.y+r.height}]);return{top_left:n,top_right:a,bottom_left:o,bottom_right:i}})(t)(e),n=((t=x())=>(e,r)=>{const n=m(e),[a,o,i,s]=v([r.top_left,r.top_right,r.bottom_left,r.bottom_right],w(L(t)),w(t=>v(M(n.numberOfItems),w(t=>n.getItem(t)),w(({matrix:t})=>t),e=>I((t,e)=>t.matrixTransform(e),t,e))));return{top_left:a,top_right:o,bottom_left:i,bottom_right:s}})(t)(e,r);return{original:r,transformed:n,bounding:((t=x())=>(e,r)=>{const n=[r.top_left,r.top_right,r.bottom_left,r.bottom_right],[a,o]=S(R(({x:t})=>t,n),t=>[Math.min(...t),Math.max(...t)]),[i,s]=S(R(({y:t})=>t,n),t=>[Math.min(...t),Math.max(...t)]),[m,f]=w(L(t),[{x:a,y:i},{x:o,y:s}]);return{min:m,max:f}})(t)(e,n)}},z=t=>{if(!(t instanceof SVGTransform))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_MATRIX:r}=t;return e===r},X=t=>{if(!(t instanceof SVGTransform))throw new Error("It's not a SVGTransform.");const{type:e,SVG_TRANSFORM_SCALE:r}=t;return e===r},k=(t,{index:e=0}={})=>e>0&&e+1<t.numberOfItems&&v(M(3),w(t=>e-1+t),w(e=>t.getItem(e)),([t,e,r])=>o(t)&&X(e)&&o(r)&&1===t.matrix.a&&0===t.matrix.b&&0===t.matrix.c&&1===t.matrix.d&&1===r.matrix.a&&0===r.matrix.b&&0===r.matrix.c&&1===r.matrix.d&&t.matrix.e+r.matrix.e===0&&t.matrix.f+r.matrix.f===0),q={appendRotateTransform:a,appendTranslateTransform:i,consolidateTransformList:s,controlRotateTransform:(t=x())=>(e,{angle:r=0,cx:n=0,cy:o=0,index:i=0}={})=>{const f=y(t)(e,{angle:r,cx:n,cy:o,index:i}),c={update:({angle:t})=>(A(f,{angle:t,cx:0,cy:0}),c),append:({angle:t})=>(a(f,{angle:t}),c),end:()=>(P(t)(e,{index:i+1}),s(m(e)),e)};return{$el:e,transform:f,controller:c}},controlTranslateTransform:(t=x())=>(e,{index:r=0,tx:n=0,ty:a=0,x_name:o,y_name:f}={})=>{const c=B(t)(e,{tx:n,ty:a,index:r}),x={update:({tx:t,ty:e})=>(j(c,{tx:t,ty:e}),x),append:({tx:t,ty:e})=>(i(c,{tx:t,ty:e}),x),end:()=>(o&&f&&N(t)(e,{index:r,x_name:o,y_name:f}),s(m(e)),e)};return{$el:e,controller:x,transform:c}},createSVGMatrix:E,createSVGPoint:L,createSVGRect:(t=x())=>({x:e=0,y:r=0,width:n=0,height:a=0}={})=>{const o=t.createSVGRect();return o.x=e,o.y=r,o.width=n,o.height=a,o},createSVGTransform:u,createSVGTransformMatrix:F,createSVGTransformRotate:l,createSVGTransformScale:$,createSVGTransformTranslate:d,el:(t=x())=>e=>V(C(t)(e)),els:C,getAnimTransformList:({transform:{animVal:t}})=>t,getBaseTransformList:m,getBoxPoints:H,getCenterPoint:(t=x())=>e=>v(H(t)(e),({original:t,transformed:e})=>[t,e],w(((t=x())=>e=>{const r=[e.top_left,e.top_right,e.bottom_left,e.bottom_right],n=v(r,w(({x:t})=>t),I((t,e)=>t+e),t=>t/4),a=v(r,w(({y:t})=>t),I((t,e)=>t+e),t=>t/4);return L(t)({x:n,y:a})})(t)),([t,e])=>({original:t,transformed:e})),getSVG:x,setSVG:c,initMatrixTransform:(t=x())=>(e,{matrix:r=E()(),index:n=0}={})=>m(e).insertItemBefore(F(t)({matrix:r}),n),initRotateTransform:y,initScaleTransform:(t=x())=>(e,{sx:r=1,sy:n=1,cx:a=0,cy:o=0,index:i=0}={})=>{const s=m(e);s.insertItemBefore(d(t)({tx:-a,ty:-o}),i);const f=s.insertItemBefore($(t)({sx:r,sy:n}),i);return s.insertItemBefore(d(t)({tx:a,ty:o}),i),f},initTranslateTransform:B,isMatrixSVGTransform:z,isRotateSVGTransform:n,isScaleSVGTransform:X,isTranslateSVGTransform:o,isValidFxScaleSVGTransformList:k,mergeRotateTransform:P,mergeScaleTransform:(t=x())=>(e,{index:r=0}={})=>{const n=m(e);if(!k(n,{index:r}))return e;const a=v(M(3),w(t=>r-1+t),w(t=>n.getItem(t)),w(({matrix:t})=>t),I((t,e)=>t.multiply(e)),t=>({matrix:t}),F(t));return O(()=>n.removeItem(r-1),M(3)),n.insertItemBefore(a,r-1),e},mergeScaleTransform2:(t,{index:e,x_name:r,y_name:n,width_name:a,height_name:o,direction:i})=>{const s=m(t);if(!k(s,{index:e}))return t;const[{e:f,f:c},{a:x,d:u},{e:l,f:d}]=v(M(3),w(t=>e-1+t),w(t=>s.getItem(t)),w(({matrix:t})=>t)),[y,g,T,S]=w(e=>parseFloat(t.getAttributeNS(null,e)),[r,n,a,o]),[p,h]=w(([t,e])=>t*Math.abs(e),[[T,x],[S,u]]);let b=y,_=g;return"n"===i?_=u>=0?(_+d)*u+c:_+S:"ne"===i?(b=x>=0?(b+l)*x+f:b-p,_=u>=0?(_+d)*u+c:_+S):"e"===i?b=x>=0?(b+l)*x+f:b-p:"se"===i?(b=x>=0?(b+l)*x+f:b-p,_=u>=0?(_+d)*u+c:_-h):"s"===i?_=u>=0?(_+d)*u+c:_-h:"sw"===i?(b=x>=0?(b+l)*x+f:b+T,_=u>=0?(_+d)*u+c:_-h):"w"===i?b=x>=0?(b+l)*x+f:b+T:"nw"===i&&(b=x>=0?(b+l)*x+f:b+T,_=u>=0?(_+d)*u+c:_+S),v([[r,b],[n,_],[a,p],[o,h]],w(([t,e])=>[t,""+e]),O(([e,r])=>t.setAttributeNS(null,e,r))),O(()=>s.removeItem(e-1),M(3)),t},mergeTranslateTransform:N,updateMatrixTransform:(t,{matrix:e}={})=>z(t)?(e&&t.setMatrix(e),t):t,updateRotateTransform:A,updateScaleTransform:(t,{sx:e=t.matrix.a,sy:r=t.matrix.d}={})=>X(t)?(t.setScale(e,r),t):t,updateTranslateTransform:j};window.$$=q}]); |
{ | ||
"name": "fxsvg", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Functional SVG Handling Library", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -11,5 +11,5 @@ import { $$appendRotateTransform } from "../appendRotateTransform/appendRotateTransform.index.js"; | ||
$el, | ||
{ angle = 0, cx = 0, cy = 0 } = {} | ||
{ angle = 0, cx = 0, cy = 0, index = 0 } = {} | ||
) => { | ||
const transform = $$initRotateTransform($svg)($el, { angle, cx, cy }); | ||
const transform = $$initRotateTransform($svg)($el, { angle, cx, cy, index }); | ||
@@ -26,3 +26,3 @@ const controller = {}; | ||
controller.end = () => { | ||
$$mergeRotateTransform($svg)($el); | ||
$$mergeRotateTransform($svg)($el, { index: index + 1 }); | ||
$$consolidateTransformList($$getBaseTransformList($el)); | ||
@@ -29,0 +29,0 @@ return $el; |
@@ -11,5 +11,5 @@ import { $$appendTranslateTransform } from "../appendTranslateTransform/appendTranslateTransform.index.js"; | ||
$el, | ||
{ tx = 0, ty = 0, x_name, y_name } = {} | ||
{ index = 0, tx = 0, ty = 0, x_name, y_name } = {} | ||
) => { | ||
const transform = $$initTranslateTransform($svg)($el, { tx, ty }); | ||
const transform = $$initTranslateTransform($svg)($el, { tx, ty, index }); | ||
@@ -27,3 +27,3 @@ const controller = {}; | ||
if (x_name && y_name) { | ||
$$mergeTranslateTransform($svg)($el, { x_name, y_name }); | ||
$$mergeTranslateTransform($svg)($el, { index, x_name, y_name }); | ||
} | ||
@@ -30,0 +30,0 @@ $$consolidateTransformList($$getBaseTransformList($el)); |
@@ -80,4 +80,5 @@ import { expect } from "chai"; | ||
`, function () { | ||
this.slow(100); | ||
each(({ matrix, values }) => expectSameMatrix(matrix, values), makeCases()); | ||
}); | ||
}); |
@@ -29,3 +29,6 @@ import { $$appendRotateTransform } from "./appendRotateTransform/appendRotateTransform.index.js"; | ||
import { $$isTranslateSVGTransform } from "./isTranslateSVGTransform/isTranslateSVGTransform.index.js"; | ||
import { $$isValidFxScaleSVGTransformList } from "./isValidFxScaleSVGTransformList/isValidFxScaleSVGTransformList.index.js"; | ||
import { $$mergeRotateTransform } from "./mergeRotateTransform/mergeRotateTransform.index.js"; | ||
import { $$mergeScaleTransform } from "./mergeScaleTransform/mergeScaleTransform.index.js"; | ||
import { $$mergeScaleTransform2 } from "./mergeScaleTransform2/mergeScaleTransform2.index.js"; | ||
import { $$mergeTranslateTransform } from "./mergeTranslateTransform/mergeTranslateTransform.index.js"; | ||
@@ -67,3 +70,6 @@ import { $$updateMatrixTransform } from "./updateMatrixTransform/updateMatrixTransform.index.js"; | ||
isTranslateSVGTransform: $$isTranslateSVGTransform, | ||
isValidFxScaleSVGTransformList: $$isValidFxScaleSVGTransformList, | ||
mergeRotateTransform: $$mergeRotateTransform, | ||
mergeScaleTransform: $$mergeScaleTransform, | ||
mergeScaleTransform2: $$mergeScaleTransform2, | ||
mergeTranslateTransform: $$mergeTranslateTransform, | ||
@@ -70,0 +76,0 @@ updateMatrixTransform: $$updateMatrixTransform, |
@@ -29,3 +29,6 @@ export { $$appendRotateTransform } from "./appendRotateTransform/appendRotateTransform.index.js"; | ||
export { $$isTranslateSVGTransform } from "./isTranslateSVGTransform/isTranslateSVGTransform.index.js"; | ||
export { $$isValidFxScaleSVGTransformList } from "./isValidFxScaleSVGTransformList/isValidFxScaleSVGTransformList.index.js"; | ||
export { $$mergeRotateTransform } from "./mergeRotateTransform/mergeRotateTransform.index.js"; | ||
export { $$mergeScaleTransform } from "./mergeScaleTransform/mergeScaleTransform.index.js"; | ||
export { $$mergeScaleTransform2 } from "./mergeScaleTransform2/mergeScaleTransform2.index.js"; | ||
export { $$mergeTranslateTransform } from "./mergeTranslateTransform/mergeTranslateTransform.index.js"; | ||
@@ -32,0 +35,0 @@ export { $$updateMatrixTransform } from "./updateMatrixTransform/updateMatrixTransform.index.js"; |
@@ -155,2 +155,3 @@ import { expect } from "chai"; | ||
it(`If the second argument is omitted, use default values ({ angle: 0, cx: 0, cy: 0, index: 0 }).`, function () { | ||
this.slow(200); | ||
go( | ||
@@ -157,0 +158,0 @@ ["angle", "cx", "cy", "index"], |
@@ -1,2 +0,2 @@ | ||
import { each, mapL, rangeL } from "fxjs2"; | ||
import { each, go, mapL, rangeL } from "fxjs2"; | ||
import { $$createSVGTransformRotate } from "../createSVGTransformRotate/createSVGTransformRotate.index.js"; | ||
@@ -8,40 +8,46 @@ import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js"; | ||
export const $$mergeRotateTransform = ($svg = $$getSVG()) => ($el) => { | ||
const base_tl = $$getBaseTransformList($el); | ||
if (base_tl.numberOfItems < 3) { | ||
return $el; | ||
const $$isValidFxRotateSVGTransformList = (transform_list, { index }) => { | ||
if (index > transform_list.numberOfItems - 2) { | ||
return false; | ||
} | ||
const [transform1, transform2, transform3] = mapL( | ||
(i) => base_tl.getItem(i), | ||
rangeL(3) | ||
return go( | ||
rangeL(3), | ||
mapL((i) => index - 1 + i), | ||
mapL((i) => transform_list.getItem(i)), | ||
([t1, t2, t3]) => | ||
$$isTranslateSVGTransform(t1) && | ||
$$isRotateSVGTransform(t2) && | ||
$$isTranslateSVGTransform(t3) && | ||
t2.matrix.e === 0 && | ||
t2.matrix.f === 0 && | ||
t1.matrix.a === 1 && | ||
t1.matrix.b === 0 && | ||
t1.matrix.c === 0 && | ||
t1.matrix.d === 1 && | ||
t3.matrix.a === 1 && | ||
t3.matrix.b === 0 && | ||
t3.matrix.c === 0 && | ||
t3.matrix.d === 1 && | ||
t1.matrix.e + t3.matrix.e === 0 && | ||
t1.matrix.f + t3.matrix.f === 0 | ||
); | ||
if ( | ||
!$$isTranslateSVGTransform(transform1) || | ||
!$$isRotateSVGTransform(transform2) || | ||
!$$isTranslateSVGTransform(transform3) || | ||
transform2.matrix.e !== 0 || | ||
transform2.matrix.f !== 0 || | ||
transform1.matrix.a !== 1 || | ||
transform1.matrix.b !== 0 || | ||
transform1.matrix.c !== 0 || | ||
transform1.matrix.d !== 1 || | ||
transform3.matrix.a !== 1 || | ||
transform3.matrix.b !== 0 || | ||
transform3.matrix.c !== 0 || | ||
transform3.matrix.d !== 1 || | ||
transform1.matrix.e + transform3.matrix.e !== 0 || | ||
transform1.matrix.f + transform3.matrix.f !== 0 | ||
) { | ||
}; | ||
export const $$mergeRotateTransform = ($svg = $$getSVG()) => ( | ||
$el, | ||
{ index = 1 } = {} | ||
) => { | ||
const base_tl = $$getBaseTransformList($el); | ||
if (!$$isValidFxRotateSVGTransformList(base_tl, { index })) { | ||
return $el; | ||
} | ||
each(() => base_tl.removeItem(0), rangeL(3)); | ||
const { angle } = base_tl.getItem(index); | ||
const { e: cx, f: cy } = base_tl.getItem(index - 1).matrix; | ||
each(() => base_tl.removeItem(index - 1), rangeL(3)); | ||
base_tl.insertItemBefore( | ||
$$createSVGTransformRotate($svg)({ | ||
angle: transform2.angle, | ||
cx: transform1.matrix.e, | ||
cy: transform1.matrix.f, | ||
}), | ||
0 | ||
$$createSVGTransformRotate($svg)({ angle, cx, cy }), | ||
index - 1 | ||
); | ||
@@ -48,0 +54,0 @@ |
import { expect } from "chai"; | ||
import { go, go1, join, mapL, rangeL, reduce } from "fxjs2"; | ||
import { deepCopyTransformListToMatrixList } from "../../test/utils/deepCopyTransformListToMatrixList.js"; | ||
import { makeRandomNumber } from "../../test/utils/makeRandomNumber.js"; | ||
import { makeRandomSVGMatrix } from "../../test/utils/makeRandomSVGMatrix.js"; | ||
import { makeRandomTransformAttributeValue } from "../../test/utils/makeRandomTransformAttributeValue.js"; | ||
import { makeRandomTransformString } from "../../test/utils/makeRandomTransformString.js"; | ||
import { appendL, each, go, mapL, object, rangeL, reduce } from "fxjs2"; | ||
import { expectSameValueSVGMatrix } from "../../test/assertions/index.js"; | ||
import { | ||
deepCopyTransformListToMatrixList, | ||
makeAllCombinations, | ||
makeRandomInt, | ||
makeRandomNumber, | ||
makeRandomSVGMatrix, | ||
makeRandomTransformAttributeValue, | ||
} from "../../test/utils/index.js"; | ||
import { $$appendTranslateTransform } from "../appendTranslateTransform/appendTranslateTransform.index.js"; | ||
@@ -19,7 +23,19 @@ import { $$createSVGTransformMatrix } from "../createSVGTransformMatrix/createSVGTransformMatrix.index.js"; | ||
const expectSameElementAndSameTransformListAfterMerge = ($el) => { | ||
const createMockEl = ({ transform_attr = "" } = {}) => | ||
$$el()(` | ||
<rect | ||
x="${makeRandomNumber()}" | ||
y="${makeRandomNumber()}" | ||
width="${makeRandomNumber(1)}" | ||
height="${makeRandomNumber(1)}" | ||
${transform_attr ? `transform="${transform_attr}"` : ""} | ||
> | ||
</rect> | ||
`); | ||
const expectSameElementAndSameTransformListAfterMerge = ($el, config) => { | ||
const before_list = deepCopyTransformListToMatrixList( | ||
$$getBaseTransformList($el) | ||
); | ||
const result = $$mergeRotateTransform()($el); | ||
const result = $$mergeRotateTransform()($el, config); | ||
const after_list = deepCopyTransformListToMatrixList( | ||
@@ -33,161 +49,138 @@ $$getBaseTransformList($el) | ||
describe(`$$mergeRotateTransform`, function () { | ||
let $el; | ||
beforeEach(function () { | ||
$el = $$el()(` | ||
<rect | ||
x="${makeRandomNumber()}" | ||
y="${makeRandomNumber()}" | ||
width="${makeRandomNumber(1)}" | ||
height="${makeRandomNumber(1)}" | ||
${go1(makeRandomTransformAttributeValue(3), (t) => | ||
t ? `transform="${t}"` : "" | ||
)} | ||
> | ||
</rect> | ||
`); | ||
}); | ||
describe(` | ||
If the first three SVGTransforms are not matched with the given conditions, | ||
the function do nothing but return the element. | ||
If the input values are invalid, the function do nothing but return the element. | ||
`, function () { | ||
describe(`The element have SVGTransforms less than 3.`, function () { | ||
beforeEach(function () { | ||
$el.removeAttributeNS(null, "transform"); | ||
}); | ||
let $el; | ||
let index; | ||
it("Have no SVGTransform.", function () { | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
}); | ||
beforeEach(function () { | ||
const transform_attr = makeRandomTransformAttributeValue(3); | ||
$el = createMockEl({ transform_attr }); | ||
index = makeRandomInt(1, $$getBaseTransformList($el).numberOfItems - 1); | ||
}); | ||
it("Have 1 SVGTransform.", function () { | ||
$el.setAttributeNS(null, "transform", makeRandomTransformString()); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
}); | ||
it("Have 2 SVGTransforms.", function () { | ||
$el.setAttributeNS( | ||
null, | ||
"transform", | ||
it("The element has no transform.", function () { | ||
go( | ||
["index"], | ||
makeAllCombinations, | ||
mapL((ks) => [createMockEl(), ks]), | ||
mapL(([$el, ks]) => | ||
go( | ||
rangeL(2), | ||
mapL(() => makeRandomTransformString()), | ||
join(" ") | ||
ks, | ||
mapL((k) => [k, makeRandomInt()]), | ||
object, | ||
(config) => [$el, config] | ||
) | ||
); | ||
), | ||
appendL([createMockEl()]), | ||
each(([$el, config]) => | ||
expectSameElementAndSameTransformListAfterMerge($el, config) | ||
) | ||
); | ||
}); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
it(`The input index is out of bounds to the element's SVGTransformList.`, function () { | ||
const $el = createMockEl({ | ||
transform_attr: makeRandomTransformAttributeValue(), | ||
}); | ||
const index = makeRandomInt( | ||
$$getBaseTransformList($el).numberOfItems - 1 | ||
); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
describe(`The first SVGTransform should be a translate SVGTransform.`, function () { | ||
describe(`The SVGTransform at index - 1 should be a translate SVGTransform.`, function () { | ||
it(`Use a matrix SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformMatrix()({ matrix: makeRandomSVGMatrix() }), | ||
0 | ||
); | ||
const matrix = makeRandomSVGMatrix(); | ||
const t = $$createSVGTransformMatrix()({ matrix }); | ||
$$getBaseTransformList($el).insertItemBefore(t, index - 1); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`Use a rotate SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformRotate()({ | ||
angle: makeRandomNumber(), | ||
cx: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
}), | ||
0 | ||
); | ||
const t = $$createSVGTransformRotate()({ | ||
angle: makeRandomNumber(), | ||
cx: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
}); | ||
$$getBaseTransformList($el).insertItemBefore(t, index - 1); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`Use a scale SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformScale()({ | ||
sx: makeRandomNumber(), | ||
sy: makeRandomNumber(), | ||
}), | ||
0 | ||
); | ||
const t = $$createSVGTransformScale()({ | ||
sx: makeRandomNumber(), | ||
sy: makeRandomNumber(), | ||
}); | ||
$$getBaseTransformList($el).insertItemBefore(t, index - 1); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
}); | ||
describe(`The second SVGTransform should be a rotate SVGTransform.`, function () { | ||
describe(`The SVGTransform at index should be a rotate SVGTransform.`, function () { | ||
it(`Use a matrix SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformMatrix()({ matrix: makeRandomSVGMatrix() }), | ||
0 | ||
); | ||
const matrix = makeRandomSVGMatrix(); | ||
const t = $$createSVGTransformMatrix()({ matrix }); | ||
$$getBaseTransformList($el).insertItemBefore(t, index); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`Use a translate SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformTranslate()({ | ||
tx: makeRandomNumber(), | ||
ty: makeRandomNumber(), | ||
}), | ||
0 | ||
); | ||
const t = $$createSVGTransformTranslate()({ | ||
tx: makeRandomNumber(), | ||
ty: makeRandomNumber(), | ||
}); | ||
$$getBaseTransformList($el).insertItemBefore(t, index); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`Use a scale SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformScale()({ | ||
sx: makeRandomNumber(), | ||
sy: makeRandomNumber(), | ||
}), | ||
0 | ||
); | ||
const t = $$createSVGTransformScale()({ | ||
sx: makeRandomNumber(), | ||
sy: makeRandomNumber(), | ||
}); | ||
$$getBaseTransformList($el).insertItemBefore(t, index); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
}); | ||
describe(`The third SVGTransform should be a translate SVGTransform.`, function () { | ||
describe(`The SVGTransform at index + 1 should be a translate SVGTransform.`, function () { | ||
it(`Use a matrix SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformMatrix()({ matrix: makeRandomSVGMatrix() }), | ||
0 | ||
); | ||
const matrix = makeRandomSVGMatrix(); | ||
const t = $$createSVGTransformMatrix()({ matrix }); | ||
$$getBaseTransformList($el).insertItemBefore(t, index + 1); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`Use a rotate SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformRotate()({ | ||
angle: makeRandomNumber(), | ||
cx: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
}), | ||
0 | ||
); | ||
const t = $$createSVGTransformRotate()({ | ||
angle: makeRandomNumber(), | ||
cx: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
}); | ||
$$getBaseTransformList($el).insertItemBefore(t, index + 1); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`Use a scale SVGTransform.`, function () { | ||
$$getBaseTransformList($el).insertItemBefore( | ||
$$createSVGTransformScale()({ | ||
sx: makeRandomNumber(), | ||
sy: makeRandomNumber(), | ||
}), | ||
0 | ||
); | ||
const t = $$createSVGTransformScale()({ | ||
sx: makeRandomNumber(), | ||
sy: makeRandomNumber(), | ||
}); | ||
$$getBaseTransformList($el).insertItemBefore(t, index + 1); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
}); | ||
it(`The cx, cy of the second SVGTransform should be 0.`, function () { | ||
it(`The cx, cy of the SVGTransform at index should be 0.`, function () { | ||
$$initRotateTransform()($el, { | ||
@@ -197,10 +190,11 @@ angle: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
index: index - 1, | ||
}); | ||
const t = $$getBaseTransformList($el).getItem(1); | ||
const t = $$getBaseTransformList($el).getItem(index); | ||
t.setRotate(t.angle, makeRandomNumber(1), makeRandomNumber(1)); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`The sum of the first SVGTransform's e and the third SVGTransform's e should be 0.`, function () { | ||
it(`(SVGTransform at index - 1).e + (SVGTransform at index + 1).e should be 0.`, function () { | ||
$$initRotateTransform()($el, { | ||
@@ -210,11 +204,13 @@ angle: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
index: index - 1, | ||
}); | ||
$$appendTranslateTransform($$getBaseTransformList($el).getItem(0), { | ||
tx: 1, | ||
}); | ||
$$appendTranslateTransform( | ||
$$getBaseTransformList($el).getItem(index - 1), | ||
{ tx: 1 } | ||
); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
it(`The sum of the first SVGTransform's f and the third SVGTransform's f should be 0.`, function () { | ||
it(`(SVGTransform at index - 1).f + (SVGTransform at index + 1).f should be 0.`, function () { | ||
$$initRotateTransform()($el, { | ||
@@ -224,13 +220,22 @@ angle: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
index: index - 1, | ||
}); | ||
$$appendTranslateTransform($$getBaseTransformList($el).getItem(0), { | ||
ty: 1, | ||
}); | ||
$$appendTranslateTransform( | ||
$$getBaseTransformList($el).getItem(index - 1), | ||
{ ty: 1 } | ||
); | ||
expectSameElementAndSameTransformListAfterMerge($el); | ||
expectSameElementAndSameTransformListAfterMerge($el, { index }); | ||
}); | ||
}); | ||
describe(`The element has valid SVGTransformList for the function. (Use $$initRotateTransform)`, function () { | ||
describe(`The input values are valid for the function. (Use $$initRotateTransform)`, function () { | ||
let $el; | ||
let index; | ||
beforeEach(function () { | ||
const transform_attr = makeRandomTransformAttributeValue(3); | ||
$el = createMockEl({ transform_attr }); | ||
index = makeRandomInt(1, $$getBaseTransformList($el).numberOfItems - 1); | ||
$$initRotateTransform()($el, { | ||
@@ -240,2 +245,3 @@ angle: makeRandomNumber(), | ||
cy: makeRandomNumber(), | ||
index: index - 1, | ||
}); | ||
@@ -247,3 +253,3 @@ }); | ||
$$mergeRotateTransform()($el); | ||
$$mergeRotateTransform()($el, { index }); | ||
@@ -255,16 +261,20 @@ const { numberOfItems: after_n } = $$getBaseTransformList($el); | ||
describe(`The first SVGTransform after merged should satisfy following conditions.`, function () { | ||
describe(`The SVGTransform at index - 1 after merged should satisfy following conditions.`, function () { | ||
it(`It is a rotate SVGTransform.`, function () { | ||
$$mergeRotateTransform()($el); | ||
$$mergeRotateTransform()($el, { index }); | ||
const t = $$getBaseTransformList($el).getItem(0); | ||
const t = $$getBaseTransformList($el).getItem(index - 1); | ||
expect($$isRotateSVGTransform(t)).to.be.true; | ||
}); | ||
it(`It's angle is same with the angle of the second SVGTransform before merged.`, function () { | ||
const { angle: before_angle } = $$getBaseTransformList($el).getItem(1); | ||
it(`It's angle is same with the angle of the SVGTransform at index before merged.`, function () { | ||
const { angle: before_angle } = $$getBaseTransformList($el).getItem( | ||
index | ||
); | ||
$$mergeRotateTransform()($el); | ||
$$mergeRotateTransform()($el, { index }); | ||
const { angle: after_angle } = $$getBaseTransformList($el).getItem(0); | ||
const { angle: after_angle } = $$getBaseTransformList($el).getItem( | ||
index - 1 | ||
); | ||
@@ -278,2 +288,3 @@ expect(after_angle).to.equal(before_angle); | ||
rangeL(3), | ||
mapL((i) => index + i - 1), | ||
mapL((i) => list.getItem(i)), | ||
@@ -284,5 +295,8 @@ mapL(({ matrix: m }) => m), | ||
$$mergeRotateTransform()($el); | ||
$$mergeRotateTransform()($el, { index }); | ||
expect($$getBaseTransformList($el).getItem(0).matrix).to.deep.equal(m); | ||
expectSameValueSVGMatrix( | ||
$$getBaseTransformList($el).getItem(index - 1).matrix, | ||
m | ||
); | ||
}); | ||
@@ -289,0 +303,0 @@ }); |
@@ -9,15 +9,15 @@ import { each, go, mapL, rangeL } from "fxjs2"; | ||
$el, | ||
{ x_name = "x", y_name = "y" } = {} | ||
{ index = 0, x_name = "x", y_name = "y" } = {} | ||
) => { | ||
const base_tl = $$getBaseTransformList($el); | ||
if (base_tl.numberOfItems < 1) { | ||
if (index > base_tl.numberOfItems - 1) { | ||
return $el; | ||
} | ||
const last_transform = base_tl.getItem(0); | ||
if (!$$isTranslateSVGTransform(last_transform)) { | ||
const transform = base_tl.getItem(index); | ||
if (!$$isTranslateSVGTransform(transform)) { | ||
return $el; | ||
} | ||
const { e: tx, f: ty } = last_transform.matrix; | ||
const { e: tx, f: ty } = transform.matrix; | ||
@@ -36,3 +36,3 @@ go( | ||
base_tl.removeItem(0); | ||
base_tl.removeItem(index); | ||
@@ -39,0 +39,0 @@ go( |
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
223554
117
4403