Skip to content

Commit f2f731d

Browse files
authored
Merge pull request #2 from HTMLToolkit/v2.1.0
Migrate to Vite, add PWA/offline support, and fix table-of-contents bug (v2.1.0)
2 parents 9ff9a03 + 1c17e8d commit f2f731d

34 files changed

+10557
-1337
lines changed

Build/.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Node modules
2+
node_modules/
3+
4+
# Logs
5+
logs/
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
11+
# Build output
12+
dist/
13+
build/
14+
out/
15+
16+
# TypeScript cache
17+
*.tsbuildinfo
18+
19+
# Environment variables
20+
.env
21+
.env.*
22+
23+
# IDE files
24+
.vscode/
25+
.idea/
26+
*.suo
27+
*.ntvs*
28+
*.njsproj
29+
*.sln
30+
31+
# OS files
32+
.DS_Store
33+
Thumbs.db
34+
35+
# Coverage
36+
coverage/
37+
38+
# Optional npm cache directory
39+
.npm/
40+
41+
# Optional eslint cache
42+
.eslintcache

Build/eslint.config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import json from "@eslint/json";
4+
import markdown from "@eslint/markdown";
5+
import css from "@eslint/css";
6+
import { defineConfig } from "eslint/config";
7+
8+
export default defineConfig([
9+
js.configs.recommended,
10+
{ files: ["**/*.{js,mjs,cjs}"], languageOptions: { globals: globals.browser } },
11+
json.configs.recommended,
12+
markdown.configs.recommended,
13+
css.configs.recommended,
14+
]);

Build/export.mjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import fs from 'fs-extra';
2+
import path from 'path';
3+
import { rimrafSync } from 'rimraf';
4+
import { fileURLToPath } from 'url';
5+
import process from 'process';
6+
7+
// ES module __dirname fix
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
11+
const root = path.resolve(__dirname, '..'); // repo root
12+
const dist = path.join(__dirname, 'dist'); // build folder
13+
14+
// Files/folders to keep
15+
const keep = new Set(['README.md', 'LICENSE', 'Build']);
16+
17+
// Clean repo root (skip hidden files/folders)
18+
fs.readdirSync(root).forEach(file => {
19+
if (!fs.existsSync(dist) || fs.readdirSync(dist).length === 0) {
20+
console.error('ERROR: dist is missing or empty:', dist);
21+
process.exit(1);
22+
}
23+
24+
if (!keep.has(file) && !file.startsWith('.')) { // <-- skip hidden
25+
rimrafSync(path.join(root, file));
26+
console.log('Deleted:', file);
27+
}
28+
});
29+
30+
// Copy each item inside dist individually
31+
fs.readdirSync(dist).forEach(item => {
32+
const srcPath = path.join(dist, item);
33+
const destPath = path.join(root, item);
34+
35+
// Skip copying if destination exists and is in keep set
36+
if (keep.has(item)) {
37+
console.log(`Skipping copy of ${item} (keep folder/file)`);
38+
return;
39+
}
40+
41+
fs.copySync(srcPath, destPath, { overwrite: true });
42+
console.log('Copied:', item);
43+
});

Build/index.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="Content-Security-Policy" content="
5+
default-src 'self' blob: data:;
6+
script-src 'self';
7+
style-src 'self' 'unsafe-inline';
8+
img-src 'self' blob: data:;
9+
connect-src 'self';
10+
frame-src 'self' blob: data:;
11+
worker-src 'self';
12+
manifest-src 'self';
13+
upgrade-insecure-requests; block-all-mixed-content;">
14+
<meta charset="UTF-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
16+
<title>HTMLReader</title>
17+
<link rel="stylesheet" href="./src/style.css" />
18+
</head>
19+
<body>
20+
<header>
21+
<div class="title">
22+
<span>HTMLReader</span>
23+
<span class="book-title" id="book-title"></span>
24+
</div>
25+
<div class="controls">
26+
<button id="toc-button" disabled>Table of Contents</button>
27+
<button id="open-button">Open EPUB</button>
28+
<button id="library-button">Library</button>
29+
<input type="file" id="file-input" class="file-input" accept=".epub">
30+
<!-- Fallback multiple file input for library import -->
31+
<input type="file" id="library-input" class="file-input" accept=".epub" multiple>
32+
<button id="install-button" hidden>Install App</button> <!-- New Install Button -->
33+
</div>
34+
</header>
35+
<main>
36+
<div id="viewer"></div>
37+
</main>
38+
<footer>
39+
<button id="prev-button" disabled>⬅ Previous</button>
40+
<div class="page-info">
41+
<span>Page</span>
42+
<input type="number" id="current-page" min="1" value="1">
43+
<span>of</span>
44+
<span id="total-pages">1</span>
45+
</div>
46+
<button id="next-button" disabled>Next ➡</button>
47+
</footer>
48+
<!-- TOC Container -->
49+
<div class="toc-container" id="toc-container">
50+
<div class="toc-header">
51+
<h3>Table of Contents</h3>
52+
<button id="close-toc">Close</button>
53+
</div>
54+
<div class="toc-content" id="toc-content"></div>
55+
</div>
56+
<!-- Library Popup (hidden by default) -->
57+
<div class="library-container" id="library-container">
58+
<div class="library-header">
59+
<h3>Library</h3>
60+
<button id="close-library">Close</button>
61+
</div>
62+
<div class="library-content" id="library-content"></div>
63+
</div>
64+
<div class="overlay" id="overlay"></div>
65+
<div class="message" id="loading-message">
66+
<h3>Loading EPUB...</h3>
67+
<p>Please wait while your book is being processed.</p>
68+
</div>
69+
<div class="message" id="error-message">
70+
<h3>Error</h3>
71+
<p id="error-text">There was an error processing your EPUB file.</p>
72+
<button id="close-error">Close</button>
73+
</div>
74+
</body>
75+
<script type="module" src="./src/main.js"></script>
76+
</html>

0 commit comments

Comments
 (0)