@edv4h/usketch-tool-helpers

中文文档
0.8.6发布于 2026/11/10MITTypeScriptES Module构建来源已验证近 30 天下载 3026
原始使用文档
文档目录5 节
  1. Install
  2. 公開 API
  3. Session helpers
  4. Pure helpers
  5. ドキュメント

@edv4h/usketch-tool-helpers

uSketch v2 のツールプラグインで再利用可能な state machine helper 集。

@edv4h/usketch-plugin-tool-select で baked されていた drag / resize / rotate / marquee / hover のロジックを単独で取り出して公開しており、サードパーティが「ドラッグで描画」「ハンドルでリサイズ」「マーキーで矩形選択」といったツールを書くときに、コアと同じ挙動 (snap・undo・子要素追従・handle flip 等) を 30 行程度で揃えられる。

@edv4h/usketch-shared と @edv4h/usketch-store にしか依存しないので、React なしのサーバサイド計算でも使える。

Install

pnpm add @edv4h/usketch-tool-helpers @edv4h/usketch-shared @edv4h/usketch-store

公開 API

Session helpers

各 helper は pointerdown で生成、pointermove で update(event)、pointerup で commit() するセッションを返す。commit() は undo 用 Command を返すので、呼び出し側で ctx.commands.execute(...) する。

関数用途
startDragSession(opts)選択した shape (子孫含む) を pointer delta だけ平行移動
startResizeSession(opts)single / multi 両対応のリサイズ。8 方向ハンドル、flip 検出、aspect 維持
startRotateSession(opts)中心点回りで回転、shift で 15° snap、子要素の剛体回転
startMarqueeSession(opts)intersect / contain (alt) の矩形選択

Pure helpers

関数用途
trackHover(ctx, event)hover 中の cursor / shape ID / handle hit を返す
findShapeAtPoint(ctx, point)shape vs container の選択優先度を考慮した hit test
findShapesInRect(ctx, rect, mode)marquee 風の矩形 hit test
findHandleAtScreenPoint(...)screen 座標での 8 方向ハンドル hit test
findRotationHandleAtScreenPoint(...)corner 外側の回転ハンドル hit test
getCursorForHandle(handle) / getRotatedCursorForHandle(handle, deg)カーソル文字列生成
computeRawBounds, applyFlip, getAnchorEdges, fixAnchorDrift, computeRelativeProps, computeMultiResizeUpdatesリサイズ計算の構成要素

ドキュメント

英: Building a Tool Plugin 日: ツールプラグインの作り方

版本与发布记录

@edv4h/usketch-tool-helpers 共发布 29 个版本,首次发布于 2026/05/25;过去 12 个月发布了 29 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.8.6latest2026/11/103 天前
0.8.52026/11/103 天前
0.8.42026/11/067 天前
0.8.22026/11/0310 天前
0.8.12026/11/0211 天前
0.8.02026/10/2519 天前

关于 @edv4h/usketch-tool-helpers 的常见问题

如何安装 @edv4h/usketch-tool-helpers?

在项目目录运行 npm install @edv4h/usketch-tool-helpers,或使用 pnpm add / yarn add / bun add。

@edv4h/usketch-tool-helpers 支持 TypeScript 吗?

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

@edv4h/usketch-tool-helpers 支持 ESM 还是 CommonJS?

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

@edv4h/usketch-tool-helpers 可以商用吗?

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

@edv4h/usketch-tool-helpers 的下载量有多少?

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

@edv4h/usketch-tool-helpers 还在维护吗?

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