any2orca 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +99 -2
- 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 +14 -0
- package/dist/engine/policy.js +266 -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 +197 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +33 -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 +314 -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 +85 -4
package/dist/profiles.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Profile catalogs: where conversion profiles come from, and how they are
|
|
4
|
+
* checked before the engine uses them.
|
|
5
|
+
*
|
|
6
|
+
* The core never bundles profile data (that is the separate, AGPL-licensed
|
|
7
|
+
* `any2orca-profiles` package). A caller hands it a {@link ProfileSource}:
|
|
8
|
+
* {@link fetchProfileSource} for a browser, `dirProfileSource()` or
|
|
9
|
+
* `bundledProfileSource()` from `any2orca/node`, or anything else with the
|
|
10
|
+
* same two methods (a partner's own CDN, a database, an in-memory object).
|
|
11
|
+
*
|
|
12
|
+
* Catalog data is treated as untrusted input, since it can come from a URL
|
|
13
|
+
* or folder the user points at: sizes are capped, every file is validated,
|
|
14
|
+
* and a profile file is only ever requested by an id the index lists.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { Any2orcaError } from "./errors.js";
|
|
18
|
+
import { APPLICATION_VALUE } from "./archive/setApplicationMetadata.js";
|
|
19
|
+
import { parseTierName } from "./engine/parseTierName.js";
|
|
20
|
+
import { ALWAYS_TRANSFER_KEYS, BLOCKLIST, FILAMENT_KEY_BLOCKLIST, isMachineGcodeKey, MACHINE_SETTINGS_KEYS, MIN_COMPARISON_KEYS, U1_VALUE_KEYS } from "./engine/policy.js";
|
|
21
|
+
/** Largest index file accepted from any source. */
|
|
22
|
+
export const MAX_INDEX_BYTES = 1024 * 1024;
|
|
23
|
+
/** Largest single profile file accepted from any source. A real one is about 100 KB. */
|
|
24
|
+
export const MAX_PROFILE_BYTES = 8 * 1024 * 1024;
|
|
25
|
+
const ID = z.string().regex(/^[a-z0-9][a-z0-9.-]{0,63}$/, "must be lowercase letters, digits, dots and dashes");
|
|
26
|
+
const VERSION = z.string().regex(/^\d+(\.\d+){1,3}([-+][0-9A-Za-z.-]{1,32})?$/);
|
|
27
|
+
const DIAMETER = z.string().regex(/^\d{1,2}(\.\d{1,3})?$/);
|
|
28
|
+
const settings = z.record(z.string().max(200), z.unknown());
|
|
29
|
+
/** Text the naming options write into a project and show to people: one line, no control or direction-override characters. */
|
|
30
|
+
const SAFE_TEXT = /^[^\u0000-\u001f\u007f-\u009f--]*$/;
|
|
31
|
+
const presetText = (max) => z.string().min(1).max(max).regex(SAFE_TEXT, "must not contain control characters");
|
|
32
|
+
const NAME = presetText(200);
|
|
33
|
+
const FilamentNamesSchema = z.object({
|
|
34
|
+
profileSet: z.object({ repository: presetText(200), version: presetText(64), commit: presetText(64) }),
|
|
35
|
+
materialAliases: z.record(presetText(20), presetText(20)).refine((r) => Object.keys(r).length <= 200, "too many material aliases"),
|
|
36
|
+
lines: z
|
|
37
|
+
.array(z.object({
|
|
38
|
+
id: ID,
|
|
39
|
+
label: presetText(100),
|
|
40
|
+
materials: z.array(presetText(20)).min(1).max(20),
|
|
41
|
+
keywords: z.array(z.string().regex(/^[a-z0-9]+( [a-z0-9]+)*$/).max(40)).max(50),
|
|
42
|
+
snapmaker: presetText(200).nullable(),
|
|
43
|
+
generic: presetText(200).nullable(),
|
|
44
|
+
}))
|
|
45
|
+
.max(500),
|
|
46
|
+
printers: z.record(ID, z.object({
|
|
47
|
+
nozzleDiameter: DIAMETER,
|
|
48
|
+
presets: z
|
|
49
|
+
.record(presetText(200), z.object({ family: presetText(200), id: z.string().max(64).regex(SAFE_TEXT), vendor: presetText(64) }))
|
|
50
|
+
.refine((r) => Object.keys(r).length <= 2000, "too many presets"),
|
|
51
|
+
})),
|
|
52
|
+
});
|
|
53
|
+
export const ProfileIndexSchema = z.object({
|
|
54
|
+
schema: z.literal(1),
|
|
55
|
+
dataVersion: VERSION,
|
|
56
|
+
slicer: z
|
|
57
|
+
.object({ name: NAME, version: VERSION, application: z.string().regex(APPLICATION_VALUE) })
|
|
58
|
+
// The Application value names the pinned release, so it can't disagree with it.
|
|
59
|
+
.refine((s) => s.application.endsWith(`-${s.version}`), "slicer.application must end with the slicer version"),
|
|
60
|
+
/** Where the profiles come from: the target slicer's repository and the release tag and commit they were generated at. */
|
|
61
|
+
source: z.object({ repository: presetText(200), tag: presetText(64), commit: presetText(64) }).optional(),
|
|
62
|
+
defaultProfileId: ID,
|
|
63
|
+
printers: z
|
|
64
|
+
.array(z.object({ id: ID, displayName: NAME, nozzleDiameter: DIAMETER, highFlowSupported: z.boolean() }))
|
|
65
|
+
.min(1)
|
|
66
|
+
.max(500),
|
|
67
|
+
profiles: z
|
|
68
|
+
.array(z.object({
|
|
69
|
+
id: ID,
|
|
70
|
+
printerId: ID,
|
|
71
|
+
displayName: NAME,
|
|
72
|
+
nozzleDiameter: DIAMETER,
|
|
73
|
+
layerHeight: z.number().positive().finite(),
|
|
74
|
+
autoSelectable: z.boolean(),
|
|
75
|
+
highFlowSpeeds: z.boolean(),
|
|
76
|
+
}))
|
|
77
|
+
.min(1)
|
|
78
|
+
.max(5000),
|
|
79
|
+
retired: z.array(z.object({ id: ID, successorId: ID, displayName: NAME })).max(5000),
|
|
80
|
+
/** Filament preset names for the Snapmaker/Generic naming options, per printer. */
|
|
81
|
+
filamentNames: FilamentNamesSchema.optional(),
|
|
82
|
+
});
|
|
83
|
+
export const ProfileFileSchema = z.object({
|
|
84
|
+
schema: z.literal(1),
|
|
85
|
+
id: ID,
|
|
86
|
+
displayName: NAME,
|
|
87
|
+
printer: z.object({
|
|
88
|
+
id: ID,
|
|
89
|
+
printableArea: z.array(z.string().max(64)).min(3).max(64),
|
|
90
|
+
extruderClearanceRadius: z.number().nonnegative().max(1000),
|
|
91
|
+
highFlowSupported: z.boolean(),
|
|
92
|
+
machineSettings: settings,
|
|
93
|
+
}),
|
|
94
|
+
baselineProjectSettings: settings,
|
|
95
|
+
filamentShape: settings,
|
|
96
|
+
highFlowOverrides: z.record(z.string().max(200), z.string().max(200)),
|
|
97
|
+
});
|
|
98
|
+
/** The catalog itself is missing or malformed (code `profile_data`). */
|
|
99
|
+
export class ProfileDataError extends Any2orcaError {
|
|
100
|
+
constructor(message) {
|
|
101
|
+
super("profile_data", message);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function describeIssues(error) {
|
|
105
|
+
return error.issues
|
|
106
|
+
.slice(0, 5)
|
|
107
|
+
.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
|
|
108
|
+
.join("; ");
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A validated catalog. Get one with {@link loadCatalog}; it caches loaded
|
|
112
|
+
* profiles, so one instance can serve many conversions.
|
|
113
|
+
*/
|
|
114
|
+
export class ProfileCatalog {
|
|
115
|
+
index;
|
|
116
|
+
source;
|
|
117
|
+
summaries;
|
|
118
|
+
byId;
|
|
119
|
+
retired;
|
|
120
|
+
cache = new Map();
|
|
121
|
+
constructor(index, source) {
|
|
122
|
+
this.index = index;
|
|
123
|
+
this.source = source;
|
|
124
|
+
const printers = new Map(index.printers.map((p) => [p.id, p]));
|
|
125
|
+
this.summaries = index.profiles.map((p) => {
|
|
126
|
+
const printer = printers.get(p.printerId);
|
|
127
|
+
if (!printer)
|
|
128
|
+
throw new ProfileDataError(`Profile catalog: ${p.id} names unknown printer ${p.printerId}.`);
|
|
129
|
+
const tierName = parseTierName(p.displayName);
|
|
130
|
+
if (!tierName)
|
|
131
|
+
throw new ProfileDataError(`Profile catalog: can't read a tier name from "${p.displayName}".`);
|
|
132
|
+
return {
|
|
133
|
+
id: p.id,
|
|
134
|
+
displayName: p.displayName,
|
|
135
|
+
printerId: p.printerId,
|
|
136
|
+
nozzleDiameter: p.nozzleDiameter,
|
|
137
|
+
layerHeight: p.layerHeight,
|
|
138
|
+
autoSelectable: p.autoSelectable,
|
|
139
|
+
tierName,
|
|
140
|
+
highFlowSupported: printer.highFlowSupported,
|
|
141
|
+
highFlowSpeeds: p.highFlowSpeeds,
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
this.byId = new Map(this.summaries.map((s) => [s.id, s]));
|
|
145
|
+
if (this.byId.size !== this.summaries.length)
|
|
146
|
+
throw new ProfileDataError("Profile catalog lists the same profile id twice.");
|
|
147
|
+
if (!this.byId.has(index.defaultProfileId)) {
|
|
148
|
+
throw new ProfileDataError(`Profile catalog's default profile ${index.defaultProfileId} isn't in the catalog.`);
|
|
149
|
+
}
|
|
150
|
+
this.retired = new Map(index.retired.map((r) => [r.id, r]));
|
|
151
|
+
}
|
|
152
|
+
/** Every profile, or only one nozzle size's, sorted by nozzle size and then layer height (finest first). */
|
|
153
|
+
list(filter = {}) {
|
|
154
|
+
const { nozzleDiameter } = filter;
|
|
155
|
+
return this.summaries.filter((s) => nozzleDiameter === undefined || s.nozzleDiameter === nozzleDiameter).map((s) => ({ ...s }));
|
|
156
|
+
}
|
|
157
|
+
get(id) {
|
|
158
|
+
const summary = this.byId.get(id);
|
|
159
|
+
return summary ? { ...summary } : undefined;
|
|
160
|
+
}
|
|
161
|
+
/** The live profile that replaced a retired id, if `id` was retired. */
|
|
162
|
+
retiredSuccessor(id) {
|
|
163
|
+
if (this.byId.has(id))
|
|
164
|
+
return undefined;
|
|
165
|
+
return this.retired.get(id);
|
|
166
|
+
}
|
|
167
|
+
/** Loads and validates one profile. Throws for an id the catalog doesn't list. */
|
|
168
|
+
load(id) {
|
|
169
|
+
const summary = this.byId.get(id);
|
|
170
|
+
if (!summary)
|
|
171
|
+
return Promise.reject(new Any2orcaError("profile_not_found", `No profile found for id "${id}".`));
|
|
172
|
+
let pending = this.cache.get(id);
|
|
173
|
+
if (!pending) {
|
|
174
|
+
pending = this.source.readProfile(id).then((raw) => toLoadedProfile(raw, summary, this.index.filamentNames));
|
|
175
|
+
// A failed read isn't cached, so a transient fetch error can be retried.
|
|
176
|
+
pending.catch(() => this.cache.delete(id));
|
|
177
|
+
this.cache.set(id, pending);
|
|
178
|
+
}
|
|
179
|
+
return pending;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function toLoadedProfile(raw, summary, filamentNames) {
|
|
183
|
+
const parsed = ProfileFileSchema.safeParse(raw);
|
|
184
|
+
if (!parsed.success)
|
|
185
|
+
throw new ProfileDataError(`Profile ${summary.id} is malformed: ${describeIssues(parsed.error)}`);
|
|
186
|
+
const file = parsed.data;
|
|
187
|
+
if (file.id !== summary.id)
|
|
188
|
+
throw new ProfileDataError(`Profile file for ${summary.id} says it is ${file.id}.`);
|
|
189
|
+
if (file.printer.id !== summary.printerId) {
|
|
190
|
+
throw new ProfileDataError(`Profile ${summary.id} names printer ${file.printer.id}, but the index says ${summary.printerId}.`);
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
summary: { ...summary },
|
|
194
|
+
convertProfile: {
|
|
195
|
+
printer: {
|
|
196
|
+
id: file.printer.id,
|
|
197
|
+
printableArea: file.printer.printableArea,
|
|
198
|
+
extruderClearanceRadius: file.printer.extruderClearanceRadius,
|
|
199
|
+
machineSettingsConfig: file.printer.machineSettings,
|
|
200
|
+
highFlowSupported: file.printer.highFlowSupported,
|
|
201
|
+
...(filamentNames ? { filamentNames } : {}),
|
|
202
|
+
},
|
|
203
|
+
profile: {
|
|
204
|
+
id: file.id,
|
|
205
|
+
baselineProjectSettings: file.baselineProjectSettings,
|
|
206
|
+
filamentShapeConfig: file.filamentShape,
|
|
207
|
+
blocklist: new Set([
|
|
208
|
+
...BLOCKLIST,
|
|
209
|
+
...U1_VALUE_KEYS,
|
|
210
|
+
...MACHINE_SETTINGS_KEYS,
|
|
211
|
+
...Object.keys(file.baselineProjectSettings).filter(isMachineGcodeKey),
|
|
212
|
+
]),
|
|
213
|
+
minComparisonKeys: new Set(MIN_COMPARISON_KEYS),
|
|
214
|
+
alwaysTransferKeys: new Set(ALWAYS_TRANSFER_KEYS),
|
|
215
|
+
filamentKeyBlocklist: new Set(FILAMENT_KEY_BLOCKLIST),
|
|
216
|
+
highFlowOverrides: file.highFlowOverrides,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const catalogs = new WeakMap();
|
|
222
|
+
/** Reads and validates a source's index. Cached per source object. */
|
|
223
|
+
export function loadCatalog(source) {
|
|
224
|
+
if (source instanceof ProfileCatalog)
|
|
225
|
+
return Promise.resolve(source);
|
|
226
|
+
let pending = catalogs.get(source);
|
|
227
|
+
if (!pending) {
|
|
228
|
+
pending = source.readIndex().then((raw) => {
|
|
229
|
+
const parsed = ProfileIndexSchema.safeParse(raw);
|
|
230
|
+
if (!parsed.success)
|
|
231
|
+
throw new ProfileDataError(`Profile catalog index is malformed: ${describeIssues(parsed.error)}`);
|
|
232
|
+
return new ProfileCatalog(parsed.data, source);
|
|
233
|
+
});
|
|
234
|
+
pending.catch(() => catalogs.delete(source));
|
|
235
|
+
catalogs.set(source, pending);
|
|
236
|
+
}
|
|
237
|
+
return pending;
|
|
238
|
+
}
|
|
239
|
+
/** Lists a catalog's profiles; see {@link ProfileCatalog.list}. */
|
|
240
|
+
export async function listProfiles(source, filter = {}) {
|
|
241
|
+
return (await loadCatalog(source)).list(filter);
|
|
242
|
+
}
|
|
243
|
+
/** Parses JSON text after checking its size; shared by every source that reads text. */
|
|
244
|
+
export function parseCatalogJson(text, maxBytes, what) {
|
|
245
|
+
// String length counts UTF-16 units, at most the UTF-8 byte count for this data; close enough for a cap.
|
|
246
|
+
if (text.length > maxBytes)
|
|
247
|
+
throw new ProfileDataError(`${what} is larger than the ${maxBytes} byte limit.`);
|
|
248
|
+
try {
|
|
249
|
+
return JSON.parse(text);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
throw new ProfileDataError(`${what} isn't valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** Reads a response body, stopping as soon as it passes `maxBytes` (a missing or false Content-Length can't make it read more). */
|
|
256
|
+
async function readBoundedText(response, maxBytes, what) {
|
|
257
|
+
if (!response.body)
|
|
258
|
+
return response.text();
|
|
259
|
+
const reader = response.body.getReader();
|
|
260
|
+
const chunks = [];
|
|
261
|
+
let total = 0;
|
|
262
|
+
for (;;) {
|
|
263
|
+
const { done, value } = await reader.read();
|
|
264
|
+
if (done)
|
|
265
|
+
break;
|
|
266
|
+
total += value.byteLength;
|
|
267
|
+
if (total > maxBytes) {
|
|
268
|
+
await reader.cancel();
|
|
269
|
+
throw new ProfileDataError(`${what} is larger than the ${maxBytes} byte limit.`);
|
|
270
|
+
}
|
|
271
|
+
chunks.push(value);
|
|
272
|
+
}
|
|
273
|
+
const bytes = new Uint8Array(total);
|
|
274
|
+
let offset = 0;
|
|
275
|
+
for (const chunk of chunks) {
|
|
276
|
+
bytes.set(chunk, offset);
|
|
277
|
+
offset += chunk.byteLength;
|
|
278
|
+
}
|
|
279
|
+
return new TextDecoder("utf-8").decode(bytes);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* A catalog served over HTTP(S), e.g. `any2orca-profiles`' `data/` folder
|
|
283
|
+
* copied into a site's static files. Fetches `index.json` once, then only
|
|
284
|
+
* the profile files actually used. Makes no request until first used.
|
|
285
|
+
*/
|
|
286
|
+
export function fetchProfileSource(baseUrl, options = {}) {
|
|
287
|
+
const base = new URL(String(baseUrl).endsWith("/") ? String(baseUrl) : `${String(baseUrl)}/`, globalThis.location?.href);
|
|
288
|
+
const doFetch = options.fetch ?? fetch;
|
|
289
|
+
async function read(path, maxBytes) {
|
|
290
|
+
const url = new URL(path, base);
|
|
291
|
+
const response = await doFetch(url, options.init);
|
|
292
|
+
if (!response.ok)
|
|
293
|
+
throw new ProfileDataError(`Couldn't load ${url.href}: HTTP ${response.status}.`);
|
|
294
|
+
const declared = Number(response.headers.get("content-length"));
|
|
295
|
+
if (Number.isFinite(declared) && declared > maxBytes)
|
|
296
|
+
throw new ProfileDataError(`${url.href} is larger than the ${maxBytes} byte limit.`);
|
|
297
|
+
return parseCatalogJson(await readBoundedText(response, maxBytes, url.href), maxBytes, url.href);
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
readIndex: () => read("index.json", MAX_INDEX_BYTES),
|
|
301
|
+
readProfile: (id) => read(`profiles/${encodeURIComponent(id)}.json`, MAX_PROFILE_BYTES),
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
|
|
305
|
+
export function memoryProfileSource(data) {
|
|
306
|
+
return {
|
|
307
|
+
readIndex: async () => data.index,
|
|
308
|
+
readProfile: async (id) => {
|
|
309
|
+
if (!Object.hasOwn(data.profiles, id))
|
|
310
|
+
throw new ProfileDataError(`No profile file for id "${id}".`);
|
|
311
|
+
return data.profiles[id];
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { type BundleEntry } from "./archive/unwrapBundle.js";
|
|
2
|
+
import { type WhatChanged } from "./explain/whatChanged.js";
|
|
3
|
+
import { type Inspection } from "./inspect.js";
|
|
4
|
+
import { ProfileCatalog, type ProfileSource, type ProfileSummary, type RetiredProfile } from "./profiles.js";
|
|
5
|
+
import { type ProfileMatch, type Shifts } from "./schema.js";
|
|
6
|
+
import { type AboveStockChoice } from "./engine/aboveStock.js";
|
|
7
|
+
import { type Preset, type PresetChange } from "./presets/preset.js";
|
|
8
|
+
import { type OutputStamp } from "./stamp.js";
|
|
9
|
+
/** Options for reading a .3mf. */
|
|
10
|
+
export interface OpenOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The most the project may unpack to, in bytes: 2 GB by default, which a browser tab can hold, and at most
|
|
13
|
+
* 16 GB. Raise it in Node for a larger project; a project over the limit throws `too_large`.
|
|
14
|
+
*/
|
|
15
|
+
maxUnpackedBytes?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ConvertOptions {
|
|
18
|
+
/** Where profiles come from. Pass the same catalog for every conversion so profiles load once. */
|
|
19
|
+
profiles: ProfileSource | ProfileCatalog;
|
|
20
|
+
/** Use this profile instead of matching one. A retired id converts with its successor, with a warning. */
|
|
21
|
+
profileId?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Convert onto the preset's base profile and write its print settings over
|
|
24
|
+
* the creator's. Can't be combined with `profileId`. Speeds above the U1's
|
|
25
|
+
* machine limits are still capped; check `report.preset.changes` for
|
|
26
|
+
* values above stock and show them to the user.
|
|
27
|
+
*/
|
|
28
|
+
preset?: Preset;
|
|
29
|
+
/**
|
|
30
|
+
* For speeds, accelerations and filament max volumetric speed above
|
|
31
|
+
* Snapmaker's stock values: settings to keep at the creator's value
|
|
32
|
+
* (accelerations and travel speed above stock, uncapped max volumetric
|
|
33
|
+
* speed) and settings to set to Snapmaker's stock value (print speeds).
|
|
34
|
+
* The U1's machine limits still cap everything. Each "What changed?" item
|
|
35
|
+
* that can be chosen differently has an `alternative`. Default: none.
|
|
36
|
+
*/
|
|
37
|
+
aboveStock?: AboveStockChoice;
|
|
38
|
+
/**
|
|
39
|
+
* Which toolheads have the Liber High Flow Hotend: `true` for all, or one
|
|
40
|
+
* entry per toolhead, T1 first (the U1 has four), e.g. `[true, false, false, false]`.
|
|
41
|
+
* Ignored, with a warning, where the nozzle has no high-flow option.
|
|
42
|
+
*/
|
|
43
|
+
highFlowHotends?: boolean | readonly boolean[];
|
|
44
|
+
/**
|
|
45
|
+
* The U1's nozzles are hardened steel rather than the stock stainless
|
|
46
|
+
* steel. Changes the 0.4 nozzle profile only (Snapmaker makes the other
|
|
47
|
+
* sizes only in hardened steel). Snapmaker Orca uses it to warn when a
|
|
48
|
+
* filament is too abrasive for the nozzle. Default false.
|
|
49
|
+
*/
|
|
50
|
+
hardenedNozzles?: boolean;
|
|
51
|
+
/** Relabel filament identity to Generic or Snapmaker presets (identity only, never tuning). */
|
|
52
|
+
filamentComplianceMode?: "generic" | "snapmaker";
|
|
53
|
+
/** Add the output stamp (Metadata/any2orca.json). Default true. */
|
|
54
|
+
stamp?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Also put every difference between the original and converted settings
|
|
57
|
+
* in `report.whatChanged.diff` (for "What changed?" > all differences, and
|
|
58
|
+
* its export). The grouped record is always in the report. Default false.
|
|
59
|
+
*/
|
|
60
|
+
explain?: boolean;
|
|
61
|
+
/** Called as the conversion moves through its steps, for a progress display. */
|
|
62
|
+
onProgress?: (stage: ConvertStage) => void;
|
|
63
|
+
}
|
|
64
|
+
export type ConvertStage = "matching" | "loading-profile" | "merging" | "writing";
|
|
65
|
+
export interface ConvertReport {
|
|
66
|
+
/** The profile the file was converted with. */
|
|
67
|
+
profile: ProfileSummary;
|
|
68
|
+
/** How the profile was matched; absent when `profileId` was given. */
|
|
69
|
+
profileMatch?: ProfileMatch;
|
|
70
|
+
/** Set when `profileId` named a retired profile and its successor was used. */
|
|
71
|
+
retiredProfile?: RetiredProfile;
|
|
72
|
+
/** Notes worth showing the user, cleaned up for display. */
|
|
73
|
+
warnings: string[];
|
|
74
|
+
/** Every note the conversion produced, including routine ones, for logs and bug reports. */
|
|
75
|
+
log: string[];
|
|
76
|
+
/** Product lines that use Generic under `filamentComplianceMode: "snapmaker"`, because Snapmaker makes no preset for them at this nozzle size. */
|
|
77
|
+
filamentComplianceFallback?: string[];
|
|
78
|
+
/** Product lines (or materials) whose names stayed as the creator had them under `filamentComplianceMode`, because no Snapmaker or Generic preset fits. */
|
|
79
|
+
filamentComplianceUnchanged?: string[];
|
|
80
|
+
/** How far each object was moved, by object id. */
|
|
81
|
+
shifts: Shifts;
|
|
82
|
+
plates: number;
|
|
83
|
+
objects: number;
|
|
84
|
+
filamentSlots: number;
|
|
85
|
+
/** The stamp written into the output, or null if `stamp: false`. */
|
|
86
|
+
stamp: OutputStamp | null;
|
|
87
|
+
/** What the conversion changed, grouped by why. */
|
|
88
|
+
whatChanged: WhatChanged;
|
|
89
|
+
/** Set when a preset was used: the settings it set (with values above stock marked) and anything it left out. */
|
|
90
|
+
preset?: {
|
|
91
|
+
base: string;
|
|
92
|
+
changes: PresetChange[];
|
|
93
|
+
notes: string[];
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export interface ConvertResult {
|
|
97
|
+
/** The converted .3mf. */
|
|
98
|
+
output: Uint8Array;
|
|
99
|
+
report: ConvertReport;
|
|
100
|
+
}
|
|
101
|
+
export interface ProfileChoice {
|
|
102
|
+
profileId: string;
|
|
103
|
+
profileMatch: ProfileMatch;
|
|
104
|
+
/** Keep the source file's own layer height (auto-matched to a tier that isn't an exact layer height match). */
|
|
105
|
+
carrySourceLayerHeight: boolean;
|
|
106
|
+
/** Why the match may not be what the file asked for (an unusable layer height or a nozzle size with no U1 profile), as sentences. */
|
|
107
|
+
notes: string[];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Picks a profile for a file's settings, the same way every UI should (never
|
|
111
|
+
* re-implement this): the source's own tier name first (from its
|
|
112
|
+
* print_settings_id, e.g. "Extra Fine"), then the nearest layer height for
|
|
113
|
+
* its nozzle size, then the catalog default.
|
|
114
|
+
*/
|
|
115
|
+
export declare function matchProfile(projectSettings: Record<string, unknown>, profiles: ProfileSource | ProfileCatalog): Promise<ProfileChoice>;
|
|
116
|
+
/**
|
|
117
|
+
* Same cleanup every UI applies before showing warnings: drop routine
|
|
118
|
+
* bookkeeping lines, strip the internal "WARN" prefix and internal file
|
|
119
|
+
* names.
|
|
120
|
+
*/
|
|
121
|
+
export declare function cleanWarnings(warnings: readonly string[]): string[];
|
|
122
|
+
/** An opened source file. Reading it again is the expensive part, so keep one per file. */
|
|
123
|
+
export declare class Project {
|
|
124
|
+
private readonly parsed;
|
|
125
|
+
private readonly request;
|
|
126
|
+
private constructor();
|
|
127
|
+
/** Reads a .3mf. Throws {@link Any2orcaError} (`invalid_file`, `too_large` or `invalid_project`) if it can't be used. */
|
|
128
|
+
static open(bytes: Uint8Array, options?: OpenOptions): Project;
|
|
129
|
+
/** The project's own settings (Metadata/project_settings.config), as a copy: for a settings diff. */
|
|
130
|
+
settings(): Record<string, unknown>;
|
|
131
|
+
inspect(): Inspection;
|
|
132
|
+
/** The profile auto-matching would pick for this file. */
|
|
133
|
+
matchProfile(profiles: ProfileSource | ProfileCatalog): Promise<ProfileChoice>;
|
|
134
|
+
convert(options: ConvertOptions): Promise<ConvertResult>;
|
|
135
|
+
}
|
|
136
|
+
/** Opens a .3mf; see {@link Project}. */
|
|
137
|
+
export declare function openProject(bytes: Uint8Array, options?: OpenOptions): Project;
|
|
138
|
+
/** Reads a .3mf and describes it, without converting. */
|
|
139
|
+
export declare function inspect(bytes: Uint8Array, options?: OpenOptions): Inspection;
|
|
140
|
+
/** Reads and converts a .3mf in one step. `maxUnpackedBytes` applies to reading it. */
|
|
141
|
+
export declare function convert(bytes: Uint8Array, options: ConvertOptions & OpenOptions): Promise<ConvertResult>;
|
|
142
|
+
/**
|
|
143
|
+
* A zip bundling several .3mf files (e.g. a "download all variants"
|
|
144
|
+
* archive) returns each one; a plain .3mf, or anything else, returns null.
|
|
145
|
+
*/
|
|
146
|
+
export declare function unwrapBundle(bytes: Uint8Array, options?: OpenOptions): BundleEntry[] | null;
|