@crystaldesign/planner-2d-core

中文文档
26.12.4发布于 2026/10/23COMMERCIALTypeScriptESM + CJS近 30 天下载 6198

Browser-free 2D planner core: article SVG parsing, docking logic, dock transform math and collision geometry.

原始使用文档
文档目录3 节
  1. Modules
  2. Node usage
  3. Testing

@crystaldesign/planner-2d-core

Browser-free core of the 2D planner: article SVG parsing, docking logic, dock transform math and collision geometry. No fabric.js, no engine, no catalog API — runs in the browser and in plain Node (backend services, unit tests, agent testbeds).

Extraction concept and phase plan: docs/2d-planner-rework/CONCEPT.md. The ported logic is a behavior-faithful extraction of web-planner-logic's DockingPointHandler, the fabric-free SVGUtils methods and the docking math of DivaStandardPlanner.updateWorldPos (phase P1 — web-planner-logic still carries its own copy until P2 switches it over to this package).

Modules

ModuleContents
svg/getDockingPointLines, getPolygonPoints, getOltGeometry/getOlfGeometry, removeOlf/removeMask, getMinBorder (DOM-based, Node-safe), pathBoundingBox (full command set M L H V C S Q T A Z incl. Bezier extrema and arcs)
stretch/stretchArticleSvg — synchronous SAH/SAV stretch engine, behavior-faithful rewrite of the legacy ccCheckStretchAreas (OLT-then-OLF double pass, rounding rules, global-scale mode) with axis-abstracted element/path transformers and a warnings[] report; deviations: unknown path commands survive, unsupported stretch areas are ignored, viewBox scaling is applied exactly once
docking/DockingPoint, DockingPointHandler (pairing rules, checkDPsDoMatch public), narrow PlannerElement2D interface
transform/computeDockedTransform — pure world-transform math for a docked element
collision/segmentsIntersect (fabric parity), polygon intersection/containment, outlinesCollide
testbed/DockingScene + SimplePlannerElement — SVGs in, docking points/pairings/world positions out

Node usage

The parser needs a DOM. In the browser nothing is required; in Node a jsdom window is loaded lazily as fallback (configureDom(new JSDOM('').window) only when a custom DOM should be used):

import { DockingScene } from '@crystaldesign/planner-2d-core';

const scene = new DockingScene();
const sofa = scene.addArticle(sofaSvg, { layer: 20 });
const extension = scene.addArticle(extensionSvg, { layer: 20 });
const result = scene.tryDock(extension, sofa); // -> { docked, dockingType, rotDeg, worldPosCorner }

Logging is a no-op by default; inject one via setPlanner2DLogger (e.g. a DivaUtils/diva-backend-commons logger).

Testing

ctra test @crystaldesign/planner-2d-core

The suites run under testEnvironment: node with explicitly configured jsdom — proving the browser-free contract on every run.

版本与发布记录

@crystaldesign/planner-2d-core 共发布 134 个版本,首次发布于 2026/08/24;过去 12 个月发布了 134 个版本。

版本发布日期距今
26.12.4latest2026/10/2318 天前
26.12.4-rc.1rc2026/10/2318 天前
26.13.0-beta.33beta2026/10/2219 天前
26.13.0-beta.322026/10/2219 天前
26.13.0-beta.312026/10/2219 天前
26.13.0-beta.302026/10/2220 天前

关于 @crystaldesign/planner-2d-core 的常见问题

@crystaldesign/planner-2d-core 是什么?

Browser-free 2D planner core: article SVG parsing, docking logic, dock transform math and collision geometry.

如何安装 @crystaldesign/planner-2d-core?

在项目目录运行 npm install @crystaldesign/planner-2d-core,或使用 pnpm add / yarn add / bun add。

@crystaldesign/planner-2d-core 支持 TypeScript 吗?

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

@crystaldesign/planner-2d-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@crystaldesign/planner-2d-core 可以商用吗?

@crystaldesign/planner-2d-core 使用 COMMERCIAL 许可。声明的许可为 COMMERCIAL,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@crystaldesign/planner-2d-core 的下载量有多少?

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

@crystaldesign/planner-2d-core 还在维护吗?

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