any2orca 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +99 -2
- package/dist/archive/adaptModelSettings.d.ts +1 -0
- package/dist/archive/adaptModelSettings.js +50 -0
- package/dist/archive/filamentColorNames.d.ts +8 -0
- package/dist/archive/filamentColorNames.js +760 -0
- package/dist/archive/fmtNum.d.ts +14 -0
- package/dist/archive/fmtNum.js +21 -0
- package/dist/archive/internal/escapeRegExp.d.ts +2 -0
- package/dist/archive/internal/escapeRegExp.js +5 -0
- package/dist/archive/lookupFilamentColorName.d.ts +45 -0
- package/dist/archive/lookupFilamentColorName.js +57 -0
- package/dist/archive/objectWorldBboxXY.d.ts +2 -0
- package/dist/archive/objectWorldBboxXY.js +123 -0
- package/dist/archive/parseItemPositions.d.ts +6 -0
- package/dist/archive/parseItemPositions.js +17 -0
- package/dist/archive/parseObjectMetadata.d.ts +10 -0
- package/dist/archive/parseObjectMetadata.js +97 -0
- package/dist/archive/parsePlateAssignments.d.ts +6 -0
- package/dist/archive/parsePlateAssignments.js +18 -0
- package/dist/archive/parseVertices.d.ts +7 -0
- package/dist/archive/parseVertices.js +12 -0
- package/dist/archive/paths.d.ts +5 -0
- package/dist/archive/paths.js +6 -0
- package/dist/archive/recenterAssembleItems.d.ts +9 -0
- package/dist/archive/recenterAssembleItems.js +53 -0
- package/dist/archive/recenterBuildItems.d.ts +15 -0
- package/dist/archive/recenterBuildItems.js +51 -0
- package/dist/archive/safeUnzip.d.ts +26 -0
- package/dist/archive/safeUnzip.js +126 -0
- package/dist/archive/setApplicationMetadata.d.ts +13 -0
- package/dist/archive/setApplicationMetadata.js +18 -0
- package/dist/archive/shouldDropFromBambu.d.ts +29 -0
- package/dist/archive/shouldDropFromBambu.js +39 -0
- package/dist/archive/streamObjectVertices.d.ts +19 -0
- package/dist/archive/streamObjectVertices.js +57 -0
- package/dist/archive/tolerantJsonParse.d.ts +20 -0
- package/dist/archive/tolerantJsonParse.js +71 -0
- package/dist/archive/transform.d.ts +21 -0
- package/dist/archive/transform.js +39 -0
- package/dist/archive/unwrapBundle.d.ts +24 -0
- package/dist/archive/unwrapBundle.js +41 -0
- package/dist/archive/xmlBlocks.d.ts +10 -0
- package/dist/archive/xmlBlocks.js +31 -0
- package/dist/archive/zip.d.ts +29 -0
- package/dist/archive/zip.js +141 -0
- package/dist/cli/archiveMove.d.ts +15 -0
- package/dist/cli/archiveMove.js +41 -0
- package/dist/cli/commands/convert.d.ts +89 -0
- package/dist/cli/commands/convert.js +311 -0
- package/dist/cli/commands/diff.d.ts +21 -0
- package/dist/cli/commands/diff.js +112 -0
- package/dist/cli/commands/presets.d.ts +51 -0
- package/dist/cli/commands/presets.js +280 -0
- package/dist/cli/commands/profiles.d.ts +5 -0
- package/dist/cli/commands/profiles.js +26 -0
- package/dist/cli/commands/telemetry.d.ts +6 -0
- package/dist/cli/commands/telemetry.js +45 -0
- package/dist/cli/config.d.ts +18 -0
- package/dist/cli/config.js +50 -0
- package/dist/cli/expandWildcards.d.ts +17 -0
- package/dist/cli/expandWildcards.js +81 -0
- package/dist/cli/logger.d.ts +17 -0
- package/dist/cli/logger.js +36 -0
- package/dist/cli/main.d.ts +24 -0
- package/dist/cli/main.js +598 -0
- package/dist/cli/sameFile.d.ts +9 -0
- package/dist/cli/sameFile.js +40 -0
- package/dist/cli/stats.d.ts +34 -0
- package/dist/cli/stats.js +137 -0
- package/dist/cli/table.d.ts +8 -0
- package/dist/cli/table.js +18 -0
- package/dist/cli/terminalText.d.ts +7 -0
- package/dist/cli/terminalText.js +22 -0
- package/dist/cli/updateCheck.d.ts +14 -0
- package/dist/cli/updateCheck.js +78 -0
- package/dist/cli/watchState.d.ts +18 -0
- package/dist/cli/watchState.js +33 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +10 -0
- package/dist/diff/diffSettings.d.ts +81 -0
- package/dist/diff/diffSettings.js +259 -0
- package/dist/diff/reference.d.ts +14 -0
- package/dist/diff/reference.js +22 -0
- package/dist/diff/settingsCatalog.d.ts +28 -0
- package/dist/diff/settingsCatalog.js +605 -0
- package/dist/diff/valueLayout.d.ts +20 -0
- package/dist/diff/valueLayout.js +65 -0
- package/dist/engine/aboveStock.d.ts +20 -0
- package/dist/engine/aboveStock.js +89 -0
- package/dist/engine/applyFilamentComplianceMode.d.ts +40 -0
- package/dist/engine/applyFilamentComplianceMode.js +68 -0
- package/dist/engine/applyFilamentFlowVariants.d.ts +42 -0
- package/dist/engine/applyFilamentFlowVariants.js +109 -0
- package/dist/engine/applyHighFlowHotends.d.ts +52 -0
- package/dist/engine/applyHighFlowHotends.js +115 -0
- package/dist/engine/applyPresetChanges.d.ts +12 -0
- package/dist/engine/applyPresetChanges.js +23 -0
- package/dist/engine/bedCenter.d.ts +19 -0
- package/dist/engine/bedCenter.js +34 -0
- package/dist/engine/buildFilamentConfigs.d.ts +18 -0
- package/dist/engine/buildFilamentConfigs.js +49 -0
- package/dist/engine/buildProjectSettings.d.ts +24 -0
- package/dist/engine/buildProjectSettings.js +164 -0
- package/dist/engine/carrySourceLayerHeight.d.ts +15 -0
- package/dist/engine/carrySourceLayerHeight.js +41 -0
- package/dist/engine/clampColorPenetration.d.ts +12 -0
- package/dist/engine/clampColorPenetration.js +28 -0
- package/dist/engine/clampToMachineLimits.d.ts +21 -0
- package/dist/engine/clampToMachineLimits.js +84 -0
- package/dist/engine/coerceValue.d.ts +15 -0
- package/dist/engine/coerceValue.js +56 -0
- package/dist/engine/collapseNozzleVariants.d.ts +31 -0
- package/dist/engine/collapseNozzleVariants.js +63 -0
- package/dist/engine/computeShifts.d.ts +12 -0
- package/dist/engine/computeShifts.js +339 -0
- package/dist/engine/constants.d.ts +11 -0
- package/dist/engine/constants.js +12 -0
- package/dist/engine/detectNozzleDiameter.d.ts +15 -0
- package/dist/engine/detectNozzleDiameter.js +29 -0
- package/dist/engine/detectVariantIndex.d.ts +39 -0
- package/dist/engine/detectVariantIndex.js +80 -0
- package/dist/engine/extractFilamentSlots.d.ts +18 -0
- package/dist/engine/extractFilamentSlots.js +88 -0
- package/dist/engine/filamentComplianceNames.d.ts +84 -0
- package/dist/engine/filamentComplianceNames.js +87 -0
- package/dist/engine/filamentVariantLayout.d.ts +29 -0
- package/dist/engine/filamentVariantLayout.js +38 -0
- package/dist/engine/fillFilamentSlots.d.ts +16 -0
- package/dist/engine/fillFilamentSlots.js +26 -0
- package/dist/engine/internal/jsonEqual.d.ts +2 -0
- package/dist/engine/internal/jsonEqual.js +5 -0
- package/dist/engine/parseTierName.d.ts +15 -0
- package/dist/engine/parseTierName.js +21 -0
- package/dist/engine/pickNearestProfile.d.ts +21 -0
- package/dist/engine/pickNearestProfile.js +24 -0
- package/dist/engine/pickProfile.d.ts +49 -0
- package/dist/engine/pickProfile.js +67 -0
- package/dist/engine/policy.d.ts +14 -0
- package/dist/engine/policy.js +266 -0
- package/dist/engine/remapBrimType.d.ts +30 -0
- package/dist/engine/remapBrimType.js +34 -0
- package/dist/engine/reshapeToCount.d.ts +15 -0
- package/dist/engine/reshapeToCount.js +27 -0
- package/dist/engine/resizeFlushVolumes.d.ts +27 -0
- package/dist/engine/resizeFlushVolumes.js +57 -0
- package/dist/engine/resolveMinIfLower.d.ts +21 -0
- package/dist/engine/resolveMinIfLower.js +59 -0
- package/dist/engine/runConvertPipeline.d.ts +79 -0
- package/dist/engine/runConvertPipeline.js +281 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.d.ts +2 -0
- package/dist/engine/stripBambuOnlyNozzleVariantKeys.js +35 -0
- package/dist/engine/types.d.ts +2 -0
- package/dist/engine/types.js +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +9 -0
- package/dist/explain/whatChanged.d.ts +102 -0
- package/dist/explain/whatChanged.js +197 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +33 -0
- package/dist/inspect.d.ts +63 -0
- package/dist/inspect.js +103 -0
- package/dist/node.d.ts +11 -0
- package/dist/node.js +50 -0
- package/dist/plainText.d.ts +10 -0
- package/dist/plainText.js +14 -0
- package/dist/presets/extractPreset.d.ts +13 -0
- package/dist/presets/extractPreset.js +87 -0
- package/dist/presets/preset.d.ts +124 -0
- package/dist/presets/preset.js +289 -0
- package/dist/presets/presetKeys.d.ts +5 -0
- package/dist/presets/presetKeys.js +42 -0
- package/dist/profiles.d.ts +184 -0
- package/dist/profiles.js +314 -0
- package/dist/project.d.ts +146 -0
- package/dist/project.js +342 -0
- package/dist/schema.d.ts +103 -0
- package/dist/schema.js +87 -0
- package/dist/stamp.d.ts +45 -0
- package/dist/stamp.js +111 -0
- package/dist/telemetry.d.ts +101 -0
- package/dist/telemetry.js +94 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/dist/worker-entry.d.ts +1 -0
- package/dist/worker-entry.js +142 -0
- package/dist/worker.d.ts +86 -0
- package/dist/worker.js +97 -0
- package/dist/workerProtocol.d.ts +91 -0
- package/dist/workerProtocol.js +1 -0
- package/package.json +85 -4
package/dist/stamp.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The output stamp: one small JSON file added to every converted 3MF, so a
|
|
4
|
+
* file can always be traced to the release that made it ("was this made
|
|
5
|
+
* before the fix?"). It holds versions and the options used, nothing else:
|
|
6
|
+
* no file names, paths, timestamps or identifiers. It sits in its own zip
|
|
7
|
+
* entry, so no slicer-read file and no mesh data changes because of it.
|
|
8
|
+
*
|
|
9
|
+
* The path and the `stamp: 1` shape are a public contract once files
|
|
10
|
+
* exist in the wild. Add fields if needed; never rename or remove one
|
|
11
|
+
* without bumping `stamp`.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import { HighFlowHotendsSchema } from "./schema.js";
|
|
15
|
+
export const STAMP_PATH = "Metadata/any2orca.json";
|
|
16
|
+
const AboveStockStampSchema = z
|
|
17
|
+
.object({
|
|
18
|
+
keep: z.array(z.string().max(100)).max(100),
|
|
19
|
+
stock: z.array(z.string().max(100)).max(100),
|
|
20
|
+
})
|
|
21
|
+
.strict();
|
|
22
|
+
const PresetStampSchema = z
|
|
23
|
+
.object({
|
|
24
|
+
base: z.string().max(64),
|
|
25
|
+
keys: z.array(z.string().max(100)).max(400),
|
|
26
|
+
sha256: z.string().regex(/^[0-9a-f]{64}$/),
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
/** What this version writes: exactly these fields. */
|
|
30
|
+
export const OutputStampSchema = z
|
|
31
|
+
.object({
|
|
32
|
+
stamp: z.literal(1),
|
|
33
|
+
generator: z.literal("any2orca"),
|
|
34
|
+
/** The `any2orca` package version that converted the file. */
|
|
35
|
+
version: z.string(),
|
|
36
|
+
profiles: z
|
|
37
|
+
.object({
|
|
38
|
+
/** The profile catalog's version (`any2orca-profiles` for the bundled one). */
|
|
39
|
+
version: z.string(),
|
|
40
|
+
/** The upstream slicer release the catalog tracks, e.g. "Snapmaker Orca 2.4.0". */
|
|
41
|
+
tracks: z.string(),
|
|
42
|
+
})
|
|
43
|
+
.strict(),
|
|
44
|
+
profileId: z.string(),
|
|
45
|
+
options: z
|
|
46
|
+
.object({
|
|
47
|
+
highFlowHotends: HighFlowHotendsSchema,
|
|
48
|
+
hardenedNozzles: z.boolean(),
|
|
49
|
+
filamentComplianceMode: z.enum(["generic", "snapmaker"]).nullable(),
|
|
50
|
+
/** Present when the file was converted with a preset: its base, the settings it set, and a fingerprint of their values. Never its name. */
|
|
51
|
+
preset: PresetStampSchema.optional(),
|
|
52
|
+
/** Present when the user chose differently for values above stock: settings kept at the creator's value, and set to stock. */
|
|
53
|
+
aboveStock: AboveStockStampSchema.optional(),
|
|
54
|
+
})
|
|
55
|
+
.strict(),
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
/**
|
|
59
|
+
* Text from a note in someone's file: one line, no control characters or
|
|
60
|
+
* direction overrides, so a program that prints it can't be tricked into
|
|
61
|
+
* sending terminal codes or showing text that reads differently.
|
|
62
|
+
*/
|
|
63
|
+
const noteText = (max) => z.string().max(max).regex(/^[^\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]*$/);
|
|
64
|
+
/** What any version accepts when reading: a later release may add fields. */
|
|
65
|
+
const StampReadSchema = z.object({
|
|
66
|
+
stamp: z.literal(1),
|
|
67
|
+
generator: z.literal("any2orca"),
|
|
68
|
+
version: noteText(64),
|
|
69
|
+
profiles: z.object({ version: noteText(64), tracks: noteText(200) }),
|
|
70
|
+
profileId: noteText(64),
|
|
71
|
+
options: z.object({
|
|
72
|
+
highFlowHotends: HighFlowHotendsSchema,
|
|
73
|
+
// Added after the first stamps were written; absent means the stock stainless nozzles.
|
|
74
|
+
hardenedNozzles: z.boolean().default(false),
|
|
75
|
+
filamentComplianceMode: z.enum(["generic", "snapmaker"]).nullable(),
|
|
76
|
+
// Added with presets; absent means no preset.
|
|
77
|
+
preset: z.object({ base: noteText(64), keys: z.array(noteText(100)).max(400), sha256: noteText(64) }).optional(),
|
|
78
|
+
aboveStock: z.object({ keep: z.array(noteText(100)).max(100), stock: z.array(noteText(100)).max(100) }).optional(),
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
export function encodeStamp(stamp) {
|
|
82
|
+
return new TextEncoder().encode(`${JSON.stringify(OutputStampSchema.parse(stamp), null, 2)}\n`);
|
|
83
|
+
}
|
|
84
|
+
/** Reads the stamp from a converted file's zip entries, or null if it has none (or an unreadable one). */
|
|
85
|
+
export function decodeStamp(bytes) {
|
|
86
|
+
if (!bytes || bytes.byteLength > 64 * 1024)
|
|
87
|
+
return null;
|
|
88
|
+
try {
|
|
89
|
+
const parsed = StampReadSchema.safeParse(JSON.parse(new TextDecoder().decode(bytes)));
|
|
90
|
+
if (!parsed.success)
|
|
91
|
+
return null;
|
|
92
|
+
const { stamp, generator, version, profiles, profileId, options } = parsed.data;
|
|
93
|
+
return {
|
|
94
|
+
stamp,
|
|
95
|
+
generator,
|
|
96
|
+
version,
|
|
97
|
+
profiles: { version: profiles.version, tracks: profiles.tracks },
|
|
98
|
+
profileId,
|
|
99
|
+
options: {
|
|
100
|
+
highFlowHotends: options.highFlowHotends,
|
|
101
|
+
hardenedNozzles: options.hardenedNozzles,
|
|
102
|
+
filamentComplianceMode: options.filamentComplianceMode,
|
|
103
|
+
...(options.preset ? { preset: { base: options.preset.base, keys: [...options.preset.keys], sha256: options.preset.sha256 } } : {}),
|
|
104
|
+
...(options.aboveStock ? { aboveStock: { keep: [...options.aboveStock.keep], stock: [...options.aboveStock.stock] } } : {}),
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage stats: the one event, how it's built, and whether it may be sent.
|
|
3
|
+
*
|
|
4
|
+
* The library never sends anything itself; it has no network code at all.
|
|
5
|
+
* A UI or the CLI calls {@link buildStatsEvent} after a successful
|
|
6
|
+
* conversion and decides with {@link resolveStatsConsent} whether to send
|
|
7
|
+
* it, and to where. Off by default everywhere except a deployment whose
|
|
8
|
+
* operator turns it on and discloses it.
|
|
9
|
+
*
|
|
10
|
+
* {@link StatsEventSchema} is strict: the sender, the "see exactly what's
|
|
11
|
+
* sent" display and the docs all come from it, and a payload with any
|
|
12
|
+
* other field fails to parse, so the explanation can't drift from what's
|
|
13
|
+
* actually sent.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from "zod";
|
|
16
|
+
import type { SourceVendor } from "./inspect.js";
|
|
17
|
+
import type { ProfileMatch } from "./schema.js";
|
|
18
|
+
export declare const REF_PATTERN: RegExp;
|
|
19
|
+
export declare const StatsEventSchema: z.ZodObject<{
|
|
20
|
+
v: z.ZodLiteral<1>;
|
|
21
|
+
core: z.ZodString;
|
|
22
|
+
profileId: z.ZodString;
|
|
23
|
+
matchSource: z.ZodEnum<{
|
|
24
|
+
"auto-tier-name": "auto-tier-name";
|
|
25
|
+
"auto-exact": "auto-exact";
|
|
26
|
+
"auto-nearest": "auto-nearest";
|
|
27
|
+
"default-fallback": "default-fallback";
|
|
28
|
+
explicit: "explicit";
|
|
29
|
+
}>;
|
|
30
|
+
plates: z.ZodNumber;
|
|
31
|
+
objects: z.ZodNumber;
|
|
32
|
+
filamentSlots: z.ZodNumber;
|
|
33
|
+
sourceVendor: z.ZodEnum<{
|
|
34
|
+
snapmaker: "snapmaker";
|
|
35
|
+
flashforge: "flashforge";
|
|
36
|
+
other: "other";
|
|
37
|
+
bambu: "bambu";
|
|
38
|
+
creality: "creality";
|
|
39
|
+
anycubic: "anycubic";
|
|
40
|
+
elegoo: "elegoo";
|
|
41
|
+
prusa: "prusa";
|
|
42
|
+
}>;
|
|
43
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
44
|
+
day: z.ZodString;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
export type StatsEvent = z.infer<typeof StatsEventSchema>;
|
|
47
|
+
/** What is never sent, for the "see exactly what's sent" display. */
|
|
48
|
+
export declare const NEVER_SENT: readonly string[];
|
|
49
|
+
export interface StatsEventInput {
|
|
50
|
+
profileId: string;
|
|
51
|
+
/** Omitted when the profile was chosen explicitly. */
|
|
52
|
+
profileMatch?: Pick<ProfileMatch, "matchSource">;
|
|
53
|
+
plates: number;
|
|
54
|
+
objects: number;
|
|
55
|
+
filamentSlots: number;
|
|
56
|
+
sourceVendor: SourceVendor;
|
|
57
|
+
/** A `?ref=` value. Dropped if it isn't a short slug. */
|
|
58
|
+
ref?: string | null;
|
|
59
|
+
/** Defaults to now. */
|
|
60
|
+
date?: Date;
|
|
61
|
+
}
|
|
62
|
+
/** Builds the event from a conversion report. Throws if a field is out of range. */
|
|
63
|
+
export declare function buildStatsEvent(input: StatsEventInput): StatsEvent;
|
|
64
|
+
/**
|
|
65
|
+
* The stored choice. `choice: null` means the user hasn't chosen, so the
|
|
66
|
+
* deployment's default applies. `gpcAtChoice` records whether the browser
|
|
67
|
+
* sent Global Privacy Control when the choice was made.
|
|
68
|
+
*/
|
|
69
|
+
export interface StatsConsentState {
|
|
70
|
+
choice: "on" | "off" | null;
|
|
71
|
+
gpcAtChoice: boolean;
|
|
72
|
+
}
|
|
73
|
+
export declare const NO_STATS_CHOICE: StatsConsentState;
|
|
74
|
+
export interface StatsConsent {
|
|
75
|
+
enabled: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* - `default`: no choice yet; the deployment default applies.
|
|
78
|
+
* - `choice`: the user's own choice applies.
|
|
79
|
+
* - `gpc`: Global Privacy Control turned it off (no choice yet).
|
|
80
|
+
* - `gpc-since-choice`: GPC appeared after the user opted in, so it's off
|
|
81
|
+
* again until they confirm.
|
|
82
|
+
*/
|
|
83
|
+
reason: "default" | "choice" | "gpc" | "gpc-since-choice";
|
|
84
|
+
/** Show the note explaining GPC turned stats off and that they can turn it back on. */
|
|
85
|
+
showGpcNote: boolean;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Decides whether stats may be sent. Rules, in order:
|
|
89
|
+
* 1. An explicit "off" is always off.
|
|
90
|
+
* 2. An explicit "on" wins over GPC if GPC was already on when the user
|
|
91
|
+
* chose; GPC appearing later counts as newer intent and turns it off.
|
|
92
|
+
* 3. With no choice, GPC means off; otherwise the deployment default.
|
|
93
|
+
* Nothing automatic ever turns stats on except the deployment default.
|
|
94
|
+
*/
|
|
95
|
+
export declare function resolveStatsConsent(input: {
|
|
96
|
+
state: StatsConsentState;
|
|
97
|
+
gpc: boolean;
|
|
98
|
+
defaultOn: boolean;
|
|
99
|
+
}): StatsConsent;
|
|
100
|
+
/** The state to store when the user makes a choice. */
|
|
101
|
+
export declare function recordStatsChoice(choice: "on" | "off", gpc: boolean): StatsConsentState;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Usage stats: the one event, how it's built, and whether it may be sent.
|
|
4
|
+
*
|
|
5
|
+
* The library never sends anything itself; it has no network code at all.
|
|
6
|
+
* A UI or the CLI calls {@link buildStatsEvent} after a successful
|
|
7
|
+
* conversion and decides with {@link resolveStatsConsent} whether to send
|
|
8
|
+
* it, and to where. Off by default everywhere except a deployment whose
|
|
9
|
+
* operator turns it on and discloses it.
|
|
10
|
+
*
|
|
11
|
+
* {@link StatsEventSchema} is strict: the sender, the "see exactly what's
|
|
12
|
+
* sent" display and the docs all come from it, and a payload with any
|
|
13
|
+
* other field fails to parse, so the explanation can't drift from what's
|
|
14
|
+
* actually sent.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { VERSION } from "./version.js";
|
|
18
|
+
export const REF_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
19
|
+
export const StatsEventSchema = z
|
|
20
|
+
.object({
|
|
21
|
+
v: z.literal(1).describe("event format version"),
|
|
22
|
+
core: z
|
|
23
|
+
.string()
|
|
24
|
+
.regex(/^\d+\.\d+\.\d+([-+][0-9A-Za-z.-]{1,32})?$/)
|
|
25
|
+
.describe("the any2orca version that converted the file"),
|
|
26
|
+
profileId: z
|
|
27
|
+
.string()
|
|
28
|
+
.regex(/^[a-z0-9][a-z0-9.-]{0,63}$/)
|
|
29
|
+
.describe('the profile used, e.g. "snapmaker-u1-0.4-standard"'),
|
|
30
|
+
matchSource: z
|
|
31
|
+
.enum(["explicit", "auto-tier-name", "auto-exact", "auto-nearest", "default-fallback"])
|
|
32
|
+
.describe("how the profile was chosen"),
|
|
33
|
+
plates: z.number().int().min(0).max(10_000).describe("number of plates"),
|
|
34
|
+
objects: z.number().int().min(0).max(10_000).describe("number of objects"),
|
|
35
|
+
filamentSlots: z.number().int().min(0).max(1_000).describe("number of filament slots"),
|
|
36
|
+
sourceVendor: z
|
|
37
|
+
.enum(["bambu", "creality", "anycubic", "snapmaker", "elegoo", "prusa", "flashforge", "other"])
|
|
38
|
+
.describe("the printer maker the source file was set up for"),
|
|
39
|
+
ref: z.string().regex(REF_PATTERN).optional().describe("which site sent you here, if it said so (a short slug, never free text)"),
|
|
40
|
+
day: z
|
|
41
|
+
.string()
|
|
42
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/)
|
|
43
|
+
.describe("the UTC date of the conversion (no time of day)"),
|
|
44
|
+
})
|
|
45
|
+
.strict();
|
|
46
|
+
/** What is never sent, for the "see exactly what's sent" display. */
|
|
47
|
+
export const NEVER_SENT = [
|
|
48
|
+
"your file, or any part of it (no geometry, no settings values)",
|
|
49
|
+
"file names or folder paths",
|
|
50
|
+
"anything that identifies you or your device (no IDs, no cookies)",
|
|
51
|
+
"the time of day (only the date)",
|
|
52
|
+
];
|
|
53
|
+
/** Builds the event from a conversion report. Throws if a field is out of range. */
|
|
54
|
+
export function buildStatsEvent(input) {
|
|
55
|
+
const ref = input.ref && REF_PATTERN.test(input.ref) ? input.ref : undefined;
|
|
56
|
+
return StatsEventSchema.parse({
|
|
57
|
+
v: 1,
|
|
58
|
+
core: VERSION,
|
|
59
|
+
profileId: input.profileId,
|
|
60
|
+
matchSource: input.profileMatch?.matchSource ?? "explicit",
|
|
61
|
+
plates: input.plates,
|
|
62
|
+
objects: input.objects,
|
|
63
|
+
filamentSlots: input.filamentSlots,
|
|
64
|
+
sourceVendor: input.sourceVendor,
|
|
65
|
+
...(ref ? { ref } : {}),
|
|
66
|
+
day: (input.date ?? new Date()).toISOString().slice(0, 10),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export const NO_STATS_CHOICE = { choice: null, gpcAtChoice: false };
|
|
70
|
+
/**
|
|
71
|
+
* Decides whether stats may be sent. Rules, in order:
|
|
72
|
+
* 1. An explicit "off" is always off.
|
|
73
|
+
* 2. An explicit "on" wins over GPC if GPC was already on when the user
|
|
74
|
+
* chose; GPC appearing later counts as newer intent and turns it off.
|
|
75
|
+
* 3. With no choice, GPC means off; otherwise the deployment default.
|
|
76
|
+
* Nothing automatic ever turns stats on except the deployment default.
|
|
77
|
+
*/
|
|
78
|
+
export function resolveStatsConsent(input) {
|
|
79
|
+
const { state, gpc, defaultOn } = input;
|
|
80
|
+
if (state.choice === "off")
|
|
81
|
+
return { enabled: false, reason: "choice", showGpcNote: false };
|
|
82
|
+
if (state.choice === "on") {
|
|
83
|
+
if (gpc && !state.gpcAtChoice)
|
|
84
|
+
return { enabled: false, reason: "gpc-since-choice", showGpcNote: true };
|
|
85
|
+
return { enabled: true, reason: "choice", showGpcNote: false };
|
|
86
|
+
}
|
|
87
|
+
if (gpc)
|
|
88
|
+
return { enabled: false, reason: "gpc", showGpcNote: defaultOn };
|
|
89
|
+
return { enabled: defaultOn, reason: "default", showGpcNote: false };
|
|
90
|
+
}
|
|
91
|
+
/** The state to store when the user makes a choice. */
|
|
92
|
+
export function recordStatsChoice(choice, gpc) {
|
|
93
|
+
return { choice, gpcAtChoice: gpc };
|
|
94
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* The script that runs inside the Web Worker. Load it with your bundler's
|
|
4
|
+
* worker support and hand the Worker to `createConverterWorker()` from
|
|
5
|
+
* `any2orca/worker`; don't post messages to it directly, the protocol
|
|
6
|
+
* isn't a public API.
|
|
7
|
+
*
|
|
8
|
+
* Vite: import ConverterWorker from "any2orca/worker-entry?worker";
|
|
9
|
+
* Others: new Worker(new URL("any2orca/worker-entry", import.meta.url), { type: "module" })
|
|
10
|
+
*
|
|
11
|
+
* Opened projects stay in the worker's memory until closed. At most
|
|
12
|
+
* MAX_OPEN_PROJECTS are kept; opening more closes the oldest.
|
|
13
|
+
*/
|
|
14
|
+
import { diffSettings } from "./diff/diffSettings.js";
|
|
15
|
+
import { diffReference, presetDiffSide } from "./diff/reference.js";
|
|
16
|
+
import { Any2orcaError } from "./errors.js";
|
|
17
|
+
import { extractPreset } from "./presets/extractPreset.js";
|
|
18
|
+
import { resolvePreset } from "./presets/preset.js";
|
|
19
|
+
import { fetchProfileSource, loadCatalog } from "./profiles.js";
|
|
20
|
+
import { Project, unwrapBundle } from "./project.js";
|
|
21
|
+
const MAX_OPEN_PROJECTS = 16;
|
|
22
|
+
const scope = globalThis;
|
|
23
|
+
let profiles = null;
|
|
24
|
+
const projects = new Map();
|
|
25
|
+
let nextHandle = 1;
|
|
26
|
+
function requireProfiles() {
|
|
27
|
+
if (!profiles)
|
|
28
|
+
throw new Any2orcaError("profile_data", "The worker has no profile catalog configured.");
|
|
29
|
+
return profiles;
|
|
30
|
+
}
|
|
31
|
+
function requireProject(handle) {
|
|
32
|
+
const project = typeof handle === "number" ? projects.get(handle) : undefined;
|
|
33
|
+
if (!project)
|
|
34
|
+
throw new Any2orcaError("invalid_file", "This file is no longer open in the worker; open it again.");
|
|
35
|
+
return project;
|
|
36
|
+
}
|
|
37
|
+
function toBytes(value) {
|
|
38
|
+
if (value instanceof ArrayBuffer)
|
|
39
|
+
return new Uint8Array(value);
|
|
40
|
+
if (value instanceof Uint8Array)
|
|
41
|
+
return value;
|
|
42
|
+
throw new Any2orcaError("invalid_file", "Expected file bytes.");
|
|
43
|
+
}
|
|
44
|
+
function isRequest(data) {
|
|
45
|
+
return typeof data === "object" && data !== null && typeof data.id === "number" && typeof data.op === "string";
|
|
46
|
+
}
|
|
47
|
+
async function handle(request) {
|
|
48
|
+
switch (request.op) {
|
|
49
|
+
case "configure": {
|
|
50
|
+
profiles = fetchProfileSource(request.profilesUrl);
|
|
51
|
+
return { result: null, transfer: [] };
|
|
52
|
+
}
|
|
53
|
+
case "listProfiles": {
|
|
54
|
+
const catalog = await loadCatalog(requireProfiles());
|
|
55
|
+
const { dataVersion, slicer, defaultProfileId } = catalog.index;
|
|
56
|
+
return { result: { profiles: catalog.list(request.filter ?? {}), dataVersion, slicer, defaultProfileId }, transfer: [] };
|
|
57
|
+
}
|
|
58
|
+
case "open": {
|
|
59
|
+
const project = Project.open(toBytes(request.bytes));
|
|
60
|
+
const handle = nextHandle++;
|
|
61
|
+
projects.set(handle, project);
|
|
62
|
+
while (projects.size > MAX_OPEN_PROJECTS)
|
|
63
|
+
projects.delete(projects.keys().next().value);
|
|
64
|
+
return { result: { handle, inspection: project.inspect() }, transfer: [] };
|
|
65
|
+
}
|
|
66
|
+
case "matchProfile": {
|
|
67
|
+
return { result: await requireProject(request.handle).matchProfile(requireProfiles()), transfer: [] };
|
|
68
|
+
}
|
|
69
|
+
case "convert": {
|
|
70
|
+
const project = requireProject(request.handle);
|
|
71
|
+
const { output, report } = await project.convert({
|
|
72
|
+
...request.options,
|
|
73
|
+
profiles: requireProfiles(),
|
|
74
|
+
onProgress: (stage) => scope.postMessage({ id: request.id, progress: stage }),
|
|
75
|
+
});
|
|
76
|
+
const buffer = output.buffer;
|
|
77
|
+
return { result: { output: buffer, byteOffset: output.byteOffset, byteLength: output.byteLength, report }, transfer: [buffer] };
|
|
78
|
+
}
|
|
79
|
+
case "close": {
|
|
80
|
+
projects.delete(request.handle);
|
|
81
|
+
return { result: null, transfer: [] };
|
|
82
|
+
}
|
|
83
|
+
case "diff": {
|
|
84
|
+
const side = async (s) => {
|
|
85
|
+
if (typeof s === "object" && s !== null && "preset" in s) {
|
|
86
|
+
// A preset as it converts: its base profile's stock settings with its changes written over them.
|
|
87
|
+
return presetDiffSide(s.preset, await loadCatalog(requireProfiles()));
|
|
88
|
+
}
|
|
89
|
+
if (typeof s === "object" && s !== null && "stock" in s && typeof s.stock === "string") {
|
|
90
|
+
const loaded = await loadCatalog(requireProfiles()).then((c) => c.load(s.stock));
|
|
91
|
+
return { label: `Snapmaker's stock ${loaded.summary.displayName} profile`, settings: loaded.convertProfile.profile.baselineProjectSettings, profileId: loaded.summary.id };
|
|
92
|
+
}
|
|
93
|
+
const { handle: h, label } = (s ?? {});
|
|
94
|
+
const project = requireProject(h);
|
|
95
|
+
return { label: typeof label === "string" ? label.slice(0, 256) : "project", settings: project.settings(), project };
|
|
96
|
+
};
|
|
97
|
+
const options = (request.options ?? {});
|
|
98
|
+
const safe = {
|
|
99
|
+
...(Array.isArray(options.groups) ? { groups: options.groups.filter((g) => ["print", "filament", "machine", "other"].includes(g)) } : {}),
|
|
100
|
+
includeUnchanged: options.includeUnchanged === true,
|
|
101
|
+
includeBookkeeping: options.includeBookkeeping === true,
|
|
102
|
+
};
|
|
103
|
+
const a = await side(request.a);
|
|
104
|
+
const b = await side(request.b);
|
|
105
|
+
// Values are measured against the stock or preset side's profile, else the profile the first file would convert with.
|
|
106
|
+
const catalog = await loadCatalog(requireProfiles());
|
|
107
|
+
const known = "profileId" in b ? b.profileId : "profileId" in a ? a.profileId : undefined;
|
|
108
|
+
const project = "project" in a ? a.project : "project" in b ? b.project : undefined;
|
|
109
|
+
const profileId = known ?? (project ? (await project.matchProfile(catalog)).profileId : catalog.index.defaultProfileId);
|
|
110
|
+
return { result: diffSettings(a, b, { ...safe, reference: await diffReference(catalog, profileId) }), transfer: [] };
|
|
111
|
+
}
|
|
112
|
+
case "extractPreset": {
|
|
113
|
+
return { result: await extractPreset(requireProject(request.handle), { profiles: requireProfiles() }), transfer: [] };
|
|
114
|
+
}
|
|
115
|
+
case "resolvePreset": {
|
|
116
|
+
return { result: await resolvePreset(request.preset, await loadCatalog(requireProfiles())), transfer: [] };
|
|
117
|
+
}
|
|
118
|
+
case "unwrapBundle": {
|
|
119
|
+
const entries = unwrapBundle(toBytes(request.bytes));
|
|
120
|
+
if (!entries)
|
|
121
|
+
return { result: null, transfer: [] };
|
|
122
|
+
// Copy each entry into its own buffer so it can be transferred alone.
|
|
123
|
+
const copies = entries.map((e) => ({ name: e.name, bytes: e.bytes.slice() }));
|
|
124
|
+
return { result: copies, transfer: copies.map((c) => c.bytes.buffer) };
|
|
125
|
+
}
|
|
126
|
+
default:
|
|
127
|
+
throw new Any2orcaError("invalid_file", "Unknown worker request.");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
scope.onmessage = (event) => {
|
|
131
|
+
const data = event.data;
|
|
132
|
+
if (!isRequest(data))
|
|
133
|
+
return;
|
|
134
|
+
handle(data).then(({ result, transfer }) => scope.postMessage({ id: data.id, ok: true, result }, transfer), (err) => scope.postMessage({
|
|
135
|
+
id: data.id,
|
|
136
|
+
ok: false,
|
|
137
|
+
error: {
|
|
138
|
+
code: err instanceof Any2orcaError ? err.code : "invalid_file",
|
|
139
|
+
message: err instanceof Error ? err.message : String(err),
|
|
140
|
+
},
|
|
141
|
+
}));
|
|
142
|
+
};
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Inspection } from "./inspect.js";
|
|
2
|
+
import type { ProfileSummary } from "./profiles.js";
|
|
3
|
+
import type { ConvertReport, ConvertStage, ProfileChoice } from "./project.js";
|
|
4
|
+
import type { DiffOptions, SettingsDiff } from "./diff/diffSettings.js";
|
|
5
|
+
import type { ExtractedPreset, Preset, ResolvedPreset } from "./presets/preset.js";
|
|
6
|
+
import type { WorkerConvertOptions } from "./workerProtocol.js";
|
|
7
|
+
/** The parts of a Worker this needs, so tests and other runtimes can supply their own. */
|
|
8
|
+
export interface WorkerLike {
|
|
9
|
+
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
10
|
+
addEventListener(type: "message", listener: (event: {
|
|
11
|
+
data: unknown;
|
|
12
|
+
}) => void): void;
|
|
13
|
+
terminate(): void;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkerConvertResult {
|
|
16
|
+
output: Uint8Array;
|
|
17
|
+
report: ConvertReport;
|
|
18
|
+
}
|
|
19
|
+
export interface WorkerProject {
|
|
20
|
+
readonly inspection: Inspection;
|
|
21
|
+
/** The profile auto-matching would pick. */
|
|
22
|
+
matchProfile(): Promise<ProfileChoice>;
|
|
23
|
+
convert(options?: WorkerConvertOptions & {
|
|
24
|
+
onProgress?: (stage: ConvertStage) => void;
|
|
25
|
+
}): Promise<WorkerConvertResult>;
|
|
26
|
+
/** Makes a preset from this file, as a file the user tuned in Snapmaker Orca (see `extractPreset`). */
|
|
27
|
+
extractPreset(): Promise<ExtractedPreset>;
|
|
28
|
+
/** Frees the worker's copy of the file. */
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** One side of a settings diff: an open project (with the name to show for it), Snapmaker's stock profile by id, or a preset as it converts. */
|
|
32
|
+
export type DiffSide = {
|
|
33
|
+
project: WorkerProject;
|
|
34
|
+
label: string;
|
|
35
|
+
} | {
|
|
36
|
+
stock: string;
|
|
37
|
+
} | {
|
|
38
|
+
preset: Preset;
|
|
39
|
+
};
|
|
40
|
+
export interface ProfileListing {
|
|
41
|
+
profiles: ProfileSummary[];
|
|
42
|
+
/** The catalog's version, e.g. "0.1.0". */
|
|
43
|
+
dataVersion: string;
|
|
44
|
+
/** The upstream release the catalog tracks. */
|
|
45
|
+
slicer: {
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
};
|
|
49
|
+
defaultProfileId: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ConverterWorker {
|
|
52
|
+
/**
|
|
53
|
+
* Opens a file in the worker. Pass `transfer: true` to move the bytes
|
|
54
|
+
* instead of copying them (faster for large files, but the caller's
|
|
55
|
+
* buffer becomes unusable).
|
|
56
|
+
*/
|
|
57
|
+
open(bytes: Uint8Array, options?: {
|
|
58
|
+
transfer?: boolean;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
project: WorkerProject;
|
|
61
|
+
inspection: Inspection;
|
|
62
|
+
}>;
|
|
63
|
+
listProfiles(filter?: {
|
|
64
|
+
nozzleDiameter?: string;
|
|
65
|
+
}): Promise<ProfileListing>;
|
|
66
|
+
/** Compares the settings of two sides (open projects or stock profiles), in the worker. */
|
|
67
|
+
diff(a: DiffSide, b: DiffSide, options?: DiffOptions): Promise<SettingsDiff>;
|
|
68
|
+
/**
|
|
69
|
+
* Checks a saved or imported preset against the current profiles: the
|
|
70
|
+
* profile it converts with, the changes it would apply (with values above
|
|
71
|
+
* stock marked, for a badge) and notes on anything it would leave out.
|
|
72
|
+
*/
|
|
73
|
+
resolvePreset(preset: Preset): Promise<ResolvedPreset>;
|
|
74
|
+
/** Each .3mf inside a bundle zip, or null for a plain .3mf. */
|
|
75
|
+
unwrapBundle(bytes: Uint8Array): Promise<Array<{
|
|
76
|
+
name: string;
|
|
77
|
+
bytes: Uint8Array;
|
|
78
|
+
}> | null>;
|
|
79
|
+
terminate(): void;
|
|
80
|
+
}
|
|
81
|
+
export declare function createConverterWorker(worker: WorkerLike, options: {
|
|
82
|
+
profilesUrl: string | URL;
|
|
83
|
+
}): ConverterWorker;
|
|
84
|
+
export type { WorkerConvertOptions } from "./workerProtocol.js";
|
|
85
|
+
export type { DiffOptions, SettingsDiff } from "./diff/diffSettings.js";
|
|
86
|
+
export type { ExtractedPreset, Preset, PresetChange, ResolvedPreset } from "./presets/preset.js";
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* any2orca/worker: run conversions in a Web Worker behind a promise API,
|
|
4
|
+
* so a large file never blocks the page.
|
|
5
|
+
*
|
|
6
|
+
* import { createConverterWorker } from "any2orca/worker";
|
|
7
|
+
* import ConverterWorker from "any2orca/worker-entry?worker"; // Vite
|
|
8
|
+
*
|
|
9
|
+
* const converter = createConverterWorker(new ConverterWorker(), { profilesUrl: "/profiles/" });
|
|
10
|
+
* const { project, inspection } = await converter.open(fileBytes);
|
|
11
|
+
* const { output, report } = await project.convert({ highFlowHotends: false });
|
|
12
|
+
*
|
|
13
|
+
* `profilesUrl` points at a copy of `any2orca-profiles`' `data/` folder,
|
|
14
|
+
* normally served by the same site. The worker fetches `index.json` and
|
|
15
|
+
* only the profile files it needs; it makes no other request.
|
|
16
|
+
*/
|
|
17
|
+
import { Any2orcaError } from "./errors.js";
|
|
18
|
+
export function createConverterWorker(worker, options) {
|
|
19
|
+
const pending = new Map();
|
|
20
|
+
let nextId = 1;
|
|
21
|
+
let terminated = false;
|
|
22
|
+
worker.addEventListener("message", (event) => {
|
|
23
|
+
const message = event.data;
|
|
24
|
+
const entry = pending.get(message?.id);
|
|
25
|
+
if (!entry)
|
|
26
|
+
return;
|
|
27
|
+
if ("progress" in message) {
|
|
28
|
+
entry.onProgress?.(message.progress);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
pending.delete(message.id);
|
|
32
|
+
if (message.ok)
|
|
33
|
+
entry.resolve(message.result);
|
|
34
|
+
else
|
|
35
|
+
entry.reject(new Any2orcaError(message.error.code, message.error.message));
|
|
36
|
+
});
|
|
37
|
+
function call(body, transfer = [], onProgress) {
|
|
38
|
+
if (terminated)
|
|
39
|
+
return Promise.reject(new Error("The converter worker has been terminated."));
|
|
40
|
+
const id = nextId++;
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
pending.set(id, { resolve: resolve, reject, onProgress });
|
|
43
|
+
worker.postMessage({ ...body, id }, transfer);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
// Resolved against the page, since a relative URL means something else inside the worker.
|
|
47
|
+
const profilesUrl = new URL(String(options.profilesUrl), globalThis.location?.href).href;
|
|
48
|
+
void call({ op: "configure", profilesUrl });
|
|
49
|
+
const handles = new WeakMap();
|
|
50
|
+
const toWire = (side) => {
|
|
51
|
+
if ("stock" in side)
|
|
52
|
+
return { stock: side.stock };
|
|
53
|
+
if ("preset" in side)
|
|
54
|
+
return { preset: side.preset };
|
|
55
|
+
const handle = handles.get(side.project);
|
|
56
|
+
if (handle === undefined)
|
|
57
|
+
throw new Any2orcaError("invalid_file", "That project wasn't opened by this converter.");
|
|
58
|
+
return { handle, label: side.label };
|
|
59
|
+
};
|
|
60
|
+
function project(handle, inspection) {
|
|
61
|
+
const opened = {
|
|
62
|
+
inspection,
|
|
63
|
+
matchProfile: () => call({ op: "matchProfile", handle }),
|
|
64
|
+
async convert(convertOptions = {}) {
|
|
65
|
+
const { onProgress, ...rest } = convertOptions;
|
|
66
|
+
const result = await call({ op: "convert", handle, options: rest }, [], onProgress);
|
|
67
|
+
return { output: new Uint8Array(result.output, result.byteOffset, result.byteLength), report: result.report };
|
|
68
|
+
},
|
|
69
|
+
extractPreset: () => call({ op: "extractPreset", handle }),
|
|
70
|
+
close: () => call({ op: "close", handle }),
|
|
71
|
+
};
|
|
72
|
+
handles.set(opened, handle);
|
|
73
|
+
return opened;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
async open(bytes, openOptions = {}) {
|
|
77
|
+
// Either way only one buffer crosses: the caller's own (transfer) or a fresh copy.
|
|
78
|
+
const ownsWholeBuffer = bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength;
|
|
79
|
+
const payload = openOptions.transfer && ownsWholeBuffer ? bytes : bytes.slice();
|
|
80
|
+
const { handle, inspection } = await call({ op: "open", bytes: payload }, [payload.buffer]);
|
|
81
|
+
return { project: project(handle, inspection), inspection };
|
|
82
|
+
},
|
|
83
|
+
async diff(a, b, diffOptions = {}) {
|
|
84
|
+
return call({ op: "diff", a: toWire(a), b: toWire(b), options: diffOptions });
|
|
85
|
+
},
|
|
86
|
+
resolvePreset: (preset) => call({ op: "resolvePreset", preset }),
|
|
87
|
+
listProfiles: (filter) => call({ op: "listProfiles", ...(filter ? { filter } : {}) }),
|
|
88
|
+
unwrapBundle: (bytes) => call({ op: "unwrapBundle", bytes }),
|
|
89
|
+
terminate() {
|
|
90
|
+
terminated = true;
|
|
91
|
+
worker.terminate();
|
|
92
|
+
for (const entry of pending.values())
|
|
93
|
+
entry.reject(new Error("The converter worker was terminated."));
|
|
94
|
+
pending.clear();
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|