js-kompo-utils 1.0.32 → 1.0.34

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.
@@ -15,6 +15,7 @@
15
15
  @touchend="stopDrawing"
16
16
  ></canvas>
17
17
  <button
18
+ class="signature-pad-button"
18
19
  type="button"
19
20
  :class="clearButtonClass"
20
21
  @click="clearSignature"
@@ -54,17 +55,14 @@ export default {
54
55
  const canvas = this.$refs.canvas
55
56
  this.context = canvas.getContext('2d')
56
57
 
57
- // Fill background
58
58
  this.context.fillStyle = this.backgroundColor
59
59
  this.context.fillRect(0, 0, this.canvasWidth, this.canvasHeight)
60
60
 
61
- // Set drawing style
62
61
  this.context.strokeStyle = this.penColor
63
62
  this.context.lineWidth = this.penWidth
64
63
  this.context.lineCap = 'round'
65
64
  this.context.lineJoin = 'round'
66
65
 
67
- // Load existing signature if any
68
66
  if (this.component.value) {
69
67
  this.loadSignature(this.component.value)
70
68
  }
@@ -74,7 +72,8 @@ export default {
74
72
  const canvas = this.$refs.canvas
75
73
  const rect = canvas.getBoundingClientRect()
76
74
 
77
- // Calculer le ratio entre la taille affichée et la taille réelle du canvas
75
+ // CSS stretches the canvas past its attribute size, so pointer coordinates
76
+ // have to be scaled back into canvas space or the ink lands off-cursor.
78
77
  const scaleX = canvas.width / rect.width
79
78
  const scaleY = canvas.height / rect.height
80
79
 
@@ -94,9 +93,19 @@ export default {
94
93
  startDrawing(event) {
95
94
  event.preventDefault()
96
95
  this.isDrawing = true
96
+
97
97
  const coords = this.getCoordinates(event)
98
98
  this.lastX = coords.x
99
99
  this.lastY = coords.y
100
+
101
+ // A click with no movement is a dot, and a signature is full of them.
102
+ this.context.beginPath()
103
+ this.context.arc(coords.x, coords.y, this.penWidth / 2, 0, Math.PI * 2)
104
+ this.context.fillStyle = this.penColor
105
+ this.context.fill()
106
+ this.context.fillStyle = this.backgroundColor
107
+
108
+ this.isEmpty = false
100
109
  },
101
110
 
102
111
  draw(event) {
@@ -113,12 +122,13 @@ export default {
113
122
  this.lastX = coords.x
114
123
  this.lastY = coords.y
115
124
  this.isEmpty = false
116
-
117
- this.saveSignature()
118
125
  },
119
126
 
120
127
  stopDrawing() {
128
+ if (!this.isDrawing) return
129
+
121
130
  this.isDrawing = false
131
+ this.saveSignature()
122
132
  },
123
133
 
124
134
  clearSignature() {
@@ -130,11 +140,11 @@ export default {
130
140
  },
131
141
 
132
142
  saveSignature() {
133
- if (!this.isEmpty) {
134
- const dataURL = this.$refs.canvas.toDataURL('image/png')
135
- this.component.value = dataURL
136
- this.$emit('input', dataURL)
137
- }
143
+ if (this.isEmpty) return
144
+
145
+ const dataURL = this.$refs.canvas.toDataURL('image/png')
146
+ this.component.value = dataURL
147
+ this.$emit('input', dataURL)
138
148
  },
139
149
 
140
150
  loadSignature(dataURL) {
@@ -154,20 +164,29 @@ export default {
154
164
 
155
165
  <style scoped>
156
166
  .signature-pad-container {
167
+ position: relative;
157
168
  display: flex;
158
169
  flex-direction: column;
159
- gap: 0.75rem;
170
+ gap: 0.5rem;
171
+ border: 1px solid #d1d5db;
172
+ border-radius: 0.5rem;
173
+ padding: 2px;
174
+ }
175
+
176
+ .signature-pad-container:hover {
177
+ border-color: #9ca3af;
160
178
  }
161
179
 
162
180
  .signature-canvas {
163
- border: 1px solid #d1d5db;
164
- border-radius: 0.5rem;
165
181
  cursor: crosshair;
166
182
  touch-action: none;
167
183
  display: block;
184
+ width: 100%;
168
185
  }
169
186
 
170
- .signature-canvas:hover {
171
- border-color: #9ca3af;
187
+ .signature-pad-button {
188
+ position: absolute;
189
+ bottom: 0.5rem;
190
+ right: 0.5rem;
172
191
  }
173
- </style>
192
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-kompo-utils",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "",
5
5
  "main": "app.js",
6
6
  "scripts": {