@sienci/gviewer 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{GCodeSVGRenderer-DBuIVjIT.js → GCodeSVGRenderer-DUQ-WgJi.js} +286 -270
- package/dist/{GCodeSVGRenderer-CUIpGM_S.cjs → GCodeSVGRenderer-hZ8tZwov.cjs} +1 -1
- package/dist/gviewer.cjs +1 -1
- package/dist/gviewer.js +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +39 -38
- package/dist/types/react/GCodeSVGVisualizer.d.ts +6 -0
- package/dist/types/viewer/svg/GCodeSVGRenderer.d.ts +6 -0
- package/dist/viewer.cjs +1 -1
- package/dist/viewer.js +1 -1
- package/package.json +1 -1
package/dist/gviewer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=/([A-Za-z])\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+))/g;class Z{parseLine(e){const n=[],t=this.stripComments(e,n),s=this.parseWords(t),r=s.filter(a=>{const c=a.letter.toUpperCase();return c==="G"||c==="M"}),i=s.filter(a=>{const c=a.letter.toUpperCase();return c!=="G"&&c!=="M"});return{raw:e,words:s,gcodes:r,params:i,comments:n}}stripComments(e,n){let t="",s=!1,r=-1,i="";for(let a=0;a<e.length;a+=1){const c=e[a];if(!s&&c===";"){const u=e.slice(a+1);n.push({type:"semicolon",text:u,start:a,end:e.length});break}if(c==="("){s?i+=c:(s=!0,r=a,i="");continue}if(c===")"&&s){n.push({type:"paren",text:i,start:r,end:a+1}),s=!1,r=-1,i="";continue}if(s){i+=c;continue}t+=c}return s&&n.push({type:"paren",text:i,start:r,end:e.length}),t}parseWords(e){const n=[];for(const t of e.matchAll($)){const s=t[0],r=t[1].toUpperCase(),i=Number(t[2]),a=t.index??0,c=a+s.length;n.push({letter:r,value:i,raw:s,start:a,end:c})}return n}}const g=["X","Y","Z","A","B","C"],C={motion:"G0",distance:"G90",plane:"G17",units:"G21",feedMode:"G94",feedRate:null,spindleSpeed:null,tool:null,coolant:null,spindle:null,coordinateSystem:"G54"};class I{constructor(e={}){this.parser=new Z,this.modals={...C},this.position={X:0,Y:0,Z:0,A:0,B:0,C:0},this.callbacks=e,this.feedRates=new Set,this.spindleSpeeds=new Set,this.tools=new Set}setCallbacks(e){this.callbacks=e}getModals(){return{...this.modals}}getPosition(){return{...this.position}}getUniqueFeedRates(){return Array.from(this.feedRates)}getUniqueSpindleSpeeds(){return Array.from(this.spindleSpeeds)}getUniqueTools(){return Array.from(this.tools)}reset(){this.modals={...C},this.position={X:0,Y:0,Z:0,A:0,B:0,C:0},this.feedRates.clear(),this.spindleSpeeds.clear(),this.tools.clear()}processLine(e){const n=this.parser.parseLine(e),t={...this.position};this.updateModals(n);const s=this.modals.motion,r=this.modals.plane;let i=this.applyAxes(n,t),a,c,u="none";return s==="G0"||s==="G1"?T(t,i)||(u="linear",this.position={...i},this.emitLinear({start:t,end:i})):(s==="G2"||s==="G3")&&(T(t,i)||(u="arc",c=this.arcCenter(n,t,i,r),a=this.computeArcMax(t,i,s,r,c),this.position={...i},this.emitArc({start:t,end:i,max:a,center:c,plane:r,motion:s}))),{parsed:n,modals:{...this.modals},start:t,end:i,movement:u,arcMax:a}}unitsScale(){return this.modals.units==="G20"?25.4:1}updateModals(e){for(const n of e.gcodes){if(n.letter.toUpperCase()==="G"){const t=`G${Math.trunc(n.value)}`;(t==="G0"||t==="G1"||t==="G2"||t==="G3")&&(this.modals.motion=t),(t==="G90"||t==="G91")&&(this.modals.distance=t),(t==="G17"||t==="G18"||t==="G19")&&(this.modals.plane=t),(t==="G20"||t==="G21")&&(this.modals.units=t),(t==="G93"||t==="G94")&&(this.modals.feedMode=t),(t==="G54"||t==="G55"||t==="G56"||t==="G57"||t==="G58"||t==="G59")&&(this.modals.coordinateSystem=t)}if(n.letter.toUpperCase()==="M"){const t=`M${Math.trunc(n.value)}`;(t==="M7"||t==="M8"||t==="M9")&&(this.modals.coolant=t),(t==="M3"||t==="M4"||t==="M5")&&(this.modals.spindle=t)}}for(const n of e.params){const t=n.letter.toUpperCase();t==="F"&&(this.modals.feedRate=n.value,this.feedRates.add(n.value)),t==="S"&&(this.modals.spindleSpeed=n.value,this.spindleSpeeds.add(n.value)),t==="T"&&(this.modals.tool=n.value,this.tools.add(n.value))}}applyAxes(e,n){const t={...n},s=this.unitsScale();for(const r of g){const i=e.params.find(c=>c.letter.toUpperCase()===r);if(!i)continue;const a=r==="X"||r==="Y"||r==="Z"?i.value*s:i.value;this.modals.distance==="G90"?t[r]=a:t[r]=t[r]+a}return t}computeArcMax(e,n,t,s,r){const{primary:i,secondary:a,tertiary:c}=X(s),u=q(e[i],e[a],r[i],r[a]),m=Math.atan2(e[a]-r[a],e[i]-r[i]),d=Math.atan2(n[a]-r[a],n[i]-r[i]),M=j(m,d,t);let l=Number.NEGATIVE_INFINITY,p=Number.NEGATIVE_INFINITY;for(const A of M){const G=r[i]+u*Math.cos(A),h=r[a]+u*Math.sin(A);G>l&&(l=G),h>p&&(p=h)}const x={...e};x[i]=l,x[a]=p,x[c]=Math.max(e[c],n[c]);for(const A of g)A!==i&&A!==a&&A!==c&&(x[A]=Math.max(e[A],n[A]));return x}arcCenter(e,n,t,s){const{primary:r,secondary:i}=X(s),a={...n},c=this.unitsScale(),u=F(e,"R"),m=W(e,s),d=m.primary===null?null:m.primary*c,M=m.secondary===null?null:m.secondary*c;if(d!==null||M!==null)return a[r]=n[r]+(d??0),a[i]=n[i]+(M??0),a;if(u===null)return a;const l=u*c,p=n[r],x=n[i],A=t[r],G=t[i],h=A-p,w=G-x,S=Math.hypot(h,w);if(S===0)return a;const P=Math.abs(l),f=Math.sqrt(Math.max(0,P*P-S/2*(S/2))),y=(p+A)/2,v=(x+G)/2,L=-w/S,Y=h/S,E=l>=0?1:-1;return a[r]=y+E*L*f,a[i]=v+E*Y*f,a}emitLinear(e){const n=this.callbacks.onLinearMove;if(!n)return;const t=e.end.A-e.start.A,s=Math.max(1,Math.ceil(Math.abs(t)/D));let r={...e.start};for(let i=1;i<=s;i+=1){const a=i/s,c=K(e.start,e.end,a),u=V(r),m=V(c);n({modals:{...this.modals},start:{...r},end:{...c},transformedStart:u,transformedEnd:m}),r=c}}emitArc(e){const n=this.callbacks.onArcMove;if(!n)return;const t=V(e.start),s=V(e.end),r=V(e.max),i=V(e.center);n({modals:{...this.modals},start:{...e.start},end:{...e.end},max:{...e.max},center:{...e.center},plane:e.plane,motion:e.motion,transformedStart:t,transformedEnd:s,transformedMax:r,transformedCenter:i})}}function F(o,e){const n=o.params.find(t=>t.letter.toUpperCase()===e);return n?n.value:null}function X(o){return o==="G18"?{primary:"Z",secondary:"X",tertiary:"Y"}:o==="G19"?{primary:"Y",secondary:"Z",tertiary:"X"}:{primary:"X",secondary:"Y",tertiary:"Z"}}function W(o,e){const n=F(o,"I"),t=F(o,"J"),s=F(o,"K");return e==="G18"?{primary:s,secondary:n}:e==="G19"?{primary:t,secondary:s}:{primary:n,secondary:t}}function j(o,e,n){const t=Math.PI*2;let s=N(o),r=N(e);const i=[0,Math.PI/2,Math.PI,3*Math.PI/2,t];if(n==="G2"){s<r&&(s+=t);const c=[s,r];for(const u of i){let m=u;m<r&&(m+=t),m<=s&&m>=r&&c.push(m)}return c}r<s&&(r+=t);const a=[s,r];for(const c of i){let u=c;u<s&&(u+=t),u>=s&&u<=r&&a.push(u)}return a}function N(o){const e=Math.PI*2;let n=o%e;return n<0&&(n+=e),n}function q(o,e,n,t){return Math.hypot(o-n,e-t)}function T(o,e){return g.every(n=>o[n]===e[n])}const D=5;function K(o,e,n){return{X:o.X+(e.X-o.X)*n,Y:o.Y+(e.Y-o.Y)*n,Z:o.Z+(e.Z-o.Z)*n,A:o.A+(e.A-o.A)*n,B:o.B+(e.B-o.B)*n,C:o.C+(e.C-o.C)*n}}function V(o){const e=o.A*Math.PI/180,n=Math.cos(e),t=Math.sin(e),s=o.Y*n-o.Z*t,r=o.Y*t+o.Z*n;return{...o,Y:s,Z:r}}function H(o,e={}){const n=[],t=e.arcSegments??30,s=e.collector??{},r=new I({onLinearMove:i=>{(s.onLinearMove??U)(i,n)},onArcMove:i=>{(s.onArcMove??((c,u)=>{b(c,u,t)}))(i,n)}});for(const i of o)i&&r.processLine(i);return Float32Array.from(n)}function J(o,e={}){const n=[],t=[],s=e.arcSegments??30,r=new I({onLinearMove:i=>{const a=i.transformedStart??i.start,c=i.transformedEnd??i.end;(i.modals.motion==="G0"?n:t).push(a.X,a.Y,a.Z,c.X,c.Y,c.Z)},onArcMove:i=>{const a=i.modals.motion==="G0"?n:t;b(i,a,s)}});for(const i of o)i&&r.processLine(i);return{rapid:Float32Array.from(n),cutting:Float32Array.from(t)}}async function Q(o,e={}){var M;const n=[],t=[],s=e.arcSegments??30,r=e.batch,i=Math.max(1,Math.floor((r==null?void 0:r.everyLines)??5e3)),a=Math.max(0,Math.floor((r==null?void 0:r.yieldEveryLines)??5e4));let c=i,u=a>0?a:Number.POSITIVE_INFINITY;const m=new I({onLinearMove:l=>{const p=l.transformedStart??l.start,x=l.transformedEnd??l.end;(l.modals.motion==="G0"?n:t).push(p.X,p.Y,p.Z,x.X,x.Y,x.Z)},onArcMove:l=>{const p=l.modals.motion==="G0"?n:t;b(l,p,s)}}),d=o.length;for(let l=0;l<d;l+=1){if((M=r==null?void 0:r.shouldAbort)!=null&&M.call(r))throw new Error("Aborted.");const p=o[l];if(!p){r!=null&&r.onProgress&&(l+1===d||l+1===c)&&(r.onProgress(l+1,d),c+=i),a>0&&(l+1===d||l+1===u)&&(await new Promise(x=>{setTimeout(x,0)}),u+=a);continue}m.processLine(p),r!=null&&r.onProgress&&(l+1===d||l+1===c)&&(r.onProgress(l+1,d),c+=i),a>0&&(l+1===d||l+1===u)&&(await new Promise(x=>{setTimeout(x,0)}),u+=a)}return{rapid:Float32Array.from(n),cutting:Float32Array.from(t)}}async function ee(o,e={}){var G;const n=[],t=e.arcSegments??30,s=e.batch,r=Math.max(1,Math.floor((s==null?void 0:s.everyLines)??5e3)),i=Math.max(0,Math.floor((s==null?void 0:s.yieldEveryLines)??5e4));let a=r,c=i>0?i:Number.POSITIVE_INFINITY;const u=new Int32Array(o.length);u.fill(-1);const m=new Int32Array(o.length);m.fill(-1);const d=new Uint8Array(o.length),M=new Int32Array(o.length);let l=-1,p=0;const x=new I({onLinearMove:h=>{const w=h.modals.motion==="G0"?1:2;l>=0&&(p===0?p=w:p!==w&&(p=3)),U(h,n)},onArcMove:h=>{const w=h.modals.motion==="G0"?1:2;l>=0&&(p===0?p=w:p!==w&&(p=3)),b(h,n,t)}}),A=o.length;for(let h=0;h<A;h+=1){if((G=s==null?void 0:s.shouldAbort)!=null&&G.call(s))throw new Error("Aborted.");const w=n.length/3;l=h,p=0;const S=o[h];S&&x.processLine(S),l=-1;const P=n.length/3;P>w&&(u[h]=w,m[h]=P,d[h]=p),M[h]=P,s!=null&&s.onProgress&&(h+1===A||h+1===a)&&(s.onProgress(h+1,A),a+=r),i>0&&(h+1===A||h+1===c)&&(await new Promise(f=>{setTimeout(f,0)}),c+=i)}return{positions:Float32Array.from(n),lineStartVertex:u,lineEndVertex:m,lineKind:d,prefixEndVertex:M}}function te(o,e={}){const n=e.arcSegments??30,t=Math.max(1,Math.floor(e.bucketCount??16)),s=e.baseOpacity??.9,{minPower:r,maxPower:i}=ae(o),a=[],c=Array.from({length:t},()=>[]),u=new I({onLinearMove:d=>{const M=d.transformedStart??d.start,l=d.transformedEnd??d.end;if(d.modals.motion==="G0"){a.push(M.X,M.Y,M.Z,l.X,l.Y,l.Z);return}const p=z(d.modals.spindleSpeed,r,i,t);c[p].push(M.X,M.Y,M.Z,l.X,l.Y,l.Z)},onArcMove:d=>{if(d.modals.motion==="G0")return;const M=z(d.modals.spindleSpeed,r,i,t),l=c[M];b(d,l,n)}});for(const d of o)d&&u.processLine(d);const m=c.map((d,M)=>({opacity:_(M,t,s),vertices:Float32Array.from(d)}));return{rapid:Float32Array.from(a),buckets:m,minPower:r,maxPower:i}}async function ne(o,e={}){const n=await R(o,e);return{rapid:n.rapidPositions,buckets:n.buckets.map(t=>({opacity:t.opacity,vertices:t.positions})),minPower:n.minPower,maxPower:n.maxPower}}async function O(o,e={}){var S,P;const n=e.arcSegments??30,t=Math.max(1,Math.floor(e.bucketCount??16)),s=!!e.laserMode,r=e.batch,i=o.length*(s?2:1),a=Math.max(1,Math.floor((r==null?void 0:r.everyLines)??5e3)),c=Math.max(0,Math.floor((r==null?void 0:r.yieldEveryLines)??5e4));let u=a,m=c>0?c:Number.POSITIVE_INFINITY,d=Number.NEGATIVE_INFINITY,M=!1;if(s){const f=new Z;for(const y of o){if(!y)continue;if(f.parseLine(y).gcodes.some(Y=>{if(Y.letter!=="M")return!1;const E=Math.trunc(Y.value);return E===3||E===4||E===5})){M=!1;break}M=!0}}const l=f=>f.spindle==="M5"||!(f.spindle==="M3"||f.spindle==="M4"||M&&f.spindle===null)?!1:f.spindleSpeed===null?!0:f.spindleSpeed>0;if(s){const f=new I({onLinearMove:y=>{if(!l(y.modals))return;const v=y.modals.spindleSpeed;v===null||v<=0||(d=Math.max(d,v))},onArcMove:y=>{if(!l(y.modals))return;const v=y.modals.spindleSpeed;v===null||v<=0||(d=Math.max(d,v))}});for(let y=0;y<o.length;y+=1){if((S=r==null?void 0:r.shouldAbort)!=null&&S.call(r))throw new Error("Aborted.");const v=o[y];v&&f.processLine(v);const L=y+1;r!=null&&r.onProgress&&(L===i||L===u)&&(r.onProgress(L,i),u+=a),c>0&&(L===i||L===m)&&(await new Promise(Y=>{setTimeout(Y,0)}),m+=c)}Number.isFinite(d)||(d=0)}else d=0;const p=f=>{if(t<=1)return 0;if(f===null)return t-1;const y=f;if(y<=0)return 0;if(d<=0)return t-1;const v=Math.min(1,Math.max(0,y/d)),L=1+Math.floor(v*(t-2));return Math.min(t-1,Math.max(1,L))},x=[],A=s?Array.from({length:t},()=>[]):[new Array],G=new Int32Array(o.length),h=Array.from({length:s?t:1},()=>new Int32Array(o.length)),w=new I({onLinearMove:f=>{const y=f.transformedStart??f.start,v=f.transformedEnd??f.end;if(f.modals.motion==="G0"){x.push(y.X,y.Y,y.Z,v.X,v.Y,v.Z);return}if(s&&!l(f.modals))return;const L=s?p(f.modals.spindleSpeed):0;A[L].push(y.X,y.Y,y.Z,v.X,v.Y,v.Z)},onArcMove:f=>{if(f.modals.motion==="G0"||s&&!l(f.modals))return;const y=s?p(f.modals.spindleSpeed):0,v=A[y];b(f,v,n)}});for(let f=0;f<o.length;f+=1){if((P=r==null?void 0:r.shouldAbort)!=null&&P.call(r))throw new Error("Aborted.");const y=o[f];y&&w.processLine(y),G[f]=x.length/3;for(let L=0;L<A.length;L+=1)h[L][f]=A[L].length/3;const v=s?o.length+f+1:f+1;r!=null&&r.onProgress&&(v===i||v===u)&&(r.onProgress(v,i),u+=a),c>0&&(v===i||v===m)&&(await new Promise(L=>{setTimeout(L,0)}),m+=c)}return{rapid:{positions:Float32Array.from(x),prefixEndVertex:G},cuts:A.map((f,y)=>({positions:Float32Array.from(f),prefixEndVertex:h[y]})),cutBucketCount:A.length,minPower:0,maxPower:d}}async function R(o,e={}){const n=Math.max(1,Math.floor(e.bucketCount??16)),t=e.baseOpacity??.9,s=await O(o,{arcSegments:e.arcSegments,bucketCount:n,laserMode:!0,batch:e.batch}),r=s.cuts.map((i,a)=>({opacity:_(a,n,t),positions:i.positions,prefixEndVertex:i.prefixEndVertex}));return{rapidPositions:s.rapid.positions,rapidPrefixEndVertex:s.rapid.prefixEndVertex,buckets:r,minPower:0,maxPower:s.maxPower}}function oe(o,e){o.push(e.X,e.Y,e.Z)}function U(o,e){const n=o.transformedStart??o.start,t=o.transformedEnd??o.end;e.push(n.X,n.Y,n.Z,t.X,t.Y,t.Z)}function b(o,e,n){const t=Math.max(1,Math.floor(n)),{primary:s,secondary:r}=re(o.plane),i=se(o.start[s],o.start[r],o.center[s],o.center[r]),a=Math.atan2(o.start[r]-o.center[r],o.start[s]-o.center[s]),c=Math.atan2(o.end[r]-o.center[r],o.end[s]-o.center[s]),u=Math.PI*2;let m=B(a),d=B(c);o.motion==="G2"?m<=d&&(m+=u):d<=m&&(d+=u);const M=o.motion==="G2"?m-d:d-m;let l={...o.start};for(let p=1;p<=t;p+=1){const x=p/t,A=o.motion==="G2"?m-M*x:m+M*x,G=ie(o.start,o.end,x);G[s]=o.center[s]+i*Math.cos(A),G[r]=o.center[r]+i*Math.sin(A);const h=k(l),w=k(G);e.push(h.X,h.Y,h.Z,w.X,w.Y,w.Z),l=G}}function k(o){const e=o.A*Math.PI/180,n=Math.cos(e),t=Math.sin(e),s=o.Y*n-o.Z*t,r=o.Y*t+o.Z*n;return{...o,Y:s,Z:r}}function re(o){return o==="G18"?{primary:"Z",secondary:"X"}:o==="G19"?{primary:"Y",secondary:"Z"}:{primary:"X",secondary:"Y"}}function B(o){const e=Math.PI*2;let n=o%e;return n<0&&(n+=e),n}function se(o,e,n,t){return Math.hypot(o-n,e-t)}function ie(o,e,n){return{X:o.X+(e.X-o.X)*n,Y:o.Y+(e.Y-o.Y)*n,Z:o.Z+(e.Z-o.Z)*n,A:o.A+(e.A-o.A)*n,B:o.B+(e.B-o.B)*n,C:o.C+(e.C-o.C)*n}}function ae(o){let e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;const t=new I({onLinearMove:s=>{const r=s.modals.spindleSpeed;r!==null&&(e=Math.min(e,r),n=Math.max(n,r))},onArcMove:s=>{const r=s.modals.spindleSpeed;r!==null&&(e=Math.min(e,r),n=Math.max(n,r))}});for(const s of o)s&&t.processLine(s);return!Number.isFinite(e)||!Number.isFinite(n)?{minPower:0,maxPower:0}:{minPower:e,maxPower:n}}function z(o,e,n,t){if(t<=1)return 0;const s=o??e;if(n<=e)return t-1;const r=(s-e)/(n-e),i=Math.floor(r*(t-1));return Math.min(t-1,Math.max(0,i))}function _(o,e,n){if(e<=1)return n;const t=o/(e-1);return n*t}function ce(o){const e=new Float32Array(o.vertices),n=new Uint32Array(o.frames),t=new Float32Array(o.colorArrayBuffer),{verticesLen:s,framesLen:r}=o,i=new Map;for(let a=0;a<r;a++){const c=n[a],u=a<r-1?n[a+1]:s;if(u<=c+1)continue;const m=c*4,d=t[m],M=t[m+1],l=t[m+2],p=t[m+3],x=le(d,M,l),A=`${x}|${Math.round(p*100)}`;let G=i.get(A);G||(G={hexColor:x,opacity:p,pos:[],rgb:[]},i.set(A,G));for(let h=c;h<u-1;h++){const w=h*3,S=(h+1)*3;G.pos.push(e[w],e[w+1],e[w+2],e[S],e[S+1],e[S+2]),G.rgb.push(d,M,l,d,M,l)}}return Array.from(i.values()).map(({hexColor:a,opacity:c,pos:u,rgb:m})=>({hexColor:a,opacity:c,positions:new Float32Array(u),rgbColors:new Float32Array(m)}))}function le(o,e,n){const t=s=>Math.round(Math.min(1,Math.max(0,s))*255).toString(16).padStart(2,"0");return`#${t(o)}${t(e)}${t(n)}`}exports.GCodeParser=Z;exports.GCodeVirtualizer=I;exports.buildLaserGeometryFromLinesBatched=R;exports.buildLaserVerticesFromLines=te;exports.buildLaserVerticesFromLinesBatched=ne;exports.buildMovementGeometryFromLinesBatched=ee;exports.buildMovementVerticesFromLines=J;exports.buildMovementVerticesFromLinesBatched=Q;exports.buildToolpathGeometryFromLinesBatched=O;exports.buildVerticesFromLines=H;exports.buildWorkerSegmentGroups=ce;exports.pushXYZ=oe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=/([A-Za-z])\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+))/g;class Z{parseLine(e){const n=[],t=this.stripComments(e,n),s=this.parseWords(t),r=s.filter(a=>{const c=a.letter.toUpperCase();return c==="G"||c==="M"}),i=s.filter(a=>{const c=a.letter.toUpperCase();return c!=="G"&&c!=="M"});return{raw:e,words:s,gcodes:r,params:i,comments:n}}stripComments(e,n){let t="",s=!1,r=-1,i="";for(let a=0;a<e.length;a+=1){const c=e[a];if(!s&&c===";"){const u=e.slice(a+1);n.push({type:"semicolon",text:u,start:a,end:e.length});break}if(c==="("){s?i+=c:(s=!0,r=a,i="");continue}if(c===")"&&s){n.push({type:"paren",text:i,start:r,end:a+1}),s=!1,r=-1,i="";continue}if(s){i+=c;continue}t+=c}return s&&n.push({type:"paren",text:i,start:r,end:e.length}),t}parseWords(e){const n=[];for(const t of e.matchAll($)){const s=t[0],r=t[1].toUpperCase(),i=Number(t[2]),a=t.index??0,c=a+s.length;n.push({letter:r,value:i,raw:s,start:a,end:c})}return n}}const g=["X","Y","Z","A","B","C"],C={motion:"G0",distance:"G90",plane:"G17",units:"G21",feedMode:"G94",feedRate:null,spindleSpeed:null,tool:null,coolant:null,spindle:null,coordinateSystem:"G54"};class I{constructor(e={}){this.parser=new Z,this.modals={...C},this.position={X:0,Y:0,Z:0,A:0,B:0,C:0},this.callbacks=e,this.feedRates=new Set,this.spindleSpeeds=new Set,this.tools=new Set}setCallbacks(e){this.callbacks=e}getModals(){return{...this.modals}}getPosition(){return{...this.position}}getUniqueFeedRates(){return Array.from(this.feedRates)}getUniqueSpindleSpeeds(){return Array.from(this.spindleSpeeds)}getUniqueTools(){return Array.from(this.tools)}reset(){this.modals={...C},this.position={X:0,Y:0,Z:0,A:0,B:0,C:0},this.feedRates.clear(),this.spindleSpeeds.clear(),this.tools.clear()}processLine(e){const n=this.parser.parseLine(e),t={...this.position};this.updateModals(n);const s=this.modals.motion,r=this.modals.plane;let i=this.applyAxes(n,t),a,c,u="none";return s==="G0"||s==="G1"?T(t,i)||(u="linear",this.position={...i},this.emitLinear({start:t,end:i})):(s==="G2"||s==="G3")&&(T(t,i)||(u="arc",c=this.arcCenter(n,t,i,r),a=this.computeArcMax(t,i,s,r,c),this.position={...i},this.emitArc({start:t,end:i,max:a,center:c,plane:r,motion:s}))),{parsed:n,modals:{...this.modals},start:t,end:i,movement:u,arcMax:a}}unitsScale(){return this.modals.units==="G20"?25.4:1}updateModals(e){for(const n of e.gcodes){if(n.letter.toUpperCase()==="G"){const t=`G${Math.trunc(n.value)}`;(t==="G0"||t==="G1"||t==="G2"||t==="G3")&&(this.modals.motion=t),(t==="G90"||t==="G91")&&(this.modals.distance=t),(t==="G17"||t==="G18"||t==="G19")&&(this.modals.plane=t),(t==="G20"||t==="G21")&&(this.modals.units=t),(t==="G93"||t==="G94")&&(this.modals.feedMode=t),(t==="G54"||t==="G55"||t==="G56"||t==="G57"||t==="G58"||t==="G59")&&(this.modals.coordinateSystem=t)}if(n.letter.toUpperCase()==="M"){const t=`M${Math.trunc(n.value)}`;(t==="M7"||t==="M8"||t==="M9")&&(this.modals.coolant=t),(t==="M3"||t==="M4"||t==="M5")&&(this.modals.spindle=t)}}for(const n of e.params){const t=n.letter.toUpperCase();t==="F"&&(this.modals.feedRate=n.value,this.feedRates.add(n.value)),t==="S"&&(this.modals.spindleSpeed=n.value,this.spindleSpeeds.add(n.value)),t==="T"&&(this.modals.tool=n.value,this.tools.add(n.value))}}applyAxes(e,n){const t={...n},s=this.unitsScale();for(const r of g){const i=e.params.find(c=>c.letter.toUpperCase()===r);if(!i)continue;const a=r==="X"||r==="Y"||r==="Z"?i.value*s:i.value;this.modals.distance==="G90"?t[r]=a:t[r]=t[r]+a}return t}computeArcMax(e,n,t,s,r){const{primary:i,secondary:a,tertiary:c}=X(s),u=q(e[i],e[a],r[i],r[a]),m=Math.atan2(e[a]-r[a],e[i]-r[i]),d=Math.atan2(n[a]-r[a],n[i]-r[i]),M=j(m,d,t);let l=Number.NEGATIVE_INFINITY,p=Number.NEGATIVE_INFINITY;for(const A of M){const G=r[i]+u*Math.cos(A),h=r[a]+u*Math.sin(A);G>l&&(l=G),h>p&&(p=h)}const x={...e};x[i]=l,x[a]=p,x[c]=Math.max(e[c],n[c]);for(const A of g)A!==i&&A!==a&&A!==c&&(x[A]=Math.max(e[A],n[A]));return x}arcCenter(e,n,t,s){const{primary:r,secondary:i}=X(s),a={...n},c=this.unitsScale(),u=F(e,"R"),m=W(e,s),d=m.primary===null?null:m.primary*c,M=m.secondary===null?null:m.secondary*c;if(d!==null||M!==null)return a[r]=n[r]+(d??0),a[i]=n[i]+(M??0),a;if(u===null)return a;const l=u*c,p=n[r],x=n[i],A=t[r],G=t[i],h=A-p,w=G-x,S=Math.hypot(h,w);if(S===0)return a;const P=Math.abs(l),f=Math.sqrt(Math.max(0,P*P-S/2*(S/2))),y=(p+A)/2,v=(x+G)/2,L=-w/S,Y=h/S,E=l>=0?1:-1;return a[r]=y+E*L*f,a[i]=v+E*Y*f,a}emitLinear(e){const n=this.callbacks.onLinearMove;if(!n)return;const t=e.end.A-e.start.A,s=Math.max(1,Math.ceil(Math.abs(t)/D));let r={...e.start};for(let i=1;i<=s;i+=1){const a=i/s,c=K(e.start,e.end,a),u=V(r),m=V(c);n({modals:{...this.modals},start:{...r},end:{...c},transformedStart:u,transformedEnd:m}),r=c}}emitArc(e){const n=this.callbacks.onArcMove;if(!n)return;const t=V(e.start),s=V(e.end),r=V(e.max),i=V(e.center);n({modals:{...this.modals},start:{...e.start},end:{...e.end},max:{...e.max},center:{...e.center},plane:e.plane,motion:e.motion,transformedStart:t,transformedEnd:s,transformedMax:r,transformedCenter:i})}}function F(o,e){const n=o.params.find(t=>t.letter.toUpperCase()===e);return n?n.value:null}function X(o){return o==="G18"?{primary:"Z",secondary:"X",tertiary:"Y"}:o==="G19"?{primary:"Y",secondary:"Z",tertiary:"X"}:{primary:"X",secondary:"Y",tertiary:"Z"}}function W(o,e){const n=F(o,"I"),t=F(o,"J"),s=F(o,"K");return e==="G18"?{primary:s,secondary:n}:e==="G19"?{primary:t,secondary:s}:{primary:n,secondary:t}}function j(o,e,n){const t=Math.PI*2;let s=N(o),r=N(e);const i=[0,Math.PI/2,Math.PI,3*Math.PI/2,t];if(n==="G2"){s<r&&(s+=t);const c=[s,r];for(const u of i){let m=u;m<r&&(m+=t),m<=s&&m>=r&&c.push(m)}return c}r<s&&(r+=t);const a=[s,r];for(const c of i){let u=c;u<s&&(u+=t),u>=s&&u<=r&&a.push(u)}return a}function N(o){const e=Math.PI*2;let n=o%e;return n<0&&(n+=e),n}function q(o,e,n,t){return Math.hypot(o-n,e-t)}function T(o,e){return g.every(n=>o[n]===e[n])}const D=5;function K(o,e,n){return{X:o.X+(e.X-o.X)*n,Y:o.Y+(e.Y-o.Y)*n,Z:o.Z+(e.Z-o.Z)*n,A:o.A+(e.A-o.A)*n,B:o.B+(e.B-o.B)*n,C:o.C+(e.C-o.C)*n}}function V(o){const e=o.A*Math.PI/180,n=Math.cos(e),t=Math.sin(e),s=o.Y*n-o.Z*t,r=o.Y*t+o.Z*n;return{...o,Y:s,Z:r}}function H(o,e={}){const n=[],t=e.arcSegments??30,s=e.collector??{},r=new I({onLinearMove:i=>{(s.onLinearMove??U)(i,n)},onArcMove:i=>{(s.onArcMove??((c,u)=>{b(c,u,t)}))(i,n)}});for(const i of o)i&&r.processLine(i);return Float32Array.from(n)}function J(o,e={}){const n=[],t=[],s=e.arcSegments??30,r=new I({onLinearMove:i=>{const a=i.transformedStart??i.start,c=i.transformedEnd??i.end;(i.modals.motion==="G0"?n:t).push(a.X,a.Y,a.Z,c.X,c.Y,c.Z)},onArcMove:i=>{const a=i.modals.motion==="G0"?n:t;b(i,a,s)}});for(const i of o)i&&r.processLine(i);return{rapid:Float32Array.from(n),cutting:Float32Array.from(t)}}async function Q(o,e={}){var M;const n=[],t=[],s=e.arcSegments??30,r=e.batch,i=Math.max(1,Math.floor((r==null?void 0:r.everyLines)??5e3)),a=Math.max(0,Math.floor((r==null?void 0:r.yieldEveryLines)??5e4));let c=i,u=a>0?a:Number.POSITIVE_INFINITY;const m=new I({onLinearMove:l=>{const p=l.transformedStart??l.start,x=l.transformedEnd??l.end;(l.modals.motion==="G0"?n:t).push(p.X,p.Y,p.Z,x.X,x.Y,x.Z)},onArcMove:l=>{const p=l.modals.motion==="G0"?n:t;b(l,p,s)}}),d=o.length;for(let l=0;l<d;l+=1){if((M=r==null?void 0:r.shouldAbort)!=null&&M.call(r))throw new Error("Aborted.");const p=o[l];if(!p){r!=null&&r.onProgress&&(l+1===d||l+1===c)&&(r.onProgress(l+1,d),c+=i),a>0&&(l+1===d||l+1===u)&&(await new Promise(x=>{setTimeout(x,0)}),u+=a);continue}m.processLine(p),r!=null&&r.onProgress&&(l+1===d||l+1===c)&&(r.onProgress(l+1,d),c+=i),a>0&&(l+1===d||l+1===u)&&(await new Promise(x=>{setTimeout(x,0)}),u+=a)}return{rapid:Float32Array.from(n),cutting:Float32Array.from(t)}}async function ee(o,e={}){var G;const n=[],t=e.arcSegments??30,s=e.batch,r=Math.max(1,Math.floor((s==null?void 0:s.everyLines)??5e3)),i=Math.max(0,Math.floor((s==null?void 0:s.yieldEveryLines)??5e4));let a=r,c=i>0?i:Number.POSITIVE_INFINITY;const u=new Int32Array(o.length);u.fill(-1);const m=new Int32Array(o.length);m.fill(-1);const d=new Uint8Array(o.length),M=new Int32Array(o.length);let l=-1,p=0;const x=new I({onLinearMove:h=>{const w=h.modals.motion==="G0"?1:2;l>=0&&(p===0?p=w:p!==w&&(p=3)),U(h,n)},onArcMove:h=>{const w=h.modals.motion==="G0"?1:2;l>=0&&(p===0?p=w:p!==w&&(p=3)),b(h,n,t)}}),A=o.length;for(let h=0;h<A;h+=1){if((G=s==null?void 0:s.shouldAbort)!=null&&G.call(s))throw new Error("Aborted.");const w=n.length/3;l=h,p=0;const S=o[h];S&&x.processLine(S),l=-1;const P=n.length/3;P>w&&(u[h]=w,m[h]=P,d[h]=p),M[h]=P,s!=null&&s.onProgress&&(h+1===A||h+1===a)&&(s.onProgress(h+1,A),a+=r),i>0&&(h+1===A||h+1===c)&&(await new Promise(f=>{setTimeout(f,0)}),c+=i)}return{positions:Float32Array.from(n),lineStartVertex:u,lineEndVertex:m,lineKind:d,prefixEndVertex:M}}function te(o,e={}){const n=e.arcSegments??30,t=Math.max(1,Math.floor(e.bucketCount??16)),s=e.baseOpacity??.9,{minPower:r,maxPower:i}=ae(o),a=[],c=Array.from({length:t},()=>[]),u=new I({onLinearMove:d=>{const M=d.transformedStart??d.start,l=d.transformedEnd??d.end;if(d.modals.motion==="G0"){a.push(M.X,M.Y,M.Z,l.X,l.Y,l.Z);return}const p=z(d.modals.spindleSpeed,r,i,t);c[p].push(M.X,M.Y,M.Z,l.X,l.Y,l.Z)},onArcMove:d=>{if(d.modals.motion==="G0")return;const M=z(d.modals.spindleSpeed,r,i,t),l=c[M];b(d,l,n)}});for(const d of o)d&&u.processLine(d);const m=c.map((d,M)=>({opacity:_(M,t,s),vertices:Float32Array.from(d)}));return{rapid:Float32Array.from(a),buckets:m,minPower:r,maxPower:i}}async function ne(o,e={}){const n=await R(o,e);return{rapid:n.rapidPositions,buckets:n.buckets.map(t=>({opacity:t.opacity,vertices:t.positions})),minPower:n.minPower,maxPower:n.maxPower}}async function O(o,e={}){var S,P;const n=e.arcSegments??30,t=Math.max(1,Math.floor(e.bucketCount??16)),s=!!e.laserMode,r=e.batch,i=o.length*(s?2:1),a=Math.max(1,Math.floor((r==null?void 0:r.everyLines)??5e3)),c=Math.max(0,Math.floor((r==null?void 0:r.yieldEveryLines)??5e4));let u=a,m=c>0?c:Number.POSITIVE_INFINITY,d=Number.NEGATIVE_INFINITY,M=!1;if(s){const f=new Z;for(const y of o){if(!y)continue;if(f.parseLine(y).gcodes.some(Y=>{if(Y.letter!=="M")return!1;const E=Math.trunc(Y.value);return E===3||E===4||E===5})){M=!1;break}M=!0}}const l=f=>f.spindle==="M5"||!(f.spindle==="M3"||f.spindle==="M4"||M&&f.spindle===null)?!1:f.spindleSpeed===null?!0:f.spindleSpeed>0;if(s){const f=new I({onLinearMove:y=>{if(!l(y.modals))return;const v=y.modals.spindleSpeed;v===null||v<=0||(d=Math.max(d,v))},onArcMove:y=>{if(!l(y.modals))return;const v=y.modals.spindleSpeed;v===null||v<=0||(d=Math.max(d,v))}});for(let y=0;y<o.length;y+=1){if((S=r==null?void 0:r.shouldAbort)!=null&&S.call(r))throw new Error("Aborted.");const v=o[y];v&&f.processLine(v);const L=y+1;r!=null&&r.onProgress&&(L===i||L===u)&&(r.onProgress(L,i),u+=a),c>0&&(L===i||L===m)&&(await new Promise(Y=>{setTimeout(Y,0)}),m+=c)}Number.isFinite(d)||(d=0)}else d=0;const p=f=>{if(t<=1)return 0;if(f===null)return t-1;const y=f;if(y<=0)return 0;if(d<=0)return t-1;const v=Math.min(1,Math.max(0,y/d)),L=1+Math.floor(v*(t-2));return Math.min(t-1,Math.max(1,L))},x=[],A=s?Array.from({length:t},()=>[]):[new Array],G=new Int32Array(o.length),h=Array.from({length:s?t:1},()=>new Int32Array(o.length)),w=new I({onLinearMove:f=>{const y=f.transformedStart??f.start,v=f.transformedEnd??f.end;if(f.modals.motion==="G0"){x.push(y.X,y.Y,y.Z,v.X,v.Y,v.Z);return}if(s&&!l(f.modals))return;const L=s?p(f.modals.spindleSpeed):0;A[L].push(y.X,y.Y,y.Z,v.X,v.Y,v.Z)},onArcMove:f=>{if(f.modals.motion==="G0"||s&&!l(f.modals))return;const y=s?p(f.modals.spindleSpeed):0,v=A[y];b(f,v,n)}});for(let f=0;f<o.length;f+=1){if((P=r==null?void 0:r.shouldAbort)!=null&&P.call(r))throw new Error("Aborted.");const y=o[f];y&&w.processLine(y),G[f]=x.length/3;for(let L=0;L<A.length;L+=1)h[L][f]=A[L].length/3;const v=s?o.length+f+1:f+1;r!=null&&r.onProgress&&(v===i||v===u)&&(r.onProgress(v,i),u+=a),c>0&&(v===i||v===m)&&(await new Promise(L=>{setTimeout(L,0)}),m+=c)}return{rapid:{positions:Float32Array.from(x),prefixEndVertex:G},cuts:A.map((f,y)=>({positions:Float32Array.from(f),prefixEndVertex:h[y]})),cutBucketCount:A.length,minPower:0,maxPower:d}}async function R(o,e={}){const n=Math.max(1,Math.floor(e.bucketCount??16)),t=e.baseOpacity??.9,s=await O(o,{arcSegments:e.arcSegments,bucketCount:n,laserMode:!0,batch:e.batch}),r=s.cuts.map((i,a)=>({opacity:_(a,n,t),positions:i.positions,prefixEndVertex:i.prefixEndVertex}));return{rapidPositions:s.rapid.positions,rapidPrefixEndVertex:s.rapid.prefixEndVertex,buckets:r,minPower:0,maxPower:s.maxPower}}function oe(o,e){o.push(e.X,e.Y,e.Z)}function U(o,e){const n=o.transformedStart??o.start,t=o.transformedEnd??o.end;e.push(n.X,n.Y,n.Z,t.X,t.Y,t.Z)}function b(o,e,n){const t=Math.max(1,Math.floor(n)),{primary:s,secondary:r}=re(o.plane),i=se(o.start[s],o.start[r],o.center[s],o.center[r]),a=Math.atan2(o.start[r]-o.center[r],o.start[s]-o.center[s]),c=Math.atan2(o.end[r]-o.center[r],o.end[s]-o.center[s]),u=Math.PI*2;let m=B(a),d=B(c);o.motion==="G2"?m<=d&&(m+=u):d<=m&&(d+=u);const M=o.motion==="G2"?m-d:d-m;let l={...o.start};for(let p=1;p<=t;p+=1){const x=p/t,A=o.motion==="G2"?m-M*x:m+M*x,G=ie(o.start,o.end,x);G[s]=o.center[s]+i*Math.cos(A),G[r]=o.center[r]+i*Math.sin(A);const h=k(l),w=k(G);e.push(h.X,h.Y,h.Z,w.X,w.Y,w.Z),l=G}}function k(o){const e=o.A*Math.PI/180,n=Math.cos(e),t=Math.sin(e),s=o.Y*n-o.Z*t,r=o.Y*t+o.Z*n;return{...o,Y:s,Z:r}}function re(o){return o==="G18"?{primary:"Z",secondary:"X"}:o==="G19"?{primary:"Y",secondary:"Z"}:{primary:"X",secondary:"Y"}}function B(o){const e=Math.PI*2;let n=o%e;return n<0&&(n+=e),n}function se(o,e,n,t){return Math.hypot(o-n,e-t)}function ie(o,e,n){return{X:o.X+(e.X-o.X)*n,Y:o.Y+(e.Y-o.Y)*n,Z:o.Z+(e.Z-o.Z)*n,A:o.A+(e.A-o.A)*n,B:o.B+(e.B-o.B)*n,C:o.C+(e.C-o.C)*n}}function ae(o){let e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;const t=new I({onLinearMove:s=>{const r=s.modals.spindleSpeed;r!==null&&(e=Math.min(e,r),n=Math.max(n,r))},onArcMove:s=>{const r=s.modals.spindleSpeed;r!==null&&(e=Math.min(e,r),n=Math.max(n,r))}});for(const s of o)s&&t.processLine(s);return!Number.isFinite(e)||!Number.isFinite(n)?{minPower:0,maxPower:0}:{minPower:e,maxPower:n}}function z(o,e,n,t){if(t<=1)return 0;const s=o??e;if(n<=e)return t-1;const r=(s-e)/(n-e),i=Math.floor(r*(t-1));return Math.min(t-1,Math.max(0,i))}function _(o,e,n){if(e<=1)return n;const t=o/(e-1);return n*t}function ce(o){const e=new Float32Array(o.vertices),n=new Uint32Array(o.frames),t=new Float32Array(o.colorArrayBuffer),{verticesLen:s,framesLen:r}=o,i=new Map;for(let a=0;a<r;a++){const c=n[a],u=a<r-1?n[a+1]:s/3;if(u<=c+1)continue;const m=c*4,d=t[m],M=t[m+1],l=t[m+2],p=t[m+3],x=le(d,M,l),A=`${x}|${Math.round(p*100)}`;let G=i.get(A);G||(G={hexColor:x,opacity:p,pos:[],rgb:[]},i.set(A,G));for(let h=c;h<u-1;h++){const w=h*3,S=(h+1)*3;G.pos.push(e[w],e[w+1],e[w+2],e[S],e[S+1],e[S+2]),G.rgb.push(d,M,l,d,M,l)}}return Array.from(i.values()).map(({hexColor:a,opacity:c,pos:u,rgb:m})=>({hexColor:a,opacity:c,positions:new Float32Array(u),rgbColors:new Float32Array(m)}))}function le(o,e,n){const t=s=>Math.round(Math.min(1,Math.max(0,s))*255).toString(16).padStart(2,"0");return`#${t(o)}${t(e)}${t(n)}`}exports.GCodeParser=Z;exports.GCodeVirtualizer=I;exports.buildLaserGeometryFromLinesBatched=R;exports.buildLaserVerticesFromLines=te;exports.buildLaserVerticesFromLinesBatched=ne;exports.buildMovementGeometryFromLinesBatched=ee;exports.buildMovementVerticesFromLines=J;exports.buildMovementVerticesFromLinesBatched=Q;exports.buildToolpathGeometryFromLinesBatched=O;exports.buildVerticesFromLines=H;exports.buildWorkerSegmentGroups=ce;exports.pushXYZ=oe;
|
package/dist/gviewer.js
CHANGED
|
@@ -642,7 +642,7 @@ function O(o, e, n) {
|
|
|
642
642
|
function le(o) {
|
|
643
643
|
const e = new Float32Array(o.vertices), n = new Uint32Array(o.frames), t = new Float32Array(o.colorArrayBuffer), { verticesLen: s, framesLen: r } = o, i = /* @__PURE__ */ new Map();
|
|
644
644
|
for (let a = 0; a < r; a++) {
|
|
645
|
-
const c = n[a], u = a < r - 1 ? n[a + 1] : s;
|
|
645
|
+
const c = n[a], u = a < r - 1 ? n[a + 1] : s / 3;
|
|
646
646
|
if (u <= c + 1) continue;
|
|
647
647
|
const f = c * 4, d = t[f], y = t[f + 1], l = t[f + 2], p = t[f + 3], x = te(d, y, l), A = `${x}|${Math.round(p * 100)}`;
|
|
648
648
|
let w = i.get(A);
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("react"),F=require("./GCodeSVGRenderer-hZ8tZwov.cjs");function w(l){const u=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const s in l)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(l,s);Object.defineProperty(u,s,i.get?i:{enumerable:!0,get:()=>l[s]})}}return u.default=l,Object.freeze(u)}const o=w(V),G=o.forwardRef(function(u,s){const{id:i,options:a,callbacks:c,className:m,style:f}=u,d=o.useRef(null),t=o.useRef(null);return o.useEffect(()=>{const e=d.current;if(!e)return;const p=new F.GCodeViewer({id:i,container:e,options:a,callbacks:c});return t.current=p,()=>{t.current=null,p.dispose()}},[i]),o.useEffect(()=>{var e;(e=t.current)==null||e.setOptions(a??{})},[a]),o.useEffect(()=>{var e;(e=t.current)==null||e.setCallbacks(c??{})},[c]),o.useImperativeHandle(s,()=>{const e=()=>{const r=t.current;if(!r)throw new Error("GCodeViewer is not ready.");return r};return{get id(){return i},setCallbacks(r){e().setCallbacks(r)},snapCameraToView(r,n){e().snapCameraToView(r,n)},setBitPosition(r,n){e().setBitPosition(r,n)},setBitVisible(r){e().setBitVisible(r)},setToolpathRotationA(r){e().setToolpathRotationA(r)},hideUntilLine(r,n){e().hideUntilLine(r,n)},seekToLine(r,n){e().seekToLine(r,n)},showAll(){e().showAll()},resetColors(){e().resetColors()},loadFromUrl(r,n){return e().loadFromUrl(r,n)},loadFromFile(r){return e().loadFromFile(r)},loadFromText(r){return e().loadFromText(r)},loadFromLines(r){return e().loadFromLines(r)},loadFromWorkerData(r){return e().loadFromWorkerData(r)},unload(){e().unload()},setOptions(r){e().setOptions(r)},getOptions(){return e().getOptions()},resize(){e().resize()},focusToModel(){e().focusToModel()},resetCamera(){e().resetCamera()},getBounds(){return e().getBounds()},dispose(){e().dispose()}}},[i]),o.createElement("div",{ref:d,className:m,style:f})}),C=o.forwardRef(function(u,s){const{id:i,options:a,className:c,style:m}=u,f=o.useRef(null),d=o.useRef(null);return o.useEffect(()=>{const t=f.current;if(!t)return;const e=new F.GCodeSVGRenderer(t,a);return d.current=e,()=>{d.current=null,e.dispose()}},[]),o.useEffect(()=>{var t;a&&((t=d.current)==null||t.setOptions(a))},[a]),o.useImperativeHandle(s,()=>{const t=()=>{const e=d.current;if(!e)throw new Error("GCodeSVGRenderer is not ready.");return e};return{loadFromLines:e=>t().loadFromLines(e),loadFromFile:e=>t().loadFromFile(e),loadFromText:e=>t().loadFromText(e),loadFromWorkerData:e=>t().loadFromWorkerData(e),loadFromPrecomputedGroups:e=>t().loadFromPrecomputedGroups(e),clear:()=>t().clear(),resetView:()=>t().resetView(),setOptions:e=>t().setOptions(e),setProjectionMode:e=>t().setProjectionMode(e),getSVGElement:()=>t().getSVGElement(),dispose:()=>t().dispose()}},[]),o.createElement("div",{ref:f,className:c,style:{width:"100%",height:"100%",...m}})});exports.GCodeSVGVisualizer=C;exports.GCodeVisualizer=G;
|
package/dist/react.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { a as F, G as w } from "./GCodeSVGRenderer-
|
|
3
|
-
const C =
|
|
1
|
+
import * as t from "react";
|
|
2
|
+
import { a as F, G as w } from "./GCodeSVGRenderer-DUQ-WgJi.js";
|
|
3
|
+
const C = t.forwardRef(
|
|
4
4
|
function(u, c) {
|
|
5
|
-
const { id: a, options: n, callbacks: l, className:
|
|
6
|
-
return
|
|
5
|
+
const { id: a, options: n, callbacks: l, className: m, style: d } = u, i = t.useRef(null), o = t.useRef(null);
|
|
6
|
+
return t.useEffect(() => {
|
|
7
7
|
const e = i.current;
|
|
8
8
|
if (!e)
|
|
9
9
|
return;
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
|
|
10
|
+
const f = new F({ id: a, container: e, options: n, callbacks: l });
|
|
11
|
+
return o.current = f, () => {
|
|
12
|
+
o.current = null, f.dispose();
|
|
13
13
|
};
|
|
14
|
-
}, [a]),
|
|
14
|
+
}, [a]), t.useEffect(() => {
|
|
15
15
|
var e;
|
|
16
|
-
(e =
|
|
17
|
-
}, [n]),
|
|
16
|
+
(e = o.current) == null || e.setOptions(n ?? {});
|
|
17
|
+
}, [n]), t.useEffect(() => {
|
|
18
18
|
var e;
|
|
19
|
-
(e =
|
|
20
|
-
}, [l]),
|
|
19
|
+
(e = o.current) == null || e.setCallbacks(l ?? {});
|
|
20
|
+
}, [l]), t.useImperativeHandle(
|
|
21
21
|
c,
|
|
22
22
|
() => {
|
|
23
23
|
const e = () => {
|
|
24
|
-
const r =
|
|
24
|
+
const r = o.current;
|
|
25
25
|
if (!r)
|
|
26
26
|
throw new Error("GCodeViewer is not ready.");
|
|
27
27
|
return r;
|
|
@@ -99,43 +99,44 @@ const C = o.forwardRef(
|
|
|
99
99
|
};
|
|
100
100
|
},
|
|
101
101
|
[a]
|
|
102
|
-
),
|
|
102
|
+
), t.createElement("div", { ref: i, className: m, style: d });
|
|
103
103
|
}
|
|
104
|
-
), G =
|
|
104
|
+
), G = t.forwardRef(
|
|
105
105
|
function(u, c) {
|
|
106
|
-
const { id: a, options: n, className: l, style:
|
|
107
|
-
return
|
|
108
|
-
const
|
|
109
|
-
if (!
|
|
110
|
-
const e = new w(
|
|
106
|
+
const { id: a, options: n, className: l, style: m } = u, d = t.useRef(null), i = t.useRef(null);
|
|
107
|
+
return t.useEffect(() => {
|
|
108
|
+
const o = d.current;
|
|
109
|
+
if (!o) return;
|
|
110
|
+
const e = new w(o, n);
|
|
111
111
|
return i.current = e, () => {
|
|
112
112
|
i.current = null, e.dispose();
|
|
113
113
|
};
|
|
114
|
-
}, []),
|
|
115
|
-
var
|
|
116
|
-
n && ((
|
|
117
|
-
}, [n]),
|
|
118
|
-
const
|
|
114
|
+
}, []), t.useEffect(() => {
|
|
115
|
+
var o;
|
|
116
|
+
n && ((o = i.current) == null || o.setOptions(n));
|
|
117
|
+
}, [n]), t.useImperativeHandle(c, () => {
|
|
118
|
+
const o = () => {
|
|
119
119
|
const e = i.current;
|
|
120
120
|
if (!e) throw new Error("GCodeSVGRenderer is not ready.");
|
|
121
121
|
return e;
|
|
122
122
|
};
|
|
123
123
|
return {
|
|
124
|
-
loadFromLines: (e) =>
|
|
125
|
-
loadFromFile: (e) =>
|
|
126
|
-
loadFromText: (e) =>
|
|
127
|
-
loadFromWorkerData: (e) =>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
124
|
+
loadFromLines: (e) => o().loadFromLines(e),
|
|
125
|
+
loadFromFile: (e) => o().loadFromFile(e),
|
|
126
|
+
loadFromText: (e) => o().loadFromText(e),
|
|
127
|
+
loadFromWorkerData: (e) => o().loadFromWorkerData(e),
|
|
128
|
+
loadFromPrecomputedGroups: (e) => o().loadFromPrecomputedGroups(e),
|
|
129
|
+
clear: () => o().clear(),
|
|
130
|
+
resetView: () => o().resetView(),
|
|
131
|
+
setOptions: (e) => o().setOptions(e),
|
|
132
|
+
setProjectionMode: (e) => o().setProjectionMode(e),
|
|
133
|
+
getSVGElement: () => o().getSVGElement(),
|
|
134
|
+
dispose: () => o().dispose()
|
|
134
135
|
};
|
|
135
|
-
}, []),
|
|
136
|
+
}, []), t.createElement("div", {
|
|
136
137
|
ref: d,
|
|
137
138
|
className: l,
|
|
138
|
-
style: { width: "100%", height: "100%", ...
|
|
139
|
+
style: { width: "100%", height: "100%", ...m }
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
142
|
);
|
|
@@ -6,6 +6,12 @@ export type GCodeSVGRendererHandle = {
|
|
|
6
6
|
loadFromFile(file: File): Promise<void>;
|
|
7
7
|
loadFromText(gcode: string): void;
|
|
8
8
|
loadFromWorkerData(data: WorkerGeometryData): void;
|
|
9
|
+
loadFromPrecomputedGroups(groups: {
|
|
10
|
+
hexColor: string;
|
|
11
|
+
opacity: number;
|
|
12
|
+
positionsBuffer: ArrayBuffer;
|
|
13
|
+
positionsLen: number;
|
|
14
|
+
}[]): void;
|
|
9
15
|
clear(): void;
|
|
10
16
|
resetView(): void;
|
|
11
17
|
setOptions(opts: Partial<GCodeSVGOptions>): void;
|
|
@@ -37,6 +37,12 @@ export declare class GCodeSVGRenderer {
|
|
|
37
37
|
loadFromText(gcode: string): void;
|
|
38
38
|
clear(): void;
|
|
39
39
|
loadFromWorkerData(data: WorkerGeometryData): void;
|
|
40
|
+
loadFromPrecomputedGroups(groups: {
|
|
41
|
+
hexColor: string;
|
|
42
|
+
opacity: number;
|
|
43
|
+
positionsBuffer: ArrayBuffer;
|
|
44
|
+
positionsLen: number;
|
|
45
|
+
}[]): void;
|
|
40
46
|
private syncSegmentGroupsFromLines;
|
|
41
47
|
resetView(): void;
|
|
42
48
|
setOptions(opts: Partial<GCodeSVGOptions>): void;
|
package/dist/viewer.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./GCodeSVGRenderer-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./GCodeSVGRenderer-hZ8tZwov.cjs"),a={dark:{background:"#111827",opacity:.9,rapidOpacity:.3,colors:{rapid:"#0ef6ae",cutting:"#3e85c7",laser:"#a855f7",processed:"#6b7280",boundingBox:"#77a9d7",grid:{major:"#77a9d7",minor:"#3e6e9e"},axes:{x:"#df3b3b",y:"#06b881",z:"#295d8d"}}},light:{background:"#e5e7eb",opacity:.9,rapidOpacity:.3,colors:{rapid:"#295d8d",cutting:"#111827",laser:"#FF0000",processed:"#9ca3af",boundingBox:"#5191cc",grid:{major:"#295d8d",minor:"#5191cc"},axes:{x:"#df3b3b",y:"#06b881",z:"#295d8d"}}},"flexoki-dark":{background:"#100f0f",opacity:.9,rapidOpacity:.3,colors:{rapid:"#DA702C",cutting:"#3AA99F",laser:"#8B7EC8",processed:"#6f6e69",boundingBox:"#da702c",grid:{major:"#a89984",minor:"#6f6e69"},axes:{x:"#d14d41",y:"#879a39",z:"#4385be"}}},"tokyo-night":{background:"#1a1b26",opacity:.9,rapidOpacity:.3,colors:{rapid:"#ff9e64",cutting:"#7dcfff",laser:"#bb9af7",processed:"#565f89",boundingBox:"#73daca",grid:{major:"#7aa2f7",minor:"#414868"},axes:{x:"#f7768e",y:"#9ece6a",z:"#7aa2f7"}}},"gruvbox-light":{background:"#fbf1c7",opacity:.9,rapidOpacity:.3,colors:{rapid:"#d65d0e",cutting:"#3c3836",laser:"#b16286",processed:"#928374",boundingBox:"#076678",grid:{major:"#7c6f64",minor:"#a89984"},axes:{x:"#cc241d",y:"#98971a",z:"#458588"}}},"ayu-dark":{background:"#0b0e14",opacity:.9,rapidOpacity:.3,colors:{rapid:"#FFA659",cutting:"#73D0FF",laser:"#DFBFFF",processed:"#6E7C8F",boundingBox:"#95E6CB",grid:{major:"#77a9d7",minor:"#3e6590"},axes:{x:"#F28779",y:"#D5FF80",z:"#5CCFE6"}}},"ayu-light":{background:"#fafafa",opacity:.9,rapidOpacity:.3,colors:{rapid:"#FA8D3E",cutting:"#22A4E6",laser:"#A37ACC",processed:"#ADAEB1",boundingBox:"#5C6773",grid:{major:"#5c6773",minor:"#9aacba"},axes:{x:"#F07171",y:"#86B300",z:"#55B4D4"}}}};exports.GCodeSVGRenderer=e.GCodeSVGRenderer;exports.GCodeViewer=e.GCodeViewer;exports.ViewCube=e.ViewCube;exports.defaultGCodeViewerOptions=e.defaultGCodeViewerOptions;exports.defaultGCodeViewerTheme=e.defaultGCodeViewerTheme;exports.gCodeViewerThemePresets=a;
|
package/dist/viewer.js
CHANGED