diff --git a/src/app.d.ts b/src/app.d.ts index da08e6d..1975813 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,13 +1,11 @@ -// See https://svelte.dev/docs/kit/types#app.d.ts -// for information about these interfaces declare global { - namespace App { - // interface Error {} - // interface Locals {} - // interface PageData {} - // interface PageState {} - // interface Platform {} - } + namespace App { + // interface Error {} + // interface Locals {} + // interface PageData {} + // interface PageState {} + // interface Platform {} + } } export {}; diff --git a/src/components/image/ImageCropper.svelte b/src/components/image/ImageCropper.svelte index 9a7d13b..35bffe7 100644 --- a/src/components/image/ImageCropper.svelte +++ b/src/components/image/ImageCropper.svelte @@ -28,7 +28,6 @@ }); function initializeCropper() { - // Remove verbose debug logging if (!imageElement || !CropperJS) { return; } @@ -52,7 +51,6 @@ throw new Error("Не удалось получить обрезанное изображение"); } - // Используем метод $toCanvas для получения HTMLCanvasElement const canvas = await cropperCanvasElement.$toCanvas({ width: 320, }); @@ -61,10 +59,8 @@ throw new Error("Не удалось получить canvas"); } - // Теперь canvas - это обычный HTMLCanvasElement const croppedImage = canvas.toDataURL("image/png"); - // Validate cropped image const cropResult: ImageCropResult = { success: true, croppedImage, @@ -171,7 +167,6 @@ background-color: #007bff; } - /* Базовые стили для cropperjs */ :global(.cropper-container) { direction: ltr; font-size: 0; diff --git a/src/components/panel/PanelList.svelte b/src/components/panel/PanelList.svelte index f76638e..265adf4 100644 --- a/src/components/panel/PanelList.svelte +++ b/src/components/panel/PanelList.svelte @@ -24,7 +24,6 @@ errorMessage = undefined; panels = panelStorage.getAllPanels(); - // Если есть текущая панель в store, отмечаем её как выбранную const currentPanel = $panelStore; if (currentPanel) { selectedPanelId = currentPanel.id; @@ -47,12 +46,10 @@ if (result.success) { panels = panels.filter((p) => p.id !== panelId); - // Если удалили выбранную панель, сбрасываем выбор if (selectedPanelId === panelId) { selectedPanelId = undefined; } - // Уведомляем родительский компонент onPanelDelete(panelId); } else { errorMessage = result.error || "Ошибка удаления панели"; diff --git a/src/components/panel/PanelPreview.svelte b/src/components/panel/PanelPreview.svelte index acc4eaa..ab09683 100644 --- a/src/components/panel/PanelPreview.svelte +++ b/src/components/panel/PanelPreview.svelte @@ -16,10 +16,8 @@ let konvaStage: KonvaStage | null = $state(null); let stageComponent: any = $state(null); - // Get the Konva stage after component mounts $effect(() => { if (stageComponent) { - // According to svelte-konva docs, access the node property to get the underlying Konva Stage konvaStage = stageComponent.node; } }); @@ -35,7 +33,6 @@ }); function loadImage(src: string) { - // Remove verbose logging - image data is too large for console const img = document.createElement("img"); img.onload = () => { backgroundImage = img; @@ -47,50 +44,30 @@ } function handleDownload() { - console.log("[PanelPreview] handleDownload called"); - console.log("[PanelPreview] onDownload exists:", onDownload ? true : false); - console.log("[PanelPreview] konvaStage exists:", konvaStage ? true : false); - console.log("[PanelPreview] konvaStage value:", konvaStage); - console.log("[PanelPreview] stageComponent exists:", stageComponent ? true : false); - - // Try different approaches to get the Konva stage for download let stageToUse = konvaStage; if (!stageToUse && stageComponent) { - console.log("[PanelPreview] konvaStage is null, trying to get stage from stageComponent"); - - // Try different properties that might contain the Konva stage stageToUse = stageComponent.node || stageComponent.stage || stageComponent._stage || stageComponent; - // Check if this is actually a valid Konva stage if (stageToUse && typeof stageToUse.toBlob === "function") { - console.log("[PanelPreview] Found valid Konva stage in stageComponent"); } else { - console.log("[PanelPreview] stageComponent itself might be the Konva stage"); - // Maybe stageComponent IS the Konva stage - check if it has toBlob if (typeof stageComponent.toBlob === "function") { stageToUse = stageComponent; - console.log("[PanelPreview] ✅ stageComponent IS the Konva stage"); - } else { - console.log("[PanelPreview] ❌ Could not find valid Konva stage"); } } } if (onDownload && stageToUse) { - console.log("[PanelPreview] Calling onDownload with panel and stage"); onDownload(panel, stageToUse); - } else { - console.error("[PanelPreview] Cannot download - onDownload or valid stage is missing"); } } function getTextPosition(textItem: TextItem) { const panelWidth = 320; - const paddingX = textItem.paddingX || 20; // Default padding + const paddingX = textItem.paddingX || 20; const verticalOffset = textItem.verticalOffset || 0; const centerY = panel.height / 2 + verticalOffset; - const textWidth = 300; // Width of the text area + const textWidth = 300; let position; switch (textItem.textAlign) { @@ -98,12 +75,10 @@ position = { x: paddingX, y: centerY }; break; case "right": - // For right alignment, position the right edge of text at panel edge minus padding position = { x: panelWidth - textWidth - paddingX, y: centerY }; break; case "center": default: - // For center alignment, center the text area within the panel position = { x: (panelWidth - textWidth) / 2, y: centerY }; break; } @@ -118,18 +93,15 @@
Настройки применятся ко всем создаваемым панелям
diff --git a/src/components/text/TextPreview.svelte b/src/components/text/TextPreview.svelte index e03b1e5..3a4c0a9 100644 --- a/src/components/text/TextPreview.svelte +++ b/src/components/text/TextPreview.svelte @@ -27,7 +27,6 @@ img.src = src; } - // Вычисляем позицию текста на основе выравнивания и отступов function getTextPosition() { const panelWidth = 320; const paddingX = textItem.paddingX || 0; diff --git a/src/lib/utils/imageValidator.ts b/src/lib/utils/imageValidator.ts index 7619e50..91cfeab 100644 --- a/src/lib/utils/imageValidator.ts +++ b/src/lib/utils/imageValidator.ts @@ -1,6 +1,6 @@ import { ImageError } from "../types/errors"; -export const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB +export const MAX_FILE_SIZE = 10 * 1024 * 1024; export const SUPPORTED_FORMATS = ["image/jpeg", "image/jpg", "image/png", "image/webp", "image/gif"]; export type ValidationResult = diff --git a/src/lib/utils/panelStorage.ts b/src/lib/utils/panelStorage.ts index dee0198..b841b68 100644 --- a/src/lib/utils/panelStorage.ts +++ b/src/lib/utils/panelStorage.ts @@ -1,9 +1,8 @@ import type { Panel } from "../types/panel"; -import { ImageError } from "../types/errors"; import { handleError, logError } from "./errorHandler"; const STORAGE_KEY = "twitch-panels"; -const MAX_PANELS = 50; // Максимальное количество сохраненных панелей +const MAX_PANELS = 50; export interface StorageResult { success: boolean; @@ -11,24 +10,17 @@ export interface StorageResult { } export class PanelStorage { - /** - * Сохраняет панель в localStorage - */ savePanel(panel: Panel): StorageResult { try { const panels = this.getAllPanels(); - // Проверяем, существует ли панель с таким ID const existingIndex = panels.findIndex((p) => p.id === panel.id); if (existingIndex >= 0) { - // Обновляем существующую панель panels[existingIndex] = panel; } else { - // Добавляем новую панель в начало списка panels.unshift(panel); - // Проверяем лимит количества панелей if (panels.length > MAX_PANELS) { panels.length = MAX_PANELS; } @@ -48,9 +40,6 @@ export class PanelStorage { } } - /** - * Загружает все панели из localStorage - */ getAllPanels(): Panel[] { try { const data = localStorage.getItem(STORAGE_KEY); @@ -60,7 +49,6 @@ export class PanelStorage { const panels: Panel[] = JSON.parse(data); - // Валидация загруженных панелей return panels.filter((panel) => this.validatePanel(panel)); } catch (error) { logError(error, "Failed to load panels"); @@ -68,9 +56,6 @@ export class PanelStorage { } } - /** - * Загружает панель по ID - */ getPanelById(id: string): Panel | undefined { try { const panels = this.getAllPanels(); @@ -81,9 +66,6 @@ export class PanelStorage { } } - /** - * Удаляет панель по ID - */ deletePanel(id: string): StorageResult { try { const panels = this.getAllPanels(); @@ -103,9 +85,6 @@ export class PanelStorage { } } - /** - * Очищает все сохраненные панели - */ clearAll(): StorageResult { try { localStorage.removeItem(STORAGE_KEY); @@ -122,9 +101,6 @@ export class PanelStorage { } } - /** - * Валидирует панель - */ private validatePanel(panel: any): panel is Panel { return ( typeof panel === "object" && @@ -139,16 +115,10 @@ export class PanelStorage { ); } - /** - * Получает количество сохраненных панелей - */ getPanelCount(): number { return this.getAllPanels().length; } - /** - * Проверяет, есть ли место для новой панели - */ hasSpaceForNewPanel(): boolean { return this.getPanelCount() < MAX_PANELS; } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index fcf1f18..ebfb687 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -14,26 +14,20 @@ let texts = $state