From b94458f5618a7077479961de6ac476dbf54b5020 Mon Sep 17 00:00:00 2001 From: Dannii Willis Date: Sat, 14 Oct 2023 14:36:34 +1000 Subject: [PATCH] Temporarily use the built-from-TS make-single-file.js from the testing branch --- tools/make-single-file.js | 171 +++----------------------------------- 1 file changed, 10 insertions(+), 161 deletions(-) diff --git a/tools/make-single-file.js b/tools/make-single-file.js index 5a300d32..c303e66b 100755 --- a/tools/make-single-file.js +++ b/tools/make-single-file.js @@ -1,162 +1,11 @@ #!/usr/bin/env node -/* - -Parchment single-file converter -=============================== - -Copyright (c) 2023 Dannii Willis -MIT licenced -https://github.com/curiousdannii/parchment - -*/ - -import child_process from 'child_process' -import fs from 'fs/promises' -import path from 'path' -import {fileURLToPath} from 'url' -import util from 'util' - -import {generate} from '../src/tools/single-file.js' -import Blorb from '../src/upstream/asyncglk/dist/blorb/blorb.js' - -const execFile = util.promisify(child_process.execFile) - -const rootpath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..') -const webpath = path.join(rootpath, 'dist/web') - -// Presets and options -const base_options = { - date: 1, - font: 1, - single_file: 1, - terps: [], -} -const presets = { - dist: { - terps: ['hugo', 'quixe', 'scare', 'tads', 'zvm'], - }, - frankendrift: { - single_file: 0, - terps: [], - }, - regtest: { - font: 0, - terps: ['quixe', 'zvm'], - }, -} - -const {values: {preset, out: outdir, story_file: story_file_path}} = util.parseArgs({options: { - "preset": {type: "string", default: "dist"}, - "story_file": { type: "string" }, - "out": { type: "string", default: path.join(webpath, '../single-file') }, -}}) - -if (!presets[preset]) { - throw new Error(`Unknown preset: ${preset}`) -} -const options = Object.assign({}, base_options, presets[preset]) - -if (story_file_path) { - try { - options.story_file = await fs.readFile(story_file_path) - } catch (cause) { - throw new Error(`Couldn't read story_file_path ${story_file_path}`, {cause}) - } - // this is a stripped-down version of src/common/formats.js, so we don't have to import the world - const formats = { - blorb: { - extensions: /\.(blb|blorb)/i, - }, - adrift4: { - extensions: /\.taf/i, - engine: 'scare', - }, - hugo: { - extensions: /\.hex/i, - engine: 'hugo', - }, - glulx: { - extensions: /\.(gblorb|glb|ulx)/i, - engine: 'quixe', - }, - tads: { - extensions: /\.(gam|t3)/i, - engine: 'tads', - }, - zcode: { - extensions: /\.(zblorb|zlb|z3|z4|z5|z8)/i, - engine: 'zvm', - } - } - - let format = Object.keys(formats).find(format => formats[format].extensions.test(story_file_path)) - if (!format) { - throw new Error(`Unknown storyfile format ${story_file_path}`) - } - if (format === 'blorb') { - // fake jQuery, just enough to get the Blorb constructor to run - globalThis.$ = () => ({ - html: () => ({ - find: () => ({ - children: () => [] - }) - }) - }) - const blorb = new Blorb(options.story_file) - const blorb_chunks = { - GLUL: 'glulx', - ZCOD: 'zcode', - } - const chunktype = blorb.get_chunk('exec', 0)?.blorbtype - format = blorb_chunks[chunktype] - if (!format) throw new Error('Unknown storyfile format in Blorb') - } - options.terps = [formats[format].engine] - options.format = format -} - -// Load files -const common = [ - 'ie.js', - 'jquery.min.js', - 'main.js', - 'waiting.gif', - 'web.css', - '../fonts/iosevka/iosevka-extended.woff2', - '../../index.html', -] -const terps = { - bocfel: ['bocfel-core.wasm', 'boxfel.js'], - git: ['git-core.wasm', 'git.js'], - glulxe: ['glulxe-core.wasm', 'glulxe.js'], - hugo: ['hugo-core.wasm', 'hugo.js'], - quixe: ['quixe.js'], - scare: ['scare-core.wasm', 'scare.js'], - tads: ['tads-core.wasm', 'tads.js'], - zvm: ['zvm.js'], -} - -// Get all the files -const files = {} -for (const file of common.concat(options.terps.map(terp => terps[terp]).flat())) { - files[path.basename(file)] = await fs.readFile(path.join(webpath, file)) -} - -const indexhtml = await generate(options, files) - -await fs.mkdir(outdir, {recursive: true}) -const outpath = path.join(outdir, 'parchment.html') - -// Write it out -console.log('Creating', outpath) -await fs.writeFile(outpath, indexhtml) - -// Zip it -let zipname = `parchment-single-file.zip` -if (options.date) { - const today = new Date() - zipname = `parchment-single-file-${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}.zip` -} -console.log(`Zipping ${outdir}/${zipname}`) -const result = await execFile('zip', ['-j', '-r', path.join(outdir, zipname), outpath]) -console.log(result.stdout.trim()) +var e,t,r=Object.create,n=Object.defineProperty,i=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,l=((e,t,l)=>(l=null!=e?r(s(e)):{},((e,t,r,s)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let l of o(t))a.call(e,l)||l===r||n(e,l,{get:()=>t[l],enumerable:!(s=i(t,l))||s.enumerable});return e})(!t&&e&&e.__esModule?l:n(l,"default",{value:e,enumerable:!0}),e)))((e={"node_modules/minimist/index.js"(e,t){function r(e){return"number"==typeof e||!!/^0x[0-9a-f]+$/i.test(e)||/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e)}function n(e,t){return"constructor"===t&&"function"==typeof e[t]||"__proto__"===t}t.exports=function(e,t){t||(t={});var i={bools:{},strings:{},unknownFn:null};"function"==typeof t.unknown&&(i.unknownFn=t.unknown),"boolean"==typeof t.boolean&&t.boolean?i.allBools=!0:[].concat(t.boolean).filter(Boolean).forEach((function(e){i.bools[e]=!0}));var o={};function s(e){return o[e].some((function(e){return i.bools[e]}))}Object.keys(t.alias||{}).forEach((function(e){o[e]=[].concat(t.alias[e]),o[e].forEach((function(t){o[t]=[e].concat(o[e].filter((function(e){return t!==e})))}))})),[].concat(t.string).filter(Boolean).forEach((function(e){i.strings[e]=!0,o[e]&&[].concat(o[e]).forEach((function(e){i.strings[e]=!0}))}));var a=t.default||{},l={_:[]};function f(e,t,r){for(var o=e,s=0;so[e]=1)),e.start();break;case"external":{let e=null;f&&(e=f(t.value)),e||"timer"!=t.value||(K=Date.now(),e={type:w.evtype_Timer}),e&&e.type&&m(e);break}case"timer":K=Date.now();m({type:w.evtype_Timer});break;case"hyperlink":!function(t,r){if(!Y)return;var i=null;for(i=L;i&&i.disprock!=t;i=i.next);if(!i||!i.hyperlink_request)return;Y.set_field(0,w.evtype_Hyperlink),Y.set_field(1,i),Y.set_field(2,r),Y.set_field(3,0),i.hyperlink_request=!1,n&&n.prepare_resume(Y);Y=null,e.resume()}(t.window,t.value);break;case"mouse":!function(t,r,i){if(!Y)return;var o=null;for(o=L;o&&o.disprock!=t;o=o.next);if(!o||!o.mouse_request)return;Y.set_field(0,w.evtype_MouseInput),Y.set_field(1,o),Y.set_field(2,r),Y.set_field(3,i),o.mouse_request=!1,n&&n.prepare_resume(Y);Y=null,e.resume()}(t.window,t.x,t.y);break;case"char":!function(t,r){var i;if(!Y)return;var o=null;for(o=L;o&&o.disprock!=t;o=o.next);if(!o||!o.char_request)return;1==r.length?(i=r.charCodeAt(0),o.char_request_uni||(i&=255)):(i=v[r])||(i=w.keycode_Unknown);Y.set_field(0,w.evtype_CharInput),Y.set_field(1,o),Y.set_field(2,i),Y.set_field(3,0),o.char_request=!1,o.char_request_uni=!1,o.input_generation=null,n&&n.prepare_resume(Y);Y=null,e.resume()}(t.window,t.value);break;case"line":!function(t,r,i){var o;if(!Y)return;var s=null;for(s=L;s&&s.disprock!=t;s=s.next);if(!s||!s.line_request)return;r.length>s.linebuf.length&&(r=r.slice(0,s.linebuf.length));s.request_echo_line_input&&(o=s.style,we(s.str,w.style_Input),re(s,r),s.echostr&&me(s.echostr,r),we(s.str,o),re(s,"\n"),s.echostr&&me(s.echostr,"\n"));for(o=0;o=256);t++);if(t==n)return e;for(r=Array(n),t=0;t=256?r[t]=63:r[t]=e[t];return r}function I(e){var t,r,n=e.length;if(0==n)return"";for(t=0;t=256);t++);if(t==n)return String.fromCharCode.apply(this,e);for(r=Array(n),t=0;t=65536);t++);if(t==i)return String.fromCharCode.apply(this,e);for(n=Array(i),t=0;t>10),56320+(1023&r)));return n.join("")}function T(e){var t=0;for(let r=0;r>6),r.push(128|63&n)):n<65536?(r.push(224|(61440&n)>>12),r.push(128|(4032&n)>>6),r.push(128|63&n)):n<2097152?(r.push(240|(1835008&n)>>18),r.push(128|(258048&n)>>12),r.push(128|(4032&n)>>6),r.push(128|63&n)):r.push(63)}return r}function z(e){for(var t=new Array(4*e.length),r=0;r>24&255,t[4*r+1]=n>>16&255,t[4*r+2]=n>>8&255,t[4*r+3]=255&n}return t}var B={dummy:"Glk call has not yet returned"};var M=1,q=2,R=3,D=4,P=null,L=null,N=null,G=!0,W=null,H=null,V=null,J=null,Y=null,Z=1,X=null,K=null,Q=null;function ee(e,t){var r={};return r.type=e,r.rock=t,r.disprock=void 0,r.parent=null,r.str=function(e){var t;return(t=le(q,!1,!0,0)).unicode=!0,t.win=e,t}(r),r.echostr=null,r.style=w.style_Normal,r.hyperlink=0,r.input_generation=null,r.linebuf=null,r.char_request=!1,r.line_request=!1,r.char_request_uni=!1,r.line_request_uni=!1,r.hyperlink_request=!1,r.mouse_request=!1,r.echo_line_input=!0,r.line_input_terminators=[],r.request_echo_line_input=null,r.prev=null,r.next=L,L=r,r.next&&(r.next.prev=r),n?n.class_register("window",r):r.disprock=Z++,G=!0,r}function te(e){var t,r;n&&n.class_unregister("window",e),G=!0,e.echostr=null,e.str&&(fe(e.str),e.str=null),t=e.prev,r=e.next,e.prev=null,e.next=null,t?t.next=r:L=r,r&&(r.prev=t),e.parent=null,e.rock=null,e.disprock=null}function re(e,t){var r,n;switch(e.type){case w.wintype_TextBuffer:e.style==e.accumstyle&&e.hyperlink==e.accumhyperlink&&e.fg==e.accum_fg&&e.bg==e.accum_bg&&e.reverse==e.accum_reverse||ie(e),e.accum.push(t);break;case w.wintype_TextGrid:for(r=0;r=e.gridwidth&&(e.cursorx=0,e.cursory++),e.cursory<0)e.cursory=0;else if(e.cursory>=e.gridheight)break;if("\n"!=n){var i=e.lines[e.cursory];i.dirty=!0,i.chars[e.cursorx]=n,i.styles[e.cursorx]=e.style,i.hyperlinks[e.cursorx]=e.hyperlink,i.fgs[e.cursorx]=e.fg,i.bgs[e.cursorx]=e.bg,i.reverses[e.cursorx]=e.reverse,e.cursorx++}else e.cursory++,e.cursorx=0}}}function ne(e){if(e.cursorx<0?e.cursorx=0:e.cursorx>=e.gridwidth&&(e.cursorx=0,e.cursory++),e.cursory<0)e.cursory=0;else if(e.cursory>=e.gridheight)return!0;return!1}function ie(e){var t,r,n,i,o=e.content,s=x[e.accumstyle];if(e.accum.length)for(t=e.accum.join("").split("\n"),r=0;re.gridheight)e.lines.length=e.gridheight;else if(oe.gridwidth)h.dirty=!0,h.chars.length=e.gridwidth,h.styles.length=e.gridwidth,h.hyperlinks.length=e.gridwidth,h.fgs.length=e.gridwidth,h.bgs.length=e.gridwidth,h.reverses.length=e.gridwidth;else if(i=a?s:Math.min(Math.max(f,s),a-u),e.pair_splitpos=f,e.pair_splitwidth=u,g=e.pair_vertical?{left:(d={left:e.bbox.left,right:e.pair_splitpos,top:e.bbox.top,bottom:e.bbox.bottom}).right+e.pair_splitwidth,right:e.bbox.right,top:e.bbox.top,bottom:e.bbox.bottom}:{top:(d={top:e.bbox.top,bottom:e.pair_splitpos,left:e.bbox.left,right:e.bbox.right}).bottom+e.pair_splitwidth,bottom:e.bbox.bottom,left:e.bbox.left,right:e.bbox.right},e.pair_backward?(b=e.child2,_=e.child1):(b=e.child1,_=e.child2),ae(b,d),ae(_,g)}}function le(e,t,r,i){var o={};return o.type=e,o.rock=i,o.disprock=void 0,o.unicode=!1,o.isbinary=!1,o.streaming=!1,o.ref=null,o.win=null,o.file=null,o.buf=null,o.bufpos=0,o.buflen=0,o.bufeof=0,o.timer_id=null,o.flush_func=null,o.fstream=null,o.readcount=0,o.writecount=0,o.readable=t,o.writable=r,o.prev=null,o.next=H,H=o,o.next&&(o.next.prev=o),n&&n.class_register("stream",o),o}function fe(e){var t,r;e===J&&(J=null),function(e){var t;for(t=L;t;t=t.next)t.echostr===e&&(t.echostr=null)}(e),e.type==R?n&&n.unretain_array(e.buf):e.type==M&&e.fstream&&(e.fstream.fclose(),e.fstream=null),n&&n.class_unregister("stream",e),t=e.prev,r=e.next,e.prev=null,e.next=null,t?t.next=r:H=r,r&&(r.prev=t),e.fstream=null,e.buf=null,e.readable=!1,e.writable=!1,e.ref=null,e.win=null,e.file=null,e.rock=null,e.disprock=null}function ue(e){e.streaming&&i.log("### gli_stream_dirty_file called for streaming file!"),null===e.timer_id&&(null===e.flush_func&&(e.flush_func=function(){ce(e)}),e.timer_id=setTimeout(e.flush_func,1e4))}function ce(e){e.streaming&&i.log("### gli_stream_flush_file called for streaming file!"),null!==e.timer_id&&clearTimeout(e.timer_id),e.timer_id=null,r.file_write(e.ref,e.buf)}function pe(t,i,o,s){var a={};if(a.filename=t,a.rock=o,a.disprock=void 0,a.textmode=0!=(i&w.fileusage_TextMode),a.filetype=i&w.fileusage_TypeMask,a.filetypename=C[a.filetype],a.filetypename||(a.filetypename="xxx"),!s){var l="";a.filetype==w.fileusage_SavedGame&&(l=e.get_signature()),s=r.file_construct_ref(a.filename,a.filetypename,l)}return a.ref=s,a.prev=null,a.next=V,V=a,a.next&&(a.next.prev=a),n&&n.class_register("fileref",a),a}function he(e,t){if(!e||!e.writable)throw"gli_put_char: invalid stream";switch(e.unicode||(t<0||t>=256)&&(t=63),e.writecount+=1,e.type){case M:var r;if(e.streaming)if(e.unicode)if(e.isbinary)e.buffer4.writeUInt32BE(t,0,!0),e.fstream.fwrite(e.buffer4,4);else if(t<65536)r=e.buffer4.write(String.fromCharCode(t)),e.fstream.fwrite(e.buffer4,r);else{var n=T([t]),i=e.fstream.BufferClass.from(n);e.fstream.fwrite(i)}else e.buffer4[0]=t,e.fstream.fwrite(e.buffer4,1);else if(ue(e),!e.unicode||t<128&&!e.isbinary)e.bufpose.bufeof&&(e.bufeof=e.bufpos));else{let r;r=e.isbinary?z([t]):T([t]);let n=r.length;n>e.buflen-e.bufpos&&(n=e.buflen-e.bufpos);for(let t=0;te.bufeof&&(e.bufeof=e.bufpos)}break;case R:e.bufpose.bufeof&&(e.bufeof=e.bufpos));break;case q:if(e.win.line_request)throw"gli_put_char: window has pending line request";re(e.win,(o=t)<65536?String.fromCharCode(o):(o-=65536,String.fromCharCode(55296+(o>>10),56320+(1023&o)))),e.win.echostr&&he(e.win.echostr,t)}var o}function de(e,t,r){var n,i;if(!e||!e.writable)throw"gli_put_array: invalid stream";switch(e.unicode||r||(t=O(t),r=!0),e.writecount+=t.length,e.type){case M:if(e.streaming)if(e.unicode)if(e.isbinary){const r=e.fstream.BufferClass.alloc(4*t.length);for(let e=0;ee.buflen-e.bufpos&&(r=e.buflen-e.bufpos);for(let t=0;te.bufeof&&(e.bufeof=e.bufpos)}break;case R:(n=t.length)>e.buflen-e.bufpos&&(n=e.buflen-e.bufpos);for(let r=0;re.bufeof&&(e.bufeof=e.bufpos);break;case q:if(e.win.line_request)throw"gli_put_array: window has pending line request";i=r?String.fromCharCode.apply(this,t):E(t),re(e.win,i),e.win.echostr&&de(e.win.echostr,t,r)}}function ge(e,t){var r;if(!e||!e.readable)return-1;switch(e.type){case M:if(e.streaming){if(e.unicode){if(e.isbinary){if(e.fstream.fread(e.buffer4,4)<4)return-1;r=e.buffer4[0]<<24,r|=e.buffer4[1]<<16,r|=e.buffer4[2]<<8,r|=e.buffer4[3]}else{let t,n,i,o;if(!e.fstream.fread(e.buffer4,1))return-1;if(t=e.buffer4[0],t<128)r=t;else{if(!e.fstream.fread(e.buffer4,1))return-1;if(n=e.buffer4[0],128!=(192&n))return-1;if(192==(224&t))r=(31&t)<<6,r|=63&n;else{if(!e.fstream.fread(e.buffer4,1))return-1;if(i=e.buffer4[0],128!=(192&i))return-1;if(224==(240&t))r=(15&t)<<12&61440,r|=(63&n)<<6&4032,r|=63&i;else{if(240!=(240&t))return-1;if(!e.fstream.fread(e.buffer4,1))return-1;if(o=e.buffer4[0],128!=(192&o))return-1;r=(7&t)<<18&1835008,r|=(63&n)<<12&258048,r|=(63&i)<<6&4032,r|=63&o}}}}return e.readcount++,r>>>=0,!t&&r>=256?63:r}return e.fstream.fread(e.buffer4,1)?(e.readcount++,e.buffer4[0]):-1}case D:if(e.unicode){if(e.isbinary){if(e.bufpos>=e.bufeof)return-1;if(r=e.buf[e.bufpos],e.bufpos++,e.bufpos>=e.bufeof)return-1;if(r=r<<8|255&e.buf[e.bufpos],e.bufpos++,e.bufpos>=e.bufeof)return-1;if(r=r<<8|255&e.buf[e.bufpos],e.bufpos++,e.bufpos>=e.bufeof)return-1;r=r<<8|255&e.buf[e.bufpos],e.bufpos++}else{let t,n,i,o;if(e.bufpos>=e.bufeof)return-1;if(t=e.buf[e.bufpos],e.bufpos++,t<128)r=t;else{if(e.bufpos>=e.bufeof)return-1;if(n=e.buf[e.bufpos],e.bufpos++,128!=(192&n))return-1;if(192==(224&t))r=(31&t)<<6,r|=63&n;else{if(e.bufpos>=e.bufeof)return-1;if(i=e.buf[e.bufpos],e.bufpos++,128!=(192&i))return-1;if(224==(240&t))r=(15&t)<<12&61440,r|=(63&n)<<6&4032,r|=63&i;else{if(240!=(240&t))return-1;if(e.bufpos>=e.bufeof)return-1;if(o=e.buf[e.bufpos],e.bufpos++,128!=(192&o))return-1;r=(7&t)<<18&1835008,r|=(63&n)<<12&258048,r|=(63&i)<<6&4032,r|=63&o}}}}return e.readcount++,r>>>=0,!t&&r>=256?63:r}case R:return e.bufpos=256?63:r):-1;default:return-1}}function be(e,t,r){if(!e||!e.readable)return 0;var n,i,o,s=t.length;switch(e.type){case M:if(e.streaming){if(0==s)return 0;for(s-=1,o=!1,n=0;n=e.bufeof?s=0:e.bufpos+s>e.bufeof&&(s=e.bufeof-e.bufpos),o=!1,r)for(n=0;n=256&&(i=63),t[n]=i,o=10==i;return e.readcount+=n,n;default:return 0}}function _e(e,t,r){if(!e||!e.readable)return 0;var n,i,o=t.length;switch(e.type){case M:if(e.streaming){for(n=0;n=e.bufeof?o=0:e.bufpos+o>e.bufeof&&(o=e.bufeof-e.bufpos),r)for(n=0;n=256&&(i=63),t[n]=i;return e.readcount+=o,o;default:return 0}}function ye(e,t){t&&(t.set_field(0,e.readcount),t.set_field(1,e.writecount))}function me(e,t,r){var n;if(!e||!e.writable)throw"glk_put_jstring: invalid stream";switch(e.writecount+=t.length,e.type){case M:if(e.streaming)if(e.unicode)if(e.isbinary){const r=e.fstream.BufferClass.alloc(4*t.length);for(let e=0;ee.buflen-e.bufpos&&(i=e.buflen-e.bufpos);for(let t=0;te.bufeof&&(e.bufeof=e.bufpos)}break;case R:if((n=t.length)>e.buflen-e.bufpos&&(n=e.buflen-e.bufpos),e.unicode||r)for(let r=0;r=256)&&(i=63),e.buf[e.bufpos+r]=i}e.bufpos+=n,e.bufpos>e.bufeof&&(e.bufeof=e.bufpos);break;case q:if(e.win.line_request)throw"glk_put_jstring: window has pending line request";re(e.win,t),e.win.echostr&&me(e.win.echostr,t,r)}}function we(e,t){if(!e||!e.writable)throw"gli_set_style: invalid stream";t>=w.style_NUMSTYLES&&(t=0),e.type==q&&(e.win.style=t,e.win.echostr&&we(e.win.echostr,t))}function ve(e,t){if(!e||!e.writable)throw"gli_set_hyperlink: invalid stream";e.type==q&&(e.win.hyperlink=t,e.win.echostr&&ve(e.win.echostr,t))}function ke(e,t,r){switch(e){case 0:return 1796;case 1:return t<=w.keycode_Left&&t>=w.keycode_End?1:t>=4294967296-w.keycode_MAXVAL||t>1114111||t>=0&&t<32||t>=127&&t<160?0:1;case 2:return t>1114111||(t>=0&&t<32||t>=127&&t<160)?0:1;case 3:return t>1114111||t>=0&&t<32||t>=127&&t<160?(r&&(r[0]=1),0):(r&&(r[0]=1),2);case 4:return t==w.wintype_TextGrid||o.graphics&&t==w.wintype_Graphics?1:0;case 5:return o.timer||0;case 6:case 14:return o.graphics||0;case 7:return!o.graphics||t!==w.wintype_TextBuffer&&t!==w.wintype_Graphics?0:1;case 8:case 9:case 10:case 13:case 21:case 23:return 0;case 11:return o.hyperlinks||0;case 12:return!o.hyperlinks||t!==w.wintype_TextBuffer&&t!==w.wintype_TextGrid?0:1;case 15:case 16:case 17:case 18:case 20:case 22:return 1;case 19:return t==w.keycode_Escape||t>=w.keycode_Func12&&t<=w.keycode_Func1?1:0;case 4352:return o.garglktext||0}if(u){var n=u(e,t,r);if(void 0!==n)return n}return 0}var xe=null,Ce={buffer:{},grid:{}};function je(e){const t={};for(const[r,n]of Object.entries(e))t[r]=Object.assign({},n);return t}const Fe=["normal","emphasized","preformatted","header","subheader","alert","note","blockquote","input","user1","user2"],Ue=["margin-left","text-indent","text-align","font-size","font-weight","font-style","monospace","color","background-color","reverse"];function Se(e){if(Array.isArray(e)){const t={};for(const[r,n]of e.entries())for(const[e,i]of Object.entries(n)){const n=`${["margin-left","text-indent","text-align"].includes(e)?"div":"span"}.Style_${Fe[r]}`;t[n]||(t[n]={}),t[n][e]=i}return t}return e}function $e(e,t,r,n){const i=`${r<=w.stylehint_Justification?"div":"span"}.Style_${Fe[t]}`;var o;r===w.stylehint_Indentation&&(o=n+"em"),r===w.stylehint_ParaIndentation&&(o=n+"em"),r===w.stylehint_Justification&&(o=["left","justify","center","right"][n]),r===w.stylehint_Size&&(o=1+.1*n+"em"),r===w.stylehint_Weight&&(o=["lighter","normal","bold"][n+1]),r===w.stylehint_Oblique&&(o=n?"italic":"normal"),r===w.stylehint_Proportional&&(o=n?0:1),r===w.stylehint_TextColor&&(o="#"+("000000"+n.toString(16)).slice(-6)),r===w.stylehint_BackColor&&(o="#"+("000000"+n.toString(16)).slice(-6)),r===w.stylehint_ReverseColor&&(o=n),e[i]||(e[i]={}),e[i][Ue[r]]=o}function Ae(e,t,r){if(!e||!e.writable)throw"garglk_set_zcolors: invalid stream";t>>=0,r>>=0,e.type==q&&(-2!==t&&(e.win.fg=-1===t?null:"#"+("000000"+t.toString(16)).slice(-6)),-2!==r&&(e.win.bg=-1===r?null:"#"+("000000"+r.toString(16)).slice(-6)),e.win.echostr&&Ae(e.win.echostr,t,r))}function Oe(e,t){if(!e||!e.writable)throw"garglk_set_reversevideo: invalid stream";e.type==q&&(e.win.reverse=t||null,e.win.echostr&&Oe(e.win.echostr,t))}function Ie(e){e?(X=e,K=Date.now()):(X=null,K=null)}function Ee(e){for(var t=(16777215&e).toString(16);t.length<6;)t="0"+t;return"#"+t.toUpperCase()}function Te(e,t){var r,n,i,o,s,a,l,f,u,c=e.slice(0,t);for(r=0,n=0;n=r)break;for(a=n;n=2)for(i=l-1;i>a;i--)for(f=a;f$[e[f+1]]&&(u=e[f],e[f]=e[f+1],e[f+1]=u)}else n++;return r}}();var d="object"==typeof global&&global&&global.Object===Object&&global,g="object"==typeof self&&self&&self.Object===Object&&self,b=(d||g||Function("return this")()).Symbol,_=Object.prototype,y=_.hasOwnProperty,m=_.toString,w=b?b.toStringTag:void 0;var v=function(e){var t=y.call(e,w),r=e[w];try{e[w]=void 0;var n=!0}catch(e){}var i=m.call(e);return n&&(t?e[w]=r:delete e[w]),i},k=Object.prototype.toString;var x=function(e){return k.call(e)},C=b?b.toStringTag:void 0;var j=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":C&&C in Object(e)?v(e):x(e)};var F=function(e){return null!=e&&"object"==typeof e};var U=function(e){return"symbol"==typeof e||F(e)&&"[object Symbol]"==j(e)};var S=function(e,t){for(var r=-1,n=null==e?0:e.length,i=Array(n);++r",""":'"',"'":"'"}),z=/&(?:amp|lt|gt|quot|#39);/g,B=RegExp(z.source);var M=function(e){return(e=E(e))&&B.test(e)?e.replace(z,T):e},q=class extends DataView{constructor(e,t,r){e instanceof Uint8Array?super(e.buffer,e.byteOffset,e.byteLength):super(e,t,r)}getFourCC(e){return String.fromCharCode(this.getUint8(e),this.getUint8(e+1),this.getUint8(e+2),this.getUint8(e+3))}getUint8Subarray(e,t){return new Uint8Array(this.buffer,this.byteOffset+(e||0),t)}setFourCC(e,t){this.setUint8(e,t.charCodeAt(0)),this.setUint8(e+1,t.charCodeAt(1)),this.setUint8(e+2,t.charCodeAt(2)),this.setUint8(e+3,t.charCodeAt(3))}setUint8Array(e,t){this.getUint8Subarray(e,t.length).set(t)}},R=new TextDecoder,D=(new TextEncoder,class{constructor(){this.type="",this.chunks=[]}parse(e){const t=new q(e);if("FORM"!==t.getFourCC(0))throw new Error("Not an IFF file");this.type=t.getFourCC(8);let r=12;const n=e.length;for(;rn)throw new Error("IFF chunk out of range");this.chunks.push({data:t.getUint8Subarray(r+8,e),offset:r,type:t.getFourCC(r)}),r+=8+e,r%2&&r++}}write(){let e=12;for(const t of this.chunks)e+=8+t.data.length,e%2&&e++;const t=new q(new ArrayBuffer(e));t.setFourCC(0,"FORM"),t.setUint32(4,e-8),t.setFourCC(8,this.type);let r=12;for(const e of this.chunks)t.setFourCC(r,e.type),t.setUint32(r+4,e.data.length),t.setUint8Array(r+8,e.data),r+=8+e.data.length,r%2&&r++;return t.getUint8Subarray()}}),P={Data:"data",Exec:"exec",Pict:"pict","Snd ":"sound"},L="????";var N=new TextDecoder("ascii",{fatal:!0});async function G(e){if("undefined"!=typeof Buffer)return e.toString("base64");if("undefined"!=typeof FileReader){return(await new Promise((t=>{const r=new FileReader;r.onload=()=>t(r.result),r.readAsDataURL(new Blob([e]))}))).split(",",2)[1]}throw new Error("Cannot encode base64")}var W=h.promisify(f.execFile),H=c.join(c.dirname(p(import.meta.url)),".."),V=c.join(H,"dist/web"),J={dist:{terps:["hugo","quixe","scare","tads","zvm"]},frankendrift:{single_file:0,terps:[]},regtest:{font:0,terps:["quixe","zvm"]}},Y={blorb:{extensions:/\.(blb|blorb)/i},adrift4:{extensions:/\.taf/i,engine:"scare"},hugo:{extensions:/\.hex/i,engine:"hugo"},glulx:{extensions:/\.(gblorb|glb|ulx)/i,engine:"quixe"},tads:{extensions:/\.(gam|t3)/i,engine:"tads"},zcode:{extensions:/\.(zblorb|zlb|z3|z4|z5|z8)/i,engine:"zvm"}},Z=(0,l.default)(process.argv.slice(2)),X=Z.out||c.join(V,"../single-file"),K=Z.preset||"dist",Q=Z.story_file;if(!J[K])throw new Error(`Unknown preset: ${K}`);var ee=Object.assign({},{date:1,font:1,single_file:1,terps:[]},J[K]);if(Q){try{ee.story_file={data:await u.readFile(Q),filename:c.basename(Q)}}catch(e){throw new Error(`Couldn't read story_file_path ${Q}`,{cause:e})}let e=Object.keys(Y).find((e=>Y[e].extensions.test(Q)));if(!e)throw new Error(`Unknown storyfile format ${Q}`);if("blorb"===e){e=function(e){const t={GLUL:"glulx",ZCOD:"zcode"},r=e.get_chunk("exec",0)?.blorbtype;if(r&&t[r])return t[r];throw new Error("Unknown storyfile format in Blorb")}(new class{constructor(e){this.classname="Blorb",this.chunks={},this.is_inited=!1,this.metadata={},e&&this.init(e)}init(e,t){if(!this.is_inited){if(e instanceof Uint8Array){const t=new D;if(t.parse(e),"IFRS"!==t.type)throw new Error("Not a Blorb file");if("RIdx"!==t.chunks[0].type)throw new Error("Malformed blorb: chunk 1 is not RIdx");for(const r of t.chunks)switch(r.type){case"Dbug":this.debugdata=r.data;break;case"Fspc":{const e=new q(r.data);this.coverimagenum=e.getUint32(0);break}case"IFmd":{const e=R.decode(r.data),t=/(.+)<\/bibliographic>/is.exec(e),n=/<(\w+)>(.+)<\/\1>/gi,i=//g,o=/\s+/g;if(t){let e;for(;e=n.exec(t[1]);){const t=e[1].toLowerCase();let r=e[2].replace(o," ");"description"===t&&(r=r.replace(i,"\n")),this.metadata[t]=M(r)}}break}case"RDes":{const e=new q(r.data);let t=4;for(;te.offset===s))[0];if(!a)throw new Error(`No Blorb chunk at offset ${s}`);const l=a.type,f={blorbtype:l,content:"FORM"===l?e.subarray(a.offset,a.offset+8+a.data.length):a.data,usage:P[r]};"Pict"===r&&(f.type="JPEG"===l?"jpeg":"PNG "===l?"png":L),"Data"===r&&(f.binary="BINA"===l||"FORM"===l),this.chunks[`${f.usage}:${o}`]=f}break}}}else if("infomap"===t?.format)for(const t in e){if(!Number.isInteger(+t))continue;const r=Object.assign({},e[t]);delete r.image,r.height&&r.width&&(r.imagesize={height:r.height,width:r.width},delete r.height,delete r.width),r.type=r.url.endsWith(".png")?"png":"jpeg",r.usage="pict",this.chunks[`pict:${t}`]=r}else if(!Array.isArray(e)||0!==e.length)throw new Error("Unsupported Blorb.init data format");this.is_inited=!0}}getlibrary(){return null}get_chunk(e,t){return this.chunks[`${e}:${t}`]||null}get_cover_pict(){return this.coverimagenum??null}get_data_chunk(e){const t=this.chunks[`data:${e}`];return t?.content?{binary:t.binary,data:t.content}:null}get_debug_info(){return this.debugdata}get_exec_data(e){const t=this.chunks["exec:0"];return!t?.content||e&&t.blorbtype!==e?null:t.content}get_image_info(e){const t=this.chunks[`pict:${e}`];if(!t)return null;!t.imagesize&&t.content&&("jpeg"===t.type?t.imagesize=function(e){const t=new q(e);let r=0;for(;r=208&&e<=217)continue;const n=t.getUint16(r);if(e>=192&&e<=207&&200!==e){if(n<7)return;return{height:t.getUint16(r+3),width:t.getUint16(r+5)}}r+=n}}(t.content):"png"===t.type&&(t.imagesize=function(e){const t=new q(e);if("‰PNG"!==t.getFourCC(0))return;let r=8;for(;rte[e])).flat()))re.set(c.basename(e),await u.readFile(c.join(V,e)));var ne=await async function(e,t){const r=[];let n="";for(const[i,o]of t){if(i.endsWith(".wasm")){r.push(`