From 5b7a61583bfc1d6faf4ec13c056c0670e3a3c4fb Mon Sep 17 00:00:00 2001 From: David Werth Date: Tue, 17 Mar 2020 08:29:08 +0100 Subject: [PATCH] #13 updated dependencies, migrated to svg.js 3 --- docs/kjua.min.js | 4 +- package-lock.json | 3551 +++++++++++++++++++++++++++++-------------- package.json | 16 +- src/lib/draw_svg.js | 20 +- 4 files changed, 2462 insertions(+), 1129 deletions(-) diff --git a/docs/kjua.min.js b/docs/kjua.min.js index 400fe07..69e5b06 100644 --- a/docs/kjua.min.js +++ b/docs/kjua.min.js @@ -1,2 +1,2 @@ -/*! kjua v1.9.1 - https://github.com/werthdavid/kjua */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("kjua",[],e):"object"==typeof exports?exports.kjua=e():t.kjua=e()}("undefined"!=typeof self?self:this,function(){return function(n){var i={};function r(t){if(i[t])return i[t].exports;var e=i[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,r),e.l=!0,e.exports}return r.m=n,r.c=i,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(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));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=0)}([function(t,e,n){var o=n(1),a=n(2),i=n(4),h=i.draw,u=i.draw_modules,l=n(9),r=n(7),c=r.create_canvas,f=r.calc_image_pos;t.exports=function(t){var e=Object.assign({},o,t),n=a(e.text,e.ecLevel,e.minVersion,e.quiet,e);if("image"===e.mode&&e.image){if("string"==typeof e.image){var i=new Image;i.src="data:image/png;base64,"+e.image,e.image=i}if(e.imageAsCode){var r=c(e);u(n,r,e),r.globalCompositeOperation="source-in";var s=f(e);r.drawImage(e.image,s.x,s.y,s.iw,s.ih),e=Object.assign({},e,{image:r.canvas})}}return"svg"===e.render?l(n,e):h(n,e)}},function(t,e){t.exports={render:"svg",crisp:!0,minVersion:1,ecLevel:"L",size:200,ratio:null,fill:"#333",back:"#fff",text:"",rounded:0,quiet:0,mode:"plain",mSize:30,mPosX:50,mPosY:50,label:"no label",fontname:"sans",fontcolor:"#333",fontoutline:!0,image:null,imageAsCode:!1}},function(t,e,n){function l(t){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var c=/code length overflow/i,f=n(3);f.stringToBytes=f.stringToBytesFuncs["UTF-8"];t.exports=function(){var t=0>n&1);l[Math.floor(n/3)][n%3+c-8-3]=i}for(n=0;n<18;n+=1){i=!t&&1==(e>>n&1);l[n%3+c-8-3][Math.floor(n/3)]=i}},p=function(t,e){for(var n=h<<3|e,i=y.getBCHTypeInfo(n),r=0;r<15;r+=1){var s=!t&&1==(i>>r&1);r<6?l[r][8]=s:r<8?l[r+1][8]=s:l[c-15+r][8]=s}for(r=0;r<15;r+=1){s=!t&&1==(i>>r&1);r<8?l[8][c-r-1]=s:r<9?l[8][15-r-1+1]=s:l[8][15-r-1]=s}l[c-8][8]=!t},g=function(t,e){for(var n=-1,i=c-1,r=7,s=0,o=y.getMaskFunction(e),a=c-1;0>>r&1)),o(i,a-h)&&(u=!u),l[i][a-h]=u,-1==(r-=1)&&(s+=1,r=7)}if((i+=n)<0||c<=i){i-=n,n=-n;break}}},m=function(t,e,n){for(var i=C.getRSBlocks(t,e),r=k(),s=0;s8*a)throw"code length overflow. ("+r.getLengthInBits()+">"+8*a+")";for(r.getLengthInBits()+4<=8*a&&r.put(0,4);r.getLengthInBits()%8!=0;)r.putBit(!1);for(;!(r.getLengthInBits()>=8*a||(r.put(236,8),r.getLengthInBits()>=8*a));)r.put(17,8);return function(t,e){for(var n=0,i=0,r=0,s=new Array(e.length),o=new Array(e.length),a=0;a',n+="";for(var i=0;i";for(var r=0;r';n+=""}return n+="",n+=""},d.createSvgTag=function(t,e){var n={};"object"==typeof t&&(t=(n=t).cellSize,e=n.margin),t=t||2,e=void 0===e?4*t:e;var i,r,s,o,a=d.getModuleCount()*t+2*e,h="";for(o="l"+t+",0 0,"+t+" -"+t+",0 0,-"+t+"z ",h+='>>8),e.push(255&r)):e.push(o)}}return e}};var o=1,a=2,r=4,h=8,v={L:1,M:0,Q:3,H:2},i=0,u=1,l=2,c=3,f=4,d=5,p=6,g=7,y=function(){function n(t){for(var e=0;0!=t;)e+=1,t>>>=1;return e}var e=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],t={};return t.getBCHTypeInfo=function(t){for(var e=t<<10;0<=n(e)-n(1335);)e^=1335<>>8)},writeBytes:function(t,e,n){e=e||0,n=n||t.length;for(var i=0;i>>7-t%8&1)},put:function(t,e){for(var n=0;n>>e-n-1&1))},getLengthInBits:function(){return i},putBit:function(t){var e=Math.floor(i/8);n.length<=e&&n.push(0),t&&(n[e]|=128>>>i%8),i+=1}};return r},A=function(t){var e=o,i=t,n={getMode:function(){return e},getLength:function(t){return i.length},write:function(t){for(var e=i,n=0;n+2>>8&255)+(255&i),t.put(i,13),n+=2}if(n=n.length){if(0==s)return-1;throw"unexpected end of file./"+s}var t=n.charAt(i);if(i+=1,"="==t)return s=0,-1;t.match(/^\s$/)||(r=r<<6|o(t.charCodeAt(0)),s+=6)}var e=r>>>s-8&255;return s-=8,e}},o=function(t){if(65<=t&&t<=90)return t-65;if(97<=t&&t<=122)return t-97+26;if(48<=t&&t<=57)return t-48+52;if(43==t)return 62;if(47==t)return 63;throw"c:"+t};return e},B=function(t,e,n){for(var i=function(t,e){var i=t,r=e,c=new Array(t*e),n={setPixel:function(t,e,n){c[e*i+t]=n},write:function(t){t.writeString("GIF87a"),t.writeShort(i),t.writeShort(r),t.writeByte(128),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(0),t.writeByte(255),t.writeByte(255),t.writeByte(255),t.writeString(","),t.writeShort(0),t.writeShort(0),t.writeShort(i),t.writeShort(r),t.writeByte(0);var e=s(2);t.writeByte(2);for(var n=0;255>>e!=0)throw"length over";for(;8<=i+e;)n.writeByte(255&(t<>>=8-i,i=r=0;r|=t<>>r-6),r-=6},t.flush=function(){if(0>6,128|63&i):i<55296||57344<=i?e.push(224|i>>12,128|i>>6&63,128|63&i):(n++,i=65536+((1023&i)<<10|1023&t.charCodeAt(n)),e.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|63&i))}return e}(t)},r=[],void 0===(s="function"==typeof(i=function(){return o})?i.apply(e,r):i)||(t.exports=s)},function(t,e,n){function u(t,e,n,i,r,s){t.isDark(r,s)&&e.rect(s*i,r*i,i,i)}function i(t,e,n){if(t){var i=0this.destination.length;)this.destination.push(n);for(;this.value.lengthn.x&&e>n.y&&t/,"").replace(/<\/svg>$/,"");e.innerHTML=""+t.replace(/\n/,"").replace(/<([\w:-]+)([^<]+?)\/>/g,"<$1$2>")+"";for(var n=0,i=e.firstChild.childNodes.length;n":function(t){return-Math.cos(t*Math.PI)/2+.5},">":function(t){return Math.sin(t*Math.PI/2)},"<":function(t){return 1-Math.cos(t*Math.PI/2)}},c.morph=function(n){return function(t,e){return new c.MorphObj(t,e).at(n)}},c.Situation=c.invent({create:function(t){this.init=!1,this.reversed=!1,this.reversing=!1,this.duration=new c.Number(t.duration).valueOf(),this.delay=new c.Number(t.delay).valueOf(),this.start=+new Date+this.delay,this.finish=this.start+this.duration,this.ease=t.ease,this.loop=0,this.loops=!1,this.animations={},this.attrs={},this.styles={},this.transforms=[],this.once={}}}),c.FX=c.invent({create:function(t){this._target=t,this.situations=[],this.active=!1,this.situation=null,this.paused=!1,this.lastPos=0,this.pos=0,this.absPos=0,this._speed=1},extend:{animate:function(t,e,n){"object"==typeof t&&(e=t.ease,n=t.delay,t=t.duration);var i=new c.Situation({duration:t||1e3,delay:n||0,ease:c.easing[e||"-"]||e});return this.queue(i),this},delay:function(t){var e=new c.Situation({duration:t,delay:0,ease:c.easing["-"]});return this.queue(e)},target:function(t){return t&&t instanceof c.Element?(this._target=t,this):this._target},timeToAbsPos:function(t){return(t-this.situation.start)/(this.situation.duration/this._speed)},absPosToTime:function(t){return this.situation.duration/this._speed*t+this.situation.start},startAnimFrame:function(){this.stopAnimFrame(),this.animationFrame=o.requestAnimationFrame(function(){this.step()}.bind(this))},stopAnimFrame:function(){o.cancelAnimationFrame(this.animationFrame)},start:function(){return!this.active&&this.situation&&(this.active=!0,this.startCurrent()),this},startCurrent:function(){return this.situation.start=+new Date+this.situation.delay/this._speed,this.situation.finish=this.situation.start+this.situation.duration/this._speed,this.initAnimations().step()},queue:function(t){return("function"==typeof t||t instanceof c.Situation)&&this.situations.push(t),this.situation||(this.situation=this.situations.shift()),this},dequeue:function(){return this.stop(),this.situation=this.situations.shift(),this.situation&&(this.situation instanceof c.Situation?this.start():this.situation.call(this)),this},initAnimations:function(){var t,e,n,i=this.situation;if(i.init)return this;for(t in i.animations)for(n=this.target()[t](),Array.isArray(n)||(n=[n]),Array.isArray(i.animations[t])||(i.animations[t]=[i.animations[t]]),e=n.length;e--;)i.animations[t][e]instanceof c.Number&&(n[e]=new c.Number(n[e])),i.animations[t][e]=n[e].morph(i.animations[t][e]);for(t in i.attrs)i.attrs[t]=new c.MorphObj(this.target().attr(t),i.attrs[t]);for(t in i.styles)i.styles[t]=new c.MorphObj(this.target().style(t),i.styles[t]);return i.initialTransformation=this.target().matrixify(),i.init=!0,this},clearQueue:function(){return this.situations=[],this},clearCurrent:function(){return this.situation=null,this},stop:function(t,e){var n=this.active;return this.active=!1,e&&this.clearQueue(),t&&this.situation&&(!n&&this.startCurrent(),this.atEnd()),this.stopAnimFrame(),this.clearCurrent()},reset:function(){if(this.situation){var t=this.situation;this.stop(),this.situation=t,this.atStart()}return this},finish:function(){for(this.stop(!0,!1);this.dequeue().situation&&this.stop(!0,!1););return this.clearQueue().clearCurrent(),this},atStart:function(){return this.at(0,!0)},atEnd:function(){return!0===this.situation.loops&&(this.situation.loops=this.situation.loop+1),"number"==typeof this.situation.loops?this.at(this.situation.loops,!0):this.at(1,!0)},at:function(t,e){var n=this.situation.duration/this._speed;return this.absPos=t,e||(this.situation.reversed&&(this.absPos=1-this.absPos),this.absPos+=this.situation.loop),this.situation.start=+new Date-this.absPos*n,this.situation.finish=this.situation.start+n,this.step(!0)},speed:function(t){return 0===t?this.pause():t?(this._speed=t,this.at(this.absPos,!0)):this._speed},loop:function(t,e){var n=this.last();return n.loops=null==t||t,n.loop=0,e&&(n.reversing=!0),this},pause:function(){return this.paused=!0,this.stopAnimFrame(),this},play:function(){return this.paused?(this.paused=!1,this.at(this.absPos,!0)):this},reverse:function(t){var e=this.last();return e.reversed=void 0===t?!e.reversed:t,this},progress:function(t){return t?this.situation.ease(this.pos):this.pos},after:function(n){var i=this.last();return this.target().on("finished.fx",function t(e){e.detail.situation==i&&(n.call(this,i),this.off("finished.fx",t))}),this._callStart()},during:function(e){var n=this.last(),t=function(t){t.detail.situation==n&&e.call(this,t.detail.pos,c.morph(t.detail.pos),t.detail.eased,n)};return this.target().off("during.fx",t).on("during.fx",t),this.after(function(){this.off("during.fx",t)}),this._callStart()},afterAll:function(n){var t=function t(e){n.call(this),this.off("allfinished.fx",t)};return this.target().off("allfinished.fx",t).on("allfinished.fx",t),this._callStart()},duringAll:function(e){var t=function(t){e.call(this,t.detail.pos,c.morph(t.detail.pos),t.detail.eased,t.detail.situation)};return this.target().off("during.fx",t).on("during.fx",t),this.afterAll(function(){this.off("during.fx",t)}),this._callStart()},last:function(){return this.situations.length?this.situations[this.situations.length-1]:this.situation},add:function(t,e,n){return this.last()[n||"animations"][t]=e,this._callStart()},step:function(t){var e,n,i;t||(this.absPos=this.timeToAbsPos(+new Date)),!1!==this.situation.loops?(e=Math.max(this.absPos,0),n=Math.floor(e),!0===this.situation.loops||nthis.lastPos&&s<=r&&(this.situation.once[s].call(this.target(),this.pos,r),delete this.situation.once[s]);return this.active&&this.target().fire("during",{pos:this.pos,eased:r,fx:this,situation:this.situation}),this.situation&&(this.eachAt(),1==this.pos&&!this.situation.reversed||this.situation.reversed&&0==this.pos?(this.stopAnimFrame(),this.target().fire("finished",{fx:this,situation:this.situation}),this.situations.length||(this.target().fire("allfinished"),this.situations.length||(this.target().off(".fx"),this.active=!1)),this.active?this.dequeue():this.clearCurrent()):!this.paused&&this.active&&this.startAnimFrame(),this.lastPos=r),this},eachAt:function(){var t,e,n,i=this,r=this.target(),s=this.situation;for(t in s.animations)n=[].concat(s.animations[t]).map(function(t){return"string"!=typeof t&&t.at?t.at(s.ease(i.pos),i.pos):t}),r[t].apply(r,n);for(t in s.attrs)n=[t].concat(s.attrs[t]).map(function(t){return"string"!=typeof t&&t.at?t.at(s.ease(i.pos),i.pos):t}),r.attr.apply(r,n);for(t in s.styles)n=[t].concat(s.styles[t]).map(function(t){return"string"!=typeof t&&t.at?t.at(s.ease(i.pos),i.pos):t}),r.style.apply(r,n);if(s.transforms.length){for(n=s.initialTransformation,t=0,e=s.transforms.length;ti/r?this.height/r:this.width/i,this.x=e,this.y=n,this.width=i,this.height=r)}else t="string"==typeof t?t.match(l).map(function(t){return parseFloat(t)}):Array.isArray(t)?t:"object"==typeof t?[t.x,t.y,t.width,t.height]:4==arguments.length?[].slice.call(arguments):[0,0,0,0],this.x=t[0],this.y=t[1],this.width=t[2],this.height=t[3]},extend:{toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height},morph:function(t,e,n,i){return this.destination=new c.ViewBox(t,e,n,i),this},at:function(t){return this.destination?new c.ViewBox([this.x+(this.destination.x-this.x)*t,this.y+(this.destination.y-this.y)*t,this.width+(this.destination.width-this.width)*t,this.height+(this.destination.height-this.height)*t]):this}},parent:c.Container,construct:{viewbox:function(t,e,n,i){return 0==arguments.length?new c.ViewBox(this):this.attr("viewBox",new c.ViewBox(t,e,n,i))}}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchmove","touchleave","touchend","touchcancel"].forEach(function(e){c.Element.prototype[e]=function(t){return null==t?c.off(this,e):c.on(this,e,t),this}}),c.listenerId=0,c.on=function(t,e,i,n,r){var s=i.bind(n||t),o=t instanceof c.Element?t.node:t;o.instance=o.instance||{_events:{}};var a=o.instance._events;i._svgjsListenerId||(i._svgjsListenerId=++c.listenerId),e.split(c.regex.delimiter).forEach(function(t){var e=t.split(".")[0],n=t.split(".")[1]||"*";a[e]=a[e]||{},a[e][n]=a[e][n]||{},a[e][n][i._svgjsListenerId]=s,o.addEventListener(e,s,r||!1)})},c.off=function(t,e,s,o){var a=t instanceof c.Element?t.node:t;if(a.instance&&("function"!=typeof s||(s=s._svgjsListenerId))){var h=a.instance._events;(e||"").split(c.regex.delimiter).forEach(function(t){var e,n,i=t&&t.split(".")[0],r=t&&t.split(".")[1];if(s)h[i]&&h[i][r||"*"]&&(a.removeEventListener(i,h[i][r||"*"][s],o||!1),delete h[i][r||"*"][s]);else if(i&&r){if(h[i]&&h[i][r]){for(n in h[i][r])c.off(a,[i,r].join("."),n);delete h[i][r]}}else if(r)for(t in h)for(e in h[t])r===e&&c.off(a,[t,r].join("."));else if(i){if(h[i]){for(e in h[i])c.off(a,[i,e].join("."));delete h[i]}}else{for(t in h)c.off(a,t);a.instance._events={}}})}},c.extend(c.Element,{on:function(t,e,n,i){return c.on(this,t,e,n,i),this},off:function(t,e){return c.off(this.node,t,e),this},fire:function(t,e){return t instanceof o.Event?this.node.dispatchEvent(t):this.node.dispatchEvent(t=new c.CustomEvent(t,{detail:e,cancelable:!0})),this._event=t,this},event:function(){return this._event}}),c.Defs=c.invent({create:"defs",inherit:c.Container}),c.G=c.invent({create:"g",inherit:c.Container,extend:{x:function(t){return null==t?this.transform("x"):this.transform({x:t-this.x()},!0)},y:function(t){return null==t?this.transform("y"):this.transform({y:t-this.y()},!0)},cx:function(t){return null==t?this.gbox().cx:this.x(t-this.gbox().width/2)},cy:function(t){return null==t?this.gbox().cy:this.y(t-this.gbox().height/2)},gbox:function(){var t=this.bbox(),e=this.transform();return t.x+=e.x,t.x2+=e.x,t.cx+=e.x,t.y+=e.y,t.y2+=e.y,t.cy+=e.y,t}},construct:{group:function(){return this.put(new c.G)}}}),c.Doc=c.invent({create:function(t){t&&("svg"==(t="string"==typeof t?r.getElementById(t):t).nodeName?this.constructor.call(this,t):(this.constructor.call(this,c.create("svg")),t.appendChild(this.node),this.size("100%","100%")),this.namespace().defs())},inherit:c.Container,extend:{namespace:function(){return this.attr({xmlns:c.ns,version:"1.1"}).attr("xmlns:xlink",c.xlink,c.xmlns).attr("xmlns:svgjs",c.svgjs,c.xmlns)},defs:function(){var t;return this._defs||((t=this.node.getElementsByTagName("defs")[0])?this._defs=c.adopt(t):this._defs=new c.Defs,this.node.appendChild(this._defs.node)),this._defs},parent:function(){return this.node.parentNode&&"#document"!=this.node.parentNode.nodeName&&"#document-fragment"!=this.node.parentNode.nodeName?this.node.parentNode:null},spof:function(){var t=this.node.getScreenCTM();return t&&this.style("left",-t.e%1+"px").style("top",-t.f%1+"px"),this},remove:function(){return this.parent()&&this.parent().removeChild(this.node),this},clear:function(){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return delete this._defs,c.parser.draw.parentNode||this.node.appendChild(c.parser.draw),this},clone:function(t){this.writeDataToDom();var e=this.node,n=m(e.cloneNode(!0));return t?(t.node||t).appendChild(n.node):e.parentNode.insertBefore(n.node,e.nextSibling),n}}}),c.extend(c.Element,{siblings:function(){return this.parent().children()},position:function(){return this.parent().index(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){var t=this.position()+1,e=this.parent();return e.removeElement(this).add(this,t),e instanceof c.Doc&&e.node.appendChild(e.defs().node),this},backward:function(){var t=this.position();return 0>n&1);l[Math.floor(n/3)][n%3+c-8-3]=r}for(n=0;n<18;n+=1){r=!t&&1==(e>>n&1);l[n%3+c-8-3][Math.floor(n/3)]=r}},v=function(t,e){for(var n=s<<3|e,r=w.getBCHTypeInfo(n),i=0;i<15;i+=1){var o=!t&&1==(r>>i&1);i<6?l[i][8]=o:i<8?l[i+1][8]=o:l[c-15+i][8]=o}for(i=0;i<15;i+=1){o=!t&&1==(r>>i&1);i<8?l[8][c-i-1]=o:i<9?l[8][15-i-1+1]=o:l[8][15-i-1]=o}l[c-8][8]=!t},p=function(t,e){for(var n=-1,r=c-1,i=7,o=0,u=w.getMaskFunction(e),a=c-1;0>>i&1)),u(r,a-s)&&(h=!h),l[r][a-s]=h,-1==--i&&(o+=1,i=7)}if((r+=n)<0||c<=r){r-=n,n=-n;break}}},y=function(t,e,n){for(var r=S.getRSBlocks(t,e),i=A(),o=0;o8*a)throw"code length overflow. ("+i.getLengthInBits()+">"+8*a+")";for(i.getLengthInBits()+4<=8*a&&i.put(0,4);i.getLengthInBits()%8!=0;)i.putBit(!1);for(;!(i.getLengthInBits()>=8*a||(i.put(236,8),i.getLengthInBits()>=8*a));)i.put(17,8);return function(t,e){for(var n=0,r=0,i=0,o=new Array(e.length),u=new Array(e.length),a=0;a',n+="";for(var r=0;r";for(var i=0;i';n+=""}return n+="",n+=""},d.createSvgTag=function(t,e,n,r){var i={};"object"==typeof t&&(t=(i=t).cellSize,e=i.margin,n=i.alt,r=i.title),t=t||2,e=void 0===e?4*t:e,(n="string"==typeof n?{text:n}:n||{}).text=n.text||null,n.id=n.text?n.id||"qrcode-description":null,(r="string"==typeof r?{text:r}:r||{}).text=r.text||null,r.id=r.text?r.id||"qrcode-title":null;var o,u,a,s,h=d.getModuleCount()*t+2*e,l="";for(s="l"+t+",0 0,"+t+" -"+t+",0 0,-"+t+"z ",l+=''+g(r.text)+"":"",l+=n.text?''+g(n.text)+"":"",l+='',l+='":e+=">";break;case"&":e+="&";break;case'"':e+=""";break;default:e+=r}}return e};return d.createASCII=function(t,e){if((t=t||1)<2)return function(t){t=void 0===t?2:t;var e,n,r,i,o,u=+d.getModuleCount()+2*t,a=t,s=u-t,h={"██":"█","█ ":"▀"," █":"▄"," ":" "},l={"██":"▀","█ ":"▀"," █":" "," ":" "},c="";for(e=0;e>>8),e.push(255&i)):e.push(u)}}return e}};var e,t,u=1,a=2,i=4,s=8,m={L:1,M:0,Q:3,H:2},n=0,r=1,h=2,l=3,c=4,f=5,d=6,v=7,w=(e=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],(t={}).getBCHTypeInfo=function(t){for(var e=t<<10;0<=p(e)-p(1335);)e^=1335<>>=1;return e}var y=function(){for(var e=new Array(256),n=new Array(256),t=0;t<8;t+=1)e[t]=1<>>8)},writeBytes:function(t,e,n){e=e||0,n=n||t.length;for(var r=0;r>>i-6),i-=6},t.flush=function(){if(0>>e!=0)throw"length over";for(;8<=a+e;)u.writeByte(255&(t<>>=8-a,a=s=0;s|=t<>>7-t%8&1)},put:function(t,e){for(var n=0;n>>e-n-1&1))},getLengthInBits:function(){return r},putBit:function(t){var e=Math.floor(r/8);n.length<=e&&n.push(0),t&&(n[e]|=128>>>r%8),r+=1}};return i},M=function(t){var e=u,r=t,n={getMode:function(){return e},getLength:function(t){return r.length},write:function(t){for(var e=r,n=0;n+2>>8&255)+(255&r),t.put(r,13),n+=2}if(n=n.length){if(0==o)return-1;throw"unexpected end of file./"+o}var t=n.charAt(r);if(r+=1,"="==t)return o=0,-1;t.match(/^\s$/)||(i=i<<6|u(t.charCodeAt(0)),o+=6)}var e=i>>>o-8&255;return o-=8,e}},u=function(t){if(65<=t&&t<=90)return t-65;if(97<=t&&t<=122)return t-97+26;if(48<=t&&t<=57)return t-48+52;if(43==t)return 62;if(47==t)return 63;throw"c:"+t};return e},P=function(t,e,n){for(var r=_(t,e),i=0;i>6,128|63&r):r<55296||57344<=r?e.push(224|r>>12,128|r>>6&63,128|63&r):(n++,r=65536+((1023&r)<<10|1023&t.charCodeAt(n)),e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r))}return e}(t)},i=[],void 0===(o="function"==typeof(r=function(){return u})?r.apply(e,i):r)||(t.exports=o)},function(t,e,n){function h(t,e,n,r,i,o){t.isDark(i,o)&&e.rect(o*r,i*r,r,r)}function o(t,e,n){if(t){var r=0i;)f(r,n=e[i++])&&(~_t(o,n)||o.push(n));return o}function ut(t,e){for(var n=Mt(e),r=L.f,i=I.f,o=0;odocument.F=Object"),t.close(),ve=t.F;n--;)delete ve[de][kt[n]];return ve()},pe=Object.create||function(t,e){var n;return null!==t?(se[de]=O(t),n=new se,se[de]=null,n[fe]=t):n=ve(),void 0===e?n:le(n,e)};V[fe]=!0;function ye(t){var e=pt.Symbol||(pt.Symbol={});f(e,t)||Me(e,t,{value:Ae.f(t)})}function ge(t,e,n){t&&!f(t=n?t:t.prototype,Ce)&&je(t,Ce,{configurable:!0,value:e})}function me(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t}function we(r,i,t){if(me(r),void 0===i)return r;switch(t){case 0:return function(){return r.call(i)};case 1:return function(t){return r.call(i,t)};case 2:return function(t,e){return r.call(i,t,e)};case 3:return function(t,e,n){return r.call(i,t,e,n)}}return function(){return r.apply(i,arguments)}}function be(t,e){var n;return Lt(t)&&("function"==typeof(n=t.constructor)&&(n===Array||Lt(n.prototype))||g(n)&&null===(n=n[Te]))&&(n=void 0),new(void 0===n?Array:n)(0===e?0:e)}function xe(d){var v=1==d,p=2==d,y=3==d,g=4==d,m=6==d,w=5==d||m;return function(t,e,n,r){for(var i,o,u=ae(t),a=M(u),s=we(e,n,3),h=nt(a.length),l=0,c=r||be,f=v?c(t,h):p?c(t,0):void 0;l=e.length?{value:t.target=void 0,done:!0}:"keys"==n?{value:r,done:!1}:"values"==n?{value:e[r],done:!1}:{value:[r,e[r]],done:!1}},"values");xn.Arguments=xn.Array,gn("keys"),gn("values"),gn("entries");var Xn=Object.assign,Hn=!Xn||y(function(){var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach(function(t){e[t]=t}),7!=Xn({},t)[n]||he(Xn({},e)).join("")!=r})?function(t,e){for(var n=ae(t),r=arguments.length,i=1,o=At.f,u=k.f;i=n.length?{value:void 0,done:!0}:(t=mr(n,r),e.index+=t.length,{value:t,done:!1})});var _r={CSSRuleList:0,CSSStyleDeclaration:0,CSSValueList:0,ClientRectList:0,DOMRectList:0,DOMStringList:0,DOMTokenList:1,DataTransferItemList:0,FileList:0,HTMLAllCollection:0,HTMLCollection:0,HTMLFormElement:0,HTMLSelectElement:0,MediaList:0,MimeTypeArray:0,NamedNodeMap:0,NodeList:1,PaintRequestList:0,Plugin:0,PluginArray:0,SVGLengthList:0,SVGNumberList:0,SVGPathSegList:0,SVGPointList:0,SVGStringList:0,SVGTransformList:0,SourceBufferList:0,StyleSheetList:0,TextTrackCueList:0,TextTrackList:0,TouchList:0},kr=lt("iterator"),Or=lt("toStringTag"),Sr=Yn.values;for(var Ar in _r){var Mr=m[Ar],jr=Mr&&Mr.prototype;if(jr){if(jr[kr]!==Sr)try{N(jr,kr,Sr)}catch(t){jr[kr]=Sr}if(jr[Or]||N(jr,Or,Ar),_r[Ar])for(var Cr in Yn)if(jr[Cr]!==Yn[Cr])try{N(jr,Cr,Yn[Cr])}catch(t){jr[Cr]=Yn[Cr]}}}function Tr(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e")}),ti=!y(function(){var t=/(?:)/,e=t.exec;t.exec=function(){return e.apply(this,arguments)};var n="ab".split(t);return 2!==n.length||"a"!==n[0]||"b"!==n[1]}),ei=gr.charAt,ni=Math.max,ri=Math.min,ii=Math.floor,oi=/\$([$&'`]|\d\d?|<[^>]*>)/g,ui=/\$([$&'`]|\d\d?)/g;Qr("replace",2,function(i,x,_){return[function(t,e){var n=c(this),r=null==t?void 0:t[i];return void 0!==r?r.call(t,n,e):x.call(String(n),t,e)},function(t,e){var n=_(x,t,this,e);if(n.done)return n.value;var r=O(t),i=String(this),o="function"==typeof e;o||(e=String(e));var u=r.global;if(u){var a=r.unicode;r.lastIndex=0}for(var s=[];;){var h=Jr(r,i);if(null===h)break;if(s.push(h),!u)break;""===String(h[0])&&(r.lastIndex=Wr(i,nt(r.lastIndex),a))}for(var l,c="",f=0,d=0;d>>0;if(0==r)return[];if(void 0===t)return[n];if(!Vr(t))return w.call(n,t,r);for(var i,o,u,a=[],s=(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.unicode?"u":"")+(t.sticky?"y":""),h=0,l=new RegExp(t.source,s+"g");(i=Gr.call(l,n))&&!(h<(o=l.lastIndex)&&(a.push(n.slice(h,i.index)),1=r));)l.lastIndex===i.index&&l.lastIndex++;return h===n.length?!u&&l.test("")||a.push(""):a.push(n.slice(h)),a.length>r?a.slice(0,r):a}:"0".split(void 0,0).length?function(t,e){return void 0===t&&0===e?[]:w.call(this,t,e)}:w,[function(t,e){var n=c(this),r=null==t?void 0:t[i];return void 0!==r?r.call(t,n,e):x.call(String(n),t,e)},function(t,e){var n=b(x,t,this,e,x!==w);if(n.done)return n.value;var r,i,o,u=O(t),a=String(this),s=(r=RegExp,void 0===(o=O(u).constructor)||null==(i=O(o)[ro])?r:me(i)),h=u.unicode,l=(u.ignoreCase?"i":"")+(u.multiline?"m":"")+(u.unicode?"u":"")+(ao?"y":"g"),c=new s(ao?u:"^(?:"+u.source+")",l),f=void 0===e?uo:e>>>0;if(0==f)return[];if(0===a.length)return null===Jr(c,a)?[a]:[];for(var d=0,v=0,p=[];v>>0||(eu.test(n)?16:10))}:tu;st({global:!0,forced:parseInt!=nu},{parseInt:nu});var ru="toString",iu=RegExp.prototype,ou=iu[ru],uu=y(function(){return"/a/b"!=ou.call({source:"a",flags:"b"})}),au=ou.name!=ru;function su(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var n=[],r=!0,i=!1,o=void 0;try{for(var u,a=t[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){i=!0,o=t}finally{try{r||null==a.return||a.return()}finally{if(i)throw o}}return n}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function hu(t,e){for(var n=0;nd?Math.pow(l,3):(l-f)/7.787),e=+(Math.pow(h,3)>d?Math.pow(h,3):(h-f)/7.787),n=1.08883*(Math.pow(c,3)>d?Math.pow(c,3):(c-f)/7.787)}var v=3.2406*t+-1.5372*e+-.4986*n,p=-.9689*t+1.8758*e+.0415*n,y=.0557*t+-.204*e+1.057*n,g=Math.pow,m=.0031308;return new C(255*(mDu;Du++)f(ju,Eu=Iu[Du])&&!f(Pu,Eu)&&Su(Pu,Eu,Ou(ju,Eu));(Pu.prototype=Cu).constructor=Pu,vt(m,Mu,Pu)}var Lu=di.trim,Nu=m.parseFloat,zu=1/Nu(hi+"-0")!=-1/0?function(t){var e=Lu(String(t)),n=Nu(e);return 0===n&&"-"==e.charAt(0)?-0:n}:Nu;st({global:!0,forced:parseFloat!=zu},{parseFloat:zu});var Ru=function(){function t(){Ti(this,t),this.init.apply(this,arguments)}return lu(t,[{key:"init",value:function(t,e){var n=0,r=0,i=Array.isArray(t)?{x:t[0],y:t[1]}:"object"===ue(t)?{x:t.x,y:t.y}:{x:t,y:e};return this.x=null==i.x?n:i.x,this.y=null==i.y?r:i.y,this}},{key:"clone",value:function(){return new t(this)}},{key:"transform",value:function(t){return this.clone().transformO(t)}},{key:"transformO",value:function(t){Fu.isMatrixLike(t)||(t=new Fu(t));var e=this.x,n=this.y;return this.x=t.a*e+t.c*n+t.e,this.y=t.b*e+t.d*n+t.f,this}},{key:"toArray",value:function(){return[this.x,this.y]}}]),t}();function Bu(t,e,n){return Math.abs(e-t)<(n||1e-6)}var Fu=function(){function h(){Ti(this,h),this.init.apply(this,arguments)}return lu(h,[{key:"init",value:function(t){var e=h.fromArray([1,0,0,1,0,0]);return t=t instanceof ia?t.matrixify():"string"==typeof t?h.fromArray(t.split(bo).map(parseFloat)):Array.isArray(t)?h.fromArray(t):"object"===ue(t)&&h.isMatrixLike(t)?t:"object"===ue(t)?(new h).transform(t):6===arguments.length?h.fromArray([].slice.call(arguments)):e,this.a=null!=t.a?t.a:e.a,this.b=null!=t.b?t.b:e.b,this.c=null!=t.c?t.c:e.c,this.d=null!=t.d?t.d:e.d,this.e=null!=t.e?t.e:e.e,this.f=null!=t.f?t.f:e.f,this}},{key:"clone",value:function(){return new h(this)}},{key:"transform",value:function(t){if(h.isMatrixLike(t))return new h(t).multiplyO(this);var e=h.formatTransforms(t),n=new Ru(e.ox,e.oy).transform(this),r=n.x,i=n.y,o=(new h).translateO(e.rx,e.ry).lmultiplyO(this).translateO(-r,-i).scaleO(e.scaleX,e.scaleY).skewO(e.skewX,e.skewY).shearO(e.shear).rotateO(e.theta).translateO(r,i);if(isFinite(e.px)||isFinite(e.py)){var u=new Ru(r,i).transform(o),a=e.px?e.px-u.x:0,s=e.py?e.py-u.y:0;o.translateO(a,s)}return o.translateO(e.tx,e.ty),o}},{key:"compose",value:function(t){t.origin&&(t.originX=t.origin[0],t.originY=t.origin[1]);var e=t.originX||0,n=t.originY||0,r=t.scaleX||1,i=t.scaleY||1,o=t.shear||0,u=t.rotate||0,a=t.translateX||0,s=t.translateY||0;return(new h).translateO(-e,-n).scaleO(r,i).shearO(o).rotateO(u).translateO(a,s).lmultiplyO(this).translateO(e,n)}},{key:"decompose",value:function(t,e){var n=0",delay:0},Zu={"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,"stroke-linejoin":"miter","stroke-linecap":"butt",fill:"#000000",stroke:"#000000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0,"stop-opacity":1,"stop-color":"#000000","text-anchor":"start"},Ku={__proto__:null,noop:Wu,timeline:Ju,attrs:Zu},ta=Gu("SVGArray",Array,function(t){this.init(t)});Gi(ta,{init:function(t){return"number"==typeof t||(this.length=0,this.push.apply(this,Tr(this.parse(t)))),this},toArray:function(){return Array.prototype.concat.apply([],this)},toString:function(){return this.join(" ")},valueOf:function(){var t=[];return t.push.apply(t,Tr(this)),t},parse:function(t){var e=0n.x&&e>n.y&&ta;)void 0!==(n=i(r,e=o[a++]))&&ht(u,e,n);return u}}),Ir("Element",{untransform:function(){return this.attr("transform",null)},matrixify:function(){return(this.attr("transform")||"").split(fo).slice(0,-1).map(function(t){var e=t.trim().split("(");return[e[0],e[1].split(bo).map(function(t){return parseFloat(t)})]}).reverse().reduce(function(t,e){return"matrix"===e[0]?t.lmultiply(Fu.fromArray(e[1])):t[e[0]].apply(t,e[1])},new Fu)},toParent:function(t){if(this===t)return this;var e=this.screenCTM(),n=t.screenCTM().inverse();return this.addTo(t).untransform().transform(n.multiply(e)),this},toRoot:function(){return this.toParent(this.root())},transform:function(t,e){if(null==t||"string"==typeof t){var n=new Fu(this).decompose();return null==t?n:n[t]}Fu.isMatrixLike(t)||(t=function(e){for(var t=1;t":function(t){return-Math.cos(t*Math.PI)/2+.5},">":function(t){return Math.sin(t*Math.PI/2)},"<":function(t){return 1-Math.cos(t*Math.PI/2)},bezier:function(e,n,r,i){return function(t){return t<0?0=e.time?e.run():bs.timeouts.push(e),e!==n););for(var r=null,i=bs.frames.last();r!==i&&(r=bs.frames.shift());)r.run(t);for(var o=null;o=bs.immediates.shift();)o();bs.nextDraw=bs.timeouts.first()||bs.frames.first()?ji.window.requestAnimationFrame(bs._draw):null}},xs=function(){function n(){var t,e=0=r;this._lastTime=this._time,i&&this.fire("start",this);var u=this._isDeclarative;if(this.done=!u&&!o&&this._time>=r,this._reseted=!1,n||u){this._initialise(n),this.transforms=new Fu;var a=this._run(u?t:e);this.fire("step",this)}return this.done=this.done||a&&u,o&&this.fire("finished",this),this}},{key:"reset",value:function(){return this._reseted||(this.time(0),this._reseted=!0),this}},{key:"finish",value:function(){return this.step(1/0)}},{key:"reverse",value:function(t){return this._reverse=null==t?!this._reverse:t,this}},{key:"ease",value:function(t){return this._stepper=new Va(t),this}},{key:"active",value:function(t){return null==t?this.enabled:(this.enabled=t,this)}},{key:"_rememberMorpher",value:function(t,e){if(this._history[t]={morpher:e,caller:this._queue[this._queue.length-1]},this._isDeclarative){var n=this.timeline();n&&n.play()}}},{key:"_tryRetarget",value:function(t,e,n){if(this._history[t]){if(!this._history[t].caller.initialised){var r=this._queue.indexOf(this._history[t].caller);return this._queue.splice(r,1),!1}this._history[t].caller.retarget?this._history[t].caller.retarget(e,n):this._history[t].morpher.to(e),this._history[t].caller.finished=!1;var i=this.timeline();return i&&i.play(),!0}return!1}},{key:"_initialise",value:function(t){if(t||this._isDeclarative)for(var e=0,n=this._queue.length;e=10.0.0" diff --git a/src/lib/draw_svg.js b/src/lib/draw_svg.js index 9514b81..c0e3c0b 100644 --- a/src/lib/draw_svg.js +++ b/src/lib/draw_svg.js @@ -1,12 +1,14 @@ const {create_canvas, calc_image_pos, calc_label_pos, canvas_to_img} = require('./dom'); -const SVGJS = require("svg.js"); +const {SVG, registerWindow} = require('@svgdotjs/svg.js') const draw_svg = (qr, settings) => { + // CHECK does this make problems with server-side rendering? + registerWindow(window, document); const svgText = qr.svgText; const container = document.createElement("div"); container.innerHTML = svgText; const svgElem = container.firstChild; - const svg = SVGJS(svgElem); + const svg = SVG(svgElem); // In crisp mode, it is possible that the SVG is not exactly 400px --> fix this if (settings.crisp) { @@ -16,13 +18,13 @@ const draw_svg = (qr, settings) => { } // Rect --> background-color if (!settings.back || settings.back === '') { - svg.select("rect").first().remove(); + svg.findOne("rect").remove(); } else { - svg.select("rect").fill(settings.back); + svg.find("rect").fill(settings.back); } // Path --> foreground-color if (!!settings.fill) { - svg.select("path").fill(settings.fill); + svg.find("path").fill(settings.fill); } if (settings.mode === "label") { const ctx = create_canvas(settings); @@ -49,12 +51,16 @@ const draw_svg = (qr, settings) => { } else if (settings.mode === "image") { if (settings.imageAsCode) { const image = canvas_to_img(settings.image, settings); - const svgImage = svg.image(image.getAttribute("src"), settings.size, settings.size); + const svgImage = svg.image(image.getAttribute("src")); + svgImage.attr("width", settings.size + "px"); + svgImage.attr("height", settings.size + "px"); svgImage.x(0); svgImage.y(0); } else { const imgPos = calc_image_pos(settings); - const svgImage = svg.image(settings.image.getAttribute("src"), imgPos.iw, imgPos.ih); + const svgImage = svg.image(settings.image.getAttribute("src")); + svgImage.attr("width", imgPos.iw + "px"); + svgImage.attr("height", imgPos.ih + "px"); svgImage.x(imgPos.x); svgImage.y(imgPos.y); }