aboutsummaryrefslogtreecommitdiffstats
path: root/build.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-01 16:34:55 -0700
committerAdam Soltys <[email protected]>2026-10-01 16:34:55 -0700
commit66d41d1aa1f5c60cd63b1691ba6bf70e88cf78fa (patch)
treeb26348dfe27873e9bd610b67a5880de00cf3db72 /build.js
parenta7806172f7ede9be345750c93e5fa72e10e9b953 (diff)
downloadcoinosv3-66d41d1aa1f5c60cd63b1691ba6bf70e88cf78fa.tar.gz
coinosv3-66d41d1aa1f5c60cd63b1691ba6bf70e88cf78fa.zip
The standalone wallet opened from a disk shows its avatars, font and languages.
With no files beside it, relative punks/, locales/, nip46.js and jsqr.js looked on the disk. From file:// they now come from v3.coinos.io (images and scripts need no CORS; /locales/ now sends Access-Control-Allow-Origin on the server), and standalone.html carries Public Sans inline. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VP5Ljqk7EYcm5QQAbzDwog
Diffstat (limited to 'build.js')
-rw-r--r--build.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/build.js b/build.js
index 848ce92..1fdd889 100644
--- a/build.js
+++ b/build.js
@@ -397,12 +397,18 @@ ${pwa && !NO_SW ? SW_REGISTER + '\n' : ''}</body>
}
// Self-contained single file (dev server, test tools, save-and-open-offline).
-export async function buildHtml({ minify = true, pwa = minify, features = process.env.HAL_FEATURES, staging = isStaging() } = {}) {
+export async function buildHtml({ minify = true, pwa = minify, features = process.env.HAL_FEATURES, staging = isStaging(), inlineFonts = false } = {}) {
const outputs = await bundleApp({ minify, features, staging });
let js = await outputs[0].text();
// Guard against a literal </script> inside the bundle closing our tag early.
js = js.replaceAll('</script', '<\\/script');
- const css = await Bun.file('./src/style.css').text();
+ let css = await Bun.file('./src/style.css').text();
+ // the standalone file has no fonts beside it on a disk, and the site's
+ // copies are same-origin only — so it carries its own
+ if (inlineFonts) for (const f of ['PublicSans.woff2', 'PublicSans-Italic.woff2']) {
+ const b64 = Buffer.from(await Bun.file('static/' + f).arrayBuffer()).toString('base64');
+ css = css.replaceAll(`url("/${f}")`, `url(data:font/woff2;base64,${b64})`);
+ }
const html = await pageHtml({ css, staging, pwa, scriptHtml: `<script>${js}</script>` });
return html.replaceAll('{{COMMIT}}', gitCommit());
}
@@ -453,7 +459,7 @@ if (import.meta.main) {
// included), no PWA plumbing — meant to be downloaded from /standalone.html
// and opened straight from a disk. Network features still reach out when
// online; the wallet itself needs no server.
- await Bun.write('dist/standalone.html', await buildHtml({ minify: true, pwa: false }));
+ await Bun.write('dist/standalone.html', await buildHtml({ minify: true, pwa: false, inlineFonts: true }));
// Lazy-loaded QR decoder — kept out of index.html, fetched only when a
// browser without BarcodeDetector opens the scanner.