From 329b4638c32677ce9851de8dcf21cb8dfac1dc33 Mon Sep 17 00:00:00 2001 From: qiqi Date: Tue, 17 Nov 2026 17:21:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(annotate):=20=E4=B8=A2=20mouseup=20?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E6=84=88=E6=94=B6=E7=AC=94=20+=20=E5=A4=B1?= =?UTF-8?q?=E7=84=A6/=E6=8C=87=E9=92=88=E5=8F=96=E6=B6=88=E5=A4=8D?= =?UTF-8?q?=E4=BD=8D=E4=BA=A4=E4=BA=92=E7=8A=B6=E6=80=81=EF=BC=88=E4=BF=AE?= =?UTF-8?q?=E3=80=8C=E7=94=BB=E4=B8=80=E6=AC=A1=E5=90=8E=E7=94=BB=E5=B8=83?= =?UTF-8?q?=E4=B8=8D=E5=93=8D=E5=BA=94=E3=80=8D=EF=BC=89v1.20.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- image-annotate/package.json | 2 +- image-annotate/plugin/editor/events.js | 28 +++++++++++++++++++++ image-annotate/src/index.js | 35 +++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/image-annotate/package.json b/image-annotate/package.json index df71ddd..d99d1b2 100644 --- a/image-annotate/package.json +++ b/image-annotate/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/image-annotate", "private": true, - "version": "1.20.1", + "version": "1.20.2", "description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)", "ibwPlugin": { "id": "image-annotate", diff --git a/image-annotate/plugin/editor/events.js b/image-annotate/plugin/editor/events.js index ff662ec..8f944a9 100644 --- a/image-annotate/plugin/editor/events.js +++ b/image-annotate/plugin/editor/events.js @@ -357,6 +357,12 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' function onMouseMove(e) { // 记下修饰键:拖动按 Alt 时临时关掉吸附(想停在「差一点点」的位置时用) S._altDown = !!e.altKey + // 自愈:拖出窗口/切换应用会丢 mouseup,isDrawing 会永远为 true,后续操作被忽略 + if (S.isDrawing && e.buttons === 0) { + S.isDrawing = false + const up = Object.prototype.hasOwnProperty.call(DRAW_UP_HANDLERS, S.tool) ? DRAW_UP_HANDLERS[S.tool] : null + try { if (up) up(getPos(e)) } catch (err) { /* 收笔失败不影响后续 */ } + } // 图片放置拖拽 if (S.placingImage && S.placingHandle && S.placingStart) { onPlacementDragMove(e); return @@ -2640,6 +2646,25 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' } /** 将 canvas 鼠标事件绑定到活跃图层 canvas(在 setupCanvas 后调用,仅绑定一次) */ + // 交互状态复位:窗口失焦 / 指针取消 / 切标签页时兜底 + function resetPointerState() { + S.isDrawing = false + S.marquee = null + S.lassoPts = null + S.textDrag = null + S.bitmapDrag = null + S.shapeDrag = null + S.penDragPt = -1 + S.penDragPending = null + S.placingHandle = null + S.panning = false + S.interaction = 'idle' + if (S.strokeCanvas) S.strokeCanvas.style.display = 'none' + document.body.style.cursor = '' + document.body.style.userSelect = '' + try { renderObjects() } catch (e) { /* ignore */ } + } + export function bindCanvasEvents() { if (S._canvasEventsBound) return S._canvasEventsBound = true @@ -2649,6 +2674,9 @@ import { hexToRgb, parseRatio, rgbToHex } from '../vendor/image-math.js' S.canvasStack.addEventListener('mousemove', onMouseMove) S.canvasStack.addEventListener('mousemove', onCanvasHover) window.addEventListener('mouseup', onMouseUp) + window.addEventListener('blur', resetPointerState) + document.addEventListener('pointercancel', resetPointerState) + document.addEventListener('visibilitychange', () => { if (document.hidden) resetPointerState() }) S.canvasStack.addEventListener('contextmenu', (e) => { e.preventDefault() if (S.open && !S.placingImage) showSelectionContext(e) diff --git a/image-annotate/src/index.js b/image-annotate/src/index.js index 4deea93..c8e5d3b 100644 --- a/image-annotate/src/index.js +++ b/image-annotate/src/index.js @@ -9,7 +9,7 @@ var __IWB_ANNOTATE_MANIFEST__ = { id: 'image-annotate', name: '标注 / 修图', - version: '1.20.1', + version: '1.20.2', apiVersion: 1, capabilities: ['commands', 'nodeActions', 'canvas', 'canvasWrite'], settings: { @@ -4847,6 +4847,14 @@ var __IWB_ANNOTATE_MANIFEST__ = { }; function onMouseMove(e) { S._altDown = !!e.altKey; + if (S.isDrawing && e.buttons === 0) { + S.isDrawing = false; + const up = Object.prototype.hasOwnProperty.call(DRAW_UP_HANDLERS, S.tool) ? DRAW_UP_HANDLERS[S.tool] : null; + try { + if (up) up(getPos(e)); + } catch (err) { + } + } if (S.placingImage && S.placingHandle && S.placingStart) { onPlacementDragMove(e); return; @@ -6875,6 +6883,26 @@ var __IWB_ANNOTATE_MANIFEST__ = { renderLayerPanel(); finishCreateTool("shape", shape.id); } + function resetPointerState() { + S.isDrawing = false; + S.marquee = null; + S.lassoPts = null; + S.textDrag = null; + S.bitmapDrag = null; + S.shapeDrag = null; + S.penDragPt = -1; + S.penDragPending = null; + S.placingHandle = null; + S.panning = false; + S.interaction = "idle"; + if (S.strokeCanvas) S.strokeCanvas.style.display = "none"; + document.body.style.cursor = ""; + document.body.style.userSelect = ""; + try { + renderObjects(); + } catch (e) { + } + } function bindCanvasEvents() { if (S._canvasEventsBound) return; S._canvasEventsBound = true; @@ -6882,6 +6910,11 @@ var __IWB_ANNOTATE_MANIFEST__ = { S.canvasStack.addEventListener("mousemove", onMouseMove); S.canvasStack.addEventListener("mousemove", onCanvasHover); window.addEventListener("mouseup", onMouseUp); + window.addEventListener("blur", resetPointerState); + document.addEventListener("pointercancel", resetPointerState); + document.addEventListener("visibilitychange", () => { + if (document.hidden) resetPointerState(); + }); S.canvasStack.addEventListener("contextmenu", (e) => { e.preventDefault(); if (S.open && !S.placingImage) showSelectionContext(e);