์ฝ˜ํ…์ธ  ๋Œ€ํ‘œ ์ด๋ฏธ์ง€ - ๐Ÿ“ฑ ๋ชจ๋ฐ”์ผ JavaScript์™€ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ์ œ์Šค์ฒ˜ ์ธ์‹ ๊ตฌํ˜„

๐Ÿ“ฑ ๋ชจ๋ฐ”์ผ JavaScript์™€ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ์ œ์Šค์ฒ˜ ์ธ์‹ ๊ตฌํ˜„

์†๊ฐ€๋ฝ ํ•˜๋‚˜๋กœ ์„ธ์ƒ์„ ์›€์ง์ด๋Š” ๋งˆ๋ฒ•, ํ„ฐ์น˜ ์ด๋ฒคํŠธ์˜ ๋ชจ๋“  ๊ฒƒ!

๐Ÿ‘‹ ์•ˆ๋…•, ์นœ๊ตฌ! ์˜ค๋Š˜์€ ๋ชจ๋ฐ”์ผ ์›น ๊ฐœ๋ฐœ์—์„œ ์ •๋ง ์ค‘์š”ํ•œ ์ฃผ์ œ๋ฅผ ๋‹ค๋ค„๋ณผ ๊ฑฐ์•ผ. ๋ฐ”๋กœ ํ„ฐ์น˜ ์ด๋ฒคํŠธ์™€ ์ œ์Šค์ฒ˜ ์ธ์‹์ด์ง€! ์Šค๋งˆํŠธํฐ์„ ์“ฐ๋ฉด์„œ ์Šค์™€์ดํ”„ํ•˜๊ณ , ํ•€์น˜ ์คŒํ•˜๊ณ , ํƒญํ•˜๋Š” ๊ฒŒ ๋„ˆ๋ฌด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋А๊ปด์ง€์ง€? ๊ทผ๋ฐ ์ด๊ฑธ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋ ค๋ฉด ์ƒ๊ฐ๋ณด๋‹ค ๋ณต์žกํ•ด. ํ•˜์ง€๋งŒ ๊ฑฑ์ • ๋งˆ! ๋‚ด๊ฐ€ ์นœ๊ตฌ์ฒ˜๋Ÿผ ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•ด์ค„๊ฒŒ. ๐Ÿ˜Š
๋ชจ๋ฐ”์ผ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ํƒญ ์Šค์™€์ดํ”„ ํ•€์น˜ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ์ข…๋ฅ˜ โ€ข touchstart - ํ„ฐ์น˜ ์‹œ์ž‘ โ€ข touchmove - ํ„ฐ์น˜ ์ด๋™ โ€ข touchend - ํ„ฐ์น˜ ์ข…๋ฃŒ โ€ข touchcancel - ํ„ฐ์น˜ ์ทจ์†Œ

๐ŸŽฏ ํ„ฐ์น˜ ์ด๋ฒคํŠธ์˜ ๊ธฐ๋ณธ ๊ฐœ๋…

๋จผ์ € ๊ธฐ๋ณธ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด๋ณด์ž! ๋ชจ๋ฐ”์ผ ๋””๋ฐ”์ด์Šค์—์„œ ์‚ฌ์šฉ์ž๊ฐ€ ํ™”๋ฉด์„ ํ„ฐ์น˜ํ•˜๋ฉด ๋ธŒ๋ผ์šฐ์ €๋Š” ํŠน๋ณ„ํ•œ ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œ์ผœ. ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ์™€๋Š” ์™„์ „ํžˆ ๋‹ค๋ฅธ ์ฒด๊ณ„์•ผ. ๐Ÿ“ฒ

๋ฐ์Šคํฌํ†ฑ์—์„œ๋Š” click, mousedown, mousemove ๊ฐ™์€ ์ด๋ฒคํŠธ๋ฅผ ์“ฐ์ง€๋งŒ, ๋ชจ๋ฐ”์ผ์—์„œ๋Š” touchstart, touchmove, touchend ๊ฐ™์€ ํ„ฐ์น˜ ์ „์šฉ ์ด๋ฒคํŠธ๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ด. ์™œ๋ƒ๊ณ ? ํ„ฐ์น˜๋Š” ๋งˆ์šฐ์Šค์™€ ๋‹ฌ๋ฆฌ ์—ฌ๋Ÿฌ ์†๊ฐ€๋ฝ์„ ๋™์‹œ์— ์“ธ ์ˆ˜ ์žˆ๊ฑฐ๋“ ! โœ‹

๐Ÿ’ก ํ„ฐ์น˜ ์ด๋ฒคํŠธ์˜ 4๋Œ€ ์ฒœ์™• 1. touchstart - ์†๊ฐ€๋ฝ์ด ํ™”๋ฉด์— ๋‹ฟ๋Š” ์ˆœ๊ฐ„
2. touchmove - ์†๊ฐ€๋ฝ์ด ํ™”๋ฉด ์œ„๋ฅผ ์›€์ง์ผ ๋•Œ
3. touchend - ์†๊ฐ€๋ฝ์ด ํ™”๋ฉด์—์„œ ๋–จ์–ด์งˆ ๋•Œ
4. touchcancel - ํ„ฐ์น˜๊ฐ€ ์ค‘๋‹จ๋  ๋•Œ (์ „ํ™”๊ฐ€ ์˜ค๊ฑฐ๋‚˜ ์•Œ๋ฆผ์ด ๋œฐ ๋•Œ)

์ด ๋„ค ๊ฐ€์ง€ ์ด๋ฒคํŠธ๋งŒ ์ œ๋Œ€๋กœ ์ดํ•ดํ•˜๋ฉด ๊ธฐ๋ณธ์€ ๋์ด์•ผ! ๊ทผ๋ฐ ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ๊ฑด, ๊ฐ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ TouchEvent ๊ฐ์ฒด๊ฐ€ ํ•จ๊ป˜ ์ „๋‹ฌ๋œ๋‹ค๋Š” ๊ฑฐ์•ผ. ์ด ๊ฐ์ฒด ์•ˆ์— ํ„ฐ์น˜์— ๊ด€ํ•œ ๋ชจ๋“  ์ •๋ณด๊ฐ€ ๋“ค์–ด์žˆ์–ด. ๐Ÿ“ฆ

๐Ÿ” TouchEvent ๊ฐ์ฒด ํŒŒํ—ค์น˜๊ธฐ

TouchEvent ๊ฐ์ฒด๋Š” ์ง„์งœ ๋ณด๋ฌผ์ฐฝ๊ณ ์•ผ. ์—ฌ๊ธฐ์—๋Š” ํ„ฐ์น˜ ํฌ์ธํŠธ์˜ ์œ„์น˜, ๊ฐœ์ˆ˜, ์••๋ ฅ ๋“ฑ ์˜จ๊ฐ– ์ •๋ณด๊ฐ€ ๋‹ค ๋“ค์–ด์žˆ๊ฑฐ๋“ . ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์„ธ ๊ฐ€์ง€ ์†์„ฑ์„ ์•Œ์•„๋ณด์ž! ๐Ÿ’Ž

์†์„ฑ ์„ค๋ช… ์‚ฌ์šฉ ์‹œ์ 
touches ํ˜„์žฌ ํ™”๋ฉด์— ๋‹ฟ์•„์žˆ๋Š” ๋ชจ๋“  ํ„ฐ์น˜ ํฌ์ธํŠธ ๋ฉ€ํ‹ฐํ„ฐ์น˜ ์ œ์Šค์ฒ˜ ๊ตฌํ˜„ ์‹œ
targetTouches ํ˜„์žฌ ์š”์†Œ์— ๋‹ฟ์•„์žˆ๋Š” ํ„ฐ์น˜ ํฌ์ธํŠธ ํŠน์ • ์š”์†Œ๋งŒ ์ถ”์ ํ•  ๋•Œ
changedTouches ์ด๋ฒˆ ์ด๋ฒคํŠธ์—์„œ ๋ณ€๊ฒฝ๋œ ํ„ฐ์น˜ ํฌ์ธํŠธ touchend์—์„œ ์œ„์น˜ ํ™•์ธ ์‹œ

๊ฐ ํ„ฐ์น˜ ํฌ์ธํŠธ๋Š” Touch ๊ฐ์ฒด๋กœ ํ‘œํ˜„๋˜๋Š”๋ฐ, ์—ฌ๊ธฐ์—๋Š” ์ด๋Ÿฐ ์ •๋ณด๋“ค์ด ๋“ค์–ด์žˆ์–ด:

โ€ข clientX, clientY - ๋ทฐํฌํŠธ ๊ธฐ์ค€ ์ขŒํ‘œ
โ€ข pageX, pageY - ๋ฌธ์„œ ์ „์ฒด ๊ธฐ์ค€ ์ขŒํ‘œ
โ€ข screenX, screenY - ํ™”๋ฉด ๊ธฐ์ค€ ์ขŒํ‘œ
โ€ข identifier - ํ„ฐ์น˜ ํฌ์ธํŠธ์˜ ๊ณ ์œ  ID
โ€ข target - ํ„ฐ์น˜๊ฐ€ ์‹œ์ž‘๋œ ์š”์†Œ

ํŠนํžˆ identifier๋Š” ๋ฉ€ํ‹ฐํ„ฐ์น˜๋ฅผ ๊ตฌํ˜„ํ•  ๋•Œ ์ •๋ง ์ค‘์š”ํ•ด. ์—ฌ๋Ÿฌ ์†๊ฐ€๋ฝ์„ ์ถ”์ ํ•  ๋•Œ ๊ฐ ์†๊ฐ€๋ฝ์„ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ ! ๐Ÿ†”

๐ŸŽ“ Pro Tip: touchend ์ด๋ฒคํŠธ์—์„œ๋Š” touches๊ฐ€ ๋น„์–ด์žˆ์–ด! ์™œ๋ƒํ•˜๋ฉด ์ด๋ฏธ ์†๊ฐ€๋ฝ์ด ๋–จ์–ด์กŒ์œผ๋‹ˆ๊นŒ. ์ด๋•Œ๋Š” changedTouches๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ด. ์ด๊ฑฐ ๋ชจ๋ฅด๋ฉด ๋ฒ„๊ทธ ์ฐพ๋А๋ผ ๋จธ๋ฆฌ ์ฅ์–ด๋œฏ๊ฒŒ ๋ผ. ๋‚ด๊ฐ€ ๊ทธ๋žฌ๊ฑฐ๋“ ... ๐Ÿ˜…

๐Ÿ› ๏ธ ๊ธฐ๋ณธ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ๊ตฌํ˜„ํ•˜๊ธฐ

์ด์ œ ์‹ค์ „์œผ๋กœ ๋“ค์–ด๊ฐ€๋ณผ๊นŒ? ๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž. ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด์„œ ํ•˜๋‚˜ํ•˜๋‚˜ ์„ค๋ช…ํ•ด์ค„๊ฒŒ! ๐Ÿ‘จโ€๐Ÿ’ป

const touchArea = document.getElementById('touch-area');

// ํ„ฐ์น˜ ์‹œ์ž‘
touchArea.addEventListener('touchstart', function(e) {
    e.preventDefault(); // ๊ธฐ๋ณธ ๋™์ž‘ ๋ฐฉ์ง€ (์Šคํฌ๋กค ๋“ฑ)
    
    const touch = e.touches[0]; // ์ฒซ ๋ฒˆ์งธ ํ„ฐ์น˜ ํฌ์ธํŠธ
    console.log('ํ„ฐ์น˜ ์‹œ์ž‘:', touch.clientX, touch.clientY);
    
    // ์‹œ์ž‘ ์œ„์น˜ ์ €์žฅ
    this.startX = touch.clientX;
    this.startY = touch.clientY;
    this.startTime = Date.now();
});

// ํ„ฐ์น˜ ์ด๋™
touchArea.addEventListener('touchmove', function(e) {
    e.preventDefault();
    
    const touch = e.touches[0];
    const deltaX = touch.clientX - this.startX;
    const deltaY = touch.clientY - this.startY;
    
    console.log('์ด๋™ ๊ฑฐ๋ฆฌ:', deltaX, deltaY);
});

// ํ„ฐ์น˜ ์ข…๋ฃŒ
touchArea.addEventListener('touchend', function(e) {
    const touch = e.changedTouches[0]; // ์ฃผ์˜: touches๊ฐ€ ์•„๋‹Œ changedTouches!
    const endTime = Date.now();
    const duration = endTime - this.startTime;
    
    console.log('ํ„ฐ์น˜ ์ง€์† ์‹œ๊ฐ„:', duration + 'ms');
});

์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ํฌ์ธํŠธ๊ฐ€ ๋ช‡ ๊ฐ€์ง€ ์žˆ์–ด:

1. preventDefault() ํ˜ธ์ถœ
์ด๊ฑธ ์•ˆ ํ•˜๋ฉด ๋ธŒ๋ผ์šฐ์ €์˜ ๊ธฐ๋ณธ ๋™์ž‘(์Šคํฌ๋กค, ์คŒ ๋“ฑ)์ด ๊ฐ™์ด ์‹คํ–‰๋ผ์„œ ์›ํ•˜๋Š” ๋Œ€๋กœ ๋™์ž‘ ์•ˆ ํ•ด. ๊ผญ ๋„ฃ์–ด์ค˜์•ผ ํ•ด! ๐Ÿšซ

2. touches[0] ์‚ฌ์šฉ
๋‹จ์ผ ํ„ฐ์น˜๋งŒ ์ฒ˜๋ฆฌํ•  ๊ฑฐ๋ฉด ์ฒซ ๋ฒˆ์งธ ํ„ฐ์น˜ ํฌ์ธํŠธ๋งŒ ๊ฐ€์ ธ์˜ค๋ฉด ๋ผ. ๊ฐ„๋‹จํ•˜์ง€? โ˜๏ธ

3. ์‹œ์ž‘ ์œ„์น˜์™€ ์‹œ๊ฐ„ ์ €์žฅ
์ œ์Šค์ฒ˜๋ฅผ ์ธ์‹ํ•˜๋ ค๋ฉด ์‹œ์ž‘์ ์„ ๊ธฐ์–ตํ•ด์•ผ ํ•ด. ๋‚˜์ค‘์— ์ด๋™ ๊ฑฐ๋ฆฌ๋‚˜ ์†๋„๋ฅผ ๊ณ„์‚ฐํ•  ๋•Œ ํ•„์š”ํ•˜๊ฑฐ๋“ . ๐Ÿ“

โš ๏ธ ์ฃผ์˜์‚ฌํ•ญ: passive ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ๋ฌธ์ œ๋ฅผ ์กฐ์‹ฌํ•ด! ์ตœ์‹  ๋ธŒ๋ผ์šฐ์ €๋Š” ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์œ„ํ•ด ํ„ฐ์น˜ ์ด๋ฒคํŠธ๋ฅผ passive๋กœ ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ, ์ด๋Ÿฌ๋ฉด preventDefault()๊ฐ€ ์ž‘๋™ ์•ˆ ํ•ด. ๋ช…์‹œ์ ์œผ๋กœ {passive: false} ์˜ต์…˜์„ ์ค˜์•ผ ํ•ด:

element.addEventListener('touchstart', handler, {passive: false});

๐Ÿ‘† ํƒญ(Tap) ์ œ์Šค์ฒ˜ ๊ตฌํ˜„

๊ฐ€์žฅ ๊ธฐ๋ณธ์ ์ธ ์ œ์Šค์ฒ˜์ธ ํƒญ๋ถ€ํ„ฐ ๋งŒ๋“ค์–ด๋ณด์ž! ํƒญ์€ ๋น ๋ฅด๊ฒŒ ํ„ฐ์น˜ํ–ˆ๋‹ค ๋–ผ๋Š” ๋™์ž‘์ด์•ผ. ๋งˆ์šฐ์Šค์˜ ํด๋ฆญ๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ, ๋ชจ๋ฐ”์ผ์—์„œ๋Š” ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒŒ ๋” ์ •ํ™•ํ•ด. ๐Ÿ‘†

1
ํƒญ ์ธ์‹ ์กฐ๊ฑด ์ •์˜ํ•˜๊ธฐ

ํƒญ์œผ๋กœ ์ธ์‹ํ•˜๋ ค๋ฉด ๋ช‡ ๊ฐ€์ง€ ์กฐ๊ฑด์ด ํ•„์š”ํ•ด:
โ€ข ํ„ฐ์น˜ ์ง€์† ์‹œ๊ฐ„์ด ์งง์•„์•ผ ํ•จ (๋ณดํ†ต 200ms ์ดํ•˜)
โ€ข ์ด๋™ ๊ฑฐ๋ฆฌ๊ฐ€ ์ž‘์•„์•ผ ํ•จ (๋ณดํ†ต 10px ์ดํ•˜)
โ€ข ๋‹จ์ผ ํ„ฐ์น˜์—ฌ์•ผ ํ•จ

class TapGesture {
    constructor(element, callback) {
        this.element = element;
        this.callback = callback;
        this.tapThreshold = 200; // ์ตœ๋Œ€ ์ง€์† ์‹œ๊ฐ„ (ms)
        this.moveThreshold = 10; // ์ตœ๋Œ€ ์ด๋™ ๊ฑฐ๋ฆฌ (px)
        
        this.init();
    }
    
    init() {
        let startX, startY, startTime;
        
        this.element.addEventListener('touchstart', (e) => {
            if (e.touches.length !== 1) return; // ๋‹จ์ผ ํ„ฐ์น˜๋งŒ
            
            const touch = e.touches[0];
            startX = touch.clientX;
            startY = touch.clientY;
            startTime = Date.now();
        }, {passive: false});
        
        this.element.addEventListener('touchend', (e) => {
            if (e.changedTouches.length !== 1) return;
            
            const touch = e.changedTouches[0];
            const endTime = Date.now();
            const duration = endTime - startTime;
            
            // ์ด๋™ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
            const deltaX = Math.abs(touch.clientX - startX);
            const deltaY = Math.abs(touch.clientY - startY);
            const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
            
            // ํƒญ ์กฐ๊ฑด ํ™•์ธ
            if (duration < this.tapThreshold && distance < this.moveThreshold) {
                this.callback({
                    x: touch.clientX,
                    y: touch.clientY,
                    target: e.target
                });
            }
        }, {passive: false});
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const tapArea = document.getElementById('tap-area');
new TapGesture(tapArea, (data) => {
    console.log('ํƒญ ๊ฐ์ง€!', data);
    tapArea.style.background = '#ffeb3b';
    setTimeout(() => tapArea.style.background = '', 200);
});

์ด ์ฝ”๋“œ์˜ ํ•ต์‹ฌ์€ ํ”ผํƒ€๊ณ ๋ผ์Šค ์ •๋ฆฌ๋ฅผ ์ด์šฉํ•œ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ์ด์•ผ! Math.sqrt(deltaX * deltaX + deltaY * deltaY) ์ด ๋ถ€๋ถ„ ๋ง์ด์•ผ. ์ˆ˜ํ•™ ์‹œ๊ฐ„์— ๋ฐฐ์šด ๊ฒŒ ์—ฌ๊ธฐ์„œ ์“ฐ์ด๋„ค! ๐Ÿ“

๊ทธ๋ฆฌ๊ณ  ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด์„œ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ ์‰ฝ๊ฒŒ ํ–ˆ์–ด. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์—ฌ๋Ÿฌ ์š”์†Œ์— ์‰ฝ๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ . ๊ฐ์ฒด์ง€ํ–ฅ์˜ ํž˜! ๐Ÿ’ช

๐Ÿ‘‰ ์Šค์™€์ดํ”„(Swipe) ์ œ์Šค์ฒ˜ ๊ตฌํ˜„

์Šค์™€์ดํ”„๋Š” ํ™”๋ฉด์„ ์“ธ์–ด๋„˜๊ธฐ๋Š” ๋™์ž‘์ด์•ผ. ์ด๋ฏธ์ง€ ๊ฐค๋Ÿฌ๋ฆฌ๋‚˜ ์นด๋“œ UI์—์„œ ๋งŽ์ด ์“ฐ์ด์ง€. ๋ฐฉํ–ฅ๊ณผ ์†๋„๋ฅผ ๊ฐ์ง€ํ•˜๋Š” ๊ฒŒ ํ•ต์‹ฌ์ด์•ผ! ๐Ÿ’จ

๐ŸŽฏ ์Šค์™€์ดํ”„ ์ธ์‹ ์ „๋žต ์Šค์™€์ดํ”„๋ฅผ ์ œ๋Œ€๋กœ ์ธ์‹ํ•˜๋ ค๋ฉด ์ด๋Ÿฐ ๊ฑธ ๊ณ ๋ คํ•ด์•ผ ํ•ด:

1. ๋ฐฉํ–ฅ ํŒ๋‹จ - ์ˆ˜ํ‰/์ˆ˜์ง ์ค‘ ์–ด๋А ๋ฐฉํ–ฅ์œผ๋กœ ๋” ๋งŽ์ด ์›€์ง์˜€๋Š”์ง€
2. ์†๋„ ๊ณ„์‚ฐ - ๋น ๋ฅด๊ฒŒ ์›€์ง์˜€๋Š”์ง€ (velocity)
3. ์ตœ์†Œ ๊ฑฐ๋ฆฌ - ์ผ์ • ๊ฑฐ๋ฆฌ ์ด์ƒ ์›€์ง์—ฌ์•ผ ์Šค์™€์ดํ”„๋กœ ์ธ์ •
4. ๊ฐ๋„ ์ œํ•œ - ๋„ˆ๋ฌด ๋Œ€๊ฐ์„ ์œผ๋กœ ์›€์ง์ด๋ฉด ์ œ์™ธ
class SwipeGesture {
    constructor(element, options = {}) {
        this.element = element;
        this.options = {
            minDistance: options.minDistance || 50,    // ์ตœ์†Œ ์ด๋™ ๊ฑฐ๋ฆฌ
            maxTime: options.maxTime || 500,           // ์ตœ๋Œ€ ์ง€์† ์‹œ๊ฐ„
            minVelocity: options.minVelocity || 0.3,   // ์ตœ์†Œ ์†๋„
            maxAngle: options.maxAngle || 30,          // ์ตœ๋Œ€ ๊ฐ๋„ ํŽธ์ฐจ
            onSwipe: options.onSwipe || (() => {})
        };
        
        this.init();
    }
    
    init() {
        let startX, startY, startTime;
        
        this.element.addEventListener('touchstart', (e) => {
            if (e.touches.length !== 1) return;
            
            const touch = e.touches[0];
            startX = touch.clientX;
            startY = touch.clientY;
            startTime = Date.now();
        }, {passive: false});
        
        this.element.addEventListener('touchend', (e) => {
            if (e.changedTouches.length !== 1) return;
            
            const touch = e.changedTouches[0];
            const endTime = Date.now();
            
            const deltaX = touch.clientX - startX;
            const deltaY = touch.clientY - startY;
            const duration = endTime - startTime;
            
            // ๊ฑฐ๋ฆฌ์™€ ์†๋„ ๊ณ„์‚ฐ
            const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
            const velocity = distance / duration;
            
            // ๊ฐ๋„ ๊ณ„์‚ฐ (๋ผ๋””์•ˆ -> ๋„)
            const angle = Math.atan2(Math.abs(deltaY), Math.abs(deltaX)) * 180 / Math.PI;
            
            // ์Šค์™€์ดํ”„ ์กฐ๊ฑด ํ™•์ธ
            if (distance >= this.options.minDistance &&
                duration <= this.options.maxTime &&
                velocity >= this.options.minVelocity) {
                
                let direction;
                
                // ์ˆ˜ํ‰ ์Šค์™€์ดํ”„
                if (angle < this.options.maxAngle) {
                    direction = deltaX > 0 ? 'right' : 'left';
                }
                // ์ˆ˜์ง ์Šค์™€์ดํ”„
                else if (angle > 90 - this.options.maxAngle) {
                    direction = deltaY > 0 ? 'down' : 'up';
                }
                
                if (direction) {
                    this.options.onSwipe({
                        direction,
                        distance,
                        velocity,
                        duration,
                        deltaX,
                        deltaY
                    });
                }
            }
        }, {passive: false});
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const swipeArea = document.getElementById('swipe-area');
new SwipeGesture(swipeArea, {
    minDistance: 60,
    onSwipe: (data) => {
        console.log(`${data.direction} ์Šค์™€์ดํ”„!`, data);
        
        // ๋ฐฉํ–ฅ์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๋™์ž‘
        switch(data.direction) {
            case 'left':
                console.log('๋‹ค์Œ ํŽ˜์ด์ง€๋กœ!');
                break;
            case 'right':
                console.log('์ด์ „ ํŽ˜์ด์ง€๋กœ!');
                break;
            case 'up':
                console.log('์œ„๋กœ ์Šคํฌ๋กค!');
                break;
            case 'down':
                console.log('์•„๋ž˜๋กœ ์Šคํฌ๋กค!');
                break;
        }
    }
});

์—ฌ๊ธฐ์„œ ์žฌ๋ฐŒ๋Š” ๋ถ€๋ถ„์€ ๊ฐ๋„ ๊ณ„์‚ฐ์ด์•ผ! Math.atan2()๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด๋™ ๋ฐฉํ–ฅ์˜ ๊ฐ๋„๋ฅผ ๊ตฌํ•˜๋Š” ๊ฑฐ์ง€. ์ด๊ฑธ๋กœ ์ˆ˜ํ‰ ์Šค์™€์ดํ”„์ธ์ง€ ์ˆ˜์ง ์Šค์™€์ดํ”„์ธ์ง€ ํŒ๋‹จํ•  ์ˆ˜ ์žˆ์–ด. ๐Ÿ“

๊ทธ๋ฆฌ๊ณ  ์†๋„(velocity)๋„ ์ค‘์š”ํ•ด! ๊ฑฐ๋ฆฌ๋ฅผ ์‹œ๊ฐ„์œผ๋กœ ๋‚˜๋ˆ„๋ฉด ์†๋„๊ฐ€ ๋‚˜์˜ค๋Š”๋ฐ, ์ด๊ฒŒ ์ผ์ • ๊ฐ’ ์ด์ƒ์ด์–ด์•ผ ์Šค์™€์ดํ”„๋กœ ์ธ์ •ํ•˜๋Š” ๊ฑฐ์•ผ. ๋А๋ฆฟ๋А๋ฆฟ ์›€์ง์ด๋ฉด ์Šค์™€์ดํ”„๊ฐ€ ์•„๋‹ˆ๋ผ ๊ทธ๋ƒฅ ๋“œ๋ž˜๊ทธ๋‹ˆ๊นŒ! โšก

๐Ÿ’ก ์‹ค์ „ ํŒ: ์Šค์™€์ดํ”„ ์ œ์Šค์ฒ˜๋ฅผ ๊ตฌํ˜„ํ•  ๋•Œ๋Š” ์‚ฌ์šฉ์ž ํ”ผ๋“œ๋ฐฑ์ด ์ •๋ง ์ค‘์š”ํ•ด! ์Šค์™€์ดํ”„ํ•˜๋Š” ๋™์•ˆ ์š”์†Œ๊ฐ€ ๋”ฐ๋ผ ์›€์ง์ด๊ฑฐ๋‚˜, ์ง„๋™ ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ๊ฑฐ๋‚˜, ์‹œ๊ฐ์  ํšจ๊ณผ๋ฅผ ๋„ฃ์œผ๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ํ›จ์”ฌ ์ข‹์•„์ ธ. ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ํ”„๋ฆฌ๋žœ์„œ ๊ฐœ๋ฐœ์ž๋“ค์ด ์ด๋Ÿฐ ๋””ํ…Œ์ผ์— ์‹ ๊ฒฝ ์“ฐ๋Š” ์ด์œ ๊ฐ€ ๋ฐ”๋กœ ์ด๊ฑฐ์•ผ! ๐Ÿ˜‰

๐Ÿค ํ•€์น˜ ์คŒ(Pinch Zoom) ์ œ์Šค์ฒ˜ ๊ตฌํ˜„

์ด์ œ ์ข€ ๋” ๊ณ ๊ธ‰ ๊ธฐ์ˆ ๋กœ ๋„˜์–ด๊ฐ€๋ณผ๊นŒ? ํ•€์น˜ ์คŒ์€ ๋‘ ์†๊ฐ€๋ฝ์œผ๋กœ ํ™•๋Œ€/์ถ•์†Œํ•˜๋Š” ์ œ์Šค์ฒ˜์•ผ. ์ง€๋„ ์•ฑ์ด๋‚˜ ์ด๋ฏธ์ง€ ๋ทฐ์–ด์—์„œ ๋งŽ์ด ์“ฐ์ด์ง€. ๋ฉ€ํ‹ฐํ„ฐ์น˜๋ฅผ ๋‹ค๋ค„์•ผ ํ•ด์„œ ์กฐ๊ธˆ ๋ณต์žกํ•ด! ๐Ÿ”

โš ๏ธ ๋‚œ์ด๋„ ์ƒ์Šน! ํ•€์น˜ ์คŒ์€ ๋‘ ๊ฐœ์˜ ํ„ฐ์น˜ ํฌ์ธํŠธ๋ฅผ ๋™์‹œ์— ์ถ”์ ํ•ด์•ผ ํ•ด. ๊ฐ ํฌ์ธํŠธ์˜ identifier๋ฅผ ์ด์šฉํ•ด์„œ ์ถ”์ ํ•˜๋Š” ๊ฒŒ ํ•ต์‹ฌ์ด์•ผ. ์ง‘์ค‘ํ•ด์„œ ๋ณด์ž! ๐Ÿง 
class PinchZoom {
    constructor(element, options = {}) {
        this.element = element;
        this.options = {
            minScale: options.minScale || 0.5,
            maxScale: options.maxScale || 3,
            onZoom: options.onZoom || (() => {})
        };
        
        this.currentScale = 1;
        this.initialDistance = 0;
        
        this.init();
    }
    
    // ๋‘ ํ„ฐ์น˜ ํฌ์ธํŠธ ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
    getDistance(touch1, touch2) {
        const dx = touch2.clientX - touch1.clientX;
        const dy = touch2.clientY - touch1.clientY;
        return Math.sqrt(dx * dx + dy * dy);
    }
    
    // ๋‘ ํ„ฐ์น˜ ํฌ์ธํŠธ์˜ ์ค‘์‹ฌ์  ๊ณ„์‚ฐ
    getCenter(touch1, touch2) {
        return {
            x: (touch1.clientX + touch2.clientX) / 2,
            y: (touch1.clientY + touch2.clientY) / 2
        };
    }
    
    init() {
        this.element.addEventListener('touchstart', (e) => {
            if (e.touches.length === 2) {
                e.preventDefault();
                
                // ์ดˆ๊ธฐ ๊ฑฐ๋ฆฌ ์ €์žฅ
                this.initialDistance = this.getDistance(
                    e.touches[0],
                    e.touches[1]
                );
            }
        }, {passive: false});
        
        this.element.addEventListener('touchmove', (e) => {
            if (e.touches.length === 2) {
                e.preventDefault();
                
                // ํ˜„์žฌ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
                const currentDistance = this.getDistance(
                    e.touches[0],
                    e.touches[1]
                );
                
                // ์Šค์ผ€์ผ ๋น„์œจ ๊ณ„์‚ฐ
                const scale = currentDistance / this.initialDistance;
                const newScale = this.currentScale * scale;
                
                // ์ตœ์†Œ/์ตœ๋Œ€ ์Šค์ผ€์ผ ์ œํ•œ
                if (newScale >= this.options.minScale && 
                    newScale <= this.options.maxScale) {
                    
                    // ์ค‘์‹ฌ์  ๊ณ„์‚ฐ
                    const center = this.getCenter(
                        e.touches[0],
                        e.touches[1]
                    );
                    
                    this.options.onZoom({
                        scale: newScale,
                        center: center,
                        delta: scale
                    });
                }
                
                // ๋‹ค์Œ ๊ณ„์‚ฐ์„ ์œ„ํ•ด ์ดˆ๊ธฐ ๊ฑฐ๋ฆฌ ์—…๋ฐ์ดํŠธ
                this.initialDistance = currentDistance;
            }
        }, {passive: false});
        
        this.element.addEventListener('touchend', (e) => {
            if (e.touches.length < 2) {
                // ํ•€์น˜ ์ œ์Šค์ฒ˜ ์ข…๋ฃŒ
                this.currentScale = this.element.style.transform ?
                    parseFloat(this.element.style.transform.match(/scale\(([\d.]+)\)/)?.[1] || 1) : 1;
            }
        }, {passive: false});
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const zoomArea = document.getElementById('zoom-area');
const zoomImage = zoomArea.querySelector('img');

new PinchZoom(zoomArea, {
    minScale: 0.5,
    maxScale: 4,
    onZoom: (data) => {
        // ์ด๋ฏธ์ง€ ํ™•๋Œ€/์ถ•์†Œ
        zoomImage.style.transform = `scale(${data.scale})`;
        zoomImage.style.transformOrigin = `${data.center.x}px ${data.center.y}px`;
        
        console.log('์คŒ ๋ ˆ๋ฒจ:', data.scale.toFixed(2));
    }
});

ํ•€์น˜ ์คŒ์˜ ํ•ต์‹ฌ์€ ๋‘ ์†๊ฐ€๋ฝ ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ ๋ณ€ํ™”๋ฅผ ์ถ”์ ํ•˜๋Š” ๊ฑฐ์•ผ! ๐Ÿ“

์ž‘๋™ ์›๋ฆฌ:
1. touchstart์—์„œ ์ดˆ๊ธฐ ๊ฑฐ๋ฆฌ๋ฅผ ์ €์žฅ
2. touchmove์—์„œ ํ˜„์žฌ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ„์‚ฐ
3. ๊ฑฐ๋ฆฌ ๋น„์œจ๋กœ ์Šค์ผ€์ผ ๊ฐ’ ๊ณ„์‚ฐ
4. transform: scale()๋กœ ์‹ค์ œ ํ™•๋Œ€/์ถ•์†Œ ์ ์šฉ

์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ๊ฑด transformOrigin์ด์•ผ! ์ด๊ฑธ ๋‘ ์†๊ฐ€๋ฝ์˜ ์ค‘์‹ฌ์ ์œผ๋กœ ์„ค์ •ํ•˜๋ฉด, ์†๊ฐ€๋ฝ ์‚ฌ์ด๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ํ™•๋Œ€/์ถ•์†Œ๋˜๋Š” ์ž์—ฐ์Šค๋Ÿฌ์šด ํšจ๊ณผ๋ฅผ ๋‚ผ ์ˆ˜ ์žˆ์–ด. ๐ŸŽฏ

๐ŸŽจ ํ•€์น˜ ์คŒ ์ตœ์ ํ™” ํŒ 1. ๋ถ€๋“œ๋Ÿฌ์šด ์• ๋‹ˆ๋ฉ”์ด์…˜
CSS transition์„ ์‚ฌ์šฉํ•˜๋˜, ํ„ฐ์น˜ ์ค‘์—๋Š” ๋น„ํ™œ์„ฑํ™”ํ•˜๊ณ  ํ„ฐ์น˜ ์ข…๋ฃŒ ํ›„์—๋งŒ ํ™œ์„ฑํ™”ํ•ด. ๊ทธ๋ž˜์•ผ ๋Š๊น€ ์—†์ด ๋ถ€๋“œ๋Ÿฌ์›Œ!

2. ๊ฒฝ๊ณ„๊ฐ’ ์ฒ˜๋ฆฌ
์ตœ์†Œ/์ตœ๋Œ€ ์Šค์ผ€์ผ์— ๋„๋‹ฌํ•˜๋ฉด ํƒ„์„ฑ ํšจ๊ณผ๋ฅผ ์ฃผ๋ฉด ์ข‹์•„. ์‚ฌ์šฉ์ž๊ฐ€ ํ•œ๊ณ„๋ฅผ ๋А๋‚„ ์ˆ˜ ์žˆ๊ฑฐ๋“ .

3. ์„ฑ๋Šฅ ์ตœ์ ํ™”
transform ๋Œ€์‹  scale์„ ์ง์ ‘ ์กฐ์ž‘ํ•˜๋ฉด GPU ๊ฐ€์†์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์–ด. will-change: transform๋„ ์ถ”๊ฐ€ํ•˜๋ฉด ๋” ์ข‹๊ณ !

๐Ÿ”„ ํšŒ์ „(Rotation) ์ œ์Šค์ฒ˜ ๊ตฌํ˜„

๋‘ ์†๊ฐ€๋ฝ์œผ๋กœ ์š”์†Œ๋ฅผ ํšŒ์ „์‹œํ‚ค๋Š” ์ œ์Šค์ฒ˜๋„ ๋งŒ๋“ค์–ด๋ณด์ž! ํ•€์น˜ ์คŒ๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ, ๊ฑฐ๋ฆฌ ๋Œ€์‹  ๊ฐ๋„๋ฅผ ์ถ”์ ํ•ด์•ผ ํ•ด. ๐ŸŒ€

class RotationGesture {
    constructor(element, options = {}) {
        this.element = element;
        this.options = {
            onRotate: options.onRotate || (() => {})
        };
        
        this.currentRotation = 0;
        this.initialAngle = 0;
        
        this.init();
    }
    
    // ๋‘ ํ„ฐ์น˜ ํฌ์ธํŠธ ์‚ฌ์ด์˜ ๊ฐ๋„ ๊ณ„์‚ฐ
    getAngle(touch1, touch2) {
        const dx = touch2.clientX - touch1.clientX;
        const dy = touch2.clientY - touch1.clientY;
        return Math.atan2(dy, dx) * 180 / Math.PI;
    }
    
    init() {
        this.element.addEventListener('touchstart', (e) => {
            if (e.touches.length === 2) {
                e.preventDefault();
                
                // ์ดˆ๊ธฐ ๊ฐ๋„ ์ €์žฅ
                this.initialAngle = this.getAngle(
                    e.touches[0],
                    e.touches[1]
                );
            }
        }, {passive: false});
        
        this.element.addEventListener('touchmove', (e) => {
            if (e.touches.length === 2) {
                e.preventDefault();
                
                // ํ˜„์žฌ ๊ฐ๋„ ๊ณ„์‚ฐ
                const currentAngle = this.getAngle(
                    e.touches[0],
                    e.touches[1]
                );
                
                // ํšŒ์ „ ๊ฐ๋„ ๊ณ„์‚ฐ
                let rotation = currentAngle - this.initialAngle;
                
                // -180 ~ 180 ๋ฒ”์œ„๋กœ ์ •๊ทœํ™”
                if (rotation > 180) rotation -= 360;
                if (rotation < -180) rotation += 360;
                
                const newRotation = this.currentRotation + rotation;
                
                this.options.onRotate({
                    rotation: newRotation,
                    delta: rotation
                });
                
                // ๋‹ค์Œ ๊ณ„์‚ฐ์„ ์œ„ํ•ด ์ดˆ๊ธฐ ๊ฐ๋„ ์—…๋ฐ์ดํŠธ
                this.initialAngle = currentAngle;
            }
        }, {passive: false});
        
        this.element.addEventListener('touchend', (e) => {
            if (e.touches.length < 2) {
                // ํšŒ์ „ ์ œ์Šค์ฒ˜ ์ข…๋ฃŒ
                this.currentRotation = this.element.style.transform ?
                    parseFloat(this.element.style.transform.match(/rotate\(([-\d.]+)deg\)/)?.[1] || 0) : 0;
            }
        }, {passive: false});
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const rotateArea = document.getElementById('rotate-area');
const rotateImage = rotateArea.querySelector('img');

new RotationGesture(rotateArea, {
    onRotate: (data) => {
        rotateImage.style.transform = `rotate(${data.rotation}deg)`;
        console.log('ํšŒ์ „ ๊ฐ๋„:', data.rotation.toFixed(1) + 'ยฐ');
    }
});

ํšŒ์ „ ์ œ์Šค์ฒ˜์˜ ํ•ต์‹ฌ์€ ๊ฐ๋„ ๊ณ„์‚ฐ์ด์•ผ! Math.atan2()๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋‘ ์†๊ฐ€๋ฝ์„ ์ž‡๋Š” ์„ ์˜ ๊ฐ๋„๋ฅผ ๊ตฌํ•˜๋Š” ๊ฑฐ์ง€. ๐Ÿ“

์—ฌ๊ธฐ์„œ ์ฃผ์˜ํ•  ์ ์€ ๊ฐ๋„๊ฐ€ 180๋„๋ฅผ ๋„˜์–ด๊ฐˆ ๋•Œ ์ฒ˜๋ฆฌ์•ผ. -180๋„์—์„œ 180๋„๋กœ ๊ฐ‘์ž๊ธฐ ์ ํ”„ํ•˜๋ฉด ์ด์ƒํ•˜๊ฒŒ ํšŒ์ „ํ•˜๊ฑฐ๋“ . ๊ทธ๋ž˜์„œ ์ •๊ทœํ™” ๊ณผ์ •์ด ํ•„์š”ํ•ด! ๐Ÿ”„

๐ŸŽญ ๋ณตํ•ฉ ์ œ์Šค์ฒ˜ ๊ตฌํ˜„ํ•˜๊ธฐ

์‹ค์ œ ์•ฑ์—์„œ๋Š” ์—ฌ๋Ÿฌ ์ œ์Šค์ฒ˜๋ฅผ ๋™์‹œ์— ์ง€์›ํ•ด์•ผ ํ•  ๋•Œ๊ฐ€ ๋งŽ์•„. ์˜ˆ๋ฅผ ๋“ค์–ด ์ด๋ฏธ์ง€ ๋ทฐ์–ด์—์„œ๋Š” ํ•€์น˜ ์คŒ, ํšŒ์ „, ๋“œ๋ž˜๊ทธ๋ฅผ ๋ชจ๋‘ ์ง€์›ํ•ด์•ผ ํ•˜์ง€. ์ด๊ฑธ ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„ํ• ๊นŒ? ๐Ÿคน

๐ŸŽฏ ๋ณตํ•ฉ ์ œ์Šค์ฒ˜ ์„ค๊ณ„ ์ „๋žต 1. ์ œ์Šค์ฒ˜ ์šฐ์„ ์ˆœ์œ„ ์ •ํ•˜๊ธฐ
์—ฌ๋Ÿฌ ์ œ์Šค์ฒ˜๊ฐ€ ๋™์‹œ์— ๊ฐ์ง€๋˜๋ฉด ์–ด๋–ค ๊ฑธ ์šฐ์„ ํ• ์ง€ ๊ฒฐ์ •ํ•ด์•ผ ํ•ด.

2. ์ƒํƒœ ๊ด€๋ฆฌ
ํ˜„์žฌ ์–ด๋–ค ์ œ์Šค์ฒ˜๊ฐ€ ์ง„ํ–‰ ์ค‘์ธ์ง€ ์ถ”์ ํ•ด์•ผ ํ•ด.

3. ์ œ์Šค์ฒ˜ ์กฐํ•ฉ
ํ•€์น˜ ์คŒ๊ณผ ํšŒ์ „์„ ๋™์‹œ์— ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ, ์—ฌ๋Ÿฌ ์ œ์Šค์ฒ˜๋ฅผ ์กฐํ•ฉํ•  ์ˆ˜๋„ ์žˆ์–ด.

4. ์ถฉ๋Œ ๋ฐฉ์ง€
ํ•œ ์ œ์Šค์ฒ˜๊ฐ€ ๋‹ค๋ฅธ ์ œ์Šค์ฒ˜๋ฅผ ๋ฐฉํ•ดํ•˜์ง€ ์•Š๋„๋ก ์กฐ์‹ฌํ•ด์•ผ ํ•ด.
class MultiGesture {
    constructor(element, options = {}) {
        this.element = element;
        this.options = options;
        
        // ํ˜„์žฌ ์ƒํƒœ
        this.state = {
            scale: 1,
            rotation: 0,
            translateX: 0,
            translateY: 0
        };
        
        // ์ œ์Šค์ฒ˜ ์ถ”์ 
        this.gesture = {
            type: null,  // 'pan', 'pinch', 'rotate', 'multi'
            initialDistance: 0,
            initialAngle: 0,
            initialTouch: null
        };
        
        this.init();
    }
    
    getDistance(touch1, touch2) {
        const dx = touch2.clientX - touch1.clientX;
        const dy = touch2.clientY - touch1.clientY;
        return Math.sqrt(dx * dx + dy * dy);
    }
    
    getAngle(touch1, touch2) {
        const dx = touch2.clientX - touch1.clientX;
        const dy = touch2.clientY - touch1.clientY;
        return Math.atan2(dy, dx) * 180 / Math.PI;
    }
    
    getCenter(touch1, touch2) {
        return {
            x: (touch1.clientX + touch2.clientX) / 2,
            y: (touch1.clientY + touch2.clientY) / 2
        };
    }
    
    init() {
        this.element.addEventListener('touchstart', (e) => {
            e.preventDefault();
            
            if (e.touches.length === 1) {
                // ๋‹จ์ผ ํ„ฐ์น˜ - ํŒฌ(๋“œ๋ž˜๊ทธ) ์‹œ์ž‘
                this.gesture.type = 'pan';
                this.gesture.initialTouch = {
                    x: e.touches[0].clientX,
                    y: e.touches[0].clientY
                };
            } else if (e.touches.length === 2) {
                // ๋‘ ์†๊ฐ€๋ฝ - ํ•€์น˜/ํšŒ์ „ ์‹œ์ž‘
                this.gesture.type = 'multi';
                this.gesture.initialDistance = this.getDistance(
                    e.touches[0],
                    e.touches[1]
                );
                this.gesture.initialAngle = this.getAngle(
                    e.touches[0],
                    e.touches[1]
                );
            }
        }, {passive: false});
        
        this.element.addEventListener('touchmove', (e) => {
            e.preventDefault();
            
            if (this.gesture.type === 'pan' && e.touches.length === 1) {
                // ํŒฌ(๋“œ๋ž˜๊ทธ) ์ฒ˜๋ฆฌ
                const touch = e.touches[0];
                const deltaX = touch.clientX - this.gesture.initialTouch.x;
                const deltaY = touch.clientY - this.gesture.initialTouch.y;
                
                this.state.translateX += deltaX;
                this.state.translateY += deltaY;
                
                this.gesture.initialTouch = {
                    x: touch.clientX,
                    y: touch.clientY
                };
                
                this.updateTransform();
                
            } else if (this.gesture.type === 'multi' && e.touches.length === 2) {
                // ํ•€์น˜ ์คŒ ์ฒ˜๋ฆฌ
                const currentDistance = this.getDistance(
                    e.touches[0],
                    e.touches[1]
                );
                const scaleRatio = currentDistance / this.gesture.initialDistance;
                this.state.scale *= scaleRatio;
                
                // ์Šค์ผ€์ผ ์ œํ•œ
                this.state.scale = Math.max(0.5, Math.min(4, this.state.scale));
                
                // ํšŒ์ „ ์ฒ˜๋ฆฌ
                const currentAngle = this.getAngle(
                    e.touches[0],
                    e.touches[1]
                );
                let rotationDelta = currentAngle - this.gesture.initialAngle;
                
                // ๊ฐ๋„ ์ •๊ทœํ™”
                if (rotationDelta > 180) rotationDelta -= 360;
                if (rotationDelta < -180) rotationDelta += 360;
                
                this.state.rotation += rotationDelta;
                
                // ๋‹ค์Œ ๊ณ„์‚ฐ์„ ์œ„ํ•ด ์—…๋ฐ์ดํŠธ
                this.gesture.initialDistance = currentDistance;
                this.gesture.initialAngle = currentAngle;
                
                this.updateTransform();
            }
        }, {passive: false});
        
        this.element.addEventListener('touchend', (e) => {
            if (e.touches.length === 0) {
                this.gesture.type = null;
            } else if (e.touches.length === 1 && this.gesture.type === 'multi') {
                // ๋‘ ์†๊ฐ€๋ฝ์—์„œ ํ•œ ์†๊ฐ€๋ฝ์œผ๋กœ ์ „ํ™˜
                this.gesture.type = 'pan';
                this.gesture.initialTouch = {
                    x: e.touches[0].clientX,
                    y: e.touches[0].clientY
                };
            }
        }, {passive: false});
    }
    
    updateTransform() {
        const transform = `
            translate(${this.state.translateX}px, ${this.state.translateY}px)
            scale(${this.state.scale})
            rotate(${this.state.rotation}deg)
        `;
        this.element.style.transform = transform;
        
        // ์ฝœ๋ฐฑ ํ˜ธ์ถœ
        if (this.options.onChange) {
            this.options.onChange(this.state);
        }
    }
    
    reset() {
        this.state = {
            scale: 1,
            rotation: 0,
            translateX: 0,
            translateY: 0
        };
        this.updateTransform();
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const multiArea = document.getElementById('multi-area');
const multiImage = multiArea.querySelector('img');

const gesture = new MultiGesture(multiImage, {
    onChange: (state) => {
        console.log('์ƒํƒœ:', state);
    }
});

// ๋ฆฌ์…‹ ๋ฒ„ํŠผ
document.getElementById('reset-btn').addEventListener('click', () => {
    gesture.reset();
});

์™€! ์ฝ”๋“œ๊ฐ€ ์ข€ ๊ธธ์–ด์กŒ์ง€? ํ•˜์ง€๋งŒ ์ด๊ฒŒ ์‹ค์ „์ด์•ผ! ๐Ÿ’ช

์ด ์ฝ”๋“œ์˜ ํ•ต์‹ฌ์€ ์ƒํƒœ ๊ด€๋ฆฌ์•ผ. ํ˜„์žฌ ์–ด๋–ค ์ œ์Šค์ฒ˜๊ฐ€ ์ง„ํ–‰ ์ค‘์ธ์ง€ ์ถ”์ ํ•˜๊ณ , ํ„ฐ์น˜ ๊ฐœ์ˆ˜๊ฐ€ ๋ณ€ํ•  ๋•Œ ์ ์ ˆํžˆ ์ „ํ™˜ํ•˜๋Š” ๊ฑฐ์ง€. ์˜ˆ๋ฅผ ๋“ค์–ด ํ•€์น˜ ์คŒํ•˜๋‹ค๊ฐ€ ํ•œ ์†๊ฐ€๋ฝ์„ ๋–ผ๋ฉด ์ž๋™์œผ๋กœ ํŒฌ ๋ชจ๋“œ๋กœ ์ „ํ™˜๋ผ. ๐Ÿ”„

๊ทธ๋ฆฌ๊ณ  ๋ชจ๋“  ๋ณ€ํ™˜์„ ํ•˜๋‚˜์˜ transform ์†์„ฑ์œผ๋กœ ํ•ฉ์ณ์„œ ์ ์šฉํ•˜๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•ด. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด GPU ๊ฐ€์†์„ ๋ฐ›์•„์„œ ์„ฑ๋Šฅ์ด ์ข‹์•„์ ธ! โšก

๐ŸŽ“ Pro Tip: ๋ณตํ•ฉ ์ œ์Šค์ฒ˜๋ฅผ ๊ตฌํ˜„ํ•  ๋•Œ๋Š” ๋””๋ฒ„๊น…์ด ์ •๋ง ์ค‘์š”ํ•ด! console.log๋กœ ํ˜„์žฌ ์ƒํƒœ๋ฅผ ๊ณ„์† ์ฐ์–ด๋ณด๋ฉด์„œ ํ…Œ์ŠคํŠธํ•ด์•ผ ํ•ด. ์‹ค์ œ ๋””๋ฐ”์ด์Šค์—์„œ ํ…Œ์ŠคํŠธํ•˜๋Š” ๊ฒƒ๋„ ํ•„์ˆ˜๊ณ ! ํฌ๋กฌ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์˜ ๋””๋ฐ”์ด์Šค ๋ชจ๋“œ๋Š” ์™„๋ฒฝํ•˜์ง€ ์•Š๊ฑฐ๋“ . ๐Ÿ“ฑ

โฑ๏ธ ๋กฑ ํ”„๋ ˆ์Šค(Long Press) ์ œ์Šค์ฒ˜

๋กฑ ํ”„๋ ˆ์Šค๋Š” ํ™”๋ฉด์„ ๊ธธ๊ฒŒ ๋ˆ„๋ฅด๊ณ  ์žˆ๋Š” ์ œ์Šค์ฒ˜์•ผ. ์ปจํ…์ŠคํŠธ ๋ฉ”๋‰ด๋ฅผ ๋„์šฐ๊ฑฐ๋‚˜ ํŠน๋ณ„ํ•œ ๊ธฐ๋Šฅ์„ ์‹คํ–‰ํ•  ๋•Œ ์“ฐ์ด์ง€. ํƒ€์ด๋จธ๋ฅผ ํ™œ์šฉํ•˜๋Š” ๊ฒŒ ํ•ต์‹ฌ์ด์•ผ! โฐ

class LongPress {
    constructor(element, options = {}) {
        this.element = element;
        this.options = {
            duration: options.duration || 500,  // ๋กฑ ํ”„๋ ˆ์Šค ์ธ์‹ ์‹œ๊ฐ„
            moveThreshold: options.moveThreshold || 10,  // ์ตœ๋Œ€ ์ด๋™ ๊ฑฐ๋ฆฌ
            onLongPress: options.onLongPress || (() => {}),
            onLongPressStart: options.onLongPressStart || (() => {}),
            onLongPressEnd: options.onLongPressEnd || (() => {})
        };
        
        this.timer = null;
        this.isLongPressing = false;
        
        this.init();
    }
    
    init() {
        let startX, startY;
        
        this.element.addEventListener('touchstart', (e) => {
            if (e.touches.length !== 1) return;
            
            const touch = e.touches[0];
            startX = touch.clientX;
            startY = touch.clientY;
            
            // ํƒ€์ด๋จธ ์‹œ์ž‘
            this.timer = setTimeout(() => {
                this.isLongPressing = true;
                this.options.onLongPress({
                    x: touch.clientX,
                    y: touch.clientY,
                    target: e.target
                });
                this.options.onLongPressStart();
                
                // ํ–…ํ‹ฑ ํ”ผ๋“œ๋ฐฑ (์ง€์›ํ•˜๋Š” ๋ธŒ๋ผ์šฐ์ €๋งŒ)
                if (navigator.vibrate) {
                    navigator.vibrate(50);
                }
            }, this.options.duration);
            
        }, {passive: false});
        
        this.element.addEventListener('touchmove', (e) => {
            if (!this.timer) return;
            
            const touch = e.touches[0];
            const deltaX = Math.abs(touch.clientX - startX);
            const deltaY = Math.abs(touch.clientY - startY);
            
            // ๋„ˆ๋ฌด ๋งŽ์ด ์›€์ง์ด๋ฉด ์ทจ์†Œ
            if (deltaX > this.options.moveThreshold || 
                deltaY > this.options.moveThreshold) {
                this.cancel();
            }
        }, {passive: false});
        
        this.element.addEventListener('touchend', (e) => {
            if (this.isLongPressing) {
                this.options.onLongPressEnd();
            }
            this.cancel();
        }, {passive: false});
        
        this.element.addEventListener('touchcancel', () => {
            this.cancel();
        }, {passive: false});
    }
    
    cancel() {
        if (this.timer) {
            clearTimeout(this.timer);
            this.timer = null;
        }
        this.isLongPressing = false;
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const longPressArea = document.getElementById('longpress-area');

new LongPress(longPressArea, {
    duration: 600,
    onLongPressStart: () => {
        longPressArea.style.background = '#ffeb3b';
        longPressArea.style.transform = 'scale(0.95)';
    },
    onLongPress: (data) => {
        console.log('๋กฑ ํ”„๋ ˆ์Šค ๊ฐ์ง€!', data);
        // ์ปจํ…์ŠคํŠธ ๋ฉ”๋‰ด ํ‘œ์‹œ
        showContextMenu(data.x, data.y);
    },
    onLongPressEnd: () => {
        longPressArea.style.background = '';
        longPressArea.style.transform = '';
    }
});

๋กฑ ํ”„๋ ˆ์Šค์˜ ํ•ต์‹ฌ์€ setTimeout์ด์•ผ! ํ„ฐ์น˜๊ฐ€ ์‹œ์ž‘๋˜๋ฉด ํƒ€์ด๋จธ๋ฅผ ๊ฑธ๊ณ , ์ง€์ •๋œ ์‹œ๊ฐ„์ด ์ง€๋‚˜๋ฉด ๋กฑ ํ”„๋ ˆ์Šค๋กœ ์ธ์‹ํ•˜๋Š” ๊ฑฐ์ง€. โฑ๏ธ

์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ๊ฑด ์ทจ์†Œ ์กฐ๊ฑด์ด์•ผ. ์‚ฌ์šฉ์ž๊ฐ€ ์†๊ฐ€๋ฝ์„ ์›€์ง์ด๊ฑฐ๋‚˜ ๋–ผ๋ฉด ํƒ€์ด๋จธ๋ฅผ ์ทจ์†Œํ•ด์•ผ ํ•ด. ์•ˆ ๊ทธ๋Ÿฌ๋ฉด ์˜๋„ํ•˜์ง€ ์•Š์€ ๋กฑ ํ”„๋ ˆ์Šค๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ ! โš ๏ธ

๊ทธ๋ฆฌ๊ณ  navigator.vibrate()๋กœ ํ–…ํ‹ฑ ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ๋Š” ๊ฒƒ๋„ ์ข‹์€ UX์•ผ! ์‚ฌ์šฉ์ž๊ฐ€ ๋กฑ ํ”„๋ ˆ์Šค๊ฐ€ ์ธ์‹๋๋‹ค๋Š” ๊ฑธ ์ด‰๊ฐ์œผ๋กœ ๋А๋‚„ ์ˆ˜ ์žˆ๊ฑฐ๋“ . ๐Ÿ“ณ

๐ŸŽจ ์ œ์Šค์ฒ˜ ์‹œ๊ฐํ™”์™€ ํ”ผ๋“œ๋ฐฑ

์ œ์Šค์ฒ˜๋ฅผ ๊ตฌํ˜„ํ–ˆ์œผ๋ฉด ์‚ฌ์šฉ์ž์—๊ฒŒ ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ๋Š” ๊ฒŒ ์ •๋ง ์ค‘์š”ํ•ด! ์‹œ๊ฐ์  ํ”ผ๋“œ๋ฐฑ์ด ์—†์œผ๋ฉด ์‚ฌ์šฉ์ž๋Š” ์ž๊ธฐ๊ฐ€ ๋ญ˜ ํ•˜๊ณ  ์žˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฑฐ๋“ . ๐Ÿ‘€

๐ŸŽฏ ํšจ๊ณผ์ ์ธ ํ”ผ๋“œ๋ฐฑ ๋ฐฉ๋ฒ• 1. ์‹œ๊ฐ์  ํ”ผ๋“œ๋ฐฑ
โ€ข ํ„ฐ์น˜ ์œ„์น˜์— ๋ฆฌํ”Œ ํšจ๊ณผ
โ€ข ๋“œ๋ž˜๊ทธ ์ค‘ ์š”์†Œ ๋”ฐ๋ผ๊ฐ€๊ธฐ
โ€ข ์Šค์™€์ดํ”„ ๋ฐฉํ–ฅ ํ‘œ์‹œ
โ€ข ์ง„ํ–‰ ์ƒํƒœ ํ‘œ์‹œ (๋กฑ ํ”„๋ ˆ์Šค ๋“ฑ)

2. ํ–…ํ‹ฑ ํ”ผ๋“œ๋ฐฑ
โ€ข ์ œ์Šค์ฒ˜ ์ธ์‹ ์‹œ ์ง„๋™
โ€ข ๊ฒฝ๊ณ„๊ฐ’ ๋„๋‹ฌ ์‹œ ์ง„๋™
โ€ข ์•ก์…˜ ์™„๋ฃŒ ์‹œ ์ง„๋™

3. ์˜ค๋””์˜ค ํ”ผ๋“œ๋ฐฑ
โ€ข ํƒญ ์‚ฌ์šด๋“œ
โ€ข ์Šค์™€์ดํ”„ ์‚ฌ์šด๋“œ
โ€ข ํ™•์ธ/์ทจ์†Œ ์‚ฌ์šด๋“œ
// ํ„ฐ์น˜ ๋ฆฌํ”Œ ํšจ๊ณผ
class TouchRipple {
    constructor(container) {
        this.container = container;
        this.container.style.position = 'relative';
        this.container.style.overflow = 'hidden';
        
        this.init();
    }
    
    init() {
        this.container.addEventListener('touchstart', (e) => {
            const touch = e.touches[0];
            const rect = this.container.getBoundingClientRect();
            
            const x = touch.clientX - rect.left;
            const y = touch.clientY - rect.top;
            
            this.createRipple(x, y);
        });
    }
    
    createRipple(x, y) {
        const ripple = document.createElement('div');
        ripple.style.position = 'absolute';
        ripple.style.left = x + 'px';
        ripple.style.top = y + 'px';
        ripple.style.width = '0';
        ripple.style.height = '0';
        ripple.style.borderRadius = '50%';
        ripple.style.background = 'rgba(255, 255, 255, 0.6)';
        ripple.style.transform = 'translate(-50%, -50%)';
        ripple.style.pointerEvents = 'none';
        ripple.style.transition = 'all 0.6s ease-out';
        
        this.container.appendChild(ripple);
        
        // ์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹œ์ž‘
        requestAnimationFrame(() => {
            ripple.style.width = '200px';
            ripple.style.height = '200px';
            ripple.style.opacity = '0';
        });
        
        // ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋๋‚˜๋ฉด ์ œ๊ฑฐ
        setTimeout(() => {
            ripple.remove();
        }, 600);
    }
}

// ๋“œ๋ž˜๊ทธ ๊ฐ€์ด๋“œ ํ‘œ์‹œ
class DragGuide {
    constructor(element) {
        this.element = element;
        this.guide = null;
        this.init();
    }
    
    init() {
        this.element.addEventListener('touchstart', (e) => {
            const touch = e.touches[0];
            this.showGuide(touch.clientX, touch.clientY);
        });
        
        this.element.addEventListener('touchmove', (e) => {
            const touch = e.touches[0];
            this.updateGuide(touch.clientX, touch.clientY);
        });
        
        this.element.addEventListener('touchend', () => {
            this.hideGuide();
        });
    }
    
    showGuide(x, y) {
        if (!this.guide) {
            this.guide = document.createElement('div');
            this.guide.style.position = 'fixed';
            this.guide.style.width = '60px';
            this.guide.style.height = '60px';
            this.guide.style.border = '3px solid #2196f3';
            this.guide.style.borderRadius = '50%';
            this.guide.style.pointerEvents = 'none';
            this.guide.style.transition = 'opacity 0.2s';
            this.guide.style.zIndex = '9999';
            document.body.appendChild(this.guide);
        }
        
        this.guide.style.left = (x - 30) + 'px';
        this.guide.style.top = (y - 30) + 'px';
        this.guide.style.opacity = '1';
    }
    
    updateGuide(x, y) {
        if (this.guide) {
            this.guide.style.left = (x - 30) + 'px';
            this.guide.style.top = (y - 30) + 'px';
        }
    }
    
    hideGuide() {
        if (this.guide) {
            this.guide.style.opacity = '0';
            setTimeout(() => {
                if (this.guide) {
                    this.guide.remove();
                    this.guide = null;
                }
            }, 200);
        }
    }
}

// ๋กฑ ํ”„๋ ˆ์Šค ์ง„ํ–‰ ํ‘œ์‹œ
class LongPressProgress {
    constructor(element, duration) {
        this.element = element;
        this.duration = duration;
        this.progress = null;
        this.startTime = 0;
        this.animationFrame = null;
        
        this.init();
    }
    
    init() {
        this.element.addEventListener('touchstart', (e) => {
            this.startProgress(e.touches[0]);
        });
        
        this.element.addEventListener('touchend', () => {
            this.stopProgress();
        });
        
        this.element.addEventListener('touchcancel', () => {
            this.stopProgress();
        });
    }
    
    startProgress(touch) {
        // ์ง„ํ–‰ ํ‘œ์‹œ ์› ์ƒ์„ฑ
        this.progress = document.createElement('div');
        this.progress.style.position = 'fixed';
        this.progress.style.left = (touch.clientX - 40) + 'px';
        this.progress.style.top = (touch.clientY - 40) + 'px';
        this.progress.style.width = '80px';
        this.progress.style.height = '80px';
        this.progress.style.borderRadius = '50%';
        this.progress.style.border = '4px solid rgba(33, 150, 243, 0.3)';
        this.progress.style.borderTopColor = '#2196f3';
        this.progress.style.pointerEvents = 'none';
        this.progress.style.zIndex = '9999';
        document.body.appendChild(this.progress);
        
        this.startTime = Date.now();
        this.animate();
    }
    
    animate() {
        const elapsed = Date.now() - this.startTime;
        const progress = Math.min(elapsed / this.duration, 1);
        const degrees = progress * 360;
        
        if (this.progress) {
            this.progress.style.transform = `rotate(${degrees}deg)`;
        }
        
        if (progress < 1) {
            this.animationFrame = requestAnimationFrame(() => this.animate());
        }
    }
    
    stopProgress() {
        if (this.animationFrame) {
            cancelAnimationFrame(this.animationFrame);
            this.animationFrame = null;
        }
        
        if (this.progress) {
            this.progress.remove();
            this.progress = null;
        }
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const rippleArea = document.getElementById('ripple-area');
new TouchRipple(rippleArea);

const dragArea = document.getElementById('drag-area');
new DragGuide(dragArea);

const longPressArea = document.getElementById('longpress-area');
new LongPressProgress(longPressArea, 600);

์‹œ๊ฐ์  ํ”ผ๋“œ๋ฐฑ์€ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ์™„์ „ํžˆ ๋ฐ”๊ฟ”๋†”! ๊ฐ™์€ ๊ธฐ๋Šฅ์ด๋ผ๋„ ํ”ผ๋“œ๋ฐฑ์ด ์žˆ๊ณ  ์—†๊ณ ์˜ ์ฐจ์ด๋Š” ์—„์ฒญ๋‚˜๊ฑฐ๋“ . โœจ

ํŠนํžˆ ๋ฆฌํ”Œ ํšจ๊ณผ๋Š” Material Design์—์„œ ์œ ๋ช…ํ•ด์ง„ ๊ฑด๋ฐ, ํ„ฐ์น˜ ์œ„์น˜๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ณด์—ฌ์ค˜์„œ ์‚ฌ์šฉ์ž๊ฐ€ ์ž์‹ ์˜ ์•ก์…˜์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด. ๐Ÿ’ง

๋กฑ ํ”„๋ ˆ์Šค ์ง„ํ–‰ ํ‘œ์‹œ๋„ ์ •๋ง ์ค‘์š”ํ•ด! ์‚ฌ์šฉ์ž๊ฐ€ ์–ผ๋งˆ๋‚˜ ๋” ๋ˆŒ๋Ÿฌ์•ผ ํ•˜๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ ๋‹ต๋‹ตํ•จ์ด ์—†์–ด์ง€์ง€. โณ

๐Ÿ› ๋””๋ฒ„๊น…๊ณผ ํ…Œ์ŠคํŠธ

ํ„ฐ์น˜ ์ด๋ฒคํŠธ๋Š” ๋””๋ฒ„๊น…์ด ์ •๋ง ๊นŒ๋‹ค๋กœ์›Œ. ์‹ค์ œ ๋””๋ฐ”์ด์Šค์—์„œ๋งŒ ์ œ๋Œ€๋กœ ํ…Œ์ŠคํŠธํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ . ํ•˜์ง€๋งŒ ๋ช‡ ๊ฐ€์ง€ ํŒ์„ ์•Œ๋ ค์ค„๊ฒŒ! ๐Ÿ”ง

โš ๏ธ ํ”ํ•œ ์‹ค์ˆ˜๋“ค 1. preventDefault() ๋ˆ„๋ฝ
์ด๊ฑฐ ์•ˆ ํ•˜๋ฉด ๋ธŒ๋ผ์šฐ์ € ๊ธฐ๋ณธ ๋™์ž‘์ด ๊ฐ™์ด ์‹คํ–‰๋ผ์„œ ์ด์ƒํ•˜๊ฒŒ ๋™์ž‘ํ•ด.

2. passive ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ
์ตœ์‹  ๋ธŒ๋ผ์šฐ์ €๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ passive: true๋ผ์„œ preventDefault()๊ฐ€ ์•ˆ ๋จนํ˜€. {passive: false} ์˜ต์…˜ ํ•„์ˆ˜!

3. touches vs changedTouches ํ˜ผ๋™
touchend์—์„œ touches ์“ฐ๋ฉด ๋นˆ ๋ฐฐ์—ด์ด์•ผ. changedTouches๋ฅผ ์จ์•ผ ํ•ด!

4. ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜
์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์ œ๊ฑฐ ์•ˆ ํ•˜๋ฉด ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ๋ฐœ์ƒ. ๊ผญ cleanup ํ•ด์ค˜!
// ํ„ฐ์น˜ ์ด๋ฒคํŠธ ๋””๋ฒ„๊ฑฐ
class TouchDebugger {
    constructor() {
        this.overlay = null;
        this.touches = new Map();
        this.init();
    }
    
    init() {
        // ์˜ค๋ฒ„๋ ˆ์ด ์ƒ์„ฑ
        this.overlay = document.createElement('div');
        this.overlay.style.position = 'fixed';
        this.overlay.style.top = '0';
        this.overlay.style.left = '0';
        this.overlay.style.width = '100%';
        this.overlay.style.height = '100%';
        this.overlay.style.pointerEvents = 'none';
        this.overlay.style.zIndex = '99999';
        document.body.appendChild(this.overlay);
        
        // ์ „์—ญ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ
        document.addEventListener('touchstart', (e) => {
            Array.from(e.touches).forEach(touch => {
                this.addTouch(touch);
            });
        }, {passive: true});
        
        document.addEventListener('touchmove', (e) => {
            Array.from(e.touches).forEach(touch => {
                this.updateTouch(touch);
            });
        }, {passive: true});
        
        document.addEventListener('touchend', (e) => {
            Array.from(e.changedTouches).forEach(touch => {
                this.removeTouch(touch);
            });
        }, {passive: true});
        
        // ์ •๋ณด ํŒจ๋„
        this.createInfoPanel();
    }
    
    addTouch(touch) {
        const marker = document.createElement('div');
        marker.style.position = 'fixed';
        marker.style.left = (touch.clientX - 25) + 'px';
        marker.style.top = (touch.clientY - 25) + 'px';
        marker.style.width = '50px';
        marker.style.height = '50px';
        marker.style.borderRadius = '50%';
        marker.style.background = 'rgba(33, 150, 243, 0.5)';
        marker.style.border = '3px solid #2196f3';
        marker.style.pointerEvents = 'none';
        marker.style.transition = 'all 0.1s';
        
        const label = document.createElement('div');
        label.textContent = touch.identifier;
        label.style.position = 'absolute';
        label.style.top = '50%';
        label.style.left = '50%';
        label.style.transform = 'translate(-50%, -50%)';
        label.style.color = 'white';
        label.style.fontWeight = 'bold';
        marker.appendChild(label);
        
        this.overlay.appendChild(marker);
        this.touches.set(touch.identifier, {
            marker,
            startX: touch.clientX,
            startY: touch.clientY,
            startTime: Date.now()
        });
        
        this.updateInfo();
    }
    
    updateTouch(touch) {
        const data = this.touches.get(touch.identifier);
        if (data) {
            data.marker.style.left = (touch.clientX - 25) + 'px';
            data.marker.style.top = (touch.clientY - 25) + 'px';
        }
    }
    
    removeTouch(touch) {
        const data = this.touches.get(touch.identifier);
        if (data) {
            // ํŽ˜์ด๋“œ ์•„์›ƒ
            data.marker.style.opacity = '0';
            setTimeout(() => {
                data.marker.remove();
            }, 200);
            
            this.touches.delete(touch.identifier);
            this.updateInfo();
        }
    }
    
    createInfoPanel() {
        this.infoPanel = document.createElement('div');
        this.infoPanel.style.position = 'fixed';
        this.infoPanel.style.top = '10px';
        this.infoPanel.style.right = '10px';
        this.infoPanel.style.background = 'rgba(0, 0, 0, 0.8)';
        this.infoPanel.style.color = 'white';
        this.infoPanel.style.padding = '10px';
        this.infoPanel.style.borderRadius = '8px';
        this.infoPanel.style.fontFamily = 'monospace';
        this.infoPanel.style.fontSize = '12px';
        this.infoPanel.style.pointerEvents = 'none';
        this.infoPanel.style.zIndex = '100000';
        document.body.appendChild(this.infoPanel);
    }
    
    updateInfo() {
        const info = [];
        info.push(`Active Touches: ${this.touches.size}`);
        
        this.touches.forEach((data, id) => {
            const duration = Date.now() - data.startTime;
            info.push(`Touch ${id}: ${duration}ms`);
        });
        
        this.infoPanel.textContent = info.join('\n');
    }
    
    destroy() {
        this.overlay.remove();
        this.infoPanel.remove();
    }
}

// ๋””๋ฒ„๊ฑฐ ํ™œ์„ฑํ™” (๊ฐœ๋ฐœ ์ค‘์—๋งŒ)
if (location.hostname === 'localhost') {
    const debugger = new TouchDebugger();
    
    // ์ฝ˜์†”์—์„œ ๋น„ํ™œ์„ฑํ™” ๊ฐ€๋Šฅ
    window.touchDebugger = debugger;
}

์ด ๋””๋ฒ„๊ฑฐ๋ฅผ ์“ฐ๋ฉด ํ„ฐ์น˜ ํฌ์ธํŠธ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ์–ด์„œ ์ •๋ง ํŽธํ•ด! ํŠนํžˆ ๋ฉ€ํ‹ฐํ„ฐ์น˜๋ฅผ ๋””๋ฒ„๊น…ํ•  ๋•Œ ํ•„์ˆ˜์•ผ. ๐Ÿ”

์‹ค์ œ ๋””๋ฐ”์ด์Šค์—์„œ ํ…Œ์ŠคํŠธํ•  ๋•Œ๋Š” ์›๊ฒฉ ๋””๋ฒ„๊น…์„ ํ™œ์šฉํ•˜๋ฉด ์ข‹์•„:

โ€ข Chrome DevTools - chrome://inspect์—์„œ USB ์—ฐ๊ฒฐ๋œ ์•ˆ๋“œ๋กœ์ด๋“œ ๋””๋ฐ”์ด์Šค ๋””๋ฒ„๊น…
โ€ข Safari Web Inspector - iOS ๋””๋ฐ”์ด์Šค ๋””๋ฒ„๊น…
โ€ข Weinre - ๊ตฌํ˜• ๋””๋ฐ”์ด์Šค ๋””๋ฒ„๊น…

๊ทธ๋ฆฌ๊ณ  console.log๋ฅผ ํ™”๋ฉด์— ํ‘œ์‹œํ•˜๋Š” ๊ฒƒ๋„ ์œ ์šฉํ•ด. ์‹ค์ œ ๋””๋ฐ”์ด์Šค์—์„œ๋Š” ์ฝ˜์†”์„ ๋ณด๊ธฐ ์–ด๋ ค์šฐ๋‹ˆ๊นŒ! ๐Ÿ“ฑ

โšก ์„ฑ๋Šฅ ์ตœ์ ํ™”

ํ„ฐ์น˜ ์ด๋ฒคํŠธ๋Š” ์ •๋ง ๋นˆ๋ฒˆํ•˜๊ฒŒ ๋ฐœ์ƒํ•ด. touchmove๋Š” ์ดˆ๋‹น 60๋ฒˆ ์ด์ƒ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ ! ๊ทธ๋ž˜์„œ ์„ฑ๋Šฅ ์ตœ์ ํ™”๊ฐ€ ์ •๋ง ์ค‘์š”ํ•ด. ๐Ÿš€

๐ŸŽฏ ์„ฑ๋Šฅ ์ตœ์ ํ™” ์ฒดํฌ๋ฆฌ์ŠคํŠธ 1. ์“ฐ๋กœํ‹€๋ง(Throttling)
์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์‹คํ–‰ ๋นˆ๋„๋ฅผ ์ œํ•œํ•ด.

2. ๋””๋ฐ”์šด์‹ฑ(Debouncing)
์—ฐ์†๋œ ์ด๋ฒคํŠธ๋ฅผ ํ•˜๋‚˜๋กœ ๋ฌถ์–ด์„œ ์ฒ˜๋ฆฌํ•ด.

3. requestAnimationFrame ์‚ฌ์šฉ
DOM ์กฐ์ž‘์€ RAF ์•ˆ์—์„œ ํ•ด์•ผ ๋ถ€๋“œ๋Ÿฌ์›Œ.

4. CSS transform ํ™œ์šฉ
left/top ๋Œ€์‹  transform์„ ์“ฐ๋ฉด GPU ๊ฐ€์†์„ ๋ฐ›์•„.

5. will-change ์†์„ฑ
๋ธŒ๋ผ์šฐ์ €์—๊ฒŒ ๋ณ€๊ฒฝ๋  ์†์„ฑ์„ ๋ฏธ๋ฆฌ ์•Œ๋ ค์ค˜.

6. ์ด๋ฒคํŠธ ์œ„์ž„
์—ฌ๋Ÿฌ ์š”์†Œ์— ๊ฐœ๋ณ„ ๋ฆฌ์Šค๋„ˆ ๋Œ€์‹  ๋ถ€๋ชจ์— ํ•˜๋‚˜๋งŒ ๋‹ฌ์•„.
// ์“ฐ๋กœํ‹€๋ง ์œ ํ‹ธ๋ฆฌํ‹ฐ
function throttle(func, limit) {
    let inThrottle;
    return function(...args) {
        if (!inThrottle) {
            func.apply(this, args);
            inThrottle = true;
            setTimeout(() => inThrottle = false, limit);
        }
    };
}

// ๋””๋ฐ”์šด์‹ฑ ์œ ํ‹ธ๋ฆฌํ‹ฐ
function debounce(func, delay) {
    let timeoutId;
    return function(...args) {
        clearTimeout(timeoutId);
        timeoutId = setTimeout(() => func.apply(this, args), delay);
    };
}

// ์ตœ์ ํ™”๋œ ํ„ฐ์น˜ ํ•ธ๋“ค๋Ÿฌ
class OptimizedTouchHandler {
    constructor(element) {
        this.element = element;
        this.rafId = null;
        this.touchData = null;
        
        // will-change ์„ค์ •
        this.element.style.willChange = 'transform';
        
        this.init();
    }
    
    init() {
        // touchmove๋Š” ์“ฐ๋กœํ‹€๋ง
        const throttledMove = throttle((e) => {
            this.touchData = {
                x: e.touches[0].clientX,
                y: e.touches[0].clientY
            };
            
            // RAF๋กœ DOM ์—…๋ฐ์ดํŠธ ์˜ˆ์•ฝ
            if (!this.rafId) {
                this.rafId = requestAnimationFrame(() => {
                    this.updatePosition();
                    this.rafId = null;
                });
            }
        }, 16); // ์•ฝ 60fps
        
        this.element.addEventListener('touchstart', (e) => {
            e.preventDefault();
            this.touchData = {
                x: e.touches[0].clientX,
                y: e.touches[0].clientY
            };
        }, {passive: false});
        
        this.element.addEventListener('touchmove', throttledMove, {passive: false});
        
        this.element.addEventListener('touchend', () => {
            if (this.rafId) {
                cancelAnimationFrame(this.rafId);
                this.rafId = null;
            }
            this.touchData = null;
        }, {passive: false});
    }
    
    updatePosition() {
        if (!this.touchData) return;
        
        // transform ์‚ฌ์šฉ (GPU ๊ฐ€์†)
        this.element.style.transform = 
            `translate(${this.touchData.x}px, ${this.touchData.y}px)`;
    }
    
    destroy() {
        if (this.rafId) {
            cancelAnimationFrame(this.rafId);
        }
        this.element.style.willChange = 'auto';
    }
}

// ์ด๋ฒคํŠธ ์œ„์ž„ ์˜ˆ์‹œ
class TouchEventDelegation {
    constructor(container) {
        this.container = container;
        this.init();
    }
    
    init() {
        // ์ปจํ…Œ์ด๋„ˆ์— ํ•˜๋‚˜์˜ ๋ฆฌ์Šค๋„ˆ๋งŒ
        this.container.addEventListener('touchstart', (e) => {
            const target = e.target.closest('[data-touchable]');
            if (target) {
                this.handleTouch(target, e);
            }
        }, {passive: false});
    }
    
    handleTouch(element, event) {
        const action = element.dataset.touchAction;
        
        switch(action) {
            case 'tap':
                this.handleTap(element, event);
                break;
            case 'swipe':
                this.handleSwipe(element, event);
                break;
            // ... ๋‹ค๋ฅธ ์•ก์…˜๋“ค
        }
    }
    
    handleTap(element, event) {
        // ํƒญ ์ฒ˜๋ฆฌ
        console.log('Tap:', element);
    }
    
    handleSwipe(element, event) {
        // ์Šค์™€์ดํ”„ ์ฒ˜๋ฆฌ
        console.log('Swipe:', element);
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const container = document.getElementById('container');
new TouchEventDelegation(container);

// HTML:
// <div id="container">
//   <div data-touchable data-touch-action="tap">ํƒญ ๊ฐ€๋Šฅ</div>
//   <div data-touchable data-touch-action="swipe">์Šค์™€์ดํ”„ ๊ฐ€๋Šฅ</div>
// </div>

์„ฑ๋Šฅ ์ตœ์ ํ™”์˜ ํ•ต์‹ฌ์€ ๋ถˆํ•„์š”ํ•œ ์ž‘์—…์„ ์ค„์ด๋Š” ๊ฒƒ์ด์•ผ! โœ‚๏ธ

ํŠนํžˆ touchmove ์ด๋ฒคํŠธ๋Š” ์ •๋ง ์ž์ฃผ ๋ฐœ์ƒํ•˜๋‹ˆ๊นŒ, ์“ฐ๋กœํ‹€๋ง์œผ๋กœ ์‹คํ–‰ ๋นˆ๋„๋ฅผ ์ œํ•œํ•˜๊ณ , requestAnimationFrame์œผ๋กœ DOM ์—…๋ฐ์ดํŠธ๋ฅผ ์ตœ์ ํ™”ํ•ด์•ผ ํ•ด. โšก

๊ทธ๋ฆฌ๊ณ  transform์„ ์“ฐ๋Š” ๊ฒŒ ์ •๋ง ์ค‘์š”ํ•ด! left๋‚˜ top์„ ์ง์ ‘ ๋ฐ”๊พธ๋ฉด ๋ ˆ์ด์•„์›ƒ ์žฌ๊ณ„์‚ฐ์ด ์ผ์–ด๋‚˜์„œ ๋А๋ ค์ง€๊ฑฐ๋“ . transform์€ GPU์—์„œ ์ฒ˜๋ฆฌ๋˜๋‹ˆ๊นŒ ํ›จ์”ฌ ๋นจ๋ผ! ๐ŸŽฎ

๐ŸŽ“ Pro Tip: Chrome DevTools์˜ Performance ํƒญ์„ ํ™œ์šฉํ•ด์„œ ํ”„๋ ˆ์ž„ ๋“œ๋กญ์„ ํ™•์ธํ•ด๋ด. 60fps๋ฅผ ์œ ์ง€ํ•˜๋Š” ๊ฒŒ ๋ชฉํ‘œ์•ผ! ๊ทธ๋ฆฌ๊ณ  "Paint flashing"์„ ์ผœ๋ฉด ์–ด๋–ค ์˜์—ญ์ด ๋‹ค์‹œ ๊ทธ๋ ค์ง€๋Š”์ง€ ๋ณผ ์ˆ˜ ์žˆ์–ด. ์ด๊ฒŒ ์ตœ์†Œํ™”๋˜๋„๋ก ์ตœ์ ํ™”ํ•˜๋ฉด ๋ผ! ๐ŸŽจ

๐Ÿ“š ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ™œ์šฉํ•˜๊ธฐ

์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ๋„ ์ข‹์ง€๋งŒ, ๊ฒ€์ฆ๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ๋Š” ๊ฒƒ๋„ ํ˜„๋ช…ํ•œ ์„ ํƒ์ด์•ผ. ์‹œ๊ฐ„๋„ ์ ˆ์•ฝ๋˜๊ณ  ๋ฒ„๊ทธ๋„ ์ ๊ฑฐ๋“ ! ๐Ÿ“ฆ

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํŠน์ง• ์šฉ๋Ÿ‰ ์ถ”์ฒœ ์šฉ๋„
Hammer.js ๊ฐ€์žฅ ์œ ๋ช…ํ•œ ํ„ฐ์น˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ~24KB ๋ณต์žกํ•œ ์ œ์Šค์ฒ˜ ๊ตฌํ˜„
ZingTouch ๊ฐ€๋ณ๊ณ  ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ์‰ฌ์›€ ~10KB ์ปค์Šคํ…€ ์ œ์Šค์ฒ˜
Interact.js ๋“œ๋ž˜๊ทธ ์•ค ๋“œ๋กญ์— ํŠนํ™” ~50KB ๋“œ๋ž˜๊ทธ ์•ค ๋“œ๋กญ UI
AlloyFinger ์ค‘๊ตญ ํ…์„ผํŠธ ์ œ์ž‘, ๊ฐ€๋ฒผ์›€ ~2KB ๊ฐ„๋‹จํ•œ ์ œ์Šค์ฒ˜
// Hammer.js ์‚ฌ์šฉ ์˜ˆ์‹œ
import Hammer from 'hammerjs';

const element = document.getElementById('hammer-area');
const hammer = new Hammer(element);

// ํƒญ ์ œ์Šค์ฒ˜
hammer.on('tap', (e) => {
    console.log('ํƒญ!', e);
});

// ์Šค์™€์ดํ”„ ์ œ์Šค์ฒ˜
hammer.on('swipe', (e) => {
    console.log('์Šค์™€์ดํ”„ ๋ฐฉํ–ฅ:', e.direction);
    // 1: left, 2: right, 4: up, 8: down
});

// ํ•€์น˜ ์ œ์Šค์ฒ˜
hammer.get('pinch').set({ enable: true });
hammer.on('pinch', (e) => {
    console.log('ํ•€์น˜ ์Šค์ผ€์ผ:', e.scale);
});

// ํšŒ์ „ ์ œ์Šค์ฒ˜
hammer.get('rotate').set({ enable: true });
hammer.on('rotate', (e) => {
    console.log('ํšŒ์ „ ๊ฐ๋„:', e.rotation);
});

// ํŒฌ(๋“œ๋ž˜๊ทธ) ์ œ์Šค์ฒ˜
hammer.on('pan', (e) => {
    console.log('ํŒฌ ์ด๋™:', e.deltaX, e.deltaY);
});

// ๋กฑ ํ”„๋ ˆ์Šค
hammer.on('press', (e) => {
    console.log('๋กฑ ํ”„๋ ˆ์Šค!', e);
});

// ZingTouch ์‚ฌ์šฉ ์˜ˆ์‹œ
import ZingTouch from 'zingtouch';

const region = new ZingTouch.Region(document.body);
const target = document.getElementById('zing-area');

// ์Šค์™€์ดํ”„
region.bind(target, 'swipe', (e) => {
    console.log('์Šค์™€์ดํ”„ ์†๋„:', e.detail.velocity);
    console.log('์Šค์™€์ดํ”„ ๋ฐฉํ–ฅ:', e.detail.currentDirection);
});

// ํƒญ
region.bind(target, 'tap', (e) => {
    console.log('ํƒญ ์œ„์น˜:', e.detail.events[0].x, e.detail.events[0].y);
});

// ์ปค์Šคํ…€ ์ œ์Šค์ฒ˜ ์ •์˜
const circleGesture = new ZingTouch.Gesture('circle', (inputs) => {
    // ์›ํ˜• ์ œ์Šค์ฒ˜ ๋กœ์ง
    // ...
});

region.bind(target, circleGesture, (e) => {
    console.log('์›ํ˜• ์ œ์Šค์ฒ˜ ๊ฐ์ง€!');
});

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ฐ๋ฉด ์ •๋ง ํŽธํ•ด! ํŠนํžˆ Hammer.js๋Š” ๊ฑฐ์˜ ํ‘œ์ค€์ฒ˜๋Ÿผ ์“ฐ์ด๋Š”๋ฐ, API๊ฐ€ ์ง๊ด€์ ์ด๊ณ  ๋ฌธ์„œ๋„ ์ž˜ ๋˜์–ด ์žˆ์–ด. ๐Ÿ”จ

๊ทผ๋ฐ ์ฃผ์˜ํ•  ์ ์€ ๋ฒˆ๋“ค ํฌ๊ธฐ์•ผ. ๋ชจ๋ฐ”์ผ ์›น์—์„œ๋Š” ๋กœ๋”ฉ ์†๋„๊ฐ€ ์ •๋ง ์ค‘์š”ํ•˜๊ฑฐ๋“ . ๊ฐ„๋‹จํ•œ ์ œ์Šค์ฒ˜๋งŒ ํ•„์š”ํ•˜๋ฉด ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒŒ ๋‚˜์„ ์ˆ˜๋„ ์žˆ์–ด. โš–๏ธ

์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ํ”„๋ฆฌ๋žœ์„œ๋กœ ์ผํ•  ๋•Œ๋„, ํด๋ผ์ด์–ธํŠธ ์š”๊ตฌ์‚ฌํ•ญ์— ๋”ฐ๋ผ ์ง์ ‘ ๊ตฌํ˜„ํ• ์ง€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์“ธ์ง€ ํŒ๋‹จํ•˜๋Š” ๊ฒŒ ์ค‘์š”ํ•ด. ํ”„๋กœ์ ํŠธ ๊ทœ๋ชจ์™€ ์ผ์ •์„ ๊ณ ๋ คํ•ด์•ผ ํ•˜๊ฑฐ๋“ ! ๐Ÿ’ผ

๐ŸŒ ํฌ๋กœ์Šค ๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

ํ„ฐ์น˜ ์ด๋ฒคํŠธ๋Š” ๋ธŒ๋ผ์šฐ์ €๋งˆ๋‹ค ์กฐ๊ธˆ์”ฉ ๋‹ค๋ฅด๊ฒŒ ๋™์ž‘ํ•ด. ํŠนํžˆ ๊ตฌํ˜• ๋ธŒ๋ผ์šฐ์ €๋Š” ์ง€์›์ด ์•ˆ ๋˜๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์–ด. ํ˜ธํ™˜์„ฑ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์ˆ˜์•ผ! ๐Ÿ”ง

๐ŸŽฏ ๋ธŒ๋ผ์šฐ์ €๋ณ„ ์ฃผ์˜์‚ฌํ•ญ iOS Safari
โ€ข 300ms ํƒญ ๋”œ๋ ˆ์ด (iOS 9.3 ์ดํ•˜)
โ€ข ํ„ฐ์น˜ ์ด๋ฒคํŠธ์™€ ๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ ์ค‘๋ณต ๋ฐœ์ƒ
โ€ข passive ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ ๊ธฐ๋ณธ๊ฐ’

Android Chrome
โ€ข ํ„ฐ์น˜ ์ด๋ฒคํŠธ ์ง€์› ์šฐ์ˆ˜
โ€ข ์ผ๋ถ€ ๊ตฌํ˜• ๋ฒ„์ „์—์„œ ๋ฒ„๊ทธ
โ€ข ๋””๋ฐ”์ด์Šค๋ณ„ ํ„ฐ์น˜ ๊ฐ๋„ ์ฐจ์ด

IE/Edge (๊ตฌ๋ฒ„์ „)
โ€ข ํ„ฐ์น˜ ์ด๋ฒคํŠธ ๋Œ€์‹  Pointer Events ์‚ฌ์šฉ
โ€ข ํด๋ฆฌํ•„ ํ•„์š”

Firefox Mobile
โ€ข ํ„ฐ์น˜ ์ด๋ฒคํŠธ ์ง€์›
โ€ข ์ผ๋ถ€ ์ œ์Šค์ฒ˜ ์ธ์‹ ์ฐจ์ด
// ํ„ฐ์น˜/๋งˆ์šฐ์Šค/ํฌ์ธํ„ฐ ์ด๋ฒคํŠธ ํ†ตํ•ฉ ์ฒ˜๋ฆฌ
class UnifiedInput {
    constructor(element, callbacks) {
        this.element = element;
        this.callbacks = callbacks;
        this.isTouch = false;
        
        this.init();
    }
    
    init() {
        // ํ„ฐ์น˜ ์ง€์› ํ™•์ธ
        const hasTouch = 'ontouchstart' in window;
        const hasPointer = 'PointerEvent' in window;
        
        if (hasPointer) {
            // Pointer Events ์‚ฌ์šฉ (์ตœ์‹  ๋ฐฉ์‹)
            this.setupPointerEvents();
        } else if (hasTouch) {
            // Touch Events ์‚ฌ์šฉ
            this.setupTouchEvents();
        } else {
            // Mouse Events ํด๋ฐฑ
            this.setupMouseEvents();
        }
    }
    
    setupPointerEvents() {
        this.element.addEventListener('pointerdown', (e) => {
            this.callbacks.onStart?.({
                x: e.clientX,
                y: e.clientY,
                id: e.pointerId,
                type: e.pointerType
            });
        });
        
        this.element.addEventListener('pointermove', (e) => {
            this.callbacks.onMove?.({
                x: e.clientX,
                y: e.clientY,
                id: e.pointerId
            });
        });
        
        this.element.addEventListener('pointerup', (e) => {
            this.callbacks.onEnd?.({
                x: e.clientX,
                y: e.clientY,
                id: e.pointerId
            });
        });
    }
    
    setupTouchEvents() {
        this.element.addEventListener('touchstart', (e) => {
            this.isTouch = true;
            const touch = e.touches[0];
            this.callbacks.onStart?.({
                x: touch.clientX,
                y: touch.clientY,
                id: touch.identifier,
                type: 'touch'
            });
        }, {passive: false});
        
        this.element.addEventListener('touchmove', (e) => {
            const touch = e.touches[0];
            this.callbacks.onMove?.({
                x: touch.clientX,
                y: touch.clientY,
                id: touch.identifier
            });
        }, {passive: false});
        
        this.element.addEventListener('touchend', (e) => {
            const touch = e.changedTouches[0];
            this.callbacks.onEnd?.({
                x: touch.clientX,
                y: touch.clientY,
                id: touch.identifier
            });
        }, {passive: false});
    }
    
    setupMouseEvents() {
        let isDown = false;
        
        this.element.addEventListener('mousedown', (e) => {
            // ํ„ฐ์น˜ ์ด๋ฒคํŠธ๊ฐ€ ์ด๋ฏธ ์ฒ˜๋ฆฌ๋์œผ๋ฉด ๋ฌด์‹œ
            if (this.isTouch) return;
            
            isDown = true;
            this.callbacks.onStart?.({
                x: e.clientX,
                y: e.clientY,
                id: 0,
                type: 'mouse'
            });
        });
        
        this.element.addEventListener('mousemove', (e) => {
            if (!isDown || this.isTouch) return;
            
            this.callbacks.onMove?.({
                x: e.clientX,
                y: e.clientY,
                id: 0
            });
        });
        
        this.element.addEventListener('mouseup', (e) => {
            if (!isDown || this.isTouch) return;
            
            isDown = false;
            this.callbacks.onEnd?.({
                x: e.clientX,
                y: e.clientY,
                id: 0
            });
        });
    }
}

// 300ms ํƒญ ๋”œ๋ ˆ์ด ์ œ๊ฑฐ (iOS ๊ตฌ๋ฒ„์ „)
function removeTapDelay() {
    // viewport meta ํƒœ๊ทธ ํ™•์ธ
    let viewport = document.querySelector('meta[name=viewport]');
    
    if (!viewport) {
        viewport = document.createElement('meta');
        viewport.name = 'viewport';
        document.head.appendChild(viewport);
    }
    
    // user-scalable=no ๋˜๋Š” width=device-width ์„ค์ •
    const content = viewport.getAttribute('content') || '';
    if (!content.includes('user-scalable=no') && 
        !content.includes('width=device-width')) {
        viewport.setAttribute('content', 
            content + ', width=device-width, user-scalable=no');
    }
    
    // CSS touch-action ์„ค์ •
    document.body.style.touchAction = 'manipulation';
}

// FastClick ๋Œ€์ฒด (๋” ์ด์ƒ ํ•„์š” ์—†์ง€๋งŒ ์ฐธ๊ณ ์šฉ)
function modernFastClick(element) {
    element.addEventListener('touchend', (e) => {
        e.preventDefault();
        
        // ํด๋ฆญ ์ด๋ฒคํŠธ ์ฆ‰์‹œ ๋ฐœ์ƒ
        const clickEvent = new MouseEvent('click', {
            bubbles: true,
            cancelable: true,
            view: window
        });
        
        e.target.dispatchEvent(clickEvent);
    }, {passive: false});
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const inputArea = document.getElementById('input-area');

new UnifiedInput(inputArea, {
    onStart: (data) => {
        console.log('์ž…๋ ฅ ์‹œ์ž‘:', data);
    },
    onMove: (data) => {
        console.log('์ž…๋ ฅ ์ด๋™:', data);
    },
    onEnd: (data) => {
        console.log('์ž…๋ ฅ ์ข…๋ฃŒ:', data);
    }
});

// ํƒญ ๋”œ๋ ˆ์ด ์ œ๊ฑฐ
removeTapDelay();

ํฌ๋กœ์Šค ๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ ์ฒ˜๋ฆฌ๋Š” ์ •๋ง ์ค‘์š”ํ•ด! ํŠนํžˆ Pointer Events๋Š” ์ตœ์‹  ํ‘œ์ค€์ด๋ผ์„œ, ๊ฐ€๋Šฅํ•˜๋ฉด ์ด๊ฑธ ์šฐ์„ ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ํด๋ฐฑ์œผ๋กœ ํ„ฐ์น˜/๋งˆ์šฐ์Šค ์ด๋ฒคํŠธ๋ฅผ ์“ฐ๋Š” ๊ฒŒ ์ข‹์•„. ๐ŸŽฏ

iOS์˜ 300ms ํƒญ ๋”œ๋ ˆ์ด๋Š” ์˜ˆ์ „์—๋Š” ํฐ ๋ฌธ์ œ์˜€๋Š”๋ฐ, ์ตœ์‹  ๋ฒ„์ „์—์„œ๋Š” ๊ฑฐ์˜ ํ•ด๊ฒฐ๋์–ด. ํ•˜์ง€๋งŒ ๊ตฌ๋ฒ„์ „ ์ง€์›์ด ํ•„์š”ํ•˜๋ฉด ์—ฌ์ „ํžˆ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•ด. โฑ๏ธ

๐ŸŽฏ ์‹ค์ „ ์˜ˆ์ œ: ์ด๋ฏธ์ง€ ๊ฐค๋Ÿฌ๋ฆฌ

์ด์ œ ๋ฐฐ์šด ๊ฑธ ๋‹ค ํ•ฉ์ณ์„œ ์‹ค์ „ ์˜ˆ์ œ๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž! ์Šค์™€์ดํ”„๋กœ ๋„˜๊ธฐ๊ณ , ํ•€์น˜๋กœ ํ™•๋Œ€ํ•˜๊ณ , ๋“œ๋ž˜๊ทธ๋กœ ์ด๋™ํ•˜๋Š” ์ด๋ฏธ์ง€ ๊ฐค๋Ÿฌ๋ฆฌ์•ผ. ๐Ÿ–ผ๏ธ

class ImageGallery {
    constructor(container, images) {
        this.container = container;
        this.images = images;
        this.currentIndex = 0;
        
        // ์ƒํƒœ
        this.state = {
            scale: 1,
            translateX: 0,
            translateY: 0,
            rotation: 0
        };
        
        // ์ œ์Šค์ฒ˜ ์ถ”์ 
        this.gesture = {
            type: null,
            startX: 0,
            startY: 0,
            startDistance: 0,
            startAngle: 0
        };
        
        this.init();
    }
    
    init() {
        this.createGallery();
        this.setupGestures();
        this.showImage(0);
    }
    
    createGallery() {
        this.container.innerHTML = `
            <div class="gallery-viewport">
                <div class="gallery-track">
                    ${this.images.map((img, i) => `
                        <div class="gallery-item" data-index="${i}">
                            <img src="${img}" alt="Image ${i + 1}">
                        </div>
                    `).join('')}
                </div>
            </div>
            <div class="gallery-indicators">
                ${this.images.map((_, i) => `
                    <span class="indicator ${i === 0 ? 'active' : ''}" 
                          data-index="${i}"></span>
                `).join('')}
            </div>
        `;
        
        this.viewport = this.container.querySelector('.gallery-viewport');
        this.track = this.container.querySelector('.gallery-track');
        this.items = this.container.querySelectorAll('.gallery-item');
        this.indicators = this.container.querySelectorAll('.indicator');
        
        // ์Šคํƒ€์ผ ์„ค์ •
        this.container.style.position = 'relative';
        this.container.style.overflow = 'hidden';
        this.viewport.style.width = '100%';
        this.viewport.style.height = '100%';
        this.track.style.display = 'flex';
        this.track.style.transition = 'transform 0.3s ease-out';
        
        this.items.forEach(item => {
            item.style.minWidth = '100%';
            item.style.display = 'flex';
            item.style.alignItems = 'center';
            item.style.justifyContent = 'center';
        });
    }
    
    setupGestures() {
        let startX, startY, startTime;
        let isDragging = false;
        
        this.viewport.addEventListener('touchstart', (e) => {
            e.preventDefault();
            
            const touch = e.touches[0];
            startX = touch.clientX;
            startY = touch.clientY;
            startTime = Date.now();
            
            // ํŠธ๋žœ์ง€์…˜ ๋น„ํ™œ์„ฑํ™”
            this.track.style.transition = 'none';
            
            if (e.touches.length === 1) {
                this.gesture.type = 'pan';
                this.gesture.startX = startX;
            } else if (e.touches.length === 2) {
                this.gesture.type = 'pinch';
                this.gesture.startDistance = this.getDistance(
                    e.touches[0],
                    e.touches[1]
                );
            }
        }, {passive: false});
        
        this.viewport.addEventListener('touchmove', (e) => {
            e.preventDefault();
            
            if (this.gesture.type === 'pan' && e.touches.length === 1) {
                const touch = e.touches[0];
                const deltaX = touch.clientX - this.gesture.startX;
                
                // ํ˜„์žฌ ์ด๋ฏธ์ง€ ์œ„์น˜ + ๋“œ๋ž˜๊ทธ ๊ฑฐ๋ฆฌ
                const baseTranslate = -this.currentIndex * this.viewport.offsetWidth;
                const newTranslate = baseTranslate + deltaX;
                
                this.track.style.transform = `translateX(${newTranslate}px)`;
                isDragging = true;
                
            } else if (this.gesture.type === 'pinch' && e.touches.length === 2) {
                const currentDistance = this.getDistance(
                    e.touches[0],
                    e.touches[1]
                );
                
                const scale = currentDistance / this.gesture.startDistance;
                this.state.scale *= scale;
                
                // ์Šค์ผ€์ผ ์ œํ•œ
                this.state.scale = Math.max(1, Math.min(4, this.state.scale));
                
                const currentItem = this.items[this.currentIndex];
                const img = currentItem.querySelector('img');
                img.style.transform = `scale(${this.state.scale})`;
                
                this.gesture.startDistance = currentDistance;
            }
        }, {passive: false});
        
        this.viewport.addEventListener('touchend', (e) => {
            if (this.gesture.type === 'pan' && isDragging) {
                const touch = e.changedTouches[0];
                const deltaX = touch.clientX - this.gesture.startX;
                const duration = Date.now() - startTime;
                const velocity = Math.abs(deltaX) / duration;
                
                // ์Šค์™€์ดํ”„ ํŒ๋‹จ
                const threshold = this.viewport.offsetWidth * 0.3;
                const isSwipe = Math.abs(deltaX) > threshold || velocity > 0.5;
                
                if (isSwipe) {
                    if (deltaX > 0 && this.currentIndex > 0) {
                        // ์ด์ „ ์ด๋ฏธ์ง€
                        this.showImage(this.currentIndex - 1);
                    } else if (deltaX < 0 && this.currentIndex < this.images.length - 1) {
                        // ๋‹ค์Œ ์ด๋ฏธ์ง€
                        this.showImage(this.currentIndex + 1);
                    } else {
                        // ๊ฒฝ๊ณ„์—์„œ ํŠ•๊น€
                        this.showImage(this.currentIndex);
                    }
                } else {
                    // ์›์œ„์น˜
                    this.showImage(this.currentIndex);
                }
            }
            
            // ํŠธ๋žœ์ง€์…˜ ์žฌํ™œ์„ฑํ™”
            this.track.style.transition = 'transform 0.3s ease-out';
            
            this.gesture.type = null;
            isDragging = false;
        }, {passive: false});
        
        // ์ธ๋””์ผ€์ดํ„ฐ ํด๋ฆญ
        this.indicators.forEach(indicator => {
            indicator.addEventListener('click', () => {
                const index = parseInt(indicator.dataset.index);
                this.showImage(index);
            });
        });
    }
    
    getDistance(touch1, touch2) {
        const dx = touch2.clientX - touch1.clientX;
        const dy = touch2.clientY - touch1.clientY;
        return Math.sqrt(dx * dx + dy * dy);
    }
    
    showImage(index) {
        this.currentIndex = index;
        
        const translateX = -index * this.viewport.offsetWidth;
        this.track.style.transform = `translateX(${translateX}px)`;
        
        // ์ธ๋””์ผ€์ดํ„ฐ ์—…๋ฐ์ดํŠธ
        this.indicators.forEach((indicator, i) => {
            indicator.classList.toggle('active', i === index);
        });
        
        // ์Šค์ผ€์ผ ๋ฆฌ์…‹
        this.state.scale = 1;
        const img = this.items[index].querySelector('img');
        img.style.transform = 'scale(1)';
    }
    
    next() {
        if (this.currentIndex < this.images.length - 1) {
            this.showImage(this.currentIndex + 1);
        }
    }
    
    prev() {
        if (this.currentIndex > 0) {
            this.showImage(this.currentIndex - 1);
        }
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const galleryContainer = document.getElementById('gallery');
const images = [
    'image1.jpg',
    'image2.jpg',
    'image3.jpg',
    'image4.jpg'
];

const gallery = new ImageGallery(galleryContainer, images);

// ์™ธ๋ถ€์—์„œ ์ œ์–ด
document.getElementById('prev-btn').addEventListener('click', () => {
    gallery.prev();
});

document.getElementById('next-btn').addEventListener('click', () => {
    gallery.next();
});

์ด ๊ฐค๋Ÿฌ๋ฆฌ๋Š” ์‹ค์ œ ํ”„๋กœ๋•์…˜์—์„œ ์“ธ ์ˆ˜ ์žˆ์„ ์ •๋„๋กœ ์™„์„ฑ๋„๊ฐ€ ๋†’์•„! โœจ

ํ•ต์‹ฌ ๊ธฐ๋Šฅ๋“ค:
โ€ข ์Šค์™€์ดํ”„ ๋„ค๋น„๊ฒŒ์ด์…˜ - ์ขŒ์šฐ๋กœ ์“ธ์–ด์„œ ์ด๋ฏธ์ง€ ์ „ํ™˜
โ€ข ํ•€์น˜ ์คŒ - ๋‘ ์†๊ฐ€๋ฝ์œผ๋กœ ํ™•๋Œ€/์ถ•์†Œ
โ€ข ๊ด€์„ฑ ์Šคํฌ๋กค - ๋น ๋ฅด๊ฒŒ ์Šค์™€์ดํ”„ํ•˜๋ฉด ์†๋„์— ๋”ฐ๋ผ ์ „ํ™˜
โ€ข ๊ฒฝ๊ณ„ ์ฒ˜๋ฆฌ - ์ฒซ/๋งˆ์ง€๋ง‰ ์ด๋ฏธ์ง€์—์„œ ํŠ•๊น€ ํšจ๊ณผ
โ€ข ์ธ๋””์ผ€์ดํ„ฐ - ํ˜„์žฌ ์œ„์น˜ ํ‘œ์‹œ

์ด๋Ÿฐ ๊ฐค๋Ÿฌ๋ฆฌ๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์œผ๋ฉด, ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ํ”„๋ฆฌ๋žœ์„œ๋กœ ํ™œ๋™ํ•  ๋•Œ ์ •๋ง ์œ ์šฉํ•ด! ํด๋ผ์ด์–ธํŠธ๋“ค์ด ์ด๋Ÿฐ ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒํ•œ UI๋ฅผ ๋งŽ์ด ์›ํ•˜๊ฑฐ๋“ . ๐Ÿ’ผ

๐Ÿ” ๋ณด์•ˆ ๊ณ ๋ ค์‚ฌํ•ญ

ํ„ฐ์น˜ ์ด๋ฒคํŠธ๋ฅผ ๋‹ค๋ฃฐ ๋•Œ ๋ณด์•ˆ๋„ ์‹ ๊ฒฝ ์จ์•ผ ํ•ด. ํŠนํžˆ ์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋งŒํผ ์กฐ์‹ฌํ•ด์•ผ ํ•  ๊ฒŒ ๋งŽ์•„. ๐Ÿ›ก๏ธ

โš ๏ธ ๋ณด์•ˆ ์ฒดํฌ๋ฆฌ์ŠคํŠธ 1. ์ž…๋ ฅ ๊ฒ€์ฆ
ํ„ฐ์น˜ ์ขŒํ‘œ๋‚˜ ์ œ์Šค์ฒ˜ ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„๋กœ ๋ณด๋‚ผ ๋•Œ ๋ฐ˜๋“œ์‹œ ๊ฒ€์ฆํ•ด์•ผ ํ•ด.

2. XSS ๋ฐฉ์ง€
์‚ฌ์šฉ์ž ์ž…๋ ฅ์„ DOM์— ์‚ฝ์ž…ํ•  ๋•Œ sanitize ํ•ด์•ผ ํ•ด.

3. ํด๋ฆญ์žฌํ‚น ๋ฐฉ์ง€
ํˆฌ๋ช…ํ•œ ์˜ค๋ฒ„๋ ˆ์ด๋กœ ์‚ฌ์šฉ์ž๋ฅผ ์†์ด๋Š” ๊ณต๊ฒฉ์„ ๋ง‰์•„์•ผ ํ•ด.

4. ํ„ฐ์น˜ ์ด๋ฒคํŠธ ํ•˜์ด์žฌํ‚น
์•…์˜์ ์ธ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ํ„ฐ์น˜ ์ด๋ฒคํŠธ๋ฅผ ๊ฐ€๋กœ์ฑ„์ง€ ๋ชปํ•˜๋„๋ก ํ•ด์•ผ ํ•ด.

5. ๋ฏผ๊ฐํ•œ ์ •๋ณด ๋ณดํ˜ธ
ํ„ฐ์น˜ ํŒจํ„ด์ด๋‚˜ ์ œ์Šค์ฒ˜๋กœ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ ํŠนํžˆ ์กฐ์‹ฌํ•ด์•ผ ํ•ด.
// ์•ˆ์ „ํ•œ ํ„ฐ์น˜ ์ž…๋ ฅ ์ฒ˜๋ฆฌ
class SecureTouchInput {
    constructor(element) {
        this.element = element;
        this.inputHistory = [];
        this.maxHistorySize = 100;
        
        this.init();
    }
    
    init() {
        this.element.addEventListener('touchstart', (e) => {
            // ์ž…๋ ฅ ๊ฒ€์ฆ
            if (!this.validateTouch(e)) {
                console.warn('Invalid touch event detected');
                return;
            }
            
            // ์ž…๋ ฅ ๊ธฐ๋ก (๋””๋ฒ„๊น…/๋ถ„์„์šฉ)
            this.recordInput(e);
            
            // ์‹ค์ œ ์ฒ˜๋ฆฌ
            this.handleTouch(e);
        }, {passive: false});
    }
    
    validateTouch(event) {
        // 1. ์ด๋ฒคํŠธ ๊ฐ์ฒด ๊ฒ€์ฆ
        if (!event || !event.touches) {
            return false;
        }
        
        // 2. ํ„ฐ์น˜ ํฌ์ธํŠธ ๊ฐœ์ˆ˜ ์ œํ•œ
        if (event.touches.length > 10) {
            console.warn('Too many touch points');
            return false;
        }
        
        // 3. ์ขŒํ‘œ ๋ฒ”์œ„ ๊ฒ€์ฆ
        for (let touch of event.touches) {
            if (touch.clientX < 0 || touch.clientY < 0 ||
                touch.clientX > window.innerWidth ||
                touch.clientY > window.innerHeight) {
                console.warn('Touch coordinates out of bounds');
                return false;
            }
        }
        
        // 4. ์‹œ๊ฐ„ ๊ฐ„๊ฒฉ ๊ฒ€์ฆ (๋„ˆ๋ฌด ๋น ๋ฅธ ์ž…๋ ฅ ๋ฐฉ์ง€)
        const now = Date.now();
        if (this.lastTouchTime && now - this.lastTouchTime < 10) {
            console.warn('Touch events too frequent');
            return false;
        }
        this.lastTouchTime = now;
        
        return true;
    }
    
    recordInput(event) {
        const record = {
            timestamp: Date.now(),
            type: event.type,
            touchCount: event.touches.length,
            // ๋ฏผ๊ฐํ•œ ์ •๋ณด๋Š” ํ•ด์‹œํ™”
            fingerprint: this.hashTouchData(event)
        };
        
        this.inputHistory.push(record);
        
        // ํžˆ์Šคํ† ๋ฆฌ ํฌ๊ธฐ ์ œํ•œ
        if (this.inputHistory.length > this.maxHistorySize) {
            this.inputHistory.shift();
        }
    }
    
    hashTouchData(event) {
        // ์‹ค์ œ๋กœ๋Š” crypto API ์‚ฌ์šฉ
        const data = Array.from(event.touches).map(t => 
            `${t.clientX},${t.clientY}`
        ).join('|');
        
        // ๊ฐ„๋‹จํ•œ ํ•ด์‹œ (์‹ค์ œ๋กœ๋Š” SHA-256 ๋“ฑ ์‚ฌ์šฉ)
        let hash = 0;
        for (let i = 0; i < data.length; i++) {
            hash = ((hash << 5) - hash) + data.charCodeAt(i);
            hash = hash & hash;
        }
        return hash.toString(36);
    }
    
    handleTouch(event) {
        // ์•ˆ์ „ํ•˜๊ฒŒ ์ฒ˜๋ฆฌ๋œ ํ„ฐ์น˜ ์ด๋ฒคํŠธ
        console.log('Safe touch event:', event);
    }
    
    // ์ด์ƒ ํŒจํ„ด ๊ฐ์ง€
    detectAnomalies() {
        if (this.inputHistory.length < 10) return false;
        
        const recent = this.inputHistory.slice(-10);
        const avgInterval = recent.reduce((sum, record, i) => {
            if (i === 0) return 0;
            return sum + (record.timestamp - recent[i-1].timestamp);
        }, 0) / 9;
        
        // ๋น„์ •์ƒ์ ์œผ๋กœ ๊ทœ์น™์ ์ธ ํŒจํ„ด ๊ฐ์ง€ (๋ด‡ ์˜์‹ฌ)
        if (avgInterval < 50 && avgInterval > 0) {
            console.warn('Suspicious input pattern detected');
            return true;
        }
        
        return false;
    }
}

// ํด๋ฆญ์žฌํ‚น ๋ฐฉ์ง€
function preventClickjacking() {
    // iframe ๋‚ด์—์„œ ์‹คํ–‰ ์ค‘์ธ์ง€ ํ™•์ธ
    if (window.self !== window.top) {
        // ๋ถ€๋ชจ ํ”„๋ ˆ์ž„๊ณผ ๊ฐ™์€ ๋„๋ฉ”์ธ์ธ์ง€ ํ™•์ธ
        try {
            const parentDomain = window.top.location.hostname;
            const currentDomain = window.location.hostname;
            
            if (parentDomain !== currentDomain) {
                // ๋‹ค๋ฅธ ๋„๋ฉ”์ธ์˜ iframe์— ํฌํ•จ๋จ - ๊ฒฝ๊ณ 
                console.error('Clickjacking attempt detected!');
                document.body.innerHTML = 
                    '<h1>Security Warning: This page cannot be displayed in a frame.</h1>';
            }
        } catch (e) {
            // ํฌ๋กœ์Šค ์˜ค๋ฆฌ์ง„ - ์ ‘๊ทผ ๋ถˆ๊ฐ€
            console.error('Clickjacking attempt detected!');
            document.body.innerHTML = 
                '<h1>Security Warning: This page cannot be displayed in a frame.</h1>';
        }
    }
}

// Content Security Policy ์„ค์ • (์„œ๋ฒ„ ์ธก)
/*
Content-Security-Policy: 
    default-src 'self'; 
    frame-ancestors 'none';
    touch-action 'manipulation';
*/

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const secureInput = new SecureTouchInput(document.getElementById('secure-area'));

// ์ฃผ๊ธฐ์ ์œผ๋กœ ์ด์ƒ ํŒจํ„ด ์ฒดํฌ
setInterval(() => {
    if (secureInput.detectAnomalies()) {
        // ์ด์ƒ ํŒจํ„ด ๊ฐ์ง€ ์‹œ ์กฐ์น˜
        console.warn('Anomaly detected - taking action');
    }
}, 5000);

// ํด๋ฆญ์žฌํ‚น ๋ฐฉ์ง€
preventClickjacking();

๋ณด์•ˆ์€ ์•„๋ฌด๋ฆฌ ๊ฐ•์กฐํ•ด๋„ ์ง€๋‚˜์น˜์ง€ ์•Š์•„! ํŠนํžˆ ๊ธˆ์œต ์•ฑ์ด๋‚˜ ๊ฒฐ์ œ ์‹œ์Šคํ…œ์—์„œ ํ„ฐ์น˜ ์ž…๋ ฅ์„ ๋‹ค๋ฃฐ ๋•Œ๋Š” ์ •๋ง ์กฐ์‹ฌํ•ด์•ผ ํ•ด. ๐Ÿ”’

์ž…๋ ฅ ๊ฒ€์ฆ์€ ๊ธฐ๋ณธ ์ค‘์˜ ๊ธฐ๋ณธ์ด๊ณ , ์ด์ƒ ํŒจํ„ด ๊ฐ์ง€๋กœ ๋ด‡์ด๋‚˜ ์ž๋™ํ™” ๊ณต๊ฒฉ์„ ๋ง‰์„ ์ˆ˜ ์žˆ์–ด. ๊ทธ๋ฆฌ๊ณ  ํด๋ฆญ์žฌํ‚น ๋ฐฉ์ง€๋„ ํ•„์ˆ˜์•ผ! ๐Ÿ›ก๏ธ

๐Ÿ“Š ๋ถ„์„๊ณผ ๋ชจ๋‹ˆํ„ฐ๋ง

์ œ์Šค์ฒ˜ ์ธ์‹์„ ๊ตฌํ˜„ํ–ˆ์œผ๋ฉด, ์‚ฌ์šฉ์ž๋“ค์ด ์‹ค์ œ๋กœ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ๋ถ„์„ํ•˜๋Š” ๊ฒƒ๋„ ์ค‘์š”ํ•ด. ๋ฐ์ดํ„ฐ ๊ธฐ๋ฐ˜์œผ๋กœ UX๋ฅผ ๊ฐœ์„ ํ•  ์ˆ˜ ์žˆ๊ฑฐ๋“ ! ๐Ÿ“ˆ

// ํ„ฐ์น˜ ์ด๋ฒคํŠธ ๋ถ„์„ ์‹œ์Šคํ…œ
class TouchAnalytics {
    constructor(options = {}) {
        this.options = {
            sampleRate: options.sampleRate || 0.1, // 10% ์ƒ˜ํ”Œ๋ง
            endpoint: options.endpoint || '/api/analytics',
            batchSize: options.batchSize || 50,
            ...options
        };
        
        this.events = [];
        this.sessionId = this.generateSessionId();
        
        this.init();
    }
    
    generateSessionId() {
        return Date.now().toString(36) + Math.random().toString(36).substr(2);
    }
    
    init() {
        // ์ƒ˜ํ”Œ๋ง - ๋ชจ๋“  ์‚ฌ์šฉ์ž๋ฅผ ์ถ”์ ํ•˜์ง€ ์•Š์Œ
        if (Math.random() > this.options.sampleRate) {
            return;
        }
        
        this.setupTracking();
        this.setupAutoFlush();
    }
    
    setupTracking() {
        // ์ „์—ญ ํ„ฐ์น˜ ์ด๋ฒคํŠธ ์ถ”์ 
        ['touchstart', 'touchmove', 'touchend'].forEach(eventType => {
            document.addEventListener(eventType, (e) => {
                this.trackEvent(eventType, e);
            }, {passive: true, capture: true});
        });
    }
    
    trackEvent(type, event) {
        const data = {
            sessionId: this.sessionId,
            timestamp: Date.now(),
            type: type,
            touchCount: event.touches ? event.touches.length : 0,
            target: this.getTargetInfo(event.target),
            viewport: {
                width: window.innerWidth,
                height: window.innerHeight
            }
        };
        
        // touchstart/touchend๋งŒ ์ƒ์„ธ ์ •๋ณด ์ˆ˜์ง‘
        if (type !== 'touchmove') {
            data.touches = Array.from(event.touches || event.changedTouches || [])
                .map(touch => ({
                    id: touch.identifier,
                    x: Math.round(touch.clientX),
                    y: Math.round(touch.clientY)
                }));
        }
        
        this.events.push(data);
        
        // ๋ฐฐ์น˜ ํฌ๊ธฐ ๋„๋‹ฌ ์‹œ ์ „์†ก
        if (this.events.length >= this.options.batchSize) {
            this.flush();
        }
    }
    
    getTargetInfo(element) {
        return {
            tag: element.tagName,
            id: element.id || null,
            class: element.className || null,
            // ๊ฐœ์ธ์ •๋ณด๋Š” ์ œ์™ธ
        };
    }
    
    flush() {
        if (this.events.length === 0) return;
        
        const payload = {
            sessionId: this.sessionId,
            userAgent: navigator.userAgent,
            events: this.events,
            metadata: {
                url: window.location.href,
                referrer: document.referrer,
                timestamp: Date.now()
            }
        };
        
        // ๋น„๋™๊ธฐ ์ „์†ก (Beacon API ์‚ฌ์šฉ)
        if (navigator.sendBeacon) {
            navigator.sendBeacon(
                this.options.endpoint,
                JSON.stringify(payload)
            );
        } else {
            // ํด๋ฐฑ: fetch
            fetch(this.options.endpoint, {
                method: 'POST',
                headers: {'Content-Type': 'application/json'},
                body: JSON.stringify(payload),
                keepalive: true
            }).catch(err => console.error('Analytics error:', err));
        }
        
        this.events = [];
    }
    
    setupAutoFlush() {
        // ์ฃผ๊ธฐ์  ์ „์†ก
        setInterval(() => this.flush(), 30000); // 30์ดˆ๋งˆ๋‹ค
        
        // ํŽ˜์ด์ง€ ์ดํƒˆ ์‹œ ์ „์†ก
        window.addEventListener('beforeunload', () => this.flush());
        
        // ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์ „ํ™˜ ์‹œ ์ „์†ก
        document.addEventListener('visibilitychange', () => {
            if (document.hidden) {
                this.flush();
            }
        });
    }
    
    // ์ปค์Šคํ…€ ์ด๋ฒคํŠธ ์ถ”์ 
    trackGesture(gestureName, data) {
        this.events.push({
            sessionId: this.sessionId,
            timestamp: Date.now(),
            type: 'gesture',
            gesture: gestureName,
            data: data
        });
    }
}

// ์ œ์Šค์ฒ˜๋ณ„ ์„ฑ๊ณต๋ฅ  ์ถ”์ 
class GestureSuccessTracker {
    constructor() {
        this.attempts = {};
        this.successes = {};
    }
    
    trackAttempt(gestureName) {
        this.attempts[gestureName] = (this.attempts[gestureName] || 0) + 1;
    }
    
    trackSuccess(gestureName) {
        this.successes[gestureName] = (this.successes[gestureName] || 0) + 1;
    }
    
    getSuccessRate(gestureName) {
        const attempts = this.attempts[gestureName] || 0;
        const successes = this.successes[gestureName] || 0;
        
        return attempts > 0 ? (successes / attempts) * 100 : 0;
    }
    
    getReport() {
        const report = {};
        
        Object.keys(this.attempts).forEach(gesture => {
            report[gesture] = {
                attempts: this.attempts[gesture],
                successes: this.successes[gesture] || 0,
                successRate: this.getSuccessRate(gesture).toFixed(2) + '%'
            };
        });
        
        return report;
    }
}

// ์‚ฌ์šฉ ์˜ˆ์‹œ
const analytics = new TouchAnalytics({
    sampleRate: 0.1,
    endpoint: '/api/touch-analytics'
});

const successTracker = new GestureSuccessTracker();

// ์Šค์™€์ดํ”„ ์ œ์Šค์ฒ˜์— ์ ์šฉ
const swipeArea = document.getElementById('swipe-area');
new SwipeGesture(swipeArea, {
    onSwipe: (data) => {
        // ์„ฑ๊ณต ์ถ”์ 
        successTracker.trackSuccess('swipe');
        
        // ๋ถ„์„ ๋ฐ์ดํ„ฐ ์ „์†ก
        analytics.trackGesture('swipe', {
            direction: data.direction,
            distance: data.distance,
            velocity: data.velocity
        });
    }
});

// ์ฃผ๊ธฐ์ ์œผ๋กœ ๋ฆฌํฌํŠธ ํ™•์ธ
setInterval(() => {
    console.log('Gesture Success Report:', successTracker.getReport());
}, 60000); // 1๋ถ„๋งˆ๋‹ค

๋ถ„์„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ชจ์œผ๋ฉด ์ •๋ง ์œ ์šฉํ•œ ์ธ์‚ฌ์ดํŠธ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์–ด! ๐Ÿ’ก

์˜ˆ๋ฅผ ๋“ค์–ด:
โ€ข ์–ด๋–ค ์ œ์Šค์ฒ˜๊ฐ€ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉ๋˜๋Š”์ง€
โ€ข ์‚ฌ์šฉ์ž๋“ค์ด ์ œ์Šค์ฒ˜๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๋Š”์ง€
โ€ข ์–ด๋–ค ์˜์—ญ์—์„œ ํ„ฐ์น˜๊ฐ€ ๋งŽ์ด ๋ฐœ์ƒํ•˜๋Š”์ง€
โ€ข ํ‰๊ท  ํ„ฐ์น˜ ์ง€์† ์‹œ๊ฐ„์€ ์–ผ๋งˆ์ธ์ง€

์ด๋Ÿฐ ๋ฐ์ดํ„ฐ๋กœ UX๋ฅผ ๊ฐœ์„ ํ•˜๋ฉด ์‚ฌ์šฉ์ž ๋งŒ์กฑ๋„๊ฐ€ ํฌ๊ฒŒ ์˜ฌ๋ผ๊ฐ€! ๐Ÿ“Š

๐ŸŽ“ Pro Tip: ๊ฐœ์ธ์ •๋ณด ๋ณดํ˜ธ๋ฅผ ํ•ญ์ƒ ์—ผ๋‘์— ๋‘ฌ์•ผ ํ•ด! ํ„ฐ์น˜ ์ขŒํ‘œ ๊ฐ™์€ ๋ฏผ๊ฐํ•œ ์ •๋ณด๋Š” ์ต๋ช…ํ™”ํ•˜๊ฑฐ๋‚˜ ์ง‘๊ณ„๋œ ํ˜•ํƒœ๋กœ๋งŒ ์ˆ˜์ง‘ํ•ด์•ผ ํ•ด. GDPR์ด๋‚˜ ๊ฐœ์ธ์ •๋ณด๋ณดํ˜ธ๋ฒ•์„ ์ค€์ˆ˜ํ•˜๋Š” ๊ฒŒ ์ •๋ง ์ค‘์š”ํ•ด! ๐Ÿ”

๐ŸŽ“ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉฐ

์™€! ์—ฌ๊ธฐ๊นŒ์ง€ ์˜ค๋А๋ผ ์ˆ˜๊ณ ํ–ˆ์–ด! ๐ŸŽ‰

๋ชจ๋ฐ”์ผ ํ„ฐ์น˜ ์ด๋ฒคํŠธ์™€ ์ œ์Šค์ฒ˜ ์ธ์‹์€ ์ฒ˜์Œ์—” ๋ณต์žกํ•ด ๋ณด์ด์ง€๋งŒ, ๊ธฐ๋ณธ ์›๋ฆฌ๋ฅผ ์ดํ•ดํ•˜๋ฉด ์ƒ๊ฐ๋ณด๋‹ค ์–ด๋ ต์ง€ ์•Š์•„. ํ•ต์‹ฌ์€ ์ด๊ฑฐ์•ผ:

1. ํ„ฐ์น˜ ์ด๋ฒคํŠธ์˜ ๊ธฐ๋ณธ
touchstart, touchmove, touchend, touchcancel - ์ด ๋„ค ๊ฐ€์ง€๋งŒ ์ œ๋Œ€๋กœ ์ดํ•ดํ•˜๋ฉด ๋ผ.

2. TouchEvent ๊ฐ์ฒด ํ™œ์šฉ
touches, targetTouches, changedTouches์˜ ์ฐจ์ด๋ฅผ ์•Œ๊ณ  ์ ์ ˆํžˆ ์‚ฌ์šฉํ•˜๊ธฐ.

3. ์ œ์Šค์ฒ˜ ์ธ์‹ ๋กœ์ง
๊ฑฐ๋ฆฌ, ์‹œ๊ฐ„, ์†๋„, ๊ฐ๋„๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ์‚ฌ์šฉ์ž์˜ ์˜๋„๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ.

4. ์„ฑ๋Šฅ ์ตœ์ ํ™”
์“ฐ๋กœํ‹€๋ง, RAF, transform ํ™œ์šฉ์œผ๋กœ ๋ถ€๋“œ๋Ÿฌ์šด ๊ฒฝํ—˜ ์ œ๊ณตํ•˜๊ธฐ.

5. ํฌ๋กœ์Šค ๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ
Pointer Events๋ฅผ ์šฐ์„ ํ•˜๊ณ , ํด๋ฐฑ ์ฒ˜๋ฆฌํ•˜๊ธฐ.

6. ๋ณด์•ˆ๊ณผ ๋ถ„์„
์ž…๋ ฅ ๊ฒ€์ฆ๊ณผ ์‚ฌ์šฉ์ž ํ–‰๋™ ๋ถ„์„์œผ๋กœ ์•ˆ์ „ํ•˜๊ณ  ๊ฐœ์„ ๋œ ์„œ๋น„์Šค ๋งŒ๋“ค๊ธฐ.

์ด์ œ ๋„ˆ๋„ ๋ฉ‹์ง„ ํ„ฐ์น˜ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์–ด! ์žฌ๋Šฅ๋„ท ๊ฐ™์€ ํ”Œ๋žซํผ์—์„œ ์ด๋Ÿฐ ์Šคํ‚ฌ์„ ํ™œ์šฉํ•˜๋ฉด ์ •๋ง ๋งŽ์€ ๊ธฐํšŒ๊ฐ€ ์žˆ์„ ๊ฑฐ์•ผ. ๋ชจ๋ฐ”์ผ ์›น ๊ฐœ๋ฐœ์€ ๊ณ„์† ์„ฑ์žฅํ•˜๋Š” ๋ถ„์•ผ๋‹ˆ๊นŒ! ๐Ÿš€

์ฒ˜์Œ์—” ์ž‘์€ ๊ฒƒ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด. ๊ฐ„๋‹จํ•œ ํƒญ ์ œ์Šค์ฒ˜๋ถ€ํ„ฐ ๋งŒ๋“ค์–ด๋ณด๊ณ , ์ ์  ๋ณต์žกํ•œ ์ œ์Šค์ฒ˜๋กœ ํ™•์žฅํ•ด ๋‚˜๊ฐ€๋ฉด ๋ผ. ์‹ค์ œ ๋””๋ฐ”์ด์Šค์—์„œ ๋งŽ์ด ํ…Œ์ŠคํŠธํ•ด๋ณด๊ณ , ์‚ฌ์šฉ์ž ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์œผ๋ฉด์„œ ๊ฐœ์„ ํ•ด ๋‚˜๊ฐ€๋Š” ๊ฒŒ ์ค‘์š”ํ•ด! ๐Ÿ’ช

๊ทธ๋ฆฌ๊ณ  ํ•ญ์ƒ ๊ธฐ์–ตํ•ด: ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ์ตœ์šฐ์„ ์ด์•ผ! ๊ธฐ์ˆ ์ ์œผ๋กœ ์™„๋ฒฝํ•ด๋„ ์‚ฌ์šฉํ•˜๊ธฐ ๋ถˆํŽธํ•˜๋ฉด ์˜๋ฏธ๊ฐ€ ์—†์–ด. ์ง๊ด€์ ์ด๊ณ  ์ž์—ฐ์Šค๋Ÿฌ์šด ์ œ์Šค์ฒ˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒŒ ๋ชฉํ‘œ์•ผ. โœจ

ํ™”์ดํŒ…! ๋ฉ‹์ง„ ๋ชจ๋ฐ”์ผ ์›น ์•ฑ์„ ๋งŒ๋“ค์–ด๋ด! ๐ŸŽŠ

๐Ÿ“š ์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด, ์žฌ๋Šฅ๋„ท์—์„œ ๋” ๋งŽ์€ ์ง€์‹์„ ๋‚˜๋ˆ ๋ณด์„ธ์š”!
ํ•จ๊ป˜ ์„ฑ์žฅํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์ปค๋ฎค๋‹ˆํ‹ฐ ๐Ÿ’œ

๋Œ“๊ธ€ ์ž‘์„ฑ

์ด ๊ธ€์— ๋Œ€ํ•œ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ƒ๊ฐ์„ ๋“ค๋ ค์ฃผ์„ธ์š”

๋Œ“๊ธ€ 0
๋Œ“๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ค‘์ž…๋‹ˆ๋‹ค.

์•„์ง ๋Œ“๊ธ€์ด ์—†์Šต๋‹ˆ๋‹ค.