gerber-to-svg
Advanced tools
Comparing version 0.1.6 to 0.1.7
/* 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){e.exports=function(t,e){var r,i,n,o,s,h,l,a,u,c,f,p,x;if(null==t)return{};if(null==e.zero||null==e.places)throw new Error("format undefined");n={},o={},n.x=null!=(h=t.match(/X[+-]?\d+/))&&null!=(l=h[0])?l.slice(1):void 0,n.y=null!=(a=t.match(/Y[+-]?\d+/))&&null!=(u=a[0])?u.slice(1):void 0,n.i=null!=(c=t.match(/I[+-]?\d+/))&&null!=(f=c[0])?f.slice(1):void 0,n.j=null!=(p=t.match(/J[+-]?\d+/))&&null!=(x=p[0])?x.slice(1):void 0;for(i in n)if(s=n[i],null!=s){if(r=1,("+"===s[0]||"-"===s[0])&&("-"===s[0]&&(r=-1),s=s.slice(1)),"L"===e.zero)r*=Math.pow(10,e.places[1]);else{if("T"!==e.zero)throw new Error("invalid zero suppression format");r*=Math.pow(10,s.length-e.places[0])}o[i]=Number(s)/r}return o}},{}],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]-?\d*){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:t===n[this.fmat]||t.match(/INCH/)?(this.format.places=[2,4],i.set={units:"in"}):t===s||t.match(/METRIC/)?(this.format.places=[3,3],i.set={units:"mm"}):t===r?i.set={notation:"abs"}:t===o?i.set={notation:"inc"}:(e=null!=(x=t.match(/T\d+/))?x[0]:void 0)&&((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}),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;for(null==e.tool&&(e.tool={}),r=null!=(s=t.match(/^ADD\d{2,}/))?s[0].slice(2):void 0,h=t.slice(2+r.length).split(","),o=h[0],n=h[1],n=null!=n?n.split("X"):void 0;"0"===r[1];)r=r[0]+r.slice(2);switch(o){case"C":if(n.length>2?i={width:+n[1],height:+n[2]}:n.length>1&&(i={dia:+n[1]}),e.tool[r]={dia:+n[0]},null!=i)return e.tool[r].hole=i;break;case"R":case"O":if(n.length>3?i={width:+n[2],height:+n[3]}:n.length>2&&(i={dia:+n[2]}),e.tool[r]={width:+n[0],height:+n[1]},"O"===o&&(e.tool[r].obround=!0),null!=i)return e.tool[r].hole=i;break;case"P":if(n.length>4?i={width:+n[3],height:+n[4]}:n.length>3&&(i={dia:+n[3]}),e.tool[r]={dia:+n[0],verticies:+n[1]},n.length>2&&(e.tool[r].degrees=+n[2]),null!=i)return e.tool[r].hole=i;break;default:return e.tool[r]={macro:o,mods:null!=n?n:[]}}},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(o=Math.sin(e*Math.PI/180),r=Math.cos(e*Math.PI/180),Math.abs(o)<1e-9&&(o=0),Math.abs(r)<1e-9&&(r=0),n=[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]],u=[],l=0,a=n.length;a>l;l++)i=n[l],s=i[0]*r-i[1]*o,h=i[0]*o+i[1]*r,(null===this.bbox[0]||s<this.bbox[0])&&(this.bbox[0]=s),(null===this.bbox[1]||h<this.bbox[1])&&(this.bbox[1]=h),(null===this.bbox[2]||s>this.bbox[2])&&(this.bbox[2]=s),u.push(null===this.bbox[3]||h>this.bbox[3]?this.bbox[3]=h:void 0);return u}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){if(null==(null!=(e=this.parser)?e.fmat:void 0))throw new Error("end of file encountered before required M02 command");this.done=!0}else 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,A,O,P;if(l=1.01*Math.pow(10,-((null!=(A=null!=(O=this.parser)?O.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(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 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){e.exports=function(t,e){var r,i,n,o,s,h,l,a,u,c,f,p,x;if(null==t)return{};if(null==e.zero||null==e.places)throw new Error("format undefined");n={},o={},n.x=null!=(h=t.match(/X[+-]?\d+/))&&null!=(l=h[0])?l.slice(1):void 0,n.y=null!=(a=t.match(/Y[+-]?\d+/))&&null!=(u=a[0])?u.slice(1):void 0,n.i=null!=(c=t.match(/I[+-]?\d+/))&&null!=(f=c[0])?f.slice(1):void 0,n.j=null!=(p=t.match(/J[+-]?\d+/))&&null!=(x=p[0])?x.slice(1):void 0;for(i in n)if(s=n[i],null!=s){if(r=1,("+"===s[0]||"-"===s[0])&&("-"===s[0]&&(r=-1),s=s.slice(1)),"L"===e.zero)r*=Math.pow(10,e.places[1]);else{if("T"!==e.zero)throw new Error("invalid zero suppression format");r*=Math.pow(10,s.length-e.places[0])}o[i]=Number(s)/r}return o}},{}],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]-?\d*){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:"M30"===t||"M00"===t?i.set={done:!0}:t===n[this.fmat]||t.match(/INCH/)?(this.format.places=[2,4],i.set={units:"in"}):t===s||t.match(/METRIC/)?(this.format.places=[3,3],i.set={units:"mm"}):t===r?i.set={notation:"abs"}:t===o?i.set={notation:"inc"}:(e=null!=(x=t.match(/T\d+/))?x[0]:void 0)&&((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}),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,A,O,P;if(l=1.01*Math.pow(10,-((null!=(A=null!=(O=this.parser)?O.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(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)}); |
@@ -35,3 +35,3 @@ (function() { | ||
GerberParser.prototype.parseToolDef = function(p, c) { | ||
var code, hole, mods, shape, _ref, _ref1; | ||
var code, hole, m, mods, shape, _ref, _ref1; | ||
if (c.tool == null) { | ||
@@ -111,5 +111,15 @@ c.tool = {}; | ||
default: | ||
mods = (function() { | ||
var _i, _len, _ref2, _results; | ||
_ref2 = mods != null ? mods : []; | ||
_results = []; | ||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) { | ||
m = _ref2[_i]; | ||
_results.push(+m); | ||
} | ||
return _results; | ||
})(); | ||
return c.tool[code] = { | ||
macro: shape, | ||
mods: mods != null ? mods : [] | ||
mods: mods | ||
}; | ||
@@ -175,4 +185,4 @@ } | ||
c["new"].sr = { | ||
x: x, | ||
y: y | ||
x: +x, | ||
y: +y | ||
}; | ||
@@ -179,0 +189,0 @@ if (i != null) { |
@@ -329,3 +329,3 @@ (function() { | ||
MacroTool.prototype.addBbox = function(bbox, rotation) { | ||
var c, p, points, s, x, y, _i, _len, _results; | ||
var b, c, p, points, s, x, y, _i, _len; | ||
if (rotation == null) { | ||
@@ -357,3 +357,2 @@ rotation = 0; | ||
points = [[bbox[0], bbox[1]], [bbox[2], bbox[1]], [bbox[2], bbox[3]], [bbox[0], bbox[3]]]; | ||
_results = []; | ||
for (_i = 0, _len = points.length; _i < _len; _i++) { | ||
@@ -373,8 +372,15 @@ p = points[_i]; | ||
if (this.bbox[3] === null || y > this.bbox[3]) { | ||
_results.push(this.bbox[3] = y); | ||
} else { | ||
_results.push(void 0); | ||
this.bbox[3] = y; | ||
} | ||
} | ||
return _results; | ||
return this.bbox = (function() { | ||
var _j, _len1, _ref, _results; | ||
_ref = this.bbox; | ||
_results = []; | ||
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { | ||
b = _ref[_j]; | ||
_results.push(b === -0 ? 0 : b); | ||
} | ||
return _results; | ||
}).call(this); | ||
} | ||
@@ -381,0 +387,0 @@ }; |
{ | ||
"name": "gerber-to-svg", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Gerber and NC drill file to SVG converter", | ||
@@ -39,3 +39,3 @@ "main": "lib/gerber-to-svg.js", | ||
"gulp-coffee": "^2.0.1", | ||
"gulp-coveralls": "^0.1.2", | ||
"gulp-coveralls": "^0.1.2", | ||
"gulp-mocha": "^0.4.1", | ||
@@ -42,0 +42,0 @@ "gulp-rename": "^1.2.0", |
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
178489
4692