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.
- package/CHANGELOG.md +80 -0
- package/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +96 -3
- package/dist/archive/adaptModelSettings.d.ts +1 -0
- package/dist/archive/adaptModelSettings.js +50 -0
- package/dist/archive/filamentColorNames.d.ts +8 -0
- package/dist/archive/filamentColorNames.js +760 -0
- package/dist/archive/fmtNum.d.ts +14 -0
- package/dist/archive/fmtNum.js +21 -0
- package/dist/archive/internal/escapeRegExp.d.ts +2 -0
- package/dist/archive/internal/escapeRegExp.js +5 -0
- package/dist/archive/lookupFilamentColorName.d.ts +45 -0
- package/dist/archive/lookupFilamentColorName.js +57 -0
- package/dist/archive/objectWorldBboxXY.d.ts +2 -0
- package/dist/archive/objectWorldBboxXY.js +123 -0
- package/dist/archive/parseItemPositions.d.ts +6 -0
- package/dist/archive/parseItemPositions.js +17 -0
- package/dist/archive/parseObjectMetadata.d.ts +10 -0
- package/dist/archive/parseObjectMetadata.js +97 -0
- package/dist/archive/parsePlateAssignments.d.ts +6 -0
- package/dist/archive/parsePlateAssignments.js +18 -0
- package/dist/archive/parseVertices.d.ts +7 -0
- package/dist/archive/parseVertices.js +12 -0
- package/dist/archive/paths.d.ts +5 -0
- package/dist/archive/paths.js +6 -0
- package/dist/archive/recenterAssembleItems.d.ts +9 -0
- package/dist/archive/recenterAssembleItems.js +53 -0
- package/dist/archive/recenterBuildItems.d.ts +15 -0
- package/dist/archive/recenterBuildItems.js +51 -0
- package/dist/archive/safeUnzip.d.ts +26 -0
- package/dist/archive/safeUnzip.js +126 -0
- package/dist/archive/setApplicationMetadata.d.ts +13 -0
- package/dist/archive/setApplicationMetadata.js +18 -0
- package/dist/archive/shouldDropFromBambu.d.ts +29 -0
- package/dist/archive/shouldDropFromBambu.js +39 -0
- package/dist/archive/streamObjectVertices.d.ts +19 -0
- package/dist/archive/streamObjectVertices.js +57 -0
- package/dist/archive/tolerantJsonParse.d.ts +20 -0
- package/dist/archive/tolerantJsonParse.js +71 -0
- package/dist/archive/transform.d.ts +21 -0
- package/dist/archive/transform.js +39 -0
- package/dist/archive/unwrapBundle.d.ts +24 -0
- package/dist/archive/unwrapBundle.js +41 -0
- package/dist/archive/xmlBlocks.d.ts +10 -0
- package/dist/archive/xmlBlocks.js +31 -0
- package/dist/archive/zip.d.ts +29 -0
- package/dist/archive/zip.js +141 -0
- package/dist/cli/archiveMove.d.ts +15 -0
- package/dist/cli/archiveMove.js +41 -0
- package/dist/cli/commands/convert.d.ts +89 -0
- package/dist/cli/commands/convert.js +311 -0
- package/dist/cli/commands/diff.d.ts +21 -0
- package/dist/cli/commands/diff.js +112 -0
- package/dist/cli/commands/presets.d.ts +51 -0
- package/dist/cli/commands/presets.js +280 -0
- package/dist/cli/commands/profiles.d.ts +5 -0
- package/dist/cli/commands/profiles.js +26 -0
- package/dist/cli/commands/telemetry.d.ts +6 -0
- package/dist/cli/commands/telemetry.js +45 -0
- package/dist/cli/config.d.ts +18 -0
- package/dist/cli/config.js +50 -0
- package/dist/cli/expandWildcards.d.ts +17 -0
- package/dist/cli/expandWildcards.js +81 -0
- package/dist/cli/logger.d.ts +17 -0
- package/dist/cli/logger.js +36 -0
- package/dist/cli/main.d.ts +24 -0
- package/dist/cli/main.js +598 -0
- package/dist/cli/sameFile.d.ts +9 -0
- package/dist/cli/sameFile.js +40 -0
- package/dist/cli/stats.d.ts +34 -0
- package/dist/cli/stats.js +137 -0
- package/dist/cli/table.d.ts +8 -0
- package/dist/cli/table.js +18 -0
- package/dist/cli/terminalText.d.ts +7 -0
- package/dist/cli/terminalText.js +22 -0
- package/dist/cli/updateCheck.d.ts +14 -0
- package/dist/cli/updateCheck.js +78 -0
- package/dist/cli/watchState.d.ts +18 -0
- package/dist/cli/watchState.js +33 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +10 -0
- package/dist/diff/diffSettings.d.ts +81 -0
- package/dist/diff/diffSettings.js +259 -0
- package/dist/diff/reference.d.ts +14 -0
- package/dist/diff/reference.js +22 -0
- package/dist/diff/settingsCatalog.d.ts +28 -0
- package/dist/diff/settingsCatalog.js +605 -0
- package/dist/diff/valueLayout.d.ts +20 -0
- package/dist/diff/valueLayout.js +65 -0
- package/dist/engine/aboveStock.d.ts +20 -0
- package/dist/engine/aboveStock.js +89 -0
- package/dist/engine/applyFilamentComplianceMode.d.ts +40 -0
- package/dist/engine/applyFilamentComplianceMode.js +68 -0
- package/dist/engine/applyFilamentFlowVariants.d.ts +42 -0
- package/dist/engine/applyFilamentFlowVariants.js +109 -0
- package/dist/engine/applyHighFlowHotends.d.ts +52 -0
- package/dist/engine/applyHighFlowHotends.js +115 -0
- package/dist/engine/applyPresetChanges.d.ts +12 -0
- package/dist/engine/applyPresetChanges.js +23 -0
- package/dist/engine/bedCenter.d.ts +19 -0
- package/dist/engine/bedCenter.js +34 -0
- package/dist/engine/buildFilamentConfigs.d.ts +18 -0
- package/dist/engine/buildFilamentConfigs.js +49 -0
- package/dist/engine/buildProjectSettings.d.ts +24 -0
- package/dist/engine/buildProjectSettings.js +164 -0
- package/dist/engine/carrySourceLayerHeight.d.ts +15 -0
- package/dist/engine/carrySourceLayerHeight.js +41 -0
- package/dist/engine/clampColorPenetration.d.ts +12 -0
- package/dist/engine/clampColorPenetration.js +28 -0
- package/dist/engine/clampToMachineLimits.d.ts +21 -0
- package/dist/engine/clampToMachineLimits.js +84 -0
- package/dist/engine/coerceValue.d.ts +15 -0
- package/dist/engine/coerceValue.js +56 -0
- package/dist/engine/collapseNozzleVariants.d.ts +31 -0
- package/dist/engine/collapseNozzleVariants.js +63 -0
- package/dist/engine/computeShifts.d.ts +12 -0
- package/dist/engine/computeShifts.js +339 -0
- package/dist/engine/constants.d.ts +11 -0
- package/dist/engine/constants.js +12 -0
- package/dist/engine/detectNozzleDiameter.d.ts +15 -0
- package/dist/engine/detectNozzleDiameter.js +29 -0
- package/dist/engine/detectVariantIndex.d.ts +39 -0
- package/dist/engine/detectVariantIndex.js +80 -0
- package/dist/engine/extractFilamentSlots.d.ts +18 -0
- package/dist/engine/extractFilamentSlots.js +88 -0
- package/dist/engine/filamentComplianceNames.d.ts +84 -0
- package/dist/engine/filamentComplianceNames.js +87 -0
- package/dist/engine/filamentVariantLayout.d.ts +29 -0
- package/dist/engine/filamentVariantLayout.js +38 -0
- package/dist/engine/fillFilamentSlots.d.ts +16 -0
- package/dist/engine/fillFilamentSlots.js +26 -0
- package/dist/engine/internal/jsonEqual.d.ts +2 -0
- package/dist/engine/internal/jsonEqual.js +5 -0
- package/dist/engine/parseTierName.d.ts +15 -0
- package/dist/engine/parseTierName.js +21 -0
- package/dist/engine/pickNearestProfile.d.ts +21 -0
- package/dist/engine/pickNearestProfile.js +24 -0
- package/dist/engine/pickProfile.d.ts +49 -0
- package/dist/engine/pickProfile.js +67 -0
- package/dist/engine/policy.d.ts +22 -0
- package/dist/engine/policy.js +274 -0
- package/dist/engine/remapBrimType.d.ts +30 -0
- package/dist/engine/remapBrimType.js +34 -0
- package/dist/engine/reshapeToCount.d.ts +15 -0
- package/dist/engine/reshapeToCount.js +27 -0
- package/dist/engine/resizeFlushVolumes.d.ts +27 -0
- package/dist/engine/resizeFlushVolumes.js +57 -0
- package/dist/engine/resolveMinIfLower.d.ts +21 -0
- package/dist/engine/resolveMinIfLower.js +59 -0
- package/dist/engine/runConvertPipeline.d.ts +79 -0
- package/dist/engine/runConvertPipeline.js +281 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.d.ts +2 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.js +35 -0
- package/dist/engine/types.d.ts +2 -0
- package/dist/engine/types.js +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +9 -0
- package/dist/explain/whatChanged.d.ts +102 -0
- package/dist/explain/whatChanged.js +199 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +34 -0
- package/dist/inspect.d.ts +63 -0
- package/dist/inspect.js +103 -0
- package/dist/node.d.ts +11 -0
- package/dist/node.js +50 -0
- package/dist/plainText.d.ts +10 -0
- package/dist/plainText.js +14 -0
- package/dist/presets/extractPreset.d.ts +13 -0
- package/dist/presets/extractPreset.js +87 -0
- package/dist/presets/preset.d.ts +124 -0
- package/dist/presets/preset.js +289 -0
- package/dist/presets/presetKeys.d.ts +5 -0
- package/dist/presets/presetKeys.js +42 -0
- package/dist/profiles.d.ts +184 -0
- package/dist/profiles.js +318 -0
- package/dist/project.d.ts +146 -0
- package/dist/project.js +342 -0
- package/dist/schema.d.ts +103 -0
- package/dist/schema.js +87 -0
- package/dist/stamp.d.ts +45 -0
- package/dist/stamp.js +111 -0
- package/dist/telemetry.d.ts +101 -0
- package/dist/telemetry.js +94 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +142 -0
- package/dist/worker.d.ts +86 -0
- package/dist/worker.js +97 -0
- package/dist/workerProtocol.d.ts +91 -0
- package/dist/workerProtocol.js +1 -0
- package/package.json +80 -12
- package/index.js +0 -3
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* "What changed?": the converter's own record of what it did to a file's
|
|
4
|
+
* settings, grouped by why. The same record backs the web app's panel, the
|
|
5
|
+
* CLI's `convert --explain` and the JSON export, so all three list the same
|
|
6
|
+
* changes in the same groups and order.
|
|
7
|
+
*
|
|
8
|
+
* The pipeline reports each step to a {@link ChangeTracker}, which compares
|
|
9
|
+
* the settings before and after the step and keeps the settings whose value
|
|
10
|
+
* really changed (by the settings diff's rules, so a value only rewritten in
|
|
11
|
+
* another layout isn't a change). A setting changed by several steps is
|
|
12
|
+
* listed under the last one, with the value from just before it. Settings
|
|
13
|
+
* the creator's file had but the converter didn't use are added at the end,
|
|
14
|
+
* with the reason they kept Snapmaker's stock value.
|
|
15
|
+
*/
|
|
16
|
+
import { BOOKKEEPING_KEYS, labelOf, sameSetting } from "../diff/diffSettings.js";
|
|
17
|
+
import { SETTINGS_CATALOG, SETTINGS_CATALOG_SOURCE } from "../diff/settingsCatalog.js";
|
|
18
|
+
import { valueLayout, valueLayoutNotes } from "../diff/valueLayout.js";
|
|
19
|
+
const GROUPS = [
|
|
20
|
+
{ reason: "creator", title: "From the creator's file", description: "Settings the creator changed, carried into the converted file. Before: Snapmaker's stock value. After: the creator's." },
|
|
21
|
+
{ reason: "stock", title: "Kept at Snapmaker's stock value", description: "Settings the creator's file has with another value, which the converted file doesn't use. Before: the creator's file. After: Snapmaker's stock value." },
|
|
22
|
+
{ reason: "capped", title: "Capped for the U1", description: "Values above what the U1 allows, lowered to its limit. Before: the value it would have had. After: the limit." },
|
|
23
|
+
{ reason: "firmware", title: "Set for the U1's firmware and Snapmaker Orca", description: "Values Snapmaker Orca or the U1's firmware reads differently, rewritten so they mean the same thing." },
|
|
24
|
+
{ reason: "layout", title: "Layout", description: "How the model sits on the U1's bed." },
|
|
25
|
+
{ reason: "yours", title: "Your choices", description: "Changes from the options you picked. Before: the value without your choice. After: with it." },
|
|
26
|
+
];
|
|
27
|
+
/** Text for one value: list entries joined with ", ", and a list repeating one value (one per toolhead) as that value. */
|
|
28
|
+
export function valueText(value) {
|
|
29
|
+
if (value === undefined || value === null)
|
|
30
|
+
return null;
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
const entries = value.map((v) => (typeof v === "string" ? v : JSON.stringify(v)));
|
|
33
|
+
return entries.length > 1 && entries.every((e) => e === entries[0]) ? entries[0] : entries.join(", ");
|
|
34
|
+
}
|
|
35
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
36
|
+
}
|
|
37
|
+
/** How many entries {@link valueText} shows for a value. */
|
|
38
|
+
function shownCount(value) {
|
|
39
|
+
if (!Array.isArray(value) || value.length < 2)
|
|
40
|
+
return 1;
|
|
41
|
+
const first = JSON.stringify(value[0]);
|
|
42
|
+
return value.every((v) => JSON.stringify(v) === first) ? 1 : value.length;
|
|
43
|
+
}
|
|
44
|
+
/** The item's `layout` field, from the settings each side's value was taken from. */
|
|
45
|
+
function layoutOf(key, before, beforeSettings, after, afterSettings) {
|
|
46
|
+
const b = valueLayout(key, shownCount(before), beforeSettings);
|
|
47
|
+
const a = valueLayout(key, shownCount(after), afterSettings);
|
|
48
|
+
return b || a ? { layout: { ...(b ? { before: b } : {}), ...(a ? { after: a } : {}) } } : {};
|
|
49
|
+
}
|
|
50
|
+
export class ChangeTracker {
|
|
51
|
+
recorded = new Map();
|
|
52
|
+
extra = new Map();
|
|
53
|
+
/** Records what changed between `before` and `after` (whole settings objects), as `classify` decides. */
|
|
54
|
+
compare(before, after, classify) {
|
|
55
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
56
|
+
if (BOOKKEEPING_KEYS.has(key))
|
|
57
|
+
continue;
|
|
58
|
+
const a = before[key];
|
|
59
|
+
const b = after[key];
|
|
60
|
+
if (a !== undefined && b !== undefined && sameSetting(a, b))
|
|
61
|
+
continue;
|
|
62
|
+
if (a === undefined && b === undefined)
|
|
63
|
+
continue;
|
|
64
|
+
const decided = classify(key, a, b);
|
|
65
|
+
if (decided)
|
|
66
|
+
this.recorded.set(key, { reason: decided.reason, before: a, ...(decided.note ? { note: decided.note } : {}) });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Runs a step that changes `settings` in place, recording what it changed. */
|
|
70
|
+
step(settings, classify, run) {
|
|
71
|
+
const before = { ...settings };
|
|
72
|
+
run();
|
|
73
|
+
this.compare(before, settings, classify);
|
|
74
|
+
}
|
|
75
|
+
/** Adds an item that isn't one setting (an object moved, a summary line). */
|
|
76
|
+
add(reason, item) {
|
|
77
|
+
const list = this.extra.get(reason) ?? [];
|
|
78
|
+
list.push(item);
|
|
79
|
+
this.extra.set(reason, list);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The record, given the source's settings, the profile's stock settings
|
|
83
|
+
* and the converted settings. `stockNote` says why a setting the creator's
|
|
84
|
+
* file has kept the stock value. Printer settings (the machine group:
|
|
85
|
+
* G-code, retraction, limits, bed) always come from the U1, so they're
|
|
86
|
+
* one summary line rather than one line each; the full diff lists them.
|
|
87
|
+
*/
|
|
88
|
+
build(source, stock, output, stockNote, alternative = () => undefined) {
|
|
89
|
+
const groups = new Map();
|
|
90
|
+
const push = (reason, item) => {
|
|
91
|
+
const list = groups.get(reason) ?? [];
|
|
92
|
+
list.push(item);
|
|
93
|
+
groups.set(reason, list);
|
|
94
|
+
};
|
|
95
|
+
for (const [key, r] of this.recorded) {
|
|
96
|
+
const after = output[key];
|
|
97
|
+
if (r.before !== undefined && after !== undefined && sameSetting(r.before, after))
|
|
98
|
+
continue;
|
|
99
|
+
const alt = alternative(key, r.reason);
|
|
100
|
+
// Recorded steps all start from Snapmaker's stock settings, so both values are in the U1's layout.
|
|
101
|
+
push(r.reason, {
|
|
102
|
+
key,
|
|
103
|
+
label: labelOf(key),
|
|
104
|
+
before: valueText(r.before),
|
|
105
|
+
after: valueText(after),
|
|
106
|
+
...(r.note ? { note: r.note } : {}),
|
|
107
|
+
...(alt ? { alternative: alt } : {}),
|
|
108
|
+
...layoutOf(key, r.before, output, after, output),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
let printerSettings = 0;
|
|
112
|
+
for (const key of Object.keys(source)) {
|
|
113
|
+
if (this.recorded.has(key) || BOOKKEEPING_KEYS.has(key))
|
|
114
|
+
continue;
|
|
115
|
+
const info = Object.hasOwn(SETTINGS_CATALOG, key) ? SETTINGS_CATALOG[key] : undefined;
|
|
116
|
+
// A filament's G-code is printer code, so it's counted with the printer settings, not summarized as the creator's filament.
|
|
117
|
+
const gcode = key.endsWith("_gcode");
|
|
118
|
+
if (!info || (info.group === "filament" && !gcode) || !Object.hasOwn(stock, key) || !Object.hasOwn(output, key))
|
|
119
|
+
continue;
|
|
120
|
+
if (sameSetting(source[key], stock[key]) || !sameSetting(output[key], stock[key]))
|
|
121
|
+
continue;
|
|
122
|
+
if (info.group === "machine" || gcode) {
|
|
123
|
+
printerSettings++;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const alt = alternative(key, "stock");
|
|
127
|
+
push("stock", {
|
|
128
|
+
key,
|
|
129
|
+
label: labelOf(key),
|
|
130
|
+
before: valueText(source[key]),
|
|
131
|
+
after: valueText(output[key]),
|
|
132
|
+
note: stockNote(key),
|
|
133
|
+
...(alt ? { alternative: alt } : {}),
|
|
134
|
+
...layoutOf(key, source[key], source, output[key], output),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (printerSettings > 0) {
|
|
138
|
+
push("stock", {
|
|
139
|
+
label: `${printerSettings} printer setting${printerSettings === 1 ? "" : "s"} (G-code, retraction, speed limits, bed size and others) use the U1's own`,
|
|
140
|
+
before: null,
|
|
141
|
+
after: null,
|
|
142
|
+
note: "the full list is in all differences",
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
for (const [reason, items] of this.extra)
|
|
146
|
+
for (const item of items)
|
|
147
|
+
push(reason, item);
|
|
148
|
+
for (const items of groups.values())
|
|
149
|
+
items.sort((x, y) => (x.key === undefined ? 1 : 0) - (y.key === undefined ? 1 : 0) || x.label.localeCompare(y.label) || (x.key ?? "").localeCompare(y.key ?? ""));
|
|
150
|
+
return groups;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Puts the groups in their fixed order with their titles, leaving out empty ones. */
|
|
154
|
+
export function toWhatChanged(profile, groups, diff) {
|
|
155
|
+
return {
|
|
156
|
+
format: "any2orca-what-changed",
|
|
157
|
+
version: 1,
|
|
158
|
+
profile,
|
|
159
|
+
catalog: { ...SETTINGS_CATALOG_SOURCE },
|
|
160
|
+
groups: GROUPS.filter((g) => (groups.get(g.reason)?.length ?? 0) > 0).map((g) => ({ ...g, items: groups.get(g.reason) ?? [] })),
|
|
161
|
+
...(diff ? { diff } : {}),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const MAX_CELL = 60;
|
|
165
|
+
function cell(value) {
|
|
166
|
+
if (value === null)
|
|
167
|
+
return "(not set)";
|
|
168
|
+
if (value.includes("\n"))
|
|
169
|
+
return `(${value.split("\n").length} lines of G-code)`;
|
|
170
|
+
const flat = value.replace(/\s+/g, " ");
|
|
171
|
+
return flat.length > MAX_CELL ? `${flat.slice(0, MAX_CELL - 3)}...` : flat;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The record as plain text: what `convert --explain` prints and the web
|
|
175
|
+
* app's "Copy as text" copies. `cliHints` adds, to each value that can be
|
|
176
|
+
* chosen differently, the `convert` flag that does it.
|
|
177
|
+
*/
|
|
178
|
+
export function formatWhatChanged(record, options = {}) {
|
|
179
|
+
const how = { matched: "matched to the file", you: "chosen by you", preset: "from your preset" }[record.profile.chosenBy];
|
|
180
|
+
const lines = [`Converted with ${record.profile.displayName} (${how}).`];
|
|
181
|
+
if (record.groups.length === 0)
|
|
182
|
+
lines.push("", "Nothing else changed.");
|
|
183
|
+
for (const group of record.groups) {
|
|
184
|
+
lines.push("", `${group.title} (${group.items.length})`);
|
|
185
|
+
for (const note of valueLayoutNotes(group.items))
|
|
186
|
+
lines.push(` ${note}`);
|
|
187
|
+
for (const item of group.items) {
|
|
188
|
+
const name = item.key && item.label !== item.key ? `${item.label} [${item.key}]` : item.label;
|
|
189
|
+
const values = item.before === null && item.after === null ? "" : `: ${cell(item.before)} -> ${cell(item.after)}`;
|
|
190
|
+
const hint = options.cliHints && item.alternative && item.key
|
|
191
|
+
? item.alternative === "stock"
|
|
192
|
+
? ` [for stock: --use-stock ${item.key}]`
|
|
193
|
+
: ` [to keep it: --keep-higher ${item.key}]`
|
|
194
|
+
: "";
|
|
195
|
+
lines.push(` ${name}${values}${item.note ? ` (${item.note})` : ""}${hint}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return lines.join("\n");
|
|
199
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* any2orca: convert Bambu Studio, Creality Print, Anycubic Slicer Next,
|
|
3
|
+
* ElegooSlicer and Flash Studio 3MF projects for the Snapmaker U1 (Snapmaker
|
|
4
|
+
* Orca), entirely in the caller's own process. The library makes no network
|
|
5
|
+
* requests of its own; profile data comes from a {@link ProfileSource} the
|
|
6
|
+
* caller provides.
|
|
7
|
+
*
|
|
8
|
+
* Runs in browsers, Web Workers and Node. For Node file-based profile
|
|
9
|
+
* sources see `any2orca/node`; for a ready-made Web Worker see
|
|
10
|
+
* `any2orca/worker`.
|
|
11
|
+
*/
|
|
12
|
+
export { convert, inspect, openProject, matchProfile, unwrapBundle, cleanWarnings, Project } from "./project.js";
|
|
13
|
+
export type { ConvertOptions, ConvertReport, ConvertResult, ConvertStage, OpenOptions, ProfileChoice } from "./project.js";
|
|
14
|
+
export { DEFAULT_MAX_UNPACKED_BYTES, LARGE_PROJECT_BYTES, MAX_UNPACKED_BYTES_LIMIT } from "./archive/safeUnzip.js";
|
|
15
|
+
export type { FilamentSlotInfo, Inspection, SourceVendor } from "./inspect.js";
|
|
16
|
+
export { fetchProfileSource, listProfiles, loadCatalog, memoryProfileSource, ProfileCatalog, ProfileDataError, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, } from "./profiles.js";
|
|
17
|
+
export type { LoadedProfile, ProfileIndex, ProfileSource, ProfileSummary, RetiredProfile } from "./profiles.js";
|
|
18
|
+
export { parseTierName, normalizeTierName } from "./engine/parseTierName.js";
|
|
19
|
+
export { pickProfile } from "./engine/pickProfile.js";
|
|
20
|
+
export type { PickProfileResult, TierAwareProfileCandidate } from "./engine/pickProfile.js";
|
|
21
|
+
export { detectNozzleDiameter, SUPPORTED_NOZZLE_DIAMETERS } from "./engine/detectNozzleDiameter.js";
|
|
22
|
+
export { matchFilamentLine, resolveFilamentName } from "./engine/filamentComplianceNames.js";
|
|
23
|
+
export type { FilamentComplianceMode, FilamentLine, FilamentNameResult, FilamentNameTable, FilamentPresetEntry, } from "./engine/filamentComplianceNames.js";
|
|
24
|
+
export { lookupFilamentColorName, parseFilamentType } from "./archive/lookupFilamentColorName.js";
|
|
25
|
+
export type { FilamentColorMatch } from "./archive/lookupFilamentColorName.js";
|
|
26
|
+
export type { BundleEntry } from "./archive/unwrapBundle.js";
|
|
27
|
+
export { Any2orcaError } from "./errors.js";
|
|
28
|
+
export type { Any2orcaErrorCode } from "./errors.js";
|
|
29
|
+
export { decodeStamp, OutputStampSchema, STAMP_PATH } from "./stamp.js";
|
|
30
|
+
export { diffSettings, labelOf, BOOKKEEPING_KEYS, MAX_DIFF_KEYS } from "./diff/diffSettings.js";
|
|
31
|
+
export { valueLayout, valueLayoutNotes, VALUE_LAYOUT_TEXT } from "./diff/valueLayout.js";
|
|
32
|
+
export type { ValueLayout } from "./diff/valueLayout.js";
|
|
33
|
+
export type { DiffAttention, DiffGroup, DiffGroupName, DiffOptions, DiffRow, DiffStatus, SettingsDiff, SettingsSide } from "./diff/diffSettings.js";
|
|
34
|
+
export { diffReference, presetDiffSide } from "./diff/reference.js";
|
|
35
|
+
export { SETTINGS_CATALOG, SETTINGS_CATALOG_SOURCE } from "./diff/settingsCatalog.js";
|
|
36
|
+
export type { SettingGroup, SettingInfo } from "./diff/settingsCatalog.js";
|
|
37
|
+
export { formatWhatChanged } from "./explain/whatChanged.js";
|
|
38
|
+
export type { ChangeGroup, ChangeItem, ChangeReason, WhatChanged } from "./explain/whatChanged.js";
|
|
39
|
+
export { extractPreset } from "./presets/extractPreset.js";
|
|
40
|
+
export { parsePresetFile, serializePresets, resolvePreset, presetFingerprint, withoutChanges, PresetSchema, PresetFileSchema, MAX_PRESET_NAME_LENGTH, MAX_PRESETS_PER_FILE, MAX_PRESETS_FILE_BYTES, } from "./presets/preset.js";
|
|
41
|
+
export type { ExtractedPreset, Preset, PresetChange, PresetFile, PresetValue, ResolvedPreset } from "./presets/preset.js";
|
|
42
|
+
export { PRESET_KEYS, PRESET_EXCLUDED_KEYS } from "./presets/presetKeys.js";
|
|
43
|
+
export { ABOVE_STOCK_DEFAULTS } from "./engine/aboveStock.js";
|
|
44
|
+
export type { AboveStockChoice, AboveStockDefault } from "./engine/aboveStock.js";
|
|
45
|
+
export type { OutputStamp } from "./stamp.js";
|
|
46
|
+
export { buildStatsEvent, NEVER_SENT, NO_STATS_CHOICE, recordStatsChoice, REF_PATTERN, resolveStatsConsent, StatsEventSchema, } from "./telemetry.js";
|
|
47
|
+
export type { StatsConsent, StatsConsentState, StatsEvent, StatsEventInput } from "./telemetry.js";
|
|
48
|
+
export type { ConvertObject, HighFlowHotends, MatchSource, ProfileMatch, Shifts } from "./schema.js";
|
|
49
|
+
export { plainText } from "./plainText.js";
|
|
50
|
+
export { VERSION } from "./version.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* any2orca: convert Bambu Studio, Creality Print, Anycubic Slicer Next,
|
|
4
|
+
* ElegooSlicer and Flash Studio 3MF projects for the Snapmaker U1 (Snapmaker
|
|
5
|
+
* Orca), entirely in the caller's own process. The library makes no network
|
|
6
|
+
* requests of its own; profile data comes from a {@link ProfileSource} the
|
|
7
|
+
* caller provides.
|
|
8
|
+
*
|
|
9
|
+
* Runs in browsers, Web Workers and Node. For Node file-based profile
|
|
10
|
+
* sources see `any2orca/node`; for a ready-made Web Worker see
|
|
11
|
+
* `any2orca/worker`.
|
|
12
|
+
*/
|
|
13
|
+
export { convert, inspect, openProject, matchProfile, unwrapBundle, cleanWarnings, Project } from "./project.js";
|
|
14
|
+
export { DEFAULT_MAX_UNPACKED_BYTES, LARGE_PROJECT_BYTES, MAX_UNPACKED_BYTES_LIMIT } from "./archive/safeUnzip.js";
|
|
15
|
+
export { fetchProfileSource, listProfiles, loadCatalog, memoryProfileSource, ProfileCatalog, ProfileDataError, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, } from "./profiles.js";
|
|
16
|
+
export { parseTierName, normalizeTierName } from "./engine/parseTierName.js";
|
|
17
|
+
export { pickProfile } from "./engine/pickProfile.js";
|
|
18
|
+
export { detectNozzleDiameter, SUPPORTED_NOZZLE_DIAMETERS } from "./engine/detectNozzleDiameter.js";
|
|
19
|
+
export { matchFilamentLine, resolveFilamentName } from "./engine/filamentComplianceNames.js";
|
|
20
|
+
export { lookupFilamentColorName, parseFilamentType } from "./archive/lookupFilamentColorName.js";
|
|
21
|
+
export { Any2orcaError } from "./errors.js";
|
|
22
|
+
export { decodeStamp, OutputStampSchema, STAMP_PATH } from "./stamp.js";
|
|
23
|
+
export { diffSettings, labelOf, BOOKKEEPING_KEYS, MAX_DIFF_KEYS } from "./diff/diffSettings.js";
|
|
24
|
+
export { valueLayout, valueLayoutNotes, VALUE_LAYOUT_TEXT } from "./diff/valueLayout.js";
|
|
25
|
+
export { diffReference, presetDiffSide } from "./diff/reference.js";
|
|
26
|
+
export { SETTINGS_CATALOG, SETTINGS_CATALOG_SOURCE } from "./diff/settingsCatalog.js";
|
|
27
|
+
export { formatWhatChanged } from "./explain/whatChanged.js";
|
|
28
|
+
export { extractPreset } from "./presets/extractPreset.js";
|
|
29
|
+
export { parsePresetFile, serializePresets, resolvePreset, presetFingerprint, withoutChanges, PresetSchema, PresetFileSchema, MAX_PRESET_NAME_LENGTH, MAX_PRESETS_PER_FILE, MAX_PRESETS_FILE_BYTES, } from "./presets/preset.js";
|
|
30
|
+
export { PRESET_KEYS, PRESET_EXCLUDED_KEYS } from "./presets/presetKeys.js";
|
|
31
|
+
export { ABOVE_STOCK_DEFAULTS } from "./engine/aboveStock.js";
|
|
32
|
+
export { buildStatsEvent, NEVER_SENT, NO_STATS_CHOICE, recordStatsChoice, REF_PATTERN, resolveStatsConsent, StatsEventSchema, } from "./telemetry.js";
|
|
33
|
+
export { plainText } from "./plainText.js";
|
|
34
|
+
export { VERSION } from "./version.js";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a UI needs to show about a source file before converting it: plates,
|
|
3
|
+
* objects and their footprints, filament slots with real color names, and
|
|
4
|
+
* the settings that drive profile matching. Everything here reads the
|
|
5
|
+
* file's own project_settings.config, which is untrusted, so every field is
|
|
6
|
+
* type-checked rather than cast.
|
|
7
|
+
*/
|
|
8
|
+
import { type FilamentColorMatch } from "./archive/lookupFilamentColorName.js";
|
|
9
|
+
import { type SupportedNozzleDiameter } from "./engine/detectNozzleDiameter.js";
|
|
10
|
+
import type { ConvertObject } from "./schema.js";
|
|
11
|
+
/** The printer maker a source file was set up for, from its `printer_model`. */
|
|
12
|
+
export type SourceVendor = "bambu" | "creality" | "anycubic" | "snapmaker" | "elegoo" | "prusa" | "flashforge" | "other";
|
|
13
|
+
export interface FilamentSlotInfo {
|
|
14
|
+
/** 1-based slot number, as slicers show it. */
|
|
15
|
+
slot: number;
|
|
16
|
+
/** "#RRGGBB" (or whatever the file holds, with a leading "#"). */
|
|
17
|
+
color: string;
|
|
18
|
+
/** Material, e.g. "PLA", from `filament_type` or guessed from the preset name. */
|
|
19
|
+
type: string;
|
|
20
|
+
/** The source preset name, e.g. `"Bambu PLA Matte @BBL X1C"`. Empty if the file has none. */
|
|
21
|
+
presetName: string;
|
|
22
|
+
/** The real product color name, when the preset and hex match a known filament. */
|
|
23
|
+
colorName?: FilamentColorMatch;
|
|
24
|
+
}
|
|
25
|
+
export interface Inspection {
|
|
26
|
+
/** Distinct plate numbers that have objects, ascending. */
|
|
27
|
+
plates: number[];
|
|
28
|
+
/** Top-level objects with their footprint on the source bed (bbox, or fallbackXy when bbox is null). */
|
|
29
|
+
objects: ConvertObject[];
|
|
30
|
+
filaments: FilamentSlotInfo[];
|
|
31
|
+
/** The file's first nozzle_diameter as written, e.g. "0.4". */
|
|
32
|
+
nozzleDiameter: string | null;
|
|
33
|
+
/** The supported nozzle size profile matching uses, or null if none could be read. */
|
|
34
|
+
matchNozzleDiameter: SupportedNozzleDiameter | null;
|
|
35
|
+
layerHeight: number | null;
|
|
36
|
+
/** The source's process preset, e.g. `"0.20mm Standard @BBL X1C"`. */
|
|
37
|
+
sourcePresetName: string | null;
|
|
38
|
+
/** The tier name parsed from it, e.g. "Standard". */
|
|
39
|
+
tierName: string | null;
|
|
40
|
+
/** e.g. "Bambu Lab X1 Carbon". */
|
|
41
|
+
printerModel: string | null;
|
|
42
|
+
sourceVendor: SourceVendor;
|
|
43
|
+
/** The source slicer's settings version string, e.g. "02.02.00.85". */
|
|
44
|
+
slicerVersion: string | null;
|
|
45
|
+
/** The source bed's printable_area, for drawing the source plate. */
|
|
46
|
+
sourcePrintableArea: string[] | null;
|
|
47
|
+
/** Non-fatal notes from reading the file. */
|
|
48
|
+
warnings: string[];
|
|
49
|
+
/**
|
|
50
|
+
* The project's unpacked size in bytes. Above 1 GB, converting takes a minute or two and a few GB of
|
|
51
|
+
* memory (the warnings say so too), so a UI can say that before the user converts.
|
|
52
|
+
*/
|
|
53
|
+
unpackedBytes: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The source printer's maker, from `printer_model` (e.g. "Creality K2 Plus"),
|
|
57
|
+
* falling back to the printer named after "@" in the process preset (e.g.
|
|
58
|
+
* "0.20mm Standard @BBL X1C"). Not the 3MF's Application tag: Anycubic
|
|
59
|
+
* Slicer Next writes "BambuStudio" there.
|
|
60
|
+
*/
|
|
61
|
+
export declare function detectSourceVendor(printerModel: string | null, sourcePresetName?: string | null): SourceVendor;
|
|
62
|
+
/** Builds an {@link Inspection} from a parsed project's settings and objects. */
|
|
63
|
+
export declare function inspectProject(projectSettings: Record<string, unknown>, objects: ConvertObject[], warnings: readonly string[], unpackedBytes: number): Inspection;
|
package/dist/inspect.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* What a UI needs to show about a source file before converting it: plates,
|
|
4
|
+
* objects and their footprints, filament slots with real color names, and
|
|
5
|
+
* the settings that drive profile matching. Everything here reads the
|
|
6
|
+
* file's own project_settings.config, which is untrusted, so every field is
|
|
7
|
+
* type-checked rather than cast.
|
|
8
|
+
*/
|
|
9
|
+
import { lookupFilamentColorName } from "./archive/lookupFilamentColorName.js";
|
|
10
|
+
import { detectNozzleDiameter } from "./engine/detectNozzleDiameter.js";
|
|
11
|
+
import { parseTierName } from "./engine/parseTierName.js";
|
|
12
|
+
import { plainText } from "./plainText.js";
|
|
13
|
+
const VENDOR_PATTERNS = [
|
|
14
|
+
{ vendor: "bambu", pattern: /^(bambu\s*lab|bbl)\b/i },
|
|
15
|
+
{ vendor: "creality", pattern: /^creality\b/i },
|
|
16
|
+
{ vendor: "anycubic", pattern: /^anycubic\b/i },
|
|
17
|
+
{ vendor: "snapmaker", pattern: /^snapmaker\b/i },
|
|
18
|
+
{ vendor: "elegoo", pattern: /^elegoo\b/i },
|
|
19
|
+
{ vendor: "prusa", pattern: /^(original\s+)?prusa\b/i },
|
|
20
|
+
{ vendor: "flashforge", pattern: /^flashforge\b/i },
|
|
21
|
+
];
|
|
22
|
+
const MAX_DISPLAY_STRING = 500;
|
|
23
|
+
function asDisplayString(value) {
|
|
24
|
+
if (typeof value === "string")
|
|
25
|
+
return value.trim() ? plainText(value.slice(0, MAX_DISPLAY_STRING)) : null;
|
|
26
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
27
|
+
return String(value);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
/** Keeps array positions so parallel arrays (colors, types, names) stay aligned; non-strings become "". */
|
|
31
|
+
function toStringArray(value) {
|
|
32
|
+
if (!Array.isArray(value))
|
|
33
|
+
return [];
|
|
34
|
+
return value.map((v) => (typeof v === "string" ? plainText(v.slice(0, MAX_DISPLAY_STRING)) : typeof v === "number" ? String(v) : ""));
|
|
35
|
+
}
|
|
36
|
+
function guessMaterial(presetName) {
|
|
37
|
+
for (const material of ["PLA", "PETG", "TPU", "ABS"])
|
|
38
|
+
if (presetName.includes(material))
|
|
39
|
+
return material;
|
|
40
|
+
return "Filament";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The source printer's maker, from `printer_model` (e.g. "Creality K2 Plus"),
|
|
44
|
+
* falling back to the printer named after "@" in the process preset (e.g.
|
|
45
|
+
* "0.20mm Standard @BBL X1C"). Not the 3MF's Application tag: Anycubic
|
|
46
|
+
* Slicer Next writes "BambuStudio" there.
|
|
47
|
+
*/
|
|
48
|
+
export function detectSourceVendor(printerModel, sourcePresetName = null) {
|
|
49
|
+
const presetPrinter = sourcePresetName?.split("@")[1]?.trim() ?? null;
|
|
50
|
+
for (const candidate of [printerModel, presetPrinter]) {
|
|
51
|
+
if (!candidate)
|
|
52
|
+
continue;
|
|
53
|
+
const match = VENDOR_PATTERNS.find(({ pattern }) => pattern.test(candidate));
|
|
54
|
+
if (match)
|
|
55
|
+
return match.vendor;
|
|
56
|
+
}
|
|
57
|
+
return "other";
|
|
58
|
+
}
|
|
59
|
+
/** Builds an {@link Inspection} from a parsed project's settings and objects. */
|
|
60
|
+
export function inspectProject(projectSettings, objects, warnings, unpackedBytes) {
|
|
61
|
+
const colors = toStringArray(projectSettings.filament_colour);
|
|
62
|
+
const types = toStringArray(projectSettings.filament_type);
|
|
63
|
+
const names = toStringArray(projectSettings.filament_settings_id);
|
|
64
|
+
const filaments = colors.map((color, i) => {
|
|
65
|
+
const presetName = names[i] ?? "";
|
|
66
|
+
const hex = color.startsWith("#") ? color : `#${color}`;
|
|
67
|
+
const colorName = lookupFilamentColorName(presetName, hex);
|
|
68
|
+
return {
|
|
69
|
+
slot: i + 1,
|
|
70
|
+
color: hex,
|
|
71
|
+
type: types[i] || guessMaterial(presetName),
|
|
72
|
+
presetName,
|
|
73
|
+
...(colorName ? { colorName } : {}),
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const plates = [...new Set(objects.flatMap((o) => (o.plate === undefined ? [] : [o.plate])))].sort((a, b) => a - b);
|
|
77
|
+
const rawNozzle = Array.isArray(projectSettings.nozzle_diameter) ? projectSettings.nozzle_diameter[0] : projectSettings.nozzle_diameter;
|
|
78
|
+
const layerHeightRaw = projectSettings.layer_height;
|
|
79
|
+
const layerHeightValue = typeof layerHeightRaw === "number" ? layerHeightRaw : typeof layerHeightRaw === "string" ? Number.parseFloat(layerHeightRaw) : NaN;
|
|
80
|
+
const sourcePresetName = asDisplayString(projectSettings.print_settings_id) ?? asDisplayString(projectSettings.name);
|
|
81
|
+
const printerModel = asDisplayString(projectSettings.printer_model) ??
|
|
82
|
+
asDisplayString(projectSettings.printer_settings_id)?.replace(/\s+\d+(\.\d+)?\s+nozzle$/i, "") ??
|
|
83
|
+
null;
|
|
84
|
+
const printableArea = projectSettings.printable_area;
|
|
85
|
+
return {
|
|
86
|
+
plates,
|
|
87
|
+
objects: objects.map((o) => ({ ...o })),
|
|
88
|
+
filaments,
|
|
89
|
+
nozzleDiameter: asDisplayString(rawNozzle),
|
|
90
|
+
matchNozzleDiameter: detectNozzleDiameter(projectSettings),
|
|
91
|
+
layerHeight: Number.isFinite(layerHeightValue) ? layerHeightValue : null,
|
|
92
|
+
sourcePresetName,
|
|
93
|
+
tierName: typeof projectSettings.print_settings_id === "string" ? parseTierName(projectSettings.print_settings_id) : null,
|
|
94
|
+
printerModel,
|
|
95
|
+
sourceVendor: detectSourceVendor(printerModel, sourcePresetName),
|
|
96
|
+
slicerVersion: asDisplayString(projectSettings.version),
|
|
97
|
+
sourcePrintableArea: Array.isArray(printableArea) && printableArea.length <= 64 && printableArea.every((p) => typeof p === "string")
|
|
98
|
+
? printableArea.slice()
|
|
99
|
+
: null,
|
|
100
|
+
warnings: [...warnings],
|
|
101
|
+
unpackedBytes,
|
|
102
|
+
};
|
|
103
|
+
}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ProfileSource } from "./profiles.js";
|
|
2
|
+
/**
|
|
3
|
+
* A catalog folder laid out like `any2orca-profiles`' `data/`:
|
|
4
|
+
* `index.json` plus `profiles/<id>.json`. Used for `--profiles-dir`, to try
|
|
5
|
+
* newer or custom profiles without waiting for a release.
|
|
6
|
+
*/
|
|
7
|
+
export declare function dirProfileSource(dir: string): ProfileSource;
|
|
8
|
+
/** The `data/` folder of the installed `any2orca-profiles` package. */
|
|
9
|
+
export declare function bundledProfilesDir(): string;
|
|
10
|
+
/** The catalog from the installed `any2orca-profiles` package. */
|
|
11
|
+
export declare function bundledProfileSource(): ProfileSource;
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* any2orca/node: profile sources that read from disk, for Node scripts,
|
|
4
|
+
* servers and the CLI.
|
|
5
|
+
*
|
|
6
|
+
* import { convert } from "any2orca";
|
|
7
|
+
* import { bundledProfileSource } from "any2orca/node";
|
|
8
|
+
* const { output, report } = await convert(bytes, { profiles: bundledProfileSource() });
|
|
9
|
+
*/
|
|
10
|
+
import { readFile, stat } from "node:fs/promises";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import { dirname, join, resolve } from "node:path";
|
|
13
|
+
import { MAX_INDEX_BYTES, MAX_PROFILE_BYTES, parseCatalogJson, ProfileDataError } from "./profiles.js";
|
|
14
|
+
async function readCapped(path, maxBytes) {
|
|
15
|
+
let size;
|
|
16
|
+
try {
|
|
17
|
+
size = (await stat(path)).size;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new ProfileDataError(`Profile catalog file not found: ${path}`);
|
|
21
|
+
}
|
|
22
|
+
if (size > maxBytes)
|
|
23
|
+
throw new ProfileDataError(`${path} is larger than the ${maxBytes} byte limit.`);
|
|
24
|
+
return parseCatalogJson(await readFile(path, "utf-8"), maxBytes, path);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A catalog folder laid out like `any2orca-profiles`' `data/`:
|
|
28
|
+
* `index.json` plus `profiles/<id>.json`. Used for `--profiles-dir`, to try
|
|
29
|
+
* newer or custom profiles without waiting for a release.
|
|
30
|
+
*/
|
|
31
|
+
export function dirProfileSource(dir) {
|
|
32
|
+
const root = resolve(dir);
|
|
33
|
+
return {
|
|
34
|
+
readIndex: () => readCapped(join(root, "index.json"), MAX_INDEX_BYTES),
|
|
35
|
+
// Ids are validated against the index (lowercase letters, digits, dots
|
|
36
|
+
// and dashes, no slashes) before this is called, so this stays in root.
|
|
37
|
+
readProfile: (id) => readCapped(join(root, "profiles", `${id}.json`), MAX_PROFILE_BYTES),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** The `data/` folder of the installed `any2orca-profiles` package. */
|
|
41
|
+
export function bundledProfilesDir() {
|
|
42
|
+
const require = createRequire(import.meta.url);
|
|
43
|
+
return join(dirname(require.resolve("any2orca-profiles/package.json")), "data");
|
|
44
|
+
}
|
|
45
|
+
let bundled;
|
|
46
|
+
/** The catalog from the installed `any2orca-profiles` package. */
|
|
47
|
+
export function bundledProfileSource() {
|
|
48
|
+
bundled ??= dirProfileSource(bundledProfilesDir());
|
|
49
|
+
return bundled;
|
|
50
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text from a file, made safe to show as plain text: every control character
|
|
3
|
+
* except newline and tab, and every Unicode direction override, becomes the
|
|
4
|
+
* replacement character. A crafted value could otherwise send terminal codes
|
|
5
|
+
* (clear the screen, change the window title, in some terminals write to the
|
|
6
|
+
* clipboard) or make text read differently from what it is. Use it before
|
|
7
|
+
* printing setting values, names or notes from a 3MF to a terminal or log.
|
|
8
|
+
* (For a web page, setting the text with `textContent` is already safe.)
|
|
9
|
+
*/
|
|
10
|
+
export declare function plainText(text: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
const UNSAFE = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f--]/g;
|
|
3
|
+
/**
|
|
4
|
+
* Text from a file, made safe to show as plain text: every control character
|
|
5
|
+
* except newline and tab, and every Unicode direction override, becomes the
|
|
6
|
+
* replacement character. A crafted value could otherwise send terminal codes
|
|
7
|
+
* (clear the screen, change the window title, in some terminals write to the
|
|
8
|
+
* clipboard) or make text read differently from what it is. Use it before
|
|
9
|
+
* printing setting values, names or notes from a 3MF to a terminal or log.
|
|
10
|
+
* (For a web page, setting the text with `textContent` is already safe.)
|
|
11
|
+
*/
|
|
12
|
+
export function plainText(text) {
|
|
13
|
+
return text.replace(UNSAFE, "�");
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ProfileCatalog, type ProfileSource } from "../profiles.js";
|
|
2
|
+
import { Project } from "../project.js";
|
|
3
|
+
import { type ExtractedPreset } from "./preset.js";
|
|
4
|
+
/**
|
|
5
|
+
* Makes a preset from a 3MF the user tuned in Snapmaker Orca: finds the U1
|
|
6
|
+
* profile it was tuned on and keeps the print settings that differ from that
|
|
7
|
+
* profile's stock values. Throws `preset_base_unknown` for a file that isn't
|
|
8
|
+
* set up for the U1 (convert it first, tune it, save it, then make the
|
|
9
|
+
* preset), or `invalid_file` / `invalid_project` for a file that can't be read.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractPreset(input: Uint8Array | Project, options: {
|
|
12
|
+
profiles: ProfileSource | ProfileCatalog;
|
|
13
|
+
}): Promise<ExtractedPreset>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { sameSetting } from "../diff/diffSettings.js";
|
|
3
|
+
import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
|
|
4
|
+
import { Any2orcaError } from "../errors.js";
|
|
5
|
+
import { loadCatalog } from "../profiles.js";
|
|
6
|
+
import { Project } from "../project.js";
|
|
7
|
+
import { checkedChanges, describeChanges, stockValue } from "./preset.js";
|
|
8
|
+
import { isPresetKey } from "./presetKeys.js";
|
|
9
|
+
function today() {
|
|
10
|
+
return new Date().toISOString().slice(0, 10);
|
|
11
|
+
}
|
|
12
|
+
/** A profile name as Snapmaker Orca 2.4 writes it: older releases left out the "mm" ("0.20 Standard @..."). */
|
|
13
|
+
function profileNameKey(name) {
|
|
14
|
+
return name.trim().replace(/^(\d+(?:\.\d+)?)(?:mm)?\s+/, "$1mm ");
|
|
15
|
+
}
|
|
16
|
+
function stringSetting(settings, key) {
|
|
17
|
+
const value = settings[key];
|
|
18
|
+
if (typeof value === "string")
|
|
19
|
+
return value;
|
|
20
|
+
if (Array.isArray(value) && typeof value[0] === "string")
|
|
21
|
+
return value[0];
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Makes a preset from a 3MF the user tuned in Snapmaker Orca: finds the U1
|
|
26
|
+
* profile it was tuned on and keeps the print settings that differ from that
|
|
27
|
+
* profile's stock values. Throws `preset_base_unknown` for a file that isn't
|
|
28
|
+
* set up for the U1 (convert it first, tune it, save it, then make the
|
|
29
|
+
* preset), or `invalid_file` / `invalid_project` for a file that can't be read.
|
|
30
|
+
*/
|
|
31
|
+
export async function extractPreset(input, options) {
|
|
32
|
+
const project = input instanceof Project ? input : Project.open(input);
|
|
33
|
+
const settings = project.settings();
|
|
34
|
+
const catalog = await loadCatalog(options.profiles);
|
|
35
|
+
const notes = [];
|
|
36
|
+
const printer = [stringSetting(settings, "printer_settings_id"), stringSetting(settings, "printer_model")];
|
|
37
|
+
if (!printer.some((name) => name !== null && name.includes("Snapmaker U1"))) {
|
|
38
|
+
throw new Any2orcaError("preset_base_unknown", "This project isn't set up for the Snapmaker U1, so there's nothing to compare it with. Convert it, tune it in Snapmaker Orca, save it, then make the preset from that file.");
|
|
39
|
+
}
|
|
40
|
+
const byName = new Map(catalog.list().map((s) => [profileNameKey(s.displayName), s.id]));
|
|
41
|
+
let base = byName.get(profileNameKey(stringSetting(settings, "print_settings_id") ?? ""));
|
|
42
|
+
let baseInferred = false;
|
|
43
|
+
if (!base) {
|
|
44
|
+
const parent = byName.get(profileNameKey(stringSetting(settings, "inherits_group") ?? ""));
|
|
45
|
+
if (parent) {
|
|
46
|
+
base = parent;
|
|
47
|
+
notes.push(`The project uses its own print preset; its changes are compared with ${catalog.get(parent)?.displayName}, the profile it was made from.`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!base) {
|
|
51
|
+
const choice = await project.matchProfile(catalog);
|
|
52
|
+
if (choice.profileMatch.matchSource === "default-fallback") {
|
|
53
|
+
throw new Any2orcaError("preset_base_unknown", "This project's nozzle size can't be read, so there's no U1 profile to compare it with.");
|
|
54
|
+
}
|
|
55
|
+
base = choice.profileId;
|
|
56
|
+
baseInferred = true;
|
|
57
|
+
notes.push(`The project doesn't name a U1 profile; it's compared with ${catalog.get(base)?.displayName}, the closest match for its nozzle and layer height.`);
|
|
58
|
+
}
|
|
59
|
+
const loaded = await catalog.load(base);
|
|
60
|
+
const stock = loaded.convertProfile.profile.baselineProjectSettings;
|
|
61
|
+
const differing = {};
|
|
62
|
+
for (const key of Object.keys(settings)) {
|
|
63
|
+
if (!Object.hasOwn(SETTINGS_CATALOG, key) || SETTINGS_CATALOG[key].group !== "print")
|
|
64
|
+
continue;
|
|
65
|
+
// Bookkeeping and the hotend-type layout differ from the stock profile's for reasons that aren't tuning; not worth a note.
|
|
66
|
+
if (key === "inherits" || key === "process_flow_support" || key.startsWith("compatible_printers"))
|
|
67
|
+
continue;
|
|
68
|
+
// A setting the profile doesn't have is noted only when the preset couldn't carry it anyway (a script, say).
|
|
69
|
+
if (!Object.hasOwn(stock, key) && isPresetKey(key))
|
|
70
|
+
continue;
|
|
71
|
+
if (sameSetting(stockValue(key, settings[key]), stockValue(key, stock[key])))
|
|
72
|
+
continue;
|
|
73
|
+
Object.defineProperty(differing, key, { value: settings[key], enumerable: true });
|
|
74
|
+
}
|
|
75
|
+
const changes = checkedChanges(differing, stock, notes);
|
|
76
|
+
return {
|
|
77
|
+
preset: {
|
|
78
|
+
base,
|
|
79
|
+
baseInferred,
|
|
80
|
+
catalog: { version: catalog.index.dataVersion, tracks: `${catalog.index.slicer.name} ${catalog.index.slicer.version}` },
|
|
81
|
+
changes,
|
|
82
|
+
created: today(),
|
|
83
|
+
},
|
|
84
|
+
changes: describeChanges(changes, stock, loaded.convertProfile.printer.machineSettingsConfig),
|
|
85
|
+
notes,
|
|
86
|
+
};
|
|
87
|
+
}
|