dsh-cad 0.14.0 → 0.15.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
@@ -41,8 +41,9 @@ Cumulative downloads from the npm registry, refreshed daily by CI:
41
41
 
42
42
  | Capability | Description |
43
43
  | --- | --- |
44
- | ⚙️ Single-kernel architecture | **occt.ts as the primary modeling kernel** (true B-splines, native shell/draft, centroid); opencascade.js stays only as the fallback backend; the old "no editing after shell" seam is gone — fillet/chamfer/boolean keep working after shelling |
44
+ | ⚙️ Kernel chain: cadorange → occt.ts → opencascade.js | Modeling goes through **[cadorange](https://github.com/LAU-MARS/cadorange)** (the agent-native CAD runtime wrapping the same occt.ts/OCCT WASM; public API + the supported `cadorange/occt` escape hatch for meshing/HLR/wire construction); the direct occt.ts adapter and opencascade.js stay as fallback tiers — `DSH_CAD_KERNEL` pins one explicitly. The old "no editing after shell" seam is gone — fillet/chamfer/boolean keep working after shelling |
45
45
  | 🔍 CAD viewing | STL / OBJ / STEP / IGES / BREP / DCPRT (3D), DXF / SVG (2D); interactive viewport in the resident right panel (orbit / zoom / wireframe / pan), with a one-line result row in the conversation |
46
+ | 🌗 Dark-mode surfaces | Every rendered surface follows the host theme — viewport slab, DXF/drawing strokes, the Three.js grid / XYZ triad / feature edges / default mesh color / sketch overlays, and the ViewCube plate; a theme flip restyles mounted viewers live. Overrides: `--dsh-cad-bg`, `--dsh-cad-stroke`, `--dsh-cad-paper` |
46
47
  | 🧭 CAD editor interactions | Onshape-style ViewCube (26-zone click-to-orient), hover/click face & edge picking with live measurement (area mm² / length mm), Faces+Edges / Faces / Wireframe render modes, switchable BRep demo parts (bracket / flange / shaft) |
47
48
  | 🏗️ Parametric modeling | Primitives, profile extrusion, **loft**, **sweep**, **revolve**, booleans, all-edge fillet/chamfer, **shell**, **draft**, **patterns** (linear/circular), transforms; profiles take **curve segments** (arcs/circles exact BRep; B-splines sampled approximation) — exact OCCT BRep, not a mesh approximation. `cad_loft` sections accept **curves** too: point loops, `{through}` splines or planar `{profile}` chains; `smooth: true` fits a **periodic B-spline** through point loops — one continuous B-spline lateral face instead of planar strips meeting at G0 creases |
48
49
  | ✏️ Named sketches | Standalone named profiles (Sketch1…) kept in the document (`cad_sketch_new` / `edit` / `list` / `delete`); extrude/revolve/sweep reference them **by name**, and `cad_sketch_edit` rewrites the definition in place + replays the log, rebuilding every dependent feature — the parametric loop. Sketches render as Onshape-style **blue curves + plane frame** in the viewport (refreshing live on edit), listed in a left-side **feature tree** (sketches + features, eye-toggle visibility, click-to-highlight bodies) over the Part tab |
@@ -213,12 +214,15 @@ cad_view(path) modeling tools (cad_create_prim, …)
213
214
  exponential-map rotation, radians). Solver capability is staged
214
215
  (point-distance-to-origin today) — the plumbing contract is finished and needs
215
216
  no changes as it grows
216
- - **Single-kernel architecture**: the primary modeling kernel is
217
- **occt.ts** — primitives, curve-segment profiles (TRUE B-spline
218
- interpolation), loft/sweep/revolve, booleans, fillet/chamfer, shell/draft,
219
- mirror (composed as scale(-1) + a π rotation) and centroid all live in one
220
- session; engineering-drawing HLR takes the shape directly (zero STEP hops);
221
- editing after shelling is seamless (the old hosted-body seam is deleted).
217
+ - **Kernel chain**: modeling goes through **cadorange** (agent-native CAD
218
+ runtime; public build123d-style API for prims/curve-segment profiles (TRUE
219
+ B-spline interpolation)/loft/sweep/revolve/booleans (cleaned by default)/
220
+ fillet/chamfer/shell/draft/native mirror/centroid, plus the supported
221
+ `cadorange/occt` escape hatch for viewer tessellation, engineering-drawing
222
+ HLR (zero STEP hops, one wasm session) and wire construction); the direct
223
+ occt.ts adapter and opencascade.js stay as fallback tiers
224
+ (`DSH_CAD_KERNEL` pins one; see docs/cadorange-integration.md for the
225
+ verb-by-verb mapping). Editing after shelling is seamless.
222
226
  opencascade.js remains as the FALLBACK backend (auto-selected when occt.ts
223
227
  cannot load). Assembly STEP export writes a **structured document** (occt.ts
224
228
  `writeStepDocument`): one root product plus one named, placed child
@@ -230,6 +234,36 @@ cad_view(path) modeling tools (cad_create_prim, …)
230
234
  by the host module table), Z-up CAD convention, empty scene with XYZ axis labels
231
235
  and a ground grid always displayed
232
236
 
237
+ ## Theming (dark mode)
238
+
239
+ The viewer follows the host appearance automatically. DSH publishes the theme as
240
+ `color-scheme` on `<html>` plus `body[data-ds-dark-theme]`; the plugin resolves
241
+ that (falling back to `prefers-color-scheme`) and themes every surface the host
242
+ tokens cannot reach:
243
+
244
+ - the viewport slab behind the transparent WebGL canvas and 2D scenes,
245
+ - default 2D entity strokes (DXF / engineering-drawing entities),
246
+ - the Three.js ground grid, XYZ axis triad/labels, feature edges, default mesh
247
+ color and sketch overlays,
248
+ - the ViewCube face plate (canvas texture).
249
+
250
+ A theme flip restyles mounted cards and the resident panel live — no reload and
251
+ no lost camera. Engineering drawings loaded as SVG keep a white sheet; in dark
252
+ mode it is framed as paper on the dark slab instead of filling the viewport.
253
+
254
+ Hosts can override the surfaces the plugin owns; an explicit definition wins in
255
+ either theme:
256
+
257
+ | CSS variable | Applies to | Default |
258
+ | --- | --- | --- |
259
+ | `--dsh-cad-bg` | viewport background (any CSS `background` value) | light `#f5f6f8→#e9ecf0`, dark `#1b1b1c→#151517` |
260
+ | `--dsh-cad-stroke` | default 2D entity stroke | `#4c5561` light / `#c8ced6` dark |
261
+ | `--dsh-cad-paper` | drawing paper behind SVG sheets | `#ffffff` |
262
+
263
+ ```css
264
+ :root { --dsh-cad-bg: #0b0d10; } /* flat canvas in both themes */
265
+ ```
266
+
233
267
  ## Tests
234
268
 
235
269
  ```sh
package/README.zh-CN.md CHANGED
@@ -38,8 +38,9 @@ npm 官方源的累计下载量,由 CI 每日刷新:
38
38
 
39
39
  | 能力 | 说明 |
40
40
  | --- | --- |
41
- | ⚙️ 单内核架构 | **occt.ts 为主建模内核**(真 BSpline、抽壳/拔模原生、质心),opencascade.js 仅作为加载失败时的降级后端;旧版的「抽壳后不可编辑」接缝消失——抽壳/拔模后可继续圆角/倒角/布尔 |
41
+ | ⚙️ 内核链:cadorange → occt.ts → opencascade.js | 建模经 **[cadorange](https://github.com/LAU-MARS/cadorange)**(agent 原生 CAD 运行时,底层同一 occt.ts/OCCT WASM;公共 API + 官方 `cadorange/occt` 逃生口承担网格/HLR/线构造),occt.ts 直连与 opencascade.js 保留为回退层级——`DSH_CAD_KERNEL` 可显式指定。旧版的「抽壳后不可编辑」接缝消失——抽壳/拔模后可继续圆角/倒角/布尔 |
42
42
  | 🔍 CAD 查看 | STL / OBJ / STEP / IGES / BREP / DCPRT(3D),DXF / SVG(2D),右侧常驻面板交互视口(轨道旋转 / 缩放 / 线框 / 平移),对话中只留一行结果摘要 |
43
+ | 🌗 深色模式绘制面 | 所有绘制面跟随宿主主题——视口底板、DXF/工程图描边、Three.js 网格 / XYZ 轴 / 特征边 / 默认网格色 / 草图覆盖层,以及 ViewCube 面板;主题切换实时重绘已挂载的查看器。覆盖钩子:`--dsh-cad-bg`、`--dsh-cad-stroke`、`--dsh-cad-paper` |
43
44
  | 🧭 CAD 编辑器交互 | Onshape 风格 ViewCube(26 区域点击定向)、悬停/点选面与边实时测量(面积 mm² / 长度 mm)、面+边 / 面 / 线框三种渲染模式、支架 / 法兰 / 轴 BRep 示例件一键切换 |
44
45
  | 🏗️ 参数化建模 | 基本体、轮廓拉伸、**放样**、**扫掠**、**旋转体**、布尔、全边圆角/倒角、**抽壳**、**拔模**、**阵列(线性/圆周)**、变换;轮廓支持**曲线段**(圆弧/圆为精确 BRep,B 样条为采样近似)—— OCCT 精确 BRep,非网格近似 |
45
46
  | ✏️ 命名草图 | 文档中独立的可命名轮廓(Sketch1…):`cad_sketch_new` / `edit` / `list` / `delete`;拉伸/旋转/扫掠**按名字引用**,`cad_sketch_edit` 原位改写定义并全量重放,所有引用特征级联重建——参数化闭环。草图以 Onshape 式**蓝色曲线 + 平面框**在视口中实时渲染(回改即刷新),并列于零件页签左侧的**特征树**(草图 + 特征、眼睛显隐、点选高亮实体) |
@@ -196,10 +197,12 @@ cad_view(path) 建模工具(cad_create_prim 等)
196
197
  原样透出给 LLM。装配实例位姿(平移 + XYZ 欧拉度)与求解器 rigid3(平移 + 指数映射
197
198
  旋转,弧度)双向映射。求解器能力按阶段推进(当前支持点到原点距离),管道契约
198
199
  已就绪、无需随求解器成长改动
199
- - **单内核架构**:建模主内核为 **occt.ts**——prims/曲线段轮廓
200
- (真 BSpline 插值)/放样/扫掠/旋转/布尔/圆角/倒角/抽壳/拔模/镜像(scale(-1)+
201
- 旋转 π 组合)/质心全在一个会话内,工程图 HLR 直接吃 shape(零 STEP 中转),
202
- 抽壳后继续编辑无缝(旧托管接缝已删除)。opencascade.js 保留为**降级后端**
200
+ - **内核链**:建模经 **cadorange**(agent 原生 CAD 运行时;build123d 风格
201
+ 公共 API 承担 prims/曲线段轮廓(真 BSpline 插值)/放样/扫掠/旋转/布尔
202
+ (默认同域清理)/圆角/倒角/抽壳/拔模/原生镜像/质心,官方 `cadorange/occt`
203
+ 逃生口承担查看器网格、工程图 HLR(零 STEP 中转、单一 wasm 会话)与线构造);
204
+ occt.ts 直连与 opencascade.js 保留为回退层级(`DSH_CAD_KERNEL` 可显式指定,
205
+ 动词级映射见 docs/cadorange-integration.md)。抽壳后继续编辑无缝。opencascade.js 保留为**降级后端**
203
206
  (occt.ts 加载失败时自动启用)。装配体 STEP 导出为**结构化文档**(occt.ts
204
207
  `writeStepDocument`):一个根产品 + 每实例一个命名、带位姿的子产品——
205
208
  实例分离在文件中保留(STL 仍为单一熔合网格;降级后端同样走 fuse)。fuse
@@ -208,6 +211,33 @@ cad_view(path) 建模工具(cad_create_prim 等)
208
211
  - **客户端**:esbuild 单文件 CJS 工厂(three.js 内联 ~560KB,react 由宿主模块表提供),
209
212
  Z-up CAD 惯例,带 XYZ 轴标签与地面网格的空场景常驻显示
210
213
 
214
+ ## 主题(深色模式)
215
+
216
+ 查看器自动跟随宿主外观。DSH 通过 `<html>` 上的 `color-scheme` 与
217
+ `body[data-ds-dark-theme]` 发布主题;插件据此解析(无信号时回退到
218
+ `prefers-color-scheme`),并为主题 token 覆盖不到的所有绘制面着色:
219
+
220
+ - 透明 WebGL 画布与 2D 场景背后的视口底板;
221
+ - 2D 实体默认描边(DXF / 工程图实体);
222
+ - Three.js 地面网格、XYZ 轴与轴标签、特征边、默认网格色与草图覆盖层;
223
+ - ViewCube 面板贴图(canvas 纹理)。
224
+
225
+ 主题切换会实时重绘已挂载的卡片与右侧常驻面板——无需刷新,也不丢失视角。
226
+ 以 SVG 载入的工程图仍是一张白纸:深色模式下它作为「纸」被框在深色底板上,
227
+ 而不是占满整个视口。
228
+
229
+ 宿主可覆盖插件自有的绘制面(显式定义在明暗两种主题下都优先):
230
+
231
+ | CSS 变量 | 作用 | 默认值 |
232
+ | --- | --- | --- |
233
+ | `--dsh-cad-bg` | 视口背景(任意 CSS `background` 值) | 浅色 `#f5f6f8→#e9ecf0`,深色 `#1b1b1c→#151517` |
234
+ | `--dsh-cad-stroke` | 2D 实体默认描边 | 浅色 `#4c5561` / 深色 `#c8ced6` |
235
+ | `--dsh-cad-paper` | SVG 图纸背后的纸面 | `#ffffff` |
236
+
237
+ ```css
238
+ :root { --dsh-cad-bg: #0b0d10; } /* 两种主题下都使用纯色底板 */
239
+ ```
240
+
211
241
  ## 测试
212
242
 
213
243
  ```sh