@coopenomics/sdk 2.2.3 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +75 -50
- package/dist/index.d.cts +22 -55
- package/dist/index.d.mts +22 -55
- package/dist/index.d.ts +22 -55
- package/dist/index.mjs +75 -50
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -61,80 +61,105 @@ var __publicField$1 = (obj, key, value) => {
|
|
|
61
61
|
return value;
|
|
62
62
|
};
|
|
63
63
|
class Canvas {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* @param width - Ширина canvas (по умолчанию 300).
|
|
68
|
-
* @param height - Высота canvas (по умолчанию 150).
|
|
69
|
-
*/
|
|
70
|
-
constructor(container, width = 300, height = 150) {
|
|
64
|
+
constructor(container, opts = {}) {
|
|
65
|
+
this.container = container;
|
|
66
|
+
this.opts = opts;
|
|
71
67
|
__publicField$1(this, "canvas");
|
|
72
68
|
__publicField$1(this, "ctx");
|
|
73
|
-
__publicField$1(this, "
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
__publicField$1(this, "drawing", false);
|
|
70
|
+
__publicField$1(this, "lastX", 0);
|
|
71
|
+
__publicField$1(this, "lastY", 0);
|
|
72
|
+
__publicField$1(this, "onMouseDown", (e) => {
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
this.drawing = true;
|
|
75
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
76
|
+
this.lastX = e.clientX - rect.left;
|
|
77
|
+
this.lastY = e.clientY - rect.top;
|
|
78
|
+
});
|
|
79
|
+
__publicField$1(this, "onMouseMove", (e) => {
|
|
80
|
+
if (!this.drawing)
|
|
81
|
+
return;
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
this.drawLine(e.clientX, e.clientY);
|
|
84
|
+
});
|
|
85
|
+
__publicField$1(this, "onMouseUp", () => {
|
|
86
|
+
this.drawing = false;
|
|
87
|
+
});
|
|
88
|
+
__publicField$1(this, "onTouchStart", (e) => {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
this.drawing = true;
|
|
91
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
92
|
+
this.lastX = e.touches[0].clientX - rect.left;
|
|
93
|
+
this.lastY = e.touches[0].clientY - rect.top;
|
|
94
|
+
});
|
|
95
|
+
__publicField$1(this, "onTouchMove", (e) => {
|
|
96
|
+
if (!this.drawing)
|
|
97
|
+
return;
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
const t = e.touches[0];
|
|
100
|
+
this.drawLine(t.clientX, t.clientY);
|
|
101
|
+
});
|
|
102
|
+
__publicField$1(this, "onTouchEnd", () => {
|
|
103
|
+
this.drawing = false;
|
|
77
104
|
});
|
|
78
105
|
this.canvas = document.createElement("canvas");
|
|
79
|
-
this.canvas.width =
|
|
80
|
-
this.canvas.height =
|
|
106
|
+
this.canvas.width = container.offsetWidth;
|
|
107
|
+
this.canvas.height = container.offsetHeight;
|
|
108
|
+
this.canvas.style.touchAction = "none";
|
|
81
109
|
container.appendChild(this.canvas);
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
const ctx = this.canvas.getContext("2d");
|
|
111
|
+
if (!ctx) {
|
|
112
|
+
throw new Error("Canvas not supported");
|
|
113
|
+
}
|
|
114
|
+
this.ctx = ctx;
|
|
115
|
+
this.ctx.lineWidth = this.opts.lineWidth ?? 5;
|
|
84
116
|
this.ctx.lineJoin = "round";
|
|
85
117
|
this.ctx.lineCap = "round";
|
|
86
|
-
this.ctx.strokeStyle = "#000";
|
|
118
|
+
this.ctx.strokeStyle = this.opts.strokeStyle ?? "#000";
|
|
119
|
+
this.initEvents();
|
|
87
120
|
}
|
|
88
121
|
/**
|
|
89
|
-
*
|
|
122
|
+
* Очистка холста.
|
|
90
123
|
*/
|
|
91
124
|
clearCanvas() {
|
|
92
125
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
93
126
|
}
|
|
94
127
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param e - Событие мыши или касания.
|
|
128
|
+
* Получение подписи в формате base64.
|
|
97
129
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
this.state.drawing = true;
|
|
101
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
102
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
103
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
104
|
-
this.state.lastX = clientX - rect.left;
|
|
105
|
-
this.state.lastY = clientY - rect.top;
|
|
130
|
+
getSignature() {
|
|
131
|
+
return this.canvas.toDataURL("image/png");
|
|
106
132
|
}
|
|
107
133
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @param e - Событие мыши или касания.
|
|
134
|
+
* Снятие всех слушателей.
|
|
110
135
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
136
|
+
destroy() {
|
|
137
|
+
this.canvas.removeEventListener("mousedown", this.onMouseDown);
|
|
138
|
+
this.canvas.removeEventListener("mousemove", this.onMouseMove);
|
|
139
|
+
this.canvas.removeEventListener("mouseup", this.onMouseUp);
|
|
140
|
+
this.canvas.removeEventListener("touchstart", this.onTouchStart);
|
|
141
|
+
this.canvas.removeEventListener("touchmove", this.onTouchMove);
|
|
142
|
+
this.canvas.removeEventListener("touchend", this.onTouchEnd);
|
|
143
|
+
}
|
|
144
|
+
// Внутренние методы
|
|
145
|
+
initEvents() {
|
|
146
|
+
this.canvas.addEventListener("mousedown", this.onMouseDown);
|
|
147
|
+
this.canvas.addEventListener("mousemove", this.onMouseMove);
|
|
148
|
+
this.canvas.addEventListener("mouseup", this.onMouseUp);
|
|
149
|
+
this.canvas.addEventListener("touchstart", this.onTouchStart, { passive: false });
|
|
150
|
+
this.canvas.addEventListener("touchmove", this.onTouchMove, { passive: false });
|
|
151
|
+
this.canvas.addEventListener("touchend", this.onTouchEnd, { passive: false });
|
|
152
|
+
}
|
|
153
|
+
drawLine(clientX, clientY) {
|
|
115
154
|
this.ctx.beginPath();
|
|
116
|
-
this.ctx.moveTo(this.
|
|
155
|
+
this.ctx.moveTo(this.lastX, this.lastY);
|
|
117
156
|
const rect = this.canvas.getBoundingClientRect();
|
|
118
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
119
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
120
157
|
const x = clientX - rect.left;
|
|
121
158
|
const y = clientY - rect.top;
|
|
122
159
|
this.ctx.lineTo(x, y);
|
|
123
160
|
this.ctx.stroke();
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Завершает процесс рисования (drawing = false).
|
|
129
|
-
*/
|
|
130
|
-
endDrawing() {
|
|
131
|
-
this.state.drawing = false;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Возвращает текущее содержимое canvas в формате base64 (PNG).
|
|
135
|
-
*/
|
|
136
|
-
getSignature() {
|
|
137
|
-
return this.canvas.toDataURL("image/png");
|
|
161
|
+
this.lastX = x;
|
|
162
|
+
this.lastY = y;
|
|
138
163
|
}
|
|
139
164
|
}
|
|
140
165
|
|
package/dist/index.d.cts
CHANGED
|
@@ -9117,71 +9117,38 @@ declare class Account {
|
|
|
9117
9117
|
private static generateKeys;
|
|
9118
9118
|
}
|
|
9119
9119
|
|
|
9120
|
-
/**
|
|
9121
|
-
* Класс `Canvas` инкапсулирует работу с HTML5 `<canvas>`:
|
|
9122
|
-
* - создание и инициализация canvas внутри переданного контейнера;
|
|
9123
|
-
* - очистка canvas;
|
|
9124
|
-
* - управление процессом рисования (начало, рисование, завершение);
|
|
9125
|
-
* - получение содержимого (подписи) в формате base64.
|
|
9126
|
-
*
|
|
9127
|
-
* @remarks
|
|
9128
|
-
* Все методы и состояние рисования (координаты, флаг `drawing`) хранятся внутри класса.
|
|
9129
|
-
*
|
|
9130
|
-
* @example
|
|
9131
|
-
* ```ts
|
|
9132
|
-
* const container = document.getElementById('canvas-container') as HTMLElement
|
|
9133
|
-
* const myCanvas = new Canvas(container, 500, 300)
|
|
9134
|
-
*
|
|
9135
|
-
* // События мыши
|
|
9136
|
-
* myCanvas.canvas.addEventListener('mousedown', (e) => myCanvas.startDrawing(e))
|
|
9137
|
-
* myCanvas.canvas.addEventListener('mousemove', (e) => myCanvas.draw(e))
|
|
9138
|
-
* myCanvas.canvas.addEventListener('mouseup', () => myCanvas.endDrawing())
|
|
9139
|
-
*
|
|
9140
|
-
* // Очистка холста
|
|
9141
|
-
* document.getElementById('clear-btn')?.addEventListener('click', () => {
|
|
9142
|
-
* myCanvas.clearCanvas()
|
|
9143
|
-
* })
|
|
9144
|
-
*
|
|
9145
|
-
* // Получение подписи (base64)
|
|
9146
|
-
* document.getElementById('get-sign-btn')?.addEventListener('click', () => {
|
|
9147
|
-
* const signature = myCanvas.getSignature()
|
|
9148
|
-
* console.log('Подпись (base64):', signature)
|
|
9149
|
-
* })
|
|
9150
|
-
* ```
|
|
9151
|
-
*/
|
|
9152
9120
|
declare class Canvas {
|
|
9121
|
+
private container;
|
|
9122
|
+
private opts;
|
|
9153
9123
|
canvas: HTMLCanvasElement;
|
|
9154
9124
|
ctx: CanvasRenderingContext2D;
|
|
9155
|
-
private
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
constructor(container: HTMLElement, width?: number, height?: number);
|
|
9125
|
+
private drawing;
|
|
9126
|
+
private lastX;
|
|
9127
|
+
private lastY;
|
|
9128
|
+
constructor(container: HTMLElement, opts?: {
|
|
9129
|
+
lineWidth?: number;
|
|
9130
|
+
strokeStyle?: string;
|
|
9131
|
+
});
|
|
9163
9132
|
/**
|
|
9164
|
-
*
|
|
9133
|
+
* Очистка холста.
|
|
9165
9134
|
*/
|
|
9166
9135
|
clearCanvas(): void;
|
|
9167
9136
|
/**
|
|
9168
|
-
*
|
|
9169
|
-
* @param e - Событие мыши или касания.
|
|
9170
|
-
*/
|
|
9171
|
-
startDrawing(e: MouseEvent | TouchEvent): void;
|
|
9172
|
-
/**
|
|
9173
|
-
* Выполняет рисование линии от предыдущей точки к текущей.
|
|
9174
|
-
* @param e - Событие мыши или касания.
|
|
9137
|
+
* Получение подписи в формате base64.
|
|
9175
9138
|
*/
|
|
9176
|
-
|
|
9177
|
-
/**
|
|
9178
|
-
* Завершает процесс рисования (drawing = false).
|
|
9179
|
-
*/
|
|
9180
|
-
endDrawing(): void;
|
|
9139
|
+
getSignature(): string;
|
|
9181
9140
|
/**
|
|
9182
|
-
*
|
|
9141
|
+
* Снятие всех слушателей.
|
|
9183
9142
|
*/
|
|
9184
|
-
|
|
9143
|
+
destroy(): void;
|
|
9144
|
+
private initEvents;
|
|
9145
|
+
private onMouseDown;
|
|
9146
|
+
private onMouseMove;
|
|
9147
|
+
private onMouseUp;
|
|
9148
|
+
private onTouchStart;
|
|
9149
|
+
private onTouchMove;
|
|
9150
|
+
private onTouchEnd;
|
|
9151
|
+
private drawLine;
|
|
9185
9152
|
}
|
|
9186
9153
|
|
|
9187
9154
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -9117,71 +9117,38 @@ declare class Account {
|
|
|
9117
9117
|
private static generateKeys;
|
|
9118
9118
|
}
|
|
9119
9119
|
|
|
9120
|
-
/**
|
|
9121
|
-
* Класс `Canvas` инкапсулирует работу с HTML5 `<canvas>`:
|
|
9122
|
-
* - создание и инициализация canvas внутри переданного контейнера;
|
|
9123
|
-
* - очистка canvas;
|
|
9124
|
-
* - управление процессом рисования (начало, рисование, завершение);
|
|
9125
|
-
* - получение содержимого (подписи) в формате base64.
|
|
9126
|
-
*
|
|
9127
|
-
* @remarks
|
|
9128
|
-
* Все методы и состояние рисования (координаты, флаг `drawing`) хранятся внутри класса.
|
|
9129
|
-
*
|
|
9130
|
-
* @example
|
|
9131
|
-
* ```ts
|
|
9132
|
-
* const container = document.getElementById('canvas-container') as HTMLElement
|
|
9133
|
-
* const myCanvas = new Canvas(container, 500, 300)
|
|
9134
|
-
*
|
|
9135
|
-
* // События мыши
|
|
9136
|
-
* myCanvas.canvas.addEventListener('mousedown', (e) => myCanvas.startDrawing(e))
|
|
9137
|
-
* myCanvas.canvas.addEventListener('mousemove', (e) => myCanvas.draw(e))
|
|
9138
|
-
* myCanvas.canvas.addEventListener('mouseup', () => myCanvas.endDrawing())
|
|
9139
|
-
*
|
|
9140
|
-
* // Очистка холста
|
|
9141
|
-
* document.getElementById('clear-btn')?.addEventListener('click', () => {
|
|
9142
|
-
* myCanvas.clearCanvas()
|
|
9143
|
-
* })
|
|
9144
|
-
*
|
|
9145
|
-
* // Получение подписи (base64)
|
|
9146
|
-
* document.getElementById('get-sign-btn')?.addEventListener('click', () => {
|
|
9147
|
-
* const signature = myCanvas.getSignature()
|
|
9148
|
-
* console.log('Подпись (base64):', signature)
|
|
9149
|
-
* })
|
|
9150
|
-
* ```
|
|
9151
|
-
*/
|
|
9152
9120
|
declare class Canvas {
|
|
9121
|
+
private container;
|
|
9122
|
+
private opts;
|
|
9153
9123
|
canvas: HTMLCanvasElement;
|
|
9154
9124
|
ctx: CanvasRenderingContext2D;
|
|
9155
|
-
private
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
constructor(container: HTMLElement, width?: number, height?: number);
|
|
9125
|
+
private drawing;
|
|
9126
|
+
private lastX;
|
|
9127
|
+
private lastY;
|
|
9128
|
+
constructor(container: HTMLElement, opts?: {
|
|
9129
|
+
lineWidth?: number;
|
|
9130
|
+
strokeStyle?: string;
|
|
9131
|
+
});
|
|
9163
9132
|
/**
|
|
9164
|
-
*
|
|
9133
|
+
* Очистка холста.
|
|
9165
9134
|
*/
|
|
9166
9135
|
clearCanvas(): void;
|
|
9167
9136
|
/**
|
|
9168
|
-
*
|
|
9169
|
-
* @param e - Событие мыши или касания.
|
|
9170
|
-
*/
|
|
9171
|
-
startDrawing(e: MouseEvent | TouchEvent): void;
|
|
9172
|
-
/**
|
|
9173
|
-
* Выполняет рисование линии от предыдущей точки к текущей.
|
|
9174
|
-
* @param e - Событие мыши или касания.
|
|
9137
|
+
* Получение подписи в формате base64.
|
|
9175
9138
|
*/
|
|
9176
|
-
|
|
9177
|
-
/**
|
|
9178
|
-
* Завершает процесс рисования (drawing = false).
|
|
9179
|
-
*/
|
|
9180
|
-
endDrawing(): void;
|
|
9139
|
+
getSignature(): string;
|
|
9181
9140
|
/**
|
|
9182
|
-
*
|
|
9141
|
+
* Снятие всех слушателей.
|
|
9183
9142
|
*/
|
|
9184
|
-
|
|
9143
|
+
destroy(): void;
|
|
9144
|
+
private initEvents;
|
|
9145
|
+
private onMouseDown;
|
|
9146
|
+
private onMouseMove;
|
|
9147
|
+
private onMouseUp;
|
|
9148
|
+
private onTouchStart;
|
|
9149
|
+
private onTouchMove;
|
|
9150
|
+
private onTouchEnd;
|
|
9151
|
+
private drawLine;
|
|
9185
9152
|
}
|
|
9186
9153
|
|
|
9187
9154
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -9117,71 +9117,38 @@ declare class Account {
|
|
|
9117
9117
|
private static generateKeys;
|
|
9118
9118
|
}
|
|
9119
9119
|
|
|
9120
|
-
/**
|
|
9121
|
-
* Класс `Canvas` инкапсулирует работу с HTML5 `<canvas>`:
|
|
9122
|
-
* - создание и инициализация canvas внутри переданного контейнера;
|
|
9123
|
-
* - очистка canvas;
|
|
9124
|
-
* - управление процессом рисования (начало, рисование, завершение);
|
|
9125
|
-
* - получение содержимого (подписи) в формате base64.
|
|
9126
|
-
*
|
|
9127
|
-
* @remarks
|
|
9128
|
-
* Все методы и состояние рисования (координаты, флаг `drawing`) хранятся внутри класса.
|
|
9129
|
-
*
|
|
9130
|
-
* @example
|
|
9131
|
-
* ```ts
|
|
9132
|
-
* const container = document.getElementById('canvas-container') as HTMLElement
|
|
9133
|
-
* const myCanvas = new Canvas(container, 500, 300)
|
|
9134
|
-
*
|
|
9135
|
-
* // События мыши
|
|
9136
|
-
* myCanvas.canvas.addEventListener('mousedown', (e) => myCanvas.startDrawing(e))
|
|
9137
|
-
* myCanvas.canvas.addEventListener('mousemove', (e) => myCanvas.draw(e))
|
|
9138
|
-
* myCanvas.canvas.addEventListener('mouseup', () => myCanvas.endDrawing())
|
|
9139
|
-
*
|
|
9140
|
-
* // Очистка холста
|
|
9141
|
-
* document.getElementById('clear-btn')?.addEventListener('click', () => {
|
|
9142
|
-
* myCanvas.clearCanvas()
|
|
9143
|
-
* })
|
|
9144
|
-
*
|
|
9145
|
-
* // Получение подписи (base64)
|
|
9146
|
-
* document.getElementById('get-sign-btn')?.addEventListener('click', () => {
|
|
9147
|
-
* const signature = myCanvas.getSignature()
|
|
9148
|
-
* console.log('Подпись (base64):', signature)
|
|
9149
|
-
* })
|
|
9150
|
-
* ```
|
|
9151
|
-
*/
|
|
9152
9120
|
declare class Canvas {
|
|
9121
|
+
private container;
|
|
9122
|
+
private opts;
|
|
9153
9123
|
canvas: HTMLCanvasElement;
|
|
9154
9124
|
ctx: CanvasRenderingContext2D;
|
|
9155
|
-
private
|
|
9156
|
-
|
|
9157
|
-
|
|
9158
|
-
|
|
9159
|
-
|
|
9160
|
-
|
|
9161
|
-
|
|
9162
|
-
constructor(container: HTMLElement, width?: number, height?: number);
|
|
9125
|
+
private drawing;
|
|
9126
|
+
private lastX;
|
|
9127
|
+
private lastY;
|
|
9128
|
+
constructor(container: HTMLElement, opts?: {
|
|
9129
|
+
lineWidth?: number;
|
|
9130
|
+
strokeStyle?: string;
|
|
9131
|
+
});
|
|
9163
9132
|
/**
|
|
9164
|
-
*
|
|
9133
|
+
* Очистка холста.
|
|
9165
9134
|
*/
|
|
9166
9135
|
clearCanvas(): void;
|
|
9167
9136
|
/**
|
|
9168
|
-
*
|
|
9169
|
-
* @param e - Событие мыши или касания.
|
|
9170
|
-
*/
|
|
9171
|
-
startDrawing(e: MouseEvent | TouchEvent): void;
|
|
9172
|
-
/**
|
|
9173
|
-
* Выполняет рисование линии от предыдущей точки к текущей.
|
|
9174
|
-
* @param e - Событие мыши или касания.
|
|
9137
|
+
* Получение подписи в формате base64.
|
|
9175
9138
|
*/
|
|
9176
|
-
|
|
9177
|
-
/**
|
|
9178
|
-
* Завершает процесс рисования (drawing = false).
|
|
9179
|
-
*/
|
|
9180
|
-
endDrawing(): void;
|
|
9139
|
+
getSignature(): string;
|
|
9181
9140
|
/**
|
|
9182
|
-
*
|
|
9141
|
+
* Снятие всех слушателей.
|
|
9183
9142
|
*/
|
|
9184
|
-
|
|
9143
|
+
destroy(): void;
|
|
9144
|
+
private initEvents;
|
|
9145
|
+
private onMouseDown;
|
|
9146
|
+
private onMouseMove;
|
|
9147
|
+
private onMouseUp;
|
|
9148
|
+
private onTouchStart;
|
|
9149
|
+
private onTouchMove;
|
|
9150
|
+
private onTouchEnd;
|
|
9151
|
+
private drawLine;
|
|
9185
9152
|
}
|
|
9186
9153
|
|
|
9187
9154
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -55,80 +55,105 @@ var __publicField$1 = (obj, key, value) => {
|
|
|
55
55
|
return value;
|
|
56
56
|
};
|
|
57
57
|
class Canvas {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* @param width - Ширина canvas (по умолчанию 300).
|
|
62
|
-
* @param height - Высота canvas (по умолчанию 150).
|
|
63
|
-
*/
|
|
64
|
-
constructor(container, width = 300, height = 150) {
|
|
58
|
+
constructor(container, opts = {}) {
|
|
59
|
+
this.container = container;
|
|
60
|
+
this.opts = opts;
|
|
65
61
|
__publicField$1(this, "canvas");
|
|
66
62
|
__publicField$1(this, "ctx");
|
|
67
|
-
__publicField$1(this, "
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
__publicField$1(this, "drawing", false);
|
|
64
|
+
__publicField$1(this, "lastX", 0);
|
|
65
|
+
__publicField$1(this, "lastY", 0);
|
|
66
|
+
__publicField$1(this, "onMouseDown", (e) => {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
this.drawing = true;
|
|
69
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
70
|
+
this.lastX = e.clientX - rect.left;
|
|
71
|
+
this.lastY = e.clientY - rect.top;
|
|
72
|
+
});
|
|
73
|
+
__publicField$1(this, "onMouseMove", (e) => {
|
|
74
|
+
if (!this.drawing)
|
|
75
|
+
return;
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
this.drawLine(e.clientX, e.clientY);
|
|
78
|
+
});
|
|
79
|
+
__publicField$1(this, "onMouseUp", () => {
|
|
80
|
+
this.drawing = false;
|
|
81
|
+
});
|
|
82
|
+
__publicField$1(this, "onTouchStart", (e) => {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
this.drawing = true;
|
|
85
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
86
|
+
this.lastX = e.touches[0].clientX - rect.left;
|
|
87
|
+
this.lastY = e.touches[0].clientY - rect.top;
|
|
88
|
+
});
|
|
89
|
+
__publicField$1(this, "onTouchMove", (e) => {
|
|
90
|
+
if (!this.drawing)
|
|
91
|
+
return;
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
const t = e.touches[0];
|
|
94
|
+
this.drawLine(t.clientX, t.clientY);
|
|
95
|
+
});
|
|
96
|
+
__publicField$1(this, "onTouchEnd", () => {
|
|
97
|
+
this.drawing = false;
|
|
71
98
|
});
|
|
72
99
|
this.canvas = document.createElement("canvas");
|
|
73
|
-
this.canvas.width =
|
|
74
|
-
this.canvas.height =
|
|
100
|
+
this.canvas.width = container.offsetWidth;
|
|
101
|
+
this.canvas.height = container.offsetHeight;
|
|
102
|
+
this.canvas.style.touchAction = "none";
|
|
75
103
|
container.appendChild(this.canvas);
|
|
76
|
-
|
|
77
|
-
|
|
104
|
+
const ctx = this.canvas.getContext("2d");
|
|
105
|
+
if (!ctx) {
|
|
106
|
+
throw new Error("Canvas not supported");
|
|
107
|
+
}
|
|
108
|
+
this.ctx = ctx;
|
|
109
|
+
this.ctx.lineWidth = this.opts.lineWidth ?? 5;
|
|
78
110
|
this.ctx.lineJoin = "round";
|
|
79
111
|
this.ctx.lineCap = "round";
|
|
80
|
-
this.ctx.strokeStyle = "#000";
|
|
112
|
+
this.ctx.strokeStyle = this.opts.strokeStyle ?? "#000";
|
|
113
|
+
this.initEvents();
|
|
81
114
|
}
|
|
82
115
|
/**
|
|
83
|
-
*
|
|
116
|
+
* Очистка холста.
|
|
84
117
|
*/
|
|
85
118
|
clearCanvas() {
|
|
86
119
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
87
120
|
}
|
|
88
121
|
/**
|
|
89
|
-
*
|
|
90
|
-
* @param e - Событие мыши или касания.
|
|
122
|
+
* Получение подписи в формате base64.
|
|
91
123
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.state.drawing = true;
|
|
95
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
96
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
97
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
98
|
-
this.state.lastX = clientX - rect.left;
|
|
99
|
-
this.state.lastY = clientY - rect.top;
|
|
124
|
+
getSignature() {
|
|
125
|
+
return this.canvas.toDataURL("image/png");
|
|
100
126
|
}
|
|
101
127
|
/**
|
|
102
|
-
*
|
|
103
|
-
* @param e - Событие мыши или касания.
|
|
128
|
+
* Снятие всех слушателей.
|
|
104
129
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
130
|
+
destroy() {
|
|
131
|
+
this.canvas.removeEventListener("mousedown", this.onMouseDown);
|
|
132
|
+
this.canvas.removeEventListener("mousemove", this.onMouseMove);
|
|
133
|
+
this.canvas.removeEventListener("mouseup", this.onMouseUp);
|
|
134
|
+
this.canvas.removeEventListener("touchstart", this.onTouchStart);
|
|
135
|
+
this.canvas.removeEventListener("touchmove", this.onTouchMove);
|
|
136
|
+
this.canvas.removeEventListener("touchend", this.onTouchEnd);
|
|
137
|
+
}
|
|
138
|
+
// Внутренние методы
|
|
139
|
+
initEvents() {
|
|
140
|
+
this.canvas.addEventListener("mousedown", this.onMouseDown);
|
|
141
|
+
this.canvas.addEventListener("mousemove", this.onMouseMove);
|
|
142
|
+
this.canvas.addEventListener("mouseup", this.onMouseUp);
|
|
143
|
+
this.canvas.addEventListener("touchstart", this.onTouchStart, { passive: false });
|
|
144
|
+
this.canvas.addEventListener("touchmove", this.onTouchMove, { passive: false });
|
|
145
|
+
this.canvas.addEventListener("touchend", this.onTouchEnd, { passive: false });
|
|
146
|
+
}
|
|
147
|
+
drawLine(clientX, clientY) {
|
|
109
148
|
this.ctx.beginPath();
|
|
110
|
-
this.ctx.moveTo(this.
|
|
149
|
+
this.ctx.moveTo(this.lastX, this.lastY);
|
|
111
150
|
const rect = this.canvas.getBoundingClientRect();
|
|
112
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
113
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
114
151
|
const x = clientX - rect.left;
|
|
115
152
|
const y = clientY - rect.top;
|
|
116
153
|
this.ctx.lineTo(x, y);
|
|
117
154
|
this.ctx.stroke();
|
|
118
|
-
this.
|
|
119
|
-
this.
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Завершает процесс рисования (drawing = false).
|
|
123
|
-
*/
|
|
124
|
-
endDrawing() {
|
|
125
|
-
this.state.drawing = false;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Возвращает текущее содержимое canvas в формате base64 (PNG).
|
|
129
|
-
*/
|
|
130
|
-
getSignature() {
|
|
131
|
-
return this.canvas.toDataURL("image/png");
|
|
155
|
+
this.lastX = x;
|
|
156
|
+
this.lastY = y;
|
|
132
157
|
}
|
|
133
158
|
}
|
|
134
159
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopenomics/sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.4",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@9.9.0",
|
|
7
7
|
"description": "",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"vite": "^5.4.3",
|
|
75
75
|
"vitest": "^2.0.5"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "cbfe37dbba00574ec4f1ca354ecf5a4438d72bc1"
|
|
78
78
|
}
|