any2orca 0.3.1 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # any2orca
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Features
6
+
7
+ - **The report lists every filament, with the name it had and the name it has.** `report.filaments` has one entry per slot, in the file's order: slot, color, type, the source preset name and the output name (the same, or what the naming option renamed it to). `any2orca convert --verbose` prints the list. Every filament stays, however many: the U1 loads four at a time, but a project can use many more, swapped in at the pauses planned in Snapmaker Orca, and that planning depends on the file's own order; a test now guards that nothing is dropped, merged or reordered.
8
+ - **The report says why a profile was matched.** `report.profileNotes` carries the matcher's sentences when an auto-match wasn't plain (the source nozzle has no U1 profile, say); empty for an exact match, a given profile id or a preset.
9
+ - **A project from a slicer the library doesn't convert has its own error code.** A readable project saved by PrusaSlicer, or a slicer built on it, now fails with `unsupported_slicer`, with the slicer's name in `error.slicer`, instead of `invalid_file`; the message is unchanged. A damaged file stays `invalid_file`, so an app can tell the two apart.
10
+
11
+ ### Other
12
+
13
+ - **The model's own metadata is kept,** as before: designer, license, copyright, title, origin and description in `3D/3dmodel.model` stay as they were, and only `Application` changes. A test now says so, and the README too.
14
+ - **The worker docs say how to go on after a failed worker:** listen for its `error` event, make a new one, and open the other files again.
15
+
16
+ ## 0.3.2
17
+
18
+ ### Fixes
19
+
20
+ - **No policy violations under a strict content security policy.** zod, which the library uses to check its input, calls the `Function` constructor once to see whether it may compile faster parsers. A policy without `'unsafe-eval'` (a browser extension's, or a site's) refuses it, and zod falls back, but the browser reported a violation each time a page or worker loaded the library. The library now turns zod's compiled parsers off as it loads, before it creates any schema, so the call never runs. Converted files are byte-for-byte the same and conversions take the same time. zod's setting is shared by every copy of zod in the same page or worker; call `z.config({ jitless: false })` before importing any2orca to keep compiled parsers for your own schemas.
21
+ - **A zip that isn't a 3MF says so.** A zip with neither a 3MF project nor a 3MF inside it (a bundle of STL files, say) was refused as a 3MF that "holds only the model". It now gets its own message.
22
+ - **The Web Worker settles every call when the worker fails.** If the worker fails to load or stops (out of memory on a very large file, say), `createConverterWorker` now rejects every call in flight with a message saying so, and refuses later ones, instead of leaving them waiting forever.
23
+
24
+ ### Other
25
+
26
+ - **Messages don't name the library,** so an app can show them as they are: the ones about a project from another slicer, a project too large, an archive with a repeated entry, an oversized model file, a retired profile and a catalog without filament names. The command line adds its own `any2orca profiles` hint for a retired profile.
27
+
3
28
  ## 0.3.1
4
29
 
5
30
  ### Fixes
package/README.md CHANGED
@@ -13,10 +13,30 @@ npx any2orca convert bundle.zip # a zip of several .3mf files is a bat
13
13
  npx any2orca profiles # the profiles --profile accepts
14
14
  ```
15
15
 
16
- Useful options: `--profile <id>`, `--snapmaker-orca-version <x.y.z>` (the Snapmaker Orca release you slice with; default the newest), `--high-flow` or `--high-flow-toolheads 1,3` (which toolheads have the Liber High Flow Hotend), `--hardened-nozzle` (hardened steel nozzles instead of the stock stainless 0.4), `--filament-compliance generic|snapmaker`, `--dry-run`, `--watch <folder>`, `--archive-dir`, `--skip-existing`, `--profiles-dir`. Run `any2orca convert --help` for all of them. The exit code is 1 if any file failed. Full reference, including exit codes, the state file and `telemetry`: [`docs/cli.md`](../../docs/cli.md).
16
+ Useful options:
17
+
18
+ | Option | What it does |
19
+ |---|---|
20
+ | `--profile <id>` | Use this profile instead of matching one |
21
+ | `--snapmaker-orca-version <x.y.z>` | Convert for the Snapmaker Orca release you slice with (default: the newest) |
22
+ | `--high-flow`, `--high-flow-toolheads 1,3` | All toolheads, or only these, have the Liber High Flow Hotend |
23
+ | `--hardened-nozzle` | Your nozzles are hardened steel instead of the stock stainless 0.4 |
24
+ | `--filament-compliance generic\|snapmaker` | Rename filaments for Snapmaker Space |
25
+ | `--dry-run` | Show what would happen, without writing files |
26
+ | `--watch <folder>` | Convert each new file that appears in a folder |
27
+ | `--archive-dir <dir>`, `--skip-existing` | For batches: move finished originals away, or skip files already converted |
28
+ | `--profiles-dir <dir>` | Use your own profile catalog |
29
+
30
+ `any2orca convert --help` lists them all. The exit code is 1 if any file failed.
31
+
32
+ The full reference, with exit codes, the state file and `telemetry`, is in [`docs/cli.md`](https://github.com/KuzuriAo/any2orca/blob/main/docs/cli.md).
17
33
 
18
34
  ## Library
19
35
 
36
+ Every exported function and type is in the [API reference](https://docs.any2orca.com). The common paths:
37
+
38
+ Every filament in the source stays in the output: all of them, with their colors, brands, types and order, however many. The U1 loads four at a time, but a project can use many more, swapped in at the pauses the user plans in Snapmaker Orca, and that planning depends on the file's own order. `report.filaments` lists each slot with the name it had and the name it has. The model's own metadata in `3D/3dmodel.model` (designer, license, copyright, title, description) stays as it was; only `Application` changes, to the Snapmaker Orca release the file is made for.
39
+
20
40
  ```js
21
41
  import { readFile, writeFile } from "node:fs/promises";
22
42
  import { convert } from "any2orca";
@@ -56,11 +76,15 @@ catalog.releases(); // [{ version, application, isDefault }, ...], newest (the d
56
76
  const { output } = await convert(bytes, { profiles: catalog, snapmakerOrcaVersion: "2.4.0" });
57
77
  ```
58
78
 
59
- Pick the release the user slices with: Snapmaker Orca's command line stops at a value an older release doesn't accept. A release the catalog doesn't hold throws `Any2orcaError` with code `release_not_found`. Anything else that reads profiles (`matchProfile`, `extractPreset`, `resolvePreset`, `diffReference`) takes the catalog from `catalog.forRelease(version)`. See [Snapmaker Orca releases](../../docs/snapmaker-orca-releases.md).
79
+ - **Pick the release the user slices with.** Snapmaker Orca's command line stops at a value an older release doesn't accept.
80
+ - **A release the catalog doesn't hold** throws `Any2orcaError` with code `release_not_found`.
81
+ - **Everything else that reads profiles** (`matchProfile`, `extractPreset`, `resolvePreset`, `diffReference`) takes the catalog from `catalog.forRelease(version)`.
82
+
83
+ More in [Snapmaker Orca releases](https://github.com/KuzuriAo/any2orca/blob/main/docs/snapmaker-orca-releases.md).
60
84
 
61
85
  Never re-implement profile matching in a UI: use `matchProfile()` (or `pickProfile()` and `parseTierName()`), so every UI picks the same profile for the same file.
62
86
 
63
- Presets (your own tuned print settings, applied to other files; see [`docs/presets.md`](../../docs/presets.md)):
87
+ Presets (your own tuned print settings, applied to other files; see [`docs/presets.md`](https://github.com/KuzuriAo/any2orca/blob/main/docs/presets.md)):
64
88
 
65
89
  ```js
66
90
  import { extractPreset } from "any2orca";
@@ -69,7 +93,13 @@ const { preset, changes, notes } = await extractPreset(tunedBytes, { profiles })
69
93
  const { output, report } = await project.convert({ profiles, preset: { ...preset, name: "My settings" } });
70
94
  ```
71
95
 
72
- `parsePresetFile()` and `serializePresets()` read and write the `any2orca-presets` file format, with size and count limits. `report.whatChanged` records what the conversion changed, grouped by why (`formatWhatChanged()` for text, `explain: true` to add every difference; see [`docs/what-changed.md`](../../docs/what-changed.md)). `diffSettings()` compares any two sets of settings (see [`docs/compare-settings.md`](../../docs/compare-settings.md)).
96
+ More tools:
97
+
98
+ | Function | What it does | Guide |
99
+ |---|---|---|
100
+ | `parsePresetFile()`, `serializePresets()` | Read and write the `any2orca-presets` file format, with size and count limits | [Presets](https://github.com/KuzuriAo/any2orca/blob/main/docs/presets.md) |
101
+ | `report.whatChanged`, `formatWhatChanged()` | What the conversion changed, grouped by why; as text with `formatWhatChanged()`, and with every difference when you pass `explain: true` | [What changed](https://github.com/KuzuriAo/any2orca/blob/main/docs/what-changed.md) |
102
+ | `diffSettings()` | Compare any two sets of settings | [Compare settings](https://github.com/KuzuriAo/any2orca/blob/main/docs/compare-settings.md) |
73
103
 
74
104
  ## Web Worker
75
105
 
@@ -86,6 +116,35 @@ The converter also compares settings (`converter.diff()`), and makes, checks and
86
116
 
87
117
  Copy `node_modules/any2orca-profiles/data/` to your site's `/profiles/` folder. The worker fetches `index.json` and only the profile files it uses.
88
118
 
119
+ If the worker fails to load or stops (out of memory on a very large file, say), every call in flight is rejected with a message saying so, and later calls are refused at once; the failed worker stays dead. To keep going after one oversized file, listen for the `Worker`'s `error` event, create a new `Worker` and a new converter from it, and open the other files again; nothing from the old one carries over.
120
+
121
+ ## Errors and messages
122
+
123
+ A call that fails throws `Any2orcaError`. Its `code` is stable, so a UI can branch on it:
124
+
125
+ | Code | Meaning |
126
+ |---|---|
127
+ | `invalid_file` | Not a readable 3MF: a damaged zip, missing project files, unsafe entries |
128
+ | `unsupported_slicer` | A readable project from a slicer this doesn't convert (PrusaSlicer, say); `error.slicer` names it |
129
+ | `too_large` | The project unpacks to more than the size limit (2 GB by default) |
130
+ | `invalid_project` | A readable 3MF whose settings or objects are malformed or over a limit |
131
+ | `profile_not_found` | The profile id isn't in the catalog and wasn't retired |
132
+ | `release_not_found` | The Snapmaker Orca release isn't one the catalog holds |
133
+ | `profile_data` | The profile catalog itself is missing or malformed |
134
+ | `invalid_preset` | A preset or presets file that is malformed, over a limit, or can't be used with the options given |
135
+ | `preset_base_unknown` | A preset can't be made from this file: it isn't set up for a profile in the catalog |
136
+
137
+ The error's message, and every entry in `report.warnings`, is written for the person converting and doesn't name the library. Any app can show it as it is.
138
+
139
+ ## Strict content security policies
140
+
141
+ The library evaluates no code, so it runs under a policy without `'unsafe-eval'`, such as a browser extension's or any2orca.com's.
142
+
143
+ - **Why this needs care:** the library checks its input with zod. zod can compile faster parsers with the `Function` constructor, and first calls it once to see whether it may. A strict policy refuses that call and reports a violation.
144
+ - **What the library does:** as it loads, before it creates any schema, it turns zod's compiled parsers off (zod's `jitless` setting). Parsing gives the same results, and conversions take the same time.
145
+ - **Your own zod schemas:** the setting is shared by every copy of zod in the same page or worker, so they parse the plain way too. To keep compiled parsers for them, call `z.config({ jitless: false })` before importing any2orca.
146
+ - **Store linters:** a linter that reads the code instead of running it (Firefox's `web-ext lint`) still reports one `DANGEROUS_EVAL` warning, for zod's check, which never runs. [`examples/plugin-extension`](https://github.com/KuzuriAo/any2orca/tree/main/examples/plugin-extension) removes it with a small Vite plugin, and explains it for a store's reviewers.
147
+
89
148
  ## What leaves your machine
90
149
 
91
150
  Your files never do. The library makes no network requests. The CLI makes at most two kinds:
@@ -99,12 +158,33 @@ Your files never do. The library makes no network requests. The CLI makes at mos
99
158
 
100
159
  ## Output stamp
101
160
 
102
- Every converted file gets a small entry, `Metadata/any2orca.json`, with the any2orca version, the profile catalog version, the profile used and the options chosen. It is there so a file can be recognized later: when a bug is found and fixed, the version inside tells you whether a file came from an affected release, and bug reports get exact details. It holds no file names, paths, times or identifiers, nothing reads it back by itself, and nothing is sent anywhere. To leave it out, pass `stamp: false` to `convert()`, or `--no-stamp` on the command line. `decodeStamp()` reads it back. Details: [`docs/output-stamp.md`](../../docs/output-stamp.md).
161
+ Every converted file gets a small entry, `Metadata/any2orca.json`.
162
+
163
+ - **What's in it:** the any2orca version, the profile catalog version, the profile used and the options chosen.
164
+ - **Why:** so a file can be recognized later. When a bug is fixed, the version inside tells you whether a file came from an affected release, and bug reports get exact details.
165
+ - **What isn't:** no file names, paths, times or identifiers. Nothing reads it back by itself, and nothing is sent anywhere.
166
+ - **To leave it out:** pass `stamp: false` to `convert()`, or `--no-stamp` on the command line. `decodeStamp()` reads it back.
167
+
168
+ Details: [`docs/output-stamp.md`](https://github.com/KuzuriAo/any2orca/blob/main/docs/output-stamp.md).
103
169
 
104
170
  ## Limits
105
171
 
106
- Files are read in memory, with limits that protect your machine from a malicious file: at most 10,000 zip entries and 2 GB unpacked in total by default (`maxUnpackedBytes` in code or `--max-unpacked` on the command line raises it, up to 16 GB; converting needs about twice the unpacked size in memory, and a project over 1 GB comes with a warning saying so), no entry over 10 MB (and no whole file) compressing more than 100:1, entry names of at most 1,024 characters and no unsafe entry paths, a main model file (`3D/3dmodel.model`) of at most 500 MB (projects saved with their meshes as separate part files have no such limit), project settings at most 2 MB and 64 levels deep, and at most 1,000 objects.
172
+ Files are read in memory, with limits that protect your machine from a malicious file:
173
+
174
+ | Limit | Value |
175
+ |---|---|
176
+ | Unpacked size, in total | 2 GB by default. `maxUnpackedBytes` in code or `--max-unpacked` on the command line raises it, up to 16 GB. Converting needs about twice the unpacked size in memory, and a project over 1 GB comes with a warning saying so. |
177
+ | Zip entries | At most 10,000 |
178
+ | Compression | No entry over 10 MB, and no whole file, compressing more than 100:1 |
179
+ | Entry names | At most 1,024 characters, and no unsafe paths |
180
+ | Main model file (`3D/3dmodel.model`) | At most 500 MB. Projects saved with their meshes as separate part files have no such limit. |
181
+ | Project settings | At most 2 MB, and 64 levels deep |
182
+ | Objects | At most 1,000 |
107
183
 
108
184
  ## License
109
185
 
110
- MIT. The profile data (`any2orca-profiles`) is AGPL-3.0-or-later, since it is derived from Snapmaker's AGPL presets; it is a separate package, loaded at runtime. [`NOTICE`](NOTICE) credits the data this package includes. any2orca is an independent project, not affiliated with, endorsed by, or sponsored by Snapmaker, Bambu Lab, OrcaSlicer or any printer, slicer or filament maker.
186
+ MIT.
187
+
188
+ The profile data (`any2orca-profiles`) is AGPL-3.0-or-later, since it is derived from Snapmaker's AGPL presets. It is a separate package, loaded at runtime. [`NOTICE`](https://github.com/KuzuriAo/any2orca/blob/main/packages/core/NOTICE) credits the data this package includes.
189
+
190
+ any2orca is an independent project, not affiliated with, endorsed by, or sponsored by Snapmaker, Bambu Lab, OrcaSlicer or any printer, slicer or filament maker.
@@ -72,7 +72,7 @@ export function safeUnzipSync(fileBytes, maxUnpackedBytes = DEFAULT_MAX_UNPACKED
72
72
  throw new TypeError(`maxUnpackedBytes must be a whole number of bytes from 1 MB to ${formatSize(MAX_UNPACKED_BYTES_LIMIT)}.`);
73
73
  }
74
74
  // Says what's wrong, not what to do: the CLI, the web app and the docs each give their own way to raise the limit.
75
- const tooLarge = () => new Any2orcaError("too_large", `This project is too large: it unpacks to more than ${formatSize(maxUnpackedBytes)}, ${maxUnpackedBytes === DEFAULT_MAX_UNPACKED_BYTES ? "the most any2orca converts by default" : "the limit set for this conversion"}.`);
75
+ const tooLarge = () => new Any2orcaError("too_large", `This project is too large: it unpacks to more than ${formatSize(maxUnpackedBytes)}, ${maxUnpackedBytes === DEFAULT_MAX_UNPACKED_BYTES ? "the most converted by default" : "the limit set for this conversion"}.`);
76
76
  const unsafe = (message) => new Any2orcaError("invalid_file", message);
77
77
  let totalBytes = 0;
78
78
  let totalCompressedBytes = 0;
@@ -83,7 +83,7 @@ export function safeUnzipSync(fileBytes, maxUnpackedBytes = DEFAULT_MAX_UNPACKED
83
83
  entryCount++;
84
84
  // Slicers read the first copy of a repeated name and this reader the last, so the two would see different files.
85
85
  if (seenNames.has(file.name)) {
86
- throw unsafe(`This file can't be opened safely: it contains ${JSON.stringify(file.name.slice(0, 200))} twice, and a slicer would read a different copy than any2orca. Re-save the project in its slicer.`);
86
+ throw unsafe(`This file can't be opened safely: it contains ${JSON.stringify(file.name.slice(0, 200))} twice, and a slicer could read a different copy from the one converted. Re-save the project in its slicer.`);
87
87
  }
88
88
  seenNames.add(file.name);
89
89
  if (exceedsDeclaredSize(file.size, file.originalSize)) {
@@ -52,7 +52,12 @@ export function prepareConvertRequest(fileBytes, maxUnpackedBytes) {
52
52
  // file and format: a project, but not one this converts.
53
53
  const otherFormatSettings = zipEntries[OTHER_FORMAT_SETTINGS_PATH];
54
54
  if (!projectSettingsBytes && otherFormatSettings) {
55
- throw new Any2orcaError("invalid_file", `This project was saved by ${otherFormatSlicer(otherFormatSettings)}, whose projects any2orca doesn't convert. It converts projects from Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer and Flash Studio.`);
55
+ const slicer = otherFormatSlicer(otherFormatSettings);
56
+ throw new Any2orcaError("unsupported_slicer", `This project was saved by ${slicer}, and only projects from Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer and Flash Studio can be converted.`, { slicer });
57
+ }
58
+ // A zip that isn't a 3MF at all (no model part, no print settings): a bundle of STL files, say.
59
+ if (!projectSettingsBytes && !zipEntries[TOP_MODEL_PATH]) {
60
+ throw new Any2orcaError("invalid_file", "This file is a zip, but not a 3MF project, and holds no 3MF to convert. Model files such as STLs don't need converting: open them in Snapmaker Orca and choose a U1 profile.");
56
61
  }
57
62
  if (!projectSettingsBytes) {
58
63
  throw new Any2orcaError("invalid_file", "This 3MF holds only the model, with no print settings, so there's nothing to convert: open it in Snapmaker Orca and choose a U1 profile.");
@@ -76,7 +81,7 @@ export function prepareConvertRequest(fileBytes, maxUnpackedBytes) {
76
81
  // The main model is read as text, and a JavaScript string can't be longer than about 512 MB. Slicers keep big
77
82
  // meshes in their own part files (3D/Objects/), which are scanned in chunks; this only stops an odd file.
78
83
  if (topModelBytes.length > MAX_TOP_MODEL_BYTES) {
79
- throw new Any2orcaError("invalid_project", `This project's main model file is ${Math.round(topModelBytes.length / 1024 / 1024)} MB, more than the ${MAX_TOP_MODEL_BYTES / 1024 / 1024} MB any2orca can read in one piece. Re-saving the project in its slicer usually stores the meshes as separate files, which have no such limit.`);
84
+ throw new Any2orcaError("invalid_project", `This project's main model file is ${Math.round(topModelBytes.length / 1024 / 1024)} MB, more than the ${MAX_TOP_MODEL_BYTES / 1024 / 1024} MB that can be read in one piece. Re-saving the project in its slicer usually stores the meshes as separate files, which have no such limit.`);
80
85
  }
81
86
  const topModelText = utf8Decoder.decode(topModelBytes);
82
87
  const modelSettingsBytes = zipEntries[MODEL_SETTINGS_PATH];
@@ -79,9 +79,15 @@ function logReport(report, verbose, logger) {
79
79
  }
80
80
  for (const w of report.warnings)
81
81
  logger.log(` warning: ${w}`);
82
- if (verbose)
82
+ if (report.retiredProfile)
83
+ logger.log(' note: run "any2orca profiles" for the current list.');
84
+ if (verbose) {
85
+ for (const f of report.filaments) {
86
+ logger.log(` filament ${f.slot}: ${f.color} ${f.type} ${f.outputName || "(no preset name)"}${f.outputName !== f.sourceName ? ` (was ${f.sourceName || "unnamed"})` : ""}`);
87
+ }
83
88
  for (const line of report.log)
84
89
  logger.log(` log: ${line}`);
90
+ }
85
91
  }
86
92
  /**
87
93
  * Whether retrying this exact file could give a different result. A
@@ -91,7 +97,7 @@ function logReport(report, verbose, logger) {
91
97
  */
92
98
  export function isPermanentFailure(err) {
93
99
  if (err instanceof Any2orcaError)
94
- return err.code === "invalid_file" || err.code === "too_large" || err.code === "invalid_project" || err.code === "profile_not_found" || err.code === "invalid_preset";
100
+ return err.code === "invalid_file" || err.code === "unsupported_slicer" || err.code === "too_large" || err.code === "invalid_project" || err.code === "profile_not_found" || err.code === "invalid_preset";
95
101
  const code = err?.code;
96
102
  if (typeof code === "string" && /^E[A-Z]+$/.test(code))
97
103
  return false;
@@ -75,7 +75,7 @@ export function runConvertPipeline(profile, request, application, options = {})
75
75
  if (applied.unchangedMaterials.length > 0)
76
76
  filamentComplianceUnchanged = applied.unchangedMaterials;
77
77
  if (!printer.filamentNames) {
78
- warnings.push(" WARN: this profile catalog has no filament names, so filament names were left as they are. Update any2orca-profiles.");
78
+ warnings.push(" WARN: this profile catalog has no filament names, so filament names were left as they are. Update the profile catalog.");
79
79
  }
80
80
  }
81
81
  const { files: filamentFiles } = buildFilamentConfigs(slots, p.filamentShapeConfig, p.filamentKeyBlocklist);
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * What went wrong, as a stable code a UI can branch on:
3
3
  * - `invalid_file`: not a readable 3MF (corrupt zip, missing project files, unsafe entries).
4
+ * - `unsupported_slicer`: a readable project from a slicer this doesn't convert (PrusaSlicer, say); `slicer` names it.
4
5
  * - `too_large`: a project that unpacks to more than the size limit (2 GB by default; `maxUnpackedBytes` changes it).
5
6
  * - `invalid_project`: a readable 3MF whose settings or objects are malformed or over a limit.
6
7
  * - `profile_not_found`: the requested profile id isn't in the catalog and wasn't retired.
@@ -9,11 +10,14 @@
9
10
  * - `invalid_preset`: a preset or presets file that is malformed, over a limit, or can't be used with the given options.
10
11
  * - `preset_base_unknown`: a file a preset can't be made from, because it isn't set up for a profile in the catalog.
11
12
  */
12
- export type Any2orcaErrorCode = "invalid_file" | "too_large" | "invalid_project" | "profile_not_found" | "release_not_found" | "profile_data" | "invalid_preset" | "preset_base_unknown";
13
+ export type Any2orcaErrorCode = "invalid_file" | "unsupported_slicer" | "too_large" | "invalid_project" | "profile_not_found" | "release_not_found" | "profile_data" | "invalid_preset" | "preset_base_unknown";
13
14
  export declare class Any2orcaError extends Error {
14
15
  name: string;
15
16
  readonly code: Any2orcaErrorCode;
17
+ /** With `unsupported_slicer`: the slicer the project names, as the message shows it. */
18
+ readonly slicer?: string;
16
19
  constructor(code: Any2orcaErrorCode, message: string, options?: {
17
20
  cause?: unknown;
21
+ slicer?: string;
18
22
  });
19
23
  }
package/dist/errors.js CHANGED
@@ -2,8 +2,12 @@
2
2
  export class Any2orcaError extends Error {
3
3
  name = "Any2orcaError";
4
4
  code;
5
+ /** With `unsupported_slicer`: the slicer the project names, as the message shows it. */
6
+ slicer;
5
7
  constructor(code, message, options) {
6
- super(message, options);
8
+ super(message, options?.cause === undefined ? undefined : { cause: options.cause });
7
9
  this.code = code;
10
+ if (options?.slicer !== undefined)
11
+ this.slicer = options.slicer;
8
12
  }
9
13
  }
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * `any2orca/worker`.
11
11
  */
12
12
  export { convert, inspect, openProject, matchProfile, unwrapBundle, cleanWarnings, Project } from "./project.js";
13
- export type { ConvertOptions, ConvertReport, ConvertResult, ConvertStage, OpenOptions, ProfileChoice } from "./project.js";
13
+ export type { ConvertOptions, ConvertReport, ConvertResult, ConvertStage, OpenOptions, ProfileChoice, ReportFilament } from "./project.js";
14
14
  export { DEFAULT_MAX_UNPACKED_BYTES, LARGE_PROJECT_BYTES, MAX_UNPACKED_BYTES_LIMIT } from "./archive/safeUnzip.js";
15
15
  export type { FilamentSlotInfo, Inspection, SourceVendor } from "./inspect.js";
16
16
  export { fetchProfileSource, isReleasePath, listProfiles, loadCatalog, memoryProfileSource, ProfileCatalog, ProfileDataError, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, } from "./profiles.js";
@@ -14,6 +14,7 @@
14
14
  * declares for the setting, and files against size and count limits, before
15
15
  * anything is used.
16
16
  */
17
+ import "../zodSetup.js";
17
18
  import { z } from "zod";
18
19
  import type { JsonRecord } from "../engine/types.js";
19
20
  import type { ProfileCatalog } from "../profiles.js";
@@ -15,6 +15,7 @@
15
15
  * declares for the setting, and files against size and count limits, before
16
16
  * anything is used.
17
17
  */
18
+ import "../zodSetup.js";
18
19
  import { z } from "zod";
19
20
  import { labelOf } from "../diff/diffSettings.js";
20
21
  import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
@@ -17,6 +17,7 @@
17
17
  * a profile file is only ever requested by an id the index lists, and a
18
18
  * release only from a path of the form `releases/<version>`.
19
19
  */
20
+ import "./zodSetup.js";
20
21
  import { z } from "zod";
21
22
  import { Any2orcaError } from "./errors.js";
22
23
  import type { ConvertProfile } from "./engine/runConvertPipeline.js";
package/dist/profiles.js CHANGED
@@ -18,6 +18,7 @@
18
18
  * a profile file is only ever requested by an id the index lists, and a
19
19
  * release only from a path of the form `releases/<version>`.
20
20
  */
21
+ import "./zodSetup.js";
21
22
  import { z } from "zod";
22
23
  import { Any2orcaError } from "./errors.js";
23
24
  import { APPLICATION_VALUE } from "./archive/setApplicationMetadata.js";
package/dist/project.d.ts CHANGED
@@ -71,11 +71,34 @@ export interface ConvertOptions {
71
71
  onProgress?: (stage: ConvertStage) => void;
72
72
  }
73
73
  export type ConvertStage = "matching" | "loading-profile" | "merging" | "writing";
74
+ /**
75
+ * One filament slot of the converted file, in the file's own order. Every
76
+ * filament is kept, however many: the U1 loads four at a time, but a project,
77
+ * even one plate, can use many more, swapped in at pauses the user plans in
78
+ * Snapmaker Orca; that planning depends on this order being the file's.
79
+ */
80
+ export interface ReportFilament {
81
+ /** 1-based slot number, as slicers show it. */
82
+ slot: number;
83
+ /** "#RRGGBB", unchanged from the source. */
84
+ color: string;
85
+ /** Material, e.g. "PLA", unchanged from the source. */
86
+ type: string;
87
+ /** The preset name the source file had, e.g. `"Bambu PLA Matte @BBL X1C"`. Empty if it had none. */
88
+ sourceName: string;
89
+ /** The preset name the converted file has: the same, or what `filamentComplianceMode` renamed it to. */
90
+ outputName: string;
91
+ }
74
92
  export interface ConvertReport {
75
93
  /** The profile the file was converted with. */
76
94
  profile: ProfileSummary;
77
95
  /** How the profile was matched; absent when `profileId` was given. */
78
96
  profileMatch?: ProfileMatch;
97
+ /**
98
+ * Why the profile was chosen, in sentences for the user, when it was auto-matched and the match wasn't plain
99
+ * (the source nozzle has no U1 profile, say). Empty for an exact match, a `profileId` or a preset.
100
+ */
101
+ profileNotes: string[];
79
102
  /** Set when `profileId` named a retired profile and its successor was used. */
80
103
  retiredProfile?: RetiredProfile;
81
104
  /** Notes worth showing the user, cleaned up for display. */
@@ -91,6 +114,8 @@ export interface ConvertReport {
91
114
  plates: number;
92
115
  objects: number;
93
116
  filamentSlots: number;
117
+ /** Every filament slot, in the file's order, with the name each has in the source and in the output. */
118
+ filaments: ReportFilament[];
94
119
  /** The stamp written into the output, or null if `stamp: false`. */
95
120
  stamp: OutputStamp | null;
96
121
  /** What the conversion changed, grouped by why. */
package/dist/project.js CHANGED
@@ -205,6 +205,7 @@ export class Project {
205
205
  const routeWarnings = [];
206
206
  let profileId;
207
207
  let profileMatch;
208
+ let profileNotes = [];
208
209
  let carrySourceLayerHeight = false;
209
210
  let retiredProfile;
210
211
  if (options.preset && options.profileId) {
@@ -220,7 +221,7 @@ export class Project {
220
221
  profileId = options.profileId;
221
222
  retiredProfile = catalog.retiredSuccessor(profileId);
222
223
  if (retiredProfile) {
223
- routeWarnings.push(` WARN: profile "${profileId}" (${retiredProfile.displayName}) has been retired; converted with "${retiredProfile.successorId}" instead. Run "any2orca profiles" for the current list.`);
224
+ routeWarnings.push(` WARN: profile "${profileId}" (${retiredProfile.displayName}) has been retired; converted with "${retiredProfile.successorId}" instead.`);
224
225
  profileId = retiredProfile.successorId;
225
226
  }
226
227
  }
@@ -228,6 +229,7 @@ export class Project {
228
229
  const choice = await matchProfile(this.request.projectSettings, catalog);
229
230
  profileId = choice.profileId;
230
231
  profileMatch = choice.profileMatch;
232
+ profileNotes = [...choice.notes];
231
233
  carrySourceLayerHeight = choice.carrySourceLayerHeight;
232
234
  routeWarnings.push(...choice.notes.map((note) => ` WARN: ${note}`));
233
235
  }
@@ -284,11 +286,20 @@ export class Project {
284
286
  const applyWarnings = [];
285
287
  const output = applyConvertResponse({ ...this.parsed, warnings: applyWarnings }, response, stamp ? { [STAMP_PATH]: encodeStamp(stamp) } : {});
286
288
  const inspection = this.inspect();
289
+ const outputNames = Array.isArray(response.projectSettings.filament_settings_id) ? response.projectSettings.filament_settings_id : [];
290
+ const filaments = inspection.filaments.map((f) => ({
291
+ slot: f.slot,
292
+ color: f.color,
293
+ type: f.type,
294
+ sourceName: f.presetName,
295
+ outputName: typeof outputNames[f.slot - 1] === "string" ? outputNames[f.slot - 1] : f.presetName,
296
+ }));
287
297
  return {
288
298
  output,
289
299
  report: {
290
300
  profile: loaded.summary,
291
301
  ...(profileMatch ? { profileMatch } : {}),
302
+ profileNotes,
292
303
  ...(retiredProfile ? { retiredProfile } : {}),
293
304
  warnings: cleanWarnings([...this.parsed.warnings, ...(response.warnings ?? []), ...applyWarnings.filter((w) => w.includes("WARN"))]),
294
305
  log: [...this.parsed.warnings, ...routeWarnings, ...pipeline.warnings, ...applyWarnings].map((w) => w.trim()).filter(Boolean),
@@ -298,6 +309,7 @@ export class Project {
298
309
  plates: Math.max(1, inspection.plates.length),
299
310
  objects: inspection.objects.length,
300
311
  filamentSlots: inspection.filaments.length,
312
+ filaments,
301
313
  stamp,
302
314
  whatChanged: toWhatChanged({ id: loaded.summary.id, displayName: loaded.summary.displayName, chosenBy: preset ? "preset" : options.profileId ? "you" : "matched" }, pipeline.changes, options.explain
303
315
  ? diffSettings({ label: "Original file", settings: this.request.projectSettings }, { label: "Converted file", settings: response.projectSettings })
package/dist/schema.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * is built from a file someone dropped in, which is untrusted:
5
5
  * validating it bounds how much work a crafted file can cause.
6
6
  */
7
+ import "./zodSetup.js";
7
8
  import { z } from "zod";
8
9
  /** A single top-level object's plate assignment and computed bounding box. */
9
10
  export declare const ConvertObjectSchema: z.ZodObject<{
package/dist/schema.js CHANGED
@@ -5,6 +5,7 @@
5
5
  * is built from a file someone dropped in, which is untrusted:
6
6
  * validating it bounds how much work a crafted file can cause.
7
7
  */
8
+ import "./zodSetup.js";
8
9
  import { z } from "zod";
9
10
  import { APPLICATION_VALUE } from "./archive/setApplicationMetadata.js";
10
11
  /** A single top-level object's plate assignment and computed bounding box. */
package/dist/stamp.d.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  * exist in the wild. Add fields if needed; never rename or remove one
10
10
  * without bumping `stamp`.
11
11
  */
12
+ import "./zodSetup.js";
12
13
  import { z } from "zod";
13
14
  export declare const STAMP_PATH = "Metadata/any2orca.json";
14
15
  /** What this version writes: exactly these fields. */
package/dist/stamp.js CHANGED
@@ -10,6 +10,7 @@
10
10
  * exist in the wild. Add fields if needed; never rename or remove one
11
11
  * without bumping `stamp`.
12
12
  */
13
+ import "./zodSetup.js";
13
14
  import { z } from "zod";
14
15
  import { HighFlowHotendsSchema } from "./schema.js";
15
16
  export const STAMP_PATH = "Metadata/any2orca.json";
@@ -12,6 +12,7 @@
12
12
  * other field fails to parse, so the explanation can't drift from what's
13
13
  * actually sent.
14
14
  */
15
+ import "./zodSetup.js";
15
16
  import { z } from "zod";
16
17
  import type { SourceVendor } from "./inspect.js";
17
18
  import type { ProfileMatch } from "./schema.js";
package/dist/telemetry.js CHANGED
@@ -13,6 +13,7 @@
13
13
  * other field fails to parse, so the explanation can't drift from what's
14
14
  * actually sent.
15
15
  */
16
+ import "./zodSetup.js";
16
17
  import { z } from "zod";
17
18
  import { VERSION } from "./version.js";
18
19
  export const REF_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.3.1";
1
+ export declare const VERSION = "0.4.0";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Written by scripts/sync-version.mjs from package.json; a test checks they match.
3
- export const VERSION = "0.3.1";
3
+ export const VERSION = "0.4.0";
@@ -151,6 +151,7 @@ scope.onmessage = (event) => {
151
151
  error: {
152
152
  code: err instanceof Any2orcaError ? err.code : "invalid_file",
153
153
  message: err instanceof Error ? err.message : String(err),
154
+ ...(err instanceof Any2orcaError && err.slicer !== undefined ? { slicer: err.slicer } : {}),
154
155
  },
155
156
  }));
156
157
  };
package/dist/worker.d.ts CHANGED
@@ -4,11 +4,19 @@ import type { ConvertReport, ConvertStage, ProfileChoice } from "./project.js";
4
4
  import type { DiffOptions, SettingsDiff } from "./diff/diffSettings.js";
5
5
  import type { ExtractedPreset, Preset, ResolvedPreset } from "./presets/preset.js";
6
6
  import type { WorkerConvertOptions, WorkerReleaseOption } from "./workerProtocol.js";
7
- /** The parts of a Worker this needs, so tests and other runtimes can supply their own. */
7
+ /**
8
+ * The parts of a Worker this needs, so tests and other runtimes can supply
9
+ * their own. Besides `message`, a real Worker's `error` and `messageerror`
10
+ * events are listened to: when the worker fails to load or stops (out of
11
+ * memory, say), every pending call is rejected instead of waiting forever.
12
+ * An implementation that has no such events can ignore those listeners.
13
+ */
8
14
  export interface WorkerLike {
9
15
  postMessage(message: unknown, transfer?: Transferable[]): void;
10
- addEventListener(type: "message", listener: (event: {
11
- data: unknown;
16
+ addEventListener(type: "message" | "error" | "messageerror", listener: (event: {
17
+ data?: unknown;
18
+ type?: string;
19
+ message?: string;
12
20
  }) => void): void;
13
21
  terminate(): void;
14
22
  }
package/dist/worker.js CHANGED
@@ -19,6 +19,22 @@ export function createConverterWorker(worker, options) {
19
19
  const pending = new Map();
20
20
  let nextId = 1;
21
21
  let terminated = false;
22
+ /** Set once the worker has failed: every later call is refused with this. */
23
+ let failure = null;
24
+ // A worker that fails to load, or stops, answers nothing more: settle every pending call now.
25
+ const onFailure = (event) => {
26
+ if (event?.type !== "error" && event?.type !== "messageerror")
27
+ return;
28
+ const detail = typeof event.message === "string" && event.message ? ` (${event.message.slice(0, 200)})` : "";
29
+ failure = new Error(event.type === "messageerror"
30
+ ? `The converter couldn't read a reply from its worker${detail}. Reload the page to try again.`
31
+ : `The converter stopped working${detail}. Reload the page to try again; a very large file may need more memory than the browser allows.`);
32
+ for (const entry of pending.values())
33
+ entry.reject(failure);
34
+ pending.clear();
35
+ };
36
+ worker.addEventListener("error", onFailure);
37
+ worker.addEventListener("messageerror", onFailure);
22
38
  worker.addEventListener("message", (event) => {
23
39
  const message = event.data;
24
40
  const entry = pending.get(message?.id);
@@ -31,12 +47,16 @@ export function createConverterWorker(worker, options) {
31
47
  pending.delete(message.id);
32
48
  if (message.ok)
33
49
  entry.resolve(message.result);
34
- else
35
- entry.reject(new Any2orcaError(message.error.code, message.error.message));
50
+ else {
51
+ const slicer = message.error.slicer;
52
+ entry.reject(new Any2orcaError(message.error.code, message.error.message, typeof slicer === "string" ? { slicer } : undefined));
53
+ }
36
54
  });
37
55
  function call(body, transfer = [], onProgress) {
38
56
  if (terminated)
39
57
  return Promise.reject(new Error("The converter worker has been terminated."));
58
+ if (failure)
59
+ return Promise.reject(failure);
40
60
  const id = nextId++;
41
61
  return new Promise((resolve, reject) => {
42
62
  pending.set(id, { resolve: resolve, reject, onProgress });
@@ -45,7 +65,8 @@ export function createConverterWorker(worker, options) {
45
65
  }
46
66
  // Resolved against the page, since a relative URL means something else inside the worker.
47
67
  const profilesUrl = new URL(String(options.profilesUrl), globalThis.location?.href).href;
48
- void call({ op: "configure", profilesUrl });
68
+ // If the worker fails, the next call reports it; this one has no caller to tell.
69
+ call({ op: "configure", profilesUrl }).catch(() => { });
49
70
  const handles = new WeakMap();
50
71
  const toWire = (side) => {
51
72
  if ("stock" in side)
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * Turns off zod's compiled parsers before any schema exists. zod builds them
4
+ * with the Function constructor, and checks first whether it may by calling
5
+ * it once. A strict content security policy, like a browser extension's or a
6
+ * site's without 'unsafe-eval', refuses that call: zod catches the error and
7
+ * parses the plain way, but the browser still reports a policy violation each
8
+ * time a page or worker loads the library. Parsing gives the same result
9
+ * either way. zod reads the setting when a schema is created, so every module
10
+ * that defines one imports this first.
11
+ *
12
+ * The setting is zod's own, shared by every copy of zod in the same page or
13
+ * worker. A caller that sets `jitless` itself before importing any2orca keeps
14
+ * its choice.
15
+ */
16
+ import { z } from "zod";
17
+ if (z.config().jitless === undefined)
18
+ z.config({ jitless: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "any2orca",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Convert Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer and Flash Studio 3MF projects for the Snapmaker U1 (Snapmaker Orca), entirely on your own machine. Library, CLI and Web Worker in one package.",
5
5
  "keywords": [
6
6
  "3mf",
@@ -53,7 +53,8 @@
53
53
  ],
54
54
  "sideEffects": [
55
55
  "./dist/worker-entry.js",
56
- "./dist/cli.js"
56
+ "./dist/cli.js",
57
+ "./dist/zodSetup.js"
57
58
  ],
58
59
  "scripts": {
59
60
  "sync-version": "node scripts/sync-version.mjs",