mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-21 15:24:09 +00:00
## Summary
This PR refactors the mask editor from a vanilla JavaScript
implementation to Vue 3 + Composition API, aligning it with the ComfyUI
frontend's modern architecture. This is a structural refactor without UI
changes - all visual appearances and user interactions remain identical.
Net change: +1,700 lines (mostly tests)
## Changes
- Converted from class-based managers to Vue 3 Composition API
- Migrated state management to Pinia stores (maskEditorStore,
maskEditorDataStore)
- Split monolithic managers into focused composables:
- useBrushDrawing - Brush rendering and drawing logic
- useCanvasManager - Canvas lifecycle and operations
- useCanvasTools - Tool-specific canvas operations
- usePanAndZoom - Pan and zoom functionality
- useToolManager - Tool selection and coordination
- useKeyboard - Keyboard shortcuts
- useMaskEditorLoader/Saver - Data loading and saving
- useCoordinateTransform - Coordinate system transformations
- Replaced imperative DOM manipulation with Vue components
- Added comprehensive test coverage
## What This PR Does NOT Change
Preserved Original Styling:
- Original CSS retained in packages/design-system/src/css/style.css
- Some generic controls (DropdownControl, SliderControl, ToggleControl)
preserved as-is
- Future migration to Tailwind and PrimeVue components is planned but
out of scope for this PR
Preserved Core Functionality:
- Drawing algorithms and brush rendering logic remain unchanged
- Pan/zoom calculations preserved
- Canvas operations (composite modes, image processing) unchanged
- Tool behaviors (brush, color select, paint bucket) identical
- No changes to mask generation or export logic
DO NOT Review:
- CSS styling choices (preserved from original)
- Drawing algorithm implementations (unchanged)
- Canvas rendering logic (ported as-is)
- UI/UX changes (none exist)
- Component library choices (future work)
┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-6629-fully-refactor-mask-editor-into-vue-based-2a46d73d36508114ab8bd2984b4b54e4)
by [Unito](https://www.unito.io)
96 lines
2.3 KiB
Vue
96 lines
2.3 KiB
Vue
<template>
|
|
<div
|
|
ref="pointerZoneRef"
|
|
class="w-[calc(100%-4rem-220px)] h-full"
|
|
@pointerdown="handlePointerDown"
|
|
@pointermove="handlePointerMove"
|
|
@pointerup="handlePointerUp"
|
|
@pointerleave="handlePointerLeave"
|
|
@pointerenter="handlePointerEnter"
|
|
@touchstart="handleTouchStart"
|
|
@touchmove="handleTouchMove"
|
|
@touchend="handleTouchEnd"
|
|
@wheel="handleWheel"
|
|
@contextmenu.prevent
|
|
/>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { onMounted, ref, watch } from 'vue'
|
|
|
|
import type { usePanAndZoom } from '@/composables/maskeditor/usePanAndZoom'
|
|
import type { useToolManager } from '@/composables/maskeditor/useToolManager'
|
|
import { useMaskEditorStore } from '@/stores/maskEditorStore'
|
|
|
|
const { toolManager, panZoom } = defineProps<{
|
|
toolManager: ReturnType<typeof useToolManager>
|
|
panZoom: ReturnType<typeof usePanAndZoom>
|
|
}>()
|
|
|
|
const store = useMaskEditorStore()
|
|
const pointerZoneRef = ref<HTMLDivElement>()
|
|
|
|
onMounted(() => {
|
|
if (!pointerZoneRef.value) {
|
|
console.error('[PointerZone] Pointer zone ref not initialized')
|
|
return
|
|
}
|
|
|
|
store.pointerZone = pointerZoneRef.value
|
|
})
|
|
|
|
watch(
|
|
() => store.isPanning,
|
|
(isPanning) => {
|
|
if (!pointerZoneRef.value) return
|
|
|
|
if (isPanning) {
|
|
pointerZoneRef.value.style.cursor = 'grabbing'
|
|
} else {
|
|
toolManager.updateCursor()
|
|
}
|
|
}
|
|
)
|
|
|
|
const handlePointerDown = async (event: PointerEvent) => {
|
|
await toolManager.handlePointerDown(event)
|
|
}
|
|
|
|
const handlePointerMove = async (event: PointerEvent) => {
|
|
await toolManager.handlePointerMove(event)
|
|
}
|
|
|
|
const handlePointerUp = (event: PointerEvent) => {
|
|
void toolManager.handlePointerUp(event)
|
|
}
|
|
|
|
const handlePointerLeave = () => {
|
|
store.brushVisible = false
|
|
if (pointerZoneRef.value) {
|
|
pointerZoneRef.value.style.cursor = ''
|
|
}
|
|
}
|
|
|
|
const handlePointerEnter = () => {
|
|
toolManager.updateCursor()
|
|
}
|
|
|
|
const handleTouchStart = (event: TouchEvent) => {
|
|
panZoom.handleTouchStart(event)
|
|
}
|
|
|
|
const handleTouchMove = async (event: TouchEvent) => {
|
|
await panZoom.handleTouchMove(event)
|
|
}
|
|
|
|
const handleTouchEnd = (event: TouchEvent) => {
|
|
panZoom.handleTouchEnd(event)
|
|
}
|
|
|
|
const handleWheel = async (event: WheelEvent) => {
|
|
await panZoom.zoom(event)
|
|
const newCursorPoint = { x: event.clientX, y: event.clientY }
|
|
panZoom.updateCursorPosition(newCursorPoint)
|
|
}
|
|
</script>
|