@chestnutlabs/gcode-preview-react 0.2.0 → 0.4.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/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install @chestnutlabs/gcode-preview-react three
|
|
|
10
10
|
|
|
11
11
|
(`three` is a peerDependency of the renderer, supported range `^0.178.0` — npm ≥ 7 installs
|
|
12
12
|
it automatically; pnpm/yarn users add it explicitly. See the
|
|
13
|
-
[support policy](
|
|
13
|
+
[support policy](https://github.com/ChestnutLabs/gcode-preview/blob/dev/docs/reference/support-policy.md).)
|
|
14
14
|
|
|
15
15
|
## Ready-to-use component
|
|
16
16
|
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { BuildVolumeDef, CameraMode, ColorMode, QualityMode, Theme, TubeOptions } from '@chestnutlabs/gcode-renderer-three';
|
|
2
2
|
import type { MachineGeometry, ProgressObservation } from '@chestnutlabs/toolpath-core';
|
|
3
3
|
import type { WireParseOptions, WorkerLike } from '@chestnutlabs/gcode-parser';
|
|
4
|
-
import { type GcodePreviewHandle, type UseGcodePreviewOptions } from './use-gcode-preview.js';
|
|
4
|
+
import { type GcodePreviewHandle, type RendererMode, type UseGcodePreviewOptions } from './use-gcode-preview.js';
|
|
5
5
|
export type GcodePreviewSource = Uint8Array | ArrayBuffer | File | null;
|
|
6
6
|
export interface GcodePreviewProps {
|
|
7
7
|
/** The one prop needed in practice: bytes/File to parse. Changing it re-parses. */
|
|
8
8
|
source?: GcodePreviewSource;
|
|
9
9
|
parseOptions?: WireParseOptions;
|
|
10
|
+
/**
|
|
11
|
+
* DD-014 D5: which renderer backs the preview — `'3d'` (default, Three.js) or `'2d'` (the
|
|
12
|
+
* low-resource Canvas layer view). Three.js is loaded on demand, so `'2d'` never ships it.
|
|
13
|
+
*/
|
|
14
|
+
renderer?: RendererMode;
|
|
15
|
+
/** 2D only (`renderer="2d"`): preceding "ghost" layers beneath the active one (default 1, floor 0). */
|
|
16
|
+
adjacentLayers?: number;
|
|
10
17
|
/** Consumer-configured volume — wins over file-discovered geometry (DD-005 precedence). */
|
|
11
18
|
buildVolume?: BuildVolumeDef | MachineGeometry;
|
|
12
19
|
quality?: QualityMode | 'auto';
|
|
@@ -20,7 +27,11 @@ export interface GcodePreviewProps {
|
|
|
20
27
|
layerRange?: [number, number] | null;
|
|
21
28
|
/** Scrub cut (IR segment index); null shows everything up to the layer range. */
|
|
22
29
|
scrub?: number | null;
|
|
30
|
+
/** Time-based scrub cut in ms of print time (#181); null clears it. */
|
|
31
|
+
scrubTime?: number | null;
|
|
23
32
|
showTravel?: boolean;
|
|
33
|
+
/** DD-016 (#182): show slicer wipe moves. Default true; set false to hide the wipe chunk. */
|
|
34
|
+
showWipe?: boolean;
|
|
24
35
|
/** DD-009 D1 (#148): opt-in retraction/deretraction markers. */
|
|
25
36
|
showRetractions?: boolean;
|
|
26
37
|
/** DD-006 live progress observation; null hides the overlay. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcode-preview-component.d.ts","sourceRoot":"","sources":["../src/gcode-preview-component.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,SAAS,EACT,WAAW,EACX,KAAK,EACL,WAAW,EACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACxF,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAEL,KAAK,kBAAkB,EAEvB,KAAK,sBAAsB,EAC5B,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,GAAG,IAAI,CAAC;AAExE,MAAM,WAAW,iBAAiB;IAChC,mFAAmF;IACnF,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,YAAY,CAAC,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O,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC1D;AAkID,8EAA8E;AAC9E,eAAO,MAAM,YAAY,kHAA+B,CAAC"}
|
|
@@ -16,12 +16,14 @@ function GcodePreviewImpl(props, ref) {
|
|
|
16
16
|
const preview = useGcodePreview({
|
|
17
17
|
createWorker: props.createWorker,
|
|
18
18
|
renderer: {
|
|
19
|
+
mode: props.renderer,
|
|
19
20
|
buildVolume: isMachine ? undefined : props.buildVolume,
|
|
20
21
|
quality: props.quality ?? 'auto',
|
|
21
22
|
cameraMode: props.cameraMode ?? 'perspective',
|
|
22
23
|
theme: props.theme,
|
|
23
24
|
colorMode: props.colorMode,
|
|
24
25
|
tube: props.tube,
|
|
26
|
+
adjacentLayers: props.adjacentLayers,
|
|
25
27
|
...props.rendererOptions
|
|
26
28
|
},
|
|
27
29
|
parseDefaults: props.parseOptions
|
|
@@ -71,7 +73,7 @@ function GcodePreviewImpl(props, ref) {
|
|
|
71
73
|
});
|
|
72
74
|
}, []);
|
|
73
75
|
// ---- prop wiring: each prop is a thin call into the hook (D1 shell rule) ----
|
|
74
|
-
const { source, layerRange, scrub, showTravel, showRetractions, colorMode, quality, cameraMode, theme, buildVolume, progress } = props;
|
|
76
|
+
const { source, layerRange, scrub, scrubTime, showTravel, showWipe, showRetractions, colorMode, quality, cameraMode, theme, buildVolume, progress } = props;
|
|
75
77
|
useEffect(() => {
|
|
76
78
|
if (source !== null && source !== undefined)
|
|
77
79
|
void preview.parse(source, cbRef.current.parseOptions);
|
|
@@ -85,9 +87,15 @@ function GcodePreviewImpl(props, ref) {
|
|
|
85
87
|
useEffect(() => {
|
|
86
88
|
preview.controls.setScrubPosition(scrub ?? null);
|
|
87
89
|
}, [scrub]);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
preview.controls.setScrubTime(scrubTime ?? null);
|
|
92
|
+
}, [scrubTime]);
|
|
88
93
|
useEffect(() => {
|
|
89
94
|
preview.controls.setKindVisible('travel', showTravel ?? true);
|
|
90
95
|
}, [showTravel]);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
preview.controls.setKindVisible('wipe', showWipe ?? true);
|
|
98
|
+
}, [showWipe]);
|
|
91
99
|
useEffect(() => {
|
|
92
100
|
preview.controls.setShowRetractions(showRetractions ?? false);
|
|
93
101
|
}, [showRetractions]);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { GcodeParseSession, WireParseOptions } from '@chestnutlabs/gcode-parser';
|
|
2
|
-
import type { ToolpathRenderer } from '@chestnutlabs/gcode-renderer-three';
|
|
3
2
|
import type { MappedProgress, ProgressObservation } from '@chestnutlabs/toolpath-core';
|
|
4
|
-
import { type GcodePreviewControls, type GcodePreviewState, type ParseOutcome, type PreviewControllerOptions, type PreviewEvent } from '@chestnutlabs/gcode-preview-core';
|
|
5
|
-
export type { GcodePreviewControls, GcodePreviewState, ParseOutcome, PreviewEvent } from '@chestnutlabs/gcode-preview-core';
|
|
3
|
+
import { type GcodePreviewControls, type GcodePreviewState, type ParseOutcome, type PreviewControllerOptions, type PreviewEvent, type PreviewRenderer } from '@chestnutlabs/gcode-preview-core';
|
|
4
|
+
export type { GcodePreviewControls, GcodePreviewState, ParseOutcome, PreviewEvent, PreviewRenderer, RendererMode } from '@chestnutlabs/gcode-preview-core';
|
|
6
5
|
/** React-facing options — identical to the controller's (the alias is the public name). */
|
|
7
6
|
export type UseGcodePreviewOptions = PreviewControllerOptions;
|
|
8
7
|
export interface GcodePreviewHandle {
|
|
@@ -18,7 +17,7 @@ export interface GcodePreviewHandle {
|
|
|
18
17
|
controls: GcodePreviewControls;
|
|
19
18
|
raw: {
|
|
20
19
|
session: GcodeParseSession;
|
|
21
|
-
renderer: () =>
|
|
20
|
+
renderer: () => PreviewRenderer | null;
|
|
22
21
|
};
|
|
23
22
|
onEvent(cb: (e: PreviewEvent) => void): () => void;
|
|
24
23
|
dispose(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-gcode-preview.d.ts","sourceRoot":"","sources":["../src/use-gcode-preview.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"use-gcode-preview.d.ts","sourceRoot":"","sources":["../src/use-gcode-preview.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EAEjB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,kCAAkC,CAAC;AAG1C,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,YAAY,EACb,MAAM,kCAAkC,CAAC;AAE1C,2FAA2F;AAC3F,MAAM,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAE9D,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,SAAS,EAAE,CAAC,EAAE,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,CAAC;IAClD,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9F,MAAM,IAAI,IAAI,CAAC;IACf,eAAe,CAAC,GAAG,EAAE,mBAAmB,GAAG,cAAc,GAAG,IAAI,CAAC;IACjE,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC;IACnD,aAAa,IAAI,IAAI,CAAC;IACtB,2EAA2E;IAC3E,KAAK,EAAE,iBAAiB,CAAC;IACzB,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,GAAG,EAAE;QAAE,OAAO,EAAE,iBAAiB,CAAC;QAAC,QAAQ,EAAE,MAAM,eAAe,GAAG,IAAI,CAAA;KAAE,CAAC;IAC5E,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACnD,OAAO,IAAI,IAAI,CAAC;CACjB;AAUD,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,kBAAkB,CAiExF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chestnutlabs/gcode-preview-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Thin React integration for the Chestnut Labs G-code viewer (DD-007 D1 amendment): useGcodePreview hook + GcodePreview component as a reactivity bridge over @chestnutlabs/gcode-preview-core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gcode",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"test": "vitest run"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@chestnutlabs/gcode-parser": "0.
|
|
53
|
-
"@chestnutlabs/gcode-preview-core": "0.
|
|
54
|
-
"@chestnutlabs/gcode-renderer-three": "0.
|
|
55
|
-
"@chestnutlabs/toolpath-core": "0.
|
|
52
|
+
"@chestnutlabs/gcode-parser": "0.4.0",
|
|
53
|
+
"@chestnutlabs/gcode-preview-core": "0.4.0",
|
|
54
|
+
"@chestnutlabs/gcode-renderer-three": "0.4.0",
|
|
55
|
+
"@chestnutlabs/toolpath-core": "0.4.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": "^18.0.0 || ^19.0.0"
|