@sienci/gviewer 0.1.29 → 0.1.32

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