mirror of https://github.com/luileito/jsketch.git
1 line
3.0 KiB
JavaScript
1 line
3.0 KiB
JavaScript
!function(a){a.jSketch.prototype.toSVG=function(a){function b(){var a='<?xml version="1.0" encoding="utf-8" standalone="no" ?>';return a+='<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',a+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="'+e.stageWidth+'" height="'+e.stageHeight+'" viewBox="0 0 '+e.stageWidth+" "+e.stageHeight+'">',a+="<desc>Generated with jSketch: https://luis.leiva.name/jsketch/</desc>",a+="<defs></defs>",a+="<g>",a+=c(),a+="</g>",a+="</svg>",a.replace(/\s+/g," ")}function c(){for(var a="",b=0;b<e.callStack.length;b++){var c=e.callStack[b];if(c.property&&"object"!=typeof c.value)h[c.property]=c.value;else if(c.method){if(!i[c.method]){console.warn("Method not implemented:",c.method);continue}a+=i[c.method].apply(null,c.args)}else console.warn("Unknown call:",c)}return a}function d(){if(0>=g){clearInterval(j);var c=b();a(c)}else console.info("Waiting for %s async operations to be finished ...",g)}if("function"!=typeof a)throw new Error("You must supply a callback in toSVG() method.");var e=this,f=[],g=0,h={},i={addAsync:function(){return g++,""},removeAsync:function(){return g--,""},drawImage:function(a,b,c){return'<image preserveAspectRatio="none" width="'+a.width+'" height="'+a.height+'" transform="translate('+b+", "+c+')" xlink:href="'+a.src+'"></image>'},fillRect:function(a,b,c,d){return'<rect stroke="none" width="'+c+'" height="'+d+'" x="'+a+'" y="'+b+'" fill="'+h.fillStyle+'"></rect>'},strokeRect:function(a,b,c,d){return'<rect fill="none" width="'+c+'" height="'+d+'" x="'+a+'" y="'+b+'" stroke="'+h.strokeStyle+'" stroke-width="'+h.lineWidth+'" stroke-linecap="'+h.lineCap+'" stroke-linejoin="'+h.lineJoin+'" stroke-miterlimit="'+h.miterLimit+'"></rect>'},strokeCircle:function(a,b,c){return'<circle fill="none" cx="'+a+'" cy="'+b+'" r="'+c+'" stroke="'+h.strokeStyle+'" stroke-width="'+h.lineWidth+'" />'},fillCircle:function(a,b,c){return'<circle stroke="none" cx="'+a+'" cy="'+b+'" r="'+c+'" fill="'+h.fillStyle+'" />'},beginPath:function(){return f=[],""},closePath:function(){var a="";return f.length>0&&(a='<path fill="none" stroke="'+h.strokeStyle+'" stroke-width="'+h.lineWidth+'" stroke-linecap="'+h.lineCap+'" stroke-linejoin="'+h.lineJoin+'" stroke-miterlimit="'+h.miterLimit+'" d="'+f.join(" ")+'" />',f=[]),a},moveTo:function(a,b){return f.push("M "+a+" "+b),""},lineTo:function(a,b){return f.push("L "+a+" "+b),""},quadraticCurveTo:function(a,b,c,d){return f.push("Q "+a+" "+b+" "+c+" "+d),""}},j=setInterval(d,150);return this}}(this); |