hexo-theme-nexmoe
Version:
🔥 A special hexo theme.
2 lines (1 loc) • 15.4 kB
JavaScript
function _classCallCheck(e, t) { if (!(e instanceof t)) throw new TypeError('Cannot call a class as a function'); } function _defineProperty(e, t, n) { return t in e ? Object.defineProperty(e, t, {value: n, enumerable: !0, configurable: !0, writable: !0}) : e[t] = n, e; } function _slicedToArray(e, t) { return _arrayWithHoles(e) || _iterableToArrayLimit(e, t) || _unsupportedIterableToArray(e, t) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError('Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'); } function _unsupportedIterableToArray(e, t) { if (e) { if (typeof e === 'string') return _arrayLikeToArray(e, t); let n = Object.prototype.toString.call(e).slice(8, -1); return n === 'Object' && e.constructor && (n = e.constructor.name), n === 'Map' || n === 'Set' ? Array.from(e) : n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? _arrayLikeToArray(e, t) : void 0; } } function _arrayLikeToArray(e, t) { (t == null || t > e.length) && (t = e.length); for (var n = 0, r = new Array(t); n < t; n++)r[n] = e[n]; return r; } function _iterableToArrayLimit(e, t) { if (typeof Symbol !== 'undefined' && Symbol.iterator in Object(e)) { const n = []; let r = !0; let i = !1; let o = void 0; try { for (var a, l = e[Symbol.iterator](); !(r = (a = l.next()).done) && (n.push(a.value), !t || n.length !== t); r = !0); } catch (e) { i = !0, o = e; } finally { try { r || l.return == null || l.return(); } finally { if (i) throw o; } } return n; } } function _arrayWithHoles(e) { if (Array.isArray(e)) return e; }!(function() { function n(e) { return ['elInY+elHeight', 'elCenterY-'.concat(e = arguments.length > 0 && void 0 !== e ? e : 30), 'elCenterY', 'elCenterY+'.concat(e), 'elOutY-elHeight']; } let l, u, s, _, P, I; const t = {fadeInOut: function(e, t) { t = arguments.length > 1 && void 0 !== t ? t : 0; return {opacity: [n(arguments.length > 0 && void 0 !== e ? e : 30), [t, 1, 1, 1, t]]}; }, fadeIn: function(e, t) { return {opacity: [['elInY+elHeight', arguments.length > 0 && void 0 !== e ? e : 'elCenterY'], [arguments.length > 1 && void 0 !== t ? t : 0, 1]]}; }, fadeOut: function(e, t) { return {opacity: [[arguments.length > 0 && void 0 !== e ? e : 'elCenterY', 'elOutY-elHeight'], [1, arguments.length > 1 && void 0 !== t ? t : 0]]}; }, blurInOut: function(e, t) { t = arguments.length > 1 && void 0 !== t ? t : 20; return {blur: [n(arguments.length > 0 && void 0 !== e ? e : 100), [t, 0, 0, 0, t]]}; }, blurIn: function(e, t) { return {blur: [['elInY+elHeight', arguments.length > 0 && void 0 !== e ? e : 'elCenterY'], [arguments.length > 1 && void 0 !== t ? t : 20, 0]]}; }, blurOut: function(e, t) { return {opacity: [[arguments.length > 0 && void 0 !== e ? e : 'elCenterY', 'elOutY-elHeight'], [0, arguments.length > 1 && void 0 !== t ? t : 20]]}; }, scaleInOut: function(e, t) { t = arguments.length > 1 && void 0 !== t ? t : .6; return {scale: [n(arguments.length > 0 && void 0 !== e ? e : 100), [t, 1, 1, 1, t]]}; }, scaleIn: function(e, t) { return {scale: [['elInY+elHeight', arguments.length > 0 && void 0 !== e ? e : 'elCenterY'], [arguments.length > 1 && void 0 !== t ? t : .6, 1]]}; }, scaleOut: function(e, t) { return {scale: [[arguments.length > 0 && void 0 !== e ? e : 'elCenterY', 'elOutY-elHeight'], [1, arguments.length > 1 && void 0 !== t ? t : .6]]}; }, slideX: function(e, t) { return {translateX: [['elInY', arguments.length > 0 && void 0 !== e ? e : 0], [0, arguments.length > 1 && void 0 !== t ? t : 500]]}; }, slideY: function(e, t) { return {translateY: [['elInY', arguments.length > 0 && void 0 !== e ? e : 0], [0, arguments.length > 1 && void 0 !== t ? t : 500]]}; }, spin: function(e, t) { e = arguments.length > 0 && void 0 !== e ? e : 1e3; return {rotate: [[0, e], [0, arguments.length > 1 && void 0 !== t ? t : 360], {modValue: e}]}; }, flipX: function(e, t) { e = arguments.length > 0 && void 0 !== e ? e : 1e3; return {rotateX: [[0, e], [0, arguments.length > 1 && void 0 !== t ? t : 360], {modValue: e}]}; }, flipY: function(e, t) { e = arguments.length > 0 && void 0 !== e ? e : 1e3; return {rotateY: [[0, e], [0, arguments.length > 1 && void 0 !== t ? t : 360], {modValue: e}]}; }, jiggle: function(e, t) { e = arguments.length > 0 && void 0 !== e ? e : 50, t = arguments.length > 1 && void 0 !== t ? t : 40; return {skewX: [[0, +e, 2 * e, 3 * e, 4 * e], [0, t, 0, -t, 0], {modValue: 4 * e}]}; }, seesaw: function(e, t) { e = arguments.length > 0 && void 0 !== e ? e : 50, t = arguments.length > 1 && void 0 !== t ? t : 40; return {skewY: [[0, +e, 2 * e, 3 * e, 4 * e], [0, t, 0, -t, 0], {modValue: 4 * e}]}; }, zigzag: function(e, t) { e = arguments.length > 0 && void 0 !== e ? e : 100, t = arguments.length > 1 && void 0 !== t ? t : 100; return {translateX: [[0, +e, 2 * e, 3 * e, 4 * e], [0, t, 0, -t, 0], {modValue: 4 * e}]}; }, hueRotate: function(e, t) { e = arguments.length > 0 && void 0 !== e ? e : 600; return {'hue-rotate': [[0, e], [0, arguments.length > 1 && void 0 !== t ? t : 360], {modValue: e}]}; }}; const e = (l = ['perspective', 'scaleX', 'scaleY', 'scale', 'skewX', 'skewY', 'skew', 'rotateX', 'rotateY', 'rotate'], u = ['blur', 'hue-rotate', 'brightness'], s = ['translateX', 'translateY', 'translateZ'], _ = ['perspective', 'border-radius', 'blur', 'translateX', 'translateY', 'translateZ'], P = ['hue-rotate', 'rotate', 'rotateX', 'rotateY', 'skew', 'skewX', 'skewY'], I = {easeInQuad: function(e) { return e * e; }, easeOutQuad: function(e) { return e * (2 - e); }, easeInOutQuad: function(e) { return e < .5 ? 2 * e * e : (4 - 2 * e) * e - 1; }, easeInCubic: function(e) { return e * e * e; }, easeOutCubic: function(e) { return --e * e * e + 1; }, easeInOutCubic: function(e) { return e < .5 ? 4 * e * e * e : (e - 1) * (2 * e - 2) * (2 * e - 2) + 1; }, easeInQuart: function(e) { return e * e * e * e; }, easeOutQuart: function(e) { return 1 - --e * e * e * e; }, easeInOutQuart: function(e) { return e < .5 ? 8 * e * e * e * e : 1 - 8 * --e * e * e * e; }, easeInQuint: function(e) { return e * e * e * e * e; }, easeOutQuint: function(e) { return 1 + --e * e * e * e * e; }, easeInOutQuint: function(e) { return e < .5 ? 16 * e * e * e * e * e : 1 + 16 * --e * e * e * e * e; }, easeOutBounce: function(e) { const t = 7.5625; const n = 2.75; return e < 1 / n ? t * e * e : e < 2 / n ? t * (e -= 1.5 / n) * e + .75 : e < 2.5 / n ? t * (e -= 2.25 / n) * e + .9375 : t * (e -= 2.625 / n) * e + .984375; }, easeInBounce: function(e) { return 1 - I.easeOutBounce(1 - e); }, easeOutBack: function(e) { return 1 + 2.70158 * Math.pow(e - 1, 3) + 1.70158 * Math.pow(e - 1, 2); }, easeInBack: function(e) { return 2.70158 * e * e * e - 1.70158 * e * e; }}, new function e() { const o = this; _classCallCheck(this, e), _defineProperty(this, 'drivers', []), _defineProperty(this, 'elements', []), _defineProperty(this, 'frame', 0), _defineProperty(this, 'debug', !1), _defineProperty(this, 'windowWidth', 0), _defineProperty(this, 'windowHeight', 0), _defineProperty(this, 'presets', t), _defineProperty(this, 'debugData', {frameLengths: []}), _defineProperty(this, 'init', () => { o.findAndAddElements(), window.requestAnimationFrame(o.onAnimationFrame), o.windowWidth = document.body.clientWidth, o.windowHeight = document.body.clientHeight, window.onresize = o.onWindowResize; }), _defineProperty(this, 'onWindowResize', () => { document.body.clientWidth === o.windowWidth && document.body.clientHeight === o.windowHeight || (o.windowWidth = document.body.clientWidth, o.windowHeight = document.body.clientHeight, o.elements.forEach(e => { return e.calculateTransforms(); })); }), _defineProperty(this, 'onAnimationFrame', e => { o.debug && (o.debugData.frameStart = Date.now()); let t; const n = {}; o.drivers.forEach(e => { n[e.name] = e.getValue(o.frame); }), o.elements.forEach(e => { e.update(n, o.frame); }), o.debug && o.debugData.frameLengths.push(Date.now() - o.debugData.frameStart), o.frame % 60 == 0 && o.debug && (t = Math.ceil(o.debugData.frameLengths.reduce((e, t) => { return e + t; }, 0) / 60), console.log('Average frame calculation time: '.concat(t, 'ms')), o.debugData.frameLengths = []), o.frame++, window.requestAnimationFrame(o.onAnimationFrame); }), _defineProperty(this, 'addDriver', function(e, t) { const n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}; o.drivers.push(new i(e, t, n)); }), _defineProperty(this, 'removeDriver', t => { o.drivers = o.drivers.filter(e => { return e.name !== t; }); }), _defineProperty(this, 'findAndAddElements', () => { o.elements = [], document.querySelectorAll('.lax').forEach(e => { const t = []; e.classList.forEach(e => { e.includes('lax_preset') && (e = e.replace('lax_preset_', ''), t.push(e)); }); const n = _defineProperty({}, 'scrollY', {presets: t}); o.elements.push(new f('.lax', o, e, n, 0, {})); }); }), _defineProperty(this, 'addElements', (n, r, i) => { document.querySelectorAll(n).forEach((e, t) => { o.elements.push(new f(n, o, e, r, t, i)); }); }), _defineProperty(this, 'removeElements', t => { o.elements = o.elements.filter(e => { return e.selector !== t; }); }), _defineProperty(this, 'addElement', (e, t, n) => { o.elements.push(new f('', o, e, t, 0, n)); }), _defineProperty(this, 'removeElement', t => { o.elements = o.elements.filter(e => { return e.domElement !== t; }); }); }()); function c(e, t) { if (Array.isArray(e)) return e; for (var n = Object.keys(e).map(e => { return parseInt(e); }).sort((e, t) => { return t < e ? 1 : -1; }), r = n[n.length - 1], i = 0; i < n.length; i++) { const o = n[i]; if (t < o) { r = o; break; } } return e[r]; } function d(e, t, n) { const r = t.width; const i = t.height; var o = t.x; var a = t.y; if (typeof e === 'number') return e; let l; const u = document.body.scrollHeight; const s = document.body.scrollWidth; const c = window.innerWidth; const d = window.innerHeight; var f = _slicedToArray((l = void 0 !== window.pageXOffset, f = (document.compatMode || '') === 'CSS1Compat', t = l ? window.pageXOffset : (f ? document.documentElement : document.body).scrollLeft, [l ? window.pageYOffset : (f ? document.documentElement : document.body).scrollTop, t]), 2); var t = f[0]; var o = o + f[1]; var f = o + r; var a = a + t; var t = a + i; return Function('return '.concat(e.replace(/screenWidth/g, c).replace(/screenHeight/g, d).replace(/pageHeight/g, u).replace(/pageWidth/g, s).replace(/elWidth/g, r).replace(/elHeight/g, i).replace(/elInY/g, a - d).replace(/elOutY/g, t).replace(/elCenterY/g, a + i / 2 - d / 2).replace(/elInX/g, o - c).replace(/elOutX/g, f).replace(/elCenterX/g, o + r / 2 - c / 2).replace(/index/g, n)))(); } function i(e, t) { const n = this; const r = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}; _classCallCheck(this, i), _defineProperty(this, 'getValueFn', void 0), _defineProperty(this, 'name', ''), _defineProperty(this, 'lastValue', 0), _defineProperty(this, 'frameStep', 1), _defineProperty(this, 'm1', 0), _defineProperty(this, 'm2', 0), _defineProperty(this, 'inertia', 0), _defineProperty(this, 'inertiaEnabled', !1), _defineProperty(this, 'getValue', e => { let t = n.lastValue; return e % n.frameStep == 0 && (t = n.getValueFn(e)), n.inertiaEnabled && (e = t - n.lastValue, n.m1 = .8 * n.m1 + e * (1 - .8), n.m2 = .8 * n.m2 + n.m1 * (1 - .8), n.inertia = Math.round(5e3 * n.m2) / 15e3), n.lastValue = t, [n.lastValue, n.inertia]; }), this.name = e, this.getValueFn = t, Object.keys(r).forEach(e => { n[e] = r[e]; }), this.lastValue = this.getValueFn(0); } function f(e, t, n, r) { const b = this; let i = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : 0; var o = arguments.length > 5 && void 0 !== arguments[5] ? arguments[5] : {}; _classCallCheck(this, f), _defineProperty(this, 'domElement', void 0), _defineProperty(this, 'transformsData', void 0), _defineProperty(this, 'styles', {}), _defineProperty(this, 'selector', ''), _defineProperty(this, 'groupIndex', 0), _defineProperty(this, 'laxInstance', void 0), _defineProperty(this, 'onUpdate', void 0), _defineProperty(this, 'update', (e, t) => { let n; const r = b.transforms; const i = {}; for (n in r) { const o = r[n]; e[n] || console.error('No lax driver with name: ', n); var a; const l = _slicedToArray(e[n], 2); const u = l[0]; const s = l[1]; for (a in o) { var c; var d = _slicedToArray(o[a], 3); const f = d[0]; const h = d[1]; var m = d[2]; var p = void 0 === m ? {} : m; const g = p.modValue; var y = p.frameStep; const v = void 0 === y ? 1 : y; var w = p.easing; var d = p.inertia; var m = p.inertiaMode; var y = p.cssFn; var p = p.cssUnit; var p = void 0 === p ? '' : p; var w = I[w]; t % v == 0 && (w = (function(e, t, n, r) { let i = 0; if (e.forEach(e => { e < n && i++; }), i <= 0) return t[0]; if (i >= e.length) return t[e.length - 1]; let o; var a = (a = e[o = i - 1], e = e[i], (n - a) / (e - a)); return r && (a = r(a)), o = t[o], t = t[i], o * (1 - (a = a)) + t * a; }(f, h, g ? u % g : u, w)), d && (c = s * d, m === 'absolute' && (c = Math.abs(c)), w += c), c = (p || _.includes(a) ? 'px' : P.includes(a) ? 'deg' : '') == 'px' ? 0 : 3, c = w.toFixed(c), i[a] = y ? y(c, b.domElement) : c + p); } }b.applyStyles(i), b.onUpdate && b.onUpdate(e, b.domElement); }), _defineProperty(this, 'calculateTransforms', () => { b.transforms = {}; let e; const l = b.laxInstance.windowWidth; for (e in b.transformsData)!(function(e) { const o = b.transformsData[e]; const a = {}; const t = o.presets; (void 0 === t ? [] : t).forEach(e => { let t; var n = _slicedToArray(e.split(':'), 3); const r = n[0]; const i = n[1]; var e = n[2]; var n = window.lax.presets[r]; n ? (t = n(i, e), Object.keys(t).forEach(e => { o[e] = t[e]; })) : console.error('Lax preset cannot be found with name: ', r); }), delete o.presets; for (const n in o)!(function(e) { var t = _slicedToArray(o[e], 3); var n = t[0]; var r = void 0 === n ? [-1e9, 1e9] : n; var n = t[1]; var n = void 0 === n ? [-1e9, 1e9] : n; var t = t[2]; var t = void 0 === t ? {} : t; const i = b.domElement.getBoundingClientRect(); var r = c(r, l).map(e => { return d(e, i, b.groupIndex); }); var n = c(n, l).map(e => { return d(e, i, b.groupIndex); }); a[e] = [r, n, t]; }(n)); b.transforms[e] = a; }(e)); }), _defineProperty(this, 'applyStyles', e => { let r, i, o; const t = (r = e, i = {transform: '', filter: ''}, o = {translateX: 1e-5, translateY: 1e-5, translateZ: 1e-5}, Object.keys(r).forEach(e => { const t = r[e]; const n = _.includes(e) ? 'px' : P.includes(e) ? 'deg' : ''; s.includes(e) ? o[e] = t : l.includes(e) ? i.transform += ''.concat(e, '(').concat(t).concat(n, ') ') : u.includes(e) ? i.filter += ''.concat(e, '(').concat(t).concat(n, ') ') : i[e] = ''.concat(t).concat(n, ' '); }), i.transform = 'translate3d('.concat(o.translateX, 'px, ').concat(o.translateY, 'px, ').concat(o.translateZ, 'px) ').concat(i.transform), i); Object.keys(t).forEach(e => { b.domElement.style.setProperty(e, t[e]); }); }), this.selector = e, this.laxInstance = t, this.domElement = n, this.transformsData = r, this.groupIndex = i; const a = void 0 === (i = o.style) ? {} : i; var o = o.onUpdate; Object.keys(a).forEach(e => { n.style.setProperty(e, a[e]); }), o && (this.onUpdate = o), this.calculateTransforms(); } typeof module !== 'undefined' && void 0 !== module.exports ? module.exports = e : window.lax = e; }());