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

cg-write

v1.0.0

Published

#### 在线体验:https://a835100635.github.io/customWrite/public/ #### 觉得有趣、对大佬有用的话点个star✨呗 ![在这里插入图片描述](https://img-blog.csdnimg.cn/91e61fc4807c4c1da4478c5dfded5ece.png)

Downloads

4

Readme

customWrite

在线体验:https://a835100635.github.io/customWrite/public/

觉得有趣、对大佬有用的话点个star✨呗

在这里插入图片描述

简述


此项目主要是canvas写字板功能,也就是电子签名插件。功能包含画笔粗细、画笔颜色、生成图片、禁止书写、重置事件、并且支持自定义配置

安装

npm

$ npm install c-write

直接安装

<script type="module" src="/path/to/lib.js"></script>
<script type="module">
  import CWrite from '/path/to/lib.js'

  const cWrite = new CWrite(options);
</script>

如何导入ES模块的示例

// 引入库
import CWrite from 'CWrite';
// 初始化库 传入配置项 options
const cWrite = new CWrite(options);

配置项 options


el 挂载元素

类型定义

type EleType = HTMLElement;
options: {
  // HTMLElement
  el: document.querySelector('#app'),
}

===>
<div id="app">
  <canvas></canvas>
</div>

attr 元素自定义属性

类型定义

interface AttrType {
  [key: string]: string | number | boolean;
}
attr: {
  width: 100,
  height: 100,
  class: 'canvas-block',
  id: 'canvas'
  ... 其他自定义属性
}

===>
<canvas 
  width="100" 
  height="100" 
  class="canvas-block" 
  id="canvas">
</canvas>

lineWidth 线条宽度

类型定义

type LineWidthType = number;
options: {
  lineWidth: 1
}

strokeStyle 线条颜色

类型定义

type StrokeStyleType = string | CanvasGradient | CanvasPattern;
options: {
  strokeStyle: 'pink' // '#cccccc'
}

lineJoin 线条拐角样式

类型定义

type LineJoinType = CanvasLineJoin; // 'bevel' | 'miter' | 'round'
options: {
  lineJoin: 'bevel' | 'miter' | 'round'
}

画布操作 action

切换画笔属性

修改画笔粗细、颜色、拐角样式等

修改完后必须调用 此方法 否则不生效 类型定义

interface RestOptionsType {
  [key: string]: string | number | boolean;
}

// 参数可选
cWrite.resetOptions(options: RestOptionsType)
// 内部判断逻辑
for(const key of Object.keys(options)) {
  // 过滤没有的属性
  if(!(key in this)) return;
  Object.assign(this, {
    [key]: options[`${key}`]
  })
}
// 所以除默认设置属性以外的属性一律不生效

// 参数可选
cWrite.resetOptions({
  lineWidth: 1,
  strokeStyle: 'red',
  lineJoin: 'round'
})

清空画布

cWrite.resetOptions()

导出图片

暂时默认导出 base64 数据

const imgData = cWrite.canvasToImage()
console.log(imgData);
// data:image/png;base64,QI....ggg==
页面展示示例
const imgData = cWrite.canvasToImage();
const img = document.createElement('img');
img.style.width = '400px';
img.style.height = '300px';
img.src = imgData;
document.body.appendChild(img);

重置画布大小

当我们页面突然发生大小的改变需要改变画布大小时可以调用此函数

cWrite.refresh();
 window.addEventListener('resize', () => {
    cWrite.refresh();
 });

销毁画布监听事件

画布监听还是依赖与原生事件监听,为了垃圾回收机制还是考虑一下销毁事件监听

cWrite.destroyed();

调用此方法后,画布活动一切禁止

恢复画布监听事件

在禁止画布活动后需要恢复操作可以抵用此函数

cWrite.initEvent();

调用后发现画布活动又可正常操作