gerber-to-svg
Advanced tools
Comparing version 0.1.8 to 0.2.0
/* copyright 2014 by mike cousins; shared under the terms of the MIT license. Source code available at github.com/mcous/gerber-to-svg */ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.gerberToSvg=t()}}(function(){return function t(e,r,i){function n(s,h){if(!r[s]){if(!e[s]){var l="function"==typeof require&&require;if(!h&&l)return l(s,!0);if(o)return o(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var u=r[s]={exports:{}};e[s][0].call(u.exports,function(t){var r=e[s][1][t];return n(r?r:t)},u,u.exports,t,e,r,i)}return r[s].exports}for(var o="function"==typeof require&&require,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(t,e){var r,i,n;n=t("./obj-to-xml"),i=t("./plotter"),r={drill:!1,pretty:!1,object:!1},e.exports=function(e,o){var s,h,l,a,u,c,f,p,x,d,b,w,g;null==o&&(o={}),f={};for(c in r)x=r[c],f[c]=x;for(c in o)x=o[c],f[c]=x;if("object"==typeof e){if(null!=e.svg)return n(e,{pretty:f.pretty});throw new Error("non SVG object cannot be converted to an SVG string")}f.drill?(h=t("./drill-reader"),s=t("./drill-parser")):(h=t("./gerber-reader"),s=t("./gerber-parser")),p=new i(e,h,s);try{w=p.plot()}catch(y){throw a=y,new Error("Error at line "+p.reader.line+" - "+a.message)}p.bbox.xMin>=p.bbox.xMax?(p.bbox.xMin=0,p.bbox.xMax=0,d=0):d=p.bbox.xMax-p.bbox.xMin,p.bbox.yMin>=p.bbox.yMax?(p.bbox.yMin=0,p.bbox.yMax=0,u=0):u=p.bbox.yMax-p.bbox.yMin,b={svg:{xmlns:"http://www.w3.org/2000/svg",version:"1.1","xmlns:xlink":"http://www.w3.org/1999/xlink",width:""+d+p.units,height:""+u+p.units,viewBox:[p.bbox.xMin,p.bbox.yMin,d,u],_:[]}},g=p.attr;for(l in g)x=g[l],b.svg[l]=x;return p.defs.length&&b.svg._.push({defs:{_:p.defs}}),p.group.g._.length&&b.svg._.push(p.group),f.object?b:n(b,{pretty:f.pretty})}},{"./drill-parser":3,"./drill-reader":4,"./gerber-parser":5,"./gerber-reader":6,"./obj-to-xml":9,"./plotter":11}],2:[function(t,e){var r=[].indexOf||function(t){for(var e=0,r=this.length;r>e;e++)if(e in this&&this[e]===t)return e;return-1};e.exports=function(t,e){var i,n,o,s,h,l,a,u,c,f,p,x,d;if(null==t)return{};if(null==e.zero||null==e.places)throw new Error("format undefined");o={},s={},o.x=null!=(l=t.match(/X[+-]?[\d\.]+/))&&null!=(a=l[0])?a.slice(1):void 0,o.y=null!=(u=t.match(/Y[+-]?[\d\.]+/))&&null!=(c=u[0])?c.slice(1):void 0,o.i=null!=(f=t.match(/I[+-]?[\d\.]+/))&&null!=(p=f[0])?p.slice(1):void 0,o.j=null!=(x=t.match(/J[+-]?[\d\.]+/))&&null!=(d=x[0])?d.slice(1):void 0;for(n in o)if(h=o[n],null!=h)if(r.call(h,".")>=0)s[n]=Number(h);else{if(i=1,("+"===h[0]||"-"===h[0])&&("-"===h[0]&&(i=-1),h=h.slice(1)),"L"===e.zero)i*=Math.pow(10,e.places[1]);else{if("T"!==e.zero)throw new Error("invalid zero suppression format");i*=Math.pow(10,h.length-e.places[0])}s[n]=Number(h)/i}return s}},{}],3:[function(t,e){var r,i,n,o,s,h,l,a,u;a=t("./coord-parser"),n={"FMAT,1":"M70","FMAT,2":"M72"},s="M71",r="G90",o="G91",u=/[XY]{1,2}/,l="L",h=[2,4],i=function(){function t(){this.format={zero:null,places:null},this.fmat="FMAT,2"}return t.prototype.parseCommand=function(t){var e,i,c,f,p,x,d,b;if(i={},";"===t[0])return i;if("FMAT,1"===t)this.fmat=t;else if("M30"===t||"M00"===t)i.set={done:!0};else if(t===n[this.fmat]||t.match(/INCH/))this.format.places=[2,4],i.set={units:"in"};else if(t===s||t.match(/METRIC/))this.format.places=[3,3],i.set={units:"mm"};else if(t===r)i.set={notation:"abs"};else if(t===o)i.set={notation:"inc"};else if(e=null!=(x=t.match(/T\d+/))?x[0]:void 0){for(;"0"===e[1];)e=e[0]+e.slice(2);(c=null!=(d=t.match(/C[\d\.]+(?=.*$)/))?d[0]:void 0)?(c=Number(c.slice(1)),i.tool={},i.tool[e]={dia:c}):i.set={currentTool:e}}if(t.match(/TZ/)?this.format.zero="L":t.match(/LZ/)&&(this.format.zero="T"),t.match(u)){i.op={"do":"flash"},null==this.format.zero&&(this.format.zero=l),null==this.format.places&&(this.format.places=h),b=a(t,this.format);for(f in b)p=b[f],i.op[f]=p}return i},t}(),e.exports=i},{"./coord-parser":2}],4:[function(t,e){var r;r=function(){function t(t){this.line=0,this.blocks=t.split(/\r?\n/)}return t.prototype.nextBlock=function(){return this.line<this.blocks.length?this.blocks[++this.line-1]:!1},t}(),e.exports=r},{}],5:[function(t,e){var r,i,n;i=t("./coord-parser"),n=/([XYIJ][+-]?\d+){1,4}/g,r=function(){function t(){this.format={zero:null,places:null}}return t.prototype.parseFormat=function(t,e){var r,i,n;if(n="L"===t[2]||"T"===t[2]?t[2]:null,r="A"===t[3]||"I"===t[3]?t[3]:null,"X"===t[4]&&"Y"===t[7]&&t.slice(5,7)===t.slice(8,10)&&t[5]<8&&t[6]<8&&(i=[+t[5],+t[6]]),null==i||null==r||null==n)throw new Error("invalid format specification");return this.format.zero=n,this.format.places=i,null==e.set&&(e.set={}),e.set.notation=r},t.prototype.parseToolDef=function(t,e){var r,i,n,o,s,h,l;for(null==e.tool&&(e.tool={}),r=null!=(h=t.match(/^ADD\d{2,}/))?h[0].slice(2):void 0,l=t.slice(2+r.length).split(","),s=l[0],o=l[1],o=null!=o?o.split("X"):void 0;"0"===r[1];)r=r[0]+r.slice(2);switch(s){case"C":if(o.length>2?i={width:+o[1],height:+o[2]}:o.length>1&&(i={dia:+o[1]}),e.tool[r]={dia:+o[0]},null!=i)return e.tool[r].hole=i;break;case"R":case"O":if(o.length>3?i={width:+o[2],height:+o[3]}:o.length>2&&(i={dia:+o[2]}),e.tool[r]={width:+o[0],height:+o[1]},"O"===s&&(e.tool[r].obround=!0),null!=i)return e.tool[r].hole=i;break;case"P":if(o.length>4?i={width:+o[3],height:+o[4]}:o.length>3&&(i={dia:+o[3]}),e.tool[r]={dia:+o[0],verticies:+o[1]},o.length>2&&(e.tool[r].degrees=+o[2]),null!=i)return e.tool[r].hole=i;break;default:return o=function(){var t,e,r,i;for(r=null!=o?o:[],i=[],t=0,e=r.length;e>t;t++)n=r[t],i.push(+n);return i}(),e.tool[r]={macro:s,mods:o}}},t.prototype.parseCommand=function(t){var e,r,o,s,h,l,a,u,c,f,p,x,d,b,w,g,y,m,M,v,k,E,q,R,T,B,D;if(null==t&&(t={}),r={},f=t.param)for(g=0,y=f.length;y>g;g++)switch(c=f[g],o=c.slice(0,2)){case"FS":this.parseFormat(c,r);break;case"MO":if(x=c.slice(2,4),null==r.set&&(r.set={}),"IN"===x)r.set.units="in";else{if("MM"!==x)throw new Error(""+c+" is an invalid units setting");r.set.units="mm"}break;case"AD":this.parseToolDef(c,r);break;case"AM":return{macro:f};case"LP":if(null==r["new"]&&(r["new"]={}),("D"===c[2]||"C"===c[2])&&(r["new"].layer=c[2]),null==r["new"].layer)throw new Error("invalid level polarity");break;case"SR":if(null==r["new"]&&(r["new"]={}),b=null!=(m=null!=(M=c.match(/X[+-]?[\d\.]+/))?M[0].slice(1):void 0)?m:1,w=null!=(v=null!=(k=c.match(/Y[+-]?[\d\.]+/))?k[0].slice(1):void 0)?v:1,h=null!=(E=c.match(/I[+-]?[\d\.]+/))?E[0].slice(1):void 0,l=null!=(q=c.match(/J[+-]?[\d\.]+/))?q[0].slice(1):void 0,1>b||1>w||b>1&&null==h||0>h||w>1&&null==l||0>l)throw new Error("invalid step repeat");r["new"].sr={x:+b,y:+w},null!=h&&(r["new"].sr.i=+h),null!=l&&(r["new"].sr.j=+l)}else if(t=t.block){if("M02"===t)return{set:{done:!0}};if("G"===t[0])switch(o=null!=(R=t.slice(1).match(/^\d{1,2}/))?R[0]:void 0){case"4":case"04":return{};case"1":case"01":case"2":case"02":case"3":case"03":o=o[o.length-1],a="1"===o?"i":"2"===o?"cw":"ccw",r.set={mode:a};break;case"36":case"37":r.set={region:"36"===o};break;case"70":case"71":r.set={backupUnits:"70"===o?"in":"mm"};break;case"74":case"75":r.set={quad:"74"===o?"s":"m"}}if(s=i(null!=(T=t.match(n))?T[0]:void 0,this.format),u=(null!=(B=t.match(/D0?[123]$/))?B[0]:void 0)||Object.keys(s).length){null!=u&&(u=u[u.length-1]),u=function(){switch(u){case"1":return"int";case"2":return"move";case"3":return"flash";default:return"last"}}(),r.op={"do":u};for(e in s)d=s[e],r.op[e]=d}else(p=null!=(D=t.match(/D\d+$/))?D[0]:void 0)&&(r.set={currentTool:p})}return r},t}(),e.exports=r},{"./coord-parser":2}],6:[function(t,e){var r;r=function(){function t(t){this.gerberFile=t,this.line=0,this.charIndex=0,this.end=this.gerberFile.length}return t.prototype.nextBlock=function(){var t,e,r;if(this.index>=this.end)return!1;for(e="",r=!1,0===this.line&&this.line++;!(this.charIndex>=this.end);)if(t=this.gerberFile[this.charIndex++],"%"===t){if(r)return{param:r};r=[]}else if("*"===t){if(!r)return{block:e};r.push(e),e=""}else"\n"===t?this.line++:t>=" "&&"~">=t&&(e+=t);return!1},t}(),e.exports=r},{}],7:[function(t,e){var r,i,n,o,s,h;i=/[\+\-\/xX\(\)]/,r=/[\$\d\.]+/,n=new RegExp("("+i.source+")|("+r.source+")","g"),h=function(t){var e;return e=t.match(n)},o=function(t){return r.test(t)},s=function(t){var e,r,i,n,s,l,a;return a=h(t),r=0,l=function(){return a[r]},e=function(t){return t===l()?r++:void 0},s=function(){var t,r;if(r=l(),e(r),o(r))t={type:"n",val:r};else{if("("!==r)throw new Error(""+r+" is unexpected in an arithmetic string");if(t=i(),")"!==l())throw new Error("expected ')'");e(")")}return t},n=function(){var t,r,i;for(t=s(),i=l();"x"===i||"/"===i||"X"===i;)e(i),"X"===i&&(i="x"),r=s(),t={type:i,left:t,right:r},i=l();return t},(i=function(){var t,r,i;for(t=n(),i=l();"+"===i||"-"===i;)e(i),r=n(),t={type:i,left:t,right:r},i=l();return t})()},e.exports={tokenize:h,isNumber:o,parse:s}},{}],8:[function(t,e){var r,i,n,o;n=t("./pad-shapes"),i=t("./macro-calc"),o=t("./unique-id"),r=function(){function t(t){this.modifiers={},this.name=t[0].slice(2),this.blocks=t.slice(1),this.shapes=[],this.masks=[],this.lastExposure=null,this.bbox=[null,null,null,null]}return t.prototype.run=function(t,e){var r,i,n,s,h,l,a,u,c,f,p,x,d,b,w,g,y,m,M;for(null==e&&(e=[]),this.lastExposure=null,this.shapes=[],this.masks=[],this.bbox=[null,null,null,null],this.modifiers={},n=c=0,d=e.length;d>c;n=++c)s=e[n],this.modifiers["$"+(n+1)]=s;for(y=this.blocks,f=0,b=y.length;b>f;f++)r=y[f],this.runBlock(r);for(l="tool-"+t+"-pad-"+o(),h=[],m=this.masks,p=0,w=m.length;w>p;p++)s=m[p],h.push(s);if(this.shapes.length>1){for(i={id:l,_:[]},M=this.shapes,x=0,g=M.length;g>x;x++)a=M[x],i._.push(a);h=[{g:i}]}else 1===this.shapes.length&&(u=Object.keys(this.shapes[0])[0],this.shapes[0][u].id=l,h.push(this.shapes[0]));return{pad:h,padId:l,bbox:this.bbox,trace:!1}},t.prototype.runBlock=function(t){var e,r,i,n,o,s,h,l;switch(t[0]){case"$":return n=null!=(l=t.match(/^\$\d+(?=\=)/))?l[0]:void 0,o=t.slice(1+n.length),this.modifiers[n]=this.getNumber(o);case"1":case"2":case"20":case"21":case"22":case"4":case"5":case"6":case"7":for(r=t.split(","),i=s=0,h=r.length;h>s;i=++s)e=r[i],r[i]=this.getNumber(e);return this.primitive(r);default:if("0"!==t[0])throw new Error("'"+t+"' unrecognized tool macro block")}},t.prototype.primitive=function(t){var e,r,i,s,h,l,a,u,c,f,p,x,d,b,w,g,y,m,M,v,k,E,q,R,T,B,D,_,C;switch(h=!1,c=!1,p=null,t[0]){case 1:p=n.circle({dia:t[2],cx:t[3],cy:t[4]}),0===t[1]?h=!0:this.addBbox(p.bbox);break;case 2:case 20:p=n.vector({width:t[2],x1:t[3],y1:t[4],x2:t[5],y2:t[6]}),t[7]&&(p.shape.line.transform="rotate("+t[7]+")"),0===t[1]?h=!0:this.addBbox(p.bbox,t[7]);break;case 21:p=n.rect({cx:t[4],cy:t[5],width:t[2],height:t[3]}),t[6]&&(p.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?h=!0:this.addBbox(p.bbox,t[6]);break;case 22:p=n.lowerLeftRect({x:t[4],y:t[5],width:t[2],height:t[3]}),t[6]&&(p.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?h=!0:this.addBbox(p.bbox,t[6]);break;case 4:for(a=[],r=x=3,q=3+2*t[2];q>=x;r=x+=2)a.push([t[r],t[r+1]]);p=n.outline({points:a}),(u=t[t.length-1])&&(p.shape.polygon.transform="rotate("+u+")"),0===t[1]?h=!0:this.addBbox(p.bbox,t[t.length-1]);break;case 5:if(0!==t[6]&&(0!==t[3]||0!==t[4]))throw new RangeError("polygon center must be 0,0 if rotated in macro");p=n.polygon({cx:t[3],cy:t[4],dia:t[5],verticies:t[2],degrees:t[6]}),0===t[1]?h=!0:this.addBbox(p.bbox);break;case 6:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("moiré center must be 0,0 if rotated in macro");if(p=n.moire({cx:t[1],cy:t[2],outerDia:t[3],ringThx:t[4],ringGap:t[5],maxRings:t[6],crossThx:t[7],crossLength:t[8]}),t[9])for(R=p.shape,d=0,g=R.length;g>d;d++)f=R[d],null!=f.line&&(f.line.transform="rotate("+t[9]+")");this.addBbox(p.bbox,t[9]);break;case 7:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("thermal center must be 0,0 if rotated in macro");if(p=n.thermal({cx:t[1],cy:t[2],outerDia:t[3],innerDia:t[4],gap:t[5]}),t[6])for(T=p.shape,b=0,y=T.length;y>b;b++)if(f=T[b],null!=f.mask)for(B=f.mask._,w=0,m=B.length;m>w;w++)s=B[w],null!=s.rect&&(s.rect.transform="rotate("+t[6]+")");this.addBbox(p.bbox,t[6]);break;default:throw new Error(""+t[0]+" is not a valid primitive code")}if(h){for(i in p.shape)p.shape[i].fill="#000";if(0!==this.lastExposure){if(this.lastExposure=0,l="macro-"+this.name+"-mask-"+o(),s={mask:{id:l}},s.mask._=[{rect:{x:this.bbox[0],y:this.bbox[1],width:this.bbox[2]-this.bbox[0],height:this.bbox[3]-this.bbox[1],fill:"#fff"}}],1===this.shapes.length)for(i in this.shapes[0])this.shapes[0][i].mask="url(#"+l+")";else if(this.shapes.length>1){for(e={mask:"url(#"+l+")",_:[]},D=this.shapes,k=0,M=D.length;M>k;k++)f=D[k],e._.push(f);this.shapes=[{g:e}]}this.masks.push(s)}return this.masks[this.masks.length-1].mask._.push(p.shape)}if(this.lastExposure=1,Array.isArray(p.shape)){for(_=p.shape,C=[],E=0,v=_.length;v>E;E++)f=_[E],C.push(null!=f.mask?this.masks.push(f):this.shapes.push(f));return C}return this.shapes.push(p.shape)},t.prototype.addBbox=function(t,e){var r,i,n,o,s,h,l,a,u;if(null==e&&(e=0),e){for(s=Math.sin(e*Math.PI/180),i=Math.cos(e*Math.PI/180),Math.abs(s)<1e-9&&(s=0),Math.abs(i)<1e-9&&(i=0),o=[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]],a=0,u=o.length;u>a;a++)n=o[a],h=n[0]*i-n[1]*s,l=n[0]*s+n[1]*i,(null===this.bbox[0]||h<this.bbox[0])&&(this.bbox[0]=h),(null===this.bbox[1]||l<this.bbox[1])&&(this.bbox[1]=l),(null===this.bbox[2]||h>this.bbox[2])&&(this.bbox[2]=h),(null===this.bbox[3]||l>this.bbox[3])&&(this.bbox[3]=l);return this.bbox=function(){var t,e,i,n;for(i=this.bbox,n=[],t=0,e=i.length;e>t;t++)r=i[t],n.push(r===-0?0:r);return n}.call(this)}return(null===this.bbox[0]||t[0]<this.bbox[0])&&(this.bbox[0]=t[0]),(null===this.bbox[1]||t[1]<this.bbox[1])&&(this.bbox[1]=t[1]),(null===this.bbox[2]||t[2]>this.bbox[2])&&(this.bbox[2]=t[2]),null===this.bbox[3]||t[3]>this.bbox[3]?this.bbox[3]=t[3]:void 0},t.prototype.getNumber=function(t){return t.match(/^[+-]?[\d.]+$/)?Number(t):t.match(/^\$\d+$/)?Number(this.modifiers[t]):this.evaluate(i.parse(t))},t.prototype.evaluate=function(t){switch(t.type){case"n":return this.getNumber(t.val);case"+":return this.evaluate(t.left)+this.evaluate(t.right);case"-":return this.evaluate(t.left)-this.evaluate(t.right);case"x":return this.evaluate(t.left)*this.evaluate(t.right);case"/":return this.evaluate(t.left)/this.evaluate(t.right)}},t}(),e.exports=r},{"./macro-calc":7,"./pad-shapes":10,"./unique-id":13}],9:[function(t,e){var r,i,n,o;o=function(t,e){var r;if(r="",0===e)return"";for(;e>1;)1&e&&(r+=t),e>>=1,t+=t;return r+t},r="_",i=" ",n=function(t,e){var s,h,l,a,u,c,f,p,x,d,b,w,g,y,m,M,v,k,E;if(null==e&&(e={}),d=e.pretty,c=null!=(v=e.indent)?v:0,h=null!=(k=e.maxDec)?k:!1,l=function(t){return"number"==typeof t?Number(t.toFixed(h)):t},p=d?"\n":"",b=p?"string"==typeof d?d:i:"",b=o(b,c),y="","function"==typeof t&&(t=t()),Array.isArray(t))for(u=m=0,M=t.length;M>m;u=++m)x=t[u],y+=(0!==u?p:"")+n(x,e);else if("object"==typeof t){if(s=!1,a=Object.keys(t)[0],null!=a){y=""+b+"<"+a,"function"==typeof t[a]&&(t[a]=t[a]()),E=t[a];for(f in E)g=E[f],"function"==typeof g&&(g=g()),f===r?s=g:(Array.isArray(g)&&(h&&(g=function(){var t,e,r;for(r=[],t=0,e=g.length;e>t;t++)w=g[t],r.push(l(w));return r}()),g=g.join(" ")),h&&(g=l(g)),y+=" "+f+'="'+g+'"');s&&(y+=">"+p+n(s,{pretty:d,indent:c+1})),y+=null!=t[a]._?""+p+b+"</"+a+">":"/>"}}else y+=""+t+" ";return y},e.exports=n},{}],10:[function(t,e){var r,i,n,o,s,h,l,a,u;a=t("./unique-id"),r=function(t){var e;if(null==t.dia)throw new Error("circle function requires diameter");if(null==t.cx)throw new Error("circle function requires x center");if(null==t.cy)throw new Error("circle function requires y center");return e=t.dia/2,{shape:{circle:{cx:t.cx,cy:t.cy,r:e}},bbox:[t.cx-e,t.cy-e,t.cx+e,t.cy+e]}},h=function(t){var e,r,i,n;if(null==t.width)throw new Error("rectangle requires width");if(null==t.height)throw new Error("rectangle requires height");if(null==t.cx)throw new Error("rectangle function requires x center");if(null==t.cy)throw new Error("rectangle function requires y center");return i=t.cx-t.width/2,n=t.cy-t.height/2,r={shape:{rect:{x:i,y:n,width:t.width,height:t.height}},bbox:[i,n,i+t.width,n+t.height]},t.obround&&(e=.5*Math.min(t.width,t.height),r.shape.rect.rx=e,r.shape.rect.ry=e),r},s=function(t){var e,r,i,n,o,s,h,l,a,u,c,f,p,x,d,b;if(null==t.dia)throw new Error("polygon requires diameter");if(null==t.verticies)throw new Error("polygon requires verticies");if(null==t.cx)throw new Error("polygon function requires x center");if(null==t.cy)throw new Error("polygon function requires y center");for(s=null!=t.degrees?t.degrees*Math.PI/180:0,h=2*Math.PI/t.verticies,i=t.dia/2,r="",c=null,x=null,u=null,p=null,e=d=0,b=t.verticies;b>=0?b>d:d>b;e=b>=0?++d:--d)l=s+e*h,n=i*Math.cos(l),o=i*Math.sin(l),Math.abs(n)<1e-9&&(n=0),Math.abs(o)<1e-9&&(o=0),a=t.cx+n,f=t.cy+o,(c>a||null===c)&&(c=a),(a>u||null===u)&&(u=a),(x>f||null===x)&&(x=f),(f>p||null===p)&&(p=f),r+=" "+a+","+f;return{shape:{polygon:{points:r.slice(1)}},bbox:[c,x,u,p]}},u=function(t){var e,r,i;if(null==t.x1)throw new Error("vector function requires start x");if(null==t.y1)throw new Error("vector function requires start y");if(null==t.x2)throw new Error("vector function requires end x");if(null==t.y2)throw new Error("vector function requires end y");if(null==t.width)throw new Error("vector function requires width");return e=Math.abs(Math.atan((t.y2-t.y1)/(t.x2-t.x1))),r=t.width/2*Math.sin(e),i=t.width/2*Math.cos(e),1e-7>r&&(r=0),1e-7>i&&(i=0),{shape:{line:{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,"stroke-width":t.width,"stroke-linecap":"butt"}},bbox:[Math.min(t.x1,t.x2)-r,Math.min(t.y1,t.y2)-i,Math.max(t.x1,t.x2)+r,Math.max(t.y1,t.y2)+i]}},i=function(t){if(null==t.width)throw new Error("lower left rect requires width");if(null==t.height)throw new Error("lower left rect requires height");if(null==t.x)throw new Error("lower left rectangle requires x");if(null==t.y)throw new Error("lower left rectangle requires y");return{shape:{rect:{x:t.x,y:t.y,width:t.width,height:t.height}},bbox:[t.x,t.y,t.x+t.width,t.y+t.height]}},o=function(t){var e,r,i,n,o,s,h,l,a,u,c,f,p;if(!(Array.isArray(t.points)&&t.points.length>1))throw new Error("outline function requires points array");for(s=null,u=null,o=null,a=null,r="",p=t.points,c=0,f=p.length;f>c;c++){if(e=p[c],!Array.isArray(e)||2!==e.length)throw new Error("outline function requires points array");i=e[0],h=e[1],(s>i||null===s)&&(s=i),(i>o||null===o)&&(o=i),(u>h||null===u)&&(u=h),(h>a||null===a)&&(a=h),r+=" "+i+","+h}if(n=t.points[t.points.length-1][0],l=t.points[t.points.length-1][1],n!==t.points[0][0]||l!==t.points[0][1])throw new RangeError("last point must match first point of outline");return{shape:{polygon:{points:r.slice(1)}},bbox:[s,u,o,a]}},n=function(t){var e,r,i;if(null==t.cx)throw new Error("moiré requires x center");if(null==t.cy)throw new Error("moiré requires y center");if(null==t.outerDia)throw new Error("moiré requires outer diameter");if(null==t.ringThx)throw new Error("moiré requires ring thickness");if(null==t.ringGap)throw new Error("moiré requires ring gap");if(null==t.maxRings)throw new Error("moiré requires max rings");if(null==t.crossLength)throw new Error("moiré requires crosshair length");if(null==t.crossThx)throw new Error("moiré requires crosshair thickness");for(i=[{line:{x1:t.cx-t.crossLength/2,y1:0,x2:t.cx+t.crossLength/2,y2:0,"stroke-width":t.crossThx,"stroke-linecap":"butt"}},{line:{x1:0,y1:t.cy-t.crossLength/2,x2:0,y2:t.cy+t.crossLength/2,"stroke-width":t.crossThx,"stroke-linecap":"butt"}}],e=(t.outerDia-t.ringThx)/2,r=0;e>=t.ringThx&&r<t.maxRings;)i.push({circle:{cx:t.cx,cy:t.cy,r:e,fill:"none","stroke-width":t.ringThx}}),r++,e-=t.ringThx+t.ringGap;return e+=.5*t.ringThx,e>0&&r<t.maxRings&&i.push({circle:{cx:t.cx,cy:t.cy,r:e}}),{shape:i,bbox:[Math.min(t.cx-t.crossLength/2,t.cx-t.outerDia/2),Math.min(t.cy-t.crossLength/2,t.cy-t.outerDia/2),Math.max(t.cx+t.crossLength/2,t.cx+t.outerDia/2),Math.max(t.cy+t.crossLength/2,t.cy+t.outerDia/2)]}},l=function(t){var e,r,i,n,o,s,h,l,u;if(null==t.cx)throw new Error("thermal requires x center");if(null==t.cy)throw new Error("thermal requires y center");if(null==t.outerDia)throw new Error("thermal requires outer diameter");if(null==t.innerDia)throw new Error("thermal requires inner diameter");if(null==t.gap)throw new Error("thermal requires gap");return r="thermal-mask-"+a(),o=(t.outerDia-t.innerDia)/2,i=t.outerDia/2,n=i-o/2,h=t.cx-i,s=t.cx+i,u=t.cy-i,l=t.cy+i,e=t.gap/2,{shape:[{mask:{id:r,_:[{circle:{cx:t.cx,cy:t.cy,r:i,"stroke-width":0,fill:"#fff"}},{rect:{x:h,y:-e,width:t.outerDia,height:t.gap,"stroke-width":0,fill:"#000"}},{rect:{x:-e,y:u,width:t.gap,height:t.outerDia,"stroke-width":0,fill:"#000"}}]}},{circle:{cx:t.cx,cy:t.cy,r:n,fill:"none","stroke-width":o,mask:"url(#"+r+")"}}],bbox:[h,u,s,l]}},e.exports={circle:r,rect:h,polygon:s,vector:u,lowerLeftRect:i,outline:o,moire:n,thermal:l}},{"./unique-id":13}],11:[function(t,e){var r,i,n,o,s,h,l,a,u;u=t("./unique-id"),n=t("./macro-tool"),a=t("./standard-tool"),i=Math.PI/2,s=3*i,h=2*Math.PI,l=1e-7,r="in",o=function(){function t(t,e,r){null==t&&(t=""),null!=e&&(this.reader=new e(t)),null!=r&&(this.parser=new r),this.macros={},this.tools={},this.currentTool="",this.defs=[],this.group={g:{_:[]}},this.polarity="D",this.current=[],this.stepRepeat={x:1,y:1,i:0,j:0},this.srOverClear=!1,this.srOverCurrent=[],this.units=null,this.mode=null,this.quad=null,this.lastOp=null,this.region=!1,this.done=!1,this.pos={x:0,y:0},this.path=[],this.attr={"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":0,stroke:"#000"},this.bbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0},this.layerBbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0}}return t.prototype.addTool=function(t,e){var r,i;if(null!=this.tools[t])throw new Error("cannot reassign tool "+t);return i=null!=e.macro?this.macros[e.macro].run(t,e.mods):a(t,e),this.tools[t]={trace:i.trace,pad:function(){var t,e,n,o;for(n=i.pad,o=[],t=0,e=n.length;e>t;t++)r=n[t],o.push(r);return o}(),flash:function(t,e){return{use:{x:t,y:e,"xlink:href":"#"+i.padId}}},bbox:function(t,e){return null==t&&(t=0),null==e&&(e=0),{xMin:t+i.bbox[0],yMin:e+i.bbox[1],xMax:t+i.bbox[2],yMax:e+i.bbox[3]}}},this.changeTool(t)},t.prototype.changeTool=function(t){var e;if(this.finishPath(),this.region)throw new Error("cannot change tool when in region mode");if(null!=this.tools[t])return this.currentTool=t;if(!(null!=(e=this.parser)?e.fmat:void 0))throw new Error("tool "+t+" is not defined")},t.prototype.command=function(t){var e,r,i,o,s,h,l,a;if(null!=t.macro)return r=new n(t.macro),void(this.macros[r.name]=r);h=t.set;for(o in h){if(s=h[o],"units"===o&&null!=this.units&&null==(null!=(l=this.parser)?l.fmat:void 0))throw new Error("cannot redefine units");if("notation"===o&&null!=this.notation)throw new Error("cannot redefine notation");"region"===o&&this.finishPath(),"currentTool"===o?this.changeTool(s):this[o]=s}if(null!=t.tool){a=t.tool;for(e in a)i=a[e],this.addTool(e,i)}if(null!=t.op&&this.operate(t.op),null!=t["new"]){if(this.finishLayer(),null!=t["new"].layer)return this.polarity=t["new"].layer;if(null!=t["new"].sr)return this.finishSR(),this.stepRepeat=t["new"].sr}},t.prototype.plot=function(){for(var t,e;!this.done;){if(t=this.reader.nextBlock(),t===!1)throw new Error(null==(null!=(e=this.parser)?e.fmat:void 0)?"end of file encountered before required M02 command":"end of drill file encountered before M00/M30 command");this.command(this.parser.parseCommand(t))}return this.finish()},t.prototype.finish=function(){return this.finishPath(),this.finishLayer(),this.finishSR(),this.group.g.fill="currentColor",this.group.g.stroke="currentColor",this.group.g.transform="translate(0,"+(this.bbox.yMin+this.bbox.yMax)+") scale(1,-1)"},t.prototype.finishSR=function(){var t,e,r,i,n,o,s,h,l,a,c,f,p,x,d,b;if(this.srOverClear&&this.srOverCurrent){for(r="gerber-sr-mask_"+u(),e={mask:{color:"#000",id:r,_:[]}},e.mask._.push({rect:{fill:"#fff",x:this.bbox.xMin,y:this.bbox.yMin,width:this.bbox.xMax-this.bbox.xMin,height:this.bbox.yMax-this.bbox.yMin}}),n=s=0,c=this.stepRepeat.x*this.stepRepeat.i,f=this.stepRepeat.i;f>0?c>s:s>c;n=s+=f)for(o=h=0,p=this.stepRepeat.y*this.stepRepeat.j,x=this.stepRepeat.j;x>0?p>h:h>p;o=h+=x)for(d=this.srOverCurrent,l=0,a=d.length;a>l;l++)t=d[l],i={use:{}},0!==n&&(i.use.x=n),0!==o&&(i.use.y=o),i.use["xlink:href"]="#"+(null!=(b=t.C)?b:t.D),null!=t.D&&(i.use.fill="#fff"),e.mask._.push(i);return this.srOverClear=!1,this.srOverCurrent=[],this.defs.push(e),this.group.g.mask="url(#"+r+")"}},t.prototype.finishLayer=function(){var t,e,r,i,n,o,s,h,l,a,c,f,p,x,d,b;if(this.finishPath(),this.current.length){if(this.stepRepeat.x>1||this.stepRepeat.y>1){for(n="gerber-sr_"+u(),this.current=[{g:{id:n,_:this.current}}],(this.srOverClear||this.stepRepeat.i<this.layerBbox.xMax-this.layerBbox.xMin||this.stepRepeat.j<this.layerBbox.yMax-this.layerBbox.yMin)&&(i={},i[this.polarity]=n,this.srOverCurrent.push(i),"C"===this.polarity&&(this.srOverClear=!0,this.defs.push(this.current[0]))),h=a=0,x=this.stepRepeat.x;x>=0?x>a:a>x;h=x>=0?++a:--a)for(l=c=0,d=this.stepRepeat.y;d>=0?d>c:c>d;l=d>=0?++c:--c)(0!==h||0!==l)&&(o={use:{"xlink:href":"#"+n}},0!==h&&(o.use.x=h*this.stepRepeat.i),0!==l&&(o.use.y=l*this.stepRepeat.j),this.current.push(o));this.layerBbox.xMax+=(this.stepRepeat.x-1)*this.stepRepeat.i,this.layerBbox.yMax+=(this.stepRepeat.y-1)*this.stepRepeat.j}if(this.addBbox(this.layerBbox,this.bbox),this.layerBbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0},"D"===this.polarity)if(null!=this.group.g.mask&&this.current.unshift(this.group),null==this.group.g.mask&&this.group.g._.length)for(b=this.current,f=0,p=b.length;p>f;f++)t=b[f],this.group.g._.push(t);else this.group={g:{_:this.current}};else"C"!==this.polarity||this.srOverClear||(r="gerber-mask_"+u(),s=this.bbox.xMax-this.bbox.xMin,e=this.bbox.yMax-this.bbox.yMin,this.current.unshift({rect:{x:this.bbox.xMin,y:this.bbox.yMin,width:s,height:e,fill:"#fff"}}),this.defs.push({mask:{id:r,color:"#000",_:this.current}}),this.group.g.mask="url(#"+r+")");return this.current=[]}},t.prototype.finishPath=function(){var t,e,r,i;if(this.path.length){if(e={path:{}},this.region)this.path.push("Z");else{i=this.tools[this.currentTool].trace;for(t in i)r=i[t],e.path[t]=r}return e.path.d=this.path,this.current.push(e),this.path=[]}},t.prototype.operate=function(t){var e,i,n,o,s,h,l,a,u,c,f,p,x,d,b;if("last"===t["do"]?t["do"]=this.lastOp:this.lastOp=t["do"],s=this.pos.x,h=this.pos.y,"I"===this.notation?(this.pos.x+=null!=(c=t.x)?c:0,this.pos.y+=null!=(f=t.y)?f:0):(this.pos.x=null!=(p=t.x)?p:this.pos.x,this.pos.y=null!=(x=t.y)?x:this.pos.y),i=this.pos.x,n=this.pos.y,l=this.tools[this.currentTool],null==this.units&&(this.units=null!=this.backupUnits?this.backupUnits:r),null==this.notation){if(null==(null!=(d=this.parser)?d.fmat:void 0))throw new Error("format has not been set");this.notation="A"}if("move"===t["do"]&&this.path.length)return this.path.push("M",i,n);if("flash"===t["do"]){if(this.finishPath(),this.region)throw new Error("cannot flash while in region mode");if(l.pad){for(b=l.pad,a=0,u=b.length;u>a;a++)o=b[a],this.defs.push(o);l.pad=!1}return this.current.push(l.flash(i,n)),this.addBbox(l.bbox(i,n),this.layerBbox)}if("int"===t["do"]){if(!this.region&&!l.trace)throw new Error(""+this.currentTool+" is not a strokable tool");return 0===this.path.length&&(this.path.push("M",s,h),e=this.region?{xMin:s,yMin:h,xMax:s,yMax:h}:l.bbox(s,h),this.addBbox(e,this.layerBbox)),null==this.mode&&(this.mode="i"),"i"===this.mode?this.drawLine(s,h,i,n):(null==t.i&&(t.i=0),null==t.j&&(t.j=0),this.drawArc(s,h,i,n,t.i,t.j))}},t.prototype.drawLine=function(t,e,r,n){var o,s,h,l,a,u,c,f,p,x,d,b,w;return b=this.tools[this.currentTool],o=this.region?{xMin:r,yMin:n,xMax:r,yMax:n}:b.bbox(r,n),this.addBbox(o,this.layerBbox),this.region||b.trace["stroke-width"]>=0?this.path.push("L",r,n):(c=b.pad[0].rect.width/2,u=b.pad[0].rect.height/2,f=t-c,p=t+c,x=e-u,d=e+u,s=r-c,h=r+c,l=n-u,a=n+u,w=Math.atan2(n-e,r-t),w>=0&&i>w?this.path.push("M",f,x,p,x,h,l,h,a,s,a,f,d,"Z"):w>=i&&w<Math.PI?this.path.push("M",f,x,p,x,p,d,h,a,s,a,s,l,"Z"):-Math.PI<=w&&-i>w?this.path.push("M",p,x,p,d,f,d,s,a,s,l,h,l,"Z"):w>=-i&&0>w?this.path.push("M",f,x,s,l,h,l,h,a,p,d,f,d,"Z"):void 0)},t.prototype.drawArc=function(t,e,r,n,o,a){var u,c,f,p,x,d,b,w,g,y,m,M,v,k,E,q,R,T,B,D,_,C,I,L,j,O,A,P;if(l=1.01*Math.pow(10,-((null!=(O=null!=(A=this.parser)?A.format.places[1]:void 0)?O:6)-1)),g=this.tools[this.currentTool],!this.region&&!g.trace["stroke-width"])throw Error("cannot stroke an arc with non-circular tool "+this.currentTool);if(null==this.quad)throw new Error("arc quadrant mode has not been set");for(d=Math.sqrt(Math.pow(o,2)+Math.pow(a,2)),w="cw"===this.mode?0:1,x=0,v=[],c=[[t+o,e+a]],"s"===this.quad&&c.push([t-o,e-a],[t-o,e+a],[t+o,e-a]),C=0,L=c.length;L>C;C++)u=c[C],p=Math.sqrt(Math.pow(u[0]-r,2)+Math.pow(u[1]-n,2)),Math.abs(d-p)<l&&v.push({x:u[0],y:u[1]});for(m=0,M=0,f=null,I=0,j=v.length;j>I&&(u=v[I],m=Math.atan2(n-u.y,r-u.x),0>m&&(m+=h),M=Math.atan2(e-u.y,t-u.x),0>M&&(M+=h),"cw"===this.mode&&m>M?M+=h:"ccw"===this.mode&&M>m&&(m+=h),y=Math.abs(m-M),"s"===this.quad&&i>=y?f=u:"m"===this.quad&&(y>=Math.PI&&(x=1),f={x:u.x,y:u.y}),null==f);I++);return null!=f?(b=this.region?0:g.bbox().xMax,"cw"===this.mode&&(P=[M,m],m=P[0],M=P[1]),R=M>0?h:0,_=i+(M>i?h:0),q=Math.PI+(M>Math.PI?h:0),D=s+(M>s?h:0),E=q>=M&&m>=q?f.x-d-b:Math.min(t,r)-b,k=R>=M&&m>=R?f.x+d+b:Math.max(t,r)+b,B=D>=M&&m>=D?f.y-d-b:Math.min(e,n)-b,T=_>=M&&m>=_?f.y+d+b:Math.max(e,n)+b,"m"===this.quad&&Math.abs(t-r)<l&&Math.abs(e-n)<l&&(this.path.push("A",d,d,0,0,w,r+2*o,n+2*a),E=f.x-d-b,B=f.y-d-b,k=f.x+d+b,T=f.y+d+b),this.path.push("A",d,d,0,x,w,r,n),this.addBbox({xMin:E,yMin:B,xMax:k,yMax:T},this.layerBbox)):void 0},t.prototype.addBbox=function(t,e){return t.xMin<e.xMin&&(e.xMin=t.xMin),t.yMin<e.yMin&&(e.yMin=t.yMin),t.xMax>e.xMax&&(e.xMax=t.xMax),t.yMax>e.yMax?e.yMax=t.yMax:void 0},t}(),e.exports=o},{"./macro-tool":8,"./standard-tool":12,"./unique-id":13}],12:[function(t,e){var r,i,n;n=t("./unique-id"),r=t("./pad-shapes"),i=function(t,e){var i,o,s,h,l,a,u;if(a={pad:[],trace:!1},e.cx=0,e.cy=0,o="tool-"+t+"-pad-"+n(),u="",null!=e.dia&&null==e.verticies){if(null!=e.obround||null!=e.width||null!=e.height||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.dia<0)throw new RangeError(""+t+" circle diameter out of range ("+e.dia+"<0)");u="circle",null==e.hole&&(a.trace={"stroke-width":e.dia,fill:"none"})}else if(null!=e.width&&null!=e.height){if(null!=e.dia||null!=e.verticies||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.width<=0)throw new RangeError(""+t+" rect width out of range ("+e.width+"<=0)");if(e.height<=0)throw new RangeError(""+t+" rect height out of range ("+e.height+"<=0)");u="rect",null!=e.hole||e.obround||(a.trace={})}else{if(null==e.dia||null==e.verticies)throw new Error("unidentified standard tool shape");if(null!=e.obround||null!=e.width||null!=e.height)throw new Error("incompatible parameters for tool "+t);if(e.verticies<3||e.verticies>12)throw new RangeError(""+t+" polygon points out of range ("+e.verticies+"<3 or >12)]");u="polygon"}if(l=r[u](e),null!=e.hole){if(i=null,null!=e.hole.dia&&null==e.hole.width&&null==e.hole.height){if(!(e.hole.dia>=0))throw new RangeError(""+t+" hole diameter out of range ("+e.hole.dia+"<0)");i=r.circle({cx:e.cx,cy:e.cy,dia:e.hole.dia}),i=i.shape,i.circle.fill="#000"}else{if(null==e.hole.width||null==e.hole.height)throw new Error(""+t+" has invalid hole parameters");if(!(e.hole.width>=0))throw new RangeError(""+t+" hole width out of range ("+e.hole.width+"<0)");if(!(e.hole.height>=0))throw new RangeError(""+t+" hole height out of range");i=r.rect({cx:e.cx,cy:e.cy,width:e.hole.width,height:e.hole.height}),i=i.shape,i.rect.fill="#000"}h=o+"-mask",s={mask:{id:o+"-mask",_:[{rect:{x:l.bbox[0],y:l.bbox[1],width:l.bbox[2]-l.bbox[0],height:l.bbox[3]-l.bbox[1],fill:"#fff"}},i]}},l.shape[u].mask="url(#"+h+")",a.pad.push(s) | ||
}return o&&(l.shape[u].id=o),a.pad.push(l.shape),a.bbox=l.bbox,a.padId=o,a},e.exports=i},{"./pad-shapes":10,"./unique-id":13}],13:[function(t,e){var r,i;i=1e3,r=function(){return i++},e.exports=r},{}]},{},[1])(1)}); | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.gerberToSvg=t()}}(function(){return function t(e,r,i){function o(s,h){if(!r[s]){if(!e[s]){var a="function"==typeof require&&require;if(!h&&a)return a(s,!0);if(n)return n(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=r[s]={exports:{}};e[s][0].call(u.exports,function(t){var r=e[s][1][t];return o(r?r:t)},u,u.exports,t,e,r,i)}return r[s].exports}for(var n="function"==typeof require&&require,s=0;s<i.length;s++)o(i[s]);return o}({1:[function(t,e){var r,i,o;o=t("./obj-to-xml"),i=t("./plotter"),r={drill:!1,pretty:!1,object:!1},e.exports=function(e,n){var s,h,a,l,u,c,f,p,x,d,b,m,g,w,y,v,M;null==n&&(n={}),f={};for(c in r)d=r[c],f[c]=d;for(c in n)d=n[c],f[c]=d;if("object"==typeof e){if(null!=e.svg)return o(e,{pretty:f.pretty});throw new Error("non SVG object cannot be converted to an SVG string")}f.drill?(h=t("./drill-reader"),s=t("./drill-parser")):(h=t("./gerber-reader"),s=t("./gerber-parser")),p=new i(e,h,s);try{g=p.plot()}catch(k){throw l=k,new Error("Error at line "+p.reader.line+" - "+l.message)}p.bbox.xMin>=p.bbox.xMax?(p.bbox.xMin=0,p.bbox.xMax=0,b=0):b=p.bbox.xMax-p.bbox.xMin,p.bbox.yMin>=p.bbox.yMax?(p.bbox.yMin=0,p.bbox.yMax=0,u=0):u=p.bbox.yMax-p.bbox.yMin,x=Math.pow(10,null!=(w=p.parser)&&null!=(y=w.format)&&null!=(v=y.places)?v[1]:void 0)||1,m={svg:{xmlns:"http://www.w3.org/2000/svg",version:"1.1","xmlns:xlink":"http://www.w3.org/1999/xlink",width:""+b/x+p.units,height:""+u/x+p.units,viewBox:[p.bbox.xMin,p.bbox.yMin,b,u],_:[]}},M=p.attr;for(a in M)d=M[a],m.svg[a]=d;return p.defs.length&&m.svg._.push({defs:{_:p.defs}}),p.group.g._.length&&m.svg._.push(p.group),f.object?m:o(m,{pretty:f.pretty})}},{"./drill-parser":3,"./drill-reader":4,"./gerber-parser":5,"./gerber-reader":6,"./obj-to-xml":10,"./plotter":12}],2:[function(t,e){var r;r=t("./get-integer"),e.exports=function(t,e){var i,o,n,s,h,a,l,u,c,f,p,x;if(null==t)return{};if(null==e.zero||null==e.places)throw new Error("format undefined");o={},n={},o.x=null!=(h=t.match(/X[+-]?[\d\.]+/))&&null!=(a=h[0])?a.slice(1):void 0,o.y=null!=(l=t.match(/Y[+-]?[\d\.]+/))&&null!=(u=l[0])?u.slice(1):void 0,o.i=null!=(c=t.match(/I[+-]?[\d\.]+/))&&null!=(f=c[0])?f.slice(1):void 0,o.j=null!=(p=t.match(/J[+-]?[\d\.]+/))&&null!=(x=p[0])?x.slice(1):void 0;for(i in o)s=o[i],null!=s&&(n[i]=r(s,e));return n}},{"./get-integer":7}],3:[function(t,e){var r,i,o,n,s,h,a,l,u,c;u=t("./coord-parser"),l=t("./get-integer"),o={"FMAT,1":"M70","FMAT,2":"M72"},s="M71",r="G90",n="G91",c=/[XY]{1,2}/,a="L",h=[2,4],i=function(){function t(){this.format={zero:null,places:null},this.fmat="FMAT,2"}return t.prototype.parseCommand=function(t){var e,i,f,p,x,d,b,m;if(i={},";"===t[0])return i;if("FMAT,1"===t)this.fmat=t;else if("M30"===t||"M00"===t)i.set={done:!0};else if(t===o[this.fmat]||t.match(/INCH/))this.format.places=[2,4],i.set={units:"in"};else if(t===s||t.match(/METRIC/))this.format.places=[3,3],i.set={units:"mm"};else if(t===r)i.set={notation:"abs"};else if(t===n)i.set={notation:"inc"};else if(e=null!=(d=t.match(/T\d+/))?d[0]:void 0){for(;"0"===e[1];)e=e[0]+e.slice(2);(f=null!=(b=t.match(/C[\d\.]+(?=.*$)/))?b[0]:void 0)?(f=f.slice(1),i.tool={},i.tool[e]={dia:l(f,{places:this.format.places})}):i.set={currentTool:e}}if(t.match(/TZ/)?this.format.zero="L":t.match(/LZ/)&&(this.format.zero="T"),t.match(c)){i.op={"do":"flash"},null==this.format.zero&&(this.format.zero=a),null==this.format.places&&(this.format.places=h),m=u(t,this.format);for(p in m)x=m[p],i.op[p]=x}return i},t}(),e.exports=i},{"./coord-parser":2,"./get-integer":7}],4:[function(t,e){var r;r=function(){function t(t){this.line=0,this.blocks=t.split(/\r?\n/)}return t.prototype.nextBlock=function(){return this.line<this.blocks.length?this.blocks[++this.line-1]:!1},t}(),e.exports=r},{}],5:[function(t,e){var r,i,o,n;o=t("./coord-parser"),i=t("./get-integer"),n=/([XYIJ][+-]?\d+){1,4}/g,r=function(){function t(){this.format={zero:null,places:null}}return t.prototype.parseFormat=function(t,e){var r,i,o;if(o="L"===t[2]||"T"===t[2]?t[2]:null,r="A"===t[3]||"I"===t[3]?t[3]:null,"X"===t[4]&&"Y"===t[7]&&t.slice(5,7)===t.slice(8,10)&&t[5]<8&&t[6]<8&&(i=[+t[5],+t[6]]),null==i||null==r||null==o)throw new Error("invalid format specification");return this.format.zero=o,this.format.places=i,null==e.set&&(e.set={}),e.set.notation=r},t.prototype.parseToolDef=function(t,e){var r,o,n,s,h,a,l;for(null==e.tool&&(e.tool={}),r=null!=(a=t.match(/^ADD\d{2,}/))?a[0].slice(2):void 0,l=t.slice(2+r.length).split(","),h=l[0],s=l[1],s=null!=s?s.split("X"):void 0;"0"===r[1];)r=r[0]+r.slice(2);switch(h){case"C":if(s.length>2?o={width:i(s[1],{places:this.format.places}),height:i(s[2],{places:this.format.places})}:s.length>1&&(o={dia:i(s[1],{places:this.format.places})}),e.tool[r]={dia:i(s[0],{places:this.format.places})},null!=o)return e.tool[r].hole=o;break;case"R":case"O":if(s.length>3?o={width:i(s[2],{places:this.format.places}),height:i(s[3],{places:this.format.places})}:s.length>2&&(o={dia:i(s[2],{places:this.format.places})}),e.tool[r]={width:i(s[0],{places:this.format.places}),height:i(s[1],{places:this.format.places})},"O"===h&&(e.tool[r].obround=!0),null!=o)return e.tool[r].hole=o;break;case"P":if(s.length>4?o={width:i(s[3],{places:this.format.places}),height:i(s[4],{places:this.format.places})}:s.length>3&&(o={dia:i(s[3],{places:this.format.places})}),e.tool[r]={dia:i(s[0],{places:this.format.places}),verticies:+s[1]},s.length>2&&(e.tool[r].degrees=+s[2]),null!=o)return e.tool[r].hole=o;break;default:return s=function(){var t,e,r,i;for(r=null!=s?s:[],i=[],t=0,e=r.length;e>t;t++)n=r[t],i.push(+n);return i}(),e.tool[r]={macro:h,mods:s}}},t.prototype.parseCommand=function(t){var e,r,s,h,a,l,u,c,f,p,x,d,b,m,g,w,y,v,M,k,E,q,R,T,B,D,_;if(null==t&&(t={}),r={},p=t.param)for(w=0,y=p.length;y>w;w++)switch(f=p[w],s=f.slice(0,2)){case"FS":this.parseFormat(f,r);break;case"MO":if(d=f.slice(2,4),null==r.set&&(r.set={}),"IN"===d)r.set.units="in";else{if("MM"!==d)throw new Error(""+f+" is an invalid units setting");r.set.units="mm"}break;case"AD":this.parseToolDef(f,r);break;case"AM":return{macro:p};case"LP":if(null==r["new"]&&(r["new"]={}),("D"===f[2]||"C"===f[2])&&(r["new"].layer=f[2]),null==r["new"].layer)throw new Error("invalid level polarity");break;case"SR":if(null==r["new"]&&(r["new"]={}),m=null!=(v=null!=(M=f.match(/X[+-]?[\d\.]+/))?M[0].slice(1):void 0)?v:1,g=null!=(k=null!=(E=f.match(/Y[+-]?[\d\.]+/))?E[0].slice(1):void 0)?k:1,a=null!=(q=f.match(/I[+-]?[\d\.]+/))?q[0].slice(1):void 0,l=null!=(R=f.match(/J[+-]?[\d\.]+/))?R[0].slice(1):void 0,1>m||1>g||m>1&&null==a||0>a||g>1&&null==l||0>l)throw new Error("invalid step repeat");r["new"].sr={x:+m,y:+g},null!=a&&(r["new"].sr.i=i(a,{places:this.format.places})),null!=l&&(r["new"].sr.j=i(l,{places:this.format.places}))}else if(t=t.block){if("M02"===t)return{set:{done:!0}};if("G"===t[0])switch(s=null!=(T=t.slice(1).match(/^\d{1,2}/))?T[0]:void 0){case"4":case"04":return{};case"1":case"01":case"2":case"02":case"3":case"03":s=s[s.length-1],u="1"===s?"i":"2"===s?"cw":"ccw",r.set={mode:u};break;case"36":case"37":r.set={region:"36"===s};break;case"70":case"71":r.set={backupUnits:"70"===s?"in":"mm"};break;case"74":case"75":r.set={quad:"74"===s?"s":"m"}}if(h=o(null!=(B=t.match(n))?B[0]:void 0,this.format),c=(null!=(D=t.match(/D0?[123]$/))?D[0]:void 0)||Object.keys(h).length){null!=c&&(c=c[c.length-1]),c=function(){switch(c){case"1":return"int";case"2":return"move";case"3":return"flash";default:return"last"}}(),r.op={"do":c};for(e in h)b=h[e],r.op[e]=b}else(x=null!=(_=t.match(/D\d+$/))?_[0]:void 0)&&(r.set={currentTool:x})}return r},t}(),e.exports=r},{"./coord-parser":2,"./get-integer":7}],6:[function(t,e){var r;r=function(){function t(t){this.gerberFile=t,this.line=0,this.charIndex=0,this.end=this.gerberFile.length}return t.prototype.nextBlock=function(){var t,e,r;if(this.index>=this.end)return!1;for(e="",r=!1,0===this.line&&this.line++;!(this.charIndex>=this.end);)if(t=this.gerberFile[this.charIndex++],"%"===t){if(r)return{param:r};r=[]}else if("*"===t){if(!r)return{block:e};r.push(e),e=""}else"\n"===t?this.line++:t>=" "&&"~">=t&&(e+=t);return!1},t}(),e.exports=r},{}],7:[function(t,e){var r=[].indexOf||function(t){for(var e=0,r=this.length;r>e;e++)if(e in this&&this[e]===t)return e;return-1};e.exports=function(t,e){var i,o,n,s,h,a,l;if("number"!=typeof(null!=e&&null!=(h=e.places)?h[0]:void 0)&&"number"!=typeof(null!=e&&null!=(a=e.places)?a[1]:void 0))return 0/0;if(t=""+t,n="+",("-"===t[0]||"+"===t[0])&&(n=t[0],t=t.slice(1)),r.call(t,".")>=0||null==e.zero){if(s=t.split("."),s.length>2)return 0/0;for(l=[s[0],s[1]],o=l[0],i=l[1],null==i&&(i=[]);i.length>e.places[1];)i=i.slice(0,-1);for(;i.length<e.places[1];)i+="0";t=o+i}else if("T"===e.zero)for(;t.length<e.places[0]+e.places[1];)t+="0";return parseInt(n+t)}},{}],8:[function(t,e){var r,i,o,n,s,h;i=/[\+\-\/xX\(\)]/,r=/[\$\d\.]+/,o=new RegExp("("+i.source+")|("+r.source+")","g"),h=function(t){var e;return e=t.match(o)},n=function(t){return r.test(t)},s=function(t){var e,r,i,o,s,a,l;return l=h(t),r=0,a=function(){return l[r]},e=function(t){return t===a()?r++:void 0},s=function(){var t,r;if(r=a(),e(r),n(r))t={type:"n",val:r};else{if("("!==r)throw new Error(""+r+" is unexpected in an arithmetic string");if(t=i(),")"!==a())throw new Error("expected ')'");e(")")}return t},o=function(){var t,r,i;for(t=s(),i=a();"x"===i||"/"===i||"X"===i;)e(i),"X"===i&&(i="x"),r=s(),t={type:i,left:t,right:r},i=a();return t},(i=function(){var t,r,i;for(t=o(),i=a();"+"===i||"-"===i;)e(i),r=o(),t={type:i,left:t,right:r},i=a();return t})()},e.exports={tokenize:h,isNumber:n,parse:s}},{}],9:[function(t,e){var r,i,o,n,s;n=t("./pad-shapes"),i=t("./macro-calc"),s=t("./unique-id"),o=t("./get-integer"),r=function(){function t(t,e){this.modifiers={},this.name=t[0].slice(2),this.blocks=t.slice(1),this.shapes=[],this.masks=[],this.lastExposure=null,this.bbox=[null,null,null,null],this.format={places:e}}return t.prototype.run=function(t,e){var r,i,o,n,h,a,l,u,c,f,p,x,d,b,m,g,w,y,v;for(null==e&&(e=[]),this.lastExposure=null,this.shapes=[],this.masks=[],this.bbox=[null,null,null,null],this.modifiers={},o=c=0,d=e.length;d>c;o=++c)n=e[o],this.modifiers["$"+(o+1)]=n;for(w=this.blocks,f=0,b=w.length;b>f;f++)r=w[f],this.runBlock(r);for(a="tool-"+t+"-pad-"+s(),h=[],y=this.masks,p=0,m=y.length;m>p;p++)n=y[p],h.push(n);if(this.shapes.length>1){for(i={id:a,_:[]},v=this.shapes,x=0,g=v.length;g>x;x++)l=v[x],i._.push(l);h=[{g:i}]}else 1===this.shapes.length&&(u=Object.keys(this.shapes[0])[0],this.shapes[0][u].id=a,h.push(this.shapes[0]));return{pad:h,padId:a,bbox:this.bbox,trace:!1}},t.prototype.runBlock=function(t){var e,r,i,o,n,s,h,a;switch(t[0]){case"$":return o=null!=(a=t.match(/^\$\d+(?=\=)/))?a[0]:void 0,n=t.slice(1+o.length),this.modifiers[o]=this.getNumber(n);case"1":case"2":case"20":case"21":case"22":case"4":case"5":case"6":case"7":for(r=t.split(","),i=s=0,h=r.length;h>s;i=++s)e=r[i],r[i]=this.getNumber(e);return this.primitive(r);default:if("0"!==t[0])throw new Error("'"+t+"' unrecognized tool macro block")}},t.prototype.primitive=function(t){var e,r,i,h,a,l,u,c,f,p,x,d,b,m,g,w,y,v,M,k,E,q,R,T,B,D,_,I,C;switch(a=!1,f=!1,x=null,t[0]){case 1:x=n.circle({dia:o(t[2],this.format),cx:o(t[3],this.format),cy:o(t[4],this.format)}),0===t[1]?a=!0:this.addBbox(x.bbox);break;case 2:case 20:x=n.vector({width:o(t[2],this.format),x1:o(t[3],this.format),y1:o(t[4],this.format),x2:o(t[5],this.format),y2:o(t[6],this.format)}),t[7]&&(x.shape.line.transform="rotate("+t[7]+")"),0===t[1]?a=!0:this.addBbox(x.bbox,t[7]);break;case 21:x=n.rect({cx:o(t[4],this.format),cy:o(t[5],this.format),width:o(t[2],this.format),height:o(t[3],this.format)}),t[6]&&(x.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?a=!0:this.addBbox(x.bbox,t[6]);break;case 22:x=n.lowerLeftRect({x:o(t[4],this.format),y:o(t[5],this.format),width:o(t[2],this.format),height:o(t[3],this.format)}),t[6]&&(x.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?a=!0:this.addBbox(x.bbox,t[6]);break;case 4:for(u=[],r=d=3,R=3+2*t[2];R>=d;r=d+=2)u.push([o(t[r],this.format),o(t[r+1],this.format)]);x=n.outline({points:u}),(c=t[t.length-1])&&(x.shape.polygon.transform="rotate("+c+")"),0===t[1]?a=!0:this.addBbox(x.bbox,t[t.length-1]);break;case 5:if(0!==t[6]&&(0!==t[3]||0!==t[4]))throw new RangeError("polygon center must be 0,0 if rotated in macro");x=n.polygon({cx:o(t[3],this.format),cy:o(t[4],this.format),dia:o(t[5],this.format),verticies:t[2],degrees:t[6]}),0===t[1]?a=!0:this.addBbox(x.bbox);break;case 6:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("moiré center must be 0,0 if rotated in macro");if(x=n.moire({cx:o(t[1],this.format),cy:o(t[2],this.format),outerDia:o(t[3],this.format),ringThx:o(t[4],this.format),ringGap:o(t[5],this.format),maxRings:t[6],crossThx:o(t[7],this.format),crossLength:o(t[8],this.format)}),t[9])for(T=x.shape,b=0,w=T.length;w>b;b++)p=T[b],null!=p.line&&(p.line.transform="rotate("+t[9]+")");this.addBbox(x.bbox,t[9]);break;case 7:if(0!==t[9]&&(0!==t[1]||0!==t[2]))throw new RangeError("thermal center must be 0,0 if rotated in macro");if(x=n.thermal({cx:o(t[1],this.format),cy:o(t[2],this.format),outerDia:o(t[3],this.format),innerDia:o(t[4],this.format),gap:o(t[5],this.format)}),t[6])for(B=x.shape,m=0,y=B.length;y>m;m++)if(p=B[m],null!=p.mask)for(D=p.mask._,g=0,v=D.length;v>g;g++)h=D[g],null!=h.rect&&(h.rect.transform="rotate("+t[6]+")");this.addBbox(x.bbox,t[6]);break;default:throw new Error(""+t[0]+" is not a valid primitive code")}if(a){for(i in x.shape)x.shape[i].fill="#000";if(0!==this.lastExposure){if(this.lastExposure=0,l="macro-"+this.name+"-mask-"+s(),h={mask:{id:l}},h.mask._=[{rect:{x:this.bbox[0],y:this.bbox[1],width:this.bbox[2]-this.bbox[0],height:this.bbox[3]-this.bbox[1],fill:"#fff"}}],1===this.shapes.length)for(i in this.shapes[0])this.shapes[0][i].mask="url(#"+l+")";else if(this.shapes.length>1){for(e={mask:"url(#"+l+")",_:[]},_=this.shapes,E=0,M=_.length;M>E;E++)p=_[E],e._.push(p);this.shapes=[{g:e}]}this.masks.push(h)}return this.masks[this.masks.length-1].mask._.push(x.shape)}if(this.lastExposure=1,Array.isArray(x.shape)){for(I=x.shape,C=[],q=0,k=I.length;k>q;q++)p=I[q],C.push(null!=p.mask?this.masks.push(p):this.shapes.push(p));return C}return this.shapes.push(x.shape)},t.prototype.addBbox=function(t,e){var r,i,o,n,s,h,a,l,u;if(null==e&&(e=0),e){for(s=Math.sin(e*Math.PI/180),i=Math.cos(e*Math.PI/180),Math.abs(s)<1e-9&&(s=0),Math.abs(i)<1e-9&&(i=0),n=[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]],l=0,u=n.length;u>l;l++)o=n[l],h=o[0]*i-o[1]*s,a=o[0]*s+o[1]*i,(null===this.bbox[0]||h<this.bbox[0])&&(this.bbox[0]=h),(null===this.bbox[1]||a<this.bbox[1])&&(this.bbox[1]=a),(null===this.bbox[2]||h>this.bbox[2])&&(this.bbox[2]=h),(null===this.bbox[3]||a>this.bbox[3])&&(this.bbox[3]=a);return this.bbox=function(){var t,e,i,o;for(i=this.bbox,o=[],t=0,e=i.length;e>t;t++)r=i[t],o.push(r===-0?0:r);return o}.call(this)}return(null===this.bbox[0]||t[0]<this.bbox[0])&&(this.bbox[0]=t[0]),(null===this.bbox[1]||t[1]<this.bbox[1])&&(this.bbox[1]=t[1]),(null===this.bbox[2]||t[2]>this.bbox[2])&&(this.bbox[2]=t[2]),null===this.bbox[3]||t[3]>this.bbox[3]?this.bbox[3]=t[3]:void 0},t.prototype.getNumber=function(t){return t.match(/^[+-]?[\d.]+$/)?Number(t):t.match(/^\$\d+$/)?Number(this.modifiers[t]):this.evaluate(i.parse(t))},t.prototype.evaluate=function(t){switch(t.type){case"n":return this.getNumber(t.val);case"+":return this.evaluate(t.left)+this.evaluate(t.right);case"-":return this.evaluate(t.left)-this.evaluate(t.right);case"x":return this.evaluate(t.left)*this.evaluate(t.right);case"/":return this.evaluate(t.left)/this.evaluate(t.right)}},t}(),e.exports=r},{"./get-integer":7,"./macro-calc":8,"./pad-shapes":11,"./unique-id":14}],10:[function(t,e){var r,i,o,n;n=function(t,e){var r;if(r="",0===e)return"";for(;e>1;)1&e&&(r+=t),e>>=1,t+=t;return r+t},r="_",i=" ",o=function(t,e){var s,h,a,l,u,c,f,p,x,d,b,m,g,w,y,v,M,k,E;if(null==e&&(e={}),d=e.pretty,c=null!=(M=e.indent)?M:0,h=null!=(k=e.maxDec)?k:!1,a=function(t){return"number"==typeof t?Number(t.toFixed(h)):t},p=d?"\n":"",b=p?"string"==typeof d?d:i:"",b=n(b,c),w="","function"==typeof t&&(t=t()),Array.isArray(t))for(u=y=0,v=t.length;v>y;u=++y)x=t[u],w+=(0!==u?p:"")+o(x,e);else if("object"==typeof t){if(s=!1,l=Object.keys(t)[0],null!=l){w=""+b+"<"+l,"function"==typeof t[l]&&(t[l]=t[l]()),E=t[l];for(f in E)g=E[f],"function"==typeof g&&(g=g()),f===r?s=g:(Array.isArray(g)&&(h&&(g=function(){var t,e,r;for(r=[],t=0,e=g.length;e>t;t++)m=g[t],r.push(a(m));return r}()),g=g.join(" ")),h&&(g=a(g)),w+=" "+f+'="'+g+'"');s&&(w+=">"+p+o(s,{pretty:d,indent:c+1})),w+=null!=t[l]._?""+p+b+"</"+l+">":"/>"}}else w+=""+t+" ";return w},e.exports=o},{}],11:[function(t,e){var r,i,o,n,s,h,a,l,u;l=t("./unique-id"),r=function(t){var e;if(null==t.dia)throw new Error("circle function requires diameter");if(null==t.cx)throw new Error("circle function requires x center");if(null==t.cy)throw new Error("circle function requires y center");return e=t.dia/2,{shape:{circle:{cx:t.cx,cy:t.cy,r:e}},bbox:[t.cx-e,t.cy-e,t.cx+e,t.cy+e]}},h=function(t){var e,r,i,o;if(null==t.width)throw new Error("rectangle requires width");if(null==t.height)throw new Error("rectangle requires height");if(null==t.cx)throw new Error("rectangle function requires x center");if(null==t.cy)throw new Error("rectangle function requires y center");return i=t.cx-t.width/2,o=t.cy-t.height/2,r={shape:{rect:{x:i,y:o,width:t.width,height:t.height}},bbox:[i,o,i+t.width,o+t.height]},t.obround&&(e=.5*Math.min(t.width,t.height),r.shape.rect.rx=e,r.shape.rect.ry=e),r},s=function(t){var e,r,i,o,n,s,h,a,l,u,c,f,p,x,d,b;if(null==t.dia)throw new Error("polygon requires diameter");if(null==t.verticies)throw new Error("polygon requires verticies");if(null==t.cx)throw new Error("polygon function requires x center");if(null==t.cy)throw new Error("polygon function requires y center");for(s=null!=t.degrees?t.degrees*Math.PI/180:0,h=2*Math.PI/t.verticies,i=t.dia/2,r="",c=null,x=null,u=null,p=null,e=d=0,b=t.verticies;b>=0?b>d:d>b;e=b>=0?++d:--d)a=s+e*h,o=i*Math.cos(a),n=i*Math.sin(a),Math.abs(o)<1e-9&&(o=0),Math.abs(n)<1e-9&&(n=0),l=t.cx+o,f=t.cy+n,(c>l||null===c)&&(c=l),(l>u||null===u)&&(u=l),(x>f||null===x)&&(x=f),(f>p||null===p)&&(p=f),r+=" "+l+","+f;return{shape:{polygon:{points:r.slice(1)}},bbox:[c,x,u,p]}},u=function(t){var e,r,i;if(null==t.x1)throw new Error("vector function requires start x");if(null==t.y1)throw new Error("vector function requires start y");if(null==t.x2)throw new Error("vector function requires end x");if(null==t.y2)throw new Error("vector function requires end y");if(null==t.width)throw new Error("vector function requires width");return e=Math.abs(Math.atan((t.y2-t.y1)/(t.x2-t.x1))),r=t.width/2*Math.sin(e),i=t.width/2*Math.cos(e),1e-7>r&&(r=0),1e-7>i&&(i=0),{shape:{line:{x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2,"stroke-width":t.width,"stroke-linecap":"butt"}},bbox:[Math.min(t.x1,t.x2)-r,Math.min(t.y1,t.y2)-i,Math.max(t.x1,t.x2)+r,Math.max(t.y1,t.y2)+i]}},i=function(t){if(null==t.width)throw new Error("lower left rect requires width");if(null==t.height)throw new Error("lower left rect requires height");if(null==t.x)throw new Error("lower left rectangle requires x");if(null==t.y)throw new Error("lower left rectangle requires y");return{shape:{rect:{x:t.x,y:t.y,width:t.width,height:t.height}},bbox:[t.x,t.y,t.x+t.width,t.y+t.height]}},n=function(t){var e,r,i,o,n,s,h,a,l,u,c,f,p;if(!(Array.isArray(t.points)&&t.points.length>1))throw new Error("outline function requires points array");for(s=null,u=null,n=null,l=null,r="",p=t.points,c=0,f=p.length;f>c;c++){if(e=p[c],!Array.isArray(e)||2!==e.length)throw new Error("outline function requires points array");i=e[0],h=e[1],(s>i||null===s)&&(s=i),(i>n||null===n)&&(n=i),(u>h||null===u)&&(u=h),(h>l||null===l)&&(l=h),r+=" "+i+","+h}if(o=t.points[t.points.length-1][0],a=t.points[t.points.length-1][1],o!==t.points[0][0]||a!==t.points[0][1])throw new RangeError("last point must match first point of outline");return{shape:{polygon:{points:r.slice(1)}},bbox:[s,u,n,l]}},o=function(t){var e,r,i;if(null==t.cx)throw new Error("moiré requires x center");if(null==t.cy)throw new Error("moiré requires y center");if(null==t.outerDia)throw new Error("moiré requires outer diameter");if(null==t.ringThx)throw new Error("moiré requires ring thickness");if(null==t.ringGap)throw new Error("moiré requires ring gap");if(null==t.maxRings)throw new Error("moiré requires max rings");if(null==t.crossLength)throw new Error("moiré requires crosshair length");if(null==t.crossThx)throw new Error("moiré requires crosshair thickness");for(i=[{line:{x1:t.cx-t.crossLength/2,y1:0,x2:t.cx+t.crossLength/2,y2:0,"stroke-width":t.crossThx,"stroke-linecap":"butt"}},{line:{x1:0,y1:t.cy-t.crossLength/2,x2:0,y2:t.cy+t.crossLength/2,"stroke-width":t.crossThx,"stroke-linecap":"butt"}}],e=(t.outerDia-t.ringThx)/2,r=0;e>=t.ringThx&&r<t.maxRings;)i.push({circle:{cx:t.cx,cy:t.cy,r:e,fill:"none","stroke-width":t.ringThx}}),r++,e-=t.ringThx+t.ringGap;return e+=.5*t.ringThx,e>0&&r<t.maxRings&&i.push({circle:{cx:t.cx,cy:t.cy,r:e}}),{shape:i,bbox:[Math.min(t.cx-t.crossLength/2,t.cx-t.outerDia/2),Math.min(t.cy-t.crossLength/2,t.cy-t.outerDia/2),Math.max(t.cx+t.crossLength/2,t.cx+t.outerDia/2),Math.max(t.cy+t.crossLength/2,t.cy+t.outerDia/2)]}},a=function(t){var e,r,i,o,n,s,h,a,u;if(null==t.cx)throw new Error("thermal requires x center");if(null==t.cy)throw new Error("thermal requires y center");if(null==t.outerDia)throw new Error("thermal requires outer diameter");if(null==t.innerDia)throw new Error("thermal requires inner diameter");if(null==t.gap)throw new Error("thermal requires gap");return r="thermal-mask-"+l(),n=(t.outerDia-t.innerDia)/2,i=t.outerDia/2,o=i-n/2,h=t.cx-i,s=t.cx+i,u=t.cy-i,a=t.cy+i,e=t.gap/2,{shape:[{mask:{id:r,_:[{circle:{cx:t.cx,cy:t.cy,r:i,"stroke-width":0,fill:"#fff"}},{rect:{x:h,y:-e,width:t.outerDia,height:t.gap,"stroke-width":0,fill:"#000"}},{rect:{x:-e,y:u,width:t.gap,height:t.outerDia,"stroke-width":0,fill:"#000"}}]}},{circle:{cx:t.cx,cy:t.cy,r:o,fill:"none","stroke-width":n,mask:"url(#"+r+")"}}],bbox:[h,u,s,a]}},e.exports={circle:r,rect:h,polygon:s,vector:u,lowerLeftRect:i,outline:n,moire:o,thermal:a}},{"./unique-id":14}],12:[function(t,e){var r,i,o,n,s,h,a,l,u;u=t("./unique-id"),o=t("./macro-tool"),l=t("./standard-tool"),i=Math.PI/2,s=3*i,h=2*Math.PI,a=1e-7,r="in",n=function(){function t(t,e,r){null==t&&(t=""),null!=e&&(this.reader=new e(t)),null!=r&&(this.parser=new r),this.macros={},this.tools={},this.currentTool="",this.defs=[],this.group={g:{_:[]}},this.polarity="D",this.current=[],this.stepRepeat={x:1,y:1,i:0,j:0},this.srOverClear=!1,this.srOverCurrent=[],this.units=null,this.mode=null,this.quad=null,this.lastOp=null,this.region=!1,this.done=!1,this.pos={x:0,y:0},this.path=[],this.attr={"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":0,stroke:"#000"},this.bbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0},this.layerBbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0}}return t.prototype.addTool=function(t,e){var r,i;if(null!=this.tools[t])throw new Error("cannot reassign tool "+t);return i=null!=e.macro?this.macros[e.macro].run(t,e.mods):l(t,e),this.tools[t]={trace:i.trace,pad:function(){var t,e,o,n;for(o=i.pad,n=[],t=0,e=o.length;e>t;t++)r=o[t],n.push(r);return n}(),flash:function(t,e){return{use:{x:t,y:e,"xlink:href":"#"+i.padId}}},bbox:function(t,e){return null==t&&(t=0),null==e&&(e=0),{xMin:t+i.bbox[0],yMin:e+i.bbox[1],xMax:t+i.bbox[2],yMax:e+i.bbox[3]}}},this.changeTool(t)},t.prototype.changeTool=function(t){var e;if(this.finishPath(),this.region)throw new Error("cannot change tool when in region mode");if(null!=this.tools[t])return this.currentTool=t;if(!(null!=(e=this.parser)?e.fmat:void 0))throw new Error("tool "+t+" is not defined")},t.prototype.command=function(t){var e,r,i,n,s,h,a,l;if(null!=t.macro)return r=new o(t.macro,this.parser.format.places),void(this.macros[r.name]=r);h=t.set;for(n in h){if(s=h[n],"units"===n&&null!=this.units&&null==(null!=(a=this.parser)?a.fmat:void 0))throw new Error("cannot redefine units");if("notation"===n&&null!=this.notation)throw new Error("cannot redefine notation");"region"===n&&this.finishPath(),"currentTool"===n?this.changeTool(s):this[n]=s}if(null!=t.tool){l=t.tool;for(e in l)i=l[e],this.addTool(e,i)}if(null!=t.op&&this.operate(t.op),null!=t["new"]){if(this.finishLayer(),null!=t["new"].layer)return this.polarity=t["new"].layer;if(null!=t["new"].sr)return this.finishSR(),this.stepRepeat=t["new"].sr}},t.prototype.plot=function(){for(var t,e;!this.done;){if(t=this.reader.nextBlock(),t===!1)throw new Error(null==(null!=(e=this.parser)?e.fmat:void 0)?"end of file encountered before required M02 command":"end of drill file encountered before M00/M30 command");this.command(this.parser.parseCommand(t))}return this.finish()},t.prototype.finish=function(){return this.finishPath(),this.finishLayer(),this.finishSR(),this.group.g.fill="currentColor",this.group.g.stroke="currentColor",this.group.g.transform="translate(0,"+(this.bbox.yMin+this.bbox.yMax)+") scale(1,-1)"},t.prototype.finishSR=function(){var t,e,r,i,o,n,s,h,a,l,c,f,p,x,d,b;if(this.srOverClear&&this.srOverCurrent){for(r="gerber-sr-mask_"+u(),e={mask:{color:"#000",id:r,_:[]}},e.mask._.push({rect:{fill:"#fff",x:this.bbox.xMin,y:this.bbox.yMin,width:this.bbox.xMax-this.bbox.xMin,height:this.bbox.yMax-this.bbox.yMin}}),o=s=0,c=this.stepRepeat.x*this.stepRepeat.i,f=this.stepRepeat.i;f>0?c>s:s>c;o=s+=f)for(n=h=0,p=this.stepRepeat.y*this.stepRepeat.j,x=this.stepRepeat.j;x>0?p>h:h>p;n=h+=x)for(d=this.srOverCurrent,a=0,l=d.length;l>a;a++)t=d[a],i={use:{}},0!==o&&(i.use.x=o),0!==n&&(i.use.y=n),i.use["xlink:href"]="#"+(null!=(b=t.C)?b:t.D),null!=t.D&&(i.use.fill="#fff"),e.mask._.push(i);return this.srOverClear=!1,this.srOverCurrent=[],this.defs.push(e),this.group.g.mask="url(#"+r+")"}},t.prototype.finishLayer=function(){var t,e,r,i,o,n,s,h,a,l,c,f,p,x,d,b;if(this.finishPath(),this.current.length){if(this.stepRepeat.x>1||this.stepRepeat.y>1){for(o="gerber-sr_"+u(),this.current=[{g:{id:o,_:this.current}}],(this.srOverClear||this.stepRepeat.i<this.layerBbox.xMax-this.layerBbox.xMin||this.stepRepeat.j<this.layerBbox.yMax-this.layerBbox.yMin)&&(i={},i[this.polarity]=o,this.srOverCurrent.push(i),"C"===this.polarity&&(this.srOverClear=!0,this.defs.push(this.current[0]))),h=l=0,x=this.stepRepeat.x;x>=0?x>l:l>x;h=x>=0?++l:--l)for(a=c=0,d=this.stepRepeat.y;d>=0?d>c:c>d;a=d>=0?++c:--c)(0!==h||0!==a)&&(n={use:{"xlink:href":"#"+o}},0!==h&&(n.use.x=h*this.stepRepeat.i),0!==a&&(n.use.y=a*this.stepRepeat.j),this.current.push(n));this.layerBbox.xMax+=(this.stepRepeat.x-1)*this.stepRepeat.i,this.layerBbox.yMax+=(this.stepRepeat.y-1)*this.stepRepeat.j}if(this.addBbox(this.layerBbox,this.bbox),this.layerBbox={xMin:1/0,yMin:1/0,xMax:-1/0,yMax:-1/0},"D"===this.polarity)if(null!=this.group.g.mask&&this.current.unshift(this.group),null==this.group.g.mask&&this.group.g._.length)for(b=this.current,f=0,p=b.length;p>f;f++)t=b[f],this.group.g._.push(t);else this.group={g:{_:this.current}};else"C"!==this.polarity||this.srOverClear||(r="gerber-mask_"+u(),s=this.bbox.xMax-this.bbox.xMin,e=this.bbox.yMax-this.bbox.yMin,this.current.unshift({rect:{x:this.bbox.xMin,y:this.bbox.yMin,width:s,height:e,fill:"#fff"}}),this.defs.push({mask:{id:r,color:"#000",_:this.current}}),this.group.g.mask="url(#"+r+")");return this.current=[]}},t.prototype.finishPath=function(){var t,e,r,i;if(this.path.length){if(e={path:{}},this.region)this.path.push("Z");else{i=this.tools[this.currentTool].trace;for(t in i)r=i[t],e.path[t]=r}return e.path.d=this.path,this.current.push(e),this.path=[]}},t.prototype.operate=function(t){var e,i,o,n,s,h,a,l,u,c,f,p,x,d,b;if("last"===t["do"]?t["do"]=this.lastOp:this.lastOp=t["do"],s=this.pos.x,h=this.pos.y,"I"===this.notation?(this.pos.x+=null!=(c=t.x)?c:0,this.pos.y+=null!=(f=t.y)?f:0):(this.pos.x=null!=(p=t.x)?p:this.pos.x,this.pos.y=null!=(x=t.y)?x:this.pos.y),i=this.pos.x,o=this.pos.y,a=this.tools[this.currentTool],null==this.units&&(this.units=null!=this.backupUnits?this.backupUnits:r),null==this.notation){if(null==(null!=(d=this.parser)?d.fmat:void 0))throw new Error("format has not been set");this.notation="A"}if("move"===t["do"]&&this.path.length)return this.path.push("M",i,o);if("flash"===t["do"]){if(this.finishPath(),this.region)throw new Error("cannot flash while in region mode");if(a.pad){for(b=a.pad,l=0,u=b.length;u>l;l++)n=b[l],this.defs.push(n);a.pad=!1}return this.current.push(a.flash(i,o)),this.addBbox(a.bbox(i,o),this.layerBbox)}if("int"===t["do"]){if(!this.region&&!a.trace)throw new Error(""+this.currentTool+" is not a strokable tool");return 0===this.path.length&&(this.path.push("M",s,h),e=this.region?{xMin:s,yMin:h,xMax:s,yMax:h}:a.bbox(s,h),this.addBbox(e,this.layerBbox)),null==this.mode&&(this.mode="i"),"i"===this.mode?this.drawLine(s,h,i,o):(null==t.i&&(t.i=0),null==t.j&&(t.j=0),this.drawArc(s,h,i,o,t.i,t.j))}},t.prototype.drawLine=function(t,e,r,o){var n,s,h,a,l,u,c,f,p,x,d,b,m;return b=this.tools[this.currentTool],n=this.region?{xMin:r,yMin:o,xMax:r,yMax:o}:b.bbox(r,o),this.addBbox(n,this.layerBbox),this.region||b.trace["stroke-width"]>=0?this.path.push("L",r,o):(c=b.pad[0].rect.width/2,u=b.pad[0].rect.height/2,f=t-c,p=t+c,x=e-u,d=e+u,s=r-c,h=r+c,a=o-u,l=o+u,m=Math.atan2(o-e,r-t),m>=0&&i>m?this.path.push("M",f,x,p,x,h,a,h,l,s,l,f,d,"Z"):m>=i&&m<Math.PI?this.path.push("M",f,x,p,x,p,d,h,l,s,l,s,a,"Z"):-Math.PI<=m&&-i>m?this.path.push("M",p,x,p,d,f,d,s,l,s,a,h,a,"Z"):m>=-i&&0>m?this.path.push("M",f,x,s,a,h,a,h,l,p,d,f,d,"Z"):void 0)},t.prototype.drawArc=function(t,e,r,o,n,l){var u,c,f,p,x,d,b,m,g,w,y,v,M,k,E,q,R,T,B,D,_,I,C,j,L,O,A,P,z;if(a=1.01*Math.pow(10,-((null!=(A=null!=(P=this.parser)?P.format.places[1]:void 0)?A:6)-1)),g=this.tools[this.currentTool],!this.region&&!g.trace["stroke-width"])throw Error("cannot stroke an arc with non-circular tool "+this.currentTool);if(null==this.quad)throw new Error("arc quadrant mode has not been set");for(d=Math.sqrt(Math.pow(n,2)+Math.pow(l,2)),m="cw"===this.mode?0:1,x=0,M=[],c=[[t+n,e+l]],"s"===this.quad&&c.push([t-n,e-l],[t-n,e+l],[t+n,e-l]),C=0,L=c.length;L>C;C++)u=c[C],p=Math.sqrt(Math.pow(u[0]-r,2)+Math.pow(u[1]-o,2)),Math.abs(d-p)<a&&M.push({x:u[0],y:u[1]});for(y=0,v=0,f=null,j=0,O=M.length;O>j&&(u=M[j],y=Math.atan2(o-u.y,r-u.x),0>y&&(y+=h),v=Math.atan2(e-u.y,t-u.x),0>v&&(v+=h),"cw"===this.mode&&y>v?v+=h:"ccw"===this.mode&&v>y&&(y+=h),w=Math.abs(y-v),"s"===this.quad&&i>=w?f=u:"m"===this.quad&&(w>=Math.PI&&(x=1),f={x:u.x,y:u.y}),null==f);j++);return null!=f?(b=this.region?0:g.bbox().xMax,"cw"===this.mode&&(z=[v,y],y=z[0],v=z[1]),R=v>0?h:0,_=i+(v>i?h:0),q=Math.PI+(v>Math.PI?h:0),D=s+(v>s?h:0),E=q>=v&&y>=q?f.x-d-b:Math.min(t,r)-b,k=R>=v&&y>=R?f.x+d+b:Math.max(t,r)+b,B=D>=v&&y>=D?f.y-d-b:Math.min(e,o)-b,T=_>=v&&y>=_?f.y+d+b:Math.max(e,o)+b,I=Math.abs(t-r)<a&&Math.abs(e-o)<a,"m"===this.quad&&I&&(this.path.push("A",d,d,0,0,m,r+2*n,o+2*l),E=f.x-d-b,B=f.y-d-b,k=f.x+d+b,T=f.y+d+b),this.path.push("A",d,d,0,x,m,r,o),"s"===this.quad&&I&&this.path.push("Z"),this.addBbox({xMin:E,yMin:B,xMax:k,yMax:T},this.layerBbox)):void 0},t.prototype.addBbox=function(t,e){return t.xMin<e.xMin&&(e.xMin=t.xMin),t.yMin<e.yMin&&(e.yMin=t.yMin),t.xMax>e.xMax&&(e.xMax=t.xMax),t.yMax>e.yMax?e.yMax=t.yMax:void 0},t}(),e.exports=n},{"./macro-tool":9,"./standard-tool":13,"./unique-id":14}],13:[function(t,e){var r,i,o;o=t("./unique-id"),r=t("./pad-shapes"),i=function(t,e){var i,n,s,h,a,l,u;if(l={pad:[],trace:!1},e.cx=0,e.cy=0,n="tool-"+t+"-pad-"+o(),u="",null!=e.dia&&null==e.verticies){if(null!=e.obround||null!=e.width||null!=e.height||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.dia<0)throw new RangeError(""+t+" circle diameter out of range ("+e.dia+"<0)"); | ||
u="circle",null==e.hole&&(l.trace={"stroke-width":e.dia,fill:"none"})}else if(null!=e.width&&null!=e.height){if(null!=e.dia||null!=e.verticies||null!=e.degrees)throw new Error("incompatible parameters for tool "+t);if(e.width<=0)throw new RangeError(""+t+" rect width out of range ("+e.width+"<=0)");if(e.height<=0)throw new RangeError(""+t+" rect height out of range ("+e.height+"<=0)");u="rect",null!=e.hole||e.obround||(l.trace={})}else{if(null==e.dia||null==e.verticies)throw new Error("unidentified standard tool shape");if(null!=e.obround||null!=e.width||null!=e.height)throw new Error("incompatible parameters for tool "+t);if(e.verticies<3||e.verticies>12)throw new RangeError(""+t+" polygon points out of range ("+e.verticies+"<3 or >12)]");u="polygon"}if(a=r[u](e),null!=e.hole){if(i=null,null!=e.hole.dia&&null==e.hole.width&&null==e.hole.height){if(!(e.hole.dia>=0))throw new RangeError(""+t+" hole diameter out of range ("+e.hole.dia+"<0)");i=r.circle({cx:e.cx,cy:e.cy,dia:e.hole.dia}),i=i.shape,i.circle.fill="#000"}else{if(null==e.hole.width||null==e.hole.height)throw new Error(""+t+" has invalid hole parameters");if(!(e.hole.width>=0))throw new RangeError(""+t+" hole width out of range ("+e.hole.width+"<0)");if(!(e.hole.height>=0))throw new RangeError(""+t+" hole height out of range");i=r.rect({cx:e.cx,cy:e.cy,width:e.hole.width,height:e.hole.height}),i=i.shape,i.rect.fill="#000"}h=n+"-mask",s={mask:{id:n+"-mask",_:[{rect:{x:a.bbox[0],y:a.bbox[1],width:a.bbox[2]-a.bbox[0],height:a.bbox[3]-a.bbox[1],fill:"#fff"}},i]}},a.shape[u].mask="url(#"+h+")",l.pad.push(s)}return n&&(a.shape[u].id=n),l.pad.push(a.shape),l.bbox=a.bbox,l.padId=n,l},e.exports=i},{"./pad-shapes":11,"./unique-id":14}],14:[function(t,e){var r,i;i=1e3,r=function(){return i++},e.exports=r},{}]},{},[1])(1)}); |
(function() { | ||
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
var getInteger; | ||
getInteger = require('./get-integer'); | ||
module.exports = function(coord, format) { | ||
var divisor, key, parse, result, val, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7; | ||
var key, parse, result, val, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7; | ||
if (coord == null) { | ||
@@ -21,21 +23,3 @@ return {}; | ||
if (val != null) { | ||
if (__indexOf.call(val, '.') >= 0) { | ||
result[key] = Number(val); | ||
} else { | ||
divisor = 1; | ||
if (val[0] === '+' || val[0] === '-') { | ||
if (val[0] === '-') { | ||
divisor = -1; | ||
} | ||
val = val.slice(1); | ||
} | ||
if (format.zero === 'L') { | ||
divisor *= Math.pow(10, format.places[1]); | ||
} else if (format.zero === 'T') { | ||
divisor *= Math.pow(10, val.length - format.places[0]); | ||
} else { | ||
throw new Error('invalid zero suppression format'); | ||
} | ||
result[key] = Number(val) / divisor; | ||
} | ||
result[key] = getInteger(val, format); | ||
} | ||
@@ -42,0 +26,0 @@ } |
(function() { | ||
var ABS_COMMAND, DrillParser, INCH_COMMAND, INC_COMMAND, METRIC_COMMAND, PLACES_BACKUP, ZERO_BACKUP, parseCoord, reCOORD; | ||
var ABS_COMMAND, DrillParser, INCH_COMMAND, INC_COMMAND, METRIC_COMMAND, PLACES_BACKUP, ZERO_BACKUP, getInteger, parseCoord, reCOORD; | ||
parseCoord = require('./coord-parser'); | ||
getInteger = require('./get-integer'); | ||
INCH_COMMAND = { | ||
@@ -67,6 +69,8 @@ 'FMAT,1': 'M70', | ||
if ((dia = (_ref1 = block.match(/C[\d\.]+(?=.*$)/)) != null ? _ref1[0] : void 0)) { | ||
dia = Number(dia.slice(1)); | ||
dia = dia.slice(1); | ||
command.tool = {}; | ||
command.tool[code] = { | ||
dia: dia | ||
dia: getInteger(dia, { | ||
places: this.format.places | ||
}) | ||
}; | ||
@@ -73,0 +77,0 @@ } else { |
(function() { | ||
var GerberParser, parseCoord, reCOORD; | ||
var GerberParser, getInteger, parseCoord, reCOORD; | ||
parseCoord = require('./coord-parser'); | ||
getInteger = require('./get-integer'); | ||
reCOORD = /([XYIJ][+-]?\d+){1,4}/g; | ||
@@ -49,12 +51,20 @@ | ||
hole = { | ||
width: +mods[1], | ||
height: +mods[2] | ||
width: getInteger(mods[1], { | ||
places: this.format.places | ||
}), | ||
height: getInteger(mods[2], { | ||
places: this.format.places | ||
}) | ||
}; | ||
} else if (mods.length > 1) { | ||
hole = { | ||
dia: +mods[1] | ||
dia: getInteger(mods[1], { | ||
places: this.format.places | ||
}) | ||
}; | ||
} | ||
c.tool[code] = { | ||
dia: +mods[0] | ||
dia: getInteger(mods[0], { | ||
places: this.format.places | ||
}) | ||
}; | ||
@@ -69,13 +79,23 @@ if (hole != null) { | ||
hole = { | ||
width: +mods[2], | ||
height: +mods[3] | ||
width: getInteger(mods[2], { | ||
places: this.format.places | ||
}), | ||
height: getInteger(mods[3], { | ||
places: this.format.places | ||
}) | ||
}; | ||
} else if (mods.length > 2) { | ||
hole = { | ||
dia: +mods[2] | ||
dia: getInteger(mods[2], { | ||
places: this.format.places | ||
}) | ||
}; | ||
} | ||
c.tool[code] = { | ||
width: +mods[0], | ||
height: +mods[1] | ||
width: getInteger(mods[0], { | ||
places: this.format.places | ||
}), | ||
height: getInteger(mods[1], { | ||
places: this.format.places | ||
}) | ||
}; | ||
@@ -92,12 +112,20 @@ if (shape === 'O') { | ||
hole = { | ||
width: +mods[3], | ||
height: +mods[4] | ||
width: getInteger(mods[3], { | ||
places: this.format.places | ||
}), | ||
height: getInteger(mods[4], { | ||
places: this.format.places | ||
}) | ||
}; | ||
} else if (mods.length > 3) { | ||
hole = { | ||
dia: +mods[3] | ||
dia: getInteger(mods[3], { | ||
places: this.format.places | ||
}) | ||
}; | ||
} | ||
c.tool[code] = { | ||
dia: +mods[0], | ||
dia: getInteger(mods[0], { | ||
places: this.format.places | ||
}), | ||
verticies: +mods[1] | ||
@@ -190,6 +218,10 @@ }; | ||
if (i != null) { | ||
c["new"].sr.i = +i; | ||
c["new"].sr.i = getInteger(i, { | ||
places: this.format.places | ||
}); | ||
} | ||
if (j != null) { | ||
c["new"].sr.j = +j; | ||
c["new"].sr.j = getInteger(j, { | ||
places: this.format.places | ||
}); | ||
} | ||
@@ -196,0 +228,0 @@ } |
@@ -22,3 +22,3 @@ | ||
module.exports = function(gerber, options) { | ||
var Parser, Reader, a, error, height, key, opts, p, val, width, xml, xmlObject, _ref; | ||
var Parser, Reader, a, error, height, key, opts, p, unitDivisor, val, width, xml, xmlObject, _ref, _ref1, _ref2, _ref3; | ||
if (options == null) { | ||
@@ -73,2 +73,3 @@ options = {}; | ||
} | ||
unitDivisor = Math.pow(10, (_ref = p.parser) != null ? (_ref1 = _ref.format) != null ? (_ref2 = _ref1.places) != null ? _ref2[1] : void 0 : void 0 : void 0) || 1; | ||
xml = { | ||
@@ -79,4 +80,4 @@ svg: { | ||
'xmlns:xlink': 'http://www.w3.org/1999/xlink', | ||
width: "" + width + p.units, | ||
height: "" + height + p.units, | ||
width: "" + (width / unitDivisor) + p.units, | ||
height: "" + (height / unitDivisor) + p.units, | ||
viewBox: [p.bbox.xMin, p.bbox.yMin, width, height], | ||
@@ -86,5 +87,5 @@ _: [] | ||
}; | ||
_ref = p.attr; | ||
for (a in _ref) { | ||
val = _ref[a]; | ||
_ref3 = p.attr; | ||
for (a in _ref3) { | ||
val = _ref3[a]; | ||
xml.svg[a] = val; | ||
@@ -91,0 +92,0 @@ } |
(function() { | ||
var MacroTool, calc, shapes, unique; | ||
var MacroTool, calc, getInteger, shapes, unique; | ||
@@ -10,4 +10,6 @@ shapes = require('./pad-shapes'); | ||
getInteger = require('./get-integer'); | ||
MacroTool = (function() { | ||
function MacroTool(blocks) { | ||
function MacroTool(blocks, numberFormat) { | ||
this.modifiers = {}; | ||
@@ -20,2 +22,5 @@ this.name = blocks[0].slice(2); | ||
this.bbox = [null, null, null, null]; | ||
this.format = { | ||
places: numberFormat | ||
}; | ||
} | ||
@@ -114,5 +119,5 @@ | ||
shape = shapes.circle({ | ||
dia: args[2], | ||
cx: args[3], | ||
cy: args[4] | ||
dia: getInteger(args[2], this.format), | ||
cx: getInteger(args[3], this.format), | ||
cy: getInteger(args[4], this.format) | ||
}); | ||
@@ -128,7 +133,7 @@ if (args[1] === 0) { | ||
shape = shapes.vector({ | ||
width: args[2], | ||
x1: args[3], | ||
y1: args[4], | ||
x2: args[5], | ||
y2: args[6] | ||
width: getInteger(args[2], this.format), | ||
x1: getInteger(args[3], this.format), | ||
y1: getInteger(args[4], this.format), | ||
x2: getInteger(args[5], this.format), | ||
y2: getInteger(args[6], this.format) | ||
}); | ||
@@ -146,6 +151,6 @@ if (args[7]) { | ||
shape = shapes.rect({ | ||
cx: args[4], | ||
cy: args[5], | ||
width: args[2], | ||
height: args[3] | ||
cx: getInteger(args[4], this.format), | ||
cy: getInteger(args[5], this.format), | ||
width: getInteger(args[2], this.format), | ||
height: getInteger(args[3], this.format) | ||
}); | ||
@@ -163,6 +168,6 @@ if (args[6]) { | ||
shape = shapes.lowerLeftRect({ | ||
x: args[4], | ||
y: args[5], | ||
width: args[2], | ||
height: args[3] | ||
x: getInteger(args[4], this.format), | ||
y: getInteger(args[5], this.format), | ||
width: getInteger(args[2], this.format), | ||
height: getInteger(args[3], this.format) | ||
}); | ||
@@ -181,3 +186,3 @@ if (args[6]) { | ||
for (i = _i = 3, _ref = 3 + 2 * args[2]; _i <= _ref; i = _i += 2) { | ||
points.push([args[i], args[i + 1]]); | ||
points.push([getInteger(args[i], this.format), getInteger(args[i + 1], this.format)]); | ||
} | ||
@@ -201,5 +206,5 @@ shape = shapes.outline({ | ||
shape = shapes.polygon({ | ||
cx: args[3], | ||
cy: args[4], | ||
dia: args[5], | ||
cx: getInteger(args[3], this.format), | ||
cy: getInteger(args[4], this.format), | ||
dia: getInteger(args[5], this.format), | ||
verticies: args[2], | ||
@@ -219,10 +224,10 @@ degrees: args[6] | ||
shape = shapes.moire({ | ||
cx: args[1], | ||
cy: args[2], | ||
outerDia: args[3], | ||
ringThx: args[4], | ||
ringGap: args[5], | ||
cx: getInteger(args[1], this.format), | ||
cy: getInteger(args[2], this.format), | ||
outerDia: getInteger(args[3], this.format), | ||
ringThx: getInteger(args[4], this.format), | ||
ringGap: getInteger(args[5], this.format), | ||
maxRings: args[6], | ||
crossThx: args[7], | ||
crossLength: args[8] | ||
crossThx: getInteger(args[7], this.format), | ||
crossLength: getInteger(args[8], this.format) | ||
}); | ||
@@ -245,7 +250,7 @@ if (args[9]) { | ||
shape = shapes.thermal({ | ||
cx: args[1], | ||
cy: args[2], | ||
outerDia: args[3], | ||
innerDia: args[4], | ||
gap: args[5] | ||
cx: getInteger(args[1], this.format), | ||
cy: getInteger(args[2], this.format), | ||
outerDia: getInteger(args[3], this.format), | ||
innerDia: getInteger(args[4], this.format), | ||
gap: getInteger(args[5], this.format) | ||
}); | ||
@@ -252,0 +257,0 @@ if (args[6]) { |
@@ -148,3 +148,3 @@ (function() { | ||
if (c.macro != null) { | ||
m = new Macro(c.macro); | ||
m = new Macro(c.macro, this.parser.format.places); | ||
this.macros[m.name] = m; | ||
@@ -504,3 +504,3 @@ return; | ||
Plotter.prototype.drawArc = function(sx, sy, ex, ey, i, j) { | ||
var c, cand, cen, dist, large, r, rTool, sweep, t, theta, thetaE, thetaS, validCen, xMax, xMin, xn, xp, yMax, yMin, yn, yp, _i, _j, _len, _len1, _ref, _ref1, _ref2; | ||
var c, cand, cen, dist, large, r, rTool, sweep, t, theta, thetaE, thetaS, validCen, xMax, xMin, xn, xp, yMax, yMin, yn, yp, zeroLength, _i, _j, _len, _len1, _ref, _ref1, _ref2; | ||
arcEps = 1.01 * Math.pow(10, -(((_ref = (_ref1 = this.parser) != null ? _ref1.format.places[1] : void 0) != null ? _ref : 6) - 1)); | ||
@@ -598,3 +598,4 @@ t = this.tools[this.currentTool]; | ||
} | ||
if (this.quad === 'm' && (Math.abs(sx - ex) < arcEps) && (Math.abs(sy - ey) < arcEps)) { | ||
zeroLength = (Math.abs(sx - ex) < arcEps) && (Math.abs(sy - ey) < arcEps); | ||
if (this.quad === 'm' && zeroLength) { | ||
this.path.push('A', r, r, 0, 0, sweep, ex + 2 * i, ey + 2 * j); | ||
@@ -607,2 +608,5 @@ xMin = cen.x - r - rTool; | ||
this.path.push('A', r, r, 0, large, sweep, ex, ey); | ||
if (this.quad === 's' && zeroLength) { | ||
this.path.push('Z'); | ||
} | ||
return this.addBbox({ | ||
@@ -609,0 +613,0 @@ xMin: xMin, |
{ | ||
"name": "gerber-to-svg", | ||
"version": "0.1.8", | ||
"version": "0.2.0", | ||
"description": "Gerber and NC drill file to SVG converter", | ||
@@ -5,0 +5,0 @@ "main": "lib/gerber-to-svg.js", |
Sorry, the diff of this file is too big to display
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
187787
23
4956