hexo-theme-shokax 0.2.10 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/LICENSE +68 -81
  2. package/README.md +17 -6
  3. package/UsageRestrictions.md +21 -0
  4. package/_config.yml +5 -12
  5. package/layout/_mixin/comment.pug +1 -2
  6. package/layout/_mixin/widgets.pug +2 -1
  7. package/layout/_partials/layout.pug +23 -23
  8. package/package.json +16 -12
  9. package/scripts/generaters/script.js +29 -8
  10. package/scripts/helpers/summary_ai.js +0 -1
  11. package/scripts/plugin/check.js +30 -0
  12. package/scripts/plugin/index.js +5 -0
  13. package/source/css/_common/components/tags/tabs.styl +0 -2
  14. package/source/css/_common/scaffolding/normalize.styl +165 -180
  15. package/source/js/_app/globals/globalVars.js +26 -0
  16. package/source/js/_app/globals/handles.js +105 -0
  17. package/source/js/_app/globals/themeColor.js +48 -0
  18. package/source/js/_app/globals/thirdparty.js +60 -0
  19. package/source/js/_app/globals/tools.js +75 -0
  20. package/source/js/_app/library/anime.js +85 -0
  21. package/source/js/_app/library/dom.js +22 -0
  22. package/source/js/_app/library/loadFile.js +32 -0
  23. package/source/js/_app/library/proto.js +105 -0
  24. package/source/js/_app/library/scriptPjax.js +57 -0
  25. package/source/js/_app/library/storage.js +11 -0
  26. package/source/js/_app/page/comment.js +19 -0
  27. package/source/js/_app/page/common.js +57 -0
  28. package/source/js/_app/page/fancybox.js +59 -0
  29. package/source/js/_app/page/post.js +232 -0
  30. package/source/js/_app/page/search.js +111 -0
  31. package/source/js/_app/page/tab.js +50 -0
  32. package/source/js/_app/pjax/domInit.js +68 -0
  33. package/source/js/_app/pjax/refresh.js +42 -0
  34. package/source/js/_app/pjax/siteInit.js +34 -0
  35. package/source/js/_app/player.js +1 -1
  36. package/source/js/_app/global.js +0 -314
  37. package/source/js/_app/library.js +0 -312
  38. package/source/js/_app/page.js +0 -673
  39. /package/source/js/_app/{components.js → components/sidebar.js} +0 -0
  40. /package/source/js/_app/{vue.js → library/vue.js} +0 -0
@@ -0,0 +1,75 @@
1
+ const showtip = (msg) => {
2
+ if (!msg) {
3
+ return;
4
+ }
5
+ const tipbox = BODY.createChild('div', {
6
+ innerHTML: msg,
7
+ className: 'tip'
8
+ });
9
+ setTimeout(() => {
10
+ tipbox.addClass('hide');
11
+ setTimeout(() => {
12
+ BODY.removeChild(tipbox);
13
+ }, 300);
14
+ }, 3000);
15
+ };
16
+ const pagePosition = () => {
17
+ if (CONFIG.auto_scroll) {
18
+ $storage.set(LOCAL_URL, String(scrollAction.y));
19
+ }
20
+ };
21
+ const positionInit = (comment) => {
22
+ const anchor = window.location.hash;
23
+ let target = null;
24
+ if (LOCAL_HASH) {
25
+ $storage.del(LOCAL_URL);
26
+ return;
27
+ }
28
+ if (anchor) {
29
+ target = $dom(decodeURI(anchor));
30
+ }
31
+ else {
32
+ target = CONFIG.auto_scroll ? parseInt($storage.get(LOCAL_URL)) : 0;
33
+ }
34
+ if (target) {
35
+ pageScroll(target);
36
+ LOCAL_HASH = 1;
37
+ }
38
+ if (comment && anchor && !LOCAL_HASH) {
39
+ pageScroll(target);
40
+ LOCAL_HASH = 1;
41
+ }
42
+ };
43
+ const clipBoard = (str, callback) => {
44
+ if (navigator.clipboard && window.isSecureContext) {
45
+ navigator.clipboard.writeText(str).then(() => {
46
+ callback && callback(true);
47
+ }, () => {
48
+ callback && callback(false);
49
+ });
50
+ }
51
+ else {
52
+ const ta = BODY.createChild('textarea', {
53
+ style: {
54
+ top: window.scrollY + 'px',
55
+ position: 'absolute',
56
+ opacity: '0'
57
+ },
58
+ readOnly: true,
59
+ value: str
60
+ });
61
+ const selection = document.getSelection();
62
+ const selected = selection.rangeCount > 0 ? selection.getRangeAt(0) : false;
63
+ ta.select();
64
+ ta.setSelectionRange(0, str.length);
65
+ ta.readOnly = false;
66
+ const result = document.execCommand('copy');
67
+ callback && callback(result);
68
+ ta.blur();
69
+ if (selected) {
70
+ selection.removeAllRanges();
71
+ selection.addRange(selected);
72
+ }
73
+ BODY.removeChild(ta);
74
+ }
75
+ };
@@ -0,0 +1,85 @@
1
+ const transition = (target, type, complete, begin) => {
2
+ let animation;
3
+ let display = 'none';
4
+ switch (type) {
5
+ case 0:
6
+ animation = { opacity: [1, 0] };
7
+ break;
8
+ case 1:
9
+ animation = { opacity: [0, 1] };
10
+ display = 'block';
11
+ break;
12
+ case 'bounceUpIn':
13
+ animation = {
14
+ begin(anim) {
15
+ target.display('block');
16
+ },
17
+ translateY: [
18
+ { value: -60, duration: 200 },
19
+ { value: 10, duration: 200 },
20
+ { value: -5, duration: 200 },
21
+ { value: 0, duration: 200 }
22
+ ],
23
+ opacity: [0, 1]
24
+ };
25
+ display = 'block';
26
+ break;
27
+ case 'shrinkIn':
28
+ animation = {
29
+ begin(anim) {
30
+ target.display('block');
31
+ },
32
+ scale: [
33
+ { value: 1.1, duration: 300 },
34
+ { value: 1, duration: 200 }
35
+ ],
36
+ opacity: 1
37
+ };
38
+ display = 'block';
39
+ break;
40
+ case 'slideRightIn':
41
+ animation = {
42
+ begin(anim) {
43
+ target.display('block');
44
+ },
45
+ translateX: ['100%', '0%'],
46
+ opacity: [0, 1]
47
+ };
48
+ display = 'block';
49
+ break;
50
+ case 'slideRightOut':
51
+ animation = {
52
+ translateX: ['0%', '100%'],
53
+ opacity: [1, 0]
54
+ };
55
+ break;
56
+ default:
57
+ animation = type;
58
+ display = type.display;
59
+ break;
60
+ }
61
+ anime(Object.assign({
62
+ targets: target,
63
+ duration: 200,
64
+ easing: 'linear',
65
+ begin() {
66
+ begin && begin();
67
+ },
68
+ complete() {
69
+ target.display(display);
70
+ complete && complete();
71
+ }
72
+ }, animation)).play();
73
+ };
74
+ const pageScroll = (target, offset, complete) => {
75
+ const opt = {
76
+ targets: typeof offset === 'number' ? target.parentNode : document.scrollingElement,
77
+ duration: 500,
78
+ easing: 'easeInOutQuad',
79
+ scrollTop: offset || (typeof target === 'number' ? target : (target ? target.getTop() + document.documentElement.scrollTop - siteNavHeight : 0)),
80
+ complete() {
81
+ complete && complete();
82
+ }
83
+ };
84
+ anime(opt).play();
85
+ };
@@ -0,0 +1,22 @@
1
+ const getDocHeight = () => $dom('main > .inner').offsetHeight;
2
+ const $dom = (selector, element = document) => {
3
+ if (selector[0] === '#') {
4
+ return element.getElementById(selector.substring(1));
5
+ }
6
+ return element.querySelector(selector);
7
+ };
8
+ $dom.all = (selector, element = document) => {
9
+ return element.querySelectorAll(selector);
10
+ };
11
+ $dom.each = (selector, callback, element) => {
12
+ $dom.all(selector, element).forEach(callback);
13
+ };
14
+ $dom.asyncify = async (selector, element = document) => {
15
+ if (selector[0] === '#') {
16
+ return element.getElementById(selector.substring(1));
17
+ }
18
+ return element.querySelector(selector);
19
+ };
20
+ $dom.asyncifyEach = (selector, callback, element) => {
21
+ $dom.all(selector, element).forEach(callback);
22
+ };
@@ -0,0 +1,32 @@
1
+ const assetUrl = (asset, type) => {
2
+ const str = CONFIG[asset][type];
3
+ if (str.includes('gh') || str.includes('combine')) {
4
+ return `https://cdn.jsdelivr.net/${str}`;
5
+ }
6
+ if (str.includes('npm')) {
7
+ return `https://cdn.jsdelivr.net/${str}`;
8
+ }
9
+ if (str.includes('http')) {
10
+ return str;
11
+ }
12
+ return `/${str}`;
13
+ };
14
+ const vendorJs = (type, callback, condition) => {
15
+ if (LOCAL[type]) {
16
+ getScript(assetUrl('js', type), callback || function () {
17
+ window[type] = true;
18
+ }, condition || window[type]);
19
+ }
20
+ };
21
+ const vendorCss = (type, condition) => {
22
+ if (window['css' + type]) {
23
+ return;
24
+ }
25
+ if (LOCAL[type]) {
26
+ document.head.createChild('link', {
27
+ rel: 'stylesheet',
28
+ href: assetUrl('css', type)
29
+ });
30
+ window['css' + type] = true;
31
+ }
32
+ };
@@ -0,0 +1,105 @@
1
+ Object.assign(HTMLElement.prototype, {
2
+ createChild(tag, obj, positon) {
3
+ const child = document.createElement(tag);
4
+ Object.assign(child, obj);
5
+ switch (positon) {
6
+ case 'after':
7
+ this.insertAfter(child);
8
+ break;
9
+ case 'replace':
10
+ this.innerHTML = '';
11
+ this.appendChild(child);
12
+ break;
13
+ default:
14
+ this.appendChild(child);
15
+ }
16
+ return child;
17
+ },
18
+ wrapObject(obj) {
19
+ const box = document.createElement('div');
20
+ Object.assign(box, obj);
21
+ this.parentNode.insertBefore(box, this);
22
+ this.parentNode.removeChild(this);
23
+ box.appendChild(this);
24
+ },
25
+ changeOrGetHeight(h) {
26
+ if (h) {
27
+ this.style.height = typeof h === 'number' ? h + 'rem' : h;
28
+ }
29
+ return this.getBoundingClientRect().height;
30
+ },
31
+ changeOrGetWidth(w) {
32
+ if (w) {
33
+ this.style.width = typeof w === 'number' ? w + 'rem' : w;
34
+ }
35
+ return this.getBoundingClientRect().width;
36
+ },
37
+ getTop() {
38
+ return this.getBoundingClientRect().top;
39
+ },
40
+ left() {
41
+ return this.getBoundingClientRect().left;
42
+ },
43
+ attr(type, value) {
44
+ if (value === null) {
45
+ return this.removeAttribute(type);
46
+ }
47
+ if (value) {
48
+ this.setAttribute(type, value);
49
+ return this;
50
+ }
51
+ else {
52
+ return this.getAttribute(type);
53
+ }
54
+ },
55
+ insertAfter(element) {
56
+ const parent = this.parentNode;
57
+ if (parent.lastChild === this) {
58
+ parent.appendChild(element);
59
+ }
60
+ else {
61
+ parent.insertBefore(element, this.nextSibling);
62
+ }
63
+ },
64
+ display(d) {
65
+ if (d == null) {
66
+ return this.style.display;
67
+ }
68
+ else {
69
+ this.style.display = d;
70
+ return this;
71
+ }
72
+ },
73
+ child(selector) {
74
+ return $dom(selector, this);
75
+ },
76
+ find(selector) {
77
+ return $dom.all(selector, this);
78
+ },
79
+ _class(type, className, display) {
80
+ const classNames = className.indexOf(' ') ? className.split(' ') : [className];
81
+ classNames.forEach((name) => {
82
+ if (type === 'toggle') {
83
+ this.classList.toggle(name, display);
84
+ }
85
+ else {
86
+ this.classList[type](name);
87
+ }
88
+ });
89
+ },
90
+ addClass(className) {
91
+ this._class('add', className);
92
+ return this;
93
+ },
94
+ removeClass(className) {
95
+ this._class('remove', className);
96
+ return this;
97
+ },
98
+ toggleClass(className, display) {
99
+ this._class('toggle', className, display);
100
+ return this;
101
+ },
102
+ hasClass(className) {
103
+ return this.classList.contains(className);
104
+ }
105
+ });
@@ -0,0 +1,57 @@
1
+ let inCloudFlare = true;
2
+ window.addEventListener('DOMContentLoaded', function () {
3
+ inCloudFlare = false;
4
+ });
5
+ if (document.readyState === 'loading') {
6
+ window.addEventListener('load', function () {
7
+ if (inCloudFlare) {
8
+ window.dispatchEvent(new Event('DOMContentLoaded'));
9
+ console.log('%c ☁️cloudflare patch ' + '%c running(rocket & minify)', 'color: white; background: #ff8c00; padding: 5px 3px;', 'padding: 4px;border:1px solid #ff8c00');
10
+ }
11
+ });
12
+ }
13
+ const getScript = (url, callback, condition) => {
14
+ if (condition) {
15
+ callback();
16
+ }
17
+ else {
18
+ let script = document.createElement('script');
19
+ script.onload = function (_, isAbort) {
20
+ if (isAbort || !script.readyState) {
21
+ console.log('abort!');
22
+ script.onload = null;
23
+ script = undefined;
24
+ if (!isAbort && callback)
25
+ setTimeout(callback, 0);
26
+ }
27
+ };
28
+ script.src = url;
29
+ document.head.appendChild(script);
30
+ }
31
+ };
32
+ const pjaxScript = (element) => {
33
+ const { text, parentNode, id, className, type, src, dataset } = element;
34
+ const code = text || element.textContent || element.innerHTML || '';
35
+ parentNode.removeChild(element);
36
+ const script = document.createElement('script');
37
+ if (id) {
38
+ script.id = id;
39
+ }
40
+ if (className) {
41
+ script.className = className;
42
+ }
43
+ if (type) {
44
+ script.type = type;
45
+ }
46
+ if (src) {
47
+ script.src = src;
48
+ script.async = false;
49
+ }
50
+ if (dataset.pjax !== undefined) {
51
+ script.dataset.pjax = '';
52
+ }
53
+ if (code !== '') {
54
+ script.appendChild(document.createTextNode(code));
55
+ }
56
+ parentNode.appendChild(script);
57
+ };
@@ -0,0 +1,11 @@
1
+ const $storage = {
2
+ set(key, value) {
3
+ localStorage.setItem(key, value);
4
+ },
5
+ get(key) {
6
+ return localStorage.getItem(key);
7
+ },
8
+ del(key) {
9
+ localStorage.removeItem(key);
10
+ }
11
+ };
@@ -0,0 +1,19 @@
1
+ const loadComments = () => {
2
+ const element = $dom('#comments');
3
+ if (!element) {
4
+ goToComment.display('none');
5
+ return;
6
+ }
7
+ else {
8
+ goToComment.display('');
9
+ }
10
+ const io = new IntersectionObserver((entries, observer) => {
11
+ const entry = entries[0];
12
+ vendorCss('valine');
13
+ if (entry.isIntersecting || entry.intersectionRatio > 0) {
14
+ transition($dom('#comments'), 'bounceUpIn');
15
+ observer.disconnect();
16
+ }
17
+ });
18
+ io.observe(element);
19
+ };
@@ -0,0 +1,57 @@
1
+ const cardActive = () => {
2
+ if (!$dom('.index.wrap')) {
3
+ return;
4
+ }
5
+ const io = new IntersectionObserver((entries) => {
6
+ entries.forEach((article) => {
7
+ if (article.target.hasClass('show')) {
8
+ io.unobserve(article.target);
9
+ }
10
+ else {
11
+ if (article.isIntersecting || article.intersectionRatio > 0) {
12
+ article.target.addClass('show');
13
+ io.unobserve(article.target);
14
+ }
15
+ }
16
+ });
17
+ }, {
18
+ root: null,
19
+ threshold: [0.3]
20
+ });
21
+ $dom.each('.index.wrap article.item, .index.wrap section.item', (article) => {
22
+ io.observe(article);
23
+ });
24
+ $dom('.index.wrap .item:first-child').addClass('show');
25
+ $dom.each('.cards .item', (element) => {
26
+ ['mouseenter', 'touchstart'].forEach((item) => {
27
+ element.addEventListener(item, () => {
28
+ if ($dom('.cards .item.active')) {
29
+ $dom('.cards .item.active').removeClass('active');
30
+ }
31
+ element.addClass('active');
32
+ }, { passive: true });
33
+ });
34
+ ['mouseleave'].forEach((item) => {
35
+ element.addEventListener(item, () => {
36
+ element.removeClass('active');
37
+ }, { passive: true });
38
+ });
39
+ });
40
+ };
41
+ const registerExtURL = () => {
42
+ $dom.each('span.exturl', (element) => {
43
+ const link = document.createElement('a');
44
+ link.href = decodeURIComponent(window.atob(element.dataset.url).split('').map((c) => {
45
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
46
+ }).join(''));
47
+ link.rel = 'noopener external nofollow noreferrer';
48
+ link.target = '_blank';
49
+ link.className = element.className;
50
+ link.title = element.title || element.innerText;
51
+ link.innerHTML = element.innerHTML;
52
+ if (element.dataset.backgroundImage) {
53
+ link.dataset.backgroundImage = element.dataset.backgroundImage;
54
+ }
55
+ element.parentNode.replaceChild(link, element);
56
+ });
57
+ };
@@ -0,0 +1,59 @@
1
+ const postFancybox = (p) => {
2
+ if ($dom(p + ' .md img')) {
3
+ vendorCss('fancybox');
4
+ vendorJs('fancybox', () => {
5
+ const q = jQuery.noConflict();
6
+ $dom.each(p + ' p.gallery', (element) => {
7
+ const box = document.createElement('div');
8
+ box.className = 'gallery';
9
+ box.attr('data-height', String(element.attr('data-height') || 220));
10
+ box.innerHTML = element.innerHTML.replace(/<br>/g, '');
11
+ element.parentNode.insertBefore(box, element);
12
+ element.remove();
13
+ });
14
+ $dom.each(p + ' .md img:not(.emoji):not(.vemoji)', (element) => {
15
+ const $image = q(element);
16
+ const imageLink = $image.attr('data-src') || $image.attr('src');
17
+ const $imageWrapLink = $image.wrap('<a class="fancybox" href="' + imageLink + '" itemscope itemtype="https://schema.org/ImageObject" itemprop="url"></a>').parent('a');
18
+ let info;
19
+ let captionClass = 'image-info';
20
+ if (!$image.is('a img')) {
21
+ $image.data('safe-src', imageLink);
22
+ if (!$image.is('.gallery img')) {
23
+ $imageWrapLink.attr('data-fancybox', 'default').attr('rel', 'default');
24
+ }
25
+ else {
26
+ captionClass = 'jg-caption';
27
+ }
28
+ }
29
+ if ((info = element.attr('title'))) {
30
+ $imageWrapLink.attr('data-caption', info);
31
+ const para = document.createElement('span');
32
+ const txt = document.createTextNode(info);
33
+ para.appendChild(txt);
34
+ para.addClass(captionClass);
35
+ element.insertAfter(para);
36
+ }
37
+ });
38
+ $dom.each(p + ' div.gallery', (el, i) => {
39
+ q(el).justifiedGallery({
40
+ rowHeight: q(el).data('height') || 120,
41
+ rel: 'gallery-' + i
42
+ }).on('jg.complete', function () {
43
+ q(this).find('a').each((k, ele) => {
44
+ ele.attr('data-fancybox', 'gallery-' + i);
45
+ });
46
+ });
47
+ });
48
+ q.fancybox.defaults.hash = false;
49
+ q(p + ' .fancybox').fancybox({
50
+ loop: true,
51
+ helpers: {
52
+ overlay: {
53
+ locked: false
54
+ }
55
+ }
56
+ });
57
+ }, window.jQuery);
58
+ }
59
+ };