From aa2ff7d4bc7dd47324a8afdf41086bbe022740d9 Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Mon, 27 Apr 2026 11:08:36 +0900 Subject: [PATCH] =?UTF-8?q?fix(study):=20HandwriteCanvas=20=EC=A0=84?= =?UTF-8?q?=EB=A9=B4=20=EC=9E=AC=EC=9E=91=EC=84=B1=20=E2=80=94=20Apple=20P?= =?UTF-8?q?encil=20=EC=9E=85=EB=A0=A5=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=ED=86=B5=ED=95=A9=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 문제: 점선 stroke / 연속 입력 누락 / 버튼 focus zoom / Safari 선택 팝업. 원인을 4축으로 분리해서 한꺼번에 fix. [1] 입력 수집 (PointerEvent 상태머신) - isDrawing flag + activePointerId 매칭으로 stroke 누락 방지 - pointerdown: 이전 inflight 가 살아있으면 finalize 후 새 stroke 시작 - setPointerCapture (try-catch) — element 외 pointer move 도 받음 - pointerup / pointercancel / pointerleave 통합 endStroke - pointerType === 'pen' (mouse 도 데스크톱) 만, 손가락 거부 [2] coalesced events - pointermove 의 e.getCoalescedEvents() 모두 points 에 push - 빠른 필기에서 sparse point → 점선 현상 방지 핵심 - normalizePressure: 0/비정상 값은 0.5 fallback [3] 렌더링: perfect-freehand polygon fill - getStroke(thinning:0.4, smoothing:0.62, streamline:0.5, last:true) - getSvgPathFromStroke (perfect-freehand README 표준 builder) → Path2D → ctx.fill() — anti-aliased polygon - 1점 케이스: arc fill 폴백 - last: true 항상 (진행 중에도 polygon 닫힘) [4] autosave 입력 분리 - 3초 idle debounce - flushSave 는 setTimeout 0 으로 다음 macrotask - PATCH 응답이 strokes 를 덮어쓰지 않음 (응답 무시, fire-and-forget) [5] Safari/Chrome hardening - 캔버스/컨테이너: touch-action: none + user-select: none + -webkit-touch-callout: none + -webkit-tap-highlight-color: transparent - canvas 에 oncontextmenu / onselectstart preventDefault - 모든 toolbar 버튼: clickThenBlur(fn) + tabindex=-1 + BTN_STYLE → button focus zoom 차단 (사용자 보고 "버튼 누르면 화면 확대" 핵심) [6] resize 정책 - ResizeObserver + window resize/orientationchange 만 트리거 - pointermove 마다 resize 절대 안 함 - DPR 반영 + setTransform(dpr,...) 으로 retina 선명 수정 범위 (사용자 명시): HandwriteCanvas.svelte 만. 다른 영역 무수정. --- .../src/lib/components/HandwriteCanvas.svelte | 307 +++++++----------- 1 file changed, 125 insertions(+), 182 deletions(-) diff --git a/frontend/src/lib/components/HandwriteCanvas.svelte b/frontend/src/lib/components/HandwriteCanvas.svelte index 79fb139..6fbc92e 100644 --- a/frontend/src/lib/components/HandwriteCanvas.svelte +++ b/frontend/src/lib/components/HandwriteCanvas.svelte @@ -1,47 +1,37 @@
- -
- + +
- +
{ if (inflight && e.pointerId === activePointerId) endStroke(e); }} + onpointerleave={endStroke} oncontextmenu={(e) => e.preventDefault()} + onselectstart={(e) => e.preventDefault()} class="block" style="touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; cursor: {tool === 'eraser' ? 'cell' : 'crosshair'};" >