mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-14 21:46:35 +00:00
feat: add ui for new split tool
This commit is contained in:
@@ -162,6 +162,7 @@
|
|||||||
--size-step-grip: 20px;
|
--size-step-grip: 20px;
|
||||||
--size-card-min: 240px;
|
--size-card-min: 240px;
|
||||||
--size-card-min-narrow: 200px;
|
--size-card-min-narrow: 200px;
|
||||||
|
--size-parts-grid-min: 120px;
|
||||||
--size-workspace-min: 260px;
|
--size-workspace-min: 260px;
|
||||||
--size-content-max: 880px;
|
--size-content-max: 880px;
|
||||||
--size-content-max-wide: 1680px;
|
--size-content-max-wide: 1680px;
|
||||||
|
|||||||
@@ -4,13 +4,14 @@
|
|||||||
import SchemaResultTile from "$lib/components/SchemaResultTile.svelte";
|
import SchemaResultTile from "$lib/components/SchemaResultTile.svelte";
|
||||||
import SchemaSourceTile from "$lib/components/SchemaSourceTile.svelte";
|
import SchemaSourceTile from "$lib/components/SchemaSourceTile.svelte";
|
||||||
import type { PixelImage } from "$lib/core/types";
|
import type { PixelImage } from "$lib/core/types";
|
||||||
import type { InputMode, ResultKind } from "$lib/registry";
|
import type { FileResult, InputMode, ResultKind } from "$lib/registry";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
inputMode: InputMode;
|
inputMode: InputMode;
|
||||||
resultKind?: ResultKind;
|
resultKind?: ResultKind;
|
||||||
source: PixelImage | null;
|
source: PixelImage | null;
|
||||||
result: PixelImage | null;
|
result: PixelImage | null;
|
||||||
|
fileResult?: FileResult | null;
|
||||||
textSource?: string;
|
textSource?: string;
|
||||||
textResult?: string | null;
|
textResult?: string | null;
|
||||||
running?: boolean;
|
running?: boolean;
|
||||||
@@ -28,6 +29,7 @@
|
|||||||
resultKind = "image",
|
resultKind = "image",
|
||||||
source,
|
source,
|
||||||
result,
|
result,
|
||||||
|
fileResult = null,
|
||||||
textSource = "",
|
textSource = "",
|
||||||
textResult = null,
|
textResult = null,
|
||||||
running = false,
|
running = false,
|
||||||
@@ -56,10 +58,22 @@
|
|||||||
? result
|
? result
|
||||||
? `${result.width} × ${result.height} px`
|
? `${result.width} × ${result.height} px`
|
||||||
: "—"
|
: "—"
|
||||||
|
: resultKind === "files"
|
||||||
|
? fileResult
|
||||||
|
? `${fileResult.files.length} parts`
|
||||||
|
: "—"
|
||||||
: textResult
|
: textResult
|
||||||
? "text"
|
? "text"
|
||||||
: "—",
|
: "—",
|
||||||
);
|
);
|
||||||
|
const formatValue = $derived(resultKind === "files" ? "ZIP (PNG)" : "PNG");
|
||||||
|
const hasResult = $derived(
|
||||||
|
resultKind === "image"
|
||||||
|
? Boolean(result)
|
||||||
|
: resultKind === "files"
|
||||||
|
? Boolean(fileResult)
|
||||||
|
: Boolean(textResult),
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="panel-head">
|
<div class="panel-head">
|
||||||
@@ -68,7 +82,7 @@
|
|||||||
>
|
>
|
||||||
<SchemaActions
|
<SchemaActions
|
||||||
{inputMode}
|
{inputMode}
|
||||||
canDownload={resultKind === "image" && Boolean(result)}
|
canDownload={hasResult}
|
||||||
{running}
|
{running}
|
||||||
{onupload}
|
{onupload}
|
||||||
ongenerate={ongenerate ?? (() => {})}
|
ongenerate={ongenerate ?? (() => {})}
|
||||||
@@ -92,8 +106,8 @@
|
|||||||
<SchemaResultTile
|
<SchemaResultTile
|
||||||
{resultKind}
|
{resultKind}
|
||||||
{result}
|
{result}
|
||||||
|
{fileResult}
|
||||||
{textResult}
|
{textResult}
|
||||||
wide={resultKind !== "image"}
|
|
||||||
{running}
|
{running}
|
||||||
oncopy={oncopytext}
|
oncopy={oncopytext}
|
||||||
{ondownloadtxt}
|
{ondownloadtxt}
|
||||||
@@ -105,7 +119,7 @@
|
|||||||
items={[
|
items={[
|
||||||
{ caption: "SOURCE", value: sourceValue },
|
{ caption: "SOURCE", value: sourceValue },
|
||||||
{ caption: "RESULT", value: resultValue },
|
{ caption: "RESULT", value: resultValue },
|
||||||
{ caption: "FORMAT", value: "PNG" },
|
{ caption: "FORMAT", value: formatValue },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { toDataUrl } from "$lib/core/io";
|
import { toDataUrl } from "$lib/core/io";
|
||||||
import type { PixelImage } from "$lib/core/types";
|
import type { PixelImage } from "$lib/core/types";
|
||||||
|
import type { FileResult } from "$lib/registry";
|
||||||
import { Check, RefreshCw } from "@lucide/svelte";
|
import { Check, RefreshCw } from "@lucide/svelte";
|
||||||
import SchemaTextResult from "./SchemaTextResult.svelte";
|
import SchemaTextResult from "./SchemaTextResult.svelte";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
resultKind?: "image" | "text" | "verdict";
|
resultKind?: "image" | "text" | "verdict" | "files";
|
||||||
result: PixelImage | null;
|
result: PixelImage | null;
|
||||||
|
fileResult?: FileResult | null;
|
||||||
textResult?: string | null;
|
textResult?: string | null;
|
||||||
wide?: boolean;
|
|
||||||
running?: boolean;
|
running?: boolean;
|
||||||
oncopy?: () => void;
|
oncopy?: () => void;
|
||||||
ondownloadtxt?: () => void;
|
ondownloadtxt?: () => void;
|
||||||
@@ -16,20 +17,31 @@
|
|||||||
let {
|
let {
|
||||||
resultKind = "image",
|
resultKind = "image",
|
||||||
result,
|
result,
|
||||||
|
fileResult = null,
|
||||||
textResult = null,
|
textResult = null,
|
||||||
wide = false,
|
|
||||||
running = false,
|
running = false,
|
||||||
oncopy,
|
oncopy,
|
||||||
ondownloadtxt,
|
ondownloadtxt,
|
||||||
}: Props = $props();
|
}: Props = $props();
|
||||||
|
|
||||||
const resultUrl = $derived(result ? toDataUrl(result) : null);
|
const resultUrl = $derived(result ? toDataUrl(result) : null);
|
||||||
|
const partUrls = $derived(
|
||||||
|
resultKind === "files" && fileResult
|
||||||
|
? fileResult.files.map((file) => ({
|
||||||
|
name: file.name,
|
||||||
|
url: toDataUrl(file.image),
|
||||||
|
}))
|
||||||
|
: [],
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<figure class="tile" style:grid-column={wide ? "1 / -1" : undefined}>
|
<figure class="tile">
|
||||||
<figcaption>
|
<figcaption>
|
||||||
<span>
|
<span>
|
||||||
RESULT
|
RESULT
|
||||||
|
{#if resultKind === "files" && fileResult}
|
||||||
|
<span class="count">{fileResult.files.length} parts</span>
|
||||||
|
{/if}
|
||||||
{#if running}
|
{#if running}
|
||||||
<RefreshCw class="rotating" size="16" />
|
<RefreshCw class="rotating" size="16" />
|
||||||
{/if}
|
{/if}
|
||||||
@@ -54,6 +66,15 @@
|
|||||||
ondownload={ondownloadtxt ?? (() => {})}
|
ondownload={ondownloadtxt ?? (() => {})}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{:else if resultKind === "files" && partUrls.length > 0}
|
||||||
|
<div class="parts-grid">
|
||||||
|
{#each partUrls as part (part.name)}
|
||||||
|
<figure class="part">
|
||||||
|
<img src={part.url} alt={part.name} loading="lazy" />
|
||||||
|
<figcaption>{part.name}</figcaption>
|
||||||
|
</figure>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
{:else if resultKind === "image" && resultUrl}
|
{:else if resultKind === "image" && resultUrl}
|
||||||
<img src={resultUrl} alt="result" />
|
<img src={resultUrl} alt="result" />
|
||||||
{:else if running}
|
{:else if running}
|
||||||
@@ -83,7 +104,7 @@
|
|||||||
min-height: clamp(var(--space-brand), 30vh, 60vh);
|
min-height: clamp(var(--space-brand), 30vh, 60vh);
|
||||||
border: var(--size-border) solid var(--color-border);
|
border: var(--size-border) solid var(--color-border);
|
||||||
border-radius: var(--radius-s);
|
border-radius: var(--radius-s);
|
||||||
overflow: hidden;
|
overflow: auto;
|
||||||
background: var(--color-background-muted);
|
background: var(--color-background-muted);
|
||||||
color: var(--color-text-muted);
|
color: var(--color-text-muted);
|
||||||
}
|
}
|
||||||
@@ -103,6 +124,47 @@
|
|||||||
.empty {
|
.empty {
|
||||||
font: var(--font-size-s) var(--font-mono);
|
font: var(--font-size-s) var(--font-mono);
|
||||||
}
|
}
|
||||||
|
.count {
|
||||||
|
margin-left: var(--space-m);
|
||||||
|
color: var(--color-main);
|
||||||
|
}
|
||||||
|
.parts-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(
|
||||||
|
auto-fill,
|
||||||
|
minmax(var(--size-parts-grid-min), 1fr)
|
||||||
|
);
|
||||||
|
gap: var(--space-m);
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding: var(--space-l);
|
||||||
|
box-sizing: border-box;
|
||||||
|
align-content: start;
|
||||||
|
}
|
||||||
|
.part {
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-s);
|
||||||
|
}
|
||||||
|
.part img {
|
||||||
|
width: 100%;
|
||||||
|
height: auto;
|
||||||
|
display: block;
|
||||||
|
border: var(--size-border) solid var(--color-border);
|
||||||
|
border-radius: var(--radius-s);
|
||||||
|
background: repeating-conic-gradient(
|
||||||
|
var(--color-checker-main) 0 25%,
|
||||||
|
var(--color-checker-alt) 0 50%
|
||||||
|
)
|
||||||
|
50% / 16px 16px;
|
||||||
|
}
|
||||||
|
.part figcaption {
|
||||||
|
font: var(--font-size-s) var(--font-mono);
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
text-align: center;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
.text-result-wrap {
|
.text-result-wrap {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: var(--space-l);
|
padding: var(--space-l);
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
import type { PixelImage } from "$lib/core/types";
|
import type { PixelImage } from "$lib/core/types";
|
||||||
import { execute } from "$lib/executor";
|
import { execute } from "$lib/executor";
|
||||||
import { t } from "$lib/i18n/t";
|
import { t } from "$lib/i18n/t";
|
||||||
import type { ToolEntry } from "$lib/registry";
|
import type { FileResult, ToolEntry } from "$lib/registry";
|
||||||
|
import { downloadZip } from "$lib/zip";
|
||||||
import {
|
import {
|
||||||
defaultSchemaParams,
|
defaultSchemaParams,
|
||||||
sanitizeSchemaParams,
|
sanitizeSchemaParams,
|
||||||
@@ -29,6 +30,7 @@
|
|||||||
let values = $state<Record<string, unknown>>({});
|
let values = $state<Record<string, unknown>>({});
|
||||||
let source = $state<PixelImage | null>(null);
|
let source = $state<PixelImage | null>(null);
|
||||||
let result = $state<PixelImage | null>(null);
|
let result = $state<PixelImage | null>(null);
|
||||||
|
let fileResult = $state<FileResult | null>(null);
|
||||||
let textSource = $state("");
|
let textSource = $state("");
|
||||||
let textResult = $state<string | null>(null);
|
let textResult = $state<string | null>(null);
|
||||||
let running = $state(false);
|
let running = $state(false);
|
||||||
@@ -50,6 +52,7 @@
|
|||||||
function reset() {
|
function reset() {
|
||||||
values = schema ? defaultSchemaParams(schema) : {};
|
values = schema ? defaultSchemaParams(schema) : {};
|
||||||
result = null;
|
result = null;
|
||||||
|
fileResult = null;
|
||||||
textResult = null;
|
textResult = null;
|
||||||
error = "";
|
error = "";
|
||||||
}
|
}
|
||||||
@@ -76,9 +79,15 @@
|
|||||||
if (resultKind === "image") {
|
if (resultKind === "image") {
|
||||||
result = out as PixelImage;
|
result = out as PixelImage;
|
||||||
textResult = null;
|
textResult = null;
|
||||||
|
fileResult = null;
|
||||||
|
} else if (resultKind === "files") {
|
||||||
|
fileResult = out as FileResult;
|
||||||
|
result = null;
|
||||||
|
textResult = null;
|
||||||
} else {
|
} else {
|
||||||
textResult = out as string;
|
textResult = out as string;
|
||||||
result = null;
|
result = null;
|
||||||
|
fileResult = null;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = errorText(e);
|
error = errorText(e);
|
||||||
@@ -88,7 +97,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function download() {
|
async function download() {
|
||||||
if (!result || !schema) return;
|
if (!schema) return;
|
||||||
|
if (resultKind === "files") {
|
||||||
|
if (!fileResult) return;
|
||||||
|
await downloadZip(fileResult.files, `${tool.id}.zip`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!result) return;
|
||||||
const out = tool.output;
|
const out = tool.output;
|
||||||
const quality = out?.qualityParamId
|
const quality = out?.qualityParamId
|
||||||
? Number(values[out.qualityParamId]) / 100
|
? Number(values[out.qualityParamId]) / 100
|
||||||
@@ -164,6 +179,7 @@
|
|||||||
<SchemaPreview
|
<SchemaPreview
|
||||||
{source}
|
{source}
|
||||||
{result}
|
{result}
|
||||||
|
{fileResult}
|
||||||
{textSource}
|
{textSource}
|
||||||
{textResult}
|
{textResult}
|
||||||
{inputMode}
|
{inputMode}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { defaultSchemaParams, sanitizeSchemaParams } from "../registry-schema";
|
|||||||
import type { ToolResult } from "./types";
|
import type { ToolResult } from "./types";
|
||||||
|
|
||||||
function asImage(result: ToolResult): PixelImage {
|
function asImage(result: ToolResult): PixelImage {
|
||||||
if (typeof result === "string") {
|
if (typeof result === "string" || "files" in result) {
|
||||||
throw new Error("expected an image result");
|
throw new Error("expected an image result");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user