@chestnutlabs/gcode-preview-core

中文文档
0.21.1发布于 2026/11/04MITTypeScriptES Module构建来源已验证近 30 天下载 2995

Framework-neutral preview controller for the Chestnut Labs G-code viewer (DD-007 §4.6): the shared engine glue, state model, and TypeScript contracts beneath the Vue/React/Svelte adapters.

原始使用文档

@chestnutlabs/gcode-preview-core

The framework-neutral preview controller for the Chestnut Labs G-code Preview stack (design: DD-007). This is the single engine under the Vue, React, Svelte, and Web Component (@chestnutlabs/gcode-preview-element) adapters — parse session + renderer + progress mapper glued into one lifecycle with an immutable-snapshot state model (getState() returns a new identity per mutation; onStateChange notifies), which every framework's reactivity can bridge cheaply.

import { createPreviewController } from '@chestnutlabs/gcode-preview-core';

const preview = createPreviewController();
preview.bindCanvas(canvas);              // resize-observed
await preview.parse(bytes);              // worker parse + progressive build
preview.controls.setLayerRange(0, 42);   // scrub / quality / colors / bed / frame ...
preview.observeProgress(obs);            // DD-006 live progress
preview.onStateChange(cb);               // snapshots: summaries only, never toolpath buffers
preview.dispose();

parse() hands a Uint8Array or ArrayBuffer to the parse worker without copying it, so the buffer you passed is empty afterwards. To parse the same file again (for example a different plate via parse(bytes, { plate: 1 })), keep your own copy and pass bytes.slice() each time. Passing the already-transferred bytes fails with E_POST_FAILED, and the preview keeps working.

Building an adapter for another framework? The portable behavioral suite is exported from @chestnutlabs/gcode-preview-core/testing — runBehavioralSuite(...) is the same parity contract the Vue, React, Svelte, and Web Component adapters pass in CI, and it is the anti-drift firewall for any new integration.

Part of Chestnut Labs G-code Preview · MIT

版本与发布记录

@chestnutlabs/gcode-preview-core 共发布 25 个版本,首次发布于 2026/07/24;过去 12 个月发布了 25 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.21.1latest2026/11/045 天前
0.21.02026/10/2911 天前
0.20.12026/09/032 个月前
0.20.02026/08/312 个月前
0.19.02026/08/282 个月前
0.18.02026/08/282 个月前

关于 @chestnutlabs/gcode-preview-core 的常见问题

@chestnutlabs/gcode-preview-core 是什么?

Framework-neutral preview controller for the Chestnut Labs G-code viewer (DD-007 §4.6): the shared engine glue, state model, and TypeScript contracts beneath the Vue/React/Svelte adapters.

如何安装 @chestnutlabs/gcode-preview-core?

在项目目录运行 npm install @chestnutlabs/gcode-preview-core,或使用 pnpm add / yarn add / bun add。

@chestnutlabs/gcode-preview-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@chestnutlabs/gcode-preview-core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@chestnutlabs/gcode-preview-core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@chestnutlabs/gcode-preview-core 可以商用吗?

@chestnutlabs/gcode-preview-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@chestnutlabs/gcode-preview-core 的下载量有多少?

根据 npm 官方下载统计,@chestnutlabs/gcode-preview-core 在 2026/10/10 – 2026/11/08 这 30 天内被下载 2,995 次,日均约 100 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@chestnutlabs/gcode-preview-core 还在维护吗?

最新版本 0.21.1 发布于 2026/11/04(5 天前);至今共发布 25 个版本,其中过去 12 个月发布了 25 个;首次发布于 2026/07/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。