@mleonard9/vin-scanner 1.4.0 → 1.4.3

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 (48) hide show
  1. package/README.md +6 -38
  2. package/ios/VisionCameraBarcodeScanner.m +4 -4
  3. package/ios/VisionCameraTextRecognition.m +5 -5
  4. package/lib/commonjs/ManualVinInput.js +1 -2
  5. package/lib/commonjs/ManualVinInput.js.map +1 -1
  6. package/lib/commonjs/PendingVinBanner.js.map +1 -1
  7. package/lib/commonjs/TextVinPrompt.js.map +1 -1
  8. package/lib/commonjs/haptics.js +1 -1
  9. package/lib/commonjs/haptics.js.map +1 -1
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/scanBarcodes.js.map +1 -1
  12. package/lib/commonjs/scanText.js.map +1 -1
  13. package/lib/commonjs/useVinScanner.js.map +1 -1
  14. package/lib/commonjs/vinUtils.js +8 -8
  15. package/lib/commonjs/vinUtils.js.map +1 -1
  16. package/lib/module/ManualVinInput.js +1 -2
  17. package/lib/module/ManualVinInput.js.map +1 -1
  18. package/lib/module/PendingVinBanner.js.map +1 -1
  19. package/lib/module/TextVinPrompt.js.map +1 -1
  20. package/lib/module/haptics.js +1 -1
  21. package/lib/module/haptics.js.map +1 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/scanBarcodes.js.map +1 -1
  24. package/lib/module/scanText.js.map +1 -1
  25. package/lib/module/useVinScanner.js.map +1 -1
  26. package/lib/module/vinUtils.js +8 -8
  27. package/lib/module/vinUtils.js.map +1 -1
  28. package/lib/typescript/src/ManualVinInput.d.ts.map +1 -1
  29. package/lib/typescript/src/PendingVinBanner.d.ts.map +1 -1
  30. package/lib/typescript/src/TextVinPrompt.d.ts.map +1 -1
  31. package/lib/typescript/src/haptics.d.ts.map +1 -1
  32. package/lib/typescript/src/index.d.ts.map +1 -1
  33. package/lib/typescript/src/scanBarcodes.d.ts.map +1 -1
  34. package/lib/typescript/src/scanText.d.ts.map +1 -1
  35. package/lib/typescript/src/types.d.ts.map +1 -1
  36. package/lib/typescript/src/useVinScanner.d.ts.map +1 -1
  37. package/lib/typescript/src/vinUtils.d.ts.map +1 -1
  38. package/package.json +1 -3
  39. package/src/ManualVinInput.tsx +44 -5
  40. package/src/PendingVinBanner.tsx +4 -5
  41. package/src/TextVinPrompt.tsx +10 -2
  42. package/src/haptics.ts +2 -5
  43. package/src/index.tsx +46 -22
  44. package/src/scanBarcodes.ts +5 -1
  45. package/src/scanText.ts +5 -1
  46. package/src/types.ts +9 -4
  47. package/src/useVinScanner.ts +38 -28
  48. package/src/vinUtils.ts +112 -70
package/src/vinUtils.ts CHANGED
@@ -81,9 +81,9 @@ const DEFAULT_RESOLVED_OPTIONS: ResolvedVinScannerOptions = {
81
81
  },
82
82
  showOverlay: false,
83
83
  overlayColors: {
84
- high: "#00FF00",
85
- medium: "#FFFF00",
86
- low: "#FF0000",
84
+ high: '#00FF00',
85
+ medium: '#FFFF00',
86
+ low: '#FF0000',
87
87
  },
88
88
  duplicateDebounceMs: 1500,
89
89
  };
@@ -96,7 +96,7 @@ export const resolveOptions = (
96
96
  const textScanInterval = Math.max(
97
97
  1,
98
98
  options?.detection?.textScanInterval ??
99
- DEFAULT_RESOLVED_OPTIONS.detection.textScanInterval
99
+ DEFAULT_RESOLVED_OPTIONS.detection.textScanInterval
100
100
  );
101
101
 
102
102
  return {
@@ -115,7 +115,8 @@ export const resolveOptions = (
115
115
  options?.text?.requireConfirmation ??
116
116
  DEFAULT_RESOLVED_OPTIONS.text.requireConfirmation,
117
117
  pendingTtlMs:
118
- options?.text?.pendingTtlMs ?? DEFAULT_RESOLVED_OPTIONS.text.pendingTtlMs,
118
+ options?.text?.pendingTtlMs ??
119
+ DEFAULT_RESOLVED_OPTIONS.text.pendingTtlMs,
119
120
  },
120
121
  detection: {
121
122
  textScanInterval,
@@ -125,15 +126,25 @@ export const resolveOptions = (
125
126
  forceOrientation:
126
127
  options?.detection?.forceOrientation ??
127
128
  DEFAULT_RESOLVED_OPTIONS.detection.forceOrientation,
128
- scanRegion: options?.detection?.scanRegion ?? DEFAULT_RESOLVED_OPTIONS.detection.scanRegion,
129
+ scanRegion:
130
+ options?.detection?.scanRegion ??
131
+ DEFAULT_RESOLVED_OPTIONS.detection.scanRegion,
129
132
  minLuma:
130
- options?.detection?.minLuma ?? DEFAULT_RESOLVED_OPTIONS.detection.minLuma,
133
+ options?.detection?.enableFrameQualityCheck === false
134
+ ? 0
135
+ : (options?.detection?.minLuma ??
136
+ DEFAULT_RESOLVED_OPTIONS.detection.minLuma),
131
137
  minSharpness:
132
- options?.detection?.minSharpness ?? DEFAULT_RESOLVED_OPTIONS.detection.minSharpness,
138
+ options?.detection?.enableFrameQualityCheck === false
139
+ ? 0
140
+ : (options?.detection?.minSharpness ??
141
+ DEFAULT_RESOLVED_OPTIONS.detection.minSharpness),
133
142
  minConfidence:
134
- options?.detection?.minConfidence ?? DEFAULT_RESOLVED_OPTIONS.detection.minConfidence,
143
+ options?.detection?.minConfidence ??
144
+ DEFAULT_RESOLVED_OPTIONS.detection.minConfidence,
135
145
  barcodeFallbackAfter:
136
- options?.detection?.barcodeFallbackAfter ?? DEFAULT_RESOLVED_OPTIONS.detection.barcodeFallbackAfter,
146
+ options?.detection?.barcodeFallbackAfter ??
147
+ DEFAULT_RESOLVED_OPTIONS.detection.barcodeFallbackAfter,
137
148
  },
138
149
  showOverlay: options?.showOverlay ?? false,
139
150
  overlayColors: {
@@ -307,24 +318,56 @@ const calculateConfidence = (
307
318
  // Known manufacturer WMI prefixes (first 3 characters) increase confidence
308
319
  const wmi = value.slice(0, 3);
309
320
  const knownManufacturers = [
310
- '1G1', '1G2', '1G3', '1G4', '1G6', // GM
311
- '1FA', '1FB', '1FC', '1FD', '1FM', '1FT', // Ford
312
- '1HG', '1HC', // Honda
313
- '1N4', '1N6', // Nissan
314
- '2C3', '2C4', // Chrysler
315
- '2HG', '2HM', // Honda
316
- '2T1', '2T2', '2T3', // Toyota
317
- '3FA', '3FE', // Ford Mexico
318
- '4T1', '4T3', // Toyota
319
- '5FN', '5FY', // Honda
320
- '5TD', '5TF', '5TJ', // Toyota
321
- 'JHM', 'JHL', // Honda Japan
322
- 'JT2', 'JT3', 'JTD', // Toyota Japan
323
- 'KM8', 'KNA', 'KND', // Hyundai/Kia
324
- 'WBA', 'WBS', 'WBY', // BMW
325
- 'WDB', 'WDC', 'WDD', // Mercedes
326
- 'WAU', 'WA1', // Audi
327
- 'WVW', 'WV1', 'WV2', // VW
321
+ '1G1',
322
+ '1G2',
323
+ '1G3',
324
+ '1G4',
325
+ '1G6', // GM
326
+ '1FA',
327
+ '1FB',
328
+ '1FC',
329
+ '1FD',
330
+ '1FM',
331
+ '1FT', // Ford
332
+ '1HG',
333
+ '1HC', // Honda
334
+ '1N4',
335
+ '1N6', // Nissan
336
+ '2C3',
337
+ '2C4', // Chrysler
338
+ '2HG',
339
+ '2HM', // Honda
340
+ '2T1',
341
+ '2T2',
342
+ '2T3', // Toyota
343
+ '3FA',
344
+ '3FE', // Ford Mexico
345
+ '4T1',
346
+ '4T3', // Toyota
347
+ '5FN',
348
+ '5FY', // Honda
349
+ '5TD',
350
+ '5TF',
351
+ '5TJ', // Toyota
352
+ 'JHM',
353
+ 'JHL', // Honda Japan
354
+ 'JT2',
355
+ 'JT3',
356
+ 'JTD', // Toyota Japan
357
+ 'KM8',
358
+ 'KNA',
359
+ 'KND', // Hyundai/Kia
360
+ 'WBA',
361
+ 'WBS',
362
+ 'WBY', // BMW
363
+ 'WDB',
364
+ 'WDC',
365
+ 'WDD', // Mercedes
366
+ 'WAU',
367
+ 'WA1', // Audi
368
+ 'WVW',
369
+ 'WV1',
370
+ 'WV2', // VW
328
371
  ];
329
372
  if (knownManufacturers.includes(wmi)) {
330
373
  score += 0.15;
@@ -383,7 +426,6 @@ const calculateConfidence = (
383
426
  return Math.min(1.0, Math.max(0.0, score));
384
427
  };
385
428
 
386
-
387
429
  /**
388
430
  * Tokenize and extract VIN candidates from raw text
389
431
  * Includes OCR error correction and context-aware extraction
@@ -508,24 +550,24 @@ export const isValidVin = (value: string): boolean => {
508
550
  const toBoundingBox = (
509
551
  candidate:
510
552
  | Pick<
511
- BarcodeDetection,
512
- 'top' | 'bottom' | 'left' | 'right' | 'width' | 'height'
513
- >
553
+ BarcodeDetection,
554
+ 'top' | 'bottom' | 'left' | 'right' | 'width' | 'height'
555
+ >
514
556
  | Pick<
515
- TextDetection,
516
- | 'blockFrameTop'
517
- | 'blockFrameBottom'
518
- | 'blockFrameLeft'
519
- | 'blockFrameRight'
520
- | 'lineFrameTop'
521
- | 'lineFrameBottom'
522
- | 'lineFrameLeft'
523
- | 'lineFrameRight'
524
- | 'elementFrameTop'
525
- | 'elementFrameBottom'
526
- | 'elementFrameLeft'
527
- | 'elementFrameRight'
528
- >,
557
+ TextDetection,
558
+ | 'blockFrameTop'
559
+ | 'blockFrameBottom'
560
+ | 'blockFrameLeft'
561
+ | 'blockFrameRight'
562
+ | 'lineFrameTop'
563
+ | 'lineFrameBottom'
564
+ | 'lineFrameLeft'
565
+ | 'lineFrameRight'
566
+ | 'elementFrameTop'
567
+ | 'elementFrameBottom'
568
+ | 'elementFrameLeft'
569
+ | 'elementFrameRight'
570
+ >,
529
571
  preferred: 'block' | 'line' | 'element' | 'barcode'
530
572
  ) => {
531
573
  'worklet';
@@ -554,39 +596,39 @@ const toBoundingBox = (
554
596
  const block = candidate as TextDetection;
555
597
  const blockBox =
556
598
  typeof block.blockFrameTop === 'number' &&
557
- typeof block.blockFrameBottom === 'number' &&
558
- typeof block.blockFrameLeft === 'number' &&
559
- typeof block.blockFrameRight === 'number'
599
+ typeof block.blockFrameBottom === 'number' &&
600
+ typeof block.blockFrameLeft === 'number' &&
601
+ typeof block.blockFrameRight === 'number'
560
602
  ? {
561
- top: block.blockFrameTop,
562
- bottom: block.blockFrameBottom,
563
- left: block.blockFrameLeft,
564
- right: block.blockFrameRight,
565
- }
603
+ top: block.blockFrameTop,
604
+ bottom: block.blockFrameBottom,
605
+ left: block.blockFrameLeft,
606
+ right: block.blockFrameRight,
607
+ }
566
608
  : undefined;
567
609
  const lineBox =
568
610
  typeof block.lineFrameTop === 'number' &&
569
- typeof block.lineFrameBottom === 'number' &&
570
- typeof block.lineFrameLeft === 'number' &&
571
- typeof block.lineFrameRight === 'number'
611
+ typeof block.lineFrameBottom === 'number' &&
612
+ typeof block.lineFrameLeft === 'number' &&
613
+ typeof block.lineFrameRight === 'number'
572
614
  ? {
573
- top: block.lineFrameTop,
574
- bottom: block.lineFrameBottom,
575
- left: block.lineFrameLeft,
576
- right: block.lineFrameRight,
577
- }
615
+ top: block.lineFrameTop,
616
+ bottom: block.lineFrameBottom,
617
+ left: block.lineFrameLeft,
618
+ right: block.lineFrameRight,
619
+ }
578
620
  : undefined;
579
621
  const elementBox =
580
622
  typeof block.elementFrameTop === 'number' &&
581
- typeof block.elementFrameBottom === 'number' &&
582
- typeof block.elementFrameLeft === 'number' &&
583
- typeof block.elementFrameRight === 'number'
623
+ typeof block.elementFrameBottom === 'number' &&
624
+ typeof block.elementFrameLeft === 'number' &&
625
+ typeof block.elementFrameRight === 'number'
584
626
  ? {
585
- top: block.elementFrameTop,
586
- bottom: block.elementFrameBottom,
587
- left: block.elementFrameLeft,
588
- right: block.elementFrameRight,
589
- }
627
+ top: block.elementFrameTop,
628
+ bottom: block.elementFrameBottom,
629
+ left: block.elementFrameLeft,
630
+ right: block.elementFrameRight,
631
+ }
590
632
  : undefined;
591
633
 
592
634
  if (preferred === 'element' && elementBox) {