@tnotesjs/core 0.1.27 → 0.2.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.
Files changed (71) hide show
  1. package/README.md +2 -1
  2. package/package.json +3 -1
  3. package/templates/sub-repo/.gitattributes +30 -0
  4. package/templates/sub-repo/.github/workflows/deploy.yml +87 -0
  5. package/templates/sub-repo/.vitepress/config.mts +12 -0
  6. package/templates/sub-repo/.vitepress/env.d.ts +10 -0
  7. package/templates/sub-repo/.vitepress/theme/index.ts +12 -0
  8. package/templates/sub-repo/.vscode/settings.json +330 -0
  9. package/templates/sub-repo/.vscode/tnotes.code-snippets +110 -0
  10. package/templates/sub-repo/public/favicon.ico +0 -0
  11. package/templates/sub-repo/public/logo.png +0 -0
  12. package/templates/sub-repo/tsconfig.json +45 -0
  13. package/vitepress/assets/icons/icon__setting_dark.svg +4 -0
  14. package/vitepress/assets/icons/icon__setting_light.svg +4 -0
  15. package/vitepress/assets/icons/index.ts +2 -2
  16. package/vitepress/client/localSearchIndexBridge.ts +24 -0
  17. package/vitepress/components/Discussions/Discussions.vue +1 -1
  18. package/vitepress/components/Footprints/Footprints.vue +90 -25
  19. package/vitepress/components/Layout/CustomSidebar.vue +489 -117
  20. package/vitepress/components/Layout/Layout.vue +5 -0
  21. package/vitepress/components/Layout/NavBarSettingsTrigger.vue +10 -2
  22. package/vitepress/components/Layout/SidebarItems.vue +517 -342
  23. package/vitepress/components/Layout/SidebarNavBefore.vue +1 -50
  24. package/vitepress/components/Layout/SidebarResizeHandle.vue +6 -23
  25. package/vitepress/components/Layout/composables/docLayoutLogic.ts +59 -0
  26. package/vitepress/components/Layout/composables/useDocLayout.test.ts +69 -0
  27. package/vitepress/components/Layout/composables/useDocLayout.ts +128 -0
  28. package/vitepress/components/Layout/composables/useSidebarDrag.ts +514 -0
  29. package/vitepress/components/Layout/composables/useSidebarLayout.ts +25 -8
  30. package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +8 -3
  31. package/vitepress/components/Layout/sidebarCollapsedState.test.ts +183 -0
  32. package/vitepress/components/Layout/sidebarCollapsedState.ts +241 -0
  33. package/vitepress/components/Layout/sidebarDragLogic.test.ts +1146 -0
  34. package/vitepress/components/Layout/sidebarDragLogic.ts +1307 -0
  35. package/vitepress/components/Layout/sidebarHitTest.test.ts +572 -0
  36. package/vitepress/components/Layout/sidebarHitTest.ts +801 -0
  37. package/vitepress/components/Layout/sidebarItemRenderLogic.test.ts +53 -0
  38. package/vitepress/components/Layout/sidebarItemRenderLogic.ts +50 -0
  39. package/vitepress/components/MarkMap/MarkMap.vue +67 -10
  40. package/vitepress/components/Settings/Settings.vue +78 -74
  41. package/vitepress/components/SidebarCard/FolderTreeItems.vue +268 -0
  42. package/vitepress/components/SidebarCard/SidebarCard.vue +125 -274
  43. package/vitepress/components/constants.ts +18 -6
  44. package/vitepress/components/sidebar.data.ts +13 -11
  45. package/vitepress/components/sidebarTreeHelpers.test.ts +142 -0
  46. package/vitepress/components/sidebarTreeHelpers.ts +168 -0
  47. package/vitepress/components/utils/vscodePaths.test.ts +41 -0
  48. package/vitepress/components/utils/vscodePaths.ts +52 -0
  49. package/vitepress/config/index.ts +2 -0
  50. package/vitepress/plugins/localSearchIndexBuilder.ts +209 -0
  51. package/vitepress/plugins/localSearchReindex.test.ts +46 -0
  52. package/vitepress/plugins/localSearchReindexLogic.ts +50 -0
  53. package/vitepress/plugins/localSearchReindexPatch.test.ts +30 -0
  54. package/vitepress/plugins/localSearchReindexPatch.ts +37 -0
  55. package/vitepress/plugins/localSearchReindexPlugin.ts +318 -0
  56. package/vitepress/plugins/sidebarStructurePlugin.ts +209 -63
  57. package/vitepress/theme/index.ts +8 -0
  58. package/vitepress/theme/styles/base.scss +0 -8
  59. package/vitepress/theme/styles/components/markmap.scss +23 -2
  60. package/vitepress/theme/styles/components/swiper.scss +1 -1
  61. package/vitepress/theme/styles/doc-layout.scss +212 -0
  62. package/vitepress/theme/styles/index.scss +3 -0
  63. package/vitepress/theme/styles/layout.scss +60 -10
  64. package/dist/chunk-4KG6RXFS.js +0 -4637
  65. package/dist/chunk-AGSL3VZE.js +0 -193
  66. package/dist/cli/index.js +0 -683
  67. package/dist/index.js +0 -8
  68. package/dist/vitepress/config/index.js +0 -1178
  69. package/vitepress/assets/icons/icon__mindmap.svg +0 -1
  70. package/vitepress/assets/icons/icon__setting.svg +0 -1
  71. package/vitepress/components/SidebarCard/MindMapView.vue +0 -488
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
2
+ <path d="M0 0h24v24H0z" fill="none" />
3
+ <path fill="#98989f" d="M19.9 12.66a1 1 0 0 1 0-1.32l1.28-1.44a1 1 0 0 0 .12-1.17l-2-3.46a1 1 0 0 0-1.07-.48l-1.88.38a1 1 0 0 1-1.15-.66l-.61-1.83a1 1 0 0 0-.95-.68h-4a1 1 0 0 0-1 .68l-.56 1.83a1 1 0 0 1-1.15.66L5 4.79a1 1 0 0 0-1 .48L2 8.73a1 1 0 0 0 .1 1.17l1.27 1.44a1 1 0 0 1 0 1.32L2.1 14.1a1 1 0 0 0-.1 1.17l2 3.46a1 1 0 0 0 1.07.48l1.88-.38a1 1 0 0 1 1.15.66l.61 1.83a1 1 0 0 0 1 .68h4a1 1 0 0 0 .95-.68l.61-1.83a1 1 0 0 1 1.15-.66l1.88.38a1 1 0 0 0 1.07-.48l2-3.46a1 1 0 0 0-.12-1.17ZM18.41 14l.8.9l-1.28 2.22l-1.18-.24a3 3 0 0 0-3.45 2L12.92 20h-2.56L10 18.86a3 3 0 0 0-3.45-2l-1.18.24l-1.3-2.21l.8-.9a3 3 0 0 0 0-4l-.8-.9l1.28-2.2l1.18.24a3 3 0 0 0 3.45-2L10.36 4h2.56l.38 1.14a3 3 0 0 0 3.45 2l1.18-.24l1.28 2.22l-.8.9a3 3 0 0 0 0 3.98m-6.77-6a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2" />
4
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
2
+ <path d="M0 0h24v24H0z" fill="none" />
3
+ <path fill="#3c3c43" d="M19.9 12.66a1 1 0 0 1 0-1.32l1.28-1.44a1 1 0 0 0 .12-1.17l-2-3.46a1 1 0 0 0-1.07-.48l-1.88.38a1 1 0 0 1-1.15-.66l-.61-1.83a1 1 0 0 0-.95-.68h-4a1 1 0 0 0-1 .68l-.56 1.83a1 1 0 0 1-1.15.66L5 4.79a1 1 0 0 0-1 .48L2 8.73a1 1 0 0 0 .1 1.17l1.27 1.44a1 1 0 0 1 0 1.32L2.1 14.1a1 1 0 0 0-.1 1.17l2 3.46a1 1 0 0 0 1.07.48l1.88-.38a1 1 0 0 1 1.15.66l.61 1.83a1 1 0 0 0 1 .68h4a1 1 0 0 0 .95-.68l.61-1.83a1 1 0 0 1 1.15-.66l1.88.38a1 1 0 0 0 1.07-.48l2-3.46a1 1 0 0 0-.12-1.17ZM18.41 14l.8.9l-1.28 2.22l-1.18-.24a3 3 0 0 0-3.45 2L12.92 20h-2.56L10 18.86a3 3 0 0 0-3.45-2l-1.18.24l-1.3-2.21l.8-.9a3 3 0 0 0 0-4l-.8-.9l1.28-2.2l1.18.24a3 3 0 0 0 3.45-2L10.36 4h2.56l.38 1.14a3 3 0 0 0 3.45 2l1.18-.24l1.28 2.22l-.8.9a3 3 0 0 0 0 3.98m-6.77-6a4 4 0 1 0 4 4a4 4 0 0 0-4-4m0 6a2 2 0 1 1 2-2a2 2 0 0 1-2 2" />
4
+ </svg>
@@ -20,7 +20,6 @@ export { default as icon__folder } from './icon__folder.svg'
20
20
  export { default as icon__fullscreen } from './icon__fullscreen.svg'
21
21
  export { default as icon__fullscreen_exit } from './icon__fullscreen_exit.svg'
22
22
  export { default as icon__github } from './icon__github.svg'
23
- export { default as icon__mindmap } from './icon__mindmap.svg'
24
23
  export { default as icon__next } from './icon__next.svg'
25
24
  export { default as icon__number_gray } from './icon__number_gray.svg'
26
25
  export { default as icon__number_purple } from './icon__number_purple.svg'
@@ -28,7 +27,8 @@ export { default as icon__prev } from './icon__prev.svg'
28
27
  export { default as icon__restore } from './icon__restore.svg'
29
28
  export { default as icon__rotate } from './icon__rotate.svg'
30
29
  export { default as icon__search } from './icon__search.svg'
31
- export { default as icon__setting } from './icon__setting.svg'
30
+ export { default as icon__setting_dark } from './icon__setting_dark.svg'
31
+ export { default as icon__setting_light } from './icon__setting_light.svg'
32
32
  export { default as icon__sidebar_collapsed } from './icon__sidebar_collapsed.svg'
33
33
  export { default as icon__sidebar_opened } from './icon__sidebar_opened.svg'
34
34
  export { default as icon__totop } from './icon__totop.svg'
@@ -0,0 +1,24 @@
1
+ /**
2
+ * localSearchIndexBridge.ts
3
+ *
4
+ * dev 下 Local Search HMR:仅 remount 搜索框,不替换 VP 索引加载逻辑。
5
+ */
6
+
7
+ import { shallowRef } from 'vue'
8
+
9
+ export const SEARCH_INDEX_HMR_EVENT = 'tnotes:search-index-updated'
10
+
11
+ /** 变更 searchIndex 后递增,强制 remount VPLocalSearchBox 以重新 import 索引 */
12
+ export const searchBoxRemountKey = shallowRef(0)
13
+
14
+ let hmrInitialized = false
15
+
16
+ export function initTnotesSearchIndexHmr(): void {
17
+ if (typeof window === 'undefined') return
18
+ if (!import.meta.hot || hmrInitialized) return
19
+ hmrInitialized = true
20
+
21
+ import.meta.hot.on(SEARCH_INDEX_HMR_EVENT, () => {
22
+ searchBoxRemountKey.value += 1
23
+ })
24
+ }
@@ -148,7 +148,7 @@ const loadGiscusScript = () => {
148
148
  giscusScript.setAttribute('data-emit-metadata', '0')
149
149
  giscusScript.setAttribute('data-input-position', 'top')
150
150
  giscusScript.setAttribute('data-lang', 'zh-CN')
151
- giscusScript.setAttribute('data-loading', 'lazy')
151
+ giscusScript.setAttribute('data-loading', 'eager')
152
152
  giscusScript.setAttribute(
153
153
  'data-theme',
154
154
  isDark.value ? GISCUS_DARK_THEME : GISCUS_LIGHT_THEME
@@ -3,6 +3,7 @@ vitepress/components/Footprints/Footprints.vue
3
3
  -->
4
4
 
5
5
  <script setup>
6
+ import { onContentUpdated } from 'vitepress'
6
7
  import { ref, onMounted, onBeforeUnmount, computed, nextTick } from 'vue'
7
8
 
8
9
  // ----------------------------------------------------------
@@ -13,6 +14,28 @@ import { ref, onMounted, onBeforeUnmount, computed, nextTick } from 'vue'
13
14
  */
14
15
  const imageContainer = ref(null)
15
16
 
17
+ /**
18
+ * 图片数量,用于朋友圈式网格布局(1 / 2 / 4 / 3 列)
19
+ */
20
+ const imageCount = ref(0)
21
+
22
+ const imageLayoutClass = computed(() => {
23
+ const n = imageCount.value
24
+ if (n === 1) return 'fp-layout-1'
25
+ if (n === 2) return 'fp-layout-2'
26
+ if (n === 4) return 'fp-layout-4'
27
+ if (n >= 3) return 'fp-layout-grid'
28
+ return ''
29
+ })
30
+
31
+ function initImageList() {
32
+ if (!imageContainer.value) return
33
+
34
+ const imgElements = imageContainer.value.querySelectorAll('img')
35
+ imageCount.value = imgElements.length
36
+ images.value = Array.from(imgElements).map((img) => img.src)
37
+ }
38
+
16
39
  /**
17
40
  * 动态存储图片路径的列表
18
41
  */
@@ -169,27 +192,16 @@ const handleMouseUp = () => {
169
192
  }
170
193
 
171
194
  onMounted(() => {
172
- const imgElements = imageContainer.value.querySelectorAll('img')
173
- images.value = Array.from(imgElements).map((img) => img.src)
195
+ nextTick(() => {
196
+ initImageList()
197
+ })
174
198
 
175
199
  // 添加键盘事件监听器
176
200
  window.addEventListener('keydown', handleKeyDown)
201
+ })
177
202
 
178
- // 添加触摸事件监听器
179
- const modalContent = document.querySelector(
180
- `.__dynamic__modal-content-${instanceId}`
181
- )
182
- if (modalContent) {
183
- modalContent.addEventListener('touchstart', handleTouchStart)
184
- modalContent.addEventListener('touchmove', handleTouchMove) // 绑定 touchmove 事件
185
- modalContent.addEventListener('touchend', (event) => {
186
- touchEndX = event.changedTouches[0].clientX // 记录手指抬起的最终位置
187
- handleTouchEnd()
188
- })
189
-
190
- // 添加鼠标事件监听器
191
- modalContent.addEventListener('mousedown', handleMouseDown)
192
- }
203
+ onContentUpdated(() => {
204
+ nextTick(initImageList)
193
205
  })
194
206
 
195
207
  onBeforeUnmount(() => {
@@ -352,7 +364,11 @@ const formattedTime = computed(() => {
352
364
  </button>
353
365
  </div>
354
366
 
355
- <div class="imageContainer" ref="imageContainer">
367
+ <div
368
+ class="imageContainer"
369
+ :class="imageLayoutClass"
370
+ ref="imageContainer"
371
+ >
356
372
  <slot
357
373
  name="image-list"
358
374
  :openModal="openModal"
@@ -422,18 +438,67 @@ const formattedTime = computed(() => {
422
438
  }
423
439
  }
424
440
 
425
- // 图片容器
441
+ // 图片容器(朋友圈式网格:Markdown 图片常被包在 p/a 中,需 grid + :deep)
426
442
  .imageContainer {
427
- display: flex;
443
+ display: grid;
444
+ gap: 4px;
428
445
  width: 100%;
429
- flex-wrap: wrap;
430
446
 
431
- img {
432
- width: calc(33.33% - 10px);
433
- aspect-ratio: 1; // 设置宽高比为 1:1
447
+ :deep(> *) {
448
+ margin: 0;
449
+ min-width: 0;
450
+ }
451
+
452
+ :deep(p) {
453
+ margin: 0;
454
+ line-height: 0;
455
+ }
456
+
457
+ :deep(a) {
458
+ display: block;
459
+ line-height: 0;
460
+ }
461
+
462
+ :deep(img) {
463
+ width: 100%;
464
+ aspect-ratio: 1;
434
465
  object-fit: cover;
466
+ display: block;
467
+ margin: 0;
435
468
  cursor: pointer;
436
- margin: 0.3rem;
469
+ vertical-align: top;
470
+ }
471
+
472
+ /* 1 张:较大单图,不强制正方形 */
473
+ &.fp-layout-1 {
474
+ grid-template-columns: 1fr;
475
+ max-width: 280px;
476
+
477
+ :deep(img) {
478
+ width: auto;
479
+ max-width: 100%;
480
+ max-height: 360px;
481
+ aspect-ratio: auto;
482
+ object-fit: cover;
483
+ }
484
+ }
485
+
486
+ /* 2 张:一行两列 */
487
+ &.fp-layout-2 {
488
+ grid-template-columns: repeat(2, 1fr);
489
+ max-width: 360px;
490
+ }
491
+
492
+ /* 4 张:2×2 */
493
+ &.fp-layout-4 {
494
+ grid-template-columns: repeat(2, 1fr);
495
+ max-width: 360px;
496
+ }
497
+
498
+ /* 3 / 5–9 张:三列网格 */
499
+ &.fp-layout-grid {
500
+ grid-template-columns: repeat(3, 1fr);
501
+ max-width: 480px;
437
502
  }
438
503
  }
439
504