|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref } from 'vue' |
| 3 | +
|
| 4 | +import { GrButton, GrImageViewer } from '@feugene/granularity' |
| 5 | +
|
| 6 | +// Картинка гарантированного размера: picsum возвращает ровно указанные width/height. |
| 7 | +const IMAGE_WIDTH = 1000 |
| 8 | +const IMAGE_HEIGHT = 1500 |
| 9 | +
|
| 10 | +const slides = [`https://picsum.photos/id/1015/${IMAGE_WIDTH}/${IMAGE_HEIGHT}`] |
| 11 | +
|
| 12 | +const open = ref(false) |
| 13 | +</script> |
| 14 | + |
| 15 | +<template> |
| 16 | + <div class="grid gap-3"> |
| 17 | + <div class="text-sm text-[var(--muted-fg)]"> |
| 18 | + Картинка гарантированного размера {{ IMAGE_WIDTH }}×{{ IMAGE_HEIGHT }}. Номинальный `scale` считается относительно |
| 19 | + вписанного в окно изображения (`object-contain`), поэтому «100%» — это не натуральный размер. Компонент сам отдаёт |
| 20 | + в slot natural-размер, фактический rendered-размер и реальный масштаб — без ручного чтения DOM. |
| 21 | + </div> |
| 22 | + |
| 23 | + <div> |
| 24 | + <GrButton size="sm" @click="open = true"> |
| 25 | + Open real-size experiment |
| 26 | + </GrButton> |
| 27 | + </div> |
| 28 | + |
| 29 | + <GrImageViewer |
| 30 | + v-model="open" |
| 31 | + :url-list="slides" |
| 32 | + show-progress |
| 33 | + :show-zoom-value="false" |
| 34 | + > |
| 35 | + <template #toolbar="{ scale, rotation, naturalWidth, naturalHeight, renderedWidth, renderedHeight, realScalePercent, actions }"> |
| 36 | + <div class="flex flex-col gap-2 rounded-2xl border border-[color-mix(in_srgb,var(--bg)_20%,transparent)] bg-[color-mix(in_srgb,var(--fg)_55%,transparent)] px-3 py-2 text-[var(--bg)] backdrop-blur-sm"> |
| 37 | + <div class="flex items-center justify-center gap-2"> |
| 38 | + <button type="button" class="rounded-full px-3 py-1 text-xs transition-colors hover:bg-[color-mix(in_srgb,var(--bg)_10%,transparent)]" @click="actions.zoomOut">−</button> |
| 39 | + <button type="button" class="rounded-full px-3 py-1 text-xs transition-colors hover:bg-[color-mix(in_srgb,var(--bg)_10%,transparent)]" @click="actions.reset">Reset</button> |
| 40 | + <button type="button" class="rounded-full px-3 py-1 text-xs transition-colors hover:bg-[color-mix(in_srgb,var(--bg)_10%,transparent)]" @click="actions.zoomIn">+</button> |
| 41 | + </div> |
| 42 | + |
| 43 | + <div class="grid gap-0.5 text-[11px] leading-tight font-500"> |
| 44 | + <span>Natural: {{ naturalWidth }} × {{ naturalHeight }} px</span> |
| 45 | + <span>Rendered: {{ renderedWidth }} × {{ renderedHeight }} px</span> |
| 46 | + <span>Nominal scale: {{ Math.round(scale * 100) }}% · rotation {{ rotation }}°</span> |
| 47 | + <span>Real scale: {{ realScalePercent }}%</span> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + </template> |
| 51 | + </GrImageViewer> |
| 52 | + </div> |
| 53 | +</template> |
0 commit comments