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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ben-sketch

v1.3.18

Published

A sketch component used canvas with powerfull feature and easy to use.

Downloads

12

Readme

ben-sketch

screen shot

arrow

arrow

line

line

rect

rect

text

text

ease

ease

ellipse

ease

Usage

import js and set a div element for init the sketch instance.

// html
<script type="text/javascript" src="//{you path to the dist file}/dist/sketch.js"></script>
<div id="sketch"></div>
// js
const options = {
    container: document.getElementById('sketch')
}
const sketch = new Sketch(options);

Options

| Options | Type | Example | description | | ------ | --------- | ----------- | --------- | | container | DOM (require) | document.getElementById('sketch') | 用来实例化的DOM节点 | | textSize | Int | 14(default) | 设置文字工具的文字大小 | | textLineHeight | Int | 18 (default) | 设置文字工具的文字行高 |

Api Method

| method | arguments | description | | ------ | --------- | ----------- | | setTool(Enum toolName) | Enum('line', 'rect', 'text', 'ease', 'ellipse') | Set the current tool of sketch instance | | setColor(String color) | String 'rgb(0,255,255)' or '#ff0' or 'rgba(255,255,255,0.5)' | Set the current color of sketch instance | | clear | (empty) | Clear all draws of the sketch instance | | draw(type, options) | | Draw the data to sketch |

example
const sketch = new Sketch({
    container: containerEl
});

sketch.setTool('rect'); // Set the tool to rectangle.
sketch.setColor('rgba(255,0,0,0.5)');  // Set the color to red with 50% opacity.
sketch.clear(); // Clear the sketch

Event

| eventName | callback arguments | Descriptions | | --------- | ------------------ | ------------ | | line | data | Emit when a line was drawed | | rect | data | Emit when a rect was drawed | | text | data | Emit when a text was drawed | | ease | data | Emit when a ease action happend | | ellipse | data | Emit when a ellipse action happend | | arrow | data | Emit when a ellipse action happend |

example
const sketch = new Sketch({
    container: containerEl
});

sketch.on('line', (data) => {
    // ...   You can done anything with the line data. 
    // The data include all the points of the line.
});

sketch.on('rect', (data) => {
    // ...   You can done anything with the rect data. 
    // The data include the rect's position, width, height, etc.
});

// ...

Change Log

1.3.5 (2017-05-15)
  • [feature] 增加拖动绘制箭头图形的方法。
1.3.3 (2017-10-11)
  • [optimize] 文字工具,绘图数据添加width、height两个数据。
1.3.0 (2017-09-30)
  • [feature] 增加通过拖动绘制椭圆的方法。
1.2.6 (2017-09-13)
  • [feature] 文字的字体选择在不同平台上表现差不多的字体。
  • [feature] 更新对 ben-canvas 的版本依赖。
1.2.5 (2017-09-06)
  • [feature] 实现文字输入的大小行高可配置。
1.2.4 (2017-09-04)
  • [optimize] 文字在输入的过程中,颜色也会根据当前颜色显示。
1.2.2 (2017-08-24)
  • [optimize] 提供一种没有选中工具的状态,对鼠标动作不做任何的处理。并且完成实例化后的默认状态为空。
1.2.0 (2017-08-24)
  • [bugfix] 在设置为不支持的工具类型时导致的事件监听器报错的问题。
  • [bugfix] 修复在通过调用 resize 来响应窗口变化时,绘图层不会同步变化而带来的绘图出现偏移的问题。
  • [bugfix] 修复鼠标移出绘图区域橡皮擦工具会重复多次的bug。
  • [bugfix] 提高最外层容器的z-index,使之不会被覆盖。
  • [bugfix] 修复鼠标移出绘画区域,绘制动作没有终止的bug。
  • [optimize] 修改绘图策略,采用常驻的绘图层,不再临时生成绘图层,完成后再删掉,会有一定的性能上的提升。
  • [optimize] 屏蔽鼠标右键,只支持鼠标左键点击绘图。
  • [optimize] 添加文字工具和橡皮工具的鼠标样式。
  • [optimize] 添加自动发布脚本。
  • [feature] 新增 width 和 height 两个可选参数来定义绘图区域的大小,不传会使用container.clientWidht 和 container.clientHeight 作为绘图区域的大小。
1.1.0 (2017-08-07)
  • [feature] 提供颜色设置功能。
  • [feature] Add example and screenshot to README.md
  • [feature] 提供编译后的文件,无需使用者配置编译环境。
  • [feature] 提供开发和打包的 webpack 配置。
  • [bugfix] 修复因为内部 canvas 的样式定位问题导致的不能绘图的bug。
  • [bugfix] 修复在firfox 浏览器下绘制文字位置错乱的问题。
  • [bugfix] 更新 ben-canvas 的版本依赖,修复重复划线或者重复擦除的bug。
  • [bugfix] 修复 package 中遗漏样式文件的bug。
1.0.0 (2017-08-03) 👏
  • [feature] 完成基本的画图功能组件。

Contact

Author: Ben Chen

E-mail: [email protected]

Contributor: 高勇

E-mail: [email protected]