@xwordly/xword-parser
Version:
Fast, type-safe TypeScript library for parsing crossword puzzles (PUZ, iPUZ, JPZ, XD)
4 lines • 77.1 kB
JavaScript
var Rt=Object.create;var Ie=Object.defineProperty;var Bt=Object.getOwnPropertyDescriptor;var Ut=Object.getOwnPropertyNames;var St=Object.getPrototypeOf,kt=Object.prototype.hasOwnProperty;var Ft=(t,e,n)=>e in t?Ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var Ot=(t,e)=>()=>(t&&(e=t(t=0)),e);var Ee=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Lt=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ut(e))!kt.call(t,i)&&i!==n&&Ie(t,i,{get:()=>e[i],enumerable:!(r=Bt(e,i))||r.enumerable});return t};var Mt=(t,e,n)=>(n=t!=null?Rt(St(t)):{},Lt(e||!t||!t.__esModule?Ie(n,"default",{value:t,enumerable:!0}):n,t));var Y=(t,e,n)=>Ft(t,typeof e!="symbol"?e+"":e,n);var $e=Ee(fe=>{"use strict";p();fe.byteLength=Zt;fe.toByteArray=Xt;fe.fromByteArray=Vt;var k=[],B=[],zt=typeof Uint8Array<"u"?Uint8Array:Array,xe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(V=0,Ge=xe.length;V<Ge;++V)k[V]=xe[V],B[xe.charCodeAt(V)]=V;var V,Ge;B[45]=62;B[95]=63;function Xe(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");n===-1&&(n=e);var r=n===e?0:4-n%4;return[n,r]}function Zt(t){var e=Xe(t),n=e[0],r=e[1];return(n+r)*3/4-r}function Gt(t,e,n){return(e+n)*3/4-n}function Xt(t){var e,n=Xe(t),r=n[0],i=n[1],o=new zt(Gt(t,r,i)),s=0,u=i>0?r-4:r,l;for(l=0;l<u;l+=4)e=B[t.charCodeAt(l)]<<18|B[t.charCodeAt(l+1)]<<12|B[t.charCodeAt(l+2)]<<6|B[t.charCodeAt(l+3)],o[s++]=e>>16&255,o[s++]=e>>8&255,o[s++]=e&255;return i===2&&(e=B[t.charCodeAt(l)]<<2|B[t.charCodeAt(l+1)]>>4,o[s++]=e&255),i===1&&(e=B[t.charCodeAt(l)]<<10|B[t.charCodeAt(l+1)]<<4|B[t.charCodeAt(l+2)]>>2,o[s++]=e>>8&255,o[s++]=e&255),o}function $t(t){return k[t>>18&63]+k[t>>12&63]+k[t>>6&63]+k[t&63]}function Jt(t,e,n){for(var r,i=[],o=e;o<n;o+=3)r=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push($t(r));return i.join("")}function Vt(t){for(var e,n=t.length,r=n%3,i=[],o=16383,s=0,u=n-r;s<u;s+=o)i.push(Jt(t,s,s+o>u?u:s+o));return r===1?(e=t[n-1],i.push(k[e>>2]+k[e<<4&63]+"==")):r===2&&(e=(t[n-2]<<8)+t[n-1],i.push(k[e>>10]+k[e>>4&63]+k[e<<2&63]+"=")),i.join("")}});var Je=Ee(_e=>{"use strict";p();_e.read=function(t,e,n,r,i){var o,s,u=i*8-r-1,l=(1<<u)-1,f=l>>1,c=-7,a=n?i-1:0,h=n?-1:1,g=t[e+a];for(a+=h,o=g&(1<<-c)-1,g>>=-c,c+=u;c>0;o=o*256+t[e+a],a+=h,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=r;c>0;s=s*256+t[e+a],a+=h,c-=8);if(o===0)o=1-f;else{if(o===l)return s?NaN:(g?-1:1)*(1/0);s=s+Math.pow(2,r),o=o-f}return(g?-1:1)*s*Math.pow(2,o-r)};_e.write=function(t,e,n,r,i,o){var s,u,l,f=o*8-i-1,c=(1<<f)-1,a=c>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,g=r?0:o-1,I=r?1:-1,b=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(u=isNaN(e)?1:0,s=c):(s=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-s))<1&&(s--,l*=2),s+a>=1?e+=h/l:e+=h*Math.pow(2,1-a),e*l>=2&&(s++,l/=2),s+a>=c?(u=0,s=c):s+a>=1?(u=(e*l-1)*Math.pow(2,i),s=s+a):(u=e*Math.pow(2,a-1)*Math.pow(2,i),s=0));i>=8;t[n+g]=u&255,g+=I,u/=256,i-=8);for(s=s<<i|u,f+=i;f>0;t[n+g]=s&255,g+=I,s/=256,f-=8);t[n+g-I]|=b*128}});var st=Ee(D=>{"use strict";p();var Ne=$e(),q=Je(),Ve=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;D.Buffer=d;D.SlowBuffer=Kt;D.INSPECT_MAX_BYTES=50;var ce=2147483647;D.kMaxLength=ce;d.TYPED_ARRAY_SUPPORT=vt();!d.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function vt(){try{let t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch{return!1}}Object.defineProperty(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}});Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function L(t){if(t>ce)throw new RangeError('The value "'+t+'" is invalid for option "size"');let e=new Uint8Array(t);return Object.setPrototypeOf(e,d.prototype),e}function d(t,e,n){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Pe(t)}return We(t,e,n)}d.poolSize=8192;function We(t,e,n){if(typeof t=="string")return Ht(t,e);if(ArrayBuffer.isView(t))return Wt(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(F(t,ArrayBuffer)||t&&F(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(F(t,SharedArrayBuffer)||t&&F(t.buffer,SharedArrayBuffer)))return Ce(t,e,n);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let r=t.valueOf&&t.valueOf();if(r!=null&&r!==t)return d.from(r,e,n);let i=Yt(t);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return d.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}d.from=function(t,e,n){return We(t,e,n)};Object.setPrototypeOf(d.prototype,Uint8Array.prototype);Object.setPrototypeOf(d,Uint8Array);function Ye(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function jt(t,e,n){return Ye(t),t<=0?L(t):e!==void 0?typeof n=="string"?L(t).fill(e,n):L(t).fill(e):L(t)}d.alloc=function(t,e,n){return jt(t,e,n)};function Pe(t){return Ye(t),L(t<0?0:Re(t)|0)}d.allocUnsafe=function(t){return Pe(t)};d.allocUnsafeSlow=function(t){return Pe(t)};function Ht(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!d.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let n=Ke(t,e)|0,r=L(n),i=r.write(t,e);return i!==n&&(r=r.slice(0,i)),r}function Ae(t){let e=t.length<0?0:Re(t.length)|0,n=L(e);for(let r=0;r<e;r+=1)n[r]=t[r]&255;return n}function Wt(t){if(F(t,Uint8Array)){let e=new Uint8Array(t);return Ce(e.buffer,e.byteOffset,e.byteLength)}return Ae(t)}function Ce(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return e===void 0&&n===void 0?r=new Uint8Array(t):n===void 0?r=new Uint8Array(t,e):r=new Uint8Array(t,e,n),Object.setPrototypeOf(r,d.prototype),r}function Yt(t){if(d.isBuffer(t)){let e=Re(t.length)|0,n=L(e);return n.length===0||t.copy(n,0,0,e),n}if(t.length!==void 0)return typeof t.length!="number"||Ue(t.length)?L(0):Ae(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Ae(t.data)}function Re(t){if(t>=ce)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ce.toString(16)+" bytes");return t|0}function Kt(t){return+t!=t&&(t=0),d.alloc(+t)}d.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==d.prototype};d.compare=function(e,n){if(F(e,Uint8Array)&&(e=d.from(e,e.offset,e.byteLength)),F(n,Uint8Array)&&(n=d.from(n,n.offset,n.byteLength)),!d.isBuffer(e)||!d.isBuffer(n))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===n)return 0;let r=e.length,i=n.length;for(let o=0,s=Math.min(r,i);o<s;++o)if(e[o]!==n[o]){r=e[o],i=n[o];break}return r<i?-1:i<r?1:0};d.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};d.concat=function(e,n){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return d.alloc(0);let r;if(n===void 0)for(n=0,r=0;r<e.length;++r)n+=e[r].length;let i=d.allocUnsafe(n),o=0;for(r=0;r<e.length;++r){let s=e[r];if(F(s,Uint8Array))o+s.length>i.length?(d.isBuffer(s)||(s=d.from(s)),s.copy(i,o)):Uint8Array.prototype.set.call(i,s,o);else if(d.isBuffer(s))s.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=s.length}return i};function Ke(t,e){if(d.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||F(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);let n=t.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return Te(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n*2;case"hex":return n>>>1;case"base64":return ot(t).length;default:if(i)return r?-1:Te(t).length;e=(""+e).toLowerCase(),i=!0}}d.byteLength=Ke;function qt(t,e,n){let r=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,e>>>=0,n<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return ln(this,e,n);case"utf8":case"utf-8":return Qe(this,e,n);case"ascii":return sn(this,e,n);case"latin1":case"binary":return un(this,e,n);case"base64":return rn(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return fn(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}d.prototype._isBuffer=!0;function v(t,e,n){let r=t[e];t[e]=t[n],t[n]=r}d.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let n=0;n<e;n+=2)v(this,n,n+1);return this};d.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let n=0;n<e;n+=4)v(this,n,n+3),v(this,n+1,n+2);return this};d.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let n=0;n<e;n+=8)v(this,n,n+7),v(this,n+1,n+6),v(this,n+2,n+5),v(this,n+3,n+4);return this};d.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Qe(this,0,e):qt.apply(this,arguments)};d.prototype.toLocaleString=d.prototype.toString;d.prototype.equals=function(e){if(!d.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:d.compare(this,e)===0};d.prototype.inspect=function(){let e="",n=D.INSPECT_MAX_BYTES;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"};Ve&&(d.prototype[Ve]=d.prototype.inspect);d.prototype.compare=function(e,n,r,i,o){if(F(e,Uint8Array)&&(e=d.from(e,e.offset,e.byteLength)),!d.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(n===void 0&&(n=0),r===void 0&&(r=e?e.length:0),i===void 0&&(i=0),o===void 0&&(o=this.length),n<0||r>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&n>=r)return 0;if(i>=o)return-1;if(n>=r)return 1;if(n>>>=0,r>>>=0,i>>>=0,o>>>=0,this===e)return 0;let s=o-i,u=r-n,l=Math.min(s,u),f=this.slice(i,o),c=e.slice(n,r);for(let a=0;a<l;++a)if(f[a]!==c[a]){s=f[a],u=c[a];break}return s<u?-1:u<s?1:0};function qe(t,e,n,r,i){if(t.length===0)return-1;if(typeof n=="string"?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,Ue(n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0)if(i)n=0;else return-1;if(typeof e=="string"&&(e=d.from(e,r)),d.isBuffer(e))return e.length===0?-1:ve(t,e,n,r,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):ve(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function ve(t,e,n,r,i){let o=1,s=t.length,u=e.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(t.length<2||e.length<2)return-1;o=2,s/=2,u/=2,n/=2}function l(c,a){return o===1?c[a]:c.readUInt16BE(a*o)}let f;if(i){let c=-1;for(f=n;f<s;f++)if(l(t,f)===l(e,c===-1?0:f-c)){if(c===-1&&(c=f),f-c+1===u)return c*o}else c!==-1&&(f-=f-c),c=-1}else for(n+u>s&&(n=s-u),f=n;f>=0;f--){let c=!0;for(let a=0;a<u;a++)if(l(t,f+a)!==l(e,a)){c=!1;break}if(c)return f}return-1}d.prototype.includes=function(e,n,r){return this.indexOf(e,n,r)!==-1};d.prototype.indexOf=function(e,n,r){return qe(this,e,n,r,!0)};d.prototype.lastIndexOf=function(e,n,r){return qe(this,e,n,r,!1)};function Qt(t,e,n,r){n=Number(n)||0;let i=t.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;let o=e.length;r>o/2&&(r=o/2);let s;for(s=0;s<r;++s){let u=parseInt(e.substr(s*2,2),16);if(Ue(u))return s;t[n+s]=u}return s}function Dt(t,e,n,r){return ae(Te(e,t.length-n),t,n,r)}function en(t,e,n,r){return ae(hn(e),t,n,r)}function tn(t,e,n,r){return ae(ot(e),t,n,r)}function nn(t,e,n,r){return ae(pn(e,t.length-n),t,n,r)}d.prototype.write=function(e,n,r,i){if(n===void 0)i="utf8",r=this.length,n=0;else if(r===void 0&&typeof n=="string")i=n,r=this.length,n=0;else if(isFinite(n))n=n>>>0,isFinite(r)?(r=r>>>0,i===void 0&&(i="utf8")):(i=r,r=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let o=this.length-n;if((r===void 0||r>o)&&(r=o),e.length>0&&(r<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let s=!1;for(;;)switch(i){case"hex":return Qt(this,e,n,r);case"utf8":case"utf-8":return Dt(this,e,n,r);case"ascii":case"latin1":case"binary":return en(this,e,n,r);case"base64":return tn(this,e,n,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return nn(this,e,n,r);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function rn(t,e,n){return e===0&&n===t.length?Ne.fromByteArray(t):Ne.fromByteArray(t.slice(e,n))}function Qe(t,e,n){n=Math.min(t.length,n);let r=[],i=e;for(;i<n;){let o=t[i],s=null,u=o>239?4:o>223?3:o>191?2:1;if(i+u<=n){let l,f,c,a;switch(u){case 1:o<128&&(s=o);break;case 2:l=t[i+1],(l&192)===128&&(a=(o&31)<<6|l&63,a>127&&(s=a));break;case 3:l=t[i+1],f=t[i+2],(l&192)===128&&(f&192)===128&&(a=(o&15)<<12|(l&63)<<6|f&63,a>2047&&(a<55296||a>57343)&&(s=a));break;case 4:l=t[i+1],f=t[i+2],c=t[i+3],(l&192)===128&&(f&192)===128&&(c&192)===128&&(a=(o&15)<<18|(l&63)<<12|(f&63)<<6|c&63,a>65535&&a<1114112&&(s=a))}}s===null?(s=65533,u=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),i+=u}return on(r)}var je=4096;function on(t){let e=t.length;if(e<=je)return String.fromCharCode.apply(String,t);let n="",r=0;for(;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=je));return n}function sn(t,e,n){let r="";n=Math.min(t.length,n);for(let i=e;i<n;++i)r+=String.fromCharCode(t[i]&127);return r}function un(t,e,n){let r="";n=Math.min(t.length,n);for(let i=e;i<n;++i)r+=String.fromCharCode(t[i]);return r}function ln(t,e,n){let r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);let i="";for(let o=e;o<n;++o)i+=gn[t[o]];return i}function fn(t,e,n){let r=t.slice(e,n),i="";for(let o=0;o<r.length-1;o+=2)i+=String.fromCharCode(r[o]+r[o+1]*256);return i}d.prototype.slice=function(e,n){let r=this.length;e=~~e,n=n===void 0?r:~~n,e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),n<0?(n+=r,n<0&&(n=0)):n>r&&(n=r),n<e&&(n=e);let i=this.subarray(e,n);return Object.setPrototypeOf(i,d.prototype),i};function _(t,e,n){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}d.prototype.readUintLE=d.prototype.readUIntLE=function(e,n,r){e=e>>>0,n=n>>>0,r||_(e,n,this.length);let i=this[e],o=1,s=0;for(;++s<n&&(o*=256);)i+=this[e+s]*o;return i};d.prototype.readUintBE=d.prototype.readUIntBE=function(e,n,r){e=e>>>0,n=n>>>0,r||_(e,n,this.length);let i=this[e+--n],o=1;for(;n>0&&(o*=256);)i+=this[e+--n]*o;return i};d.prototype.readUint8=d.prototype.readUInt8=function(e,n){return e=e>>>0,n||_(e,1,this.length),this[e]};d.prototype.readUint16LE=d.prototype.readUInt16LE=function(e,n){return e=e>>>0,n||_(e,2,this.length),this[e]|this[e+1]<<8};d.prototype.readUint16BE=d.prototype.readUInt16BE=function(e,n){return e=e>>>0,n||_(e,2,this.length),this[e]<<8|this[e+1]};d.prototype.readUint32LE=d.prototype.readUInt32LE=function(e,n){return e=e>>>0,n||_(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};d.prototype.readUint32BE=d.prototype.readUInt32BE=function(e,n){return e=e>>>0,n||_(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};d.prototype.readBigUInt64LE=Z(function(e){e=e>>>0,Q(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&ne(e,this.length-8);let i=n+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,o=this[++e]+this[++e]*2**8+this[++e]*2**16+r*2**24;return BigInt(i)+(BigInt(o)<<BigInt(32))});d.prototype.readBigUInt64BE=Z(function(e){e=e>>>0,Q(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&ne(e,this.length-8);let i=n*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],o=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r;return(BigInt(i)<<BigInt(32))+BigInt(o)});d.prototype.readIntLE=function(e,n,r){e=e>>>0,n=n>>>0,r||_(e,n,this.length);let i=this[e],o=1,s=0;for(;++s<n&&(o*=256);)i+=this[e+s]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*n)),i};d.prototype.readIntBE=function(e,n,r){e=e>>>0,n=n>>>0,r||_(e,n,this.length);let i=n,o=1,s=this[e+--i];for(;i>0&&(o*=256);)s+=this[e+--i]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*n)),s};d.prototype.readInt8=function(e,n){return e=e>>>0,n||_(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};d.prototype.readInt16LE=function(e,n){e=e>>>0,n||_(e,2,this.length);let r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};d.prototype.readInt16BE=function(e,n){e=e>>>0,n||_(e,2,this.length);let r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};d.prototype.readInt32LE=function(e,n){return e=e>>>0,n||_(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};d.prototype.readInt32BE=function(e,n){return e=e>>>0,n||_(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};d.prototype.readBigInt64LE=Z(function(e){e=e>>>0,Q(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&ne(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(r<<24);return(BigInt(i)<<BigInt(32))+BigInt(n+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)});d.prototype.readBigInt64BE=Z(function(e){e=e>>>0,Q(e,"offset");let n=this[e],r=this[e+7];(n===void 0||r===void 0)&&ne(e,this.length-8);let i=(n<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+r)});d.prototype.readFloatLE=function(e,n){return e=e>>>0,n||_(e,4,this.length),q.read(this,e,!0,23,4)};d.prototype.readFloatBE=function(e,n){return e=e>>>0,n||_(e,4,this.length),q.read(this,e,!1,23,4)};d.prototype.readDoubleLE=function(e,n){return e=e>>>0,n||_(e,8,this.length),q.read(this,e,!0,52,8)};d.prototype.readDoubleBE=function(e,n){return e=e>>>0,n||_(e,8,this.length),q.read(this,e,!1,52,8)};function C(t,e,n,r,i,o){if(!d.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}d.prototype.writeUintLE=d.prototype.writeUIntLE=function(e,n,r,i){if(e=+e,n=n>>>0,r=r>>>0,!i){let u=Math.pow(2,8*r)-1;C(this,e,n,r,u,0)}let o=1,s=0;for(this[n]=e&255;++s<r&&(o*=256);)this[n+s]=e/o&255;return n+r};d.prototype.writeUintBE=d.prototype.writeUIntBE=function(e,n,r,i){if(e=+e,n=n>>>0,r=r>>>0,!i){let u=Math.pow(2,8*r)-1;C(this,e,n,r,u,0)}let o=r-1,s=1;for(this[n+o]=e&255;--o>=0&&(s*=256);)this[n+o]=e/s&255;return n+r};d.prototype.writeUint8=d.prototype.writeUInt8=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,1,255,0),this[n]=e&255,n+1};d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,2,65535,0),this[n]=e&255,this[n+1]=e>>>8,n+2};d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,2,65535,0),this[n]=e>>>8,this[n+1]=e&255,n+2};d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,4,4294967295,0),this[n+3]=e>>>24,this[n+2]=e>>>16,this[n+1]=e>>>8,this[n]=e&255,n+4};d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,4,4294967295,0),this[n]=e>>>24,this[n+1]=e>>>16,this[n+2]=e>>>8,this[n+3]=e&255,n+4};function De(t,e,n,r,i){it(e,r,i,t,n,7);let o=Number(e&BigInt(4294967295));t[n++]=o,o=o>>8,t[n++]=o,o=o>>8,t[n++]=o,o=o>>8,t[n++]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=s,s=s>>8,t[n++]=s,s=s>>8,t[n++]=s,s=s>>8,t[n++]=s,n}function et(t,e,n,r,i){it(e,r,i,t,n,7);let o=Number(e&BigInt(4294967295));t[n+7]=o,o=o>>8,t[n+6]=o,o=o>>8,t[n+5]=o,o=o>>8,t[n+4]=o;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=s,s=s>>8,t[n+2]=s,s=s>>8,t[n+1]=s,s=s>>8,t[n]=s,n+8}d.prototype.writeBigUInt64LE=Z(function(e,n=0){return De(this,e,n,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeBigUInt64BE=Z(function(e,n=0){return et(this,e,n,BigInt(0),BigInt("0xffffffffffffffff"))});d.prototype.writeIntLE=function(e,n,r,i){if(e=+e,n=n>>>0,!i){let l=Math.pow(2,8*r-1);C(this,e,n,r,l-1,-l)}let o=0,s=1,u=0;for(this[n]=e&255;++o<r&&(s*=256);)e<0&&u===0&&this[n+o-1]!==0&&(u=1),this[n+o]=(e/s>>0)-u&255;return n+r};d.prototype.writeIntBE=function(e,n,r,i){if(e=+e,n=n>>>0,!i){let l=Math.pow(2,8*r-1);C(this,e,n,r,l-1,-l)}let o=r-1,s=1,u=0;for(this[n+o]=e&255;--o>=0&&(s*=256);)e<0&&u===0&&this[n+o+1]!==0&&(u=1),this[n+o]=(e/s>>0)-u&255;return n+r};d.prototype.writeInt8=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,1,127,-128),e<0&&(e=255+e+1),this[n]=e&255,n+1};d.prototype.writeInt16LE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,2,32767,-32768),this[n]=e&255,this[n+1]=e>>>8,n+2};d.prototype.writeInt16BE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,2,32767,-32768),this[n]=e>>>8,this[n+1]=e&255,n+2};d.prototype.writeInt32LE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,4,2147483647,-2147483648),this[n]=e&255,this[n+1]=e>>>8,this[n+2]=e>>>16,this[n+3]=e>>>24,n+4};d.prototype.writeInt32BE=function(e,n,r){return e=+e,n=n>>>0,r||C(this,e,n,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[n]=e>>>24,this[n+1]=e>>>16,this[n+2]=e>>>8,this[n+3]=e&255,n+4};d.prototype.writeBigInt64LE=Z(function(e,n=0){return De(this,e,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});d.prototype.writeBigInt64BE=Z(function(e,n=0){return et(this,e,n,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function tt(t,e,n,r,i,o){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function nt(t,e,n,r,i){return e=+e,n=n>>>0,i||tt(t,e,n,4,34028234663852886e22,-34028234663852886e22),q.write(t,e,n,r,23,4),n+4}d.prototype.writeFloatLE=function(e,n,r){return nt(this,e,n,!0,r)};d.prototype.writeFloatBE=function(e,n,r){return nt(this,e,n,!1,r)};function rt(t,e,n,r,i){return e=+e,n=n>>>0,i||tt(t,e,n,8,17976931348623157e292,-17976931348623157e292),q.write(t,e,n,r,52,8),n+8}d.prototype.writeDoubleLE=function(e,n,r){return rt(this,e,n,!0,r)};d.prototype.writeDoubleBE=function(e,n,r){return rt(this,e,n,!1,r)};d.prototype.copy=function(e,n,r,i){if(!d.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!i&&i!==0&&(i=this.length),n>=e.length&&(n=e.length),n||(n=0),i>0&&i<r&&(i=r),i===r||e.length===0||this.length===0)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-n<i-r&&(i=e.length-n+r);let o=i-r;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(n,r,i):Uint8Array.prototype.set.call(e,this.subarray(r,i),n),o};d.prototype.fill=function(e,n,r,i){if(typeof e=="string"){if(typeof n=="string"?(i=n,n=0,r=this.length):typeof r=="string"&&(i=r,r=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!d.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){let s=e.charCodeAt(0);(i==="utf8"&&s<128||i==="latin1")&&(e=s)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(n<0||this.length<n||this.length<r)throw new RangeError("Out of range index");if(r<=n)return this;n=n>>>0,r=r===void 0?this.length:r>>>0,e||(e=0);let o;if(typeof e=="number")for(o=n;o<r;++o)this[o]=e;else{let s=d.isBuffer(e)?e:d.from(e,i),u=s.length;if(u===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(o=0;o<r-n;++o)this[o+n]=s[o%u]}return this};var K={};function Be(t,e,n){K[t]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}Be("ERR_BUFFER_OUT_OF_BOUNDS",function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);Be("ERR_INVALID_ARG_TYPE",function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`},TypeError);Be("ERR_OUT_OF_RANGE",function(t,e,n){let r=`The value of "${t}" is out of range.`,i=n;return Number.isInteger(n)&&Math.abs(n)>2**32?i=He(String(n)):typeof n=="bigint"&&(i=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(i=He(i)),i+="n"),r+=` It must be ${e}. Received ${i}`,r},RangeError);function He(t){let e="",n=t.length,r=t[0]==="-"?1:0;for(;n>=r+4;n-=3)e=`_${t.slice(n-3,n)}${e}`;return`${t.slice(0,n)}${e}`}function cn(t,e,n){Q(e,"offset"),(t[e]===void 0||t[e+n]===void 0)&&ne(e,t.length-(n+1))}function it(t,e,n,r,i,o){if(t>n||t<e){let s=typeof e=="bigint"?"n":"",u;throw o>3?e===0||e===BigInt(0)?u=`>= 0${s} and < 2${s} ** ${(o+1)*8}${s}`:u=`>= -(2${s} ** ${(o+1)*8-1}${s}) and < 2 ** ${(o+1)*8-1}${s}`:u=`>= ${e}${s} and <= ${n}${s}`,new K.ERR_OUT_OF_RANGE("value",u,t)}cn(r,i,o)}function Q(t,e){if(typeof t!="number")throw new K.ERR_INVALID_ARG_TYPE(e,"number",t)}function ne(t,e,n){throw Math.floor(t)!==t?(Q(t,n),new K.ERR_OUT_OF_RANGE(n||"offset","an integer",t)):e<0?new K.ERR_BUFFER_OUT_OF_BOUNDS:new K.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${e}`,t)}var an=/[^+/0-9A-Za-z-_]/g;function dn(t){if(t=t.split("=")[0],t=t.trim().replace(an,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Te(t,e){e=e||1/0;let n,r=t.length,i=null,o=[];for(let s=0;s<r;++s){if(n=t.charCodeAt(s),n>55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&o.push(239,191,189);continue}else if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&o.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;o.push(n)}else if(n<2048){if((e-=2)<0)break;o.push(n>>6|192,n&63|128)}else if(n<65536){if((e-=3)<0)break;o.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((e-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return o}function hn(t){let e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n)&255);return e}function pn(t,e){let n,r,i,o=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)n=t.charCodeAt(s),r=n>>8,i=n%256,o.push(i),o.push(r);return o}function ot(t){return Ne.toByteArray(dn(t))}function ae(t,e,n,r){let i;for(i=0;i<r&&!(i+n>=e.length||i>=t.length);++i)e[i+n]=t[i];return i}function F(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Ue(t){return t!==t}var gn=function(){let t="0123456789abcdef",e=new Array(256);for(let n=0;n<16;++n){let r=n*16;for(let i=0;i<16;++i)e[r+i]=t[n]+t[i]}return e}();function Z(t){return typeof BigInt>"u"?mn:t}function mn(){throw new Error("BigInt not supported")}});var m,p=Ot(()=>{"use strict";m=Mt(st(),1);typeof globalThis<"u"&&!globalThis.Buffer&&(globalThis.Buffer=m.Buffer)});p();p();p();p();var Ur=t=>t,Sr=t=>t,kr=t=>t,wn=(y=>(y.FORMAT_DETECTION_FAILED="FORMAT_DETECTION_FAILED",y.INVALID_FILE="INVALID_FILE",y.UNSUPPORTED_PUZZLE_TYPE="UNSUPPORTED_PUZZLE_TYPE",y.BINARY_PARSE_ERROR="BINARY_PARSE_ERROR",y.IPUZ_PARSE_ERROR="IPUZ_PARSE_ERROR",y.IPUZ_INVALID_JSON="IPUZ_INVALID_JSON",y.IPUZ_MISSING_VERSION="IPUZ_MISSING_VERSION",y.IPUZ_MISSING_KIND="IPUZ_MISSING_KIND",y.IPUZ_MISSING_REQUIRED_FIELD="IPUZ_MISSING_REQUIRED_FIELD",y.IPUZ_INVALID_DATA_TYPE="IPUZ_INVALID_DATA_TYPE",y.IPUZ_INVALID_GRID_SIZE="IPUZ_INVALID_GRID_SIZE",y.PUZ_PARSE_ERROR="PUZ_PARSE_ERROR",y.PUZ_INVALID_HEADER="PUZ_INVALID_HEADER",y.PUZ_INVALID_GRID="PUZ_INVALID_GRID",y.PUZ_CHECKSUM_MISMATCH="PUZ_CHECKSUM_MISMATCH",y.JPZ_PARSE_ERROR="JPZ_PARSE_ERROR",y.JPZ_INVALID_XML="JPZ_INVALID_XML",y.JPZ_MISSING_GRID="JPZ_MISSING_GRID",y.JPZ_INVALID_GRID="JPZ_INVALID_GRID",y.XD_PARSE_ERROR="XD_PARSE_ERROR",y.XD_FORMAT_ERROR="XD_FORMAT_ERROR",y.XD_INVALID_GRID="XD_INVALID_GRID",y.XD_MISSING_CLUES="XD_MISSING_CLUES",y))(wn||{});var T=class extends Error{constructor(n,r="FORMAT_DETECTION_FAILED",i,o){super(n,{cause:o});Y(this,"code");Y(this,"context");this.code=r,this.context=i}isFormatMismatch(){return this.code==="UNSUPPORTED_PUZZLE_TYPE"||this.code==="FORMAT_DETECTION_FAILED"}},re=class extends T{constructor(e="Unable to detect puzzle format",n,r){super(e,"FORMAT_DETECTION_FAILED",n,r)}},de=class extends T{constructor(e,n,r,i){super(`Invalid ${e} file: ${n}`,"INVALID_FILE",r,i)}},G=class extends T{constructor(e,n,r){super(`${e} puzzles are not supported`,"UNSUPPORTED_PUZZLE_TYPE",n,r)}},S=class extends T{constructor(e,n="IPUZ_PARSE_ERROR",r,i){super(e,n,r,i)}isFormatMismatch(){return super.isFormatMismatch()||this.code==="IPUZ_INVALID_JSON"||this.code==="IPUZ_MISSING_VERSION"||this.code==="IPUZ_MISSING_KIND"}},M=class extends T{constructor(e,n="PUZ_PARSE_ERROR",r,i){super(e,n,r,i)}isFormatMismatch(){return super.isFormatMismatch()||this.code==="PUZ_INVALID_HEADER"}},z=class extends T{constructor(e,n="JPZ_PARSE_ERROR",r,i){super(e,n,r,i)}isFormatMismatch(){return super.isFormatMismatch()||this.code==="JPZ_INVALID_XML"}},X=class extends T{constructor(e,n="XD_PARSE_ERROR",r,i){super(e,n,r,i)}isFormatMismatch(){return super.isFormatMismatch()||this.code==="XD_FORMAT_ERROR"}},O=class extends T{constructor(e,n){super(e,"BINARY_PARSE_ERROR",n),this.name="BinaryParseError"}};p();var ie="ACROSS&DOWN";var ut="GEXT",lt="LTIM",ft="RTBL";var ct="GRBS";var bn=(r=>(r.NORMAL="normal",r.BLOCK="block",r.NULL="null",r))(bn||{});function yn(t,e){let n={type:"normal"};if(t===null||t==="null")return n.type="null",n;if(t==="#")return n.type="block",n;if(typeof t=="object"&&t!==null){let r=t;if("cell"in r&&r.cell!==void 0){let i=r.cell;i==="#"?n.type="block":i==="null"||i===null?n.type="null":(typeof i=="number"||typeof i=="string")&&i!==0&&i!=="0"&&(n.number=i)}if("style"in r&&r.style&&typeof r.style=="object"){n.style={};let i=["shapebg","highlight","named","border","divided","label","mark","imagebg","color","colortext","colorborder","colorbar","barred","dotted","dashed","lessthan","greaterthan","equal","handler","handlerdata"];for(let o of i)if(o in r.style){let s=r.style[o];s!==void 0&&(n.style[o]=s)}}"value"in r&&r.value!==void 0&&(n.value=r.value),"continued"in r&&r.continued!==void 0&&(n.continued=r.continued),"directions"in r&&r.directions!==void 0&&(n.directions=r.directions),"given"in r&&r.given!==void 0&&(n.given=r.given)}else if(typeof t=="number"||typeof t=="string"){if(typeof t=="number"&&t>0)n.number=t;else if(typeof t=="string")if(t==="0"||t==="#"||t==="null")t==="#"&&(n.type="block");else{let r=Number.parseInt(t,10);!Number.isNaN(r)&&r>0?n.number=t:n.value=t}}return e&&typeof e=="string"&&e!=="#"&&e!=="null"&&e!==null&&(n.solution=e),n}function In(t){let e={};for(let[n,r]of Object.entries(t))if(Array.isArray(r)){e[n]=[];for(let i of r){let o=null;if(Array.isArray(i)&&i.length>=2){if(o={number:i[0],text:i[1]},i.length>2)for(let s=2;s<i.length;s++){let u=i[s];if(typeof u=="object"&&u!==null){let l=u;"references"in l&&l.references&&(o.references=l.references),"continued"in l&&l.continued&&(o.continued=l.continued),"highlight"in l&&l.highlight&&(o.highlight=l.highlight),"image"in l&&l.image&&(o.image=l.image)}}}else if(typeof i=="object"&&i!==null){let s=i;o={number:s.number||"",text:s.clue||""},s.cells&&(o.cells=s.cells),s.references&&(o.references=s.references),s.continued&&(o.continued=s.continued),s.highlight!==void 0&&(o.highlight=s.highlight),s.image&&(o.image=s.image)}o&&e[n].push(o)}}return e}function at(t,e){let r=(typeof t=="string"?t:t.toString("utf-8")).trim();r.startsWith("ipuz(")&&r.endsWith(")")&&(r=r.slice(5,-1));let i;try{i=JSON.parse(r)}catch(a){throw new S(`Invalid JSON: ${a instanceof Error?a.message:"Unknown error"}`,"IPUZ_INVALID_JSON",void 0,a)}if(!i.kind||!Array.isArray(i.kind)||!i.kind.some(a=>a.includes("crossword")))throw new G("Non-crossword");if(!i.dimensions||typeof i.dimensions!="object")throw new S("Missing or invalid dimensions field","IPUZ_MISSING_REQUIRED_FIELD");if(!i.dimensions.width||!i.dimensions.height)throw new S("Missing width or height in dimensions","IPUZ_MISSING_REQUIRED_FIELD");if(typeof i.dimensions.width!="number"||typeof i.dimensions.height!="number")throw new S("Width and height must be numbers","IPUZ_INVALID_DATA_TYPE");if(!Number.isInteger(i.dimensions.width)||!Number.isInteger(i.dimensions.height))throw new S("Width and height must be integers","IPUZ_INVALID_DATA_TYPE");if(i.dimensions.width<=0||i.dimensions.height<=0)throw new S("Width and height must be positive numbers","IPUZ_INVALID_GRID_SIZE");let o=e?.maxGridSize?.width??100,s=e?.maxGridSize?.height??100;if(i.dimensions.width>o||i.dimensions.height>s)throw new S(`Grid dimensions too large: ${i.dimensions.width}x${i.dimensions.height}. Maximum supported size is ${o}x${s}`,"IPUZ_INVALID_GRID_SIZE");if(!i.puzzle||!Array.isArray(i.puzzle))throw new S("Missing or invalid puzzle grid","IPUZ_MISSING_REQUIRED_FIELD");let u={version:i.version||"",kind:i.kind||[],dimensions:i.dimensions,puzzle:[],clues:{},extensions:{}},l=["title","author","copyright","publisher","publication","url","intro","explanation","annotation","notes","difficulty","origin","date","empty","charset","block","answer"];for(let a of l)a in i&&i[a]!==void 0&&(u[a]=i[a]);"uniqueid"in i&&i.uniqueid!==void 0&&(u.uniqueId=i.uniqueid),"showenumerations"in i&&i.showenumerations!==void 0&&(u.showEnumerations=i.showenumerations),"clueplacement"in i&&i.clueplacement!==void 0&&(u.cluePlacement=i.clueplacement),"answers"in i&&i.answers&&(u.answers=i.answers),"enumeration"in i&&i.enumeration!==void 0&&(u.enumeration=i.enumeration),"enumerations"in i&&i.enumerations&&(u.enumerations=i.enumerations),"volatile"in i&&i.volatile&&(u.volatile=i.volatile),"checksum"in i&&i.checksum&&(u.checksum=i.checksum),"zones"in i&&i.zones&&(u.zones=i.zones),"styles"in i&&i.styles&&(u.styles=i.styles),"misses"in i&&i.misses&&(u.misses=i.misses);let f=i.solution||[];f.length>0&&(u.solution=f),"saved"in i&&i.saved&&(u.saved=i.saved);let c=i.puzzle||[];for(let a=0;a<c.length;a++){let h=c[a];if(!h)continue;let g=[];for(let I=0;I<h.length;I++){let b=h[I],A;f.length>a&&f[a]&&f[a].length>I&&(A=f[a][I]);let U=yn(b,A);g.push(U)}u.puzzle.push(g)}"clues"in i&&i.clues&&(u.clues=In(i.clues));for(let[a,h]of Object.entries(i))(a.startsWith("http://")||a.startsWith("https://")||a.includes(":"))&&(u.extensions[a]=h);return u}function dt(t){let e={width:t.dimensions.width,height:t.dimensions.height,cells:[]};for(let o=0;o<t.dimensions.height;o++){let s=[];for(let u=0;u<t.dimensions.width;u++){let l=t.puzzle[o]?.[u],f=t.solution?.[o]?.[u],c=l?.number?typeof l.number=="string"?parseInt(l.number):l.number:void 0,a=l?.type==="block",g={solution:typeof f=="string"?f:l?.value||void 0,number:c,isBlack:a};l?.style&&typeof l.style=="object"&&l.style.shapebg==="circle"&&(g.isCircled=!0),(l?.style||l?.continued||l?.directions||l?.given)&&(g.additionalProperties={},l.style&&typeof l.style=="object"&&(Object.keys(l.style).length>1||l.style.shapebg!=="circle")&&(g.additionalProperties.style=l.style),l.continued&&(g.additionalProperties.continued=l.continued),l.directions&&(g.additionalProperties.directions=l.directions),l.given!==void 0&&(g.additionalProperties.given=l.given),Object.keys(g.additionalProperties).length===0&&delete g.additionalProperties),s.push(g)}e.cells.push(s)}let n={across:[],down:[]};if(t.clues?.Across)for(let o of t.clues.Across){let s=typeof o.number=="string"?parseInt(o.number):o.number;!Number.isNaN(s)&&s>0&&n.across.push({number:s,text:o.text||""})}if(t.clues?.Down)for(let o of t.clues.Down){let s=typeof o.number=="string"?parseInt(o.number):o.number;!Number.isNaN(s)&&s>0&&n.down.push({number:s,text:o.text||""})}let r={title:t.title,author:t.author,copyright:t.copyright,notes:t.notes,date:t.date,grid:e,clues:n},i={};return t.difficulty&&(i.difficulty=t.difficulty),t.publisher&&(i.publisher=t.publisher),t.publication&&(i.publication=t.publication),t.url&&(i.url=t.url),t.uniqueId&&(i.uniqueId=t.uniqueId),t.intro&&(i.intro=t.intro),t.explanation&&(i.explanation=t.explanation),t.annotation&&(i.annotation=t.annotation),t.styles&&Object.keys(t.styles).length>0&&(i.styles=t.styles),t.zones&&t.zones.length>0&&(i.zones=t.zones),Object.keys(t.extensions).length>0&&(i.extensions=t.extensions),Object.keys(i).length>0&&(r.additionalProperties=i),r}p();function En(t){let e={};for(let n of t){let r=n.indexOf(":");if(r===-1)continue;let i=n.substring(0,r).trim(),o=n.substring(r+1).trim();if(i&&o){let s=(i[0]??"").toLowerCase()+i.slice(1);e[s]=o}}return e}function xn(t){return t.map(e=>{let n=[];for(let r=0;r<e.length;r++){let i=e[r];i!==void 0&&n.push(i)}return n})}function _n(t){let e=[],n=[];for(let r of t){if(r.length===0)continue;let i=r.match(/^([AD])(\d+)\.\s+(.+?)(?:\s+~\s+(.+))?$/);if(i){let[,o,s,u,l]=i,f={number:s??"",clue:u?.trim()??"",answer:l?.trim()??""};o==="A"?e.push(f):n.push(f)}}return{across:e,down:n}}function Nn(t){let e=t.split(`
`),n=[],r=[],i=0;for(let u of e)u.trim()===""?(i++,i>=2&&r.length>0&&(n.push(r),r=[],i=0)):(i===1&&r.length>0&&(n.push(r),r=[]),i=0,r.push(u));r.length>0&&n.push(r);let o={metadata:[],grid:[],clues:[],notes:[]},s=0;if(n.length>s){let u=n[s];u&&u.some(l=>l.includes(":"))&&(o.metadata=u,s++)}if(n.length>s){let u=n[s];u&&u.every(l=>/^[A-Za-z0-9#._]+$/.test(l)&&l.length>0)&&(o.grid=u,s++)}for(;n.length>s;){let u=n[s];if(u&&u.some(l=>/^[AD]\d+\./.test(l)))o.clues.push(...u),s++;else break}if(n.length>s)for(let u=s;u<n.length;u++){let l=n[u];l&&o.notes.push(...l)}return o}function ht(t,e){let n=Nn(t);if(n.grid.length===0)throw new X("Invalid XD file: no grid section found","XD_FORMAT_ERROR");let r=En(n.metadata),i=xn(n.grid),{across:o,down:s}=_n(n.clues);if(i.length===0)throw new X("Grid is empty","XD_INVALID_GRID");let u=i[0]?.length||0;if(u===0)throw new X("Grid has no columns","XD_INVALID_GRID");let l=i.length,f=e?.maxGridSize?.width??100,c=e?.maxGridSize?.height??100;if(u>f||l>c)throw new X(`Grid dimensions too large: ${u}x${l}. Maximum supported size is ${f}x${c}`,"XD_INVALID_GRID");for(let h=0;h<i.length;h++)if(!i[h]||i[h]?.length!==u)throw new X(`Grid row ${h} has inconsistent width (expected ${u}, got ${i[h]?.length||0})`,"XD_INVALID_GRID");let a={metadata:r,grid:i,across:o,down:s};return n.notes.length>0&&(a.notes=n.notes.join(`
`).trim()),a}function pt(t){let e=t.grid[0];if(!e)throw new Error("Invalid state: grid is empty");let n={width:e.length,height:t.grid.length,cells:[]},r=1;for(let u=0;u<t.grid.length;u++){let l=t.grid[u],f=[];for(let c=0;c<l.length;c++){let a=l[c],h=a==="#",g;h||((c===0||t.grid[u][c-1]==="#")&&c<l.length-1&&t.grid[u][c+1]!=="#"||(u===0||t.grid[u-1]?.[c]==="#")&&u<t.grid.length-1&&t.grid[u+1]?.[c]!=="#")&&(g=r++),f.push({solution:h?void 0:a,number:g,isBlack:h})}n.cells.push(f)}let i={across:t.across.map(u=>({number:parseInt(u.number),text:u.clue})),down:t.down.map(u=>({number:parseInt(u.number),text:u.clue}))},o={title:t.metadata.title,author:t.metadata.author,copyright:t.metadata.copyright,notes:t.notes,date:t.metadata.date,grid:n,clues:i},s={};return t.metadata.editor&&(s.editor=t.metadata.editor),t.metadata.rebus&&(s.rebus=t.metadata.rebus),t.metadata.notepad&&(s.notepad=t.metadata.notepad),Object.keys(s).length>0&&(o.additionalProperties=s),o}p();p();var ge=class{constructor(e){Y(this,"_buffer");Y(this,"_offset");e instanceof ArrayBuffer?this._buffer=m.Buffer.from(e):e instanceof Uint8Array?this._buffer=m.Buffer.from(e):this._buffer=e,this._offset=0}readUInt8(){if(this._offset+1>this._buffer.length)throw new O(`Cannot read byte at offset ${this._offset}: buffer too short (length: ${this._buffer.length})`);let e=this._buffer.readUInt8(this._offset);return this._offset+=1,e}readUInt16LE(){if(this._offset+2>this._buffer.length)throw new O(`Cannot read 16-bit value at offset ${this._offset}: buffer too short (length: ${this._buffer.length})`);let e=this._buffer.readUInt16LE(this._offset);return this._offset+=2,e}readBytes(e){if(this._offset+e>this._buffer.length)throw new O(`Cannot read ${e} bytes at offset ${this._offset}: buffer too short (length: ${this._buffer.length})`);let n=this._buffer.slice(this._offset,this._offset+e);return this._offset+=e,n}readString(e,n=!0,r="latin1"){let i=this.readBytes(e);if(n){let o=i.indexOf(0);return o===-1&&(o=e),i.toString(r,0,o)}return i.toString(r)}readNullTerminatedString(e="latin1"){let n=this._offset;for(;this._offset<this._buffer.length&&this._buffer[this._offset]!==0;)this._offset++;if(this._offset>=this._buffer.length)throw new O(`Cannot read null-terminated string at offset ${n}: buffer ended without null terminator`);let r=this._buffer.toString(e,n,this._offset);return this._offset++,r}seek(e){if(e<0||e>this._buffer.length)throw new O(`Cannot seek to position ${e}: out of bounds (buffer length: ${this._buffer.length})`);this._offset=e}get position(){return this._offset}get length(){return this._buffer.length}get buffer(){return this._buffer}hasMore(){return this._offset<this._buffer.length}get remaining(){return this._buffer.length-this._offset}};function Tn(t){let e=m.Buffer.from(ie,"latin1"),n=-1;for(let J=0;J<=t.length-e.length;J++){let te=!0;for(let le=0;le<e.length;le++)if(t.buffer[J+le]!==e[le]){te=!1;break}if(te){n=J;break}}if(n===-1)throw new M(`Invalid PUZ file: magic string "${ie}" not found`,"PUZ_INVALID_HEADER");let r=n-2;if(r<0)throw new M("Invalid PUZ file: magic string found too early in file","PUZ_INVALID_HEADER");if(r+52>t.length)throw new M("Invalid PUZ file: insufficient data for header","PUZ_INVALID_HEADER");t.seek(r);let i=t.readUInt16LE(),o=t.readString(12,!0,"latin1"),s=t.readUInt16LE(),u=t.readUInt16LE(),l=t.readUInt16LE(),f=t.readString(4,!0,"latin1"),c=t.readUInt16LE(),a=t.readUInt16LE(),h=t.readBytes(12);t.readBytes(4);let g=t.readUInt8(),I=t.readUInt8(),b=t.readUInt16LE(),A=t.readUInt16LE(),U=t.readUInt16LE(),R={checksum:i,magic:o,cibChecksum:s,maskedLowChecksum:u,maskedHighChecksum:l,version:f,reserved1:c,scrambledChecksum:a,reserved2:h,width:g,height:I,numClues:b,puzzleType:A,scrambledTag:U};if(R.magic!==ie)throw new de("PUZ",`magic string mismatch after positioning. Expected "${ie}", got "${R.magic}"`);return R}function Pn(t,e,n,r){let i=[];for(let o=0;o<r;o++){let s=[];for(let u=0;u<n;u++){let l=o*n+u,f=t[l],c=e[l];s.push({solution:f==="."?void 0:f,playerState:c==="-"||c==="."?void 0:c,isBlack:f==="."})}i.push(s)}return i}function Rn(t){let e=new Map,n=1,r=t.length,i=t[0]?.length||0;for(let o=0;o<r;o++)for(let s=0;s<i;s++){if(t[o]?.[s]?.isBlack)continue;let u=(s===0||t[o]?.[s-1]?.isBlack)&&s<i-1&&!t[o]?.[s+1]?.isBlack,l=(o===0||t[o-1]?.[s]?.isBlack)&&o<r-1&&!t[o+1]?.[s]?.isBlack;(u||l)&&(u&&e.set(`A${o},${s}`,n),l&&e.set(`D${o},${s}`,n),n++)}return e}function Bn(t,e){let n=[],r=[],i=0,o=Array.from(e.entries()).sort((s,u)=>{let[l,f]=s[0].split(","),[c,a]=u[0].split(","),h=parseInt(l?.substring(1)||"0"),g=parseInt(c?.substring(1)||"0"),I=parseInt(f||"0"),b=parseInt(a||"0");return h!==g?h-g:I-b});for(let[s,u]of o)s.startsWith("A")&&i<t.length&&n.push({number:u,text:t[i++]||""});for(let[s,u]of o)s.startsWith("D")&&i<t.length&&r.push({number:u,text:t[i++]||""});return{across:n,down:r}}function Un(t,e){let n={};for(;t.hasMore()&&!(t.position+8>t.length);){for(;t.hasMore()&&t.buffer[t.position]===0;)t.readUInt8();if(t.position+8>t.length)break;let r=t.readString(4,!0,"latin1"),i=t.readUInt16LE();if(t.readUInt16LE(),i>t.length-t.position)break;let o=t.readBytes(i);switch(r){case ct:{let s=e.length,u=e[0]?.length||0;for(let l=0;l<s;l++)for(let f=0;f<u;f++){let c=l*u+f;if(c<o.length){let a=o[c];a&&a>0&&e[l]?.[f]&&(e[l][f].hasRebus=!0,e[l][f].rebusKey=a-1)}}break}case ft:{let u=o.toString("latin1").split(";");n.rebusTable=new Map;for(let l of u)if(l.includes(":")){let[f,c]=l.split(":"),a=Number.parseInt(f||"0",10);Number.isNaN(a)||n.rebusTable.set(a,c||"")}break}case ut:{let s=e.length,u=e[0]?.length||0;for(let l=0;l<s;l++)for(let f=0;f<u;f++){let c=l*u+f;if(c<o.length&&e[l]?.[f]){let a=o[c];a&&a&128&&(e[l][f].isCircled=!0)}}break}case lt:{let s=o.toString("latin1"),[u,l]=s.split(",");n.timer={elapsed:parseInt(u||"0")||0,running:l!=="0"};break}}}return n}function gt(t,e){let n;typeof t=="string"?n=m.Buffer.from(t,"base64"):t instanceof m.Buffer?n=t:n=m.Buffer.from(t);try{let r=new ge(n),i=Tn(r);if(i.width<=0||i.height<=0)throw new M(`Invalid puzzle dimensions: width=${i.width}, height=${i.height}`,"PUZ_INVALID_GRID");let o=e?.maxGridSize?.width??100,s=e?.maxGridSize?.height??100;if(i.width>o||i.height>s)throw new M(`Grid dimensions too large: ${i.width}x${i.height}. Maximum supported size is ${o}x${s}`,"PUZ_INVALID_GRID");let u=i.width*i.height,l=r.readString(u,!0,"latin1"),f=r.readString(u,!0,"latin1"),c=r.readNullTerminatedString("latin1"),a=r.readNullTerminatedString("latin1"),h=r.readNullTerminatedString("latin1"),g=[];for(let te=0;te<i.numClues;te++)g.push(r.readNullTerminatedString("latin1"));let I=r.readNullTerminatedString("latin1"),b=Pn(l,f,i.width,i.height),A=Rn(b),{across:U,down:R}=Bn(g,A),J=Un(r,b);return{width:i.width,height:i.height,metadata:{title:c||void 0,author:a||void 0,copyright:h||void 0,notes:I||void 0},grid:b,across:U,down:R,rebusTable:J.rebusTable,isScrambled:i.scrambledTag!==0,timer:J.timer}}catch(r){throw r instanceof O?new M(r.message,"PUZ_PARSE_ERROR"):r}}function mt(t){let e={width:t.width,height:t.height,cells:[]},n=1;for(let s=0;s<t.height;s++){let u=[];for(let l=0;l<t.width;l++){let f=t.grid[s]?.[l],c;f&&!f.isBlack&&((l===0||t.grid[s]?.[l-1]?.isBlack)&&l<t.width-1&&!t.grid[s]?.[l+1]?.isBlack||(s===0||t.grid[s-1]?.[l]?.isBlack)&&s<t.height-1&&!t.grid[s+1]?.[l]?.isBlack)&&(c=n++);let a={solution:f?.solution,number:c,isBlack:f?.isBlack||!1};f?.isCircled&&(a.isCircled=!0),f?.hasRebus&&(a.hasRebus=!0,f.rebusKey!==void 0&&(a.rebusKey=f.rebusKey)),u.push(a)}e.cells.push(u)}let r={across:t.across.map(s=>({number:s.number,text:s.text})),down:t.down.map(s=>({number:s.number,text:s.text}))},i={title:t.metadata.title,author:t.metadata.author,copyright:t.metadata.copyright,notes:t.metadata.notes,grid:e,clues:r,rebusTable:t.rebusTable},o={};return t.isScrambled&&(o.isScrambled=t.isScrambled),t.timer&&(o.timer=t.timer),Object.keys(o).length>0&&(i.additionalProperties=o),i}p();p();p();p();var wt=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD",Sn=wt+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",kn="["+wt+"]["+Sn+"]*",Fn=new RegExp("^"+kn+"$");function me(t,e){let n=[],r=e.exec(t);for(;r;){let i=[];i.startIndex=e.lastIndex-r[0].length;let o=r.length;for(let s=0;s<o;s++)i.push(r[s]);n.push(i),r=e.exec(t)}return n}var oe=function(t){let e=Fn.exec(t);return!(e===null||typeof e>"u")};function bt(t){return typeof t<"u"}var On={allowBooleanAttributes:!1,unpairedTags:[]};function _t(t,e){e=Object.assign({},On,e);let n=[],r=!1,i=!1;t[0]==="\uFEFF"&&(t=t.substr(1));for(let o=0;o<t.length;o++)if(t[o]==="<"&&t[o+1]==="?"){if(o+=2,o=It(t,o),o.err)return o}else if(t[o]==="<"){let s=o;if(o++,t[o]==="!"){o=Et(t,o);continue}else{let u=!1;t[o]==="/"&&(u=!0,o++);let l="";for(;o<t.length&&t[o]!==">"&&t[o]!==" "&&t[o]!==" "&&t[o]!==`
`&&t[o]!=="\r";o++)l+=t[o];if(l=l.trim(),l[l.length-1]==="/"&&(l=l.substring(0,l.length-1),o--),!Jn(l)){let a;return l.trim().length===0?a="Invalid space after '<'.":a="Tag '"+l+"' is an invalid name.",E("InvalidTag",a,N(t,o))}let f=zn(t,o);if(f===!1)return E("InvalidAttr","Attributes for '"+l+"' have open quote.",N(t,o));let c=f.value;if(o=f.index,c[c.length-1]==="/"){let a=o-c.length;c=c.substring(0,c.length-1);let h=xt(c,e);if(h===!0)r=!0;else return E(h.err.code,h.err.msg,N(t,a+h.err.line))}else if(u)if(f.tagClosed){if(c.trim().length>0)return E("InvalidTag","Closing tag '"+l+"' can't have attributes or invalid starting.",N(t,s));if(n.length===0)return E("InvalidTag","Closing tag '"+l+"' has not been opened.",N(t,s));{let a=n.pop();if(l!==a.tagName){let h=N(t,a.tagStartPos);return E("InvalidTag","Expected closing tag '"+a.tagName+"' (opened in line "+h.line+", col "+h.col+") instead of closing tag '"+l+"'.",N(t,s))}n.length==0&&(i=!0)}}else return E("InvalidTag","Closing tag '"+l+"' doesn't have proper closing.",N(t,o));else{let a=xt(c,e);if(a!==!0)return E(a.err.code,a.err.msg,N(t,o-c.length+a.err.line));if(i===!0)return E("InvalidXml","Multiple possible root nodes found.",N(t,o));e.unpairedTags.indexOf(l)!==-1||n.push({tagName:l,tagStartPos:s}),r=!0}for(o++;o<t.length;o++)if(t[o]==="<")if(t[o+1]==="!"){o++,o=Et(t,o);conti