three-slicer 0.2.5 → 0.3.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +9 -4
  3. package/THIRD-PARTY-NOTICES.md +7 -2
  4. package/components/dist/SettingsPanel.js +12 -198
  5. package/data/config-schema-lean.json +1 -0
  6. package/data/ui-tree-keys.json +1 -0
  7. package/engine/src/client.js +9 -0
  8. package/engine/src/data.js +6 -0
  9. package/engine/src/settings.js +12 -627
  10. package/engine/src/toggle_eval.js +9 -77
  11. package/package.json +20 -10
  12. package/types/client.d.ts +3 -0
  13. package/types/components.d.ts +3 -29
  14. package/types/settings.d.ts +3 -0
  15. package/types/toggle.d.ts +2 -22
  16. package/types/viewer-gcode.d.ts +2 -29
  17. package/types/viewer-loaders.d.ts +1 -33
  18. package/types/viewer-toolpath.d.ts +3 -113
  19. package/types/viewer.d.ts +6 -213
  20. package/viewer/dist/Viewport.js +9 -6571
  21. package/viewer/dist/gcode_reexport.js +1 -0
  22. package/viewer/dist/loaders_reexport.js +1 -0
  23. package/viewer/dist/toolpath_reexport.js +1 -0
  24. package/components/README.md +0 -44
  25. package/components/styles.css +0 -88
  26. package/engine/src/kernel_setting_keys.js +0 -132
  27. package/engine/src/preset_file.js +0 -99
  28. package/viewer/README.md +0 -423
  29. package/viewer/dist/gcode_parse.js +0 -190
  30. package/viewer/dist/make_worker.js +0 -31
  31. package/viewer/dist/model_loaders.js +0 -184
  32. package/viewer/dist/parse_3mf-C2X_W442.js +0 -300
  33. package/viewer/dist/parse_3mf.worker.js +0 -10
  34. package/viewer/dist/sl1_encode.worker.js +0 -10
  35. package/viewer/dist/sl1_write-CtX8cVL7.js +0 -302
  36. package/viewer/dist/sla_reconstruct-CXkYhux2.js +0 -176
  37. package/viewer/dist/sla_reconstruct.worker.js +0 -24
  38. package/viewer/dist/sla_slice.worker.js +0 -74
  39. package/viewer/dist/toolpath_gpu-4foc4FaU.js +0 -482
  40. package/viewer/dist/toolpath_gpu.js +0 -13
  41. package/viewer/styles.css +0 -394
@@ -1,77 +1,9 @@
1
- // Stage 25 S5.1: partial translation of toggle-rules — upstream C++ toggle_options conditions (enable_if) -> JS.
2
- // Scope: among the rules touching keys the viewer handles, only those "fully" translatable with the hardcoded locals below.
3
- // Untranslatable ones (unknown locals, enum comparisons, …) fail open (stay enabled) — avoids wrongly disabling (honest partial implementation).
4
- // Translating all 907 keys / 231 rules is out of scope (noted in the README). Reference: toggle_print_fff_options.locals in toggle-rules.json.
5
- import { toggleRules as toggles, schema } from './data.js'
6
-
7
- // Settings value accessor (settings map first, schema default otherwise). Percentages ("15%") become numbers.
8
- export function makeCfg(settings) {
9
- const val = k => {
10
- let v = settings ? settings[k] : undefined
11
- if (v === undefined || v === '') { const d = schema[k]?.default; v = Array.isArray(d) ? d[0] : d }
12
- return v
13
- }
14
- const num = k => { const v = val(k); const n = parseFloat(v); return Number.isFinite(n) ? n : 0 }
15
- return {
16
- bool: k => { const v = val(k); return v === true || v === 1 || v === '1' || v === 'true' },
17
- int: k => Math.trunc(num(k)),
18
- float: k => num(k),
19
- has: k => k in schema,
20
- }
21
- }
22
-
23
- // Upstream locals translated inline (viewer-related conditions only). Each value is a boolean.
24
- function makeLocals(cfg) {
25
- const have_raft = cfg.int('raft_layers') > 0
26
- const has_spiral_vase = cfg.bool('spiral_mode')
27
- const has_top_shell = cfg.int('top_shell_layers') > 0 || (has_spiral_vase && cfg.int('bottom_shell_layers') > 1)
28
- const has_bottom_shell = cfg.int('bottom_shell_layers') > 0
29
- return {
30
- have_raft,
31
- have_perimeters: cfg.int('wall_loops') > 0,
32
- have_infill: cfg.float('sparse_infill_density') > 0,
33
- has_spiral_vase,
34
- has_top_shell,
35
- has_bottom_shell,
36
- has_solid_infill: has_top_shell || has_bottom_shell,
37
- have_skirt: cfg.int('skirt_loops') > 0,
38
- have_support_material: cfg.bool('enable_support') || have_raft,
39
- have_support_interface: cfg.int('support_interface_top_layers') > 0 || cfg.int('support_interface_bottom_layers') > 0,
40
- have_prime_tower: cfg.bool('enable_prime_tower'),
41
- }
42
- }
43
-
44
- // Evaluates enable_if (up to the first comma) to a boolean. Returns null (= stays enabled) when not fully translatable.
45
- export function evalEnableIf(expr, locals, cfg) {
46
- let s = String(expr).split(',')[0].trim()
47
- if (!s) return null
48
- // Direct config access pattern -> value substitution
49
- s = s.replace(/config->opt_bool\(\s*"([^"]+)"\s*\)/g, (_, k) => cfg.bool(k) ? 'true' : 'false')
50
- s = s.replace(/config->opt_int\(\s*"([^"]+)"\s*\)/g, (_, k) => String(cfg.int(k)))
51
- s = s.replace(/config->opt_float\(\s*"([^"]+)"\s*\)/g, (_, k) => String(cfg.float(k)))
52
- // Substitute known locals (longest name first — prevents partial matches)
53
- for (const name of Object.keys(locals).sort((a, b) => b.length - a.length))
54
- s = s.replace(new RegExp('\\b' + name + '\\b', 'g'), locals[name] ? 'true' : 'false')
55
- // Check the remaining string is a safe boolean expression (only true/false/numbers/operators/parens) — otherwise unknown -> null
56
- const stripped = s.replace(/\btrue\b|\bfalse\b/g, '1')
57
- if (!/^[\s()!<>=&|0-9.]*$/.test(stripped)) return null
58
- try { return !!Function('"use strict";return (' + s + ')')() } catch { return null }
59
- }
60
-
61
- // Map of keys disabled under the current settings { key: condition }. Only rules that are unambiguously false.
62
- export function disabledKeys(cfg) {
63
- const locals = makeLocals(cfg)
64
- const groups = ['toggle_print_fff_options', 'toggle_filament_options', 'toggle_printer_options',
65
- 'TabFilament::toggle_options', 'TabPrinter::toggle_options']
66
- const out = {}
67
- for (const gname of groups) {
68
- const g = toggles[gname]
69
- if (!g || !Array.isArray(g.rules)) continue
70
- for (const rule of g.rules) {
71
- if (!rule.enable_if || !Array.isArray(rule.fields)) continue
72
- const en = evalEnableIf(rule.enable_if, locals, cfg)
73
- if (en === false) for (const k of rule.fields) if (!(k in out)) out[k] = rule.enable_if
74
- }
75
- }
76
- return out
77
- }
1
+ // three-slicer/toggle — the evaluator from the permissive package, bound to upstream's toggle rules.
2
+ // The rules (toggle-rules.json, extracted from OrcaSlicer's toggle_options) and the full schema are this
3
+ // package's data; the evaluator itself is three-slicer-viewer's. Same surface as before the split.
4
+ import { makeToggle, evalEnableIf } from 'three-slicer-viewer/toggle'
5
+ import { toggleRules, schema } from './data.js'
6
+ const bound = makeToggle(toggleRules, schema)
7
+ export const makeCfg = bound.makeCfg
8
+ export const disabledKeys = bound.disabledKeys
9
+ export { evalEnableIf }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-slicer",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "Browser/WASM 3D-printing slicer reverse-engineered from OrcaSlicer: slicing engine (Arachne walls, tree/grid supports, multi-material), SLA resin slicing with PrusaSlicer's ported support/pad chain and .sl1 export, React viewer with GPU toolpath preview, and schema-driven settings UI.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "type": "module",
@@ -39,15 +39,15 @@
39
39
  },
40
40
  "./viewer/toolpath": {
41
41
  "types": "./types/viewer-toolpath.d.ts",
42
- "default": "./viewer/dist/toolpath_gpu.js"
42
+ "default": "./viewer/dist/toolpath_reexport.js"
43
43
  },
44
44
  "./viewer/loaders": {
45
45
  "types": "./types/viewer-loaders.d.ts",
46
- "default": "./viewer/dist/model_loaders.js"
46
+ "default": "./viewer/dist/loaders_reexport.js"
47
47
  },
48
48
  "./viewer/gcode": {
49
49
  "types": "./types/viewer-gcode.d.ts",
50
- "default": "./viewer/dist/gcode_parse.js"
50
+ "default": "./viewer/dist/gcode_reexport.js"
51
51
  },
52
52
  "./components": {
53
53
  "types": "./types/components.d.ts",
@@ -65,7 +65,7 @@
65
65
  },
66
66
  "sideEffects": false,
67
67
  "scripts": {
68
- "build": "node types/gen_settings_types.mjs && node types/gen_kernel_params.mjs && vite build --config components/vite.config.js && vite build --config viewer/vite.config.js && cp viewer/src/make_worker.js viewer/dist/make_worker.js",
68
+ "build": "node types/gen_settings_types.mjs && node types/gen_kernel_params.mjs && vite build --config components/vite.config.js && vite build --config viewer/vite.config.js",
69
69
  "check": "bash pack_check.sh"
70
70
  },
71
71
  "peerDependencies": {
@@ -74,9 +74,15 @@
74
74
  "three": "^0.160.0"
75
75
  },
76
76
  "peerDependenciesMeta": {
77
- "react": { "optional": true },
78
- "react-dom": { "optional": true },
79
- "three": { "optional": true }
77
+ "react": {
78
+ "optional": true
79
+ },
80
+ "react-dom": {
81
+ "optional": true
82
+ },
83
+ "three": {
84
+ "optional": true
85
+ }
80
86
  },
81
87
  "devDependencies": {
82
88
  "typescript": "^5.6.0",
@@ -93,6 +99,8 @@
93
99
  "viewer/styles.css",
94
100
  "components/styles.css",
95
101
  "data",
102
+ "data/ui-tree-keys.json",
103
+ "data/config-schema-lean.json",
96
104
  "!data/config-schema-builddump.json",
97
105
  "!data/**/.omc",
98
106
  "README.md",
@@ -127,6 +135,8 @@
127
135
  "3d",
128
136
  "mesh",
129
137
  "clipping"
130
- ]
138
+ ],
139
+ "dependencies": {
140
+ "three-slicer-viewer": "0.3.0"
141
+ }
131
142
  }
132
-
package/types/client.d.ts CHANGED
@@ -86,3 +86,6 @@ export interface SlicerClient {
86
86
  */
87
87
  export function createSlicerClient(worker?: Worker): SlicerClient
88
88
  export default createSlicerClient
89
+
90
+ /** The WASM kernel's worker, as a factory — what `three-slicer-viewer`'s `useSlicer` takes as `deps.makeWorker`. */
91
+ export function makeSlicerWorker(): Worker
@@ -1,29 +1,3 @@
1
- // three-slicer/components
2
- import type * as React from 'react'
3
- import type { SlicerSettings } from './settings-keys.d.ts'
4
-
5
- export interface SettingsPanelProps {
6
- /** Sparse map — only edited keys. Missing keys fall back to the config-schema default. */
7
- settings: SlicerSettings
8
- /** React setState shape. The only channel through which state leaves the component. */
9
- setSettings: React.Dispatch<React.SetStateAction<SlicerSettings>>
10
- /** Label click — for deep links / detail views. Omit for a plain label (zero router coupling). */
11
- onOptionOpen?: (optKey: string) => void
12
- /** When embedding inside another panel */
13
- embedded?: boolean
14
- /** Replace schema-driven widgets per key (e.g. `{ printable_area: MyBedEditor }`) */
15
- customWidgets?: Record<string, React.ComponentType<any>>
16
- /**
17
- * Pins the panel to one builder (optionally one page) and drops the search/group/page/mode chrome, so the form
18
- * can be folded into another card. This is how `<Viewport/>`'s `motionPanel` slot is meant to be filled:
19
- *
20
- * ```jsx
21
- * <SettingsPanel settings={settings} setSettings={setSettings} embedded
22
- * only={{ builder: 'TabPrinter::build_kinematics_page' }} />
23
- * ```
24
- */
25
- only?: { builder: string; page?: string }
26
- }
27
-
28
- declare const SettingsPanel: React.FC<SettingsPanelProps>
29
- export default SettingsPanel
1
+ // three-slicer/components — the permissive settings panel with upstream's data plugged in. Same surface.
2
+ export * from 'three-slicer-viewer/components'
3
+ export { default } from 'three-slicer-viewer/components'
@@ -201,3 +201,6 @@ export interface FilamentPresetsApi {
201
201
  settingsFor(presetName: string): SlicerSettings | null
202
202
  }
203
203
  export function filamentPresets(): Promise<FilamentPresetsApi>
204
+
205
+ /** The nine catalog lookups above as one object — what `three-slicer-viewer`'s `<Viewport catalog>` takes. */
206
+ export const bundledCatalog: import('three-slicer-viewer').Catalog
package/types/toggle.d.ts CHANGED
@@ -1,22 +1,2 @@
1
- // three-slicer/toggle — partial evaluation of the enable_if expressions in toggle-rules.json.
2
- import type { SlicerSettings } from './settings-keys.d.ts'
3
-
4
- /** Settings accessor — schema default when a value is missing, [0] for vector types. */
5
- export interface ToggleCfg {
6
- bool(key: string): boolean
7
- int(key: string): number
8
- float(key: string): number
9
- /** Whether the key exists in config-schema */
10
- has(key: string): boolean
11
- }
12
-
13
- export function makeCfg(settings: SlicerSettings | null | undefined): ToggleCfg
14
-
15
- /**
16
- * Evaluates a single enable_if expression. Untranslatable expressions return `null` (= fail-open, stays enabled) —
17
- * make sure to treat that as distinct from `false`.
18
- */
19
- export function evalEnableIf(expr: string, locals: Record<string, unknown>, cfg: ToggleCfg): boolean | null
20
-
21
- /** Keys that must be disabled under the current settings -> the enable_if expression that disabled them. Only rules that are unambiguously false. */
22
- export function disabledKeys(cfg: ToggleCfg): Record<string, string>
1
+ // three-slicer/toggle — the permissive evaluator bound to upstream's toggle rules. Same surface.
2
+ export * from 'three-slicer-viewer/toggle'
@@ -1,29 +1,2 @@
1
- // three-slicer/viewer/gcode — G-code text -> kernel-shaped layer stream (renderable without slicing).
2
- // Feed the returned layers straight into buildSegmentData (three-slicer/viewer/toolpath).
3
-
4
- export interface GcodeLayer {
5
- z: number
6
- /** Stride 8: [x0,y0,z0,enc, x1,y1,z1,enc] per segment, enc = role + tool*16 (role 0 = travel). */
7
- paths: Float32Array
8
- /** One entry per segment; 0 means "use the default line width". */
9
- widths: Float32Array
10
- }
11
-
12
- export interface ParseGcodeResult {
13
- layers: GcodeLayer[]
14
- stats: { layers: number; path_segments: number; travel_segments: number; tools: number[] }
15
- }
16
-
17
- export interface ParseGcodeOptions {
18
- /** Used to derive bead width from E when the file has no ;WIDTH: comments. Default 1.75. */
19
- filamentDiameter?: number
20
- /** Bead-height fallback when a layer's height cannot be inferred from z steps. Default 0.2. */
21
- defaultLayerHeight?: number
22
- }
23
-
24
- /**
25
- * Parses G0/G1/G2/G3 (I/J arcs), G90/G91, M82/M83, G92, T<n>, and the layer/role comment conventions of
26
- * OrcaSlicer/PrusaSlicer (;TYPE: ;WIDTH: ;LAYER_CHANGE ;Z:), Cura (;TYPE: ;LAYER:) and this kernel's own output.
27
- * Recovery is lossy where G-code carries no data: unknown roles become wall(1), widths are derived from E.
28
- */
29
- export function parseGcode(text: string, opts?: ParseGcodeOptions): ParseGcodeResult
1
+ // Re-exported from the permissive package (MIT), where the implementation now lives.
2
+ export * from 'three-slicer-viewer/gcode'
@@ -1,33 +1 @@
1
- // three-slicer/viewer/loaders — pure loaders, independent of the kernel.
2
-
3
- /** The 5 built-ins plus any extension registered via `registerLoader()`, which pushes onto this array. */
4
- export const SUPPORTED_EXT: string[]
5
-
6
- /** Lowercased extension. Empty string when there is no dot. */
7
- export function fileExt(name: string): string
8
-
9
- export interface LoadedObject {
10
- name: string
11
- /** Triangle vertex coordinates (N*9, model z-up) */
12
- modelPos: Float32Array
13
- }
14
-
15
- /** A single file may contain several objects (3mf/amf/step) -> always an array. */
16
- export function loadModel(name: string, buffer: ArrayBuffer): Promise<LoadedObject[]>
17
-
18
- /**
19
- * Registers an extra format. Formats needing heavy dependencies (STEP=OCCT WASM, etc.) are not bundled here,
20
- * so the app wires them up itself. The `<Viewport/>` file dialog and drag-and-drop filters pick them up automatically.
21
- *
22
- * ```js
23
- * import { registerLoader } from 'three-slicer/viewer/loaders'
24
- * registerLoader('step,stp', async (buffer, name) => [{ name, modelPos }])
25
- * ```
26
- */
27
- export function registerLoader(
28
- exts: string | string[],
29
- fn: (buffer: ArrayBuffer, name: string) => LoadedObject[] | Promise<LoadedObject[]>,
30
- ): void
31
-
32
- /** Connected-component split. Returns `null` when there is only one component (cannot split) — not an empty array. */
33
- export function splitConnectedComponents(localPos: Float32Array): Float32Array[] | null
1
+ export * from 'three-slicer-viewer/loaders'
@@ -1,113 +1,3 @@
1
- // three-slicer/viewer/toolpath — kernel layers -> GPU-instanced toolpath.
2
- // Does not import three: makeToolpath takes the THREE namespace as an argument (guaranteeing a single instance).
3
-
4
- /** The 24 triangle indices of the 8-vertex diamond cross-section (from SegmentTemplate.cpp:18) */
5
- export const VERTEX_DATA: number[]
6
-
7
- /** Toolpath type -> color. 0=travel, 1=wall … 11=prime */
8
- export const TYPE_COLOR: Record<number, number[]>
9
- export const TYPE_LABEL: Record<number, string>
10
-
11
- /**
12
- * Per-extruder colors for the Filament view. Categorical, not semantic — the toolpath stream carries a tool index and
13
- * nothing about the material, and a machine may have more extruders than entries, so index it modulo its length.
14
- */
15
- export const TOOL_COLOR: number[][]
16
-
17
- /** Blue-to-red 11-color heatmap (libvgcode ColorRange.hpp:14) */
18
- export const DEFAULT_RANGES_COLORS: number[][]
19
-
20
- export interface ViewTypeDef {
21
- key: 'feature' | 'speed' | 'height' | 'width' | 'fan' | 'temp' | 'filament'
22
- label: string
23
- /** Whether values are continuous (heatmap). False means a fixed color. */
24
- cont: boolean
25
- unit: string
26
- }
27
- export const VIEW_TYPES: ViewTypeDef[]
28
-
29
- /** Per-vertex extra data */
30
- export interface SegmentMeta {
31
- vType: Uint8Array
32
- /** Printing extruder, decoded out of the role field's high bits. Untooled output decodes to 0, i.e. single material. */
33
- vTool: Uint8Array
34
- vWidth: Float32Array
35
- vHeight: Float32Array
36
- vLayer: Int32Array
37
- }
38
-
39
- export interface SegmentData {
40
- position: Float32Array
41
- hwa: Float32Array
42
- segIndex: Uint32Array
43
- nV: number
44
- nSeg: number
45
- layerSegPrefix: Uint32Array
46
- travelPos: Float32Array
47
- travelPrefix: Uint32Array
48
- nTrav: number
49
- layerCount: number
50
- maxAbs: number
51
- hasNaN: boolean
52
- meta: SegmentMeta
53
- /** Total extruded length per type (index = toolpath type, length 16) */
54
- typeLengths: Float64Array
55
- /** Null when there is not a single vertex */
56
- bbox: { min: [number, number, number]; max: [number, number, number] } | null
57
- }
58
-
59
- /** Kernel layers[{z, paths(stride8), widths[]}] -> GPU stream. */
60
- export function buildSegmentData(layers: unknown[], defaultLineWidth: number): SegmentData
61
-
62
- /** Length share per type (%), descending by pct. The kernel does not expose time per role, so length is used as an approximation. */
63
- export function roleRatios(typeLengths: Float64Array | number[]): Array<{
64
- type: number
65
- label: string
66
- pct: number
67
- color: number[]
68
- }>
69
-
70
- /**
71
- * speed/fan/temp are absent from the kernel toolpath and derived from settings — these are the values used for that.
72
- */
73
- export interface ColorContext {
74
- speedByType?: Record<number, number>
75
- firstLayerSpeed?: number
76
- fanByType?: Record<number, number>
77
- fanFirstLayers?: number
78
- tempNormal?: number
79
- tempFirst?: number
80
- closeFanLayers?: number
81
- }
82
-
83
- export interface ColorResult {
84
- /** Per-vertex RGBA (nV*4). The color is packed into `.r`. */
85
- color: Float32Array
86
- min: number
87
- max: number
88
- viewType: ViewTypeDef['key']
89
- label: string
90
- unit: string
91
- /** False means fixed colors — min/max are 0 and no legend should be drawn. */
92
- cont: boolean
93
- }
94
-
95
- export function computeColors(data: SegmentData, viewType: ViewTypeDef['key'], ctx: ColorContext): ColorResult
96
-
97
- export interface ToolpathHandle {
98
- /** THREE.Mesh — typed by the THREE namespace passed in */
99
- mesh: any
100
- /** THREE.LineSegments (travel) */
101
- travLines: any
102
- setLayerRange(lo: number, hi: number): void
103
- /** Backwards compatible — same as setLayerRange(0, n-1). */
104
- setVisibleLayers(n: number): void
105
- setTravelVisible(visible: boolean): void
106
- setColors(color: Float32Array): void
107
- dispose(): void
108
- nSeg: number
109
- layerCount: number
110
- }
111
-
112
- /** @param THREE - the `import * as THREE from 'three'` namespace. The consumer's instance is used as-is. */
113
- export function makeToolpath(THREE: any, data: SegmentData): ToolpathHandle
1
+ // Re-exported from the permissive package (MIT), where the implementation now lives.
2
+ // three-slicer/viewer/toolpath stays a valid entry point for every existing consumer.
3
+ export * from 'three-slicer-viewer'
package/types/viewer.d.ts CHANGED
@@ -1,214 +1,7 @@
1
- // three-slicer/viewer
2
- import type * as React from 'react'
3
- import type { SlicerSettings } from './settings-keys.d.ts'
4
-
5
- export interface ViewportProps {
6
- /**
7
- * Sparse settings map. Defaults to `{}`. Two viewer knobs ride in it beside the schema keys: `sla_antialias`
8
- * (SL1 mask MSAA, 1|2|4) and `slice_workers` — how many plates an all-plates run slices at once (0/absent =
9
- * Auto: half the cores on the threaded kernel, one per core on the single-threaded one; the in-app select
10
- * writes it). Neither reaches a 3mf.
11
- */
12
- settings?: SlicerSettings
13
- /** React setState shape. Defaults to a no-op. */
14
- setSettings?: React.Dispatch<React.SetStateAction<SlicerSettings>>
15
- /**
16
- * Per-plate overrides: `{[plateIndex]: sparse map}`, merged over `settings` for that plate's slice only —
17
- * a key's absence means "follow the global value" (delete the key to clear an override). Plate identity is
18
- * the plate index; deleting the last plate truncates its entry. Editing one plate's override invalidates only
19
- * that plate's cached result. Any key can be overridden: `printer_technology` routes that plate to the
20
- * FFF or SLA slicer (an SLA plate's grid cell is sized to its resin display), and a bed override
21
- * (`printable_area`/`printable_height`) resizes that plate's own grid cell. What a 3mf cannot represent —
22
- * a mixed-technology or mixed-bed project — is refused at project export with a typed error
23
- * (`error.code` `'UNSUPPORTED_MIXED_TECH_3MF'` / `'UNSUPPORTED_MIXED_BED_3MF'`); per-plate G-code/.sl1
24
- * exports always work. Defaults to `{}`.
25
- */
26
- plateSettings?: Record<number, SlicerSettings>
27
- /** React setState shape for {@link ViewportProps.plateSettings}. Defaults to a no-op. */
28
- setPlateSettings?: React.Dispatch<React.SetStateAction<Record<number, SlicerSettings>>>
29
- /**
30
- * Left process-panel slot — usually `<SettingsPanel embedded/>`. Defaults to null.
31
- *
32
- * Pass a FUNCTION to opt into the per-plate scope toggle (shown with more than one plate): in plate scope
33
- * the panel receives the selected plate's EFFECTIVE map and a setter that writes only the changed keys into
34
- * {@link ViewportProps.plateSettings}; `meta.overriddenKeys`/`meta.onRevertKey` drive the override badges
35
- * (`<SettingsPanel overriddenKeys={...} onRevertKey={...}/>`). In global scope the pair is simply
36
- * `settings`/`setSettings`. A plain node keeps the global-only binding.
37
- */
38
- processPanel?: React.ReactNode
39
- | ((settings: SlicerSettings, setSettings: React.Dispatch<React.SetStateAction<SlicerSettings>>,
40
- meta: { scope: 'global' | 'plate', selectedPlate: number, overriddenKeys: string[],
41
- onRevertKey: ((key: string) => void) | null }) => React.ReactNode)
42
- /** Motion-limits editor, folded into the printer card — usually `<SettingsPanel only={{builder:'TabPrinter::build_kinematics_page'}}/>`. */
43
- motionPanel?: React.ReactNode
44
- /**
45
- * Filament editor, folded into the filament card. Pass a function rather than a node: with more than one
46
- * extruder loaded the card projects that extruder's slice of the per-extruder columns and writes the form's
47
- * edits back at its index, so the panel must bind to the pair it is given.
48
- */
49
- filamentPanel?: React.ReactNode
50
- | ((settings: SlicerSettings, setSettings: React.Dispatch<React.SetStateAction<SlicerSettings>>) => React.ReactNode)
51
- /**
52
- * Per-panel visibility. Every panel is visible unless its key is explicitly `false`, so a host only opts out —
53
- * and a panel added in a later version does not disappear for hosts that listed the ones they wanted.
54
- *
55
- * A {@link LockablePanel} also accepts `'readonly'`: the panel is drawn but nothing inside it can be clicked,
56
- * typed into or tabbed to — including any node the host passed into it. That is the shape a host wants when it
57
- * presets the printer, process and filament itself and does not want the user changing them.
58
- *
59
- * Note what it locks: the UI path, not the value. `settings` is still the host's own prop, and other paths
60
- * inside the viewer still write it — importing a 3mf project applies that project's settings either way.
61
- */
62
- panels?: Partial<Record<ViewportPanel, boolean>> & Partial<Record<LockablePanel, boolean | 'readonly'>>
63
- /**
64
- * Behaviour switches, following the same opt-out rule as {@link ViewportProps.panels}: everything is on unless
65
- * its key is explicitly `false`. These are the things the component does *outside* its own box — take the page's
66
- * keyboard, load the WASM kernel, write to the console — which a host embedding it in a larger app may already
67
- * be doing itself. See {@link ViewportFeature}.
68
- */
69
- features?: Partial<Record<ViewportFeature, boolean>>
70
- /**
71
- * Intercepts every file the viewer would otherwise hand to the browser as a download — the 3mf project, the STL,
72
- * and each plate's G-code. Return anything truthy to say it is handled and suppress the download; return nothing
73
- * to let it proceed as well. This is the only way in: the save buttons live inside the component.
74
- *
75
- * ```jsx
76
- * <Viewport onExport={(blob, filename) => { upload(blob, filename); return true }} />
77
- * ```
78
- */
79
- onExport?: (file: Blob, filename: string) => boolean | void
80
- /**
81
- * G-code text to render instead of a slice result. Parsed into the same layer stream the kernel produces and
82
- * shown on the selected plate; the kernel is never started. While it is set, auto re-slice leaves that plate alone.
83
- */
84
- gcode?: string | null
85
- /**
86
- * An `.sl1` archive rendered as a raster preview — the SLA half of {@link ViewportProps.gcode}'s contract: it
87
- * lands on the selected plate and the kernel is never started. Set both and the G-code wins; one plate holds
88
- * one artifact.
89
- *
90
- * Two things it does that `gcode` does not. It writes to your `settings` — the archive's own job description,
91
- * `printer_technology` included, because an .sl1 opened in an FFF session has to switch it. And it reconstructs
92
- * a surface from the masks in the background, so the preview fills in a moment after the layers appear.
93
- *
94
- * Re-injects whenever the value's IDENTITY changes, so hold the File/buffer in state rather than building it
95
- * during render — a fresh `new Uint8Array(...)` each render re-imports each render. `{name, data}` exists
96
- * because the name is the import notice's subject and the filename a re-export hands back.
97
- */
98
- sl1?: File | Blob | ArrayBuffer | Uint8Array | { name?: string, data: ArrayBuffer | Uint8Array } | null
99
- /**
100
- * Content imported once on mount, through the same extension dispatch as a drop: models (STL/OBJ/3MF/AMF/PLY —
101
- * a 3mf project applies its settings, plates and painting), `.sl1` raster archives, and preset files
102
- * (`.json` / `.orca_printer` / `.orca_bundle` / `.orca_filament` / `.zip`). The `{name, data}` form exists
103
- * because the dispatch runs on the file NAME's extension. Deliberately mount-only — recreating the array on a
104
- * later render does not re-import; runtime loading is the picker, drop, or a remount.
105
- */
106
- files?: Array<File | { name: string, data: ArrayBuffer | Uint8Array }>
107
- /**
108
- * A token whose identity CHANGE requests one slice of the current plate — the host's Slice button:
109
- * keep a counter in state and bump it. The mount value is inert (0 and null both slice nothing), so is
110
- * setting it back to `null`. Ignored while a `gcode`/`sl1` injection holds the plate or the scene is
111
- * empty — the same conditions under which the built-in slice bar is not pressable. A change while a
112
- * slice is running cancels it and re-slices: the last request wins.
113
- */
114
- sliceRequest?: number | string | object | null
115
-
116
- /** Initial filament colours (hex), one per extruder. Defaults to the built-in T1/T2 pair. */
117
- defaultExtruderColors?: string[] | null
118
- /**
119
- * Start with auto re-slice on. Unlike the in-app toggle's original behaviour this also performs the FIRST slice,
120
- * which is what makes a panel-less embed able to slice at all.
121
- */
122
- defaultAutoSlice?: boolean
123
- /** Every value change in one channel. See {@link ViewportEvent}. */
124
- onEvent?: (event: ViewportEvent) => void
125
- /** A finished slice, fired where the result is cached — switching plate tabs does not re-fire it. */
126
- /** `throughput` is how fast the slice ran — see `SliceThroughput` in the engine entry. Absent on a kernel
127
- * result that carried none (a cached plate re-announced from before the field existed). */
128
- onSliced?: (result: {
129
- plate: number; stats: Record<string, unknown>; gcode: string
130
- throughput?: { ms: number; kernelMs: number | null; layersPerSecond: number; msPerMsegment: number | null }
131
- }) => void
132
- /**
133
- * An all-plates run as it moves: the run map on every change, `null` when none is on. `workers.pool` is how
134
- * many slice at once, `workers.kernel` which kernel loaded ('mt' threads / 'st'); each plate carries its state
135
- * and its own progress (0..1) and layers/second. Fired several times a second while a run is on.
136
- */
137
- onSliceRun?: (run: {
138
- workers: { pool: number; active: number; kernel: 'mt' | 'st' | null }
139
- plates: Record<number, { state: 'queued' | 'busy' | 'done' | 'failed'; progress: number; rate: number }>
140
- } | null) => void
141
- }
142
-
143
- /**
144
- * Behaviour keys accepted by {@link ViewportProps.features}. All default to enabled.
145
- *
146
- * - `shortcuts` — the keyboard bindings. They are installed on `window`, so while the viewer is mounted they fire
147
- * wherever focus is (except inside inputs) and `Ctrl+C` in particular preventDefaults. Turn them off when the
148
- * host page has its own.
149
- * - `warmup` — loading the WASM kernel on mount, ahead of the first slice. Off, nothing is downloaded or compiled
150
- * until something actually slices — which for a `gcode`-only viewer is never.
151
- * - `drop` — drag and drop onto the canvas.
152
- * - `filePicker` — the file dialog, from every button that opens it.
153
- * - `contextMenu` — the right-click menu. Note that the browser's own menu stays suppressed over the canvas either
154
- * way: OrbitControls preventDefaults `contextmenu` itself.
155
- * - `logs` — console diagnostics, from the component and from the slice worker.
156
- */
157
- export type ViewportFeature = 'shortcuts' | 'warmup' | 'drop' | 'filePicker' | 'contextMenu' | 'logs'
158
-
159
- /**
160
- * The panels that accept `'readonly'` as well as `true`/`false` — the right column and the cards in it. Everything
161
- * else takes a boolean only: locking the gizmo rail or the plate tabs is what `features` and `panels: false` are
162
- * for, and pretending otherwise would mean a `'readonly'` that silently does nothing on half the keys.
163
- *
164
- * `sidebar: 'readonly'` locks the whole column in one go, so the per-card keys are for mixing — a locked printer
165
- * card above a live object list, say.
166
- */
167
- export type LockablePanel =
168
- | 'sidebar' | 'printerCard' | 'filamentCard' | 'objectList' | 'towerCard'
169
- | 'previewControls' | 'processCard' | 'sliceBar'
170
-
171
- /** Panel keys accepted by {@link ViewportProps.panels}. `sidebar: false` hides the whole right column at once. */
172
- export type ViewportPanel =
173
- | 'topBar' | 'gizmoRail' | 'objectToolbar' | 'paintPanel' | 'statsCard' | 'plateBar' | 'emptyHint' | 'status'
174
- | 'sidebar' | 'printerCard' | 'filamentCard' | 'objectList' | 'previewControls' | 'processCard' | 'sliceBar'
175
- /** The horizontal move scrub under the canvas — how far into the top shown layer the print has got. Preview
176
- * and FFF only: a resin layer is cured in one exposure and has no intra-layer order to walk. */
177
- | 'moveBar'
178
- /** The over-the-bed warning, shown in Prepare when something leaves the printable area. */
179
- | 'bedWarn'
180
- /** The prime tower card. Only rendered anyway once a second filament exists. */
181
- | 'towerCard'
182
- /** The resin (SLA) card. Takes the filament card's place when the printer profile declares SLA. */
183
- | 'resinCard'
184
-
185
- /** Value changes reported through {@link ViewportProps.onEvent}. Not fired for the initial values. */
186
- export type ViewportEvent =
187
- | { type: 'canvasMode'; value: 'prepare' | 'preview' }
188
- | { type: 'objects'; value: Array<{ id: number; name: string; extruder: number; visible: boolean }> }
189
- | { type: 'selectedPlate'; value: number }
190
- | { type: 'plateCount'; value: number }
191
- | { type: 'extruderColors'; value: string[] }
192
- | { type: 'autoSlice'; value: boolean }
193
- | { type: 'slicing'; value: boolean }
194
- /** 0..1. Fires several times a second while slicing — throttle on the host side if that matters. */
195
- | { type: 'progress'; value: number }
196
- /**
197
- * Live throughput: layers finished per second over a 250ms window, `0` between slices. An SLA slice reports it
198
- * throughout. An FFF slice reports it only once the emission pass begins streaming layers — the earlier passes
199
- * publish no per-layer progress, so nothing is measured there and none is invented. For the whole-slice figure
200
- * use `throughput` from `onSliced`.
201
- */
202
- | { type: 'sliceRate'; value: number }
203
- | { type: 'viewType'; value: 'feature' | 'speed' | 'height' | 'width' | 'fan' | 'temp' | 'filament' }
204
- | { type: 'paintMode'; value: 'off' | 'enforcer' | 'blocker' | 'material' }
205
- | { type: 'layerCount'; value: number }
206
- | { type: 'layerRange'; value: { lo: number; hi: number } }
207
- /** The move scrub's position within the top shown layer; `max` is that layer's move count, extrusions and
208
- * travels together. Not fired while the whole layer is shown. */
209
- | { type: 'moveScrub'; value: { at: number; max: number } }
210
- | { type: 'error'; value: string }
211
- | { type: 'notice'; value: string }
212
-
213
- declare const Viewport: React.FC<ViewportProps>
1
+ // three-slicer/viewer — the permissive viewer (three-slicer-viewer, MIT) with the kernel plugged in.
2
+ export * from 'three-slicer-viewer'
3
+ import type { ViewportProps, SlicerHandle } from 'three-slicer-viewer'
4
+ /** The permissive `useSlicer` bound to the WASM kernel worker (three-slicer/client's makeSlicerWorker). */
5
+ export function useSlicer(deps: Record<string, unknown>): SlicerHandle
6
+ declare function Viewport(props: ViewportProps): JSX.Element
214
7
  export default Viewport