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
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { unzipSync } from "fflate";
|
|
3
|
+
import { Any2orcaError } from "../errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Defeats a classic decompression-bomb .3mf (a tiny compressed file whose
|
|
6
|
+
* zip central directory *declares* a huge uncompressed size) -- fflate's
|
|
7
|
+
* `filter` callback runs against each entry's declared size, read straight
|
|
8
|
+
* from the zip's central directory, BEFORE that entry is actually
|
|
9
|
+
* inflated, so an oversized claim is rejected up front rather than after
|
|
10
|
+
* the expensive decompression already happened. This matters because
|
|
11
|
+
* .3mf parsing runs on the machine of whoever converts the file (a browser
|
|
12
|
+
* tab or the CLI), so a malicious file shared on a creator site would
|
|
13
|
+
* otherwise crash or hang that person's machine.
|
|
14
|
+
*
|
|
15
|
+
* The actual signature of a bomb is an absurd COMPRESSION RATIO, not a
|
|
16
|
+
* large absolute size -- a single DEFLATE stream tops out near ~1032:1
|
|
17
|
+
* even on maximally-repetitive input, so a small compressed file claiming
|
|
18
|
+
* gigabytes is only achievable by a crafted bomb, never real data. A flat
|
|
19
|
+
* total size cap alone would reject real large projects: creators publish
|
|
20
|
+
* models that unpack to 1.5GB from a 250MB file, an ordinary ~6:1 ratio.
|
|
21
|
+
* MAX_COMPRESSION_RATIO catches the real signature; the absolute caps
|
|
22
|
+
* below are now just a generous backstop against a single entry/archive
|
|
23
|
+
* being too large to handle regardless of how honestly it compresses.
|
|
24
|
+
*/
|
|
25
|
+
const MAX_COMPRESSION_RATIO = 100;
|
|
26
|
+
// Ratio math is noisy/meaningless on small entries (a 50-byte file
|
|
27
|
+
// expanding to 5KB is "100:1" but harmless) -- only entries at least this
|
|
28
|
+
// large uncompressed are worth ratio-checking at all.
|
|
29
|
+
const MIN_UNCOMPRESSED_BYTES_FOR_RATIO_CHECK = 10 * 1024 * 1024; // 10MB
|
|
30
|
+
// The same ratio limit applied to the archive as a whole once its declared
|
|
31
|
+
// total passes the threshold, so many entries each just under it can't add up
|
|
32
|
+
// to gigabytes from a few megabytes of file.
|
|
33
|
+
/**
|
|
34
|
+
* The most a project may unpack to by default: above the largest real
|
|
35
|
+
* projects seen (1.5GB), and as much as a browser tab reliably holds while
|
|
36
|
+
* converting (about twice the unpacked size at the peak).
|
|
37
|
+
*/
|
|
38
|
+
export const DEFAULT_MAX_UNPACKED_BYTES = 2 * 1024 * 1024 * 1024;
|
|
39
|
+
/** The most `maxUnpackedBytes` can raise the limit to, for the command line and Node. */
|
|
40
|
+
export const MAX_UNPACKED_BYTES_LIMIT = 16 * 1024 * 1024 * 1024;
|
|
41
|
+
/** Above this, opening a project warns that converting it takes a lot of memory. */
|
|
42
|
+
export const LARGE_PROJECT_BYTES = 1024 * 1024 * 1024;
|
|
43
|
+
const MAX_ENTRY_COUNT = 10_000;
|
|
44
|
+
const MAX_ENTRY_NAME_LENGTH = 1024;
|
|
45
|
+
/**
|
|
46
|
+
* Rejects zip-slip shaped entry names: parent-directory segments, absolute
|
|
47
|
+
* or drive-letter paths, backslashes and NUL. Nothing here writes entries
|
|
48
|
+
* to disk by name, but output filenames for a bundle's nested files come
|
|
49
|
+
* from these names, and a name like that has no legitimate use in a 3MF.
|
|
50
|
+
*/
|
|
51
|
+
export function isSafeEntryName(name) {
|
|
52
|
+
if (name.length === 0 || name.length > MAX_ENTRY_NAME_LENGTH)
|
|
53
|
+
return false;
|
|
54
|
+
if (name.includes("\\") || name.includes("\0"))
|
|
55
|
+
return false;
|
|
56
|
+
if (name.startsWith("/") || /^[A-Za-z]:/.test(name))
|
|
57
|
+
return false;
|
|
58
|
+
return !name.split("/").some((segment) => segment === "..");
|
|
59
|
+
}
|
|
60
|
+
/** "2 GB", "1.5 GB", "512 MB": a size for a message. */
|
|
61
|
+
export function formatSize(bytes) {
|
|
62
|
+
const gb = bytes / 1024 ** 3;
|
|
63
|
+
return gb >= 1 ? `${Number(gb.toFixed(1))} GB` : `${Math.round(bytes / 1024 ** 2)} MB`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Unzips a project in memory, refusing what looks crafted (see above).
|
|
67
|
+
* `maxUnpackedBytes` raises or lowers the size limit; the default suits a
|
|
68
|
+
* browser tab.
|
|
69
|
+
*/
|
|
70
|
+
export function safeUnzipSync(fileBytes, maxUnpackedBytes = DEFAULT_MAX_UNPACKED_BYTES) {
|
|
71
|
+
if (!Number.isSafeInteger(maxUnpackedBytes) || maxUnpackedBytes < 1024 * 1024 || maxUnpackedBytes > MAX_UNPACKED_BYTES_LIMIT) {
|
|
72
|
+
throw new TypeError(`maxUnpackedBytes must be a whole number of bytes from 1 MB to ${formatSize(MAX_UNPACKED_BYTES_LIMIT)}.`);
|
|
73
|
+
}
|
|
74
|
+
// Says what's wrong, not what to do: the CLI, the web app and the docs each give their own way to raise the limit.
|
|
75
|
+
const tooLarge = () => new Any2orcaError("too_large", `This project is too large: it unpacks to more than ${formatSize(maxUnpackedBytes)}, ${maxUnpackedBytes === DEFAULT_MAX_UNPACKED_BYTES ? "the most any2orca converts by default" : "the limit set for this conversion"}.`);
|
|
76
|
+
const unsafe = (message) => new Any2orcaError("invalid_file", message);
|
|
77
|
+
let totalBytes = 0;
|
|
78
|
+
let totalCompressedBytes = 0;
|
|
79
|
+
let entryCount = 0;
|
|
80
|
+
const seenNames = new Set();
|
|
81
|
+
const entries = unzipSync(fileBytes, {
|
|
82
|
+
filter(file) {
|
|
83
|
+
entryCount++;
|
|
84
|
+
// Slicers read the first copy of a repeated name and this reader the last, so the two would see different files.
|
|
85
|
+
if (seenNames.has(file.name)) {
|
|
86
|
+
throw unsafe(`This file can't be opened safely: it contains ${JSON.stringify(file.name.slice(0, 200))} twice, and a slicer would read a different copy than any2orca. Re-save the project in its slicer.`);
|
|
87
|
+
}
|
|
88
|
+
seenNames.add(file.name);
|
|
89
|
+
if (exceedsDeclaredSize(file.size, file.originalSize)) {
|
|
90
|
+
throw unsafe(`This file is damaged: ${JSON.stringify(file.name.slice(0, 200))} holds more data than the file says it does. Download it again, or re-save the project in its slicer.`);
|
|
91
|
+
}
|
|
92
|
+
if (!isSafeEntryName(file.name)) {
|
|
93
|
+
throw unsafe(`This file can't be opened safely: it contains a file named ${JSON.stringify(file.name.slice(0, 200))}, a kind of path a real 3MF never has.`);
|
|
94
|
+
}
|
|
95
|
+
if (entryCount > MAX_ENTRY_COUNT) {
|
|
96
|
+
throw unsafe(`This file holds more than ${MAX_ENTRY_COUNT.toLocaleString("en-US")} files inside it, far more than a real 3MF project, so it isn't opened.`);
|
|
97
|
+
}
|
|
98
|
+
if (file.originalSize > maxUnpackedBytes)
|
|
99
|
+
throw tooLarge();
|
|
100
|
+
if (file.originalSize >= MIN_UNCOMPRESSED_BYTES_FOR_RATIO_CHECK) {
|
|
101
|
+
const ratio = file.size > 0 ? file.originalSize / file.size : Infinity;
|
|
102
|
+
if (ratio > MAX_COMPRESSION_RATIO) {
|
|
103
|
+
throw unsafe(`This file can't be opened safely: part of it (${JSON.stringify(file.name.slice(0, 200))}) expands to more than ${MAX_COMPRESSION_RATIO} times its packed size, which is how a file built to fill up memory (a "zip bomb") looks.`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
totalBytes += file.originalSize;
|
|
107
|
+
totalCompressedBytes += file.size;
|
|
108
|
+
if (totalBytes > maxUnpackedBytes)
|
|
109
|
+
throw tooLarge();
|
|
110
|
+
if (totalBytes >= MIN_UNCOMPRESSED_BYTES_FOR_RATIO_CHECK) {
|
|
111
|
+
const ratio = totalCompressedBytes > 0 ? totalBytes / totalCompressedBytes : Infinity;
|
|
112
|
+
if (ratio > MAX_COMPRESSION_RATIO) {
|
|
113
|
+
throw unsafe(`This file can't be opened safely: it expands to more than ${MAX_COMPRESSION_RATIO} times its packed size, which is how a file built to fill up memory (a "zip bomb") looks.`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
return entries;
|
|
120
|
+
}
|
|
121
|
+
// Deflate never grows data by more than a few bytes per block, so compressed
|
|
122
|
+
// data much larger than its declared size is a stream that inflates far past
|
|
123
|
+
// the size every cap above trusted.
|
|
124
|
+
function exceedsDeclaredSize(compressedBytes, declaredBytes) {
|
|
125
|
+
return compressedBytes > declaredBytes * 1.01 + 1024;
|
|
126
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pattern an `Application` value must match: a slicer's name, a dash and
|
|
3
|
+
* its version, as Snapmaker Orca writes it (`Snapmaker_Orca-2.4.0`). Checked
|
|
4
|
+
* when a catalog is loaded, since the value is written into the file's XML.
|
|
5
|
+
*/
|
|
6
|
+
export declare const APPLICATION_VALUE: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* Rewrites `<metadata name="Application">` in `3D/3dmodel.model` to name the
|
|
9
|
+
* slicer release the converted file's settings come from, copying what that
|
|
10
|
+
* release writes in its own saves. Only the value changes; every other byte of the file stays as it was. A no-op when
|
|
11
|
+
* the file has no Application line.
|
|
12
|
+
*/
|
|
13
|
+
export declare function setApplicationMetadata(topModelText: string, application: string): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The pattern an `Application` value must match: a slicer's name, a dash and
|
|
4
|
+
* its version, as Snapmaker Orca writes it (`Snapmaker_Orca-2.4.0`). Checked
|
|
5
|
+
* when a catalog is loaded, since the value is written into the file's XML.
|
|
6
|
+
*/
|
|
7
|
+
export const APPLICATION_VALUE = /^[A-Za-z][A-Za-z0-9_.+]{0,39}-\d+(\.\d+){1,3}$/;
|
|
8
|
+
/**
|
|
9
|
+
* Rewrites `<metadata name="Application">` in `3D/3dmodel.model` to name the
|
|
10
|
+
* slicer release the converted file's settings come from, copying what that
|
|
11
|
+
* release writes in its own saves. Only the value changes; every other byte of the file stays as it was. A no-op when
|
|
12
|
+
* the file has no Application line.
|
|
13
|
+
*/
|
|
14
|
+
export function setApplicationMetadata(topModelText, application) {
|
|
15
|
+
if (!APPLICATION_VALUE.test(application))
|
|
16
|
+
throw new Error(`Not a slicer name and version: "${application.slice(0, 64)}"`);
|
|
17
|
+
return topModelText.replace(/(<metadata name="Application">)[^<]*(<\/metadata>)/, `$1${application}$2`);
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bambu-only files that have no Orca equivalent and should be dropped
|
|
3
|
+
* rather than carried into the output.
|
|
4
|
+
*
|
|
5
|
+
* `Metadata/filament_sequence.json`: no Orca equivalent.
|
|
6
|
+
* `Metadata/cut_information.xml`: tracks which objects were created with
|
|
7
|
+
* Bambu Studio's Cut tool. Dropping it is a low-risk experiment against a
|
|
8
|
+
* false "too tall to slice" error that cleared when a cut-tracked object
|
|
9
|
+
* was deleted and re-pasted (which would also discard any cut-history
|
|
10
|
+
* tracking).
|
|
11
|
+
*/
|
|
12
|
+
export declare const DROP_FROM_BAMBU: Set<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Same idea as `DROP_FROM_BAMBU`, but for filenames that vary per
|
|
15
|
+
* plate/object. `Metadata/plate_N.json` is Bambu Studio's own cached
|
|
16
|
+
* slice-result data in BAMBU's coordinate frame -- confirmed as the cause
|
|
17
|
+
* of a false "object too tall to slice" error.
|
|
18
|
+
* The `.py`/`.3mf` patterns catch stray files accidentally dragged into a
|
|
19
|
+
* real-world source file (e.g. a working folder zipped up alongside the
|
|
20
|
+
* actual project). `Metadata/{process,machine,filament}_settings_N.config`
|
|
21
|
+
* are the source slicer's embedded custom presets (about a third of real
|
|
22
|
+
* Bambu Studio projects carry them): they describe the source printer, and
|
|
23
|
+
* Snapmaker Orca would import them as presets. The converter writes its own
|
|
24
|
+
* filament presets in their place.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DROP_FROM_BAMBU_PATTERNS: readonly RegExp[];
|
|
27
|
+
/**
|
|
28
|
+
*/
|
|
29
|
+
export declare function shouldDropFromBambu(name: string): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Bambu-only files that have no Orca equivalent and should be dropped
|
|
4
|
+
* rather than carried into the output.
|
|
5
|
+
*
|
|
6
|
+
* `Metadata/filament_sequence.json`: no Orca equivalent.
|
|
7
|
+
* `Metadata/cut_information.xml`: tracks which objects were created with
|
|
8
|
+
* Bambu Studio's Cut tool. Dropping it is a low-risk experiment against a
|
|
9
|
+
* false "too tall to slice" error that cleared when a cut-tracked object
|
|
10
|
+
* was deleted and re-pasted (which would also discard any cut-history
|
|
11
|
+
* tracking).
|
|
12
|
+
*/
|
|
13
|
+
export const DROP_FROM_BAMBU = new Set(["Metadata/filament_sequence.json", "Metadata/cut_information.xml"]);
|
|
14
|
+
/**
|
|
15
|
+
* Same idea as `DROP_FROM_BAMBU`, but for filenames that vary per
|
|
16
|
+
* plate/object. `Metadata/plate_N.json` is Bambu Studio's own cached
|
|
17
|
+
* slice-result data in BAMBU's coordinate frame -- confirmed as the cause
|
|
18
|
+
* of a false "object too tall to slice" error.
|
|
19
|
+
* The `.py`/`.3mf` patterns catch stray files accidentally dragged into a
|
|
20
|
+
* real-world source file (e.g. a working folder zipped up alongside the
|
|
21
|
+
* actual project). `Metadata/{process,machine,filament}_settings_N.config`
|
|
22
|
+
* are the source slicer's embedded custom presets (about a third of real
|
|
23
|
+
* Bambu Studio projects carry them): they describe the source printer, and
|
|
24
|
+
* Snapmaker Orca would import them as presets. The converter writes its own
|
|
25
|
+
* filament presets in their place.
|
|
26
|
+
*/
|
|
27
|
+
export const DROP_FROM_BAMBU_PATTERNS = [
|
|
28
|
+
/^Metadata\/plate_\d+\.json$/,
|
|
29
|
+
/^Metadata\/(?:process|machine|filament)_settings_\d+\.config$/,
|
|
30
|
+
/^Metadata\/.*\.py$/,
|
|
31
|
+
/^Metadata\/.*\.3mf$/,
|
|
32
|
+
];
|
|
33
|
+
/**
|
|
34
|
+
*/
|
|
35
|
+
export function shouldDropFromBambu(name) {
|
|
36
|
+
if (DROP_FROM_BAMBU.has(name))
|
|
37
|
+
return true;
|
|
38
|
+
return DROP_FROM_BAMBU_PATTERNS.some((p) => p.test(name));
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Vec3 } from "./transform.js";
|
|
2
|
+
/** Part files above this size are scanned in chunks instead of being decoded into one string. */
|
|
3
|
+
export declare const LARGE_PART_BYTES: number;
|
|
4
|
+
/**
|
|
5
|
+
* Calls `visit` for every vertex of the first `<object id="objectId" ...>`
|
|
6
|
+
* block in a part file, reading the file's bytes in chunks, without ever
|
|
7
|
+
* holding the file as one string: a single mesh can be larger than the longest
|
|
8
|
+
* string a JavaScript engine can make (about 512 MB in V8), and real projects
|
|
9
|
+
* have meshes that big.
|
|
10
|
+
*
|
|
11
|
+
* Returns true when the block was found and closed. Only then are the visited
|
|
12
|
+
* vertices the ones the whole-file path finds (`parseVertices` on the block
|
|
13
|
+
* from its opening tag to the first `</object>`, the tag included), so a
|
|
14
|
+
* caller must ignore what it was given when this returns false: an object
|
|
15
|
+
* that never closes has no block at all on the whole-file path.
|
|
16
|
+
*
|
|
17
|
+
* @param chunkBytes chunk size, for tests; real callers use the default.
|
|
18
|
+
*/
|
|
19
|
+
export declare function forEachObjectVertex(bytes: Uint8Array, objectId: string, visit: (v: Vec3) => void, chunkBytes?: number): boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** Part files above this size are scanned in chunks instead of being decoded into one string. */
|
|
2
|
+
export const LARGE_PART_BYTES = 64 * 1024 * 1024;
|
|
3
|
+
const CHUNK_BYTES = 8 * 1024 * 1024;
|
|
4
|
+
const VERTEX = /<vertex x="([^"]+)" y="([^"]+)" z="([^"]+)"/g;
|
|
5
|
+
/**
|
|
6
|
+
* Calls `visit` for every vertex of the first `<object id="objectId" ...>`
|
|
7
|
+
* block in a part file, reading the file's bytes in chunks, without ever
|
|
8
|
+
* holding the file as one string: a single mesh can be larger than the longest
|
|
9
|
+
* string a JavaScript engine can make (about 512 MB in V8), and real projects
|
|
10
|
+
* have meshes that big.
|
|
11
|
+
*
|
|
12
|
+
* Returns true when the block was found and closed. Only then are the visited
|
|
13
|
+
* vertices the ones the whole-file path finds (`parseVertices` on the block
|
|
14
|
+
* from its opening tag to the first `</object>`, the tag included), so a
|
|
15
|
+
* caller must ignore what it was given when this returns false: an object
|
|
16
|
+
* that never closes has no block at all on the whole-file path.
|
|
17
|
+
*
|
|
18
|
+
* @param chunkBytes chunk size, for tests; real callers use the default.
|
|
19
|
+
*/
|
|
20
|
+
export function forEachObjectVertex(bytes, objectId, visit, chunkBytes = CHUNK_BYTES) {
|
|
21
|
+
const decoder = new TextDecoder("utf-8");
|
|
22
|
+
const start = `<object id="${objectId}"`;
|
|
23
|
+
let carry = "";
|
|
24
|
+
let inObject = false;
|
|
25
|
+
for (let offset = 0; offset < bytes.length; offset += chunkBytes) {
|
|
26
|
+
const last = offset + chunkBytes >= bytes.length;
|
|
27
|
+
let text = carry + decoder.decode(bytes.subarray(offset, offset + chunkBytes), { stream: !last });
|
|
28
|
+
if (!inObject) {
|
|
29
|
+
const at = text.indexOf(start);
|
|
30
|
+
if (at === -1) {
|
|
31
|
+
// Keep enough of the end to catch a start tag split across chunks.
|
|
32
|
+
carry = text.slice(-start.length);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
// The opening tag must be complete before the object's contents begin.
|
|
36
|
+
const tagEnd = text.indexOf(">", at + start.length);
|
|
37
|
+
if (tagEnd === -1) {
|
|
38
|
+
carry = text.slice(at);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
inObject = true;
|
|
42
|
+
// The whole-file path scans the block from its opening tag, so a vertex written inside the tag counts too.
|
|
43
|
+
for (const m of text.slice(at, tagEnd + 1).matchAll(VERTEX))
|
|
44
|
+
visit([Number(m[1]), Number(m[2]), Number(m[3])]);
|
|
45
|
+
text = text.slice(tagEnd + 1);
|
|
46
|
+
}
|
|
47
|
+
const end = text.indexOf("</object>");
|
|
48
|
+
// Process up to the object's end, or up to the last tag that may be cut off by the chunk boundary.
|
|
49
|
+
const upTo = end !== -1 ? end : last ? text.length : Math.max(0, text.lastIndexOf("<"));
|
|
50
|
+
for (const m of text.slice(0, upTo).matchAll(VERTEX))
|
|
51
|
+
visit([Number(m[1]), Number(m[2]), Number(m[3])]);
|
|
52
|
+
if (end !== -1)
|
|
53
|
+
return true;
|
|
54
|
+
carry = text.slice(upTo);
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Real config files are tens to a few hundred KB; this bounds what a crafted one can cost. */
|
|
2
|
+
export declare const MAX_JSON_TEXT_LENGTH: number;
|
|
3
|
+
/** Real config files nest two or three levels deep. */
|
|
4
|
+
export declare const MAX_JSON_DEPTH = 64;
|
|
5
|
+
export interface TolerantJsonParseResult {
|
|
6
|
+
value: unknown;
|
|
7
|
+
/** Trimmed leftover text after the first parsed JSON value, if any. */
|
|
8
|
+
trailingText: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Parse the leading JSON value out of a string that may have trailing
|
|
12
|
+
* non-JSON content after it (observed in real Bambu Studio
|
|
13
|
+
* `project_settings.config` files: a `cache_hash = <hex>` line after the
|
|
14
|
+
* closing brace). `JSON.parse` throws hard on any trailing content, so
|
|
15
|
+
* this scans for the end of the first top-level value by hand instead.
|
|
16
|
+
*
|
|
17
|
+
* This does NOT skip leading whitespace before the value -- real config files
|
|
18
|
+
* always start with `{` at position 0.
|
|
19
|
+
*/
|
|
20
|
+
export declare function tolerantJsonParse(text: string): TolerantJsonParseResult;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/** Real config files are tens to a few hundred KB; this bounds what a crafted one can cost. */
|
|
3
|
+
export const MAX_JSON_TEXT_LENGTH = 16 * 1024 * 1024;
|
|
4
|
+
/** Real config files nest two or three levels deep. */
|
|
5
|
+
export const MAX_JSON_DEPTH = 64;
|
|
6
|
+
/**
|
|
7
|
+
* Parse the leading JSON value out of a string that may have trailing
|
|
8
|
+
* non-JSON content after it (observed in real Bambu Studio
|
|
9
|
+
* `project_settings.config` files: a `cache_hash = <hex>` line after the
|
|
10
|
+
* closing brace). `JSON.parse` throws hard on any trailing content, so
|
|
11
|
+
* this scans for the end of the first top-level value by hand instead.
|
|
12
|
+
*
|
|
13
|
+
* This does NOT skip leading whitespace before the value -- real config files
|
|
14
|
+
* always start with `{` at position 0.
|
|
15
|
+
*/
|
|
16
|
+
export function tolerantJsonParse(text) {
|
|
17
|
+
const end = findFirstJsonValueEnd(text);
|
|
18
|
+
const value = JSON.parse(text.slice(0, end));
|
|
19
|
+
const trailingText = text.slice(end).trim();
|
|
20
|
+
return { value, trailingText };
|
|
21
|
+
}
|
|
22
|
+
/** Scan for the index right after the first complete top-level JSON value, respecting string/escape state. */
|
|
23
|
+
function findFirstJsonValueEnd(text) {
|
|
24
|
+
const n = text.length;
|
|
25
|
+
if (n === 0)
|
|
26
|
+
throw new SyntaxError("Unexpected end of JSON input");
|
|
27
|
+
if (n > MAX_JSON_TEXT_LENGTH)
|
|
28
|
+
throw new SyntaxError(`JSON text is longer than the ${MAX_JSON_TEXT_LENGTH} character limit`);
|
|
29
|
+
const first = text[0];
|
|
30
|
+
if (first !== "{" && first !== "[") {
|
|
31
|
+
// Bare scalar (string/number/literal) -- rare for real config files
|
|
32
|
+
// (always objects), handled for completeness.
|
|
33
|
+
const m = /^(true|false|null|-?\d+(\.\d+)?([eE][+-]?\d+)?|"(?:[^"\\]|\\.)*")/.exec(text);
|
|
34
|
+
if (!m)
|
|
35
|
+
throw new SyntaxError("Expecting value");
|
|
36
|
+
return m[0].length;
|
|
37
|
+
}
|
|
38
|
+
let depth = 0;
|
|
39
|
+
let inString = false;
|
|
40
|
+
let escaped = false;
|
|
41
|
+
for (let i = 0; i < n; i++) {
|
|
42
|
+
const ch = text[i];
|
|
43
|
+
if (inString) {
|
|
44
|
+
if (escaped) {
|
|
45
|
+
escaped = false;
|
|
46
|
+
}
|
|
47
|
+
else if (ch === "\\") {
|
|
48
|
+
escaped = true;
|
|
49
|
+
}
|
|
50
|
+
else if (ch === '"') {
|
|
51
|
+
inString = false;
|
|
52
|
+
}
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (ch === '"') {
|
|
56
|
+
inString = true;
|
|
57
|
+
}
|
|
58
|
+
else if (ch === "{" || ch === "[") {
|
|
59
|
+
depth++;
|
|
60
|
+
if (depth > MAX_JSON_DEPTH)
|
|
61
|
+
throw new SyntaxError(`JSON nests deeper than the ${MAX_JSON_DEPTH} level limit`);
|
|
62
|
+
}
|
|
63
|
+
else if (ch === "}" || ch === "]") {
|
|
64
|
+
depth--;
|
|
65
|
+
if (depth === 0) {
|
|
66
|
+
return i + 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new SyntaxError("Unexpected end of JSON input");
|
|
71
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type Vec3 = [number, number, number];
|
|
2
|
+
export type Mat3 = [Vec3, Vec3, Vec3];
|
|
3
|
+
/**
|
|
4
|
+
* Parse a 3MF transform string: 12 space-separated numbers -- row-major
|
|
5
|
+
* 3x3 rotation/scale matrix (rows 0-2) then a translation (last 3).
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseMatrix(transformStr: string): [Mat3, Vec3];
|
|
9
|
+
/**
|
|
10
|
+
* Apply an (R, T) affine transform to a 3-vector using Bambu's row-major
|
|
11
|
+
* convention: `v * R + T`, not `R * v`.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyTransform(v: Vec3, R: Mat3, T: Vec3): Vec3;
|
|
15
|
+
/**
|
|
16
|
+
* Combine two transforms so `result(v) = transform1(transform2(v))` --
|
|
17
|
+
* i.e. combine an item's plate-placement transform with a sub-component's
|
|
18
|
+
* own transform.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export declare function compose(R1: Mat3, T1: Vec3, R2: Mat3, T2: Vec3): [Mat3, Vec3];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a 3MF transform string: 12 space-separated numbers -- row-major
|
|
3
|
+
* 3x3 rotation/scale matrix (rows 0-2) then a translation (last 3).
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export function parseMatrix(transformStr) {
|
|
7
|
+
const t = transformStr.split(/\s+/).filter(Boolean).map(Number);
|
|
8
|
+
const R = [
|
|
9
|
+
[t[0], t[1], t[2]],
|
|
10
|
+
[t[3], t[4], t[5]],
|
|
11
|
+
[t[6], t[7], t[8]],
|
|
12
|
+
];
|
|
13
|
+
const T = [t[9], t[10], t[11]];
|
|
14
|
+
return [R, T];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Apply an (R, T) affine transform to a 3-vector using Bambu's row-major
|
|
18
|
+
* convention: `v * R + T`, not `R * v`.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
export function applyTransform(v, R, T) {
|
|
22
|
+
const [x, y, z] = v;
|
|
23
|
+
return [
|
|
24
|
+
R[0][0] * x + R[1][0] * y + R[2][0] * z + T[0],
|
|
25
|
+
R[0][1] * x + R[1][1] * y + R[2][1] * z + T[1],
|
|
26
|
+
R[0][2] * x + R[1][2] * y + R[2][2] * z + T[2],
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Combine two transforms so `result(v) = transform1(transform2(v))` --
|
|
31
|
+
* i.e. combine an item's plate-placement transform with a sub-component's
|
|
32
|
+
* own transform.
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
35
|
+
export function compose(R1, T1, R2, T2) {
|
|
36
|
+
const R = [0, 1, 2].map((i) => [0, 1, 2].map((j) => [0, 1, 2].reduce((sum, k) => sum + R2[i][k] * R1[k][j], 0)));
|
|
37
|
+
const T = applyTransform(T2, R1, T1);
|
|
38
|
+
return [R, T];
|
|
39
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface BundleEntry {
|
|
2
|
+
/** Display/output filename -- the entry's own basename, directory prefixes stripped. */
|
|
3
|
+
name: string;
|
|
4
|
+
bytes: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Detects whether raw file bytes are a single 3MF (returns `null` --
|
|
8
|
+
* caller should treat the bytes as-is, unchanged) or a zip bundling
|
|
9
|
+
* several 3MFs as sibling entries (returns each nested .3mf's own raw
|
|
10
|
+
* bytes) -- e.g. a "download all variants" zip some creator marketplaces
|
|
11
|
+
* already produce (AMS.3mf + SPLIT.3mf inside one bundle.zip, handed over
|
|
12
|
+
* by a partner site or just dropped in by hand).
|
|
13
|
+
*
|
|
14
|
+
* A single 3MF is itself a zip archive with Metadata/project_settings.config
|
|
15
|
+
* at its root -- that presence is exactly what distinguishes the two
|
|
16
|
+
* shapes, since a bundle zip has no project_settings.config of its own,
|
|
17
|
+
* only nested .3mf entries that each have theirs.
|
|
18
|
+
*
|
|
19
|
+
* @returns nested entries if this is a bundle, `null` if it's a plain
|
|
20
|
+
* 3MF (including "not a zip at all" and "a zip with no .3mf entries" --
|
|
21
|
+
* both cases are left for `prepareConvertRequest` to raise its own
|
|
22
|
+
* clear error on, rather than this function guessing).
|
|
23
|
+
*/
|
|
24
|
+
export declare function unwrapIfBundle(fileBytes: Uint8Array, maxUnpackedBytes?: number): BundleEntry[] | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
import { PROJECT_SETTINGS_PATH } from "./paths.js";
|
|
3
|
+
import { safeUnzipSync } from "./safeUnzip.js";
|
|
4
|
+
/**
|
|
5
|
+
* Detects whether raw file bytes are a single 3MF (returns `null` --
|
|
6
|
+
* caller should treat the bytes as-is, unchanged) or a zip bundling
|
|
7
|
+
* several 3MFs as sibling entries (returns each nested .3mf's own raw
|
|
8
|
+
* bytes) -- e.g. a "download all variants" zip some creator marketplaces
|
|
9
|
+
* already produce (AMS.3mf + SPLIT.3mf inside one bundle.zip, handed over
|
|
10
|
+
* by a partner site or just dropped in by hand).
|
|
11
|
+
*
|
|
12
|
+
* A single 3MF is itself a zip archive with Metadata/project_settings.config
|
|
13
|
+
* at its root -- that presence is exactly what distinguishes the two
|
|
14
|
+
* shapes, since a bundle zip has no project_settings.config of its own,
|
|
15
|
+
* only nested .3mf entries that each have theirs.
|
|
16
|
+
*
|
|
17
|
+
* @returns nested entries if this is a bundle, `null` if it's a plain
|
|
18
|
+
* 3MF (including "not a zip at all" and "a zip with no .3mf entries" --
|
|
19
|
+
* both cases are left for `prepareConvertRequest` to raise its own
|
|
20
|
+
* clear error on, rather than this function guessing).
|
|
21
|
+
*/
|
|
22
|
+
export function unwrapIfBundle(fileBytes, maxUnpackedBytes) {
|
|
23
|
+
let entries;
|
|
24
|
+
try {
|
|
25
|
+
entries = safeUnzipSync(fileBytes, maxUnpackedBytes);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// Corrupt/non-zip bytes, or a decompression-bomb-shaped entry rejected
|
|
29
|
+
// by safeUnzipSync -- either way, fall through and let
|
|
30
|
+
// prepareConvertRequest's own safeUnzipSync call raise the real,
|
|
31
|
+
// specific error against these same bytes treated as a plain 3MF.
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (Object.hasOwn(entries, PROJECT_SETTINGS_PATH)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const nested = Object.entries(entries).filter(([name]) => name.toLowerCase().endsWith(".3mf"));
|
|
38
|
+
if (nested.length === 0)
|
|
39
|
+
return null;
|
|
40
|
+
return nested.map(([path, bytes]) => ({ name: path.split("/").pop() || path, bytes }));
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every `<tag ...>body</tag>` block in `text`, in order, with the same
|
|
3
|
+
* matches as `/<tag(\s[^>]*?)?>([\s\S]*?)<\/tag>/g`, found in linear time.
|
|
4
|
+
* A lazy pattern like that one rescans the rest of the text for each opener
|
|
5
|
+
* that has no closing tag, which a crafted file can turn into minutes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function xmlBlocks(text: string, tag: string): Generator<{
|
|
8
|
+
attrs: string;
|
|
9
|
+
body: string;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Every `<tag ...>body</tag>` block in `text`, in order, with the same
|
|
4
|
+
* matches as `/<tag(\s[^>]*?)?>([\s\S]*?)<\/tag>/g`, found in linear time.
|
|
5
|
+
* A lazy pattern like that one rescans the rest of the text for each opener
|
|
6
|
+
* that has no closing tag, which a crafted file can turn into minutes.
|
|
7
|
+
*/
|
|
8
|
+
export function* xmlBlocks(text, tag) {
|
|
9
|
+
const open = `<${tag}`;
|
|
10
|
+
const close = `</${tag}>`;
|
|
11
|
+
let from = 0;
|
|
12
|
+
for (;;) {
|
|
13
|
+
const start = text.indexOf(open, from);
|
|
14
|
+
if (start === -1)
|
|
15
|
+
return;
|
|
16
|
+
const next = text[start + open.length];
|
|
17
|
+
if (next !== ">" && next !== " " && next !== "\t" && next !== "\n" && next !== "\r") {
|
|
18
|
+
from = start + open.length;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const openerEnd = text.indexOf(">", start + open.length);
|
|
22
|
+
if (openerEnd === -1)
|
|
23
|
+
return;
|
|
24
|
+
const end = text.indexOf(close, openerEnd + 1);
|
|
25
|
+
// No closing tag after this opener means none after any later one either.
|
|
26
|
+
if (end === -1)
|
|
27
|
+
return;
|
|
28
|
+
yield { attrs: text.slice(start + open.length, openerEnd).trim(), body: text.slice(openerEnd + 1, end) };
|
|
29
|
+
from = end + close.length;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ConvertRequest, type ConvertResponse } from "../schema.js";
|
|
2
|
+
export interface ParsedBambuProject {
|
|
3
|
+
/** The full decompressed source zip, kept for applyConvertResponse's final reassembly. */
|
|
4
|
+
zipEntries: Record<string, Uint8Array>;
|
|
5
|
+
/** The conversion request payload. */
|
|
6
|
+
request: ConvertRequest;
|
|
7
|
+
/** Non-fatal notes collected while parsing (e.g. tolerantJsonParse's trailing-content note), for surfacing in the UI. */
|
|
8
|
+
warnings: string[];
|
|
9
|
+
/** The project's unpacked size, every entry together. */
|
|
10
|
+
unpackedBytes: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Unzip a source .3mf (already in memory as bytes) and build the conversion request payload: the
|
|
14
|
+
* full project_settings.config JSON, plus each top-level object's
|
|
15
|
+
* world-space bounding box (or its raw transform translation as a
|
|
16
|
+
* fallback when mesh geometry is missing), its plate assignment, and its name.
|
|
17
|
+
*/
|
|
18
|
+
export declare function prepareConvertRequest(fileBytes: Uint8Array, maxUnpackedBytes?: number): ParsedBambuProject;
|
|
19
|
+
/**
|
|
20
|
+
* Apply a conversion response to the originally parsed project and
|
|
21
|
+
* produce the final Snapmaker Orca .3mf bytes, ready to offer as a
|
|
22
|
+
* download. Copies every untouched zip entry verbatim (dropping
|
|
23
|
+
* Bambu-only files per shouldDropFromBambu), sets the Application line (or, when
|
|
24
|
+
* the catalog names none, adds the OrcaSlicer origin tag), recenters the build/assemble transforms using the
|
|
25
|
+
* response's shift map, adapts model_settings.config, and writes the
|
|
26
|
+
* response's merged project_settings.config plus every generated/
|
|
27
|
+
* passthrough config file. `extraEntries` are added last (the output stamp).
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyConvertResponse(parsed: ParsedBambuProject, response: ConvertResponse, extraEntries?: Record<string, Uint8Array>): Uint8Array;
|