your personal website on atproto - mirror blento.app

fix ios bug (needs testing)

+22
+22
src/lib/components/qr/qrOverlay.svelte.ts
··· 18 const LONG_PRESS_DURATION = 500; 19 let longPressTimer: ReturnType<typeof setTimeout> | null = null; 20 let isLongPress = false; 21 22 function getHref() { 23 return params.href || (node as HTMLAnchorElement).href || ''; ··· 27 if (params.disabled) return; 28 // Only start long press for primary button (touch/left-click), not right-click 29 if (e.button !== 0) return; 30 isLongPress = false; 31 longPressTimer = setTimeout(() => { 32 isLongPress = true; ··· 39 clearTimeout(longPressTimer); 40 longPressTimer = null; 41 } 42 } 43 44 function handleClick(e: MouseEvent) { ··· 55 } 56 } 57 58 node.addEventListener('pointerdown', startLongPress); 59 node.addEventListener('pointerup', cancelLongPress); 60 node.addEventListener('pointercancel', cancelLongPress); 61 node.addEventListener('pointerleave', cancelLongPress); 62 node.addEventListener('click', handleClick); 63 64 return { 65 update(newParams: { href?: string; context?: QRContext; disabled?: boolean }) { ··· 71 node.removeEventListener('pointercancel', cancelLongPress); 72 node.removeEventListener('pointerleave', cancelLongPress); 73 node.removeEventListener('click', handleClick); 74 cancelLongPress(); 75 } 76 }; 77 }
··· 18 const LONG_PRESS_DURATION = 500; 19 let longPressTimer: ReturnType<typeof setTimeout> | null = null; 20 let isLongPress = false; 21 + let touchActive = false; 22 + 23 + // Prevent iOS link preview on long-press 24 + const originalCallout = node.style.getPropertyValue('-webkit-touch-callout'); 25 + node.style.setProperty('-webkit-touch-callout', 'none'); 26 27 function getHref() { 28 return params.href || (node as HTMLAnchorElement).href || ''; ··· 32 if (params.disabled) return; 33 // Only start long press for primary button (touch/left-click), not right-click 34 if (e.button !== 0) return; 35 + touchActive = e.pointerType === 'touch'; 36 isLongPress = false; 37 longPressTimer = setTimeout(() => { 38 isLongPress = true; ··· 45 clearTimeout(longPressTimer); 46 longPressTimer = null; 47 } 48 + touchActive = false; 49 } 50 51 function handleClick(e: MouseEvent) { ··· 62 } 63 } 64 65 + function handleContextMenu(e: Event) { 66 + // Prevent context menu during touch to avoid iOS preview 67 + if (touchActive || isLongPress) { 68 + e.preventDefault(); 69 + } 70 + } 71 + 72 node.addEventListener('pointerdown', startLongPress); 73 node.addEventListener('pointerup', cancelLongPress); 74 node.addEventListener('pointercancel', cancelLongPress); 75 node.addEventListener('pointerleave', cancelLongPress); 76 node.addEventListener('click', handleClick); 77 + node.addEventListener('contextmenu', handleContextMenu); 78 79 return { 80 update(newParams: { href?: string; context?: QRContext; disabled?: boolean }) { ··· 86 node.removeEventListener('pointercancel', cancelLongPress); 87 node.removeEventListener('pointerleave', cancelLongPress); 88 node.removeEventListener('click', handleClick); 89 + node.removeEventListener('contextmenu', handleContextMenu); 90 cancelLongPress(); 91 + // Restore original style 92 + if (originalCallout) { 93 + node.style.setProperty('-webkit-touch-callout', originalCallout); 94 + } else { 95 + node.style.removeProperty('-webkit-touch-callout'); 96 + } 97 } 98 }; 99 }