any2orca 0.0.1 → 0.2.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 +80 -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 +22 -0
  142. package/dist/engine/policy.js +274 -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 +199 -0
  161. package/dist/index.d.ts +50 -0
  162. package/dist/index.js +34 -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 +318 -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 +80 -12
  194. package/index.js +0 -3
@@ -0,0 +1,259 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * The settings diff: compares two sets of project settings key by key, the
4
+ * way Snapmaker Orca groups and names them. Either side can be a project's
5
+ * own settings, a stock profile's, or a preset applied to its base profile;
6
+ * the caller supplies the settings and a label for each side.
7
+ *
8
+ * Values are compared as Snapmaker Orca treats them, so a difference is a
9
+ * real one: numbers compare by value ("1.0" equals "1", "15.0%" equals
10
+ * "15%"), a single value equals a list that repeats it (Snapmaker Orca
11
+ * repeats one value for every toolhead or variant), G-code compares without
12
+ * line-ending or trailing-space differences, and filament settings compare
13
+ * filament slot by filament slot.
14
+ *
15
+ * A setting only one side has is `only-a` or `only-b` when Snapmaker Orca
16
+ * knows the setting, and `unmatched` when it doesn't (a key from another
17
+ * slicer, which may exist in Snapmaker Orca under another name). The diff
18
+ * never guesses a mapping between names.
19
+ */
20
+ import { Any2orcaError } from "../errors.js";
21
+ import { ABOVE_STOCK_DEFAULTS, machineLimitFor } from "../engine/aboveStock.js";
22
+ import { FILAMENT_FLOW_VARIANT_KEYS, MAX_VOLUMETRIC_SPEED } from "../engine/applyFilamentFlowVariants.js";
23
+ import { SETTINGS_CATALOG, SETTINGS_CATALOG_SOURCE } from "./settingsCatalog.js";
24
+ import { isOtherPrinter, valueLayout } from "./valueLayout.js";
25
+ /** Entries that describe how a file was saved rather than how it prints. */
26
+ export const BOOKKEEPING_KEYS = new Set([
27
+ "different_settings_to_system",
28
+ "inherits",
29
+ "inherits_group",
30
+ "name",
31
+ "from",
32
+ "version",
33
+ "is_custom_defined",
34
+ "print_compatible_printers",
35
+ "compatible_printers",
36
+ "compatible_printers_condition",
37
+ "compatible_prints",
38
+ "compatible_prints_condition",
39
+ "compatible_machine_expression_group",
40
+ "compatible_process_expression_group",
41
+ "upward_compatible_machine",
42
+ "filament_ids",
43
+ "project_schema_version",
44
+ ]);
45
+ /** A project has a few hundred settings; this bounds the work for a crafted file. */
46
+ export const MAX_DIFF_KEYS = 10_000;
47
+ const GROUP_ORDER = ["print", "filament", "machine", "other"];
48
+ const VARIANT_KEYS = new Set(FILAMENT_FLOW_VARIANT_KEYS);
49
+ const NUMBER = /^-?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?%?$/;
50
+ function entryText(value) {
51
+ if (typeof value === "string")
52
+ return value;
53
+ if (typeof value === "number" || typeof value === "boolean")
54
+ return String(value);
55
+ if (value === null || value === undefined)
56
+ return "";
57
+ return JSON.stringify(value);
58
+ }
59
+ /** One entry as Snapmaker Orca would compare it. */
60
+ function normalizeEntry(raw) {
61
+ const text = raw.includes("\n") || raw.includes("\r") ? raw.replace(/\r\n?/g, "\n").replace(/[ \t]+$/gm, "").replace(/\n+$/, "") : raw.trim();
62
+ if (NUMBER.test(text)) {
63
+ const percent = text.endsWith("%");
64
+ const n = Number(percent ? text.slice(0, -1) : text);
65
+ if (Number.isFinite(n))
66
+ return `${n}${percent ? "%" : ""}`;
67
+ }
68
+ return text;
69
+ }
70
+ function entries(value) {
71
+ return Array.isArray(value) ? value.map(entryText) : [entryText(value)];
72
+ }
73
+ /** Equal as Snapmaker Orca treats them: same entries, or one value repeated for every entry. */
74
+ function sameValue(a, b) {
75
+ const x = a.map(normalizeEntry);
76
+ const y = b.map(normalizeEntry);
77
+ if (x.length === y.length)
78
+ return x.every((v, i) => v === y[i]);
79
+ // An empty list equals only an empty value, never "one value repeated".
80
+ if (x.length === 0 || y.length === 0)
81
+ return [...x, ...y].every((v) => v === "");
82
+ if (x.length === 1)
83
+ return y.every((v) => v === x[0]);
84
+ if (y.length === 1)
85
+ return x.every((v) => v === y[0]);
86
+ // Two lists that each repeat one value, such as a two-nozzle printer's five columns and the U1's two.
87
+ return x.every((v) => v === x[0]) && y.every((v) => v === x[0]);
88
+ }
89
+ /** Whether two values of one setting are equal as Snapmaker Orca treats them (the comparison the diff uses). */
90
+ export function sameSetting(a, b) {
91
+ return sameValue(entries(a), entries(b));
92
+ }
93
+ function display(list) {
94
+ return list === null ? null : list.join(", ");
95
+ }
96
+ export function labelOf(key) {
97
+ const info = SETTINGS_CATALOG[key];
98
+ if (!info)
99
+ return key;
100
+ // A section often has the same name as its only setting; say it once.
101
+ const parts = [info.page, info.section, info.label].filter((p, i, all) => Boolean(p) && p !== all[i + 1]);
102
+ return parts.length > 0 && info.label ? parts.join(" > ") : key;
103
+ }
104
+ function groupOf(key) {
105
+ return Object.hasOwn(SETTINGS_CATALOG, key) ? SETTINGS_CATALOG[key].group : "other";
106
+ }
107
+ /** How many filament slots a project's settings describe. */
108
+ function slotCount(settings) {
109
+ for (const key of ["filament_colour", "filament_settings_id", "filament_type"]) {
110
+ const value = settings[key];
111
+ if (Array.isArray(value) && value.length > 0)
112
+ return value.length;
113
+ }
114
+ return 1;
115
+ }
116
+ /** The entries of each filament slot for one setting, or null if the setting isn't laid out per slot. */
117
+ function splitSlots(settings, key, slots) {
118
+ const value = settings[key];
119
+ if (!Array.isArray(value))
120
+ return null;
121
+ const list = value.map(entryText);
122
+ if (VARIANT_KEYS.has(key)) {
123
+ const steps = settings.filament_flow_step_size;
124
+ if (Array.isArray(steps) && steps.length === slots) {
125
+ const sizes = steps.map((s) => Math.max(1, Math.trunc(Number(s)) || 1));
126
+ if (sizes.reduce((n, s) => n + s, 0) === list.length) {
127
+ const out = [];
128
+ let start = 0;
129
+ for (const size of sizes) {
130
+ out.push(list.slice(start, start + size));
131
+ start += size;
132
+ }
133
+ return out;
134
+ }
135
+ }
136
+ }
137
+ if (list.length % slots !== 0 || list.length === 0)
138
+ return null;
139
+ const per = list.length / slots;
140
+ return Array.from({ length: slots }, (_, i) => list.slice(i * per, (i + 1) * per));
141
+ }
142
+ /** How a value compares with the reference, for the settings the above-stock choice covers. Percentages and "nil" are left alone. */
143
+ function attentionFor(key, sides, reference) {
144
+ if (!reference || !Object.hasOwn(ABOVE_STOCK_DEFAULTS, key))
145
+ return undefined;
146
+ const numbers = (entries) => entries.map((e) => (e.trim().endsWith("%") ? NaN : Number(e)));
147
+ if (key === "filament_max_volumetric_speed") {
148
+ // Per filament slot: the standard value, then the high-flow value where there is one.
149
+ const over = sides.some((entries) => entries !== null && numbers(entries).some((n, i) => n > (i % 2 === 1 ? MAX_VOLUMETRIC_SPEED.highFlow : MAX_VOLUMETRIC_SPEED.standard)));
150
+ return over ? "above-stock" : undefined;
151
+ }
152
+ if (!Object.hasOwn(reference.stock, key))
153
+ return undefined;
154
+ const limit = machineLimitFor(key, reference.machine);
155
+ const stock = numbers(entries(reference.stock[key]));
156
+ const stockAt = (i) => stock[i] ?? stock[0];
157
+ let result;
158
+ for (const side of sides) {
159
+ if (side === null)
160
+ continue;
161
+ numbers(side).forEach((n, i) => {
162
+ // Only values above stock count: Snapmaker's own values are never capped (its 0.20mm Standard high-flow speeds are above the U1's limit by design).
163
+ if (!Number.isFinite(n) || !Number.isFinite(stockAt(i)) || n <= stockAt(i))
164
+ return;
165
+ if (limit !== null && n > limit)
166
+ result = "above-limit";
167
+ else if (result === undefined)
168
+ result = "above-stock";
169
+ });
170
+ }
171
+ return result;
172
+ }
173
+ function rowFor(key, a, b, reference, firstOnly = [false, false], layout) {
174
+ let status;
175
+ if (a !== null && b !== null)
176
+ status = sameValue(a, b) ? "same" : "changed";
177
+ else if (!Object.hasOwn(SETTINGS_CATALOG, key))
178
+ status = "unmatched";
179
+ else
180
+ status = a === null ? "only-b" : "only-a";
181
+ const attention = attentionFor(key, [firstOnly[0] ? (a?.slice(0, 1) ?? null) : a, firstOnly[1] ? (b?.slice(0, 1) ?? null) : b], reference);
182
+ const info = Object.hasOwn(SETTINGS_CATALOG, key) ? SETTINGS_CATALOG[key] : undefined;
183
+ return {
184
+ key,
185
+ label: labelOf(key),
186
+ a: display(a),
187
+ b: display(b),
188
+ status,
189
+ ...(info?.page ? { page: info.page } : {}),
190
+ ...(info?.page && info.section ? { section: info.section } : {}),
191
+ ...(attention ? { attention } : {}),
192
+ ...(layout && (layout.a || layout.b) ? { layout: { ...(layout.a ? { a: layout.a } : {}), ...(layout.b ? { b: layout.b } : {}) } } : {}),
193
+ };
194
+ }
195
+ /** Snapmaker Orca's settings-page order, then label, then key. */
196
+ function rowOrder(x, y) {
197
+ const ox = Object.hasOwn(SETTINGS_CATALOG, x.key) ? (SETTINGS_CATALOG[x.key].order ?? Infinity) : Infinity;
198
+ const oy = Object.hasOwn(SETTINGS_CATALOG, y.key) ? (SETTINGS_CATALOG[y.key].order ?? Infinity) : Infinity;
199
+ return (ox === oy ? 0 : ox < oy ? -1 : 1) || x.label.localeCompare(y.label) || x.key.localeCompare(y.key);
200
+ }
201
+ function ownKeys(settings, side) {
202
+ if (settings === null || typeof settings !== "object" || Array.isArray(settings)) {
203
+ throw new Any2orcaError("invalid_project", `The ${side} settings aren't a settings object.`);
204
+ }
205
+ const keys = Object.keys(settings);
206
+ if (keys.length > MAX_DIFF_KEYS)
207
+ throw new Any2orcaError("invalid_project", `The ${side} settings have ${keys.length} entries, more than the ${MAX_DIFF_KEYS} a project can have.`);
208
+ return keys;
209
+ }
210
+ /** Compares two sets of settings. */
211
+ export function diffSettings(a, b, options = {}) {
212
+ const wanted = new Set(options.groups ?? GROUP_ORDER);
213
+ const keys = [...new Set([...ownKeys(a.settings, "first"), ...ownKeys(b.settings, "second")])].filter((key) => options.includeBookkeeping || !BOOKKEEPING_KEYS.has(key));
214
+ const otherPrinter = [isOtherPrinter(a.settings), isOtherPrinter(b.settings)];
215
+ const slotsA = slotCount(a.settings);
216
+ const slotsB = slotCount(b.settings);
217
+ const byGroup = new Map();
218
+ const groupFor = (group, slot) => {
219
+ const id = slot === undefined ? group : `${group}:${slot}`;
220
+ let found = byGroup.get(id);
221
+ if (!found) {
222
+ found = slot === undefined ? { group, rows: [] } : { group, slot, rows: [] };
223
+ byGroup.set(id, found);
224
+ }
225
+ return found;
226
+ };
227
+ for (const key of keys) {
228
+ const group = groupOf(key);
229
+ if (!wanted.has(group))
230
+ continue;
231
+ const hasA = Object.hasOwn(a.settings, key);
232
+ const hasB = Object.hasOwn(b.settings, key);
233
+ if (group === "filament") {
234
+ const split = (side, has, slots) => (has ? splitSlots(side.settings, key, slots) : null);
235
+ const sa = split(a, hasA, slotsA);
236
+ const sb = split(b, hasB, slotsB);
237
+ if ((hasA ? sa : true) && (hasB ? sb : true)) {
238
+ const slots = Math.max(hasA ? slotsA : 0, hasB ? slotsB : 0);
239
+ for (let i = 0; i < slots; i++) {
240
+ const ea = sa?.[i] ?? null;
241
+ const eb = sb?.[i] ?? null;
242
+ const layout = { a: ea ? valueLayout(key, ea.length, a.settings, true) : undefined, b: eb ? valueLayout(key, eb.length, b.settings, true) : undefined };
243
+ groupFor("filament", i + 1).rows.push(rowFor(key, ea, eb, options.reference, undefined, layout));
244
+ }
245
+ continue;
246
+ }
247
+ }
248
+ const ea = hasA ? entries(a.settings[key]) : null;
249
+ const eb = hasB ? entries(b.settings[key]) : null;
250
+ const layout = { a: ea ? valueLayout(key, ea.length, a.settings) : undefined, b: eb ? valueLayout(key, eb.length, b.settings) : undefined };
251
+ groupFor(group).rows.push(rowFor(key, ea, eb, options.reference, otherPrinter, layout));
252
+ }
253
+ const groups = [...byGroup.values()]
254
+ .map((g) => ({ ...g, rows: g.rows.sort(rowOrder) }))
255
+ .sort((x, y) => GROUP_ORDER.indexOf(x.group) - GROUP_ORDER.indexOf(y.group) || (x.slot ?? 0) - (y.slot ?? 0));
256
+ const identical = groups.every((g) => g.rows.every((r) => r.status === "same"));
257
+ const shown = options.includeUnchanged ? groups : groups.map((g) => ({ ...g, rows: g.rows.filter((r) => r.status !== "same") })).filter((g) => g.rows.length > 0);
258
+ return { format: "any2orca-diff", version: 1, aLabel: a.label, bLabel: b.label, catalog: { ...SETTINGS_CATALOG_SOURCE }, groups: shown, identical };
259
+ }
@@ -0,0 +1,14 @@
1
+ import type { ProfileCatalog } from "../profiles.js";
2
+ import { type Preset } from "../presets/preset.js";
3
+ import type { DiffOptions, SettingsSide } from "./diffSettings.js";
4
+ /** A profile as a diff's reference: its stock project settings and its printer's machine settings (see DiffOptions.reference). */
5
+ export declare function diffReference(catalog: ProfileCatalog, profileId: string): Promise<NonNullable<DiffOptions["reference"]>>;
6
+ /**
7
+ * A preset as a diff side, the way it converts: its base profile's stock
8
+ * settings with its changes written over them. Shared by the CLI's
9
+ * `diff --against-preset` and the worker's preset side, so both compare
10
+ * the same thing.
11
+ */
12
+ export declare function presetDiffSide(preset: Preset, catalog: ProfileCatalog): Promise<SettingsSide & {
13
+ profileId: string;
14
+ }>;
@@ -0,0 +1,22 @@
1
+ // SPDX-License-Identifier: MIT
2
+ import { applyPresetChanges } from "../engine/applyPresetChanges.js";
3
+ import { resolvePreset } from "../presets/preset.js";
4
+ /** A profile as a diff's reference: its stock project settings and its printer's machine settings (see DiffOptions.reference). */
5
+ export async function diffReference(catalog, profileId) {
6
+ const loaded = await catalog.load(profileId);
7
+ return { stock: loaded.convertProfile.profile.baselineProjectSettings, machine: loaded.convertProfile.printer.machineSettingsConfig };
8
+ }
9
+ /**
10
+ * A preset as a diff side, the way it converts: its base profile's stock
11
+ * settings with its changes written over them. Shared by the CLI's
12
+ * `diff --against-preset` and the worker's preset side, so both compare
13
+ * the same thing.
14
+ */
15
+ export async function presetDiffSide(preset, catalog) {
16
+ const resolved = await resolvePreset(preset, catalog);
17
+ const loaded = await catalog.load(resolved.profileId);
18
+ const settings = structuredClone(loaded.convertProfile.profile.baselineProjectSettings);
19
+ applyPresetChanges(settings, resolved.changes, []);
20
+ const name = typeof preset.name === "string" ? preset.name.slice(0, 40) : "";
21
+ return { label: `Your preset ${name} on ${loaded.summary.displayName}`, settings, profileId: resolved.profileId };
22
+ }
@@ -0,0 +1,28 @@
1
+ export type SettingGroup = "print" | "filament" | "machine";
2
+ export interface SettingInfo {
3
+ readonly group: SettingGroup;
4
+ /** The label Snapmaker Orca's settings pages show, or null where it shows none. */
5
+ readonly label: string | null;
6
+ /** The settings page the setting is on, for example "Speed", or null where Snapmaker Orca shows it on none. */
7
+ readonly page: string | null;
8
+ /** The section on that page, for example "Acceleration". */
9
+ readonly section: string | null;
10
+ /** Where the setting appears in Snapmaker Orca's settings pages, counting from 0 across all pages in order; null where it appears on none. */
11
+ readonly order: number | null;
12
+ /** Snapmaker Orca's value type, for example "coFloat", "coFloats", "coPercent", "coBool", "coEnum", "coString". */
13
+ readonly type: string | null;
14
+ /** The smallest and largest value Snapmaker Orca accepts, where it declares one. */
15
+ readonly min: number | null;
16
+ readonly max: number | null;
17
+ /** The values Snapmaker Orca accepts for a setting with a fixed set of choices. */
18
+ readonly choices: readonly string[] | null;
19
+ }
20
+ /** Every setting in Snapmaker Orca's print, filament and printer presets, by key. */
21
+ export declare const SETTINGS_CATALOG: {
22
+ readonly [key: string]: SettingInfo;
23
+ };
24
+ /** The Snapmaker Orca release the catalog was generated from. */
25
+ export declare const SETTINGS_CATALOG_SOURCE: {
26
+ readonly tag: "v2.4.0";
27
+ readonly commit: "b1831e5dcb464172de33783142425aafda834fbc";
28
+ };