From 64dc63587ff90e79547e2d149d2e121447878ec6 Mon Sep 17 00:00:00 2001 From: unfunny Date: Tue, 20 Oct 2026 20:17:01 -0400 Subject: [PATCH] Added proper IWA support --- AGENTS.md | 8 +++--- iwa-build.js | 61 ++++++++++++++++++++++++++++++++++++++++ package.json | 1 + public/iwa.html | 30 ++++++++++++++++++++ public/iwa/index.html | 15 ++++++++++ public/iwa/manifest.json | 20 +++++++++++++ vite.config.js | 5 ++-- 7 files changed, 134 insertions(+), 6 deletions(-) create mode 100755 iwa-build.js create mode 100644 public/iwa.html create mode 100644 public/iwa/index.html create mode 100644 public/iwa/manifest.json diff --git a/AGENTS.md b/AGENTS.md index 43f31d9..feed02d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,8 +13,8 @@ Open `dist/index.html` directly in any browser—no server required. ## Build Targets -- **Singlefile HTML** (`SINGLEFILE=1 vite build`) — self-contained, offline-capable -- **IWA/Chrome Extension** — load popup from `public/manifest.json` +- **Singlefile HTML** (`SINGLEFILE=1 vite build`) — self-contained, offline-capable (~16KB) +- **IWA/Chrome Extension** (`npm run build:iwa`) — Installer for Web Applications manifest at `public/iwa/manifest.json` - **PWA** — installable app with service worker in `dist/sw.js` ## Project Structure @@ -24,8 +24,8 @@ src/ # React components (App.jsx, Editor.jsx, Toolbar.jsx) components/ # MarkdownEditor, LaTeXRenderer, SvgRenderer hooks/ # useTheme, useKeyboardShortcuts utils/ # exportDocx, importDocx, fileIo, exportPdf -public/ # sample.md, favicon.svg, icons.svg -dist/ # Production build (single index.html + manifest.json) +public/ # sample.md, favicon.svg, icons.svg, iwa/ (Chrome extension manifest) +dist/ # Production build (single index.html + assets) ``` ## Toolchain Quirks diff --git a/iwa-build.js b/iwa-build.js new file mode 100755 index 0000000..e2be6c5 --- /dev/null +++ b/iwa-build.js @@ -0,0 +1,61 @@ +#!/usr/bin/env node +/** + * IWA (Installer for Web Applications) Build Script + * Generates Chrome extension manifest and required files for deployment. + * + * Usage: npm run build:iwa + */ + +import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs'; +import { join, dirname } from 'path'; +import { fileURLToPath } from 'url'; + +const __dirname = join( + dirname(fileURLToPath(import.meta.url)), + '.' +); + +// Read existing manifest for reference +const distManifestPath = join(__dirname, 'dist', 'manifest.json'); +try { + const distManifest = JSON.parse(readFileSync(distManifestPath, 'utf-8')); + + // Generate IWA manifest with Chrome-specific fields + const iwaManifest = { + name: distManifest.name, + short_name: distManifest.short_name, + description: distManifest.description, + version: distManifest.version || '1.0.0', + start_url: '../index.html', + display: distManifest.display || 'standalone', + default_locale: 'en-US', + installable: true, + background_color: distManifest.background_color, + theme_color: distManifest.theme_color, + icons: distManifest.icons.map(icon => ({ + src: icon.src, + sizes: icon.sizes, + type: icon.type, + purpose: 'any maskable' + })) + }; + + // Write IWA manifest + const iwaDir = join(__dirname, 'public', 'iwa'); + if (!existsSync(iwaDir)) { + mkdirSync(iwaDir, { recursive: true }); + } + + writeFileSync(join(iwaDir, 'manifest.json'), JSON.stringify(iwaManifest, null, 2)); + + console.log('✅ IWA manifest generated at:', join(iwaDir, 'manifest.json')); + console.log(''); + console.log('📦 Deployment instructions:'); + console.log(' 1. Copy /public/iwa to your package directory (e.g., /usr/local/share/applications/iwa/)'); + console.log(' 2. The manifest references index.html which loads from the main dist/index.html'); + console.log(' 3. Chrome will detect this and offer installation via the Chrome Store'); + +} catch (error) { + console.error('❌ Build failed:', error.message); + process.exit(1); +} diff --git a/package.json b/package.json index 0ba344b..333dde5 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dev": "vite", "build": "vite build", "build:single": "SINGLEFILE=1 vite build", + "build:iwa": "npm run build && node iwa-build.js", "preview": "vite preview" }, "dependencies": { diff --git a/public/iwa.html b/public/iwa.html new file mode 100644 index 0000000..d36fef2 --- /dev/null +++ b/public/iwa.html @@ -0,0 +1,30 @@ + + + + + + + + AboveTheMark - GFM Editor + + + + + + + + + + + + + + + + +
+ + + + + diff --git a/public/iwa/index.html b/public/iwa/index.html new file mode 100644 index 0000000..4fe1b57 --- /dev/null +++ b/public/iwa/index.html @@ -0,0 +1,15 @@ + + + + + + AboveTheMark - GFM Editor + + + + +
+ + + + diff --git a/public/iwa/manifest.json b/public/iwa/manifest.json new file mode 100644 index 0000000..5caf43b --- /dev/null +++ b/public/iwa/manifest.json @@ -0,0 +1,20 @@ +{ + "name": "AboveTheMark GFM Editor", + "short_name": "AboveTheMark", + "description": "GitHub Flavored Markdown editor with LaTeX, SVG, PDF and DOCX support", + "version": "1.0.0", + "start_url": "../index.html", + "display": "standalone", + "default_locale": "en-US", + "installable": true, + "background_color": "#ffffff", + "theme_color": "#0969da", + "icons": [ + { + "src": "favicon.svg", + "sizes": "any", + "type": "image/svg+xml", + "purpose": "any maskable" + } + ] +} \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index 0332a0e..0c87357 100644 --- a/vite.config.js +++ b/vite.config.js @@ -2,8 +2,9 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import { viteSingleFile } from 'vite-plugin-singlefile'; -// Set SINGLEFILE=1 to emit one self-contained index.html (all JS/CSS/fonts inlined). +// Build modes: single-file, iwa (Installer for Web Applications), or default/pwa const singleFile = process.env.SINGLEFILE === '1'; +const iwaBuild = process.env.IWA === '1'; export default defineConfig({ plugins: [react(), ...(singleFile ? [viteSingleFile()] : [])], @@ -18,7 +19,7 @@ export default defineConfig({ minify: 'terser', // Inline every asset (including KaTeX fonts) as data URIs for the single file. assetsInlineLimit: singleFile ? 100_000_000 : 4096, - cssCodeSplit: !singleFile, + cssCodeSplit: !(singleFile || iwaBuild), chunkSizeWarningLimit: singleFile ? 6000 : 500 }, optimizeDeps: {