feat: move to new workflow
This commit is contained in:
@@ -1,24 +1,47 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { panelStore } from "../stores/panelStore";
|
|
||||||
import { uiStore, setCurrentStep } from "../stores/uiStore";
|
import { uiStore, setCurrentStep } from "../stores/uiStore";
|
||||||
import type { TextItem } from "../lib/types/panel";
|
import type { Panel } from "../lib/types/panel";
|
||||||
import { Stage, Layer, Image, Text } from "svelte-konva";
|
import { Stage, Layer, Image, Text } from "svelte-konva";
|
||||||
import { Button } from "../lib/components/ui";
|
import { Button, IconButton } from "../lib/components/ui";
|
||||||
|
|
||||||
let {
|
let {
|
||||||
|
panel,
|
||||||
onDownload,
|
onDownload,
|
||||||
|
onUpdate,
|
||||||
|
onDelete,
|
||||||
}: {
|
}: {
|
||||||
|
panel: Panel;
|
||||||
onDownload?: () => void;
|
onDownload?: () => void;
|
||||||
|
onUpdate?: (text: string) => void;
|
||||||
|
onDelete?: () => void;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
|
let backgroundImage: HTMLImageElement | undefined = $state(undefined);
|
||||||
|
let editingText = $state(false);
|
||||||
|
let editText = $state("");
|
||||||
|
|
||||||
function handleUploadNewImage() {
|
function handleUploadNewImage() {
|
||||||
setCurrentStep("upload");
|
setCurrentStep("upload");
|
||||||
}
|
}
|
||||||
|
|
||||||
let backgroundImage: HTMLImageElement | undefined = $state(undefined);
|
function handleEdit() {
|
||||||
|
editText = panel.texts[0]?.text || "";
|
||||||
|
editingText = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSaveEdit() {
|
||||||
|
if (onUpdate && editText.trim()) {
|
||||||
|
onUpdate(editText.trim());
|
||||||
|
}
|
||||||
|
editingText = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCancelEdit() {
|
||||||
|
editingText = false;
|
||||||
|
editText = "";
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const panel = $panelStore;
|
|
||||||
if (panel?.backgroundImage && panel.backgroundImage !== backgroundImage?.src) {
|
if (panel?.backgroundImage && panel.backgroundImage !== backgroundImage?.src) {
|
||||||
loadImage(panel.backgroundImage);
|
loadImage(panel.backgroundImage);
|
||||||
}
|
}
|
||||||
@@ -39,8 +62,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTextPosition(textItem: TextItem) {
|
function getTextPosition(textItem: TextItem) {
|
||||||
const panel = $panelStore;
|
|
||||||
if (!panel) return { x: 0, y: 0 };
|
|
||||||
const panelWidth = 320;
|
const panelWidth = 320;
|
||||||
const paddingX = textItem.paddingX || 0;
|
const paddingX = textItem.paddingX || 0;
|
||||||
const verticalOffset = textItem.verticalOffset || 0;
|
const verticalOffset = textItem.verticalOffset || 0;
|
||||||
@@ -59,20 +80,38 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="panel-preview">
|
<div class="panel-preview">
|
||||||
{#if $panelStore}
|
|
||||||
<div class="preview-header">
|
<div class="preview-header">
|
||||||
<Button variant="primary" onclick={handleDownload}>Скачать панель</Button>
|
{#if editingText}
|
||||||
<Button variant="secondary" onclick={handleUploadNewImage}>Загрузить</Button>
|
<div class="edit-controls">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
bind:value={editText}
|
||||||
|
class="edit-input"
|
||||||
|
onkeypress={(e) => e.key === "Enter" && handleSaveEdit()}
|
||||||
|
/>
|
||||||
|
<Button variant="primary" size="sm" onclick={handleSaveEdit}>✓</Button>
|
||||||
|
<Button variant="secondary" size="sm" onclick={handleCancelEdit}>✕</Button>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="panel-title">{panel.texts[0]?.text || "Без названия"}</div>
|
||||||
|
<div class="panel-actions">
|
||||||
|
<IconButton variant="secondary" onclick={handleEdit} ariaLabel="Редактировать">✎</IconButton>
|
||||||
|
<Button variant="primary" size="sm" onclick={onDownload}>Скачать</Button>
|
||||||
|
{#if onDelete}
|
||||||
|
<IconButton variant="danger" onclick={onDelete} ariaLabel="Удалить">🗑</IconButton>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="preview-sections">
|
<div class="preview-sections">
|
||||||
<!-- Превью чистой картинки -->
|
<!-- Превью чистой картинки -->
|
||||||
<div class="preview-section">
|
<div class="preview-section">
|
||||||
<h3>Фон</h3>
|
<h3>Фон</h3>
|
||||||
<div class="canvas-container">
|
<div class="canvas-container">
|
||||||
<Stage width={320} height={$panelStore.height}>
|
<Stage width={320} height={panel.height}>
|
||||||
<Layer>
|
<Layer>
|
||||||
{#if backgroundImage}
|
{#if backgroundImage}
|
||||||
<Image image={backgroundImage} width={320} height={$panelStore.height} />
|
<Image image={backgroundImage} width={320} height={panel.height} />
|
||||||
{/if}
|
{/if}
|
||||||
</Layer>
|
</Layer>
|
||||||
</Stage>
|
</Stage>
|
||||||
@@ -83,15 +122,15 @@
|
|||||||
<div class="preview-section">
|
<div class="preview-section">
|
||||||
<h3>Финальный результат</h3>
|
<h3>Финальный результат</h3>
|
||||||
<div class="canvas-container">
|
<div class="canvas-container">
|
||||||
<Stage width={320} height={$panelStore.height}>
|
<Stage width={320} height={panel.height}>
|
||||||
<Layer>
|
<Layer>
|
||||||
{#if backgroundImage}
|
{#if backgroundImage}
|
||||||
<Image image={backgroundImage} width={320} height={$panelStore.height} />
|
<Image image={backgroundImage} width={320} height={panel.height} />
|
||||||
{/if}
|
{/if}
|
||||||
{#each $panelStore.texts || [] as textItem (textItem.id)}
|
{#each panel.texts || [] as textItem (textItem.id)}
|
||||||
{@const textPosition = getTextPosition(textItem)}
|
{@const textPosition = getTextPosition(textItem)}
|
||||||
<Text
|
<Text
|
||||||
text={textItem.text}
|
text={editingText ? editText : textItem.text}
|
||||||
fontSize={textItem.fontSize}
|
fontSize={textItem.fontSize}
|
||||||
fill={textItem.color}
|
fill={textItem.color}
|
||||||
fontFamily={textItem.fontFamily}
|
fontFamily={textItem.fontFamily}
|
||||||
@@ -106,11 +145,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
|
||||||
<div class="empty-state">
|
|
||||||
<p>Нет данных для предпросмотра</p>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -123,11 +157,45 @@
|
|||||||
|
|
||||||
.preview-header {
|
.preview-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
background: #f8f9fa;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-title {
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-controls {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-input {
|
||||||
|
flex: 1;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.edit-input:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: #007bff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-sections {
|
.preview-sections {
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { panelStore, addTextToPanel, updateTextInPanel, removeTextFromPanel } from "../stores/panelStore";
|
import { Button } from "../lib/components/ui";
|
||||||
import type { TextItem } from "../lib/types/panel";
|
|
||||||
import { v4 as uuidv4 } from "uuid";
|
|
||||||
import { Button, IconButton } from "../lib/components/ui";
|
|
||||||
|
|
||||||
let { onTextUpdate }: {
|
let { onTextAdd }: {
|
||||||
onTextUpdate: (texts: TextItem[]) => void;
|
onTextAdd: (text: string) => void;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
let currentPanel = $state($panelStore);
|
|
||||||
let newText = $state("");
|
let newText = $state("");
|
||||||
let errorMessage = $state<string | null>(null);
|
let errorMessage = $state<string | null>(null);
|
||||||
|
|
||||||
// Общие настройки текста для всех текстов
|
// Общие настройки текста для всех панелей
|
||||||
let commonTextSettings = $state({
|
let commonTextSettings = $state({
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontFamily: "Arial",
|
fontFamily: "Arial",
|
||||||
@@ -35,33 +31,7 @@
|
|||||||
"Trebuchet MS",
|
"Trebuchet MS",
|
||||||
];
|
];
|
||||||
|
|
||||||
// Применить общие настройки ко всем текстам
|
|
||||||
function applyCommonSettingsToAll() {
|
|
||||||
if (!currentPanel) return;
|
|
||||||
|
|
||||||
const updatedTexts = currentPanel.texts.map(text => ({
|
|
||||||
...text,
|
|
||||||
fontSize: commonTextSettings.fontSize,
|
|
||||||
fontFamily: commonTextSettings.fontFamily,
|
|
||||||
color: commonTextSettings.color,
|
|
||||||
textAlign: commonTextSettings.textAlign,
|
|
||||||
paddingX: commonTextSettings.paddingX,
|
|
||||||
verticalOffset: commonTextSettings.verticalOffset,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const updatedPanel = updatePanel(currentPanel, { texts: updatedTexts });
|
|
||||||
panelStore.set(updatedPanel);
|
|
||||||
onTextUpdate(updatedTexts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe to panel store
|
|
||||||
$effect(() => {
|
|
||||||
currentPanel = $panelStore;
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleAddText() {
|
function handleAddText() {
|
||||||
if (!currentPanel) return;
|
|
||||||
|
|
||||||
if (!newText.trim()) {
|
if (!newText.trim()) {
|
||||||
errorMessage = "Введите текст";
|
errorMessage = "Введите текст";
|
||||||
return;
|
return;
|
||||||
@@ -74,46 +44,44 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
const updatedPanel = addTextToPanel(currentPanel, newText.trim());
|
onTextAdd(newText.trim());
|
||||||
panelStore.set(updatedPanel);
|
|
||||||
onTextUpdate(updatedPanel.texts);
|
|
||||||
newText = "";
|
newText = "";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
errorMessage = error instanceof Error ? error.message : "Ошибка добавления текста";
|
errorMessage = error instanceof Error ? error.message : "Ошибка добавления текста";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpdateText(textId: string, updates: Partial<TextItem>) {
|
function handleKeyPress(e: KeyboardEvent) {
|
||||||
if (!currentPanel) return;
|
if (e.key === "Enter") {
|
||||||
|
handleAddText();
|
||||||
try {
|
|
||||||
errorMessage = null;
|
|
||||||
const updatedPanel = updateTextInPanel(currentPanel, textId, updates);
|
|
||||||
panelStore.set(updatedPanel);
|
|
||||||
onTextUpdate(updatedPanel.texts);
|
|
||||||
} catch (error) {
|
|
||||||
errorMessage = error instanceof Error ? error.message : "Ошибка обновления текста";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleRemoveText(textId: string) {
|
|
||||||
if (!currentPanel) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
errorMessage = null;
|
|
||||||
const updatedPanel = removeTextFromPanel(currentPanel, textId);
|
|
||||||
panelStore.set(updatedPanel);
|
|
||||||
onTextUpdate(updatedPanel.texts);
|
|
||||||
} catch (error) {
|
|
||||||
errorMessage = error instanceof Error ? error.message : "Ошибка удаления текста";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="text-manager">
|
<div class="text-manager">
|
||||||
|
<div class="add-text-section">
|
||||||
|
<div class="input-group">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
bind:value={newText}
|
||||||
|
placeholder="Введите текст для панели (например: links, about me, projects...)"
|
||||||
|
class="text-input"
|
||||||
|
maxlength="100"
|
||||||
|
onkeypress={handleKeyPress}
|
||||||
|
/>
|
||||||
|
<Button variant="primary" onclick={handleAddText}>Добавить</Button>
|
||||||
|
</div>
|
||||||
|
{#if errorMessage}
|
||||||
|
<div class="error-message">
|
||||||
|
{errorMessage}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Общие настройки текста -->
|
<!-- Общие настройки текста -->
|
||||||
<div class="common-settings-section">
|
<div class="common-settings-section">
|
||||||
<h3>Общие настройки текста</h3>
|
<h3>Общие настройки текста</h3>
|
||||||
|
<p class="settings-note">Настройки применятся ко всем создаваемым панелям</p>
|
||||||
|
|
||||||
<div class="settings-grid">
|
<div class="settings-grid">
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
@@ -127,7 +95,6 @@
|
|||||||
value={commonTextSettings.fontSize}
|
value={commonTextSettings.fontSize}
|
||||||
oninput={(e) => {
|
oninput={(e) => {
|
||||||
commonTextSettings.fontSize = parseInt(e.target.value);
|
commonTextSettings.fontSize = parseInt(e.target.value);
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span class="value-display">{commonTextSettings.fontSize}px</span>
|
<span class="value-display">{commonTextSettings.fontSize}px</span>
|
||||||
@@ -141,7 +108,6 @@
|
|||||||
value={commonTextSettings.fontFamily}
|
value={commonTextSettings.fontFamily}
|
||||||
onchange={(e) => {
|
onchange={(e) => {
|
||||||
commonTextSettings.fontFamily = e.target.value;
|
commonTextSettings.fontFamily = e.target.value;
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{#each availableFonts as font}
|
{#each availableFonts as font}
|
||||||
@@ -159,7 +125,6 @@
|
|||||||
value={commonTextSettings.color}
|
value={commonTextSettings.color}
|
||||||
oninput={(e) => {
|
oninput={(e) => {
|
||||||
commonTextSettings.color = e.target.value;
|
commonTextSettings.color = e.target.value;
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
@@ -169,36 +134,33 @@
|
|||||||
<label>
|
<label>
|
||||||
Выравнивание:
|
Выравнивание:
|
||||||
<div class="alignment-buttons">
|
<div class="alignment-buttons">
|
||||||
<IconButton
|
<button
|
||||||
variant={commonTextSettings.textAlign === 'left' ? 'primary' : 'secondary'}
|
class="align-btn {commonTextSettings.textAlign === 'left' ? 'active' : ''}"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
commonTextSettings.textAlign = 'left';
|
commonTextSettings.textAlign = 'left';
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
ariaLabel="Выровнять по левому краю"
|
aria-label="Выровнять по левому краю"
|
||||||
>
|
>
|
||||||
←
|
←
|
||||||
</IconButton>
|
</button>
|
||||||
<IconButton
|
<button
|
||||||
variant={commonTextSettings.textAlign === 'center' ? 'primary' : 'secondary'}
|
class="align-btn {commonTextSettings.textAlign === 'center' ? 'active' : ''}"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
commonTextSettings.textAlign = 'center';
|
commonTextSettings.textAlign = 'center';
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
ariaLabel="Выровнять по центру"
|
aria-label="Выровнять по центру"
|
||||||
>
|
>
|
||||||
↔
|
↔
|
||||||
</IconButton>
|
</button>
|
||||||
<IconButton
|
<button
|
||||||
variant={commonTextSettings.textAlign === 'right' ? 'primary' : 'secondary'}
|
class="align-btn {commonTextSettings.textAlign === 'right' ? 'active' : ''}"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
commonTextSettings.textAlign = 'right';
|
commonTextSettings.textAlign = 'right';
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
ariaLabel="Выровнять по правому краю"
|
aria-label="Выровнять по правому краю"
|
||||||
>
|
>
|
||||||
→
|
→
|
||||||
</IconButton>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@@ -214,7 +176,6 @@
|
|||||||
value={commonTextSettings.paddingX}
|
value={commonTextSettings.paddingX}
|
||||||
oninput={(e) => {
|
oninput={(e) => {
|
||||||
commonTextSettings.paddingX = parseInt(e.target.value);
|
commonTextSettings.paddingX = parseInt(e.target.value);
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span class="value-display">{commonTextSettings.paddingX}px</span>
|
<span class="value-display">{commonTextSettings.paddingX}px</span>
|
||||||
@@ -232,7 +193,6 @@
|
|||||||
value={commonTextSettings.verticalOffset}
|
value={commonTextSettings.verticalOffset}
|
||||||
oninput={(e) => {
|
oninput={(e) => {
|
||||||
commonTextSettings.verticalOffset = parseInt(e.target.value);
|
commonTextSettings.verticalOffset = parseInt(e.target.value);
|
||||||
applyCommonSettingsToAll();
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<span class="value-display">{commonTextSettings.verticalOffset > 0 ? '+' : ''}{commonTextSettings.verticalOffset}px</span>
|
<span class="value-display">{commonTextSettings.verticalOffset > 0 ? '+' : ''}{commonTextSettings.verticalOffset}px</span>
|
||||||
@@ -241,44 +201,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="add-text-section">
|
|
||||||
<div class="input-group">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
bind:value={newText}
|
|
||||||
placeholder="Введите текст..."
|
|
||||||
class="text-input"
|
|
||||||
maxlength="100"
|
|
||||||
/>
|
|
||||||
<Button variant="primary" onclick={handleAddText}>Добавить</Button>
|
|
||||||
</div>
|
|
||||||
{#if errorMessage}
|
|
||||||
<div class="error-message">
|
|
||||||
{errorMessage}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if currentPanel && currentPanel.texts.length > 0}
|
|
||||||
<div class="text-list">
|
|
||||||
{#each currentPanel.texts as textItem (textItem.id)}
|
|
||||||
<div class="text-item">
|
|
||||||
<span class="text-content">{textItem.text}</span>
|
|
||||||
<IconButton
|
|
||||||
variant="danger"
|
|
||||||
onclick={() => handleRemoveText(textItem.id)}
|
|
||||||
ariaLabel="Удалить текст"
|
|
||||||
>
|
|
||||||
×
|
|
||||||
</IconButton>
|
|
||||||
</div>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="empty-state">
|
|
||||||
<p>Нет добавленного текста</p>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -289,13 +211,6 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.text-manager h2 {
|
|
||||||
margin: 0;
|
|
||||||
color: #333;
|
|
||||||
font-size: 1.5rem;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.common-settings-section {
|
.common-settings-section {
|
||||||
background: #f8f9fa;
|
background: #f8f9fa;
|
||||||
border: 2px solid #e9ecef;
|
border: 2px solid #e9ecef;
|
||||||
@@ -311,6 +226,13 @@
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.settings-note {
|
||||||
|
margin: 0 0 1rem 0;
|
||||||
|
color: #666;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
.settings-grid {
|
.settings-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||||
@@ -319,13 +241,35 @@
|
|||||||
|
|
||||||
.alignment-buttons {
|
.alignment-buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.5rem;
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.align-btn {
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
background: white;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.align-btn:hover {
|
||||||
|
background: #f0f0f0;
|
||||||
|
border-color: #007bff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.align-btn.active {
|
||||||
|
background: #007bff;
|
||||||
|
color: white;
|
||||||
|
border-color: #007bff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.add-text-section {
|
.add-text-section {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-group {
|
.input-group {
|
||||||
|
|||||||
+93
-45
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { panelStore, createEmptyPanel } from "../stores/panelStore";
|
import { createPanelFromText, updatePanelText } from "../stores/panelStore";
|
||||||
import { uiStore, setLoading, setCurrentStep } from "../stores/uiStore";
|
import { uiStore, setLoading, setCurrentStep } from "../stores/uiStore";
|
||||||
|
|
||||||
import { exportService } from "../lib/services/exportService";
|
import { exportService } from "../lib/services/exportService";
|
||||||
@@ -10,11 +10,12 @@
|
|||||||
import ImageCropper from "../components/ImageCropper.svelte";
|
import ImageCropper from "../components/ImageCropper.svelte";
|
||||||
import TextManager from "../components/TextManager.svelte";
|
import TextManager from "../components/TextManager.svelte";
|
||||||
import PanelPreview from "../components/PanelPreview.svelte";
|
import PanelPreview from "../components/PanelPreview.svelte";
|
||||||
|
import { Button } from "../lib/components/ui";
|
||||||
|
|
||||||
let uploadedImage = $state<string | null>(null);
|
let uploadedImage = $state<string | null>(null);
|
||||||
let croppedImage = $state<string | null>(null);
|
let panels = $state<Panel[]>([]);
|
||||||
let currentPanel = $state<Panel | null>(null);
|
|
||||||
let errorMessage = $state<string | null>(null);
|
let errorMessage = $state<string | null>(null);
|
||||||
|
let backgroundImage = $state<string | null>(null);
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
// Загружаем фоновое изображение по умолчанию
|
// Загружаем фоновое изображение по умолчанию
|
||||||
@@ -25,8 +26,7 @@
|
|||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = () => {
|
reader.onload = () => {
|
||||||
const base64 = reader.result as string;
|
backgroundImage = reader.result as string;
|
||||||
initializePanel(base64);
|
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(blob);
|
reader.readAsDataURL(blob);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -35,17 +35,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function initializePanel(backgroundImage: string) {
|
|
||||||
const newPanel = createEmptyPanel();
|
|
||||||
newPanel.backgroundImage = backgroundImage;
|
|
||||||
panelStore.set(newPanel);
|
|
||||||
currentPanel = newPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
$effect(() => {
|
|
||||||
currentPanel = $panelStore;
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleImageUpload(image: string) {
|
function handleImageUpload(image: string) {
|
||||||
uploadedImage = image;
|
uploadedImage = image;
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
@@ -57,19 +46,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleCropComplete(croppedImage: string) {
|
function handleCropComplete(croppedImage: string) {
|
||||||
croppedImage = croppedImage;
|
backgroundImage = croppedImage;
|
||||||
|
// Обновляем все панели с новым фоновым изображением
|
||||||
// Обновляем текущую панель с обрезанным изображением
|
panels = panels.map(panel => ({
|
||||||
if (currentPanel) {
|
...panel,
|
||||||
const updatedPanel = {
|
|
||||||
...currentPanel,
|
|
||||||
backgroundImage: croppedImage,
|
backgroundImage: croppedImage,
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
};
|
}));
|
||||||
panelStore.set(updatedPanel);
|
|
||||||
currentPanel = updatedPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCurrentStep("text");
|
setCurrentStep("text");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,26 +61,26 @@
|
|||||||
setCurrentStep("text");
|
setCurrentStep("text");
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleTextUpdate(texts: Panel["texts"]) {
|
function handleAddText(text: string) {
|
||||||
if (currentPanel) {
|
if (!backgroundImage) return;
|
||||||
const updatedPanel = {
|
const newPanel = createPanelFromText(backgroundImage, text);
|
||||||
...currentPanel,
|
panels = [...panels, newPanel];
|
||||||
texts,
|
|
||||||
updatedAt: new Date(),
|
|
||||||
};
|
|
||||||
panelStore.set(updatedPanel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleDownload() {
|
function handleUpdateText(panelId: string, text: string) {
|
||||||
if (!currentPanel) {
|
panels = panels.map(panel =>
|
||||||
errorMessage = "Нет панели для скачивания";
|
panel.id === panelId ? updatePanelText(panel, text) : panel
|
||||||
return;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleDeletePanel(panelId: string) {
|
||||||
|
panels = panels.filter(panel => panel.id !== panelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleDownload(panel: Panel) {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const result = await exportService.exportPanel(currentPanel);
|
const result = await exportService.exportPanel(panel);
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
errorMessage = result.error || "Ошибка экспорта панели";
|
errorMessage = result.error || "Ошибка экспорта панели";
|
||||||
@@ -109,6 +92,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleDownloadAll() {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
for (const panel of panels) {
|
||||||
|
await exportService.exportPanel(panel);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
errorMessage = error instanceof Error ? error.message : "Ошибка экспорта панелей";
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -131,15 +127,32 @@
|
|||||||
<ImageCropper imageSrc={uploadedImage} onCropComplete={handleCropComplete} onCancel={handleCropCancel} />
|
<ImageCropper imageSrc={uploadedImage} onCropComplete={handleCropComplete} onCancel={handleCropCancel} />
|
||||||
{:else if $uiStore.currentStep === "text"}
|
{:else if $uiStore.currentStep === "text"}
|
||||||
<div class="text-section">
|
<div class="text-section">
|
||||||
<h2>Управление текстом</h2>
|
<h2>Добавьте тексты для панелей</h2>
|
||||||
<TextManager onTextUpdate={handleTextUpdate} />
|
<TextManager onTextAdd={handleAddText} />
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="sidebar">
|
<div class="sidebar">
|
||||||
{#if $uiStore.currentStep === "text"}
|
{#if $uiStore.currentStep === "text" && panels.length > 0}
|
||||||
<PanelPreview onDownload={handleDownload} />
|
<div class="panels-container">
|
||||||
|
<div class="panels-header">
|
||||||
|
<h2>Созданные панели ({panels.length})</h2>
|
||||||
|
<Button variant="primary" onclick={handleDownloadAll}>Скачать все</Button>
|
||||||
|
</div>
|
||||||
|
<div class="panels-list">
|
||||||
|
{#each panels as panel (panel.id)}
|
||||||
|
<div class="panel-item">
|
||||||
|
<PanelPreview
|
||||||
|
panel={panel}
|
||||||
|
onDownload={() => handleDownload(panel)}
|
||||||
|
onUpdate={(text) => handleUpdateText(panel.id, text)}
|
||||||
|
onDelete={() => handleDeletePanel(panel.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -203,6 +216,41 @@
|
|||||||
gap: 1.5rem;
|
gap: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.panels-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panels-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
padding: 1rem;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panels-header h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panels-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-item {
|
||||||
|
border: 2px solid #e9ecef;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
.error-message {
|
.error-message {
|
||||||
background: #ffebee;
|
background: #ffebee;
|
||||||
color: #c62828;
|
color: #c62828;
|
||||||
|
|||||||
@@ -50,3 +50,30 @@ export const removeTextFromPanel = (panel: Panel, textId: string): Panel => {
|
|||||||
const updatedTexts = panel.texts.filter((text) => text.id !== textId);
|
const updatedTexts = panel.texts.filter((text) => text.id !== textId);
|
||||||
return updatePanel(panel, { texts: updatedTexts });
|
return updatePanel(panel, { texts: updatedTexts });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createPanelFromText = (backgroundImage: string, text: string, height: number = 100): Panel => {
|
||||||
|
const newText = {
|
||||||
|
id: uuidv4(),
|
||||||
|
text,
|
||||||
|
fontSize: 18,
|
||||||
|
fontFamily: "Arial",
|
||||||
|
color: "#ffffff",
|
||||||
|
textAlign: "center" as const,
|
||||||
|
paddingX: 10,
|
||||||
|
verticalOffset: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: uuidv4(),
|
||||||
|
backgroundImage,
|
||||||
|
texts: [newText],
|
||||||
|
height,
|
||||||
|
createdAt: new Date(),
|
||||||
|
updatedAt: new Date(),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updatePanelText = (panel: Panel, text: string): Panel => {
|
||||||
|
const updatedTexts = panel.texts.map((t) => ({ ...t, text }));
|
||||||
|
return updatePanel(panel, { texts: updatedTexts });
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user