Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eraser): solves issues with eraser #725

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/signature_pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface PointGroupOptions {
maxWidth: number;
penColor: string;
velocityFilterWeight: number;
compositeOperation: GlobalCompositeOperation;
}

export interface Options extends Partial<PointGroupOptions> {
Expand All @@ -56,6 +57,7 @@ export default class SignaturePad extends SignatureEventTarget {
public penColor: string;
public minDistance: number;
public velocityFilterWeight: number;
public compositeOperation: GlobalCompositeOperation;
public backgroundColor: string;
public throttle: number;

Expand Down Expand Up @@ -83,6 +85,7 @@ export default class SignaturePad extends SignatureEventTarget {
this.dotSize = options.dotSize || 0;
this.penColor = options.penColor || 'black';
this.backgroundColor = options.backgroundColor || 'rgba(0,0,0,0)';
this.compositeOperation = options.compositeOperation || 'source-over';

this._strokeMoveUpdate = this.throttle
? throttle(SignaturePad.prototype._strokeUpdate, this.throttle)
Expand Down Expand Up @@ -314,7 +317,7 @@ export default class SignaturePad extends SignatureEventTarget {
}
};

private _getPointGroupOptions(group?: PointGroup) {
private _getPointGroupOptions(group?: PointGroup): PointGroupOptions {
return {
penColor: group && 'penColor' in group ? group.penColor : this.penColor,
dotSize: group && 'dotSize' in group ? group.dotSize : this.dotSize,
Expand All @@ -324,6 +327,10 @@ export default class SignaturePad extends SignatureEventTarget {
group && 'velocityFilterWeight' in group
? group.velocityFilterWeight
: this.velocityFilterWeight,
compositeOperation:
group && 'compositeOperation' in group
? group.compositeOperation
: this.compositeOperation,
};
}

Expand Down Expand Up @@ -361,8 +368,8 @@ export default class SignaturePad extends SignatureEventTarget {
(event as PointerEvent).pressure !== undefined
? (event as PointerEvent).pressure
: (event as Touch).force !== undefined
? (event as Touch).force
: 0;
? (event as Touch).force
: 0;

const point = this._createPoint(x, y, pressure);
const lastPointGroup = this._data[this._data.length - 1];
Expand Down Expand Up @@ -432,6 +439,7 @@ export default class SignaturePad extends SignatureEventTarget {
this._lastVelocity = 0;
this._lastWidth = (options.minWidth + options.maxWidth) / 2;
this._ctx.fillStyle = options.penColor;
this._ctx.globalCompositeOperation = options.compositeOperation;
}

private _createPoint(x: number, y: number, pressure: number): Point {
Expand Down