|
| 1 | +<script setup lang="ts"> |
| 2 | +import { computed, ref } from 'vue' |
| 3 | +import ParameterSlider from './ParameterSlider.vue' |
| 4 | +import { findActivePreset, presets } from './presets' |
| 5 | +import SegmentedControl from './SegmentedControl.vue' |
| 6 | +import type { ClusteringMode, ConversionParams, HierarchicalMode, TraceMode } from './types' |
| 7 | +
|
| 8 | +const props = defineProps<{ |
| 9 | + disabled?: boolean |
| 10 | +}>() |
| 11 | +
|
| 12 | +const params = defineModel<ConversionParams>({ required: true }) |
| 13 | +
|
| 14 | +const activePresetKey = computed(() => findActivePreset(params.value)) |
| 15 | +const showAdvanced = ref(false) |
| 16 | +
|
| 17 | +function applyPreset(key: string) { |
| 18 | + const preset = presets.find(preset => preset.key === key) |
| 19 | +
|
| 20 | + if (preset) { |
| 21 | + params.value = { ...preset.params } |
| 22 | + } |
| 23 | +} |
| 24 | +
|
| 25 | +const traceModes: { value: TraceMode; label: string; description: string }[] = [ |
| 26 | + { value: 'spline', label: 'Spline', description: 'Smooth curves (best for most images)' }, |
| 27 | + { value: 'polygon', label: 'Polygon', description: 'Straight segments (pixel-art style)' }, |
| 28 | + { value: 'none', label: 'None', description: 'No path simplification (raw pixel edges)' }, |
| 29 | +] |
| 30 | +
|
| 31 | +const clusteringModes: { value: ClusteringMode; label: string; description: string }[] = [ |
| 32 | + { value: 'color', label: 'Color', description: 'Full color tracing with clustering' }, |
| 33 | + { value: 'binary', label: 'B/W', description: 'Black and white tracing' }, |
| 34 | +] |
| 35 | +
|
| 36 | +const hierarchicalModes: { value: HierarchicalMode; label: string; description: string }[] = [ |
| 37 | + { value: 'stacked', label: 'Stacked', description: 'Layers stacked on top of each other' }, |
| 38 | + { value: 'cutout', label: 'Cutout', description: 'Shapes cut out from layers below' }, |
| 39 | +] |
| 40 | +
|
| 41 | +const sliders = computed(() => { |
| 42 | + const colorSliders = params.value.clusteringMode === 'color' |
| 43 | + ? [ |
| 44 | + { |
| 45 | + key: 'colorPrecision' as const, |
| 46 | + label: 'Color Precision', |
| 47 | + min: 1, |
| 48 | + max: 8, |
| 49 | + step: 1, |
| 50 | + description: 'How many colors to distinguish. Higher values preserve more color detail, lower values simplify.', |
| 51 | + }, |
| 52 | + { |
| 53 | + key: 'layerDifference' as const, |
| 54 | + label: 'Gradient Step', |
| 55 | + min: 0, |
| 56 | + max: 128, |
| 57 | + step: 1, |
| 58 | + description: 'Color difference between gradient layers. Higher values produce fewer layers and a more posterized look.', |
| 59 | + }, |
| 60 | + ] |
| 61 | + : [] |
| 62 | +
|
| 63 | + return [ |
| 64 | + ...colorSliders, |
| 65 | + { |
| 66 | + key: 'filterSpeckle' as const, |
| 67 | + label: 'Filter Speckle', |
| 68 | + min: 0, |
| 69 | + max: 128, |
| 70 | + step: 1, |
| 71 | + description: 'Removes clusters smaller than this size (in pixels). Increase to clean up noise and tiny artifacts.', |
| 72 | + }, |
| 73 | + { |
| 74 | + key: 'cornerThreshold' as const, |
| 75 | + label: 'Corner Threshold', |
| 76 | + min: 0, |
| 77 | + max: 180, |
| 78 | + step: 1, |
| 79 | + description: 'Angle (in degrees) below which a point is treated as a corner. Lower values produce rounder shapes; higher values keep sharp corners.', |
| 80 | + }, |
| 81 | + { |
| 82 | + key: 'lengthThreshold' as const, |
| 83 | + label: 'Length Threshold', |
| 84 | + min: 0, |
| 85 | + max: 100, |
| 86 | + step: 0.5, |
| 87 | + description: 'Minimum segment length to keep. Higher values simplify paths by dropping short segments, reducing file size.', |
| 88 | + }, |
| 89 | + { |
| 90 | + key: 'spliceThreshold' as const, |
| 91 | + label: 'Splice Threshold', |
| 92 | + min: 0, |
| 93 | + max: 180, |
| 94 | + step: 1, |
| 95 | + description: 'Angle threshold for joining adjacent curves. Higher values merge more curves together for smoother output.', |
| 96 | + }, |
| 97 | + { |
| 98 | + key: 'pathPrecision' as const, |
| 99 | + label: 'Path Precision', |
| 100 | + min: 0, |
| 101 | + max: 8, |
| 102 | + step: 1, |
| 103 | + description: 'Decimal places in SVG path coordinates. Higher values are more precise but produce larger files.', |
| 104 | + }, |
| 105 | + ] |
| 106 | +}) |
| 107 | +</script> |
| 108 | + |
| 109 | +<template> |
| 110 | + <div class="space-y-4" :class="{ 'opacity-50 pointer-events-none': props.disabled }"> |
| 111 | + <!-- Presets --> |
| 112 | + <div class="flex flex-wrap items-center gap-2"> |
| 113 | + <span class="text-xs font-semibold uppercase tracking-wider text-text-muted">Preset</span> |
| 114 | + <button |
| 115 | + v-for="preset in presets" |
| 116 | + :key="preset.key" |
| 117 | + type="button" |
| 118 | + :disabled="props.disabled" |
| 119 | + class="px-3 py-1.5 text-xs font-medium rounded-lg transition-colors cursor-pointer" |
| 120 | + :class="activePresetKey === preset.key |
| 121 | + ? 'bg-accent text-white' |
| 122 | + : 'bg-surface-overlay text-text-secondary hover:text-text-primary border border-border'" |
| 123 | + :title="preset.description" |
| 124 | + @click="applyPreset(preset.key)" |
| 125 | + > |
| 126 | + {{ preset.label }} |
| 127 | + </button> |
| 128 | + </div> |
| 129 | + |
| 130 | + <!-- Advanced toggle --> |
| 131 | + <button |
| 132 | + type="button" |
| 133 | + class="flex items-center gap-1.5 text-xs text-text-muted hover:text-text-secondary transition-colors cursor-pointer" |
| 134 | + :disabled="props.disabled" |
| 135 | + @click="showAdvanced = !showAdvanced" |
| 136 | + > |
| 137 | + <span class="transition-transform" :class="showAdvanced ? 'rotate-90' : ''">▶</span> |
| 138 | + Advanced parameters |
| 139 | + </button> |
| 140 | + |
| 141 | + <div v-if="showAdvanced" class="space-y-4"> |
| 142 | + <SegmentedControl v-model="params.clusteringMode" label="Clustering" :options="clusteringModes" :disabled="props.disabled" /> |
| 143 | + |
| 144 | + <SegmentedControl |
| 145 | + v-if="params.clusteringMode === 'color'" |
| 146 | + v-model="params.hierarchical" |
| 147 | + label="Hierarchy" |
| 148 | + :options="hierarchicalModes" |
| 149 | + :disabled="props.disabled" |
| 150 | + /> |
| 151 | + |
| 152 | + <SegmentedControl v-model="params.mode" label="Curve fitting" :options="traceModes" :disabled="props.disabled" /> |
| 153 | + |
| 154 | + <div class="grid grid-cols-1 sm:grid-cols-2 gap-4"> |
| 155 | + <ParameterSlider |
| 156 | + v-for="slider in sliders" |
| 157 | + :key="slider.key" |
| 158 | + v-model="params[slider.key]" |
| 159 | + :label="slider.label" |
| 160 | + :min="slider.min" |
| 161 | + :max="slider.max" |
| 162 | + :step="slider.step" |
| 163 | + :description="slider.description" |
| 164 | + :disabled="props.disabled" |
| 165 | + /> |
| 166 | + </div> |
| 167 | + </div> |
| 168 | + </div> |
| 169 | +</template> |
0 commit comments