index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="thumbnail-slide"
  3. :style="{
  4. width: size + 'px',
  5. height: size * VIEWPORT_ASPECT_RATIO + 'px',
  6. }"
  7. >
  8. <div
  9. class="elements-wrapper"
  10. :style="{
  11. width: VIEWPORT_SIZE + 'px',
  12. height: VIEWPORT_SIZE * VIEWPORT_ASPECT_RATIO + 'px',
  13. transform: `scale(${scale})`,
  14. }"
  15. >
  16. <div class="background" :style="{ ...backgroundStyle }"></div>
  17. <ThumbnailElement
  18. v-for="(element, index) in slide.elements"
  19. :key="element.id"
  20. :elementInfo="element"
  21. :elementIndex="index + 1"
  22. />
  23. </div>
  24. </div>
  25. </template>
  26. <script lang="ts">
  27. import { computed, PropType, defineComponent, provide } from 'vue'
  28. import { Slide } from '@/types/slides'
  29. import { VIEWPORT_SIZE, VIEWPORT_ASPECT_RATIO } from '@/configs/canvas'
  30. import useSlideBackgroundStyle from '@/hooks/useSlideBackgroundStyle'
  31. import ThumbnailElement from './ThumbnailElement.vue'
  32. export default defineComponent({
  33. name: 'thumbnail-slide',
  34. components: {
  35. ThumbnailElement,
  36. },
  37. props: {
  38. slide: {
  39. type: Object as PropType<Slide>,
  40. required: true,
  41. },
  42. size: {
  43. type: Number,
  44. required: true,
  45. },
  46. },
  47. setup(props) {
  48. const background = computed(() => props.slide.background)
  49. const { backgroundStyle } = useSlideBackgroundStyle(background)
  50. const scale = computed(() => props.size / VIEWPORT_SIZE)
  51. provide('scale', 1)
  52. return {
  53. scale,
  54. backgroundStyle,
  55. VIEWPORT_SIZE,
  56. VIEWPORT_ASPECT_RATIO,
  57. }
  58. },
  59. })
  60. </script>
  61. <style lang="scss" scoped>
  62. .thumbnail-slide {
  63. background-color: #fff;
  64. overflow: hidden;
  65. }
  66. .elements-wrapper {
  67. transform-origin: 0 0;
  68. }
  69. .background {
  70. width: 100%;
  71. height: 100%;
  72. background-position: center;
  73. position: absolute;
  74. }
  75. </style>