@sienci/gviewer 0.1.13 → 0.1.14

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/gviewer.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const U = /([A-Za-z])\s*([+-]?(?:\d+(?:\.\d*)?|\.\d+))/g;
2
2
  class R {
3
- parseLine(t) {
4
- const n = [], e = this.stripComments(t, n), s = this.parseWords(e), r = s.filter((a) => {
3
+ parseLine(e) {
4
+ const o = [], t = this.stripComments(e, o), s = this.parseWords(t), r = s.filter((a) => {
5
5
  const c = a.letter.toUpperCase();
6
6
  return c === "G" || c === "M";
7
7
  }), i = s.filter((a) => {
@@ -9,20 +9,20 @@ class R {
9
9
  return c !== "G" && c !== "M";
10
10
  });
11
11
  return {
12
- raw: t,
12
+ raw: e,
13
13
  words: s,
14
14
  gcodes: r,
15
15
  params: i,
16
- comments: n
16
+ comments: o
17
17
  };
18
18
  }
19
- stripComments(t, n) {
20
- let e = "", s = !1, r = -1, i = "";
21
- for (let a = 0; a < t.length; a += 1) {
22
- const c = t[a];
19
+ stripComments(e, o) {
20
+ let t = "", s = !1, r = -1, i = "";
21
+ for (let a = 0; a < e.length; a += 1) {
22
+ const c = e[a];
23
23
  if (!s && c === ";") {
24
- const u = t.slice(a + 1);
25
- n.push({ type: "semicolon", text: u, start: a, end: t.length });
24
+ const u = e.slice(a + 1);
25
+ o.push({ type: "semicolon", text: u, start: a, end: e.length });
26
26
  break;
27
27
  }
28
28
  if (c === "(") {
@@ -30,7 +30,7 @@ class R {
30
30
  continue;
31
31
  }
32
32
  if (c === ")" && s) {
33
- n.push({
33
+ o.push({
34
34
  type: "paren",
35
35
  text: i,
36
36
  start: r,
@@ -42,25 +42,25 @@ class R {
42
42
  i += c;
43
43
  continue;
44
44
  }
45
- e += c;
45
+ t += c;
46
46
  }
47
- return s && n.push({
47
+ return s && o.push({
48
48
  type: "paren",
49
49
  text: i,
50
50
  start: r,
51
- end: t.length
52
- }), e;
51
+ end: e.length
52
+ }), t;
53
53
  }
54
- parseWords(t) {
55
- const n = [];
56
- for (const e of t.matchAll(U)) {
57
- const s = e[0], r = e[1].toUpperCase(), i = Number(e[2]), a = e.index ?? 0, c = a + s.length;
58
- n.push({ letter: r, value: i, raw: s, start: a, end: c });
54
+ parseWords(e) {
55
+ const o = [];
56
+ for (const t of e.matchAll(U)) {
57
+ const s = t[0], r = t[1].toUpperCase(), i = Number(t[2]), a = t.index ?? 0, c = a + s.length;
58
+ o.push({ letter: r, value: i, raw: s, start: a, end: c });
59
59
  }
60
- return n;
60
+ return o;
61
61
  }
62
62
  }
63
- const Z = ["X", "Y", "Z", "A", "B", "C"], X = {
63
+ const F = ["X", "Y", "Z", "A", "B", "C"], Z = {
64
64
  motion: "G0",
65
65
  distance: "G90",
66
66
  plane: "G17",
@@ -73,12 +73,12 @@ const Z = ["X", "Y", "Z", "A", "B", "C"], X = {
73
73
  spindle: null,
74
74
  coordinateSystem: "G54"
75
75
  };
76
- class L {
77
- constructor(t = {}) {
78
- this.parser = new R(), this.modals = { ...X }, this.position = { X: 0, Y: 0, Z: 0, A: 0, B: 0, C: 0 }, this.callbacks = t, this.feedRates = /* @__PURE__ */ new Set(), this.spindleSpeeds = /* @__PURE__ */ new Set(), this.tools = /* @__PURE__ */ new Set();
76
+ class I {
77
+ constructor(e = {}) {
78
+ this.parser = new R(), this.modals = { ...Z }, this.position = { X: 0, Y: 0, Z: 0, A: 0, B: 0, C: 0 }, this.callbacks = e, this.feedRates = /* @__PURE__ */ new Set(), this.spindleSpeeds = /* @__PURE__ */ new Set(), this.tools = /* @__PURE__ */ new Set();
79
79
  }
80
- setCallbacks(t) {
81
- this.callbacks = t;
80
+ setCallbacks(e) {
81
+ this.callbacks = e;
82
82
  }
83
83
  getModals() {
84
84
  return { ...this.modals };
@@ -96,17 +96,17 @@ class L {
96
96
  return Array.from(this.tools);
97
97
  }
98
98
  reset() {
99
- this.modals = { ...X }, this.position = { X: 0, Y: 0, Z: 0, A: 0, B: 0, C: 0 }, this.feedRates.clear(), this.spindleSpeeds.clear(), this.tools.clear();
99
+ this.modals = { ...Z }, this.position = { X: 0, Y: 0, Z: 0, A: 0, B: 0, C: 0 }, this.feedRates.clear(), this.spindleSpeeds.clear(), this.tools.clear();
100
100
  }
101
- processLine(t) {
102
- const n = this.parser.parseLine(t), e = { ...this.position };
103
- this.updateModals(n);
101
+ processLine(e) {
102
+ const o = this.parser.parseLine(e), t = { ...this.position };
103
+ this.updateModals(o);
104
104
  const s = this.modals.motion, r = this.modals.plane;
105
- let i = this.applyAxes(n, e), a, c, u = "none";
106
- return s === "G0" || s === "G1" ? N(e, i) || (u = "linear", this.position = { ...i }, this.emitLinear({ start: e, end: i })) : (s === "G2" || s === "G3") && (N(e, i) || (u = "arc", c = this.arcCenter(n, e, i, r), a = this.computeArcMax(e, i, s, r, c), this.position = { ...i }, this.emitArc({ start: e, end: i, max: a, center: c, plane: r, motion: s }))), {
107
- parsed: n,
105
+ let i = this.applyAxes(o, t), a, c, u = "none";
106
+ return s === "G0" || s === "G1" ? N(t, i) || (u = "linear", this.position = { ...i }, this.emitLinear({ start: t, end: i })) : (s === "G2" || s === "G3") && (N(t, i) || (u = "arc", c = this.arcCenter(o, 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 }))), {
107
+ parsed: o,
108
108
  modals: { ...this.modals },
109
- start: e,
109
+ start: t,
110
110
  end: i,
111
111
  movement: u,
112
112
  arcMax: a
@@ -115,78 +115,78 @@ class L {
115
115
  unitsScale() {
116
116
  return this.modals.units === "G20" ? 25.4 : 1;
117
117
  }
118
- updateModals(t) {
119
- for (const n of t.gcodes) {
120
- if (n.letter.toUpperCase() === "G") {
121
- const e = `G${Math.trunc(n.value)}`;
122
- (e === "G0" || e === "G1" || e === "G2" || e === "G3") && (this.modals.motion = e), (e === "G90" || e === "G91") && (this.modals.distance = e), (e === "G17" || e === "G18" || e === "G19") && (this.modals.plane = e), (e === "G20" || e === "G21") && (this.modals.units = e), (e === "G93" || e === "G94") && (this.modals.feedMode = e), (e === "G54" || e === "G55" || e === "G56" || e === "G57" || e === "G58" || e === "G59") && (this.modals.coordinateSystem = e);
118
+ updateModals(e) {
119
+ for (const o of e.gcodes) {
120
+ if (o.letter.toUpperCase() === "G") {
121
+ const t = `G${Math.trunc(o.value)}`;
122
+ (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);
123
123
  }
124
- if (n.letter.toUpperCase() === "M") {
125
- const e = `M${Math.trunc(n.value)}`;
126
- (e === "M7" || e === "M8" || e === "M9") && (this.modals.coolant = e), (e === "M3" || e === "M4" || e === "M5") && (this.modals.spindle = e);
124
+ if (o.letter.toUpperCase() === "M") {
125
+ const t = `M${Math.trunc(o.value)}`;
126
+ (t === "M7" || t === "M8" || t === "M9") && (this.modals.coolant = t), (t === "M3" || t === "M4" || t === "M5") && (this.modals.spindle = t);
127
127
  }
128
128
  }
129
- for (const n of t.params) {
130
- const e = n.letter.toUpperCase();
131
- e === "F" && (this.modals.feedRate = n.value, this.feedRates.add(n.value)), e === "S" && (this.modals.spindleSpeed = n.value, this.spindleSpeeds.add(n.value)), e === "T" && (this.modals.tool = n.value, this.tools.add(n.value));
129
+ for (const o of e.params) {
130
+ const t = o.letter.toUpperCase();
131
+ t === "F" && (this.modals.feedRate = o.value, this.feedRates.add(o.value)), t === "S" && (this.modals.spindleSpeed = o.value, this.spindleSpeeds.add(o.value)), t === "T" && (this.modals.tool = o.value, this.tools.add(o.value));
132
132
  }
133
133
  }
134
- applyAxes(t, n) {
135
- const e = { ...n }, s = this.unitsScale();
136
- for (const r of Z) {
137
- const i = t.params.find((c) => c.letter.toUpperCase() === r);
134
+ applyAxes(e, o) {
135
+ const t = { ...o }, s = this.unitsScale();
136
+ for (const r of F) {
137
+ const i = e.params.find((c) => c.letter.toUpperCase() === r);
138
138
  if (!i)
139
139
  continue;
140
140
  const a = r === "X" || r === "Y" || r === "Z" ? i.value * s : i.value;
141
- this.modals.distance === "G90" ? e[r] = a : e[r] = e[r] + a;
141
+ this.modals.distance === "G90" ? t[r] = a : t[r] = t[r] + a;
142
142
  }
143
- return e;
143
+ return t;
144
144
  }
145
- computeArcMax(t, n, e, s, r) {
146
- const { primary: i, secondary: a, tertiary: c } = C(s), u = j(
147
- t[i],
148
- t[a],
145
+ computeArcMax(e, o, t, s, r) {
146
+ const { primary: i, secondary: a, tertiary: c } = X(s), u = j(
147
+ e[i],
148
+ e[a],
149
149
  r[i],
150
150
  r[a]
151
151
  ), f = Math.atan2(
152
- t[a] - r[a],
153
- t[i] - r[i]
152
+ e[a] - r[a],
153
+ e[i] - r[i]
154
154
  ), d = Math.atan2(
155
- n[a] - r[a],
156
- n[i] - r[i]
157
- ), y = $(f, d, e);
158
- let l = Number.NEGATIVE_INFINITY, h = Number.NEGATIVE_INFINITY;
159
- for (const A of y) {
160
- const G = r[i] + u * Math.cos(A), p = r[a] + u * Math.sin(A);
161
- G > l && (l = G), p > h && (h = p);
155
+ o[a] - r[a],
156
+ o[i] - r[i]
157
+ ), M = $(f, d, t);
158
+ let l = Number.NEGATIVE_INFINITY, m = Number.NEGATIVE_INFINITY;
159
+ for (const x of M) {
160
+ const w = r[i] + u * Math.cos(x), h = r[a] + u * Math.sin(x);
161
+ w > l && (l = w), h > m && (m = h);
162
162
  }
163
- const M = { ...t };
164
- M[i] = l, M[a] = h, M[c] = Math.max(t[c], n[c]);
165
- for (const A of Z)
166
- A !== i && A !== a && A !== c && (M[A] = Math.max(t[A], n[A]));
167
- return M;
163
+ const A = { ...e };
164
+ A[i] = l, A[a] = m, A[c] = Math.max(e[c], o[c]);
165
+ for (const x of F)
166
+ x !== i && x !== a && x !== c && (A[x] = Math.max(e[x], o[x]));
167
+ return A;
168
168
  }
169
- arcCenter(t, n, e, s) {
170
- const { primary: r, secondary: i } = C(s), a = { ...n }, c = this.unitsScale(), u = F(t, "R"), f = _(t, s), d = f.primary === null ? null : f.primary * c, y = f.secondary === null ? null : f.secondary * c;
171
- if (d !== null || y !== null)
172
- return a[r] = n[r] + (d ?? 0), a[i] = n[i] + (y ?? 0), a;
169
+ arcCenter(e, o, t, s) {
170
+ const { primary: r, secondary: i } = X(s), a = { ...o }, c = this.unitsScale(), u = C(e, "R"), f = _(e, s), d = f.primary === null ? null : f.primary * c, M = f.secondary === null ? null : f.secondary * c;
171
+ if (d !== null || M !== null)
172
+ return a[r] = o[r] + (d ?? 0), a[i] = o[i] + (M ?? 0), a;
173
173
  if (u === null)
174
174
  return a;
175
- const l = u * c, h = n[r], M = n[i], A = e[r], G = e[i], p = A - h, w = G - M, S = Math.hypot(p, w);
175
+ const l = u * c, m = o[r], A = o[i], x = t[r], w = t[i], h = x - m, G = w - A, S = Math.hypot(h, G);
176
176
  if (S === 0)
177
177
  return a;
178
- const I = Math.abs(l), m = Math.sqrt(Math.max(0, I * I - S / 2 * (S / 2))), x = (h + A) / 2, v = (M + G) / 2, P = -w / S, E = p / S, Y = l >= 0 ? 1 : -1;
179
- return a[r] = x + Y * P * m, a[i] = v + Y * E * m, a;
178
+ const L = Math.abs(l), p = Math.sqrt(Math.max(0, L * L - S / 2 * (S / 2))), y = (m + x) / 2, v = (A + w) / 2, P = -G / S, E = h / S, Y = l >= 0 ? 1 : -1;
179
+ return a[r] = y + Y * P * p, a[i] = v + Y * E * p, a;
180
180
  }
181
- emitLinear(t) {
182
- const n = this.callbacks.onLinearMove;
183
- if (!n)
181
+ emitLinear(e) {
182
+ const o = this.callbacks.onLinearMove;
183
+ if (!o)
184
184
  return;
185
- const e = t.end.A - t.start.A, s = Math.max(1, Math.ceil(Math.abs(e) / W));
186
- let r = { ...t.start };
185
+ const t = e.end.A - e.start.A, s = Math.max(1, Math.ceil(Math.abs(t) / W));
186
+ let r = { ...e.start };
187
187
  for (let i = 1; i <= s; i += 1) {
188
- const a = i / s, c = q(t.start, t.end, a), u = V(r), f = V(c);
189
- n({
188
+ const a = i / s, c = q(e.start, e.end, a), u = V(r), f = V(c);
189
+ o({
190
190
  modals: { ...this.modals },
191
191
  start: { ...r },
192
192
  end: { ...c },
@@ -195,212 +195,212 @@ class L {
195
195
  }), r = c;
196
196
  }
197
197
  }
198
- emitArc(t) {
199
- const n = this.callbacks.onArcMove;
200
- if (!n)
198
+ emitArc(e) {
199
+ const o = this.callbacks.onArcMove;
200
+ if (!o)
201
201
  return;
202
- const e = V(t.start), s = V(t.end), r = V(t.max), i = V(t.center);
203
- n({
202
+ const t = V(e.start), s = V(e.end), r = V(e.max), i = V(e.center);
203
+ o({
204
204
  modals: { ...this.modals },
205
- start: { ...t.start },
206
- end: { ...t.end },
207
- max: { ...t.max },
208
- center: { ...t.center },
209
- plane: t.plane,
210
- motion: t.motion,
211
- transformedStart: e,
205
+ start: { ...e.start },
206
+ end: { ...e.end },
207
+ max: { ...e.max },
208
+ center: { ...e.center },
209
+ plane: e.plane,
210
+ motion: e.motion,
211
+ transformedStart: t,
212
212
  transformedEnd: s,
213
213
  transformedMax: r,
214
214
  transformedCenter: i
215
215
  });
216
216
  }
217
217
  }
218
- function F(o, t) {
219
- const n = o.params.find((e) => e.letter.toUpperCase() === t);
220
- return n ? n.value : null;
218
+ function C(n, e) {
219
+ const o = n.params.find((t) => t.letter.toUpperCase() === e);
220
+ return o ? o.value : null;
221
221
  }
222
- function C(o) {
223
- return o === "G18" ? { primary: "Z", secondary: "X", tertiary: "Y" } : o === "G19" ? { primary: "Y", secondary: "Z", tertiary: "X" } : { primary: "X", secondary: "Y", tertiary: "Z" };
222
+ function X(n) {
223
+ return n === "G18" ? { primary: "Z", secondary: "X", tertiary: "Y" } : n === "G19" ? { primary: "Y", secondary: "Z", tertiary: "X" } : { primary: "X", secondary: "Y", tertiary: "Z" };
224
224
  }
225
- function _(o, t) {
226
- const n = F(o, "I"), e = F(o, "J"), s = F(o, "K");
227
- return t === "G18" ? { primary: s, secondary: n } : t === "G19" ? { primary: e, secondary: s } : { primary: n, secondary: e };
225
+ function _(n, e) {
226
+ const o = C(n, "I"), t = C(n, "J"), s = C(n, "K");
227
+ return e === "G18" ? { primary: s, secondary: o } : e === "G19" ? { primary: t, secondary: s } : { primary: o, secondary: t };
228
228
  }
229
- function $(o, t, n) {
230
- const e = Math.PI * 2;
231
- let s = b(o), r = b(t);
232
- const i = [0, Math.PI / 2, Math.PI, 3 * Math.PI / 2, e];
233
- if (n === "G2") {
234
- s < r && (s += e);
229
+ function $(n, e, o) {
230
+ const t = Math.PI * 2;
231
+ let s = b(n), r = b(e);
232
+ const i = [0, Math.PI / 2, Math.PI, 3 * Math.PI / 2, t];
233
+ if (o === "G2") {
234
+ s < r && (s += t);
235
235
  const c = [s, r];
236
236
  for (const u of i) {
237
237
  let f = u;
238
- f < r && (f += e), f <= s && f >= r && c.push(f);
238
+ f < r && (f += t), f <= s && f >= r && c.push(f);
239
239
  }
240
240
  return c;
241
241
  }
242
- r < s && (r += e);
242
+ r < s && (r += t);
243
243
  const a = [s, r];
244
244
  for (const c of i) {
245
245
  let u = c;
246
- u < s && (u += e), u >= s && u <= r && a.push(u);
246
+ u < s && (u += t), u >= s && u <= r && a.push(u);
247
247
  }
248
248
  return a;
249
249
  }
250
- function b(o) {
251
- const t = Math.PI * 2;
252
- let n = o % t;
253
- return n < 0 && (n += t), n;
250
+ function b(n) {
251
+ const e = Math.PI * 2;
252
+ let o = n % e;
253
+ return o < 0 && (o += e), o;
254
254
  }
255
- function j(o, t, n, e) {
256
- return Math.hypot(o - n, t - e);
255
+ function j(n, e, o, t) {
256
+ return Math.hypot(n - o, e - t);
257
257
  }
258
- function N(o, t) {
259
- return Z.every((n) => o[n] === t[n]);
258
+ function N(n, e) {
259
+ return F.every((o) => n[o] === e[o]);
260
260
  }
261
261
  const W = 5;
262
- function q(o, t, n) {
262
+ function q(n, e, o) {
263
263
  return {
264
- X: o.X + (t.X - o.X) * n,
265
- Y: o.Y + (t.Y - o.Y) * n,
266
- Z: o.Z + (t.Z - o.Z) * n,
267
- A: o.A + (t.A - o.A) * n,
268
- B: o.B + (t.B - o.B) * n,
269
- C: o.C + (t.C - o.C) * n
264
+ X: n.X + (e.X - n.X) * o,
265
+ Y: n.Y + (e.Y - n.Y) * o,
266
+ Z: n.Z + (e.Z - n.Z) * o,
267
+ A: n.A + (e.A - n.A) * o,
268
+ B: n.B + (e.B - n.B) * o,
269
+ C: n.C + (e.C - n.C) * o
270
270
  };
271
271
  }
272
- function V(o) {
273
- const t = o.A * Math.PI / 180, n = Math.cos(t), e = Math.sin(t), s = o.Y * n - o.Z * e, r = o.Y * e + o.Z * n;
274
- return { ...o, Y: s, Z: r };
272
+ function V(n) {
273
+ const e = n.A * Math.PI / 180, o = Math.cos(e), t = Math.sin(e), s = n.Y * o - n.Z * t, r = n.Y * t + n.Z * o;
274
+ return { ...n, Y: s, Z: r };
275
275
  }
276
- function ne(o, t = {}) {
277
- const n = [], e = t.arcSegments ?? 30, s = t.collector ?? {}, r = new L({
276
+ function ne(n, e = {}) {
277
+ const o = [], t = e.arcSegments ?? 30, s = e.collector ?? {}, r = new I({
278
278
  onLinearMove: (i) => {
279
- (s.onLinearMove ?? z)(i, n);
279
+ (s.onLinearMove ?? z)(i, o);
280
280
  },
281
281
  onArcMove: (i) => {
282
282
  (s.onArcMove ?? ((c, u) => {
283
- g(c, u, e);
284
- }))(i, n);
283
+ g(c, u, t);
284
+ }))(i, o);
285
285
  }
286
286
  });
287
- for (const i of o)
287
+ for (const i of n)
288
288
  i && r.processLine(i);
289
- return Float32Array.from(n);
289
+ return Float32Array.from(o);
290
290
  }
291
- function oe(o, t = {}) {
292
- const n = [], e = [], s = t.arcSegments ?? 30, r = new L({
291
+ function oe(n, e = {}) {
292
+ const o = [], t = [], s = e.arcSegments ?? 30, r = new I({
293
293
  onLinearMove: (i) => {
294
294
  const a = i.transformedStart ?? i.start, c = i.transformedEnd ?? i.end;
295
- (i.modals.motion === "G0" ? n : e).push(a.X, a.Y, a.Z, c.X, c.Y, c.Z);
295
+ (i.modals.motion === "G0" ? o : t).push(a.X, a.Y, a.Z, c.X, c.Y, c.Z);
296
296
  },
297
297
  onArcMove: (i) => {
298
- const a = i.modals.motion === "G0" ? n : e;
298
+ const a = i.modals.motion === "G0" ? o : t;
299
299
  g(i, a, s);
300
300
  }
301
301
  });
302
- for (const i of o)
302
+ for (const i of n)
303
303
  i && r.processLine(i);
304
304
  return {
305
- rapid: Float32Array.from(n),
306
- cutting: Float32Array.from(e)
305
+ rapid: Float32Array.from(o),
306
+ cutting: Float32Array.from(t)
307
307
  };
308
308
  }
309
- async function re(o, t = {}) {
310
- var y;
311
- const n = [], e = [], s = t.arcSegments ?? 30, r = t.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));
309
+ async function re(n, e = {}) {
310
+ var M;
311
+ const o = [], 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));
312
312
  let c = i, u = a > 0 ? a : Number.POSITIVE_INFINITY;
313
- const f = new L({
313
+ const f = new I({
314
314
  onLinearMove: (l) => {
315
- const h = l.transformedStart ?? l.start, M = l.transformedEnd ?? l.end;
316
- (l.modals.motion === "G0" ? n : e).push(h.X, h.Y, h.Z, M.X, M.Y, M.Z);
315
+ const m = l.transformedStart ?? l.start, A = l.transformedEnd ?? l.end;
316
+ (l.modals.motion === "G0" ? o : t).push(m.X, m.Y, m.Z, A.X, A.Y, A.Z);
317
317
  },
318
318
  onArcMove: (l) => {
319
- const h = l.modals.motion === "G0" ? n : e;
320
- g(l, h, s);
319
+ const m = l.modals.motion === "G0" ? o : t;
320
+ g(l, m, s);
321
321
  }
322
- }), d = o.length;
322
+ }), d = n.length;
323
323
  for (let l = 0; l < d; l += 1) {
324
- if ((y = r == null ? void 0 : r.shouldAbort) != null && y.call(r))
324
+ if ((M = r == null ? void 0 : r.shouldAbort) != null && M.call(r))
325
325
  throw new Error("Aborted.");
326
- const h = o[l];
327
- if (!h) {
328
- 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((M) => {
329
- setTimeout(M, 0);
326
+ const m = n[l];
327
+ if (!m) {
328
+ 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((A) => {
329
+ setTimeout(A, 0);
330
330
  }), u += a);
331
331
  continue;
332
332
  }
333
- f.processLine(h), 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((M) => {
334
- setTimeout(M, 0);
333
+ f.processLine(m), 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((A) => {
334
+ setTimeout(A, 0);
335
335
  }), u += a);
336
336
  }
337
337
  return {
338
- rapid: Float32Array.from(n),
339
- cutting: Float32Array.from(e)
338
+ rapid: Float32Array.from(o),
339
+ cutting: Float32Array.from(t)
340
340
  };
341
341
  }
342
- async function se(o, t = {}) {
343
- var G;
344
- const n = [], e = t.arcSegments ?? 30, s = t.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));
342
+ async function se(n, e = {}) {
343
+ var w;
344
+ const o = [], 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));
345
345
  let a = r, c = i > 0 ? i : Number.POSITIVE_INFINITY;
346
- const u = new Int32Array(o.length);
346
+ const u = new Int32Array(n.length);
347
347
  u.fill(-1);
348
- const f = new Int32Array(o.length);
348
+ const f = new Int32Array(n.length);
349
349
  f.fill(-1);
350
- const d = new Uint8Array(o.length), y = new Int32Array(o.length);
351
- let l = -1, h = 0;
352
- const M = new L({
353
- onLinearMove: (p) => {
354
- const w = p.modals.motion === "G0" ? 1 : 2;
355
- l >= 0 && (h === 0 ? h = w : h !== w && (h = 3)), z(p, n);
350
+ const d = new Uint8Array(n.length), M = new Int32Array(n.length);
351
+ let l = -1, m = 0;
352
+ const A = new I({
353
+ onLinearMove: (h) => {
354
+ const G = h.modals.motion === "G0" ? 1 : 2;
355
+ l >= 0 && (m === 0 ? m = G : m !== G && (m = 3)), z(h, o);
356
356
  },
357
- onArcMove: (p) => {
358
- const w = p.modals.motion === "G0" ? 1 : 2;
359
- l >= 0 && (h === 0 ? h = w : h !== w && (h = 3)), g(p, n, e);
357
+ onArcMove: (h) => {
358
+ const G = h.modals.motion === "G0" ? 1 : 2;
359
+ l >= 0 && (m === 0 ? m = G : m !== G && (m = 3)), g(h, o, t);
360
360
  }
361
- }), A = o.length;
362
- for (let p = 0; p < A; p += 1) {
363
- if ((G = s == null ? void 0 : s.shouldAbort) != null && G.call(s))
361
+ }), x = n.length;
362
+ for (let h = 0; h < x; h += 1) {
363
+ if ((w = s == null ? void 0 : s.shouldAbort) != null && w.call(s))
364
364
  throw new Error("Aborted.");
365
- const w = n.length / 3;
366
- l = p, h = 0;
367
- const S = o[p];
368
- S && M.processLine(S), l = -1;
369
- const I = n.length / 3;
370
- I > w && (u[p] = w, f[p] = I, d[p] = h), y[p] = I, s != null && s.onProgress && (p + 1 === A || p + 1 === a) && (s.onProgress(p + 1, A), a += r), i > 0 && (p + 1 === A || p + 1 === c) && (await new Promise((m) => {
371
- setTimeout(m, 0);
365
+ const G = o.length / 3;
366
+ l = h, m = 0;
367
+ const S = n[h];
368
+ S && A.processLine(S), l = -1;
369
+ const L = o.length / 3;
370
+ L > G && (u[h] = G, f[h] = L, d[h] = m), M[h] = L, s != null && s.onProgress && (h + 1 === x || h + 1 === a) && (s.onProgress(h + 1, x), a += r), i > 0 && (h + 1 === x || h + 1 === c) && (await new Promise((p) => {
371
+ setTimeout(p, 0);
372
372
  }), c += i);
373
373
  }
374
374
  return {
375
- positions: Float32Array.from(n),
375
+ positions: Float32Array.from(o),
376
376
  lineStartVertex: u,
377
377
  lineEndVertex: f,
378
378
  lineKind: d,
379
- prefixEndVertex: y
379
+ prefixEndVertex: M
380
380
  };
381
381
  }
382
- function ie(o, t = {}) {
383
- const n = t.arcSegments ?? 30, e = Math.max(1, Math.floor(t.bucketCount ?? 16)), s = t.baseOpacity ?? 0.9, { minPower: r, maxPower: i } = ee(o), a = [], c = Array.from({ length: e }, () => []), u = new L({
382
+ function ie(n, e = {}) {
383
+ const o = e.arcSegments ?? 30, t = Math.max(1, Math.floor(e.bucketCount ?? 16)), s = e.baseOpacity ?? 0.9, { minPower: r, maxPower: i } = ee(n), a = [], c = Array.from({ length: t }, () => []), u = new I({
384
384
  onLinearMove: (d) => {
385
- const y = d.transformedStart ?? d.start, l = d.transformedEnd ?? d.end;
385
+ const M = d.transformedStart ?? d.start, l = d.transformedEnd ?? d.end;
386
386
  if (d.modals.motion === "G0") {
387
- a.push(y.X, y.Y, y.Z, l.X, l.Y, l.Z);
387
+ a.push(M.X, M.Y, M.Z, l.X, l.Y, l.Z);
388
388
  return;
389
389
  }
390
- const h = B(d.modals.spindleSpeed, r, i, e);
391
- c[h].push(y.X, y.Y, y.Z, l.X, l.Y, l.Z);
390
+ const m = B(d.modals.spindleSpeed, r, i, t);
391
+ c[m].push(M.X, M.Y, M.Z, l.X, l.Y, l.Z);
392
392
  },
393
393
  onArcMove: (d) => {
394
394
  if (d.modals.motion === "G0")
395
395
  return;
396
- const y = B(d.modals.spindleSpeed, r, i, e), l = c[y];
397
- g(d, l, n);
396
+ const M = B(d.modals.spindleSpeed, r, i, t), l = c[M];
397
+ g(d, l, o);
398
398
  }
399
399
  });
400
- for (const d of o)
400
+ for (const d of n)
401
401
  d && u.processLine(d);
402
- const f = c.map((d, y) => ({
403
- opacity: O(y, e, s),
402
+ const f = c.map((d, M) => ({
403
+ opacity: O(M, t, s),
404
404
  vertices: Float32Array.from(d)
405
405
  }));
406
406
  return {
@@ -410,58 +410,58 @@ function ie(o, t = {}) {
410
410
  maxPower: i
411
411
  };
412
412
  }
413
- async function ae(o, t = {}) {
414
- const n = await K(o, t);
413
+ async function ae(n, e = {}) {
414
+ const o = await K(n, e);
415
415
  return {
416
- rapid: n.rapidPositions,
417
- buckets: n.buckets.map((e) => ({ opacity: e.opacity, vertices: e.positions })),
418
- minPower: n.minPower,
419
- maxPower: n.maxPower
416
+ rapid: o.rapidPositions,
417
+ buckets: o.buckets.map((t) => ({ opacity: t.opacity, vertices: t.positions })),
418
+ minPower: o.minPower,
419
+ maxPower: o.maxPower
420
420
  };
421
421
  }
422
- async function D(o, t = {}) {
423
- var S, I;
424
- const n = t.arcSegments ?? 30, e = Math.max(1, Math.floor(t.bucketCount ?? 16)), s = !!t.laserMode, r = t.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));
425
- let u = a, f = c > 0 ? c : Number.POSITIVE_INFINITY, d = Number.NEGATIVE_INFINITY, y = !1;
422
+ async function D(n, e = {}) {
423
+ var S, L;
424
+ const o = e.arcSegments ?? 30, t = Math.max(1, Math.floor(e.bucketCount ?? 16)), s = !!e.laserMode, r = e.batch, i = n.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));
425
+ let u = a, f = c > 0 ? c : Number.POSITIVE_INFINITY, d = Number.NEGATIVE_INFINITY, M = !1;
426
426
  if (s) {
427
- const m = new R();
428
- for (const x of o) {
429
- if (!x)
427
+ const p = new R();
428
+ for (const y of n) {
429
+ if (!y)
430
430
  continue;
431
- if (m.parseLine(x).gcodes.some((E) => {
431
+ if (p.parseLine(y).gcodes.some((E) => {
432
432
  if (E.letter !== "M")
433
433
  return !1;
434
434
  const Y = Math.trunc(E.value);
435
435
  return Y === 3 || Y === 4 || Y === 5;
436
436
  })) {
437
- y = !1;
437
+ M = !1;
438
438
  break;
439
439
  }
440
- y = !0;
440
+ M = !0;
441
441
  }
442
442
  }
443
- const l = (m) => m.spindle === "M5" || !(m.spindle === "M3" || m.spindle === "M4" || y && m.spindle === null) ? !1 : m.spindleSpeed === null ? !0 : m.spindleSpeed > 0;
443
+ const l = (p) => p.spindle === "M5" || !(p.spindle === "M3" || p.spindle === "M4" || M && p.spindle === null) ? !1 : p.spindleSpeed === null ? !0 : p.spindleSpeed > 0;
444
444
  if (s) {
445
- const m = new L({
446
- onLinearMove: (x) => {
447
- if (!l(x.modals))
445
+ const p = new I({
446
+ onLinearMove: (y) => {
447
+ if (!l(y.modals))
448
448
  return;
449
- const v = x.modals.spindleSpeed;
449
+ const v = y.modals.spindleSpeed;
450
450
  v === null || v <= 0 || (d = Math.max(d, v));
451
451
  },
452
- onArcMove: (x) => {
453
- if (!l(x.modals))
452
+ onArcMove: (y) => {
453
+ if (!l(y.modals))
454
454
  return;
455
- const v = x.modals.spindleSpeed;
455
+ const v = y.modals.spindleSpeed;
456
456
  v === null || v <= 0 || (d = Math.max(d, v));
457
457
  }
458
458
  });
459
- for (let x = 0; x < o.length; x += 1) {
459
+ for (let y = 0; y < n.length; y += 1) {
460
460
  if ((S = r == null ? void 0 : r.shouldAbort) != null && S.call(r))
461
461
  throw new Error("Aborted.");
462
- const v = o[x];
463
- v && m.processLine(v);
464
- const P = x + 1;
462
+ const v = n[y];
463
+ v && p.processLine(v);
464
+ const P = y + 1;
465
465
  r != null && r.onProgress && (P === i || P === u) && (r.onProgress(P, i), u += a), c > 0 && (P === i || P === f) && (await new Promise((E) => {
466
466
  setTimeout(E, 0);
467
467
  }), f += c);
@@ -469,71 +469,71 @@ async function D(o, t = {}) {
469
469
  Number.isFinite(d) || (d = 0);
470
470
  } else
471
471
  d = 0;
472
- const h = (m) => {
473
- if (e <= 1)
472
+ const m = (p) => {
473
+ if (t <= 1)
474
474
  return 0;
475
- if (m === null)
476
- return e - 1;
477
- const x = m;
478
- if (x <= 0)
475
+ if (p === null)
476
+ return t - 1;
477
+ const y = p;
478
+ if (y <= 0)
479
479
  return 0;
480
480
  if (d <= 0)
481
- return e - 1;
482
- const v = Math.min(1, Math.max(0, x / d)), P = 1 + Math.floor(v * (e - 2));
483
- return Math.min(e - 1, Math.max(1, P));
484
- }, M = [], A = s ? Array.from({ length: e }, () => []) : [new Array()], G = new Int32Array(o.length), p = Array.from(
485
- { length: s ? e : 1 },
486
- () => new Int32Array(o.length)
487
- ), w = new L({
488
- onLinearMove: (m) => {
489
- const x = m.transformedStart ?? m.start, v = m.transformedEnd ?? m.end;
490
- if (m.modals.motion === "G0") {
491
- M.push(x.X, x.Y, x.Z, v.X, v.Y, v.Z);
481
+ return t - 1;
482
+ const v = Math.min(1, Math.max(0, y / d)), P = 1 + Math.floor(v * (t - 2));
483
+ return Math.min(t - 1, Math.max(1, P));
484
+ }, A = [], x = s ? Array.from({ length: t }, () => []) : [new Array()], w = new Int32Array(n.length), h = Array.from(
485
+ { length: s ? t : 1 },
486
+ () => new Int32Array(n.length)
487
+ ), G = new I({
488
+ onLinearMove: (p) => {
489
+ const y = p.transformedStart ?? p.start, v = p.transformedEnd ?? p.end;
490
+ if (p.modals.motion === "G0") {
491
+ A.push(y.X, y.Y, y.Z, v.X, v.Y, v.Z);
492
492
  return;
493
493
  }
494
- if (s && !l(m.modals))
494
+ if (s && !l(p.modals))
495
495
  return;
496
- const P = s ? h(m.modals.spindleSpeed) : 0;
497
- A[P].push(x.X, x.Y, x.Z, v.X, v.Y, v.Z);
496
+ const P = s ? m(p.modals.spindleSpeed) : 0;
497
+ x[P].push(y.X, y.Y, y.Z, v.X, v.Y, v.Z);
498
498
  },
499
- onArcMove: (m) => {
500
- if (m.modals.motion === "G0" || s && !l(m.modals))
499
+ onArcMove: (p) => {
500
+ if (p.modals.motion === "G0" || s && !l(p.modals))
501
501
  return;
502
- const x = s ? h(m.modals.spindleSpeed) : 0, v = A[x];
503
- g(m, v, n);
502
+ const y = s ? m(p.modals.spindleSpeed) : 0, v = x[y];
503
+ g(p, v, o);
504
504
  }
505
505
  });
506
- for (let m = 0; m < o.length; m += 1) {
507
- if ((I = r == null ? void 0 : r.shouldAbort) != null && I.call(r))
506
+ for (let p = 0; p < n.length; p += 1) {
507
+ if ((L = r == null ? void 0 : r.shouldAbort) != null && L.call(r))
508
508
  throw new Error("Aborted.");
509
- const x = o[m];
510
- x && w.processLine(x), G[m] = M.length / 3;
511
- for (let P = 0; P < A.length; P += 1)
512
- p[P][m] = A[P].length / 3;
513
- const v = s ? o.length + m + 1 : m + 1;
509
+ const y = n[p];
510
+ y && G.processLine(y), w[p] = A.length / 3;
511
+ for (let P = 0; P < x.length; P += 1)
512
+ h[P][p] = x[P].length / 3;
513
+ const v = s ? n.length + p + 1 : p + 1;
514
514
  r != null && r.onProgress && (v === i || v === u) && (r.onProgress(v, i), u += a), c > 0 && (v === i || v === f) && (await new Promise((P) => {
515
515
  setTimeout(P, 0);
516
516
  }), f += c);
517
517
  }
518
518
  return {
519
- rapid: { positions: Float32Array.from(M), prefixEndVertex: G },
520
- cuts: A.map((m, x) => ({
521
- positions: Float32Array.from(m),
522
- prefixEndVertex: p[x]
519
+ rapid: { positions: Float32Array.from(A), prefixEndVertex: w },
520
+ cuts: x.map((p, y) => ({
521
+ positions: Float32Array.from(p),
522
+ prefixEndVertex: h[y]
523
523
  })),
524
- cutBucketCount: A.length,
524
+ cutBucketCount: x.length,
525
525
  minPower: 0,
526
526
  maxPower: d
527
527
  };
528
528
  }
529
- async function K(o, t = {}) {
530
- const n = Math.max(1, Math.floor(t.bucketCount ?? 16)), e = t.baseOpacity ?? 0.9, s = await D(o, {
531
- arcSegments: t.arcSegments,
532
- bucketCount: n,
529
+ async function K(n, e = {}) {
530
+ const o = Math.max(1, Math.floor(e.bucketCount ?? 16)), t = e.baseOpacity ?? 0.9, s = await D(n, {
531
+ arcSegments: e.arcSegments,
532
+ bucketCount: o,
533
533
  laserMode: !0,
534
- batch: t.batch
534
+ batch: e.batch
535
535
  }), r = s.cuts.map((i, a) => ({
536
- opacity: O(a, n, e),
536
+ opacity: O(a, o, t),
537
537
  positions: i.positions,
538
538
  prefixEndVertex: i.prefixEndVertex
539
539
  }));
@@ -545,111 +545,111 @@ async function K(o, t = {}) {
545
545
  maxPower: s.maxPower
546
546
  };
547
547
  }
548
- function ce(o, t) {
549
- o.push(t.X, t.Y, t.Z);
548
+ function ce(n, e) {
549
+ n.push(e.X, e.Y, e.Z);
550
550
  }
551
- function z(o, t) {
552
- const n = o.transformedStart ?? o.start, e = o.transformedEnd ?? o.end;
553
- t.push(n.X, n.Y, n.Z, e.X, e.Y, e.Z);
551
+ function z(n, e) {
552
+ const o = n.transformedStart ?? n.start, t = n.transformedEnd ?? n.end;
553
+ e.push(o.X, o.Y, o.Z, t.X, t.Y, t.Z);
554
554
  }
555
- function g(o, t, n) {
556
- const e = Math.max(1, Math.floor(n)), { primary: s, secondary: r } = H(o.plane), i = J(
557
- o.start[s],
558
- o.start[r],
559
- o.center[s],
560
- o.center[r]
555
+ function g(n, e, o) {
556
+ const t = Math.max(1, Math.floor(o)), { primary: s, secondary: r } = H(n.plane), i = J(
557
+ n.start[s],
558
+ n.start[r],
559
+ n.center[s],
560
+ n.center[r]
561
561
  ), a = Math.atan2(
562
- o.start[r] - o.center[r],
563
- o.start[s] - o.center[s]
562
+ n.start[r] - n.center[r],
563
+ n.start[s] - n.center[s]
564
564
  ), c = Math.atan2(
565
- o.end[r] - o.center[r],
566
- o.end[s] - o.center[s]
565
+ n.end[r] - n.center[r],
566
+ n.end[s] - n.center[s]
567
567
  ), u = Math.PI * 2;
568
568
  let f = k(a), d = k(c);
569
- o.motion === "G2" ? f <= d && (f += u) : d <= f && (d += u);
570
- const y = o.motion === "G2" ? f - d : d - f;
571
- let l = { ...o.start };
572
- for (let h = 1; h <= e; h += 1) {
573
- const M = h / e, A = o.motion === "G2" ? f - y * M : f + y * M, G = Q(o.start, o.end, M);
574
- G[s] = o.center[s] + i * Math.cos(A), G[r] = o.center[r] + i * Math.sin(A);
575
- const p = T(l), w = T(G);
576
- t.push(
577
- p.X,
578
- p.Y,
579
- p.Z,
580
- w.X,
581
- w.Y,
582
- w.Z
583
- ), l = G;
569
+ n.motion === "G2" ? f <= d && (f += u) : d <= f && (d += u);
570
+ const M = n.motion === "G2" ? f - d : d - f;
571
+ let l = { ...n.start };
572
+ for (let m = 1; m <= t; m += 1) {
573
+ const A = m / t, x = n.motion === "G2" ? f - M * A : f + M * A, w = Q(n.start, n.end, A);
574
+ w[s] = n.center[s] + i * Math.cos(x), w[r] = n.center[r] + i * Math.sin(x);
575
+ const h = T(l), G = T(w);
576
+ e.push(
577
+ h.X,
578
+ h.Y,
579
+ h.Z,
580
+ G.X,
581
+ G.Y,
582
+ G.Z
583
+ ), l = w;
584
584
  }
585
585
  }
586
- function T(o) {
587
- const t = o.A * Math.PI / 180, n = Math.cos(t), e = Math.sin(t), s = o.Y * n - o.Z * e, r = o.Y * e + o.Z * n;
588
- return { ...o, Y: s, Z: r };
586
+ function T(n) {
587
+ const e = n.A * Math.PI / 180, o = Math.cos(e), t = Math.sin(e), s = n.Y * o - n.Z * t, r = n.Y * t + n.Z * o;
588
+ return { ...n, Y: s, Z: r };
589
589
  }
590
- function H(o) {
591
- return o === "G18" ? { primary: "Z", secondary: "X" } : o === "G19" ? { primary: "Y", secondary: "Z" } : { primary: "X", secondary: "Y" };
590
+ function H(n) {
591
+ return n === "G18" ? { primary: "Z", secondary: "X" } : n === "G19" ? { primary: "Y", secondary: "Z" } : { primary: "X", secondary: "Y" };
592
592
  }
593
- function k(o) {
594
- const t = Math.PI * 2;
595
- let n = o % t;
596
- return n < 0 && (n += t), n;
593
+ function k(n) {
594
+ const e = Math.PI * 2;
595
+ let o = n % e;
596
+ return o < 0 && (o += e), o;
597
597
  }
598
- function J(o, t, n, e) {
599
- return Math.hypot(o - n, t - e);
598
+ function J(n, e, o, t) {
599
+ return Math.hypot(n - o, e - t);
600
600
  }
601
- function Q(o, t, n) {
601
+ function Q(n, e, o) {
602
602
  return {
603
- X: o.X + (t.X - o.X) * n,
604
- Y: o.Y + (t.Y - o.Y) * n,
605
- Z: o.Z + (t.Z - o.Z) * n,
606
- A: o.A + (t.A - o.A) * n,
607
- B: o.B + (t.B - o.B) * n,
608
- C: o.C + (t.C - o.C) * n
603
+ X: n.X + (e.X - n.X) * o,
604
+ Y: n.Y + (e.Y - n.Y) * o,
605
+ Z: n.Z + (e.Z - n.Z) * o,
606
+ A: n.A + (e.A - n.A) * o,
607
+ B: n.B + (e.B - n.B) * o,
608
+ C: n.C + (e.C - n.C) * o
609
609
  };
610
610
  }
611
- function ee(o) {
612
- let t = Number.POSITIVE_INFINITY, n = Number.NEGATIVE_INFINITY;
613
- const e = new L({
611
+ function ee(n) {
612
+ let e = Number.POSITIVE_INFINITY, o = Number.NEGATIVE_INFINITY;
613
+ const t = new I({
614
614
  onLinearMove: (s) => {
615
615
  const r = s.modals.spindleSpeed;
616
- r !== null && (t = Math.min(t, r), n = Math.max(n, r));
616
+ r !== null && (e = Math.min(e, r), o = Math.max(o, r));
617
617
  },
618
618
  onArcMove: (s) => {
619
619
  const r = s.modals.spindleSpeed;
620
- r !== null && (t = Math.min(t, r), n = Math.max(n, r));
620
+ r !== null && (e = Math.min(e, r), o = Math.max(o, r));
621
621
  }
622
622
  });
623
- for (const s of o)
624
- s && e.processLine(s);
625
- return !Number.isFinite(t) || !Number.isFinite(n) ? { minPower: 0, maxPower: 0 } : { minPower: t, maxPower: n };
623
+ for (const s of n)
624
+ s && t.processLine(s);
625
+ return !Number.isFinite(e) || !Number.isFinite(o) ? { minPower: 0, maxPower: 0 } : { minPower: e, maxPower: o };
626
626
  }
627
- function B(o, t, n, e) {
628
- if (e <= 1)
627
+ function B(n, e, o, t) {
628
+ if (t <= 1)
629
629
  return 0;
630
- const s = o ?? t;
631
- if (n <= t)
632
- return e - 1;
633
- const r = (s - t) / (n - t), i = Math.floor(r * (e - 1));
634
- return Math.min(e - 1, Math.max(0, i));
630
+ const s = n ?? e;
631
+ if (o <= e)
632
+ return t - 1;
633
+ const r = (s - e) / (o - e), i = Math.floor(r * (t - 1));
634
+ return Math.min(t - 1, Math.max(0, i));
635
635
  }
636
- function O(o, t, n) {
637
- if (t <= 1)
638
- return n;
639
- const e = o / (t - 1);
640
- return n * e;
636
+ function O(n, e, o) {
637
+ if (e <= 1)
638
+ return o;
639
+ const t = n / (e - 1);
640
+ return o * t;
641
641
  }
642
- function le(o) {
643
- const t = new Float32Array(o.vertices), n = new Uint32Array(o.frames), e = new Float32Array(o.colorArrayBuffer), { verticesLen: s, framesLen: r } = o, i = /* @__PURE__ */ new Map();
642
+ function le(n) {
643
+ const e = new Float32Array(n.vertices), o = new Uint32Array(n.frames), t = new Float32Array(n.colorArrayBuffer), { verticesLen: s, framesLen: r } = n, 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 / 3;
645
+ const c = o[a], u = a < r - 1 ? o[a + 1] : s / 3;
646
646
  if (u <= c + 1) continue;
647
- const f = c * 4, d = e[f], y = e[f + 1], l = e[f + 2], h = e[f + 3], M = te(d, y, l), A = `${M}|${Math.round(h * 100)}`;
648
- let G = i.get(A);
649
- G || (G = { hexColor: M, opacity: h, pos: [], rgb: [] }, i.set(A, G));
650
- for (let p = c; p < u - 1; p++) {
651
- const w = p * 3, S = (p + 1) * 3;
652
- G.pos.push(t[w], t[w + 1], t[w + 2], t[S], t[S + 1], t[S + 2]), G.rgb.push(d, y, l, d, y, l);
647
+ const f = c * 4, d = t[f], M = t[f + 1], l = t[f + 2], m = t[f + 3], A = te(d, M, l), x = `${A}|${Math.round(m * 100)}`;
648
+ let w = i.get(x);
649
+ w || (w = { hexColor: A, opacity: m, pos: [], rgb: [] }, i.set(x, w));
650
+ for (let h = c; h < u - 1; h++) {
651
+ const G = h * 3, S = (h + 1) * 3;
652
+ w.pos.push(e[G], e[G + 1], e[G + 2], e[S], e[S + 1], e[S + 2]), w.rgb.push(d, M, l, d, M, l);
653
653
  }
654
654
  }
655
655
  return Array.from(i.values()).map(({ hexColor: a, opacity: c, pos: u, rgb: f }) => ({
@@ -659,41 +659,41 @@ function le(o) {
659
659
  rgbColors: new Float32Array(f)
660
660
  }));
661
661
  }
662
- function te(o, t, n) {
663
- const e = (s) => Math.round(Math.min(1, Math.max(0, s)) * 255).toString(16).padStart(2, "0");
664
- return `#${e(o)}${e(t)}${e(n)}`;
665
- }
666
- function de(o) {
667
- const t = new Float32Array(o.vertices), n = new Uint32Array(o.frames), e = new Float32Array(o.colorArrayBuffer), { verticesLen: s, framesLen: r } = o, i = [], a = [], c = [], u = [], f = new Int32Array(r), d = new Int32Array(r);
668
- for (let y = 0; y < r; y++) {
669
- const l = n[y], h = y < r - 1 ? n[y + 1] : s / 3;
670
- if (h > l + 1) {
671
- const M = e[l * 4 + 3] < 0.75, A = M ? i : c, G = M ? a : u;
672
- for (let p = l; p < h - 1; p++) {
673
- const w = p * 3, S = (p + 1) * 3;
674
- A.push(t[w], t[w + 1], t[w + 2], t[S], t[S + 1], t[S + 2]);
675
- const I = p * 4, m = (p + 1) * 4;
676
- G.push(e[I], e[I + 1], e[I + 2], e[m], e[m + 1], e[m + 2]);
662
+ function te(n, e, o) {
663
+ const t = (s) => Math.round(Math.min(1, Math.max(0, s)) * 255).toString(16).padStart(2, "0");
664
+ return `#${t(n)}${t(e)}${t(o)}`;
665
+ }
666
+ function de(n) {
667
+ const e = new Float32Array(n.vertices), o = new Uint32Array(n.frames), t = new Float32Array(n.colorArrayBuffer), r = (n.isLaser && n.savedColorsBuffer && n.savedColorLen ? new Float32Array(n.savedColorsBuffer) : null) ?? t, { verticesLen: i, framesLen: a } = n, c = [], u = [], f = [], d = [], M = new Int32Array(a), l = new Int32Array(a);
668
+ for (let m = 0; m < a; m++) {
669
+ const A = o[m], x = m < a - 1 ? o[m + 1] : i / 3;
670
+ if (x > A + 1) {
671
+ const w = t[A * 4 + 3] < 0.75, h = w ? c : f, G = w ? u : d;
672
+ for (let S = A; S < x - 1; S++) {
673
+ const L = S * 3, p = (S + 1) * 3;
674
+ h.push(e[L], e[L + 1], e[L + 2], e[p], e[p + 1], e[p + 2]);
675
+ const y = S * 4, v = (S + 1) * 4;
676
+ G.push(r[y], r[y + 1], r[y + 2], r[v], r[v + 1], r[v + 2]);
677
677
  }
678
678
  }
679
- f[y] = i.length / 3, d[y] = c.length / 3;
679
+ M[m] = c.length / 3, l[m] = f.length / 3;
680
680
  }
681
681
  return {
682
682
  rapid: {
683
- positions: Float32Array.from(i),
684
- colors: Float32Array.from(a),
685
- prefixEndVertex: f
686
- },
687
- cut: {
688
683
  positions: Float32Array.from(c),
689
684
  colors: Float32Array.from(u),
690
- prefixEndVertex: d
685
+ prefixEndVertex: M
686
+ },
687
+ cut: {
688
+ positions: Float32Array.from(f),
689
+ colors: Float32Array.from(d),
690
+ prefixEndVertex: l
691
691
  }
692
692
  };
693
693
  }
694
694
  export {
695
695
  R as GCodeParser,
696
- L as GCodeVirtualizer,
696
+ I as GCodeVirtualizer,
697
697
  K as buildLaserGeometryFromLinesBatched,
698
698
  ie as buildLaserVerticesFromLines,
699
699
  ae as buildLaserVerticesFromLinesBatched,