valaxy 0.17.4 → 0.18.0-beta.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.
- package/client/components/ValaxyMd.vue +1 -4
- package/client/components/builtin/ValaxyMermaid.vue +86 -0
- package/client/components/internals/ShadowRoot.vue +24 -0
- package/client/composables/common.ts +4 -2
- package/client/composables/dark.ts +3 -2
- package/client/composables/post.ts +5 -6
- package/client/constants/index.ts +0 -0
- package/client/modules/mermaid.ts +26 -0
- package/client/setup/mermaid.ts +15 -0
- package/client/setups.ts +8 -0
- package/client/stores/index.ts +1 -0
- package/client/stores/router.ts +10 -0
- package/client/stores/site.ts +8 -6
- package/client/types/index.ts +3 -0
- package/client/utils/code.ts +24 -0
- package/client/utils/index.ts +1 -0
- package/client/utils/time.ts +0 -6
- package/dist/chunk-AQGELPBR.mjs +142 -0
- package/dist/chunk-GO3LEXT4.cjs +141 -0
- package/dist/{config-hM2lXH4J.d.cts → config-qoiMoYQY.d.cts} +0 -6
- package/dist/{config-hM2lXH4J.d.ts → config-qoiMoYQY.d.ts} +0 -6
- package/dist/node/cli/index.cjs +1 -1
- package/dist/node/cli/index.mjs +1 -1
- package/dist/node/index.cjs +1 -1
- package/dist/node/index.d.cts +52 -25
- package/dist/node/index.d.ts +52 -25
- package/dist/node/index.mjs +1 -1
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.mjs +1 -1
- package/package.json +11 -9
- package/shims.d.ts +7 -1
- package/types/config.ts +0 -8
- package/types/data.ts +0 -1
- package/dist/chunk-UTVJER4P.mjs +0 -146
- package/dist/chunk-VJXQXPVC.cjs +0 -145
- /package/dist/{chunk-R4WV6S3O.mjs → chunk-MJRGR35B.mjs} +0 -0
- /package/dist/{chunk-FNMRWIFM.cjs → chunk-RWOIGW5M.cjs} +0 -0
|
@@ -45,10 +45,7 @@ useVanillaLazyLoad()
|
|
|
45
45
|
|
|
46
46
|
<template>
|
|
47
47
|
<article v-if="$slots.default" :class="frontmatter.markdown !== false && 'markdown-body'">
|
|
48
|
-
<
|
|
49
|
-
<ValaxyDecrypt :encrypted-content="frontmatter.encryptedContent" />
|
|
50
|
-
</template>
|
|
51
|
-
<slot v-else ref="contentRef" @vue:updated="runContentUpdated" />
|
|
48
|
+
<slot ref="contentRef" @vue:updated="runContentUpdated" />
|
|
52
49
|
|
|
53
50
|
<div v-if="frontmatter.url" text="center">
|
|
54
51
|
<a
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Mermaid
|
|
3
|
+
(auto transformed, you don't need to use this component directly)
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
pie
|
|
9
|
+
"Dogs" : 386
|
|
10
|
+
"Cats" : 85
|
|
11
|
+
"Rats" : 15
|
|
12
|
+
```
|
|
13
|
+
-->
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { getCurrentInstance, ref, watch, watchEffect } from 'vue'
|
|
17
|
+
|
|
18
|
+
import { isClient } from '@vueuse/core'
|
|
19
|
+
import { renderMermaid } from '../../modules/mermaid'
|
|
20
|
+
import ShadowRoot from '../internals/ShadowRoot.vue'
|
|
21
|
+
|
|
22
|
+
import { isDark } from '../../composables'
|
|
23
|
+
|
|
24
|
+
const props = defineProps<{
|
|
25
|
+
code: string
|
|
26
|
+
scale?: number
|
|
27
|
+
theme?: string
|
|
28
|
+
}>()
|
|
29
|
+
|
|
30
|
+
const vm = getCurrentInstance()
|
|
31
|
+
const el = ref<ShadowRoot>()
|
|
32
|
+
const html = ref('')
|
|
33
|
+
|
|
34
|
+
if (isClient) {
|
|
35
|
+
// dynamic import to reduce initial bundle size
|
|
36
|
+
import('mermaid').then(m => m.default)
|
|
37
|
+
.then((mermaid) => {
|
|
38
|
+
mermaid.startOnLoad = false
|
|
39
|
+
mermaid.initialize({ startOnLoad: false })
|
|
40
|
+
|
|
41
|
+
watchEffect(async (onCleanup) => {
|
|
42
|
+
let disposed = false
|
|
43
|
+
onCleanup(() => {
|
|
44
|
+
disposed = true
|
|
45
|
+
})
|
|
46
|
+
const svg = await renderMermaid(
|
|
47
|
+
mermaid,
|
|
48
|
+
props.code || '',
|
|
49
|
+
{
|
|
50
|
+
theme: props.theme || (isDark.value ? 'dark' : undefined),
|
|
51
|
+
...vm!.attrs,
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
if (!disposed)
|
|
55
|
+
html.value = svg
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const actualHeight = ref<number>()
|
|
59
|
+
|
|
60
|
+
watch(html, () => {
|
|
61
|
+
actualHeight.value = undefined
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
watchEffect(() => {
|
|
65
|
+
const svgEl = el.value?.children?.[0] as SVGElement | undefined
|
|
66
|
+
if (svgEl && svgEl.hasAttribute('viewBox') && actualHeight.value == null) {
|
|
67
|
+
const v = Number.parseFloat(svgEl.getAttribute('viewBox')?.split(' ')[3] || '')
|
|
68
|
+
actualHeight.value = Number.isNaN(v) ? undefined : v
|
|
69
|
+
}
|
|
70
|
+
}, { flush: 'post' })
|
|
71
|
+
|
|
72
|
+
watchEffect(() => {
|
|
73
|
+
const svgEl = el.value?.children?.[0] as SVGElement | undefined
|
|
74
|
+
if (svgEl != null && props.scale != null && actualHeight.value != null) {
|
|
75
|
+
svgEl.setAttribute('height', `${actualHeight.value * props.scale}`)
|
|
76
|
+
svgEl.removeAttribute('width')
|
|
77
|
+
svgEl.removeAttribute('style')
|
|
78
|
+
}
|
|
79
|
+
}, { flush: 'post' })
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<ShadowRoot class="mermaid" :inner-html="html" @shadow="el = $event" />
|
|
86
|
+
</template>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watchEffect } from 'vue'
|
|
3
|
+
|
|
4
|
+
const props = defineProps<{
|
|
5
|
+
innerHtml: string
|
|
6
|
+
}>()
|
|
7
|
+
|
|
8
|
+
const emit = defineEmits<{
|
|
9
|
+
(event: 'shadow', div: ShadowRoot): void
|
|
10
|
+
}>()
|
|
11
|
+
|
|
12
|
+
const el = ref<HTMLDivElement>()
|
|
13
|
+
const shadow = computed(() => el.value ? (el.value.shadowRoot || el.value.attachShadow({ mode: 'open' })) : null)
|
|
14
|
+
watchEffect(() => {
|
|
15
|
+
if (shadow.value && props.innerHtml) {
|
|
16
|
+
emit('shadow', shadow.value)
|
|
17
|
+
shadow.value.innerHTML = props.innerHtml
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<div ref="el" />
|
|
24
|
+
</template>
|
|
@@ -6,9 +6,11 @@ import type { PageData, Post } from 'valaxy/types'
|
|
|
6
6
|
import { useSiteConfig } from '../config'
|
|
7
7
|
|
|
8
8
|
export function useFrontmatter() {
|
|
9
|
+
// inject not in app root
|
|
9
10
|
const route = useRoute()
|
|
10
|
-
const frontmatter = computed<Post>(() =>
|
|
11
|
-
|
|
11
|
+
const frontmatter = computed<Post>(() => {
|
|
12
|
+
return route.meta.frontmatter || {}
|
|
13
|
+
})
|
|
12
14
|
return frontmatter
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { useDark, useToggle } from '@vueuse/core'
|
|
1
|
+
import { isClient, useDark, useToggle } from '@vueuse/core'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
if (isClient)
|
|
4
|
+
import('valaxy/client/styles/common/view-transition.css')
|
|
4
5
|
|
|
5
6
|
export const isDark = useDark()
|
|
6
7
|
export const toggleDark = useToggle(isDark)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ComputedRef } from 'vue'
|
|
2
2
|
import { computed } from 'vue'
|
|
3
|
-
import { useRoute
|
|
3
|
+
import { useRoute } from 'vue-router'
|
|
4
4
|
import { useI18n } from 'vue-i18n'
|
|
5
5
|
import type { Post } from 'valaxy'
|
|
6
6
|
import { sortByDate } from '../utils'
|
|
7
|
-
import { useSiteStore } from '../stores'
|
|
7
|
+
import { useRouterStore, useSiteStore } from '../stores'
|
|
8
8
|
|
|
9
9
|
export function usePostTitle(post: ComputedRef<Post>) {
|
|
10
10
|
const { locale } = useI18n()
|
|
@@ -18,12 +18,11 @@ export function usePostTitle(post: ComputedRef<Post>) {
|
|
|
18
18
|
* get all page in 'pages' folder
|
|
19
19
|
*/
|
|
20
20
|
export function usePageList() {
|
|
21
|
-
const
|
|
21
|
+
const routerStore = useRouterStore()
|
|
22
|
+
const router = routerStore.router
|
|
23
|
+
|
|
22
24
|
return computed<Post[]>(() => {
|
|
23
25
|
const excludePages = ['/:..all', '/:all(.*)*', '/', '/:path(.*)']
|
|
24
|
-
if (!router)
|
|
25
|
-
return []
|
|
26
|
-
|
|
27
26
|
const routes = router.getRoutes()
|
|
28
27
|
.filter(i => i.name)
|
|
29
28
|
.filter(i => i.meta)
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { customAlphabet } from 'nanoid'
|
|
2
|
+
import { decode } from 'js-base64'
|
|
3
|
+
import { clearUndefined } from '@antfu/utils'
|
|
4
|
+
import type { Mermaid } from 'mermaid'
|
|
5
|
+
import setupMermaid from '../setup/mermaid'
|
|
6
|
+
|
|
7
|
+
const nanoid = customAlphabet('abcedfghicklmn', 10)
|
|
8
|
+
const cache = new Map<string, string>()
|
|
9
|
+
|
|
10
|
+
export async function renderMermaid(mermaid: Mermaid, encoded: string, options: any) {
|
|
11
|
+
const key = encoded + JSON.stringify(options)
|
|
12
|
+
const _cache = cache.get(key)
|
|
13
|
+
if (_cache)
|
|
14
|
+
return _cache
|
|
15
|
+
|
|
16
|
+
mermaid.initialize({
|
|
17
|
+
startOnLoad: false,
|
|
18
|
+
...clearUndefined(setupMermaid() || {}),
|
|
19
|
+
...clearUndefined(options),
|
|
20
|
+
})
|
|
21
|
+
const code = decode(encoded)
|
|
22
|
+
const id = nanoid()
|
|
23
|
+
const { svg } = await mermaid.render(id, code)
|
|
24
|
+
cache.set(key, svg)
|
|
25
|
+
return svg
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* __imports__ */
|
|
2
|
+
|
|
3
|
+
import { defineMermaidSetup } from 'valaxy'
|
|
4
|
+
import type { MermaidOptions } from '../types'
|
|
5
|
+
|
|
6
|
+
export default defineMermaidSetup(() => {
|
|
7
|
+
// eslint-disable-next-line prefer-const
|
|
8
|
+
let injection_return: MermaidOptions = {
|
|
9
|
+
theme: 'default',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* __injections__ */
|
|
13
|
+
|
|
14
|
+
return injection_return
|
|
15
|
+
})
|
package/client/setups.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import type { ViteSSGContext } from 'vite-ssg'
|
|
2
2
|
import type { Awaitable } from '@antfu/utils'
|
|
3
|
+
import type { MermaidOptions } from './types'
|
|
3
4
|
|
|
4
5
|
export type AppContext = ViteSSGContext
|
|
5
6
|
|
|
6
7
|
export type AppSetup = (ctx: AppContext) => Awaitable<void>
|
|
7
8
|
|
|
9
|
+
// client
|
|
10
|
+
export type MermaidSetup = () => Partial<MermaidOptions> | void
|
|
11
|
+
|
|
8
12
|
export function defineAppSetup(fn: AppSetup) {
|
|
9
13
|
return fn
|
|
10
14
|
}
|
|
15
|
+
|
|
16
|
+
export function defineMermaidSetup(fn: MermaidSetup) {
|
|
17
|
+
return fn
|
|
18
|
+
}
|
package/client/stores/index.ts
CHANGED
package/client/stores/site.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { computed, ref } from 'vue'
|
|
2
2
|
import { acceptHMRUpdate, defineStore } from 'pinia'
|
|
3
|
-
import {
|
|
4
|
-
import { usePostList } from '..'
|
|
3
|
+
import { usePostList, useRouterStore } from '..'
|
|
5
4
|
import type { PageDataPayload } from '../../types'
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -11,18 +10,21 @@ import type { PageDataPayload } from '../../types'
|
|
|
11
10
|
* - category
|
|
12
11
|
*/
|
|
13
12
|
export const useSiteStore = defineStore('site', () => {
|
|
13
|
+
const routerStore = useRouterStore()
|
|
14
|
+
const router = routerStore.router
|
|
15
|
+
|
|
14
16
|
const reload = ref(1)
|
|
15
17
|
// for dev hot reload
|
|
16
18
|
const postList = computed(() => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
const val = usePostList().value
|
|
20
|
+
if (reload.value && val)
|
|
21
|
+
return val
|
|
19
22
|
else
|
|
20
|
-
return
|
|
23
|
+
return val
|
|
21
24
|
})
|
|
22
25
|
|
|
23
26
|
// const postList = usePostList()
|
|
24
27
|
|
|
25
|
-
const router = useRouter()
|
|
26
28
|
if (router) {
|
|
27
29
|
router.isReady().then(() => {
|
|
28
30
|
// hot reload when save md
|
package/client/types/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { range, uniq } from '@antfu/utils'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 1,3-5,8 => [1, 3, 4, 5, 8]
|
|
5
|
+
*/
|
|
6
|
+
export function parseRangeString(total: number, rangeStr?: string) {
|
|
7
|
+
if (!rangeStr || rangeStr === 'all' || rangeStr === '*')
|
|
8
|
+
return range(1, total + 1)
|
|
9
|
+
|
|
10
|
+
const pages: number[] = []
|
|
11
|
+
for (const part of rangeStr.split(/[,;]/g)) {
|
|
12
|
+
if (!part.includes('-')) {
|
|
13
|
+
pages.push(+part)
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const [start, end] = part.split('-', 2)
|
|
17
|
+
pages.push(
|
|
18
|
+
...range(+start, !end ? (total + 1) : (+end + 1)),
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return uniq(pages).filter(i => i <= total).sort((a, b) => a - b)
|
|
24
|
+
}
|
package/client/utils/index.ts
CHANGED
package/client/utils/time.ts
CHANGED