UNPKG

@urpflanze/gcode-exporter

Version:
2 lines 13.3 kB
/*! For license information please see urpflanze-gcode-exporter.min.js.LICENSE.txt */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.GCODEExporter=e():t.GCODEExporter=e()}(window,(function(){return t={704:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.GCODEExporter=void 0;const r=n(313),o=n(479),i=n(825);class a{static parse(t,e){const n={...a.defaults,...e};return a.generate(t,n).join("\n")}static setUnit(t){return"inches"===t?"G20":"G21"}static useRelativePosition(){return"G91"}static useAbsolutePosition(){return"G90"}static goHome(t){return[t,"G28 X0 Y0"]}static setCurrentMachinePosition(t,e,n){return`G28.1 X${i.round(t,n)} Y${i.round(e,n)}`}static setCurrentWorkspacePosition(t,e,n){return`G92 X${i.round(t,n)} Y${i.round(e,n)}`}static goTo(t,e,n,r){return void 0!==r?`G1 X${i.round(t,n)} Y${i.round(e,n)} F${r}`:`G0 X${i.round(t,n)} Y${i.round(e,n)}`}static moveTo(t,e,n,r,o){return[t,this.goTo(n,r,o),e]}static lineTo(t,e,n,r){return this.goTo(t,e,r,n)}static generate(t,e){const n=e.maxX-e.minX,s=e.maxY-e.minY,c=n/s,u=t.width/t.height,f=[c>u?t.width*s/t.height:n,c>u?s:t.height*n/t.width],l=[(n-f[0])/2,(s-f[1])/2],h=c>u?t.width/f[0]:t.height/f[1],p=[];i.concat(p,e.penUpCommand),i.concat(p,this.setUnit(e.unit)),i.concat(p,this.useAbsolutePosition()),i.concat(p,this.setCurrentMachinePosition(e.minX,e.minY,e.decimals)),i.concat(p,this.setCurrentWorkspacePosition(e.minX,e.minY,e.decimals));const d=t.getChildren();for(let t=0,n=d.length;t<n;t++){d[t].generate(0,!0);const n=d[t].getBuffer()||[],s=d[t].getIndexedBuffer()||[];let c=0;for(let t=0,u=s.length;t<u;t++){const u=s[t],f=r.clamp(e.minX,e.maxX,e.minX+n[c]/h+l[0]),d=r.clamp(e.minY,e.maxY,e.minY+n[c+1]/h+l[1]);i.concat(p,this.moveTo(e.penUpCommand,e.penDownCommand,f,d,e.decimals));const m=a.pointsToBuffer(o(a.bufferToPoints(n.slice(c,c+u.frameLength)),1/10**e.decimals,!0));for(let t=0,n=m.length;t<n;t+=2){const n=r.clamp(e.minX,e.maxX,e.minX+m[t]/h+l[0]),o=r.clamp(e.minY,e.maxY,e.minY+m[t+1]/h+l[1]);i.concat(p,this.lineTo(n,o,e.velocity,e.decimals))}u.shape.isClosed()&&i.concat(p,this.lineTo(f,d,e.velocity,e.decimals)),c+=u.frameLength}}return i.concat(p,this.goHome(e.penUpCommand)),p}static bufferToPoints(t){const e=[];for(let n=0,r=t.length;n<r;n+=2)e.push({x:t[n],y:t[n+1]});return e}static pointsToBuffer(t){const e=[];for(let n=0,r=t.length;n<r;n++)e.push(t[n].x),e.push(t[n].y);return Float32Array.from(e)}}e.GCODEExporter=a,a.defaults={minX:0,minY:0,maxX:297,maxY:210,unit:"millimeters",velocity:1500,penUpCommand:"M3 S30",penDownCommand:"M3 S0",decimals:2}},915:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[n]}})}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),o(n(291),e),o(n(704),e)},291:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0})},825:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.concat=e.round=void 0,e.round=(t,e)=>Math.round(t*10**e)/10**e,e.concat=(t,e)=>{"string"==typeof e?t.push(e):e.forEach((e=>t.push(e)))}},313:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.interpolate=e.prepareBufferForInterpolation=e.distributePointsInBuffer=e.distanceFromRepetition=e.angle2FromRepetition=e.angleFromRepetition=e.random=e.noise=e.relativeClamp=e.clamp=e.lerp=e.toRadians=e.toDegrees=e.now=void 0;const r=n(21),o=n(769),i=n(795),a="undefined"!=typeof performance?performance:Date;function s(t,e,n){return n<=t?t:n>=e?e:n}e.now=function(){return a.now()},e.toDegrees=function(t){return 180*t/Math.PI},e.toRadians=function(t){return t*Math.PI/180},e.lerp=function(t,e,n){return(1-n)*t+n*e},e.clamp=s,e.relativeClamp=function(t,e,n,r,o){return s(r,o,(n-t)/(e-t)*(o-r)+r)};const c={random:new r(Math.random)};e.noise=function(t="random",e=0,n=0,o=0,i=-1,a=1){void 0===c[t]&&(c[t]=new r(t));const s=c[t].noise3D(e,n,o);return-1!==i||1!==a?(.5+.5*s)*(a-i)+i:s};const u={};function f(t,e){const n=t.length,r=n/2,o=2*(r+e),i=r-1;if(i>1){const r=n-2,a=Math.floor(e/i);let s=(o-(n+a*r))/2;const c=Math.round(i/s),u=new Float32Array(o);for(let e=0,n=0,o=0;e<r;e+=2,n++,o+=2){const i=t[e],f=t[e+1],l=t[e+2],h=t[e+3];u[o]=i,u[o+1]=f;const p=s>0&&(n%c==0||e===r-2),d=a+(p?1:0),m=1/(d+1);for(let t=0;t<d;t++,o+=2){const e=m*(t+1);u[o+2]=(1-e)*i+e*l,u[o+3]=(1-e)*f+e*h}p&&s--}return u[o-2]=t[n-2],u[o-1]=t[n-1],u}const a=new Float32Array(o);for(let e=0;e<o;e+=2)a[e]=t[e%n],a[e+1]=t[(e+1)%n];return a}function l(t,e){const n=t.length,r=e.length;if(n===r)return[t,e];const o=Math.abs(n-r),i=n<r?e:t,a=f(n<r?t:e,Math.floor(o/2));return n>r?[i,a]:[a,i]}e.random=function(t,e=0,n=1,r){const o=t+"";if(void 0===u[o]){const t=function(t){let e=0,n=1779033703^t.length;for(;e<t.length;e++)n=Math.imul(n^t.charCodeAt(e),3432918353),n=n<<13|n>>>19;return function(){return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),(n^=n>>>16)>>>0}}(o);u[o]=(i=t(),a=t(),s=t(),c=t(),function(){let t=(i>>>=0)+(a>>>=0)|0;return i=a^a>>>9,a=(s>>>=0)+(s<<3)|0,t=t+(c=1+(c>>>=0)|0)|0,s=(s=s<<21|s>>>11)+t|0,(t>>>0)/4294967296})}var i,a,s,c;const f=e+u[o]()*(n-e);return void 0!==r?Math.round(f*10**r)/10**r:f},e.angleFromRepetition=function(t,e=[0,0]){if(t.type===o.ERepetitionType.Matrix){const n=[(t.col.count-1)/2,(t.row.count-1)/2];n[0]+=n[0]*e[0],n[1]+=n[1]*e[1];const r=t.col.index-1-n[0],o=t.row.index-1-n[1];return 0===r?0:Math.atan(o/r)}return(t.angle-Math.PI)/2},e.angle2FromRepetition=function(t,e=[0,0]){if(t.type===o.ERepetitionType.Matrix){const n=[(t.col.count-1)/2,(t.row.count-1)/2];n[0]+=n[0]*e[0],n[1]+=n[1]*e[1];const r=t.col.index-1-n[0],o=t.row.index-1-n[1];return 0===r?0:Math.atan2(o,r)}return t.angle-Math.PI},e.distanceFromRepetition=function(t,e=[0,0]){if(t.type===o.ERepetitionType.Matrix){const n=[.5,.5];n[0]+=n[0]*e[0],n[1]+=n[1]*e[1];const r=[t.col.offset,t.row.offset];return i.default.distance(r,n)}return 1},e.distributePointsInBuffer=f,e.prepareBufferForInterpolation=l,e.interpolate=function(t,e,n=.5){const[r,o]=l(t,e),i=Math.max(r.length,o.length),a="number"==typeof n?[n]:n,s=i/2;if(a.length!==s){const t=a.length;for(let e=0;e<s;e++)a[e]=a[e%t]}const c=new Float32Array(i);for(let t=0,e=0;t<i;t+=2,e++)c[t]=(1-a[e])*r[t]+a[e]*o[t],c[t+1]=(1-a[e])*r[t+1]+a[e]*o[t+1];return c}},795:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});const n=new Array(4),r={from:(t=0,e)=>{const n=new Array(2);return"number"==typeof t?(n[0]=t,n[1]=null!=e?e:t):(n[0]=t[0],n[1]=t[1]),n},normalize:t=>{const e=r.length(t);return 0!==e?[t[0]/e,t[1]/e]:[0,0]},distance:(t,e)=>Math.hypot(t[0]-e[0],t[1]-e[1]),dot:(t,e)=>t[0]*e[0]+t[1]*e[1],length:t=>Math.hypot(t[0],t[1]),angle:(t,e)=>(t=r.normalize(t),e=r.normalize(e),Math.acos(r.dot(t,e))),skewX:(t,e)=>{t[0]+=Math.tan(e)*t[1]},skewY:(t,e)=>{t[1]+=Math.tan(e)*t[0]},squeezeX:(t,e)=>{t[1]+=t[1]*(t[0]*-e)},squeezeY:(t,e)=>{t[0]+=t[0]*(t[1]*e)},rotate:(t,e,n)=>{const r=t[0]-n[0],o=t[1]-n[1];t[0]=r*e[0]+o*e[1]+n[0],t[1]=r*e[2]+o*e[3]+n[1]},rotateX:(t,e,o)=>{n[0]=1,n[1]=0,n[2]=0,n[3]=Math.cos(o),r.rotate(t,n,e)},rotateY:(t,e,o)=>{n[0]=Math.cos(o),n[1]=0,n[2]=0,n[3]=1,r.rotate(t,n,e)},rotateZ:(t,e,o)=>{n[0]=Math.cos(o),n[1]=-Math.sin(o),n[2]=Math.sin(o),n[3]=Math.cos(o),r.rotate(t,n,e)},translate:(t,e)=>{t[0]+=e[0],t[1]+=e[1]},scale:(t,e)=>{t[0]*=e[0],t[1]*=e[1]},divide:(t,e)=>{t[0]/=e[0],t[1]/=e[1]},toString:t=>`x: ${t[0]}, y: ${t[1]}`,ZERO:Array.from([0,0]),ONE:Array.from([1,1])};e.default=r},769:(t,e)=>{"use strict";var n;Object.defineProperty(e,"__esModule",{value:!0}),e.ERepetitionType=void 0,(n=e.ERepetitionType||(e.ERepetitionType={}))[n.Ring=1]="Ring",n[n.Matrix=2]="Matrix"},21:(t,e,n)=>{var r;!function(){"use strict";var o=.5*(Math.sqrt(3)-1),i=(3-Math.sqrt(3))/6,a=1/6,s=(Math.sqrt(5)-1)/4,c=(5-Math.sqrt(5))/20;function u(t){var e;e="function"==typeof t?t:t?function(){var t=0,e=0,n=0,r=1,o=l();t=o(" "),e=o(" "),n=o(" ");for(var i=0;i<arguments.length;i++)(t-=o(arguments[i]))<0&&(t+=1),(e-=o(arguments[i]))<0&&(e+=1),(n-=o(arguments[i]))<0&&(n+=1);return o=null,function(){var o=2091639*t+2.3283064365386963e-10*r;return t=e,e=n,n=o-(r=0|o)}}(t):Math.random,this.p=f(e),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(var n=0;n<512;n++)this.perm[n]=this.p[255&n],this.permMod12[n]=this.perm[n]%12}function f(t){var e,n=new Uint8Array(256);for(e=0;e<256;e++)n[e]=e;for(e=0;e<255;e++){var r=e+~~(t()*(256-e)),o=n[e];n[e]=n[r],n[r]=o}return n}function l(){var t=4022871197;return function(e){e=e.toString();for(var n=0;n<e.length;n++){var r=.02519603282416938*(t+=e.charCodeAt(n));r-=t=r>>>0,t=(r*=t)>>>0,t+=4294967296*(r-=t)}return 2.3283064365386963e-10*(t>>>0)}}u.prototype={grad3:new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),grad4:new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]),noise2D:function(t,e){var n,r,a=this.permMod12,s=this.perm,c=this.grad3,u=0,f=0,l=0,h=(t+e)*o,p=Math.floor(t+h),d=Math.floor(e+h),m=(p+d)*i,v=t-(p-m),M=e-(d-m);v>M?(n=1,r=0):(n=0,r=1);var g=v-n+i,y=M-r+i,x=v-1+2*i,w=M-1+2*i,b=255&p,P=255&d,C=.5-v*v-M*M;if(C>=0){var X=3*a[b+s[P]];u=(C*=C)*C*(c[X]*v+c[X+1]*M)}var Y=.5-g*g-y*y;if(Y>=0){var T=3*a[b+n+s[P+r]];f=(Y*=Y)*Y*(c[T]*g+c[T+1]*y)}var _=.5-x*x-w*w;if(_>=0){var R=3*a[b+1+s[P+1]];l=(_*=_)*_*(c[R]*x+c[R+1]*w)}return 70*(u+f+l)},noise3D:function(t,e,n){var r,o,i,s,c,u,f,l,h,p,d=this.permMod12,m=this.perm,v=this.grad3,M=.3333333333333333*(t+e+n),g=Math.floor(t+M),y=Math.floor(e+M),x=Math.floor(n+M),w=(g+y+x)*a,b=t-(g-w),P=e-(y-w),C=n-(x-w);b>=P?P>=C?(c=1,u=0,f=0,l=1,h=1,p=0):b>=C?(c=1,u=0,f=0,l=1,h=0,p=1):(c=0,u=0,f=1,l=1,h=0,p=1):P<C?(c=0,u=0,f=1,l=0,h=1,p=1):b<C?(c=0,u=1,f=0,l=0,h=1,p=1):(c=0,u=1,f=0,l=1,h=1,p=0);var X=b-c+a,Y=P-u+a,T=C-f+a,_=b-l+2*a,R=P-h+2*a,A=C-p+2*a,E=b-1+.5,O=P-1+.5,F=C-1+.5,j=255&g,D=255&y,G=255&x,$=.6-b*b-P*P-C*C;if($<0)r=0;else{var B=3*d[j+m[D+m[G]]];r=($*=$)*$*(v[B]*b+v[B+1]*P+v[B+2]*C)}var I=.6-X*X-Y*Y-T*T;if(I<0)o=0;else{var U=3*d[j+c+m[D+u+m[G+f]]];o=(I*=I)*I*(v[U]*X+v[U+1]*Y+v[U+2]*T)}var q=.6-_*_-R*R-A*A;if(q<0)i=0;else{var S=3*d[j+l+m[D+h+m[G+p]]];i=(q*=q)*q*(v[S]*_+v[S+1]*R+v[S+2]*A)}var z=.6-E*E-O*O-F*F;if(z<0)s=0;else{var k=3*d[j+1+m[D+1+m[G+1]]];s=(z*=z)*z*(v[k]*E+v[k+1]*O+v[k+2]*F)}return 32*(r+o+i+s)},noise4D:function(t,e,n,r){var o,i,a,u,f,l,h,p,d,m,v,M,g,y,x,w,b,P=this.perm,C=this.grad4,X=(t+e+n+r)*s,Y=Math.floor(t+X),T=Math.floor(e+X),_=Math.floor(n+X),R=Math.floor(r+X),A=(Y+T+_+R)*c,E=t-(Y-A),O=e-(T-A),F=n-(_-A),j=r-(R-A),D=0,G=0,$=0,B=0;E>O?D++:G++,E>F?D++:$++,E>j?D++:B++,O>F?G++:$++,O>j?G++:B++,F>j?$++:B++;var I=E-(l=D>=3?1:0)+c,U=O-(h=G>=3?1:0)+c,q=F-(p=$>=3?1:0)+c,S=j-(d=B>=3?1:0)+c,z=E-(m=D>=2?1:0)+2*c,k=O-(v=G>=2?1:0)+2*c,H=F-(M=$>=2?1:0)+2*c,L=j-(g=B>=2?1:0)+2*c,N=E-(y=D>=1?1:0)+3*c,W=O-(x=G>=1?1:0)+3*c,Z=F-(w=$>=1?1:0)+3*c,J=j-(b=B>=1?1:0)+3*c,K=E-1+4*c,Q=O-1+4*c,V=F-1+4*c,tt=j-1+4*c,et=255&Y,nt=255&T,rt=255&_,ot=255&R,it=.6-E*E-O*O-F*F-j*j;if(it<0)o=0;else{var at=P[et+P[nt+P[rt+P[ot]]]]%32*4;o=(it*=it)*it*(C[at]*E+C[at+1]*O+C[at+2]*F+C[at+3]*j)}var st=.6-I*I-U*U-q*q-S*S;if(st<0)i=0;else{var ct=P[et+l+P[nt+h+P[rt+p+P[ot+d]]]]%32*4;i=(st*=st)*st*(C[ct]*I+C[ct+1]*U+C[ct+2]*q+C[ct+3]*S)}var ut=.6-z*z-k*k-H*H-L*L;if(ut<0)a=0;else{var ft=P[et+m+P[nt+v+P[rt+M+P[ot+g]]]]%32*4;a=(ut*=ut)*ut*(C[ft]*z+C[ft+1]*k+C[ft+2]*H+C[ft+3]*L)}var lt=.6-N*N-W*W-Z*Z-J*J;if(lt<0)u=0;else{var ht=P[et+y+P[nt+x+P[rt+w+P[ot+b]]]]%32*4;u=(lt*=lt)*lt*(C[ht]*N+C[ht+1]*W+C[ht+2]*Z+C[ht+3]*J)}var pt=.6-K*K-Q*Q-V*V-tt*tt;if(pt<0)f=0;else{var dt=P[et+1+P[nt+1+P[rt+1+P[ot+1]]]]%32*4;f=(pt*=pt)*pt*(C[dt]*K+C[dt+1]*Q+C[dt+2]*V+C[dt+3]*tt)}return 27*(o+i+a+u+f)}},u._buildPermutationTable=f,void 0===(r=function(){return u}.call(e,n,e,t))||(t.exports=r),e.SimplexNoise=u,t.exports=u}()},479:(t,e,n)=>{var r;!function(){"use strict";function o(t,e,n){var r=e.x,o=e.y,i=n.x-r,a=n.y-o;if(0!==i||0!==a){var s=((t.x-r)*i+(t.y-o)*a)/(i*i+a*a);s>1?(r=n.x,o=n.y):s>0&&(r+=i*s,o+=a*s)}return(i=t.x-r)*i+(a=t.y-o)*a}function i(t,e,n,r,a){for(var s,c=r,u=e+1;u<n;u++){var f=o(t[u],t[e],t[n]);f>c&&(s=u,c=f)}c>r&&(s-e>1&&i(t,e,s,r,a),a.push(t[s]),n-s>1&&i(t,s,n,r,a))}function a(t,e){var n=t.length-1,r=[t[0]];return i(t,0,n,e,r),r.push(t[n]),r}function s(t,e,n){if(t.length<=2)return t;var r=void 0!==e?e*e:1;return a(t=n?t:function(t,e){for(var n,r,o,i,a,s=t[0],c=[s],u=1,f=t.length;u<f;u++)o=s,void 0,void 0,(i=(r=n=t[u]).x-o.x)*i+(a=r.y-o.y)*a>e&&(c.push(n),s=n);return s!==n&&c.push(n),c}(t,r),r)}void 0===(r=function(){return s}.call(e,n,e,t))||(t.exports=r)}()}},e={},function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}(915);var t,e}));