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 🙏

© 2025 – Pkg Stats / Ryan Hefner

leafer-x-snap

v1.0.7

Published

吸附插件,为 Leafer 应用提供元素自动吸附功能。

Downloads

174

Readme

leafer-x-snap

吸附插件,为 Leafer 应用提供元素自动吸附功能。

npm version npm downloads

安装

npm install leafer-x-snap

类型定义

type SnapConfig = {
  snapSize?: number;
  lineColor?: string;
  showLine?: boolean;
  strokeWidth?: number;
  dashPattern?: number[];
  isDash?: boolean;
  showLinePoints?: boolean;
  filter?: (element: IUI) => boolean;
};

基础使用

import { Snap } from 'leafer-x-snap';

const app = new App({
  view: window,
  editor: {}
});

const snap = new Snap(app, {
  snapSize: 5,
  strokeWidth: 2,
});

// 启用吸附功能
snap.enable(true);

可以在元素上设置 isSnap 属性来控制元素是否参与吸附计算,默认为 true

new Rect({ isSnap: false });
// or
rect.isSnap = false;

API 文档

构造函数

constructor(app: IApp, config?: SnapConfig)

参数

  • app: Leafer App 实例
  • config: 可选的配置项

配置项

| 属性 | 类型 | 默认值 | 说明 | | ---------------- | ------------------------- | --------- | -------------------------- | | snapSize | number | 5 | 吸附距离范围 | | lineColor | string | '#D2D4D7' | 吸附辅助线颜色 | | showLine | boolean | true | 是否显示辅助线 | | strokeWidth | number | 1 | 线宽 | | dashPattern | number[] | [5] | 虚线样式 | | isDash | boolean | true | 是否使用虚线 | | showLinePoints | boolean | true | 是否显示辅助线端点 | | filter | (element: IUI) => boolean | undefined | 过滤需要参与吸附计算的元素 |

实例方法

enable(enable: boolean)

控制吸附功能的开启/关闭

// 启用吸附
snap.enable(true)

// 禁用吸附
snap.enable(false)

destroy()

销毁吸附实例

snap.destroy()

changeFilter(filter: (element: IUI) => boolean)

更改元素过滤器函数

// 示例:只对矩形元素进行吸附
snap.changeFilter((element) => element.tag === 'Rect')

使用示例

// 创建带配置的实例
const snap = new Snap(app, {
  snapSize: 10,
})

// 启用吸附功能
snap.enable(true)

注意事项

  1. 必须传入有效的 Leafer App 实例
  2. 吸附功能默认是禁用的,需要调用 enable(true) 来启用
  3. 吸附功能会自动检测视口内的元素作为吸附参考点
  4. 建议在页面元素加载完成后再初始化 Snap 实例
  5. 必须安装editor插件