any2orca 0.6.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +2 -2
  3. package/dist/archive/lookupFilamentColorName.js +15 -4
  4. package/dist/archive/objectWorldBboxXY.js +80 -58
  5. package/dist/archive/parseObjectMetadata.js +33 -9
  6. package/dist/archive/recenterAssembleItems.js +9 -1
  7. package/dist/archive/recenterBuildItems.js +9 -1
  8. package/dist/archive/xmlBlocks.d.ts +52 -3
  9. package/dist/archive/xmlBlocks.js +106 -4
  10. package/dist/cli/config.js +32 -2
  11. package/dist/cli/watchState.js +22 -1
  12. package/dist/engine/buildFilamentConfigs.js +8 -5
  13. package/dist/errors.d.ts +1 -1
  14. package/dist/inspect.d.ts +8 -1
  15. package/dist/inspect.js +4 -1
  16. package/dist/node.js +7 -1
  17. package/dist/profiles.d.ts +39 -0
  18. package/dist/profiles.js +63 -0
  19. package/dist/project.js +10 -1
  20. package/dist/sources/prusa/beds.d.ts +33 -0
  21. package/dist/sources/prusa/beds.js +66 -0
  22. package/dist/sources/prusa/bundle.d.ts +53 -0
  23. package/dist/sources/prusa/bundle.js +106 -0
  24. package/dist/sources/prusa/convertSettings.d.ts +2 -0
  25. package/dist/sources/prusa/convertSettings.js +62 -2
  26. package/dist/sources/prusa/keyMap.js +5 -2
  27. package/dist/sources/prusa/modelConfig.d.ts +5 -1
  28. package/dist/sources/prusa/modelConfig.js +27 -10
  29. package/dist/sources/prusa/policyB.d.ts +56 -0
  30. package/dist/sources/prusa/policyB.js +161 -0
  31. package/dist/sources/prusa/prusa.d.ts +1 -1
  32. package/dist/sources/prusa/prusa.js +102 -36
  33. package/dist/sources/prusa/splitParts.d.ts +0 -13
  34. package/dist/sources/prusa/splitParts.js +107 -42
  35. package/dist/sources/reader.d.ts +26 -0
  36. package/dist/stamp.d.ts +1 -1
  37. package/dist/version.d.ts +1 -1
  38. package/dist/version.js +1 -1
  39. package/dist/worker-entry.js +4 -3
  40. package/dist/worker.d.ts +7 -2
  41. package/dist/worker.js +22 -8
  42. package/package.json +3 -3
@@ -29,13 +29,43 @@ export function readCliConfig(env = process.env) {
29
29
  const text = readFileSync(path, "utf-8");
30
30
  if (text.length > MAX_CONFIG_BYTES)
31
31
  return {};
32
- const value = JSON.parse(text);
33
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
32
+ return checkedConfig(JSON.parse(text));
34
33
  }
35
34
  catch {
36
35
  return {};
37
36
  }
38
37
  }
38
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
39
+ /** What the update check stores as the latest version (see updateCheck.ts); anything else isn't a version. */
40
+ const VERSION_TEXT = /^\d{1,9}\.\d{1,9}\.\d{1,9}(-[0-9A-Za-z.-]{1,64})?$/;
41
+ /**
42
+ * The parts of a parsed config file that have the shape this tool writes. A
43
+ * value of the wrong type is dropped rather than used: the file can be
44
+ * hand-edited, or sit in a folder someone else controls, and a bad entry once
45
+ * stopped every command before it did any work.
46
+ */
47
+ function checkedConfig(value) {
48
+ if (!isRecord(value))
49
+ return {};
50
+ const config = {};
51
+ const { stats, updateCheck } = value;
52
+ if (isRecord(stats) && (stats.choice === "on" || stats.choice === "off") && typeof stats.decidedOn === "string") {
53
+ config.stats = { choice: stats.choice, decidedOn: stats.decidedOn.slice(0, 64) };
54
+ }
55
+ if (isRecord(updateCheck)) {
56
+ const checked = {};
57
+ if (typeof updateCheck.enabled === "boolean")
58
+ checked.enabled = updateCheck.enabled;
59
+ if (typeof updateCheck.lastCheckedAt === "number" && Number.isFinite(updateCheck.lastCheckedAt))
60
+ checked.lastCheckedAt = updateCheck.lastCheckedAt;
61
+ if (typeof updateCheck.latest === "string" && VERSION_TEXT.test(updateCheck.latest))
62
+ checked.latest = updateCheck.latest;
63
+ if (typeof updateCheck.outputAffecting === "string")
64
+ checked.outputAffecting = updateCheck.outputAffecting.slice(0, 300);
65
+ config.updateCheck = checked;
66
+ }
67
+ return config;
68
+ }
39
69
  /** Writes atomically (temp file + rename), so a crash never leaves a half-written config. */
40
70
  export function writeCliConfig(config, env = process.env) {
41
71
  const dir = configDir(env);
@@ -22,12 +22,33 @@ export function loadStateFile(dir) {
22
22
  if (!existsSync(path))
23
23
  return {};
24
24
  try {
25
- return JSON.parse(readFileSync(path, "utf-8"));
25
+ return checkedState(JSON.parse(readFileSync(path, "utf-8")));
26
26
  }
27
27
  catch {
28
28
  return {};
29
29
  }
30
30
  }
31
+ const OUTCOMES = new Set(["succeeded", "failed-once", "permanently-failed"]);
32
+ /**
33
+ * The records of a parsed state file that have the expected shape; anything
34
+ * else counts as not recorded. The file sits in the output folder, which may
35
+ * be shared, and a file holding `null` or a list once stopped the run.
36
+ */
37
+ function checkedState(value) {
38
+ if (typeof value !== "object" || value === null || Array.isArray(value))
39
+ return {};
40
+ // No prototype, so a file named "__proto__" or "constructor" is an ordinary key.
41
+ const state = Object.create(null);
42
+ for (const [name, record] of Object.entries(value)) {
43
+ if (typeof record !== "object" || record === null)
44
+ continue;
45
+ const { fingerprint, outcome } = record;
46
+ if (typeof fingerprint === "string" && typeof outcome === "string" && OUTCOMES.has(outcome)) {
47
+ state[name] = { fingerprint, outcome: outcome };
48
+ }
49
+ }
50
+ return state;
51
+ }
31
52
  export function saveStateFile(dir, state) {
32
53
  writeFileSync(stateFilePath(dir), JSON.stringify(state, null, 2));
33
54
  }
@@ -12,17 +12,20 @@ export function buildFilamentConfigs(slots, filamentShape, filamentKeyBlocklist)
12
12
  if (slots.length === 0) {
13
13
  return { files: {}, uniqueNames: null };
14
14
  }
15
- const uniqueNames = [];
15
+ // Each name's first slot, in one pass, in the order names first appear. Every slot is kept in the project; this
16
+ // only picks which one each embedded preset is written from. (Scanning the list for every slot was quadratic.)
17
+ // The settings came through JSON, so no name is NaN, the one value a Map compares differently from `===`.
18
+ const firstSlotByName = new Map();
16
19
  for (const slot of slots) {
17
20
  const name = slot.filament_settings_id ?? "Unnamed Filament";
18
- if (!uniqueNames.some((n) => n === name)) {
19
- uniqueNames.push(name);
20
- }
21
+ if (!firstSlotByName.has(name))
22
+ firstSlotByName.set(name, slot);
21
23
  }
24
+ const uniqueNames = [...firstSlotByName.keys()];
22
25
  const files = {};
23
26
  uniqueNames.forEach((name, i) => {
24
27
  const idx = i + 1;
25
- const rep = slots.find((s) => (s.filament_settings_id ?? "Unnamed Filament") === name);
28
+ const rep = firstSlotByName.get(name);
26
29
  const cfg = { ...filamentShape };
27
30
  for (const [key, val] of Object.entries(rep)) {
28
31
  if (filamentKeyBlocklist.has(key))
package/dist/errors.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * What went wrong, as a stable code a UI can branch on:
3
3
  * - `invalid_file`: not a readable 3MF (corrupt zip, missing project files, unsafe entries).
4
- * - `unsupported_slicer`: a readable project from a slicer this doesn't convert (PrusaSlicer, say); `slicer` names it.
4
+ * - `unsupported_slicer`: a readable project from a slicer this doesn't convert (SuperSlicer, say, or an older AnycubicSlicer, both built on PrusaSlicer); `slicer` names it.
5
5
  * - `too_large`: a project that unpacks to more than the size limit (2 GB by default; `maxUnpackedBytes` changes it).
6
6
  * - `invalid_project`: a readable 3MF whose settings or objects are malformed or over a limit.
7
7
  * - `profile_not_found`: the requested profile id isn't in the catalog and wasn't retired.
package/dist/inspect.d.ts CHANGED
@@ -44,6 +44,13 @@ export interface Inspection {
44
44
  slicerVersion: string | null;
45
45
  /** The source bed's printable_area, for drawing the source plate. */
46
46
  sourcePrintableArea: string[] | null;
47
+ /**
48
+ * Where each plate's bed sits in the source project, in mm from the first plate's, keyed by plate number: subtract it
49
+ * from an object's `bbox` to draw the object on its own plate. Present only when the source slicer doesn't lay its
50
+ * plates out on Bambu Studio's grid (columns = ceil(sqrt(plate count)), a pitch of 1.2 beds, later rows at negative Y):
51
+ * PrusaSlicer 2.9 places its beds in rings with a gap of at most 100 mm, later rows at positive Y. Absent: use that grid.
52
+ */
53
+ sourcePlateOrigins?: Record<number, [number, number]>;
47
54
  /** Non-fatal notes from reading the file. */
48
55
  warnings: string[];
49
56
  /**
@@ -54,4 +61,4 @@ export interface Inspection {
54
61
  }
55
62
  export declare function detectSourceVendor(printerModel: string | null, sourcePresetName?: string | null, printerNotes?: string | null, printerPresetName?: string | null): SourceVendor;
56
63
  /** Builds an {@link Inspection} from a parsed project's settings and objects. */
57
- export declare function inspectProject(projectSettings: Record<string, unknown>, objects: ConvertObject[], warnings: readonly string[], unpackedBytes: number): Inspection;
64
+ export declare function inspectProject(projectSettings: Record<string, unknown>, objects: ConvertObject[], warnings: readonly string[], unpackedBytes: number, sourcePlateOrigins?: Readonly<Record<number, readonly [number, number]>>): Inspection;
package/dist/inspect.js CHANGED
@@ -63,7 +63,7 @@ export function detectSourceVendor(printerModel, sourcePresetName = null, printe
63
63
  return "other";
64
64
  }
65
65
  /** Builds an {@link Inspection} from a parsed project's settings and objects. */
66
- export function inspectProject(projectSettings, objects, warnings, unpackedBytes) {
66
+ export function inspectProject(projectSettings, objects, warnings, unpackedBytes, sourcePlateOrigins) {
67
67
  const colors = toStringArray(projectSettings.filament_colour);
68
68
  const types = toStringArray(projectSettings.filament_type);
69
69
  const names = toStringArray(projectSettings.filament_settings_id);
@@ -105,5 +105,8 @@ export function inspectProject(projectSettings, objects, warnings, unpackedBytes
105
105
  : null,
106
106
  warnings: [...warnings],
107
107
  unpackedBytes,
108
+ ...(sourcePlateOrigins
109
+ ? { sourcePlateOrigins: Object.fromEntries(plates.filter((p) => Object.hasOwn(sourcePlateOrigins, p)).map((p) => [p, [sourcePlateOrigins[p][0], sourcePlateOrigins[p][1]]])) }
110
+ : {}),
108
111
  };
109
112
  }
package/dist/node.js CHANGED
@@ -10,7 +10,7 @@
10
10
  import { readFile, stat } from "node:fs/promises";
11
11
  import { createRequire } from "node:module";
12
12
  import { dirname, join, resolve } from "node:path";
13
- import { isReleasePath, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, parseCatalogJson, ProfileDataError } from "./profiles.js";
13
+ import { isReleasePath, isSourcePath, MAX_INDEX_BYTES, MAX_PROFILE_BYTES, MAX_SOURCE_BYTES, parseCatalogJson, ProfileDataError } from "./profiles.js";
14
14
  async function readCapped(path, maxBytes) {
15
15
  let size;
16
16
  try {
@@ -36,6 +36,12 @@ export function dirProfileSource(dir) {
36
36
  // Ids are validated against the index (lowercase letters, digits, dots
37
37
  // and dashes, no slashes) before this is called, so this stays in root.
38
38
  readProfile: (id) => readCapped(join(root, "profiles", `${id}.json`), MAX_PROFILE_BYTES),
39
+ // sources/prusaslicer/<Vendor>.json only (checked by the catalog and here), so this stays in root too.
40
+ readSource: (path) => {
41
+ if (!isSourcePath(path))
42
+ throw new ProfileDataError(`Not a source data file: ${JSON.stringify(path.slice(0, 60))}.`);
43
+ return readCapped(join(root, ...path.split("/")), MAX_SOURCE_BYTES);
44
+ },
39
45
  release: (path) => {
40
46
  // releases/<digits.digits.digits> only, so this stays in root too.
41
47
  if (!isReleasePath(path))
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import "./zodSetup.js";
21
21
  import { z } from "zod";
22
+ import { type PrusaBundle } from "./sources/prusa/bundle.js";
22
23
  import { Any2orcaError } from "./errors.js";
23
24
  import type { ConvertProfile } from "./engine/runConvertPipeline.js";
24
25
  /** Raw access to a catalog. Both methods return parsed JSON; the core validates it. */
@@ -34,6 +35,13 @@ export interface ProfileSource {
34
35
  * catalog with one release.
35
36
  */
36
37
  release?(path: string): ProfileSource;
38
+ /**
39
+ * One source-slicer data file (`sources/prusaslicer/<Vendor>.json`). Only
40
+ * called with a path the index lists, which passes {@link isSourcePath}.
41
+ * Leave it out for a source without such data: a PrusaSlicer project is
42
+ * then converted with every mapped setting treated as changed.
43
+ */
44
+ readSource?(path: string): Promise<unknown>;
37
45
  }
38
46
  /** True for a path a {@link ProfileSource.release} may be asked for. */
39
47
  export declare function isReleasePath(path: string): boolean;
@@ -41,6 +49,11 @@ export declare function isReleasePath(path: string): boolean;
41
49
  export declare const MAX_INDEX_BYTES: number;
42
50
  /** Largest single profile file accepted from any source. A real one is about 100 KB. */
43
51
  export declare const MAX_PROFILE_BYTES: number;
52
+ /** A source-slicer bundle file (a vendor's print presets, unresolved) is a few hundred KB; this bounds a hostile one. */
53
+ export declare const MAX_SOURCE_BYTES: number;
54
+ /** Where the index may point for source-slicer data: `sources/prusaslicer/<Vendor>.json` only. */
55
+ export declare const SOURCE_PATH: RegExp;
56
+ export declare function isSourcePath(path: string): boolean;
44
57
  export declare const ProfileIndexSchema: z.ZodObject<{
45
58
  schema: z.ZodLiteral<1>;
46
59
  dataVersion: z.ZodString;
@@ -104,6 +117,16 @@ export declare const ProfileIndexSchema: z.ZodObject<{
104
117
  application: z.ZodString;
105
118
  path: z.ZodUnion<readonly [z.ZodLiteral<".">, z.ZodString]>;
106
119
  }, z.core.$strip>>>;
120
+ sources: z.ZodOptional<z.ZodObject<{
121
+ prusaslicer: z.ZodArray<z.ZodObject<{
122
+ vendor: z.ZodString;
123
+ name: z.ZodString;
124
+ path: z.ZodString;
125
+ slicerVersion: z.ZodString;
126
+ configVersion: z.ZodString;
127
+ slicerTag: z.ZodString;
128
+ }, z.core.$strip>>;
129
+ }, z.core.$strip>>;
107
130
  }, z.core.$strip>;
108
131
  export type ProfileIndex = z.infer<typeof ProfileIndexSchema>;
109
132
  export declare const ProfileFileSchema: z.ZodObject<{
@@ -179,12 +202,26 @@ export declare class ProfileCatalog {
179
202
  private readonly retired;
180
203
  private readonly cache;
181
204
  private readonly releaseCatalogs;
205
+ private readonly bundles;
182
206
  constructor(index: ProfileIndex, source: ProfileSource);
183
207
  /** Every profile, or only one nozzle size's, sorted by nozzle size and then layer height (finest first). */
184
208
  list(filter?: {
185
209
  nozzleDiameter?: string;
186
210
  }): ProfileSummary[];
187
211
  get(id: string): ProfileSummary | undefined;
212
+ /** The PrusaSlicer vendor bundles this catalog holds, as the index lists them. */
213
+ prusaBundles(): {
214
+ vendor: string;
215
+ name: string;
216
+ slicerVersion: string;
217
+ configVersion: string;
218
+ slicerTag: string;
219
+ }[];
220
+ /**
221
+ * One PrusaSlicer vendor bundle, loaded and checked once, or null when the
222
+ * catalog doesn't list it or its source can't read source data.
223
+ */
224
+ prusaBundle(vendor: string, slicerVersion: string): Promise<PrusaBundle | null>;
188
225
  /** The live profile that replaced a retired id, if `id` was retired. */
189
226
  retiredSuccessor(id: string): RetiredProfile | undefined;
190
227
  /** The Snapmaker Orca releases this catalog holds, newest first. The first is the default. */
@@ -222,6 +259,8 @@ export interface MemoryCatalogData {
222
259
  index: unknown;
223
260
  profiles: Record<string, unknown>;
224
261
  releases?: Record<string, MemoryCatalogData>;
262
+ /** Source-slicer data files by their index path (`sources/prusaslicer/<Vendor>.json`). */
263
+ sources?: Record<string, unknown>;
225
264
  }
226
265
  /** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
227
266
  export declare function memoryProfileSource(data: MemoryCatalogData): ProfileSource;
package/dist/profiles.js CHANGED
@@ -20,6 +20,7 @@
20
20
  */
21
21
  import "./zodSetup.js";
22
22
  import { z } from "zod";
23
+ import { PrusaBundleSchema } from "./sources/prusa/bundle.js";
23
24
  import { Any2orcaError } from "./errors.js";
24
25
  import { APPLICATION_VALUE } from "./archive/setApplicationMetadata.js";
25
26
  import { parseTierName } from "./engine/parseTierName.js";
@@ -34,6 +35,13 @@ export function isReleasePath(path) {
34
35
  export const MAX_INDEX_BYTES = 1024 * 1024;
35
36
  /** Largest single profile file accepted from any source. A real one is about 100 KB. */
36
37
  export const MAX_PROFILE_BYTES = 8 * 1024 * 1024;
38
+ /** A source-slicer bundle file (a vendor's print presets, unresolved) is a few hundred KB; this bounds a hostile one. */
39
+ export const MAX_SOURCE_BYTES = 8 * 1024 * 1024;
40
+ /** Where the index may point for source-slicer data: `sources/prusaslicer/<Vendor>.json` only. */
41
+ export const SOURCE_PATH = /^sources\/prusaslicer\/[A-Za-z0-9]{1,64}-\d+\.\d+\.\d+\.json$/;
42
+ export function isSourcePath(path) {
43
+ return SOURCE_PATH.test(path);
44
+ }
37
45
  const ID = z.string().regex(/^[a-z0-9][a-z0-9.-]{0,63}$/, "must be lowercase letters, digits, dots and dashes");
38
46
  const VERSION = z.string().regex(/^\d+(\.\d+){1,3}([-+][0-9A-Za-z.-]{1,32})?$/);
39
47
  const DIAMETER = z.string().regex(/^\d{1,2}(\.\d{1,3})?$/);
@@ -105,6 +113,18 @@ export const ProfileIndexSchema = z.object({
105
113
  .min(1)
106
114
  .max(50)
107
115
  .optional(),
116
+ /**
117
+ * Source-slicer data the catalog holds, independent of the Snapmaker Orca
118
+ * release: PrusaSlicer's vendor preset bundles (print presets), used to
119
+ * tell what a PrusaSlicer project's creator changed. Absent in older data.
120
+ */
121
+ sources: z
122
+ .object({
123
+ prusaslicer: z
124
+ .array(z.object({ vendor: z.string().regex(/^[A-Za-z0-9]{1,64}$/), name: NAME, path: z.string().regex(SOURCE_PATH), slicerVersion: VERSION, configVersion: presetText(64), slicerTag: presetText(64) }))
125
+ .max(50),
126
+ })
127
+ .optional(),
108
128
  });
109
129
  export const ProfileFileSchema = z.object({
110
130
  schema: z.literal(1),
@@ -145,6 +165,7 @@ export class ProfileCatalog {
145
165
  retired;
146
166
  cache = new Map();
147
167
  releaseCatalogs = new Map();
168
+ bundles = new Map();
148
169
  constructor(index, source) {
149
170
  this.index = index;
150
171
  this.source = source;
@@ -200,6 +221,34 @@ export class ProfileCatalog {
200
221
  const summary = this.byId.get(id);
201
222
  return summary ? { ...summary } : undefined;
202
223
  }
224
+ /** The PrusaSlicer vendor bundles this catalog holds, as the index lists them. */
225
+ prusaBundles() {
226
+ return (this.index.sources?.prusaslicer ?? []).map(({ vendor, name, slicerVersion, configVersion, slicerTag }) => ({ vendor, name, slicerVersion, configVersion, slicerTag }));
227
+ }
228
+ /**
229
+ * One PrusaSlicer vendor bundle, loaded and checked once, or null when the
230
+ * catalog doesn't list it or its source can't read source data.
231
+ */
232
+ prusaBundle(vendor, slicerVersion) {
233
+ const entry = this.index.sources?.prusaslicer.find((b) => b.vendor === vendor && b.slicerVersion === slicerVersion);
234
+ if (!entry || !this.source.readSource || !isSourcePath(entry.path))
235
+ return Promise.resolve(null);
236
+ const cacheKey = `${vendor}-${slicerVersion}`;
237
+ let pending = this.bundles.get(cacheKey);
238
+ if (!pending) {
239
+ const path = entry.path;
240
+ pending = this.source.readSource(path).then((raw) => {
241
+ const parsed = PrusaBundleSchema.safeParse(raw);
242
+ if (!parsed.success)
243
+ throw new ProfileDataError(`Profile catalog's ${path} isn't a vendor bundle: ${describeIssues(parsed.error)}`);
244
+ if (parsed.data.vendor !== vendor || parsed.data.slicer.version !== slicerVersion)
245
+ throw new ProfileDataError(`Profile catalog's ${path} is the bundle for ${parsed.data.vendor} ${parsed.data.slicer.version}, not ${vendor} ${slicerVersion}.`);
246
+ return parsed.data;
247
+ });
248
+ this.bundles.set(cacheKey, pending);
249
+ }
250
+ return pending;
251
+ }
203
252
  /** The live profile that replaced a retired id, if `id` was retired. */
204
253
  retiredSuccessor(id) {
205
254
  if (this.byId.has(id))
@@ -392,6 +441,11 @@ export function fetchProfileSource(baseUrl, options = {}) {
392
441
  throw new ProfileDataError(`Not a release folder: ${plainVersion(path)}.`);
393
442
  return fetchProfileSource(new URL(`${path}/`, base), options);
394
443
  },
444
+ readSource: (path) => {
445
+ if (!isSourcePath(path))
446
+ throw new ProfileDataError(`Not a source data file: ${JSON.stringify(path.slice(0, 60))}.`);
447
+ return read(path, MAX_SOURCE_BYTES);
448
+ },
395
449
  };
396
450
  }
397
451
  /** A catalog already in memory, e.g. for tests or a bundler that inlines the JSON. */
@@ -403,6 +457,15 @@ export function memoryProfileSource(data) {
403
457
  throw new ProfileDataError(`No profile file for id "${id}".`);
404
458
  return data.profiles[id];
405
459
  },
460
+ ...(data.sources
461
+ ? {
462
+ readSource: async (path) => {
463
+ if (!isSourcePath(path) || !Object.hasOwn(data.sources, path))
464
+ throw new ProfileDataError(`No source data at ${JSON.stringify(path.slice(0, 60))}.`);
465
+ return data.sources[path];
466
+ },
467
+ }
468
+ : {}),
406
469
  release: (path) => {
407
470
  if (!isReleasePath(path) || !data.releases || !Object.hasOwn(data.releases, path))
408
471
  throw new ProfileDataError(`No catalog data for ${plainVersion(path)}.`);
package/dist/project.js CHANGED
@@ -8,6 +8,7 @@
8
8
  * and response pass through JSON, so numbers serialize the same way every
9
9
  * time (e.g. -0 becomes 0) and output is reproducible byte for byte.
10
10
  */
11
+ import { applyPolicyB, policyBFallbackNote } from "./sources/prusa/policyB.js";
11
12
  import { applyConvertResponse, prepareConvertRequest } from "./archive/zip.js";
12
13
  import { unwrapIfBundle } from "./archive/unwrapBundle.js";
13
14
  import { detectNozzleDiameter } from "./engine/detectNozzleDiameter.js";
@@ -190,7 +191,7 @@ export class Project {
190
191
  return structuredClone(this.request.projectSettings);
191
192
  }
192
193
  inspect() {
193
- return inspectProject(this.request.projectSettings, this.request.objects, this.parsed.warnings, this.parsed.unpackedBytes);
194
+ return inspectProject(this.request.projectSettings, this.request.objects, this.parsed.warnings, this.parsed.unpackedBytes, this.parsed.sourcePlateOrigins);
194
195
  }
195
196
  /** The profile auto-matching would pick for this file. */
196
197
  matchProfile(profiles) {
@@ -203,6 +204,13 @@ export class Project {
203
204
  const top = await loadCatalog(options.profiles);
204
205
  const catalog = options.snapmakerOrcaVersion === undefined ? top : await top.forRelease(options.snapmakerOrcaVersion);
205
206
  const routeWarnings = [];
207
+ // A PrusaSlicer project records no list of what its creator changed; with the vendor's presets at hand, the
208
+ // list is the diff against the project's print preset (policy B), as a Bambu Studio family project's own list is.
209
+ let policyB = null;
210
+ if (this.parsed.prusa) {
211
+ policyB = await applyPolicyB(this.parsed.prusa, top, this.request.projectSettings);
212
+ routeWarnings.push(...(policyB ? policyB.notes : [policyBFallbackNote(this.parsed.prusa, top)]));
213
+ }
206
214
  let profileId;
207
215
  let profileMatch;
208
216
  let profileNotes = [];
@@ -245,6 +253,7 @@ export class Project {
245
253
  const highFlowHotends = normalizeHighFlowOption(options.highFlowHotends);
246
254
  const request = {
247
255
  ...this.request,
256
+ ...(policyB ? { projectSettings: policyB.projectSettings } : {}),
248
257
  ...(options.filamentComplianceMode ? { filamentComplianceMode: options.filamentComplianceMode } : {}),
249
258
  ...(highFlowHotends !== false ? { highFlowHotends } : {}),
250
259
  ...(options.hardenedNozzles === true ? { hardenedNozzles: true } : {}),
@@ -0,0 +1,33 @@
1
+ /**
2
+ * PrusaSlicer 2.9's several beds. The project records no bed for an object:
3
+ * the beds are virtual copies of the printer's bed laid out on a grid around
4
+ * it, and an object is on the first bed (in index order) whose area it
5
+ * touches, as PrusaSlicer decides it on load (`BuildVolume::object_state`
6
+ * with `MultipleBeds::get_bed_translation`). The grid walks outward in square
7
+ * rings: bed 0 at the origin, 1 to its right, 2 above it, 3 diagonally, then
8
+ * the next ring (`BedsGrid::grid_coords_abs2index`). The gap between beds is
9
+ * the smaller of 100 mm and three tenths of the bed's diagonal
10
+ * (`MultipleBeds::bed_gap`). Projects saved before 2.9.0 have one bed.
11
+ */
12
+ /** PrusaSlicer's `MAX_NUMBER_OF_BEDS`. */
13
+ export declare const MAX_BEDS = 9;
14
+ export interface BedRect {
15
+ minX: number;
16
+ minY: number;
17
+ maxX: number;
18
+ maxY: number;
19
+ }
20
+ /** The printer's bed from `bed_shape` ("0x0,250x0,250x210,0x210"), as its bounding rectangle; null when unreadable. */
21
+ export declare function parseBedShape(value: string | undefined): BedRect | null;
22
+ /** The gap between two beds, in mm. */
23
+ export declare function bedGap(bed: BedRect): number;
24
+ /** Grid coordinates of bed `index` (the first quadrant of PrusaSlicer's grid). */
25
+ export declare function bedGridCoords(index: number): [number, number];
26
+ /** Where bed `index` sits: its translation from the printer's bed, in mm. */
27
+ export declare function bedTranslation(index: number, bed: BedRect): [number, number];
28
+ /**
29
+ * The bed an object is on, by its world bounding box: the first bed whose
30
+ * rectangle the box touches, or null when it touches none (PrusaSlicer leaves
31
+ * such an object on no bed).
32
+ */
33
+ export declare function bedIndexOf(bbox: readonly [number, number, number, number], bed: BedRect): number | null;
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ * PrusaSlicer 2.9's several beds. The project records no bed for an object:
4
+ * the beds are virtual copies of the printer's bed laid out on a grid around
5
+ * it, and an object is on the first bed (in index order) whose area it
6
+ * touches, as PrusaSlicer decides it on load (`BuildVolume::object_state`
7
+ * with `MultipleBeds::get_bed_translation`). The grid walks outward in square
8
+ * rings: bed 0 at the origin, 1 to its right, 2 above it, 3 diagonally, then
9
+ * the next ring (`BedsGrid::grid_coords_abs2index`). The gap between beds is
10
+ * the smaller of 100 mm and three tenths of the bed's diagonal
11
+ * (`MultipleBeds::bed_gap`). Projects saved before 2.9.0 have one bed.
12
+ */
13
+ /** PrusaSlicer's `MAX_NUMBER_OF_BEDS`. */
14
+ export const MAX_BEDS = 9;
15
+ /** The printer's bed from `bed_shape` ("0x0,250x0,250x210,0x210"), as its bounding rectangle; null when unreadable. */
16
+ export function parseBedShape(value) {
17
+ if (!value)
18
+ return null;
19
+ const points = value.split(",").map((p) => p.trim().split("x").map(Number));
20
+ if (points.length < 3 || points.some((p) => p.length !== 2 || !p.every(Number.isFinite)))
21
+ return null;
22
+ const xs = points.map((p) => p[0]);
23
+ const ys = points.map((p) => p[1]);
24
+ const rect = { minX: Math.min(...xs), minY: Math.min(...ys), maxX: Math.max(...xs), maxY: Math.max(...ys) };
25
+ return rect.maxX > rect.minX && rect.maxY > rect.minY ? rect : null;
26
+ }
27
+ /** The gap between two beds, in mm. */
28
+ export function bedGap(bed) {
29
+ const w = bed.maxX - bed.minX;
30
+ const h = bed.maxY - bed.minY;
31
+ return Math.min(100, Math.hypot(w, h) * 0.3);
32
+ }
33
+ /** Grid coordinates of bed `index` (the first quadrant of PrusaSlicer's grid). */
34
+ export function bedGridCoords(index) {
35
+ if (index <= 0)
36
+ return [0, 0];
37
+ const ring = Math.floor(Math.sqrt(index)) + 1; // the ring whose outer coordinate is ring - 1
38
+ const start = (ring - 1) * (ring - 1);
39
+ const edge = ring - 1;
40
+ if (index === ring * ring - 1)
41
+ return [edge, edge];
42
+ if (index < start + edge)
43
+ return [edge, index - start];
44
+ return [index - start - edge, edge];
45
+ }
46
+ /** Where bed `index` sits: its translation from the printer's bed, in mm. */
47
+ export function bedTranslation(index, bed) {
48
+ const [gx, gy] = bedGridCoords(index);
49
+ const gap = bedGap(bed);
50
+ return [gx * (bed.maxX - bed.minX + gap), gy * (bed.maxY - bed.minY + gap)];
51
+ }
52
+ /**
53
+ * The bed an object is on, by its world bounding box: the first bed whose
54
+ * rectangle the box touches, or null when it touches none (PrusaSlicer leaves
55
+ * such an object on no bed).
56
+ */
57
+ export function bedIndexOf(bbox, bed) {
58
+ const [minX, maxX, minY, maxY] = bbox;
59
+ for (let index = 0; index < MAX_BEDS; index++) {
60
+ const [tx, ty] = bedTranslation(index, bed);
61
+ const touches = maxX >= bed.minX + tx && minX <= bed.maxX + tx && maxY >= bed.minY + ty && minY <= bed.maxY + ty;
62
+ if (touches)
63
+ return index;
64
+ }
65
+ return null;
66
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * A PrusaSlicer vendor bundle as `any2orca-profiles` ships it
3
+ * (`sources/prusaslicer/<Vendor>.json`): the vendor's print presets as the
4
+ * bundle has them, each with its own keys and its `inherits` list, and the
5
+ * old names `renamed_from` lines map to current ones. Resolving a preset
6
+ * follows PrusaSlicer's own rule (`PresetBundle.cpp`,
7
+ * `flatten_configbundle_hierarchy`): a preset's own keys win, then the last
8
+ * parent listed, down to the first; parents are resolved the same way first.
9
+ */
10
+ import "../../zodSetup.js";
11
+ import { z } from "zod";
12
+ export declare const PrusaBundleSchema: z.ZodObject<{
13
+ schema: z.ZodLiteral<1>;
14
+ vendor: z.ZodString;
15
+ name: z.ZodString;
16
+ configVersion: z.ZodString;
17
+ slicer: z.ZodObject<{
18
+ name: z.ZodString;
19
+ version: z.ZodString;
20
+ repository: z.ZodString;
21
+ tag: z.ZodString;
22
+ commit: z.ZodString;
23
+ }, z.core.$strip>;
24
+ license: z.ZodString;
25
+ groups: z.ZodArray<z.ZodLiteral<"print">>;
26
+ printerModels: z.ZodRecord<z.ZodString, z.ZodObject<{
27
+ name: z.ZodString;
28
+ variants: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
+ }, z.core.$strip>>;
30
+ presets: z.ZodObject<{
31
+ print: z.ZodRecord<z.ZodString, z.ZodObject<{
32
+ inherits: z.ZodOptional<z.ZodArray<z.ZodString>>;
33
+ values: z.ZodRecord<z.ZodString, z.ZodString>;
34
+ }, z.core.$strip>>;
35
+ }, z.core.$strip>;
36
+ renamedFrom: z.ZodRecord<z.ZodString, z.ZodString>;
37
+ defaults: z.ZodRecord<z.ZodString, z.ZodString>;
38
+ }, z.core.$strict>;
39
+ export type PrusaBundle = z.infer<typeof PrusaBundleSchema>;
40
+ /**
41
+ * The print preset's full values, with inheritance applied, or null when the
42
+ * bundle doesn't have it. Abstract presets (names in `*`) resolve too; they're
43
+ * what concrete ones inherit from.
44
+ */
45
+ export declare function resolvePrintPreset(bundle: PrusaBundle, name: string): Record<string, string> | null;
46
+ /**
47
+ * The bundle's name for a preset name a project recorded: the name itself, a
48
+ * current name for one the bundle renamed, or the preset a project-embedded
49
+ * copy was made from. PrusaSlicer names an embedded copy
50
+ * `<file>.3mf (<preset>)`, nested once more at each re-save
51
+ * (`a.3mf (b.3mf (0.20mm QUALITY @MK3))`), so the innermost name is the one.
52
+ */
53
+ export declare function lookupPrintPresetName(bundle: PrusaBundle, recorded: string): string | null;