gerber-to-svg
Advanced tools
Comparing version 0.4.1 to 0.4.2
/* copyright 2015 by mike cousins and contributors; 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 r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.gerberToSvg=t()}}(function(){return function t(r,e,i){function o(s,l){if(!e[s]){if(!r[s]){var h="function"==typeof require&&require;if(!l&&h)return h(s,!0);if(n)return n(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var u=e[s]={exports:{}};r[s][0].call(u.exports,function(t){var e=r[s][1][t];return o(e?e:t)},u,u.exports,t,r,e,i)}return e[s].exports}for(var n="function"==typeof require&&require,s=0;s<i.length;s++)o(i[s]);return o}({1:[function(t,r){(function(e){var i,o,n,s,l,h,a,u;a=t("./obj-to-xml"),h=t("./plotter"),n=t("./drill-reader"),o=t("./drill-parser"),l=t("./gerber-reader"),s=t("./gerber-parser"),u=t("./svg-coord").factor,i={drill:!1,pretty:!1,object:!1,warnArr:null,places:null,zero:null,notation:null,units:null},r.exports=function(t,r){var c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R;null==r&&(r={}),b={};for(d in i)E=i[d],b[d]=E;for(d in r)E=r[d],b[d]=E;if("object"==typeof t){if(null!=t.svg)return a(t,{pretty:b.pretty});throw new Error("non SVG object cannot be converted to an SVG string")}w=null,(null!=b.places||null!=b.zero)&&(w={places:b.places,zero:b.zero}),b.drill?(v=new n(t),g=new o(w)):(v=new l(t),g=new s(w)),y=null,(null!=b.notation||null!=b.units)&&(y={notation:b.notation,units:b.units}),m=new h(v,g,y),x=null,k=null,Array.isArray(b.warnArr)&&(k="undefined"!=typeof window&&null!==window?window:e,null==k.console&&(k.console={}),x=k.console.warn,k.console.warn=function(t){return b.warnArr.push(t.toString())});try{R=m.plot()}catch(T){throw f=T,new Error("Error at line "+m.reader.line+" - "+f.message)}finally{null!=x&&null!=k&&(k.console.warn=x)}m.bbox.xMin>=m.bbox.xMax?(m.bbox.xMin=0,m.bbox.xMax=0,q=0):q=m.bbox.xMax-m.bbox.xMin,m.bbox.yMin>=m.bbox.yMax?(m.bbox.yMin=0,m.bbox.yMax=0,p=0):p=m.bbox.yMax-m.bbox.yMin,_={svg:{xmlns:"http://www.w3.org/2000/svg",version:"1.1","xmlns:xlink":"http://www.w3.org/1999/xlink",width:""+q/u+m.units,height:""+p/u+m.units,viewBox:[m.bbox.xMin,m.bbox.yMin,q,p],_:[]}},M=m.attr;for(c in M)E=M[c],_.svg[c]=E;return m.defs.length&&_.svg._.push({defs:{_:m.defs}}),m.group.g._.length&&_.svg._.push(m.group),b.object?_:a(_,{pretty:b.pretty})}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./drill-parser":3,"./drill-reader":4,"./gerber-parser":5,"./gerber-reader":6,"./obj-to-xml":9,"./plotter":12,"./svg-coord":14}],2:[function(t,r){var e;e=t("./svg-coord").get,r.exports=function(t,r){var i,o,n,s,l,h,a,u,c,f,p,d;if(null==t)return{};if(null==r.zero||null==r.places)throw new Error("format undefined");o={},p={},o.x=null!=(n=t.match(/X[+-]?[\d\.]+/))&&null!=(s=n[0])?s.slice(1):void 0,o.y=null!=(l=t.match(/Y[+-]?[\d\.]+/))&&null!=(h=l[0])?h.slice(1):void 0,o.i=null!=(a=t.match(/I[+-]?[\d\.]+/))&&null!=(u=a[0])?u.slice(1):void 0,o.j=null!=(c=t.match(/J[+-]?[\d\.]+/))&&null!=(f=c[0])?f.slice(1):void 0;for(i in o)d=o[i],null!=d&&(p[i]=e(d,r));return p}},{"./svg-coord":14}],3:[function(t,r){var e,i,o,n,s,l,h,a,u,c,f,p=function(t,r){function e(){this.constructor=t}for(var i in r)d.call(r,i)&&(t[i]=r[i]);return e.prototype=r.prototype,t.prototype=new e,t.__super__=r.prototype,t},d={}.hasOwnProperty;h=t("./parser"),c=t("./coord-parser"),u=t("./svg-coord").get,o={"FMAT,1":"M70","FMAT,2":"M72"},s="M71",e="G90",n="G91",f=/[XY]{1,2}/,a="L",l=[2,4],i=function(t){function r(){this.fmat="FMAT,2",r.__super__.constructor.call(this,arguments[0])}return p(r,t),r.prototype.parseCommand=function(t){var r,i,h,p,d,x,b,m,g,w,y,v;if(x={},";"===t[0])return x;if("FMAT,1"===t)this.fmat=t;else if("M30"===t||"M00"===t)x.set={done:!0};else if(t===o[this.fmat]||t.match(/INCH/))null==(r=this.format).places&&(r.places=[2,4]),x.set={units:"in"};else if(t===s||t.match(/METRIC/))null==(i=this.format).places&&(i.places=[3,3]),x.set={units:"mm"};else if(t===e)x.set={notation:"A"};else if(t===n)x.set={notation:"I"};else if(d=null!=(g=t.match(/T\d+/))?g[0]:void 0){for(;"0"===d[1];)d=d[0]+d.slice(2);(b=null!=(w=t.match(/C[\d\.]+(?=.*$)/))?w[0]:void 0)?(b=b.slice(1),x.tool={},x.tool[d]={dia:u(b,{places:this.format.places})}):x.set={currentTool:d}}if(t.match(/TZ/)?null==(h=this.format).zero&&(h.zero="L"):t.match(/LZ/)&&null==(p=this.format).zero&&(p.zero="T"),t.match(f)){x.op={"do":"flash"},null==this.format.zero&&(this.format.zero=a),null==this.format.places&&(this.format.places=l),y=c(t,this.format);for(m in y)v=y[m],x.op[m]=v}return x},r}(h),r.exports=i},{"./coord-parser":2,"./parser":11,"./svg-coord":14}],4:[function(t,r){var e;e=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}(),r.exports=e},{}],5:[function(t,r){var e,i,o,n,s,l=function(t,r){function e(){this.constructor=t}for(var i in r)h.call(r,i)&&(t[i]=r[i]);return e.prototype=r.prototype,t.prototype=new e,t.__super__=r.prototype,t},h={}.hasOwnProperty;i=t("./parser"),n=t("./coord-parser"),o=t("./svg-coord").get,s=/([XYIJ][+-]?\d+){1,4}/g,e=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return l(r,t),r.prototype.parseFormat=function(t,r){var e,i,o,n,s;if(s="L"===t[2]||"T"===t[2]?t[2]:null,o="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&&(n=[+t[5],+t[6]]),null==n||null==o||null==s)throw new Error("invalid format specification");return null==(e=this.format).zero&&(e.zero=s),null==(i=this.format).places&&(i.places=n),null==r.set&&(r.set={}),r.set.notation=o},r.prototype.parseToolDef=function(t,r){var e,i,n,s,l,h,a;for(null==r.tool&&(r.tool={}),e=null!=(l=t.match(/^ADD\d{2,}/))?l[0].slice(2):void 0,h=t.slice(2+e.length).split(","),a=h[0],s=h[1],s=null!=s?s.split("X"):void 0;"0"===e[1];)e=e[0]+e.slice(2);switch(a){case"C":if(s.length>2?i={width:o(s[1],{places:this.format.places}),height:o(s[2],{places:this.format.places})}:s.length>1&&(i={dia:o(s[1],{places:this.format.places})}),r.tool[e]={dia:o(s[0],{places:this.format.places})},null!=i)return r.tool[e].hole=i;break;case"R":case"O":if(s.length>3?i={width:o(s[2],{places:this.format.places}),height:o(s[3],{places:this.format.places})}:s.length>2&&(i={dia:o(s[2],{places:this.format.places})}),r.tool[e]={width:o(s[0],{places:this.format.places}),height:o(s[1],{places:this.format.places})},"O"===a&&(r.tool[e].obround=!0),null!=i)return r.tool[e].hole=i;break;case"P":if(s.length>4?i={width:o(s[3],{places:this.format.places}),height:o(s[4],{places:this.format.places})}:s.length>3&&(i={dia:o(s[3],{places:this.format.places})}),r.tool[e]={dia:o(s[0],{places:this.format.places}),verticies:+s[1]},s.length>2&&(r.tool[e].degrees=+s[2]),null!=i)return r.tool[e].hole=i;break;default:return s=function(){var t,r,e,i;for(e=null!=s?s:[],i=[],t=0,r=e.length;r>t;t++)n=e[t],i.push(+n);return i}(),r.tool[e]={macro:a,mods:s}}},r.prototype.parseCommand=function(t){var r,e,i,l,h,a,u,c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R,T,B,A;if(null==t&&(t={}),e={},x=t.param)for(u=0,c=x.length;c>u;u++)switch(d=x[u],i=d.slice(0,2)){case"FS":this.parseFormat(d,e);break;case"MO":if(R=d.slice(2,4),null==e.set&&(e.set={}),"IN"===R)e.set.units="in";else{if("MM"!==R)throw new Error(d+" is an invalid units setting");e.set.units="mm"}break;case"AD":this.parseToolDef(d,e);break;case"AM":return{macro:x};case"LP":if(null==e["new"]&&(e["new"]={}),("D"===d[2]||"C"===d[2])&&(e["new"].layer=d[2]),null==e["new"].layer)throw new Error("invalid level polarity");break;case"SR":if(null==e["new"]&&(e["new"]={}),B=null!=(b=null!=(m=d.match(/X[+-]?[\d\.]+/))?m[0].slice(1):void 0)?b:1,A=null!=(g=null!=(w=d.match(/Y[+-]?[\d\.]+/))?w[0].slice(1):void 0)?g:1,h=null!=(y=d.match(/I[+-]?[\d\.]+/))?y[0].slice(1):void 0,a=null!=(v=d.match(/J[+-]?[\d\.]+/))?v[0].slice(1):void 0,1>B||1>A||B>1&&(null==h||0>h)||A>1&&(null==a||0>a))throw new Error("invalid step repeat");e["new"].sr={x:+B,y:+A},null!=h&&(e["new"].sr.i=o(h,{places:this.format.places})),null!=a&&(e["new"].sr.j=o(a,{places:this.format.places}))}else if(t=t.block){if("M02"===t)return{set:{done:!0}};if("G"===t[0])switch(i=null!=(M=t.slice(1).match(/^\d{1,2}/))?M[0]:void 0){case"4":case"04":return{};case"1":case"01":case"2":case"02":case"3":case"03":i=i[i.length-1],f="1"===i?"i":"2"===i?"cw":"ccw",e.set={mode:f};break;case"36":case"37":e.set={region:"36"===i};break;case"70":case"71":e.set={backupUnits:"70"===i?"in":"mm"};break;case"74":case"75":e.set={quad:"74"===i?"s":"m"}}if(l=n(null!=(k=t.match(s))?k[0]:void 0,this.format),p=(null!=(E=t.match(/D0?[123]$/))?E[0]:void 0)||Object.keys(l).length){null!=p&&(p=p[p.length-1]),p=function(){switch(p){case"1":return"int";case"2":return"move";case"3":return"flash";default:return"last"}}(),e.op={"do":p};for(r in l)T=l[r],e.op[r]=T}else(_=null!=(q=t.match(/D\d+$/))?q[0]:void 0)&&(e.set={currentTool:_})}return e},r}(i),r.exports=e},{"./coord-parser":2,"./parser":11,"./svg-coord":14}],6:[function(t,r){var e;e=function(){function t(t){this.gerberFile=null!=t?t:"",this.line=0,this.charIndex=0,this.end=this.gerberFile.length}return t.prototype.nextBlock=function(){var t,r,e;if(this.index>=this.end)return!1;for(r="",e=!1,0===this.line&&this.line++;!(this.charIndex>=this.end);)if(t=this.gerberFile[this.charIndex++],"%"===t){if(e)return{param:e};e=[]}else if("*"===t){if(!e)return{block:r};e.push(r),r=""}else"\n"===t?this.line++:t>=" "&&"~">=t&&(r+=t);return!1},t.prototype.getLine=function(){return this.line},t}(),r.exports=e},{}],7:[function(t,r){var e,i,o,n,s,l;i=/[\+\-\/xX\(\)]/,e=/[\$\d\.]+/,o=new RegExp("("+i.source+")|("+e.source+")","g"),l=function(t){var r;return r=t.match(o)},n=function(t){return e.test(t)},s=function(t){var r,e,i,o,s,h,a;return a=l(t),e=0,h=function(){return a[e]},r=function(t){return t===h()?e++:void 0},s=function(){var t,e;if(e=h(),r(e),n(e))t={type:"n",val:e};else{if("("!==e)throw new Error(e+" is unexpected in an arithmetic string");if(t=i(),")"!==h())throw new Error("expected ')'");r(")")}return t},o=function(){var t,e,i;for(t=s(),i=h();"x"===i||"/"===i||"X"===i;)r(i),"X"===i&&(i="x"),e=s(),t={type:i,left:t,right:e},i=h();return t},(i=function(){var t,e,i;for(t=o(),i=h();"+"===i||"-"===i;)r(i),e=o(),t={type:i,left:t,right:e},i=h();return t})()},r.exports={tokenize:l,isNumber:n,parse:s}},{}],8:[function(t,r){var e,i,o,n,s;n=t("./pad-shapes"),i=t("./macro-calc"),s=t("./unique-id"),o=t("./svg-coord").get,e=function(){function t(t,r){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:r}}return t.prototype.run=function(t,r){var e,i,o,n,l,h,a,u,c,f,p,d,x,b,m,g,w,y,v;for(null==r&&(r=[]),this.lastExposure=null,this.shapes=[],this.masks=[],this.bbox=[null,null,null,null],this.modifiers={},o=n=0,a=r.length;a>n;o=++n)p=r[o],this.modifiers["$"+(o+1)]=p;for(m=this.blocks,l=0,u=m.length;u>l;l++)e=m[l],this.runBlock(e);for(b="tool-"+t+"-pad-"+s(),x=[],g=this.masks,h=0,c=g.length;c>h;h++)p=g[h],x.push(p);if(this.shapes.length>1){for(i={id:b,_:[]},w=this.shapes,d=0,f=w.length;f>d;d++)y=w[d],i._.push(y);x=[{g:i}]}else 1===this.shapes.length&&(v=Object.keys(this.shapes[0])[0],this.shapes[0][v].id=b,x.push(this.shapes[0]));return{pad:x,padId:b,bbox:this.bbox,trace:!1}},t.prototype.runBlock=function(t){var r,e,i,o,n,s,l,h;switch(t[0]){case"$":return s=null!=(l=t.match(/^\$\d+(?=\=)/))?l[0]:void 0,h=t.slice(1+s.length),this.modifiers[s]=this.getNumber(h);case"1":case"2":case"20":case"21":case"22":case"4":case"5":case"6":case"7":for(e=t.split(","),i=o=0,n=e.length;n>o;i=++o)r=e[i],e[i]=this.getNumber(r);return this.primitive(e);default:if("0"!==t[0])throw new Error("'"+t+"' unrecognized tool macro block")}},t.prototype.primitive=function(t){var r,e,i,l,h,a,u,c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R,T,B,A,D,L;switch(b=!1,A=!1,L=null,t[0]){case 1:L=n.circle({dia:o(t[2],this.format),cx:o(t[3],this.format),cy:o(t[4],this.format)}),0===t[1]?b=!0:this.addBbox(L.bbox);break;case 2:case 20:L=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]&&(L.shape.line.transform="rotate("+t[7]+")"),0===t[1]?b=!0:this.addBbox(L.bbox,t[7]);break;case 21:L=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]&&(L.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?b=!0:this.addBbox(L.bbox,t[6]);break;case 22:L=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]&&(L.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?b=!0:this.addBbox(L.bbox,t[6]);break;case 4:for(y=[],e=i=3,M=3+2*t[2];M>=i;e=i+=2)y.push([o(t[e],this.format),o(t[e+1],this.format)]);L=n.outline({points:y}),(B=t[t.length-1])&&(L.shape.polygon.transform="rotate("+B+")"),0===t[1]?b=!0:this.addBbox(L.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");L=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]?b=!0:this.addBbox(L.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(L=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(k=L.shape,l=0,u=k.length;u>l;l++)D=k[l],null!=D.line&&(D.line.transform="rotate("+t[9]+")");this.addBbox(L.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(L=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(E=L.shape,a=0,c=E.length;c>a;a++)if(D=E[a],null!=D.mask)for(q=D.mask._,g=0,f=q.length;f>g;g++)x=q[g],null!=x.rect&&(x.rect.transform="rotate("+t[6]+")");this.addBbox(L.bbox,t[6]);break;default:throw new Error(t[0]+" is not a valid primitive code")}if(b){for(h in L.shape)L.shape[h].fill="#000";if(0!==this.lastExposure){if(this.lastExposure=0,m="macro-"+this.name+"-mask-"+s(),x={mask:{id:m}},x.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(h in this.shapes[0])this.shapes[0][h].mask="url(#"+m+")";else if(this.shapes.length>1){for(r={mask:"url(#"+m+")",_:[]},_=this.shapes,w=0,p=_.length;p>w;w++)D=_[w],r._.push(D);this.shapes=[{g:r}]}this.masks.push(x)}return this.masks[this.masks.length-1].mask._.push(L.shape)}if(this.lastExposure=1,Array.isArray(L.shape)){for(R=L.shape,T=[],v=0,d=R.length;d>v;v++)D=R[v],T.push(null!=D.mask?this.masks.push(D):this.shapes.push(D));return T}return this.shapes.push(L.shape)},t.prototype.addBbox=function(t,r){var e,i,o,n,s,l,h,a,u;if(null==r&&(r=0),r){for(h=Math.sin(r*Math.PI/180),i=Math.cos(r*Math.PI/180),Math.abs(h)<1e-9&&(h=0),Math.abs(i)<1e-9&&(i=0),l=[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]],o=0,n=l.length;n>o;o++)s=l[o],a=s[0]*i-s[1]*h,u=s[0]*h+s[1]*i,(null===this.bbox[0]||a<this.bbox[0])&&(this.bbox[0]=a),(null===this.bbox[1]||u<this.bbox[1])&&(this.bbox[1]=u),(null===this.bbox[2]||a>this.bbox[2])&&(this.bbox[2]=a),(null===this.bbox[3]||u>this.bbox[3])&&(this.bbox[3]=u);return this.bbox=function(){var t,r,i,o;for(i=this.bbox,o=[],t=0,r=i.length;r>t;t++)e=i[t],o.push(e===-0?0:e);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}(),r.exports=e},{"./macro-calc":7,"./pad-shapes":10,"./svg-coord":14,"./unique-id":15}],9:[function(t,r){var e,i,o,n;n=function(t,r){var e;if(e="",0===r)return"";for(;r>1;)1&r&&(e+=t),r>>=1,t+=t;return e+t},e="_",i=" ",o=function(t,r){var s,l,h,a,u,c,f,p,d,x,b,m,g,w,y,v,M,k,E;if(null==r&&(r={}),m=r.pretty,c=null!=(g=r.indent)?g:0,l=null!=(w=r.maxDec)?w:!1,h=function(t){return"number"==typeof t?Number(t.toFixed(l)):t},x=m?"\n":"",v=x?"string"==typeof m?m:i:"",v=n(v,c),E="","function"==typeof t&&(t=t()),Array.isArray(t))for(u=f=0,d=t.length;d>f;u=++f)b=t[u],E+=(0!==u?x:"")+o(b,r);else if("object"==typeof t){if(s=!1,a=Object.keys(t)[0],null!=a){E=v+"<"+a,"function"==typeof t[a]&&(t[a]=t[a]()),y=t[a];for(p in y)k=y[p],"function"==typeof k&&(k=k()),p===e?s=k:(Array.isArray(k)&&(l&&(k=function(){var t,r,e;for(e=[],t=0,r=k.length;r>t;t++)M=k[t],e.push(h(M));return e}()),k=k.join(" ")),l&&(k=h(k)),E+=" "+p+'="'+k+'"');s&&(E+=">"+x+o(s,{pretty:m,indent:c+1})),E+=null!=t[a]._?""+x+v+"</"+a+">":"/>"}}else E+=t+" ";return E},r.exports=o},{}],10:[function(t,r){var e,i,o,n,s,l,h,a,u;a=t("./unique-id"),e=function(t){var r;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 r=t.dia/2,{shape:{circle:{cx:t.cx,cy:t.cy,r:r}},bbox:[t.cx-r,t.cy-r,t.cx+r,t.cy+r]}},l=function(t){var r,e,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,e={shape:{rect:{x:i,y:o,width:t.width,height:t.height}},bbox:[i,o,i+t.width,o+t.height]},t.obround&&(r=.5*Math.min(t.width,t.height),e.shape.rect.rx=r,e.shape.rect.ry=r),e},s=function(t){var r,e,i,o,n,s,l,h,a,u,c,f,p,d,x,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(h=null!=t.degrees?t.degrees*Math.PI/180:0,a=2*Math.PI/t.verticies,o=t.dia/2,i="",p=null,b=null,f=null,x=null,r=e=0,n=t.verticies;n>=0?n>e:e>n;r=n>=0?++e:--e)u=h+r*a,s=o*Math.cos(u),l=o*Math.sin(u),Math.abs(s)<1e-9&&(s=0),Math.abs(l)<1e-9&&(l=0),c=t.cx+s,d=t.cy+l,(p>c||null===p)&&(p=c),(c>f||null===f)&&(f=c),(b>d||null===b)&&(b=d),(d>x||null===x)&&(x=d),i+=" "+c+","+d;return{shape:{polygon:{points:i.slice(1)}},bbox:[p,b,f,x]}},u=function(t){var r,e,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 r=Math.abs(Math.atan((t.y2-t.y1)/(t.x2-t.x1))),e=t.width/2*Math.sin(r),i=t.width/2*Math.cos(r),1e-7>e&&(e=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)-e,Math.min(t.y1,t.y2)-i,Math.max(t.x1,t.x2)+e,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 r,e,i,o,n,s,l,h,a,u,c,f,p;if(!(Array.isArray(t.points)&&t.points.length>1))throw new Error("outline function requires points array");for(a=null,p=null,h=null,f=null,o="",n=t.points,r=0,e=n.length;e>r;r++){if(i=n[r],!Array.isArray(i)||2!==i.length)throw new Error("outline function requires points array");s=i[0],u=i[1],(a>s||null===a)&&(a=s),(s>h||null===h)&&(h=s),(p>u||null===p)&&(p=u),(u>f||null===f)&&(f=u),o+=" "+s+","+u}if(l=t.points[t.points.length-1][0],c=t.points[t.points.length-1][1],l!==t.points[0][0]||c!==t.points[0][1])throw new RangeError("last point must match first point of outline");return{shape:{polygon:{points:o.slice(1)}},bbox:[a,p,h,f]}},o=function(t){var r,e,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"}}],r=(t.outerDia-t.ringThx)/2,e=0;r>=t.ringThx&&e<t.maxRings;)i.push({circle:{cx:t.cx,cy:t.cy,r:r,fill:"none","stroke-width":t.ringThx}}),e++,r-=t.ringThx+t.ringGap;return r+=.5*t.ringThx,r>0&&e<t.maxRings&&i.push({circle:{cx:t.cx,cy:t.cy,r:r}}),{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)]}},h=function(t){var r,e,i,o,n,s,l,h,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 e="thermal-mask-"+a(),n=(t.outerDia-t.innerDia)/2,i=t.outerDia/2,o=i-n/2,l=t.cx-i,s=t.cx+i,u=t.cy-i,h=t.cy+i,r=t.gap/2,{shape:[{mask:{id:e,_:[{circle:{cx:t.cx,cy:t.cy,r:i,fill:"#fff"}},{rect:{x:l,y:-r,width:t.outerDia,height:t.gap,fill:"#000"}},{rect:{x:-r,y:u,width:t.gap,height:t.outerDia,fill:"#000"}}]}},{circle:{cx:t.cx,cy:t.cy,r:o,fill:"none","stroke-width":n,mask:"url(#"+e+")"}}],bbox:[l,u,s,h]}},r.exports={circle:e,rect:l,polygon:s,vector:u,lowerLeftRect:i,outline:n,moire:o,thermal:h}},{"./unique-id":15}],11:[function(t,r){var e;e=function(){function t(t){var r,e;if(null==t&&(t={}),this.format={zero:null!=(r=t.zero)?r:null,places:null!=(e=t.places)?e:null},null!=this.format.places&&(!Array.isArray(this.format.places)||2!==this.format.places.length||"number"!=typeof this.format.places[0]||"number"!=typeof this.format.places[1]))throw new Error("parser places format must be an array of two numbers");if(null!=this.format.zero&&("string"!=typeof this.format.zero||"L"!==this.format.zero&&"T"!==this.format.zero))throw new Error("parser zero format must be either 'L' or 'T'")}return t}(),r.exports=e},{}],12:[function(t,r){var e,i,o,n,s,l,h,a,u;u=t("./unique-id"),o=t("./macro-tool"),a=t("./standard-tool"),h=t("./svg-coord").factor,i=Math.PI/2,s=3*i,l=2*Math.PI,e="in",n=function(){function t(t,r,e){var i,o;this.reader=t,this.parser=r,null==e&&(e={}),this.units=null!=(i=e.units)?i:null,this.notation=null!=(o=e.notation)?o:null,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.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,r){var e,i;if(null!=this.tools[t])throw new Error("cannot reassign tool "+t);return i=null!=r.macro?this.macros[r.macro].run(t,r.mods):a(t,r),this.tools[t]={trace:i.trace,pad:function(){var t,r,o,n;for(o=i.pad,n=[],t=0,r=o.length;r>t;t++)e=o[t],n.push(e);return n}(),flash:function(t,r){return{use:{x:t,y:r,"xlink:href":"#"+i.padId}}},flashed:!1,bbox:function(t,r){return null==t&&(t=0),null==r&&(r=0),{xMin:t+i.bbox[0],yMin:r+i.bbox[1],xMax:t+i.bbox[2],yMax:r+i.bbox[3]}}},this.changeTool(t)},t.prototype.changeTool=function(t){var r;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!=(r=this.parser)?r.fmat:void 0))throw new Error("tool "+t+" is not defined")},t.prototype.command=function(t){var r,e,i,n,s,l,h;if(null!=t.macro)return e=new o(t.macro,this.parser.format.places),void(this.macros[e.name]=e);n=t.set;for(l in n)switch(h=n[l],"region"===l&&this.finishPath(),l){case"currentTool":this.changeTool(h);break;case"units":case"notation":null==this[l]&&(this[l]=h);break;default:this[l]=h}if(null!=t.tool){s=t.tool;for(r in s)i=s[r],this.addTool(r,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,r;!this.done;){if(t=this.reader.nextBlock(),t===!1)throw new Error(null==(null!=(r=this.parser)?r.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,r,e,i,o,n,s,l,h,a,c,f,p,d,x,b;if(this.srOverClear&&this.srOverCurrent){for(n="gerber-sr-mask_"+u(),o={mask:{color:"#000",id:n,_:[]}},o.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}}),x=t=0,l=this.stepRepeat.x*this.stepRepeat.i,h=this.stepRepeat.i;h>0?l>t:t>l;x=t+=h)for(b=r=0,a=this.stepRepeat.y*this.stepRepeat.j,c=this.stepRepeat.j;c>0?a>r:r>a;b=r+=c)for(f=this.srOverCurrent,s=0,i=f.length;i>s;s++)e=f[s],d={use:{}},0!==x&&(d.use.x=x),0!==b&&(d.use.y=b),d.use["xlink:href"]="#"+(null!=(p=e.C)?p:e.D),null!=e.D&&(d.use.fill="#fff"),o.mask._.push(d);return this.srOverClear=!1,this.srOverCurrent=[],this.defs.push(o),this.group.g.mask="url(#"+n+")"}},t.prototype.finishLayer=function(){var t,r,e,i,o,n,s,l,h,a,c,f,p,d,x,b;if(this.finishPath(),this.current.length){if(this.stepRepeat.x>1||this.stepRepeat.y>1){for(f="gerber-sr_"+u(),this.current=[{g:{id:f,_:this.current}}],(this.srOverClear||this.stepRepeat.i<this.layerBbox.xMax-this.layerBbox.xMin||this.stepRepeat.j<this.layerBbox.yMax-this.layerBbox.yMin)&&(l={},l[this.polarity]=f,this.srOverCurrent.push(l),"C"===this.polarity&&(this.srOverClear=!0,this.defs.push(this.current[0]))),x=i=0,h=this.stepRepeat.x;h>=0?h>i:i>h;x=h>=0?++i:--i)for(b=o=0,a=this.stepRepeat.y;a>=0?a>o:o>a;b=a>=0?++o:--o)(0!==x||0!==b)&&(p={use:{"xlink:href":"#"+f}},0!==x&&(p.use.x=x*this.stepRepeat.i),0!==b&&(p.use.y=b*this.stepRepeat.j),this.current.push(p));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(c=this.current,s=0,n=c.length;n>s;s++)t=c[s],this.group.g._.push(t);else this.group={g:{_:this.current}};else"C"!==this.polarity||this.srOverClear||(e="gerber-mask_"+u(),d=this.bbox.xMax-this.bbox.xMin,r=this.bbox.yMax-this.bbox.yMin,this.current.unshift({rect:{x:this.bbox.xMin,y:this.bbox.yMin,width:d,height:r,fill:"#fff"}}),this.defs.push({mask:{id:e,color:"#000",_:this.current}}),this.group.g.mask="url(#"+e+")");return this.current=[]}},t.prototype.finishPath=function(){var t,r,e,i;if(this.path.length){if(r={path:{}},this.region)this.path.push("Z");else{e=this.tools[this.currentTool].trace;for(t in e)i=e[t],r.path[t]=i}return r.path.d=this.path,this.current.push(r),this.path=[]}},t.prototype.operate=function(t){var r,i,o,n,s,l,h,a,u,c,f,p,d,x,b,m,g;if("last"===t["do"]?t["do"]=this.lastOp:this.lastOp=t["do"],b=this.pos.x,m=this.pos.y,"I"===this.notation?(this.pos.x+=null!=(l=t.x)?l:0,this.pos.y+=null!=(h=t.y)?h:0):(this.pos.x=null!=(a=t.x)?a:this.pos.x,this.pos.y=null!=(u=t.y)?u:this.pos.y),i=this.pos.x,o=this.pos.y,g=this.tools[this.currentTool],null==this.units&&(this.units=null!=this.backupUnits?this.backupUnits:e),null==this.notation){if(null==(null!=(c=this.parser)?c.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(!g.flashed){for(f=g.pad,n=0,s=f.length;s>n;n++)x=f[n],this.defs.push(x);g.flashed=!0}return this.current.push(g.flash(i,o)),this.addBbox(g.bbox(i,o),this.layerBbox)}if("int"===t["do"]){if(!this.region&&!g.trace)throw new Error(this.currentTool+" is not a strokable tool");return 0===this.path.length&&(this.path.push("M",b,m),r=this.region?{xMin:b,yMin:m,xMax:b,yMax:m}:g.bbox(b,m),this.addBbox(r,this.layerBbox)),null==this.mode&&(this.mode="i"),"i"===this.mode?this.drawLine(b,m,i,o):this.drawArc(b,m,i,o,null!=(p=t.i)?p:0,null!=(d=t.j)?d:0)}},t.prototype.drawLine=function(t,r,e,o){var n,s,l,h,a,u,c,f,p,d,x,b,m;return b=this.tools[this.currentTool],n=this.region?{xMin:e,yMin:o,xMax:e,yMax:o}:b.bbox(e,o),this.addBbox(n,this.layerBbox),this.region||b.trace["stroke-width"]>=0?this.path.push("L",e,o):(c=b.pad[0].rect.width/2,u=b.pad[0].rect.height/2,f=t-c,p=t+c,d=r-u,x=r+u,s=e-c,l=e+c,h=o-u,a=o+u,m=Math.atan2(o-r,e-t),m>=0&&i>m?this.path.push("M",f,d,p,d,l,h,l,a,s,a,f,x,"Z"):m>=i&&m<=Math.PI?this.path.push("M",f,d,p,d,p,x,l,a,s,a,s,h,"Z"):-Math.PI<=m&&-i>m?this.path.push("M",p,d,p,x,f,x,s,a,s,h,l,h,"Z"):m>=-i&&0>m?this.path.push("M",f,d,s,h,l,h,l,a,p,x,f,x,"Z"):void 0)},t.prototype.drawArc=function(t,r,e,o,n,a){var u,c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R,T,B,A,D,L,I,O,z,C,j,P,N;if(u=1.5*h*Math.pow(10,-1*(null!=(M=null!=(k=this.parser)?k.format.places[1]:void 0)?M:7)),_=this.tools[this.currentTool],!this.region&&!_.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(y=Math.sqrt(Math.pow(n,2)+Math.pow(a,2)),q="cw"===this.mode?0:1,m=0,A=[],f=[[t+n,r+a]],"s"===this.quad&&f.push([t-n,r-a],[t-n,r+a],[t+n,r-a]),x=0,g=f.length;g>x;x++)c=f[x],d=Math.sqrt(Math.pow(c[0]-e,2)+Math.pow(c[1]-o,2)),Math.abs(y-d)<u&&A.push({x:c[0],y:c[1]});for(T=0,B=0,p=null,b=0,w=A.length;w>b&&(c=A[b],T=Math.atan2(o-c.y,e-c.x),0>T&&(T+=l),B=Math.atan2(r-c.y,t-c.x),0>B&&(B+=l),"cw"===this.mode&&T>B?B+=l:"ccw"===this.mode&&B>T&&(T+=l),R=Math.abs(T-B),"s"===this.quad&&i>=R?p=c:"m"===this.quad&&(R>=Math.PI&&(m=1),p={x:c.x,y:c.y}),null==p);b++);return null!=p?(v=this.region?0:_.bbox().xMax,"cw"===this.mode&&(E=[B,T],T=E[0],B=E[1]),O=B>0?l:0,P=i+(B>i?l:0),I=Math.PI+(B>Math.PI?l:0),j=s+(B>s?l:0),L=I>=B&&T>=I?p.x-y-v:Math.min(t,e)-v,D=O>=B&&T>=O?p.x+y+v:Math.max(t,e)+v,C=j>=B&&T>=j?p.y-y-v:Math.min(r,o)-v,z=P>=B&&T>=P?p.y+y+v:Math.max(r,o)+v,N=Math.abs(t-e)<u&&Math.abs(r-o)<u,"m"===this.quad&&N&&(this.path.push("A",y,y,0,0,q,e+2*n,o+2*a),L=p.x-y-v,C=p.y-y-v,D=p.x+y+v,z=p.y+y+v),this.path.push("A",y,y,0,m,q,e,o),"s"===this.quad&&N&&this.path.push("Z"),this.addBbox({xMin:L,yMin:C,xMax:D,yMax:z},this.layerBbox)):void 0 | ||
},t.prototype.addBbox=function(t,r){return t.xMin<r.xMin&&(r.xMin=t.xMin),t.yMin<r.yMin&&(r.yMin=t.yMin),t.xMax>r.xMax&&(r.xMax=t.xMax),t.yMax>r.yMax?r.yMax=t.yMax:void 0},t}(),r.exports=n},{"./macro-tool":8,"./standard-tool":13,"./svg-coord":14,"./unique-id":15}],13:[function(t,r){var e,i,o;o=t("./unique-id"),e=t("./pad-shapes"),i=function(t,r){var i,n,s,l,h,a,u;if(a={pad:[],trace:!1},r.cx=0,r.cy=0,n="tool-"+t+"-pad-"+o(),u="",null!=r.dia&&null==r.verticies){if(null!=r.obround||null!=r.width||null!=r.height||null!=r.degrees)throw new Error("incompatible parameters for tool "+t);if(r.dia<0)throw new RangeError(t+" circle diameter out of range ("+r.dia+"<0)");u="circle",null==r.hole&&(a.trace={"stroke-width":r.dia,fill:"none"})}else if(null!=r.width&&null!=r.height){if(null!=r.dia||null!=r.verticies||null!=r.degrees)throw new Error("incompatible parameters for tool "+t);if(r.width<0)throw new RangeError(t+" rect width out of range ("+r.width+"<0)");if(r.height<0)throw new RangeError(t+" rect height out of range ("+r.height+"<0)");u="rect",0!==r.width&&0!==r.height||r.obround||(u="circle",r.dia=0),null!=r.hole||r.obround||(a.trace={})}else{if(null==r.dia||null==r.verticies)throw new Error("unidentified standard tool shape");if(null!=r.obround||null!=r.width||null!=r.height)throw new Error("incompatible parameters for tool "+t);if(r.verticies<3||r.verticies>12)throw new RangeError(t+" polygon points out of range ("+r.verticies+"<3 or >12)]");u="polygon"}if(h=e[u](r),null!=r.hole){if(i=null,null!=r.hole.dia&&null==r.hole.width&&null==r.hole.height){if(!(r.hole.dia>=0))throw new RangeError(t+" hole diameter out of range ("+r.hole.dia+"<0)");i=e.circle({cx:r.cx,cy:r.cy,dia:r.hole.dia}),i=i.shape,i.circle.fill="#000"}else{if(null==r.hole.width||null==r.hole.height)throw new Error(t+" has invalid hole parameters");if(!(r.hole.width>=0))throw new RangeError(t+" hole width out of range ("+r.hole.width+"<0)");if(!(r.hole.height>=0))throw new RangeError(t+" hole height out of range ("+r.hole.height+"<0)");i=e.rect({cx:r.cx,cy:r.cy,width:r.hole.width,height:r.hole.height}),i=i.shape,i.rect.fill="#000"}l=n+"-mask",s={mask:{id:n+"-mask",_:[{rect:{x:h.bbox[0],y:h.bbox[1],width:h.bbox[2]-h.bbox[0],height:h.bbox[3]-h.bbox[1],fill:"#fff"}},i]}},h.shape[u].mask="url(#"+l+")",a.pad.push(s)}return n&&(h.shape[u].id=n),a.pad.push(h.shape),a.bbox=h.bbox,a.padId=n,a},r.exports=i},{"./pad-shapes":10,"./unique-id":15}],14:[function(t,r){var e,i,o=[].indexOf||function(t){for(var r=0,e=this.length;e>r;r++)if(r in this&&this[r]===t)return r;return-1};e=3,i=function(t,r){var i,n,s,l,h,a,u,c,f,p,d,x,b,m;if(null==t)return 0/0;if(t=""+t,n="",i="",b="+",("-"===t[0]||"+"===t[0])&&(b=t[0],t=t.slice(1)),o.call(t,".")>=0||null==r.zero){if(m=t.split("."),m.length>2)return 0/0;p=[m[0],null!=(f=m[1])?f:""],n=p[0],i=p[1]}else{if("number"!=typeof(null!=r&&null!=(d=r.places)?d[0]:void 0)||"number"!=typeof(null!=r&&null!=(x=r.places)?x[1]:void 0))return 0/0;if("T"===r.zero){for(l=h=0,u=t.length;u>h;l=++h)s=t[l],l<r.places[0]?n+=s:i+=s;for(;n.length<r.places[0];)n+="0"}else if("L"===r.zero){for(l=a=0,c=t.length;c>a;l=++a)s=t[l],t.length-l<=r.places[1]?i+=s:n+=s;for(;i.length<r.places[1];)i="0"+i}}for(;i.length<e;)i+="0";return n+=i.slice(0,e),i=i.length>e?"."+i.slice(e):"",Number(b+n+i)},r.exports={get:i,factor:Math.pow(10,e)}},{}],15:[function(t,r){var e,i;i=1e3,e=function(){return i++},r.exports=e},{}]},{},[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 r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.gerberToSvg=t()}}(function(){return function t(r,e,i){function o(s,l){if(!e[s]){if(!r[s]){var h="function"==typeof require&&require;if(!l&&h)return h(s,!0);if(n)return n(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var u=e[s]={exports:{}};r[s][0].call(u.exports,function(t){var e=r[s][1][t];return o(e?e:t)},u,u.exports,t,r,e,i)}return e[s].exports}for(var n="function"==typeof require&&require,s=0;s<i.length;s++)o(i[s]);return o}({1:[function(t,r,e){(function(e){var i,o,n,s,l,h,a,u;a=t("./obj-to-xml"),h=t("./plotter"),n=t("./drill-reader"),o=t("./drill-parser"),l=t("./gerber-reader"),s=t("./gerber-parser"),u=t("./svg-coord").factor,i={drill:!1,pretty:!1,object:!1,warnArr:null,places:null,zero:null,notation:null,units:null},r.exports=function(t,r){var c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R;null==r&&(r={}),b={};for(d in i)E=i[d],b[d]=E;for(d in r)E=r[d],b[d]=E;if("object"==typeof t){if(null!=t.svg)return a(t,{pretty:b.pretty});throw new Error("non SVG object cannot be converted to an SVG string")}w=null,(null!=b.places||null!=b.zero)&&(w={places:b.places,zero:b.zero}),b.drill?(v=new n(t),g=new o(w)):(v=new l(t),g=new s(w)),y=null,(null!=b.notation||null!=b.units)&&(y={notation:b.notation,units:b.units}),m=new h(v,g,y),x=null,k=null,Array.isArray(b.warnArr)&&(k="undefined"!=typeof window&&null!==window?window:e,null==k.console&&(k.console={}),x=k.console.warn,k.console.warn=function(t){return b.warnArr.push(t.toString())});try{R=m.plot()}catch(T){throw f=T,new Error("Error at line "+m.reader.line+" - "+f.message)}finally{null!=x&&null!=k&&(k.console.warn=x)}m.bbox.xMin>=m.bbox.xMax?(m.bbox.xMin=0,m.bbox.xMax=0,q=0):q=m.bbox.xMax-m.bbox.xMin,m.bbox.yMin>=m.bbox.yMax?(m.bbox.yMin=0,m.bbox.yMax=0,p=0):p=m.bbox.yMax-m.bbox.yMin,_={svg:{xmlns:"http://www.w3.org/2000/svg",version:"1.1","xmlns:xlink":"http://www.w3.org/1999/xlink",width:""+q/u+m.units,height:""+p/u+m.units,viewBox:[m.bbox.xMin,m.bbox.yMin,q,p],_:[]}},M=m.attr;for(c in M)E=M[c],_.svg[c]=E;return m.defs.length&&_.svg._.push({defs:{_:m.defs}}),m.group.g._.length&&_.svg._.push(m.group),b.object?_:a(_,{pretty:b.pretty})}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./drill-parser":3,"./drill-reader":4,"./gerber-parser":5,"./gerber-reader":6,"./obj-to-xml":9,"./plotter":12,"./svg-coord":14}],2:[function(t,r,e){var i;i=t("./svg-coord").get,r.exports=function(t,r){var e,o,n,s,l,h,a,u,c,f,p,d;if(null==t)return{};if(null==r.zero||null==r.places)throw new Error("format undefined");o={},p={},o.x=null!=(n=t.match(/X[+-]?[\d\.]+/))&&null!=(s=n[0])?s.slice(1):void 0,o.y=null!=(l=t.match(/Y[+-]?[\d\.]+/))&&null!=(h=l[0])?h.slice(1):void 0,o.i=null!=(a=t.match(/I[+-]?[\d\.]+/))&&null!=(u=a[0])?u.slice(1):void 0,o.j=null!=(c=t.match(/J[+-]?[\d\.]+/))&&null!=(f=c[0])?f.slice(1):void 0;for(e in o)d=o[e],null!=d&&(p[e]=i(d,r));return p}},{"./svg-coord":14}],3:[function(t,r,e){var i,o,n,s,l,h,a,u,c,f,p,d=function(t,r){function e(){this.constructor=t}for(var i in r)x.call(r,i)&&(t[i]=r[i]);return e.prototype=r.prototype,t.prototype=new e,t.__super__=r.prototype,t},x={}.hasOwnProperty;a=t("./parser"),f=t("./coord-parser"),c=t("./svg-coord").get,n={"FMAT,1":"M70","FMAT,2":"M72"},l="M71",i="G90",s="G91",p=/[XY]{1,2}/,u="L",h=[2,4],o=function(t){function r(){this.fmat="FMAT,2",r.__super__.constructor.call(this,arguments[0])}return d(r,t),r.prototype.parseCommand=function(t){var r,e,o,a,d,x,b,m,g,w,y,v;if(x={},";"===t[0])return x;if("FMAT,1"===t)this.fmat=t;else if("M30"===t||"M00"===t)x.set={done:!0};else if(t===n[this.fmat]||t.match(/INCH/))null==(r=this.format).places&&(r.places=[2,4]),x.set={units:"in"};else if(t===l||t.match(/METRIC/))null==(e=this.format).places&&(e.places=[3,3]),x.set={units:"mm"};else if(t===i)x.set={notation:"A"};else if(t===s)x.set={notation:"I"};else if(d=null!=(g=t.match(/T\d+/))?g[0]:void 0){for(;"0"===d[1];)d=d[0]+d.slice(2);(b=null!=(w=t.match(/C[\d\.]+(?=.*$)/))?w[0]:void 0)?(b=b.slice(1),x.tool={},x.tool[d]={dia:c(b,{places:this.format.places})}):x.set={currentTool:d}}if(t.match(/TZ/)?null==(o=this.format).zero&&(o.zero="L"):t.match(/LZ/)&&null==(a=this.format).zero&&(a.zero="T"),t.match(p)){x.op={"do":"flash"},null==this.format.zero&&(this.format.zero=u),null==this.format.places&&(this.format.places=h),y=f(t,this.format);for(m in y)v=y[m],x.op[m]=v}return x},r}(a),r.exports=o},{"./coord-parser":2,"./parser":11,"./svg-coord":14}],4:[function(t,r,e){var i;i=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}(),r.exports=i},{}],5:[function(t,r,e){var i,o,n,s,l,h,a=function(t,r){function e(){this.constructor=t}for(var i in r)u.call(r,i)&&(t[i]=r[i]);return e.prototype=r.prototype,t.prototype=new e,t.__super__=r.prototype,t},u={}.hasOwnProperty;o=t("./parser"),s=t("./coord-parser"),n=t("./svg-coord").get,l=/([XYIJ][+-]?\d+){1,4}/g,h=/^FS([A-Z]?)([A-Z]?)X([0-7])([0-7])Y\3\4/,i=function(t){function r(){return r.__super__.constructor.apply(this,arguments)}return a(r,t),r.prototype.parseFormat=function(t,r){var e,i,o,n,s,l,a,u;if(!(n=t.match(h)))throw new Error("invalid format specification");return e=n[0],u=n[1],s=n[2],a=n[3],l=n[4],"L"!==u&&"T"!==u&&(u="L"),"A"!==s&&"I"!==s&&(s="A"),null==(i=this.format).zero&&(i.zero=u),null==(o=this.format).places&&(o.places=[Number(a),Number(l)]),null==r.set&&(r.set={}),r.set.notation=s},r.prototype.parseToolDef=function(t,r){var e,i,o,s,l,h,a;for(null==r.tool&&(r.tool={}),e=null!=(l=t.match(/^ADD\d{2,}/))?l[0].slice(2):void 0,h=t.slice(2+e.length).split(","),a=h[0],s=h[1],s=null!=s?s.split("X"):void 0;"0"===e[1];)e=e[0]+e.slice(2);switch(a){case"C":if(s.length>2?i={width:n(s[1],{places:this.format.places}),height:n(s[2],{places:this.format.places})}:s.length>1&&(i={dia:n(s[1],{places:this.format.places})}),r.tool[e]={dia:n(s[0],{places:this.format.places})},null!=i)return r.tool[e].hole=i;break;case"R":case"O":if(s.length>3?i={width:n(s[2],{places:this.format.places}),height:n(s[3],{places:this.format.places})}:s.length>2&&(i={dia:n(s[2],{places:this.format.places})}),r.tool[e]={width:n(s[0],{places:this.format.places}),height:n(s[1],{places:this.format.places})},"O"===a&&(r.tool[e].obround=!0),null!=i)return r.tool[e].hole=i;break;case"P":if(s.length>4?i={width:n(s[3],{places:this.format.places}),height:n(s[4],{places:this.format.places})}:s.length>3&&(i={dia:n(s[3],{places:this.format.places})}),r.tool[e]={dia:n(s[0],{places:this.format.places}),verticies:+s[1]},s.length>2&&(r.tool[e].degrees=+s[2]),null!=i)return r.tool[e].hole=i;break;default:return s=function(){var t,r,e,i;for(e=null!=s?s:[],i=[],t=0,r=e.length;r>t;t++)o=e[t],i.push(+o);return i}(),r.tool[e]={macro:a,mods:s}}},r.prototype.parseCommand=function(t){var r,e,i,o,h,a,u,c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R,T,A,B;if(null==t&&(t={}),e={},x=t.param)for(u=0,c=x.length;c>u;u++)switch(d=x[u],i=d.slice(0,2)){case"FS":this.parseFormat(d,e);break;case"MO":if(R=d.slice(2,4),null==e.set&&(e.set={}),"IN"===R)e.set.units="in";else{if("MM"!==R)throw new Error(d+" is an invalid units setting");e.set.units="mm"}break;case"AD":this.parseToolDef(d,e);break;case"AM":return{macro:x};case"LP":if(null==e["new"]&&(e["new"]={}),("D"===d[2]||"C"===d[2])&&(e["new"].layer=d[2]),null==e["new"].layer)throw new Error("invalid level polarity");break;case"SR":if(null==e["new"]&&(e["new"]={}),A=null!=(b=null!=(m=d.match(/X[+-]?[\d\.]+/))?m[0].slice(1):void 0)?b:1,B=null!=(g=null!=(w=d.match(/Y[+-]?[\d\.]+/))?w[0].slice(1):void 0)?g:1,h=null!=(y=d.match(/I[+-]?[\d\.]+/))?y[0].slice(1):void 0,a=null!=(v=d.match(/J[+-]?[\d\.]+/))?v[0].slice(1):void 0,1>A||1>B||A>1&&(null==h||0>h)||B>1&&(null==a||0>a))throw new Error("invalid step repeat");e["new"].sr={x:+A,y:+B},null!=h&&(e["new"].sr.i=n(h,{places:this.format.places})),null!=a&&(e["new"].sr.j=n(a,{places:this.format.places}))}else if(t=t.block){if("M02"===t)return{set:{done:!0}};if("G"===t[0])switch(i=null!=(M=t.slice(1).match(/^\d{1,2}/))?M[0]:void 0){case"4":case"04":return{};case"1":case"01":case"2":case"02":case"3":case"03":i=i[i.length-1],f="1"===i?"i":"2"===i?"cw":"ccw",e.set={mode:f};break;case"36":case"37":e.set={region:"36"===i};break;case"70":case"71":e.set={backupUnits:"70"===i?"in":"mm"};break;case"74":case"75":e.set={quad:"74"===i?"s":"m"}}if(o=s(null!=(k=t.match(l))?k[0]:void 0,this.format),p=(null!=(E=t.match(/D0?[123]$/))?E[0]:void 0)||Object.keys(o).length){null!=p&&(p=p[p.length-1]),p=function(){switch(p){case"1":return"int";case"2":return"move";case"3":return"flash";default:return"last"}}(),e.op={"do":p};for(r in o)T=o[r],e.op[r]=T}else(_=null!=(q=t.match(/D\d+$/))?q[0]:void 0)&&(e.set={currentTool:_})}return e},r}(o),r.exports=i},{"./coord-parser":2,"./parser":11,"./svg-coord":14}],6:[function(t,r,e){var i;i=function(){function t(t){this.gerberFile=null!=t?t:"",this.line=0,this.charIndex=0,this.end=this.gerberFile.length}return t.prototype.nextBlock=function(){var t,r,e;if(this.index>=this.end)return!1;for(r="",e=!1,0===this.line&&this.line++;!(this.charIndex>=this.end);)if(t=this.gerberFile[this.charIndex++],"%"===t){if(e)return{param:e};e=[]}else if("*"===t){if(!e)return{block:r};e.push(r),r=""}else"\n"===t?this.line++:t>=" "&&"~">=t&&(r+=t);return!1},t.prototype.getLine=function(){return this.line},t}(),r.exports=i},{}],7:[function(t,r,e){var i,o,n,s,l,h;o=/[\+\-\/xX\(\)]/,i=/[\$\d\.]+/,n=new RegExp("("+o.source+")|("+i.source+")","g"),h=function(t){var r;return r=t.match(n)},s=function(t){return i.test(t)},l=function(t){var r,e,i,o,n,l,a;return a=h(t),e=0,l=function(){return a[e]},r=function(t){return t===l()?e++:void 0},n=function(){var t,e;if(e=l(),r(e),s(e))t={type:"n",val:e};else{if("("!==e)throw new Error(e+" is unexpected in an arithmetic string");if(t=i(),")"!==l())throw new Error("expected ')'");r(")")}return t},o=function(){var t,e,i;for(t=n(),i=l();"x"===i||"/"===i||"X"===i;)r(i),"X"===i&&(i="x"),e=n(),t={type:i,left:t,right:e},i=l();return t},(i=function(){var t,e,i;for(t=o(),i=l();"+"===i||"-"===i;)r(i),e=o(),t={type:i,left:t,right:e},i=l();return t})()},r.exports={tokenize:h,isNumber:s,parse:l}},{}],8:[function(t,r,e){var i,o,n,s,l;s=t("./pad-shapes"),o=t("./macro-calc"),l=t("./unique-id"),n=t("./svg-coord").get,i=function(){function t(t,r){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:r}}return t.prototype.run=function(t,r){var e,i,o,n,s,h,a,u,c,f,p,d,x,b,m,g,w,y,v;for(null==r&&(r=[]),this.lastExposure=null,this.shapes=[],this.masks=[],this.bbox=[null,null,null,null],this.modifiers={},o=n=0,a=r.length;a>n;o=++n)p=r[o],this.modifiers["$"+(o+1)]=p;for(m=this.blocks,s=0,u=m.length;u>s;s++)e=m[s],this.runBlock(e);for(b="tool-"+t+"-pad-"+l(),x=[],g=this.masks,h=0,c=g.length;c>h;h++)p=g[h],x.push(p);if(this.shapes.length>1){for(i={id:b,_:[]},w=this.shapes,d=0,f=w.length;f>d;d++)y=w[d],i._.push(y);x=[{g:i}]}else 1===this.shapes.length&&(v=Object.keys(this.shapes[0])[0],this.shapes[0][v].id=b,x.push(this.shapes[0]));return{pad:x,padId:b,bbox:this.bbox,trace:!1}},t.prototype.runBlock=function(t){var r,e,i,o,n,s,l,h;switch(t[0]){case"$":return s=null!=(l=t.match(/^\$\d+(?=\=)/))?l[0]:void 0,h=t.slice(1+s.length),this.modifiers[s]=this.getNumber(h);case"1":case"2":case"20":case"21":case"22":case"4":case"5":case"6":case"7":for(e=t.split(","),i=o=0,n=e.length;n>o;i=++o)r=e[i],e[i]=this.getNumber(r);return this.primitive(e);default:if("0"!==t[0])throw new Error("'"+t+"' unrecognized tool macro block")}},t.prototype.primitive=function(t){var r,e,i,o,h,a,u,c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R,T,A,B,D,L;switch(b=!1,B=!1,L=null,t[0]){case 1:L=s.circle({dia:n(t[2],this.format),cx:n(t[3],this.format),cy:n(t[4],this.format)}),0===t[1]?b=!0:this.addBbox(L.bbox);break;case 2:case 20:L=s.vector({width:n(t[2],this.format),x1:n(t[3],this.format),y1:n(t[4],this.format),x2:n(t[5],this.format),y2:n(t[6],this.format)}),t[7]&&(L.shape.line.transform="rotate("+t[7]+")"),0===t[1]?b=!0:this.addBbox(L.bbox,t[7]);break;case 21:L=s.rect({cx:n(t[4],this.format),cy:n(t[5],this.format),width:n(t[2],this.format),height:n(t[3],this.format)}),t[6]&&(L.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?b=!0:this.addBbox(L.bbox,t[6]);break;case 22:L=s.lowerLeftRect({x:n(t[4],this.format),y:n(t[5],this.format),width:n(t[2],this.format),height:n(t[3],this.format)}),t[6]&&(L.shape.rect.transform="rotate("+t[6]+")"),0===t[1]?b=!0:this.addBbox(L.bbox,t[6]);break;case 4:for(y=[],e=i=3,M=3+2*t[2];M>=i;e=i+=2)y.push([n(t[e],this.format),n(t[e+1],this.format)]);L=s.outline({points:y}),(A=t[t.length-1])&&(L.shape.polygon.transform="rotate("+A+")"),0===t[1]?b=!0:this.addBbox(L.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");L=s.polygon({cx:n(t[3],this.format),cy:n(t[4],this.format),dia:n(t[5],this.format),verticies:t[2],degrees:t[6]}),0===t[1]?b=!0:this.addBbox(L.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(L=s.moire({cx:n(t[1],this.format),cy:n(t[2],this.format),outerDia:n(t[3],this.format),ringThx:n(t[4],this.format),ringGap:n(t[5],this.format),maxRings:t[6],crossThx:n(t[7],this.format),crossLength:n(t[8],this.format)}),t[9])for(k=L.shape,o=0,u=k.length;u>o;o++)D=k[o],null!=D.line&&(D.line.transform="rotate("+t[9]+")");this.addBbox(L.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(L=s.thermal({cx:n(t[1],this.format),cy:n(t[2],this.format),outerDia:n(t[3],this.format),innerDia:n(t[4],this.format),gap:n(t[5],this.format)}),t[6])for(E=L.shape,a=0,c=E.length;c>a;a++)if(D=E[a],null!=D.mask)for(q=D.mask._,g=0,f=q.length;f>g;g++)x=q[g],null!=x.rect&&(x.rect.transform="rotate("+t[6]+")");this.addBbox(L.bbox,t[6]);break;default:throw new Error(t[0]+" is not a valid primitive code")}if(b){for(h in L.shape)L.shape[h].fill="#000";if(0!==this.lastExposure){if(this.lastExposure=0,m="macro-"+this.name+"-mask-"+l(),x={mask:{id:m}},x.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(h in this.shapes[0])this.shapes[0][h].mask="url(#"+m+")";else if(this.shapes.length>1){for(r={mask:"url(#"+m+")",_:[]},_=this.shapes,w=0,p=_.length;p>w;w++)D=_[w],r._.push(D);this.shapes=[{g:r}]}this.masks.push(x)}return this.masks[this.masks.length-1].mask._.push(L.shape)}if(this.lastExposure=1,Array.isArray(L.shape)){for(R=L.shape,T=[],v=0,d=R.length;d>v;v++)D=R[v],T.push(null!=D.mask?this.masks.push(D):this.shapes.push(D));return T}return this.shapes.push(L.shape)},t.prototype.addBbox=function(t,r){var e,i,o,n,s,l,h,a,u;if(null==r&&(r=0),r){for(h=Math.sin(r*Math.PI/180),i=Math.cos(r*Math.PI/180),Math.abs(h)<1e-9&&(h=0),Math.abs(i)<1e-9&&(i=0),l=[[t[0],t[1]],[t[2],t[1]],[t[2],t[3]],[t[0],t[3]]],o=0,n=l.length;n>o;o++)s=l[o],a=s[0]*i-s[1]*h,u=s[0]*h+s[1]*i,(null===this.bbox[0]||a<this.bbox[0])&&(this.bbox[0]=a),(null===this.bbox[1]||u<this.bbox[1])&&(this.bbox[1]=u),(null===this.bbox[2]||a>this.bbox[2])&&(this.bbox[2]=a),(null===this.bbox[3]||u>this.bbox[3])&&(this.bbox[3]=u);return this.bbox=function(){var t,r,i,o;for(i=this.bbox,o=[],t=0,r=i.length;r>t;t++)e=i[t],o.push(e===-0?0:e);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(o.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}(),r.exports=i},{"./macro-calc":7,"./pad-shapes":10,"./svg-coord":14,"./unique-id":15}],9:[function(t,r,e){var i,o,n,s;s=function(t,r){var e;if(e="",0===r)return"";for(;r>1;)1&r&&(e+=t),r>>=1,t+=t;return e+t},i="_",o=" ",n=function(t,r){var e,l,h,a,u,c,f,p,d,x,b,m,g,w,y,v,M,k,E;if(null==r&&(r={}),m=r.pretty,c=null!=(g=r.indent)?g:0,l=null!=(w=r.maxDec)?w:!1,h=function(t){return"number"==typeof t?Number(t.toFixed(l)):t},x=m?"\n":"",v=x?"string"==typeof m?m:o:"",v=s(v,c),E="","function"==typeof t&&(t=t()),Array.isArray(t))for(u=f=0,d=t.length;d>f;u=++f)b=t[u],E+=(0!==u?x:"")+n(b,r);else if("object"==typeof t){if(e=!1,a=Object.keys(t)[0],null!=a){E=v+"<"+a,"function"==typeof t[a]&&(t[a]=t[a]()),y=t[a];for(p in y)k=y[p],"function"==typeof k&&(k=k()),p===i?e=k:(Array.isArray(k)&&(l&&(k=function(){var t,r,e;for(e=[],t=0,r=k.length;r>t;t++)M=k[t],e.push(h(M));return e}()),k=k.join(" ")),l&&(k=h(k)),E+=" "+p+'="'+k+'"');e&&(E+=">"+x+n(e,{pretty:m,indent:c+1})),E+=null!=t[a]._?""+x+v+"</"+a+">":"/>"}}else E+=t+" ";return E},r.exports=n},{}],10:[function(t,r,e){var i,o,n,s,l,h,a,u,c;u=t("./unique-id"),i=function(t){var r;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 r=t.dia/2,{shape:{circle:{cx:t.cx,cy:t.cy,r:r}},bbox:[t.cx-r,t.cy-r,t.cx+r,t.cy+r]}},h=function(t){var r,e,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,e={shape:{rect:{x:i,y:o,width:t.width,height:t.height}},bbox:[i,o,i+t.width,o+t.height]},t.obround&&(r=.5*Math.min(t.width,t.height),e.shape.rect.rx=r,e.shape.rect.ry=r),e},l=function(t){var r,e,i,o,n,s,l,h,a,u,c,f,p,d,x,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(h=null!=t.degrees?t.degrees*Math.PI/180:0,a=2*Math.PI/t.verticies,o=t.dia/2,i="",p=null,b=null,f=null,x=null,r=e=0,n=t.verticies;n>=0?n>e:e>n;r=n>=0?++e:--e)u=h+r*a,s=o*Math.cos(u),l=o*Math.sin(u),Math.abs(s)<1e-9&&(s=0),Math.abs(l)<1e-9&&(l=0),c=t.cx+s,d=t.cy+l,(p>c||null===p)&&(p=c),(c>f||null===f)&&(f=c),(b>d||null===b)&&(b=d),(d>x||null===x)&&(x=d),i+=" "+c+","+d;return{shape:{polygon:{points:i.slice(1)}},bbox:[p,b,f,x]}},c=function(t){var r,e,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 r=Math.abs(Math.atan((t.y2-t.y1)/(t.x2-t.x1))),e=t.width/2*Math.sin(r),i=t.width/2*Math.cos(r),1e-7>e&&(e=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)-e,Math.min(t.y1,t.y2)-i,Math.max(t.x1,t.x2)+e,Math.max(t.y1,t.y2)+i]}},o=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]}},s=function(t){var r,e,i,o,n,s,l,h,a,u,c,f,p;if(!(Array.isArray(t.points)&&t.points.length>1))throw new Error("outline function requires points array");for(a=null,p=null,h=null,f=null,o="",n=t.points,r=0,e=n.length;e>r;r++){if(i=n[r],!Array.isArray(i)||2!==i.length)throw new Error("outline function requires points array");s=i[0],u=i[1],(a>s||null===a)&&(a=s),(s>h||null===h)&&(h=s),(p>u||null===p)&&(p=u),(u>f||null===f)&&(f=u),o+=" "+s+","+u}if(l=t.points[t.points.length-1][0],c=t.points[t.points.length-1][1],l!==t.points[0][0]||c!==t.points[0][1])throw new RangeError("last point must match first point of outline");return{shape:{polygon:{points:o.slice(1)}},bbox:[a,p,h,f]}},n=function(t){var r,e,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"}}],r=(t.outerDia-t.ringThx)/2,e=0;r>=t.ringThx&&e<t.maxRings;)i.push({circle:{cx:t.cx,cy:t.cy,r:r,fill:"none","stroke-width":t.ringThx}}),e++,r-=t.ringThx+t.ringGap;return r+=.5*t.ringThx,r>0&&e<t.maxRings&&i.push({circle:{cx:t.cx,cy:t.cy,r:r}}),{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 r,e,i,o,n,s,l,h,a;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 e="thermal-mask-"+u(),n=(t.outerDia-t.innerDia)/2,i=t.outerDia/2,o=i-n/2,l=t.cx-i,s=t.cx+i,a=t.cy-i,h=t.cy+i,r=t.gap/2,{shape:[{mask:{id:e,_:[{circle:{cx:t.cx,cy:t.cy,r:i,fill:"#fff"}},{rect:{x:l,y:-r,width:t.outerDia,height:t.gap,fill:"#000"}},{rect:{x:-r,y:a,width:t.gap,height:t.outerDia,fill:"#000"}}]}},{circle:{cx:t.cx,cy:t.cy,r:o,fill:"none","stroke-width":n,mask:"url(#"+e+")"}}],bbox:[l,a,s,h]}},r.exports={circle:i,rect:h,polygon:l,vector:c,lowerLeftRect:o,outline:s,moire:n,thermal:a}},{"./unique-id":15}],11:[function(t,r,e){var i;i=function(){function t(t){var r,e;if(null==t&&(t={}),this.format={zero:null!=(r=t.zero)?r:null,places:null!=(e=t.places)?e:null},null!=this.format.places&&(!Array.isArray(this.format.places)||2!==this.format.places.length||"number"!=typeof this.format.places[0]||"number"!=typeof this.format.places[1]))throw new Error("parser places format must be an array of two numbers");if(null!=this.format.zero&&("string"!=typeof this.format.zero||"L"!==this.format.zero&&"T"!==this.format.zero))throw new Error("parser zero format must be either 'L' or 'T'")}return t}(),r.exports=i},{}],12:[function(t,r,e){var i,o,n,s,l,h,a,u,c;c=t("./unique-id"),n=t("./macro-tool"),u=t("./standard-tool"),a=t("./svg-coord").factor,o=Math.PI/2,l=3*o,h=2*Math.PI,i="in",s=function(){function t(t,r,e){var i,o;this.reader=t,this.parser=r,null==e&&(e={}),this.units=null!=(i=e.units)?i:null,this.notation=null!=(o=e.notation)?o:null,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.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,r){var e,i;if(null!=this.tools[t])throw new Error("cannot reassign tool "+t);return i=null!=r.macro?this.macros[r.macro].run(t,r.mods):u(t,r),this.tools[t]={trace:i.trace,pad:function(){var t,r,o,n;for(o=i.pad,n=[],t=0,r=o.length;r>t;t++)e=o[t],n.push(e);return n}(),flash:function(t,r){return{use:{x:t,y:r,"xlink:href":"#"+i.padId}}},flashed:!1,bbox:function(t,r){return null==t&&(t=0),null==r&&(r=0),{xMin:t+i.bbox[0],yMin:r+i.bbox[1],xMax:t+i.bbox[2],yMax:r+i.bbox[3]}}},this.changeTool(t)},t.prototype.changeTool=function(t){var r;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!=(r=this.parser)?r.fmat:void 0))throw new Error("tool "+t+" is not defined")},t.prototype.command=function(t){var r,e,i,o,s,l,h;if(null!=t.macro)return e=new n(t.macro,this.parser.format.places),void(this.macros[e.name]=e);o=t.set;for(l in o)switch(h=o[l],"region"===l&&this.finishPath(),l){case"currentTool":this.changeTool(h);break;case"units":case"notation":null==this[l]&&(this[l]=h);break;default:this[l]=h}if(null!=t.tool){s=t.tool;for(r in s)i=s[r],this.addTool(r,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,r;!this.done;){if(t=this.reader.nextBlock(),t===!1)throw new Error(null==(null!=(r=this.parser)?r.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,r,e,i,o,n,s,l,h,a,u,f,p,d,x,b;if(this.srOverClear&&this.srOverCurrent){for(n="gerber-sr-mask_"+c(),o={mask:{color:"#000",id:n,_:[]}},o.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}}),x=t=0,l=this.stepRepeat.x*this.stepRepeat.i,h=this.stepRepeat.i;h>0?l>t:t>l;x=t+=h)for(b=r=0,a=this.stepRepeat.y*this.stepRepeat.j,u=this.stepRepeat.j;u>0?a>r:r>a;b=r+=u)for(f=this.srOverCurrent,s=0,i=f.length;i>s;s++)e=f[s],d={use:{}},0!==x&&(d.use.x=x),0!==b&&(d.use.y=b),d.use["xlink:href"]="#"+(null!=(p=e.C)?p:e.D),null!=e.D&&(d.use.fill="#fff"),o.mask._.push(d);return this.srOverClear=!1,this.srOverCurrent=[],this.defs.push(o),this.group.g.mask="url(#"+n+")"}},t.prototype.finishLayer=function(){var t,r,e,i,o,n,s,l,h,a,u,f,p,d,x,b;if(this.finishPath(),this.current.length){if(this.stepRepeat.x>1||this.stepRepeat.y>1){for(f="gerber-sr_"+c(),this.current=[{g:{id:f,_:this.current}}],(this.srOverClear||this.stepRepeat.i<this.layerBbox.xMax-this.layerBbox.xMin||this.stepRepeat.j<this.layerBbox.yMax-this.layerBbox.yMin)&&(l={},l[this.polarity]=f,this.srOverCurrent.push(l),"C"===this.polarity&&(this.srOverClear=!0,this.defs.push(this.current[0]))),x=i=0,h=this.stepRepeat.x;h>=0?h>i:i>h;x=h>=0?++i:--i)for(b=o=0,a=this.stepRepeat.y;a>=0?a>o:o>a;b=a>=0?++o:--o)(0!==x||0!==b)&&(p={use:{"xlink:href":"#"+f}},0!==x&&(p.use.x=x*this.stepRepeat.i),0!==b&&(p.use.y=b*this.stepRepeat.j),this.current.push(p));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(u=this.current,s=0,n=u.length;n>s;s++)t=u[s],this.group.g._.push(t);else this.group={g:{_:this.current}};else"C"!==this.polarity||this.srOverClear||(e="gerber-mask_"+c(),d=this.bbox.xMax-this.bbox.xMin,r=this.bbox.yMax-this.bbox.yMin,this.current.unshift({rect:{x:this.bbox.xMin,y:this.bbox.yMin,width:d,height:r,fill:"#fff"}}),this.defs.push({mask:{id:e,color:"#000",_:this.current}}),this.group.g.mask="url(#"+e+")");return this.current=[]}},t.prototype.finishPath=function(){var t,r,e,i;if(this.path.length){if(r={path:{}},this.region)this.path.push("Z");else{e=this.tools[this.currentTool].trace;for(t in e)i=e[t],r.path[t]=i}return r.path.d=this.path,this.current.push(r),this.path=[]}},t.prototype.operate=function(t){var r,e,o,n,s,l,h,a,u,c,f,p,d,x,b,m,g;if("last"===t["do"]?t["do"]=this.lastOp:this.lastOp=t["do"],b=this.pos.x,m=this.pos.y,"I"===this.notation?(this.pos.x+=null!=(l=t.x)?l:0,this.pos.y+=null!=(h=t.y)?h:0):(this.pos.x=null!=(a=t.x)?a:this.pos.x,this.pos.y=null!=(u=t.y)?u:this.pos.y),e=this.pos.x,o=this.pos.y,g=this.tools[this.currentTool],null==this.units&&(this.units=null!=this.backupUnits?this.backupUnits:i),null==this.notation){if(null==(null!=(c=this.parser)?c.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",e,o);if("flash"===t["do"]){if(this.finishPath(),this.region)throw new Error("cannot flash while in region mode");if(!g.flashed){for(f=g.pad,n=0,s=f.length;s>n;n++)x=f[n],this.defs.push(x);g.flashed=!0}return this.current.push(g.flash(e,o)),this.addBbox(g.bbox(e,o),this.layerBbox)}if("int"===t["do"]){if(!this.region&&!g.trace)throw new Error(this.currentTool+" is not a strokable tool");return 0===this.path.length&&(this.path.push("M",b,m),r=this.region?{xMin:b,yMin:m,xMax:b,yMax:m}:g.bbox(b,m),this.addBbox(r,this.layerBbox)),null==this.mode&&(this.mode="i"),"i"===this.mode?this.drawLine(b,m,e,o):this.drawArc(b,m,e,o,null!=(p=t.i)?p:0,null!=(d=t.j)?d:0)}},t.prototype.drawLine=function(t,r,e,i){var n,s,l,h,a,u,c,f,p,d,x,b,m;return b=this.tools[this.currentTool],n=this.region?{xMin:e,yMin:i,xMax:e,yMax:i}:b.bbox(e,i),this.addBbox(n,this.layerBbox),this.region||b.trace["stroke-width"]>=0?this.path.push("L",e,i):(c=b.pad[0].rect.width/2,u=b.pad[0].rect.height/2,f=t-c,p=t+c,d=r-u,x=r+u,s=e-c,l=e+c,h=i-u,a=i+u,m=Math.atan2(i-r,e-t),m>=0&&o>m?this.path.push("M",f,d,p,d,l,h,l,a,s,a,f,x,"Z"):m>=o&&m<=Math.PI?this.path.push("M",f,d,p,d,p,x,l,a,s,a,s,h,"Z"):-Math.PI<=m&&-o>m?this.path.push("M",p,d,p,x,f,x,s,a,s,h,l,h,"Z"):m>=-o&&0>m?this.path.push("M",f,d,s,h,l,h,l,a,p,x,f,x,"Z"):void 0)},t.prototype.drawArc=function(t,r,e,i,n,s){var u,c,f,p,d,x,b,m,g,w,y,v,M,k,E,q,_,R,T,A,B,D,L,I,O,z,C,j,P,N;if(u=1.5*a*Math.pow(10,-1*(null!=(M=null!=(k=this.parser)?k.format.places[1]:void 0)?M:7)),_=this.tools[this.currentTool],!this.region&&!_.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(y=Math.sqrt(Math.pow(n,2)+Math.pow(s,2)),q="cw"===this.mode?0:1,m=0,B=[],f=[[t+n,r+s]],"s"===this.quad&&f.push([t-n,r-s],[t-n,r+s],[t+n,r-s]),x=0,g=f.length;g>x;x++)c=f[x],d=Math.sqrt(Math.pow(c[0]-e,2)+Math.pow(c[1]-i,2)),Math.abs(y-d)<u&&B.push({x:c[0],y:c[1]});for(T=0,A=0,p=null,b=0,w=B.length;w>b&&(c=B[b],T=Math.atan2(i-c.y,e-c.x),0>T&&(T+=h),A=Math.atan2(r-c.y,t-c.x),0>A&&(A+=h),"cw"===this.mode&&T>A?A+=h:"ccw"===this.mode&&A>T&&(T+=h),R=Math.abs(T-A),"s"===this.quad&&o>=R?p=c:"m"===this.quad&&(R>=Math.PI&&(m=1),p={x:c.x,y:c.y}),null==p);b++);return null!=p?(v=this.region?0:_.bbox().xMax,"cw"===this.mode&&(E=[A,T], | ||
T=E[0],A=E[1]),O=A>0?h:0,P=o+(A>o?h:0),I=Math.PI+(A>Math.PI?h:0),j=l+(A>l?h:0),L=I>=A&&T>=I?p.x-y-v:Math.min(t,e)-v,D=O>=A&&T>=O?p.x+y+v:Math.max(t,e)+v,C=j>=A&&T>=j?p.y-y-v:Math.min(r,i)-v,z=P>=A&&T>=P?p.y+y+v:Math.max(r,i)+v,N=Math.abs(t-e)<u&&Math.abs(r-i)<u,"m"===this.quad&&N&&(this.path.push("A",y,y,0,0,q,e+2*n,i+2*s),L=p.x-y-v,C=p.y-y-v,D=p.x+y+v,z=p.y+y+v),this.path.push("A",y,y,0,m,q,e,i),"s"===this.quad&&N&&this.path.push("Z"),this.addBbox({xMin:L,yMin:C,xMax:D,yMax:z},this.layerBbox)):void 0},t.prototype.addBbox=function(t,r){return t.xMin<r.xMin&&(r.xMin=t.xMin),t.yMin<r.yMin&&(r.yMin=t.yMin),t.xMax>r.xMax&&(r.xMax=t.xMax),t.yMax>r.yMax?r.yMax=t.yMax:void 0},t}(),r.exports=s},{"./macro-tool":8,"./standard-tool":13,"./svg-coord":14,"./unique-id":15}],13:[function(t,r,e){var i,o,n;n=t("./unique-id"),i=t("./pad-shapes"),o=function(t,r){var e,o,s,l,h,a,u;if(a={pad:[],trace:!1},r.cx=0,r.cy=0,o="tool-"+t+"-pad-"+n(),u="",null!=r.dia&&null==r.verticies){if(null!=r.obround||null!=r.width||null!=r.height||null!=r.degrees)throw new Error("incompatible parameters for tool "+t);if(r.dia<0)throw new RangeError(t+" circle diameter out of range ("+r.dia+"<0)");u="circle",null==r.hole&&(a.trace={"stroke-width":r.dia,fill:"none"})}else if(null!=r.width&&null!=r.height){if(null!=r.dia||null!=r.verticies||null!=r.degrees)throw new Error("incompatible parameters for tool "+t);if(r.width<0)throw new RangeError(t+" rect width out of range ("+r.width+"<0)");if(r.height<0)throw new RangeError(t+" rect height out of range ("+r.height+"<0)");u="rect",0!==r.width&&0!==r.height||r.obround||(u="circle",r.dia=0),null!=r.hole||r.obround||(a.trace={})}else{if(null==r.dia||null==r.verticies)throw new Error("unidentified standard tool shape");if(null!=r.obround||null!=r.width||null!=r.height)throw new Error("incompatible parameters for tool "+t);if(r.verticies<3||r.verticies>12)throw new RangeError(t+" polygon points out of range ("+r.verticies+"<3 or >12)]");u="polygon"}if(h=i[u](r),null!=r.hole){if(e=null,null!=r.hole.dia&&null==r.hole.width&&null==r.hole.height){if(!(r.hole.dia>=0))throw new RangeError(t+" hole diameter out of range ("+r.hole.dia+"<0)");e=i.circle({cx:r.cx,cy:r.cy,dia:r.hole.dia}),e=e.shape,e.circle.fill="#000"}else{if(null==r.hole.width||null==r.hole.height)throw new Error(t+" has invalid hole parameters");if(!(r.hole.width>=0))throw new RangeError(t+" hole width out of range ("+r.hole.width+"<0)");if(!(r.hole.height>=0))throw new RangeError(t+" hole height out of range ("+r.hole.height+"<0)");e=i.rect({cx:r.cx,cy:r.cy,width:r.hole.width,height:r.hole.height}),e=e.shape,e.rect.fill="#000"}l=o+"-mask",s={mask:{id:o+"-mask",_:[{rect:{x:h.bbox[0],y:h.bbox[1],width:h.bbox[2]-h.bbox[0],height:h.bbox[3]-h.bbox[1],fill:"#fff"}},e]}},h.shape[u].mask="url(#"+l+")",a.pad.push(s)}return o&&(h.shape[u].id=o),a.pad.push(h.shape),a.bbox=h.bbox,a.padId=o,a},r.exports=o},{"./pad-shapes":10,"./unique-id":15}],14:[function(t,r,e){var i,o,n=[].indexOf||function(t){for(var r=0,e=this.length;e>r;r++)if(r in this&&this[r]===t)return r;return-1};i=3,o=function(t,r){var e,o,s,l,h,a,u,c,f,p,d,x,b,m;if(null==t)return 0/0;if(t=""+t,o="",e="",b="+",("-"===t[0]||"+"===t[0])&&(b=t[0],t=t.slice(1)),n.call(t,".")>=0||null==r.zero){if(m=t.split("."),m.length>2)return 0/0;p=[m[0],null!=(f=m[1])?f:""],o=p[0],e=p[1]}else{if("number"!=typeof(null!=r&&null!=(d=r.places)?d[0]:void 0)||"number"!=typeof(null!=r&&null!=(x=r.places)?x[1]:void 0))return 0/0;if("T"===r.zero){for(l=h=0,u=t.length;u>h;l=++h)s=t[l],l<r.places[0]?o+=s:e+=s;for(;o.length<r.places[0];)o+="0"}else if("L"===r.zero){for(l=a=0,c=t.length;c>a;l=++a)s=t[l],t.length-l<=r.places[1]?e+=s:o+=s;for(;e.length<r.places[1];)e="0"+e}}for(;e.length<i;)e+="0";return o+=e.slice(0,i),e=e.length>i?"."+e.slice(i):"",Number(b+o+e)},r.exports={get:o,factor:Math.pow(10,i)}},{}],15:[function(t,r,e){var i,o;o=1e3,i=function(){return o++},r.exports=i},{}]},{},[1])(1)}); |
(function() { | ||
var GerberParser, Parser, getSvgCoord, parseCoord, reCOORD, | ||
var GerberParser, Parser, getSvgCoord, parseCoord, reCOORD, reFS, | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
@@ -14,2 +14,4 @@ hasProp = {}.hasOwnProperty; | ||
reFS = /^FS([A-Z]?)([A-Z]?)X([0-7])([0-7])Y\3\4/; | ||
GerberParser = (function(superClass) { | ||
@@ -23,11 +25,15 @@ extend(GerberParser, superClass); | ||
GerberParser.prototype.parseFormat = function(p, c) { | ||
var base, base1, nota, places, zero; | ||
zero = p[2] === 'L' || p[2] === 'T' ? p[2] : null; | ||
nota = p[3] === 'A' || p[3] === 'I' ? p[3] : null; | ||
if (p[4] === 'X' && p[7] === 'Y' && p.slice(5, 7) === p.slice(8, 10) && p[5] < 8 && p[6] < 8) { | ||
places = [+p[5], +p[6]]; | ||
} | ||
if ((places == null) || (nota == null) || (zero == null)) { | ||
var _, base, base1, m, nota, pM, pN, zero; | ||
if (!(m = p.match(reFS))) { | ||
throw new Error('invalid format specification'); | ||
} | ||
_ = m[0], zero = m[1], nota = m[2], pN = m[3], pM = m[4]; | ||
if (zero !== 'L' && zero !== 'T') { | ||
console.warn('gerber zero suppression is not specified. assuming leading zero suppression (same as no zero suppression)'); | ||
zero = 'L'; | ||
} | ||
if (nota !== 'A' && nota !== 'I') { | ||
console.warn('gerber coordinate notation is not specified. assuming absolute notation'); | ||
nota = 'A'; | ||
} | ||
if ((base = this.format).zero == null) { | ||
@@ -37,3 +43,3 @@ base.zero = zero; | ||
if ((base1 = this.format).places == null) { | ||
base1.places = places; | ||
base1.places = [Number(pN), Number(pM)]; | ||
} | ||
@@ -40,0 +46,0 @@ if (c.set == null) { |
{ | ||
"name": "gerber-to-svg", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Gerber and NC drill file to SVG converter", | ||
@@ -5,0 +5,0 @@ "main": "lib/gerber-to-svg.js", |
@@ -36,5 +36,6 @@ # gerber-to-svg | ||
#### examples: | ||
* `gerber2svg path/to/gerber.gbr` will write the SVG to stdout | ||
* `gerber2svg -o some/dir -- path/to/gerber.gbr` will create some/dir/gerber.svg | ||
* `gerber2svg -d **/*.drl -o out -- gerb/*` will process any files in gerb that end in '.drl' as a drill files, everything else as Gerber files, and output to out | ||
* `$ gerber2svg path/to/gerber.gbr` will write the SVG to stdout | ||
* `$ gerber2svg -o some/dir -- path/to/gerber.gbr` will create some/dir/gerber.svg | ||
* `$ gerber2svg -d **/*.drl -o out -- gerb/*` will process any files in gerb that end in '.drl' as a drill files, everything else as Gerber files, and output to out | ||
* `$ gerber2svg -o out -j -- gerber.gbr` will output `gerber.json` in directory `out` | ||
@@ -45,7 +46,9 @@ ### api (node and browser) | ||
`$ npm install --save gerber-to-svg` | ||
1. `$ npm install --save gerber-to-svg` | ||
2. Add `var gerberToSvg = require('gerber-to-svg');` to your script | ||
With Bower: | ||
`$ bower install --save gerber-to-svg` | ||
1. `$ bower install --save gerber-to-svg` | ||
2. Add `<script src="/bower_components/gerber-to-svg/dist/gerber-to-svg.js"></script>` to your HTML | ||
@@ -59,7 +62,8 @@ If you'd rather not manage your packages: | ||
``` javascript | ||
var gerberToSvg = require('gerber-to-svg'); | ||
// get an svg string | ||
var svgString = gerberToSvg(gerberString, opts); | ||
// get an svg object and then convert that object into a string | ||
var svgObj = gerberToSvg(gerberString, { object: true } ) | ||
var svgString = gerberToSvg(svgObj) | ||
var svgObj = gerberToSvg(gerberString, {object: true}); | ||
var svgString = gerberToSvg(svgObj); | ||
``` | ||
@@ -124,3 +128,3 @@ Where `gerberString` is the gerber file (e.g. from fs.readFile encoded with UTF-8) or an SVG object previously outputted by the function. | ||
var gerberFile = require('fs').readFileSync('./path/to/file.gbr', 'utf-8') | ||
var svgString = gerberToSvg(gerberFile, { pretty: true } ) | ||
var svgString = gerberToSvg(gerberFile, {pretty: true}) | ||
// outputs pretty printed SVG | ||
@@ -134,5 +138,5 @@ console.log(svgString) | ||
# get the layer object | ||
frontObj = gerberToSvg gerberFront, { object: true } | ||
backObj = gerberToSvg gerberBack, { object: true } | ||
drillObj = gerberToSvg drillFile, { object: true, drill: true} | ||
frontObj = gerberToSvg gerberFront, {object: true} | ||
backObj = gerberToSvg gerberBack, {object: true} | ||
drillObj = gerberToSvg drillFile, {object: true, drill: true} | ||
# pull the layer origin offsets from the viewBox | ||
@@ -162,5 +166,5 @@ offsetFront = frontObj.svg.viewBox[0..1] | ||
## things to watch out for | ||
The produced image should be correct, but if issues do occur, they'll most likely be with arcs or step / repeat blocks. It's possible a floating point rounding error or several could throw things off. | ||
The produced image should be correct, but if issues do occur, they'll most likely be with arcs or step/repeat blocks. It's possible a floating point rounding error or several could throw things off. | ||
Certain exceptions to the spec have been made to allow some older and/or improperly written files to process, but if they're not technically to spec, they won't necessarily process without throwing an error. Try / catches are your friend. | ||
Certain exceptions to the spec have been made to allow some older and/or improperly written files to process, but if they're not technically to spec, they won't necessarily process without throwing an error. Try/catches are your friend. | ||
@@ -167,0 +171,0 @@ If it messes up, open up an issue and attach your Gerber, if you can. I appreciate files to test on. |
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
201897
5216
191