Line data Source code
1 2 : <template>
2 9 : <div
3 : class="absolute top-4 left-1/2 z-10 flex -translate-x-1/2 items-center gap-1 rounded-full border bg-background p-1 shadow-lg"
4 : >
5 : <ToggleGroup
6 : type="single"
7 : :model-value="pointerMode"
8 : @update:model-value="onPointerModeChange"
9 : >
10 : <ToggleGroupItem
11 : value="pointer"
12 : class="size-8 rounded-full p-0"
13 : :title="t('layerEditor.selectTool')"
14 : :aria-label="t('layerEditor.selectTool')"
15 : >
16 : <i class="icon-[lucide--mouse-pointer-2]" />
17 : </ToggleGroupItem>
18 : <ToggleGroupItem
19 : value="hand"
20 : class="size-8 rounded-full p-0"
21 : :title="t('layerEditor.handTool')"
22 : :aria-label="t('layerEditor.handTool')"
23 : >
24 : <i class="icon-[lucide--hand]" />
25 : </ToggleGroupItem>
26 : </ToggleGroup>
27 :
28 : <PopoverRoot v-model:open="zoomOpen">
29 : <PopoverTrigger as-child>
30 : <Button
31 : variant="textonly"
32 : class="gap-1 rounded-full"
33 : :title="t('layerEditor.zoom')"
34 : :aria-label="t('layerEditor.zoom')"
35 : >
36 : <span class="min-w-8 text-center">{{ zoomPercent }}</span>
37 : <i class="icon-[lucide--chevron-down] size-3" />
38 : </Button>
39 : </PopoverTrigger>
40 : <PopoverContent
41 : :side-offset="8"
42 : :class="cn(menuContentClass, 'flex w-auto min-w-20 flex-col')"
43 : >
44 0 : <button
45 : v-for="item in zoomItems"
46 : :key="item.label"
47 : :class="menuButtonClass"
48 : @click="applyZoom(item.ratio)"
49 : >
50 : {{ item.label }}
51 : </button>
52 : <button :class="menuButtonClass" @click="applyZoom(null)">
53 : {{ t('layerEditor.fitView') }}
54 : </button>
55 : </PopoverContent>
56 : </PopoverRoot>
57 :
58 : <button
59 : :class="toolButtonClass(false)"
60 : :disabled="!canUndo"
61 : :title="t('layerEditor.undo')"
62 : :aria-label="t('layerEditor.undo')"
63 : @click="session.undo()"
64 : >
65 : <i class="icon-[lucide--undo-2]" />
66 : </button>
67 : <button
68 : :class="toolButtonClass(false)"
69 : :disabled="!canRedo"
70 : :title="t('layerEditor.redo')"
71 : :aria-label="t('layerEditor.redo')"
72 : @click="session.redo()"
73 : >
74 : <i class="icon-[lucide--redo-2]" />
75 : </button>
76 : <button
77 : :class="toolButtonClass(false)"
78 : :disabled="exporting || !session.glOk.value"
79 : :title="t('layerEditor.exportPsd')"
80 : :aria-label="t('layerEditor.exportPsd')"
81 : @click="emit('export-psd')"
82 : >
83 : <i class="icon-[lucide--file-down]" />
84 : </button>
85 : </div>
86 : </template>
87 :
88 : <script setup lang="ts">
89 : import type { AcceptableValue } from 'reka-ui'
90 : import { PopoverRoot, PopoverTrigger } from 'reka-ui'
91 : import { computed, ref } from 'vue'
92 : import { useI18n } from 'vue-i18n'
93 :
94 : import Button from '@comfyorg/design-system/button/Button'
95 : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
96 : import {
97 : menuContentClass,
98 : menuButtonClass
99 : } from '@comfyorg/design-system/lib/menu/menuStyles'
100 : import ToggleGroup from '@comfyorg/design-system/toggle-group/ToggleGroup'
101 : import ToggleGroupItem from '@comfyorg/design-system/toggle-group/ToggleGroupItem'
102 : import type { LayerEditorSession } from '@comfyorg/layer-editor/vue'
103 : import { cn } from '@comfyorg/tailwind-utils'
104 :
105 : const { session, exporting = false } = defineProps<{
106 : session: LayerEditorSession
107 : exporting?: boolean
108 : }>()
109 :
110 2 : const emit = defineEmits<{ 'export-psd': [] }>()
111 :
112 2 : const { t } = useI18n()
113 2 : const { pointerMode, canUndo, canRedo, zoomRatio } = session
114 :
115 2 : const zoomOpen = ref(false)
116 :
117 2 : const zoomItems = [
118 : { label: '25%', ratio: 0.25 },
119 : { label: '50%', ratio: 0.5 },
120 : { label: '100%', ratio: 1 },
121 : { label: '200%', ratio: 2 }
122 : ]
123 :
124 0 : function onPointerModeChange(value: AcceptableValue | AcceptableValue[]): void {
125 0 : if (value === 'pointer' || value === 'hand') session.setPointerMode(value)
126 : }
127 :
128 0 : function applyZoom(ratio: number | null): void {
129 0 : if (ratio == null) session.fitView()
130 0 : else session.setZoom(ratio)
131 0 : zoomOpen.value = false
132 : }
133 :
134 2 : const zoomPercent = computed(() => `${Math.round(zoomRatio.value * 100)}%`)
135 :
136 27 : function toolButtonClass(active: boolean): string {
137 27 : return cn(
138 : 'flex size-8 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent text-foreground transition-colors',
139 : 'hover:bg-accent disabled:cursor-default disabled:opacity-40',
140 : active && 'bg-muted'
141 : )
142 : }
143 : </script>
|