diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f06235c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/barcode-scanner.js b/barcode-scanner.js deleted file mode 100644 index 6189de7..0000000 --- a/barcode-scanner.js +++ /dev/null @@ -1,157 +0,0 @@ -// barcode-scanner.js - Barcode scanning module with console logging for testing - -/** - * Initialize barcode scanner with dual input support: - * - Keyboard input (simulation) - * - Hardware barcode scanner devices - * - * Logs scanned barcodes to console for testing purposes - */ - -let barcodeBuffer = ''; -let lastBarcodeTime = 0; -const SCANNER_TIMEOUT = 100; // ms - detect hardware scanner vs human typing - -/** - * Log barcode to console with metadata - * @param {string} barcode - The scanned barcode value - * @param {string} inputType - Either 'keyboard' or 'hardware-scanner' - */ -export function logBarcodeToConsole(barcode, inputType = 'keyboard') { - const timestamp = new Date().toLocaleTimeString('en-US', { - hour12: false, - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - fractionalSecondDigits: 3 - }); - - console.log( - `%c[Barcode Scanned] %c${timestamp} | %cBarcode: %c${barcode} %c| Input: %c${inputType}`, - 'color: #4CAF50; font-weight: bold;', - 'color: #666; font-family: monospace;', - 'color: #333; font-weight: bold;', - 'color: #2196F3; font-weight: bold; font-family: monospace;', - 'color: #666;', - 'color: #FF9800; font-weight: bold;' - ); - - // Additional metadata for debugging - console.log({ - barcode, - timestamp: new Date().toISOString(), - inputType, - length: barcode.length - }); -} - -/** - * Detect if input is from a hardware scanner or keyboard - * Hardware scanners typically input a full barcode very quickly (within SCANNER_TIMEOUT ms) - * @returns {string} - 'hardware-scanner' or 'keyboard' - */ -function detectInputType(currentTime) { - const timeSinceLastInput = currentTime - lastBarcodeTime; - lastBarcodeTime = currentTime; - - // If more than SCANNER_TIMEOUT ms since last character, it's likely keyboard input - return timeSinceLastInput > SCANNER_TIMEOUT ? 'keyboard' : 'hardware-scanner'; -} - -/** - * Handle barcode input from both keyboard and hardware scanner - * @param {HTMLElement} inputElement - The input field element - * @param {Function} onBarcodeScanned - Callback function when barcode is complete - */ -export function initializeBarcodeScanner(inputElement, onBarcodeScanned) { - if (!inputElement) { - console.error('Barcode input element not found'); - return; - } - - // Auto-focus for seamless scanning - inputElement.focus(); - - inputElement.addEventListener('keypress', (event) => { - // Most barcode scanners send Enter key at the end - if (event.key === 'Enter') { - event.preventDefault(); - - const barcode = inputElement.value.trim(); - - if (barcode) { - // Detect input type - const inputType = barcodeBuffer.length === 0 ? 'keyboard' : 'hardware-scanner'; - barcodeBuffer = ''; - - // Log to console - logBarcodeToConsole(barcode, inputType); - - // Call the callback function - if (onBarcodeScanned) { - onBarcodeScanned(barcode, inputType); - } - } - - // Clear input for next scan - inputElement.value = ''; - inputElement.focus(); - } else { - // Accumulate characters in buffer for input type detection - const now = Date.now(); - if (barcodeBuffer === '') { - lastBarcodeTime = now; - } - barcodeBuffer += event.key; - } - }); - - // Handle pasted input (in case user pastes barcode) - inputElement.addEventListener('paste', (event) => { - event.preventDefault(); - - const pastedText = (event.clipboardData || window.clipboardData).getData('text').trim(); - - if (pastedText) { - logBarcodeToConsole(pastedText, 'keyboard-paste'); - - if (onBarcodeScanned) { - onBarcodeScanned(pastedText, 'keyboard-paste'); - } - } - - inputElement.value = ''; - inputElement.focus(); - }); - - // Maintain focus - inputElement.addEventListener('blur', () => { - setTimeout(() => inputElement.focus(), 0); - }); - - console.log('%cBarcode Scanner Initialized', 'color: #4CAF50; font-weight: bold;'); - console.log('Ready to scan. Focus the input field and scan a barcode or press Enter to complete.'); -} - -/** - * Get scanning statistics from console (for testing) - * This is just a helper for development/testing - * @returns {Object} - Statistics object - */ -export function getScanningStats() { - return { - initialized: true, - timestamp: new Date().toISOString(), - message: 'Barcode scanner is active. Check console for scanned barcodes.' - }; -} - -/** - * Log camera-detected barcode to console - * Camera detection is already included in logBarcodeToConsole with inputType = 'camera' - * This function maintains backward compatibility - * @param {string} barcode - The camera-detected barcode - */ -export function logCameraDetectedBarcode(barcode) { - logBarcodeToConsole(barcode, 'camera-device'); -} diff --git a/barcode.html b/barcode.html deleted file mode 100644 index b229668..0000000 --- a/barcode.html +++ /dev/null @@ -1,615 +0,0 @@ - - - - - - - Barcode Scanner - - - - - -
-

Barcode Scanner

-
- -
-
-

📱 Barcode Scanner

-

Scan barcodes using camera or keyboard input

-
- - -
- - -
- - -
- - -
-
- ✓ Scanner Ready - Click below and scan a barcode -
- -
- - -
- -
-

How to Use (Keyboard):

-
    -
  • Keyboard Entry: Type or paste a barcode and press Enter
  • -
  • Hardware Scanner: Plug in a barcode scanner and scan directly
  • -
  • Testing: Scanned barcodes are logged to the browser console (Press F12)
  • -
-
-
- - -
-
- 📷 Camera Ready - Click "Start Camera" to begin scanning -
- - - -
- - -
- -
-
Detected Barcode:
-
-
-
- -
-

How to Use (Camera):

-
    -
  • Permission: Browser will request camera access on first use
  • -
  • Position: Hold barcode in front of camera lens
  • -
  • Detection: Barcode is detected automatically in real-time
  • -
  • Supported: UPC, EAN, Code-128, Code-39, and more
  • -
  • Console: All detections logged to console (Press F12)
  • -
-
-
- -
- 🔍 View Console Output: - Press F12 (or Cmd+Option+I on Mac) to open Developer Tools. Check the Console tab to see scanned barcodes logged with timestamps and input type detection. -
- -
- - -
-
-
- - - - - diff --git a/index.html b/index.html index fc6cb7a..7616fda 100644 --- a/index.html +++ b/index.html @@ -1,47 +1,12 @@ - - - - - - - Homepage - - - -
-

Homepage

-
-

To use

-
- -
-

Inventory Breakdown

-
- - - - - - -
-
-
- - - - \ No newline at end of file + + + + + + Webpage Playground + + +
+ + + diff --git a/item-component.js b/item-component.js deleted file mode 100644 index f28ca5c..0000000 --- a/item-component.js +++ /dev/null @@ -1,92 +0,0 @@ -// item-component.js -// Reusable item component: image on left, three text areas on right. - -const _ensureStyles = (() => { - if (document.getElementById('item-component-styles')) return true; - const style = document.createElement('style'); - style.id = 'item-component-styles'; - style.textContent = ` -/* Grid wrapper for multiple item components */ -.item-component-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;align-items:start} -.item-component{display:flex;align-items:flex-start;gap:12px;font-family:inherit;padding:10px;border:1px solid #e6e6e6;border-radius:8px;background:#fff} -.item-component__img{flex:0 0 auto} -.item-component__img img{display:block;width:72px;height:72px;object-fit:cover;border-radius:6px} -.item-component__content{flex:1;display:flex;flex-direction:column;gap:6px} -.item-component__line{margin:0;padding:0;color:#222} -.item-component__line--title{font-weight:700} -.item-component__line--subtitle{color:#555;font-size:0.95em} -.item-component__line--desc{color:#666;font-size:0.9em} -.item-component__textarea{width:100%;box-sizing:border-box;padding:6px;font:inherit;border:1px solid #ccc;border-radius:4px} - -/* Responsive: on small screens show 1 or 2 columns */ -@media (max-width: 900px){ - .item-component-grid{grid-template-columns:repeat(2,1fr)} -} -@media (max-width: 560px){ - .item-component-grid{grid-template-columns:repeat(1,1fr)} -} -`; - document.head.appendChild(style); - return true; -})(); - -/** - * Create an item component element. - * @param {Object} opts - * @param {string} opts.imgSrc - image URL - * @param {string} opts.imgAlt - image alt text - * @param {string} opts.text1 - first text area (title) - * @param {string} opts.text2 - second text area (subtitle) - * @param {string} opts.text3 - third text area (description) - * @param {boolean} opts.editable - if true, text areas are `