hexo-theme-shokax 0.3.9 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. package/README.md +4 -1
  2. package/_config.yml +26 -28
  3. package/layout/_mixin/comment.pug +1 -34
  4. package/layout/_mixin/segment.pug +1 -1
  5. package/layout/_partials/head/head.pug +1 -4
  6. package/layout/_partials/layout.pug +2 -2
  7. package/package.json +18 -17
  8. package/scripts/filters/locals.js +6 -0
  9. package/scripts/filters/post.js +2 -0
  10. package/scripts/generaters/archive.js +13 -1
  11. package/scripts/generaters/config.js +4 -1
  12. package/scripts/generaters/images.js +2 -0
  13. package/scripts/generaters/index.js +5 -2
  14. package/scripts/generaters/pages.js +0 -2
  15. package/scripts/generaters/script.js +34 -9
  16. package/scripts/helpers/asset.js +16 -7
  17. package/scripts/helpers/engine.js +24 -1
  18. package/scripts/helpers/list_categories.js +4 -0
  19. package/scripts/helpers/summary_ai.js +4 -0
  20. package/scripts/helpers/symbols_count_time.js +14 -8
  21. package/scripts/plugin/check.js +5 -3
  22. package/scripts/plugin/index.js +36 -9
  23. package/scripts/plugin/lib/injects.js +15 -0
  24. package/scripts/tags/media.js +1 -0
  25. package/source/js/_app/components/sidebar.js +54 -56
  26. package/source/js/_app/fireworks.js +6 -137
  27. package/source/js/_app/globals/globalVars.js +80 -96
  28. package/source/js/_app/globals/handles.js +81 -60
  29. package/source/js/_app/globals/themeColor.js +30 -26
  30. package/source/js/_app/globals/thirdparty.js +25 -24
  31. package/source/js/_app/globals/tools.js +36 -30
  32. package/source/js/_app/library/anime.js +31 -17
  33. package/source/js/_app/library/dom.js +12 -5
  34. package/source/js/_app/library/loadFile.js +7 -9
  35. package/source/js/_app/library/proto.js +59 -7
  36. package/source/js/_app/library/scriptPjax.js +14 -9
  37. package/source/js/_app/library/storage.js +2 -4
  38. package/source/js/_app/library/vue.js +16 -19
  39. package/source/js/_app/page/comment.js +10 -11
  40. package/source/js/_app/page/common.js +8 -12
  41. package/source/js/_app/page/fancybox.js +13 -14
  42. package/source/js/_app/page/post.js +43 -45
  43. package/source/js/_app/page/search.js +20 -20
  44. package/source/js/_app/page/tab.js +7 -10
  45. package/source/js/_app/pjax/domInit.js +29 -29
  46. package/source/js/_app/pjax/refresh.js +45 -50
  47. package/source/js/_app/pjax/siteInit.js +27 -31
  48. package/source/js/_app/player.js +44 -27
  49. package/test/dom.test.js +0 -86
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ /* global hexo */
2
3
  const prepareQuery = (categories, parent) => {
3
4
  const query = {
4
5
  parent: undefined
@@ -12,6 +13,7 @@ const prepareQuery = (categories, parent) => {
12
13
  return categories.find(query).sort('name', 1).filter(cat => cat.length);
13
14
  };
14
15
  hexo.extend.helper.register('_list_categories', function (depth = 0) {
16
+ // let hexo = this
15
17
  const categories = this.site.categories;
16
18
  if (!categories || !categories.length)
17
19
  return '';
@@ -46,6 +48,7 @@ hexo.extend.helper.register('_list_categories', function (depth = 0) {
46
48
  return hierarchicalList(0);
47
49
  });
48
50
  hexo.extend.helper.register('_category_prev', function (name) {
51
+ // let hexo = this
49
52
  const categories = this.site.categories;
50
53
  if (!categories || !categories.length)
51
54
  return '';
@@ -60,6 +63,7 @@ hexo.extend.helper.register('_category_prev', function (name) {
60
63
  return result;
61
64
  });
62
65
  hexo.extend.helper.register('_category_posts', function (page) {
66
+ // let hexo = this
63
67
  const categories = this.site.categories;
64
68
  if (!categories || !categories.length || !page.categories || !page.categories.length)
65
69
  return '';
@@ -10,6 +10,7 @@ function getContent(post) {
10
10
  let db;
11
11
  function postMessage(path, content, dbPath, startMessage) {
12
12
  if (node_fs_1.default.existsSync('summary.json')) {
13
+ // @ts-ignore
13
14
  db = JSON.parse(node_fs_1.default.readFileSync('summary.json'));
14
15
  }
15
16
  else {
@@ -39,6 +40,7 @@ function postMessage(path, content, dbPath, startMessage) {
39
40
  throw Error('ERROR: Failed to get summary from Openai API');
40
41
  }
41
42
  response.json().then((data) => {
43
+ // @ts-ignore
42
44
  const summary = data.choices[0].message.content;
43
45
  try {
44
46
  db[path][dbPath] = summary;
@@ -63,6 +65,7 @@ function postMessage(path, content, dbPath, startMessage) {
63
65
  setTimeout(checkTime, 1000 * waitTime);
64
66
  return;
65
67
  }
68
+ // Openai API 针对个人用户免费试用限制 3 RPM,这里是25s后发送请求
66
69
  node_fs_1.default.writeFileSync('requested.lock', '');
67
70
  setTimeout(request, 1000 * 2.5 * waitTime);
68
71
  node_fs_1.default.unlinkSync('request.lock');
@@ -92,6 +95,7 @@ function postMessage(path, content, dbPath, startMessage) {
92
95
  }
93
96
  }
94
97
  else {
98
+ // custom尚未支持
95
99
  }
96
100
  }
97
101
  }
@@ -1,5 +1,11 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* global hexo */
4
+ /*!
5
+ hexo-symbols-count-time by theme-next
6
+ under GNU Lesser General Public License v3.0 or later
7
+ https://github.com/theme-next/hexo-symbols-count-time/blob/master/LICENSE
8
+ */
3
9
  const hexo_util_1 = require("hexo-util");
4
10
  const config = hexo.config.symbols_count_time = Object.assign({
5
11
  symbols: true,
@@ -25,20 +31,20 @@ function getFormatTime(minutes, suffix) {
25
31
  const fHours = Math.floor(minutes / 60);
26
32
  let fMinutes = Math.floor(minutes - (fHours * 60));
27
33
  if (fMinutes < 1) {
28
- fMinutes = 1;
34
+ fMinutes = 1; // 0 => 1
29
35
  }
30
36
  return fHours < 1
31
- ? fMinutes + ' ' + suffix
32
- : fHours + ':' + ('00' + fMinutes).slice(-2);
37
+ ? fMinutes + ' ' + suffix // < 59 => 59 mins.
38
+ : fHours + ':' + ('00' + fMinutes).slice(-2); // = 61 => 1:01
33
39
  }
34
40
  hexo.extend.helper.register('symbolsCount', function (post) {
35
41
  let symbolsResult = getSymbols(post);
36
42
  if (symbolsResult > 9999) {
37
- symbolsResult = Math.round(symbolsResult / 1000) + 'k';
43
+ symbolsResult = Math.round(symbolsResult / 1000) + 'k'; // > 9999 => 11k
38
44
  }
39
45
  else if (symbolsResult > 999) {
40
- symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k';
41
- }
46
+ symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k'; // > 999 => 1.1k
47
+ } // < 999 => 111
42
48
  return symbolsResult;
43
49
  });
44
50
  hexo.extend.helper.register('symbolsTime', function (post, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
@@ -48,8 +54,8 @@ hexo.extend.helper.register('symbolsTime', function (post, awl = config.awl, wpm
48
54
  hexo.extend.helper.register('symbolsCountTotal', function (site) {
49
55
  const symbolsResultTotal = getSymbolsTotal(site);
50
56
  return symbolsResultTotal < 1000000
51
- ? Math.round(symbolsResultTotal / 1000) + 'k'
52
- : Math.round(symbolsResultTotal / 100000) / 10 + 'm';
57
+ ? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 111k
58
+ : Math.round(symbolsResultTotal / 100000) / 10 + 'm'; // > 999k => 1.1m
53
59
  });
54
60
  hexo.extend.helper.register('symbolsTimeTotal', function (site, awl = config.awl, wpm = config.wpm, suffix = config.suffix) {
55
61
  const minutes = Math.round(getSymbolsTotal(site) / (awl * wpm));
@@ -1,10 +1,11 @@
1
+ /* global hexo */
1
2
  let findProblem = false;
2
3
  hexo.on('generateBefore', function () {
3
4
  if (hexo.config.syntax_highlighter) {
4
5
  findProblem = true;
5
6
  hexo.log.error('[SXEC 101] Highlight.js or Prismjs enabled. The code block will render incomplete');
6
7
  }
7
- if (!hexo.config.autoprefixer || !hexo.config.markdown) {
8
+ if (!hexo.config.markdown) {
8
9
  findProblem = true;
9
10
  hexo.log.error(`[SXEC 102] Critical rendering plugins are missing or incorrectly configured.
10
11
  Some features will be disabled or render incorrectly`);
@@ -17,8 +18,9 @@ Some features will be disabled or render incorrectly`);
17
18
  findProblem = true;
18
19
  hexo.log.warn('[SXEC 201] Essential information(title, desc, lang, etc) config incorrectly, Page will render incorrectly');
19
20
  }
20
- if (hexo.theme.config.gitalk.clientID || hexo.theme.config.giscus.repo) {
21
- hexo.log.info('You are using an untested feature and there may be undiscovered issues');
21
+ if (hexo.theme.config.gitalk?.clientID || hexo.theme.config.giscus?.repo) {
22
+ findProblem = true;
23
+ hexo.log.warn('[SXEC 202] You are using an deprecated feature and it was removed in the v0.3.10');
22
24
  }
23
25
  });
24
26
  hexo.on('generateAfter', function () {
@@ -4,25 +4,52 @@
4
4
  under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
5
5
  https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
6
6
  */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || function (mod) {
24
+ if (mod && mod.__esModule) return mod;
25
+ var result = {};
26
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ __setModuleDefault(result, mod);
28
+ return result;
29
+ };
7
30
  var __importDefault = (this && this.__importDefault) || function (mod) {
8
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
9
32
  };
10
33
  Object.defineProperty(exports, "__esModule", { value: true });
11
34
  const injects_1 = __importDefault(require("./lib/injects"));
12
- const node_https_1 = __importDefault(require("node:https"));
13
- const package_json_1 = require("../../package.json");
14
- const node_fs_1 = __importDefault(require("node:fs"));
35
+ const node_https_1 = require("node:https");
36
+ // @ts-ignore
37
+ // import { version } from '../../package.json'
38
+ const fs = __importStar(require("node:fs"));
39
+ const version = '0.3.10';
15
40
  hexo.on('generateBefore', () => {
41
+ // 加载`theme_injects`过滤器
16
42
  (0, injects_1.default)(hexo);
17
- if (node_fs_1.default.existsSync('request.lock')) {
18
- node_fs_1.default.unlinkSync('request.lock');
43
+ if (fs.existsSync('request.lock')) {
44
+ fs.unlinkSync('request.lock');
19
45
  }
20
- if (node_fs_1.default.existsSync('requested.lock')) {
21
- node_fs_1.default.unlinkSync('requested.lock');
46
+ if (fs.existsSync('requested.lock')) {
47
+ fs.unlinkSync('requested.lock');
22
48
  }
23
49
  });
24
50
  hexo.on('generateAfter', () => {
25
- node_https_1.default.get('https://api.github.com/repos/theme-shoka-x/hexo-theme-shokaX/releases/latest', {
51
+ // 检查版本更新
52
+ (0, node_https_1.get)('https://api.github.com/repos/theme-shoka-x/hexo-theme-shokaX/releases/latest', {
26
53
  headers: {
27
54
  'User-Agent': 'Theme ShokaX Client'
28
55
  }
@@ -34,7 +61,7 @@ hexo.on('generateAfter', () => {
34
61
  res.on('end', () => {
35
62
  try {
36
63
  const latest = JSON.parse(result).tag_name.replace('v', '').split('.');
37
- const current = package_json_1.version.split('.');
64
+ const current = version.split('.');
38
65
  let isOutdated = false;
39
66
  for (let i = 0; i < Math.max(latest.length, current.length); i++) {
40
67
  if (!current[i] || latest[i] > current[i]) {
@@ -3,6 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ /*!
7
+ inject.js in next-theme/hexo-theme-next by next-theme
8
+ under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
9
+ https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
10
+ */
6
11
  const node_fs_1 = __importDefault(require("node:fs"));
7
12
  const node_path_1 = __importDefault(require("node:path"));
8
13
  const injects_point_1 = __importDefault(require("./injects-point"));
@@ -18,6 +23,7 @@ class StylusInject {
18
23
  this.files.push(node_path_1.default.resolve(this.base_dir, file));
19
24
  }
20
25
  }
26
+ // Defining view types
21
27
  class ViewInject {
22
28
  base_dir;
23
29
  raws;
@@ -26,18 +32,22 @@ class ViewInject {
26
32
  this.raws = [];
27
33
  }
28
34
  raw(name, raw, ...args) {
35
+ // Set default extname
29
36
  if (node_path_1.default.extname(name) === '') {
30
37
  name += defaultExtname;
31
38
  }
32
39
  this.raws.push({ name, raw, args });
33
40
  }
34
41
  file(name, file, ...args) {
42
+ // Set default extname from file's extname
35
43
  if (node_path_1.default.extname(name) === '') {
36
44
  name += node_path_1.default.extname(file);
37
45
  }
46
+ // Get absolute path base on hexo dir
38
47
  this.raw(name, node_fs_1.default.readFileSync(node_path_1.default.resolve(this.base_dir, file), 'utf8'), ...args);
39
48
  }
40
49
  }
50
+ // Init injects
41
51
  function initInject(base_dir) {
42
52
  const injects = {};
43
53
  injects_point_1.default.styles.forEach(item => {
@@ -49,15 +59,19 @@ function initInject(base_dir) {
49
59
  return injects;
50
60
  }
51
61
  exports.default = (hexo) => {
62
+ // Exec theme_inject filter
52
63
  const injects = initInject(hexo.base_dir);
53
64
  hexo.execFilterSync('theme_inject', injects);
54
65
  hexo.theme.config.injects = {};
66
+ // Inject stylus
55
67
  injects_point_1.default.styles.forEach(type => {
56
68
  hexo.theme.config.injects[type] = injects[type].files;
57
69
  });
70
+ // Inject views
58
71
  injects_point_1.default.views.forEach(type => {
59
72
  const configs = Object.create(null);
60
73
  hexo.theme.config.injects[type] = [];
74
+ // Add or override view.
61
75
  injects[type].raws.forEach((injectObj, index) => {
62
76
  const name = `inject/${type}/${injectObj.name}`;
63
77
  hexo.theme.setView(name, injectObj.raw);
@@ -68,6 +82,7 @@ exports.default = (hexo) => {
68
82
  order: injectObj.args[2] || index
69
83
  };
70
84
  });
85
+ // Views sort.
71
86
  hexo.theme.config.injects[type] = Object.values(configs)
72
87
  .sort((x, y) => x.order - y.order);
73
88
  });
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* global hexo */
6
7
  const js_yaml_1 = __importDefault(require("js-yaml"));
7
8
  function postMedia(args, content) {
8
9
  if (!args[0] || !content) {
@@ -1,52 +1,53 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.menuActive = exports.goToCommentHandle = exports.goToBottomHandle = exports.backToTopHandle = exports.sidebarTOC = exports.sideBarTab = exports.sideBarToggleHandle = void 0;
4
- const globalVars_1 = require("../globals/globalVars");
5
- const tools_1 = require("../globals/tools");
6
- const anime_1 = require("../library/anime");
7
- const dom_1 = require("../library/dom");
8
- const sideBarToggleHandle = (event, force) => {
9
- if (globalVars_1.sideBar.hasClass('on')) {
10
- globalVars_1.sideBar.removeClass('on');
11
- globalVars_1.menuToggle.removeClass('close');
1
+ /* 边栏分区 */
2
+ import { Container, diffY, menuToggle, showContents, sideBar } from '../globals/globalVars';
3
+ import { clipBoard } from '../globals/tools';
4
+ import { pageScroll, transition } from '../library/anime';
5
+ import { $dom } from '../library/dom';
6
+ export const sideBarToggleHandle = (event, force) => {
7
+ if (sideBar.hasClass('on')) {
8
+ sideBar.removeClass('on');
9
+ menuToggle.removeClass('close');
12
10
  if (force) {
13
- globalVars_1.sideBar.style = '';
11
+ // @ts-ignore
12
+ // noinspection JSConstantReassignment
13
+ sideBar.style = '';
14
14
  }
15
15
  else {
16
- (0, anime_1.transition)(globalVars_1.sideBar, 'slideRightOut');
16
+ transition(sideBar, 'slideRightOut');
17
17
  }
18
18
  }
19
19
  else {
20
20
  if (force) {
21
- globalVars_1.sideBar.style = '';
21
+ // @ts-ignore
22
+ // noinspection JSConstantReassignment
23
+ sideBar.style = '';
22
24
  }
23
25
  else {
24
- (0, anime_1.transition)(globalVars_1.sideBar, 'slideRightIn', () => {
25
- globalVars_1.sideBar.addClass('on');
26
- globalVars_1.menuToggle.addClass('close');
26
+ transition(sideBar, 'slideRightIn', () => {
27
+ sideBar.addClass('on');
28
+ menuToggle.addClass('close');
27
29
  });
28
30
  }
29
31
  }
30
32
  };
31
- exports.sideBarToggleHandle = sideBarToggleHandle;
32
- const sideBarTab = () => {
33
- const sideBarInner = globalVars_1.sideBar.child('.inner');
34
- if (globalVars_1.sideBar.child('.tab')) {
35
- sideBarInner.removeChild(globalVars_1.sideBar.child('.tab'));
33
+ export const sideBarTab = () => {
34
+ const sideBarInner = sideBar.child('.inner');
35
+ if (sideBar.child('.tab')) {
36
+ sideBarInner.removeChild(sideBar.child('.tab'));
36
37
  }
37
38
  const list = document.createElement('ul');
38
39
  let active = 'active';
39
40
  list.className = 'tab';
40
41
  ['contents', 'related', 'overview'].forEach((item) => {
41
- const element = globalVars_1.sideBar.child('.panel.' + item);
42
+ const element = sideBar.child('.panel.' + item);
42
43
  if (element.innerHTML.trim().length < 1) {
43
44
  if (item === 'contents') {
44
- globalVars_1.showContents.display('none');
45
+ showContents.display('none');
45
46
  }
46
47
  return;
47
48
  }
48
49
  if (item === 'contents') {
49
- globalVars_1.showContents.display('');
50
+ showContents.display('');
50
51
  }
51
52
  const tab = document.createElement('li');
52
53
  const span = document.createElement('span');
@@ -65,13 +66,13 @@ const sideBarTab = () => {
65
66
  const target = event.currentTarget;
66
67
  if (target.hasClass('active'))
67
68
  return;
68
- globalVars_1.sideBar.find('.tab .item').forEach((element) => {
69
+ sideBar.find('.tab .item').forEach((element) => {
69
70
  element.removeClass('active');
70
71
  });
71
- globalVars_1.sideBar.find('.panel').forEach((element) => {
72
+ sideBar.find('.panel').forEach((element) => {
72
73
  element.removeClass('active');
73
74
  });
74
- globalVars_1.sideBar.child('.panel.' + target.className.replace(' item', '')).addClass('active');
75
+ sideBar.child('.panel.' + target.className.replace(' item', '')).addClass('active');
75
76
  target.addClass('active');
76
77
  });
77
78
  list.appendChild(tab);
@@ -79,14 +80,13 @@ const sideBarTab = () => {
79
80
  });
80
81
  if (list.childNodes.length > 1) {
81
82
  sideBarInner.insertBefore(list, sideBarInner.childNodes[0]);
82
- globalVars_1.sideBar.child('.panels').style.paddingTop = '';
83
+ sideBar.child('.panels').style.paddingTop = '';
83
84
  }
84
85
  else {
85
- globalVars_1.sideBar.child('.panels').style.paddingTop = '.625rem';
86
+ sideBar.child('.panels').style.paddingTop = '.625rem';
86
87
  }
87
88
  };
88
- exports.sideBarTab = sideBarTab;
89
- const sidebarTOC = () => {
89
+ export const sidebarTOC = () => {
90
90
  const activateNavByIndex = (index) => {
91
91
  const target = navItems[index];
92
92
  if (!target)
@@ -94,7 +94,7 @@ const sidebarTOC = () => {
94
94
  if (target.hasClass('current')) {
95
95
  return;
96
96
  }
97
- dom_1.$dom.each('.toc .active', (element) => {
97
+ $dom.each('.toc .active', (element) => {
98
98
  element && element.removeClass('active current');
99
99
  });
100
100
  sections.forEach((element) => {
@@ -106,46 +106,49 @@ const sidebarTOC = () => {
106
106
  while (!parent.matches('.contents')) {
107
107
  if (parent.matches('li')) {
108
108
  parent.addClass('active');
109
- const t = (0, dom_1.$dom)(parent.child('a.toc-link').attr('href'));
109
+ const t = $dom(parent.child('a.toc-link').attr('href'));
110
110
  if (t) {
111
111
  t.addClass('active');
112
112
  }
113
113
  }
114
114
  parent = parent.parentNode;
115
115
  }
116
- if (getComputedStyle(globalVars_1.sideBar).display !== 'none' && tocElement.hasClass('active')) {
117
- (0, anime_1.pageScroll)(tocElement, target.offsetTop - (tocElement.offsetHeight / 4));
116
+ // Scrolling to center active TOC element if TOC content is taller than viewport.
117
+ if (getComputedStyle(sideBar).display !== 'none' && tocElement.hasClass('active')) {
118
+ pageScroll(tocElement, target.offsetTop - (tocElement.offsetHeight / 4));
118
119
  }
119
120
  };
120
- const navItems = dom_1.$dom.all('.contents li');
121
+ const navItems = $dom.all('.contents li');
121
122
  if (navItems.length < 1) {
122
123
  return;
123
124
  }
125
+ // @ts-ignore
124
126
  let sections = [...navItems];
125
127
  let activeLock = null;
126
128
  sections = sections.map((element, index) => {
127
129
  const link = element.child('a.toc-link');
128
- const anchor = (0, dom_1.$dom)(decodeURI(link.attr('href')));
130
+ const anchor = $dom(decodeURI(link.attr('href')));
129
131
  if (!anchor)
130
132
  return null;
131
133
  const alink = anchor.child('a.anchor');
132
134
  const anchorScroll = (event) => {
133
135
  event.preventDefault();
134
- const target = (0, dom_1.$dom)(decodeURI(event.currentTarget.attr('href')));
136
+ const target = $dom(decodeURI(event.currentTarget.attr('href')));
135
137
  activeLock = index;
136
- (0, anime_1.pageScroll)(target, null, () => {
138
+ pageScroll(target, null, () => {
137
139
  activateNavByIndex(index);
138
140
  activeLock = null;
139
141
  });
140
142
  };
143
+ // TOC item animation navigate.
141
144
  link.addEventListener('click', anchorScroll);
142
145
  alink && alink.addEventListener('click', (event) => {
143
146
  anchorScroll(event);
144
- (0, tools_1.clipBoard)(CONFIG.hostname + '/' + LOCAL.path + event.currentTarget.attr('href'));
147
+ clipBoard(CONFIG.hostname + '/' + LOCAL.path + event.currentTarget.attr('href'));
145
148
  });
146
149
  return anchor;
147
150
  });
148
- const tocElement = globalVars_1.sideBar.child('.contents.panel');
151
+ const tocElement = sideBar.child('.contents.panel');
149
152
  const findIndex = (entries) => {
150
153
  let index = 0;
151
154
  let entry = entries[index];
@@ -165,7 +168,7 @@ const sidebarTOC = () => {
165
168
  };
166
169
  const createIntersectionObserver = () => {
167
170
  const observer = new IntersectionObserver((entries) => {
168
- const index = findIndex(entries) + (globalVars_1.diffY < 0 ? 1 : 0);
171
+ const index = findIndex(entries) + (diffY < 0 ? 1 : 0);
169
172
  if (activeLock === null) {
170
173
  activateNavByIndex(index);
171
174
  }
@@ -178,21 +181,17 @@ const sidebarTOC = () => {
178
181
  };
179
182
  createIntersectionObserver();
180
183
  };
181
- exports.sidebarTOC = sidebarTOC;
182
- const backToTopHandle = () => {
183
- (0, anime_1.pageScroll)(0);
184
+ export const backToTopHandle = () => {
185
+ pageScroll(0);
184
186
  };
185
- exports.backToTopHandle = backToTopHandle;
186
- const goToBottomHandle = () => {
187
- (0, anime_1.pageScroll)(parseInt(String(globalVars_1.Container.changeOrGetHeight())));
187
+ export const goToBottomHandle = () => {
188
+ pageScroll(parseInt(String(Container.changeOrGetHeight())));
188
189
  };
189
- exports.goToBottomHandle = goToBottomHandle;
190
- const goToCommentHandle = () => {
191
- (0, anime_1.pageScroll)((0, dom_1.$dom)('#comments'));
190
+ export const goToCommentHandle = () => {
191
+ pageScroll($dom('#comments'));
192
192
  };
193
- exports.goToCommentHandle = goToCommentHandle;
194
- const menuActive = () => {
195
- dom_1.$dom.each('.menu .item:not(.title)', (element) => {
193
+ export const menuActive = () => {
194
+ $dom.each('.menu .item:not(.title)', (element) => {
196
195
  const target = element.child('a[href]');
197
196
  const parentItem = element.parentNode.parentNode;
198
197
  if (!target)
@@ -209,4 +208,3 @@ const menuActive = () => {
209
208
  }
210
209
  });
211
210
  };
212
- exports.menuActive = menuActive;
@@ -1,141 +1,10 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initFireworks = void 0;
7
- const theme_shokax_anime_1 = __importDefault(require("theme-shokax-anime"));
8
- const canvasEl = document.createElement('canvas');
9
- canvasEl.style.cssText = 'position:fixed;top:0;left:0;pointer-events:none;z-index:9999999';
10
- document.body.appendChild(canvasEl);
11
- const ctx = canvasEl.getContext('2d');
12
- const numberOfParticules = 30;
13
- let pointerX = 0;
14
- let pointerY = 0;
15
- const tap = 'click';
16
- const colors = CONFIG.fireworks;
17
- function setCanvasSize() {
18
- canvasEl.width = window.innerWidth * 2;
19
- canvasEl.height = window.innerHeight * 2;
20
- canvasEl.style.width = window.innerWidth + 'px';
21
- canvasEl.style.height = window.innerHeight + 'px';
22
- canvasEl.getContext('2d').scale(2, 2);
23
- }
24
- function updateCoords(e) {
25
- pointerX = e.clientX || (e.touches && e.touches[0].clientX);
26
- pointerY = e.clientY || (e.touches && e.touches[0].clientY);
27
- }
28
- function setParticuleDirection(p) {
29
- const angle = theme_shokax_anime_1.default.random(0, 360) * Math.PI / 180;
30
- const value = theme_shokax_anime_1.default.random(50, 180);
31
- const radius = [-1, 1][theme_shokax_anime_1.default.random(0, 1)] * value;
32
- return {
33
- x: p.x + radius * Math.cos(angle),
34
- y: p.y + radius * Math.sin(angle)
35
- };
36
- }
37
- function createParticule(x, y) {
38
- const p = {
39
- x,
40
- y,
41
- color: undefined,
42
- radius: undefined,
43
- endPos: undefined,
44
- draw() {
45
- ctx.beginPath();
46
- ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true);
47
- ctx.fillStyle = p.color;
48
- ctx.fill();
49
- }
50
- };
51
- p.color = colors[theme_shokax_anime_1.default.random(0, colors.length - 1)];
52
- p.radius = theme_shokax_anime_1.default.random(16, 32);
53
- p.endPos = setParticuleDirection(p);
54
- return p;
55
- }
56
- function createCircle(x, y) {
57
- const p = {
58
- x,
59
- y,
60
- color: '#FFF',
61
- radius: 0.1,
62
- endPos: undefined,
63
- alpha: 0.5,
64
- lineWidth: 6,
65
- draw() {
66
- ctx.globalAlpha = p.alpha;
67
- ctx.beginPath();
68
- ctx.arc(p.x, p.y, p.radius, 0, 2 * Math.PI, true);
69
- ctx.lineWidth = p.lineWidth;
70
- ctx.strokeStyle = p.color;
71
- ctx.stroke();
72
- ctx.globalAlpha = 1;
73
- }
74
- };
75
- return p;
76
- }
77
- function renderParticule(targets) {
78
- for (const target of targets) {
79
- target.draw();
80
- }
81
- }
82
- function animateParticules(x, y) {
83
- const circle = createCircle(x, y);
84
- const particules = [];
85
- for (let i = 0; i < numberOfParticules; i++) {
86
- particules.push(createParticule(x, y));
87
- }
88
- (0, theme_shokax_anime_1.default)().timeline().add({
89
- targets: particules,
90
- duration: theme_shokax_anime_1.default.random(1200, 1800),
91
- easing: 'easeOutExpo',
92
- update: renderParticule,
93
- x: p => p.endPos.x,
94
- y: p => p.endPos.y,
95
- radius: 0.1
96
- }).add({
97
- targets: circle,
98
- duration: theme_shokax_anime_1.default.random(1200, 1800),
99
- easing: 'easeOutExpo',
100
- update: renderParticule,
101
- radius: theme_shokax_anime_1.default.random(80, 160),
102
- lineWidth: 0,
103
- alpha: {
104
- value: 0,
105
- easing: 'linear',
106
- duration: theme_shokax_anime_1.default.random(600, 800)
107
- }
108
- }).play();
109
- }
110
- const render = (0, theme_shokax_anime_1.default)({
111
- duration: Infinity,
112
- update() {
113
- ctx.clearRect(0, 0, canvasEl.width, canvasEl.height);
114
- }
115
- });
116
- const hasAncestor = (node, name) => {
117
- name = name.toUpperCase();
118
- do {
119
- if (node === null || node === undefined)
120
- break;
121
- if (node.nodeName === name)
122
- return true;
123
- } while ((node = node.parentNode) !== null);
124
- return false;
125
- };
126
- function initFireworks() {
1
+ import firework from 'mouse-firework';
2
+ /*
3
+ * 烟花分区
4
+ */
5
+ export function initFireworks() {
127
6
  if (typeof CONFIG.fireworks === 'undefined') {
128
7
  return;
129
8
  }
130
- document.addEventListener(tap, (e) => {
131
- if (hasAncestor(e.target, 'a')) {
132
- return;
133
- }
134
- render.play();
135
- updateCoords(e);
136
- animateParticules(pointerX, pointerY);
137
- }, false);
138
- setCanvasSize();
139
- window.addEventListener('resize', setCanvasSize, false);
9
+ firework(CONFIG.fireworks);
140
10
  }
141
- exports.initFireworks = initFireworks;