Files
QIDI_PLUS4/fluidd/assets/parseGcode.worker-DKc0-WBC.js
2024-12-04 10:21:57 +08:00

6 lines
13 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function(){"use strict";const ee=(e,t)=>e in t;var te=typeof global=="object"&&global&&global.Object===Object&&global,ne=typeof self=="object"&&self&&self.Object===Object&&self,I=te||ne||Function("return this")(),g=I.Symbol,D=Object.prototype,re=D.hasOwnProperty,ie=D.toString,w=g?g.toStringTag:void 0;function oe(e){var t=re.call(e,w),n=e[w];try{e[w]=void 0;var r=!0}catch{}var o=ie.call(e);return r&&(t?e[w]=n:delete e[w]),o}var ae=Object.prototype,se=ae.toString;function ce(e){return se.call(e)}var le="[object Null]",ue="[object Undefined]",H=g?g.toStringTag:void 0;function $(e){return e==null?e===void 0?ue:le:H&&H in Object(e)?oe(e):ce(e)}function A(e){return e!=null&&typeof e=="object"}var fe="[object Symbol]";function F(e){return typeof e=="symbol"||A(e)&&$(e)==fe}function he(e,t){for(var n=-1,r=e==null?0:e.length,o=Array(r);++n<r;)o[n]=t(e[n],n,e);return o}var x=Array.isArray,pe=1/0,L=g?g.prototype:void 0,U=L?L.toString:void 0;function Q(e){if(typeof e=="string")return e;if(x(e))return he(e,Q)+"";if(F(e))return U?U.call(e):"";var t=e+"";return t=="0"&&1/e==-pe?"-0":t}function S(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}function de(e){return e}var ge="[object AsyncFunction]",ye="[object Function]",_e="[object GeneratorFunction]",me="[object Proxy]";function be(e){if(!S(e))return!1;var t=$(e);return t==ye||t==_e||t==ge||t==me}var N=I["__core-js_shared__"],k=function(){var e=/[^.]+$/.exec(N&&N.keys&&N.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function ve(e){return!!k&&k in e}var we=Function.prototype,xe=we.toString;function Oe(e){if(e!=null){try{return xe.call(e)}catch{}try{return e+""}catch{}}return""}var Ce=/[\\^$.*+?()[\]{}|]/g,Se=/^\[object .+?Constructor\]$/,Pe=Function.prototype,Ee=Object.prototype,Te=Pe.toString,ze=Ee.hasOwnProperty,Ie=RegExp("^"+Te.call(ze).replace(Ce,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function $e(e){if(!S(e)||ve(e))return!1;var t=be(e)?Ie:Se;return t.test(Oe(e))}function Ae(e,t){return e==null?void 0:e[t]}function j(e,t){var n=Ae(e,t);return $e(n)?n:void 0}function Fe(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var Ne=800,je=16,Me=Date.now;function Re(e){var t=0,n=0;return function(){var r=Me(),o=je-(r-n);if(n=r,o>0){if(++t>=Ne)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function Ge(e){return function(){return e}}var P=function(){try{var e=j(Object,"defineProperty");return e({},"",{}),e}catch{}}(),De=P?function(e,t){return P(e,"toString",{configurable:!0,enumerable:!1,value:Ge(t),writable:!0})}:de,He=Re(De),Le=9007199254740991,Ue=/^(?:0|[1-9]\d*)$/;function q(e,t){var n=typeof e;return t=t??Le,!!t&&(n=="number"||n!="symbol"&&Ue.test(e))&&e>-1&&e%1==0&&e<t}function Qe(e,t,n){t=="__proto__"&&P?P(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}function X(e,t){return e===t||e!==e&&t!==t}var ke=Object.prototype,qe=ke.hasOwnProperty;function Xe(e,t,n){var r=e[t];(!(qe.call(e,t)&&X(r,n))||n===void 0&&!(t in e))&&Qe(e,t,n)}var K=Math.max;function Ke(e,t,n){return t=K(t===void 0?e.length-1:t,0),function(){for(var r=arguments,o=-1,s=K(r.length-t,0),c=Array(s);++o<s;)c[o]=r[t+o];o=-1;for(var a=Array(t+1);++o<t;)a[o]=r[o];return a[t]=n(c),Fe(e,this,a)}}var Je=9007199254740991;function Be(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Je}var Ye="[object Arguments]";function J(e){return A(e)&&$(e)==Ye}var B=Object.prototype,Ze=B.hasOwnProperty,Ve=B.propertyIsEnumerable,Y=J(function(){return arguments}())?J:function(e){return A(e)&&Ze.call(e,"callee")&&!Ve.call(e,"callee")},We=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,et=/^\w*$/;function tt(e,t){if(x(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||F(e)?!0:et.test(e)||!We.test(e)||t!=null&&e in Object(t)}var O=j(Object,"create");function nt(){this.__data__=O?O(null):{},this.size=0}function rt(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var it="__lodash_hash_undefined__",ot=Object.prototype,at=ot.hasOwnProperty;function st(e){var t=this.__data__;if(O){var n=t[e];return n===it?void 0:n}return at.call(t,e)?t[e]:void 0}var ct=Object.prototype,lt=ct.hasOwnProperty;function ut(e){var t=this.__data__;return O?t[e]!==void 0:lt.call(t,e)}var ft="__lodash_hash_undefined__";function ht(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=O&&t===void 0?ft:t,this}function _(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}_.prototype.clear=nt,_.prototype.delete=rt,_.prototype.get=st,_.prototype.has=ut,_.prototype.set=ht;function pt(){this.__data__=[],this.size=0}function E(e,t){for(var n=e.length;n--;)if(X(e[n][0],t))return n;return-1}var dt=Array.prototype,gt=dt.splice;function yt(e){var t=this.__data__,n=E(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():gt.call(t,n,1),--this.size,!0}function _t(e){var t=this.__data__,n=E(t,e);return n<0?void 0:t[n][1]}function mt(e){return E(this.__data__,e)>-1}function bt(e,t){var n=this.__data__,r=E(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}function v(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}v.prototype.clear=pt,v.prototype.delete=yt,v.prototype.get=_t,v.prototype.has=mt,v.prototype.set=bt;var vt=j(I,"Map");function wt(){this.size=0,this.__data__={hash:new _,map:new(vt||v),string:new _}}function xt(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function T(e,t){var n=e.__data__;return xt(t)?n[typeof t=="string"?"string":"hash"]:n.map}function Ot(e){var t=T(this,e).delete(e);return this.size-=t?1:0,t}function Ct(e){return T(this,e).get(e)}function St(e){return T(this,e).has(e)}function Pt(e,t){var n=T(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}function m(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}m.prototype.clear=wt,m.prototype.delete=Ot,m.prototype.get=Ct,m.prototype.has=St,m.prototype.set=Pt;var Et="Expected a function";function M(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(Et);var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],s=n.cache;if(s.has(o))return s.get(o);var c=e.apply(this,r);return n.cache=s.set(o,c)||s,c};return n.cache=new(M.Cache||m),n}M.Cache=m;var Tt=500;function zt(e){var t=M(e,function(r){return n.size===Tt&&n.clear(),r}),n=t.cache;return t}var It=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,$t=/\\(\\)?/g,At=zt(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(It,function(n,r,o,s){t.push(o?s.replace($t,"$1"):r||n)}),t});function Ft(e){return e==null?"":Q(e)}function z(e,t){return x(e)?e:tt(e,t)?[e]:At(Ft(e))}var Nt=1/0;function R(e){if(typeof e=="string"||F(e))return e;var t=e+"";return t=="0"&&1/e==-Nt?"-0":t}function jt(e,t){t=z(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[R(t[n++])];return n&&n==r?e:void 0}function Mt(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}var Z=g?g.isConcatSpreadable:void 0;function Rt(e){return x(e)||Y(e)||!!(Z&&e&&e[Z])}function Gt(e,t,n,r,o){var s=-1,c=e.length;for(n||(n=Rt),o||(o=[]);++s<c;){var a=e[s];n(a)?Mt(o,a):o[o.length]=a}return o}function Dt(e){var t=e==null?0:e.length;return t?Gt(e):[]}function Ht(e){return He(Ke(e,void 0,Dt),e+"")}function Lt(e,t){return e!=null&&t in Object(e)}function Ut(e,t,n){t=z(t,e);for(var r=-1,o=t.length,s=!1;++r<o;){var c=R(t[r]);if(!(s=e!=null&&n(e,c)))break;e=e[c]}return s||++r!=o?s:(o=e==null?0:e.length,!!o&&Be(o)&&q(c,o)&&(x(e)||Y(e)))}function Qt(e,t){return e!=null&&Ut(e,t,Lt)}function kt(e,t,n,r){if(!S(e))return e;t=z(t,e);for(var o=-1,s=t.length,c=s-1,a=e;a!=null&&++o<s;){var h=R(t[o]),i=n;if(h==="__proto__"||h==="constructor"||h==="prototype")return e;if(o!=c){var u=a[h];i=void 0,i===void 0&&(i=S(u)?u:q(t[o+1])?[]:{})}Xe(a,h,i),a=a[h]}return e}function qt(e,t,n){for(var r=-1,o=t.length,s={};++r<o;){var c=t[r],a=jt(e,c);n(a,c)&&kt(s,z(c,e),a)}return s}function Xt(e,t){return qt(e,t,function(n,r){return Qt(e,r)})}var V=Ht(function(e,t){return e==null?{}:Xt(e,t)});function Kt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var W={};(function(e){class t{constructor(r){this.i=0,this.string=r,this.whitespace=` \r
`,this.quotes=`'"`,this.escapes="\\",this.escapedQuotes='"',this.ansiCQuotes=!0,this.localeQuotes=!0,this.debug=!1}readChar(){return this.string.charAt(this.i++)}processEscapes(r,o,s){if(!s&&!this.escapedQuotes.includes(o))return r;const c="["+this.escapes.replace(/(.)/g,"\\$1")+"]";if(!s&&this.escapedQuotes.includes(o)){const a=new RegExp(c+"("+c+"|\\"+o+")","g");return r.replace(a,"$1")}if(s){const a={"([\\\\'\"?])":i=>i,a:()=>"\x07",b:()=>"\b","e|E":()=>"\x1B",f:()=>"\f",n:()=>`
`,r:()=>"\r",t:()=>" ",v:()=>"\v","([0-7]{1,3})":i=>String.fromCharCode(parseInt(i,8)),"x([0-9a-fA-F]{1,2})":i=>String.fromCharCode(parseInt(i,16)),"u([0-9a-fA-F]{1,4})":i=>String.fromCharCode(parseInt(i,16)),"U([0-9a-fA-F]{1,8})":i=>String.fromCharCode(parseInt(i,16)),"c(.)":i=>i==="?"?"":i==="@"?"\0":String.fromCharCode(i.charCodeAt(0)&31)},h=new RegExp(c+"("+Object.keys(a).join("|")+")","g");return r.replace(h,function(i,u){for(const y in a){const C=new RegExp("^"+y+"$").exec(u);if(C!==null)return a[y].apply(null,C.slice(1))}})}}*[Symbol.iterator](){let r=!1,o=!1,s=!1,c=-2,a;for(this.debug&&console.log("full input:",">"+this.string+"<");;){const h=this.i,i=this.readChar();if(this.debug&&console.log("position:",h,"input:",">"+i+"<","accumulated:",a,"inQuote:",r,"inDollarQuote:",o,"lastDollar:",c,"escaped:",s),i===""){if(r)throw new Error("Got EOF while in a quoted string");if(s)throw new Error("Got EOF while in an escape sequence");a!==void 0&&(yield a);return}if(s){i===`
`||(r?a=(a||"")+s+i:a=(a||"")+i),s=!1;continue}if(this.escapes.includes(i)&&(!r||o!==!1||this.escapedQuotes.includes(r))){s=i;continue}if(r!==!1){if(i===r){a=this.processEscapes(a,r,o==="'"),r=!1,o=!1;continue}a=(a||"")+i;continue}if(this.quotes.includes(i)){r=i,c===h-1&&(i==="'"&&!this.ansiCQuotes||i==='"'&&!this.localeQuotes||(o=i)),a=a||"",o!==!1&&(a=a.slice(0,-1));continue}if(r===!1&&i==="$"&&(c=h),this.whitespace.includes(i)){a!==void 0&&(yield a),a=void 0;continue}a=(a||"")+i}}}e.split=function(n){return Array.from(new t(n))},e.quote=function(n){return n===""?"''":/[^\w@%\-+=:,./]/.test(n)?("'"+n.replace(/('+)/g,`'"$1"'`)+"'").replace(/^''|''$/g,""):n},e.join=function(n){if(!Array.isArray(n))throw new TypeError("args should be an array");return n.map(e.quote).join(" ")}})(W);var Jt=Kt(W);const Bt=e=>{const t={};for(const[,n,r]of e.matchAll(/([a-z])[ \t]*(-?(?:\d+(?:\.\d+)?|\.\d+))/ig))t[n.toLowerCase()]=+r;return t},Yt=e=>{const t={};for(const n of Jt.split(e)){const r=n.indexOf("="),o=n.substring(0,r),s=n.substring(r+1);t[o.toLowerCase()]=s}return t},Zt=e=>{const t=e.trim().split(";",2)[0],[,n,r=""]=t.split(/^([gm][0-9]+)\s*/i);if(n)return{type:"gcode",command:n.toUpperCase(),args:Bt(r)};const[,o,s=""]=t.split(/^(SET_PRINT_STATS_INFO|EXCLUDE_OBJECT_DEFINE|SET_RETRACTION)\s+/i);return o?{type:"macro",command:o.toUpperCase(),args:Yt(s)}:{type:"other"}},b=e=>Math.round(e*1e4)/1e4,Vt=(e,t)=>{const n=[],r=[],o=[],s=e.split(`
`);let c=!1,a="relative",h="absolute";const i={x:0,y:0,z:0,e:0,filePosition:0},u={length:1,extrudeExtra:0,z:0};for(let y=0;y<s.length;y++){const{type:C,command:G,args:f}=Zt(s[y])??{};let l=null;if(C==="macro")switch(G){case"SET_PRINT_STATS_INFO":"current_layer"in f&&(c=!0);break;case"EXCLUDE_OBJECT_DEFINE":if("polygon"in f&&f.polygon){const d={polygon:JSON.parse(f.polygon).map(([tn,nn])=>({x:tn,y:nn}))};o.push(Object.freeze(d))}break;case"SET_RETRACTION":"retract_length"in f&&(u.length=+f.retract_length),"unretract_extra_length"in f&&(u.extrudeExtra=+f.unretract_extra_length);break}else if(C==="gcode"){switch(G){case"G0":case"G1":{const p=["x","y","z","e"];p.some(d=>d in f)&&(l={...V(f,p),filePosition:i.filePosition});break}case"G2":case"G3":{const p=["x","y","z","e","i","j","k","r"];p.some(d=>d in f)&&(l={...V(f,p),direction:G==="G2"?"clockwise":"counter-clockwise",filePosition:i.filePosition});break}case"G10":l={e:-u.length,filePosition:i.filePosition},u.z!==0&&(l.z=b(i.z+u.z));break;case"G11":l={e:b(u.length+u.extrudeExtra),filePosition:i.filePosition},u.z!==0&&(l.z=b(i.z-u.z));break;case"G90":h="absolute";case"M82":a="absolute",i.e=0;break;case"G91":h="relative";case"M83":a="relative";break;case"G92":a==="absolute"&&(i.e=f.e??i.e),h==="absolute"&&(i.x=f.x??i.x,i.y=f.y??i.y,i.z=f.z??i.z);break;case"M207":u.length=f.s??u.length,u.z=f.z??u.z;break}if(l){if(a==="absolute"&&l.e!==void 0){const p=b(l.e-i.e);i.e=l.e,l.e=p}if(h==="relative"&&(l.x!==void 0&&(l.x=b(l.x+i.x)),l.y!==void 0&&(l.y=b(l.y+i.y)),l.z!==void 0&&(l.z=b(l.z+i.z))),c&&l.e&&l.e>0){const p=l;if(["x","y","i","j"].some(d=>ee(d,p)&&p[d]!==0)){const d={z:i.z,move:n.length-1,filePosition:i.filePosition};r.push(Object.freeze(d)),c=!1}}i.x=l.x??i.x,i.y=l.y??i.y,i.z=l.z??i.z,n.push(Object.freeze(l))}}y%Math.floor(s.length/100)===0&&t(i.filePosition),i.filePosition+=s[y].length+1}return t(i.filePosition),{moves:n,layers:r,parts:o}},Wt=e=>{const t={action:"progress",filePosition:e};self.postMessage(t)},en=(e,t,n)=>{const r={action:"result",moves:e,layers:t,parts:n};self.postMessage(r)};self.onmessage=e=>{const t=e.data;switch(t.action){case"parse":{const{moves:n,layers:r,parts:o}=Vt(t.gcode,Wt);en(n,r,o);break}}}})();