Skip to content

Commit

Permalink
Separate materialize css and remove babel (#6)
Browse files Browse the repository at this point in the history
* remove step 1

* modify deps

* add animations

* fix: image not in manifest

* 1.0.0-alpha.10
  • Loading branch information
swwind committed Aug 25, 2020
1 parent 44fc1d8 commit 650bedf
Show file tree
Hide file tree
Showing 31 changed files with 743 additions and 304 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/node_modules
/src
/.babelrc
/.gitignore
/webpack.config.js
/yarn.lock
15 changes: 0 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,6 @@ if (lstat.isDirectory()) {
app.use(serveZip(zip));
}

// development env
const dist1 = here('node_modules', 'materialize-css', 'dist');
// production env
const dist2 = here('..', 'materialize-css', 'dist');
if (fs.existsSync(dist1)) {
app.use(express.static(dist1));
} else if (fs.existsSync(dist2)) {
app.use(express.static(dist2));
} else {
alert.error('Materialize CSS not found');
alert.debug('__dirname = ' + __dirname);
alert.debug('development = ' + dist1);
alert.debug('production = ' + dist2);
process.exit(1);
}
// serve public folder
app.use(express.static(here('public')));

Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xepub",
"version": "1.0.0-alpha.9",
"version": "1.0.0-alpha.10",
"repository": "https://github.com/swwind/xepub",
"author": "swwind <swwind233@gmail.com>",
"license": "MIT",
Expand All @@ -11,20 +11,16 @@
"express": "^4.16.4",
"fast-xml-parser": "^3.12.16",
"image-size": "^0.7.2",
"materialize-css": "^1.0.0-rc.2",
"memory-fs": "^0.4.1",
"mime-types": "^2.1.22",
"natural-orderby": "^2.0.1",
"node-forge": "^0.8.2",
"opn": "^5.5.0",
"pug": "^2.0.3",
"serve-handler": "^6.0.0",
"socket.io": "^2.2.0"
},
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"babel-loader": "^8.0.5",
"css-loader": "^4.2.2",
"less-loader": "^6.2.0",
"style-loader": "^1.2.1",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
},
Expand Down
82 changes: 0 additions & 82 deletions public/css/xepub.css

This file was deleted.

3 changes: 0 additions & 3 deletions public/img/logo.svg

This file was deleted.

68 changes: 36 additions & 32 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,58 @@
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>Xepub</title>
<link rel="stylesheet" href="/css/materialize.min.css" />
<link rel="stylesheet" href="/css/xepub.css" />
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<noscript>
<p>Before reading this book, you need to cheer "It's nice to have a capable sister" for three times, otherwise it's a thought crime and could end up as:</p>
<ul>
<li>Your computer exploded</li>
<li>Your black history leaked</li>
<li>Your beloved girl got married with your beloved friend</li>
</ul>
</noscript>

<div class="inner">
<div class="container">
<div class="content">
<div class="fake-body"></div>
</div>
<div class="container">
<div class="header logo">Xepub</div>
<div class="content">
<div class="fake-body"></div>
</div>
</div>

<nav class="blue header">
<div class="nav-wrapper container">
<span class="brand-logo left">Xepub</span>
<div class="buttons">
<div class="large-button" id="menu">
<i class="material-icons">menu</i>
</div>
</nav>

<ul id="bookmark-sidenav" class="sidenav collapsible collapsible-accordion">
<li><a class="subheader">Bookmarks</a></li>
</ul>
<ul class="button-list" id="submenu">
<li data-tooltip="Settings" id="settings"><i class="material-icons">settings</i></li>
<li data-tooltip="Infomations" id="info"><i class="material-icons">info</i></li>
<li data-tooltip="Bookmarks" id="bookmark"><i class="material-icons">bookmark</i></li>
<li data-tooltip="To Top" id="totop"><i class="material-icons">arrow_upward</i></li>
</ul>
</div>

<div class="fixed-action-btn">
<a class="btn-floating btn-large red waves-effect">
<i class="large material-icons">menu</i>
</a>
<ul>
<li><a class="tooltipped btn-floating red" data-position="left" data-tooltip="Settings" id="settings"><i class="material-icons">settings</i></a></li>
<li><a class="tooltipped btn-floating green" data-position="left" data-tooltip="Infomations" id="info"><i class="material-icons">info</i></a></li>
<li><a class="tooltipped btn-floating blue" data-position="left" data-tooltip="Bookmarks" id="bookmark"><i class="material-icons">bookmark</i></a></li>
<li><a class="tooltipped btn-floating yellow" data-position="left" data-tooltip="To Top" id="totop"><i class="material-icons">arrow_upward</i></a></li>
<div class="sidenav">
<div class="background"></div>
<ul class="nav">
<li class="header">Bookmarks</li>
</ul>
</div>

<div class="modal" id="infomations-modal">
<div class="modal-content">
<h4>Infomations</h4>
<div class="info-add"></div>
</div>
<div class="modal-footer">
<a class="modal-close waves-effect btn-flat blue white-font">OK</a>
<div class="background">
<div class="container">
<div class="header">Informations</div>
<div class="content" id="informations"></div>
<div class="footer">
<a class="button ok">OK</a>
</div>
</div>
</div>
</div>

<div class="toast"></div>

<script src="/socket.io/socket.io.js"></script>
<script src="/js/materialize.min.js"></script>
<script src="/js/xepub.min.js"></script>
</body>
</html>
107 changes: 32 additions & 75 deletions src/animate.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,41 @@

/**
* get scroll top
* @returns {number}
*/
const getScrollTop = () => {
return document.documentElement.scrollTop || document.body.scrollTop;
export const timings = {
'ease-in-out': (x) => {
return (x * x) / (2 * x * x - 2 * x + 1);
},
'linear': (x) => x
}

/**
* set scroll top
* @param {number} top
*/
export const setScrollTop = (top) => {
document.body.scrollTop = top; // For Safari
document.documentElement.scrollTop = top; // For Chrome, Firefox, IE and Opera
}

/**
* Scroll to the specific position
* @param {number} pos position
* @param {number} time million second
*/
export const scrollTo = (pos, time = 500, onend) => {
const timefn = x => x*x / (x*x + (1-x)*(1-x));
const last = Date.now();
const lastpos = getScrollTop();
const fn = (now) => {
now = Date.now() - last;
if (now < time) {
const nowpos = (pos - lastpos) * timefn(now / time) + lastpos;
setScrollTop(nowpos);
requestAnimationFrame(fn);
} else {
setScrollTop(pos);
onend && onend();
export const walk = (step, duration = 200, timing = timings['ease-in-out']) => {
return new Promise((resolve) => {
const start = Date.now();
const fn = () => {
const now = Date.now();
if (now - start >= duration) {
step(1);
resolve();
} else {
step(timing((now - start) / duration));
requestAnimationFrame(fn);
}
}
}
requestAnimationFrame(fn);
}

/**
* fly to element
* @param {string} el selector
*/
export const flyToElement = (el) => {
// fake invoke
if (!el) return;

console.log('Scrolling to ' + el);

const elem = document.querySelector(el);
if (!elem) {
console.warn('Cannot find element: ' + el);
return;
}
const target = getScrollTop() + elem.getBoundingClientRect().top;
elem.classList.remove('xepub-highlight');

scrollTo(target - 100, 500, () => {
elem.classList.add('xepub-highlight');

requestAnimationFrame(fn);
});
}

/**
* fly to an element or top without animations
* @param {string} el selector
*/
export const flyToElementImmediately = (el) => {

if (!el) {
setScrollTop(0);
return;
}

const elem = document.querySelector(el);
if (!elem) {
setScrollTop(0);
return;
export const animate = async (target, dest, duration = 200, timing = timings['ease-in-out']) => {
const from = { };
for (const key in dest) {
if (typeof dest[key] === 'number') {
from[key] = parseFloat(target.style[key]);
}
}
const target = getScrollTop() + elem.getBoundingClientRect().top;

setScrollTop(target - 100);
await walk((x) => {
for (const key in from) {
const now = (dest[key] - from[key]) * x + from[key];
target.style[key] = now + 'px';
}
}, duration, timing);
}

Loading

0 comments on commit 650bedf

Please sign in to comment.