valaxy 0.15.12 → 0.15.13

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,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import { onMounted, onUpdated, ref } from 'vue'
3
3
  import { useI18n } from 'vue-i18n'
4
- import { onContentUpdated, runContentUpdated, useAplayer, useCodePen, useCopyCode, useMediumZoom, wrapTable } from 'valaxy'
4
+ import { onContentUpdated, runContentUpdated, useAplayer, useCodePen, useCollapseCode, useCopyCode, useMediumZoom, wrapTable } from 'valaxy'
5
5
  import type { Post } from 'valaxy'
6
6
  import { useVanillaLazyLoad } from '../composables/features/vanilla-lazyload'
7
7
  import { useCodeGroups } from '../composables/codeGroups'
@@ -35,6 +35,7 @@ if (props.frontmatter.codepen)
35
35
 
36
36
  useCopyCode()
37
37
  useCodeGroups()
38
+ useCollapseCode()
38
39
 
39
40
  if (typeof props.frontmatter.medium_zoom === 'undefined' || props.frontmatter.medium_zoom)
40
41
  useMediumZoom()
@@ -0,0 +1,42 @@
1
+ import { isClient } from '@vueuse/core'
2
+ import { onMounted } from 'vue'
3
+ import { useFrontmatter, useSiteConfig } from 'valaxy'
4
+
5
+ export function useCollapseCode() {
6
+ const config = useSiteConfig()
7
+ const frontmatter = useFrontmatter()
8
+
9
+ if (isClient) {
10
+ window.addEventListener('click', (e) => {
11
+ const el = e.target as HTMLElement
12
+ if (el.matches('[class*="language-"] > button.collapse')) {
13
+ const parent = el.parentElement
14
+ parent?.removeAttribute('style')
15
+ parent?.classList.remove('folded')
16
+ }
17
+ })
18
+ }
19
+
20
+ // determine whether to add folded class name
21
+ onMounted(() => {
22
+ const els = document.querySelectorAll('div[class*="language-"]')
23
+ const siteConfigLimit = config.value.codeHeightLimit
24
+ const frontmatterLimit = frontmatter.value.codeHeightLimit
25
+ let codeHeightLimit: number
26
+
27
+ if (typeof frontmatterLimit !== 'number' || frontmatterLimit <= 0) {
28
+ if (siteConfigLimit === undefined || siteConfigLimit <= 0)
29
+ return
30
+ else
31
+ codeHeightLimit = siteConfigLimit
32
+ }
33
+ else {
34
+ codeHeightLimit = frontmatterLimit
35
+ }
36
+
37
+ for (const el of Array.from(els)) {
38
+ if (el.scrollHeight > codeHeightLimit)
39
+ el.classList.add('folded')
40
+ }
41
+ })
42
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './copy-code'
2
2
  export * from './medium-zoom'
3
+ export * from './collapse-code'
@@ -5,6 +5,7 @@ import { useSiteConfig } from '../..'
5
5
 
6
6
  /**
7
7
  * use MetingJS and Aplayer
8
+ * @deprecated will migrate to valaxy-addon-meting
8
9
  * @see https://github.com/MoePlayer/APlayer
9
10
  * @see https://github.com/metowolf/MetingJS
10
11
  */
@@ -38,6 +38,7 @@ html:not(.dark) .vp-code-dark {
38
38
  }
39
39
 
40
40
  div[class*="language-"] {
41
+ overflow-y: hidden;
41
42
  position: relative;
42
43
  background-color: var(--va-code-block-bg);
43
44
  overflow-x: auto;
@@ -220,4 +221,33 @@ html:not(.dark) .vp-code-dark {
220
221
  content: '+';
221
222
  color: var(--va-code-line-diff-add-symbol-color);
222
223
  }
224
+
225
+ // collapse
226
+ [class*='language-'] > button.collapse {
227
+ display: none;
228
+ position: absolute;
229
+ z-index: 10;
230
+ bottom: 0;
231
+ left: 0;
232
+ width: 100%;
233
+ height: 24px;
234
+ opacity: 1;
235
+ cursor: pointer;
236
+ background-image: linear-gradient(-180deg,rgba(0,0,0,0) 0%,var(--va-c-bg-dark) 100%);
237
+
238
+ &::before {
239
+ display: block;
240
+ content: '';
241
+ width: 100%;
242
+ height: 100%;
243
+ background-image: var(--va-icon-collapse);
244
+ background-position: 50%;
245
+ background-size: 16px;
246
+ background-repeat: no-repeat;
247
+ }
248
+ }
249
+
250
+ [class*='language-'].folded > button.collapse {
251
+ display: block;
252
+ }
223
253
  }
@@ -114,6 +114,7 @@ $c-primary: #0078e7 !default;
114
114
  :root {
115
115
  --va-icon-copy: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' height='20' width='20' stroke='rgba(128,128,128,1)' stroke-width='2' class='h-6 w-6' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2'/%3E%3C/svg%3E");
116
116
  --va-icon-copied: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' height='20' width='20' stroke='rgba(128,128,128,1)' stroke-width='2' class='h-6 w-6' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2m-6 9 2 2 4-4'/%3E%3C/svg%3E");
117
+ --va-icon-collapse: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='32'%20height='32' stroke='rgba(128,128,128,1)' viewBox='0%200%2024%2024'%3E%3Cpath%20fill='currentColor'%20d='m12%2016.175l3.9-3.875q.275-.275.688-.288t.712.288q.275.275.275.7t-.275.7l-4.6%204.6q-.15.15-.325.213t-.375.062q-.2%200-.375-.063T11.3%2018.3l-4.6-4.6q-.275-.275-.288-.687T6.7%2012.3q.275-.275.7-.275t.7.275l3.9%203.875Zm0-6L15.9%206.3q.275-.275.688-.287t.712.287q.275.275.275.7t-.275.7l-4.6%204.6q-.15.15-.325.213t-.375.062q-.2%200-.375-.062T11.3%2012.3L6.7%207.7q-.275-.275-.288-.688T6.7%206.3q.275-.275.7-.275t.7.275l3.9%203.875Z'/%3E%3C/svg%3E")
117
118
  }
118
119
 
119
120
  /**