npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@edv4h/usketch-shape-utils

v2.0.1

Published

uSketch v2 の shape プラグインを書くときに使う共通ユーティリティ集。 サードパーティが `@acme/usketch-plugin-shape-foo` のような独自 shape プラグインを実装する際、bounds 計算・ヒットテスト・リサイズ・GPU primitive の差し込みをここから取ってくる想定。

Readme

@edv4h/usketch-shape-utils

uSketch v2 の shape プラグインを書くときに使う共通ユーティリティ集。 サードパーティが @acme/usketch-plugin-shape-foo のような独自 shape プラグインを実装する際、bounds 計算・ヒットテスト・リサイズ・GPU primitive の差し込みをここから取ってくる想定。

React に依存しない純粋な関数群なので、サーバサイドでの shape データ処理にも使える。

Install

pnpm add @edv4h/usketch-shape-utils @edv4h/usketch-shared

公開 API

getBounds(data: ShapeData): BoundingBox

shape の AABB を返す。ほとんどの shape はこれをそのまま ShapeDefinition.getBounds に指定すれば OK。

Hit test

| 関数 | 用途 | |------|------| | aabbHitTest(data, point) | 矩形 AABB との当たり判定 | | ellipseHitTest(data, point) | 楕円との当たり判定 | | lineHitTest(data, point, tolerance?) | 線分との距離判定(デフォルト tolerance: 4px) | | pointInPolygon(point, polygon) | 任意多角形との当たり判定(三角形・六角形・星形など) |

回転に対応したい場合は、@edv4h/usketch-sharedwithRotation(hitTest) でラップする。

createResize(minW, minH): ResizeFn

8 方向(se / nw / ne / sw / e / w / n / s)のリサイズハンドルに対応した resize 関数を生成する。最小幅・最小高を渡す。

GPU primitive

WebGPU レンダラが有効な場合に使われる低レベル primitive を返すヘルパ。

| 関数 | 返す kind | |------|----------| | rectGpuPrimitive(data) | rect | | roundedRectGpuPrimitive(data) | rect(cornerRadius 自動計算) | | ellipseGpuPrimitive(data) | ellipse | | lineGpuPrimitive(data) | polyline |

使用例

import { DEFAULT_STYLE, type ShapeData, withRotation } from "@edv4h/usketch-shared";
import { createResize, getBounds, pointInPolygon } from "@edv4h/usketch-shape-utils";

function getHexagonPoints(data: ShapeData) {
  const cx = data.x + data.width / 2;
  const cy = data.y + data.height / 2;
  return Array.from({ length: 6 }, (_, i) => {
    const angle = (Math.PI / 3) * i - Math.PI / 2;
    return {
      x: cx + (data.width / 2) * Math.cos(angle),
      y: cy + (data.height / 2) * Math.sin(angle),
    };
  });
}

export const hexagonDefinition = {
  render: (data: ShapeData) => (
    <polygon
      points={getHexagonPoints(data).map((p) => `${p.x},${p.y}`).join(" ")}
      fill={data.style.fill}
    />
  ),
  getBounds,
  hitTest: withRotation((data, point) => pointInPolygon(point, getHexagonPoints(data))),
  resize: createResize(10, 10),
  createDefault: ({ id, x, y }) => ({
    id,
    type: "hexagon",
    x,
    y,
    width: 120,
    height: 104,
    style: { ...DEFAULT_STYLE },
  }),
};

プラグインとしての組み込み方は apps/docs の Plugin authoring ガイド を参照。

License

MIT