any2orca 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -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 +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 +78 -12
- package/index.js +0 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presets: a user's own tuned print settings, made from a 3MF they tuned in
|
|
3
|
+
* Snapmaker Orca, applied to other files when converting.
|
|
4
|
+
*
|
|
5
|
+
* A preset is a base profile (the U1 tier it was tuned on) plus only the
|
|
6
|
+
* print settings that differ from that tier's stock values. Converting with
|
|
7
|
+
* a preset converts onto its base, then writes its values over the
|
|
8
|
+
* creator's. Machine settings, G-code, filaments and the model's layout are
|
|
9
|
+
* never part of a preset (see presetKeys.ts).
|
|
10
|
+
*
|
|
11
|
+
* Masters and presets files come from anyone (a forum post, a shared link),
|
|
12
|
+
* so everything here is hostile input: keys are checked against the
|
|
13
|
+
* allowlist, values against the type, limits and choices Snapmaker Orca
|
|
14
|
+
* declares for the setting, and files against size and count limits, before
|
|
15
|
+
* anything is used.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import type { JsonRecord } from "../engine/types.js";
|
|
19
|
+
import type { ProfileCatalog } from "../profiles.js";
|
|
20
|
+
export declare const MAX_PRESET_NAME_LENGTH = 40;
|
|
21
|
+
export declare const MAX_PRESETS_PER_FILE = 100;
|
|
22
|
+
export declare const MAX_PRESETS_FILE_BYTES: number;
|
|
23
|
+
/** A setting value as Snapmaker Orca writes it: text, or a list of text for a list setting. */
|
|
24
|
+
export type PresetValue = string | string[];
|
|
25
|
+
export interface Preset {
|
|
26
|
+
/** The user's name for it. Shown as plain text only; never written into a converted file. */
|
|
27
|
+
name: string;
|
|
28
|
+
/** The catalog profile id the changes were made on, e.g. "snapmaker-u1-0.4-0.16hq". */
|
|
29
|
+
base: string;
|
|
30
|
+
/** True when the master didn't name its profile and the base was matched from its nozzle and layer height. */
|
|
31
|
+
baseInferred: boolean;
|
|
32
|
+
/** The profile catalog the preset was made with. */
|
|
33
|
+
catalog: {
|
|
34
|
+
version: string;
|
|
35
|
+
tracks: string;
|
|
36
|
+
};
|
|
37
|
+
/** Only the print settings that differ from the base profile's stock values. */
|
|
38
|
+
changes: Record<string, PresetValue>;
|
|
39
|
+
/** The date it was made, YYYY-MM-DD. */
|
|
40
|
+
created: string;
|
|
41
|
+
}
|
|
42
|
+
/** One setting of a preset, for showing before saving or applying. */
|
|
43
|
+
export interface PresetChange {
|
|
44
|
+
key: string;
|
|
45
|
+
/** Where Snapmaker Orca shows the setting, e.g. "Speed > Other layers speed > Outer wall". */
|
|
46
|
+
label: string;
|
|
47
|
+
/** The base profile's stock value (the standard entry for a setting stored per hotend type). */
|
|
48
|
+
stock: string;
|
|
49
|
+
yours: string;
|
|
50
|
+
/** A speed or acceleration above the base profile's stock value. */
|
|
51
|
+
aboveStock: boolean;
|
|
52
|
+
/** Set when the value is above the U1's machine limit: the conversion caps it at this. */
|
|
53
|
+
cappedAt?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface ExtractedPreset {
|
|
56
|
+
/** The preset, without a name: the caller asks the user for one. */
|
|
57
|
+
preset: Omit<Preset, "name">;
|
|
58
|
+
changes: PresetChange[];
|
|
59
|
+
/** Settings the master changed that the preset leaves out, and why; and how the base was found. */
|
|
60
|
+
notes: string[];
|
|
61
|
+
}
|
|
62
|
+
/** The stock value a preset value is compared with: the standard entry for a per-hotend-type setting. */
|
|
63
|
+
export declare function stockValue(key: string, stock: unknown): unknown;
|
|
64
|
+
/** Describes each change: its label, stock and new value, and whether it's above stock or above the machine limit. */
|
|
65
|
+
export declare function describeChanges(changes: Readonly<Record<string, PresetValue>>, stock: JsonRecord, machine: JsonRecord): PresetChange[];
|
|
66
|
+
/** The changes a preset can apply on a base profile: allowed keys the profile has, with valid values. Notes say what was left out. */
|
|
67
|
+
export declare function checkedChanges(changes: Readonly<Record<string, unknown>>, stock: JsonRecord, notes: string[]): Record<string, PresetValue>;
|
|
68
|
+
/** A preset ready to apply: its profile (a retired base is replaced by its successor) and the changes that are valid for it. */
|
|
69
|
+
export interface ResolvedPreset {
|
|
70
|
+
profileId: string;
|
|
71
|
+
changes: Record<string, PresetValue>;
|
|
72
|
+
described: PresetChange[];
|
|
73
|
+
notes: string[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Checks a preset against the current catalog before applying it: the base
|
|
77
|
+
* must exist (a retired one converts with its successor), and every change
|
|
78
|
+
* must still be an allowed setting with a valid value. Anything else is left
|
|
79
|
+
* out with a note, never applied.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolvePreset(preset: Preset, catalog: ProfileCatalog): Promise<ResolvedPreset>;
|
|
82
|
+
/**
|
|
83
|
+
* The preset with some settings put back to the base profile's stock value,
|
|
84
|
+
* which for a preset means leaving them out (a preset only holds what
|
|
85
|
+
* differs from stock). For "use stock" choices on values above stock.
|
|
86
|
+
*/
|
|
87
|
+
export declare function withoutChanges<T extends Pick<Preset, "changes">>(preset: T, keys: readonly string[]): T;
|
|
88
|
+
/** A fingerprint of a preset's changes (SHA-256 of the sorted changes as JSON), for the output stamp. */
|
|
89
|
+
export declare function presetFingerprint(changes: Readonly<Record<string, PresetValue>>): Promise<string>;
|
|
90
|
+
export declare const PresetSchema: z.ZodObject<{
|
|
91
|
+
name: z.ZodString;
|
|
92
|
+
base: z.ZodString;
|
|
93
|
+
baseInferred: z.ZodBoolean;
|
|
94
|
+
catalog: z.ZodObject<{
|
|
95
|
+
version: z.ZodString;
|
|
96
|
+
tracks: z.ZodString;
|
|
97
|
+
}, z.core.$strict>;
|
|
98
|
+
changes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
99
|
+
created: z.ZodString;
|
|
100
|
+
}, z.core.$strict>;
|
|
101
|
+
export declare const PresetFileSchema: z.ZodObject<{
|
|
102
|
+
format: z.ZodLiteral<"any2orca-presets">;
|
|
103
|
+
version: z.ZodLiteral<1>;
|
|
104
|
+
presets: z.ZodArray<z.ZodObject<{
|
|
105
|
+
name: z.ZodString;
|
|
106
|
+
base: z.ZodString;
|
|
107
|
+
baseInferred: z.ZodBoolean;
|
|
108
|
+
catalog: z.ZodObject<{
|
|
109
|
+
version: z.ZodString;
|
|
110
|
+
tracks: z.ZodString;
|
|
111
|
+
}, z.core.$strict>;
|
|
112
|
+
changes: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
113
|
+
created: z.ZodString;
|
|
114
|
+
}, z.core.$strict>>;
|
|
115
|
+
}, z.core.$strict>;
|
|
116
|
+
export interface PresetFile {
|
|
117
|
+
format: "any2orca-presets";
|
|
118
|
+
version: 1;
|
|
119
|
+
presets: Preset[];
|
|
120
|
+
}
|
|
121
|
+
/** Reads a presets file (any2orca-presets.json). Throws `invalid_preset` for anything that isn't one, or is over a limit. */
|
|
122
|
+
export declare function parsePresetFile(input: string | Uint8Array): PresetFile;
|
|
123
|
+
/** Writes presets in the file format, ready to save as any2orca-presets.json. */
|
|
124
|
+
export declare function serializePresets(presets: readonly Preset[]): string;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Presets: a user's own tuned print settings, made from a 3MF they tuned in
|
|
4
|
+
* Snapmaker Orca, applied to other files when converting.
|
|
5
|
+
*
|
|
6
|
+
* A preset is a base profile (the U1 tier it was tuned on) plus only the
|
|
7
|
+
* print settings that differ from that tier's stock values. Converting with
|
|
8
|
+
* a preset converts onto its base, then writes its values over the
|
|
9
|
+
* creator's. Machine settings, G-code, filaments and the model's layout are
|
|
10
|
+
* never part of a preset (see presetKeys.ts).
|
|
11
|
+
*
|
|
12
|
+
* Masters and presets files come from anyone (a forum post, a shared link),
|
|
13
|
+
* so everything here is hostile input: keys are checked against the
|
|
14
|
+
* allowlist, values against the type, limits and choices Snapmaker Orca
|
|
15
|
+
* declares for the setting, and files against size and count limits, before
|
|
16
|
+
* anything is used.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
import { labelOf } from "../diff/diffSettings.js";
|
|
20
|
+
import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
|
|
21
|
+
import { machineLimitFor } from "../engine/aboveStock.js";
|
|
22
|
+
import { VARIANT_PROCESS_KEYS } from "../engine/applyHighFlowHotends.js";
|
|
23
|
+
import { Any2orcaError } from "../errors.js";
|
|
24
|
+
import { isPresetKey, PRESET_EXCLUDED_KEYS, PRESET_KEYS } from "./presetKeys.js";
|
|
25
|
+
export const MAX_PRESET_NAME_LENGTH = 40;
|
|
26
|
+
export const MAX_PRESETS_PER_FILE = 100;
|
|
27
|
+
export const MAX_PRESETS_FILE_BYTES = 1024 * 1024;
|
|
28
|
+
const MAX_VALUE_LENGTH = 4000;
|
|
29
|
+
const MAX_LIST_ENTRIES = 64;
|
|
30
|
+
const VARIANT_KEYS = new Set(VARIANT_PROCESS_KEYS);
|
|
31
|
+
const LIST_TYPES = new Set(["coFloats", "coBools", "coPercents", "coFloatsOrPercents", "coInts", "coStrings", "coEnums", "coPoints"]);
|
|
32
|
+
const NUMBER = /^-?(?:\d{1,12}(?:\.\d{0,12})?|\.\d{1,12})$/;
|
|
33
|
+
const UNSAFE_TEXT = /[\u0000-\u0008\u000b-\u001f\u007f]/;
|
|
34
|
+
const FORBIDDEN_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
35
|
+
/** Text shown to people: no control characters and no line breaks. */
|
|
36
|
+
const plainLine = (s) => !UNSAFE_TEXT.test(s) && !/[\n\t]/.test(s);
|
|
37
|
+
/** Checks one entry against the setting's type and limits; returns why it's invalid, or null. */
|
|
38
|
+
function entryProblem(key, entry) {
|
|
39
|
+
const info = SETTINGS_CATALOG[key];
|
|
40
|
+
if (entry === "nil")
|
|
41
|
+
return "has no value";
|
|
42
|
+
if (entry.length > MAX_VALUE_LENGTH || UNSAFE_TEXT.test(entry))
|
|
43
|
+
return "isn't plain text of a sensible length";
|
|
44
|
+
const type = (info.type ?? "").replace(/s$/, "");
|
|
45
|
+
const numeric = (allowPercent) => {
|
|
46
|
+
const text = allowPercent && entry.endsWith("%") ? entry.slice(0, -1) : entry;
|
|
47
|
+
if (!NUMBER.test(text))
|
|
48
|
+
return `isn't a number ("${entry}")`;
|
|
49
|
+
const n = Number(text);
|
|
50
|
+
if (info.min !== null && n < info.min)
|
|
51
|
+
return `is below Snapmaker Orca's minimum of ${info.min} ("${entry}")`;
|
|
52
|
+
if (info.max !== null && n > info.max)
|
|
53
|
+
return `is above Snapmaker Orca's maximum of ${info.max} ("${entry}")`;
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
switch (type) {
|
|
57
|
+
case "coBool":
|
|
58
|
+
return entry === "0" || entry === "1" ? null : `isn't on or off ("${entry}")`;
|
|
59
|
+
case "coInt":
|
|
60
|
+
return /^-?\d{1,12}$/.test(entry) ? numeric(false) : `isn't a whole number ("${entry}")`;
|
|
61
|
+
case "coFloat":
|
|
62
|
+
return numeric(false);
|
|
63
|
+
case "coPercent":
|
|
64
|
+
case "coFloatOrPercent":
|
|
65
|
+
return numeric(true);
|
|
66
|
+
case "coEnum":
|
|
67
|
+
if (info.choices)
|
|
68
|
+
return info.choices.includes(entry) ? null : `isn't one of Snapmaker Orca's choices ("${entry}")`;
|
|
69
|
+
return /^[A-Za-z0-9_-]{1,64}$/.test(entry) ? null : `isn't a valid choice ("${entry}")`;
|
|
70
|
+
default:
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The value a preset stores for a setting, from a project's raw value, or
|
|
76
|
+
* why it can't be stored. A setting Snapmaker Orca keeps per hotend type
|
|
77
|
+
* (`[standard, high_flow]`) stores only the standard entry.
|
|
78
|
+
*/
|
|
79
|
+
function presetValue(key, raw) {
|
|
80
|
+
const info = SETTINGS_CATALOG[key];
|
|
81
|
+
const isList = LIST_TYPES.has(info.type ?? "") && !VARIANT_KEYS.has(key);
|
|
82
|
+
const source = VARIANT_KEYS.has(key) && Array.isArray(raw) ? raw[0] : raw;
|
|
83
|
+
if (isList) {
|
|
84
|
+
// An empty list is a real value (Snapmaker Orca writes one for "none").
|
|
85
|
+
if (!Array.isArray(source) || source.length > MAX_LIST_ENTRIES || !source.every((e) => typeof e === "string")) {
|
|
86
|
+
return { problem: "isn't a list of values" };
|
|
87
|
+
}
|
|
88
|
+
for (const entry of source) {
|
|
89
|
+
const problem = entryProblem(key, entry);
|
|
90
|
+
if (problem)
|
|
91
|
+
return { problem };
|
|
92
|
+
}
|
|
93
|
+
return { value: [...source] };
|
|
94
|
+
}
|
|
95
|
+
if (typeof source !== "string")
|
|
96
|
+
return { problem: "isn't a single value" };
|
|
97
|
+
const problem = entryProblem(key, source);
|
|
98
|
+
return problem ? { problem } : { value: source };
|
|
99
|
+
}
|
|
100
|
+
/** The stock value a preset value is compared with: the standard entry for a per-hotend-type setting. */
|
|
101
|
+
export function stockValue(key, stock) {
|
|
102
|
+
return VARIANT_KEYS.has(key) && Array.isArray(stock) ? stock[0] : stock;
|
|
103
|
+
}
|
|
104
|
+
function text(value) {
|
|
105
|
+
if (Array.isArray(value))
|
|
106
|
+
return value.map(String).join(", ");
|
|
107
|
+
return value === undefined || value === null ? "" : String(value);
|
|
108
|
+
}
|
|
109
|
+
/** Describes each change: its label, stock and new value, and whether it's above stock or above the machine limit. */
|
|
110
|
+
export function describeChanges(changes, stock, machine) {
|
|
111
|
+
return Object.keys(changes)
|
|
112
|
+
.sort()
|
|
113
|
+
.map((key) => {
|
|
114
|
+
const value = changes[key];
|
|
115
|
+
const base = stockValue(key, stock[key]);
|
|
116
|
+
const change = { key, label: labelOf(key), stock: text(base), yours: text(value), aboveStock: false };
|
|
117
|
+
const limit = machineLimitFor(key, machine);
|
|
118
|
+
if (limit !== null && typeof value === "string" && !value.endsWith("%")) {
|
|
119
|
+
const n = Number(value);
|
|
120
|
+
const stockN = Number(text(base));
|
|
121
|
+
if (Number.isFinite(n) && Number.isFinite(stockN) && n > stockN)
|
|
122
|
+
change.aboveStock = true;
|
|
123
|
+
if (Number.isFinite(n) && n > limit)
|
|
124
|
+
change.cappedAt = limit;
|
|
125
|
+
}
|
|
126
|
+
return change;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** The changes a preset can apply on a base profile: allowed keys the profile has, with valid values. Notes say what was left out. */
|
|
130
|
+
export function checkedChanges(changes, stock, notes) {
|
|
131
|
+
const out = {};
|
|
132
|
+
for (const key of Object.keys(changes).sort()) {
|
|
133
|
+
if (!isPresetKey(key)) {
|
|
134
|
+
const reason = Object.hasOwn(PRESET_EXCLUDED_KEYS, key) ? PRESET_EXCLUDED_KEYS[key] : "isn't a print setting a preset can change";
|
|
135
|
+
notes.push(`Left out ${labelOf(key)}: it ${reason}.`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (!Object.hasOwn(stock, key)) {
|
|
139
|
+
notes.push(`Left out ${labelOf(key)}: the base profile doesn't have this setting.`);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const checked = presetValue(key, changes[key]);
|
|
143
|
+
if ("problem" in checked) {
|
|
144
|
+
notes.push(`Left out ${labelOf(key)}: the value ${checked.problem}.`);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
Object.defineProperty(out, key, { value: checked.value, enumerable: true, writable: true, configurable: true });
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Checks a preset against the current catalog before applying it: the base
|
|
153
|
+
* must exist (a retired one converts with its successor), and every change
|
|
154
|
+
* must still be an allowed setting with a valid value. Anything else is left
|
|
155
|
+
* out with a note, never applied.
|
|
156
|
+
*/
|
|
157
|
+
export async function resolvePreset(preset, catalog) {
|
|
158
|
+
const parsed = PresetSchema.safeParse(preset);
|
|
159
|
+
if (!parsed.success)
|
|
160
|
+
throw new Any2orcaError("invalid_preset", `This preset can't be used: ${describeIssues(parsed.error)}`);
|
|
161
|
+
const notes = [];
|
|
162
|
+
let profileId = parsed.data.base;
|
|
163
|
+
const retired = catalog.retiredSuccessor(profileId);
|
|
164
|
+
if (retired) {
|
|
165
|
+
notes.push(`The preset's base profile has been retired; it's applied on ${retired.displayName} instead.`);
|
|
166
|
+
profileId = retired.successorId;
|
|
167
|
+
}
|
|
168
|
+
if (!catalog.get(profileId))
|
|
169
|
+
throw new Any2orcaError("invalid_preset", `The preset's base profile "${profileId}" isn't in the profile catalog.`);
|
|
170
|
+
const loaded = await catalog.load(profileId);
|
|
171
|
+
const stock = loaded.convertProfile.profile.baselineProjectSettings;
|
|
172
|
+
const changes = checkedChanges(parsed.data.changes, stock, notes);
|
|
173
|
+
return { profileId, changes, described: describeChanges(changes, stock, loaded.convertProfile.printer.machineSettingsConfig), notes };
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The preset with some settings put back to the base profile's stock value,
|
|
177
|
+
* which for a preset means leaving them out (a preset only holds what
|
|
178
|
+
* differs from stock). For "use stock" choices on values above stock.
|
|
179
|
+
*/
|
|
180
|
+
export function withoutChanges(preset, keys) {
|
|
181
|
+
const drop = new Set(keys);
|
|
182
|
+
const changes = {};
|
|
183
|
+
for (const key of Object.keys(preset.changes)) {
|
|
184
|
+
if (!drop.has(key))
|
|
185
|
+
Object.defineProperty(changes, key, { value: preset.changes[key], enumerable: true, writable: true, configurable: true });
|
|
186
|
+
}
|
|
187
|
+
return { ...preset, changes };
|
|
188
|
+
}
|
|
189
|
+
/** A fingerprint of a preset's changes (SHA-256 of the sorted changes as JSON), for the output stamp. */
|
|
190
|
+
export async function presetFingerprint(changes) {
|
|
191
|
+
const canonical = JSON.stringify(Object.keys(changes).sort().map((key) => [key, changes[key]]));
|
|
192
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(canonical));
|
|
193
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
194
|
+
}
|
|
195
|
+
// The file format, shared by the web app's export, the CLI's saved presets and imports.
|
|
196
|
+
const PresetValueSchema = z.union([z.string().max(MAX_VALUE_LENGTH), z.array(z.string().max(MAX_VALUE_LENGTH)).max(MAX_LIST_ENTRIES)]);
|
|
197
|
+
export const PresetSchema = z
|
|
198
|
+
.object({
|
|
199
|
+
name: z
|
|
200
|
+
.string()
|
|
201
|
+
.trim()
|
|
202
|
+
.min(1)
|
|
203
|
+
.max(MAX_PRESET_NAME_LENGTH)
|
|
204
|
+
.refine((s) => !UNSAFE_TEXT.test(s) && !/[\n\t]/.test(s), "must be plain text on one line"),
|
|
205
|
+
base: z.string().regex(/^[a-z0-9][a-z0-9.-]{0,63}$/, "must be a profile id"),
|
|
206
|
+
baseInferred: z.boolean(),
|
|
207
|
+
catalog: z
|
|
208
|
+
.object({
|
|
209
|
+
version: z.string().max(64).refine(plainLine, "must be plain text on one line"),
|
|
210
|
+
tracks: z.string().max(200).refine(plainLine, "must be plain text on one line"),
|
|
211
|
+
})
|
|
212
|
+
.strict(),
|
|
213
|
+
changes: z
|
|
214
|
+
.record(z
|
|
215
|
+
.string()
|
|
216
|
+
.regex(/^[a-z0-9_]{1,100}$/)
|
|
217
|
+
.refine((k) => !FORBIDDEN_KEYS.has(k), "isn't a setting"), PresetValueSchema)
|
|
218
|
+
.refine((c) => Object.keys(c).length <= PRESET_KEYS.length, "has more changes than there are print settings"),
|
|
219
|
+
created: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
220
|
+
})
|
|
221
|
+
.strict();
|
|
222
|
+
export const PresetFileSchema = z
|
|
223
|
+
.object({
|
|
224
|
+
format: z.literal("any2orca-presets"),
|
|
225
|
+
version: z.literal(1),
|
|
226
|
+
presets: z.array(PresetSchema).max(MAX_PRESETS_PER_FILE),
|
|
227
|
+
})
|
|
228
|
+
.strict();
|
|
229
|
+
function describeIssues(error) {
|
|
230
|
+
return error.issues
|
|
231
|
+
.slice(0, 3)
|
|
232
|
+
.map((issue) => `${issue.path.map(String).join(".") || "(root)"}: ${issue.message}`)
|
|
233
|
+
.join("; ");
|
|
234
|
+
}
|
|
235
|
+
/** Rejects keys that could reach an object's prototype, and nesting deeper than the format has. */
|
|
236
|
+
function assertPlainJson(value, depth) {
|
|
237
|
+
if (depth > 6)
|
|
238
|
+
throw new Any2orcaError("invalid_preset", "This presets file is nested deeper than the format allows.");
|
|
239
|
+
if (Array.isArray(value)) {
|
|
240
|
+
for (const item of value)
|
|
241
|
+
assertPlainJson(item, depth + 1);
|
|
242
|
+
}
|
|
243
|
+
else if (value !== null && typeof value === "object") {
|
|
244
|
+
for (const key of Object.keys(value)) {
|
|
245
|
+
if (FORBIDDEN_KEYS.has(key))
|
|
246
|
+
throw new Any2orcaError("invalid_preset", `This presets file has a key named "${key}", which no preset has.`);
|
|
247
|
+
assertPlainJson(value[key], depth + 1);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** Reads a presets file (any2orca-presets.json). Throws `invalid_preset` for anything that isn't one, or is over a limit. */
|
|
252
|
+
export function parsePresetFile(input) {
|
|
253
|
+
const bytes = typeof input === "string" ? new TextEncoder().encode(input).length : input.length;
|
|
254
|
+
if (bytes > MAX_PRESETS_FILE_BYTES)
|
|
255
|
+
throw new Any2orcaError("invalid_preset", `This presets file is larger than the ${MAX_PRESETS_FILE_BYTES / 1024 / 1024} MB a presets file can be.`);
|
|
256
|
+
let raw;
|
|
257
|
+
try {
|
|
258
|
+
raw = JSON.parse(typeof input === "string" ? input : new TextDecoder("utf-8", { fatal: true }).decode(input));
|
|
259
|
+
}
|
|
260
|
+
catch {
|
|
261
|
+
throw new Any2orcaError("invalid_preset", "This isn't a presets file: it isn't valid JSON.");
|
|
262
|
+
}
|
|
263
|
+
assertPlainJson(raw, 0);
|
|
264
|
+
const parsed = PresetFileSchema.safeParse(raw);
|
|
265
|
+
if (!parsed.success)
|
|
266
|
+
throw new Any2orcaError("invalid_preset", `This isn't a valid presets file: ${describeIssues(parsed.error)}`);
|
|
267
|
+
const names = new Set();
|
|
268
|
+
for (const preset of parsed.data.presets) {
|
|
269
|
+
const key = preset.name.toLowerCase();
|
|
270
|
+
if (names.has(key))
|
|
271
|
+
throw new Any2orcaError("invalid_preset", `This presets file has two presets named "${preset.name}".`);
|
|
272
|
+
names.add(key);
|
|
273
|
+
}
|
|
274
|
+
return parsed.data;
|
|
275
|
+
}
|
|
276
|
+
/** Writes presets in the file format, ready to save as any2orca-presets.json. */
|
|
277
|
+
export function serializePresets(presets) {
|
|
278
|
+
if (presets.length > MAX_PRESETS_PER_FILE)
|
|
279
|
+
throw new Any2orcaError("invalid_preset", `A presets file holds at most ${MAX_PRESETS_PER_FILE} presets.`);
|
|
280
|
+
// Same error contract as the readers: an invalid preset is an Any2orcaError with a stable code, never a raw schema error.
|
|
281
|
+
const checked = presets.map((p) => {
|
|
282
|
+
const parsed = PresetSchema.safeParse(p);
|
|
283
|
+
if (!parsed.success)
|
|
284
|
+
throw new Any2orcaError("invalid_preset", `This preset can't be saved: ${describeIssues(parsed.error)}`);
|
|
285
|
+
return parsed.data;
|
|
286
|
+
});
|
|
287
|
+
const file = { format: "any2orca-presets", version: 1, presets: checked };
|
|
288
|
+
return `${JSON.stringify(file, null, 2)}\n`;
|
|
289
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Print settings a preset never carries, with the reason, so a note can say why one was left out. */
|
|
2
|
+
export declare const PRESET_EXCLUDED_KEYS: Readonly<Record<string, string>>;
|
|
3
|
+
/** Every key a preset may set, sorted. */
|
|
4
|
+
export declare const PRESET_KEYS: readonly string[];
|
|
5
|
+
export declare function isPresetKey(key: string): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Which settings a preset can carry: Snapmaker Orca's print (process)
|
|
4
|
+
* settings, from the settings catalog generated at the pinned release, minus
|
|
5
|
+
* the ones below. Nothing outside this list is ever read from a master file
|
|
6
|
+
* or applied from a presets file.
|
|
7
|
+
*/
|
|
8
|
+
import { SETTINGS_CATALOG } from "../diff/settingsCatalog.js";
|
|
9
|
+
/** Print settings a preset never carries, with the reason, so a note can say why one was left out. */
|
|
10
|
+
export const PRESET_EXCLUDED_KEYS = Object.freeze({
|
|
11
|
+
// Tied to the model's layout and filament slots, not a printing preference.
|
|
12
|
+
// A different print sequence can make the toolhead hit printed objects.
|
|
13
|
+
print_sequence: "belongs to the model's layout",
|
|
14
|
+
print_order: "belongs to the model's layout",
|
|
15
|
+
wall_filament: "is a filament slot of the model",
|
|
16
|
+
sparse_infill_filament: "is a filament slot of the model",
|
|
17
|
+
solid_infill_filament: "is a filament slot of the model",
|
|
18
|
+
support_filament: "is a filament slot of the model",
|
|
19
|
+
support_interface_filament: "is a filament slot of the model",
|
|
20
|
+
wipe_tower_filament: "is a filament slot of the model",
|
|
21
|
+
wiping_volumes_extruders: "depends on the model's filaments",
|
|
22
|
+
// Which hotend types the profile has values for: the layout of the per-hotend-type settings, set by the profile.
|
|
23
|
+
process_flow_support: "is set by the profile",
|
|
24
|
+
// Preset bookkeeping, not a setting.
|
|
25
|
+
inherits: "is preset bookkeeping",
|
|
26
|
+
compatible_printers: "is preset bookkeeping",
|
|
27
|
+
compatible_printers_condition: "is preset bookkeeping",
|
|
28
|
+
// Scripts and free text.
|
|
29
|
+
post_process: "runs a script",
|
|
30
|
+
filename_format: "is a file name template",
|
|
31
|
+
notes: "is free text",
|
|
32
|
+
// The U1's Klipper firmware doesn't use arc moves.
|
|
33
|
+
enable_arc_fitting: "doesn't suit the U1's firmware",
|
|
34
|
+
});
|
|
35
|
+
/** Every key a preset may set, sorted. */
|
|
36
|
+
export const PRESET_KEYS = Object.freeze(Object.keys(SETTINGS_CATALOG)
|
|
37
|
+
.filter((key) => SETTINGS_CATALOG[key].group === "print" && !Object.hasOwn(PRESET_EXCLUDED_KEYS, key))
|
|
38
|
+
.sort());
|
|
39
|
+
const PRESET_KEY_SET = new Set(PRESET_KEYS);
|
|
40
|
+
export function isPresetKey(key) {
|
|
41
|
+
return PRESET_KEY_SET.has(key);
|
|
42
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profile catalogs: where conversion profiles come from, and how they are
|
|
3
|
+
* checked before the engine uses them.
|
|
4
|
+
*
|
|
5
|
+
* The core never bundles profile data (that is the separate, AGPL-licensed
|
|
6
|
+
* `any2orca-profiles` package). A caller hands it a {@link ProfileSource}:
|
|
7
|
+
* {@link fetchProfileSource} for a browser, `dirProfileSource()` or
|
|
8
|
+
* `bundledProfileSource()` from `any2orca/node`, or anything else with the
|
|
9
|
+
* same two methods (a partner's own CDN, a database, an in-memory object).
|
|
10
|
+
*
|
|
11
|
+
* Catalog data is treated as untrusted input, since it can come from a URL
|
|
12
|
+
* or folder the user points at: sizes are capped, every file is validated,
|
|
13
|
+
* and a profile file is only ever requested by an id the index lists.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import { Any2orcaError } from "./errors.js";
|
|
17
|
+
import type { ConvertProfile } from "./engine/runConvertPipeline.js";
|
|
18
|
+
/** Raw access to a catalog. Both methods return parsed JSON; the core validates it. */
|
|
19
|
+
export interface ProfileSource {
|
|
20
|
+
/** The catalog index (`index.json`). */
|
|
21
|
+
readIndex(): Promise<unknown>;
|
|
22
|
+
/** One profile file (`profiles/<id>.json`). Only called with an id the index lists. */
|
|
23
|
+
readProfile(id: string): Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
/** Largest index file accepted from any source. */
|
|
26
|
+
export declare const MAX_INDEX_BYTES: number;
|
|
27
|
+
/** Largest single profile file accepted from any source. A real one is about 100 KB. */
|
|
28
|
+
export declare const MAX_PROFILE_BYTES: number;
|
|
29
|
+
export declare const ProfileIndexSchema: z.ZodObject<{
|
|
30
|
+
schema: z.ZodLiteral<1>;
|
|
31
|
+
dataVersion: z.ZodString;
|
|
32
|
+
slicer: z.ZodObject<{
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
version: z.ZodString;
|
|
35
|
+
application: z.ZodString;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
source: z.ZodOptional<z.ZodObject<{
|
|
38
|
+
repository: z.ZodString;
|
|
39
|
+
tag: z.ZodString;
|
|
40
|
+
commit: z.ZodString;
|
|
41
|
+
}, z.core.$strip>>;
|
|
42
|
+
defaultProfileId: z.ZodString;
|
|
43
|
+
printers: z.ZodArray<z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
displayName: z.ZodString;
|
|
46
|
+
nozzleDiameter: z.ZodString;
|
|
47
|
+
highFlowSupported: z.ZodBoolean;
|
|
48
|
+
}, z.core.$strip>>;
|
|
49
|
+
profiles: z.ZodArray<z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
printerId: z.ZodString;
|
|
52
|
+
displayName: z.ZodString;
|
|
53
|
+
nozzleDiameter: z.ZodString;
|
|
54
|
+
layerHeight: z.ZodNumber;
|
|
55
|
+
autoSelectable: z.ZodBoolean;
|
|
56
|
+
highFlowSpeeds: z.ZodBoolean;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
retired: z.ZodArray<z.ZodObject<{
|
|
59
|
+
id: z.ZodString;
|
|
60
|
+
successorId: z.ZodString;
|
|
61
|
+
displayName: z.ZodString;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
filamentNames: z.ZodOptional<z.ZodObject<{
|
|
64
|
+
profileSet: z.ZodObject<{
|
|
65
|
+
repository: z.ZodString;
|
|
66
|
+
version: z.ZodString;
|
|
67
|
+
commit: z.ZodString;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
materialAliases: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
70
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
71
|
+
id: z.ZodString;
|
|
72
|
+
label: z.ZodString;
|
|
73
|
+
materials: z.ZodArray<z.ZodString>;
|
|
74
|
+
keywords: z.ZodArray<z.ZodString>;
|
|
75
|
+
snapmaker: z.ZodNullable<z.ZodString>;
|
|
76
|
+
generic: z.ZodNullable<z.ZodString>;
|
|
77
|
+
}, z.core.$strip>>;
|
|
78
|
+
printers: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
79
|
+
nozzleDiameter: z.ZodString;
|
|
80
|
+
presets: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
81
|
+
family: z.ZodString;
|
|
82
|
+
id: z.ZodString;
|
|
83
|
+
vendor: z.ZodString;
|
|
84
|
+
}, z.core.$strip>>;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
export type ProfileIndex = z.infer<typeof ProfileIndexSchema>;
|
|
89
|
+
export declare const ProfileFileSchema: z.ZodObject<{
|
|
90
|
+
schema: z.ZodLiteral<1>;
|
|
91
|
+
id: z.ZodString;
|
|
92
|
+
displayName: z.ZodString;
|
|
93
|
+
printer: z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
printableArea: z.ZodArray<z.ZodString>;
|
|
96
|
+
extruderClearanceRadius: z.ZodNumber;
|
|
97
|
+
highFlowSupported: z.ZodBoolean;
|
|
98
|
+
machineSettings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
99
|
+
}, z.core.$strip>;
|
|
100
|
+
baselineProjectSettings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
101
|
+
filamentShape: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
102
|
+
highFlowOverrides: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
export type ProfileFile = z.infer<typeof ProfileFileSchema>;
|
|
105
|
+
/** One entry in a profile listing: enough to render a picker. */
|
|
106
|
+
export interface ProfileSummary {
|
|
107
|
+
id: string;
|
|
108
|
+
displayName: string;
|
|
109
|
+
printerId: string;
|
|
110
|
+
nozzleDiameter: string;
|
|
111
|
+
layerHeight: number;
|
|
112
|
+
/**
|
|
113
|
+
* False for a tier that shares its layer height with another tier at the
|
|
114
|
+
* same nozzle size (e.g. "0.20mm High Quality" next to "0.20mm Standard").
|
|
115
|
+
* Auto-matching never picks these, since nothing in a source file says
|
|
116
|
+
* which one was meant. Still listed for manual selection.
|
|
117
|
+
*/
|
|
118
|
+
autoSelectable: boolean;
|
|
119
|
+
/** The tier's own name parsed from displayName, e.g. "Standard" or "High Quality". */
|
|
120
|
+
tierName: string;
|
|
121
|
+
/** This profile's nozzle supports the Liber High Flow Hotend (in the current catalog, only 0.4mm). */
|
|
122
|
+
highFlowSupported: boolean;
|
|
123
|
+
/** This tier has its own high-flow speeds (in the current catalog, only 0.20mm Standard, 0.4mm). */
|
|
124
|
+
highFlowSpeeds: boolean;
|
|
125
|
+
}
|
|
126
|
+
/** A retired profile id that still converts, with its successor. */
|
|
127
|
+
export interface RetiredProfile {
|
|
128
|
+
id: string;
|
|
129
|
+
successorId: string;
|
|
130
|
+
displayName: string;
|
|
131
|
+
}
|
|
132
|
+
/** A loaded profile: what the engine runs on, plus its catalog entry. */
|
|
133
|
+
export interface LoadedProfile {
|
|
134
|
+
summary: ProfileSummary;
|
|
135
|
+
convertProfile: ConvertProfile;
|
|
136
|
+
}
|
|
137
|
+
/** The catalog itself is missing or malformed (code `profile_data`). */
|
|
138
|
+
export declare class ProfileDataError extends Any2orcaError {
|
|
139
|
+
constructor(message: string);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A validated catalog. Get one with {@link loadCatalog}; it caches loaded
|
|
143
|
+
* profiles, so one instance can serve many conversions.
|
|
144
|
+
*/
|
|
145
|
+
export declare class ProfileCatalog {
|
|
146
|
+
readonly index: ProfileIndex;
|
|
147
|
+
private readonly source;
|
|
148
|
+
private readonly summaries;
|
|
149
|
+
private readonly byId;
|
|
150
|
+
private readonly retired;
|
|
151
|
+
private readonly cache;
|
|
152
|
+
constructor(index: ProfileIndex, source: ProfileSource);
|
|
153
|
+
/** Every profile, or only one nozzle size's, sorted by nozzle size and then layer height (finest first). */
|
|
154
|
+
list(filter?: {
|
|
155
|
+
nozzleDiameter?: string;
|
|
156
|
+
}): ProfileSummary[];
|
|
157
|
+
get(id: string): ProfileSummary | undefined;
|
|
158
|
+
/** The live profile that replaced a retired id, if `id` was retired. */
|
|
159
|
+
retiredSuccessor(id: string): RetiredProfile | undefined;
|
|
160
|
+
/** Loads and validates one profile. Throws for an id the catalog doesn't list. */
|
|
161
|
+
load(id: string): Promise<LoadedProfile>;
|
|
162
|
+
}
|
|
163
|
+
/** Reads and validates a source's index. Cached per source object. */
|
|
164
|
+
export declare function loadCatalog(source: ProfileSource | ProfileCatalog): Promise<ProfileCatalog>;
|
|
165
|
+
/** Lists a catalog's profiles; see {@link ProfileCatalog.list}. */
|
|
166
|
+
export declare function listProfiles(source: ProfileSource | ProfileCatalog, filter?: {
|
|
167
|
+
nozzleDiameter?: string;
|
|
168
|
+
}): Promise<ProfileSummary[]>;
|
|
169
|
+
/** Parses JSON text after checking its size; shared by every source that reads text. */
|
|
170
|
+
export declare function parseCatalogJson(text: string, maxBytes: number, what: string): unknown;
|
|
171
|
+
/**
|
|
172
|
+
* A catalog served over HTTP(S), e.g. `any2orca-profiles`' `data/` folder
|
|
173
|
+
* copied into a site's static files. Fetches `index.json` once, then only
|
|
174
|
+
* the profile files actually used. Makes no request until first used.
|
|
175
|
+
*/
|
|
176
|
+
export declare function fetchProfileSource(baseUrl: string | URL, options?: {
|
|
177
|
+
fetch?: typeof fetch;
|
|
178
|
+
init?: RequestInit;
|
|
179
|
+
}): ProfileSource;
|
|
180
|
+
/** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
|
|
181
|
+
export declare function memoryProfileSource(data: {
|
|
182
|
+
index: unknown;
|
|
183
|
+
profiles: Record<string, unknown>;
|
|
184
|
+
}): ProfileSource;
|