any2orca 0.9.2 → 0.11.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,27 @@
1
1
  # any2orca
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Output-affecting
6
+
7
+ - **Snapmaker Orca no longer warns about modified G-code when it opens a converted file, and a filament named like another printer's preset stays usable with the U1.** Since 0.10.0 each filament's list of changed settings named every filament setting, its start and end G-code included, and Snapmaker Orca warns about every G-code setting such a list names. Now the list names only the settings that differ from the preset Snapmaker Orca resets the filament to, so the app keeps every value that differs and fills in the rest with the same values. Under Original, a filament whose name isn't one of Snapmaker Orca's U1 presets (a Bambu preset, say) gets the preset the Snapmaker option would choose as its parent (Snapmaker PLA Matte for a matte PLA, Generic where Snapmaker has none): its name and the creator's values stay, and Snapmaker Orca no longer resets it to another printer's preset of the same name, which listed only that maker's printers. A filament whose base is a U1 preset takes that preset's own filament G-code. A filament no U1 preset fits names what the creator changed, what the conversion changed and the printers it can be used with. In the test projects, the Snapmaker and Generic options change only the lists; Original also gains the parents, and its filament G-code changes only where the parent's differs from Snapmaker's stock comment (a comment too).
8
+ - **Snapmaker Orca keeps the nozzle type a converted file records.** The file records the U1's stock stainless steel 0.4 nozzle and the hardened steel 0.6, or hardened steel when you choose hardened nozzles, so Snapmaker Orca can warn when a filament is too abrasive for the nozzle. Snapmaker's own printer presets have the 0.4 and 0.6 swapped, and Snapmaker Orca's app reset the file's nozzle type to the installed preset's when it opened the file, so the warning followed the swapped value there; only the command line used the file's. Now the printer's entry in the list of changed settings names the nozzle type, so the app keeps it. Where the file and the installed preset agree, nothing changes; where they differ, the app shows the printer preset as modified.
9
+
10
+ ### Other
11
+
12
+ - **any2orca needs Node 22 or newer.** Node 20 reached its end of life in April 2026 and no longer gets security fixes, so CI tests Node 22 and 24. Nothing in the library's API or the CLI changes.
13
+ - **The docs say that warning and error messages can be reworded in any release.** Branch on an error's `code`, or on whether `report.warnings` or `inspection.warnings` has any entries, never on the text. The library README, the two fields' doc comments and the publishing ideas say so.
14
+
15
+ ## 0.10.0
16
+
17
+ ### Output-affecting
18
+
19
+ - **The Snapmaker and Generic filament options set each filament to its preset's own settings, and every option keeps what the file says when Snapmaker Orca opens it.** Snapmaker Orca's app resets a filament whose name matches one of its presets to that preset's settings when it opens a project, while its command line uses the file's own values, so a relabeled file printed differently depending on how it was sliced (the creator's 225 °C in the file, Snapmaker's 220 °C in the app). Now a slot set to a Snapmaker or Generic preset takes that preset's own settings, standard and high-flow values and its start and end G-code included, from the profile catalog, so the file, the app and the command line agree; colors and order stay. `report.filamentPresets` lists each such slot and the creator's values it replaced, and the new `filamentNotes(report)` says it in words, the same sentences the web app and the CLI show. Original keeps the creator's filaments exactly, and every filament's list of changed settings now names every filament setting, so Snapmaker Orca keeps the creator's values even for a filament named like one of its presets. In the quick corpus, Original changes only that list (no setting's value); the Snapmaker option changes the filament settings of every project with a filament it renames. With a profile catalog that has no preset settings, the options change names only and say so.
20
+
21
+ ### Other
22
+
23
+ - Pins any2orca-profiles 0.4.0.
24
+
3
25
  ## 0.9.2
4
26
 
5
27
  ### Fixes
package/README.md CHANGED
@@ -21,7 +21,7 @@ Useful options:
21
21
  | `--snapmaker-orca-version <x.y.z>` | Convert for the Snapmaker Orca release you slice with (default: the newest) |
22
22
  | `--high-flow`, `--high-flow-toolheads 1,3` | All toolheads, or only these, have the Liber High Flow Hotend |
23
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 |
24
+ | `--filament-compliance generic\|snapmaker` | Set filaments to Snapmaker or Generic presets, with their own settings, for Snapmaker Space |
25
25
  | `--dry-run` | Show what would happen, without writing files |
26
26
  | `--watch <folder>` | Convert each new file that appears in a folder |
27
27
  | `--archive-dir <dir>`, `--skip-existing` | For batches: move finished originals away, or skip files already converted |
@@ -136,7 +136,7 @@ A call that fails throws `Any2orcaError`. Its `code` is stable, so a UI can bran
136
136
  | `invalid_preset` | A preset or presets file that is malformed, over a limit, or can't be used with the options given |
137
137
  | `preset_base_unknown` | A preset can't be made from this file: it isn't set up for a profile in the catalog |
138
138
 
139
- 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.
139
+ 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. The wording can change in any release, so branch on the error's `code`, or on whether there are any warnings at all, never on the text.
140
140
 
141
141
  ## Strict content security policies
142
142
 
@@ -2,6 +2,7 @@
2
2
  import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { basename, dirname, extname, join, resolve } from "node:path";
4
4
  import { Any2orcaError } from "../../errors.js";
5
+ import { filamentNotes } from "../../explain/filamentNotes.js";
5
6
  import { formatWhatChanged } from "../../explain/whatChanged.js";
6
7
  import { openProject, unwrapBundle } from "../../project.js";
7
8
  import { archiveOriginal } from "../archiveMove.js";
@@ -69,14 +70,9 @@ function logReport(report, verbose, logger) {
69
70
  for (const c of report.preset.changes)
70
71
  logger.log(` preset: ${c.key} ${c.stock} -> ${c.yours}${c.aboveStock ? " (above stock)" : ""}`);
71
72
  }
72
- const fallback = report.filamentComplianceFallback ?? [];
73
- if (fallback.length > 0) {
74
- logger.log(` note: Snapmaker makes no preset for ${fallback.join(", ")} at this nozzle size, so ${fallback.length === 1 ? "it uses" : "those use"} Generic.`);
75
- }
76
- const unchanged = report.filamentComplianceUnchanged ?? [];
77
- if (unchanged.length > 0) {
78
- logger.log(` note: no Snapmaker or Generic preset fits ${unchanged.join(", ")} at this nozzle size, so ${unchanged.length === 1 ? "its name stays" : "those names stay"} as the creator had ${unchanged.length === 1 ? "it" : "them"}.`);
79
- }
73
+ // The same sentences the web app shows (filamentNotes).
74
+ for (const note of filamentNotes(report))
75
+ logger.log(` note: ${note}`);
80
76
  for (const w of report.warnings)
81
77
  logger.log(` warning: ${w}`);
82
78
  if (report.retiredProfile)
package/dist/cli/main.js CHANGED
@@ -186,7 +186,7 @@ ${formatOptions([
186
186
  ["--keep <setting,...>", "A --preset file: keep only these settings above stock; the rest use stock"],
187
187
  ["--use-stock <setting,...>", "Use Snapmaker's stock value for these settings instead of the creator's faster one (print speeds, e.g. outer_wall_speed)"],
188
188
  ["--keep-higher <setting,...>", "Keep the creator's value for these settings even when higher than stock (accelerations, travel speed, filament_max_volumetric_speed). The U1's machine limits still apply"],
189
- ["--filament-compliance <mode>", '"generic" or "snapmaker": relabel filament identity for marketplace uploads (e.g. Snapmaker Space). Identity only: never changes temperatures, retraction, flow or other tuning. Omit to keep the source file\'s filament names'],
189
+ ["--filament-compliance <mode>", '"generic" or "snapmaker": set each filament to a preset Snapmaker Orca ships, with that preset\'s own settings, for marketplace uploads (e.g. Snapmaker Space); colors and order stay. Omit to keep the creator\'s filaments, names and settings'],
190
190
  ["--high-flow", "All four toolheads have the Snapmaker Liber High Flow Hotend. The converted file records it, so Snapmaker Orca matches your printer; colors you put on a high-flow nozzle when slicing use Snapmaker's high-flow speeds on profiles that have them (today only 0.20mm Standard, 0.4mm nozzle). Gains are largest on big prints with long, continuous paths. Ignored, with a note, on nozzle sizes with no high-flow option"],
191
191
  ["--high-flow-toolheads <list>", "Only these toolheads have the Liber hotend, numbered 1 to 4, e.g. 1 or 1,3. Otherwise the same as --high-flow; use one or the other"],
192
192
  ["--hardened-nozzle", "Your U1 has hardened steel nozzles instead of the stock stainless steel 0.4. The file records it, so Snapmaker Orca warns about abrasive filaments correctly. Only changes 0.4 nozzle conversions; Snapmaker's other sizes are hardened steel already"],
@@ -1,4 +1,6 @@
1
1
  import type { FilamentSlot } from "./extractFilamentSlots.js";
2
+ import type { PrinterFilamentPresets } from "../profiles.js";
3
+ import { type AppliedFilamentPreset } from "./applyFilamentPresets.js";
2
4
  import { type FilamentComplianceMode, type FilamentNameTable } from "./filamentComplianceNames.js";
3
5
  export interface RenamedFilament {
4
6
  /** 0-based slot index. */
@@ -15,6 +17,10 @@ export interface ApplyFilamentComplianceModeResult {
15
17
  unchangedMaterials: string[];
16
18
  /** Each slot whose name changed. */
17
19
  renamed: RenamedFilament[];
20
+ /** Each slot that takes its preset's settings (every slot a preset fits, renamed or already so named), with what that replaces. */
21
+ presets: AppliedFilamentPreset[];
22
+ /** Presets named whose settings the catalog's presets file doesn't have (with a file at all): those slots changed names only. */
23
+ missingPresets: string[];
18
24
  }
19
25
  /**
20
26
  * Overrides each filament slot's identity with a real Generic/Snapmaker
@@ -37,4 +43,6 @@ export interface ApplyFilamentComplianceModeResult {
37
43
  * @param table the profile catalog's `filamentNames`; without it every slot is left as it is and reported.
38
44
  * @param printerId the target printer: names exist per nozzle size, so they follow the printer converted to, not the source.
39
45
  */
40
- export declare function applyFilamentComplianceMode(slots: FilamentSlot[], filamentKeyArrays: Record<string, unknown[]> | null, mode: FilamentComplianceMode, table: FilamentNameTable | undefined, printerId: string): ApplyFilamentComplianceModeResult;
46
+ export declare function applyFilamentComplianceMode(slots: FilamentSlot[], filamentKeyArrays: Record<string, unknown[]> | null, mode: FilamentComplianceMode, table: FilamentNameTable | undefined, printerId: string,
47
+ /** The printer's presets' settings; without them only the names change. */
48
+ presets?: PrinterFilamentPresets): ApplyFilamentComplianceModeResult;
@@ -1,3 +1,4 @@
1
+ import { presetChanges, presetSettingsFor } from "./applyFilamentPresets.js";
1
2
  import { resolveFilamentName } from "./filamentComplianceNames.js";
2
3
  /** The keys a saved project records a filament preset's identity in, one entry per slot. */
3
4
  const IDENTITY_KEYS = ["filament_settings_id", "filament_ids", "filament_vendor"];
@@ -22,10 +23,14 @@ const IDENTITY_KEYS = ["filament_settings_id", "filament_ids", "filament_vendor"
22
23
  * @param table the profile catalog's `filamentNames`; without it every slot is left as it is and reported.
23
24
  * @param printerId the target printer: names exist per nozzle size, so they follow the printer converted to, not the source.
24
25
  */
25
- export function applyFilamentComplianceMode(slots, filamentKeyArrays, mode, table, printerId) {
26
+ export function applyFilamentComplianceMode(slots, filamentKeyArrays, mode, table, printerId,
27
+ /** The printer's presets' settings; without them only the names change. */
28
+ presets) {
26
29
  const fellBackToGeneric = new Set();
27
30
  const unchanged = new Set();
28
31
  const renamed = [];
32
+ const applied = [];
33
+ const missing = new Set();
29
34
  const arrays = {};
30
35
  for (const key of IDENTITY_KEYS)
31
36
  if (filamentKeyArrays?.[key])
@@ -46,15 +51,20 @@ export function applyFilamentComplianceMode(slots, filamentKeyArrays, mode, tabl
46
51
  fellBackToGeneric.add(result.line?.label ?? filamentType);
47
52
  if (result.preset.name !== filamentSettingsId)
48
53
  renamed.push({ slot: i, before: filamentSettingsId, after: result.preset.name });
49
- const values = { filament_settings_id: result.preset.name, filament_ids: result.preset.id, filament_vendor: result.preset.vendor };
54
+ const values = presetSettingsFor(presets, result.preset.name);
55
+ if (values)
56
+ applied.push({ slot: i, preset: result.preset.name, changed: presetChanges(values, (key) => filamentKeyArrays?.[key]?.[i] ?? slot[key]) });
57
+ else if (presets)
58
+ missing.add(result.preset.name);
59
+ const identity = { filament_settings_id: result.preset.name, filament_ids: result.preset.id, filament_vendor: result.preset.vendor };
50
60
  for (const key of IDENTITY_KEYS) {
51
61
  const list = arrays[key];
52
62
  if (list && i < list.length)
53
- list[i] = values[key];
63
+ list[i] = identity[key];
54
64
  }
55
- const next = { ...slot, filament_settings_id: values.filament_settings_id, filament_vendor: values.filament_vendor };
65
+ const next = { ...slot, filament_settings_id: identity.filament_settings_id, filament_vendor: identity.filament_vendor };
56
66
  if (Object.hasOwn(slot, "filament_ids"))
57
- next.filament_ids = values.filament_ids;
67
+ next.filament_ids = identity.filament_ids;
58
68
  return next;
59
69
  });
60
70
  const newFilamentKeyArrays = filamentKeyArrays && Object.keys(arrays).length > 0 ? { ...filamentKeyArrays, ...arrays } : filamentKeyArrays;
@@ -64,5 +74,7 @@ export function applyFilamentComplianceMode(slots, filamentKeyArrays, mode, tabl
64
74
  fellBackToGenericMaterials: [...fellBackToGeneric],
65
75
  unchangedMaterials: [...unchanged],
66
76
  renamed,
77
+ presets: applied,
78
+ missingPresets: [...missing],
67
79
  };
68
80
  }
@@ -0,0 +1,64 @@
1
+ import type { PrinterFilamentPresets } from "../profiles.js";
2
+ import { type FilamentNameTable } from "./filamentComplianceNames.js";
3
+ import type { JsonRecord } from "./types.js";
4
+ /** A slot that takes a preset's settings: its 0-based index, the preset, and the creator's values it replaces. */
5
+ export interface AppliedFilamentPreset {
6
+ slot: number;
7
+ preset: string;
8
+ changed: Array<{
9
+ key: string;
10
+ before: string;
11
+ after: string;
12
+ }>;
13
+ }
14
+ /** One preset's settings: the values the printer's presets share, with its own over them. Undefined when there are none. */
15
+ export declare function presetSettingsFor(presets: PrinterFilamentPresets | undefined, name: string): Record<string, string[]> | undefined;
16
+ /** What a slot's preset replaces: each setting whose standard value differs from the creator's. */
17
+ export declare function presetChanges(values: Record<string, string[]>, creator: (key: string) => unknown): AppliedFilamentPreset["changed"];
18
+ /**
19
+ * Writes each applied preset's settings into its slot: the project's per-filament lists (both values of a
20
+ * per-variant setting where the nozzle has a high-flow option) and the slot's embedded preset file. Runs after
21
+ * every other filament step, so nothing later overwrites it.
22
+ */
23
+ export declare function writeFilamentPresets(settings: JsonRecord, files: Record<string, JsonRecord>, applied: readonly AppliedFilamentPreset[], presets: PrinterFilamentPresets | undefined, slotCount: number): void;
24
+ /**
25
+ * What Snapmaker Orca's app resets a filament's unnamed settings to when it opens the file: the parent the file
26
+ * names for it, or else the installed preset of the same name (Preset.cpp, load_external_preset).
27
+ * - `preset`: a U1 preset whose settings the catalog holds: the slot's own, or the `parent` written for it.
28
+ * - `named`: a preset the Snapmaker or Generic option named whose settings the catalog lacks; the app uses its own.
29
+ * - `source`: no U1 preset fits, so the app resets to whatever preset of that name is installed, if any.
30
+ */
31
+ export type FilamentBase = {
32
+ kind: "preset";
33
+ values: Record<string, string[]>;
34
+ parent?: string;
35
+ } | {
36
+ kind: "named";
37
+ } | {
38
+ kind: "source";
39
+ };
40
+ /**
41
+ * Each slot's base. Under Original, a filament whose name isn't a U1 preset gets a U1 parent, the preset the
42
+ * Snapmaker option would choose (Snapmaker's own for the product line, or Generic where Snapmaker has none): the
43
+ * creator's name and values stay, and what the file doesn't name resets to a preset made for the U1 rather than
44
+ * to another printer's preset of the same name.
45
+ */
46
+ export declare function filamentBases(settings: JsonRecord, slotCount: number, presets: PrinterFilamentPresets | undefined, table: FilamentNameTable | undefined, printerId: string,
47
+ /** The Snapmaker or Generic option was chosen. */
48
+ option: boolean): FilamentBase[];
49
+ /**
50
+ * A slot whose base is a U1 preset, its own or its parent, takes that preset's G-code, the U1's own, so the app
51
+ * (which resets unnamed settings to the base's) and the command line (which uses the file's) run the same
52
+ * G-code, and neither calls it modified.
53
+ */
54
+ export declare function writeBaseGcode(settings: JsonRecord, files: Record<string, JsonRecord>, bases: readonly FilamentBase[], slotCount: number): void;
55
+ /**
56
+ * Each filament's entry in `different_settings_to_system` names the settings that differ from its base, and
57
+ * a parent goes in `inherits_group`. The app resets every setting an entry doesn't name to the base's value,
58
+ * which is the file's anyway, and warns about every G-code setting one names (PresetBundle.cpp,
59
+ * validate_presets), so an entry naming more than differs warns about G-code nobody changed. A filament no
60
+ * U1 preset fits names what the source file says the creator changed, what the conversion changed (its
61
+ * G-code, the U1's own, among them) and the printers it suits; every filament setting when the source's list
62
+ * can't be read.
63
+ */
64
+ export declare function listFilamentSettings(settings: JsonRecord, bases: readonly FilamentBase[], source: JsonRecord, slotCount: number): void;
@@ -0,0 +1,180 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * The Snapmaker and Generic filament options: a slot renamed to a preset Snapmaker Orca ships takes that
4
+ * preset's own settings, standard and high-flow values and its G-code included, so the file, Snapmaker Orca's
5
+ * app (which resets a filament whose name matches a shipped preset) and its command line (which uses the file's
6
+ * values) all agree. And each filament's entry in `different_settings_to_system` names the settings that differ
7
+ * from the preset the app resets that filament to, so the app keeps what the file says, the creator's values
8
+ * under Original included, and warns about G-code only where it really differs.
9
+ */
10
+ import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
11
+ import { FILAMENT_FLOW_VARIANT_KEYS } from "./applyFilamentFlowVariants.js";
12
+ import { resolveFilamentName } from "./filamentComplianceNames.js";
13
+ const VARIANT_KEYS = new Set(FILAMENT_FLOW_VARIANT_KEYS);
14
+ /** Filament settings that are project state rather than a preset's (Snapmaker Orca's presets hold no color), so never named. */
15
+ const PROJECT_STATE_KEYS = new Set(["filament_colour"]);
16
+ /**
17
+ * Named for a filament no U1 preset fits: the app resets it to an installed preset of the same name, and one made for
18
+ * another printer (Bambu's, say) lists only that maker's printers, so the filament couldn't be used with the U1.
19
+ */
20
+ const COMPATIBILITY_KEYS = ["compatible_printers"];
21
+ /** One preset's settings: the values the printer's presets share, with its own over them. Undefined when there are none. */
22
+ export function presetSettingsFor(presets, name) {
23
+ if (!presets || !Object.hasOwn(presets.presets, name))
24
+ return undefined;
25
+ return { ...presets.shared, ...presets.presets[name] };
26
+ }
27
+ const first = (value) => (Array.isArray(value) ? (value[0] === undefined ? undefined : String(value[0])) : value === undefined ? undefined : String(value));
28
+ /** What a slot's preset replaces: each setting whose standard value differs from the creator's. */
29
+ export function presetChanges(values, creator) {
30
+ const out = [];
31
+ for (const key of Object.keys(values).sort()) {
32
+ const before = first(creator(key));
33
+ const after = values[key][0];
34
+ if (before !== undefined && after !== undefined && before !== after)
35
+ out.push({ key, before, after });
36
+ }
37
+ return out;
38
+ }
39
+ /** Writes `values` into one slot: the project's per-filament lists, and the embedded preset file named `name`. */
40
+ function writeSlot(settings, files, slot, name, values, slotCount) {
41
+ for (const [key, value] of Object.entries(values)) {
42
+ const list = settings[key];
43
+ if (!Array.isArray(list))
44
+ continue;
45
+ const next = [...list];
46
+ if (VARIANT_KEYS.has(key) && next.length === slotCount * 2) {
47
+ next[slot * 2] = value[0];
48
+ next[slot * 2 + 1] = value[1] ?? value[0];
49
+ }
50
+ else if (next.length === slotCount) {
51
+ next[slot] = value[0];
52
+ }
53
+ else
54
+ continue;
55
+ settings[key] = next;
56
+ }
57
+ for (const cfg of Object.values(files)) {
58
+ if (cfg.name !== name)
59
+ continue;
60
+ for (const [key, value] of Object.entries(values)) {
61
+ const own = cfg[key];
62
+ // The embedded preset keeps its layout: one value where it holds one, the preset's own list otherwise.
63
+ cfg[key] = Array.isArray(own) && own.length === 1 ? [value[0]] : [...value];
64
+ }
65
+ }
66
+ }
67
+ /**
68
+ * Writes each applied preset's settings into its slot: the project's per-filament lists (both values of a
69
+ * per-variant setting where the nozzle has a high-flow option) and the slot's embedded preset file. Runs after
70
+ * every other filament step, so nothing later overwrites it.
71
+ */
72
+ export function writeFilamentPresets(settings, files, applied, presets, slotCount) {
73
+ for (const { slot, preset } of applied) {
74
+ const values = presetSettingsFor(presets, preset);
75
+ if (values)
76
+ writeSlot(settings, files, slot, preset, values, slotCount);
77
+ }
78
+ }
79
+ /**
80
+ * Each slot's base. Under Original, a filament whose name isn't a U1 preset gets a U1 parent, the preset the
81
+ * Snapmaker option would choose (Snapmaker's own for the product line, or Generic where Snapmaker has none): the
82
+ * creator's name and values stay, and what the file doesn't name resets to a preset made for the U1 rather than
83
+ * to another printer's preset of the same name.
84
+ */
85
+ export function filamentBases(settings, slotCount, presets, table, printerId,
86
+ /** The Snapmaker or Generic option was chosen. */
87
+ option) {
88
+ const names = Array.isArray(settings.filament_settings_id) ? settings.filament_settings_id : [];
89
+ const types = Array.isArray(settings.filament_type) ? settings.filament_type : [];
90
+ const offered = table && Object.hasOwn(table.printers, printerId) ? table.printers[printerId].presets : {};
91
+ return Array.from({ length: slotCount }, (_, i) => {
92
+ const name = typeof names[i] === "string" ? names[i] : "";
93
+ const own = presetSettingsFor(presets, name);
94
+ if (own)
95
+ return { kind: "preset", values: own };
96
+ if (Object.hasOwn(offered, name))
97
+ return option ? { kind: "named" } : { kind: "source" };
98
+ if (!table)
99
+ return { kind: "source" };
100
+ const parent = resolveFilamentName(table, printerId, typeof types[i] === "string" ? types[i] : "", name, "snapmaker").preset?.name;
101
+ const values = parent === undefined ? undefined : presetSettingsFor(presets, parent);
102
+ return values ? { kind: "preset", values, parent } : { kind: "source" };
103
+ });
104
+ }
105
+ /**
106
+ * A slot whose base is a U1 preset, its own or its parent, takes that preset's G-code, the U1's own, so the app
107
+ * (which resets unnamed settings to the base's) and the command line (which uses the file's) run the same
108
+ * G-code, and neither calls it modified.
109
+ */
110
+ export function writeBaseGcode(settings, files, bases, slotCount) {
111
+ const names = Array.isArray(settings.filament_settings_id) ? settings.filament_settings_id : [];
112
+ bases.forEach((base, slot) => {
113
+ const name = names[slot];
114
+ if (base.kind !== "preset" || typeof name !== "string")
115
+ return;
116
+ const gcode = Object.fromEntries(Object.entries(base.values).filter(([key]) => key.endsWith("_gcode")));
117
+ writeSlot(settings, files, slot, name, gcode, slotCount);
118
+ });
119
+ }
120
+ const text = (v) => (typeof v === "string" || typeof v === "number" || typeof v === "boolean" ? String(v) : undefined);
121
+ /** One slot's values of a filament setting: one per slot, or two (standard, high flow); undefined for any other layout. */
122
+ function slotValues(value, slot, slotCount) {
123
+ const values = !Array.isArray(value) ? [value] : value.length === slotCount * 2 ? value.slice(slot * 2, slot * 2 + 2) : value.length === slotCount ? [value[slot]] : undefined;
124
+ const out = values?.map(text);
125
+ return out?.every((v) => v !== undefined) ? out : undefined;
126
+ }
127
+ /** Whether two value lists mean the same, one value standing for both variants as Snapmaker Orca reads it. */
128
+ function sameValues(a, b) {
129
+ if (!a || !b)
130
+ return false;
131
+ if (a.length === b.length)
132
+ return a.every((v, i) => v === b[i]);
133
+ if (a.length === 1)
134
+ return b.every((v) => v === a[0]);
135
+ return b.length === 1 && a.every((v) => v === b[0]);
136
+ }
137
+ /** The settings the source file says the creator changed in one filament; null when its list can't be read for that slot. */
138
+ function sourceEntry(source, slot, slotCount) {
139
+ const list = source.different_settings_to_system;
140
+ if (!Array.isArray(list) || list.length !== slotCount + 2)
141
+ return null;
142
+ const entry = list[slot + 1];
143
+ return typeof entry === "string" ? entry.split(";") : null;
144
+ }
145
+ /**
146
+ * Each filament's entry in `different_settings_to_system` names the settings that differ from its base, and
147
+ * a parent goes in `inherits_group`. The app resets every setting an entry doesn't name to the base's value,
148
+ * which is the file's anyway, and warns about every G-code setting one names (PresetBundle.cpp,
149
+ * validate_presets), so an entry naming more than differs warns about G-code nobody changed. A filament no
150
+ * U1 preset fits names what the source file says the creator changed, what the conversion changed (its
151
+ * G-code, the U1's own, among them) and the printers it suits; every filament setting when the source's list
152
+ * can't be read.
153
+ */
154
+ export function listFilamentSettings(settings, bases, source, slotCount) {
155
+ if (slotCount < 1)
156
+ return;
157
+ const keys = Object.keys(settings)
158
+ .filter((k) => Object.hasOwn(SETTINGS_CATALOG, k) && SETTINGS_CATALOG[k].group === "filament" && !PROJECT_STATE_KEYS.has(k))
159
+ .sort();
160
+ const known = new Set(keys);
161
+ const entries = Array.from({ length: slotCount }, (_, slot) => {
162
+ const base = bases[slot] ?? { kind: "source" };
163
+ if (base.kind === "named")
164
+ return "";
165
+ const values = (key) => slotValues(settings[key], slot, slotCount);
166
+ if (base.kind === "preset")
167
+ return keys.filter((k) => !sameValues(values(k), Object.hasOwn(base.values, k) ? base.values[k] : undefined)).join(";");
168
+ const creator = sourceEntry(source, slot, slotCount);
169
+ const named = creator === null ? keys : [...creator.filter((k) => known.has(k)), ...keys.filter((k) => !sameValues(slotValues(source[k], slot, slotCount), values(k)))];
170
+ return [...new Set([...named, ...COMPATIBILITY_KEYS])].sort().join(";");
171
+ });
172
+ const current = Array.isArray(settings.different_settings_to_system) ? settings.different_settings_to_system : [];
173
+ const print = typeof current[0] === "string" ? current[0] : "";
174
+ const last = current.length >= 2 ? current[current.length - 1] : undefined;
175
+ const printer = typeof last === "string" ? last : "";
176
+ settings.different_settings_to_system = [print, ...entries, printer];
177
+ const parents = bases.map((base) => (base.kind === "preset" && base.parent !== undefined ? base.parent : ""));
178
+ if (parents.some((parent) => parent !== ""))
179
+ settings.inherits_group = ["", ...parents, ""];
180
+ }
@@ -6,6 +6,7 @@ import { coerceValue } from "./coerceValue.js";
6
6
  import { collapseNozzleVariants } from "./collapseNozzleVariants.js";
7
7
  import { detectVariantIndex } from "./detectVariantIndex.js";
8
8
  import { jsonEqual } from "./internal/jsonEqual.js";
9
+ import { PRINTER_KEYS_KEPT } from "./policy.js";
9
10
  import { resolveMinIfLower } from "./resolveMinIfLower.js";
10
11
  import { stripBambuOnlyNozzleVariantKeys } from "./stripBambuOnlyNozzleVariantKeys.js";
11
12
  /** Bambu/Orca both store this as an array whose first element is a `;`-joined key list (remaining elements are unused padding). */
@@ -153,7 +154,8 @@ release) {
153
154
  //
154
155
  // A stock baseline has no list of its own (Snapmaker Orca writes none
155
156
  // for an unmodified project), so one is created with Orca's layout: the
156
- // print entry, one entry per filament, then the printer entry.
157
+ // print entry, one entry per filament, then the printer entry, which
158
+ // names the printer settings the file keeps (PRINTER_KEYS_KEPT).
157
159
  const allKeys = Object.keys(newSettings)
158
160
  .filter((k) => k !== "different_settings_to_system")
159
161
  .sort();
@@ -161,7 +163,7 @@ release) {
161
163
  const filamentCount = Array.isArray(newSettings.filament_colour) ? newSettings.filament_colour.length : 1;
162
164
  newSettings.different_settings_to_system = Array.isArray(diffs)
163
165
  ? [allKeys.join(";"), ...diffs.slice(1)]
164
- : [allKeys.join(";"), ...Array.from({ length: filamentCount }, () => ""), ""];
166
+ : [allKeys.join(";"), ...Array.from({ length: filamentCount }, () => ""), PRINTER_KEYS_KEPT.join(";")];
165
167
  return {
166
168
  newSettings,
167
169
  changedKeys,
@@ -20,3 +20,11 @@ export declare const MACHINE_SETTINGS_KEYS: readonly string[];
20
20
  export declare function isGcodeKey(key: string): boolean;
21
21
  /** Filament keys that always keep the U1 profile's value, besides every G-code key (see {@link isGcodeKey}). */
22
22
  export declare const FILAMENT_KEY_BLOCKLIST: readonly string[];
23
+ /**
24
+ * Printer settings named in the printer's entry of `different_settings_to_system`, so Snapmaker Orca's app keeps
25
+ * the file's value: it resets every printer setting the entry doesn't name to the installed printer preset's, and
26
+ * that preset can change without a release (Snapmaker updates its profiles through the app). `nozzle_type`: the
27
+ * file records the U1's stock stainless 0.4 and the hardened 0.6, or hardened nozzles when the user says so, where
28
+ * Snapmaker's presets have the 0.4 and 0.6 swapped. A named value equal to the preset's changes nothing.
29
+ */
30
+ export declare const PRINTER_KEYS_KEPT: readonly string[];
@@ -273,3 +273,11 @@ export const FILAMENT_KEY_BLOCKLIST = [
273
273
  "compatible_prints",
274
274
  "compatible_prints_condition",
275
275
  ];
276
+ /**
277
+ * Printer settings named in the printer's entry of `different_settings_to_system`, so Snapmaker Orca's app keeps
278
+ * the file's value: it resets every printer setting the entry doesn't name to the installed printer preset's, and
279
+ * that preset can change without a release (Snapmaker updates its profiles through the app). `nozzle_type`: the
280
+ * file records the U1's stock stainless 0.4 and the hardened 0.6, or hardened nozzles when the user says so, where
281
+ * Snapmaker's presets have the 0.4 and 0.6 swapped. A named value equal to the preset's changes nothing.
282
+ */
283
+ export const PRINTER_KEYS_KEPT = ["nozzle_type"];
@@ -1,5 +1,6 @@
1
1
  import type { ConvertRequest, ConvertResponse } from "../schema.js";
2
2
  import type { FilamentNameTable } from "./filamentComplianceNames.js";
3
+ import type { PrinterFilamentPresets } from "../profiles.js";
3
4
  import { type ResolvedAboveStockChoice } from "./aboveStock.js";
4
5
  import type { JsonRecord } from "./types.js";
5
6
  import { type ChangeItem, type ChangeReason } from "../explain/whatChanged.js";
@@ -18,6 +19,8 @@ export interface ConvertProfile {
18
19
  highFlowSupported?: boolean;
19
20
  /** The catalog's filament names for the Snapmaker/Generic naming options (index.json `filamentNames`). Absent: those options leave names as they are and say so. */
20
21
  filamentNames?: FilamentNameTable;
22
+ /** The settings of this printer's filament presets, for the Snapmaker/Generic naming options; loaded only when one is used. Absent: those options change names only. */
23
+ filamentPresets?: PrinterFilamentPresets;
21
24
  };
22
25
  profile: {
23
26
  /** The Snapmaker Orca release the profile is for, e.g. "2.4.1": what a value is checked against. Absent: the newest. */
@@ -1,4 +1,6 @@
1
1
  import { applyFilamentComplianceMode } from "./applyFilamentComplianceMode.js";
2
+ import { labelOf } from "../diff/diffSettings.js";
3
+ import { filamentBases, listFilamentSettings, writeBaseGcode, writeFilamentPresets } from "./applyFilamentPresets.js";
2
4
  import { EXTRA_PROJECT_LEVEL_FILAMENT_KEYS } from "./constants.js";
3
5
  import { buildFilamentConfigs } from "./buildFilamentConfigs.js";
4
6
  import { clampColorPenetration } from "./clampColorPenetration.js";
@@ -64,12 +66,17 @@ export function runConvertPipeline(profile, request, application, options = {})
64
66
  let filamentComplianceFallback;
65
67
  let filamentComplianceUnchanged;
66
68
  let renamedFilaments = [];
69
+ let appliedPresets = [];
67
70
  if (request.filamentComplianceMode) {
68
71
  // Preset names exist per nozzle size, so they follow the target printer, not the source's nozzle.
69
- const applied = applyFilamentComplianceMode(slots, filamentKeyArrays, request.filamentComplianceMode, printer.filamentNames, printer.id);
72
+ const applied = applyFilamentComplianceMode(slots, filamentKeyArrays, request.filamentComplianceMode, printer.filamentNames, printer.id, printer.filamentPresets);
70
73
  slots = applied.slots;
71
74
  filamentKeyArrays = applied.filamentKeyArrays;
72
75
  renamedFilaments = applied.renamed;
76
+ appliedPresets = applied.presets;
77
+ if (applied.missingPresets.length > 0) {
78
+ warnings.push(` WARN: the profile catalog has no settings for ${applied.missingPresets.join(", ")}, so only ${applied.missingPresets.length === 1 ? "its name" : "their names"} changed. Update the profile catalog.`);
79
+ }
73
80
  if (applied.fellBackToGenericMaterials.length > 0)
74
81
  filamentComplianceFallback = applied.fellBackToGenericMaterials;
75
82
  if (applied.unchangedMaterials.length > 0)
@@ -77,6 +84,9 @@ export function runConvertPipeline(profile, request, application, options = {})
77
84
  if (!printer.filamentNames) {
78
85
  warnings.push(" WARN: this profile catalog has no filament names, so filament names were left as they are. Update the profile catalog.");
79
86
  }
87
+ else if (!printer.filamentPresets) {
88
+ warnings.push(" WARN: this profile catalog has no filament preset settings, so only the filament names changed; Snapmaker Orca uses the presets' own settings when it opens the file. Update the profile catalog.");
89
+ }
80
90
  }
81
91
  const { files: filamentFiles } = buildFilamentConfigs(slots, p.filamentShapeConfig, p.filamentKeyBlocklist);
82
92
  // High-flow hotends (request.highFlowHotends): which toolheads have the
@@ -132,14 +142,28 @@ export function runConvertPipeline(profile, request, application, options = {})
132
142
  ...(filamentComplianceFallback ? [`Generic for ${filamentComplianceFallback.join(", ")}`] : []),
133
143
  ...(filamentComplianceUnchanged ? [`kept the creator's name for ${filamentComplianceUnchanged.join(", ")} (no Snapmaker or Generic preset for this nozzle size)`] : []),
134
144
  ];
145
+ const kind = request.filamentComplianceMode === "generic" ? "Generic" : "Snapmaker";
135
146
  tracker.add("yours", {
136
- label: `Filament names relabeled to ${request.filamentComplianceMode === "generic" ? "Generic" : "Snapmaker"} presets (names only, never temperatures or flow)`,
147
+ label: printer.filamentPresets
148
+ ? `Filaments set to ${kind} presets Snapmaker Orca ships, with those presets' own settings; colors and order kept`
149
+ : `Filament names relabeled to ${kind} presets (names only: this catalog has no preset settings)`,
137
150
  before: null,
138
151
  after: null,
139
152
  ...(notes.length > 0 ? { note: notes.join("; ") } : {}),
140
153
  });
141
154
  for (const r of renamedFilaments)
142
155
  tracker.add("yours", { label: `Filament ${r.slot + 1} name`, before: r.before || null, after: r.after });
156
+ for (const a of appliedPresets) {
157
+ if (a.changed.length === 0)
158
+ continue;
159
+ const shown = a.changed.slice(0, 3).map((c) => `${labelOf(c.key)} ${c.before} -> ${c.after}`).join(", ");
160
+ tracker.add("yours", {
161
+ label: `Filament ${a.slot + 1} uses ${a.preset}'s settings`,
162
+ before: null,
163
+ after: null,
164
+ note: `instead of the creator's: ${shown}${a.changed.length > 3 ? ` and ${a.changed.length - 3} more` : ""}`,
165
+ });
166
+ }
143
167
  }
144
168
  if (useStock.size > 0) {
145
169
  tracker.step(mergedSettings, because("yours", "you chose Snapmaker's stock value"), () => {
@@ -202,6 +226,12 @@ export function runConvertPipeline(profile, request, application, options = {})
202
226
  const { shifts, plateOrigins, warnings: shiftWarnings } = computeShifts(request.objects, printer.printableArea, Number.isFinite(bambuClearanceRadius) ? bambuClearanceRadius : null, printer.extruderClearanceRadius, request.plateCount);
203
227
  warnings.push(...shiftWarnings);
204
228
  addShiftItems(tracker, request.objects, shifts);
229
+ // Last of the filament steps: the chosen presets' settings, each U1 base preset's G-code, then each filament's
230
+ // changed settings named against the preset Snapmaker Orca resets it to, so it keeps what the file says.
231
+ writeFilamentPresets(newSettings, filamentFiles, appliedPresets, printer.filamentPresets, slotCount);
232
+ const bases = filamentBases(newSettings, slotCount, printer.filamentPresets, printer.filamentNames, printer.id, Boolean(request.filamentComplianceMode));
233
+ writeBaseGcode(newSettings, filamentFiles, bases, slotCount);
234
+ listFilamentSettings(newSettings, bases, request.projectSettings, slotCount);
205
235
  const configFiles = { ...filamentFiles };
206
236
  // `warnings` mixes routine per-conversion bookkeeping (e.g. computeShifts'
207
237
  // "true geometric center -> target" line, which fires on every plate
@@ -220,6 +250,7 @@ export function runConvertPipeline(profile, request, application, options = {})
220
250
  application,
221
251
  ...(filamentComplianceFallback ? { filamentComplianceFallback } : {}),
222
252
  ...(filamentComplianceUnchanged ? { filamentComplianceUnchanged } : {}),
253
+ ...(appliedPresets.length > 0 ? { filamentPresets: appliedPresets.map((a) => ({ slot: a.slot + 1, preset: a.preset, changed: a.changed })) } : {}),
223
254
  ...(userFacingWarnings.length > 0 ? { warnings: userFacingWarnings } : {}),
224
255
  },
225
256
  warnings,
@@ -0,0 +1,7 @@
1
+ import type { ConvertReport } from "../project.js";
2
+ /**
3
+ * What the Snapmaker or Generic filament option did, one sentence per note: which filaments use a preset's own
4
+ * settings and what that replaced, which use Generic because Snapmaker makes no preset for them, and which kept
5
+ * the creator's name and settings because no preset fits. Empty when the option wasn't used or changed nothing.
6
+ */
7
+ export declare function filamentNotes(report: Pick<ConvertReport, "filamentPresets" | "filamentComplianceFallback" | "filamentComplianceUnchanged">): string[];
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * The filament naming options' notes for a conversion, in words: the one wording the web app, the command line
4
+ * and any other UI show, so they always say the same thing.
5
+ */
6
+ import { plainText } from "../plainText.js";
7
+ /** A value quoted from someone's file: no control or direction codes, and short, whatever the file held. */
8
+ const quoted = (value) => {
9
+ const clean = plainText(value);
10
+ return clean.length > 24 ? `${clean.slice(0, 23)}…` : clean;
11
+ };
12
+ /** The settings a note names first, in this order, with how people say them and their unit. */
13
+ const NAMED = [
14
+ ["nozzle_temperature", "nozzle temperature", " °C"],
15
+ ["nozzle_temperature_initial_layer", "first-layer nozzle temperature", " °C"],
16
+ ["filament_flow_ratio", "flow ratio", ""],
17
+ ["filament_max_volumetric_speed", "max volumetric speed", " mm³/s"],
18
+ ["pressure_advance", "pressure advance", ""],
19
+ ["filament_retraction_length", "retraction length", " mm"],
20
+ ["hot_plate_temp", "bed temperature (smooth PEI)", " °C"],
21
+ ["textured_plate_temp", "bed temperature (textured PEI)", " °C"],
22
+ ["fan_max_speed", "max fan speed", "%"],
23
+ ];
24
+ const list = (items) => (items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`);
25
+ /**
26
+ * What the Snapmaker or Generic filament option did, one sentence per note: which filaments use a preset's own
27
+ * settings and what that replaced, which use Generic because Snapmaker makes no preset for them, and which kept
28
+ * the creator's name and settings because no preset fits. Empty when the option wasn't used or changed nothing.
29
+ */
30
+ export function filamentNotes(report) {
31
+ const notes = [];
32
+ const byPreset = new Map();
33
+ for (const p of report.filamentPresets ?? [])
34
+ byPreset.set(p.preset, [...(byPreset.get(p.preset) ?? []), p]);
35
+ for (const [preset, slots] of byPreset) {
36
+ const changed = slots.find((s) => s.changed.length > 0)?.changed ?? [];
37
+ const which = `${slots.length === 1 ? "Filament" : "Filaments"} ${list(slots.map((s) => String(s.slot)))}`;
38
+ if (changed.length === 0) {
39
+ notes.push(`${which} ${slots.length === 1 ? "uses" : "use"} ${preset}'s own settings, which match the creator's.`);
40
+ continue;
41
+ }
42
+ // The settings people know by name first; the rest as a count.
43
+ const named = NAMED.flatMap(([key, name, unit]) => {
44
+ const c = changed.find((x) => x.key === key);
45
+ return c && c.before !== "nil" && c.after !== "nil" ? [`${name} ${quoted(c.before)}${unit} → ${quoted(c.after)}${unit}`] : [];
46
+ }).slice(0, 3);
47
+ const rest = changed.length - named.length;
48
+ const others = `${rest} other setting${rest === 1 ? "" : "s"}`;
49
+ const what = named.length === 0 ? others : rest > 0 ? `${named.join(", ")}, and ${others}` : list(named);
50
+ notes.push(`${which} ${slots.length === 1 ? "uses" : "use"} ${preset}'s own settings instead of the creator's: ${what}.`);
51
+ }
52
+ const fallback = report.filamentComplianceFallback ?? [];
53
+ if (fallback.length > 0)
54
+ notes.push(`Snapmaker makes no preset for ${list(fallback)} at this nozzle size, so ${fallback.length === 1 ? "it uses" : "those use"} Generic.`);
55
+ const unchanged = report.filamentComplianceUnchanged ?? [];
56
+ if (unchanged.length > 0) {
57
+ notes.push(`No Snapmaker or Generic preset fits ${list(unchanged)} at this nozzle size, so ${unchanged.length === 1 ? "its name and settings stay" : "their names and settings stay"} as the creator had them. Snapmaker Space may refuse this file.`);
58
+ }
59
+ return notes;
60
+ }
@@ -119,7 +119,8 @@ export class ChangeTracker {
119
119
  const gcode = key.endsWith("_gcode");
120
120
  if (!info || (info.group === "filament" && !gcode) || !Object.hasOwn(stock, key) || !Object.hasOwn(output, key))
121
121
  continue;
122
- if (sameSetting(source[key], stock[key]) || !sameSetting(output[key], stock[key]))
122
+ // All G-code in the file is the U1's own: Snapmaker's stock, or that of the U1 preset a filament takes it from.
123
+ if (gcode ? sameSetting(source[key], output[key]) : sameSetting(source[key], stock[key]) || !sameSetting(output[key], stock[key]))
123
124
  continue;
124
125
  if (info.group === "machine" || gcode) {
125
126
  printerSettings++;
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * `any2orca/worker`.
11
11
  */
12
12
  export { convert, inspect, openProject, matchProfile, unwrapBundle, Project, CONVERT_STAGES } from "./project.js";
13
- export type { ConvertOptions, ConvertReport, ConvertResult, ConvertStage, KnownConvertStage, OpenOptions, ProfileChoice, ReportFilament } from "./project.js";
13
+ export type { ConvertOptions, ConvertReport, ConvertResult, ConvertStage, KnownConvertStage, OpenOptions, ProfileChoice, ReportFilament, ReportFilamentPreset } from "./project.js";
14
14
  export { DEFAULT_MAX_UNPACKED_BYTES, LARGE_PROJECT_BYTES, MAX_UNPACKED_BYTES_LIMIT } from "./archive/safeUnzip.js";
15
15
  export { SOURCE_VENDORS } from "./inspect.js";
16
16
  export type { FilamentSlotInfo, Inspection, KnownSourceVendor, SourceVendor } from "./inspect.js";
@@ -35,6 +35,7 @@ export type { DiffAttention, DiffGroup, DiffGroupName, DiffOptions, DiffRow, Dif
35
35
  export { diffReference, presetDiffSide, stockDiffSide } from "./diff/reference.js";
36
36
  export type { SettingGroup, SettingInfo } from "./diff/settingsCatalog.js";
37
37
  export { formatWhatChanged, CHANGE_REASONS } from "./explain/whatChanged.js";
38
+ export { filamentNotes } from "./explain/filamentNotes.js";
38
39
  export type { ChangeGroup, ChangeItem, ChangeReason, KnownChangeReason, WhatChanged } from "./explain/whatChanged.js";
39
40
  export { extractPreset } from "./presets/extractPreset.js";
40
41
  export { parsePresetFile, serializePresets, resolvePreset, withoutChanges, MAX_PRESET_NAME_LENGTH, MAX_PRESETS_PER_FILE, MAX_PRESETS_FILE_BYTES } from "./presets/preset.js";
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ export { diffSettings, DIFF_ATTENTIONS, DIFF_STATUSES } from "./diff/diffSetting
23
23
  export { valueLayoutNotes, VALUE_LAYOUTS } from "./diff/valueLayout.js";
24
24
  export { diffReference, presetDiffSide, stockDiffSide } from "./diff/reference.js";
25
25
  export { formatWhatChanged, CHANGE_REASONS } from "./explain/whatChanged.js";
26
+ export { filamentNotes } from "./explain/filamentNotes.js";
26
27
  export { extractPreset } from "./presets/extractPreset.js";
27
28
  export { parsePresetFile, serializePresets, resolvePreset, withoutChanges, MAX_PRESET_NAME_LENGTH, MAX_PRESETS_PER_FILE, MAX_PRESETS_FILE_BYTES } from "./presets/preset.js";
28
29
  export { buildStatsEvent, parseStatsEvent, receiveStatsEvent, resolveStatsConsent, STATS_MATCH_SOURCES } from "./telemetry.js";
package/dist/inspect.d.ts CHANGED
@@ -62,7 +62,7 @@ export interface Inspection {
62
62
  * PrusaSlicer 2.9 places its beds in rings with a gap of at most 100 mm, later rows at positive Y. Absent: use that grid.
63
63
  */
64
64
  sourcePlateOrigins?: Record<number, [number, number]>;
65
- /** Non-fatal notes from reading the file. */
65
+ /** Non-fatal notes from reading the file. Their wording can change in any release: check whether there are any, not what they say. */
66
66
  warnings: string[];
67
67
  /**
68
68
  * The project's unpacked size in bytes. Above 1 GB, converting takes a minute or two and a few GB of
package/dist/node.js CHANGED
@@ -10,7 +10,7 @@
10
10
  import { readFile, stat } from "node:fs/promises";
11
11
  import { createRequire } from "node:module";
12
12
  import { dirname, join, resolve } from "node:path";
13
- import { isReleasePath, isSourcePath, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, MAX_SOURCE_BYTES, parseCatalogJson, ProfileDataError } from "./profiles.js";
13
+ import { FILAMENT_PRESETS_PATH, isReleasePath, isSourcePath, MAX_FILAMENT_PRESETS_BYTES, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, MAX_SOURCE_BYTES, parseCatalogJson, ProfileDataError } from "./profiles.js";
14
14
  async function readCapped(path, maxBytes) {
15
15
  let size;
16
16
  try {
@@ -42,6 +42,7 @@ export function dirProfileSource(dir) {
42
42
  throw new ProfileDataError(`Not a source data file: ${JSON.stringify(path.slice(0, 60))}.`);
43
43
  return readCapped(join(root, ...path.split("/")), MAX_SOURCE_BYTES);
44
44
  },
45
+ readFilamentPresets: () => readCapped(join(root, FILAMENT_PRESETS_PATH), MAX_FILAMENT_PRESETS_BYTES),
45
46
  release: (path) => {
46
47
  // releases/<digits.digits.digits> only, so this stays in root too.
47
48
  if (!isReleasePath(path))
@@ -43,6 +43,13 @@ export interface ProfileSource {
43
43
  * then converted with every mapped setting treated as changed.
44
44
  */
45
45
  readSource?(path: string): Promise<unknown>;
46
+ /**
47
+ * The catalog's filament presets file (`filament-presets.json`, named by the index): the settings of every
48
+ * filament preset Snapmaker Orca installs for each printer, which the Snapmaker and Generic filament options
49
+ * write. Only called when a conversion uses one of those options. Leave it out for a source without the file:
50
+ * those options then change filament names only.
51
+ */
52
+ readFilamentPresets?(): Promise<unknown>;
46
53
  }
47
54
  /** True for a path a {@link ProfileSource.release} may be asked for. */
48
55
  export declare function isReleasePath(path: string): boolean;
@@ -52,6 +59,10 @@ export declare const MAX_INDEX_BYTES: number;
52
59
  export declare const MAX_PROFILE_BYTES: number;
53
60
  /** A source-slicer bundle file (a vendor's print presets, unresolved) is a few hundred KB; this bounds a hostile one. */
54
61
  export declare const MAX_SOURCE_BYTES: number;
62
+ /** A filament presets file is a few hundred KB; this bounds a hostile one. */
63
+ export declare const MAX_FILAMENT_PRESETS_BYTES: number;
64
+ /** The only name the index may give the filament presets file. */
65
+ export declare const FILAMENT_PRESETS_PATH = "filament-presets.json";
55
66
  /** Where the index may point for source-slicer data: `sources/prusaslicer/<Vendor>.json` only. */
56
67
  export declare const SOURCE_PATH: RegExp;
57
68
  export declare function isSourcePath(path: string): boolean;
@@ -113,6 +124,7 @@ export declare const ProfileIndexSchema: z.ZodObject<{
113
124
  }, z.core.$strip>>;
114
125
  }, z.core.$strip>>;
115
126
  }, z.core.$strip>>;
127
+ filamentPresets: z.ZodOptional<z.ZodLiteral<"filament-presets.json">>;
116
128
  releases: z.ZodOptional<z.ZodArray<z.ZodObject<{
117
129
  version: z.ZodString;
118
130
  application: z.ZodString;
@@ -129,6 +141,17 @@ export declare const ProfileIndexSchema: z.ZodObject<{
129
141
  }, z.core.$strip>>;
130
142
  }, z.core.$strip>>;
131
143
  }, z.core.$strip>;
144
+ export declare const FilamentPresetsSchema: z.ZodObject<{
145
+ printers: z.ZodRecord<z.ZodString, z.ZodObject<{
146
+ shared: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
147
+ presets: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
148
+ }, z.core.$strip>>;
149
+ }, z.core.$strip>;
150
+ /** One printer's filament presets: the values they share, and each preset's own, by preset name. */
151
+ export interface PrinterFilamentPresets {
152
+ shared: Record<string, string[]>;
153
+ presets: Record<string, Record<string, string[]>>;
154
+ }
132
155
  /** A printer the catalog has profiles for. */
133
156
  export interface ProfileIndexPrinter {
134
157
  id: string;
@@ -182,6 +205,8 @@ export interface ProfileIndex {
182
205
  retired: RetiredProfile[];
183
206
  /** Filament preset names for the Snapmaker/Generic naming options, per printer. */
184
207
  filamentNames?: FilamentNameTable;
208
+ /** The filament presets file, when the catalog has one: always `filament-presets.json`. */
209
+ filamentPresets?: "filament-presets.json";
185
210
  /** Every Snapmaker Orca release this catalog holds, newest first. Absent in a catalog with one release. */
186
211
  releases?: ProfileIndexRelease[];
187
212
  /** Source-slicer data the catalog holds, independent of the Snapmaker Orca release. Absent in older data. */
@@ -250,6 +275,8 @@ export interface LoadedProfile {
250
275
  export interface CatalogEngine {
251
276
  load(id: string): Promise<LoadedProfile>;
252
277
  prusaBundle(vendor: string, slicerVersion: string): Promise<PrusaBundle | null>;
278
+ /** The filament presets, by printer id; null when the catalog or its source has none. */
279
+ filamentPresets(): Promise<Record<string, PrinterFilamentPresets> | null>;
253
280
  }
254
281
  /** For tests: gives a stand-in catalog an engine side. */
255
282
  export declare function withCatalogEngine<T extends object>(catalog: T, engine: Partial<CatalogEngine>): T;
@@ -272,6 +299,7 @@ export declare class ProfileCatalog {
272
299
  private readonly cache;
273
300
  private readonly releaseCatalogs;
274
301
  private readonly bundles;
302
+ private filamentPresetsPending;
275
303
  constructor(index: ProfileIndex, source: ProfileSource);
276
304
  /** Every profile, or only one nozzle size's, sorted by nozzle size and then layer height (finest first). */
277
305
  list(filter?: {
@@ -291,6 +319,8 @@ export declare class ProfileCatalog {
291
319
  * catalog doesn't list it or its source can't read source data.
292
320
  */
293
321
  private prusaBundle;
322
+ /** The filament presets, loaded and checked once; null when the index names none or the source can't read it. */
323
+ private filamentPresets;
294
324
  /** The live profile that replaced a retired id, if `id` was retired. */
295
325
  retiredSuccessor(id: string): RetiredProfile | undefined;
296
326
  /** The Snapmaker Orca releases this catalog holds, newest first. The first is the default. */
@@ -330,6 +360,8 @@ export interface MemoryCatalogData {
330
360
  releases?: Record<string, MemoryCatalogData>;
331
361
  /** Source-slicer data files by their index path (`sources/prusaslicer/<Vendor>.json`). */
332
362
  sources?: Record<string, unknown>;
363
+ /** The filament presets file's contents, when the index names one. */
364
+ filamentPresets?: unknown;
333
365
  }
334
366
  /** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
335
367
  export declare function memoryProfileSource(data: MemoryCatalogData): ProfileSource;
package/dist/profiles.js CHANGED
@@ -37,6 +37,10 @@ export const MAX_INDEX_BYTES = 1024 * 1024;
37
37
  export const MAX_PROFILE_BYTES = 8 * 1024 * 1024;
38
38
  /** A source-slicer bundle file (a vendor's print presets, unresolved) is a few hundred KB; this bounds a hostile one. */
39
39
  export const MAX_SOURCE_BYTES = 8 * 1024 * 1024;
40
+ /** A filament presets file is a few hundred KB; this bounds a hostile one. */
41
+ export const MAX_FILAMENT_PRESETS_BYTES = 8 * 1024 * 1024;
42
+ /** The only name the index may give the filament presets file. */
43
+ export const FILAMENT_PRESETS_PATH = "filament-presets.json";
40
44
  /** Where the index may point for source-slicer data: `sources/prusaslicer/<Vendor>.json` only. */
41
45
  export const SOURCE_PATH = /^sources\/prusaslicer\/[A-Za-z0-9]{1,64}-\d+\.\d+\.\d+\.json$/;
42
46
  export function isSourcePath(path) {
@@ -99,6 +103,8 @@ export const ProfileIndexSchema = z.object({
99
103
  retired: z.array(z.object({ id: ID, successorId: ID, displayName: NAME })).max(5000),
100
104
  /** Filament preset names for the Snapmaker/Generic naming options, per printer. */
101
105
  filamentNames: FilamentNamesSchema.optional(),
106
+ /** The filament presets file, when the catalog has one: always `filament-presets.json`. */
107
+ filamentPresets: z.literal(FILAMENT_PRESETS_PATH).optional(),
102
108
  /**
103
109
  * Every Snapmaker Orca release this catalog holds, newest first: this
104
110
  * index's own (`path` ".") and each older one's folder. Absent in a
@@ -126,6 +132,20 @@ export const ProfileIndexSchema = z.object({
126
132
  })
127
133
  .optional(),
128
134
  });
135
+ /** Keys that could reach an object's prototype when the shared values are merged into a preset. */
136
+ const UNSAFE_KEYS = new Set(["__proto__", "constructor", "prototype"]);
137
+ const safeKey = (max, pattern) => z.string().max(max).regex(pattern).refine((k) => !UNSAFE_KEYS.has(k), "not a usable key");
138
+ const presetSettings = z
139
+ .record(safeKey(100, /^[A-Za-z0-9_]{1,100}$/), z.array(z.string().max(20_000)).max(64))
140
+ .refine((r) => Object.keys(r).length <= 1000, "too many settings");
141
+ export const FilamentPresetsSchema = z.object({
142
+ printers: z
143
+ .record(ID.refine((k) => !UNSAFE_KEYS.has(k), "not a usable key"), z.object({
144
+ shared: presetSettings,
145
+ presets: z.record(presetText(200).refine((k) => !UNSAFE_KEYS.has(k), "not a usable key"), presetSettings).refine((r) => Object.keys(r).length <= 2000, "too many presets"),
146
+ }))
147
+ .refine((r) => Object.keys(r).length <= 500, "too many printers"),
148
+ });
129
149
  export const ProfileFileSchema = z.object({
130
150
  schema: z.literal(1),
131
151
  id: ID,
@@ -144,7 +164,7 @@ export const ProfileFileSchema = z.object({
144
164
  const ENGINES = new WeakMap();
145
165
  /** For tests: gives a stand-in catalog an engine side. */
146
166
  export function withCatalogEngine(catalog, engine) {
147
- ENGINES.set(catalog, { load: () => Promise.reject(new ProfileDataError("No profiles in this stand-in.")), prusaBundle: () => Promise.resolve(null), ...engine });
167
+ ENGINES.set(catalog, { load: () => Promise.reject(new ProfileDataError("No profiles in this stand-in.")), prusaBundle: () => Promise.resolve(null), filamentPresets: () => Promise.resolve(null), ...engine });
148
168
  return catalog;
149
169
  }
150
170
  /** The engine's access to a catalog. Kept off the class, so the public API holds only what a UI needs. */
@@ -179,8 +199,9 @@ export class ProfileCatalog {
179
199
  cache = new Map();
180
200
  releaseCatalogs = new Map();
181
201
  bundles = new Map();
202
+ filamentPresetsPending;
182
203
  constructor(index, source) {
183
- ENGINES.set(this, { load: (id) => this.load(id), prusaBundle: (vendor, slicerVersion) => this.prusaBundle(vendor, slicerVersion) });
204
+ ENGINES.set(this, { load: (id) => this.load(id), prusaBundle: (vendor, slicerVersion) => this.prusaBundle(vendor, slicerVersion), filamentPresets: () => this.filamentPresets() });
184
205
  this.index = index;
185
206
  this.source = source;
186
207
  if (index.releases) {
@@ -263,6 +284,20 @@ export class ProfileCatalog {
263
284
  }
264
285
  return pending;
265
286
  }
287
+ /** The filament presets, loaded and checked once; null when the index names none or the source can't read it. */
288
+ filamentPresets() {
289
+ if (this.index.filamentPresets !== FILAMENT_PRESETS_PATH || !this.source.readFilamentPresets)
290
+ return Promise.resolve(null);
291
+ this.filamentPresetsPending ??= this.source.readFilamentPresets().then((raw) => {
292
+ const parsed = FilamentPresetsSchema.safeParse(raw);
293
+ if (!parsed.success)
294
+ throw new ProfileDataError(`Profile catalog's ${FILAMENT_PRESETS_PATH} is malformed: ${describeIssues(parsed.error)}`);
295
+ return parsed.data.printers;
296
+ });
297
+ // A failed read isn't kept, so a transient fetch error can be retried.
298
+ this.filamentPresetsPending.catch(() => (this.filamentPresetsPending = undefined));
299
+ return this.filamentPresetsPending;
300
+ }
266
301
  /** The live profile that replaced a retired id, if `id` was retired. */
267
302
  retiredSuccessor(id) {
268
303
  if (this.byId.has(id))
@@ -461,6 +496,7 @@ export function fetchProfileSource(baseUrl, options = {}) {
461
496
  throw new ProfileDataError(`Not a source data file: ${JSON.stringify(path.slice(0, 60))}.`);
462
497
  return read(path, MAX_SOURCE_BYTES);
463
498
  },
499
+ readFilamentPresets: () => read(FILAMENT_PRESETS_PATH, MAX_FILAMENT_PRESETS_BYTES),
464
500
  };
465
501
  }
466
502
  /** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
@@ -481,6 +517,7 @@ export function memoryProfileSource(data) {
481
517
  },
482
518
  }
483
519
  : {}),
520
+ ...(data.filamentPresets !== undefined ? { readFilamentPresets: async () => data.filamentPresets } : {}),
484
521
  release: (path) => {
485
522
  if (!isReleasePath(path) || !data.releases || !Object.hasOwn(data.releases, path))
486
523
  throw new ProfileDataError(`No catalog data for ${plainVersion(path)}.`);
package/dist/project.d.ts CHANGED
@@ -105,7 +105,7 @@ export interface ConvertReport {
105
105
  profileNotes: string[];
106
106
  /** Set when `profileId` named a retired profile and its successor was used. */
107
107
  retiredProfile?: RetiredProfile;
108
- /** Notes worth showing the user, cleaned up for display. */
108
+ /** Notes worth showing the user, cleaned up for display. Their wording can change in any release: check whether there are any, not what they say. */
109
109
  warnings: string[];
110
110
  /** Every note the conversion produced, including routine ones, for logs and bug reports. */
111
111
  log: string[];
@@ -113,6 +113,12 @@ export interface ConvertReport {
113
113
  filamentComplianceFallback?: string[];
114
114
  /** Product lines (or materials) whose names stayed as the creator had them under `filamentComplianceMode`, because no Snapmaker or Generic preset fits. */
115
115
  filamentComplianceUnchanged?: string[];
116
+ /**
117
+ * Under `filamentComplianceMode`: each filament slot (1-based) set to a preset Snapmaker Orca ships, with that
118
+ * preset's own settings, and the creator's values it replaced (each setting's standard value, before and after).
119
+ * {@link filamentNotes} says it in words.
120
+ */
121
+ filamentPresets?: ReportFilamentPreset[];
116
122
  /** How far each object was moved, by object id. */
117
123
  shifts: Shifts;
118
124
  /**
@@ -137,6 +143,19 @@ export interface ConvertReport {
137
143
  notes: string[];
138
144
  };
139
145
  }
146
+ /** A filament slot set to a preset Snapmaker Orca ships, and the creator's values the preset replaced. */
147
+ export interface ReportFilamentPreset {
148
+ /** The slot, counting from 1 as slicers show them. */
149
+ slot: number;
150
+ /** The preset, e.g. "Snapmaker PLA SnapSpeed @U1". */
151
+ preset: string;
152
+ /** Each setting whose standard value differs from the creator's: the key, the creator's value, the preset's. */
153
+ changed: Array<{
154
+ key: string;
155
+ before: string;
156
+ after: string;
157
+ }>;
158
+ }
140
159
  export interface ConvertResult {
141
160
  /** The converted .3mf. */
142
161
  output: Uint8Array;
package/dist/project.js CHANGED
@@ -245,6 +245,9 @@ export class Project {
245
245
  }
246
246
  progress("loading-profile");
247
247
  const loaded = await catalogEngine(catalog).load(profileId);
248
+ // The Snapmaker and Generic filament options write the chosen presets' own settings; every option compares each
249
+ // filament with the preset Snapmaker Orca resets it to.
250
+ const filamentPresets = (await catalogEngine(catalog).filamentPresets())?.[loaded.convertProfile.printer.id];
248
251
  progress("merging");
249
252
  if (preset) {
250
253
  const sourceNozzle = detectNozzleDiameter(this.request.projectSettings);
@@ -260,7 +263,8 @@ export class Project {
260
263
  ...(highFlowHotends !== false ? { highFlowHotends } : {}),
261
264
  ...(options.hardenedNozzles === true ? { hardenedNozzles: true } : {}),
262
265
  };
263
- const pipeline = runConvertPipeline(loaded.convertProfile, request, catalog.index.slicer.application, {
266
+ const convertProfile = filamentPresets ? { ...loaded.convertProfile, printer: { ...loaded.convertProfile.printer, filamentPresets } } : loaded.convertProfile;
267
+ const pipeline = runConvertPipeline(convertProfile, request, catalog.index.slicer.application, {
264
268
  carrySourceLayerHeight,
265
269
  ...(preset ? { presetChanges: preset.changes } : {}),
266
270
  ...(aboveStock.keep.size + aboveStock.stock.size > 0 ? { aboveStock } : {}),
@@ -320,6 +324,7 @@ export class Project {
320
324
  log: [...this.parsed.warnings, ...routeWarnings, ...pipeline.warnings, ...applyWarnings].map((w) => w.trim()).filter(Boolean),
321
325
  ...(response.filamentComplianceFallback ? { filamentComplianceFallback: response.filamentComplianceFallback } : {}),
322
326
  ...(response.filamentComplianceUnchanged ? { filamentComplianceUnchanged: response.filamentComplianceUnchanged } : {}),
327
+ ...(response.filamentPresets ? { filamentPresets: response.filamentPresets } : {}),
323
328
  shifts: response.shifts,
324
329
  ...(response.plateOrigins ? { plateOrigins: Object.fromEntries(Object.entries(response.plateOrigins).map(([plate, origin]) => [Number(plate), origin])) } : {}),
325
330
  plates: Math.max(1, this.request.plateCount ?? 0, ...inspection.plates),
package/dist/schema.d.ts CHANGED
@@ -128,6 +128,15 @@ export declare const ConvertResponseSchema: z.ZodObject<{
128
128
  }, z.core.$strip>>;
129
129
  filamentComplianceFallback: z.ZodOptional<z.ZodArray<z.ZodString>>;
130
130
  filamentComplianceUnchanged: z.ZodOptional<z.ZodArray<z.ZodString>>;
131
+ filamentPresets: z.ZodOptional<z.ZodArray<z.ZodObject<{
132
+ slot: z.ZodNumber;
133
+ preset: z.ZodString;
134
+ changed: z.ZodArray<z.ZodObject<{
135
+ key: z.ZodString;
136
+ before: z.ZodString;
137
+ after: z.ZodString;
138
+ }, z.core.$strip>>;
139
+ }, z.core.$strip>>>;
131
140
  warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
132
141
  }, z.core.$strip>;
133
142
  export type ConvertResponse = z.infer<typeof ConvertResponseSchema>;
package/dist/schema.js CHANGED
@@ -92,6 +92,9 @@ export const ConvertResponseSchema = z.object({
92
92
  filamentComplianceFallback: z.array(z.string()).optional(),
93
93
  /** Product lines (or materials) whose names stayed as the creator had them under `filamentComplianceMode`, because no Snapmaker or Generic preset fits at this nozzle size. */
94
94
  filamentComplianceUnchanged: z.array(z.string()).optional(),
95
+ filamentPresets: z
96
+ .array(z.object({ slot: z.number().int().min(1), preset: z.string(), changed: z.array(z.object({ key: z.string(), before: z.string(), after: z.string() })) }))
97
+ .optional(),
95
98
  /** Notes worth showing the user (each contains "WARN"). */
96
99
  warnings: z.array(z.string()).optional(),
97
100
  });
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  // Written by scripts/sync-version.mjs from package.json; a test checks they match.
3
3
  // Typed as string, so a release doesn't change the public API's shape.
4
- export const VERSION = "0.9.2";
4
+ export const VERSION = "0.11.0";
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "any2orca",
3
- "version": "0.9.2",
3
+ "version": "0.11.0",
4
+ "outputAffecting": "Snapmaker Orca no longer warns about modified G-code when it opens a converted file, and a filament named like another printer's preset stays usable with the U1; Snapmaker Orca keeps the nozzle type a converted file records",
4
5
  "description": "Convert Bambu Studio, Creality Print, Anycubic Slicer Next, ElegooSlicer, Flash Studio, QIDI Studio and PrusaSlicer 3MF projects for the Snapmaker U1 (Snapmaker Orca), entirely on your own machine. Library, CLI and Web Worker in one package.",
5
6
  "keywords": [
6
7
  "3mf",
@@ -66,7 +67,7 @@
66
67
  "api": "node scripts/api-report.mjs"
67
68
  },
68
69
  "dependencies": {
69
- "any2orca-profiles": "0.3.1",
70
+ "any2orca-profiles": "0.4.0",
70
71
  "fflate": "0.8.3",
71
72
  "zod": "4.6.7"
72
73
  },
@@ -84,7 +85,7 @@
84
85
  },
85
86
  "homepage": "https://github.com/KuzuriAo/any2orca",
86
87
  "engines": {
87
- "node": ">=20"
88
+ "node": ">=22"
88
89
  },
89
90
  "bugs": {
90
91
  "url": "https://github.com/KuzuriAo/any2orca/issues"