canvasframework 0.5.18 → 0.5.19

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.
Files changed (112) hide show
  1. package/components/Accordion.js +265 -0
  2. package/components/AndroidDatePickerDialog.js +406 -0
  3. package/components/AppBar.js +398 -0
  4. package/components/AudioPlayer.js +611 -0
  5. package/components/Avatar.js +202 -0
  6. package/components/Banner.js +342 -0
  7. package/components/BottomNavigationBar.js +433 -0
  8. package/components/BottomSheet.js +234 -0
  9. package/components/Button.js +358 -0
  10. package/components/Camera.js +644 -0
  11. package/components/Card.js +193 -0
  12. package/components/Chart.js +700 -0
  13. package/components/Checkbox.js +166 -0
  14. package/components/Chip.js +212 -0
  15. package/components/CircularProgress.js +327 -0
  16. package/components/ContextMenu.js +116 -0
  17. package/components/DatePicker.js +298 -0
  18. package/components/Dialog.js +337 -0
  19. package/components/Divider.js +125 -0
  20. package/components/Drawer.js +276 -0
  21. package/components/FAB.js +270 -0
  22. package/components/FileUpload.js +315 -0
  23. package/components/FloatedCamera.js +644 -0
  24. package/components/IOSDatePickerWheel.js +430 -0
  25. package/components/ImageCarousel.js +219 -0
  26. package/components/ImageComponent.js +223 -0
  27. package/components/Input.js +831 -0
  28. package/components/InputDatalist.js +723 -0
  29. package/components/InputTags.js +624 -0
  30. package/components/List.js +95 -0
  31. package/components/ListItem.js +269 -0
  32. package/components/Modal.js +364 -0
  33. package/components/MorphingFAB.js +428 -0
  34. package/components/MultiSelectDialog.js +206 -0
  35. package/components/NumberInput.js +271 -0
  36. package/components/PasswordInput.js +462 -0
  37. package/components/ProgressBar.js +88 -0
  38. package/components/QRCodeReader.js +539 -0
  39. package/components/RadioButton.js +151 -0
  40. package/components/SearchInput.js +315 -0
  41. package/components/SegmentedControl.js +357 -0
  42. package/components/Select.js +199 -0
  43. package/components/SelectDialog.js +255 -0
  44. package/components/Slider.js +113 -0
  45. package/components/SliverAppBar.js +139 -0
  46. package/components/Snackbar.js +243 -0
  47. package/components/SpeedDialFAB.js +397 -0
  48. package/components/Stepper.js +281 -0
  49. package/components/SwipeableListItem.js +327 -0
  50. package/components/Switch.js +147 -0
  51. package/components/Table.js +492 -0
  52. package/components/Tabs.js +423 -0
  53. package/components/Text.js +141 -0
  54. package/components/TextField.js +151 -0
  55. package/components/TimePicker.js +934 -0
  56. package/components/Toast.js +236 -0
  57. package/components/TreeView.js +420 -0
  58. package/components/Video.js +397 -0
  59. package/components/View.js +140 -0
  60. package/components/VirtualList.js +120 -0
  61. package/core/CanvasFramework.js +3045 -0
  62. package/core/Component.js +243 -0
  63. package/core/ThemeManager.js +358 -0
  64. package/core/UIBuilder.js +267 -0
  65. package/core/WebGLCanvasAdapter.js +782 -0
  66. package/features/Column.js +43 -0
  67. package/features/Grid.js +47 -0
  68. package/features/LayoutComponent.js +43 -0
  69. package/features/OpenStreetMap.js +310 -0
  70. package/features/Positioned.js +33 -0
  71. package/features/PullToRefresh.js +328 -0
  72. package/features/Row.js +40 -0
  73. package/features/SignaturePad.js +257 -0
  74. package/features/Skeleton.js +193 -0
  75. package/features/Stack.js +21 -0
  76. package/index.js +119 -0
  77. package/manager/AccessibilityManager.js +107 -0
  78. package/manager/ErrorHandler.js +59 -0
  79. package/manager/FeatureFlags.js +60 -0
  80. package/manager/MemoryManager.js +107 -0
  81. package/manager/PerformanceMonitor.js +84 -0
  82. package/manager/SecurityManager.js +54 -0
  83. package/package.json +22 -16
  84. package/utils/AnimationEngine.js +734 -0
  85. package/utils/CryptoManager.js +303 -0
  86. package/utils/DataStore.js +403 -0
  87. package/utils/DevTools.js +1618 -0
  88. package/utils/DevToolsConsole.js +201 -0
  89. package/utils/EventBus.js +407 -0
  90. package/utils/FetchClient.js +74 -0
  91. package/utils/FirebaseAuth.js +653 -0
  92. package/utils/FirebaseCore.js +246 -0
  93. package/utils/FirebaseFirestore.js +581 -0
  94. package/utils/FirebaseFunctions.js +97 -0
  95. package/utils/FirebaseRealtimeDB.js +498 -0
  96. package/utils/FirebaseStorage.js +612 -0
  97. package/utils/FormValidator.js +355 -0
  98. package/utils/GeoLocationService.js +62 -0
  99. package/utils/I18n.js +207 -0
  100. package/utils/IndexedDBManager.js +273 -0
  101. package/utils/InspectionOverlay.js +308 -0
  102. package/utils/NotificationManager.js +60 -0
  103. package/utils/OfflineSyncManager.js +342 -0
  104. package/utils/PayPalPayment.js +678 -0
  105. package/utils/QueryBuilder.js +478 -0
  106. package/utils/SafeArea.js +64 -0
  107. package/utils/SecureStorage.js +289 -0
  108. package/utils/StateManager.js +207 -0
  109. package/utils/StripePayment.js +552 -0
  110. package/utils/WebSocketClient.js +66 -0
  111. package/dist/canvasframework.js +0 -2
  112. package/dist/canvasframework.js.LICENSE.txt +0 -1
@@ -0,0 +1,644 @@
1
+ import Component from '../core/Component.js';
2
+
3
+ /**
4
+ * Composant Camera autonome avec gestion directe des clics/touches
5
+ * Modes : contain (tout visible + bandes), cover (remplit + crop), fit (centre sans crop)
6
+ */
7
+ class Camera extends Component {
8
+ constructor(framework, options = {}) {
9
+ super(framework, options);
10
+
11
+ this.facingMode = options.facingMode || 'environment';
12
+ this.autoStart = options.autoStart !== false;
13
+ this.onPhoto = options.onPhoto || null;
14
+
15
+ this.fitModes = ['contain', 'cover'];
16
+ this.currentFitModeIndex = 0;
17
+ this.fitMode = this.fitModes[this.currentFitModeIndex];
18
+
19
+ this.stream = null;
20
+ this.video = null;
21
+ this.loaded = false;
22
+ this.error = null;
23
+
24
+ this.showControls = true;
25
+ this.torchSupported = false;
26
+ this.torchOn = false;
27
+ this.captureButtonRadius = 35;
28
+ this.modeButtonSize = 40;
29
+
30
+ // Feedback capture
31
+ this.flashTimer = null;
32
+ this.previewPhoto = null; // dataUrl dernière photo
33
+ this.previewTimeout = null;
34
+
35
+ this.isStarting = false;
36
+ }
37
+
38
+ static cleanupAllCameras() {
39
+ const allVideos = document.querySelectorAll('video');
40
+ allVideos.forEach(video => {
41
+ // Arrêter les streams
42
+ if (video.srcObject) {
43
+ const stream = video.srcObject;
44
+ if (stream && stream.getTracks) {
45
+ stream.getTracks().forEach(track => track.stop());
46
+ }
47
+ video.srcObject = null;
48
+ }
49
+
50
+ // Supprimer du DOM
51
+ if (video.parentNode) {
52
+ video.parentNode.removeChild(video);
53
+ }
54
+ });
55
+ }
56
+
57
+ async _mount() {
58
+ super._mount?.();
59
+
60
+ // Redémarrage auto si besoin
61
+ if (this.autoStart && !this.stream && !this.isStarting) {
62
+ this.isStarting = true;
63
+ await this.startCamera();
64
+ this.isStarting = false;
65
+ }
66
+
67
+ this.setupEventListeners();
68
+ }
69
+
70
+ destroy() {
71
+ this.removeEventListeners();
72
+ this.stopCamera();
73
+ if (this.flashTimer) clearTimeout(this.flashTimer);
74
+ if (this.previewTimeout) clearTimeout(this.previewTimeout);
75
+ super.destroy?.();
76
+ }
77
+
78
+ // Écoute directe (indépendante du framework)
79
+ setupEventListeners() {
80
+ this.onTouchStart = this.handleTouchStart.bind(this);
81
+ this.onTouchMove = this.handleTouchMove.bind(this);
82
+ this.onTouchEnd = this.handleTouchEnd.bind(this);
83
+ this.onMouseDown = this.handleMouseDown.bind(this);
84
+ this.onMouseMove = this.handleMouseMove.bind(this);
85
+ this.onMouseUp = this.handleMouseUp.bind(this);
86
+
87
+ const canvas = this.framework.canvas;
88
+ canvas.addEventListener('touchstart', this.onTouchStart, { passive: false });
89
+ canvas.addEventListener('touchmove', this.onTouchMove, { passive: false });
90
+ canvas.addEventListener('touchend', this.onTouchEnd, { passive: false });
91
+ canvas.addEventListener('mousedown', this.onMouseDown);
92
+ canvas.addEventListener('mousemove', this.onMouseMove);
93
+ canvas.addEventListener('mouseup', this.onMouseUp);
94
+ }
95
+
96
+ removeEventListeners() {
97
+ const canvas = this.framework.canvas;
98
+ canvas.removeEventListener('touchstart', this.onTouchStart);
99
+ canvas.removeEventListener('touchmove', this.onTouchMove);
100
+ canvas.removeEventListener('touchend', this.onTouchEnd);
101
+ canvas.removeEventListener('mousedown', this.onMouseDown);
102
+ canvas.removeEventListener('mousemove', this.onMouseMove);
103
+ canvas.removeEventListener('mouseup', this.onMouseUp);
104
+ }
105
+
106
+ // Coordonnées locales
107
+ getLocalPos(clientX, clientY) {
108
+ const rect = this.framework.canvas.getBoundingClientRect();
109
+ const globalX = clientX - rect.left;
110
+ const globalY = clientY - rect.top - this.framework.scrollOffset;
111
+ return {
112
+ x: globalX - this.x,
113
+ y: globalY - this.y
114
+ };
115
+ }
116
+
117
+ handleTouchStart(e) {
118
+ e.preventDefault();
119
+ const touch = e.touches[0];
120
+ const pos = this.getLocalPos(touch.clientX, touch.clientY);
121
+ this.handlePress(pos.x, pos.y);
122
+ }
123
+
124
+ handleTouchMove(e) {
125
+ e.preventDefault();
126
+ }
127
+
128
+ handleTouchEnd(e) {
129
+ e.preventDefault();
130
+ }
131
+
132
+ handleMouseDown(e) {
133
+ const pos = this.getLocalPos(e.clientX, e.clientY);
134
+ this.handlePress(pos.x, pos.y);
135
+ }
136
+
137
+ handleMouseMove(e) {}
138
+
139
+ handleMouseUp(e) {}
140
+
141
+ async startCamera() {
142
+ Camera.cleanupAllCameras();
143
+ if (this.stream) return;
144
+
145
+ try {
146
+ this.stopCamera();
147
+
148
+ this.stream = await navigator.mediaDevices.getUserMedia({
149
+ video: {
150
+ facingMode: this.facingMode,
151
+ width: { ideal: 1280 },
152
+ height: { ideal: 720 },
153
+ frameRate: { ideal: 30 }
154
+ }
155
+ });
156
+
157
+ const [track] = this.stream.getVideoTracks();
158
+ const caps = track.getCapabilities?.() || {};
159
+ this.torchSupported = !!caps.torch;
160
+
161
+ this.video = document.createElement('video');
162
+ this.video.autoplay = true;
163
+ this.video.playsInline = true;
164
+ this.video.muted = true;
165
+ this.video.srcObject = this.stream;
166
+
167
+ this.video.style.position = 'fixed';
168
+ this.video.style.left = '-9999px';
169
+ this.video.style.top = '-9999px';
170
+ this.video.style.width = '1px';
171
+ this.video.style.height = '1px';
172
+ document.body.appendChild(this.video);
173
+
174
+ await new Promise(resolve => {
175
+ this.video.onloadedmetadata = () => {
176
+ this.loaded = true;
177
+ this.video.play().catch(e => console.warn('Play auto échoué:', e));
178
+ resolve();
179
+ };
180
+ this.video.onerror = (e) => {
181
+ this.error = 'Erreur vidéo';
182
+ console.error('Video error:', e);
183
+ resolve();
184
+ };
185
+ });
186
+
187
+ this.markDirty();
188
+ } catch (err) {
189
+ this.error = err.message || 'Accès caméra refusé';
190
+ console.error('Échec getUserMedia:', err);
191
+ this.markDirty();
192
+ }
193
+ }
194
+
195
+ stopCamera() {
196
+ if (this.stream) {
197
+ this.stream.getTracks().forEach(track => track.stop());
198
+ this.stream = null;
199
+ }
200
+ if (this.video) {
201
+ if (this.video.parentNode) {
202
+ this.video.parentNode.removeChild(this.video);
203
+ }
204
+ this.video.srcObject = null;
205
+ this.video = null;
206
+ }
207
+ this.loaded = false;
208
+ this.markDirty();
209
+ }
210
+
211
+ async switchCamera() {
212
+ this.stopCamera();
213
+ this.facingMode = this.facingMode === 'user' ? 'environment' : 'user';
214
+ await this.startCamera();
215
+ }
216
+
217
+ async toggleTorch() {
218
+ if (!this.torchSupported || !this.stream) return;
219
+
220
+ const [track] = this.stream.getVideoTracks();
221
+ try {
222
+ await track.applyConstraints({
223
+ advanced: [{ torch: !this.torchOn }]
224
+ });
225
+ this.torchOn = !this.torchOn;
226
+ this.markDirty();
227
+ } catch (err) {
228
+ console.warn('Torch impossible:', err);
229
+ }
230
+ }
231
+
232
+ capturePhoto() {
233
+ if (!this.loaded || !this.video) {
234
+ console.warn('Capture impossible : caméra pas prête');
235
+ return null;
236
+ }
237
+
238
+ const canvas = document.createElement('canvas');
239
+ canvas.width = this.video.videoWidth;
240
+ canvas.height = this.video.videoHeight;
241
+
242
+ const ctx = canvas.getContext('2d');
243
+ ctx.drawImage(this.video, 0, 0);
244
+
245
+ const dataUrl = canvas.toDataURL('image/jpeg', 0.92);
246
+ if (this.onPhoto) this.onPhoto(dataUrl);
247
+ console.log('Photo capturée ! DataURL:', dataUrl.substring(0, 50) + '...');
248
+
249
+ // Feedback : flash + preview 3s
250
+ this.flashTimer = setTimeout(() => {
251
+ this.flashTimer = null;
252
+ this.markDirty();
253
+ }, 200);
254
+
255
+ this.previewPhoto = dataUrl;
256
+ this.previewTimeout = setTimeout(() => {
257
+ this.previewPhoto = null;
258
+ this.markDirty();
259
+ }, 3000);
260
+
261
+ this.markDirty();
262
+ return dataUrl;
263
+ }
264
+
265
+ switchFitMode() {
266
+ this.currentFitModeIndex = (this.currentFitModeIndex + 1) % this.fitModes.length;
267
+ this.fitMode = this.fitModes[this.currentFitModeIndex];
268
+ this.markDirty();
269
+ }
270
+
271
+ handlePress(relX, relY) {
272
+
273
+ // Capture centrale
274
+ const captureX = this.width / 2;
275
+ const captureY = this.height - 60;
276
+ if (Math.hypot(relX - captureX, relY - captureY) < this.captureButtonRadius + 10) {
277
+ this.capturePhoto();
278
+ return;
279
+ }
280
+
281
+ // Switch caméra
282
+ if (relX < 60 && relY < 60) {
283
+ this.switchCamera();
284
+ return;
285
+ }
286
+
287
+ // Torch
288
+ if (this.torchSupported && relX > this.width - 60 && relY < 60) {
289
+ this.toggleTorch();
290
+ return;
291
+ }
292
+
293
+ // Switch mode
294
+ const modeButtonX = this.width - 80;
295
+ const modeButtonY = 20;
296
+ if (relX > modeButtonX && relX < modeButtonX + this.modeButtonSize &&
297
+ relY > modeButtonY && relY < modeButtonY + this.modeButtonSize) {
298
+ this.switchFitMode();
299
+ return;
300
+ }
301
+ }
302
+
303
+ drawContainIcon(ctx, x, y, size) {
304
+ // Icône "contain" : rectangle avec flèches vers l'intérieur
305
+ const pad = size * 0.2;
306
+ ctx.strokeStyle = '#000';
307
+ ctx.lineWidth = 2;
308
+
309
+ // Rectangle extérieur
310
+ ctx.strokeRect(x + pad, y + pad, size - pad * 2, size - pad * 2);
311
+
312
+ // Flèches pointant vers l'intérieur
313
+ const arrowSize = size * 0.15;
314
+ ctx.fillStyle = '#000';
315
+
316
+ // Flèche haut
317
+ ctx.beginPath();
318
+ ctx.moveTo(x + size/2, y + pad - 2);
319
+ ctx.lineTo(x + size/2 - arrowSize, y + pad + arrowSize);
320
+ ctx.lineTo(x + size/2 + arrowSize, y + pad + arrowSize);
321
+ ctx.fill();
322
+
323
+ // Flèche bas
324
+ ctx.beginPath();
325
+ ctx.moveTo(x + size/2, y + size - pad + 2);
326
+ ctx.lineTo(x + size/2 - arrowSize, y + size - pad - arrowSize);
327
+ ctx.lineTo(x + size/2 + arrowSize, y + size - pad - arrowSize);
328
+ ctx.fill();
329
+
330
+ // Flèche gauche
331
+ ctx.beginPath();
332
+ ctx.moveTo(x + pad - 2, y + size/2);
333
+ ctx.lineTo(x + pad + arrowSize, y + size/2 - arrowSize);
334
+ ctx.lineTo(x + pad + arrowSize, y + size/2 + arrowSize);
335
+ ctx.fill();
336
+
337
+ // Flèche droite
338
+ ctx.beginPath();
339
+ ctx.moveTo(x + size - pad + 2, y + size/2);
340
+ ctx.lineTo(x + size - pad - arrowSize, y + size/2 - arrowSize);
341
+ ctx.lineTo(x + size - pad - arrowSize, y + size/2 + arrowSize);
342
+ ctx.fill();
343
+ }
344
+
345
+ drawCoverIcon(ctx, x, y, size) {
346
+ // Icône "cover" : rectangle avec flèches vers l'extérieur
347
+ const pad = size * 0.2;
348
+ ctx.strokeStyle = '#000';
349
+ ctx.lineWidth = 2;
350
+
351
+ // Rectangle intérieur
352
+ ctx.strokeRect(x + pad, y + pad, size - pad * 2, size - pad * 2);
353
+
354
+ // Flèches pointant vers l'extérieur
355
+ const arrowSize = size * 0.15;
356
+ ctx.fillStyle = '#000';
357
+
358
+ // Flèche haut
359
+ ctx.beginPath();
360
+ ctx.moveTo(x + size/2, y + 2);
361
+ ctx.lineTo(x + size/2 - arrowSize, y + arrowSize + 2);
362
+ ctx.lineTo(x + size/2 + arrowSize, y + arrowSize + 2);
363
+ ctx.fill();
364
+
365
+ // Flèche bas
366
+ ctx.beginPath();
367
+ ctx.moveTo(x + size/2, y + size - 2);
368
+ ctx.lineTo(x + size/2 - arrowSize, y + size - arrowSize - 2);
369
+ ctx.lineTo(x + size/2 + arrowSize, y + size - arrowSize - 2);
370
+ ctx.fill();
371
+
372
+ // Flèche gauche
373
+ ctx.beginPath();
374
+ ctx.moveTo(x + 2, y + size/2);
375
+ ctx.lineTo(x + arrowSize + 2, y + size/2 - arrowSize);
376
+ ctx.lineTo(x + arrowSize + 2, y + size/2 + arrowSize);
377
+ ctx.fill();
378
+
379
+ // Flèche droite
380
+ ctx.beginPath();
381
+ ctx.moveTo(x + size - 2, y + size/2);
382
+ ctx.lineTo(x + size - arrowSize - 2, y + size/2 - arrowSize);
383
+ ctx.lineTo(x + size - arrowSize - 2, y + size/2 + arrowSize);
384
+ ctx.fill();
385
+ }
386
+
387
+ drawContainIcon(ctx, x, y, size) {
388
+ // Icône "contain" : rectangle avec flèches vers l'intérieur
389
+ const pad = size * 0.2;
390
+ ctx.strokeStyle = '#000';
391
+ ctx.lineWidth = 2;
392
+
393
+ // Rectangle extérieur
394
+ ctx.strokeRect(x + pad, y + pad, size - pad * 2, size - pad * 2);
395
+
396
+ // Flèches pointant vers l'intérieur
397
+ const arrowSize = size * 0.15;
398
+ ctx.fillStyle = '#000';
399
+
400
+ // Flèche haut
401
+ ctx.beginPath();
402
+ ctx.moveTo(x + size/2, y + pad - 2);
403
+ ctx.lineTo(x + size/2 - arrowSize, y + pad + arrowSize);
404
+ ctx.lineTo(x + size/2 + arrowSize, y + pad + arrowSize);
405
+ ctx.fill();
406
+
407
+ // Flèche bas
408
+ ctx.beginPath();
409
+ ctx.moveTo(x + size/2, y + size - pad + 2);
410
+ ctx.lineTo(x + size/2 - arrowSize, y + size - pad - arrowSize);
411
+ ctx.lineTo(x + size/2 + arrowSize, y + size - pad - arrowSize);
412
+ ctx.fill();
413
+
414
+ // Flèche gauche
415
+ ctx.beginPath();
416
+ ctx.moveTo(x + pad - 2, y + size/2);
417
+ ctx.lineTo(x + pad + arrowSize, y + size/2 - arrowSize);
418
+ ctx.lineTo(x + pad + arrowSize, y + size/2 + arrowSize);
419
+ ctx.fill();
420
+
421
+ // Flèche droite
422
+ ctx.beginPath();
423
+ ctx.moveTo(x + size - pad + 2, y + size/2);
424
+ ctx.lineTo(x + size - pad - arrowSize, y + size/2 - arrowSize);
425
+ ctx.lineTo(x + size - pad - arrowSize, y + size/2 + arrowSize);
426
+ ctx.fill();
427
+ }
428
+
429
+ drawCoverIcon(ctx, x, y, size) {
430
+ // Icône "cover" : rectangle avec flèches vers l'extérieur
431
+ const pad = size * 0.2;
432
+ ctx.strokeStyle = '#000';
433
+ ctx.lineWidth = 2;
434
+
435
+ // Rectangle intérieur
436
+ ctx.strokeRect(x + pad, y + pad, size - pad * 2, size - pad * 2);
437
+
438
+ // Flèches pointant vers l'extérieur
439
+ const arrowSize = size * 0.15;
440
+ ctx.fillStyle = '#000';
441
+
442
+ // Flèche haut
443
+ ctx.beginPath();
444
+ ctx.moveTo(x + size/2, y + 2);
445
+ ctx.lineTo(x + size/2 - arrowSize, y + arrowSize + 2);
446
+ ctx.lineTo(x + size/2 + arrowSize, y + arrowSize + 2);
447
+ ctx.fill();
448
+
449
+ // Flèche bas
450
+ ctx.beginPath();
451
+ ctx.moveTo(x + size/2, y + size - 2);
452
+ ctx.lineTo(x + size/2 - arrowSize, y + size - arrowSize - 2);
453
+ ctx.lineTo(x + size/2 + arrowSize, y + size - arrowSize - 2);
454
+ ctx.fill();
455
+
456
+ // Flèche gauche
457
+ ctx.beginPath();
458
+ ctx.moveTo(x + 2, y + size/2);
459
+ ctx.lineTo(x + arrowSize + 2, y + size/2 - arrowSize);
460
+ ctx.lineTo(x + arrowSize + 2, y + size/2 + arrowSize);
461
+ ctx.fill();
462
+
463
+ // Flèche droite
464
+ ctx.beginPath();
465
+ ctx.moveTo(x + size - 2, y + size/2);
466
+ ctx.lineTo(x + size - arrowSize - 2, y + size/2 - arrowSize);
467
+ ctx.lineTo(x + size - arrowSize - 2, y + size/2 + arrowSize);
468
+ ctx.fill();
469
+ }
470
+
471
+ drawSwitchCameraIcon(ctx, x, y, size) {
472
+ // Icône de switch caméra : deux caméras avec flèche circulaire
473
+ const centerX = x + size / 2;
474
+ const centerY = y + size / 2;
475
+ const radius = size * 0.35;
476
+
477
+ ctx.strokeStyle = '#ffffff';
478
+ ctx.lineWidth = 3;
479
+ ctx.lineCap = 'round';
480
+
481
+ // Arc circulaire (flèche de rotation)
482
+ ctx.beginPath();
483
+ ctx.arc(centerX, centerY, radius, -Math.PI * 0.7, Math.PI * 0.7);
484
+ ctx.stroke();
485
+
486
+ // Flèche en haut à droite
487
+ const arrowSize = size * 0.15;
488
+ const arrowAngle = Math.PI * 0.7;
489
+ const arrowX = centerX + radius * Math.cos(arrowAngle);
490
+ const arrowY = centerY + radius * Math.sin(arrowAngle);
491
+
492
+ ctx.fillStyle = '#ffffff';
493
+ ctx.beginPath();
494
+ ctx.moveTo(arrowX, arrowY);
495
+ ctx.lineTo(arrowX - arrowSize, arrowY - arrowSize * 0.5);
496
+ ctx.lineTo(arrowX - arrowSize * 0.5, arrowY + arrowSize);
497
+ ctx.fill();
498
+
499
+ // Mini caméra au centre
500
+ const camWidth = size * 0.25;
501
+ const camHeight = size * 0.18;
502
+ const camX = centerX - camWidth / 2;
503
+ const camY = centerY - camHeight / 2;
504
+
505
+ ctx.fillStyle = '#ffffff';
506
+ ctx.fillRect(camX, camY, camWidth, camHeight);
507
+
508
+ // Objectif
509
+ ctx.fillStyle = '#000';
510
+ ctx.beginPath();
511
+ ctx.arc(centerX, centerY, size * 0.08, 0, Math.PI * 2);
512
+ ctx.fill();
513
+ }
514
+
515
+ draw(ctx) {
516
+ ctx.save();
517
+
518
+ ctx.fillStyle = '#000';
519
+ ctx.fillRect(this.x, this.y, this.width, this.height);
520
+
521
+ // Flash blanc après capture
522
+ if (this.flashTimer) {
523
+ ctx.fillStyle = 'rgba(255,255,255,0.6)';
524
+ ctx.fillRect(this.x, this.y, this.width, this.height);
525
+ }
526
+
527
+ if (this.error) {
528
+ ctx.fillStyle = '#ff4444';
529
+ ctx.font = '16px Arial';
530
+ ctx.textAlign = 'center';
531
+ ctx.textBaseline = 'middle';
532
+ ctx.fillText(this.error, this.x + this.width/2, this.y + this.height/2);
533
+ } else if (!this.loaded) {
534
+ ctx.fillStyle = '#fff';
535
+ ctx.font = '16px Arial';
536
+ ctx.textAlign = 'center';
537
+ ctx.textBaseline = 'middle';
538
+ ctx.fillText('Démarrage caméra...', this.x + this.width/2, this.y + this.height/2);
539
+ } else if (this.video && this.loaded) {
540
+ const videoRatio = this.video.videoWidth / this.video.videoHeight;
541
+ const canvasRatio = this.width / this.height;
542
+
543
+ let drawWidth = this.width;
544
+ let drawHeight = this.height;
545
+ let offsetX = 0;
546
+ let offsetY = 0;
547
+
548
+ if (this.fitMode === 'cover') {
549
+ if (videoRatio > canvasRatio) {
550
+ drawHeight = this.height;
551
+ drawWidth = drawHeight * videoRatio;
552
+ offsetX = (this.width - drawWidth) / 2;
553
+ } else {
554
+ drawWidth = this.width;
555
+ drawHeight = drawWidth / videoRatio;
556
+ offsetY = (this.height - drawHeight) / 2;
557
+ }
558
+ } else if (this.fitMode === 'contain') {
559
+ if (videoRatio > canvasRatio) {
560
+ drawWidth = this.width;
561
+ drawHeight = drawWidth / videoRatio;
562
+ offsetY = (this.height - drawHeight) / 2;
563
+ } else {
564
+ drawHeight = this.height;
565
+ drawWidth = drawHeight * videoRatio;
566
+ offsetX = (this.width - drawWidth) / 2;
567
+ }
568
+ }
569
+
570
+ ctx.drawImage(this.video, this.x + offsetX, this.y + offsetY, drawWidth, drawHeight);
571
+
572
+ // Mini preview dernière photo (bas droite, 3s)
573
+ if (this.previewPhoto) {
574
+ const previewSize = 80;
575
+ const img = new Image();
576
+ img.src = this.previewPhoto;
577
+ ctx.drawImage(img, this.x + this.width - previewSize - 10, this.y + this.height - previewSize - 10, previewSize, previewSize);
578
+ ctx.strokeStyle = '#fff';
579
+ ctx.lineWidth = 2;
580
+ ctx.strokeRect(this.x + this.width - previewSize - 10, this.y + this.height - previewSize - 10, previewSize, previewSize);
581
+ }
582
+ }
583
+
584
+ // Contrôles bas
585
+ ctx.fillStyle = 'rgba(0,0,0,0.5)';
586
+ ctx.fillRect(this.x, this.y + this.height - 100, this.width, 100);
587
+
588
+ // Bouton capture
589
+ ctx.fillStyle = '#ffffff';
590
+ ctx.beginPath();
591
+ ctx.arc(this.x + this.width/2, this.y + this.height - 50, this.captureButtonRadius, 0, Math.PI * 2);
592
+ ctx.fill();
593
+
594
+ ctx.strokeStyle = '#ff4444';
595
+ ctx.lineWidth = 6;
596
+ ctx.beginPath();
597
+ ctx.arc(this.x + this.width/2, this.y + this.height - 50, this.captureButtonRadius + 10, 0, Math.PI * 2);
598
+ ctx.stroke();
599
+
600
+ // Switch caméra avec icône
601
+ const switchBtnX = this.x + 20;
602
+ const switchBtnY = this.y + 20;
603
+ const switchBtnSize = 50;
604
+
605
+ // Fond semi-transparent
606
+ ctx.fillStyle = 'rgba(0,0,0,0.5)';
607
+ ctx.beginPath();
608
+ ctx.arc(switchBtnX + switchBtnSize/2, switchBtnY + switchBtnSize/2, switchBtnSize/2, 0, Math.PI * 2);
609
+ ctx.fill();
610
+
611
+ // Icône
612
+ this.drawSwitchCameraIcon(ctx, switchBtnX, switchBtnY, switchBtnSize);
613
+
614
+ // Torch
615
+ if (this.torchSupported) {
616
+ ctx.fillStyle = this.torchOn ? '#ffeb3b' : '#ffffff';
617
+ ctx.fillText('⚡', this.x + this.width - 50, this.y + 45);
618
+ }
619
+
620
+ // Bouton switch mode avec icône
621
+ const btnX = this.x + this.width - 80;
622
+ const btnY = this.y + 20;
623
+
624
+ // Fond du bouton
625
+ ctx.fillStyle = 'rgba(255,255,255,0.9)';
626
+ ctx.fillRect(btnX, btnY, this.modeButtonSize, this.modeButtonSize);
627
+
628
+ // Bordure
629
+ ctx.strokeStyle = '#000';
630
+ ctx.lineWidth = 2;
631
+ ctx.strokeRect(btnX, btnY, this.modeButtonSize, this.modeButtonSize);
632
+
633
+ // Dessiner l'icône appropriée
634
+ if (this.fitMode === 'contain') {
635
+ this.drawContainIcon(ctx, btnX, btnY, this.modeButtonSize);
636
+ } else {
637
+ this.drawCoverIcon(ctx, btnX, btnY, this.modeButtonSize);
638
+ }
639
+
640
+ ctx.restore();
641
+ }
642
+ }
643
+
644
+ export default Camera;