hexo-theme-shokax 0.3.13 → 0.4.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/_config.yml +11 -5
- package/layout/_mixin/comment.pug +4 -4
- package/package.json +4 -4
- package/scripts/filters/locals.d.ts +1 -0
- package/scripts/filters/locals.ts +59 -0
- package/scripts/filters/post.d.ts +0 -0
- package/scripts/filters/post.ts +6 -0
- package/scripts/generaters/archive.d.ts +1 -0
- package/scripts/generaters/archive.ts +144 -0
- package/scripts/generaters/config.d.ts +1 -0
- package/scripts/generaters/config.ts +52 -0
- package/scripts/generaters/images.d.ts +1 -0
- package/scripts/generaters/images.ts +26 -0
- package/scripts/generaters/index.d.ts +1 -0
- package/scripts/generaters/index.ts +110 -0
- package/scripts/generaters/pages.d.ts +0 -0
- package/scripts/generaters/pages.ts +16 -0
- package/scripts/generaters/script.d.ts +1 -0
- package/scripts/generaters/script.js +22 -6
- package/scripts/generaters/script.ts +110 -0
- package/scripts/helpers/asset.d.ts +1 -0
- package/scripts/helpers/asset.ts +158 -0
- package/scripts/helpers/engine.d.ts +1 -0
- package/scripts/helpers/engine.ts +171 -0
- package/scripts/helpers/list_categories.d.ts +1 -0
- package/scripts/helpers/list_categories.ts +104 -0
- package/scripts/helpers/summary_ai.d.ts +1 -0
- package/scripts/helpers/summary_ai.ts +100 -0
- package/scripts/helpers/symbols_count_time.d.ts +1 -0
- package/scripts/helpers/symbols_count_time.ts +76 -0
- package/scripts/plugin/check.d.ts +1 -0
- package/scripts/plugin/check.ts +35 -0
- package/scripts/plugin/index.d.ts +6 -0
- package/scripts/plugin/index.ts +52 -0
- package/scripts/plugin/lib/injects-point.d.ts +5 -0
- package/scripts/plugin/lib/injects-point.ts +20 -0
- package/scripts/plugin/lib/injects.d.ts +2 -0
- package/scripts/plugin/lib/injects.ts +101 -0
- package/scripts/tags/links.d.ts +1 -0
- package/scripts/tags/links.ts +75 -0
- package/scripts/tags/media.d.ts +1 -0
- package/scripts/tags/media.ts +19 -0
- package/source/js/_app/components/sidebar.ts +237 -0
- package/source/js/_app/globals/globalVars.ts +98 -0
- package/source/js/_app/globals/handles.ts +122 -0
- package/source/js/_app/globals/themeColor.ts +64 -0
- package/source/js/_app/globals/thirdparty.ts +63 -0
- package/source/js/_app/globals/tools.ts +74 -0
- package/source/js/_app/library/anime.ts +109 -0
- package/source/js/_app/library/declare.d.ts +117 -0
- package/source/js/_app/library/dom.ts +26 -0
- package/source/js/_app/library/libtype.d.ts +4 -0
- package/source/js/_app/library/loadFile.ts +41 -0
- package/source/js/_app/library/proto.ts +143 -0
- package/source/js/_app/library/scriptPjax.ts +72 -0
- package/source/js/_app/library/storage.ts +12 -0
- package/source/js/_app/library/vue.ts +60 -0
- package/source/js/_app/page/common.ts +42 -0
- package/source/js/_app/page/fancybox.ts +70 -0
- package/source/js/_app/page/post.ts +265 -0
- package/source/js/_app/page/search.ts +129 -0
- package/source/js/_app/page/tab.ts +59 -0
- package/source/js/_app/pjax/domInit.ts +95 -0
- package/source/js/_app/pjax/refresh.ts +75 -0
- package/source/js/_app/pjax/siteInit.ts +67 -0
- package/source/js/_app/player.ts +798 -0
- package/source/js/_app/components/sidebar.js +0 -209
- package/source/js/_app/fireworks.js +0 -10
- package/source/js/_app/globals/globalVars.js +0 -80
- package/source/js/_app/globals/handles.js +0 -98
- package/source/js/_app/globals/themeColor.js +0 -62
- package/source/js/_app/globals/thirdparty.js +0 -62
- package/source/js/_app/globals/tools.js +0 -66
- package/source/js/_app/library/anime.js +0 -106
- package/source/js/_app/library/dom.js +0 -34
- package/source/js/_app/library/loadFile.js +0 -36
- package/source/js/_app/library/proto.js +0 -163
- package/source/js/_app/library/scriptPjax.js +0 -70
- package/source/js/_app/library/storage.js +0 -12
- package/source/js/_app/library/vue.js +0 -53
- package/source/js/_app/page/comment.js +0 -23
- package/source/js/_app/page/common.js +0 -41
- package/source/js/_app/page/fancybox.js +0 -65
- package/source/js/_app/page/post.js +0 -244
- package/source/js/_app/page/search.js +0 -118
- package/source/js/_app/page/tab.js +0 -53
- package/source/js/_app/pjax/domInit.js +0 -76
- package/source/js/_app/pjax/refresh.js +0 -52
- package/source/js/_app/pjax/siteInit.js +0 -51
- package/source/js/_app/player.js +0 -771
@@ -0,0 +1,98 @@
|
|
1
|
+
import { $dom } from '../library/dom'
|
2
|
+
import Pjax from 'theme-shokax-pjax'
|
3
|
+
import initProto from '../library/proto'
|
4
|
+
|
5
|
+
initProto()
|
6
|
+
export const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root
|
7
|
+
export const scrollAction: { x: number, y: number } = { x: 0, y: 0 }
|
8
|
+
export let diffY = 0
|
9
|
+
export let originTitle: string, titleTime: NodeJS.Timeout
|
10
|
+
export const BODY = document.getElementsByTagName('body')[0]
|
11
|
+
export const HTML = document.documentElement
|
12
|
+
export const Container = $dom('#container')
|
13
|
+
export const loadCat = $dom('#loading')
|
14
|
+
export const siteNav = $dom('#nav')
|
15
|
+
export const siteHeader = $dom('#header')
|
16
|
+
export const menuToggle = siteNav.child('.toggle')
|
17
|
+
export const quickBtn = $dom('#quick')
|
18
|
+
export const sideBar = $dom('#sidebar')
|
19
|
+
export const siteBrand = $dom('#brand')
|
20
|
+
export let toolBtn = $dom('#tool')
|
21
|
+
export let toolPlayer
|
22
|
+
export let backToTop: HTMLElement
|
23
|
+
export let goToComment
|
24
|
+
export let showContents
|
25
|
+
export let siteSearch = $dom('#search')
|
26
|
+
export let siteNavHeight: number, headerHightInner: number, headerHight: number
|
27
|
+
export let oWinHeight = window.innerHeight
|
28
|
+
export let oWinWidth = window.innerWidth
|
29
|
+
export let LOCAL_HASH = 0
|
30
|
+
export let LOCAL_URL = window.location.href
|
31
|
+
export let pjax:Pjax
|
32
|
+
|
33
|
+
export function setSiteNavHeight (value:number):void {
|
34
|
+
siteNavHeight = value
|
35
|
+
}
|
36
|
+
export function setHeaderHightInner (value:number):void {
|
37
|
+
headerHightInner = value
|
38
|
+
}
|
39
|
+
|
40
|
+
export function setHeaderHight (value:number):void {
|
41
|
+
headerHight = value
|
42
|
+
}
|
43
|
+
|
44
|
+
export function setOWinHeight (value:number):void {
|
45
|
+
oWinHeight = value
|
46
|
+
}
|
47
|
+
|
48
|
+
export function setOWinWidth (value:number):void {
|
49
|
+
oWinWidth = value
|
50
|
+
}
|
51
|
+
|
52
|
+
export function setDiffY (value:number):void {
|
53
|
+
diffY = value
|
54
|
+
}
|
55
|
+
|
56
|
+
export function setTitleTime (value:NodeJS.Timeout):void {
|
57
|
+
titleTime = value
|
58
|
+
}
|
59
|
+
|
60
|
+
export function setLocalHash (value:number):void {
|
61
|
+
LOCAL_HASH = value
|
62
|
+
}
|
63
|
+
|
64
|
+
export function setLocalUrl (value:string):void {
|
65
|
+
LOCAL_URL = value
|
66
|
+
}
|
67
|
+
|
68
|
+
export function setPjax (value:Pjax):void {
|
69
|
+
pjax = value
|
70
|
+
}
|
71
|
+
|
72
|
+
export function setOriginTitle (value:string):void {
|
73
|
+
originTitle = value
|
74
|
+
}
|
75
|
+
|
76
|
+
export function setToolPlayer (value:any):void {
|
77
|
+
toolPlayer = value
|
78
|
+
}
|
79
|
+
|
80
|
+
export function setBackToTop (value:HTMLElement):void {
|
81
|
+
backToTop = value
|
82
|
+
}
|
83
|
+
|
84
|
+
export function setGoToComment (value:any):void {
|
85
|
+
goToComment = value
|
86
|
+
}
|
87
|
+
|
88
|
+
export function setShowContents (value:any):void {
|
89
|
+
showContents = value
|
90
|
+
}
|
91
|
+
|
92
|
+
export function setToolBtn (value:HTMLElement):void {
|
93
|
+
toolBtn = value
|
94
|
+
}
|
95
|
+
|
96
|
+
export function setSiteSearch (value:HTMLElement):void {
|
97
|
+
siteSearch = value
|
98
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import { sideBarToggleHandle } from '../components/sidebar'
|
2
|
+
import { $dom, getDocHeight } from '../library/dom'
|
3
|
+
import {
|
4
|
+
backToTop,
|
5
|
+
diffY,
|
6
|
+
headerHight,
|
7
|
+
headerHightInner,
|
8
|
+
oWinWidth,
|
9
|
+
originTitle,
|
10
|
+
scrollAction,
|
11
|
+
sideBar,
|
12
|
+
siteBrand,
|
13
|
+
siteHeader,
|
14
|
+
siteNav,
|
15
|
+
statics,
|
16
|
+
titleTime,
|
17
|
+
toolBtn,
|
18
|
+
setSiteNavHeight,
|
19
|
+
setHeaderHightInner,
|
20
|
+
setHeaderHight,
|
21
|
+
setOWinHeight, setOWinWidth, setDiffY, setTitleTime
|
22
|
+
} from './globalVars'
|
23
|
+
import { changeMetaTheme } from './themeColor'
|
24
|
+
import { Loader } from './thirdparty'
|
25
|
+
|
26
|
+
export const resizeHandle = () => {
|
27
|
+
// 获取 siteNav 的高度
|
28
|
+
setSiteNavHeight(siteNav.changeOrGetHeight())
|
29
|
+
// 获取 siteHeader 的高度
|
30
|
+
setHeaderHightInner(siteHeader.changeOrGetHeight())
|
31
|
+
// 获取 #waves 的高度
|
32
|
+
setHeaderHight(headerHightInner + $dom('#waves').changeOrGetHeight())
|
33
|
+
|
34
|
+
// 判断窗口宽度是否改变
|
35
|
+
if (oWinWidth !== window.innerWidth) {
|
36
|
+
sideBarToggleHandle(null, 1)
|
37
|
+
}
|
38
|
+
|
39
|
+
// 记录窗口高度和宽度
|
40
|
+
setOWinHeight(window.innerHeight)
|
41
|
+
setOWinWidth(window.innerWidth)
|
42
|
+
}
|
43
|
+
|
44
|
+
export const scrollHandle = () => {
|
45
|
+
// 获取窗口高度
|
46
|
+
const winHeight = window.innerHeight
|
47
|
+
// 获取文档高度
|
48
|
+
const docHeight = getDocHeight()
|
49
|
+
// 计算可见内容高度
|
50
|
+
const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight
|
51
|
+
// 判断页面是否滚动超过 headerHightInner
|
52
|
+
const SHOW = window.scrollY > headerHightInner
|
53
|
+
// 判断页面是否开始滚动
|
54
|
+
const startScroll = window.scrollY > 0
|
55
|
+
|
56
|
+
// 根据条件修改 meta theme
|
57
|
+
if (SHOW) {
|
58
|
+
changeMetaTheme('#FFF')
|
59
|
+
} else {
|
60
|
+
changeMetaTheme('#222')
|
61
|
+
}
|
62
|
+
|
63
|
+
// 控制导航栏的显示隐藏
|
64
|
+
siteNav.toggleClass('show', SHOW)
|
65
|
+
// 控制网站 logo 的显示隐藏
|
66
|
+
toolBtn.toggleClass('affix', startScroll)
|
67
|
+
// 控制侧边栏的显示隐藏,当滚动高度大于 headerHight 且窗口宽度大于 991px 时显示
|
68
|
+
siteBrand.toggleClass('affix', startScroll)
|
69
|
+
sideBar.toggleClass('affix', window.scrollY > headerHight && document.body.offsetWidth > 991)
|
70
|
+
// 初始化滚动时导航栏的显示方向
|
71
|
+
if (typeof scrollAction.y === 'undefined') {
|
72
|
+
scrollAction.y = window.scrollY
|
73
|
+
}
|
74
|
+
setDiffY(scrollAction.y - window.scrollY)
|
75
|
+
|
76
|
+
// 控制滑动时导航栏显示
|
77
|
+
if (diffY < 0) {
|
78
|
+
siteNav.removeClass('up')
|
79
|
+
siteNav.toggleClass('down', SHOW)
|
80
|
+
} else if (diffY > 0) {
|
81
|
+
siteNav.removeClass('down')
|
82
|
+
siteNav.toggleClass('up', SHOW)
|
83
|
+
} else { /* empty */ }
|
84
|
+
scrollAction.y = window.scrollY
|
85
|
+
// 计算滚动百分比
|
86
|
+
const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%'
|
87
|
+
// 更新回到顶部按钮的文字
|
88
|
+
if (backToTop.child('span').innerText !== scrollPercent) {
|
89
|
+
backToTop.child('span').innerText = scrollPercent
|
90
|
+
}
|
91
|
+
// 更新百分比进度条的宽度
|
92
|
+
if ($dom('#sidebar').hasClass('affix') || $dom('#sidebar').hasClass('on')) {
|
93
|
+
$dom('.percent').changeOrGetWidth(scrollPercent)
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
// 可见度监听(离开页面和返回时更改document的title)
|
98
|
+
export const visibilityListener = () => {
|
99
|
+
const iconNode = $dom('[rel="icon"]')
|
100
|
+
document.addEventListener('visibilitychange', () => {
|
101
|
+
switch (document.visibilityState) {
|
102
|
+
case 'hidden':
|
103
|
+
iconNode.setAttribute('href', statics + CONFIG.favicon.hidden)
|
104
|
+
document.title = LOCAL.favicon.hide
|
105
|
+
if (CONFIG.loader.switch) {
|
106
|
+
Loader.show()
|
107
|
+
}
|
108
|
+
clearTimeout(titleTime)
|
109
|
+
break
|
110
|
+
case 'visible':
|
111
|
+
iconNode.setAttribute('href', statics + CONFIG.favicon.normal)
|
112
|
+
document.title = LOCAL.favicon.show
|
113
|
+
if (CONFIG.loader.switch) {
|
114
|
+
Loader.hide(1000)
|
115
|
+
}
|
116
|
+
setTitleTime(setTimeout(() => {
|
117
|
+
document.title = originTitle
|
118
|
+
}, 2000))
|
119
|
+
break
|
120
|
+
}
|
121
|
+
})
|
122
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { $storage } from '../library/storage'
|
2
|
+
import { $dom } from '../library/dom'
|
3
|
+
import { HTML } from './globalVars'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* 更改日夜模式
|
7
|
+
*/
|
8
|
+
export const changeTheme = (type?: string) => {
|
9
|
+
const btn = <HTMLElement>$dom('.theme .ic')
|
10
|
+
if (type === 'dark') {
|
11
|
+
HTML.setAttribute('data-theme', type)
|
12
|
+
btn.removeClass('i-sun')
|
13
|
+
btn.addClass('i-moon')
|
14
|
+
} else {
|
15
|
+
HTML.removeAttribute('data-theme')
|
16
|
+
btn.removeClass('i-moon')
|
17
|
+
btn.addClass('i-sun')
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
* 自动调整黑夜白天
|
23
|
+
* 优先级: 手动选择>时间>跟随系统
|
24
|
+
*/
|
25
|
+
export const autoDarkmode = () => {
|
26
|
+
if (CONFIG.auto_dark.enable) {
|
27
|
+
if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
|
28
|
+
changeTheme('dark')
|
29
|
+
} else {
|
30
|
+
changeTheme()
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* 更改主题的meta
|
37
|
+
*/
|
38
|
+
export const changeMetaTheme = (color: string): void => {
|
39
|
+
if (HTML.getAttribute('data-theme') === 'dark') {
|
40
|
+
color = '#222'
|
41
|
+
}
|
42
|
+
|
43
|
+
$dom('meta[name="theme-color"]').setAttribute('content', color)
|
44
|
+
}
|
45
|
+
|
46
|
+
// 记忆日夜模式切换和系统亮暗模式监听
|
47
|
+
export const themeColorListener = () => {
|
48
|
+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
|
49
|
+
if (mediaQueryList.matches) {
|
50
|
+
changeTheme('dark')
|
51
|
+
} else {
|
52
|
+
changeTheme()
|
53
|
+
}
|
54
|
+
})
|
55
|
+
|
56
|
+
const t = $storage.get('theme')
|
57
|
+
if (t) {
|
58
|
+
changeTheme(t)
|
59
|
+
} else {
|
60
|
+
if (CONFIG.darkmode) {
|
61
|
+
changeTheme('dark')
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
// 与第三方js的交互或第三方嵌入js
|
2
|
+
|
3
|
+
import { loadCat } from './globalVars'
|
4
|
+
import { transition } from '../library/anime'
|
5
|
+
|
6
|
+
// 加载动画
|
7
|
+
export const Loader = {
|
8
|
+
timer: undefined,
|
9
|
+
lock: false,
|
10
|
+
show () {
|
11
|
+
clearTimeout(this.timer)
|
12
|
+
document.body.removeClass('loaded')
|
13
|
+
loadCat.setAttribute('style', 'display:block')
|
14
|
+
Loader.lock = false
|
15
|
+
},
|
16
|
+
hide (sec?: number) {
|
17
|
+
if (!CONFIG.loader.start) {
|
18
|
+
sec = -1
|
19
|
+
}
|
20
|
+
this.timer = setTimeout(this.vanish, sec || 3000)
|
21
|
+
},
|
22
|
+
vanish (): void {
|
23
|
+
if (Loader.lock) {
|
24
|
+
return
|
25
|
+
}
|
26
|
+
if (CONFIG.loader.start) {
|
27
|
+
transition(loadCat, 0)
|
28
|
+
}
|
29
|
+
document.body.addClass('loaded')
|
30
|
+
Loader.lock = true
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
export const isOutime = (): void => {
|
35
|
+
let updateTime: Date
|
36
|
+
const times = document.getElementsByTagName('time')
|
37
|
+
if (times.length === 0) {
|
38
|
+
return
|
39
|
+
}
|
40
|
+
const posts = document.getElementsByClassName('body md')
|
41
|
+
if (posts.length === 0) {
|
42
|
+
return
|
43
|
+
}
|
44
|
+
|
45
|
+
const now = Date.now() // 当前时间戳
|
46
|
+
const pubTime = new Date(times[0].dateTime) // 文章发布时间戳
|
47
|
+
if (times.length === 1) {
|
48
|
+
updateTime = pubTime // 文章发布时间亦是最后更新时间
|
49
|
+
} else {
|
50
|
+
updateTime = new Date(times[1].dateTime) // 文章最后更新时间戳
|
51
|
+
}
|
52
|
+
// @ts-ignore
|
53
|
+
const interval = parseInt(String(now - updateTime)) // 时间差
|
54
|
+
const days = parseInt(String(CONFIG.outime.days)) || 30 // 设置时效,默认硬编码 30 天
|
55
|
+
// 最后一次更新时间超过 days 天(毫秒)
|
56
|
+
if (interval > (days * 86400000)) {
|
57
|
+
// @ts-ignore
|
58
|
+
const publish = parseInt(String((now - pubTime) / 86400000))
|
59
|
+
const updated = parseInt(String(interval / 86400000))
|
60
|
+
const template = LOCAL.template.replace('{{publish}}', String(publish)).replace('{{updated}}', String(updated))
|
61
|
+
posts[0].insertAdjacentHTML('afterbegin', template)
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { pageScroll } from '../library/anime'
|
2
|
+
import { $dom } from '../library/dom'
|
3
|
+
import { $storage } from '../library/storage'
|
4
|
+
import { BODY, LOCAL_HASH, LOCAL_URL, scrollAction, setLocalHash } from './globalVars'
|
5
|
+
|
6
|
+
// 显示提示(现阶段用于版权及复制结果提示)
|
7
|
+
export const showtip = (msg: string): void | never => {
|
8
|
+
if (!msg) {
|
9
|
+
return
|
10
|
+
}
|
11
|
+
|
12
|
+
const tipbox = BODY.createChild('div', {
|
13
|
+
innerHTML: msg,
|
14
|
+
className: 'tip'
|
15
|
+
})
|
16
|
+
|
17
|
+
setTimeout(() => {
|
18
|
+
tipbox.addClass('hide')
|
19
|
+
setTimeout(() => {
|
20
|
+
BODY.removeChild(tipbox)
|
21
|
+
}, 300)
|
22
|
+
}, 3000)
|
23
|
+
}
|
24
|
+
|
25
|
+
export const pagePosition = () => {
|
26
|
+
// 判断配置项是否开启了自动记录滚动位置
|
27
|
+
if (CONFIG.auto_scroll) {
|
28
|
+
// 将当前页面的滚动位置存入本地缓存
|
29
|
+
$storage.set(LOCAL_URL, String(scrollAction.y))
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
export const positionInit = (comment?: boolean) => {
|
34
|
+
// 获取页面锚点
|
35
|
+
const anchor = window.location.hash
|
36
|
+
|
37
|
+
let target = null
|
38
|
+
if (LOCAL_HASH) {
|
39
|
+
$storage.del(LOCAL_URL)
|
40
|
+
return
|
41
|
+
}
|
42
|
+
|
43
|
+
if (anchor) {
|
44
|
+
target = $dom(decodeURI(anchor))
|
45
|
+
} else {
|
46
|
+
target = CONFIG.auto_scroll ? parseInt($storage.get(LOCAL_URL)) : 0
|
47
|
+
}
|
48
|
+
|
49
|
+
if (target) {
|
50
|
+
pageScroll(target)
|
51
|
+
setLocalHash(1)
|
52
|
+
}
|
53
|
+
|
54
|
+
if (comment && anchor && !LOCAL_HASH) {
|
55
|
+
pageScroll(target)
|
56
|
+
setLocalHash(1)
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
/*
|
61
|
+
基于clipboard API的复制功能,仅在https环境下有效
|
62
|
+
*/
|
63
|
+
export const clipBoard = (str: string, callback?: (result:boolean) => void) => {
|
64
|
+
if (navigator.clipboard && window.isSecureContext) {
|
65
|
+
navigator.clipboard.writeText(str).then(() => {
|
66
|
+
callback && callback(true)
|
67
|
+
}, () => {
|
68
|
+
callback && callback(false)
|
69
|
+
})
|
70
|
+
} else {
|
71
|
+
console.error('Too old browser, clipborad API not supported.')
|
72
|
+
callback && callback(false)
|
73
|
+
}
|
74
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import anime from 'theme-shokax-anime'
|
2
|
+
import { siteNavHeight } from '../globals/globalVars'
|
3
|
+
import type { AnimeOptions } from 'theme-shokax-anime/dist/types'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* 参数 动画效果
|
7
|
+
* 0 元素逐渐消失
|
8
|
+
* 1 元素逐渐出现
|
9
|
+
* bounceUpIn 元素从下方弹跳出现
|
10
|
+
* shrinkIn 元素从放大到正常大小出现
|
11
|
+
* slideRightIn 元素从右侧滑入
|
12
|
+
* slideRightOut 元素向右侧滑出
|
13
|
+
* TODO 函数功能过于复杂,需要拆分
|
14
|
+
*/
|
15
|
+
export const transition = (target: HTMLElement, type: number|string|Function, complete?: Function, begin?: Function): void => {
|
16
|
+
let animation:Partial<AnimeOptions>
|
17
|
+
let display = 'none'
|
18
|
+
switch (type) {
|
19
|
+
case 0:
|
20
|
+
animation = { opacity: [1, 0] }
|
21
|
+
break
|
22
|
+
case 1:
|
23
|
+
animation = { opacity: [0, 1] }
|
24
|
+
display = 'block'
|
25
|
+
break
|
26
|
+
case 'bounceUpIn':
|
27
|
+
animation = {
|
28
|
+
begin (anim) {
|
29
|
+
target.display('block')
|
30
|
+
},
|
31
|
+
translateY: [
|
32
|
+
{ value: -60, duration: 200 },
|
33
|
+
{ value: 10, duration: 200 },
|
34
|
+
{ value: -5, duration: 200 },
|
35
|
+
{ value: 0, duration: 200 }
|
36
|
+
],
|
37
|
+
opacity: [0, 1]
|
38
|
+
}
|
39
|
+
display = 'block'
|
40
|
+
break
|
41
|
+
case 'shrinkIn':
|
42
|
+
animation = {
|
43
|
+
begin (anim) {
|
44
|
+
target.display('block')
|
45
|
+
},
|
46
|
+
scale: [
|
47
|
+
{ value: 1.1, duration: 300 },
|
48
|
+
{ value: 1, duration: 200 }
|
49
|
+
],
|
50
|
+
opacity: 1
|
51
|
+
}
|
52
|
+
display = 'block'
|
53
|
+
break
|
54
|
+
case 'slideRightIn':
|
55
|
+
animation = {
|
56
|
+
begin (anim) {
|
57
|
+
target.display('block')
|
58
|
+
},
|
59
|
+
translateX: ['100%', '0%'],
|
60
|
+
opacity: [0, 1]
|
61
|
+
}
|
62
|
+
display = 'block'
|
63
|
+
break
|
64
|
+
case 'slideRightOut':
|
65
|
+
animation = {
|
66
|
+
translateX: ['0%', '100%'],
|
67
|
+
opacity: [1, 0]
|
68
|
+
}
|
69
|
+
break
|
70
|
+
default:
|
71
|
+
// @ts-ignore
|
72
|
+
animation = type
|
73
|
+
// @ts-ignore
|
74
|
+
display = type.display
|
75
|
+
break
|
76
|
+
}
|
77
|
+
anime(Object.assign({
|
78
|
+
targets: target,
|
79
|
+
duration: 200,
|
80
|
+
easing: 'linear',
|
81
|
+
begin () {
|
82
|
+
begin && begin()
|
83
|
+
},
|
84
|
+
complete () {
|
85
|
+
target.display(display)
|
86
|
+
complete && complete()
|
87
|
+
}
|
88
|
+
}, animation)).play()
|
89
|
+
}
|
90
|
+
|
91
|
+
export const pageScroll = (target: HTMLElement|number, offset?: number, complete?: Function) => {
|
92
|
+
// target: 滚动到的目标元素或坐标(number)
|
93
|
+
// offset: 可选的偏移量
|
94
|
+
// complete: 可选的回调函数,在动画完成时调用
|
95
|
+
anime({
|
96
|
+
// 动画目标
|
97
|
+
targets: typeof offset === 'number' && typeof target !== 'number' ? target.parentNode : document.scrollingElement,
|
98
|
+
// 动画持续时间
|
99
|
+
duration: 500,
|
100
|
+
// 动画缓动函数
|
101
|
+
easing: 'easeInOutQuad',
|
102
|
+
// 如果 offset 存在,则滚动到 offset,如果 target 是数字,则滚动到 target,如果 target 是 DOM 元素,则滚动到下述表达式
|
103
|
+
scrollTop: offset || (typeof target === 'number' ? target : (target ? target.getTop() + document.documentElement.scrollTop - siteNavHeight : 0)),
|
104
|
+
// 完成回调函数
|
105
|
+
complete () {
|
106
|
+
complete && complete()
|
107
|
+
}
|
108
|
+
}).play()
|
109
|
+
}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
/*
|
2
|
+
对注释的说明: 部分注释为openai-chatgpt生成的注释,可能存在描述或语义的问题
|
3
|
+
*/
|
4
|
+
interface AudioItem {
|
5
|
+
title: string;
|
6
|
+
list: string[];
|
7
|
+
}
|
8
|
+
|
9
|
+
declare interface EventTarget {
|
10
|
+
createChild(tag: string, obj: Object, positon?: string): HTMLElement;
|
11
|
+
wrapObject(obj: Object): void;
|
12
|
+
changeOrGetHeight(h: number | string): void;
|
13
|
+
changeOrGetHeight(): number;
|
14
|
+
changeOrGetWidth(w: number | string): void;
|
15
|
+
changeOrGetWidth(): number;
|
16
|
+
getTop(): number;
|
17
|
+
left(): number;
|
18
|
+
insertAfter(element: HTMLElement): void;
|
19
|
+
display(d: string): EventTarget;
|
20
|
+
display():string
|
21
|
+
child(selector: string): HTMLElement;
|
22
|
+
find(selector: string): NodeListOf<HTMLElement>;
|
23
|
+
_class(type: string, className: string, display?: boolean): void;
|
24
|
+
addClass(className: string): EventTarget;
|
25
|
+
removeClass(className: string): EventTarget;
|
26
|
+
toggleClass(className: string, display?: boolean): EventTarget;
|
27
|
+
hasClass(className: string): boolean;
|
28
|
+
}
|
29
|
+
|
30
|
+
declare const LOCAL: {
|
31
|
+
path: string;
|
32
|
+
ignores: Array<(uri:string)=>boolean>;
|
33
|
+
audio: string[];
|
34
|
+
search: {
|
35
|
+
placeholder: string,
|
36
|
+
empty: string,
|
37
|
+
stats: string
|
38
|
+
};
|
39
|
+
quiz: {
|
40
|
+
choice: string,
|
41
|
+
multiple: string,
|
42
|
+
true_false: string,
|
43
|
+
essay: string,
|
44
|
+
gap_fill: string,
|
45
|
+
mistake: string
|
46
|
+
};
|
47
|
+
nocopy: boolean;
|
48
|
+
copyright: string;
|
49
|
+
outime: boolean
|
50
|
+
template: string
|
51
|
+
favicon: {
|
52
|
+
hide: string
|
53
|
+
show: string
|
54
|
+
}
|
55
|
+
}
|
56
|
+
declare const CONFIG: {
|
57
|
+
hostname: string;
|
58
|
+
fireworks: any;
|
59
|
+
audio: AudioItem[];
|
60
|
+
version: number
|
61
|
+
root: string
|
62
|
+
statics: string
|
63
|
+
outime: {
|
64
|
+
enable: boolean
|
65
|
+
days: number
|
66
|
+
}
|
67
|
+
favicon: {
|
68
|
+
normal: string,
|
69
|
+
hidden: string
|
70
|
+
}
|
71
|
+
darkmode: boolean
|
72
|
+
auto_dark: {
|
73
|
+
enable: boolean
|
74
|
+
start: number
|
75
|
+
end: number
|
76
|
+
}
|
77
|
+
auto_scroll: boolean
|
78
|
+
loader: {
|
79
|
+
start: boolean
|
80
|
+
switch: boolean
|
81
|
+
}
|
82
|
+
js: {
|
83
|
+
chart: string
|
84
|
+
copy_tex: string
|
85
|
+
fancybox: string
|
86
|
+
echarts: string
|
87
|
+
}
|
88
|
+
css: {
|
89
|
+
valine: string
|
90
|
+
katex: string
|
91
|
+
mermaid: string
|
92
|
+
fancybox: string
|
93
|
+
}
|
94
|
+
search: any,
|
95
|
+
valine: string
|
96
|
+
quicklink: {
|
97
|
+
ignores: any
|
98
|
+
timeout: number
|
99
|
+
priority: string
|
100
|
+
}
|
101
|
+
playerAPI: string
|
102
|
+
}
|
103
|
+
declare const instantsearch: any
|
104
|
+
|
105
|
+
declare function algoliasearch(appID: string, apiKey: string): any;
|
106
|
+
|
107
|
+
declare const quicklink: any
|
108
|
+
|
109
|
+
// esbuild 静态常量
|
110
|
+
declare const __shokax_player__:boolean
|
111
|
+
declare const __shokax_fireworks__:boolean
|
112
|
+
declare const __shokax_search__:boolean
|
113
|
+
declare const __shokax_VL__:boolean
|
114
|
+
declare const __shokax_outime__:boolean
|
115
|
+
declare const __shokax_tabs__: boolean
|
116
|
+
declare const __shokax_quiz__: boolean
|
117
|
+
declare const __shokax_fancybox__: boolean
|
@@ -0,0 +1,26 @@
|
|
1
|
+
const getDocHeight = () => $dom('main > .inner').offsetHeight
|
2
|
+
/**
|
3
|
+
* 获取一个dom选择器对应的元素
|
4
|
+
*/
|
5
|
+
const $dom = (selector: string, element: Document = document): HTMLElement => {
|
6
|
+
// 在测试环境中这能优化0.01-0.02ms左右
|
7
|
+
if (selector[0] === '#') {
|
8
|
+
return <HTMLElement> element.getElementById(selector.substring(1))
|
9
|
+
}
|
10
|
+
return <HTMLElement> element.querySelector(selector)
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* 获取具有此选择器的所有dom节点
|
15
|
+
*/
|
16
|
+
$dom.all = (selector: string, element: Document = document): NodeListOf<HTMLElement> => {
|
17
|
+
return element.querySelectorAll(selector)
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* 获取具有此选择器的所有dom节点,并依次执行callback函数
|
21
|
+
*/
|
22
|
+
$dom.each = (selector: string, callback: (value: HTMLElement, key: number, parent: NodeListOf<Element>) => void, element?: Document): void => {
|
23
|
+
$dom.all(selector, element).forEach(callback)
|
24
|
+
}
|
25
|
+
|
26
|
+
export { $dom, getDocHeight }
|