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
package/dist/project.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The two-step API: open a file once, inspect it, convert it (as many
|
|
4
|
+
* times as needed, e.g. with a different profile picked in a UI).
|
|
5
|
+
*
|
|
6
|
+
* `convert()` runs in the caller's own process: read the 3MF, match a
|
|
7
|
+
* profile, merge settings, recenter objects, write the output. The request
|
|
8
|
+
* and response pass through JSON, so numbers serialize the same way every
|
|
9
|
+
* time (e.g. -0 becomes 0) and output is reproducible byte for byte.
|
|
10
|
+
*/
|
|
11
|
+
import { applyConvertResponse, prepareConvertRequest } from "./archive/zip.js";
|
|
12
|
+
import { unwrapIfBundle } from "./archive/unwrapBundle.js";
|
|
13
|
+
import { detectNozzleDiameter } from "./engine/detectNozzleDiameter.js";
|
|
14
|
+
import { parseTierName } from "./engine/parseTierName.js";
|
|
15
|
+
import { pickProfile } from "./engine/pickProfile.js";
|
|
16
|
+
import { runConvertPipeline } from "./engine/runConvertPipeline.js";
|
|
17
|
+
import { diffSettings } from "./diff/diffSettings.js";
|
|
18
|
+
import { Any2orcaError } from "./errors.js";
|
|
19
|
+
import { toWhatChanged } from "./explain/whatChanged.js";
|
|
20
|
+
import { inspectProject } from "./inspect.js";
|
|
21
|
+
import { loadCatalog, ProfileCatalog } from "./profiles.js";
|
|
22
|
+
import { ConvertRequestSchema, ConvertResponseSchema, HighFlowHotendsSchema, } from "./schema.js";
|
|
23
|
+
import { resolveAboveStockChoice } from "./engine/aboveStock.js";
|
|
24
|
+
import { presetFingerprint, resolvePreset } from "./presets/preset.js";
|
|
25
|
+
import { encodeStamp, STAMP_PATH } from "./stamp.js";
|
|
26
|
+
import { plainText } from "./plainText.js";
|
|
27
|
+
import { VERSION } from "./version.js";
|
|
28
|
+
function numericLayerHeight(projectSettings) {
|
|
29
|
+
const raw = projectSettings.layer_height;
|
|
30
|
+
const value = typeof raw === "string" ? Number(raw.trim()) : typeof raw === "number" ? raw : NaN;
|
|
31
|
+
return Number.isFinite(value) && value > 0 ? value : null;
|
|
32
|
+
}
|
|
33
|
+
function rawNozzleDiameter(projectSettings) {
|
|
34
|
+
const raw = projectSettings.nozzle_diameter;
|
|
35
|
+
const first = Array.isArray(raw) ? raw[0] : raw;
|
|
36
|
+
const value = typeof first === "string" ? Number(first.trim()) : typeof first === "number" ? first : NaN;
|
|
37
|
+
return Number.isFinite(value) ? value : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Picks a profile for a file's settings, the same way every UI should (never
|
|
41
|
+
* re-implement this): the source's own tier name first (from its
|
|
42
|
+
* print_settings_id, e.g. "Extra Fine"), then the nearest layer height for
|
|
43
|
+
* its nozzle size, then the catalog default.
|
|
44
|
+
*/
|
|
45
|
+
export async function matchProfile(projectSettings, profiles) {
|
|
46
|
+
const catalog = await loadCatalog(profiles);
|
|
47
|
+
const detectedDiameter = detectNozzleDiameter(projectSettings);
|
|
48
|
+
const sourceLayerHeight = numericLayerHeight(projectSettings);
|
|
49
|
+
const printSettingsId = projectSettings.print_settings_id;
|
|
50
|
+
const picked = detectedDiameter
|
|
51
|
+
? pickProfile(catalog.list({ nozzleDiameter: detectedDiameter }), {
|
|
52
|
+
layerHeight: sourceLayerHeight,
|
|
53
|
+
tierName: typeof printSettingsId === "string" ? parseTierName(printSettingsId) : null,
|
|
54
|
+
})
|
|
55
|
+
: null;
|
|
56
|
+
const profileId = picked?.profileId ?? catalog.index.defaultProfileId;
|
|
57
|
+
const notes = [];
|
|
58
|
+
const sourceNozzle = rawNozzleDiameter(projectSettings);
|
|
59
|
+
if (sourceNozzle === null) {
|
|
60
|
+
notes.push("the source file doesn't give a usable nozzle size, so the default profile is used");
|
|
61
|
+
}
|
|
62
|
+
else if (detectedDiameter && Math.abs(sourceNozzle - Number(detectedDiameter)) > 1e-6) {
|
|
63
|
+
notes.push(`the source file is set up for a ${sourceNozzle}mm nozzle, which has no U1 profile; the ${detectedDiameter}mm profile is used`);
|
|
64
|
+
}
|
|
65
|
+
if (Object.hasOwn(projectSettings, "layer_height") && sourceLayerHeight === null) {
|
|
66
|
+
notes.push(`the source file's layer height (${plainText(String(projectSettings.layer_height)).slice(0, 40)}) isn't a usable number, so it isn't used to choose the profile`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
profileId,
|
|
70
|
+
profileMatch: {
|
|
71
|
+
profileId,
|
|
72
|
+
nozzleDiameter: detectedDiameter ?? "",
|
|
73
|
+
exact: picked?.exact ?? false,
|
|
74
|
+
matchedByTierName: picked?.matchedByTierName ?? false,
|
|
75
|
+
matchSource: picked ? (picked.matchedByTierName ? "auto-tier-name" : picked.exact ? "auto-exact" : "auto-nearest") : "default-fallback",
|
|
76
|
+
},
|
|
77
|
+
carrySourceLayerHeight: Boolean(picked && !picked.exact && sourceLayerHeight !== null),
|
|
78
|
+
notes,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Same cleanup every UI applies before showing warnings: drop routine
|
|
83
|
+
* bookkeeping lines, strip the internal "WARN" prefix and internal file
|
|
84
|
+
* names.
|
|
85
|
+
*/
|
|
86
|
+
export function cleanWarnings(warnings) {
|
|
87
|
+
return warnings
|
|
88
|
+
.map((w) => w.trim())
|
|
89
|
+
.filter((w) => {
|
|
90
|
+
if (!w)
|
|
91
|
+
return false;
|
|
92
|
+
if (w.includes("SKIP filament_colour: list length mismatch"))
|
|
93
|
+
return false;
|
|
94
|
+
if (w.includes("left unchanged"))
|
|
95
|
+
return false;
|
|
96
|
+
if (w.includes("ignored") && w.includes("trailing non-JSON"))
|
|
97
|
+
return false;
|
|
98
|
+
return true;
|
|
99
|
+
})
|
|
100
|
+
.map((w) => w
|
|
101
|
+
.replace(/^WARN:\s*/i, "")
|
|
102
|
+
.replace(/^WARN\s+/i, "")
|
|
103
|
+
.replace(/\s+in\s+model_settings\.config\.?/i, "")
|
|
104
|
+
.replace(/\s+in\s+3D\/3dmodel\.model\.?/i, "")
|
|
105
|
+
.replace(/\s+in\s+[A-Za-z0-9_./-]+\.(config|model|xml)\.?/i, "")
|
|
106
|
+
.replace(/\.$/, ""))
|
|
107
|
+
// Warnings can quote names from the file; they're prose for people, so they never carry control characters.
|
|
108
|
+
.map(plainText);
|
|
109
|
+
}
|
|
110
|
+
/** JSON round trip, as the request and response took over HTTP. */
|
|
111
|
+
function viaJson(value) {
|
|
112
|
+
return JSON.parse(JSON.stringify(value));
|
|
113
|
+
}
|
|
114
|
+
const BOOLEAN_OPTIONS = ["hardenedNozzles", "stamp", "explain"];
|
|
115
|
+
/**
|
|
116
|
+
* Checks what a caller passed before anything uses it. These are programming
|
|
117
|
+
* mistakes rather than problems with a file, so they're a TypeError with a
|
|
118
|
+
* sentence (the worker forwards whatever a page posts, so this is where they're caught).
|
|
119
|
+
*/
|
|
120
|
+
function checkConvertOptions(options) {
|
|
121
|
+
const o = (options ?? {});
|
|
122
|
+
const profiles = o.profiles;
|
|
123
|
+
if (!(profiles instanceof ProfileCatalog) && (typeof profiles !== "object" || profiles === null || typeof profiles.readIndex !== "function" || typeof profiles.readProfile !== "function")) {
|
|
124
|
+
throw new TypeError("convert() needs a `profiles` option: a ProfileSource or a ProfileCatalog.");
|
|
125
|
+
}
|
|
126
|
+
if (o.filamentComplianceMode !== undefined && o.filamentComplianceMode !== "generic" && o.filamentComplianceMode !== "snapmaker") {
|
|
127
|
+
throw new TypeError('The `filamentComplianceMode` option must be "generic" or "snapmaker", or left out.');
|
|
128
|
+
}
|
|
129
|
+
for (const key of BOOLEAN_OPTIONS) {
|
|
130
|
+
if (o[key] !== undefined && typeof o[key] !== "boolean")
|
|
131
|
+
throw new TypeError(`The \`${key}\` option must be true or false.`);
|
|
132
|
+
}
|
|
133
|
+
if (o.profileId !== undefined && typeof o.profileId !== "string")
|
|
134
|
+
throw new TypeError("The `profileId` option must be a string.");
|
|
135
|
+
const hf = o.highFlowHotends;
|
|
136
|
+
// A list's length and entries are checked where it's read (normalizeHighFlowOption).
|
|
137
|
+
if (hf !== undefined && typeof hf !== "boolean" && !Array.isArray(hf)) {
|
|
138
|
+
throw new TypeError("The `highFlowHotends` option must be true, false or a list of true/false, one per toolhead.");
|
|
139
|
+
}
|
|
140
|
+
const above = o.aboveStock;
|
|
141
|
+
const stringList = (v) => v === undefined || (Array.isArray(v) && v.every((x) => typeof x === "string"));
|
|
142
|
+
if (above !== undefined && (typeof above !== "object" || above === null || !stringList(above.keep) || !stringList(above.stock))) {
|
|
143
|
+
throw new TypeError("The `aboveStock` option must be { keep?: string[], stock?: string[] }.");
|
|
144
|
+
}
|
|
145
|
+
if (o.onProgress !== undefined && typeof o.onProgress !== "function")
|
|
146
|
+
throw new TypeError("The `onProgress` option must be a function.");
|
|
147
|
+
}
|
|
148
|
+
function describeIssues(issues) {
|
|
149
|
+
return issues
|
|
150
|
+
.slice(0, 3)
|
|
151
|
+
.map((issue) => `${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`)
|
|
152
|
+
.join("; ");
|
|
153
|
+
}
|
|
154
|
+
/** An opened source file. Reading it again is the expensive part, so keep one per file. */
|
|
155
|
+
export class Project {
|
|
156
|
+
parsed;
|
|
157
|
+
request;
|
|
158
|
+
constructor(parsed, request) {
|
|
159
|
+
this.parsed = parsed;
|
|
160
|
+
this.request = request;
|
|
161
|
+
}
|
|
162
|
+
/** Reads a .3mf. Throws {@link Any2orcaError} (`invalid_file`, `too_large` or `invalid_project`) if it can't be used. */
|
|
163
|
+
static open(bytes, options = {}) {
|
|
164
|
+
let parsed;
|
|
165
|
+
try {
|
|
166
|
+
parsed = prepareConvertRequest(bytes, options.maxUnpackedBytes);
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
if (err instanceof Any2orcaError)
|
|
170
|
+
throw err;
|
|
171
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
172
|
+
// The zip reader's own errors ("invalid zip data", "unexpected EOF") mean a damaged or partial download.
|
|
173
|
+
const damaged = /invalid zip data|unexpected EOF|invalid (block type|length|distance)|unknown compression/i.test(reason);
|
|
174
|
+
const text = damaged ? "it isn't a complete zip archive (a .3mf is one). It may be damaged or only partly downloaded; download it again." : reason;
|
|
175
|
+
throw new Any2orcaError("invalid_file", `This file can't be read as a 3MF project: ${text}`, {
|
|
176
|
+
cause: err,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
const checked = ConvertRequestSchema.safeParse(viaJson(parsed.request));
|
|
180
|
+
if (!checked.success) {
|
|
181
|
+
throw new Any2orcaError("invalid_project", `This project's settings can't be converted: ${describeIssues(checked.error.issues)}`);
|
|
182
|
+
}
|
|
183
|
+
return new Project(parsed, checked.data);
|
|
184
|
+
}
|
|
185
|
+
/** The project's own settings (Metadata/project_settings.config), as a copy: for a settings diff. */
|
|
186
|
+
settings() {
|
|
187
|
+
return structuredClone(this.request.projectSettings);
|
|
188
|
+
}
|
|
189
|
+
inspect() {
|
|
190
|
+
return inspectProject(this.request.projectSettings, this.request.objects, this.parsed.warnings, this.parsed.unpackedBytes);
|
|
191
|
+
}
|
|
192
|
+
/** The profile auto-matching would pick for this file. */
|
|
193
|
+
matchProfile(profiles) {
|
|
194
|
+
return matchProfile(this.request.projectSettings, profiles);
|
|
195
|
+
}
|
|
196
|
+
async convert(options) {
|
|
197
|
+
checkConvertOptions(options);
|
|
198
|
+
const progress = options.onProgress ?? (() => { });
|
|
199
|
+
progress("matching");
|
|
200
|
+
const catalog = await loadCatalog(options.profiles);
|
|
201
|
+
const routeWarnings = [];
|
|
202
|
+
let profileId;
|
|
203
|
+
let profileMatch;
|
|
204
|
+
let carrySourceLayerHeight = false;
|
|
205
|
+
let retiredProfile;
|
|
206
|
+
if (options.preset && options.profileId) {
|
|
207
|
+
throw new Any2orcaError("invalid_preset", "A preset sets its own profile, so it can't be combined with a profile id.");
|
|
208
|
+
}
|
|
209
|
+
const preset = options.preset ? await resolvePreset(options.preset, catalog) : null;
|
|
210
|
+
const aboveStock = resolveAboveStockChoice(options.aboveStock);
|
|
211
|
+
if (preset) {
|
|
212
|
+
profileId = preset.profileId;
|
|
213
|
+
routeWarnings.push(...preset.notes.map((note) => ` WARN: ${note}`));
|
|
214
|
+
}
|
|
215
|
+
else if (options.profileId) {
|
|
216
|
+
profileId = options.profileId;
|
|
217
|
+
retiredProfile = catalog.retiredSuccessor(profileId);
|
|
218
|
+
if (retiredProfile) {
|
|
219
|
+
routeWarnings.push(` WARN: profile "${profileId}" (${retiredProfile.displayName}) has been retired; converted with "${retiredProfile.successorId}" instead. Run "any2orca profiles" for the current list.`);
|
|
220
|
+
profileId = retiredProfile.successorId;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
const choice = await matchProfile(this.request.projectSettings, catalog);
|
|
225
|
+
profileId = choice.profileId;
|
|
226
|
+
profileMatch = choice.profileMatch;
|
|
227
|
+
carrySourceLayerHeight = choice.carrySourceLayerHeight;
|
|
228
|
+
routeWarnings.push(...choice.notes.map((note) => ` WARN: ${note}`));
|
|
229
|
+
}
|
|
230
|
+
progress("loading-profile");
|
|
231
|
+
const loaded = await catalog.load(profileId);
|
|
232
|
+
progress("merging");
|
|
233
|
+
if (preset) {
|
|
234
|
+
const sourceNozzle = detectNozzleDiameter(this.request.projectSettings);
|
|
235
|
+
if (sourceNozzle && sourceNozzle !== loaded.summary.nozzleDiameter) {
|
|
236
|
+
routeWarnings.push(` WARN: converted with your ${loaded.summary.nozzleDiameter}mm nozzle preset; the original project was set up for a ${sourceNozzle}mm nozzle.`);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const highFlowHotends = normalizeHighFlowOption(options.highFlowHotends);
|
|
240
|
+
const request = {
|
|
241
|
+
...this.request,
|
|
242
|
+
...(options.filamentComplianceMode ? { filamentComplianceMode: options.filamentComplianceMode } : {}),
|
|
243
|
+
...(highFlowHotends !== false ? { highFlowHotends } : {}),
|
|
244
|
+
...(options.hardenedNozzles === true ? { hardenedNozzles: true } : {}),
|
|
245
|
+
};
|
|
246
|
+
const pipeline = runConvertPipeline(loaded.convertProfile, request, catalog.index.slicer.application, {
|
|
247
|
+
carrySourceLayerHeight,
|
|
248
|
+
...(preset ? { presetChanges: preset.changes } : {}),
|
|
249
|
+
...(aboveStock.keep.size + aboveStock.stock.size > 0 ? { aboveStock } : {}),
|
|
250
|
+
});
|
|
251
|
+
const checked = ConvertResponseSchema.safeParse(viaJson({
|
|
252
|
+
...pipeline.response,
|
|
253
|
+
...(routeWarnings.length > 0 ? { warnings: [...routeWarnings, ...(pipeline.response.warnings ?? [])] } : {}),
|
|
254
|
+
...(profileMatch ? { profileMatch } : {}),
|
|
255
|
+
}));
|
|
256
|
+
// Numbers that don't survive JSON (an object placed absurdly far away, say) end up here.
|
|
257
|
+
if (!checked.success) {
|
|
258
|
+
throw new Any2orcaError("invalid_project", `This project can't be converted: ${describeIssues(checked.error.issues)}.`);
|
|
259
|
+
}
|
|
260
|
+
const response = checked.data;
|
|
261
|
+
const stamp = options.stamp === false
|
|
262
|
+
? null
|
|
263
|
+
: {
|
|
264
|
+
stamp: 1,
|
|
265
|
+
generator: "any2orca",
|
|
266
|
+
version: VERSION,
|
|
267
|
+
profiles: { version: catalog.index.dataVersion, tracks: `${catalog.index.slicer.name} ${catalog.index.slicer.version}` },
|
|
268
|
+
profileId,
|
|
269
|
+
options: {
|
|
270
|
+
highFlowHotends,
|
|
271
|
+
hardenedNozzles: options.hardenedNozzles === true,
|
|
272
|
+
filamentComplianceMode: options.filamentComplianceMode ?? null,
|
|
273
|
+
...(preset ? { preset: { base: preset.profileId, keys: Object.keys(preset.changes).sort(), sha256: await presetFingerprint(preset.changes) } } : {}),
|
|
274
|
+
...(aboveStock.keep.size + aboveStock.stock.size > 0 ? { aboveStock: { keep: [...aboveStock.keep].sort(), stock: [...aboveStock.stock].sort() } } : {}),
|
|
275
|
+
},
|
|
276
|
+
};
|
|
277
|
+
// applyConvertResponse appends its own notes to the project's warning
|
|
278
|
+
// list; give it a copy so converting twice doesn't repeat them.
|
|
279
|
+
progress("writing");
|
|
280
|
+
const applyWarnings = [];
|
|
281
|
+
const output = applyConvertResponse({ ...this.parsed, warnings: applyWarnings }, response, stamp ? { [STAMP_PATH]: encodeStamp(stamp) } : {});
|
|
282
|
+
const inspection = this.inspect();
|
|
283
|
+
return {
|
|
284
|
+
output,
|
|
285
|
+
report: {
|
|
286
|
+
profile: loaded.summary,
|
|
287
|
+
...(profileMatch ? { profileMatch } : {}),
|
|
288
|
+
...(retiredProfile ? { retiredProfile } : {}),
|
|
289
|
+
warnings: cleanWarnings([...this.parsed.warnings, ...(response.warnings ?? []), ...applyWarnings.filter((w) => w.includes("WARN"))]),
|
|
290
|
+
log: [...this.parsed.warnings, ...routeWarnings, ...pipeline.warnings, ...applyWarnings].map((w) => w.trim()).filter(Boolean),
|
|
291
|
+
...(response.filamentComplianceFallback ? { filamentComplianceFallback: response.filamentComplianceFallback } : {}),
|
|
292
|
+
...(response.filamentComplianceUnchanged ? { filamentComplianceUnchanged: response.filamentComplianceUnchanged } : {}),
|
|
293
|
+
shifts: response.shifts,
|
|
294
|
+
plates: Math.max(1, inspection.plates.length),
|
|
295
|
+
objects: inspection.objects.length,
|
|
296
|
+
filamentSlots: inspection.filaments.length,
|
|
297
|
+
stamp,
|
|
298
|
+
whatChanged: toWhatChanged({ id: loaded.summary.id, displayName: loaded.summary.displayName, chosenBy: preset ? "preset" : options.profileId ? "you" : "matched" }, pipeline.changes, options.explain
|
|
299
|
+
? diffSettings({ label: "Original file", settings: this.request.projectSettings }, { label: "Converted file", settings: response.projectSettings })
|
|
300
|
+
: undefined),
|
|
301
|
+
...(preset ? { preset: { base: preset.profileId, changes: preset.described, notes: preset.notes } } : {}),
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/** Opens a .3mf; see {@link Project}. */
|
|
307
|
+
export function openProject(bytes, options = {}) {
|
|
308
|
+
return Project.open(bytes, options);
|
|
309
|
+
}
|
|
310
|
+
/** Reads a .3mf and describes it, without converting. */
|
|
311
|
+
export function inspect(bytes, options = {}) {
|
|
312
|
+
return Project.open(bytes, options).inspect();
|
|
313
|
+
}
|
|
314
|
+
/** Reads and converts a .3mf in one step. `maxUnpackedBytes` applies to reading it. */
|
|
315
|
+
export function convert(bytes, options) {
|
|
316
|
+
const { maxUnpackedBytes, ...convertOptions } = options;
|
|
317
|
+
return Project.open(bytes, { maxUnpackedBytes }).convert(convertOptions);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* A zip bundling several .3mf files (e.g. a "download all variants"
|
|
321
|
+
* archive) returns each one; a plain .3mf, or anything else, returns null.
|
|
322
|
+
*/
|
|
323
|
+
export function unwrapBundle(bytes, options = {}) {
|
|
324
|
+
return unwrapIfBundle(bytes, options.maxUnpackedBytes);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* The high-flow option as recorded in the request and the stamp: `false`
|
|
328
|
+
* for none, or one entry per toolhead. `true` becomes all four. Rejects any
|
|
329
|
+
* other shape instead of guessing, since a wrong hotend choice changes the
|
|
330
|
+
* speeds a toolhead prints at.
|
|
331
|
+
*/
|
|
332
|
+
function normalizeHighFlowOption(value) {
|
|
333
|
+
if (value === undefined || value === false)
|
|
334
|
+
return false;
|
|
335
|
+
if (value === true)
|
|
336
|
+
return [true, true, true, true];
|
|
337
|
+
const parsed = HighFlowHotendsSchema.safeParse(value);
|
|
338
|
+
if (!parsed.success || typeof parsed.data === "boolean") {
|
|
339
|
+
throw new TypeError("highFlowHotends must be true, false, or a list of exactly 4 booleans (one per toolhead, T1 first).");
|
|
340
|
+
}
|
|
341
|
+
return parsed.data.some(Boolean) ? [...parsed.data] : false;
|
|
342
|
+
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine's internal request/response shapes. The request is built and
|
|
3
|
+
* consumed in the same process. They are zod schemas because the request
|
|
4
|
+
* is built from a file someone dropped in, which is untrusted:
|
|
5
|
+
* validating it bounds how much work a crafted file can cause.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/** A single top-level object's plate assignment and computed bounding box. */
|
|
9
|
+
export declare const ConvertObjectSchema: z.ZodObject<{
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
name: z.ZodOptional<z.ZodString>;
|
|
12
|
+
sequence: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
isAssembly: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
plate: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
bbox: z.ZodNullable<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
16
|
+
fallbackXy: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export type ConvertObject = z.infer<typeof ConvertObjectSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* A parsed Metadata/project_settings.config: hundreds of slicer settings,
|
|
21
|
+
* so open-shaped by key, with a cap on its serialized size. A real one runs
|
|
22
|
+
* tens to a few hundred KB.
|
|
23
|
+
*/
|
|
24
|
+
export declare const MAX_PROJECT_SETTINGS_BYTES: number;
|
|
25
|
+
export declare const ProjectSettingsSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
26
|
+
export type ProjectSettings = z.infer<typeof ProjectSettingsSchema>;
|
|
27
|
+
/** Far past any real multi-plate project; bounds the work one file can cause. */
|
|
28
|
+
export declare const MAX_OBJECTS = 1000;
|
|
29
|
+
export declare const FilamentComplianceModeSchema: z.ZodEnum<{
|
|
30
|
+
generic: "generic";
|
|
31
|
+
snapmaker: "snapmaker";
|
|
32
|
+
}>;
|
|
33
|
+
/** `true` for every toolhead, or exactly one entry per U1 toolhead, T1 to T4. */
|
|
34
|
+
export declare const HighFlowHotendsSchema: z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodBoolean>]>;
|
|
35
|
+
export type HighFlowHotends = z.infer<typeof HighFlowHotendsSchema>;
|
|
36
|
+
export declare const ConvertRequestSchema: z.ZodObject<{
|
|
37
|
+
projectSettings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
38
|
+
objects: z.ZodArray<z.ZodObject<{
|
|
39
|
+
id: z.ZodString;
|
|
40
|
+
name: z.ZodOptional<z.ZodString>;
|
|
41
|
+
sequence: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
isAssembly: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
plate: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
bbox: z.ZodNullable<z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>>;
|
|
45
|
+
fallbackXy: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
profileId: z.ZodOptional<z.ZodString>;
|
|
48
|
+
filamentComplianceMode: z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
generic: "generic";
|
|
50
|
+
snapmaker: "snapmaker";
|
|
51
|
+
}>>;
|
|
52
|
+
highFlowHotends: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodBoolean>]>>;
|
|
53
|
+
hardenedNozzles: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export type ConvertRequest = z.infer<typeof ConvertRequestSchema>;
|
|
56
|
+
/** Other Metadata/*.config files to write into the output 3MF, keyed by archive path. */
|
|
57
|
+
export declare const ConfigFilesSchema: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
58
|
+
export type ConfigFiles = z.infer<typeof ConfigFilesSchema>;
|
|
59
|
+
/** objectId -> [dx, dy] shift to apply to that object's transform. */
|
|
60
|
+
export declare const ShiftsSchema: z.ZodRecord<z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
61
|
+
export type Shifts = z.infer<typeof ShiftsSchema>;
|
|
62
|
+
export declare const MatchSourceSchema: z.ZodEnum<{
|
|
63
|
+
"auto-tier-name": "auto-tier-name";
|
|
64
|
+
"auto-exact": "auto-exact";
|
|
65
|
+
"auto-nearest": "auto-nearest";
|
|
66
|
+
"default-fallback": "default-fallback";
|
|
67
|
+
}>;
|
|
68
|
+
export type MatchSource = z.infer<typeof MatchSourceSchema>;
|
|
69
|
+
export declare const ProfileMatchSchema: z.ZodObject<{
|
|
70
|
+
profileId: z.ZodString;
|
|
71
|
+
nozzleDiameter: z.ZodString;
|
|
72
|
+
exact: z.ZodBoolean;
|
|
73
|
+
matchedByTierName: z.ZodBoolean;
|
|
74
|
+
matchSource: z.ZodEnum<{
|
|
75
|
+
"auto-tier-name": "auto-tier-name";
|
|
76
|
+
"auto-exact": "auto-exact";
|
|
77
|
+
"auto-nearest": "auto-nearest";
|
|
78
|
+
"default-fallback": "default-fallback";
|
|
79
|
+
}>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
export type ProfileMatch = z.infer<typeof ProfileMatchSchema>;
|
|
82
|
+
export declare const ConvertResponseSchema: z.ZodObject<{
|
|
83
|
+
projectSettings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
84
|
+
configFiles: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
85
|
+
shifts: z.ZodRecord<z.ZodString, z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
86
|
+
application: z.ZodString;
|
|
87
|
+
profileMatch: z.ZodOptional<z.ZodObject<{
|
|
88
|
+
profileId: z.ZodString;
|
|
89
|
+
nozzleDiameter: z.ZodString;
|
|
90
|
+
exact: z.ZodBoolean;
|
|
91
|
+
matchedByTierName: z.ZodBoolean;
|
|
92
|
+
matchSource: z.ZodEnum<{
|
|
93
|
+
"auto-tier-name": "auto-tier-name";
|
|
94
|
+
"auto-exact": "auto-exact";
|
|
95
|
+
"auto-nearest": "auto-nearest";
|
|
96
|
+
"default-fallback": "default-fallback";
|
|
97
|
+
}>;
|
|
98
|
+
}, z.core.$strip>>;
|
|
99
|
+
filamentComplianceFallback: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
100
|
+
filamentComplianceUnchanged: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
101
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
export type ConvertResponse = z.infer<typeof ConvertResponseSchema>;
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The engine's internal request/response shapes. The request is built and
|
|
4
|
+
* consumed in the same process. They are zod schemas because the request
|
|
5
|
+
* is built from a file someone dropped in, which is untrusted:
|
|
6
|
+
* validating it bounds how much work a crafted file can cause.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { APPLICATION_VALUE } from "./archive/setApplicationMetadata.js";
|
|
10
|
+
/** A single top-level object's plate assignment and computed bounding box. */
|
|
11
|
+
export const ConvertObjectSchema = z.object({
|
|
12
|
+
id: z.string().max(128),
|
|
13
|
+
name: z.string().max(500).optional(),
|
|
14
|
+
sequence: z.number().int().optional(),
|
|
15
|
+
isAssembly: z.boolean().optional(),
|
|
16
|
+
/** Omitted for objects with no plate metadata. */
|
|
17
|
+
plate: z.number().int().optional(),
|
|
18
|
+
/** [minX, maxX, minY, maxY], or null when no mesh geometry was found for this object. */
|
|
19
|
+
bbox: z.tuple([z.number(), z.number(), z.number(), z.number()]).nullable(),
|
|
20
|
+
/** The item transform's raw translation, set only when bbox is null. */
|
|
21
|
+
fallbackXy: z.tuple([z.number(), z.number()]).optional(),
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* A parsed Metadata/project_settings.config: hundreds of slicer settings,
|
|
25
|
+
* so open-shaped by key, with a cap on its serialized size. A real one runs
|
|
26
|
+
* tens to a few hundred KB.
|
|
27
|
+
*/
|
|
28
|
+
export const MAX_PROJECT_SETTINGS_BYTES = 2 * 1024 * 1024;
|
|
29
|
+
export const ProjectSettingsSchema = z.record(z.string(), z.unknown()).refine((settings) => JSON.stringify(settings).length <= MAX_PROJECT_SETTINGS_BYTES, { message: `project_settings.config is over the ${MAX_PROJECT_SETTINGS_BYTES} byte limit` });
|
|
30
|
+
/** Far past any real multi-plate project; bounds the work one file can cause. */
|
|
31
|
+
export const MAX_OBJECTS = 1000;
|
|
32
|
+
export const FilamentComplianceModeSchema = z.enum(["generic", "snapmaker"]);
|
|
33
|
+
/** `true` for every toolhead, or exactly one entry per U1 toolhead, T1 to T4. */
|
|
34
|
+
export const HighFlowHotendsSchema = z.union([z.boolean(), z.array(z.boolean()).length(4)]);
|
|
35
|
+
export const ConvertRequestSchema = z.object({
|
|
36
|
+
projectSettings: ProjectSettingsSchema,
|
|
37
|
+
objects: z.array(ConvertObjectSchema).max(MAX_OBJECTS),
|
|
38
|
+
profileId: z.string().optional(),
|
|
39
|
+
/**
|
|
40
|
+
* Relabels each filament's identity (name/filament_settings_id) to a real
|
|
41
|
+
* Generic or Snapmaker-brand preset, for marketplaces that require one.
|
|
42
|
+
* Identity only: never touches temperatures, retraction or flow.
|
|
43
|
+
*/
|
|
44
|
+
filamentComplianceMode: FilamentComplianceModeSchema.optional(),
|
|
45
|
+
/**
|
|
46
|
+
* Which toolheads have the Snapmaker Liber High Flow Hotend:
|
|
47
|
+
* `true` for all, or one entry per toolhead (the U1 has four, T1 first).
|
|
48
|
+
* Only applies where the nozzle supports it (today 0.4mm); see
|
|
49
|
+
* engine/applyHighFlowHotends.ts.
|
|
50
|
+
*/
|
|
51
|
+
highFlowHotends: HighFlowHotendsSchema.optional(),
|
|
52
|
+
/** The nozzles are hardened steel, not the stock stainless steel (0.4 nozzle profile only). */
|
|
53
|
+
hardenedNozzles: z.boolean().optional(),
|
|
54
|
+
});
|
|
55
|
+
/** Other Metadata/*.config files to write into the output 3MF, keyed by archive path. */
|
|
56
|
+
export const ConfigFilesSchema = z.record(z.string(), z.record(z.string(), z.unknown()));
|
|
57
|
+
/** objectId -> [dx, dy] shift to apply to that object's transform. */
|
|
58
|
+
export const ShiftsSchema = z.record(z.string(), z.tuple([z.number(), z.number()]));
|
|
59
|
+
export const MatchSourceSchema = z.enum(["auto-tier-name", "auto-exact", "auto-nearest", "default-fallback"]);
|
|
60
|
+
export const ProfileMatchSchema = z.object({
|
|
61
|
+
profileId: z.string(),
|
|
62
|
+
nozzleDiameter: z.string(),
|
|
63
|
+
exact: z.boolean(),
|
|
64
|
+
/** The pick came from the source file's own tier name (e.g. "Extra Fine"), not nearest layer height. */
|
|
65
|
+
matchedByTierName: z.boolean(),
|
|
66
|
+
/**
|
|
67
|
+
* "auto-tier-name"/"auto-exact" are confident; "auto-nearest" is the
|
|
68
|
+
* closest available layer height; "default-fallback" means no match at
|
|
69
|
+
* all, so the profile is just the catalog default.
|
|
70
|
+
*/
|
|
71
|
+
matchSource: MatchSourceSchema,
|
|
72
|
+
});
|
|
73
|
+
export const ConvertResponseSchema = z.object({
|
|
74
|
+
projectSettings: ProjectSettingsSchema,
|
|
75
|
+
configFiles: ConfigFilesSchema,
|
|
76
|
+
shifts: ShiftsSchema,
|
|
77
|
+
/** What the target slicer writes as its Application at the pinned release (e.g. "Snapmaker_Orca-2.4.0"); replaces the source's. */
|
|
78
|
+
application: z.string().regex(APPLICATION_VALUE),
|
|
79
|
+
/** Present when the profile was auto-matched rather than chosen. */
|
|
80
|
+
profileMatch: ProfileMatchSchema.optional(),
|
|
81
|
+
/** Product lines that use Generic under `filamentComplianceMode: "snapmaker"`, because Snapmaker makes no preset for them at this nozzle size. */
|
|
82
|
+
filamentComplianceFallback: z.array(z.string()).optional(),
|
|
83
|
+
/** Product lines (or materials) whose names stayed as the creator had them under `filamentComplianceMode`, because no Snapmaker or Generic preset fits at this nozzle size. */
|
|
84
|
+
filamentComplianceUnchanged: z.array(z.string()).optional(),
|
|
85
|
+
/** Notes worth showing the user (each contains "WARN"). */
|
|
86
|
+
warnings: z.array(z.string()).optional(),
|
|
87
|
+
});
|
package/dist/stamp.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The output stamp: one small JSON file added to every converted 3MF, so a
|
|
3
|
+
* file can always be traced to the release that made it ("was this made
|
|
4
|
+
* before the fix?"). It holds versions and the options used, nothing else:
|
|
5
|
+
* no file names, paths, timestamps or identifiers. It sits in its own zip
|
|
6
|
+
* entry, so no slicer-read file and no mesh data changes because of it.
|
|
7
|
+
*
|
|
8
|
+
* The path and the `stamp: 1` shape are a public contract once files
|
|
9
|
+
* exist in the wild. Add fields if needed; never rename or remove one
|
|
10
|
+
* without bumping `stamp`.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
export declare const STAMP_PATH = "Metadata/any2orca.json";
|
|
14
|
+
/** What this version writes: exactly these fields. */
|
|
15
|
+
export declare const OutputStampSchema: z.ZodObject<{
|
|
16
|
+
stamp: z.ZodLiteral<1>;
|
|
17
|
+
generator: z.ZodLiteral<"any2orca">;
|
|
18
|
+
version: z.ZodString;
|
|
19
|
+
profiles: z.ZodObject<{
|
|
20
|
+
version: z.ZodString;
|
|
21
|
+
tracks: z.ZodString;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
profileId: z.ZodString;
|
|
24
|
+
options: z.ZodObject<{
|
|
25
|
+
highFlowHotends: z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodBoolean>]>;
|
|
26
|
+
hardenedNozzles: z.ZodBoolean;
|
|
27
|
+
filamentComplianceMode: z.ZodNullable<z.ZodEnum<{
|
|
28
|
+
generic: "generic";
|
|
29
|
+
snapmaker: "snapmaker";
|
|
30
|
+
}>>;
|
|
31
|
+
preset: z.ZodOptional<z.ZodObject<{
|
|
32
|
+
base: z.ZodString;
|
|
33
|
+
keys: z.ZodArray<z.ZodString>;
|
|
34
|
+
sha256: z.ZodString;
|
|
35
|
+
}, z.core.$strict>>;
|
|
36
|
+
aboveStock: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
keep: z.ZodArray<z.ZodString>;
|
|
38
|
+
stock: z.ZodArray<z.ZodString>;
|
|
39
|
+
}, z.core.$strict>>;
|
|
40
|
+
}, z.core.$strict>;
|
|
41
|
+
}, z.core.$strict>;
|
|
42
|
+
export type OutputStamp = z.infer<typeof OutputStampSchema>;
|
|
43
|
+
export declare function encodeStamp(stamp: OutputStamp): Uint8Array;
|
|
44
|
+
/** Reads the stamp from a converted file's zip entries, or null if it has none (or an unreadable one). */
|
|
45
|
+
export declare function decodeStamp(bytes: Uint8Array | undefined): OutputStamp | null;
|