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,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 numberOfParticles = 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 setParticleDirection(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 createParticle(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 = setParticleDirection(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 renderParticle(targets) {
78
- for (const target of targets) {
79
- target.draw();
80
- }
81
- }
82
- function animateParticles(x, y) {
83
- const circle = createCircle(x, y);
84
- const particles = [];
85
- for (let i = 0; i < numberOfParticles; i++) {
86
- particles.push(createParticle(x, y));
87
- }
88
- (0, theme_shokax_anime_1.default)().timeline().add({
89
- targets: particles,
90
- duration: theme_shokax_anime_1.default.random(1200, 1800),
91
- easing: 'easeOutExpo',
92
- update: renderParticle,
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: renderParticle,
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
- animateParticles(pointerX, pointerY);
137
- }, false);
138
- setCanvasSize();
139
- window.addEventListener('resize', setCanvasSize, false);
9
+ firework(CONFIG.fireworks);
140
10
  }
141
- exports.initFireworks = initFireworks;
@@ -1,96 +1,80 @@
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.setSiteSearch = exports.setToolBtn = exports.setShowContents = exports.setGoToComment = exports.setBackToTop = exports.setToolPlayer = exports.setOriginTitle = exports.setPjax = exports.setLocalUrl = exports.setLocalHash = exports.setTitleTime = exports.setDiffY = exports.setOWinWidth = exports.setOWinHeight = exports.setHeaderHight = exports.setHeaderHightInner = exports.setSiteNavHeight = exports.pjax = exports.LOCAL_URL = exports.LOCAL_HASH = exports.oWinWidth = exports.oWinHeight = exports.headerHight = exports.headerHightInner = exports.siteNavHeight = exports.siteSearch = exports.showContents = exports.goToComment = exports.backToTop = exports.toolPlayer = exports.toolBtn = exports.siteBrand = exports.sideBar = exports.quickBtn = exports.menuToggle = exports.siteHeader = exports.siteNav = exports.loadCat = exports.Container = exports.HTML = exports.BODY = exports.titleTime = exports.originTitle = exports.diffY = exports.scrollAction = exports.statics = void 0;
7
- const dom_1 = require("../library/dom");
8
- const proto_1 = __importDefault(require("../library/proto"));
9
- (0, proto_1.default)();
10
- exports.statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root;
11
- exports.scrollAction = { x: 0, y: 0 };
12
- exports.diffY = 0;
13
- exports.BODY = document.getElementsByTagName('body')[0];
14
- exports.HTML = document.documentElement;
15
- exports.Container = (0, dom_1.$dom)('#container');
16
- exports.loadCat = (0, dom_1.$dom)('#loading');
17
- exports.siteNav = (0, dom_1.$dom)('#nav');
18
- exports.siteHeader = (0, dom_1.$dom)('#header');
19
- exports.menuToggle = exports.siteNav.child('.toggle');
20
- exports.quickBtn = (0, dom_1.$dom)('#quick');
21
- exports.sideBar = (0, dom_1.$dom)('#sidebar');
22
- exports.siteBrand = (0, dom_1.$dom)('#brand');
23
- exports.toolBtn = (0, dom_1.$dom)('#tool');
24
- exports.siteSearch = (0, dom_1.$dom)('#search');
25
- exports.oWinHeight = window.innerHeight;
26
- exports.oWinWidth = window.innerWidth;
27
- exports.LOCAL_HASH = 0;
28
- exports.LOCAL_URL = window.location.href;
29
- function setSiteNavHeight(value) {
30
- exports.siteNavHeight = value;
31
- }
32
- exports.setSiteNavHeight = setSiteNavHeight;
33
- function setHeaderHightInner(value) {
34
- exports.headerHightInner = value;
35
- }
36
- exports.setHeaderHightInner = setHeaderHightInner;
37
- function setHeaderHight(value) {
38
- exports.headerHight = value;
39
- }
40
- exports.setHeaderHight = setHeaderHight;
41
- function setOWinHeight(value) {
42
- exports.oWinHeight = value;
43
- }
44
- exports.setOWinHeight = setOWinHeight;
45
- function setOWinWidth(value) {
46
- exports.oWinWidth = value;
47
- }
48
- exports.setOWinWidth = setOWinWidth;
49
- function setDiffY(value) {
50
- exports.diffY = value;
51
- }
52
- exports.setDiffY = setDiffY;
53
- function setTitleTime(value) {
54
- exports.titleTime = value;
55
- }
56
- exports.setTitleTime = setTitleTime;
57
- function setLocalHash(value) {
58
- exports.LOCAL_HASH = value;
59
- }
60
- exports.setLocalHash = setLocalHash;
61
- function setLocalUrl(value) {
62
- exports.LOCAL_URL = value;
63
- }
64
- exports.setLocalUrl = setLocalUrl;
65
- function setPjax(value) {
66
- exports.pjax = value;
67
- }
68
- exports.setPjax = setPjax;
69
- function setOriginTitle(value) {
70
- exports.originTitle = value;
71
- }
72
- exports.setOriginTitle = setOriginTitle;
73
- function setToolPlayer(value) {
74
- exports.toolPlayer = value;
75
- }
76
- exports.setToolPlayer = setToolPlayer;
77
- function setBackToTop(value) {
78
- exports.backToTop = value;
79
- }
80
- exports.setBackToTop = setBackToTop;
81
- function setGoToComment(value) {
82
- exports.goToComment = value;
83
- }
84
- exports.setGoToComment = setGoToComment;
85
- function setShowContents(value) {
86
- exports.showContents = value;
87
- }
88
- exports.setShowContents = setShowContents;
89
- function setToolBtn(value) {
90
- exports.toolBtn = value;
91
- }
92
- exports.setToolBtn = setToolBtn;
93
- function setSiteSearch(value) {
94
- exports.siteSearch = value;
95
- }
96
- exports.setSiteSearch = setSiteSearch;
1
+ import { $dom } from '../library/dom';
2
+ import initProto from '../library/proto';
3
+ initProto();
4
+ export const statics = CONFIG.statics.indexOf('//') > 0 ? CONFIG.statics : CONFIG.root;
5
+ export const scrollAction = { x: 0, y: 0 };
6
+ export let diffY = 0;
7
+ export let originTitle, titleTime;
8
+ export const BODY = document.getElementsByTagName('body')[0];
9
+ export const HTML = document.documentElement;
10
+ export const Container = $dom('#container');
11
+ export const loadCat = $dom('#loading');
12
+ export const siteNav = $dom('#nav');
13
+ export const siteHeader = $dom('#header');
14
+ export const menuToggle = siteNav.child('.toggle');
15
+ export const quickBtn = $dom('#quick');
16
+ export const sideBar = $dom('#sidebar');
17
+ export const siteBrand = $dom('#brand');
18
+ export let toolBtn = $dom('#tool');
19
+ export let toolPlayer;
20
+ export let backToTop;
21
+ export let goToComment;
22
+ export let showContents;
23
+ export let siteSearch = $dom('#search');
24
+ export let siteNavHeight, headerHightInner, headerHight;
25
+ export let oWinHeight = window.innerHeight;
26
+ export let oWinWidth = window.innerWidth;
27
+ export let LOCAL_HASH = 0;
28
+ export let LOCAL_URL = window.location.href;
29
+ export let pjax;
30
+ export function setSiteNavHeight(value) {
31
+ siteNavHeight = value;
32
+ }
33
+ export function setHeaderHightInner(value) {
34
+ headerHightInner = value;
35
+ }
36
+ export function setHeaderHight(value) {
37
+ headerHight = value;
38
+ }
39
+ export function setOWinHeight(value) {
40
+ oWinHeight = value;
41
+ }
42
+ export function setOWinWidth(value) {
43
+ oWinWidth = value;
44
+ }
45
+ export function setDiffY(value) {
46
+ diffY = value;
47
+ }
48
+ export function setTitleTime(value) {
49
+ titleTime = value;
50
+ }
51
+ export function setLocalHash(value) {
52
+ LOCAL_HASH = value;
53
+ }
54
+ export function setLocalUrl(value) {
55
+ LOCAL_URL = value;
56
+ }
57
+ export function setPjax(value) {
58
+ pjax = value;
59
+ }
60
+ export function setOriginTitle(value) {
61
+ originTitle = value;
62
+ }
63
+ export function setToolPlayer(value) {
64
+ toolPlayer = value;
65
+ }
66
+ export function setBackToTop(value) {
67
+ backToTop = value;
68
+ }
69
+ export function setGoToComment(value) {
70
+ goToComment = value;
71
+ }
72
+ export function setShowContents(value) {
73
+ showContents = value;
74
+ }
75
+ export function setToolBtn(value) {
76
+ toolBtn = value;
77
+ }
78
+ export function setSiteSearch(value) {
79
+ siteSearch = value;
80
+ }
@@ -1,80 +1,102 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.visibilityListener = exports.clickMenu = exports.scrollHandle = exports.resizeHandle = void 0;
4
- const sidebar_1 = require("../components/sidebar");
5
- const dom_1 = require("../library/dom");
6
- const globalVars_1 = require("./globalVars");
7
- const themeColor_1 = require("./themeColor");
8
- const thirdparty_1 = require("./thirdparty");
9
- const resizeHandle = () => {
10
- (0, globalVars_1.setSiteNavHeight)(globalVars_1.siteNav.changeOrGetHeight());
11
- (0, globalVars_1.setHeaderHightInner)(globalVars_1.siteHeader.changeOrGetHeight());
12
- (0, globalVars_1.setHeaderHight)(globalVars_1.headerHightInner + (0, dom_1.$dom)('#waves').changeOrGetHeight());
13
- if (globalVars_1.oWinWidth !== window.innerWidth) {
14
- (0, sidebar_1.sideBarToggleHandle)(null, 1);
1
+ import { sideBarToggleHandle } from '../components/sidebar';
2
+ import { $dom, getDocHeight } from '../library/dom';
3
+ import { backToTop, diffY, headerHight, headerHightInner, oWinWidth, originTitle, scrollAction, sideBar, siteBrand, siteHeader, siteNav, statics, titleTime, toolBtn, setSiteNavHeight, setHeaderHightInner, setHeaderHight, setOWinHeight, setOWinWidth, setDiffY, setTitleTime } from './globalVars';
4
+ import { changeMetaTheme } from './themeColor';
5
+ import { Loader } from './thirdparty';
6
+ export const resizeHandle = () => {
7
+ // 获取 siteNav 的高度
8
+ setSiteNavHeight(siteNav.changeOrGetHeight());
9
+ // 获取 siteHeader 的高度
10
+ setHeaderHightInner(siteHeader.changeOrGetHeight());
11
+ // 获取 #waves 的高度
12
+ setHeaderHight(headerHightInner + $dom('#waves').changeOrGetHeight());
13
+ // 判断窗口宽度是否改变
14
+ if (oWinWidth !== window.innerWidth) {
15
+ sideBarToggleHandle(null, 1);
15
16
  }
16
- (0, globalVars_1.setOWinHeight)(window.innerHeight);
17
- (0, globalVars_1.setOWinWidth)(window.innerWidth);
17
+ // 记录窗口高度和宽度
18
+ setOWinHeight(window.innerHeight);
19
+ setOWinWidth(window.innerWidth);
18
20
  };
19
- exports.resizeHandle = resizeHandle;
20
- const scrollHandle = () => {
21
+ export const scrollHandle = () => {
22
+ // 获取窗口高度
21
23
  const winHeight = window.innerHeight;
22
- const docHeight = (0, dom_1.getDocHeight)();
24
+ // 获取文档高度
25
+ const docHeight = getDocHeight();
26
+ // 计算可见内容高度
23
27
  const contentVisibilityHeight = docHeight > winHeight ? docHeight - winHeight : document.body.scrollHeight - winHeight;
24
- const SHOW = window.scrollY > globalVars_1.headerHightInner;
28
+ // 判断页面是否滚动超过 headerHightInner
29
+ const SHOW = window.scrollY > headerHightInner;
30
+ // 判断页面是否开始滚动
25
31
  const startScroll = window.scrollY > 0;
32
+ // 根据条件修改 meta theme
26
33
  if (SHOW) {
27
- (0, themeColor_1.changeMetaTheme)('#FFF');
34
+ changeMetaTheme('#FFF');
28
35
  }
29
36
  else {
30
- (0, themeColor_1.changeMetaTheme)('#222');
37
+ changeMetaTheme('#222');
31
38
  }
32
- globalVars_1.siteNav.toggleClass('show', SHOW);
33
- globalVars_1.toolBtn.toggleClass('affix', startScroll);
34
- globalVars_1.siteBrand.toggleClass('affix', startScroll);
35
- globalVars_1.sideBar.toggleClass('affix', window.scrollY > globalVars_1.headerHight && document.body.offsetWidth > 991);
36
- if (typeof globalVars_1.scrollAction.y === 'undefined') {
37
- globalVars_1.scrollAction.y = window.scrollY;
39
+ // 控制导航栏的显示隐藏
40
+ siteNav.toggleClass('show', SHOW);
41
+ // 控制网站 logo 的显示隐藏
42
+ toolBtn.toggleClass('affix', startScroll);
43
+ // 控制侧边栏的显示隐藏,当滚动高度大于 headerHight 且窗口宽度大于 991px 时显示
44
+ siteBrand.toggleClass('affix', startScroll);
45
+ sideBar.toggleClass('affix', window.scrollY > headerHight && document.body.offsetWidth > 991);
46
+ // 初始化滚动时导航栏的显示方向
47
+ if (typeof scrollAction.y === 'undefined') {
48
+ scrollAction.y = window.scrollY;
38
49
  }
39
- (0, globalVars_1.setDiffY)(globalVars_1.scrollAction.y - window.scrollY);
40
- if (globalVars_1.diffY < 0) {
41
- globalVars_1.siteNav.removeClass('up');
42
- globalVars_1.siteNav.toggleClass('down', SHOW);
50
+ setDiffY(scrollAction.y - window.scrollY);
51
+ // 控制滑动时导航栏显示
52
+ if (diffY < 0) {
53
+ siteNav.removeClass('up');
54
+ siteNav.toggleClass('down', SHOW);
43
55
  }
44
- else if (globalVars_1.diffY > 0) {
45
- globalVars_1.siteNav.removeClass('down');
46
- globalVars_1.siteNav.toggleClass('up', SHOW);
56
+ else if (diffY > 0) {
57
+ siteNav.removeClass('down');
58
+ siteNav.toggleClass('up', SHOW);
47
59
  }
48
- else { }
49
- globalVars_1.scrollAction.y = window.scrollY;
60
+ else { /* empty */ }
61
+ scrollAction.y = window.scrollY;
62
+ // 计算滚动百分比
50
63
  const scrollPercent = Math.round(Math.min(100 * window.scrollY / contentVisibilityHeight, 100)) + '%';
51
- if (globalVars_1.backToTop.child('span').innerText !== scrollPercent) {
52
- globalVars_1.backToTop.child('span').innerText = scrollPercent;
64
+ // 更新回到顶部按钮的文字
65
+ if (backToTop.child('span').innerText !== scrollPercent) {
66
+ backToTop.child('span').innerText = scrollPercent;
53
67
  }
54
- if ((0, dom_1.$dom)('#sidebar').hasClass('affix') || (0, dom_1.$dom)('#sidebar').hasClass('on')) {
55
- (0, dom_1.$dom)('.percent').changeOrGetWidth(scrollPercent);
68
+ // 更新百分比进度条的宽度
69
+ if ($dom('#sidebar').hasClass('affix') || $dom('#sidebar').hasClass('on')) {
70
+ $dom('.percent').changeOrGetWidth(scrollPercent);
56
71
  }
57
72
  };
58
- exports.scrollHandle = scrollHandle;
59
- const clickMenu = () => {
60
- const menuElement = (0, dom_1.$dom)('#clickMenu');
73
+ /**
74
+ * 此函数用于修改右键点击显示菜单 <br/>
75
+ * 需要在document下存在如下元素:
76
+ * - id为clickMenu的容器(右键菜单容器)
77
+ * - class为clickSubmenu的容器(可以有0到无限个)(子菜单容器)
78
+ * CSS应有如下class:
79
+ * - clickMenu的active类(控制显示)
80
+ */
81
+ export const clickMenu = () => {
82
+ const menuElement = $dom('#clickMenu');
61
83
  window.oncontextmenu = function (event) {
62
- if (event.ctrlKey) {
84
+ if (event.ctrlKey) { // 当按下ctrl键时不触发自定义菜单
63
85
  return;
64
86
  }
65
87
  event.preventDefault();
66
- let x = event.offsetX;
88
+ let x = event.offsetX; // 触发点到页面窗口左边的距离
67
89
  let y = event.offsetY;
68
- const winWidth = window.innerWidth;
90
+ const winWidth = window.innerWidth; // 窗口的内部宽度(包括滚动条)
69
91
  const winHeight = window.innerHeight;
70
- const menuWidth = menuElement.offsetWidth;
92
+ const menuWidth = menuElement.offsetWidth; // 菜单宽度
71
93
  const menuHeight = menuElement.offsetHeight;
72
94
  x = winWidth - menuWidth >= x ? x : winWidth - menuWidth;
73
95
  y = winHeight - menuHeight >= y ? y : winHeight - menuHeight;
74
96
  menuElement.style.top = y + 'px';
75
97
  menuElement.style.left = x + 'px';
76
98
  menuElement.classList.add('active');
77
- dom_1.$dom.each('.clickSubmenu', (submenu) => {
99
+ $dom.each('.clickSubmenu', (submenu) => {
78
100
  if (x > (winWidth - menuWidth - submenu.offsetWidth)) {
79
101
  submenu.style.left = '-200px';
80
102
  }
@@ -88,30 +110,29 @@ const clickMenu = () => {
88
110
  menuElement.classList.remove('active');
89
111
  });
90
112
  };
91
- exports.clickMenu = clickMenu;
92
- const visibilityListener = () => {
93
- const iconNode = (0, dom_1.$dom)('[rel="icon"]');
113
+ // 可见度监听(离开页面和返回时更改document的title)
114
+ export const visibilityListener = () => {
115
+ const iconNode = $dom('[rel="icon"]');
94
116
  document.addEventListener('visibilitychange', () => {
95
117
  switch (document.visibilityState) {
96
118
  case 'hidden':
97
- iconNode.attr('href', globalVars_1.statics + CONFIG.favicon.hidden);
119
+ iconNode.attr('href', statics + CONFIG.favicon.hidden);
98
120
  document.title = LOCAL.favicon.hide;
99
121
  if (CONFIG.loader.switch) {
100
- thirdparty_1.Loader.show();
122
+ Loader.show();
101
123
  }
102
- clearTimeout(globalVars_1.titleTime);
124
+ clearTimeout(titleTime);
103
125
  break;
104
126
  case 'visible':
105
- iconNode.attr('href', globalVars_1.statics + CONFIG.favicon.normal);
127
+ iconNode.attr('href', statics + CONFIG.favicon.normal);
106
128
  document.title = LOCAL.favicon.show;
107
129
  if (CONFIG.loader.switch) {
108
- thirdparty_1.Loader.hide(1000);
130
+ Loader.hide(1000);
109
131
  }
110
- (0, globalVars_1.setTitleTime)(setTimeout(() => {
111
- document.title = globalVars_1.originTitle;
132
+ setTitleTime(setTimeout(() => {
133
+ document.title = originTitle;
112
134
  }, 2000));
113
135
  break;
114
136
  }
115
137
  });
116
138
  };
117
- exports.visibilityListener = visibilityListener;
@@ -1,58 +1,62 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.themeColorListener = exports.changeMetaTheme = exports.autoDarkmode = exports.changeTheme = void 0;
4
- const storage_1 = require("../library/storage");
5
- const dom_1 = require("../library/dom");
6
- const globalVars_1 = require("./globalVars");
7
- const changeTheme = (type) => {
8
- const btn = (0, dom_1.$dom)('.theme .ic');
1
+ import { $storage } from '../library/storage';
2
+ import { $dom } from '../library/dom';
3
+ import { HTML } from './globalVars';
4
+ /**
5
+ * 更改日夜模式
6
+ */
7
+ export const changeTheme = (type) => {
8
+ const btn = $dom('.theme .ic');
9
9
  if (type === 'dark') {
10
- globalVars_1.HTML.attr('data-theme', type);
10
+ HTML.attr('data-theme', type);
11
11
  btn.removeClass('i-sun');
12
12
  btn.addClass('i-moon');
13
13
  }
14
14
  else {
15
- globalVars_1.HTML.attr('data-theme', null);
15
+ HTML.attr('data-theme', null);
16
16
  btn.removeClass('i-moon');
17
17
  btn.addClass('i-sun');
18
18
  }
19
19
  };
20
- exports.changeTheme = changeTheme;
21
- const autoDarkmode = () => {
20
+ /**
21
+ * 自动调整黑夜白天
22
+ * 优先级: 手动选择>时间>跟随系统
23
+ */
24
+ export const autoDarkmode = () => {
22
25
  if (CONFIG.auto_dark.enable) {
23
26
  if (new Date().getHours() >= CONFIG.auto_dark.start || new Date().getHours() <= CONFIG.auto_dark.end) {
24
- (0, exports.changeTheme)('dark');
27
+ changeTheme('dark');
25
28
  }
26
29
  else {
27
- (0, exports.changeTheme)();
30
+ changeTheme();
28
31
  }
29
32
  }
30
33
  };
31
- exports.autoDarkmode = autoDarkmode;
32
- const changeMetaTheme = (color) => {
33
- if (globalVars_1.HTML.attr('data-theme') === 'dark') {
34
+ /**
35
+ * 更改主题的meta
36
+ */
37
+ export const changeMetaTheme = (color) => {
38
+ if (HTML.attr('data-theme') === 'dark') {
34
39
  color = '#222';
35
40
  }
36
- (0, dom_1.$dom)('meta[name="theme-color"]').attr('content', color);
41
+ $dom('meta[name="theme-color"]').attr('content', color);
37
42
  };
38
- exports.changeMetaTheme = changeMetaTheme;
39
- const themeColorListener = () => {
43
+ // 记忆日夜模式切换和系统亮暗模式监听
44
+ export const themeColorListener = () => {
40
45
  window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (mediaQueryList) => {
41
46
  if (mediaQueryList.matches) {
42
- (0, exports.changeTheme)('dark');
47
+ changeTheme('dark');
43
48
  }
44
49
  else {
45
- (0, exports.changeTheme)();
50
+ changeTheme();
46
51
  }
47
52
  });
48
- const t = storage_1.$storage.get('theme');
53
+ const t = $storage.get('theme');
49
54
  if (t) {
50
- (0, exports.changeTheme)(t);
55
+ changeTheme(t);
51
56
  }
52
57
  else {
53
58
  if (CONFIG.darkmode) {
54
- (0, exports.changeTheme)('dark');
59
+ changeTheme('dark');
55
60
  }
56
61
  }
57
62
  };
58
- exports.themeColorListener = themeColorListener;