85 lines
2.3 KiB
TypeScript
85 lines
2.3 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import { ref, computed } from "vue";
|
|
import { invoke } from "@tauri-apps/api/core";
|
|
|
|
export interface ImageItem {
|
|
path: string;
|
|
thumbnail: string; // Now mandatory from backend
|
|
name: string;
|
|
width?: number;
|
|
height?: number;
|
|
zcaSuggestion?: { x: number; y: number; zone: string };
|
|
manualPosition?: { x: number; y: number };
|
|
}
|
|
|
|
export interface WatermarkSettings {
|
|
type: 'text';
|
|
text: string;
|
|
color: string;
|
|
opacity: number;
|
|
scale: number;
|
|
// Global override removed/deprecated in logic, but kept in type if needed for other things?
|
|
// Let's keep it clean: no global override flag anymore for logic.
|
|
// But backend struct expects it. We can just ignore it or send dummy.
|
|
}
|
|
|
|
export const useGalleryStore = defineStore("gallery", () => {
|
|
const images = ref<ImageItem[]>([]);
|
|
const selectedIndex = ref<number>(-1);
|
|
const watermarkSettings = ref<WatermarkSettings>({
|
|
type: 'text',
|
|
text: 'Watermark',
|
|
color: '#FFFFFF',
|
|
opacity: 1.0,
|
|
scale: 0.03,
|
|
});
|
|
|
|
const selectedImage = computed(() => {
|
|
if (selectedIndex.value >= 0 && selectedIndex.value < images.value.length) {
|
|
return images.value[selectedIndex.value];
|
|
}
|
|
return null;
|
|
});
|
|
|
|
function setImages(newImages: ImageItem[]) {
|
|
images.value = newImages;
|
|
selectedIndex.value = -1;
|
|
}
|
|
|
|
function updateWatermarkSettings(settings: Partial<WatermarkSettings>) {
|
|
watermarkSettings.value = { ...watermarkSettings.value, ...settings };
|
|
}
|
|
|
|
function setImageManualPosition(index: number, x: number, y: number) {
|
|
if (images.value[index]) {
|
|
images.value[index].manualPosition = { x, y };
|
|
}
|
|
}
|
|
|
|
async function selectImage(index: number) {
|
|
if (index < 0 || index >= images.value.length) return;
|
|
selectedIndex.value = index;
|
|
|
|
const img = images.value[index];
|
|
if (!img.zcaSuggestion) {
|
|
try {
|
|
const suggestion = await invoke<{x: number, y: number, zone: string}>("get_zca_suggestion", { path: img.path });
|
|
img.zcaSuggestion = suggestion;
|
|
} catch (e) {
|
|
console.error("ZCA failed", e);
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
images,
|
|
selectedIndex,
|
|
selectedImage,
|
|
watermarkSettings,
|
|
setImages,
|
|
selectImage,
|
|
updateWatermarkSettings,
|
|
setImageManualPosition
|
|
};
|
|
});
|