hexo-theme-shokax 0.3.10 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. package/_config.yml +47 -57
  2. package/layout/_mixin/comment.pug +1 -1
  3. package/layout/_partials/head/head.pug +2 -7
  4. package/layout/_partials/layout.pug +5 -5
  5. package/package.json +16 -21
  6. package/scripts/filters/locals.js +6 -0
  7. package/scripts/filters/post.js +2 -0
  8. package/scripts/generaters/archive.js +13 -1
  9. package/scripts/generaters/config.js +4 -1
  10. package/scripts/generaters/images.js +2 -0
  11. package/scripts/generaters/index.js +2 -0
  12. package/scripts/generaters/pages.js +0 -2
  13. package/scripts/generaters/script.js +37 -11
  14. package/scripts/helpers/asset.js +17 -71
  15. package/scripts/helpers/engine.js +24 -1
  16. package/scripts/helpers/list_categories.js +4 -0
  17. package/scripts/helpers/summary_ai.js +4 -0
  18. package/scripts/helpers/symbols_count_time.js +14 -8
  19. package/scripts/plugin/check.js +5 -3
  20. package/scripts/plugin/index.js +39 -23
  21. package/scripts/plugin/lib/injects.js +15 -0
  22. package/scripts/tags/media.js +1 -0
  23. package/scripts/utils.js +14 -0
  24. package/source/js/_app/components/sidebar.js +54 -56
  25. package/source/js/_app/fireworks.js +6 -137
  26. package/source/js/_app/globals/globalVars.js +80 -96
  27. package/source/js/_app/globals/handles.js +81 -60
  28. package/source/js/_app/globals/themeColor.js +30 -26
  29. package/source/js/_app/globals/thirdparty.js +25 -24
  30. package/source/js/_app/globals/tools.js +36 -30
  31. package/source/js/_app/library/anime.js +30 -15
  32. package/source/js/_app/library/dom.js +12 -5
  33. package/source/js/_app/library/loadFile.js +10 -12
  34. package/source/js/_app/library/proto.js +59 -7
  35. package/source/js/_app/library/scriptPjax.js +14 -9
  36. package/source/js/_app/library/storage.js +2 -4
  37. package/source/js/_app/library/vue.js +16 -19
  38. package/source/js/_app/page/comment.js +10 -11
  39. package/source/js/_app/page/common.js +8 -12
  40. package/source/js/_app/page/fancybox.js +14 -14
  41. package/source/js/_app/page/post.js +43 -45
  42. package/source/js/_app/page/search.js +20 -20
  43. package/source/js/_app/page/tab.js +7 -10
  44. package/source/js/_app/pjax/domInit.js +29 -29
  45. package/source/js/_app/pjax/refresh.js +44 -50
  46. package/source/js/_app/pjax/siteInit.js +27 -31
  47. package/source/js/_app/player.js +44 -27
  48. package/test/dom.test.js +0 -86
@@ -1,25 +1,24 @@
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.isOutime = exports.Loader = exports.lazyload = void 0;
7
- const lozad_1 = __importDefault(require("lozad"));
8
- const globalVars_1 = require("./globalVars");
9
- const anime_1 = require("../library/anime");
10
- exports.lazyload = (0, lozad_1.default)('img, [data-background-image]', {
1
+ // 与第三方js的交互或第三方嵌入js
2
+ import lozad from 'lozad';
3
+ import { loadCat } from './globalVars';
4
+ import { transition } from '../library/anime';
5
+ /**
6
+ * 懒加载图片
7
+ */
8
+ export const lazyload = lozad('img, [data-background-image]', {
11
9
  loaded(el) {
12
10
  el.addClass('lozaded');
13
11
  }
14
12
  });
15
- exports.Loader = {
13
+ // 加载动画
14
+ export const Loader = {
16
15
  timer: undefined,
17
16
  lock: false,
18
17
  show() {
19
18
  clearTimeout(this.timer);
20
19
  document.body.removeClass('loaded');
21
- globalVars_1.loadCat.attr('style', 'display:block');
22
- exports.Loader.lock = false;
20
+ loadCat.attr('style', 'display:block');
21
+ Loader.lock = false;
23
22
  },
24
23
  hide(sec) {
25
24
  if (!CONFIG.loader.start) {
@@ -28,17 +27,17 @@ exports.Loader = {
28
27
  this.timer = setTimeout(this.vanish, sec || 3000);
29
28
  },
30
29
  vanish() {
31
- if (exports.Loader.lock) {
30
+ if (Loader.lock) {
32
31
  return;
33
32
  }
34
33
  if (CONFIG.loader.start) {
35
- (0, anime_1.transition)(globalVars_1.loadCat, 0);
34
+ transition(loadCat, 0);
36
35
  }
37
36
  document.body.addClass('loaded');
38
- exports.Loader.lock = true;
37
+ Loader.lock = true;
39
38
  }
40
39
  };
41
- const isOutime = () => {
40
+ export const isOutime = () => {
42
41
  let updateTime;
43
42
  if (CONFIG.outime.enable && LOCAL.outime) {
44
43
  const times = document.getElementsByTagName('time');
@@ -49,17 +48,20 @@ const isOutime = () => {
49
48
  if (posts.length === 0) {
50
49
  return;
51
50
  }
52
- const now = Date.now();
53
- const pubTime = new Date(times[0].dateTime);
51
+ const now = Date.now(); // 当前时间戳
52
+ const pubTime = new Date(times[0].dateTime); // 文章发布时间戳
54
53
  if (times.length === 1) {
55
- updateTime = pubTime;
54
+ updateTime = pubTime; // 文章发布时间亦是最后更新时间
56
55
  }
57
56
  else {
58
- updateTime = new Date(times[1].dateTime);
57
+ updateTime = new Date(times[1].dateTime); // 文章最后更新时间戳
59
58
  }
60
- const interval = parseInt(String(now - updateTime));
61
- const days = parseInt(String(CONFIG.outime.days)) || 30;
59
+ // @ts-ignore
60
+ const interval = parseInt(String(now - updateTime)); // 时间差
61
+ const days = parseInt(String(CONFIG.outime.days)) || 30; // 设置时效,默认硬编码 30 天
62
+ // 最后一次更新时间超过 days 天(毫秒)
62
63
  if (interval > (days * 86400000)) {
64
+ // @ts-ignore
63
65
  const publish = parseInt(String((now - pubTime) / 86400000));
64
66
  const updated = parseInt(String(interval / 86400000));
65
67
  const template = LOCAL.template.replace('{{publish}}', String(publish)).replace('{{updated}}', String(updated));
@@ -67,4 +69,3 @@ const isOutime = () => {
67
69
  }
68
70
  }
69
71
  };
70
- exports.isOutime = isOutime;
@@ -1,65 +1,71 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.clipBoard = exports.positionInit = exports.pagePosition = exports.showtip = void 0;
4
- const anime_1 = require("../library/anime");
5
- const dom_1 = require("../library/dom");
6
- const storage_1 = require("../library/storage");
7
- const globalVars_1 = require("./globalVars");
8
- const showtip = (msg) => {
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
+ export const showtip = (msg) => {
9
7
  if (!msg) {
10
8
  return;
11
9
  }
12
- const tipbox = globalVars_1.BODY.createChild('div', {
10
+ const tipbox = BODY.createChild('div', {
13
11
  innerHTML: msg,
14
12
  className: 'tip'
15
13
  });
16
14
  setTimeout(() => {
17
15
  tipbox.addClass('hide');
18
16
  setTimeout(() => {
19
- globalVars_1.BODY.removeChild(tipbox);
17
+ BODY.removeChild(tipbox);
20
18
  }, 300);
21
19
  }, 3000);
22
20
  };
23
- exports.showtip = showtip;
24
- const pagePosition = () => {
21
+ export const pagePosition = () => {
22
+ // 判断配置项是否开启了自动记录滚动位置
25
23
  if (CONFIG.auto_scroll) {
26
- storage_1.$storage.set(globalVars_1.LOCAL_URL, String(globalVars_1.scrollAction.y));
24
+ // 将当前页面的滚动位置存入本地缓存
25
+ $storage.set(LOCAL_URL, String(scrollAction.y));
27
26
  }
28
27
  };
29
- exports.pagePosition = pagePosition;
30
- const positionInit = (comment) => {
28
+ export const positionInit = (comment) => {
29
+ // 获取页面锚点
31
30
  const anchor = window.location.hash;
32
31
  let target = null;
33
- if (globalVars_1.LOCAL_HASH) {
34
- storage_1.$storage.del(globalVars_1.LOCAL_URL);
32
+ if (LOCAL_HASH) {
33
+ $storage.del(LOCAL_URL);
35
34
  return;
36
35
  }
37
36
  if (anchor) {
38
- target = (0, dom_1.$dom)(decodeURI(anchor));
37
+ target = $dom(decodeURI(anchor));
39
38
  }
40
39
  else {
41
- target = CONFIG.auto_scroll ? parseInt(storage_1.$storage.get(globalVars_1.LOCAL_URL)) : 0;
40
+ target = CONFIG.auto_scroll ? parseInt($storage.get(LOCAL_URL)) : 0;
42
41
  }
43
42
  if (target) {
44
- (0, anime_1.pageScroll)(target);
45
- (0, globalVars_1.setLocalHash)(1);
43
+ pageScroll(target);
44
+ setLocalHash(1);
46
45
  }
47
- if (comment && anchor && !globalVars_1.LOCAL_HASH) {
48
- (0, anime_1.pageScroll)(target);
49
- (0, globalVars_1.setLocalHash)(1);
46
+ if (comment && anchor && !LOCAL_HASH) {
47
+ pageScroll(target);
48
+ setLocalHash(1);
50
49
  }
51
50
  };
52
- exports.positionInit = positionInit;
53
- const clipBoard = (str, callback) => {
51
+ /*
52
+ 这段代码是用来复制文本的。它使用了浏览器的 Clipboard API,如果浏览器支持该 API 并且当前页面是安全协议 (https)
53
+ 它将使用 Clipboard API 将文本复制到剪贴板。如果不支持,它会创建一个隐藏的文本区域并使用 document.execCommand('copy') 将文本复制到剪贴板。
54
+ 最后,它会回调传入的函数并传入一个布尔值表示是否成功复制。
55
+ */
56
+ export const clipBoard = (str, callback) => {
54
57
  if (navigator.clipboard && window.isSecureContext) {
55
58
  navigator.clipboard.writeText(str).then(() => {
59
+ // eslint-disable-next-line chai-friendly/no-unused-expressions
56
60
  callback && callback(true);
57
61
  }, () => {
62
+ // eslint-disable-next-line chai-friendly/no-unused-expressions
58
63
  callback && callback(false);
59
64
  });
60
65
  }
61
66
  else {
62
- const ta = globalVars_1.BODY.createChild('textarea', {
67
+ // TODO 根据caniuse,需要此polyfill的设备不足5%,应考虑删除
68
+ const ta = BODY.createChild('textarea', {
63
69
  style: {
64
70
  top: window.scrollY + 'px',
65
71
  position: 'absolute',
@@ -74,13 +80,13 @@ const clipBoard = (str, callback) => {
74
80
  ta.setSelectionRange(0, str.length);
75
81
  ta.readOnly = false;
76
82
  const result = document.execCommand('copy');
83
+ // eslint-disable-next-line chai-friendly/no-unused-expressions
77
84
  callback && callback(result);
78
- ta.blur();
85
+ ta.blur(); // For iOS
79
86
  if (selected) {
80
87
  selection.removeAllRanges();
81
88
  selection.addRange(selected);
82
89
  }
83
- globalVars_1.BODY.removeChild(ta);
90
+ BODY.removeChild(ta);
84
91
  }
85
92
  };
86
- exports.clipBoard = clipBoard;
@@ -1,12 +1,16 @@
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.pageScroll = exports.transition = void 0;
7
- const theme_shokax_anime_1 = __importDefault(require("theme-shokax-anime"));
8
- const globalVars_1 = require("../globals/globalVars");
9
- const transition = (target, type, complete, begin) => {
1
+ import anime from 'theme-shokax-anime';
2
+ import { siteNavHeight } from '../globals/globalVars';
3
+ /**
4
+ * 参数 动画效果
5
+ * 0 元素逐渐消失
6
+ * 1 元素逐渐出现
7
+ * bounceUpIn 元素从下方弹跳出现
8
+ * shrinkIn 元素从放大到正常大小出现
9
+ * slideRightIn 元素从右侧滑入
10
+ * slideRightOut 元素向右侧滑出
11
+ * TODO 函数功能过于复杂,需要拆分
12
+ */
13
+ export const transition = (target, type, complete, begin) => {
10
14
  let animation;
11
15
  let display = 'none';
12
16
  switch (type) {
@@ -63,32 +67,43 @@ const transition = (target, type, complete, begin) => {
63
67
  break;
64
68
  default:
65
69
  animation = type;
70
+ // @ts-ignore
66
71
  display = type.display;
67
72
  break;
68
73
  }
69
- (0, theme_shokax_anime_1.default)(Object.assign({
74
+ anime(Object.assign({
70
75
  targets: target,
71
76
  duration: 200,
72
77
  easing: 'linear',
73
78
  begin() {
79
+ // eslint-disable-next-line chai-friendly/no-unused-expressions
74
80
  begin && begin();
75
81
  },
76
82
  complete() {
77
83
  target.display(display);
84
+ // eslint-disable-next-line chai-friendly/no-unused-expressions
78
85
  complete && complete();
79
86
  }
80
87
  }, animation)).play();
81
88
  };
82
- exports.transition = transition;
83
- const pageScroll = (target, offset, complete) => {
84
- (0, theme_shokax_anime_1.default)({
89
+ export const pageScroll = (target, offset, complete) => {
90
+ // target: 滚动到的目标元素或坐标(number)
91
+ // offset: 可选的偏移量
92
+ // complete: 可选的回调函数,在动画完成时调用
93
+ anime({
94
+ // 动画目标
85
95
  targets: typeof offset === 'number' && typeof target !== 'number' ? target.parentNode : document.scrollingElement,
96
+ // 动画持续时间
86
97
  duration: 500,
98
+ // 动画缓动函数
87
99
  easing: 'easeInOutQuad',
88
- scrollTop: offset || (typeof target === 'number' ? target : (target ? target.getTop() + document.documentElement.scrollTop - globalVars_1.siteNavHeight : 0)),
100
+ // 如果 offset 存在,则滚动到 offset,如果 target 是数字,则滚动到 target,如果 target DOM 元素,则滚动到下述表达式
101
+ scrollTop: offset || (typeof target === 'number' ? target : (target ? target.getTop() + document.documentElement.scrollTop - siteNavHeight : 0)),
102
+ // 完成回调函数
89
103
  complete() {
104
+ // eslint-disable-next-line chai-friendly/no-unused-expressions
90
105
  complete && complete();
91
106
  }
92
107
  }).play();
108
+ // 调用 anime.js 函数,并传入参数
93
109
  };
94
- exports.pageScroll = pageScroll;
@@ -1,21 +1,27 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDocHeight = exports.$dom = void 0;
4
1
  const getDocHeight = () => $dom('main > .inner').offsetHeight;
5
- exports.getDocHeight = getDocHeight;
2
+ /**
3
+ * 获取一个dom选择器对应的元素
4
+ */
6
5
  const $dom = (selector, element = document) => {
6
+ // 在测试环境中这能优化0.01-0.02ms左右
7
7
  if (selector[0] === '#') {
8
8
  return element.getElementById(selector.substring(1));
9
9
  }
10
10
  return element.querySelector(selector);
11
11
  };
12
- exports.$dom = $dom;
12
+ /**
13
+ * 获取具有此选择器的所有dom节点
14
+ */
13
15
  $dom.all = (selector, element = document) => {
14
16
  return element.querySelectorAll(selector);
15
17
  };
18
+ /**
19
+ * 获取具有此选择器的所有dom节点,并依次执行callback函数
20
+ */
16
21
  $dom.each = (selector, callback, element) => {
17
22
  $dom.all(selector, element).forEach(callback);
18
23
  };
24
+ // TODO 异步化意义不明确,代码实现存在问题
19
25
  $dom.asyncify = async (selector, element = document) => {
20
26
  if (selector[0] === '#') {
21
27
  return element.getElementById(selector.substring(1));
@@ -25,3 +31,4 @@ $dom.asyncify = async (selector, element = document) => {
25
31
  $dom.asyncifyEach = (selector, callback, element) => {
26
32
  $dom.all(selector, element).forEach(callback);
27
33
  };
34
+ export { $dom, getDocHeight };
@@ -1,29 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.vendorCss = exports.vendorJs = void 0;
4
- const scriptPjax_1 = require("./scriptPjax");
1
+ import { getScript } from './scriptPjax';
2
+ /**
3
+ * 用途是根据不同的资源名称和类型生成相应的资源 URL。
4
+ */
5
5
  const assetUrl = (asset, type) => {
6
6
  const str = CONFIG[asset][type];
7
+ if (str.includes('http')) {
8
+ return str;
9
+ }
7
10
  if (str.includes('gh') || str.includes('combine')) {
8
11
  return `https://cdn.jsdelivr.net/${str}`;
9
12
  }
10
13
  if (str.includes('npm')) {
11
14
  return `https://cdn.jsdelivr.net/${str}`;
12
15
  }
13
- if (str.includes('http')) {
14
- return str;
15
- }
16
16
  return `/${str}`;
17
17
  };
18
- const vendorJs = (type, callback, condition) => {
18
+ export const vendorJs = (type, callback, condition) => {
19
19
  if (LOCAL[type]) {
20
- (0, scriptPjax_1.getScript)(assetUrl('js', type), callback || function () {
20
+ getScript(assetUrl('js', type), callback || function () {
21
21
  window[type] = true;
22
22
  }, condition || window[type]);
23
23
  }
24
24
  };
25
- exports.vendorJs = vendorJs;
26
- const vendorCss = (type, condition) => {
25
+ export const vendorCss = (type, condition) => {
27
26
  if (window['css' + type]) {
28
27
  return;
29
28
  }
@@ -35,4 +34,3 @@ const vendorCss = (type, condition) => {
35
34
  window['css' + type] = true;
36
35
  }
37
36
  };
38
- exports.vendorCss = vendorCss;
@@ -1,8 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dom_1 = require("./dom");
4
- function initProto() {
1
+ import { $dom } from './dom';
2
+ export default function initProto() {
5
3
  Object.assign(HTMLElement.prototype, {
4
+ /**
5
+ * 创建一个子节点并放置
6
+ */
6
7
  createChild(tag, obj, positon) {
7
8
  const child = document.createElement(tag);
8
9
  Object.assign(child, obj);
@@ -19,6 +20,10 @@ function initProto() {
19
20
  }
20
21
  return child;
21
22
  },
23
+ /**
24
+ * 此方法使用`<div>`包装一个 DOM 元素
25
+ * @param obj 需要被包装的对象
26
+ */
22
27
  wrapObject(obj) {
23
28
  const box = document.createElement('div');
24
29
  Object.assign(box, obj);
@@ -28,12 +33,18 @@ function initProto() {
28
33
  },
29
34
  changeOrGetHeight(h) {
30
35
  if (h) {
36
+ // TODO 0rem是期望的值吗?
31
37
  this.style.height = typeof h === 'number' ? h + 'rem' : h;
32
38
  }
33
39
  return this.getBoundingClientRect().height;
34
40
  },
41
+ /**
42
+ 此函数将元素的宽度设置为指定值,如果未提供值,则返回元素的宽度.<br />
43
+ 宽度可以作为数字提供(假定它以`rem`为单位).作为字符串提供则直接设置为元素宽度
44
+ */
35
45
  changeOrGetWidth(w) {
36
46
  if (w) {
47
+ // TODO 0rem是期望的值吗?
37
48
  this.style.width = typeof w === 'number' ? w + 'rem' : w;
38
49
  }
39
50
  return this.getBoundingClientRect().width;
@@ -44,6 +55,12 @@ function initProto() {
44
55
  left() {
45
56
  return this.getBoundingClientRect().left;
46
57
  },
58
+ /**
59
+ * 该函数接受两个参数:`type`字符串和 `value`字符串的可选参数。该函数具有基于参数值的三个主要逻辑分支。 <br />
60
+ * 1. `value`如果是`null`,则该函数从当前上下文中删除具有`type`函数名称的属性。 <br />
61
+ * 2. `value`如果为真,则该函数将使用`type`参数指定的名称将属性设置为当前上下文中`value`参数的值。然后,该函数返回当前上下文。 <br />
62
+ * 3. `value`如果不是真,则该函数返回属性的值,该值具有当前上下文中的参数指定的名称。
63
+ */
47
64
  attr(type, value) {
48
65
  if (value === null) {
49
66
  return this.removeAttribute(type);
@@ -56,6 +73,9 @@ function initProto() {
56
73
  return this.getAttribute(type);
57
74
  }
58
75
  },
76
+ /**
77
+ * 将此节点插入父节点的下一个节点之前
78
+ */
59
79
  insertAfter(element) {
60
80
  const parent = this.parentNode;
61
81
  if (parent.lastChild === this) {
@@ -65,6 +85,10 @@ function initProto() {
65
85
  parent.insertBefore(element, this.nextSibling);
66
86
  }
67
87
  },
88
+ /**
89
+ * 当d为空时返回此节点的CSSStyle display属性 <br />
90
+ * 反之,将d设置为此节点的CSSStyle display属性
91
+ */
68
92
  display(d) {
69
93
  if (d == null) {
70
94
  return this.style.display;
@@ -74,12 +98,25 @@ function initProto() {
74
98
  return this;
75
99
  }
76
100
  },
101
+ /**
102
+ * 找到此节点第一个符合selector选择器的子节点
103
+ */
77
104
  child(selector) {
78
- return (0, dom_1.$dom)(selector, this);
105
+ return $dom(selector, this);
79
106
  },
107
+ /**
108
+ * 找到此节点所有符合selector选择器的子节点
109
+ */
80
110
  find(selector) {
81
- return dom_1.$dom.all(selector, this);
111
+ return $dom.all(selector, this);
82
112
  },
113
+ /**
114
+ * 这个方法接受三个参数:
115
+ * type 表示操作类型('add'、'remove'、'toggle'),
116
+ * className 是一个或多个要操作的类名,
117
+ * display 是一个可选的布尔值,用于在执行切换操作时指定类名是否应显示或隐藏。
118
+ * 该方法会根据操作类型执行相应的类名操作。
119
+ */
83
120
  _class(type, className, display) {
84
121
  const classNames = className.indexOf(' ') ? className.split(' ') : [className];
85
122
  classNames.forEach((name) => {
@@ -91,21 +128,36 @@ function initProto() {
91
128
  }
92
129
  });
93
130
  },
131
+ /**
132
+ * 这个方法是对 _class 方法的封装,调用时会将操作类型设为 'add',然后执行添加类名的操作。
133
+ * 最后,它返回当前的 EventTarget,通常是 DOM 元素本身,以支持链式调用。
134
+ */
94
135
  addClass(className) {
95
136
  this._class('add', className);
96
137
  return this;
97
138
  },
139
+ /**
140
+ * 这个方法是对 _class 方法的封装,调用时会将操作类型设为 'remove',然后执行移除类名的操作。
141
+ * 最后,它返回当前的 EventTarget,通常是 DOM 元素本身,以支持链式调用。
142
+ */
98
143
  removeClass(className) {
99
144
  this._class('remove', className);
100
145
  return this;
101
146
  },
147
+ /**
148
+ * 这个方法是对 _class 方法的封装,调用时会将操作类型设为 'toggle',然后执行切换类名的操作。
149
+ * 如果提供了 display 参数,它将根据布尔值决定是否显示或隐藏类名。
150
+ * 最后,它返回当前的 EventTarget,通常是 DOM 元素本身,以支持链式调用。
151
+ */
102
152
  toggleClass(className, display) {
103
153
  this._class('toggle', className, display);
104
154
  return this;
105
155
  },
156
+ /**
157
+ * 这个方法返回一个布尔值,表示元素是否包含指定的类名。
158
+ */
106
159
  hasClass(className) {
107
160
  return this.classList.contains(className);
108
161
  }
109
162
  });
110
163
  }
111
- exports.default = initProto;
@@ -1,7 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pjaxScript = exports.getScript = exports.cloudflareInit = void 0;
4
- function cloudflareInit() {
1
+ // rocket-loader & Auto minify(cloudflare) 补丁
2
+ // cloudflare 的上述功能会导致DOMContentLoaded事件无法触发,此补丁会将DOMContentLoaded重定向为load事件
3
+ export function cloudflareInit() {
5
4
  let inCloudFlare = true;
6
5
  window.addEventListener('DOMContentLoaded', function () {
7
6
  inCloudFlare = false;
@@ -15,14 +14,21 @@ function cloudflareInit() {
15
14
  });
16
15
  }
17
16
  }
18
- exports.cloudflareInit = cloudflareInit;
19
- const getScript = (url, callback, condition) => {
17
+ export const getScript = (url, callback, condition) => {
18
+ // url: 脚本文件的URL地址
19
+ // callback: 当脚本加载完成时要执行的回调函数
20
+ // condition: 可选的条件参数,如果存在,则执行callback
20
21
  if (condition) {
22
+ // 如果条件存在,则执行回调函数
21
23
  callback();
22
24
  }
23
25
  else {
24
26
  let script = document.createElement('script');
27
+ // @ts-ignore
25
28
  script.onload = function (_, isAbort) {
29
+ // _: 事件对象
30
+ // isAbort: 是否中止
31
+ // @ts-ignore
26
32
  if (isAbort || !script.readyState) {
27
33
  console.log('abort!');
28
34
  script.onload = null;
@@ -35,8 +41,7 @@ const getScript = (url, callback, condition) => {
35
41
  document.head.appendChild(script);
36
42
  }
37
43
  };
38
- exports.getScript = getScript;
39
- const pjaxScript = (element) => {
44
+ export const pjaxScript = (element) => {
40
45
  const { text, parentNode, id, className, type, src, dataset } = element;
41
46
  const code = text || element.textContent || element.innerHTML || '';
42
47
  parentNode.removeChild(element);
@@ -51,6 +56,7 @@ const pjaxScript = (element) => {
51
56
  script.type = type;
52
57
  }
53
58
  if (src) {
59
+ // Force synchronous loading of peripheral JS.
54
60
  script.src = src;
55
61
  script.async = false;
56
62
  }
@@ -62,4 +68,3 @@ const pjaxScript = (element) => {
62
68
  }
63
69
  parentNode.appendChild(script);
64
70
  };
65
- exports.pjaxScript = pjaxScript;
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.$storage = void 0;
4
- exports.$storage = {
1
+ // Html5LocalStorage的一个API
2
+ export const $storage = {
5
3
  set(key, value) {
6
4
  localStorage.setItem(key, value);
7
5
  },
@@ -1,12 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initVue = void 0;
4
- const storage_1 = require("./storage");
5
- const anime_1 = require("./anime");
6
- const dom_1 = require("./dom");
7
- const globalVars_1 = require("../globals/globalVars");
8
- const themeColor_1 = require("../globals/themeColor");
9
- function initVue() {
1
+ import { $storage } from './storage';
2
+ import { transition } from './anime';
3
+ import { $dom } from './dom';
4
+ import { BODY } from '../globals/globalVars';
5
+ import { changeTheme } from '../globals/themeColor';
6
+ export function initVue() {
10
7
  Vue.createApp({
11
8
  data() {
12
9
  return {};
@@ -14,24 +11,25 @@ function initVue() {
14
11
  methods: {
15
12
  changeThemeByBtn() {
16
13
  let c;
17
- const btn = (0, dom_1.$dom)('.theme').child('.ic');
18
- const neko = globalVars_1.BODY.createChild('div', {
14
+ const btn = $dom('.theme').child('.ic');
15
+ const neko = BODY.createChild('div', {
19
16
  id: 'neko',
20
17
  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>'
21
18
  });
22
19
  const hideNeko = () => {
23
- (0, anime_1.transition)(neko, {
20
+ transition(neko, {
21
+ // @ts-ignore
24
22
  delay: 2500,
25
23
  opacity: 0
26
24
  }, () => {
27
- globalVars_1.BODY.removeChild(neko);
25
+ BODY.removeChild(neko);
28
26
  });
29
27
  };
30
28
  if (btn.hasClass('i-sun')) {
31
29
  c = () => {
32
30
  neko.addClass('dark');
33
- (0, themeColor_1.changeTheme)('dark');
34
- storage_1.$storage.set('theme', 'dark');
31
+ changeTheme('dark');
32
+ $storage.set('theme', 'dark');
35
33
  hideNeko();
36
34
  };
37
35
  }
@@ -39,12 +37,12 @@ function initVue() {
39
37
  neko.addClass('dark');
40
38
  c = () => {
41
39
  neko.removeClass('dark');
42
- (0, themeColor_1.changeTheme)();
43
- storage_1.$storage.set('theme', 'light');
40
+ changeTheme();
41
+ $storage.set('theme', 'light');
44
42
  hideNeko();
45
43
  };
46
44
  }
47
- (0, anime_1.transition)(neko, 1, () => {
45
+ transition(neko, 1, () => {
48
46
  setTimeout(c, 210);
49
47
  }, () => {
50
48
  neko.display('block');
@@ -53,4 +51,3 @@ function initVue() {
53
51
  }
54
52
  }).mount('#rightNav');
55
53
  }
56
- exports.initVue = initVue;