- oraEditor function now defined in <head> before x-data directive - Added <body> tag with x-data attribute - Added canvas click handler using () to access Alpine instance - Added id to imageContainer for canvas interaction - All tests passing (16/16)
695 lines
29 KiB
HTML
695 lines
29 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>ORA Editor</title>
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
|
<style>
|
|
::-webkit-scrollbar { width: 8px; height: 8px; }
|
|
::-webkit-scrollbar-track { background: #374151; }
|
|
::-webkit-scrollbar-thumb { background: #6B7280; border-radius: 4px; }
|
|
.polygon-point { position: absolute; width: 8px; height: 8px; background: #0F0; border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }
|
|
</style>
|
|
|
|
<!-- Alpine data component - MUST be defined before x-data directive -->
|
|
<script>
|
|
function oraEditor() {
|
|
return {
|
|
// File state
|
|
filePath: '',
|
|
oraPath: '',
|
|
layers: [],
|
|
|
|
// Image dimensions
|
|
imageWidth: 800,
|
|
imageHeight: 600,
|
|
|
|
// Selection state
|
|
selectedLayer: null,
|
|
|
|
// Polygon state
|
|
isDrawing: false,
|
|
polygonPoints: [],
|
|
polygonColor: '#FF0000',
|
|
polygonWidth: 2,
|
|
polygonPreviewUrl: null,
|
|
|
|
// Mask extraction state
|
|
maskSubject: '',
|
|
usePolygonHint: true,
|
|
isExtracting: false,
|
|
showMaskModal: false,
|
|
tempMaskPath: null,
|
|
tempMaskUrl: null,
|
|
lastError: '',
|
|
|
|
// Settings
|
|
showSettings: false,
|
|
comfyUrl: localStorage.getItem('ora_comfy_url') || '127.0.0.1:8188',
|
|
|
|
// Loading/error state
|
|
isLoading: false,
|
|
error: '',
|
|
|
|
init() {
|
|
console.log('ORA Editor initialized');
|
|
this.setupKeyHandlers();
|
|
},
|
|
|
|
setupKeyHandlers() {
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape' && this.isDrawing) this.clearPolygon();
|
|
if (e.key === 'Enter' && this.isDrawing && this.polygonPoints.length >= 3) this.finishDrawing();
|
|
});
|
|
},
|
|
|
|
async openFile() {
|
|
if (!this.filePath || this.isLoading) return;
|
|
|
|
this.isLoading = true;
|
|
this.error = '';
|
|
|
|
try {
|
|
const response = await fetch('/api/open', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ path: this.filePath })
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!data.success) throw new Error(data.error || 'Failed to open file');
|
|
|
|
this.oraPath = data.ora_path;
|
|
this.layers = data.layers;
|
|
this.imageWidth = data.width;
|
|
this.imageHeight = data.height;
|
|
this.clearPolygon();
|
|
} catch (e) {
|
|
this.error = e.message;
|
|
} finally {
|
|
this.isLoading = false;
|
|
}
|
|
},
|
|
|
|
async saveCurrent() {
|
|
if (!this.oraPath) return;
|
|
|
|
await fetch('/api/save', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ ora_path: this.oraPath })
|
|
});
|
|
},
|
|
|
|
async toggleVisibility(layerName, visible) {
|
|
const layer = this.layers.find(l => l.name === layerName);
|
|
if (layer) layer.visible = visible;
|
|
|
|
await fetch('/api/layer/visibility', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ora_path: this.oraPath,
|
|
layer_name: layerName,
|
|
visible: visible
|
|
})
|
|
});
|
|
},
|
|
|
|
async renameLayer() {
|
|
const oldName = this.selectedLayer;
|
|
const newName = prompt('New layer name:', this.selectedLayer);
|
|
if (!newName || newName === oldName) return;
|
|
|
|
const layer = this.layers.find(l => l.name === oldName);
|
|
if (layer) layer.name = newName;
|
|
this.selectedLayer = newName;
|
|
|
|
await fetch('/api/layer/rename', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ora_path: this.oraPath,
|
|
old_name: oldName,
|
|
new_name: newName
|
|
})
|
|
});
|
|
},
|
|
|
|
async deleteLayer() {
|
|
const layerToDelete = this.selectedLayer;
|
|
if (!confirm(`Delete layer "${layerToDelete}"?`)) return;
|
|
|
|
const idx = this.layers.findIndex(l => l.name === layerToDelete);
|
|
if (idx > -1) this.layers.splice(idx, 1);
|
|
this.selectedLayer = null;
|
|
|
|
await fetch('/api/layer/delete', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ora_path: this.oraPath,
|
|
layer_name: layerToDelete
|
|
})
|
|
});
|
|
},
|
|
|
|
async reorderLayer(direction) {
|
|
if (!this.selectedLayer) return;
|
|
|
|
const idx = this.layers.findIndex(l => l.name === this.selectedLayer);
|
|
if (idx < 0) return;
|
|
|
|
const newIdx = direction === 'up' ? idx - 1 : idx + 1;
|
|
if (newIdx < 0 || newIdx >= this.layers.length) return;
|
|
|
|
const layerName = this.selectedLayer;
|
|
[this.layers[idx], this.layers[newIdx]] = [this.layers[newIdx], this.layers[idx]];
|
|
|
|
await fetch('/api/layer/reorder', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ora_path: this.oraPath,
|
|
layer_name: layerName,
|
|
direction: direction
|
|
})
|
|
});
|
|
},
|
|
|
|
startDrawing() {
|
|
this.isDrawing = true;
|
|
this.polygonPoints = [];
|
|
|
|
// Setup canvas after it's created
|
|
setTimeout(() => this.setupCanvas(), 50);
|
|
},
|
|
|
|
setupCanvas() {
|
|
const canvas = document.getElementById('polygonCanvas');
|
|
if (!canvas) return;
|
|
|
|
// Match canvas size to image
|
|
canvas.width = this.imageWidth;
|
|
canvas.height = this.imageHeight;
|
|
},
|
|
|
|
addPolygonPoint(x, y) {
|
|
if (!this.isDrawing) return;
|
|
|
|
// Normalize to 0-1 range
|
|
x = Math.max(0, Math.min(1, x));
|
|
y = Math.max(0, Math.min(1, y));
|
|
|
|
this.polygonPoints.push({ x, y });
|
|
this.updatePolygonPreview();
|
|
},
|
|
|
|
async updatePolygonPreview() {
|
|
if (!this.oraPath || this.polygonPoints.length < 3) return;
|
|
|
|
const response = await fetch('/api/polygon', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ora_path: this.oraPath,
|
|
points: this.polygonPoints,
|
|
color: this.polygonColor,
|
|
width: this.polygonWidth
|
|
})
|
|
});
|
|
|
|
if (response.ok) {
|
|
const data = await response.json();
|
|
this.polygonPreviewUrl = data.overlay_url;
|
|
}
|
|
},
|
|
|
|
finishDrawing() {
|
|
this.isDrawing = false;
|
|
if (this.polygonPoints.length >= 3) {
|
|
// Keep polygon visible
|
|
} else {
|
|
this.clearPolygon();
|
|
}
|
|
},
|
|
|
|
clearPolygon() {
|
|
this.isDrawing = false;
|
|
this.polygonPoints = [];
|
|
this.polygonPreviewUrl = null;
|
|
|
|
if (this.oraPath) {
|
|
fetch('/api/polygon/clear', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ ora_path: this.oraPath })
|
|
});
|
|
}
|
|
},
|
|
|
|
async extractMask() {
|
|
if (!this.maskSubject.trim()) return;
|
|
|
|
this.isExtracting = true;
|
|
this.lastError = '';
|
|
|
|
try {
|
|
const response = await fetch('/api/mask/extract', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
subject: this.maskSubject,
|
|
use_polygon: this.usePolygonHint && this.polygonPoints.length >= 3,
|
|
ora_path: this.oraPath,
|
|
comfy_url: this.comfyUrl
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!data.success) throw new Error(data.error || 'Failed to extract mask');
|
|
|
|
this.tempMaskPath = data.mask_path;
|
|
this.tempMaskUrl = data.mask_url || '/api/file/mask?path=' + encodeURIComponent(data.mask_path);
|
|
this.showMaskModal = true;
|
|
} catch (e) {
|
|
this.lastError = e.message;
|
|
} finally {
|
|
this.isExtracting = false;
|
|
}
|
|
},
|
|
|
|
rerollMask() {
|
|
this.extractMask();
|
|
},
|
|
|
|
async useMask() {
|
|
if (!this.tempMaskPath) return;
|
|
|
|
await fetch('/api/layer/add', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ora_path: this.oraPath,
|
|
entity_name: 'mask',
|
|
mask_path: this.tempMaskPath
|
|
})
|
|
});
|
|
|
|
// Refresh layers
|
|
const response = await fetch('/api/layers?ora_path=' + encodeURIComponent(this.oraPath));
|
|
const data = await response.json();
|
|
if (data.success) {
|
|
this.layers = data.layers;
|
|
}
|
|
|
|
this.closeMaskModal();
|
|
},
|
|
|
|
closeMaskModal() {
|
|
this.showMaskModal = false;
|
|
this.tempMaskPath = null;
|
|
this.tempMaskUrl = null;
|
|
},
|
|
|
|
async openInKrita() {
|
|
if (!this.selectedLayer) {
|
|
alert('Select a layer first');
|
|
return;
|
|
}
|
|
|
|
const response = await fetch('/api/krita/open', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
ora_path: this.oraPath,
|
|
layer_name: this.selectedLayer
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
if (data.success) {
|
|
window.open(data.file_url);
|
|
}
|
|
},
|
|
|
|
saveSettings() {
|
|
localStorage.setItem('ora_comfy_url', this.comfyUrl);
|
|
this.showSettings = false;
|
|
}
|
|
};
|
|
}
|
|
</script>
|
|
</head>
|
|
<body class="bg-gray-900 text-white">
|
|
<div x-data="oraEditor()" x-init="init()" class="min-h-screen p-4">
|
|
<!-- Header -->
|
|
<header class="mb-4 flex items-center gap-4">
|
|
<div class="flex-1 flex items-center gap-2">
|
|
<input
|
|
type="text"
|
|
x-model="filePath"
|
|
placeholder="Path (e.g., scenes/kq4_010/pic.png)"
|
|
class="flex-1 bg-gray-700 border border-gray-600 rounded px-3 py-2 text-white focus:border-blue-500 outline-none"
|
|
@keydown.enter="openFile()"
|
|
>
|
|
<button
|
|
@click="openFile()"
|
|
:disabled="!filePath || isLoading"
|
|
class="bg-blue-600 hover:bg-blue-700 disabled:bg-gray-600 px-4 py-2 rounded transition"
|
|
>Open</button>
|
|
</div>
|
|
<button
|
|
@click="openInKrita()"
|
|
:disabled="!oraPath || isExtracting"
|
|
class="bg-purple-600 hover:bg-purple-700 disabled:bg-gray-600 px-4 py-2 rounded flex items-center gap-2"
|
|
>
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"/>
|
|
</svg>
|
|
Open in Krita
|
|
</button>
|
|
<button
|
|
@click="saveCurrent()"
|
|
:disabled="!oraPath || isLoading"
|
|
class="bg-green-600 hover:bg-green-700 disabled:bg-gray-600 px-4 py-2 rounded transition"
|
|
>Save</button>
|
|
<button
|
|
@click="showSettings = true"
|
|
class="bg-gray-700 hover:bg-gray-600 px-4 py-2 rounded transition"
|
|
>⚙️</button>
|
|
</header>
|
|
|
|
<!-- Main content (hidden until file loaded) -->
|
|
<template x-if="oraPath">
|
|
<div class="flex gap-4">
|
|
|
|
<!-- Sidebar -->
|
|
<aside class="w-72 flex-shrink-0 space-y-4">
|
|
|
|
<!-- Layers panel -->
|
|
<div class="bg-gray-800 rounded-lg p-4 border border-gray-700">
|
|
<h3 class="font-bold mb-3 text-gray-300">Layers</h3>
|
|
|
|
<div class="space-y-2 max-h-64 overflow-y-auto">
|
|
<template x-for="layer in layers" :key="layer.name">
|
|
<div
|
|
@click="selectedLayer = layer.name"
|
|
class="flex items-center gap-2 bg-gray-700 hover:bg-gray-650 rounded px-2 py-1 transition cursor-pointer"
|
|
:class="{ 'bg-gray-600': selectedLayer === layer.name }"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
:checked="layer.visible"
|
|
@change="toggleVisibility(layer.name, $event.target.checked)"
|
|
class="w-4 h-4 rounded"
|
|
>
|
|
<span class="flex-1 text-sm truncate" x-text="layer.name"></span>
|
|
</div>
|
|
</template>
|
|
</div>
|
|
|
|
<!-- Layer controls -->
|
|
<div x-show="selectedLayer" class="mt-3 pt-3 border-t border-gray-600 space-y-2">
|
|
<div class="grid grid-cols-2 gap-2">
|
|
<button @click="renameLayer()" class="bg-gray-600 hover:bg-gray-500 px-2 py-1 rounded text-sm">Rename</button>
|
|
<button @click="deleteLayer()" class="bg-red-600 hover:bg-red-700 px-2 py-1 rounded text-sm">Delete</button>
|
|
</div>
|
|
<div class="grid grid-cols-2 gap-2">
|
|
<button @click="reorderLayer('up')" :disabled="isLoading" class="bg-gray-600 hover:bg-gray-500 disabled:bg-gray-700 px-2 py-1 rounded text-sm">▲ Up</button>
|
|
<button @click="reorderLayer('down')" :disabled="isLoading" class="bg-gray-600 hover:bg-gray-500 disabled:bg-gray-700 px-2 py-1 rounded text-sm">▼ Down</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Polygon tool -->
|
|
<div class="bg-gray-800 rounded-lg p-4 border border-gray-700">
|
|
<h3 class="font-bold mb-3 text-gray-300">Polygon</h3>
|
|
|
|
<div class="space-y-3">
|
|
<label class="block text-xs text-gray-400 mb-1">Color: <input type="color" x-model="polygonColor" class="h-8 w-full rounded cursor-pointer"></label>
|
|
<label class="block text-xs text-gray-400 mb-1">Width: <input type="number" x-model.number="polygonWidth" min="1" max="10" class="w-full bg-gray-700 border border-gray-600 rounded px-2 py-1"></label>
|
|
|
|
<div class="flex gap-2">
|
|
<button @click="startDrawing()" :disabled="!oraPath || isDrawing || isLoading" class="flex-1 bg-blue-600 hover:bg-blue-700 disabled:bg-gray-600 px-3 py-1.5 rounded text-sm transition">Start Drawing</button>
|
|
<button @click="finishDrawing()" :disabled="!isDrawing || polygonPoints.length < 3" class="bg-green-600 hover:bg-green-700 disabled:bg-gray-600 px-3 py-1.5 rounded text-sm transition">Done</button>
|
|
</div>
|
|
|
|
<div x-show="polygonPoints.length > 0">
|
|
<span class="text-xs text-gray-400">Points: </span><span x-text="polygonPoints.length"></span>
|
|
</div>
|
|
|
|
<button @click="clearPolygon()" :disabled="!isDrawing && polygonPoints.length === 0" class="w-full bg-gray-600 hover:bg-gray-500 disabled:bg-gray-700 px-3 py-1.5 rounded text-sm transition">Clear</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Mask extraction -->
|
|
<div class="bg-gray-800 rounded-lg p-4 border border-gray-700">
|
|
<h3 class="font-bold mb-3 text-gray-300">Mask Extraction</h3>
|
|
|
|
<div class="space-y-3">
|
|
<input
|
|
type="text"
|
|
x-model="maskSubject"
|
|
placeholder="e.g., 'the door'"
|
|
:disabled="isExtracting || !oraPath"
|
|
class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2 text-white focus:border-blue-500 outline-none disabled:bg-gray-800"
|
|
>
|
|
|
|
<label class="flex items-center gap-2 cursor-pointer">
|
|
<input
|
|
type="checkbox"
|
|
x-model="usePolygonHint"
|
|
:disabled="isExtracting || !oraPath"
|
|
class="w-4 h-4 rounded"
|
|
>
|
|
<span class="text-sm">Use polygon hint</span>
|
|
</label>
|
|
|
|
<button
|
|
@click="extractMask()"
|
|
:disabled="!maskSubject.trim() || isExtracting || !oraPath"
|
|
class="w-full bg-indigo-600 hover:bg-indigo-700 disabled:bg-gray-600 px-4 py-2 rounded transition"
|
|
>
|
|
<span x-show="!isExtracting">Extract Mask</span>
|
|
<span x-show="isExtracting">Extracting...</span>
|
|
</button>
|
|
|
|
<div x-show="lastError" class="text-red-400 text-xs" x-text="lastError"></div>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- Main canvas area -->
|
|
<main class="flex-1 bg-gray-800 rounded-lg border border-gray-700 p-4 relative overflow-auto" style="min-height: 600px;">
|
|
|
|
<div id="imageContainer" x-show="!isLoading && !error && layers.length > 0" class="relative inline-block"
|
|
:style="`width: ${imageWidth}px; height: ${imageHeight}px; position: relative;`">
|
|
|
|
<!-- Layer display -->
|
|
<div class="relative w-full h-full">
|
|
<!-- Base image -->
|
|
<img
|
|
:src="'/api/image/base?ora_path=' + encodeURIComponent(oraPath)"
|
|
class="absolute inset-0 w-full h-full object-contain"
|
|
@load="initCanvas"
|
|
id="baseImage"
|
|
>
|
|
|
|
<!-- Polygon points markers when drawing -->
|
|
<template x-for="(point, idx) in polygonPoints" :key="idx">
|
|
<div class="polygon-point"
|
|
:style="`left: ${point.x * 100}%; top: ${point.y * 100}%`">
|
|
</div>
|
|
</template>
|
|
|
|
<!-- Polygon overlay when viewing or after drawing -->
|
|
<img
|
|
x-show="!isDrawing && polygonPreviewUrl"
|
|
:src="polygonPreviewUrl"
|
|
class="absolute inset-0 w-full h-full object-contain pointer-events-none"
|
|
alt="Polygon overlay"
|
|
>
|
|
|
|
<!-- Drawing canvas (only visible when drawing) -->
|
|
<canvas
|
|
id="polygonCanvas"
|
|
x-show="isDrawing"
|
|
:width="imageWidth"
|
|
:height="imageHeight"
|
|
class="absolute inset-0 cursor-crosshair pointer-events-auto border-2 border-dashed border-blue-500 opacity-90"
|
|
@click="handleCanvasClick"
|
|
@dblclick="handleCanvasDoubleClick"
|
|
></canvas>
|
|
|
|
</div>
|
|
|
|
<!-- Loading indicator -->
|
|
<div x-show="isLoading && !error" class="flex items-center justify-center h-full">
|
|
<div class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-blue-500"></div>
|
|
</div>
|
|
|
|
<!-- Error message -->
|
|
<div x-show="error" class="text-red-400 text-center mt-8" x-text="error"></div>
|
|
|
|
<!-- Drawing hint -->
|
|
<div x-show="isDrawing" class="mt-2 text-sm text-gray-400">
|
|
Click on image to add points. Double-click or Enter/Escape when done.
|
|
</div>
|
|
</main>
|
|
</div>
|
|
</template>
|
|
|
|
<!-- No file loaded message -->
|
|
<div x-show="!oraPath && !isLoading && !error" class="text-gray-400 text-center mt-20">
|
|
<p class="text-xl">Open a PNG or ORA file to start editing</p>
|
|
</div>
|
|
|
|
<!-- Mask preview modal -->
|
|
<div x-show="showMaskModal" @keydown.escape.window="closeMaskModal()"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-75">
|
|
<div class="bg-gray-800 rounded-lg p-6 max-w-2xl w-full mx-4 border border-gray-600" style="max-height: 90vh; display: flex; flex-direction: column;">
|
|
<h2 class="text-xl font-bold mb-4">Extracted Mask</h2>
|
|
|
|
<div class="flex-1 overflow-auto bg-gray-700 rounded mb-4 relative" :style="`min-height: 300px; max-height: 50vh;`">
|
|
<!-- Base image -->
|
|
<img :src="'/api/image/base?ora_path=' + encodeURIComponent(oraPath)" class="relative w-full h-auto object-contain">
|
|
|
|
<!-- Mask overlay with tint -->
|
|
<div x-show="tempMaskUrl" class="absolute inset-0 bg-green-500 opacity-30 pointer-events-none">
|
|
<img :src="tempMaskUrl" class="w-full h-auto object-contain mix-blend-screen">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex gap-4 justify-end">
|
|
<button @click="rerollMask()" :disabled="isExtracting" class="bg-gray-600 hover:bg-gray-500 disabled:bg-gray-700 px-4 py-2 rounded transition">Re-roll</button>
|
|
<button @click="useMask()" :disabled="isExtracting || !tempMaskPath" class="bg-green-600 hover:bg-green-700 disabled:bg-gray-600 px-4 py-2 rounded transition">Use This Mask</button>
|
|
<button @click="closeMaskModal()" :disabled="isExtracting" class="bg-red-600 hover:bg-red-700 disabled:bg-gray-600 px-4 py-2 rounded transition">Cancel</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Settings modal -->
|
|
<div x-show="showSettings" @keydown.escape.window="showSettings = false"
|
|
class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-75">
|
|
<div class="bg-gray-800 rounded-lg p-6 max-w-md w-full mx-4 border border-gray-600">
|
|
<h2 class="text-xl font-bold mb-4">Settings</h2>
|
|
|
|
<div class="mb-4">
|
|
<label class="block text-sm text-gray-300 mb-2">ComfyUI Server URL</label>
|
|
<input
|
|
type="text"
|
|
x-model="comfyUrl"
|
|
placeholder="127.0.0.1:8188"
|
|
class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2 text-white focus:outline-none focus:border-blue-500"
|
|
>
|
|
</div>
|
|
|
|
<div class="flex gap-4 justify-end mt-4">
|
|
<button @click="showSettings = false" class="bg-gray-600 hover:bg-gray-500 px-4 py-2 rounded transition">Cancel</button>
|
|
<button @click="saveSettings()" class="bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded transition">Save</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- Minimal JS for canvas polygon drawing -->
|
|
<script>
|
|
function initCanvas() {
|
|
const canvas = document.getElementById('polygonCanvas');
|
|
if (!canvas) return;
|
|
|
|
// Set canvas to proper size
|
|
canvas.style.width = canvas.parentElement.offsetWidth + 'px';
|
|
canvas.style.height = canvas.parentElement.offsetHeight + 'px';
|
|
}
|
|
|
|
// Access Alpine store for canvas click
|
|
function handleCanvasClick(e) {
|
|
const container = e.target.closest('[x-data]');
|
|
if (!container) return;
|
|
|
|
// Get click position
|
|
const rect = container.getBoundingClientRect();
|
|
let x = (e.clientX - rect.left) / rect.width;
|
|
let y = (e.clientY - rect.top) / rect.height;
|
|
|
|
// Normalize to 0-1 range
|
|
x = Math.max(0, Math.min(1, x));
|
|
y = Math.max(0, Math.min(1, y));
|
|
|
|
// Get Alpine component and add point
|
|
const alpineComponent = $data(container);
|
|
if (alpineComponent) {
|
|
alpineComponent.addPolygonPoint(x, y);
|
|
}
|
|
}
|
|
|
|
function handleCanvasDoubleClick(e) {
|
|
e.preventDefault();
|
|
const alpineComponent = $data(e.target.closest('[x-data]'));
|
|
if (alpineComponent) {
|
|
alpineComponent.finishDrawing();
|
|
}
|
|
}
|
|
|
|
<!-- Canvas click handler - works with Alpine -->
|
|
<script>
|
|
function handleCanvasClick(e) {
|
|
const container = e.target.closest('#imageContainer');
|
|
if (!container) return;
|
|
|
|
const rect = container.getBoundingClientRect();
|
|
let x = (e.clientX - rect.left) / rect.width;
|
|
let y = (e.clientY - rect.top) / rect.height;
|
|
|
|
// Normalize to 0-1 range
|
|
x = Math.max(0, Math.min(1, x));
|
|
y = Math.max(0, Math.min(1, y));
|
|
|
|
// Get Alpine component from container
|
|
const alpineEl = container.closest('[x-data]');
|
|
if (!alpineEl) return;
|
|
|
|
// Get the Alpine component instance using $data
|
|
const store = $data(alpineEl);
|
|
if (!store) return;
|
|
|
|
store.addPolygonPoint(x, y);
|
|
}
|
|
|
|
function handleCanvasDoubleClick(e) {
|
|
e.preventDefault();
|
|
const container = e.target.closest('#imageContainer');
|
|
if (!container) return;
|
|
|
|
const alpineEl = container.closest('[x-data]');
|
|
if (!alpineEl) return;
|
|
|
|
const store = $data(alpineEl);
|
|
if (!store) return;
|
|
|
|
if (store.isDrawing && store.polygonPoints.length >= 3) {
|
|
store.finishDrawing();
|
|
}
|
|
}
|
|
|
|
// Wait for Alpine to initialize, then setup canvas
|
|
document.addEventListener('alpine:init', () => {
|
|
setTimeout(() => {
|
|
const canvas = document.getElementById('polygonCanvas');
|
|
if (canvas) {
|
|
canvas.addEventListener('click', handleCanvasClick);
|
|
canvas.addEventListener('dblclick', handleCanvasDoubleClick);
|
|
}
|
|
}, 200);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|