hexo-theme-shokax 0.5.0 → 0.5.2

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 (165) hide show
  1. package/CODE_OF_CONDUCT.md +128 -128
  2. package/LICENSE +660 -660
  3. package/LICENSE-shoka +21 -21
  4. package/README.md +74 -53
  5. package/UsageRestrictions.md +25 -25
  6. package/_config.yml +352 -350
  7. package/languages/README.md +19 -19
  8. package/languages/default.yml +1 -1
  9. package/languages/en.yml +155 -155
  10. package/languages/ja.yml +155 -155
  11. package/languages/zh-CN.yml +155 -155
  12. package/languages/zh-HK.yml +155 -155
  13. package/languages/zh-TW.yml +155 -155
  14. package/layout/_alternate/atom.ejs +30 -30
  15. package/layout/_alternate/json.ejs +16 -16
  16. package/layout/_alternate/rss.ejs +34 -34
  17. package/layout/_mixin/breadcrumb.pug +33 -33
  18. package/layout/_mixin/card.pug +37 -37
  19. package/layout/_mixin/comment.pug +6 -6
  20. package/layout/_mixin/postmeta.pug +29 -29
  21. package/layout/_mixin/segment.pug +35 -35
  22. package/layout/_mixin/sidebar.pug +40 -40
  23. package/layout/_mixin/widgets.pug +28 -28
  24. package/layout/_partials/footer.pug +43 -43
  25. package/layout/_partials/head/head.pug +50 -50
  26. package/layout/_partials/head/head_com.pug +24 -24
  27. package/layout/_partials/head/pwa.pug +18 -18
  28. package/layout/_partials/header.pug +18 -18
  29. package/layout/_partials/layout.pug +137 -137
  30. package/layout/_partials/loading.pug +13 -13
  31. package/layout/_partials/pagination.pug +4 -4
  32. package/layout/_partials/post/copyright.pug +20 -20
  33. package/layout/_partials/post/footer.pug +20 -20
  34. package/layout/_partials/post/nav.pug +17 -17
  35. package/layout/_partials/post/post.pug +42 -42
  36. package/layout/_partials/post/reward.pug +18 -18
  37. package/layout/_partials/sidebar/menu.pug +37 -37
  38. package/layout/_partials/sidebar/overview.pug +42 -42
  39. package/layout/_partials/third-party/baidu-analytics.pug +11 -11
  40. package/layout/_partials/third-party/clarity.pug +8 -8
  41. package/layout/_partials/third-party/google-analytics.pug +9 -9
  42. package/layout/archive.pug +121 -121
  43. package/layout/category.pug +62 -62
  44. package/layout/index.pug +36 -36
  45. package/layout/page.pug +60 -60
  46. package/layout/post.pug +42 -42
  47. package/layout/tag.pug +46 -46
  48. package/package.json +14 -14
  49. package/scripts/generaters/images.js +11 -13
  50. package/scripts/generaters/script.js +3 -1
  51. package/scripts/helpers/engine.js +5 -0
  52. package/scripts/plugin/check.js +48 -10
  53. package/scripts/plugin/index.js +2 -2
  54. package/source/assets/algolia_logo.svg +9 -9
  55. package/source/assets/logo.svg +16 -16
  56. package/source/css/_colors.styl +207 -207
  57. package/source/css/_common/components/components.styl +5 -6
  58. package/source/css/_common/components/pages/collapse.styl +119 -119
  59. package/source/css/_common/components/pages/home.styl +391 -391
  60. package/source/css/_common/components/pages/pages.styl +56 -56
  61. package/source/css/_common/components/pages/tag-cloud.styl +12 -12
  62. package/source/css/_common/components/post/breadcrumb.styl +39 -39
  63. package/source/css/_common/components/post/copyright.styl +41 -41
  64. package/source/css/_common/components/post/expand.styl +263 -263
  65. package/source/css/_common/components/post/footer.styl +11 -11
  66. package/source/css/_common/components/post/header.styl +79 -79
  67. package/source/css/_common/components/post/nav.styl +64 -64
  68. package/source/css/_common/components/post/post.styl +29 -29
  69. package/source/css/_common/components/post/reward.styl +50 -50
  70. package/source/css/_common/components/post/rtl.styl +12 -12
  71. package/source/css/_common/components/post/tags.styl +39 -39
  72. package/source/css/_common/components/tags/collapse.styl +72 -72
  73. package/source/css/_common/components/tags/container.styl +49 -49
  74. package/source/css/_common/components/tags/label.styl +12 -12
  75. package/source/css/_common/components/tags/links.styl +77 -77
  76. package/source/css/_common/components/tags/list.styl +131 -131
  77. package/source/css/_common/components/tags/note.styl +70 -70
  78. package/source/css/_common/components/tags/player.styl +361 -361
  79. package/source/css/_common/components/tags/quiz.styl +200 -200
  80. package/source/css/_common/components/tags/tabs.styl +89 -89
  81. package/source/css/_common/components/tags/tags.styl +9 -9
  82. package/source/css/_common/components/third-party/loading.styl +222 -222
  83. package/source/css/_common/components/third-party/mermaid/class.styl +90 -90
  84. package/source/css/_common/components/third-party/mermaid/flowchart.styl +72 -72
  85. package/source/css/_common/components/third-party/mermaid/gantt.styl +251 -251
  86. package/source/css/_common/components/third-party/mermaid/git.styl +7 -7
  87. package/source/css/_common/components/third-party/mermaid/mermaid.styl +37 -37
  88. package/source/css/_common/components/third-party/mermaid/pie.styl +9 -9
  89. package/source/css/_common/components/third-party/mermaid/sequence.styl +95 -95
  90. package/source/css/_common/components/third-party/mermaid/state.styl +130 -130
  91. package/source/css/_common/components/third-party/pace.styl +18 -18
  92. package/source/css/_common/components/third-party/search.styl +167 -167
  93. package/source/css/_common/components/third-party/theme.styl +151 -151
  94. package/source/css/_common/components/third-party/third-party.styl +22 -22
  95. package/source/css/_common/components/third-party/widgets.styl +57 -57
  96. package/source/css/_common/outline/footer/footer.styl +67 -67
  97. package/source/css/_common/outline/header/brand.styl +77 -77
  98. package/source/css/_common/outline/header/header.styl +20 -20
  99. package/source/css/_common/outline/header/image.styl +85 -85
  100. package/source/css/_common/outline/header/menu.styl +117 -117
  101. package/source/css/_common/outline/header/nav.styl +81 -81
  102. package/source/css/_common/outline/header/right.styl +15 -15
  103. package/source/css/_common/outline/header/tool.styl +207 -207
  104. package/source/css/_common/outline/header/waves.styl +57 -57
  105. package/source/css/_common/outline/mobile.styl +46 -46
  106. package/source/css/_common/outline/outline.styl +78 -78
  107. package/source/css/_common/outline/sidebar/author.styl +59 -59
  108. package/source/css/_common/outline/sidebar/dimmer.styl +23 -23
  109. package/source/css/_common/outline/sidebar/menu.styl +63 -63
  110. package/source/css/_common/outline/sidebar/quick.styl +43 -43
  111. package/source/css/_common/outline/sidebar/related.styl +56 -56
  112. package/source/css/_common/outline/sidebar/sidebar.styl +82 -82
  113. package/source/css/_common/outline/sidebar/social.styl +69 -69
  114. package/source/css/_common/outline/sidebar/state.styl +37 -37
  115. package/source/css/_common/outline/sidebar/tab.styl +71 -71
  116. package/source/css/_common/outline/sidebar/toc.styl +47 -47
  117. package/source/css/_common/scaffolding/animate.styl +322 -322
  118. package/source/css/_common/scaffolding/base.styl +192 -190
  119. package/source/css/_common/scaffolding/buttons.styl +48 -48
  120. package/source/css/_common/scaffolding/divider.styl +36 -36
  121. package/source/css/_common/scaffolding/iconfont.styl +443 -443
  122. package/source/css/_common/scaffolding/normalize.styl +273 -273
  123. package/source/css/_common/scaffolding/pagination.styl +81 -81
  124. package/source/css/_common/scaffolding/ribbon.styl +38 -38
  125. package/source/css/_common/scaffolding/scaffolding.styl +14 -14
  126. package/source/css/_common/scaffolding/scrollbar.styl +37 -37
  127. package/source/css/_common/scaffolding/tables.styl +50 -50
  128. package/source/css/_common/scaffolding/tip.styl +19 -19
  129. package/source/css/_common/scaffolding/toggles.styl +59 -59
  130. package/source/css/_iconfont.styl +455 -455
  131. package/source/css/_mixins.styl +148 -148
  132. package/source/css/_variables.styl +89 -89
  133. package/source/css/app.styl +25 -25
  134. package/source/css/mermaid.styl +5 -5
  135. package/source/css/page.styl +2 -2
  136. package/source/css/post.styl +6 -5
  137. package/source/css/scaffolding.styl +4 -4
  138. package/source/js/_app/components/cloudflare.ts +18 -18
  139. package/source/js/_app/components/comments.ts +88 -86
  140. package/source/js/_app/components/sidebar.ts +243 -243
  141. package/source/js/_app/components/tcomments.ts +53 -53
  142. package/source/js/_app/globals/globalVars.ts +84 -84
  143. package/source/js/_app/globals/handles.ts +124 -124
  144. package/source/js/_app/globals/themeColor.ts +62 -62
  145. package/source/js/_app/globals/thirdparty.ts +63 -63
  146. package/source/js/_app/globals/tools.ts +73 -73
  147. package/source/js/_app/library/anime.ts +121 -121
  148. package/source/js/_app/library/declare.d.ts +128 -126
  149. package/source/js/_app/library/proto.ts +70 -70
  150. package/source/js/_app/library/vue.ts +49 -49
  151. package/source/js/_app/page/common.ts +41 -41
  152. package/source/js/_app/page/imageviewer.ts +15 -15
  153. package/source/js/_app/page/post.ts +252 -248
  154. package/source/js/_app/page/search.ts +109 -109
  155. package/source/js/_app/page/tab.ts +59 -59
  156. package/source/js/_app/pjax/domInit.ts +102 -102
  157. package/source/js/_app/pjax/refresh.ts +117 -117
  158. package/source/js/_app/pjax/siteInit.ts +90 -90
  159. package/source/js/_app/player.ts +13 -13
  160. package/toolbox/compiler.mjs +49 -53
  161. package/toolbox/dev-version.mjs +14 -14
  162. package/toolbox/hoistdep.mjs +5 -5
  163. package/toolbox/lib.mjs +63 -63
  164. package/source/css/_common/components/highlight/highlight.styl +0 -357
  165. package/source/css/_common/components/highlight/operation.styl +0 -21
@@ -1,86 +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
- dark: 'html[data-theme="dark"]'
21
- })
22
- }
23
-
24
- export const walinePageview = function () {
25
- pageviewCount({
26
- serverURL: CONFIG.waline.serverURL,
27
- path: window.location.pathname
28
- })
29
- }
30
-
31
- export const walineRecentComments = async function () {
32
- const root = shokax_siteURL.replace(/^(https?:\/\/)?[^/]*/, '')
33
- let items = []
34
- const { comments } = await RecentComments({
35
- serverURL: CONFIG.waline.serverURL.replace(/\/+$/, ''),
36
- count: 10
37
- })
38
- // @ts-ignore
39
- comments.data.forEach(function (item) {
40
- let cText = (item.orig.length > 50) ? item.orig.substring(0, 50) + '...' : item.orig
41
- item.url = item.url.startsWith('/') ? item.url : '/' + item.url
42
- const siteLink = item.url + '#' + item.objectId
43
-
44
- const time = new Date(item.time)
45
- const now = new Date()
46
- const diff = now.valueOf() - time.valueOf()
47
- let dateStr:string
48
- if (diff < 3600000) {
49
- dateStr = `${Math.floor(diff / 60000)} 分钟前`
50
- } else if (diff < 86400000) {
51
- dateStr = `${Math.floor(diff / 3600000)} 小时前`
52
- } else if (diff < 2592000000) {
53
- dateStr = `${Math.floor(diff / 86400000)} 天前`
54
- } else {
55
- dateStr = `${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}`
56
- }
57
-
58
- items.push({
59
- href: siteLink,
60
- nick: item.nick,
61
- time: dateStr,
62
- text: cText
63
- })
64
- })
65
- const newComments = new DocumentFragment()
66
- items.forEach(function (item) {
67
- const commentEl = document.createElement('li')
68
- const commentLink = document.createElement('a')
69
- const commentTime = document.createElement('span')
70
- const commentText = document.createElement('span')
71
-
72
- commentText.innerText = item.text
73
- commentTime.className = 'breadcrumb'
74
- commentTime.innerText = `${item.nick} @ ${item.time}`
75
- commentLink.href = root + item.href
76
- commentEl.className = 'item'
77
-
78
- commentText.appendChild(document.createElement('br'))
79
- commentLink.appendChild(commentTime)
80
- commentLink.appendChild(commentText)
81
- commentEl.appendChild(commentLink)
82
- newComments.appendChild(commentEl)
83
- })
84
-
85
- document.getElementById("new-comment").appendChild(newComments)
86
- }
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((target as HTMLElement), null, () => {
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
+ }