hexo-theme-shokax 0.4.0-alpha.1 → 0.4.0-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/_config.yml +5 -4
  2. package/layout/_partials/footer.pug +1 -1
  3. package/layout/_partials/head/head.pug +7 -1
  4. package/layout/_partials/header.pug +1 -1
  5. package/layout/_partials/layout.pug +0 -10
  6. package/layout/_partials/post/footer.pug +1 -2
  7. package/package.json +7 -2
  8. package/scripts/generaters/archive.js +1 -1
  9. package/scripts/generaters/script.js +44 -38
  10. package/scripts/helpers/asset.js +1 -1
  11. package/scripts/helpers/list_categories.js +0 -4
  12. package/scripts/plugin/lib/injects.js +1 -1
  13. package/source/js/_app/components/comments.ts +33 -0
  14. package/source/js/_app/components/sidebar.ts +7 -5
  15. package/source/js/_app/globals/globalVars.ts +1 -0
  16. package/source/js/_app/globals/handles.ts +6 -5
  17. package/source/js/_app/globals/themeColor.ts +1 -1
  18. package/source/js/_app/globals/thirdparty.ts +1 -1
  19. package/source/js/_app/globals/tools.ts +3 -2
  20. package/source/js/_app/library/anime.ts +6 -5
  21. package/source/js/_app/library/declare.d.ts +18 -9
  22. package/source/js/_app/library/loadFile.ts +3 -1
  23. package/source/js/_app/library/proto.ts +75 -77
  24. package/source/js/_app/library/vue.ts +38 -48
  25. package/source/js/_app/page/fancybox.ts +2 -1
  26. package/source/js/_app/page/post.ts +4 -3
  27. package/source/js/_app/page/search.ts +17 -11
  28. package/source/js/_app/page/tab.ts +3 -2
  29. package/source/js/_app/pjax/domInit.ts +5 -4
  30. package/source/js/_app/pjax/refresh.ts +5 -2
  31. package/source/js/_app/pjax/siteInit.ts +12 -7
  32. package/source/js/_app/player.ts +16 -15
  33. package/scripts/filters/locals.d.ts +0 -1
  34. package/scripts/filters/locals.ts +0 -59
  35. package/scripts/filters/post.d.ts +0 -0
  36. package/scripts/filters/post.ts +0 -6
  37. package/scripts/generaters/archive.d.ts +0 -1
  38. package/scripts/generaters/archive.ts +0 -144
  39. package/scripts/generaters/config.d.ts +0 -1
  40. package/scripts/generaters/config.ts +0 -52
  41. package/scripts/generaters/images.d.ts +0 -1
  42. package/scripts/generaters/images.ts +0 -26
  43. package/scripts/generaters/index.d.ts +0 -1
  44. package/scripts/generaters/index.ts +0 -110
  45. package/scripts/generaters/pages.d.ts +0 -0
  46. package/scripts/generaters/pages.ts +0 -16
  47. package/scripts/generaters/script.d.ts +0 -1
  48. package/scripts/generaters/script.ts +0 -110
  49. package/scripts/helpers/asset.d.ts +0 -1
  50. package/scripts/helpers/asset.ts +0 -158
  51. package/scripts/helpers/engine.d.ts +0 -1
  52. package/scripts/helpers/engine.ts +0 -171
  53. package/scripts/helpers/list_categories.d.ts +0 -1
  54. package/scripts/helpers/list_categories.ts +0 -104
  55. package/scripts/helpers/summary_ai.d.ts +0 -1
  56. package/scripts/helpers/summary_ai.ts +0 -100
  57. package/scripts/helpers/symbols_count_time.d.ts +0 -1
  58. package/scripts/helpers/symbols_count_time.ts +0 -76
  59. package/scripts/plugin/check.d.ts +0 -1
  60. package/scripts/plugin/check.ts +0 -35
  61. package/scripts/plugin/index.d.ts +0 -6
  62. package/scripts/plugin/index.ts +0 -52
  63. package/scripts/plugin/lib/injects-point.d.ts +0 -5
  64. package/scripts/plugin/lib/injects-point.ts +0 -20
  65. package/scripts/plugin/lib/injects.d.ts +0 -2
  66. package/scripts/plugin/lib/injects.ts +0 -101
  67. package/scripts/tags/links.d.ts +0 -1
  68. package/scripts/tags/links.ts +0 -75
  69. package/scripts/tags/media.d.ts +0 -1
  70. package/scripts/tags/media.ts +0 -19
  71. package/source/assets/beian.webp +0 -0
  72. package/source/js/_app/library/libtype.d.ts +0 -4
@@ -1,84 +1,82 @@
1
1
  import { $dom } from './dom'
2
2
 
3
+ export const insertAfter = function (el: HTMLElement, element: HTMLElement): void {
4
+ const parent = el.parentNode
5
+ if (parent.lastChild === el) {
6
+ parent.appendChild(element)
7
+ } else {
8
+ parent.insertBefore(element, el.nextSibling)
9
+ }
10
+ }
11
+
12
+ /**
13
+ * 创建一个子节点并放置
14
+ */
15
+ export const createChild = function (parent: HTMLElement, tag: string, obj: object, positon?: string): HTMLElement {
16
+ const child = document.createElement(tag)
17
+ Object.assign(child, obj)
18
+ switch (positon) {
19
+ case 'after':
20
+ insertAfter(parent, child)
21
+ break
22
+ case 'replace':
23
+ parent.innerHTML = ''
24
+ parent.appendChild(child)
25
+ break
26
+ default:
27
+ parent.appendChild(child)
28
+ }
29
+ return child
30
+ }
31
+
32
+ /**
33
+ * 此方法使用`<div>`包装一个 DOM 元素
34
+ * @param parent
35
+ * @param obj 需要被包装的对象
36
+ */
37
+ export const wrapObject = function (parent: HTMLElement, obj: any): void {
38
+ const box = document.createElement('div')
39
+ Object.assign(box, obj)
40
+ parent.insertBefore(box, obj)
41
+ parent.removeChild(obj)
42
+ box.appendChild(obj)
43
+ }
44
+
45
+ export const getHeight = function (el: HTMLElement): number {
46
+ return el.getBoundingClientRect().height
47
+ }
48
+
49
+ export const setWidth = function (el: HTMLElement, w: number|string): void {
50
+ el.style.width = typeof w === 'number' ? w + 'rem' : w
51
+ }
52
+
53
+ export const getWidth = function (el: HTMLElement): number {
54
+ return el.getBoundingClientRect().width
55
+ }
56
+
57
+ export const getTop = function (el: HTMLElement): number {
58
+ return el.getBoundingClientRect().top
59
+ }
60
+
61
+ export const getLeft = function (el: HTMLElement): number {
62
+ return el.getBoundingClientRect().left
63
+ }
64
+
65
+ export const getDisplay = function (el: HTMLElement): string {
66
+ return el.style.display
67
+ }
68
+
69
+ export const setDisplay = function (el: HTMLElement, d: string): HTMLElement {
70
+ el.style.display = d
71
+ return el
72
+ }
73
+
74
+ // TODO 未完成迁移
75
+ export const child = function (el: HTMLElement, selector: string): HTMLElement {
76
+ return $dom(selector, (el as unknown as Document))
77
+ }
3
78
  export default function initProto () {
4
79
  Object.assign(HTMLElement.prototype, {
5
- /**
6
- * 创建一个子节点并放置
7
- */
8
- createChild (tag: string, obj: ElementCreationOptions, positon?: string): HTMLElement {
9
- const child = document.createElement(tag)
10
- Object.assign(child, obj)
11
- switch (positon) {
12
- case 'after':
13
- this.insertAfter(child)
14
- break
15
- case 'replace':
16
- this.innerHTML = ''
17
- this.appendChild(child)
18
- break
19
- default:
20
- this.appendChild(child)
21
- }
22
- return child
23
- },
24
- /**
25
- * 此方法使用`<div>`包装一个 DOM 元素
26
- * @param obj 需要被包装的对象
27
- */
28
- wrapObject (obj: HTMLElement) {
29
- const box = document.createElement('div')
30
- Object.assign(box, obj)
31
- this.parentNode.insertBefore(box, this)
32
- this.parentNode.removeChild(this)
33
- box.appendChild(this)
34
- },
35
- changeOrGetHeight (h?: number | string): number {
36
- if (h) {
37
- // TODO 0rem是期望的值吗?
38
- this.style.height = typeof h === 'number' ? h + 'rem' : h
39
- }
40
- return this.getBoundingClientRect().height
41
- },
42
- /**
43
- 此函数将元素的宽度设置为指定值,如果未提供值,则返回元素的宽度.<br />
44
- 宽度可以作为数字提供(假定它以`rem`为单位).作为字符串提供则直接设置为元素宽度
45
- */
46
- changeOrGetWidth (w?: number | string): number {
47
- if (w) {
48
- // TODO 0rem是期望的值吗?
49
- this.style.width = typeof w === 'number' ? w + 'rem' : w
50
- }
51
- return this.getBoundingClientRect().width
52
- },
53
- getTop (): number {
54
- return this.getBoundingClientRect().top
55
- },
56
- left (): number {
57
- return this.getBoundingClientRect().left
58
- },
59
- /**
60
- * 将此节点插入父节点的下一个节点之前
61
- */
62
- insertAfter (element: HTMLElement): void {
63
- const parent = this.parentNode
64
- if (parent.lastChild === this) {
65
- parent.appendChild(element)
66
- } else {
67
- parent.insertBefore(element, this.nextSibling)
68
- }
69
- },
70
- /**
71
- * 当d为空时返回此节点的CSSStyle display属性 <br />
72
- * 反之,将d设置为此节点的CSSStyle display属性
73
- */
74
- display (d?: string): string | EventTarget {
75
- if (d == null) {
76
- return this.style.display
77
- } else {
78
- this.style.display = d
79
- return this
80
- }
81
- },
82
80
  /**
83
81
  * 找到此节点第一个符合selector选择器的子节点
84
82
  */
@@ -3,58 +3,48 @@ import { transition } from './anime'
3
3
  import { $dom } from './dom'
4
4
  import { BODY } from '../globals/globalVars'
5
5
  import { changeTheme } from '../globals/themeColor'
6
-
6
+ import { child, createChild, setDisplay } from './proto'
7
7
  export function initVue () {
8
- Vue.createApp(
9
- {
10
- data () {
11
- return {
12
-
13
- }
14
- },
15
- methods: {
16
- changeThemeByBtn () {
17
- let c: { (): void; (): void; (): void }
18
- const btn = $dom('.theme').child('.ic')
8
+ function changeThemeByBtn () {
9
+ let c: { (): void; (): void; (): void }
10
+ const btn = child($dom('.theme'), '.ic')
19
11
 
20
- const neko = BODY.createChild('div', {
21
- id: 'neko',
22
- innerHTML: '<div class="planet"><div class="sun"></div><div class="moon"></div></div><div class="body"><div class="face"><section class="eyes left"><span class="pupil"></span></section><section class="eyes right"><span class="pupil"></span></section><span class="nose"></span></div></div>'
23
- })
12
+ const neko = createChild(BODY, 'div', {
13
+ id: 'neko',
14
+ innerHTML: '<div class="planet"><div class="sun"></div><div class="moon"></div></div><div class="body"><div class="face"><section class="eyes left"><span class="pupil"></span></section><section class="eyes right"><span class="pupil"></span></section><span class="nose"></span></div></div>'
15
+ })
24
16
 
25
- const hideNeko = () => {
26
- transition(neko, {
27
- // @ts-ignore
28
- delay: 2500,
29
- opacity: 0
30
- }, () => {
31
- BODY.removeChild(neko)
32
- })
33
- }
17
+ const hideNeko = () => {
18
+ transition(neko, {
19
+ // @ts-ignore
20
+ delay: 2500,
21
+ opacity: 0
22
+ }, () => {
23
+ BODY.removeChild(neko)
24
+ })
25
+ }
34
26
 
35
- if (btn.hasClass('i-sun')) {
36
- c = () => {
37
- neko.addClass('dark')
38
- changeTheme('dark')
39
- $storage.set('theme', 'dark')
40
- hideNeko()
41
- }
42
- } else {
43
- neko.addClass('dark')
44
- c = () => {
45
- neko.removeClass('dark')
46
- changeTheme()
47
- $storage.set('theme', 'light')
48
- hideNeko()
49
- }
50
- }
51
- transition(neko, 1, () => {
52
- setTimeout(c, 210)
53
- }, () => {
54
- neko.display('block')
55
- })
56
- }
27
+ if (btn.hasClass('i-sun')) {
28
+ c = () => {
29
+ neko.addClass('dark')
30
+ changeTheme('dark')
31
+ $storage.set('theme', 'dark')
32
+ hideNeko()
33
+ }
34
+ } else {
35
+ neko.addClass('dark')
36
+ c = () => {
37
+ neko.removeClass('dark')
38
+ changeTheme()
39
+ $storage.set('theme', 'light')
40
+ hideNeko()
57
41
  }
58
42
  }
59
- ).mount('#rightNav')
43
+ transition(neko, 1, () => {
44
+ setTimeout(c, 210)
45
+ }, () => {
46
+ setDisplay(neko, 'block')
47
+ })
48
+ }
49
+ child($dom('#rightNav'), '.theme .ic').addEventListener('click', changeThemeByBtn)
60
50
  }
@@ -1,5 +1,6 @@
1
1
  import { $dom } from '../library/dom'
2
2
  import { vendorCss, vendorJs } from '../library/loadFile'
3
+ import { insertAfter } from '../library/proto'
3
4
 
4
5
  export const postFancybox = (p:string) => {
5
6
  if ($dom(p + ' .md img')) {
@@ -38,7 +39,7 @@ export const postFancybox = (p:string) => {
38
39
  const txt = document.createTextNode(info)
39
40
  para.appendChild(txt)
40
41
  para.addClass(captionClass)
41
- element.insertAfter(para)
42
+ insertAfter(element, para)
42
43
  }
43
44
  })
44
45
 
@@ -4,6 +4,7 @@ import { clipBoard, showtip } from '../globals/tools'
4
4
  import { BODY } from '../globals/globalVars'
5
5
  import { pageScroll, transition } from '../library/anime'
6
6
  import { mediaPlayer } from '../player'
7
+ import { getDisplay, setDisplay, wrapObject } from '../library/proto'
7
8
 
8
9
  export const postBeauty = () => {
9
10
  if (!$dom('.md')) { return }
@@ -57,7 +58,7 @@ export const postBeauty = () => {
57
58
  })
58
59
 
59
60
  $dom.each('.md table', (element) => {
60
- element.wrapObject({
61
+ wrapObject(element, {
61
62
  className: 'table-container'
62
63
  })
63
64
  })
@@ -174,11 +175,11 @@ export const postBeauty = () => {
174
175
  element.addEventListener('click', (event) => {
175
176
  event.preventDefault()
176
177
  const qr = $dom('#qr')
177
- if (qr.display() === 'inline-flex') {
178
+ if (getDisplay(qr) === 'inline-flex') {
178
179
  transition(qr, 0)
179
180
  } else {
180
181
  transition(qr, 1, () => {
181
- qr.display('inline-flex')
182
+ setDisplay(qr, 'inline-flex')
182
183
  }) // slideUpBigIn
183
184
  }
184
185
  })
@@ -1,12 +1,17 @@
1
- import { BODY, setSiteSearch, siteSearch } from '../globals/globalVars'
1
+ import { BODY, CONFIG, setSiteSearch, siteSearch } from '../globals/globalVars'
2
2
  import { transition } from '../library/anime'
3
3
  import { $dom } from '../library/dom'
4
+ import { searchBox, configure, stats, hits, pagination } from 'instantsearch.js/es/widgets'
5
+ import type { HitHighlightResult } from 'instantsearch.js/es/types/results'
6
+ import instantsearch from 'instantsearch.js'
7
+ import algoliasearch from 'algoliasearch/lite'
8
+ import {createChild} from "../library/proto";
4
9
 
5
10
  export function algoliaSearch (pjax) {
6
11
  if (CONFIG.search === null) { return }
7
12
 
8
13
  if (!siteSearch) {
9
- setSiteSearch(BODY.createChild('div', {
14
+ setSiteSearch(createChild(BODY, 'div', {
10
15
  id: 'search',
11
16
  innerHTML: '<div class="inner"><div class="header"><span class="icon"><i class="ic i-search"></i></span><div class="search-input-container"></div><span class="close-btn"><i class="ic i-times-circle"></i></span></div><div class="results"><div class="inner"><div id="search-stats"></div><div id="search-hits"></div><div id="search-pagination"></div></div></div></div>'
12
17
  }))
@@ -15,8 +20,9 @@ export function algoliaSearch (pjax) {
15
20
  const search = instantsearch({
16
21
  indexName: CONFIG.search.indexName,
17
22
  searchClient: algoliasearch(CONFIG.search.appID, CONFIG.search.apiKey),
23
+ // TODO 移除弃用函数
18
24
  searchFunction (helper) {
19
- const searchInput = <HTMLInputElement><unknown>$dom('.search-input')
25
+ const searchInput = $dom('.search-input') as HTMLInputElement
20
26
  if (searchInput.value) {
21
27
  helper.search()
22
28
  }
@@ -29,11 +35,11 @@ export function algoliaSearch (pjax) {
29
35
 
30
36
  // Registering Widgets
31
37
  search.addWidgets([
32
- instantsearch.widgets.configure({
38
+ configure({
33
39
  hitsPerPage: CONFIG.search.hits.per_page || 10
34
40
  }),
35
41
 
36
- instantsearch.widgets.searchBox({
42
+ searchBox({
37
43
  container: '.search-input-container',
38
44
  placeholder: LOCAL.search.placeholder,
39
45
  // Hide default icons of algolia search
@@ -45,24 +51,24 @@ export function algoliaSearch (pjax) {
45
51
  }
46
52
  }),
47
53
 
48
- instantsearch.widgets.stats({
54
+ stats({
49
55
  container: '#search-stats',
50
56
  templates: {
51
57
  text (data) {
52
58
  const stats = LOCAL.search.stats
53
- .replace(/\$\{hits}/, data.nbHits)
54
- .replace(/\$\{time}/, data.processingTimeMS)
59
+ .replace(/\$\{hits}/, data.nbHits.toString())
60
+ .replace(/\$\{time}/, data.processingTimeMS.toString())
55
61
  return stats + '<span class="algolia-powered"></span><hr>'
56
62
  }
57
63
  }
58
64
  }),
59
65
 
60
- instantsearch.widgets.hits({
66
+ hits({
61
67
  container: '#search-hits',
62
68
  templates: {
63
69
  item (data) {
64
70
  const cats = data.categories ? '<span>' + data.categories.join('<i class="ic i-angle-right"></i>') + '</span>' : ''
65
- return '<a href="' + CONFIG.root + data.path + '">' + cats + data._highlightResult.title.value + '</a>'
71
+ return '<a href="' + CONFIG.root + data.path + '">' + cats + (data._highlightResult.title as HitHighlightResult).value + '</a>'
66
72
  },
67
73
  empty (data) {
68
74
  return '<div id="hits-empty">' +
@@ -75,7 +81,7 @@ export function algoliaSearch (pjax) {
75
81
  }
76
82
  }),
77
83
 
78
- instantsearch.widgets.pagination({
84
+ pagination({
79
85
  container: '#search-pagination',
80
86
  scrollTo: false,
81
87
  showFirst: false,
@@ -1,5 +1,6 @@
1
1
  import { pageScroll } from '../library/anime'
2
2
  import { $dom } from '../library/dom'
3
+ import { createChild } from '../library/proto'
3
4
 
4
5
  export const tabFormat = () => {
5
6
  // tab
@@ -29,13 +30,13 @@ export const tabFormat = () => {
29
30
 
30
31
  let ul = box.child('.nav ul')
31
32
  if (!ul) {
32
- ul = box.createChild('div', {
33
+ ul = createChild(box, 'div', {
33
34
  className: 'nav',
34
35
  innerHTML: '<ul></ul>'
35
36
  }).child('ul')
36
37
  }
37
38
 
38
- const li = ul.createChild('li', {
39
+ const li = createChild(ul, 'li', {
39
40
  innerHTML: title
40
41
  })
41
42
 
@@ -15,21 +15,22 @@ import {
15
15
  import { Loader } from '../globals/thirdparty'
16
16
  import { $dom } from '../library/dom'
17
17
  import { mediaPlayer } from '../player'
18
+ import { child, createChild } from '../library/proto'
18
19
 
19
20
  export default function domInit () {
20
21
  $dom.each('.overview .menu > .item', (el) => {
21
- siteNav.child('.menu').appendChild(el.cloneNode(true))
22
+ child(siteNav, '.menu').appendChild(el.cloneNode(true))
22
23
  })
23
24
 
24
25
  loadCat.addEventListener('click', Loader.vanish)
25
26
  menuToggle.addEventListener('click', sideBarToggleHandle)
26
27
  $dom('.dimmer').addEventListener('click', sideBarToggleHandle)
27
28
 
28
- quickBtn.child('.down').addEventListener('click', goToBottomHandle)
29
- quickBtn.child('.up').addEventListener('click', backToTopHandle)
29
+ child(quickBtn, '.down').addEventListener('click', goToBottomHandle)
30
+ child(quickBtn, '.up').addEventListener('click', backToTopHandle)
30
31
 
31
32
  if (!toolBtn) {
32
- setToolBtn(siteHeader.createChild('div', {
33
+ setToolBtn(createChild(siteHeader, 'div', {
33
34
  id: 'tool',
34
35
  innerHTML: '<div class="item player"></div><div class="item contents"><i class="ic i-list-ol"></i></div><div class="item chat"><i class="ic i-comments"></i></div><div class="item back-to-top"><i class="ic i-arrow-up"></i><span>0%</span></div>'
35
36
  }))
@@ -1,11 +1,11 @@
1
1
  import { $dom } from '../library/dom'
2
2
  import { cardActive } from '../page/common'
3
- import { postBeauty } from '../page/post'
4
3
  import { pageScroll, transition } from '../library/anime'
5
4
  import { vendorCss, vendorJs } from '../library/loadFile'
6
5
  import { pjaxScript } from '../library/scriptPjax'
7
6
  import { resizeHandle } from '../globals/handles'
8
7
  import {
8
+ CONFIG,
9
9
  loadCat,
10
10
  menuToggle,
11
11
  setLocalHash, setLocalUrl, setOriginTitle,
@@ -53,7 +53,10 @@ export const siteRefresh = (reload) => {
53
53
  sideBarTab()
54
54
  sidebarTOC()
55
55
 
56
- postBeauty()
56
+ import('../page/post').then(({ postBeauty }) => {
57
+ postBeauty()
58
+ })
59
+
57
60
  if (__shokax_tabs__) {
58
61
  tabFormat()
59
62
  }
@@ -1,19 +1,17 @@
1
1
  import domInit from './domInit'
2
2
  import { pjaxReload, siteRefresh } from './refresh'
3
3
  import { cloudflareInit } from '../library/scriptPjax'
4
- import { algoliaSearch } from '../page/search'
5
- import { pjax, setPjax } from '../globals/globalVars'
4
+ import { CONFIG, pjax, setPjax } from '../globals/globalVars'
6
5
  import { autoDarkmode, themeColorListener } from '../globals/themeColor'
7
6
  import { resizeHandle, scrollHandle, visibilityListener } from '../globals/handles'
8
7
  import { pagePosition } from '../globals/tools'
9
8
  import Pjax from 'theme-shokax-pjax'
10
9
  import { initVue } from '../library/vue'
11
10
  import { lazyLoad } from 'unlazy'
12
- import firework from 'mouse-firework'
13
11
 
14
12
  const siteInit = () => {
15
- domInit()
16
13
  initVue()
14
+ domInit()
17
15
 
18
16
  setPjax(new Pjax({
19
17
  selectors: [
@@ -28,7 +26,10 @@ const siteInit = () => {
28
26
  }))
29
27
 
30
28
  CONFIG.quicklink.ignores = LOCAL.ignores
31
- quicklink.listen(CONFIG.quicklink)
29
+ import('quicklink').then(({ listen }) => {
30
+ listen(CONFIG.quicklink)
31
+ })
32
+
32
33
  autoDarkmode()
33
34
 
34
35
  if (__shokax_VL__) {
@@ -36,11 +37,15 @@ const siteInit = () => {
36
37
  }
37
38
  themeColorListener()
38
39
  if (__shokax_search__) {
39
- algoliaSearch(pjax)
40
+ import('../page/search').then(({ algoliaSearch }) => {
41
+ algoliaSearch(pjax)
42
+ })
40
43
  }
41
44
 
42
45
  if (__shokax_fireworks__) {
43
- firework(CONFIG.fireworks)
46
+ import('mouse-firework').then((firework) => {
47
+ firework.default(CONFIG.fireworks)
48
+ })
44
49
  }
45
50
  lazyLoad()
46
51
 
@@ -1,9 +1,10 @@
1
- import { originTitle } from './globals/globalVars'
1
+ import { CONFIG, originTitle } from './globals/globalVars'
2
2
  import { showtip } from './globals/tools'
3
3
  import { pageScroll } from './library/anime'
4
4
  import { $dom } from './library/dom'
5
5
  import { $storage } from './library/storage'
6
6
  import { tabFormat } from './page/tab'
7
+ import { createChild, getLeft, getWidth, setDisplay, setWidth } from './library/proto'
7
8
 
8
9
  let NOWPLAYING = null
9
10
 
@@ -16,7 +17,7 @@ export const mediaPlayer = (t, config?) => {
16
17
  t.player.options.btns.forEach((item) => {
17
18
  if (buttons.el[item]) { return }
18
19
 
19
- buttons.el[item] = t.createChild('div', {
20
+ buttons.el[item] = createChild(t, 'div', {
20
21
  className: item + ' btn',
21
22
  onclick (event) {
22
23
  t.player.fetch().then(() => {
@@ -64,7 +65,7 @@ export const mediaPlayer = (t, config?) => {
64
65
 
65
66
  opt.className = item + opt.className + ' btn'
66
67
 
67
- that.btns[item] = that.el.createChild('div', opt)
68
+ that.btns[item] = createChild(that.el, 'div', opt)
68
69
  })
69
70
 
70
71
  that.btns.volume.bar = that.btns.volume.child('.bar')
@@ -130,10 +131,10 @@ export const mediaPlayer = (t, config?) => {
130
131
  },
131
132
  update (percent) {
132
133
  controller.btns.volume.className = 'volume ' + (!source.muted && percent > 0 ? 'on' : 'off') + ' btn'
133
- controller.btns.volume.bar.changeOrGetWidth(Math.floor(percent * 100) + '%')
134
+ setWidth(controller.btns.volume.bar, Math.floor(percent * 100) + '%')
134
135
  },
135
136
  percent (e, el) {
136
- let percentage = ((e.clientX || e.changedTouches[0].clientX) - el.left()) / el.changeOrGetWidth()
137
+ let percentage = ((e.clientX || e.changedTouches[0].clientX) - getLeft(el)) / getWidth(el)
137
138
  percentage = Math.max(percentage, 0)
138
139
  return Math.min(percentage, 1)
139
140
  }
@@ -151,13 +152,13 @@ export const mediaPlayer = (t, config?) => {
151
152
  progress.el.remove()
152
153
  }
153
154
 
154
- progress.el = current.createChild('div', {
155
+ progress.el = createChild(current, 'div', {
155
156
  className: 'progress'
156
157
  });
157
158
 
158
159
  (progress.el as HTMLElement).setAttribute('data-dtime', utils.secondToTime(0))
159
160
 
160
- progress.bar = progress.el.createChild('div', {
161
+ progress.bar = createChild(progress.el, 'div', {
161
162
  className: 'bar'
162
163
  })
163
164
 
@@ -169,14 +170,14 @@ export const mediaPlayer = (t, config?) => {
169
170
  }
170
171
  },
171
172
  update (percent) {
172
- progress.bar.changeOrGetWidth(Math.floor(percent * 100) + '%');
173
+ setWidth(progress.bar, Math.floor(percent * 100) + '%');
173
174
  (progress.el as HTMLElement).setAttribute('data-ptime', utils.secondToTime(percent * source.duration))
174
175
  },
175
176
  seeking (type) {
176
177
  if (type) { progress.el.addClass('seeking') } else { progress.el.removeClass('seeking') }
177
178
  },
178
179
  percent (e, el) {
179
- let percentage = ((e.clientX || e.changedTouches[0].clientX) - el.left()) / el.changeOrGetWidth()
180
+ let percentage = ((e.clientX || e.changedTouches[0].clientX) - getLeft(el)) / getWidth(el)
180
181
  percentage = Math.max(percentage, 0)
181
182
  return Math.min(percentage, 1)
182
183
  },
@@ -258,7 +259,7 @@ export const mediaPlayer = (t, config?) => {
258
259
  const id = 'list-' + t.player._id + '-' + item.group
259
260
  let tab = $dom('#' + id)
260
261
  if (!tab) {
261
- tab = el.createChild('div', {
262
+ tab = createChild(el, 'div', {
262
263
  id,
263
264
  className: t.player.group ? 'tab' : '',
264
265
  innerHTML: '<ol></ol>'
@@ -269,7 +270,7 @@ export const mediaPlayer = (t, config?) => {
269
270
  }
270
271
  }
271
272
 
272
- item.el = tab.child('ol').createChild('li', {
273
+ item.el = createChild(tab.child('ol'), 'li', {
273
274
  title: item.name + ' - ' + item.artist,
274
275
  innerHTML: '<span class="info"><span>' + item.name + '</span><span>' + item.artist + '</span></span>',
275
276
  onclick (event) {
@@ -329,7 +330,7 @@ export const mediaPlayer = (t, config?) => {
329
330
  create () {
330
331
  if (this.el) { return }
331
332
 
332
- this.el = t.createChild('div', {
333
+ this.el = createChild(t, 'div', {
333
334
  className: 'player-info',
334
335
  innerHTML: (t.player.options.type === 'audio' ? '<div class="preview"></div>' : '') + '<div class="controller"></div><div class="playlist"></div>'
335
336
  }, 'after')
@@ -469,7 +470,7 @@ export const mediaPlayer = (t, config?) => {
469
470
  this.pause()
470
471
  }
471
472
  for (const el in buttons.el) {
472
- buttons.el[el].display(d)
473
+ setDisplay(buttons.el[el], d)
473
474
  }
474
475
  return this
475
476
  },
@@ -662,7 +663,7 @@ export const mediaPlayer = (t, config?) => {
662
663
  lrc += '<p' + (index === 0 ? ' class="current"' : '') + '>' + line[1] + '</p>'
663
664
  })
664
665
 
665
- this.el = box.createChild('div', {
666
+ this.el = createChild(box, 'div', {
666
667
  className: 'inner',
667
668
  innerHTML: lrc
668
669
  }, 'replace')
@@ -783,7 +784,7 @@ export const mediaPlayer = (t, config?) => {
783
784
  buttons.create()
784
785
 
785
786
  // 初始化audio or video
786
- source = t.createChild(t.player.options.type, events)
787
+ source = createChild(t, t.player.options.type, events)
787
788
  // 初始化播放列表、预览、控件按钮等
788
789
  info.create()
789
790
 
@@ -1 +0,0 @@
1
- declare const fmtNum: (num: any) => any;