# @wines/hand-writing

> The hand-writing @wines

Latest version **2.0.0** (published 2025-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wines/hand-writing
pnpm add @wines/hand-writing
yarn add @wines/hand-writing
bun add @wines/hand-writing
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-04-01 |
| First published | 2021-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 3 |
| Unpacked size | 56.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tianyingchun |

## Links

- npm: https://www.npmjs.com/package/@wines/hand-writing
- Repository: https://gitlab.itcjf.com/wines/hand-writing
- npm.io page: https://npm.io/package/@wines/hand-writing

## Dependencies (3)

- [@wines/core](https://npm.io/package/@wines/core.md) 2.0.0
- [@wines/button](https://npm.io/package/@wines/button.md) 2.0.0
- [@wines/styles](https://npm.io/package/@wines/styles.md) 2.0.0

## Recent versions

- 2.0.0 (latest) — 2025-04-01
- 2.0.0-next.7 (next) — 2025-04-01
- 2.0.0-next.6 — 2025-03-06
- 2.0.0-next.5 — 2025-03-05
- 2.0.0-next.4 — 2025-03-05
- 2.0.0-next.3 — 2025-03-04
- 2.0.0-next.2 — 2025-02-28
- 2.0.0-next.1 — 2025-02-27
- 2.0.0-next.0 — 2025-02-27
- 1.5.1 — 2023-03-07
- 1.5.0 — 2022-11-22
- 1.4.0 — 2022-02-23
- 1.3.5 — 2021-12-03
- 1.3.2 — 2021-09-24
- 1.3.1 — 2021-04-25
- … 1 more at https://npm.io/package/@wines/hand-writing/versions

## README

# `@wines/hand-writing`

# hand writing Canvas手写板

Canvas实现用户签字功能

## 使用指南

### 在 page.json 中引入组件

```json
{
  "navigationBarTitleText": "Hand Wrting",
  "usingComponents": {
    "wux-button": "@wines/button",
    "wux-hand-writing": "@wines/hand-writing"
  }
}
```

### 示例

```xml

```

<view class="page">
	<view class="page__hd">
		<view class="page__title">Hand Writing</view>
		<view class="page__desc">电子签名 手写版</view>
	</view>
	<view class="page__bd page__bd_spacing">
		<view class="writing">
			<wux-hand-writing
			 id="wux-hand-writing"
			 height="{{height}}"
			 width="{{width}}"
			 bg-color="{{bgColor}}"
			 line-color="{{lineColor}}"
			 line-size="{{lineSize}}"
			 line-min="{{lineMin}}"
			 line-max="{{lineMax}}"
			 pressure="{{pressure}}"
			 transparent="{{transparent}}"
			 smoothness="{{smoothness}}"
			>
			</wux-hand-writing>
		</view>
		<wux-button block type="light" bind:click="onBgColor">背景色({{bgColor}})</wux-button>
		<wux-button block type="light" bind:click="onTransparent">笔触透明度({{transparent}})</wux-button>
		<wux-button block type="light" bind:click="onLineColor">笔触颜色({{lineColor}})</wux-button>
		<wux-button block type="light" bind:click="onLineSize">笔触倍数({{lineSize}})</wux-button>
		<wux-button block type="light" bind:click="onLineMin">笔画半径({{lineMin}})</wux-button>
		<wux-button block type="light" bind:click="onLineMax">笔画半径({{lineMax}})</wux-button>
		<wux-button block type="light" bind:click="onPressure">笔触压力({{pressure}})</wux-button>
		<wux-button block type="light" bind:click="onSmoothness">顺滑度({{smoothness}})</wux-button>
		<wux-button block type="light" bind:click="onReset">重新初始化</wux-button>
		<wux-button block type="light" bind:click="onSave">保存临时文件</wux-button>
	</view>
</view>

```ts
import './index.less';
import { PageData, PageCustom } from '@wines/core';
import { $wuxHandWriting } from '@wines/hand-writing';
const random = (min = 0, max = 1) => {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};
Page<PageData, PageCustom>({
  data: {
    height: 300,
    width: 300,
    bgColor: '',
    transparent: 1,
    lineColor: '#1A1A1A',
    lineSize: 1,
    lineMin: 0.5,
    lineMax: 4,
    pressure: 1,
    smoothness: 60,
  },
  onBgColor() {
    this.setData({
      bgColor: ['#fff', '#f0f0f0'][random(0, 1)],
    });
  },
  onTransparent() {
    this.setData({
      transparent: [0.8, 1][random(0, 1)],
    });
  },
  onLineColor() {
    this.setData({
      lineColor: ['#1A1A1A', '#fc5531'][random(0, 1)],
    });
  },
  onLineSize() {
    this.setData({
      lineSize: [0.5, 1, 1.5, 2, 3][random(0, 4)],
    });
  },
  onLineMin() {
    this.setData({
      lineMin: [0.1, 0.2, 0.4, 0.5][random(0, 3)],
    });
  },
  onLineMax() {
    this.setData({
      lineMax: [1, 2, 3, 4][random(0, 3)],
    });
  },
  onPressure() {
    this.setData({
      pressure: [0.5, 1, 2][random(0, 2)],
    });
  },
  onSmoothness() {
    this.setData({
      smoothness: [30, 45, 60, 75][random(0, 3)],
    });
  },
  onReset() {
    $wuxHandWriting().reset();
  },
  onSave() {
    $wuxHandWriting()
      .saveCanvasAsImage()
      .then((filePath: string) => {
        void wx.showModal({
          title: filePath,
        });
      });
  },
});
```

## API

### Result props

| 参数        | 类型     | 描述                                              | 默认值           |
| ----------- | -------- | ------------------------------------------------- | ---------------- |
| prefixCls   | `string` | 自定义类名前缀                                    | wux-hand-writing |
| width       | `number` | canvas 组件的宽度                                 | 300              |
| height      | `number` | canvas 组件的高度                                 | 300              |
| bgColor     | `number` | 设置canvas背景色, 不设置,导出的canvas的背景为透明 | 300              |
| transparent | `number` | 透明度                                            | 1                |
| lineColor   | `string` | 笔迹颜色                                          | `#1A1A1A`        |
| lineSize    | `number` | 笔迹倍数                                          | 1                |
| lineMin     | `number` | 最小笔画半径                                      | 0.5              |
| lineMax     | `number` | 最大笔画半径                                      | 4                |
| pressure    | `number` | 默认压力                                          | 1                |
| smoothness  | `number` | 顺滑度，用60的距离来计算速度                      | 60               |

### method

```ts
// 重置画布到初始化状态
-$wuxHandWriting().reset() -
  // 保存签名到本地临时图片
  $wuxHandWriting().saveCanvasAsImage();
```

---
_Source: https://npm.io/package/@wines/hand-writing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
