@eve-sama/ngx-signature-pad

中文文档
16.0.0发布于 2023/05/20TypeScriptES Module近 30 天下载 6841

English | 简体中文

原始使用文档
文档目录10 节
  1. Introduction
  2. Demo
  3. Direction
  4. Install
  5. Usage
  6. AppModule
  7. AppComponent
  8. NgxSignatureOptions
  9. Instance Method
  10. Modify config during run time

English | 简体中文

Introduction

A handwritten signature plugin suitable for Angular ecology, suppprt V15.

avatar

Demo

You can see all detail directions of API and demo in here. There are diffent contents in the mode of PC and Mobile. PC emphasis on document, Mobile emphasis on example.

Direction

This project is based on canvas plugin signature_pad, and the canvas plugin only has basic functions, like signature canvas. I have encapsulated it with Angular which has the following features:

  • Provide API more suitable style for Angular.
  • Provide features not available in native plugins, like modify state of signature manually、revert painting、fullScreen to sign and so on.
  • You can change the config in run time, such as width/height.

Install

Via NPM

npm install --save @eve-sama/ngx-signature-pad

Via yarn

yarn add --save @eve-sama/ngx-signature-pad

Usage

AppModule

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';

import { NgxSignaturePadModule } from '@eve-sama/ngx-signature-pad';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    // You need to import module of ngx-signature-pad
    NgxSignaturePadModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

AppComponent

<ngx-signature-pad
  #signature
  [options]="options"
  (beginSign)="onBeginSign()"
  (endSign)="onEndSign()">
</ngx-signature-pad>
import { Component, ViewChild } from '@angular/core';
import { NgxSignaturePadComponent, NgxSignatureOptions } from '@eve-sama/ngx-signature-pad';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
  /** Catch object, call functions via instance object */
  @ViewChild('signature') signature: NgxSignaturePadComponent;

  /** You can see more introduction in the below about NgxSignatureOptions */
  public options: NgxSignatureOptions = {
    backgroundColor: '#F4F5F5',
    width: 570,
    height: 300,
    css: {
      'border-radius': '16px'
    }
  };

  /** The begin event of sign */
  onBeginSign(): void { }

  /** The end event of sign */
  onEndSign(): void { }
}

NgxSignatureOptions

ParamsDirectionTypeDefault
dotSizeRadius of a single dot.number | (() => number)-
minWidthMinimum width of a line.number0.5
maxWidthMaximum width of a line.number2.5
throttleDraw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling.number16
minDistanceAdd the next point only if the previous one is farther than x pixels.number0.5
backgroundColorColor used to clear the background. Can be any color format accepted by context.fillStyle. Use a non-transparent color e.g. "rgb(255,255,255)" (opaque white) if you'd like to save signatures as JPEG images.string'rgba(0,0,0,0)'
penColorColor used to draw the lines. Can be any color format accepted by context.fillStyle.string'black'
velocityFilterWeightWeight used to modify new velocity based on the previous velocity.number0.7
widthThe width of canvas.number300px
heightThe height of canvas.number150px
cssCustom css of canvs, you can see code of demo to get detail info. Notice that we use Renderer2 to render css, not sure whether it support all css{ [key: string]: string }-

Instance Method

FcuntionDirection
toDataURL()Get data URL of it as PNG.
toDataURL("image/jpeg")Get data URL of it as JPEG.
toDataURL("image/svg+xml")Get data URL of it as SVG.
fromDataURL(dataUrl: string)Draws signature image from data URL, you need to pass it with base64.
toData()Returns signature image as IPointGroup[].
fromData(pointGroups: IPointGroup[])Draws signature image from IPointGroup[].
clear()Clears the canvas.
isEmpty()Returns true if canvas is empty, otherwise returns false.
setDirty()Set pad's state as dirty, then isEmpty() return false.
setEmpty()Set pad's state as empty, then isEmpty() return true.
revert()Undo the last action. Notice that if you have the change of fullScreen() and miniScreen(), the revert() can not work after you change the mode. Under this situation, I do not recommend use it.
fullScreen()You can change the mode to fullScreen, the aspect ratio of the fullScreen signature is the same as that of the miniScreen signature.
miniScreen()You can change the mode to miniScreen. The inicial mode is miniScreen when you init the component.
getContext()Get canvas's Context, this is about canvas, after get Context, you can do anything you want, for example you can use drawImage to draw something in canvas pad, see demo in PC of dragImage.

Modify config during run time

This plugin allow you modify config during run time, just modify the options that you want to pass. Notice that you can not only change the attribute of options. Because OnChanges does not trigger under this circumstance. You need to reassign the options. For example, the initial options as below:

const options: NgxSignatureOptions = {
  penColor: 'rgb(0, 0, 0)', // Black
  width: 300,
  height: 150
};

After run code, if you wan to change the color of pen, if you write code as below, it does not work.

options.penColor = 'rgb(255, 0, 0)'; // Does not work, because can not trigger OnChanges

You need to reassign as below.

const options: NgxSignatureOptions = {
  penColor: 'rgb(255, 0, 0)' // Change the black to red
  width: 300,
  height: 150
};

版本与发布记录

@eve-sama/ngx-signature-pad 共发布 27 个版本,首次发布于 2020/09/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
16.0.0latest2023/05/203 年前
15.0.42022/11/293 年前
15.0.32022/11/293 年前
15.0.22022/11/293 年前
15.0.12022/11/293 年前
15.0.02022/11/293 年前

关于 @eve-sama/ngx-signature-pad 的常见问题

@eve-sama/ngx-signature-pad 是什么?

English | 简体中文

如何安装 @eve-sama/ngx-signature-pad?

在项目目录运行 npm install @eve-sama/ngx-signature-pad,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/cdk(^16.0.0)、@angular/common(^16.0.2)、@angular/core(^16.0.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@eve-sama/ngx-signature-pad 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eve-sama/ngx-signature-pad 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@eve-sama/ngx-signature-pad 可以商用吗?

@eve-sama/ngx-signature-pad 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@eve-sama/ngx-signature-pad 的下载量有多少?

根据 npm 官方下载统计,@eve-sama/ngx-signature-pad 在 2026/10/14 – 2026/11/12 这 30 天内被下载 6,841 次,日均约 228 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eve-sama/ngx-signature-pad 还在维护吗?

最新版本 16.0.0 发布于 2023/05/20(3 年前);至今共发布 27 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/09/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。