@slidev/client 0.47.3 → 0.47.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,48 @@
1
1
  <script setup lang="ts">
2
- import { computed, inject } from 'vue'
3
2
  import type { RenderContext } from '@slidev/types'
4
-
3
+ import { computed, inject, ref } from 'vue'
4
+ import { useElementVisibility } from '@vueuse/core'
5
5
  import { injectionRenderContext } from '../constants'
6
6
 
7
- type Context = 'main' | RenderContext
7
+ type Context = 'main' | 'visible' | RenderContext
8
8
 
9
9
  const props = defineProps<{
10
10
  context: Context | Context[]
11
11
  }>()
12
12
  const { context } = props
13
+ const target = ref(null)
14
+ const targetVisible = useElementVisibility(target)
13
15
 
14
- const currentContext = inject(injectionRenderContext)
16
+ // When context has `visible`, we need to wrap the content with a div to track the visibility
17
+ const needsDomWrapper = Array.isArray(context) ? context.includes('visible') : context === 'visible'
15
18
 
16
- const shouldRender = computed(() => Array.isArray(context) ? context.some(contextMatch) : contextMatch(context))
19
+ const currentContext = inject(injectionRenderContext)
20
+ const shouldRender = computed(() => {
21
+ const anyContext = Array.isArray(context) ? context.some(contextMatch) : contextMatch(context)
22
+ const allConditions = Array.isArray(context) ? context.every(conditionsMatch) : conditionsMatch(context)
23
+ return anyContext && allConditions
24
+ })
17
25
 
18
26
  function contextMatch(context: Context) {
19
27
  if (context === currentContext?.value)
20
28
  return true
21
29
  if (context === 'main' && (currentContext?.value === 'slide' || currentContext?.value === 'presenter'))
22
30
  return true
31
+ if (context === 'visible')
32
+ return true
23
33
  return false
24
34
  }
35
+
36
+ function conditionsMatch(context: Context) {
37
+ if (context === 'visible')
38
+ return targetVisible.value
39
+ return true
40
+ }
25
41
  </script>
26
42
 
27
43
  <template>
28
- <slot v-if="shouldRender" />
44
+ <div v-if="needsDomWrapper" ref="target">
45
+ <slot v-if="shouldRender" />
46
+ </div>
47
+ <slot v-else-if="shouldRender" />
29
48
  </template>
@@ -5,7 +5,7 @@ body,
5
5
  margin: 0;
6
6
  background: var(--slidev-code-background);
7
7
  width: 100%;
8
- height: 100%;
8
+ height: 200%;
9
9
  }
10
10
 
11
11
  #container {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/client",
3
- "version": "0.47.3",
3
+ "version": "0.47.4",
4
4
  "description": "Presentation slides for developers",
5
5
  "author": "antfu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -46,8 +46,8 @@
46
46
  "unocss": "^0.58.5",
47
47
  "vue": "^3.4.15",
48
48
  "vue-router": "^4.2.5",
49
- "@slidev/parser": "0.47.3",
50
- "@slidev/types": "0.47.3"
49
+ "@slidev/parser": "0.47.4",
50
+ "@slidev/types": "0.47.4"
51
51
  },
52
52
  "devDependencies": {
53
53
  "vite": "^5.0.12"