mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
feat: add size presets for tools
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n/t";
|
||||
import type {
|
||||
Dimension,
|
||||
DimensionSpec,
|
||||
FieldSpec,
|
||||
import {
|
||||
SIZE_PRESETS,
|
||||
type Dimension,
|
||||
type DimensionSpec,
|
||||
type FieldSpec,
|
||||
} from "$lib/registry-schema";
|
||||
import ChipButton from "$lib/components/ui/ChipButton.svelte";
|
||||
import Control from "./Control.svelte";
|
||||
|
||||
interface Props {
|
||||
label: string;
|
||||
value: unknown;
|
||||
spec: FieldSpec;
|
||||
onchange?: (value: Dimension, axis?: "width" | "height") => void;
|
||||
onchange?: (value: Dimension, axis?: "width" | "height" | "both") => void;
|
||||
}
|
||||
let { label, value, spec, onchange }: Props = $props();
|
||||
|
||||
@@ -33,6 +35,11 @@
|
||||
function setAxis(axis: "width" | "height", n: number) {
|
||||
onchange?.({ ...current, [axis]: n }, axis);
|
||||
}
|
||||
|
||||
function applyPreset(n: number) {
|
||||
// Пресет задаёт обе оси явно — lockAspect его не пересчитывает.
|
||||
onchange?.({ width: n, height: n }, "both");
|
||||
}
|
||||
</script>
|
||||
|
||||
<Control {label} caps>
|
||||
@@ -60,6 +67,17 @@
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{#if sp.presets}
|
||||
<div class="dimension-presets">
|
||||
{#each SIZE_PRESETS as n (n)}
|
||||
<ChipButton
|
||||
label={`${n}×${n}`}
|
||||
active={current.width === n && current.height === n}
|
||||
onclick={() => applyPreset(n)}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</Control>
|
||||
|
||||
<style>
|
||||
@@ -81,4 +99,10 @@
|
||||
color: var(--color-text);
|
||||
font: var(--font-size-s) var(--font-mono);
|
||||
}
|
||||
.dimension-presets {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-s);
|
||||
margin-top: var(--space-m);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<span class="range-trailing">
|
||||
<IconButton
|
||||
icon={Minus}
|
||||
label={t("ui.decrease")}
|
||||
label={`${t("ui.decrease")} ${label}`}
|
||||
variant="clear"
|
||||
size="s"
|
||||
disabled={atMin}
|
||||
@@ -57,7 +57,7 @@
|
||||
/>
|
||||
<IconButton
|
||||
icon={Plus}
|
||||
label={t("ui.increase")}
|
||||
label={`${t("ui.increase")} ${label}`}
|
||||
variant="clear"
|
||||
size="s"
|
||||
disabled={atMax}
|
||||
@@ -65,7 +65,7 @@
|
||||
/>
|
||||
<IconButton
|
||||
icon={RotateCcw}
|
||||
label={t("ui.reset")}
|
||||
label={`${t("ui.reset")} ${label}`}
|
||||
variant="clear"
|
||||
size="s"
|
||||
disabled={atDefault}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
spec: FieldSpec;
|
||||
toolId: string;
|
||||
fieldId: string;
|
||||
onchange?: (value: unknown, axis?: "width" | "height") => void;
|
||||
onchange?: (value: unknown, axis?: "width" | "height" | "both") => void;
|
||||
}
|
||||
|
||||
const FIELDS: Record<FieldSpecKind, Component<FieldControlProps>> = {
|
||||
@@ -54,7 +54,11 @@
|
||||
schema: ToolSchema<Record<string, unknown>>;
|
||||
values: Record<string, unknown>;
|
||||
toolId: string;
|
||||
onchange: (id: string, value: unknown, axis?: "width" | "height") => void;
|
||||
onchange: (
|
||||
id: string,
|
||||
value: unknown,
|
||||
axis?: "width" | "height" | "both",
|
||||
) => void;
|
||||
onreset: () => void;
|
||||
}
|
||||
let { schema, values, toolId, onchange, onreset }: Props = $props();
|
||||
|
||||
@@ -74,9 +74,13 @@
|
||||
values = defaultSchemaParams(schema);
|
||||
}
|
||||
|
||||
function setValue(id: string, value: unknown, axis?: "width" | "height") {
|
||||
function setValue(
|
||||
id: string,
|
||||
value: unknown,
|
||||
axis?: "width" | "height" | "both",
|
||||
) {
|
||||
touched.add(id);
|
||||
if (axis) lastAxis[id] = axis;
|
||||
if (axis) lastAxis[id] = axis === "both" ? "width" : axis;
|
||||
const next: Record<string, unknown> = { ...values, [id]: value };
|
||||
const spec = schema?.fields[id]?.spec;
|
||||
if (source && schema && spec) {
|
||||
@@ -84,6 +88,7 @@
|
||||
if (
|
||||
spec.kind === "dimension" &&
|
||||
spec.lockAspectWith &&
|
||||
axis !== "both" &&
|
||||
next[spec.lockAspectWith] === true
|
||||
) {
|
||||
next[id] = withAspectLock(
|
||||
|
||||
Reference in New Issue
Block a user