@slidev/client 0.37.1 → 0.38.0

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.
@@ -12,7 +12,7 @@ Learn more: https://sli.dev/guide/syntax.html#monaco-editor
12
12
  -->
13
13
 
14
14
  <script setup lang="ts">
15
- import { computed, onMounted, ref, watchEffect } from 'vue'
15
+ import { computed, onMounted, ref } from 'vue'
16
16
  import { useEventListener } from '@vueuse/core'
17
17
  import { decode } from 'js-base64'
18
18
  import { nanoid } from 'nanoid'
@@ -40,7 +40,6 @@ const id = nanoid()
40
40
  const code = ref(decode(props.code).trimEnd())
41
41
  const lineHeight = +(getComputedStyle(document.body).getPropertyValue('--slidev-code-line-height') || '18').replace('px', '') || 18
42
42
  const height = computed(() => props.height === 'auto' ? `${code.value.split(/\r?\n/g).length * lineHeight + 20}px` : props.height)
43
- const isReady = ref(false)
44
43
 
45
44
  const iframe = ref<HTMLIFrameElement>()
46
45
 
@@ -79,11 +78,6 @@ onMounted(() => {
79
78
  : `${import.meta.env.BASE_URL}iframes/monaco/index.html`
80
79
 
81
80
  frame.style.backgroundColor = 'transparent'
82
-
83
- frame.addEventListener('load', () => {
84
- postCode()
85
- isReady.value = true
86
- }, { once: true })
87
81
  })
88
82
 
89
83
  function post(payload: any) {
@@ -96,38 +90,27 @@ function post(payload: any) {
96
90
  )
97
91
  }
98
92
 
99
- function postCode() {
100
- post({
101
- code: code.value,
102
- lang: props.lang,
103
- })
104
- }
105
-
106
- function postStyle() {
107
- if (!iframe.value)
108
- return
109
- post({
110
- id,
111
- readonly: props.readonly,
112
- lineNumbers: props.lineNumbers,
113
- dark: isDark.value,
114
- style: Object.entries(getStyleObject(iframe.value)).map(([k, v]) => `${k}: ${v};`).join(''),
115
- })
116
- }
117
-
118
93
  useEventListener(window, 'message', ({ data: payload }) => {
94
+ if (payload.type === 'slidev-monaco-loaded') {
95
+ if (iframe.value) {
96
+ post({
97
+ code: code.value,
98
+ lang: props.lang,
99
+ id,
100
+ readonly: props.readonly,
101
+ lineNumbers: props.lineNumbers,
102
+ dark: isDark.value,
103
+ style: Object.entries(getStyleObject(iframe.value)).map(([k, v]) => `${k}: ${v};`).join(''),
104
+ })
105
+ }
106
+ return
107
+ }
119
108
  if (payload.type !== 'slidev-monaco' || payload.id !== id)
120
109
  return
121
110
  if (!payload?.data?.code || code.value === payload.data.code)
122
111
  return
123
112
  code.value = payload.data.code
124
113
  })
125
-
126
- watchEffect(() => {
127
- if (!isReady.value)
128
- return
129
- postStyle()
130
- })
131
114
  </script>
132
115
 
133
116
  <template>
@@ -5,7 +5,7 @@ import type { TocItem } from '../logic/nav'
5
5
  import { addToTree, filterTree, getPath, getTreeWithActiveStatuses } from '../logic/nav'
6
6
  import { rawRoutes } from '../routes'
7
7
 
8
- export function useNav(route: ComputedRef<RouteLocationNormalizedLoaded>) {
8
+ export function useNav(route: ComputedRef<RouteRecordRaw | RouteLocationNormalizedLoaded>) {
9
9
  const path = computed(() => route.value.path)
10
10
  const total = computed(() => rawRoutes.length - 1)
11
11
 
@@ -18,7 +18,7 @@ const props = {
18
18
 
19
19
  const styleObject = document.createElement('style')
20
20
  let editor: monaco.editor.IStandaloneCodeEditor
21
- let update: () => void = () => {}
21
+ let update: () => void = () => { }
22
22
 
23
23
  document.body.appendChild(styleObject)
24
24
 
@@ -146,4 +146,6 @@ window.addEventListener('message', (payload) => {
146
146
  }
147
147
  })
148
148
 
149
+ window.parent.postMessage({ type: 'slidev-monaco-loaded' }, location.origin)
150
+
149
151
  start()
@@ -49,7 +49,7 @@ provide(injectionSlidevContext, reactive({
49
49
  <GlobalBottom />
50
50
 
51
51
  <SlideWrapper
52
- :is="route?.component"
52
+ :is="route?.component!"
53
53
  v-model:clicks-elements="clicksElements"
54
54
  :clicks="clicks"
55
55
  :clicks-disabled="false"
@@ -1,14 +1,25 @@
1
1
  <script setup lang="ts">
2
- const props = defineProps<{ class?: string; url: string }>()
2
+ import { computed } from '@vue/reactivity'
3
+
4
+ const props = defineProps<{
5
+ url: string
6
+ scale?: number
7
+ }>()
8
+
9
+ const scaleInvertPercent = computed(() => `${(1 / (props.scale || 1)) * 100}%`)
3
10
  </script>
4
11
 
5
12
  <template>
6
13
  <div class="grid grid-cols-2 w-full h-full">
7
- <div class="h-full">
8
- <iframe id="frame" class="w-full h-full" :src="url" />
9
- </div>
10
- <div class="slidev-layout default" :class="props.class">
11
- <slot />
14
+ <div relative :style="{ width: scaleInvertPercent, height: scaleInvertPercent }">
15
+ <iframe
16
+ id="frame" class="w-full h-full"
17
+ :src="url"
18
+ :style="scale ? { transform: `scale(${scale})`, transformOrigin: 'top left' } : {}"
19
+ />
20
+ <div class="slidev-layout default" :class="props.class">
21
+ <slot />
22
+ </div>
12
23
  </div>
13
24
  </div>
14
25
  </template>
@@ -1,5 +1,12 @@
1
1
  <script setup lang="ts">
2
- const props = defineProps<{ class?: string; url: string }>()
2
+ import { computed } from '@vue/reactivity'
3
+
4
+ const props = defineProps<{
5
+ url: string
6
+ scale?: number
7
+ }>()
8
+
9
+ const scaleInvertPercent = computed(() => `${(1 / (props.scale || 1)) * 100}%`)
3
10
  </script>
4
11
 
5
12
  <template>
@@ -7,8 +14,12 @@ const props = defineProps<{ class?: string; url: string }>()
7
14
  <div class="slidev-layout default" :class="props.class">
8
15
  <slot />
9
16
  </div>
10
- <div class="h-full">
11
- <iframe id="frame" class="w-full h-full" :src="url" />
17
+ <div relative :style="{ width: scaleInvertPercent, height: scaleInvertPercent }">
18
+ <iframe
19
+ id="frame" class="w-full h-full"
20
+ :src="url"
21
+ :style="scale ? { transform: `scale(${scale})`, transformOrigin: 'top left' } : {}"
22
+ />
12
23
  </div>
13
24
  </div>
14
25
  </template>
@@ -20,4 +20,3 @@ const scaleInvertPercent = computed(() => `${(1 / (props.scale || 1)) * 100}%`)
20
20
  </div>
21
21
  </div>
22
22
  </template>
23
-
@@ -1,4 +1,3 @@
1
- /* eslint-disable import/default */
2
1
  import mermaid from 'mermaid/dist/mermaid'
3
2
  import { customAlphabet } from 'nanoid'
4
3
  import { decode } from 'js-base64'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slidev/client",
3
- "version": "0.37.1",
3
+ "version": "0.38.0",
4
4
  "description": "Presentation slides for developers",
5
5
  "author": "antfu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -15,35 +15,35 @@
15
15
  "node": ">=14.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "@antfu/utils": "^0.6.3",
19
- "@slidev/parser": "0.37.1",
20
- "@slidev/types": "0.37.1",
21
- "@unocss/reset": "^0.46.3",
22
- "@vueuse/core": "^9.5.0",
23
- "@vueuse/head": "^0.9.8",
24
- "@vueuse/math": "^9.5.0",
25
- "@vueuse/motion": "^2.0.0-beta.24",
18
+ "@antfu/utils": "^0.7.2",
19
+ "@unocss/reset": "^0.47.6",
20
+ "@vueuse/core": "^9.6.0",
21
+ "@vueuse/head": "^1.0.22",
22
+ "@vueuse/math": "^9.6.0",
23
+ "@vueuse/motion": "^2.0.0-beta.26",
26
24
  "codemirror": "^5.65.5",
27
- "defu": "^6.1.0",
25
+ "defu": "^6.1.1",
28
26
  "drauu": "^0.3.2",
29
27
  "file-saver": "^2.0.5",
30
- "js-base64": "^3.7.2",
28
+ "js-base64": "^3.7.3",
31
29
  "js-yaml": "^4.1.0",
32
- "katex": "^0.16.3",
33
- "mermaid": "^9.2.1",
30
+ "katex": "^0.16.4",
31
+ "mermaid": "^9.2.2",
34
32
  "monaco-editor": "^0.33.0",
35
33
  "nanoid": "^4.0.0",
36
- "prettier": "^2.7.1",
34
+ "prettier": "^2.8.1",
37
35
  "recordrtc": "^5.6.2",
38
36
  "resolve": "^1.22.1",
39
- "unocss": "^0.46.3",
40
- "vite-plugin-windicss": "^1.8.8",
41
- "vue": "^3.2.42",
37
+ "unocss": "^0.47.6",
38
+ "vite-plugin-windicss": "^1.8.9",
39
+ "vue": "^3.2.45",
42
40
  "vue-router": "^4.1.6",
43
41
  "vue-starport": "^0.3.0",
44
- "windicss": "^3.5.6"
42
+ "windicss": "^3.5.6",
43
+ "@slidev/parser": "0.38.0",
44
+ "@slidev/types": "0.38.0"
45
45
  },
46
46
  "devDependencies": {
47
- "vite": "^3.2.3"
47
+ "vite": "^4.0.1"
48
48
  }
49
49
  }
@@ -48,7 +48,14 @@ export default function setupShortcuts() {
48
48
  { name: 'prev_overview', key: and(left, showOverview), fn: prevOverviewPage },
49
49
  { name: 'up_overview', key: and(up, showOverview), fn: upOverviewPage },
50
50
  { name: 'down_overview', key: and(down, showOverview), fn: downOverviewPage },
51
- { name: 'goto_from_overview', key: and(enter, showOverview), fn: () => { go(currentOverviewPage.value); showOverview.value = false } },
51
+ {
52
+ name: 'goto_from_overview',
53
+ key: and(enter, showOverview),
54
+ fn: () => {
55
+ go(currentOverviewPage.value)
56
+ showOverview.value = false
57
+ },
58
+ },
52
59
  ]
53
60
 
54
61
  const baseShortcutNames = new Set(injection_return.map(s => s.name))