mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 18:52:19 +00:00
Add workaround for Firefox pointer events (#412)
* Add workaround for Firefox pointer events Co-Authored-By: catboxanon <122327233+catboxanon@users.noreply.github.com> * nit --------- Co-authored-by: catboxanon <122327233+catboxanon@users.noreply.github.com> Co-authored-by: huchenlei <huchenlei@proton.me>
This commit is contained in:
@@ -28,8 +28,7 @@ import type {
|
|||||||
CanvasMouseEvent,
|
CanvasMouseEvent,
|
||||||
CanvasEventDetail,
|
CanvasEventDetail,
|
||||||
CanvasPointerEvent,
|
CanvasPointerEvent,
|
||||||
ICanvasPosition,
|
CanvasPointerExtensions,
|
||||||
IDeltaPosition,
|
|
||||||
} from "./types/events"
|
} from "./types/events"
|
||||||
import type { ClipboardItems } from "./types/serialisation"
|
import type { ClipboardItems } from "./types/serialisation"
|
||||||
import { LLink, type LinkId } from "./LLink"
|
import { LLink, type LinkId } from "./LLink"
|
||||||
@@ -4122,7 +4121,7 @@ export class LGraphCanvas {
|
|||||||
* adds some useful properties to a mouse event, like the position in graph coordinates
|
* adds some useful properties to a mouse event, like the position in graph coordinates
|
||||||
*/
|
*/
|
||||||
adjustMouseEvent<T extends MouseEvent>(
|
adjustMouseEvent<T extends MouseEvent>(
|
||||||
e: T & Partial<ICanvasPosition & IDeltaPosition>,
|
e: T & Partial<CanvasPointerExtensions>,
|
||||||
): asserts e is T & CanvasMouseEvent {
|
): asserts e is T & CanvasMouseEvent {
|
||||||
let clientX_rel = e.clientX
|
let clientX_rel = e.clientX
|
||||||
let clientY_rel = e.clientY
|
let clientY_rel = e.clientY
|
||||||
@@ -4133,6 +4132,9 @@ export class LGraphCanvas {
|
|||||||
clientY_rel -= b.top
|
clientY_rel -= b.top
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.safeOffsetX = clientX_rel
|
||||||
|
e.safeOffsetY = clientY_rel
|
||||||
|
|
||||||
// TODO: Find a less brittle way to do this
|
// TODO: Find a less brittle way to do this
|
||||||
|
|
||||||
// Only set deltaX and deltaY if not already set.
|
// Only set deltaX and deltaY if not already set.
|
||||||
@@ -4447,9 +4449,9 @@ export class LGraphCanvas {
|
|||||||
const ratio = window.devicePixelRatio
|
const ratio = window.devicePixelRatio
|
||||||
ctx.setTransform(ratio, 0, 0, ratio, 0, 0)
|
ctx.setTransform(ratio, 0, 0, ratio, 0, 0)
|
||||||
|
|
||||||
const x = eDown.offsetX
|
const x = eDown.safeOffsetX
|
||||||
const y = eDown.offsetY
|
const y = eDown.safeOffsetX
|
||||||
ctx.strokeRect(x, y, eMove.offsetX - x, eMove.offsetY - y)
|
ctx.strokeRect(x, y, eMove.safeOffsetX - x, eMove.safeOffsetX - y)
|
||||||
|
|
||||||
ctx.setTransform(transform)
|
ctx.setTransform(transform)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import type { ConnectingLink, LinkReleaseContextExtended } from "../litegraph"
|
|||||||
import type { IWidget } from "./widgets"
|
import type { IWidget } from "./widgets"
|
||||||
import type { LGraphNode } from "../LGraphNode"
|
import type { LGraphNode } from "../LGraphNode"
|
||||||
import type { LGraphGroup } from "../LGraphGroup"
|
import type { LGraphGroup } from "../LGraphGroup"
|
||||||
|
import type { LGraphCanvas } from "../LGraphCanvas"
|
||||||
|
|
||||||
/** For Canvas*Event - adds graph space co-ordinates (property names are shipped) */
|
/** For Canvas*Event - adds graph space co-ordinates (property names are shipped) */
|
||||||
export interface ICanvasPosition {
|
export interface ICanvasPosition {
|
||||||
@@ -21,6 +22,20 @@ export interface IDeltaPosition {
|
|||||||
deltaY: number
|
deltaY: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Workaround for Firefox returning 0 on offsetX/Y props
|
||||||
|
* See https://github.com/Comfy-Org/litegraph.js/issues/403 for details
|
||||||
|
*/
|
||||||
|
export interface IOffsetWorkaround {
|
||||||
|
/** See {@link MouseEvent.offsetX}. This workaround is required (2024-12-31) to support Firefox, which always returns 0 */
|
||||||
|
safeOffsetX: number
|
||||||
|
/** See {@link MouseEvent.offsetY}. This workaround is required (2024-12-31) to support Firefox, which always returns 0 */
|
||||||
|
safeOffsetY: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/** All properties added when converting a pointer event to a CanvasPointerEvent (via {@link LGraphCanvas.adjustMouseEvent}). */
|
||||||
|
export type CanvasPointerExtensions = ICanvasPosition & IDeltaPosition & IOffsetWorkaround
|
||||||
|
|
||||||
interface LegacyMouseEvent {
|
interface LegacyMouseEvent {
|
||||||
/** @deprecated Part of DragAndScale mouse API - incomplete / not maintained */
|
/** @deprecated Part of DragAndScale mouse API - incomplete / not maintained */
|
||||||
dragging?: boolean
|
dragging?: boolean
|
||||||
@@ -33,15 +48,13 @@ export interface CanvasPointerEvent extends PointerEvent, CanvasMouseEvent {}
|
|||||||
/** MouseEvent with canvasX/Y and deltaX/Y properties */
|
/** MouseEvent with canvasX/Y and deltaX/Y properties */
|
||||||
export interface CanvasMouseEvent extends
|
export interface CanvasMouseEvent extends
|
||||||
MouseEvent,
|
MouseEvent,
|
||||||
Readonly<ICanvasPosition>,
|
Readonly<CanvasPointerExtensions>,
|
||||||
Readonly<IDeltaPosition>,
|
|
||||||
LegacyMouseEvent {}
|
LegacyMouseEvent {}
|
||||||
|
|
||||||
/** DragEvent with canvasX/Y and deltaX/Y properties */
|
/** DragEvent with canvasX/Y and deltaX/Y properties */
|
||||||
export interface CanvasDragEvent extends
|
export interface CanvasDragEvent extends
|
||||||
DragEvent,
|
DragEvent,
|
||||||
ICanvasPosition,
|
CanvasPointerExtensions {}
|
||||||
IDeltaPosition {}
|
|
||||||
|
|
||||||
export type CanvasEventDetail =
|
export type CanvasEventDetail =
|
||||||
| GenericEventDetail
|
| GenericEventDetail
|
||||||
|
|||||||
Reference in New Issue
Block a user