three-slicer-viewer 0.3.0 → 0.3.2

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.
@@ -0,0 +1,327 @@
1
+ import { unzip as Y, unzipSync as H } from "three/examples/jsm/libs/fflate.module.js";
2
+ import { S as W } from "./viewer_defaults-B7UUZ582.js";
3
+ function q(t) {
4
+ return new Promise((o) => {
5
+ let s = !1;
6
+ const e = (r) => {
7
+ s || (s = !0, o(r));
8
+ };
9
+ try {
10
+ Y(t, (r, i) => e(r ? H(t) : i));
11
+ } catch {
12
+ e(H(t));
13
+ }
14
+ });
15
+ }
16
+ const L = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0];
17
+ function K(t, o) {
18
+ const s = new Array(12);
19
+ for (let e = 0; e < 4; e++)
20
+ for (let r = 0; r < 3; r++)
21
+ s[e * 3 + r] = t[e * 3] * o[r] + t[e * 3 + 1] * o[3 + r] + t[e * 3 + 2] * o[6 + r] + (e === 3 ? o[9 + r] : 0);
22
+ return s;
23
+ }
24
+ function U(t) {
25
+ if (!t) return L;
26
+ const o = t.trim().split(/\s+/).map(Number);
27
+ return o.length === 12 && o.every(Number.isFinite) ? o : L;
28
+ }
29
+ const x = {};
30
+ function f(t, o) {
31
+ const e = (x[o] || (x[o] = new RegExp(`\\b${o}\\s*=\\s*"([^"]*)"`))).exec(t);
32
+ return e ? e[1] : null;
33
+ }
34
+ const B = /<vertex\s+x="([^"]*)"\s+y="([^"]*)"\s+z="([^"]*)"/g, D = /<triangle\s+v1="([^"]*)"\s+v2="([^"]*)"\s+v3="([^"]*)"([^>]*)/g, C = [
35
+ ["paint_color", "color"],
36
+ // multi-material: state 1..16 == Extruder1..16
37
+ ["paint_supports", "supports"],
38
+ // support enforcer/blocker: states 1 and 2
39
+ ["paint_seam", "seam"],
40
+ // unsupported by the kernel — collected for the warning only
41
+ ["paint_fuzzy_skin", "fuzzy"]
42
+ // ditto
43
+ ];
44
+ function G() {
45
+ return { color: /* @__PURE__ */ new Map(), supports: /* @__PURE__ */ new Map(), seam: /* @__PURE__ */ new Map(), fuzzy: /* @__PURE__ */ new Map() };
46
+ }
47
+ function Q(t) {
48
+ return !t || C.every(([, o]) => t[o].size === 0);
49
+ }
50
+ function J(t, o, s) {
51
+ for (const [e, r] of C) {
52
+ if (!t.includes(e)) continue;
53
+ const i = f(t, e);
54
+ i && s[r].set(o, i);
55
+ }
56
+ }
57
+ function Z(t) {
58
+ const o = [];
59
+ B.lastIndex = 0;
60
+ let s;
61
+ for (; s = B.exec(t); ) o.push(+s[1], +s[2], +s[3]);
62
+ if (!o.length)
63
+ for (const i of t.match(/<vertex\b[^>]*>/g) || []) o.push(+f(i, "x"), +f(i, "y"), +f(i, "z"));
64
+ if (o.length < 9) return null;
65
+ const e = [], r = G();
66
+ for (D.lastIndex = 0; s = D.exec(t); ) {
67
+ const i = e.length / 3;
68
+ e.push(+s[1], +s[2], +s[3]), s[4].length > 2 && J(s[4], i, r);
69
+ }
70
+ if (!e.length)
71
+ for (const i of t.match(/<triangle\b[^>]*>/g) || []) {
72
+ const p = e.length / 3;
73
+ e.push(+f(i, "v1"), +f(i, "v2"), +f(i, "v3")), J(i, p, r);
74
+ }
75
+ return e.length ? { verts: o, tris: e, paint: r } : null;
76
+ }
77
+ function tt(t) {
78
+ const o = /* @__PURE__ */ new Map(), s = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
79
+ let e;
80
+ for (; e = s.exec(t); ) {
81
+ const p = f(e[1], "id");
82
+ if (!p) continue;
83
+ const u = e[2], n = [];
84
+ for (const a of u.match(/<component\b[^>]*>/g) || []) {
85
+ const c = f(a, "objectid");
86
+ c && n.push({ objectid: c, path: f(a, "p:path") || f(a, "path"), transform: U(f(a, "transform")) });
87
+ }
88
+ o.set(p, n.length ? { components: n } : { mesh: Z(u) });
89
+ }
90
+ const r = [], i = /<build\b[^>]*>([\s\S]*?)<\/build>/.exec(t);
91
+ if (i)
92
+ for (const p of i[1].match(/<item\b[^>]*>/g) || []) {
93
+ const u = f(p, "objectid");
94
+ u && r.push({ objectid: u, path: f(p, "p:path") || f(p, "path"), transform: U(f(p, "transform")) });
95
+ }
96
+ return { objects: o, items: r };
97
+ }
98
+ function k(t) {
99
+ const o = String(t).replace(/^\/+/, "");
100
+ return o.includes("%") ? decodeURIComponent(o) : o;
101
+ }
102
+ function R(t) {
103
+ const o = {};
104
+ for (const s of t.match(/<metadata\b[^>]*>/g) || []) {
105
+ const e = f(s, "key");
106
+ e && (o[e] = f(s, "value") ?? "");
107
+ }
108
+ return o;
109
+ }
110
+ function et(t) {
111
+ const o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), e = /<object\b([^>]*)>([\s\S]*?)<\/object>/g;
112
+ let r;
113
+ for (; r = e.exec(t); ) {
114
+ const u = f(r[1], "id");
115
+ if (u) {
116
+ const n = r[2];
117
+ o.set(u, R(n.replace(/<(?:part|volume)\b[\s\S]*?<\/(?:part|volume)>/g, "")));
118
+ const a = [];
119
+ for (const c of n.match(/<volume\b[\s\S]*?<\/volume>/g) || []) {
120
+ const d = R(c).volume_type, y = d === "SupportBlocker" ? "blocker" : d === "SupportEnforcer" ? "enforcer" : null, _ = Number(f(c, "firstid")), S = Number(f(c, "lastid"));
121
+ y && Number.isInteger(_) && Number.isInteger(S) && _ >= 0 && S >= _ && a.push({ firstTriangle: _, lastTriangle: S, kind: y });
122
+ }
123
+ a.length && s.set(u, a);
124
+ }
125
+ }
126
+ const i = [], p = /<plate\b[^>]*>([\s\S]*?)<\/plate>/g;
127
+ for (; r = p.exec(t); ) {
128
+ const u = r[1], n = R(u.replace(/<model_instance\b[\s\S]*?<\/model_instance>/g, "")), a = [];
129
+ for (const c of u.match(/<model_instance\b[\s\S]*?<\/model_instance>/g) || []) {
130
+ const d = R(c).object_id;
131
+ d && a.push(d);
132
+ }
133
+ i.push({ index: Math.max(0, (Number(n.plater_id) || i.length + 1) - 1), objectIds: a, gcodeFile: n.gcode_file || null });
134
+ }
135
+ return { objects: o, plates: i, volumes: s };
136
+ }
137
+ const nt = Object.freeze({
138
+ manualSupportPoints: "prepared-roundtrip",
139
+ drainHoles: "preserved-unsupported",
140
+ modifierVolumes: "prepared-mask-filtering",
141
+ uiEditing: "unavailable"
142
+ });
143
+ function V(t, o, s, e, r) {
144
+ const i = /* @__PURE__ */ new Map();
145
+ if (!t?.trim()) return i;
146
+ const p = t.trim().split(/\r?\n/), u = new RegExp(`^${o}_format_version=(\\d+)$`).exec(p[0]), n = u ? Number(u[1]) : 0;
147
+ for (const a of p.slice(u ? 1 : 0)) {
148
+ const c = /^object_id=(\d+)\|(.*)$/.exec(a);
149
+ if (!c || i.has(Number(c?.[1]))) continue;
150
+ const d = Number(c[1]), y = c[2].trim() ? c[2].trim().split(/\s+/).map(Number) : [], _ = s(n);
151
+ if (!_ || y.length % _ !== 0 || y.some((l) => !Number.isFinite(l))) {
152
+ e.push({ code: o === "support_points" ? "SLA_SUPPORT_POINT_COUNT" : "SLA_DRAIN_HOLE_COUNT", object: d }), i.set(d, []);
153
+ continue;
154
+ }
155
+ const S = [];
156
+ for (let l = 0; l < y.length; l += _) S.push(r(y.slice(l, l + _), n));
157
+ i.set(d, S);
158
+ }
159
+ return i;
160
+ }
161
+ function X(t, o) {
162
+ const [s, e, r] = o;
163
+ return [s * t[0] + e * t[3] + r * t[6] + t[9], s * t[1] + e * t[4] + r * t[7] + t[10], s * t[2] + e * t[5] + r * t[8] + t[11]];
164
+ }
165
+ function ot(t, o) {
166
+ const [s, e, r] = o, i = [s * t[0] + e * t[3] + r * t[6], s * t[1] + e * t[4] + r * t[7], s * t[2] + e * t[5] + r * t[8]], p = Math.hypot(...i);
167
+ return p ? i.map((u) => u / p) : i;
168
+ }
169
+ function st(t, o) {
170
+ const s = (n) => {
171
+ const a = t.get(n);
172
+ return a ? o.decode(a) : null;
173
+ }, e = {
174
+ settings: null,
175
+ // Metadata/project_settings.config — the flattened preset (raw upstream strings)
176
+ objectMeta: /* @__PURE__ */ new Map(),
177
+ // 3mf object id -> per-object metadata (name, extruder, per-object overrides)
178
+ plates: [],
179
+ // [{index, objectIds}]
180
+ hasLayerHeightProfile: !1,
181
+ hasCustomGcodePerLayer: !1,
182
+ volumeMeta: /* @__PURE__ */ new Map(),
183
+ sla: { capabilities: { ...nt }, issues: [], supportPoints: /* @__PURE__ */ new Map(), drainHoles: /* @__PURE__ */ new Map() },
184
+ viewerSettings: null,
185
+ // Metadata/three_slicer_settings.json — this package's own member (write_3mf.js)
186
+ plateSettings: null,
187
+ // ...its two halves: global viewer knobs, and per-plate overrides keyed by plate index
188
+ plateCount: null,
189
+ // ...and the plate count it was saved with (empty plates hold no <plate> record)
190
+ gcodePlates: null
191
+ // a .gcode.3mf's sliced plates: [{index, gcode}] (write_3mf.js writeGcode3MF), else null
192
+ }, r = s("Metadata/project_settings.config");
193
+ if (r)
194
+ try {
195
+ e.settings = JSON.parse(r);
196
+ } catch {
197
+ e.settings = null;
198
+ }
199
+ const i = s("Metadata/three_slicer_settings.json");
200
+ if (i) {
201
+ let n = null;
202
+ try {
203
+ n = JSON.parse(i);
204
+ } catch {
205
+ n = null;
206
+ }
207
+ const a = (c) => c && typeof c == "object" && !Array.isArray(c);
208
+ if (a(n)) {
209
+ a(n.viewer) && Object.keys(n.viewer).length && (e.viewerSettings = n.viewer);
210
+ let c = [];
211
+ a(n.plates) && (c = Object.entries(n.plates));
212
+ const d = c.filter(([y, _]) => /^\d+$/.test(y) && a(_) && Object.keys(_).length);
213
+ d.length && (e.plateSettings = Object.fromEntries(d.map(([y, _]) => [Number(y), _]))), Number.isInteger(n.plateCount) && n.plateCount >= 1 && (e.plateCount = n.plateCount);
214
+ }
215
+ }
216
+ const p = s("Metadata/model_settings.config");
217
+ if (p) {
218
+ const n = et(p);
219
+ e.objectMeta = n.objects, e.plates = n.plates, e.volumeMeta = n.volumes;
220
+ }
221
+ const u = e.plates.map((n) => ({ index: n.index, gcode: n.gcodeFile && s(k(n.gcodeFile)) })).filter((n) => n.gcode);
222
+ return u.length && (e.gcodePlates = u), e.sla.supportPoints = V(
223
+ s("Metadata/Slic3r_PE_sla_support_points.txt"),
224
+ "support_points",
225
+ (n) => n === 0 ? 3 : n === 1 ? 5 : 0,
226
+ e.sla.issues,
227
+ (n, a) => ({
228
+ position: n.slice(0, 3),
229
+ radius: a === 0 ? W : n[3],
230
+ type: a === 0 || n[4] === 2 ? "manual" : n[4] === 1 ? "island" : "slope"
231
+ })
232
+ ), e.sla.drainHoles = V(
233
+ s("Metadata/Slic3r_PE_sla_drain_holes.txt"),
234
+ "drain_holes",
235
+ (n) => n === 1 ? 8 : 0,
236
+ e.sla.issues,
237
+ (n) => {
238
+ const a = Math.hypot(n[3], n[4], n[5]), c = a ? n.slice(3, 6).map((d) => d / a) : n.slice(3, 6);
239
+ return { position: n.slice(0, 3).map((d, y) => d + c[y]), normal: c, radius: n[6], height: n[7] - 1 };
240
+ }
241
+ ), e.hasLayerHeightProfile = !!s("Metadata/layer_heights_profile.txt")?.trim(), e.hasCustomGcodePerLayer = !!s("Metadata/custom_gcode_per_layer.xml")?.trim(), e;
242
+ }
243
+ async function ct(t, o = "model") {
244
+ const s = ArrayBuffer.isView(t) ? new Uint8Array(t.buffer, t.byteOffset, t.byteLength) : new Uint8Array(t), e = await q(s), r = /* @__PURE__ */ new Map();
245
+ for (const l of Object.keys(e)) r.set(k(l), e[l]);
246
+ const i = new TextDecoder(), p = /* @__PURE__ */ new Map(), u = (l) => {
247
+ const w = k(l);
248
+ if (p.has(w)) return p.get(w);
249
+ const m = r.get(w), M = m ? tt(i.decode(m)) : null;
250
+ return p.set(w, M), M;
251
+ };
252
+ let n = "3D/3dmodel.model";
253
+ const a = r.get("_rels/.rels");
254
+ if (a) {
255
+ for (const l of i.decode(a).match(/<Relationship\b[^>]*>/g) || [])
256
+ if ((f(l, "Type") || "").endsWith("/3dmodel")) {
257
+ n = k(f(l, "Target"));
258
+ break;
259
+ }
260
+ }
261
+ const c = st(r, i), d = u(n);
262
+ if (!d && c.gcodePlates) return { objects: [], project: c };
263
+ if (!d) throw new Error(`3MF root model not found: ${n}`);
264
+ const y = [], _ = (l, w, m, M, P, N) => {
265
+ if (N > 16) return;
266
+ const T = u(w)?.objects.get(l);
267
+ if (!T) return;
268
+ if (T.components) {
269
+ for (const j of T.components) _(j.objectid, j.path || w, K(j.transform, m), M, P, N + 1);
270
+ return;
271
+ }
272
+ if (!T.mesh) return;
273
+ const { verts: E, tris: I, paint: v } = T.mesh, z = M.length / 9;
274
+ for (let j = 0; j < I.length; j++) {
275
+ const h = I[j] * 3, b = E[h], g = E[h + 1], A = E[h + 2];
276
+ M.push(
277
+ b * m[0] + g * m[3] + A * m[6] + m[9],
278
+ b * m[1] + g * m[4] + A * m[7] + m[10],
279
+ b * m[2] + g * m[5] + A * m[8] + m[11]
280
+ );
281
+ }
282
+ if (v) for (const [, j] of C)
283
+ for (const [h, b] of v[j]) P[j].set(z + h, b);
284
+ }, S = d.items.length ? d.items : [...d.objects.keys()].filter((l) => d.objects.get(l).mesh).map((l) => ({ objectid: l, path: n, transform: L }));
285
+ return S.forEach((l, w) => {
286
+ const m = [], M = G();
287
+ if (_(l.objectid, l.path || n, l.transform, m, M, 0), m.length < 9) return;
288
+ let P = new Float32Array(m);
289
+ const N = [], O = c.volumeMeta.get(l.objectid) || [];
290
+ if (O.length) {
291
+ const h = /* @__PURE__ */ new Set();
292
+ for (let b = 0; b < O.length; b++) {
293
+ const g = O[b], A = g.firstTriangle * 9, $ = Math.min(m.length, (g.lastTriangle + 1) * 9);
294
+ if (!(A >= $)) {
295
+ for (let F = g.firstTriangle; F <= g.lastTriangle; F++) h.add(F);
296
+ N.push({ id: `${l.objectid}:modifier:${b}`, kind: g.kind, tris: new Float32Array(m.slice(A, $)) });
297
+ }
298
+ }
299
+ if (h.size) {
300
+ const b = [];
301
+ for (let g = 0; g < m.length / 9; g++) h.has(g) || b.push(...m.slice(g * 9, g * 9 + 9));
302
+ P = new Float32Array(b);
303
+ }
304
+ }
305
+ const T = (c.sla.supportPoints.get(w + 1) || []).map((h) => ({ ...h, position: X(l.transform, h.position) })), E = (c.sla.drainHoles.get(w + 1) || []).map((h) => ({
306
+ ...h,
307
+ position: X(l.transform, h.position),
308
+ normal: ot(l.transform, h.normal)
309
+ }));
310
+ let I = 1 / 0, v = 1 / 0, z = -1 / 0, j = -1 / 0;
311
+ for (let h = 0; h < P.length; h += 3) {
312
+ const b = P[h], g = P[h + 1];
313
+ b < I && (I = b), b > z && (z = b), g < v && (v = g), g > j && (j = g);
314
+ }
315
+ y.push({
316
+ name: S.length > 1 ? `${o}#${w + 1}` : o,
317
+ tris: P,
318
+ objectid: l.objectid,
319
+ paint: Q(M) ? null : M,
320
+ sla: { supportPoints: T, drainHoles: E, modifierVolumes: N },
321
+ bbox: { minX: I, minY: v, maxX: z, maxY: j }
322
+ });
323
+ }), { objects: y, project: c };
324
+ }
325
+ export {
326
+ ct as p
327
+ };
@@ -1,4 +1,4 @@
1
- import { p as f } from "./parse_3mf-CQ5rAX6P.js";
1
+ import { p as f } from "./parse_3mf-BZISF3eW.js";
2
2
  self.onmessage = async (a) => {
3
3
  const { id: s, buffer: r, baseName: t } = a.data || {};
4
4
  try {
@@ -0,0 +1,16 @@
1
+ import d, { useRef as l, useState as u, useLayoutEffect as i } from "react";
2
+ import { createPortal as f } from "react-dom";
3
+ function h({ css: s, className: c, children: r }) {
4
+ const a = l(null), [o] = u(() => {
5
+ const t = document.createElement("div");
6
+ return t.style.display = "contents", t;
7
+ });
8
+ return i(() => {
9
+ const t = a.current, n = t.shadowRoot || t.attachShadow({ mode: "open" });
10
+ let e = n.querySelector("style[data-ts-css]");
11
+ e || (e = document.createElement("style"), e.setAttribute("data-ts-css", ""), n.append(e)), e.textContent = s, n.contains(o) || n.append(o);
12
+ }, [s, o]), /* @__PURE__ */ d.createElement("div", { ref: a, className: c }, f(r, o));
13
+ }
14
+ export {
15
+ h as S
16
+ };
@@ -1,5 +1,5 @@
1
1
  import { zlibSync as p } from "three/examples/jsm/libs/fflate.module.js";
2
- import { s as m, r as l, e as g } from "./sl1_write-CvrNejbW.js";
2
+ import { s as m, r as l, e as g } from "./sl1_write-BovHbg3k.js";
3
3
  self.onmessage = async ({ data: { indices: r, paths: o, params: t, aa: f } }) => {
4
4
  const a = m(t), e = [];
5
5
  for (let s = 0; s < r.length; s++) {
@@ -1,29 +1,30 @@
1
- import { strToU8 as V, zipSync as I, zlibSync as z } from "three/examples/jsm/libs/fflate.module.js";
2
- let $ = !0;
3
- function it(t) {
4
- $ = !!t;
1
+ import { strToU8 as V, zipSync as z, zlibSync as j } from "three/examples/jsm/libs/fflate.module.js";
2
+ import { S as A, r as X, R as C } from "./toolpath_encoding-BuYs95qZ.js";
3
+ let M = !0;
4
+ function ft(t) {
5
+ M = !!t;
5
6
  }
6
- const O = {
7
+ const Y = {
7
8
  info: (...t) => {
8
- $ && console.info(...t);
9
+ M && console.info(...t);
9
10
  },
10
11
  warn: (...t) => {
11
- $ && console.warn(...t);
12
+ M && console.warn(...t);
12
13
  },
13
14
  error: (...t) => {
14
- $ && console.error(...t);
15
+ M && console.error(...t);
15
16
  }
16
17
  };
17
- function j(t) {
18
+ function G(t) {
18
19
  const e = [];
19
20
  let n = null;
20
- for (let r = 0; r < t.length; r += 8) {
21
+ for (let r = 0; r < t.length; r += A) {
21
22
  const a = t[r], f = t[r + 1], c = t[r + 4], s = t[r + 5];
22
23
  n && Math.abs(n.lx - a) < 1e-6 && Math.abs(n.ly - f) < 1e-6 ? (n.pts.push(c, s), n.lx = c, n.ly = s) : (n = { pts: [a, f, c, s], lx: c, ly: s }, e.push(n));
23
24
  }
24
25
  return e.map((r) => r.pts);
25
26
  }
26
- function R(t, e, n, r, a, f) {
27
+ function L(t, e, n, r, a, f) {
27
28
  const c = new Array(n).fill(null);
28
29
  for (const l of t) {
29
30
  const i = l.length / 2;
@@ -56,10 +57,10 @@ function R(t, e, n, r, a, f) {
56
57
  for (const o of s) o.x += o.dx;
57
58
  }
58
59
  }
59
- function X(t, e, n = 1) {
60
- const { px: r, py: a } = e, f = j(t), c = new Uint8Array(r * a);
60
+ function W(t, e, n = 1) {
61
+ const { px: r, py: a } = e, f = G(t), c = new Uint8Array(r * a);
61
62
  if (n <= 1)
62
- return R(
63
+ return L(
63
64
  f,
64
65
  r,
65
66
  a,
@@ -70,7 +71,7 @@ function X(t, e, n = 1) {
70
71
  }
71
72
  ), c;
72
73
  const s = new Uint16Array(r * a);
73
- R(
74
+ L(
74
75
  f,
75
76
  r * n,
76
77
  a * n,
@@ -85,7 +86,7 @@ function X(t, e, n = 1) {
85
86
  for (let i = 0; i < s.length; i++) c[i] = Math.round(s[i] * 255 / l);
86
87
  return c;
87
88
  }
88
- const Y = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), G = (() => {
89
+ const H = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), Z = (() => {
89
90
  const t = new Uint32Array(256);
90
91
  for (let e = 0; e < 256; e++) {
91
92
  let n = e;
@@ -93,18 +94,18 @@ const Y = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), G = (() => {
93
94
  t[e] = n >>> 0;
94
95
  }
95
96
  return t;
96
- })(), W = (t) => {
97
+ })(), q = (t) => {
97
98
  let e = 4294967295;
98
- for (let n = 0; n < t.length; n++) e = G[(e ^ t[n]) & 255] ^ e >>> 8;
99
+ for (let n = 0; n < t.length; n++) e = Z[(e ^ t[n]) & 255] ^ e >>> 8;
99
100
  return (e ^ 4294967295) >>> 0;
100
- }, E = (t, e) => {
101
+ }, F = (t, e) => {
101
102
  const n = new Uint8Array(12 + e.length), r = new DataView(n.buffer);
102
103
  r.setUint32(0, e.length);
103
104
  for (let f = 0; f < 4; f++) n[4 + f] = t.charCodeAt(f);
104
105
  n.set(e, 8);
105
106
  const a = n.subarray(4, 8 + e.length);
106
- return r.setUint32(8 + e.length, W(a)), n;
107
- }, H = async (t) => {
107
+ return r.setUint32(8 + e.length, q(a)), n;
108
+ }, J = async (t) => {
108
109
  const e = new CompressionStream("deflate"), n = [], r = (async () => {
109
110
  const l = e.readable.getReader();
110
111
  for (; ; ) {
@@ -122,15 +123,15 @@ const Y = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]), G = (() => {
122
123
  c.set(l, s), s += l.length;
123
124
  return c;
124
125
  };
125
- async function Z(t, e, n, r = {}) {
126
+ async function K(t, e, n, r = {}) {
126
127
  if (t.length !== e * n) throw new Error(`gray8: ${t.length} bytes for ${e}x${n}`);
127
128
  const a = new Uint8Array(13), f = new DataView(a.buffer);
128
129
  f.setUint32(0, e), f.setUint32(4, n), a[8] = 8, a[9] = 0;
129
130
  const c = new Uint8Array(n * (1 + e));
130
131
  for (let u = 0; u < n; u++) c.set(t.subarray(u * e, (u + 1) * e), u * (1 + e) + 1);
131
- const s = typeof CompressionStream < "u" ? await H(c) : r.deflate ? r.deflate(c) : (() => {
132
+ const s = typeof CompressionStream < "u" ? await J(c) : r.deflate ? r.deflate(c) : (() => {
132
133
  throw new Error("gray8: no CompressionStream and no deflate fallback injected");
133
- })(), l = [Y, E("IHDR", a), E("IDAT", s), E("IEND", new Uint8Array(0))];
134
+ })(), l = [H, F("IHDR", a), F("IDAT", s), F("IEND", new Uint8Array(0))];
134
135
  let i = 0;
135
136
  for (const u of l) i += u.length;
136
137
  const o = new Uint8Array(i);
@@ -139,7 +140,7 @@ async function Z(t, e, n, r = {}) {
139
140
  o.set(u, d), d += u.length;
140
141
  return o;
141
142
  }
142
- function q(t) {
143
+ function Q(t) {
143
144
  const e = Number(t.display_width) > 0 ? Number(t.display_width) : 120.96, n = Number(t.display_height) > 0 ? Number(t.display_height) : 68.04, r = Number(t.display_pixels_x) > 0 ? Math.round(Number(t.display_pixels_x)) : 2560, a = Number(t.display_pixels_y) > 0 ? Math.round(Number(t.display_pixels_y)) : 1440, f = t.display_mirror_x !== !1, c = t.display_mirror_y === !0, s = (t.display_orientation ?? "portrait") !== "landscape", l = r / e, i = a / n, o = (u) => (f ? e / 2 - u : u + e / 2) * l, d = (u) => (c ? n / 2 - u : u + n / 2) * i;
144
145
  return s ? {
145
146
  px: a,
@@ -156,20 +157,20 @@ function q(t) {
156
157
  map: (u, p) => [o(u), d(p)]
157
158
  };
158
159
  }
159
- function J(t, e, n) {
160
+ function tt(t, e, n) {
160
161
  const r = e.length / 8;
161
162
  if (!r) return 0;
162
163
  let a = 0;
163
164
  t.beginPath();
164
165
  let f = NaN, c = NaN;
165
166
  for (let s = 0; s < r; s++) {
166
- const l = e[s * 8], i = e[s * 8 + 1], o = e[s * 8 + 4], d = e[s * 8 + 5];
167
+ const l = e[s * A], i = e[s * A + 1], o = e[s * A + 4], d = e[s * A + 5];
167
168
  (l !== f || i !== c) && (t.moveTo(...n.map(l, i)), a++), t.lineTo(...n.map(o, d)), f = o, c = d;
168
169
  }
169
170
  return t.fill("evenodd"), a;
170
171
  }
171
- const K = (t) => String(t ?? "");
172
- function Q({ params: t, stats: e, jobName: n, timestamp: r }) {
172
+ const et = (t) => String(t ?? "");
173
+ function nt({ params: t, stats: e, jobName: n, timestamp: r }) {
173
174
  const a = String(t.material_print_speed ?? "fast"), f = {
174
175
  action: "print",
175
176
  jobDir: n,
@@ -191,12 +192,12 @@ function Q({ params: t, stats: e, jobName: n, timestamp: r }) {
191
192
  prusaSlicerVersion: "three-slicer",
192
193
  usedMaterial: Number(e.resin_ml ?? 0).toFixed(6)
193
194
  };
194
- return Object.keys(f).sort().map((c) => `${c} = ${K(f[c])}`).join(`
195
+ return Object.keys(f).sort().map((c) => `${c} = ${et(f[c])}`).join(`
195
196
  `) + `
196
197
  `;
197
198
  }
198
- const T = (t, e) => `${t}${String(e).padStart(5, "0")}.png`, tt = "Metadata/threeslicer_roles.bin", et = "Metadata/threeslicer_scene.bin";
199
- function nt({ modelSTL: t, supportMesh: e, padMesh: n, lift: r = 0 }) {
199
+ const B = (t, e) => `${t}${String(e).padStart(5, "0")}.png`, ot = "Metadata/threeslicer_roles.bin", rt = "Metadata/threeslicer_scene.bin";
200
+ function st({ modelSTL: t, supportMesh: e, padMesh: n, lift: r = 0 }) {
200
201
  const a = t instanceof Uint8Array ? t : new Uint8Array(t ?? 0), f = e instanceof Float32Array ? e : new Float32Array(e ?? 0), c = n instanceof Float32Array ? n : new Float32Array(n ?? 0), s = new Uint8Array(12 + a.length + 4 + f.length * 4 + 4 + c.length * 4), l = new DataView(s.buffer);
201
202
  s.set([84, 83, 83, 49], 0), l.setFloat32(4, r, !0);
202
203
  let i = 8;
@@ -208,12 +209,12 @@ function nt({ modelSTL: t, supportMesh: e, padMesh: n, lift: r = 0 }) {
208
209
  }
209
210
  return s;
210
211
  }
211
- function ot(t) {
212
+ function it(t) {
212
213
  const e = t.map(({ paths: c }) => {
213
214
  const s = [];
214
- for (let l = 0; l + 7 < c.length; l += 8) {
215
- const i = c[l + 3] & 15;
216
- if (i === 5 || i === 6) for (let o = 0; o < 8; o++) s.push(c[l + o]);
215
+ for (let l = 0; l + A - 1 < c.length; l += A) {
216
+ const i = X(c[l + 3]);
217
+ if (i === C.SUPPORT || i === C.RAFT) for (let o = 0; o < A; o++) s.push(c[l + o]);
217
218
  }
218
219
  return s;
219
220
  }), n = 8 + e.reduce((c, s) => c + 4 + s.length * 4, 0), r = new Uint8Array(n), a = new DataView(r.buffer);
@@ -226,7 +227,7 @@ function ot(t) {
226
227
  }
227
228
  return r;
228
229
  }
229
- function rt({ layers: t, params: e, makeWorker: n, workerCount: r, onProgress: a, aa: f = 1 }) {
230
+ function lt({ layers: t, params: e, makeWorker: n, workerCount: r, onProgress: a, aa: f = 1 }) {
230
231
  return new Promise((c, s) => {
231
232
  const l = new Array(t.length), i = new Array(r).fill(0);
232
233
  let o = 0, d = !1;
@@ -252,8 +253,8 @@ function rt({ layers: t, params: e, makeWorker: n, workerCount: r, onProgress: a
252
253
  }
253
254
  });
254
255
  }
255
- async function lt({ layers: t, params: e, stats: n, jobName: r = "plate", timestamp: a, makeCanvas: f, onProgress: c, scene: s = null, makeWorker: l = null, workerCount: i = 0, aa: o = 1, gpuRaster: d = null }) {
256
- const u = f ?? null, p = q(e), x = {}, w = l && typeof Worker < "u" && t.length > 1 ? {
256
+ async function ut({ layers: t, params: e, stats: n, jobName: r = "plate", timestamp: a, makeCanvas: f, onProgress: c, scene: s = null, makeWorker: l = null, workerCount: i = 0, aa: o = 1, gpuRaster: d = null }) {
257
+ const u = f ?? null, p = Q(e), x = {}, w = l && typeof Worker < "u" && t.length > 1 ? {
257
258
  makeWorker: l,
258
259
  workerCount: Math.max(1, Math.min(i > 0 ? i : 4, t.length))
259
260
  } : null, b = () => performance.now(), m = { canvas: 0, clear: 0, draw: 0, encode: 0, read: 0 }, y = (h, g) => {
@@ -261,42 +262,42 @@ async function lt({ layers: t, params: e, stats: n, jobName: r = "plate", timest
261
262
  return m[h] += v - g, v;
262
263
  };
263
264
  let _ = 0, U = 0;
264
- const B = async (h) => {
265
+ const P = async (h) => {
265
266
  let g = b();
266
267
  if (!u) {
267
- const P = d ? await d(t[h].paths, p, o, t[h], h) : X(t[h].paths, p, o);
268
+ const I = d ? await d(t[h].paths, p, o, t[h], h) : W(t[h].paths, p, o);
268
269
  g = y("draw", g);
269
- const D = await Z(P, p.px, p.py, { deflate: z });
270
+ const D = await K(I, p.px, p.py, { deflate: j });
270
271
  return y("encode", g), _ += D.length, D;
271
272
  }
272
- const v = u(p.px, p.py), S = v.getContext("2d");
273
- g = y("canvas", g), S.fillStyle = "#000", S.fillRect(0, 0, p.px, p.py), g = y("clear", g), S.fillStyle = "#fff", U += J(S, t[h].paths, p), g = y("draw", g);
274
- const L = await v.convertToBlob({ type: "image/png" });
273
+ const v = u(p.px, p.py), $ = v.getContext("2d");
274
+ g = y("canvas", g), $.fillStyle = "#000", $.fillRect(0, 0, p.px, p.py), g = y("clear", g), $.fillStyle = "#fff", U += tt($, t[h].paths, p), g = y("draw", g);
275
+ const O = await v.convertToBlob({ type: "image/png" });
275
276
  g = y("encode", g);
276
- const C = new Uint8Array(await L.arrayBuffer());
277
- return y("read", g), _ += C.length, C;
278
- }, F = b();
277
+ const T = new Uint8Array(await O.arrayBuffer());
278
+ return y("read", g), _ += T.length, T;
279
+ }, N = b();
279
280
  if (w) {
280
- const h = await rt({ layers: t, params: e, onProgress: c, aa: o, ...w });
281
+ const h = await lt({ layers: t, params: e, onProgress: c, aa: o, ...w });
281
282
  for (let g = 0; g < t.length; g++)
282
- x[T(r, g)] = [h[g], { level: 0 }], _ += h[g].length;
283
+ x[B(r, g)] = [h[g], { level: 0 }], _ += h[g].length;
283
284
  } else
284
285
  for (let h = 0; h < t.length; h++)
285
- x[T(r, h)] = [await B(h), { level: 0 }], h & 31 || c?.(h, t.length);
286
- const M = b();
287
- x["config.ini"] = V(Q({ params: e, stats: n, jobName: r, timestamp: a })), x[tt] = [ot(t), { level: 6 }], s && (x[et] = [nt(s), { level: 6 }]);
288
- const N = b(), k = I(x), A = (h) => h.toFixed(0);
289
- return O.info(`[vp-prof] sl1 build: ${t.length} layers ${p.px}x${p.py},` + (w ? ` raster ${A(M - F)}ms (${w.workerCount} workers),` : ` ${U} loops, raster ${A(M - F)}ms (canvas ${A(m.canvas)} + clear ${A(m.clear)} + draw ${A(m.draw)} + encode ${A(m.encode)} + read ${A(m.read)}),`) + ` sidecar ${A(N - M)}ms, zip ${A(b() - N)}ms -> ${(k.byteLength / 1e6).toFixed(1)}MB (png ${(_ / 1e6).toFixed(1)}MB)`), k;
286
+ x[B(r, h)] = [await P(h), { level: 0 }], h & 31 || c?.(h, t.length);
287
+ const E = b();
288
+ x["config.ini"] = V(nt({ params: e, stats: n, jobName: r, timestamp: a })), x[ot] = [it(t), { level: 6 }], s && (x[rt] = [st(s), { level: 6 }]);
289
+ const k = b(), R = z(x), S = (h) => h.toFixed(0);
290
+ return Y.info(`[vp-prof] sl1 build: ${t.length} layers ${p.px}x${p.py},` + (w ? ` raster ${S(E - N)}ms (${w.workerCount} workers),` : ` ${U} loops, raster ${S(E - N)}ms (canvas ${S(m.canvas)} + clear ${S(m.clear)} + draw ${S(m.draw)} + encode ${S(m.encode)} + read ${S(m.read)}),`) + ` sidecar ${S(k - E)}ms, zip ${S(b() - k)}ms -> ${(R.byteLength / 1e6).toFixed(1)}MB (png ${(_ / 1e6).toFixed(1)}MB)`), R;
290
291
  }
291
292
  export {
292
- et as S,
293
- tt as a,
294
- j as b,
295
- it as c,
296
- J as d,
297
- Z as e,
298
- O as l,
299
- lt as m,
300
- X as r,
301
- q as s
293
+ rt as S,
294
+ ot as a,
295
+ G as b,
296
+ ft as c,
297
+ tt as d,
298
+ K as e,
299
+ Y as l,
300
+ ut as m,
301
+ W as r,
302
+ Q as s
302
303
  };