vitepress-plugin-artalk 0.1.1 → 0.1.3

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.
@@ -28,10 +28,13 @@ const commentConfig = computed(() => {
28
28
  const route = useRoute()
29
29
  const artalk = ref<Artalk>()
30
30
  const artalkContainer = ref<HTMLDivElement>()
31
+ let artalkObserver: MutationObserver | undefined
31
32
 
32
33
  function initArtalk() {
33
- // CDN 异步加载,有优化空间
34
- const observer = new MutationObserver((mutationsList, observer) => {
34
+ const doInit = () => {
35
+ if (artalk.value) {
36
+ return true
37
+ }
35
38
  // @ts-expect-error
36
39
  if (window.Artalk && commentConfig.value && artalkContainer.value) {
37
40
  // @ts-expect-error
@@ -44,11 +47,22 @@ function initArtalk() {
44
47
  site: commentConfig.value?.site,
45
48
  ...commentConfig.value
46
49
  })
47
- observer.disconnect()
50
+ return true
51
+ }
52
+ return false
53
+ }
54
+
55
+ if (doInit()) return
56
+
57
+ artalkObserver?.disconnect()
58
+ artalkObserver = new MutationObserver(() => {
59
+ if (doInit()) {
60
+ artalkObserver?.disconnect()
61
+ artalkObserver = undefined
48
62
  }
49
63
  })
50
64
 
51
- observer.observe(document.head, { subtree: true, childList: true, attributes: true, attributeFilter: ['id'] })
65
+ artalkObserver.observe(document.head, { subtree: true, childList: true })
52
66
  }
53
67
 
54
68
  watch(() => route.path, () => {
@@ -62,6 +76,8 @@ watch(() => route.path, () => {
62
76
  })
63
77
 
64
78
  onUnmounted(() => {
79
+ artalkObserver?.disconnect()
80
+ artalkObserver = undefined
65
81
  if (artalk.value) {
66
82
  artalk.value.destroy()
67
83
  }
@@ -21,6 +21,7 @@ const size = computed(() => props.size && (typeof props.size === 'number' ? `${p
21
21
  --color: inherit;
22
22
  align-items: center;
23
23
  display: inline-flex;
24
+ flex-shrink: 0;
24
25
  height: 1em;
25
26
  justify-content: center;
26
27
  line-height: 1em;
@@ -30,4 +31,9 @@ const size = computed(() => props.size && (typeof props.size === 'number' ? `${p
30
31
  color: var(--color);
31
32
  font-size: inherit;
32
33
  }
34
+ .sugar-theme-icon :deep(svg) {
35
+ width: 1em;
36
+ height: 1em;
37
+ flex-shrink: 0;
38
+ }
33
39
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitepress-plugin-artalk",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "vitepress plugin artalk",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/components/util.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,eAAe,CAAA;AACvC,MAAM,mBAAmB,GAAG,SAAS,CAAA;AACrC,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAEvC,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,GAAG,GAAoC,EAAE,CAAA;IAC/C,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1E,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAA;YAC3C,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QACxD,CAAC;IACH,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,aAAa,CAAoC,EAAK,EAAE,KAAa;IACnF,IAAI,KAAU,CAAA;IACd,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,YAAY,CAAC,KAAK,CAAC,CAAA;QACnB,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,EAAE,CAAC,GAAG,IAAI,CAAC,CAAA;QACb,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,QAAQ,KAAK,WAAW,CAAA"}