canvasframework 0.5.16 → 0.5.18

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/dist/canvasframework.js +2 -0
  2. package/dist/canvasframework.js.LICENSE.txt +1 -0
  3. package/package.json +18 -17
  4. package/components/Accordion.js +0 -265
  5. package/components/AndroidDatePickerDialog.js +0 -406
  6. package/components/AppBar.js +0 -398
  7. package/components/AudioPlayer.js +0 -611
  8. package/components/Avatar.js +0 -202
  9. package/components/Banner.js +0 -342
  10. package/components/BottomNavigationBar.js +0 -433
  11. package/components/BottomSheet.js +0 -234
  12. package/components/Button.js +0 -360
  13. package/components/Camera.js +0 -644
  14. package/components/Card.js +0 -193
  15. package/components/Chart.js +0 -700
  16. package/components/Checkbox.js +0 -166
  17. package/components/Chip.js +0 -212
  18. package/components/CircularProgress.js +0 -327
  19. package/components/ContextMenu.js +0 -116
  20. package/components/DatePicker.js +0 -298
  21. package/components/Dialog.js +0 -337
  22. package/components/Divider.js +0 -125
  23. package/components/Drawer.js +0 -276
  24. package/components/FAB.js +0 -270
  25. package/components/FileUpload.js +0 -315
  26. package/components/FloatedCamera.js +0 -644
  27. package/components/IOSDatePickerWheel.js +0 -430
  28. package/components/ImageCarousel.js +0 -219
  29. package/components/ImageComponent.js +0 -223
  30. package/components/Input.js +0 -831
  31. package/components/InputDatalist.js +0 -723
  32. package/components/InputTags.js +0 -624
  33. package/components/List.js +0 -95
  34. package/components/ListItem.js +0 -269
  35. package/components/Modal.js +0 -364
  36. package/components/MorphingFAB.js +0 -428
  37. package/components/MultiSelectDialog.js +0 -206
  38. package/components/NumberInput.js +0 -271
  39. package/components/PasswordInput.js +0 -462
  40. package/components/ProgressBar.js +0 -88
  41. package/components/QRCodeReader.js +0 -539
  42. package/components/RadioButton.js +0 -151
  43. package/components/SearchInput.js +0 -315
  44. package/components/SegmentedControl.js +0 -357
  45. package/components/Select.js +0 -199
  46. package/components/SelectDialog.js +0 -255
  47. package/components/Slider.js +0 -113
  48. package/components/SliverAppBar.js +0 -139
  49. package/components/Snackbar.js +0 -243
  50. package/components/SpeedDialFAB.js +0 -397
  51. package/components/Stepper.js +0 -281
  52. package/components/SwipeableListItem.js +0 -327
  53. package/components/Switch.js +0 -147
  54. package/components/Table.js +0 -492
  55. package/components/Tabs.js +0 -423
  56. package/components/Text.js +0 -141
  57. package/components/TextField.js +0 -151
  58. package/components/TimePicker.js +0 -934
  59. package/components/Toast.js +0 -236
  60. package/components/TreeView.js +0 -420
  61. package/components/Video.js +0 -397
  62. package/components/View.js +0 -140
  63. package/components/VirtualList.js +0 -120
  64. package/core/CanvasFramework.js +0 -3034
  65. package/core/Component.js +0 -243
  66. package/core/ThemeManager.js +0 -358
  67. package/core/UIBuilder.js +0 -267
  68. package/core/WebGLCanvasAdapter.js +0 -782
  69. package/features/Column.js +0 -43
  70. package/features/Grid.js +0 -47
  71. package/features/LayoutComponent.js +0 -43
  72. package/features/OpenStreetMap.js +0 -310
  73. package/features/Positioned.js +0 -33
  74. package/features/PullToRefresh.js +0 -328
  75. package/features/Row.js +0 -40
  76. package/features/SignaturePad.js +0 -257
  77. package/features/Skeleton.js +0 -193
  78. package/features/Stack.js +0 -21
  79. package/index.js +0 -119
  80. package/manager/AccessibilityManager.js +0 -107
  81. package/manager/ErrorHandler.js +0 -59
  82. package/manager/FeatureFlags.js +0 -60
  83. package/manager/MemoryManager.js +0 -107
  84. package/manager/PerformanceMonitor.js +0 -84
  85. package/manager/SecurityManager.js +0 -54
  86. package/utils/AnimationEngine.js +0 -734
  87. package/utils/CryptoManager.js +0 -303
  88. package/utils/DataStore.js +0 -403
  89. package/utils/DevTools.js +0 -1618
  90. package/utils/DevToolsConsole.js +0 -201
  91. package/utils/EventBus.js +0 -407
  92. package/utils/FetchClient.js +0 -74
  93. package/utils/FirebaseAuth.js +0 -653
  94. package/utils/FirebaseCore.js +0 -246
  95. package/utils/FirebaseFirestore.js +0 -581
  96. package/utils/FirebaseFunctions.js +0 -97
  97. package/utils/FirebaseRealtimeDB.js +0 -498
  98. package/utils/FirebaseStorage.js +0 -612
  99. package/utils/FormValidator.js +0 -355
  100. package/utils/GeoLocationService.js +0 -62
  101. package/utils/I18n.js +0 -207
  102. package/utils/IndexedDBManager.js +0 -273
  103. package/utils/InspectionOverlay.js +0 -308
  104. package/utils/NotificationManager.js +0 -60
  105. package/utils/OfflineSyncManager.js +0 -342
  106. package/utils/PayPalPayment.js +0 -678
  107. package/utils/QueryBuilder.js +0 -478
  108. package/utils/SafeArea.js +0 -64
  109. package/utils/SecureStorage.js +0 -289
  110. package/utils/StateManager.js +0 -207
  111. package/utils/StripePayment.js +0 -552
  112. package/utils/WebSocketClient.js +0 -66
@@ -1,539 +0,0 @@
1
- import Component from '../core/Component.js';
2
-
3
- /**
4
- * Composant QR Code Reader autonome
5
- * Analyse en temps réel le flux vidéo pour détecter les QR codes
6
- */
7
- class QRCodeReader 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.onQRCodeDetected = options.onQRCodeDetected || null; // Callback quand un QR code est détecté
14
- this.onError = options.onError || null;
15
-
16
- // Options de scan
17
- this.scanInterval = options.scanInterval || 300; // ms entre chaque analyse
18
- this.continuous = options.continuous !== false; // Continue à scanner même après détection
19
- this.vibrateOnDetect = options.vibrateOnDetect !== false; // Vibration mobile
20
-
21
- this.stream = null;
22
- this.video = null;
23
- this.loaded = false;
24
- this.error = null;
25
-
26
- // État du scan
27
- this.isScanning = false;
28
- this.scanTimer = null;
29
- this.lastScanTime = 0;
30
- this.currentQRCode = null;
31
- this.scanHistory = []; // Historique des codes scannés
32
-
33
- // UI
34
- this.showControls = true;
35
- this.showScannerOverlay = true;
36
- this.scannerFrameSize = 250; // Taille du cadre de scan
37
- this.scannerFrameColor = '#00ff00';
38
- this.scannerLineColor = '#ff0000';
39
- this.scannerLineHeight = 2;
40
- this.scannerLineSpeed = 2;
41
- this.scannerLinePosition = 0;
42
- this.scannerLineDirection = 1;
43
-
44
- this.torchSupported = false;
45
- this.torchOn = false;
46
-
47
- this.isStarting = false;
48
-
49
- // Charger la librairie QR code (jsQR)
50
- this.loadQRScanner();
51
- }
52
-
53
- async _mount() {
54
- super._mount?.();
55
-
56
- if (this.autoStart && !this.stream && !this.isStarting) {
57
- this.isStarting = true;
58
- await this.startCamera();
59
- this.isStarting = false;
60
- }
61
-
62
- this.setupEventListeners();
63
- }
64
-
65
- destroy() {
66
- this.stopScanning();
67
- this.removeEventListeners();
68
- this.stopCamera();
69
- super.destroy?.();
70
- }
71
-
72
- // Charger jsQR depuis CDN
73
- loadQRScanner() {
74
- if (typeof jsQR === 'undefined') {
75
- const script = document.createElement('script');
76
- script.src = 'https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.min.js';
77
- script.onload = () => {
78
- console.log('jsQR loaded');
79
- if (this.loaded && !this.isScanning) {
80
- this.startScanning();
81
- }
82
- };
83
- script.onerror = () => {
84
- console.error('Failed to load jsQR');
85
- this.error = 'Échec du chargement du scanner QR';
86
- };
87
- document.head.appendChild(script);
88
- }
89
- }
90
-
91
- setupEventListeners() {
92
- this.onTouchStart = this.handleTouchStart.bind(this);
93
- this.onMouseDown = this.handleMouseDown.bind(this);
94
-
95
- const canvas = this.framework.canvas;
96
- canvas.addEventListener('touchstart', this.onTouchStart, { passive: false });
97
- canvas.addEventListener('mousedown', this.onMouseDown);
98
- }
99
-
100
- removeEventListeners() {
101
- const canvas = this.framework.canvas;
102
- canvas.removeEventListener('touchstart', this.onTouchStart);
103
- canvas.removeEventListener('mousedown', this.onMouseDown);
104
- }
105
-
106
- getLocalPos(clientX, clientY) {
107
- const rect = this.framework.canvas.getBoundingClientRect();
108
- const globalX = clientX - rect.left;
109
- const globalY = clientY - rect.top - this.framework.scrollOffset;
110
- return {
111
- x: globalX - this.x,
112
- y: globalY - this.y
113
- };
114
- }
115
-
116
- handleTouchStart(e) {
117
- e.preventDefault();
118
- const touch = e.touches[0];
119
- const pos = this.getLocalPos(touch.clientX, touch.clientY);
120
- this.handlePress(pos.x, pos.y);
121
- }
122
-
123
- handleMouseDown(e) {
124
- const pos = this.getLocalPos(e.clientX, e.clientY);
125
- this.handlePress(pos.x, pos.y);
126
- }
127
-
128
- async startCamera() {
129
- if (this.stream) return;
130
-
131
- try {
132
- this.stopCamera();
133
-
134
- this.stream = await navigator.mediaDevices.getUserMedia({
135
- video: {
136
- facingMode: this.facingMode,
137
- width: { ideal: 320 },
138
- height: { ideal: 240 },
139
- frameRate: { ideal: 30 }
140
- }
141
- });
142
-
143
- const [track] = this.stream.getVideoTracks();
144
- const caps = track.getCapabilities?.() || {};
145
- this.torchSupported = !!caps.torch;
146
-
147
- this.video = document.createElement('video');
148
- this.video.autoplay = true;
149
- this.video.playsInline = true;
150
- this.video.muted = true;
151
- this.video.srcObject = this.stream;
152
-
153
- this.video.style.position = 'fixed';
154
- this.video.style.left = '-9999px';
155
- this.video.style.top = '-9999px';
156
- this.video.style.width = '1px';
157
- this.video.style.height = '1px';
158
- document.body.appendChild(this.video);
159
-
160
- await new Promise(resolve => {
161
- this.video.onloadedmetadata = () => {
162
- this.loaded = true;
163
- this.video.play().then(() => {
164
- if (typeof jsQR !== 'undefined') {
165
- this.startScanning();
166
- }
167
- resolve();
168
- }).catch(e => {
169
- console.warn('Play auto échoué:', e);
170
- resolve();
171
- });
172
- };
173
- this.video.onerror = (e) => {
174
- this.error = 'Erreur vidéo';
175
- console.error('Video error:', e);
176
- resolve();
177
- };
178
- });
179
-
180
- this.markDirty();
181
- } catch (err) {
182
- this.error = err.message || 'Accès caméra refusé';
183
- console.error('Échec getUserMedia:', err);
184
- if (this.onError) this.onError(this.error);
185
- this.markDirty();
186
- }
187
- }
188
-
189
- stopCamera() {
190
- this.stopScanning();
191
- if (this.stream) {
192
- this.stream.getTracks().forEach(track => track.stop());
193
- this.stream = null;
194
- }
195
- if (this.video) {
196
- if (this.video.parentNode) {
197
- this.video.parentNode.removeChild(this.video);
198
- }
199
- this.video.srcObject = null;
200
- this.video = null;
201
- }
202
- this.loaded = false;
203
- this.markDirty();
204
- }
205
-
206
- startScanning() {
207
- if (this.isScanning || !this.loaded || !this.video) return;
208
-
209
- this.isScanning = true;
210
- this.scanTimer = setInterval(() => {
211
- this.scanQRCode();
212
- }, this.scanInterval);
213
- }
214
-
215
- stopScanning() {
216
- if (this.scanTimer) {
217
- clearInterval(this.scanTimer);
218
- this.scanTimer = null;
219
- }
220
- this.isScanning = false;
221
- }
222
-
223
- async switchCamera() {
224
- this.stopScanning();
225
- this.stopCamera();
226
- this.facingMode = this.facingMode === 'user' ? 'environment' : 'user';
227
- await this.startCamera();
228
- }
229
-
230
- async toggleTorch() {
231
- if (!this.torchSupported || !this.stream) return;
232
-
233
- const [track] = this.stream.getVideoTracks();
234
- try {
235
- await track.applyConstraints({
236
- advanced: [{ torch: !this.torchOn }]
237
- });
238
- this.torchOn = !this.torchOn;
239
- this.markDirty();
240
- } catch (err) {
241
- console.warn('Torch impossible:', err);
242
- }
243
- }
244
-
245
- scanQRCode() {
246
- if (!this.loaded || !this.video || typeof jsQR === 'undefined') return;
247
-
248
- const canvas = document.createElement('canvas');
249
- const ctx = canvas.getContext('2d');
250
-
251
- // Définir la taille optimale pour la détection
252
- const width = this.video.videoWidth;
253
- const height = this.video.videoHeight;
254
-
255
- canvas.width = width;
256
- canvas.height = height;
257
-
258
- // Dessiner l'image vidéo
259
- ctx.drawImage(this.video, 0, 0, width, height);
260
-
261
- // Extraire les données d'image
262
- const imageData = ctx.getImageData(0, 0, width, height);
263
-
264
- // Scanner le QR code
265
- const code = jsQR(imageData.data, imageData.width, imageData.height, {
266
- inversionAttempts: 'dontInvert',
267
- });
268
-
269
- if (code) {
270
- this.handleQRCodeDetected(code.data, code.location);
271
- } else {
272
- this.currentQRCode = null;
273
- }
274
-
275
- this.markDirty();
276
- }
277
-
278
- handleQRCodeDetected(data, location) {
279
- const now = Date.now();
280
-
281
- // Éviter les doublons rapides
282
- if (this.scanHistory.length > 0) {
283
- const lastScan = this.scanHistory[this.scanHistory.length - 1];
284
- if (lastScan.data === data && now - lastScan.timestamp < 2000) {
285
- return; // Code déjà scanné récemment
286
- }
287
- }
288
-
289
- this.currentQRCode = {
290
- data: data,
291
- location: location,
292
- timestamp: now
293
- };
294
-
295
- // Ajouter à l'historique
296
- this.scanHistory.push({
297
- data: data,
298
- timestamp: now
299
- });
300
-
301
- // Limiter l'historique
302
- if (this.scanHistory.length > 10) {
303
- this.scanHistory.shift();
304
- }
305
-
306
- // Feedback haptique
307
- if (this.vibrateOnDetect && navigator.vibrate) {
308
- navigator.vibrate(200);
309
- }
310
-
311
- // Callback
312
- if (this.onQRCodeDetected) {
313
- this.onQRCodeDetected(data);
314
- }
315
-
316
- // Stop si pas en mode continu
317
- if (!this.continuous) {
318
- this.stopScanning();
319
- }
320
-
321
- console.log('QR Code détecté:', data);
322
- }
323
-
324
- handlePress(relX, relY) {
325
- // Bouton switch caméra (haut gauche)
326
- if (relX < 60 && relY < 60) {
327
- this.switchCamera();
328
- return;
329
- }
330
-
331
- // Torch (haut droite)
332
- if (this.torchSupported && relX > this.width - 60 && relY < 60) {
333
- this.toggleTorch();
334
- return;
335
- }
336
-
337
- // Zone centrale pour réinitialiser le scan
338
- if (relX > this.width/2 - 100 && relX < this.width/2 + 100 &&
339
- relY > this.height/2 - 100 && relY < this.height/2 + 100) {
340
- if (!this.isScanning && this.loaded) {
341
- this.startScanning();
342
- }
343
- return;
344
- }
345
- }
346
-
347
- drawScannerOverlay(ctx) {
348
- if (!this.showScannerOverlay) return;
349
-
350
- const centerX = this.x + this.width / 2;
351
- const centerY = this.y + this.height / 2;
352
- const frameSize = this.scannerFrameSize;
353
- const halfSize = frameSize / 2;
354
-
355
- // Fond semi-transparent autour
356
- ctx.fillStyle = 'rgba(0, 0, 0, 0.7)';
357
-
358
- // Haut
359
- ctx.fillRect(this.x, this.y, this.width, centerY - this.y - halfSize);
360
-
361
- // Bas
362
- ctx.fillRect(this.x, centerY + halfSize, this.width, this.y + this.height - (centerY + halfSize));
363
-
364
- // Gauche
365
- ctx.fillRect(this.x, centerY - halfSize, centerX - this.x - halfSize, frameSize);
366
-
367
- // Droite
368
- ctx.fillRect(centerX + halfSize, centerY - halfSize, this.x + this.width - (centerX + halfSize), frameSize);
369
-
370
- // Cadre de scan
371
- ctx.strokeStyle = this.scannerFrameColor;
372
- ctx.lineWidth = 4;
373
- ctx.strokeRect(centerX - halfSize, centerY - halfSize, frameSize, frameSize);
374
-
375
- // Coins décoratifs
376
- const cornerSize = 20;
377
-
378
- // Coin haut gauche
379
- ctx.beginPath();
380
- ctx.moveTo(centerX - halfSize, centerY - halfSize + cornerSize);
381
- ctx.lineTo(centerX - halfSize, centerY - halfSize);
382
- ctx.lineTo(centerX - halfSize + cornerSize, centerY - halfSize);
383
- ctx.stroke();
384
-
385
- // Coin haut droit
386
- ctx.beginPath();
387
- ctx.moveTo(centerX + halfSize - cornerSize, centerY - halfSize);
388
- ctx.lineTo(centerX + halfSize, centerY - halfSize);
389
- ctx.lineTo(centerX + halfSize, centerY - halfSize + cornerSize);
390
- ctx.stroke();
391
-
392
- // Coin bas gauche
393
- ctx.beginPath();
394
- ctx.moveTo(centerX - halfSize, centerY + halfSize - cornerSize);
395
- ctx.lineTo(centerX - halfSize, centerY + halfSize);
396
- ctx.lineTo(centerX - halfSize + cornerSize, centerY + halfSize);
397
- ctx.stroke();
398
-
399
- // Coin bas droit
400
- ctx.beginPath();
401
- ctx.moveTo(centerX + halfSize - cornerSize, centerY + halfSize);
402
- ctx.lineTo(centerX + halfSize, centerY + halfSize);
403
- ctx.lineTo(centerX + halfSize, centerY + halfSize - cornerSize);
404
- ctx.stroke();
405
-
406
- // Ligne animée
407
- this.scannerLinePosition += this.scannerLineSpeed * this.scannerLineDirection;
408
- if (this.scannerLinePosition > frameSize || this.scannerLinePosition < 0) {
409
- this.scannerLineDirection *= -1;
410
- }
411
-
412
- const lineY = centerY - halfSize + this.scannerLinePosition;
413
- ctx.fillStyle = this.scannerLineColor;
414
- ctx.fillRect(centerX - halfSize, lineY, frameSize, this.scannerLineHeight);
415
- }
416
-
417
- drawControls(ctx) {
418
- // Bouton switch caméra
419
- ctx.fillStyle = 'rgba(0,0,0,0.5)';
420
- ctx.beginPath();
421
- ctx.arc(this.x + 30, this.y + 30, 25, 0, Math.PI * 2);
422
- ctx.fill();
423
-
424
- // Icône caméra
425
- ctx.fillStyle = '#fff';
426
- ctx.font = '20px Arial';
427
- ctx.textAlign = 'center';
428
- ctx.textBaseline = 'middle';
429
- ctx.fillText('🔄', this.x + 30, this.y + 30);
430
-
431
- // Torch
432
- if (this.torchSupported) {
433
- ctx.fillStyle = 'rgba(0,0,0,0.5)';
434
- ctx.beginPath();
435
- ctx.arc(this.x + this.width - 30, this.y + 30, 25, 0, Math.PI * 2);
436
- ctx.fill();
437
-
438
- ctx.fillStyle = this.torchOn ? '#ffeb3b' : '#fff';
439
- ctx.fillText('⚡', this.x + this.width - 30, this.y + 30);
440
- }
441
-
442
- // État du scan
443
- const scanStatusY = this.y + this.height - 40;
444
- ctx.fillStyle = this.isScanning ? '#4CAF50' : '#FF5722';
445
- ctx.font = '14px Arial';
446
- ctx.textAlign = 'center';
447
- ctx.fillText(
448
- this.isScanning ? 'Scan en cours...' : 'Scan arrêté',
449
- this.x + this.width / 2,
450
- scanStatusY
451
- );
452
-
453
- // Dernier QR code détecté
454
- if (this.currentQRCode) {
455
- ctx.fillStyle = 'rgba(0, 150, 0, 0.8)';
456
- ctx.fillRect(this.x, this.y + this.height - 90, this.width, 40);
457
-
458
- ctx.fillStyle = '#fff';
459
- ctx.font = '12px Arial';
460
- ctx.textAlign = 'center';
461
-
462
- // Tronquer si trop long
463
- const displayText = this.currentQRCode.data.length > 50
464
- ? this.currentQRCode.data.substring(0, 47) + '...'
465
- : this.currentQRCode.data;
466
-
467
- ctx.fillText(
468
- `QR Code: ${displayText}`,
469
- this.x + this.width / 2,
470
- this.y + this.height - 70
471
- );
472
- }
473
- }
474
-
475
- draw(ctx) {
476
- ctx.save();
477
-
478
- // Fond
479
- ctx.fillStyle = '#000';
480
- ctx.fillRect(this.x, this.y, this.width, this.height);
481
-
482
- if (this.error) {
483
- ctx.fillStyle = '#ff4444';
484
- ctx.font = '16px Arial';
485
- ctx.textAlign = 'center';
486
- ctx.textBaseline = 'middle';
487
- ctx.fillText(this.error, this.x + this.width/2, this.y + this.height/2);
488
- } else if (!this.loaded) {
489
- ctx.fillStyle = '#fff';
490
- ctx.font = '16px Arial';
491
- ctx.textAlign = 'center';
492
- ctx.textBaseline = 'middle';
493
- ctx.fillText('Démarrage caméra...', this.x + this.width/2, this.y + this.height/2);
494
- } else if (this.video && this.loaded) {
495
- // Ajustement de la vidéo (cover pour remplir l'écran)
496
- const videoRatio = this.video.videoWidth / this.video.videoHeight;
497
- const canvasRatio = this.width / this.height;
498
-
499
- let drawWidth = this.width;
500
- let drawHeight = this.height;
501
- let offsetX = 0;
502
- let offsetY = 0;
503
-
504
- if (videoRatio > canvasRatio) {
505
- drawHeight = this.height;
506
- drawWidth = drawHeight * videoRatio;
507
- offsetX = (this.width - drawWidth) / 2;
508
- } else {
509
- drawWidth = this.width;
510
- drawHeight = drawWidth / videoRatio;
511
- offsetY = (this.height - drawHeight) / 2;
512
- }
513
-
514
- ctx.drawImage(this.video, this.x + offsetX, this.y + offsetY, drawWidth, drawHeight);
515
-
516
- // Dessiner l'overlay de scan
517
- this.drawScannerOverlay(ctx);
518
-
519
- // Dessiner les contrôles
520
- this.drawControls(ctx);
521
- }
522
-
523
- // Instructions
524
- if (this.loaded && !this.currentQRCode) {
525
- ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
526
- ctx.font = '16px Arial';
527
- ctx.textAlign = 'center';
528
- ctx.fillText(
529
- 'Placez un QR code dans le cadre',
530
- this.x + this.width / 2,
531
- this.y + this.height / 2 + 150
532
- );
533
- }
534
-
535
- ctx.restore();
536
- }
537
- }
538
-
539
- export default QRCodeReader;
@@ -1,151 +0,0 @@
1
- import Component from '../core/Component.js';
2
-
3
- /**
4
- * Bouton radio pour les sélections uniques
5
- * @class
6
- * @extends Component
7
- * @property {string} group - Groupe de boutons radio
8
- * @property {boolean} checked - État sélectionné
9
- * @property {string} label - Texte du label
10
- * @property {string} platform - Plateforme
11
- * @property {number} circleSize - Taille du cercle
12
- * @property {number} circleRadius - Rayon du cercle
13
- * @property {Function} onChange - Callback au changement
14
- */
15
- class RadioButton extends Component {
16
- /**
17
- * Crée une instance de RadioButton
18
- * @param {CanvasFramework} framework - Framework parent
19
- * @param {Object} [options={}] - Options de configuration
20
- * @param {string} [options.group='default'] - Groupe de boutons
21
- * @param {boolean} [options.checked=false] - État initial
22
- * @param {string} [options.label=''] - Texte du label
23
- * @param {Function} [options.onChange] - Callback au changement
24
- */
25
- constructor(framework, options = {}) {
26
- super(framework, options);
27
- this.group = options.group || 'default';
28
- this.checked = options.checked || false;
29
- this.label = options.label || '';
30
- this.labelColor = options.labelColor || '#000000'; // Nouvelle propriété
31
- this.platform = framework.platform;
32
- this.circleSize = 24; // Taille du cercle
33
- this.circleRadius = 10; // Rayon du cercle
34
- this.onChange = options.onChange;
35
-
36
- // Calculer la largeur totale incluant le label
37
- this.totalWidth = this.label ? this.circleSize + 8 + this.getTextWidth(this.label) : this.circleSize;
38
- this.width = this.totalWidth; // Mettre à jour la largeur totale
39
- this.height = this.circleSize; // Garder la même hauteur
40
-
41
- // Définir onClick
42
- this.onClick = this.handleClick.bind(this);
43
- }
44
-
45
- /**
46
- * Calcule la largeur du texte
47
- * @param {string} text - Texte à mesurer
48
- * @returns {number} Largeur du texte
49
- * @private
50
- */
51
- getTextWidth(text) {
52
- // Utiliser le contexte temporaire pour mesurer le texte
53
- const ctx = this.framework.ctx;
54
- ctx.save();
55
- ctx.font = '16px -apple-system, sans-serif';
56
- const width = ctx.measureText(text).width;
57
- ctx.restore();
58
- return width;
59
- }
60
-
61
- /**
62
- * Gère le clic sur le bouton radio
63
- * @private
64
- */
65
- handleClick() {
66
- // Décocher les autres du même groupe
67
- for (let comp of this.framework.components) {
68
- if (comp instanceof RadioButton && comp.group === this.group && comp !== this) {
69
- comp.checked = false;
70
- }
71
- }
72
- this.checked = true;
73
- if (this.onChange) this.onChange(this.checked);
74
- }
75
-
76
- /**
77
- * Dessine le bouton radio
78
- * @param {CanvasRenderingContext2D} ctx - Contexte de dessin
79
- */
80
- draw(ctx) {
81
- ctx.save();
82
-
83
- const centerX = this.x + this.circleSize / 2;
84
- const centerY = this.y + this.circleSize / 2;
85
-
86
- if (this.platform === 'material') {
87
- // Outer circle
88
- ctx.strokeStyle = this.checked ? '#6200EE' : '#666666';
89
- ctx.lineWidth = 2;
90
- ctx.beginPath();
91
- ctx.arc(centerX, centerY, this.circleRadius, 0, Math.PI * 2);
92
- ctx.stroke();
93
-
94
- // Inner circle
95
- if (this.checked) {
96
- ctx.fillStyle = '#6200EE';
97
- ctx.beginPath();
98
- ctx.arc(centerX, centerY, 5, 0, Math.PI * 2);
99
- ctx.fill();
100
- }
101
- } else {
102
- // Cupertino (iOS style)
103
- if (this.checked) {
104
- // Cercle bleu rempli
105
- ctx.fillStyle = '#007AFF';
106
- ctx.beginPath();
107
- ctx.arc(centerX, centerY, this.circleRadius, 0, Math.PI * 2);
108
- ctx.fill();
109
-
110
- // Point blanc au centre
111
- ctx.fillStyle = '#FFFFFF';
112
- ctx.beginPath();
113
- ctx.arc(centerX, centerY, 4, 0, Math.PI * 2);
114
- ctx.fill();
115
- } else {
116
- // Cercle gris clair
117
- ctx.strokeStyle = '#D1D1D6';
118
- ctx.lineWidth = 1.5;
119
- ctx.beginPath();
120
- ctx.arc(centerX, centerY, this.circleRadius, 0, Math.PI * 2);
121
- ctx.stroke();
122
- }
123
- }
124
-
125
- // Label
126
- if (this.label) {
127
- ctx.fillStyle = this.labelColor; // Au lieu de '#000000'
128
- ctx.font = '16px -apple-system, sans-serif';
129
- ctx.textAlign = 'left';
130
- ctx.textBaseline = 'middle';
131
- ctx.fillText(this.label, this.x + this.circleSize + 8, centerY);
132
- }
133
-
134
- ctx.restore();
135
- }
136
-
137
- /**
138
- * Vérifie si un point est dans les limites
139
- * @param {number} x - Coordonnée X
140
- * @param {number} y - Coordonnée Y
141
- * @returns {boolean} True si le point est dans le bouton
142
- */
143
- isPointInside(x, y) {
144
- return x >= this.x &&
145
- x <= this.x + this.width &&
146
- y >= this.y &&
147
- y <= this.y + this.height;
148
- }
149
- }
150
-
151
- export default RadioButton;