GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tilewright/build.js at main · Ax1zz/tilewright

Expand file tree

/

build.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
89 lines (76 loc) · 3.56 KB
/

build.js

Copy path

File metadata and controls

89 lines (76 loc) · 3.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
/**
* Bundle the app into ONE self-contained HTML file.
*
* Why bother: the whole promise of this tool is that an unreleased pattern
* never leaves the designer's machine. A single file they can download, keep,
* and open years from now — with no server, no npm, no CDN, no build step —
* is the strongest possible version of that promise.
*
* The pdf.js worker is base64-inlined and revived as a Blob URL at runtime, so
* even the preview works with the network unplugged.
*
* node build.js -> dist/tilewright.html
*/
'use strict';
var fs = require('fs');
var path = require('path');
var ROOT = __dirname;
var OUT_DIR = path.join(ROOT, 'dist');
var OUT = path.join(OUT_DIR, 'tilewright.html');
function read(p) { return fs.readFileSync(path.join(ROOT, p), 'utf8'); }
function main() {
var html = read('index.html');
// 1. Inline the pdf.js worker as a Blob URL so the preview works offline.
var workerB64 = fs.readFileSync(path.join(ROOT, 'vendor/pdf.worker.min.js')).toString('base64');
var workerBoot = [
'<script>',
'// pdf.js worker, inlined. Revived as a Blob URL so the preview works with',
'// no network and no sibling files.',
'window.__TW_WORKER_B64__ = "' + workerB64 + '";',
'window.__TW_WORKER_URL__ = (function () {',
' try {',
' var bin = atob(window.__TW_WORKER_B64__);',
' var arr = new Uint8Array(bin.length);',
' for (var i = 0; i < bin.length; i++) arr[i] = bin.charCodeAt(i);',
' return URL.createObjectURL(new Blob([arr], { type: "text/javascript" }));',
' } catch (e) { return null; }',
'})();',
'<' + '/script>',
].join('\n');
// 2. Replace every <script src="..."> with the file's contents.
var order = [];
html = html.replace(/[ \t]*<script src="([^"]+)"><\/script>\s*/g, function (m, src) {
if (/pdf\.worker/.test(src)) return '';
order.push(src);
var code = read(src);
return '<script>\n/* ===== ' + src + ' ===== */\n' + code + '\n<' + '/script>\n';
});
// 3. Point the UI at the inlined worker instead of a sibling path.
html = html.replace(
"window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'vendor/pdf.worker.min.js';",
"window.pdfjsLib.GlobalWorkerOptions.workerSrc = window.__TW_WORKER_URL__ || '';"
);
// 4. Drop the worker boot in ahead of everything else.
html = html.replace('<script>\n/* ===== vendor/pdf-lib.min.js', workerBoot + '\n<script>\n/* ===== vendor/pdf-lib.min.js');
// 5. Mark the build so support questions are answerable.
var stamp = new Date().toISOString().slice(0, 10);
html = html.replace('</title>', '</title>\n<meta name="tilewright-build" content="single-file ' + stamp + '">');
html = html.replace('<small>layer-preserving PDF pattern tiler</small>',
'<small>layer-preserving PDF pattern tiler &middot; offline build</small>');
if (!fs.existsSync(OUT_DIR)) fs.mkdirSync(OUT_DIR, { recursive: true });
fs.writeFileSync(OUT, html);
var kb = (Buffer.byteLength(html) / 1024).toFixed(0);
console.log(' dist/tilewright.html ' + kb + ' kB');
console.log(' inlined: ' + order.join(', '));
console.log(' worker: ' + (workerB64.length / 1024).toFixed(0) + ' kB base64');
// Sanity: nothing external must remain.
var leftovers = html.match(/<script[^>]+src=/g) || [];
var links = (html.match(/<link[^>]+href="https?:/g) || []);
if (leftovers.length || links.length) {
console.error(' ! external references remain: ' + leftovers.concat(links).join(', '));
process.exit(1);
}
console.log(' no external references — fully self-contained');
}
main();
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.