any2orca 0.0.1 → 0.1.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.
Files changed (194) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +28 -0
  4. package/README.md +96 -3
  5. package/dist/archive/adaptModelSettings.d.ts +1 -0
  6. package/dist/archive/adaptModelSettings.js +50 -0
  7. package/dist/archive/filamentColorNames.d.ts +8 -0
  8. package/dist/archive/filamentColorNames.js +760 -0
  9. package/dist/archive/fmtNum.d.ts +14 -0
  10. package/dist/archive/fmtNum.js +21 -0
  11. package/dist/archive/internal/escapeRegExp.d.ts +2 -0
  12. package/dist/archive/internal/escapeRegExp.js +5 -0
  13. package/dist/archive/lookupFilamentColorName.d.ts +45 -0
  14. package/dist/archive/lookupFilamentColorName.js +57 -0
  15. package/dist/archive/objectWorldBboxXY.d.ts +2 -0
  16. package/dist/archive/objectWorldBboxXY.js +123 -0
  17. package/dist/archive/parseItemPositions.d.ts +6 -0
  18. package/dist/archive/parseItemPositions.js +17 -0
  19. package/dist/archive/parseObjectMetadata.d.ts +10 -0
  20. package/dist/archive/parseObjectMetadata.js +97 -0
  21. package/dist/archive/parsePlateAssignments.d.ts +6 -0
  22. package/dist/archive/parsePlateAssignments.js +18 -0
  23. package/dist/archive/parseVertices.d.ts +7 -0
  24. package/dist/archive/parseVertices.js +12 -0
  25. package/dist/archive/paths.d.ts +5 -0
  26. package/dist/archive/paths.js +6 -0
  27. package/dist/archive/recenterAssembleItems.d.ts +9 -0
  28. package/dist/archive/recenterAssembleItems.js +53 -0
  29. package/dist/archive/recenterBuildItems.d.ts +15 -0
  30. package/dist/archive/recenterBuildItems.js +51 -0
  31. package/dist/archive/safeUnzip.d.ts +26 -0
  32. package/dist/archive/safeUnzip.js +126 -0
  33. package/dist/archive/setApplicationMetadata.d.ts +13 -0
  34. package/dist/archive/setApplicationMetadata.js +18 -0
  35. package/dist/archive/shouldDropFromBambu.d.ts +29 -0
  36. package/dist/archive/shouldDropFromBambu.js +39 -0
  37. package/dist/archive/streamObjectVertices.d.ts +19 -0
  38. package/dist/archive/streamObjectVertices.js +57 -0
  39. package/dist/archive/tolerantJsonParse.d.ts +20 -0
  40. package/dist/archive/tolerantJsonParse.js +71 -0
  41. package/dist/archive/transform.d.ts +21 -0
  42. package/dist/archive/transform.js +39 -0
  43. package/dist/archive/unwrapBundle.d.ts +24 -0
  44. package/dist/archive/unwrapBundle.js +41 -0
  45. package/dist/archive/xmlBlocks.d.ts +10 -0
  46. package/dist/archive/xmlBlocks.js +31 -0
  47. package/dist/archive/zip.d.ts +29 -0
  48. package/dist/archive/zip.js +141 -0
  49. package/dist/cli/archiveMove.d.ts +15 -0
  50. package/dist/cli/archiveMove.js +41 -0
  51. package/dist/cli/commands/convert.d.ts +89 -0
  52. package/dist/cli/commands/convert.js +311 -0
  53. package/dist/cli/commands/diff.d.ts +21 -0
  54. package/dist/cli/commands/diff.js +112 -0
  55. package/dist/cli/commands/presets.d.ts +51 -0
  56. package/dist/cli/commands/presets.js +280 -0
  57. package/dist/cli/commands/profiles.d.ts +5 -0
  58. package/dist/cli/commands/profiles.js +26 -0
  59. package/dist/cli/commands/telemetry.d.ts +6 -0
  60. package/dist/cli/commands/telemetry.js +45 -0
  61. package/dist/cli/config.d.ts +18 -0
  62. package/dist/cli/config.js +50 -0
  63. package/dist/cli/expandWildcards.d.ts +17 -0
  64. package/dist/cli/expandWildcards.js +81 -0
  65. package/dist/cli/logger.d.ts +17 -0
  66. package/dist/cli/logger.js +36 -0
  67. package/dist/cli/main.d.ts +24 -0
  68. package/dist/cli/main.js +598 -0
  69. package/dist/cli/sameFile.d.ts +9 -0
  70. package/dist/cli/sameFile.js +40 -0
  71. package/dist/cli/stats.d.ts +34 -0
  72. package/dist/cli/stats.js +137 -0
  73. package/dist/cli/table.d.ts +8 -0
  74. package/dist/cli/table.js +18 -0
  75. package/dist/cli/terminalText.d.ts +7 -0
  76. package/dist/cli/terminalText.js +22 -0
  77. package/dist/cli/updateCheck.d.ts +14 -0
  78. package/dist/cli/updateCheck.js +78 -0
  79. package/dist/cli/watchState.d.ts +18 -0
  80. package/dist/cli/watchState.js +33 -0
  81. package/dist/cli.d.ts +1 -0
  82. package/dist/cli.js +10 -0
  83. package/dist/diff/diffSettings.d.ts +81 -0
  84. package/dist/diff/diffSettings.js +259 -0
  85. package/dist/diff/reference.d.ts +14 -0
  86. package/dist/diff/reference.js +22 -0
  87. package/dist/diff/settingsCatalog.d.ts +28 -0
  88. package/dist/diff/settingsCatalog.js +605 -0
  89. package/dist/diff/valueLayout.d.ts +20 -0
  90. package/dist/diff/valueLayout.js +65 -0
  91. package/dist/engine/aboveStock.d.ts +20 -0
  92. package/dist/engine/aboveStock.js +89 -0
  93. package/dist/engine/applyFilamentComplianceMode.d.ts +40 -0
  94. package/dist/engine/applyFilamentComplianceMode.js +68 -0
  95. package/dist/engine/applyFilamentFlowVariants.d.ts +42 -0
  96. package/dist/engine/applyFilamentFlowVariants.js +109 -0
  97. package/dist/engine/applyHighFlowHotends.d.ts +52 -0
  98. package/dist/engine/applyHighFlowHotends.js +115 -0
  99. package/dist/engine/applyPresetChanges.d.ts +12 -0
  100. package/dist/engine/applyPresetChanges.js +23 -0
  101. package/dist/engine/bedCenter.d.ts +19 -0
  102. package/dist/engine/bedCenter.js +34 -0
  103. package/dist/engine/buildFilamentConfigs.d.ts +18 -0
  104. package/dist/engine/buildFilamentConfigs.js +49 -0
  105. package/dist/engine/buildProjectSettings.d.ts +24 -0
  106. package/dist/engine/buildProjectSettings.js +164 -0
  107. package/dist/engine/carrySourceLayerHeight.d.ts +15 -0
  108. package/dist/engine/carrySourceLayerHeight.js +41 -0
  109. package/dist/engine/clampColorPenetration.d.ts +12 -0
  110. package/dist/engine/clampColorPenetration.js +28 -0
  111. package/dist/engine/clampToMachineLimits.d.ts +21 -0
  112. package/dist/engine/clampToMachineLimits.js +84 -0
  113. package/dist/engine/coerceValue.d.ts +15 -0
  114. package/dist/engine/coerceValue.js +56 -0
  115. package/dist/engine/collapseNozzleVariants.d.ts +31 -0
  116. package/dist/engine/collapseNozzleVariants.js +63 -0
  117. package/dist/engine/computeShifts.d.ts +12 -0
  118. package/dist/engine/computeShifts.js +339 -0
  119. package/dist/engine/constants.d.ts +11 -0
  120. package/dist/engine/constants.js +12 -0
  121. package/dist/engine/detectNozzleDiameter.d.ts +15 -0
  122. package/dist/engine/detectNozzleDiameter.js +29 -0
  123. package/dist/engine/detectVariantIndex.d.ts +39 -0
  124. package/dist/engine/detectVariantIndex.js +80 -0
  125. package/dist/engine/extractFilamentSlots.d.ts +18 -0
  126. package/dist/engine/extractFilamentSlots.js +88 -0
  127. package/dist/engine/filamentComplianceNames.d.ts +84 -0
  128. package/dist/engine/filamentComplianceNames.js +87 -0
  129. package/dist/engine/filamentVariantLayout.d.ts +29 -0
  130. package/dist/engine/filamentVariantLayout.js +38 -0
  131. package/dist/engine/fillFilamentSlots.d.ts +16 -0
  132. package/dist/engine/fillFilamentSlots.js +26 -0
  133. package/dist/engine/internal/jsonEqual.d.ts +2 -0
  134. package/dist/engine/internal/jsonEqual.js +5 -0
  135. package/dist/engine/parseTierName.d.ts +15 -0
  136. package/dist/engine/parseTierName.js +21 -0
  137. package/dist/engine/pickNearestProfile.d.ts +21 -0
  138. package/dist/engine/pickNearestProfile.js +24 -0
  139. package/dist/engine/pickProfile.d.ts +49 -0
  140. package/dist/engine/pickProfile.js +67 -0
  141. package/dist/engine/policy.d.ts +14 -0
  142. package/dist/engine/policy.js +266 -0
  143. package/dist/engine/remapBrimType.d.ts +30 -0
  144. package/dist/engine/remapBrimType.js +34 -0
  145. package/dist/engine/reshapeToCount.d.ts +15 -0
  146. package/dist/engine/reshapeToCount.js +27 -0
  147. package/dist/engine/resizeFlushVolumes.d.ts +27 -0
  148. package/dist/engine/resizeFlushVolumes.js +57 -0
  149. package/dist/engine/resolveMinIfLower.d.ts +21 -0
  150. package/dist/engine/resolveMinIfLower.js +59 -0
  151. package/dist/engine/runConvertPipeline.d.ts +79 -0
  152. package/dist/engine/runConvertPipeline.js +281 -0
  153. package/dist/engine/stripBambuOnlyNozzleVariantKeys.d.ts +2 -0
  154. package/dist/engine/stripBambuOnlyNozzleVariantKeys.js +35 -0
  155. package/dist/engine/types.d.ts +2 -0
  156. package/dist/engine/types.js +1 -0
  157. package/dist/errors.d.ts +18 -0
  158. package/dist/errors.js +9 -0
  159. package/dist/explain/whatChanged.d.ts +102 -0
  160. package/dist/explain/whatChanged.js +197 -0
  161. package/dist/index.d.ts +49 -0
  162. package/dist/index.js +33 -0
  163. package/dist/inspect.d.ts +63 -0
  164. package/dist/inspect.js +103 -0
  165. package/dist/node.d.ts +11 -0
  166. package/dist/node.js +50 -0
  167. package/dist/plainText.d.ts +10 -0
  168. package/dist/plainText.js +14 -0
  169. package/dist/presets/extractPreset.d.ts +13 -0
  170. package/dist/presets/extractPreset.js +87 -0
  171. package/dist/presets/preset.d.ts +124 -0
  172. package/dist/presets/preset.js +289 -0
  173. package/dist/presets/presetKeys.d.ts +5 -0
  174. package/dist/presets/presetKeys.js +42 -0
  175. package/dist/profiles.d.ts +184 -0
  176. package/dist/profiles.js +314 -0
  177. package/dist/project.d.ts +146 -0
  178. package/dist/project.js +342 -0
  179. package/dist/schema.d.ts +103 -0
  180. package/dist/schema.js +87 -0
  181. package/dist/stamp.d.ts +45 -0
  182. package/dist/stamp.js +111 -0
  183. package/dist/telemetry.d.ts +101 -0
  184. package/dist/telemetry.js +94 -0
  185. package/dist/version.d.ts +1 -0
  186. package/dist/version.js +3 -0
  187. package/dist/worker-entry.d.ts +1 -0
  188. package/dist/worker-entry.js +142 -0
  189. package/dist/worker.d.ts +86 -0
  190. package/dist/worker.js +97 -0
  191. package/dist/workerProtocol.d.ts +91 -0
  192. package/dist/workerProtocol.js +1 -0
  193. package/package.json +78 -12
  194. package/index.js +0 -3
@@ -0,0 +1,281 @@
1
+ import { applyFilamentComplianceMode } from "./applyFilamentComplianceMode.js";
2
+ import { EXTRA_PROJECT_LEVEL_FILAMENT_KEYS } from "./constants.js";
3
+ import { buildFilamentConfigs } from "./buildFilamentConfigs.js";
4
+ import { clampColorPenetration } from "./clampColorPenetration.js";
5
+ import { clampToMachineLimits } from "./clampToMachineLimits.js";
6
+ import { applyFilamentFlowVariants, MAX_VOLUMETRIC_SPEED } from "./applyFilamentFlowVariants.js";
7
+ import { applyHighFlowHotends, resolveHighFlowSelection } from "./applyHighFlowHotends.js";
8
+ import { applyPresetChanges } from "./applyPresetChanges.js";
9
+ import { ABOVE_STOCK_DEFAULTS, firstNumber, largestNumber } from "./aboveStock.js";
10
+ import { buildProjectSettings } from "./buildProjectSettings.js";
11
+ import { carrySourceLayerHeight } from "./carrySourceLayerHeight.js";
12
+ import { computeShifts } from "./computeShifts.js";
13
+ import { extractFilamentSlots } from "./extractFilamentSlots.js";
14
+ import { fillFilamentSlots } from "./fillFilamentSlots.js";
15
+ import { remapBrimType } from "./remapBrimType.js";
16
+ import { resizeFlushVolumes } from "./resizeFlushVolumes.js";
17
+ import { ChangeTracker, valueText } from "../explain/whatChanged.js";
18
+ import { U1_VALUE_KEYS } from "./policy.js";
19
+ const U1_VALUE_KEY_SET = new Set(U1_VALUE_KEYS);
20
+ function numbers(value) {
21
+ return (Array.isArray(value) ? value : [value]).map((v) => Number(v)).filter(Number.isFinite);
22
+ }
23
+ /** A step that only ever changes settings for one reason. */
24
+ const because = (reason, note) => () => ({ reason, ...(note ? { note } : {}) });
25
+ /**
26
+ * The full conversion merge + centering pipeline, given an already
27
+ * resolved profile. Pure function: no network or file access. `Project.convert()`
28
+ * loads a ConvertProfile from the catalog and calls this; tests build one
29
+ * straight from the profile templates.
30
+ *
31
+ * Orchestrates the engine functions: extract filament slots -> build
32
+ * filament configs -> build the merged project settings -> cap speeds at
33
+ * the U1's machine limits -> compute the centering shifts.
34
+ *
35
+ * The print and printer are Snapmaker's stock presets, which Snapmaker Orca
36
+ * already has, so like Snapmaker Orca's own stock projects the output
37
+ * carries no embedded print or machine preset; the source's embedded
38
+ * presets are dropped (shouldDropFromBambu). Filament presets are embedded,
39
+ * as Snapmaker Orca does for filaments that aren't its own presets.
40
+ *
41
+ * @param application the target slicer's Application value at the pinned
42
+ * release (the catalog index's `slicer.application`), passed straight
43
+ * through to the response's `application` field.
44
+ */
45
+ export function runConvertPipeline(profile, request, application, options = {}) {
46
+ const warnings = [];
47
+ const { printer, profile: p } = profile;
48
+ const filamentTemplateKeys = new Set(Object.keys(p.filamentShapeConfig));
49
+ let { filamentKeyArrays, slots } = extractFilamentSlots(request.projectSettings, filamentTemplateKeys, EXTRA_PROJECT_LEVEL_FILAMENT_KEYS, p.filamentKeyBlocklist, warnings);
50
+ // flush_volumes_matrix/vector aren't a per-filament template key (a full
51
+ // n x n matrix, not one value per slot), so extractFilamentSlots' generic
52
+ // reshape can't cover them -- resized separately here and merged into the
53
+ // same overlay, which buildProjectSettings already fully-replaces
54
+ // whatever keys are present in, exactly like filament_colour/filament_ids.
55
+ // Skipped entirely (not just a no-op merge) when filamentKeyArrays is
56
+ // null -- filament extraction already failed and warned; a "resized to 0
57
+ // filaments" warning on top of that would just be confusing noise.
58
+ if (filamentKeyArrays) {
59
+ const resizedFlushVolumes = resizeFlushVolumes(request.projectSettings, slots.length, warnings);
60
+ if (resizedFlushVolumes) {
61
+ filamentKeyArrays = { ...filamentKeyArrays, ...resizedFlushVolumes };
62
+ }
63
+ }
64
+ let filamentComplianceFallback;
65
+ let filamentComplianceUnchanged;
66
+ let renamedFilaments = [];
67
+ if (request.filamentComplianceMode) {
68
+ // 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);
70
+ slots = applied.slots;
71
+ filamentKeyArrays = applied.filamentKeyArrays;
72
+ renamedFilaments = applied.renamed;
73
+ if (applied.fellBackToGenericMaterials.length > 0)
74
+ filamentComplianceFallback = applied.fellBackToGenericMaterials;
75
+ if (applied.unchangedMaterials.length > 0)
76
+ filamentComplianceUnchanged = applied.unchangedMaterials;
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.");
79
+ }
80
+ }
81
+ const { files: filamentFiles } = buildFilamentConfigs(slots, p.filamentShapeConfig, p.filamentKeyBlocklist);
82
+ // High-flow hotends (request.highFlowHotends): which toolheads have the
83
+ // Liber hotend, only where the nozzle supports it. The tier's high-flow
84
+ // values are applied after the merge, as the second variant of each
85
+ // speed, so a creator-customized value still wins (applyHighFlowHotends).
86
+ const toolheads = Array.isArray(printer.machineSettingsConfig.nozzle_diameter) && printer.machineSettingsConfig.nozzle_diameter.length > 0
87
+ ? printer.machineSettingsConfig.nozzle_diameter.length
88
+ : 4;
89
+ const highFlowSelection = resolveHighFlowSelection(request.highFlowHotends, toolheads);
90
+ const highFlowApplies = highFlowSelection !== null && printer.highFlowSupported === true;
91
+ if (highFlowSelection !== null && !highFlowApplies) {
92
+ warnings.push(" WARN: high-flow hotends were requested, but Snapmaker has no high-flow option for this nozzle size (only 0.4mm), so the project is set up for standard hotends.");
93
+ }
94
+ const highFlowValues = highFlowApplies ? (p.highFlowOverrides ?? {}) : {};
95
+ const highFlowTuning = Object.keys(highFlowValues).length > 0
96
+ ? {
97
+ highFlow: highFlowValues,
98
+ // The stock standard value: the first entry where the profile stores one per variant.
99
+ standard: Object.fromEntries(Object.keys(highFlowValues).map((key) => {
100
+ const stock = p.baselineProjectSettings[key];
101
+ return [key, String((Array.isArray(stock) ? stock[0] : stock) ?? "")];
102
+ })),
103
+ }
104
+ : null;
105
+ const tracker = new ChangeTracker();
106
+ const keep = options.aboveStock?.keep ?? new Set();
107
+ const useStock = options.aboveStock?.stock ?? new Set();
108
+ // Keeping the creator's acceleration or travel speed above stock: take it as it is, instead of only when lower.
109
+ const keptHigher = [...keep].filter((key) => p.minComparisonKeys.has(key));
110
+ const { newSettings: mergedSettings, notCarried } = buildProjectSettings(p.baselineProjectSettings, request.projectSettings, filamentKeyArrays, p.blocklist, keptHigher.length > 0 ? new Set([...p.minComparisonKeys].filter((key) => !keep.has(key))) : p.minComparisonKeys, keptHigher.length > 0 ? new Set([...p.alwaysTransferKeys, ...keptHigher]) : p.alwaysTransferKeys, warnings);
111
+ // Filament settings are the creator's, carried as a whole; they're summarized in one line below.
112
+ tracker.compare(p.baselineProjectSettings, mergedSettings, (key) => {
113
+ if (filamentKeyArrays && Object.hasOwn(filamentKeyArrays, key))
114
+ return null;
115
+ if (key === "print_sequence")
116
+ return { reason: "layout", note: "kept to match how the model is laid out" };
117
+ if (keep.has(key) && p.minComparisonKeys.has(key))
118
+ return { reason: "yours", note: "you chose to keep the creator's value" };
119
+ if (p.minComparisonKeys.has(key))
120
+ return { reason: "creator", note: "lower than Snapmaker's stock value" };
121
+ return { reason: "creator" };
122
+ });
123
+ if (filamentKeyArrays && slots.length > 0) {
124
+ tracker.add("creator", {
125
+ label: `${slots.length} filament${slots.length === 1 ? "" : "s"}: colors, materials and filament settings kept as the creator set them`,
126
+ before: null,
127
+ after: null,
128
+ });
129
+ }
130
+ if (request.filamentComplianceMode) {
131
+ const notes = [
132
+ ...(filamentComplianceFallback ? [`Generic for ${filamentComplianceFallback.join(", ")}`] : []),
133
+ ...(filamentComplianceUnchanged ? [`kept the creator's name for ${filamentComplianceUnchanged.join(", ")} (no Snapmaker or Generic preset for this nozzle size)`] : []),
134
+ ];
135
+ tracker.add("yours", {
136
+ label: `Filament names relabeled to ${request.filamentComplianceMode === "generic" ? "Generic" : "Snapmaker"} presets (names only, never temperatures or flow)`,
137
+ before: null,
138
+ after: null,
139
+ ...(notes.length > 0 ? { note: notes.join("; ") } : {}),
140
+ });
141
+ for (const r of renamedFilaments)
142
+ tracker.add("yours", { label: `Filament ${r.slot + 1} name`, before: r.before || null, after: r.after });
143
+ }
144
+ if (useStock.size > 0) {
145
+ tracker.step(mergedSettings, because("yours", "you chose Snapmaker's stock value"), () => {
146
+ for (const key of useStock)
147
+ if (Object.hasOwn(p.baselineProjectSettings, key))
148
+ mergedSettings[key] = p.baselineProjectSettings[key];
149
+ });
150
+ }
151
+ const presetChanges = options.presetChanges;
152
+ if (presetChanges)
153
+ tracker.step(mergedSettings, because("yours", "from your preset"), () => applyPresetChanges(mergedSettings, presetChanges, warnings));
154
+ const newSettings = remapBrimType(mergedSettings, warnings);
155
+ tracker.compare(mergedSettings, newSettings, because("firmware", "Bambu Studio's name for a painted brim means something else in Snapmaker Orca"));
156
+ // When the source carries no filament settings at all, the filament count comes from its colors.
157
+ const slotCount = slots.length > 0 ? slots.length : Array.isArray(newSettings.filament_colour) ? newSettings.filament_colour.length : 0;
158
+ const filamentFromSource = new Set(Object.keys(filamentKeyArrays ?? {}));
159
+ fillFilamentSlots(newSettings, filamentTemplateKeys, filamentFromSource, slotCount);
160
+ // Laying the filament settings out per hotend type isn't a change in meaning; lowering a max volumetric speed is.
161
+ tracker.step(newSettings, (key, before, after) => {
162
+ if (key !== "filament_max_volumetric_speed")
163
+ return null;
164
+ const was = numbers(before);
165
+ const step = Number(Array.isArray(newSettings.filament_flow_step_size) ? newSettings.filament_flow_step_size[0] : 1);
166
+ const standard = numbers(after).filter((_, i) => step !== 2 || i % 2 === 0);
167
+ return standard.length === was.length && standard.some((v, i) => v < was[i])
168
+ ? { reason: "capped", note: `at most ${MAX_VOLUMETRIC_SPEED.standard} mm³/s, ${MAX_VOLUMETRIC_SPEED.highFlow} with a high-flow hotend` }
169
+ : null;
170
+ }, () => applyFilamentFlowVariants(newSettings, request.projectSettings, p.baselineProjectSettings, printer.highFlowSupported === true, filamentFromSource, slotCount, warnings, {
171
+ capVolumetricSpeed: !keep.has("filament_max_volumetric_speed"),
172
+ }));
173
+ if (keep.has("filament_max_volumetric_speed")) {
174
+ tracker.add("yours", {
175
+ key: "filament_max_volumetric_speed",
176
+ label: "Filament max volumetric speed kept as the creator set it",
177
+ before: null,
178
+ after: valueText(newSettings.filament_max_volumetric_speed),
179
+ note: `you chose not to cap it at ${MAX_VOLUMETRIC_SPEED.standard} mm³/s (${MAX_VOLUMETRIC_SPEED.highFlow} high flow)`,
180
+ alternative: "stock",
181
+ });
182
+ }
183
+ tracker.step(newSettings, because("firmware", "no deeper than the shell, as Snapmaker Orca would reset it"), () => clampColorPenetration(newSettings, warnings));
184
+ if (options.carrySourceLayerHeight) {
185
+ tracker.step(newSettings, because("creator", "no U1 profile has this layer height, so the creator's is kept"), () => carrySourceLayerHeight(newSettings, request.projectSettings, printer.machineSettingsConfig, warnings));
186
+ }
187
+ if (highFlowApplies && highFlowSelection) {
188
+ tracker.step(newSettings, because("yours", "for the toolheads with the Liber High Flow Hotend"), () => applyHighFlowHotends(newSettings, highFlowSelection, highFlowTuning, warnings));
189
+ }
190
+ tracker.step(newSettings, because("capped", "the U1's machine limit"), () => clampToMachineLimits(newSettings, p.baselineProjectSettings, printer.machineSettingsConfig, warnings));
191
+ // Hardened steel nozzles instead of the stock stainless ones (only the 0.4
192
+ // profile says stainless; the other sizes are hardened already).
193
+ if (request.hardenedNozzles) {
194
+ tracker.step(newSettings, because("yours", "hardened steel nozzles"), () => {
195
+ newSettings.nozzle_type = "hardened_steel";
196
+ });
197
+ }
198
+ const bambuClearanceRadiusRaw = request.projectSettings.extruder_clearance_max_radius;
199
+ const bambuClearanceRadius = typeof bambuClearanceRadiusRaw === "string" || typeof bambuClearanceRadiusRaw === "number"
200
+ ? Number(bambuClearanceRadiusRaw)
201
+ : null;
202
+ const { shifts, warnings: shiftWarnings } = computeShifts(request.objects, printer.printableArea, Number.isFinite(bambuClearanceRadius) ? bambuClearanceRadius : null, printer.extruderClearanceRadius);
203
+ warnings.push(...shiftWarnings);
204
+ addShiftItems(tracker, request.objects, shifts);
205
+ const configFiles = { ...filamentFiles };
206
+ // `warnings` mixes routine per-conversion bookkeeping (e.g. computeShifts'
207
+ // "true geometric center -> target" line, which fires on every plate
208
+ // every time) with genuinely actionable notes -- every actionable one is
209
+ // consistently marked with a "WARN" substring (see computeShifts.ts,
210
+ // extractFilamentSlots.ts, coerceValue.ts), so that's what the response
211
+ // surfaces. The full, unfiltered list stays available in this function's
212
+ // own return value for tests and debugging.
213
+ const userFacingWarnings = warnings.filter((w) => w.includes("WARN"));
214
+ return {
215
+ response: {
216
+ projectSettings: newSettings,
217
+ configFiles,
218
+ shifts,
219
+ application,
220
+ ...(filamentComplianceFallback ? { filamentComplianceFallback } : {}),
221
+ ...(filamentComplianceUnchanged ? { filamentComplianceUnchanged } : {}),
222
+ ...(userFacingWarnings.length > 0 ? { warnings: userFacingWarnings } : {}),
223
+ },
224
+ warnings,
225
+ changes: tracker.build(request.projectSettings, p.baselineProjectSettings, newSettings, (key) => {
226
+ if (U1_VALUE_KEY_SET.has(key))
227
+ return "always the U1's own value";
228
+ if (p.blocklist.has(key))
229
+ return "always the U1's own value";
230
+ if (p.minComparisonKeys.has(key)) {
231
+ // In Snapmaker Orca and Bambu Studio, an acceleration of 0 means "the same as normal printing".
232
+ if (firstNumber(request.projectSettings[key]) === 0)
233
+ return "0 in the creator's file means the same as normal printing; Snapmaker's stock value is used";
234
+ return "higher than Snapmaker's stock value; only lower values are carried over";
235
+ }
236
+ if (notCarried.includes(key))
237
+ return "the creator changed it, but its values don't fit the U1's layout; Snapmaker's stock value is used";
238
+ return "the creator's file doesn't mark it as changed";
239
+ }, (key, reason) => {
240
+ const choice = ABOVE_STOCK_DEFAULTS[key];
241
+ if (!choice)
242
+ return undefined;
243
+ if (reason === "yours")
244
+ return keep.has(key) ? "stock" : useStock.has(key) ? "keep" : undefined;
245
+ const above = (firstNumber(newSettings[key]) ?? 0) > (firstNumber(p.baselineProjectSettings[key]) ?? Infinity);
246
+ const sourceAbove = (firstNumber(request.projectSettings[key]) ?? 0) > (firstNumber(p.baselineProjectSettings[key]) ?? Infinity);
247
+ if (reason === "creator" && choice === "keep" && above)
248
+ return "stock";
249
+ if (reason === "stock" && choice === "stock" && sourceAbove)
250
+ return "keep";
251
+ if (reason === "capped")
252
+ return choice === "capped" && (largestNumber(request.projectSettings[key]) ?? 0) > 0 ? "keep" : "stock";
253
+ return undefined;
254
+ }),
255
+ };
256
+ }
257
+ /** One line per plate whose objects moved to the center of the U1's bed (or per object, where they moved differently). */
258
+ function addShiftItems(tracker, objects, shifts) {
259
+ const round = (n) => Math.round(n * 10) / 10;
260
+ const byPlate = new Map();
261
+ for (const object of objects) {
262
+ const shift = shifts[object.id];
263
+ if (!shift || (round(shift[0]) === 0 && round(shift[1]) === 0))
264
+ continue;
265
+ const list = byPlate.get(object.plate ?? 1) ?? [];
266
+ list.push({ name: object.name ?? `object ${object.id}`, shift });
267
+ byPlate.set(object.plate ?? 1, list);
268
+ }
269
+ for (const [plate, moved] of [...byPlate].sort((a, b) => a[0] - b[0])) {
270
+ const same = moved.every((m) => round(m.shift[0]) === round(moved[0].shift[0]) && round(m.shift[1]) === round(moved[0].shift[1]));
271
+ const entries = same ? [{ name: moved.length === 1 ? `"${moved[0].name}"` : `${moved.length} objects`, shift: moved[0].shift }] : moved.map((m) => ({ name: `"${m.name}"`, shift: m.shift }));
272
+ for (const entry of entries) {
273
+ tracker.add("layout", {
274
+ label: `Plate ${plate}: ${entry.name} moved to the center of the U1's bed`,
275
+ before: null,
276
+ after: null,
277
+ note: `${round(entry.shift[0])} mm in X, ${round(entry.shift[1])} mm in Y`,
278
+ });
279
+ }
280
+ }
281
+ }
@@ -0,0 +1,2 @@
1
+ import type { JsonRecord } from "./types.js";
2
+ export declare function stripBambuOnlyNozzleVariantKeys(settings: JsonRecord, baseline: JsonRecord): void;
@@ -0,0 +1,35 @@
1
+ const BAMBU_ONLY_NOZZLE_VARIANT_KEYS = ["nozzle_volume_type", "default_nozzle_volume_type"];
2
+ /**
3
+ * Removes the source slicer's nozzle-variant selection from the output and
4
+ * puts back the U1 profile's own value, right before the settings are
5
+ * returned. Unconditional, whatever path the source's value took.
6
+ *
7
+ * In Bambu Studio, `nozzle_volume_type` (and `default_nozzle_volume_type`)
8
+ * select which column of a per-variant paired array (a nozzle's
9
+ * "Standard" vs "High Flow" profile) the file was sliced with;
10
+ * `detectVariantIndex.ts` reads it from the SOURCE for exactly that. Its
11
+ * values and length describe the source printer, not the U1.
12
+ *
13
+ * A mis-sized value is dangerous: a converted file with one entry for four
14
+ * toolheads crashes OrcaSlicer on load. So the
15
+ * source's value never survives.
16
+ *
17
+ * Snapmaker Orca 2.4 uses `nozzle_volume_type` too, with its own meaning:
18
+ * one entry per U1 toolhead, "standard" or "high_flow" for the Liber High
19
+ * Flow hotend, and its stock projects always carry it. So the value is
20
+ * restored from the U1 profile (four "standard" entries) when the profile
21
+ * has a value in Snapmaker Orca's spelling, and `applyHighFlowHotends`
22
+ * later marks the toolheads that have the hotend. A value in Bambu
23
+ * Studio's spelling is never restored.
24
+ * `default_nozzle_volume_type` has no U1 meaning and is always removed.
25
+ */
26
+ /** Snapmaker Orca's own spelling; Bambu Studio writes "Standard"/"High Flow". */
27
+ const U1_VOLUME_TYPES = new Set(["standard", "high_flow"]);
28
+ export function stripBambuOnlyNozzleVariantKeys(settings, baseline) {
29
+ for (const key of BAMBU_ONLY_NOZZLE_VARIANT_KEYS)
30
+ delete settings[key];
31
+ const u1Value = baseline.nozzle_volume_type;
32
+ if (Array.isArray(u1Value) && u1Value.length > 0 && u1Value.every((v) => U1_VOLUME_TYPES.has(String(v)))) {
33
+ settings.nozzle_volume_type = [...u1Value];
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ /** A parsed JSON object — settings/config files are always objects at the top level. */
2
+ export type JsonRecord = Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * What went wrong, as a stable code a UI can branch on:
3
+ * - `invalid_file`: not a readable 3MF (corrupt zip, missing project files, unsafe entries).
4
+ * - `too_large`: a project that unpacks to more than the size limit (2 GB by default; `maxUnpackedBytes` changes it).
5
+ * - `invalid_project`: a readable 3MF whose settings or objects are malformed or over a limit.
6
+ * - `profile_not_found`: the requested profile id isn't in the catalog and wasn't retired.
7
+ * - `profile_data`: the profile catalog itself is missing or malformed.
8
+ * - `invalid_preset`: a preset or presets file that is malformed, over a limit, or can't be used with the given options.
9
+ * - `preset_base_unknown`: a file a preset can't be made from, because it isn't set up for a profile in the catalog.
10
+ */
11
+ export type Any2orcaErrorCode = "invalid_file" | "too_large" | "invalid_project" | "profile_not_found" | "profile_data" | "invalid_preset" | "preset_base_unknown";
12
+ export declare class Any2orcaError extends Error {
13
+ name: string;
14
+ readonly code: Any2orcaErrorCode;
15
+ constructor(code: Any2orcaErrorCode, message: string, options?: {
16
+ cause?: unknown;
17
+ });
18
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: MIT
2
+ export class Any2orcaError extends Error {
3
+ name = "Any2orcaError";
4
+ code;
5
+ constructor(code, message, options) {
6
+ super(message, options);
7
+ this.code = code;
8
+ }
9
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * "What changed?": the converter's own record of what it did to a file's
3
+ * settings, grouped by why. The same record backs the web app's panel, the
4
+ * CLI's `convert --explain` and the JSON export, so all three list the same
5
+ * changes in the same groups and order.
6
+ *
7
+ * The pipeline reports each step to a {@link ChangeTracker}, which compares
8
+ * the settings before and after the step and keeps the settings whose value
9
+ * really changed (by the settings diff's rules, so a value only rewritten in
10
+ * another layout isn't a change). A setting changed by several steps is
11
+ * listed under the last one, with the value from just before it. Settings
12
+ * the creator's file had but the converter didn't use are added at the end,
13
+ * with the reason they kept Snapmaker's stock value.
14
+ */
15
+ import { type SettingsDiff } from "../diff/diffSettings.js";
16
+ import { type ValueLayout } from "../diff/valueLayout.js";
17
+ import type { JsonRecord } from "../engine/types.js";
18
+ export type ChangeReason = "creator" | "stock" | "capped" | "firmware" | "layout" | "yours";
19
+ export interface ChangeItem {
20
+ /** The setting's key, or absent for an item that isn't one setting (an object moved, a summary). */
21
+ key?: string;
22
+ /** Where Snapmaker Orca shows the setting, e.g. "Strength > Walls > Wall loops", or a sentence. */
23
+ label: string;
24
+ /** The value before the change, as text (list entries joined with ", "), or null if there was none. */
25
+ before: string | null;
26
+ /** The value in the converted file, or null if it has none. */
27
+ after: string | null;
28
+ /** Why, in a few words, when the group's description doesn't say it all. */
29
+ note?: string;
30
+ /**
31
+ * Set when the user can choose differently for this value:
32
+ * "stock" to use Snapmaker's stock value instead, "keep" to keep the
33
+ * creator's value instead. Convert again with `aboveStock` to apply it.
34
+ */
35
+ alternative?: "keep" | "stock";
36
+ /** What the before and after values are, where they're a pair or per-nozzle list (see {@link ValueLayout}); absent for single values. */
37
+ layout?: {
38
+ before?: ValueLayout;
39
+ after?: ValueLayout;
40
+ };
41
+ }
42
+ export interface ChangeGroup {
43
+ reason: ChangeReason;
44
+ title: string;
45
+ /** What "before" and "after" mean in this group. */
46
+ description: string;
47
+ items: ChangeItem[];
48
+ }
49
+ export interface WhatChanged {
50
+ format: "any2orca-what-changed";
51
+ version: 1;
52
+ /** The profile the file was converted with, and how it was chosen. */
53
+ profile: {
54
+ id: string;
55
+ displayName: string;
56
+ chosenBy: "matched" | "you" | "preset";
57
+ };
58
+ /** The Snapmaker Orca release whose labels and settings the record uses. */
59
+ catalog: {
60
+ tag: string;
61
+ commit: string;
62
+ };
63
+ /** In this order: creator, stock, capped, firmware, layout, yours. Empty groups are left out. */
64
+ groups: ChangeGroup[];
65
+ /** Every difference between the original and converted settings, when asked for (`explain: true`). */
66
+ diff?: SettingsDiff;
67
+ }
68
+ /** Text for one value: list entries joined with ", ", and a list repeating one value (one per toolhead) as that value. */
69
+ export declare function valueText(value: unknown): string | null;
70
+ /** Decides a step's reason for one changed setting, or null to leave the change out of the record. */
71
+ export type Classify = (key: string, before: unknown, after: unknown) => {
72
+ reason: ChangeReason;
73
+ note?: string;
74
+ } | null;
75
+ export declare class ChangeTracker {
76
+ private readonly recorded;
77
+ private readonly extra;
78
+ /** Records what changed between `before` and `after` (whole settings objects), as `classify` decides. */
79
+ compare(before: JsonRecord, after: JsonRecord, classify: Classify): void;
80
+ /** Runs a step that changes `settings` in place, recording what it changed. */
81
+ step(settings: JsonRecord, classify: Classify, run: () => void): void;
82
+ /** Adds an item that isn't one setting (an object moved, a summary line). */
83
+ add(reason: ChangeReason, item: ChangeItem): void;
84
+ /**
85
+ * The record, given the source's settings, the profile's stock settings
86
+ * and the converted settings. `stockNote` says why a setting the creator's
87
+ * file has kept the stock value. Printer settings (the machine group:
88
+ * G-code, retraction, limits, bed) always come from the U1, so they're
89
+ * one summary line rather than one line each; the full diff lists them.
90
+ */
91
+ build(source: JsonRecord, stock: JsonRecord, output: JsonRecord, stockNote: (key: string) => string, alternative?: (key: string, reason: ChangeReason) => "keep" | "stock" | undefined): Map<ChangeReason, ChangeItem[]>;
92
+ }
93
+ /** Puts the groups in their fixed order with their titles, leaving out empty ones. */
94
+ export declare function toWhatChanged(profile: WhatChanged["profile"], groups: ReadonlyMap<ChangeReason, ChangeItem[]>, diff?: SettingsDiff): WhatChanged;
95
+ /**
96
+ * The record as plain text: what `convert --explain` prints and the web
97
+ * app's "Copy as text" copies. `cliHints` adds, to each value that can be
98
+ * chosen differently, the `convert` flag that does it.
99
+ */
100
+ export declare function formatWhatChanged(record: WhatChanged, options?: {
101
+ cliHints?: boolean;
102
+ }): string;