|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { SlideRoute } from '@slidev/types' |
| 3 | +import HandoutBottom from '#slidev/global-components/handout-bottom' |
| 4 | +import { computed } from 'vue' |
| 5 | +import { slideHeight, slideWidth } from '../env' |
| 6 | +import NoteDisplay from './NoteDisplay.vue' |
| 7 | +import PrintSlide from './PrintSlide.vue' |
| 8 | +
|
| 9 | +const props = defineProps<{ |
| 10 | + route: SlideRoute |
| 11 | + index: number |
| 12 | + pageOffset?: number |
| 13 | +}>() |
| 14 | +const route = computed(() => props.route) |
| 15 | +const pageOffset = computed(() => props.pageOffset ?? 0) |
| 16 | +
|
| 17 | +// Use fixed A4 dimensions in CSS pixels (96 DPI) to avoid relying on |
| 18 | +// runtime viewport sizes which can skew scaling during headless export |
| 19 | +const PAGE_WIDTH_PX = Math.round(210 / 25.4 * 96) |
| 20 | +const PAGE_HEIGHT_PX = Math.round(297 / 25.4 * 96) |
| 21 | +const pageWidth = computed(() => PAGE_WIDTH_PX) |
| 22 | +const pageHeight = computed(() => PAGE_HEIGHT_PX) |
| 23 | +
|
| 24 | +// Target layout: slide ~50% height, notes the rest, footer pinned |
| 25 | +const SLIDE_PORTION = 0.5 |
| 26 | +const PX_PER_MM = 96 / 25.4 |
| 27 | +// Inner paddings of the page box |
| 28 | +const PAGE_PAD_SIDE_MM = 12 |
| 29 | +const PAGE_PAD_TOP_MM = 10 |
| 30 | +const PAGE_PAD_BOTTOM_MM = 10 |
| 31 | +// Extra margins around the slide area |
| 32 | +const SLIDE_SIDE_MARGIN_MM = 6 |
| 33 | +const SLIDE_TOP_MARGIN_MM = 4 |
| 34 | +
|
| 35 | +// Constrain slide scale by width and by allowed height portion with top/side margins |
| 36 | +const scale = computed(() => { |
| 37 | + const innerWidth = pageWidth.value - 2 * PAGE_PAD_SIDE_MM * PX_PER_MM |
| 38 | + const innerHeight = pageHeight.value - (PAGE_PAD_TOP_MM + PAGE_PAD_BOTTOM_MM) * PX_PER_MM |
| 39 | + const byWidth = (innerWidth - 2 * SLIDE_SIDE_MARGIN_MM * PX_PER_MM) / slideWidth.value |
| 40 | + const byHeight = ((innerHeight * SLIDE_PORTION) - (SLIDE_TOP_MARGIN_MM * PX_PER_MM)) / slideHeight.value |
| 41 | + const s = Math.min(1, byWidth, byHeight) |
| 42 | + return Math.max(0, s - 0.006) |
| 43 | +}) |
| 44 | +
|
| 45 | +const slideHeightScaled = computed(() => slideHeight.value * scale.value) |
| 46 | +const slideAreaStyle = computed(() => ({ |
| 47 | + height: `${slideHeightScaled.value}px`, |
| 48 | + padding: `${SLIDE_TOP_MARGIN_MM}mm ${SLIDE_SIDE_MARGIN_MM}mm 0`, |
| 49 | +})) |
| 50 | +</script> |
| 51 | + |
| 52 | +<template> |
| 53 | + <div class="break-after-page page"> |
| 54 | + <div class="slide-area" :style="slideAreaStyle"> |
| 55 | + <div class="slide-scale-wrap" :style="{ width: `${slideWidth}px`, height: `${slideHeight}px`, transform: `scale(${scale})` }"> |
| 56 | + <PrintSlide :route="route" /> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + <div class="notes-area"> |
| 60 | + <NoteDisplay |
| 61 | + v-if="route.meta?.slide!.noteHTML" |
| 62 | + :note-html="route.meta?.slide!.noteHTML" |
| 63 | + class="w-full mx-auto px-4 handout-notes" |
| 64 | + /> |
| 65 | + </div> |
| 66 | + <div class="footer-area"> |
| 67 | + <div class="footer-bleed"> |
| 68 | + <HandoutBottom :page-number="index + 1 + pageOffset" :page-offset="pageOffset" /> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | +</template> |
| 73 | + |
| 74 | +<style scoped> |
| 75 | +/* One handout page per printed page, sized to A4 with internal padding */ |
| 76 | +.page { |
| 77 | + display: flex; |
| 78 | + flex-direction: column; |
| 79 | + width: 210mm; |
| 80 | + min-height: 297mm; |
| 81 | + margin: 0 auto; |
| 82 | + padding: 10mm 12mm 4mm; /* top, sides, bottom */ |
| 83 | +
|
| 84 | + box-sizing: border-box; |
| 85 | + break-after: page; |
| 86 | + page-break-after: always; /* Chromium fallback */ |
| 87 | + break-inside: avoid-page; |
| 88 | +} |
| 89 | +.slide-area { |
| 90 | + flex: 0 0 auto; |
| 91 | + display: flex; |
| 92 | + justify-content: center; |
| 93 | + align-items: flex-start; |
| 94 | +} |
| 95 | +.slide-area { |
| 96 | + /* Allow slide borders/shadows to render fully */ |
| 97 | + overflow: visible; |
| 98 | + margin-bottom: 4mm; |
| 99 | +} |
| 100 | +.slide-scale-wrap { |
| 101 | + transform-origin: top center; |
| 102 | + margin: 0 auto; |
| 103 | +} |
| 104 | +.slide-scale-wrap :deep(.print-slide-container) { |
| 105 | + break-after: auto; |
| 106 | + /* Thin dark gray border around each slide in handout */ |
| 107 | + border: 1px solid rgba(0, 0, 0, 0.6); |
| 108 | + border-radius: 2px; |
| 109 | +} |
| 110 | +.notes-area { |
| 111 | + flex: 1 1 auto; |
| 112 | + overflow: hidden; |
| 113 | + display: flex; |
| 114 | + /* add a bit more top spacing above notes */ |
| 115 | + padding: 8mm 3mm 12mm; |
| 116 | +} |
| 117 | +.handout-notes { |
| 118 | + margin: 0 auto; |
| 119 | + max-width: none; |
| 120 | +} |
| 121 | +.footer-area { |
| 122 | + position: relative; |
| 123 | + display: flex; |
| 124 | + align-items: flex-end; |
| 125 | + gap: 6mm; |
| 126 | + flex: 0 0 auto; |
| 127 | + min-height: 14mm; |
| 128 | +} |
| 129 | +/* full-width top rule across footer */ |
| 130 | +.footer-area::before { |
| 131 | + content: ''; |
| 132 | + position: absolute; |
| 133 | + left: -12mm; |
| 134 | + right: -12mm; |
| 135 | + top: 0; |
| 136 | + height: 1px; |
| 137 | + background: #222; |
| 138 | + opacity: 0.9; |
| 139 | +} |
| 140 | +.footer-bleed { |
| 141 | + flex: 1 1 auto; |
| 142 | + position: relative; |
| 143 | + margin: 0; |
| 144 | + overflow: visible; |
| 145 | + padding-top: 2mm; |
| 146 | +} |
| 147 | +.footer-bleed :deep(*) { |
| 148 | + max-width: 100% !important; |
| 149 | + margin-left: 0 !important; |
| 150 | + margin-right: 0 !important; |
| 151 | + border-top-width: 0 !important; |
| 152 | +} |
| 153 | +.page-num { |
| 154 | + flex: 0 0 auto; |
| 155 | + font-size: 11px; |
| 156 | + text-align: right; |
| 157 | + padding-bottom: 1mm; |
| 158 | + z-index: 1; |
| 159 | +} |
| 160 | +</style> |
0 commit comments