Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
f3a4c1af05
|
|||
|
616f615d7c
|
|||
|
4d572b55ca
|
|||
|
9822cab93e
|
|||
|
9409bd3e21
|
|||
|
346ded460a
|
|||
|
170539a62f
|
|||
|
cfc1785863
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
|
public/wasm
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.vscode/*
|
.vscode/*
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "tools-app",
|
"name": "tools-app",
|
||||||
"version": "0.6.5",
|
"version": "0.6.9",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "tools-app",
|
"name": "tools-app",
|
||||||
"version": "0.6.5",
|
"version": "0.6.9",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"barcode-detector": "^3.1.0",
|
"barcode-detector": "^3.1.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "tools-app",
|
"name": "tools-app",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.6.5",
|
"version": "0.6.9",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
Binary file not shown.
@@ -8,7 +8,7 @@ const scannedCodes = ref([])
|
|||||||
const hasMultipleCameras = ref(false)
|
const hasMultipleCameras = ref(false)
|
||||||
const isFullscreen = ref(false)
|
const isFullscreen = ref(false)
|
||||||
const videoAspect = ref(1)
|
const videoAspect = ref(1)
|
||||||
const isFront = computed(() => facingMode.value === 'user')
|
const isMirrored = ref(false)
|
||||||
const wrapperRef = ref(null)
|
const wrapperRef = ref(null)
|
||||||
const bgCanvas = ref(null)
|
const bgCanvas = ref(null)
|
||||||
let bgRafId = null
|
let bgRafId = null
|
||||||
@@ -19,6 +19,95 @@ let stream = null
|
|||||||
let scanRafId = null
|
let scanRafId = null
|
||||||
let barcodeDetector = null
|
let barcodeDetector = null
|
||||||
|
|
||||||
|
const overlayCanvas = ref(null)
|
||||||
|
|
||||||
|
const paintDetections = (codes) => {
|
||||||
|
const canvas = overlayCanvas.value
|
||||||
|
const video = videoRef.value
|
||||||
|
|
||||||
|
if (!canvas || !video) return
|
||||||
|
|
||||||
|
const ctx = canvas.getContext('2d')
|
||||||
|
const { width, height } = canvas.getBoundingClientRect()
|
||||||
|
|
||||||
|
// Update canvas size if needed (to match CSS size)
|
||||||
|
if (canvas.width !== width || canvas.height !== height) {
|
||||||
|
canvas.width = width
|
||||||
|
canvas.height = height
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.clearRect(0, 0, width, height)
|
||||||
|
|
||||||
|
if (!codes || codes.length === 0) return
|
||||||
|
|
||||||
|
const vw = video.videoWidth
|
||||||
|
const vh = video.videoHeight
|
||||||
|
if (!vw || !vh) return
|
||||||
|
|
||||||
|
// Calculate object-fit: cover scaling
|
||||||
|
const videoRatio = vw / vh
|
||||||
|
const canvasRatio = width / height
|
||||||
|
|
||||||
|
let drawWidth, drawHeight, startX, startY
|
||||||
|
|
||||||
|
if (canvasRatio > videoRatio) {
|
||||||
|
// Canvas is wider than video (video cropped top/bottom)
|
||||||
|
drawWidth = width
|
||||||
|
drawHeight = width / videoRatio
|
||||||
|
startX = 0
|
||||||
|
startY = (height - drawHeight) / 2
|
||||||
|
} else {
|
||||||
|
// Canvas is taller than video (video cropped left/right)
|
||||||
|
drawHeight = height
|
||||||
|
drawWidth = height * videoRatio
|
||||||
|
startY = 0
|
||||||
|
startX = (width - drawWidth) / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
const scale = drawWidth / vw
|
||||||
|
// Canvas is mirrored via CSS if isMirrored is true, so no manual coordinate mirroring needed
|
||||||
|
|
||||||
|
// Styles
|
||||||
|
const styles = getComputedStyle(document.documentElement)
|
||||||
|
const accent = styles.getPropertyValue('--primary-accent').trim() || '#00f2fe'
|
||||||
|
|
||||||
|
ctx.lineWidth = 4
|
||||||
|
ctx.strokeStyle = accent
|
||||||
|
ctx.fillStyle = accent
|
||||||
|
|
||||||
|
codes.forEach(code => {
|
||||||
|
const points = code.cornerPoints
|
||||||
|
if (!points || points.length < 4) return
|
||||||
|
|
||||||
|
ctx.beginPath()
|
||||||
|
|
||||||
|
const transform = (p) => {
|
||||||
|
let x = p.x * scale + startX
|
||||||
|
let y = p.y * scale + startY
|
||||||
|
return { x, y }
|
||||||
|
}
|
||||||
|
|
||||||
|
const p0 = transform(points[0])
|
||||||
|
ctx.moveTo(p0.x, p0.y)
|
||||||
|
|
||||||
|
for (let i = 1; i < points.length; i++) {
|
||||||
|
const p = transform(points[i])
|
||||||
|
ctx.lineTo(p.x, p.y)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.closePath()
|
||||||
|
ctx.stroke()
|
||||||
|
|
||||||
|
// Draw corners
|
||||||
|
points.forEach(p => {
|
||||||
|
const tp = transform(p)
|
||||||
|
ctx.beginPath()
|
||||||
|
ctx.arc(tp.x, tp.y, 4, 0, Math.PI * 2)
|
||||||
|
ctx.fill()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const updateVideoAspect = () => {
|
const updateVideoAspect = () => {
|
||||||
if (videoRef.value && videoRef.value.videoWidth && videoRef.value.videoHeight) {
|
if (videoRef.value && videoRef.value.videoWidth && videoRef.value.videoHeight) {
|
||||||
videoAspect.value = videoRef.value.videoWidth / videoRef.value.videoHeight
|
videoAspect.value = videoRef.value.videoWidth / videoRef.value.videoHeight
|
||||||
@@ -110,6 +199,23 @@ const startScan = async () => {
|
|||||||
|
|
||||||
stream = await navigator.mediaDevices.getUserMedia(constraints)
|
stream = await navigator.mediaDevices.getUserMedia(constraints)
|
||||||
|
|
||||||
|
// Detect actual facing mode to mirror front camera correctly
|
||||||
|
const videoTrack = stream.getVideoTracks()[0]
|
||||||
|
if (videoTrack) {
|
||||||
|
const settings = videoTrack.getSettings()
|
||||||
|
if (settings.facingMode) {
|
||||||
|
isMirrored.value = settings.facingMode === 'user'
|
||||||
|
} else {
|
||||||
|
// Fallback: check label for desktop cameras or assume requested mode
|
||||||
|
const label = videoTrack.label ? videoTrack.label.toLowerCase() : ''
|
||||||
|
if (label.includes('front') || label.includes('facetime') || label.includes('macbook')) {
|
||||||
|
isMirrored.value = true
|
||||||
|
} else {
|
||||||
|
isMirrored.value = facingMode.value === 'user'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (videoRef.value) {
|
if (videoRef.value) {
|
||||||
videoRef.value.srcObject = stream
|
videoRef.value.srcObject = stream
|
||||||
// Wait for metadata to play
|
// Wait for metadata to play
|
||||||
@@ -142,6 +248,7 @@ const detectLoop = async () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const codes = await barcodeDetector.detect(videoRef.value)
|
const codes = await barcodeDetector.detect(videoRef.value)
|
||||||
|
paintDetections(codes)
|
||||||
if (codes.length > 0) {
|
if (codes.length > 0) {
|
||||||
onDetect(codes)
|
onDetect(codes)
|
||||||
}
|
}
|
||||||
@@ -228,20 +335,10 @@ const onDetect = (detectedCodes) => {
|
|||||||
processCodes(validCodes)
|
processCodes(validCodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onCameraOn = async () => {} // Removed
|
|
||||||
|
|
||||||
const ensureFrontMirror = () => {} // Removed
|
|
||||||
|
|
||||||
const startFrontMirrorObserver = () => {} // Removed
|
|
||||||
|
|
||||||
const stopFrontMirrorObserver = () => {} // Removed
|
|
||||||
|
|
||||||
watch(facingMode, () => {
|
watch(facingMode, () => {
|
||||||
startScan()
|
startScan()
|
||||||
})
|
})
|
||||||
|
|
||||||
const paintDetections = () => {} // Removed, we don't paint detections on video anymore (too complex without overlay canvas)
|
|
||||||
|
|
||||||
const onError = (err) => {
|
const onError = (err) => {
|
||||||
if (err.name === 'NotAllowedError') {
|
if (err.name === 'NotAllowedError') {
|
||||||
error.value = 'Camera permission denied'
|
error.value = 'Camera permission denied'
|
||||||
@@ -380,7 +477,7 @@ const isUrl = (string) => {
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="camera-wrapper"
|
class="camera-wrapper"
|
||||||
:class="{ 'clickable': !isFullscreen, 'is-front': isFront }"
|
:class="{ 'clickable': !isFullscreen, 'is-mirrored': isMirrored }"
|
||||||
:style="desktopFullscreenStyle"
|
:style="desktopFullscreenStyle"
|
||||||
ref="wrapperRef"
|
ref="wrapperRef"
|
||||||
@click="!isFullscreen && toggleFullscreen()"
|
@click="!isFullscreen && toggleFullscreen()"
|
||||||
@@ -388,12 +485,14 @@ const isUrl = (string) => {
|
|||||||
<video
|
<video
|
||||||
ref="videoRef"
|
ref="videoRef"
|
||||||
class="camera-feed"
|
class="camera-feed"
|
||||||
:class="{ 'is-front': isFront }"
|
:class="{ 'is-mirrored': isMirrored }"
|
||||||
autoplay
|
autoplay
|
||||||
playsinline
|
playsinline
|
||||||
muted
|
muted
|
||||||
></video>
|
></video>
|
||||||
|
|
||||||
|
<canvas ref="overlayCanvas" class="scan-overlay-canvas" :class="{ 'is-mirrored': isMirrored }"></canvas>
|
||||||
|
|
||||||
<div v-if="error" class="error-overlay">
|
<div v-if="error" class="error-overlay">
|
||||||
<p>{{ error }}</p>
|
<p>{{ error }}</p>
|
||||||
<button @click="startScan" class="retry-btn">Retry</button>
|
<button @click="startScan" class="retry-btn">Retry</button>
|
||||||
@@ -546,7 +645,21 @@ const isUrl = (string) => {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.camera-feed.is-front {
|
.camera-feed.is-mirrored {
|
||||||
|
transform: scaleX(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.scan-overlay-canvas {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scan-overlay-canvas.is-mirrored {
|
||||||
transform: scaleX(-1);
|
transform: scaleX(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user