hexo-theme-shokax 0.5.2-hotfix.2 → 0.5.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.
Files changed (160) hide show
  1. package/.vscode/settings.json +5 -5
  2. package/CODE_OF_CONDUCT.md +128 -128
  3. package/LICENSE +660 -660
  4. package/LICENSE-shoka +21 -21
  5. package/README.md +74 -74
  6. package/UsageRestrictions.md +25 -25
  7. package/_config.yml +359 -352
  8. package/languages/README.md +19 -19
  9. package/languages/default.yml +1 -1
  10. package/languages/en.yml +155 -155
  11. package/languages/ja.yml +155 -155
  12. package/languages/zh-CN.yml +155 -155
  13. package/languages/zh-HK.yml +155 -155
  14. package/languages/zh-TW.yml +155 -155
  15. package/layout/_alternate/atom.ejs +30 -30
  16. package/layout/_alternate/json.ejs +16 -16
  17. package/layout/_alternate/rss.ejs +34 -34
  18. package/layout/_mixin/breadcrumb.pug +33 -33
  19. package/layout/_mixin/card.pug +37 -37
  20. package/layout/_mixin/comment.pug +6 -6
  21. package/layout/_mixin/postmeta.pug +29 -29
  22. package/layout/_mixin/segment.pug +35 -35
  23. package/layout/_mixin/sidebar.pug +40 -40
  24. package/layout/_mixin/widgets.pug +28 -28
  25. package/layout/_partials/footer.pug +43 -43
  26. package/layout/_partials/head/head.pug +50 -50
  27. package/layout/_partials/head/head_com.pug +24 -24
  28. package/layout/_partials/head/pwa.pug +18 -18
  29. package/layout/_partials/header.pug +18 -18
  30. package/layout/_partials/layout.pug +138 -137
  31. package/layout/_partials/loading.pug +13 -13
  32. package/layout/_partials/pagination.pug +4 -4
  33. package/layout/_partials/post/copyright.pug +20 -20
  34. package/layout/_partials/post/footer.pug +20 -20
  35. package/layout/_partials/post/nav.pug +17 -17
  36. package/layout/_partials/post/post.pug +42 -42
  37. package/layout/_partials/post/reward.pug +18 -18
  38. package/layout/_partials/sidebar/menu.pug +37 -37
  39. package/layout/_partials/sidebar/overview.pug +42 -42
  40. package/layout/_partials/third-party/baidu-analytics.pug +11 -11
  41. package/layout/_partials/third-party/clarity.pug +8 -8
  42. package/layout/_partials/third-party/google-analytics.pug +9 -9
  43. package/layout/archive.pug +121 -121
  44. package/layout/category.pug +62 -62
  45. package/layout/index.pug +36 -36
  46. package/layout/page.pug +60 -60
  47. package/layout/post.pug +42 -42
  48. package/layout/tag.pug +46 -46
  49. package/package.json +6 -5
  50. package/scripts/generaters/script.js +2 -1
  51. package/source/assets/algolia_logo.svg +9 -9
  52. package/source/assets/logo.svg +16 -16
  53. package/source/css/_colors.styl +207 -207
  54. package/source/css/_common/components/components.styl +5 -5
  55. package/source/css/_common/components/pages/collapse.styl +119 -119
  56. package/source/css/_common/components/pages/home.styl +391 -391
  57. package/source/css/_common/components/pages/pages.styl +56 -56
  58. package/source/css/_common/components/pages/tag-cloud.styl +12 -12
  59. package/source/css/_common/components/post/breadcrumb.styl +39 -39
  60. package/source/css/_common/components/post/copyright.styl +41 -41
  61. package/source/css/_common/components/post/expand.styl +263 -263
  62. package/source/css/_common/components/post/footer.styl +11 -11
  63. package/source/css/_common/components/post/header.styl +79 -79
  64. package/source/css/_common/components/post/nav.styl +64 -64
  65. package/source/css/_common/components/post/post.styl +29 -29
  66. package/source/css/_common/components/post/reward.styl +50 -50
  67. package/source/css/_common/components/post/rtl.styl +12 -12
  68. package/source/css/_common/components/post/tags.styl +39 -39
  69. package/source/css/_common/components/tags/collapse.styl +72 -72
  70. package/source/css/_common/components/tags/container.styl +49 -49
  71. package/source/css/_common/components/tags/label.styl +12 -12
  72. package/source/css/_common/components/tags/links.styl +77 -77
  73. package/source/css/_common/components/tags/list.styl +131 -131
  74. package/source/css/_common/components/tags/note.styl +70 -70
  75. package/source/css/_common/components/tags/player.styl +361 -361
  76. package/source/css/_common/components/tags/quiz.styl +200 -200
  77. package/source/css/_common/components/tags/tabs.styl +89 -89
  78. package/source/css/_common/components/tags/tags.styl +9 -9
  79. package/source/css/_common/components/third-party/loading.styl +222 -222
  80. package/source/css/_common/components/third-party/mermaid/class.styl +90 -90
  81. package/source/css/_common/components/third-party/mermaid/flowchart.styl +72 -72
  82. package/source/css/_common/components/third-party/mermaid/gantt.styl +251 -251
  83. package/source/css/_common/components/third-party/mermaid/git.styl +7 -7
  84. package/source/css/_common/components/third-party/mermaid/mermaid.styl +37 -37
  85. package/source/css/_common/components/third-party/mermaid/pie.styl +9 -9
  86. package/source/css/_common/components/third-party/mermaid/sequence.styl +95 -95
  87. package/source/css/_common/components/third-party/mermaid/state.styl +130 -130
  88. package/source/css/_common/components/third-party/pace.styl +18 -18
  89. package/source/css/_common/components/third-party/search.styl +167 -167
  90. package/source/css/_common/components/third-party/theme.styl +151 -151
  91. package/source/css/_common/components/third-party/third-party.styl +22 -22
  92. package/source/css/_common/components/third-party/widgets.styl +57 -57
  93. package/source/css/_common/outline/footer/footer.styl +67 -67
  94. package/source/css/_common/outline/header/brand.styl +77 -77
  95. package/source/css/_common/outline/header/header.styl +20 -20
  96. package/source/css/_common/outline/header/image.styl +85 -85
  97. package/source/css/_common/outline/header/menu.styl +117 -117
  98. package/source/css/_common/outline/header/nav.styl +81 -81
  99. package/source/css/_common/outline/header/right.styl +15 -15
  100. package/source/css/_common/outline/header/tool.styl +207 -207
  101. package/source/css/_common/outline/header/waves.styl +57 -57
  102. package/source/css/_common/outline/mobile.styl +46 -46
  103. package/source/css/_common/outline/outline.styl +78 -78
  104. package/source/css/_common/outline/sidebar/author.styl +59 -59
  105. package/source/css/_common/outline/sidebar/dimmer.styl +23 -23
  106. package/source/css/_common/outline/sidebar/menu.styl +63 -63
  107. package/source/css/_common/outline/sidebar/quick.styl +43 -43
  108. package/source/css/_common/outline/sidebar/related.styl +56 -56
  109. package/source/css/_common/outline/sidebar/sidebar.styl +82 -82
  110. package/source/css/_common/outline/sidebar/social.styl +69 -69
  111. package/source/css/_common/outline/sidebar/state.styl +37 -37
  112. package/source/css/_common/outline/sidebar/tab.styl +71 -71
  113. package/source/css/_common/outline/sidebar/toc.styl +47 -47
  114. package/source/css/_common/scaffolding/animate.styl +322 -322
  115. package/source/css/_common/scaffolding/base.styl +192 -192
  116. package/source/css/_common/scaffolding/buttons.styl +48 -48
  117. package/source/css/_common/scaffolding/divider.styl +36 -36
  118. package/source/css/_common/scaffolding/iconfont.styl +443 -443
  119. package/source/css/_common/scaffolding/normalize.styl +273 -273
  120. package/source/css/_common/scaffolding/pagination.styl +81 -81
  121. package/source/css/_common/scaffolding/ribbon.styl +38 -38
  122. package/source/css/_common/scaffolding/scaffolding.styl +14 -14
  123. package/source/css/_common/scaffolding/scrollbar.styl +37 -37
  124. package/source/css/_common/scaffolding/tables.styl +50 -50
  125. package/source/css/_common/scaffolding/tip.styl +19 -19
  126. package/source/css/_common/scaffolding/toggles.styl +59 -59
  127. package/source/css/_iconfont.styl +455 -455
  128. package/source/css/_mixins.styl +148 -148
  129. package/source/css/_variables.styl +89 -89
  130. package/source/css/app.styl +25 -25
  131. package/source/css/mermaid.styl +5 -5
  132. package/source/css/page.styl +2 -2
  133. package/source/css/post.styl +4 -4
  134. package/source/css/scaffolding.styl +4 -4
  135. package/source/js/_app/components/cloudflare.ts +18 -18
  136. package/source/js/_app/components/comments.ts +88 -88
  137. package/source/js/_app/components/sidebar.ts +243 -243
  138. package/source/js/_app/components/tcomments.ts +53 -53
  139. package/source/js/_app/globals/globalVars.ts +84 -84
  140. package/source/js/_app/globals/handles.ts +124 -124
  141. package/source/js/_app/globals/themeColor.ts +62 -62
  142. package/source/js/_app/globals/thirdparty.ts +63 -63
  143. package/source/js/_app/globals/tools.ts +73 -73
  144. package/source/js/_app/library/anime.ts +121 -121
  145. package/source/js/_app/library/declare.d.ts +129 -128
  146. package/source/js/_app/library/proto.ts +70 -70
  147. package/source/js/_app/library/vue.ts +49 -49
  148. package/source/js/_app/page/common.ts +41 -41
  149. package/source/js/_app/page/imageviewer.ts +15 -15
  150. package/source/js/_app/page/post.ts +251 -251
  151. package/source/js/_app/page/search.ts +109 -109
  152. package/source/js/_app/page/tab.ts +59 -59
  153. package/source/js/_app/pjax/domInit.ts +102 -102
  154. package/source/js/_app/pjax/refresh.ts +117 -117
  155. package/source/js/_app/pjax/siteInit.ts +93 -90
  156. package/source/js/_app/player.ts +13 -13
  157. package/toolbox/compiler.mjs +49 -49
  158. package/toolbox/dev-version.mjs +14 -14
  159. package/toolbox/hoistdep.mjs +5 -5
  160. package/toolbox/lib.mjs +63 -63
@@ -1,88 +1,88 @@
1
- import { CONFIG } from '../globals/globalVars'
2
- import { init, RecentComments } from '@waline/client'
3
- import { pageviewCount } from '@waline/client/pageview'
4
- // @ts-ignore
5
- await import('@waline/client/style')
6
-
7
- export const walineComment = function () {
8
- init({
9
- el: '#comments',
10
- serverURL: CONFIG.waline.serverURL,
11
- lang: CONFIG.waline.lang,
12
- locale: CONFIG.waline.locale,
13
- emoji: CONFIG.waline.emoji,
14
- meta: CONFIG.waline.meta,
15
- requiredMeta: CONFIG.waline.requiredMeta,
16
- wordLimit: CONFIG.waline.wordLimit,
17
- pageSize: CONFIG.waline.pageSize,
18
- pageview: CONFIG.waline.pageview,
19
- path: window.location.pathname,
20
- recaptchaV3Key: CONFIG.waline.recaptchaV3Key,
21
- turnstileKey: CONFIG.waline.turnstileKey,
22
- dark: 'html[data-theme="dark"]'
23
- })
24
- }
25
-
26
- export const walinePageview = function () {
27
- pageviewCount({
28
- serverURL: CONFIG.waline.serverURL,
29
- path: window.location.pathname
30
- })
31
- }
32
-
33
- export const walineRecentComments = async function () {
34
- const root = shokax_siteURL.replace(/^(https?:\/\/)?[^/]*/, '')
35
- let items = []
36
- const { comments } = await RecentComments({
37
- serverURL: CONFIG.waline.serverURL.replace(/\/+$/, ''),
38
- count: 10
39
- })
40
- // @ts-ignore
41
- comments.data.forEach(function (item) {
42
- let cText = (item.orig.length > 50) ? item.orig.substring(0, 50) + '...' : item.orig
43
- item.url = item.url.startsWith('/') ? item.url : '/' + item.url
44
- const siteLink = item.url + '#' + item.objectId
45
-
46
- const time = new Date(item.time)
47
- const now = new Date()
48
- const diff = now.valueOf() - time.valueOf()
49
- let dateStr:string
50
- if (diff < 3600000) {
51
- dateStr = `${Math.floor(diff / 60000)} 分钟前`
52
- } else if (diff < 86400000) {
53
- dateStr = `${Math.floor(diff / 3600000)} 小时前`
54
- } else if (diff < 2592000000) {
55
- dateStr = `${Math.floor(diff / 86400000)} 天前`
56
- } else {
57
- dateStr = `${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}`
58
- }
59
-
60
- items.push({
61
- href: siteLink,
62
- nick: item.nick,
63
- time: dateStr,
64
- text: cText
65
- })
66
- })
67
- const newComments = new DocumentFragment()
68
- items.forEach(function (item) {
69
- const commentEl = document.createElement('li')
70
- const commentLink = document.createElement('a')
71
- const commentTime = document.createElement('span')
72
- const commentText = document.createElement('span')
73
-
74
- commentText.innerText = item.text
75
- commentTime.className = 'breadcrumb'
76
- commentTime.innerText = `${item.nick} @ ${item.time}`
77
- commentLink.href = root + item.href
78
- commentEl.className = 'item'
79
-
80
- commentText.appendChild(document.createElement('br'))
81
- commentLink.appendChild(commentTime)
82
- commentLink.appendChild(commentText)
83
- commentEl.appendChild(commentLink)
84
- newComments.appendChild(commentEl)
85
- })
86
-
87
- document.getElementById("new-comment").appendChild(newComments)
88
- }
1
+ import { CONFIG } from '../globals/globalVars'
2
+ import { init, RecentComments } from '@waline/client'
3
+ import { pageviewCount } from '@waline/client/pageview'
4
+ // @ts-ignore
5
+ await import('@waline/client/style')
6
+
7
+ export const walineComment = function () {
8
+ init({
9
+ el: '#comments',
10
+ serverURL: CONFIG.waline.serverURL,
11
+ lang: CONFIG.waline.lang,
12
+ locale: CONFIG.waline.locale,
13
+ emoji: CONFIG.waline.emoji,
14
+ meta: CONFIG.waline.meta,
15
+ requiredMeta: CONFIG.waline.requiredMeta,
16
+ wordLimit: CONFIG.waline.wordLimit,
17
+ pageSize: CONFIG.waline.pageSize,
18
+ pageview: CONFIG.waline.pageview,
19
+ path: window.location.pathname,
20
+ recaptchaV3Key: CONFIG.waline.recaptchaV3Key,
21
+ turnstileKey: CONFIG.waline.turnstileKey,
22
+ dark: 'html[data-theme="dark"]'
23
+ })
24
+ }
25
+
26
+ export const walinePageview = function () {
27
+ pageviewCount({
28
+ serverURL: CONFIG.waline.serverURL,
29
+ path: window.location.pathname
30
+ })
31
+ }
32
+
33
+ export const walineRecentComments = async function () {
34
+ const root = shokax_siteURL.replace(/^(https?:\/\/)?[^/]*/, '')
35
+ let items = []
36
+ const { comments } = await RecentComments({
37
+ serverURL: CONFIG.waline.serverURL.replace(/\/+$/, ''),
38
+ count: 10
39
+ })
40
+ // @ts-ignore
41
+ comments.data.forEach(function (item) {
42
+ let cText = (item.orig.length > 50) ? item.orig.substring(0, 50) + '...' : item.orig
43
+ item.url = item.url.startsWith('/') ? item.url : '/' + item.url
44
+ const siteLink = item.url + '#' + item.objectId
45
+
46
+ const time = new Date(item.time)
47
+ const now = new Date()
48
+ const diff = now.valueOf() - time.valueOf()
49
+ let dateStr:string
50
+ if (diff < 3600000) {
51
+ dateStr = `${Math.floor(diff / 60000)} 分钟前`
52
+ } else if (diff < 86400000) {
53
+ dateStr = `${Math.floor(diff / 3600000)} 小时前`
54
+ } else if (diff < 2592000000) {
55
+ dateStr = `${Math.floor(diff / 86400000)} 天前`
56
+ } else {
57
+ dateStr = `${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}`
58
+ }
59
+
60
+ items.push({
61
+ href: siteLink,
62
+ nick: item.nick,
63
+ time: dateStr,
64
+ text: cText
65
+ })
66
+ })
67
+ const newComments = new DocumentFragment()
68
+ items.forEach(function (item) {
69
+ const commentEl = document.createElement('li')
70
+ const commentLink = document.createElement('a')
71
+ const commentTime = document.createElement('span')
72
+ const commentText = document.createElement('span')
73
+
74
+ commentText.innerText = item.text
75
+ commentTime.className = 'breadcrumb'
76
+ commentTime.innerText = `${item.nick} @ ${item.time}`
77
+ commentLink.href = root + item.href
78
+ commentEl.className = 'item'
79
+
80
+ commentText.appendChild(document.createElement('br'))
81
+ commentLink.appendChild(commentTime)
82
+ commentLink.appendChild(commentText)
83
+ commentEl.appendChild(commentLink)
84
+ newComments.appendChild(commentEl)
85
+ })
86
+
87
+ document.getElementById("new-comment").appendChild(newComments)
88
+ }
@@ -1,243 +1,243 @@
1
- /* 边栏分区 */
2
-
3
- import { CONFIG, Container, diffY, menuToggle, showContents, sideBar } from '../globals/globalVars'
4
- import { clipBoard } from '../globals/tools'
5
- import { pageScroll, transition } from '../library/anime'
6
- import { getHeight, setDisplay } from '../library/proto'
7
-
8
- export const sideBarToggleHandle = (event:Event, force?:number) => {
9
- if (sideBar.classList.contains('on')) {
10
- sideBar.classList.remove('on')
11
- menuToggle.classList.remove('close')
12
- if (force) {
13
- // @ts-ignore
14
- // noinspection JSConstantReassignment
15
- sideBar.style = ''
16
- } else {
17
- transition(sideBar, 'slideRightOut')
18
- }
19
- } else {
20
- if (force) {
21
- // @ts-ignore
22
- // noinspection JSConstantReassignment
23
- sideBar.style = ''
24
- } else {
25
- transition(sideBar, 'slideRightIn', () => {
26
- sideBar.classList.add('on')
27
- menuToggle.classList.add('close')
28
- })
29
- }
30
- }
31
- }
32
-
33
- export const sideBarTab = () => {
34
- const sideBarInner = sideBar.querySelector('.inner')
35
-
36
- if (sideBar.querySelector('.tab')) {
37
- sideBarInner.removeChild(sideBar.querySelector('.tab'))
38
- }
39
-
40
- const list = document.createElement('ul'); let active = 'active'
41
- list.className = 'tab';
42
-
43
- ['contents', 'related', 'overview'].forEach((item) => {
44
- const element = sideBar.querySelector('.panel.' + item)
45
-
46
- if (element.innerHTML.trim().length < 1) {
47
- if (item === 'contents') {
48
- setDisplay(showContents, 'none')
49
- }
50
- return
51
- }
52
-
53
- if (item === 'contents') {
54
- setDisplay(showContents, '')
55
- }
56
-
57
- const tab = document.createElement('li')
58
- const span = document.createElement('span')
59
- const text = document.createTextNode(element.getAttribute('data-title'))
60
- span.appendChild(text)
61
- tab.appendChild(span)
62
- tab.classList.add(item)
63
- tab.classList.add('item')
64
-
65
- if (active) {
66
- element.classList.add(active)
67
- tab.classList.add(active)
68
- } else {
69
- element.classList.remove('active')
70
- }
71
- tab.addEventListener('click', (event) => {
72
- const target = event.currentTarget as HTMLElement
73
- if (target.classList.contains('active')) return
74
-
75
- sideBar.querySelectorAll('.tab .item').forEach((element) => {
76
- element.classList.remove('active')
77
- })
78
-
79
- sideBar.querySelectorAll('.panel').forEach((element) => {
80
- element.classList.remove('active')
81
- })
82
-
83
- sideBar.querySelector('.panel.' + target.className.replace(' item', '')).classList.add('active')
84
-
85
- target.classList.add('active')
86
- })
87
-
88
- list.appendChild(tab)
89
- active = ''
90
- })
91
-
92
- if (list.childNodes.length > 1) {
93
- sideBarInner.insertBefore(list, sideBarInner.childNodes[0]);
94
- (sideBar.querySelector('.panels') as HTMLElement).style.paddingTop = ''
95
- } else {
96
- (sideBar.querySelector('.panels') as HTMLElement).style.paddingTop = '.625rem'
97
- }
98
- }
99
-
100
- export const sidebarTOC = () => {
101
- const activateNavByIndex = (index:number): void => {
102
- const target = navItems[index]
103
-
104
- if (!target) return
105
-
106
- if (target.classList.contains('current')) {
107
- return
108
- }
109
-
110
- document.querySelectorAll('.toc .active').forEach((element) => {
111
- element && element.classList.remove('active')
112
- element && element.classList.remove('current')
113
- })
114
-
115
- sections.forEach((element) => {
116
- element && element.classList.remove('active')
117
- })
118
-
119
- target.classList.add('active')
120
- target.classList.add('current')
121
- sections[index] && sections[index].classList.add('active')
122
-
123
- let parent = <Element> target.parentNode
124
-
125
- while (!parent.matches('.contents')) {
126
- if (parent.matches('li')) {
127
- parent.classList.add('active')
128
- const t = document.getElementById(decodeURIComponent(parent.querySelector('a.toc-link').getAttribute('href').replace('#', '')))
129
- if (t) {
130
- t.classList.add('active')
131
- }
132
- }
133
- parent = <Element> parent.parentNode
134
- }
135
- // Scrolling to center active TOC element if TOC content is taller than viewport.
136
- if (getComputedStyle(sideBar).display !== 'none' && tocElement.classList.contains('active')) {
137
- pageScroll((tocElement as HTMLElement), target.offsetTop - ((tocElement as HTMLElement).offsetHeight / 4))
138
- }
139
- }
140
- const navItems = document.querySelectorAll<HTMLElement>('.contents li')
141
-
142
- if (navItems.length < 1) {
143
- return
144
- }
145
-
146
- let sections = [...navItems] as HTMLElement[]
147
- let activeLock = null
148
-
149
- sections = sections.map((element, index) => {
150
- const link = element.querySelector('a.toc-link')
151
- const linkHref = link.getAttribute('href')
152
- if (!linkHref) return null
153
- const anchor = document.getElementById(decodeURI(linkHref.replace('#', '')))
154
- if (!anchor) return null
155
- const alink = anchor.querySelector('a.anchor')
156
-
157
- const anchorScroll = (event:MouseEvent) => {
158
- event.preventDefault()
159
- const target = document.getElementById(decodeURI((event.currentTarget as HTMLElement).getAttribute('href').replace('#', '')))
160
-
161
- activeLock = index
162
- pageScroll(document.body, target.offsetTop, () => {
163
- activateNavByIndex(index)
164
- activeLock = null
165
- })
166
- }
167
-
168
- // TOC item animation navigate.
169
- link.addEventListener('click', anchorScroll)
170
- alink && alink.addEventListener('click', (event) => {
171
- anchorScroll(<MouseEvent>event)
172
- clipBoard(CONFIG.hostname + '/' + LOCAL.path + (event.currentTarget as HTMLElement).getAttribute('href'))
173
- })
174
- return (anchor as HTMLElement)
175
- })
176
-
177
- const tocElement = sideBar.querySelector('.contents.panel')
178
-
179
- const findIndex = (entries: IntersectionObserverEntry[]) => {
180
- let index = 0
181
- let entry = entries[index]
182
-
183
- if (entry.boundingClientRect.top > 0) {
184
- index = sections.indexOf(entry.target as HTMLElement)
185
- return index === 0 ? 0 : index - 1
186
- }
187
- for (; index < entries.length; index++) {
188
- if (entries[index].boundingClientRect.top <= 0) {
189
- entry = entries[index]
190
- } else {
191
- return sections.indexOf(entry.target as HTMLElement)
192
- }
193
- }
194
- return sections.indexOf(entry.target as HTMLElement)
195
- }
196
-
197
- const createIntersectionObserver = () => {
198
- const observer = new IntersectionObserver((entries) => {
199
- const index = findIndex(entries) + (diffY < 0 ? 1 : 0)
200
- if (activeLock === null) {
201
- activateNavByIndex(index)
202
- }
203
- }, {
204
- rootMargin: '0px 0px -100% 0px', threshold: 0
205
- })
206
-
207
- sections.forEach((element) => {
208
- element && observer.observe(element)
209
- })
210
- }
211
-
212
- createIntersectionObserver()
213
- }
214
-
215
- export const backToTopHandle = () => {
216
- pageScroll(0)
217
- }
218
-
219
- export const goToBottomHandle = () => {
220
- pageScroll(parseInt(String(getHeight(Container))))
221
- }
222
-
223
- export const goToCommentHandle = () => {
224
- pageScroll(document.getElementById('comments'))
225
- }
226
-
227
- export const menuActive = () => {
228
- document.querySelectorAll('.menu .item:not(.title)').forEach((element) => {
229
- const target = <HTMLAnchorElement> element.querySelector('a[href]')
230
- const parentItem = element.parentNode.parentNode as HTMLElement
231
- if (!target) return
232
- const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', '')
233
- const isSubPath = !CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname)
234
- const active = !target.onclick && target.hostname === location.hostname && (isSamePath || isSubPath)
235
- element.classList.toggle('active', active)
236
- if (element.parentNode.querySelector('.active') && parentItem.classList.contains('dropdown')) {
237
- parentItem.classList.remove('active')
238
- parentItem.classList.add('expand')
239
- } else {
240
- parentItem.classList.remove('expand')
241
- }
242
- })
243
- }
1
+ /* 边栏分区 */
2
+
3
+ import { CONFIG, Container, diffY, menuToggle, showContents, sideBar } from '../globals/globalVars'
4
+ import { clipBoard } from '../globals/tools'
5
+ import { pageScroll, transition } from '../library/anime'
6
+ import { getHeight, setDisplay } from '../library/proto'
7
+
8
+ export const sideBarToggleHandle = (event:Event, force?:number) => {
9
+ if (sideBar.classList.contains('on')) {
10
+ sideBar.classList.remove('on')
11
+ menuToggle.classList.remove('close')
12
+ if (force) {
13
+ // @ts-ignore
14
+ // noinspection JSConstantReassignment
15
+ sideBar.style = ''
16
+ } else {
17
+ transition(sideBar, 'slideRightOut')
18
+ }
19
+ } else {
20
+ if (force) {
21
+ // @ts-ignore
22
+ // noinspection JSConstantReassignment
23
+ sideBar.style = ''
24
+ } else {
25
+ transition(sideBar, 'slideRightIn', () => {
26
+ sideBar.classList.add('on')
27
+ menuToggle.classList.add('close')
28
+ })
29
+ }
30
+ }
31
+ }
32
+
33
+ export const sideBarTab = () => {
34
+ const sideBarInner = sideBar.querySelector('.inner')
35
+
36
+ if (sideBar.querySelector('.tab')) {
37
+ sideBarInner.removeChild(sideBar.querySelector('.tab'))
38
+ }
39
+
40
+ const list = document.createElement('ul'); let active = 'active'
41
+ list.className = 'tab';
42
+
43
+ ['contents', 'related', 'overview'].forEach((item) => {
44
+ const element = sideBar.querySelector('.panel.' + item)
45
+
46
+ if (element.innerHTML.trim().length < 1) {
47
+ if (item === 'contents') {
48
+ setDisplay(showContents, 'none')
49
+ }
50
+ return
51
+ }
52
+
53
+ if (item === 'contents') {
54
+ setDisplay(showContents, '')
55
+ }
56
+
57
+ const tab = document.createElement('li')
58
+ const span = document.createElement('span')
59
+ const text = document.createTextNode(element.getAttribute('data-title'))
60
+ span.appendChild(text)
61
+ tab.appendChild(span)
62
+ tab.classList.add(item)
63
+ tab.classList.add('item')
64
+
65
+ if (active) {
66
+ element.classList.add(active)
67
+ tab.classList.add(active)
68
+ } else {
69
+ element.classList.remove('active')
70
+ }
71
+ tab.addEventListener('click', (event) => {
72
+ const target = event.currentTarget as HTMLElement
73
+ if (target.classList.contains('active')) return
74
+
75
+ sideBar.querySelectorAll('.tab .item').forEach((element) => {
76
+ element.classList.remove('active')
77
+ })
78
+
79
+ sideBar.querySelectorAll('.panel').forEach((element) => {
80
+ element.classList.remove('active')
81
+ })
82
+
83
+ sideBar.querySelector('.panel.' + target.className.replace(' item', '')).classList.add('active')
84
+
85
+ target.classList.add('active')
86
+ })
87
+
88
+ list.appendChild(tab)
89
+ active = ''
90
+ })
91
+
92
+ if (list.childNodes.length > 1) {
93
+ sideBarInner.insertBefore(list, sideBarInner.childNodes[0]);
94
+ (sideBar.querySelector('.panels') as HTMLElement).style.paddingTop = ''
95
+ } else {
96
+ (sideBar.querySelector('.panels') as HTMLElement).style.paddingTop = '.625rem'
97
+ }
98
+ }
99
+
100
+ export const sidebarTOC = () => {
101
+ const activateNavByIndex = (index:number): void => {
102
+ const target = navItems[index]
103
+
104
+ if (!target) return
105
+
106
+ if (target.classList.contains('current')) {
107
+ return
108
+ }
109
+
110
+ document.querySelectorAll('.toc .active').forEach((element) => {
111
+ element && element.classList.remove('active')
112
+ element && element.classList.remove('current')
113
+ })
114
+
115
+ sections.forEach((element) => {
116
+ element && element.classList.remove('active')
117
+ })
118
+
119
+ target.classList.add('active')
120
+ target.classList.add('current')
121
+ sections[index] && sections[index].classList.add('active')
122
+
123
+ let parent = <Element> target.parentNode
124
+
125
+ while (!parent.matches('.contents')) {
126
+ if (parent.matches('li')) {
127
+ parent.classList.add('active')
128
+ const t = document.getElementById(decodeURIComponent(parent.querySelector('a.toc-link').getAttribute('href').replace('#', '')))
129
+ if (t) {
130
+ t.classList.add('active')
131
+ }
132
+ }
133
+ parent = <Element> parent.parentNode
134
+ }
135
+ // Scrolling to center active TOC element if TOC content is taller than viewport.
136
+ if (getComputedStyle(sideBar).display !== 'none' && tocElement.classList.contains('active')) {
137
+ pageScroll((tocElement as HTMLElement), target.offsetTop - ((tocElement as HTMLElement).offsetHeight / 4))
138
+ }
139
+ }
140
+ const navItems = document.querySelectorAll<HTMLElement>('.contents li')
141
+
142
+ if (navItems.length < 1) {
143
+ return
144
+ }
145
+
146
+ let sections = [...navItems] as HTMLElement[]
147
+ let activeLock = null
148
+
149
+ sections = sections.map((element, index) => {
150
+ const link = element.querySelector('a.toc-link')
151
+ const linkHref = link.getAttribute('href')
152
+ if (!linkHref) return null
153
+ const anchor = document.getElementById(decodeURI(linkHref.replace('#', '')))
154
+ if (!anchor) return null
155
+ const alink = anchor.querySelector('a.anchor')
156
+
157
+ const anchorScroll = (event:MouseEvent) => {
158
+ event.preventDefault()
159
+ const target = document.getElementById(decodeURI((event.currentTarget as HTMLElement).getAttribute('href').replace('#', '')))
160
+
161
+ activeLock = index
162
+ pageScroll(document.body, target.offsetTop, () => {
163
+ activateNavByIndex(index)
164
+ activeLock = null
165
+ })
166
+ }
167
+
168
+ // TOC item animation navigate.
169
+ link.addEventListener('click', anchorScroll)
170
+ alink && alink.addEventListener('click', (event) => {
171
+ anchorScroll(<MouseEvent>event)
172
+ clipBoard(CONFIG.hostname + '/' + LOCAL.path + (event.currentTarget as HTMLElement).getAttribute('href'))
173
+ })
174
+ return (anchor as HTMLElement)
175
+ })
176
+
177
+ const tocElement = sideBar.querySelector('.contents.panel')
178
+
179
+ const findIndex = (entries: IntersectionObserverEntry[]) => {
180
+ let index = 0
181
+ let entry = entries[index]
182
+
183
+ if (entry.boundingClientRect.top > 0) {
184
+ index = sections.indexOf(entry.target as HTMLElement)
185
+ return index === 0 ? 0 : index - 1
186
+ }
187
+ for (; index < entries.length; index++) {
188
+ if (entries[index].boundingClientRect.top <= 0) {
189
+ entry = entries[index]
190
+ } else {
191
+ return sections.indexOf(entry.target as HTMLElement)
192
+ }
193
+ }
194
+ return sections.indexOf(entry.target as HTMLElement)
195
+ }
196
+
197
+ const createIntersectionObserver = () => {
198
+ const observer = new IntersectionObserver((entries) => {
199
+ const index = findIndex(entries) + (diffY < 0 ? 1 : 0)
200
+ if (activeLock === null) {
201
+ activateNavByIndex(index)
202
+ }
203
+ }, {
204
+ rootMargin: '0px 0px -100% 0px', threshold: 0
205
+ })
206
+
207
+ sections.forEach((element) => {
208
+ element && observer.observe(element)
209
+ })
210
+ }
211
+
212
+ createIntersectionObserver()
213
+ }
214
+
215
+ export const backToTopHandle = () => {
216
+ pageScroll(0)
217
+ }
218
+
219
+ export const goToBottomHandle = () => {
220
+ pageScroll(parseInt(String(getHeight(Container))))
221
+ }
222
+
223
+ export const goToCommentHandle = () => {
224
+ pageScroll(document.getElementById('comments'))
225
+ }
226
+
227
+ export const menuActive = () => {
228
+ document.querySelectorAll('.menu .item:not(.title)').forEach((element) => {
229
+ const target = <HTMLAnchorElement> element.querySelector('a[href]')
230
+ const parentItem = element.parentNode.parentNode as HTMLElement
231
+ if (!target) return
232
+ const isSamePath = target.pathname === location.pathname || target.pathname === location.pathname.replace('index.html', '')
233
+ const isSubPath = !CONFIG.root.startsWith(target.pathname) && location.pathname.startsWith(target.pathname)
234
+ const active = !target.onclick && target.hostname === location.hostname && (isSamePath || isSubPath)
235
+ element.classList.toggle('active', active)
236
+ if (element.parentNode.querySelector('.active') && parentItem.classList.contains('dropdown')) {
237
+ parentItem.classList.remove('active')
238
+ parentItem.classList.add('expand')
239
+ } else {
240
+ parentItem.classList.remove('expand')
241
+ }
242
+ })
243
+ }