Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@preserves/core

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@preserves/core - npm Package Compare versions

Comparing version 0.995.202 to 0.995.203

2

dist/preserves.es6.min.js

@@ -1,1 +0,1 @@

var t;!function(t){t[t.False=128]="False",t[t.True=129]="True",t[t.End=132]="End",t[t.Annotation=133]="Annotation",t[t.Embedded=134]="Embedded",t[t.Ieee754=135]="Ieee754",t[t.SignedInteger=176]="SignedInteger",t[t.String=177]="String",t[t.ByteString=178]="ByteString",t[t.Symbol=179]="Symbol",t[t.Record=180]="Record",t[t.Sequence=181]="Sequence",t[t.Set=182]="Set",t[t.Dictionary=183]="Dictionary"}(t||(t={}));var e=Object.freeze({__proto__:null,get Tag(){return t}});const n={};function r(t){const e=new Uint8Array(Math.floor(3*t.length/4));let r=0,s=0;for(;r<t.length;){const i=n[t[r++]],o=n[t[r++]],a=n[t[r++]],u=n[t[r++]],c=i<<18|o<<12|a<<6|u;if(e[s++]=c>>16&255,void 0===a)break;if(e[s++]=c>>8&255,void 0===u)break;e[s++]=255&c}return e.subarray(0,s)}[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"].forEach(((t,e)=>n[t]=e)),n["+"]=n["-"]=62,n["/"]=n._=63;const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(t){let e="",n=0,r=0;for(let i of t)for(n=(63&n)<<8|i,r+=8;r>=6;){r-=6;e+=s[n>>r&63]}if(r>0){e+=s[n<<6-r&63]}return e}const o=new TextEncoder,a=new TextDecoder("utf-8",{fatal:!0}),u=Symbol.for("IsPreservesBytes");class c{constructor(t=new Uint8Array){if(c.isBytes(t))this._view=t._view;else if(ArrayBuffer.isView(t))this._view=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else if(t instanceof ArrayBuffer)this._view=new Uint8Array(t);else if("string"==typeof t)this._view=o.encode(t);else if("number"==typeof t)this._view=new Uint8Array(t);else{if("number"!=typeof t.length)throw new TypeError("Attempt to initialize Bytes from unsupported value: "+t);this._view=Uint8Array.from(t)}}dataview(){return new DataView(this._view.buffer,this._view.byteOffset,this._view.byteLength)}get length(){return this._view.length}static from(t){return new c(t)}static of(...t){return new c(Uint8Array.of(...t))}static fromLatin1(t){const e=new c(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>=256)throw new Error("Codepoint out of range for 'latin1' byte encoding");e._view[n]=r}return e}static fromBase64(t){return new c(r(t))}static fromHex(t){if(1&t.length)throw new Error("Cannot decode odd-length hexadecimal string");const e=new c(t.length>>1);return c._raw_fromHexInto(t,e._view),e}static _raw_fromHexInto(t,e){const n=t.length>>1;for(let r=0;r<n;r++)e[r]=l(t.charCodeAt(r<<1))<<4|l(t.charCodeAt(1+(r<<1)))}static fromIO(t){return"string"==typeof t||c.isBytes(t)?t:new c(t)}static toIO(t){return"string"==typeof t?t:c.isBytes(t)?t._view:t}get(t){return this._view[t]}equals(t){if(!c.isBytes(t))return!1;if(t.length!==this.length)return!1;const e=this._view,n=t._view;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}hashCode(){const t=this._view;let e=0;for(let n=0;n<t.length;n++)e=31*e+t[n]|0;return e}static compare(t,e){return t<e?-1:e<t?1:0}static decodeUtf8(t){return a.decode(d(t))}fromUtf8(){return a.decode(this._view)}__as_preserve__(){return this}static __from_preserve__(t){return c.isBytes(t)?t:void 0}toLatin1(){return String.fromCharCode.apply(null,this._view)}toBase64(){return i(this._view)}toHex(t=h){var e=[];for(let n=0;n<this.length;n++)e.push(t(this._view[n]>>4)),e.push(t(15&this._view[n]));return e.join("")}valueOf(){return this.toHex()}__preserve_on__(e){e.state.emitbyte(t.ByteString),e.state.varint(this.length),e.state.emitbytes(this._view)}__preserve_text_on__(t){t.state.writeBytes(this._view)}get[u](){return!0}static isBytes(t){return!!(null==t?void 0:t[u])}}function h(t){return"0123456789abcdef"[t]}function l(t,e=Error){if(t>=48&&t<=57)return t-48;if(t>=97&&t<=102)return t-97+10;if(t>=65&&t<=70)return t-65+10;throw new e("Invalid hex digit: "+String.fromCharCode(t))}function d(t){return t instanceof Uint8Array?t:t._view}function f(t){return t instanceof DataView?t:t.dataview()}c.concat=function(t){let e=0;for(let n=0;n<t.length;n++)e+=d(t[n]).length;const n=new c(e);let r=0;for(let e=0;e<t.length;e++){const s=d(t[e]);n._view.set(s,r),r+=s.length}return n},function(){for(const t of"entries every find findIndex forEach includes indexOf join\nkeys lastIndexOf reduce reduceRight some toLocaleString values".split(/\s+/))c.prototype[t]=function(...e){return this._view[t](...e)};for(const t of"filter map slice subarray".split(/\s+/))c.prototype[t]=function(...e){return new c(this._view[t](...e))};for(const t of"reverse sort".split(/\s+/))c.prototype[t]=function(...e){return new c(this._view.slice()[t](...e))};c.prototype[Symbol.iterator]=function(){return this._view[Symbol.iterator]()}}();const p=Symbol.for("ErrorType");class m{static isCodecError(t,e){return(null==t?void 0:t[p])===e}}class y extends Error{get[p](){return"DecodeError"}constructor(t,e){super(t),this.pos=e}static isDecodeError(t){return m.isCodecError(t,"DecodeError")}}class b extends Error{get[p](){return"EncodeError"}static isEncodeError(t){return m.isCodecError(t,"EncodeError")}constructor(t,e){super(t),this.irritant=e}}class w extends y{get[p](){return"ShortPacket"}static isShortPacket(t){return m.isCodecError(t,"ShortPacket")}}function g(t,e){return e.label=t,e}!function(t){t.isRecord=function(t){return Array.isArray(t)&&"label"in t},t.constructorInfo=function(t){return{label:t.label,arity:t.length}},t.isClassOf=function(e,n){return t.isRecord(n)&&ct(e.label,n.label)&&e.arity===n.length},t.makeConstructor=function(){return(e,n)=>{const r=(...n)=>t(e,n),s={label:e,arity:n.length};return r.constructorInfo=s,r.isClassOf=e=>t.isClassOf(s,e),r.fieldNumbers={},r._={},n.forEach(((t,e)=>{r._[t]=t=>t[e],r.fieldNumbers[t]=e})),r}}}(g||(g={}));const v=Symbol.for("IsEmbedded");function x(t){return!!(null==t?void 0:t[v])}let _=class{get[v](){return!0}constructor(t){this.value=t}equals(t){return"object"==typeof t&&"value"in t&&Object.is(this.value,t.value)}};class S{get[v](){return!0}constructor(t){this.generic=t}equals(t,e){return"object"==typeof t&&"generic"in t&&e(this.generic,t.generic)}toString(){return this.generic.toString()}}function k(t){return"object"==typeof t&&null!==t&&"__preserve_on__"in t&&"function"==typeof t.__preserve_on__}function E(t){return String.fromCharCode.apply(null,t)}let A=0;const j=new WeakMap;function C(t){let e=j.get(t);return void 0===e&&(e=A++,j.set(t,e)),e}const B={encode(t,e){new D(t,this).push(C(e))}};class I{constructor(t){this.chunks=[],this.view=new DataView(new ArrayBuffer(256)),this.index=0,this.options=t}get canonical(){var t;return null===(t=this.options.canonical)||void 0===t||t}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t?t:!this.canonical}contents(){if(0===this.chunks.length){const t=this.index;return this.index=0,new c(this.view.buffer.slice(0,t))}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],c.concat(t)}}contentsString(){if(0===this.chunks.length){const t=E(new Uint8Array(this.view.buffer,0,this.index));return this.index=0,t}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],t.map(E).join("")}}rotatebuffer(t){this.chunks.push(new Uint8Array(this.view.buffer,0,this.index)),this.view=new DataView(new ArrayBuffer(t)),this.index=0}makeroom(t){this.index+t>this.view.byteLength&&this.rotatebuffer(t+4096)}emitbyte(t){this.makeroom(1),this.view.setUint8(this.index++,t)}emitbytes(t){this.makeroom(t.length),new Uint8Array(this.view.buffer).set(t,this.index),this.index+=t.length}claimbytes(t){this.makeroom(t);const e=new Uint8Array(this.view.buffer,this.index,t);return this.index+=t,e}varint(t){for(;t>=128;)this.emitbyte(t%128+128),t=Math.floor(t/128);this.emitbyte(t)}encodeint(e){if("bigint"==typeof e)return this.encodebigint(e);if(this.emitbyte(t.SignedInteger),0===e)return void this.emitbyte(0);const n=(-1===e?0:Math.floor(Math.log2(e>0?e:-(1+e)))+1)+1+7>>3;this.varint(n);const r=(t,e)=>{t>0&&(r(t-1,Math.floor(e/256)),this.emitbyte(255&e))};r(n,e)}encodebigint(e){let n;if(this.emitbyte(t.SignedInteger),e>0)n=e.toString(16),1&n.length?n="0"+n:l(n.charCodeAt(0))>=8&&(n="00"+n);else{if(!(e<0))return void this.emitbyte(0);{const t=(~e).toString(16);n="";for(let e=0;e<t.length;e++)n+="fedcba9876543210"[l(t.charCodeAt(e))];1&n.length?n="f"+n:l(n.charCodeAt(0))<8&&(n="ff"+n)}}this.varint(n.length>>1),c._raw_fromHexInto(n,this.claimbytes(n.length>>1))}encodebytes(t,e){this.emitbyte(t),this.varint(e.length),this.emitbytes(e)}}class D{constructor(t={},e){var n;t instanceof I?(this.state=t,this.embeddedEncode=null!=e?e:B):(this.state=new I(t),this.embeddedEncode=null!==(n=t.embeddedEncode)&&void 0!==n?n:B)}withEmbeddedEncode(t,e){return e(new D(this.state,t)),this}get canonical(){return this.state.canonical}get includeAnnotations(){return this.state.includeAnnotations}contents(){return this.state.contents()}contentsString(){return this.state.contentsString()}grouped(e,n){this.state.emitbyte(e),n(),this.state.emitbyte(t.End)}push(e){if(k(e))e.__preserve_on__(this);else if(k(e))e.__preserve_on__(this);else if("boolean"==typeof e)this.state.emitbyte(e?t.True:t.False);else if("number"==typeof e||"bigint"==typeof e)this.state.encodeint(e);else if("string"==typeof e)this.state.encodebytes(t.String,new c(e)._view);else if("symbol"==typeof e){const n=Symbol.keyFor(e);if(void 0===n)throw new b("Cannot preserve non-global Symbol",e);this.state.encodebytes(t.Symbol,new c(n)._view)}else if(ArrayBuffer.isView(e))if(e instanceof Uint8Array)this.state.encodebytes(t.ByteString,e);else{const n=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);this.state.encodebytes(t.ByteString,n)}else if(g.isRecord(e)){this.state.emitbyte(t.Record),this.push(e.label);for(let t of e)this.push(t);this.state.emitbyte(t.End)}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(e)?x(e)?(this.state.emitbyte(t.Embedded),this.embeddedEncode.encode(this.state,e)):tt(new Q(e),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.grouped(t.Sequence,(()=>{for(let t of e)this.push(t)}));return this}}function O(t,e={}){return new D(e).push(t).contents()}const q=new D({canonical:!0});let M=!1;function V(t,e){if(void 0!==e||M)return O(t,Object.assign(Object.assign({},e),{canonical:!0}));{M=!0;const e=q.push(t).contents();return M=!1,e}}function U(t){if(M)return new D({canonical:!0}).push(t).contentsString();{M=!0;const e=q.push(t).contentsString();return M=!1,e}}function P(t,e={}){return O(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const N=Map,T=Set,F=Symbol.for("IsMap"),R=Symbol.for("IsSet");function z(t,e){const n=t=>t.done?{done:!0,value:null}:{done:!1,value:e(t.value)};return{next:e=>n(t.next(e)),return:e=>{var r,s;return n(null!==(s=null===(r=t.return)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},throw:e=>{var r,s;return n(null!==(s=null===(r=t.throw)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},[Symbol.iterator](){return this}}}F in Map.prototype||(Object.defineProperty(Map.prototype,F,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[F])),R in Set.prototype||(Object.defineProperty(Set.prototype,R,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[R]));class H{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(z(e[Symbol.iterator](),(([t,e])=>[this._key(t),[t,e]])))}_key(t){return this.canonicalizer(t)}get(t,e){const n=this.items.get(this._key(t));return void 0===n?e:n[1]}getOrSet(t,e){const n=this._key(t);let r=this.items.get(n);return void 0===r&&(r=[t,e()],this.items.set(n,r)),r[1]}set(t,e){return this.items.set(this._key(t),[t,e]),this}forEach(t,e){this.items.forEach((([n,r])=>t.call(e,r,n,this)))}entries(){return this.items.values()}keys(){return z(this.items.values(),(([t,e])=>t))}values(){return z(this.items.values(),(([t,e])=>e))}delete(t){return this.items.delete(this._key(t))}getAndDelete(t,e){const n=this._key(t),r=this.items.get(n);return void 0===r?e:(this.items.delete(n),r[1])}clear(){this.items.clear()}has(t){return this.items.has(this._key(t))}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexMap"}equals(t,e=((t,e)=>t===e)){if(!("size"in t&&"has"in t&&"get"in t))return!1;if(this.size!==t.size)return!1;for(let[n,r]of this.items.values()){if(!t.has(n))return!1;if(!e(r,t.get(n)))return!1}return!0}update(t,e,n,r=((t,e)=>t===e)){const s=this._key(t);if(this.items.has(s)){const n=this.items.get(s)[1],i=e(n);return void 0===i?(this.items.delete(s),-1):(r(i,n)||this.items.set(s,[t,i]),0)}{const r=e(n);return void 0===r?0:(this.items.set(s,[t,r]),1)}}canonicalKeys(){return this.items.keys()}get[F](){return!0}}class L{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(z(e[Symbol.iterator](),(t=>[this._key(t),t])))}_key(t){return this.canonicalizer(t)}has(t){return this.items.has(this._key(t))}get(t){const e=this._key(t);return this.items.has(e)?{item:this.items.get(e)}:null}add(t){return this.items.set(this._key(t),t),this}forEach(t,e){this.items.forEach((n=>t.call(e,n,n,this)))}entries(){return z(this.items.values(),(t=>[t,t]))}keys(){return this.items.values()}values(){return this.items.values()}delete(t){return this.items.delete(this._key(t))}clear(){this.items.clear()}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexSet"}equals(t){if(!("size"in t)||!("has"in t))return!1;if(this.size!==t.size)return!1;for(let e of this.items.values())if(!t.has(e))return!1;return!0}canonicalValues(){return this.items.keys()}union(t){const e=new L(this.canonicalizer,this);for(let n of t)e.add(n);return e}intersect(t){const e=new L(this.canonicalizer);for(let n of this)t.has(n)&&e.add(n);return e}subtract(t){const e=new L(this.canonicalizer);for(let n of this)t.has(n)||e.add(n);return e}get[R](){return!0}}var W;function $(t){return ft.isAnnotated(t)?t.item:t}function G(t){return K(t,1)}function K(t,e=1/0){return function t(e,n){if(0===n)return e;if(!ft.isAnnotated(e))return e;const r=n-1;function s(e){return t(e,r)}if(g.isRecord(e.item))return g(t(e.item.label,n),e.item.map(s));if(ft.isAnnotated(e.item))throw new Error("Improper annotation structure");if(0===r)return e.item;if(Array.isArray(e.item))return e.item.map(s);if(st.isSet(e.item))return e.item.map(s);if(Y.isDictionary(e.item)){const t=new Q;return new Q(e.item).forEach(((e,n)=>t.set(s(n),s(e)))),t.simplifiedValue()}return e.item}(t,e)}!function(t){function e(t,e){return t[e.description]}function n(t,e){return Object.hasOwnProperty.call(t,e.description)}function r(t){return Object.keys(t).length}function s(t){return z(Object.entries(t).values(),(([t,e])=>[Symbol.for(t),e]))}t.isJsDictionary=function(t){return"object"==typeof t&&null!==t&&null===Object.getPrototypeOf(Object.getPrototypeOf(t))&&"function"!=typeof t.__as_preserve__},t.from=function(t){const e={};for(const[n,r]of t)e[n.description]=r;return e},t.clear=function(t){for(const e in t)delete t[e]},t.remove=function(t,e){const r=n(t,e);return delete t[e.description],r},t.forEach=function(t,e){Object.entries(t).forEach((([t,n])=>e(n,Symbol.for(t))))},t.get=e,t.has=n,t.set=function(t,e,n){return t[e.description]=n,t},t.size=r,t.entries=s,t.keys=function(t){return z(Object.keys(t).values(),(t=>Symbol.for(t)))},t.values=function(t){return Object.values(t).values()},t.clone=function(t){const e={};return Object.keys(t).forEach((n=>e[n]=t[n])),e},t.equals=function(t,i,o=((t,e)=>t===e)){if(r(t)!==r(i))return!1;for(let[r,a]of s(t)){if(!n(i,r))return!1;if(!o(a,e(i,r)))return!1}return!0}}(W||(W={}));const J=Symbol.for("DictionaryType");class X extends H{constructor(t,e,n){super((e=>U(t(e))),n),this.encodeK=t,this.encodeV=e}__preserve_on__(t){tt(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){et(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}}class Z extends X{get[J](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[J])}constructor(t){super((t=>t),(t=>t),t)}clone(){return new Z(this)}get[Symbol.toStringTag](){return"Dictionary"}equals(t,e=((t,e)=>t===e)){const n=Y.asMap(t);return!!n&&super.equals(n,e)}}class Q{get[F](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):J in t?(this.j=void 0,this.k=t):(this.j=t,this.k=void 0)}static from(t){const e=new Q;for(const[n,r]of t)e.set(n,r);return e}clear(){this.j?W.clear(this.j):this.k.clear()}delete(t){return this.j?"symbol"==typeof(t=$(t))&&W.remove(this.j,t):this.k.delete(t)}forEach(t,e){this.j?W.forEach(this.j,((n,r)=>t.call(e,n,r,this))):this.k.forEach(t,e)}get(t){if(this.j){if("symbol"!=typeof(t=$(t)))return;return W.get(this.j,t)}return this.k.get(t)}has(t){return this.j?"symbol"==typeof(t=$(t))&&W.has(this.j,t):this.k.has(t)}set(t,e){if(this.j){if("symbol"==typeof t)return W.set(this.j,t,e),this;this.k=new Z(W.entries(this.j)),this.j=void 0}return this.k.set(t,e),this}get size(){return this.j?W.size(this.j):this.k.size}entries(){return this.j?W.entries(this.j):this.k.entries()}keys(){return this.j?W.keys(this.j):this.k.keys()}values(){return this.j?W.values(this.j):this.k.values()}[Symbol.iterator](){return this.entries()}get[Symbol.toStringTag](){return"DictionaryMap"}clone(){return new Q(this.j?W.clone(this.j):this.k.clone())}get value(){var t;return null!==(t=this.j)&&void 0!==t?t:this.k}simplify(){if(!this.j){const t={};for(const[e,n]of this.k.entries()){if("symbol"!=typeof e)return;t[e.description]=n}this.j=t,this.k=void 0}}simplifiedValue(){return this.simplify(),this.value}asJsDictionary(){if(this.simplify(),!this.j)throw new Error("Cannot represent general dictionary as JsDictionary");return this.j}asKeyedDictionary(){var t;return null!==(t=this.k)&&void 0!==t?t:new Z(W.entries(this.j))}}var Y;function tt(e,n,r,s){if(n.canonical){const i=Array.from(e),o=new D({canonical:!0,embeddedEncode:n.embeddedEncode}),a=i.map((([t,e],n)=>(r(t,o),[o.contents(),n])));a.sort(((t,e)=>c.compare(t[0],e[0]))),n.grouped(t.Dictionary,(()=>a.forEach((([t,e])=>{const[o,a]=i[e];r(o,n),s(a,n)}))))}else n.grouped(t.Dictionary,(()=>e.forEach(((t,e)=>{r(e,n),s(t,n)}))))}function et(t,e,n,r){e.state.writeSeq("{","}",t.entries(),(([t,s])=>{n(t,e),ft.isAnnotated(s)&&mt(s).length>1&&e.state.isIndenting?(e.state.pieces.push(":"),e.state.indentCount++,e.state.writeIndent(),r(s,e),e.state.indentCount--):(e.state.pieces.push(": "),r(s,e))}))}!function(t){function e(t){if("object"!=typeof t||null===t)return!1;switch(t[J]){case"Dictionary":return!0;case void 0:return W.isJsDictionary(t);default:return!1}}t.isDictionary=e,t.asMap=function(t){return e(t)?new Q(t):void 0},t.from=function(t){return Q.from(t).simplifiedValue()},t.__from_preserve__=function(e){return t.isDictionary(e)?e:void 0}}(Y||(Y={}));class nt extends L{constructor(t,e){super((e=>U(t(e))),e),this.encodeV=t}__preserve_on__(t){it(this,t,((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){ot(this,t,((t,e)=>e.push(this.encodeV(t))))}}class rt extends nt{get[J](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[J])}constructor(t){super((t=>t),t)}map(t){return new rt(z(this[Symbol.iterator](),t))}filter(t){const e=new rt;for(let n of this)t(n)&&e.add(n);return e}clone(){return new rt(this)}get[Symbol.toStringTag](){return"Set"}}let st=class t extends rt{static isSet(t){return"Set"===(null==t?void 0:t[J])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function it(e,n,r){if(n.canonical){const s=new D({canonical:!0,embeddedEncode:n.embeddedEncode}),i=Array.from(e).map((t=>(r(t,s),[s.contents(),t])));i.sort(((t,e)=>c.compare(t[0],e[0]))),n.grouped(t.Set,(()=>i.forEach((([t,e])=>r(e,n)))))}else n.grouped(t.Set,(()=>e.forEach((t=>r(t,n)))))}function ot(t,e,n){e.state.writeSeq("#{","}",t,(t=>n(t,e)))}const at=Symbol.for("IsPreservesAnnotated");function ut(t){return!!(null==t?void 0:t[at])}function ct(t,e){if(ut(t)&&(t=t.item),ut(e)&&(e=e.item),Object.is(t,e))return!0;if(typeof t!=typeof e)return("number"==typeof t&&"bigint"==typeof e||"bigint"==typeof t&&"number"==typeof e)&&t==e;if("object"==typeof t){if(null===t||null===e)return!1;if("equals"in t&&"function"==typeof t.equals)return t.equals(e,ct);if(Array.isArray(t)&&Array.isArray(e)){const n="label"in t;if(n!=="label"in e)return!1;if(n&&!ct(t.label,e.label))return!1;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!ct(t[n],e[n]))return!1;return!0}{const n=Y.asMap(t),r=Y.asMap(e);if(!n||!r)return!1;if(n.size!==r.size)return!1;for(const t of n.keys()){if(!r.has(t))return!1;if(!ct(n.get(t),r.get(t)))return!1}return!0}}return!1}function ht(t){return{line:1,column:0,pos:0,name:t}}function lt(t,e){if(t.pos++,void 0===t.line)return!1;{let n=!1;switch(e){case"\t":t.column=t.column+8&-8;break;case"\n":t.column=0,t.line++,n=!0;break;case"\r":t.column=0;break;default:t.column++}return n}}function dt(t){var e,n,r;return null===t?"<unknown>":"string"==typeof t?t:`${null!==(e=t.name)&&void 0!==e?e:""}:${null!==(n=t.line)&&void 0!==n?n:""}:${null!==(r=t.column)&&void 0!==r?r:""}:${t.pos}`}class ft{constructor(t,e){this.annotations=[],this.pos=null!=e?e:null,this.item=t}__as_preserve__(){return this}static __from_preserve__(t){return ut(t)?t:void 0}__preserve_on__(e){if(e.includeAnnotations)for(const n of this.annotations)e.state.emitbyte(t.Annotation),e.push(n);e.push(this.item)}__preserve_text_on__(t){if(t.includeAnnotations){const e=this.annotations.length<=1;for(const n of this.annotations)t.state.pieces.push("@"),t.push(n),e?t.state.pieces.push(" "):t.state.writeIndentSpace()}t.push(this.item)}equals(t){return ct(this.item,ft.isAnnotated(t)?t.item:t)}get[at](){return!0}static isAnnotated(t){return ut(t)}}function pt(t,...e){const n=ft.isAnnotated(t)?t:new ft(t);return e.forEach((t=>n.annotations.push(t))),n}function mt(t){return ft.isAnnotated(t)?t.annotations:[]}function yt(t){return ft.isAnnotated(t)?t.pos:null}function bt(t){return Array.isArray(t)||st.isSet(t)||Y.isDictionary(t)}function wt(t){return Array.isArray(t)&&!("label"in t)}const gt=Symbol.for("FloatType");class vt{constructor(t){this.value="number"==typeof t?t:t.value}__preserve_text_on__(t){t.state.pieces.push(this.toString())}equals(t){return!!Object.is(t.constructor,this.constructor)&&(Number.isNaN(this.value)&&Number.isNaN(t.value)?t.toBytes().equals(this.toBytes()):Object.is(t.value,this.value))}hashCode(){return 0|this.value}}function xt(t){return"number"==typeof t?t:vt.isFloat(t)?t.value:NaN}function _t(t){if(Object.is(t,-0))return"-0.0";const e=""+t;return e.includes(".")||e.includes("e")||e.includes("E")?e:e+".0"}vt.isFloat=t=>void 0!==(null==t?void 0:t[gt]),vt.isDouble=t=>"Double"===(null==t?void 0:t[gt]);class St extends vt{__as_preserve__(){return this}static fromBytes(t){return new St(f(t).getFloat64(0,!1))}static __from_preserve__(t){return vt.isDouble(t)?t:void 0}__preserve_on__(e){e.state.emitbyte(t.Ieee754),e.state.emitbyte(8),e.state.makeroom(8),e.state.view.setFloat64(e.state.index,this.value,!1),e.state.index+=8}toBytes(){const t=new c(8);return t.dataview().setFloat64(0,this.value,!1),t}toString(){return Number.isFinite(this.value)?_t(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[gt](){return"Double"}}function kt(t){return new St(t)}const Et=BigInt(Number.MAX_SAFE_INTEGER),At=BigInt(Number.MIN_SAFE_INTEGER),jt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class Ct{constructor(t,e){switch(this.discarded=0,this.buffer=t,typeof e.name){case"undefined":this.pos=ht();break;case"string":this.pos=ht(e.name);break;case"object":this.pos=Object.assign({},e.name)}this.index=0,this.options=e}error(t,e){throw new y(t,Object.assign({},e))}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}copyPos(){return Object.assign({},this.pos)}write(t){this.atEnd()?this.buffer=t:this.buffer=this.buffer.substring(this.index)+t,this.discarded+=this.index,this.index=0}atEnd(){return this.index>=this.buffer.length}peek(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.index]}advance(){const t=this.index++;return lt(this.pos,this.buffer[t]),t}nextchar(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.advance()]}nextcharcode(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer.charCodeAt(this.advance())}skipws(t=!1){for(;!this.atEnd();){const e=this.peek();if(!(Ot(e)||t&&","===e))break;this.advance()}}readHex2(){return l(this.nextcharcode(),y)<<4|l(this.nextcharcode(),y)}readHex4(){return l(this.nextcharcode(),y)<<12|l(this.nextcharcode(),y)<<8|l(this.nextcharcode(),y)<<4|l(this.nextcharcode(),y)}readHexBinary(){const t=[];for(;;){if(this.skipws(),'"'===this.peek())return this.advance(),c.from(t);t.push(this.readHex2())}}readHexFloat(){const t=this.copyPos();'"'!==this.nextchar()&&this.error("Missing open-double-quote in hex-encoded floating-point number",t);const e=this.readHexBinary();return 8!==e.length&&this.error("Incorrect number of bytes in hex-encoded Double",t),St.fromBytes(e)}readBase64Binary(){let t="";for(;;){this.skipws();const e=this.nextchar();if("]"===e)break;t+=e}return c.fromBase64(t)}requireDelimiter(t){this.delimiterFollows()||this.error(`Delimiter must follow ${t}`,this.pos)}delimiterFollows(){if(this.atEnd())return!0;const t=this.peek();return-1!=='(){}[]<>";,@#:|'.indexOf(t)||Ot(t)}readRawSymbolOrNumber(t){for(;!this.delimiterFollows();)t+=this.nextchar();const e=jt.exec(t);if(e){if(void 0===e[2]){let t=BigInt(e[1]);return t<=At||t>=Et?t:Number(t)}return kt(parseFloat(t))}return Symbol.for(t)}readStringlike(t,e,n,r,s){let i=[];for(;;){const o=this.nextchar();switch(o){case n:return e(i);case"\\":{const e=this.nextchar();switch(e){case r:i.push(s());break;case n:case"\\":case"/":i.push(t(e));break;case"b":i.push(t("\b"));break;case"f":i.push(t("\f"));break;case"n":i.push(t("\n"));break;case"r":i.push(t("\r"));break;case"t":i.push(t("\t"));break;default:this.error(`Invalid escape code \\${e}`,this.pos)}break}default:i.push(t(o))}}}readString(t){return this.readStringlike((t=>t),(t=>t.join("")),t,"u",(()=>{const t=this.readHex4();if(t>=55296&&t<=57343){if("\\"===this.nextchar()&&"u"===this.nextchar()){const e=this.readHex4();if(e>=56320&&e<=57343&&t<=56319)return String.fromCharCode(t,e)}this.error("Invalid surrogate pair",this.pos)}return String.fromCharCode(t)}))}readLiteralBinary(){return this.readStringlike((t=>{const e=t.charCodeAt(0);return e>=256&&this.error(`Invalid code point ${e} in literal binary`,this.pos),e}),c.from,'"',"x",(()=>this.readHex2()))}readCommentLine(){let t="";for(;;){const e=this.nextchar();if("\n"===e||"\r"===e)return t;t+=e}}}const Bt={decode(t){return new S(new Kt(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:K(t))};class It{constructor(t="",e){var n,r;if(t instanceof Ct)this.state=t,this.embeddedType=e;else{const s=null!==(n=e)&&void 0!==n?n:{};this.state=new Ct(t,s),this.embeddedType=null!==(r=s.embeddedDecode)&&void 0!==r?r:Gt}}write(t){this.state.write(t)}}let Dt=class t extends It{readCommentLine(){const t=this.state.copyPos();return this.wrap(this.state.readCommentLine(),t)}wrap(t,e){return this.state.includeAnnotations&&!ft.isAnnotated(t)&&(t=new ft(t,e)),t}annotateNextWith(t){if(this.state.skipws(),this.state.atEnd())throw new y("Trailing annotations and comments are not permitted",this.state.pos);const e=this.next();return this.state.includeAnnotations&&e.annotations.unshift(t),e}readToEnd(){const t=[];for(;;){if(this.state.skipws(),this.state.atEnd())return t;t.push(this.next())}}next(){this.state.skipws();const e=this.state.copyPos(),n=(()=>{const n=this.state.nextchar();switch(n){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",e);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",e);case"#":{const n=this.state.nextchar();switch(n){case" ":case"\t":return this.annotateNextWith(this.readCommentLine());case"\n":case"\r":return this.annotateNextWith("");case"!":return this.annotateNextWith(g(Symbol.for("interpreter"),[this.readCommentLine()]));case"f":return this.state.requireDelimiter("#f"),!1;case"t":return this.state.requireDelimiter("#t"),!0;case"{":return this.readSet();case'"':return this.state.readLiteralBinary();case"x":switch(this.state.nextchar()){case'"':return this.state.readHexBinary();case"d":return this.state.readHexFloat();default:this.state.error("Invalid #x syntax",e)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new t(this.state,Bt).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${n}`,e)}}case"<":return g(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",e);case"]":this.state.error("Unexpected ]",e);case"}":this.state.error("Unexpected }",e);case",":this.state.error("Unexpected ,",e);default:return this.state.readRawSymbolOrNumber(n)}})();return this.wrap(n,e)}seq(t,e,n,r){for(;;){if(this.state.skipws(t),this.state.peek()===r)return this.state.advance(),e;n(this.next(),e)}}readSequence(t,e){return this.seq(e,[],((t,e)=>e.push(t)),t)}readDictionary(){return this.seq(!0,new Q,((t,e)=>{if(this.state.skipws(),":"===this.state.peek())this.state.advance(),e.has(t)&&this.state.error(`Duplicate key: ${Ht(t)}`,this.state.pos),e.set(t,this.next());else this.state.error("Missing key/value separator",this.state.pos)}),"}").simplifiedValue()}readSet(){return this.seq(!0,new st,((t,e)=>{e.has(t)&&this.state.error(`Duplicate value in set: ${Ht(t)}`,this.state.pos),e.add(t)}),"}")}};function Ot(t){return-1!==" \t\n\r".indexOf(t)}function qt(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const Mt={encode(t,e){new D(t,this).push(e.generic)},toValue:t=>t.generic},Vt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class Ut{constructor(t){var e;this.pieces=[],this.indentCount=0,this.options=t,this.indentDelta=" ".repeat(null!==(e=t.indent)&&void 0!==e?e:0)}get isIndenting(){return this.indentDelta.length>0}get includeAnnotations(){var t;return null===(t=this.options.includeAnnotations)||void 0===t||t}writeIndent(){if(this.isIndenting){this.pieces.push("\n");for(let t=0;t<this.indentCount;t++)this.pieces.push(this.indentDelta)}}writeIndentSpace(){this.isIndenting?this.writeIndent():this.pieces.push(" ")}escapeStringlikeChar(t,e=(t=>t)){switch(t){case"\\":return"\\\\";case"\b":return"\\b";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";default:return e(t)}}escapeStringlike(t,e){let n=e;for(let r of t)n+=r===e?"\\"+e:this.escapeStringlikeChar(r);return n+e}writeSeq(t,e,n,r){let s=n[Symbol.iterator]();this.pieces.push(t);const i=s.next();if(!0!==i.done){const t=i.value,e=s.next();if(!0===e.done)r(t);else{let n;for(this.indentCount++,this.writeIndent(),r(t),this.writeIndentSpace(),r(e.value);!0!==(n=s.next()).done;)this.writeIndentSpace(),r(n.value);this.indentCount--,this.writeIndent()}}this.pieces.push(e)}writeBytes(t){var e,n;const r=null!==(e=this.options.maxBinaryAsciiLength)&&void 0!==e?e:1024,s=null!==(n=this.options.maxBinaryAsciiProportion)&&void 0!==n?n:.75;if(t.length>=r)this.writeBase64(t);else{let e=0,n=Math.min(t.length,r);for(let r=0;r<n;r++){const n=t[r];switch(n){case 9:case 10:case 13:e++;break;default:n>=32&&n<=126&&e++}}0===n||e/n>=s?this.writeBinaryStringlike(t):this.writeBase64(t)}}writeBase64(t){this.pieces.push("#[",i(t),"]")}writeBinaryStringlike(t){let e='#"';for(let n of t)e+=34===n?'\\"':this.escapeStringlikeChar(String.fromCharCode(n),(t=>n>=32&&n<=126&&92!==n?t:"\\x"+("0"+n.toString(16)).slice(-2)));this.pieces.push(e+'"')}couldBeFlat(t){let e=!1;for(let n of t){if(Array.isArray(n)||Set.isSet(n)||Map.isMap(n)){if(e)return!1;e=!0}if(this.includeAnnotations&&ut(n)&&n.annotations.length>1)return!1}return!0}}class Pt{constructor(t={},e){var n;t instanceof Ut?(this.state=t,this.embeddedWrite=e):(this.state=new Ut(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:Vt)}static stringify(t,e){const n=new Pt(e);return n.push(t),n.contents()}contents(){return this.state.pieces.join("")}get includeAnnotations(){return this.state.includeAnnotations}push(t){switch(typeof t){case"boolean":this.state.pieces.push(t?"#t":"#f");break;case"string":this.state.pieces.push(this.state.escapeStringlike(t,'"'));break;case"symbol":{const e=t.description;/^[-a-zA-Z0-9~!$%^&*?_=+/.]+$/.exec(e)&&!jt.exec(e)?this.state.pieces.push(e):this.state.pieces.push(this.state.escapeStringlike(e,"|"));break}case"bigint":case"number":this.state.pieces.push(""+t);break;case"object":if(null===t)throw new Error("Cannot encode null in Preserves Writer.push");if(qt(t))t.__preserve_text_on__(this);else if(qt(t))t.__preserve_text_on__(this);else if(ArrayBuffer.isView(t))if(t instanceof Uint8Array)this.state.writeBytes(t);else{const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.state.writeBytes(e)}else if(g.isRecord(t)){const e=this.state.couldBeFlat(t);this.state.pieces.push("<"),this.push(t.label),e||this.state.indentCount++;for(let n of t)e?this.state.pieces.push(" "):this.state.writeIndentSpace(),this.push(n);e||this.state.indentCount--,this.state.pieces.push(">")}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(t)?x(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new Pt(this.state,Mt).push(this.embeddedWrite.toValue(t))):et(new Q(t),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.state.writeSeq("[","]",t,(t=>this.push(t)));break;default:(e=>{throw new Error(`Internal error: unhandled in Preserves Writer.push for ${t}`)})()}return this}}function Nt(t){return Tt(t)}function Tt(t,e){return function t(n){var r,s;switch(typeof n){case"number":if(!Number.isInteger(n)){const t=null!==(s=null===(r=null==e?void 0:e.onNonInteger)||void 0===r?void 0:r.call(e,n))&&void 0!==s?s:void 0;if(void 0!==t)return t;throw new TypeError("Refusing to autoconvert non-integer number to Double")}case"bigint":case"string":case"symbol":case"boolean":return n;case"undefined":case"function":break;case"object":if(null===n)break;if("function"==typeof n.__as_preserve__)return n.__as_preserve__();if(g.isRecord(n))return n;if(Array.isArray(n))return n.map(t);if(ArrayBuffer.isView(n)||n instanceof ArrayBuffer)return c.from(n);if(Map.isMap(n)){const e=new Z;return n.forEach(((n,r)=>e.set(t(r),t(n)))),e}if(st.isSet(n)){const e=new st;return n.forEach((n=>e.add(t(n)))),e}if(x(n))return n;{const e={};return Object.entries(n).forEach((([n,r])=>e[n]=t(r))),e}}throw new TypeError("Cannot represent JavaScript value as Preserves: "+n)}(t)}function Ft(t,e){return new Dt(t,e).next()}function Rt(t,e){return new Dt(t,e).readToEnd()}Y.stringMap=function(t){const e=new Z;return Object.entries(t).forEach((([t,n])=>e.set(t,Nt(n)))),e};const zt={write(t,e){if(e instanceof S)new Pt(t,this).push(e.generic);else{try{const n=Nt(e);if(!x(n))return void new Pt(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Ht(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:zt,Pt.stringify(Nt(t),e)}function Lt(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Ht(e)),n.push(t[r+1])})),n.join("")}function Wt(t,e){return ct(t,e)?e:void 0}[ft,c,Z,rt].forEach((t=>{t.prototype.toString=function(){return Ht(this)}}));class $t{constructor(t,e){this.index=0,this.packet=d(t),this.options=e}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}write(t){this.index===this.packet.length?this.packet=d(t):this.packet=c.concat([this.packet.slice(this.index),t])._view,this.index=0}atEnd(){return this.index>=this.packet.length}mark(){return this.index}restoreMark(t){this.index=t}shortGuard(t,e){if(this.atEnd())return e();const n=this.mark();try{return t()}catch(t){if(w.isShortPacket(t))return this.restoreMark(n),e();throw t}}nextbyte(){if(this.atEnd())throw new w("Short packet");return this.packet[this.index++]}nextbytes(t){const e=this.index;if(this.index+=t,this.index>this.packet.length)throw new w("Short packet");return new DataView(this.packet.buffer,this.packet.byteOffset+e,t)}varint(){const t=this.nextbyte();return t<128?t:(this.varint()<<7)+(t-128)}peekend(){return this.nextbyte()===t.End||(this.index--,!1)}nextint(t){const e=this.index;if(0===t)return 0;if(t>7)return this.nextbigint(t);if(7===t){const e=this.packet[this.index];if(e>=32&&e<224)return this.nextbigint(t)}let n=this.nextbyte();128&n&&(n-=256);for(let e=1;e<t;e++)n=256*n+this.nextbyte();return Number.isSafeInteger(n)?n:(this.index=e,this.nextbigint(t))}nextbigint(t){if(0===t)return BigInt(0);const e=c.from(this.nextbytes(t));if(e.get(0)>=128){const t=e.toHex((t=>h(15-t)));return~BigInt("0x"+t)}{const t=e.toHex();return BigInt("0x"+t)}}wrap(t){return this.includeAnnotations?new ft(t):t}unshiftAnnotation(t,e){return this.includeAnnotations&&e.annotations.unshift(t),e}}const Gt={decode(t){throw new Error("Embeddeds not permitted at this point in Preserves document")},fromValue(t,e){throw new Error("Embeddeds not permitted at this point in Preserves document")}};class Kt{constructor(t=new Uint8Array(0),e){var n,r,s;if(t instanceof $t)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:Gt;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new $t(t,n),this.embeddedDecode=null!==(s=n.embeddedDecode)&&void 0!==s?s:Gt}}write(t){this.state.write(t)}nextvalues(){const t=[];for(;!this.state.peekend();)t.push(this.next());return t}static dictionaryFromArray(t){const e=new Q;if(t.length%2)throw new y("Missing dictionary value");for(let n=0;n<t.length;n+=2){if(e.has(t[n]))throw new y(`Duplicate key: ${Ht(t[n])}`);e.set(t[n],t[n+1])}return e.simplifiedValue()}next(){const e=this.state.nextbyte();switch(e){case t.False:return this.state.wrap(!1);case t.True:return this.state.wrap(!0);case t.End:throw new y("Unexpected Compound end marker");case t.Annotation:{const t=this.next(),e=this.next();return this.state.unshiftAnnotation(t,e)}case t.Embedded:return this.state.wrap(this.embeddedDecode.decode(this.state));case t.Ieee754:if(8===this.state.varint())return this.state.wrap(St.fromBytes(this.state.nextbytes(8)));throw new y("Invalid IEEE754 size");case t.SignedInteger:return this.state.wrap(this.state.nextint(this.state.varint()));case t.String:return this.state.wrap(c.from(this.state.nextbytes(this.state.varint())).fromUtf8());case t.ByteString:return this.state.wrap(c.from(this.state.nextbytes(this.state.varint())));case t.Symbol:return this.state.wrap(Symbol.for(c.from(this.state.nextbytes(this.state.varint())).fromUtf8()));case t.Record:{const t=this.nextvalues();if(0===t.length)throw new y("Too few elements in encoded record");return this.state.wrap(g(t[0],t.slice(1)))}case t.Sequence:return this.state.wrap(this.nextvalues());case t.Set:{const t=new st;for(const e of this.nextvalues()){if(t.has(e))throw new y(`Duplicate value: ${Ht(e)}`);t.add(e)}return this.state.wrap(t)}case t.Dictionary:return this.state.wrap(Kt.dictionaryFromArray(this.nextvalues()));default:throw new y("Unsupported Preserves tag: "+e)}}try_next(){return this.state.shortGuard((()=>this.next()),(()=>{}))}atEnd(){return this.state.atEnd()}mark(){return this.state.mark()}restoreMark(t){return this.state.restoreMark(t)}skip(){this.next()}withEmbeddedDecode(t,e){return e(new Kt(this.state,t))}skipAnnotations(e){const n=this.mark();for(;!this.state.atEnd()&&this.state.packet[this.state.index]===t.Annotation;)this.state.index++,this.skip();return e((()=>this.restoreMark(n)))}nextBoolean(){return this.skipAnnotations((e=>{switch(this.state.nextbyte()){case t.False:return!1;case t.True:return!0;default:return e()}}))}nextDouble(){return this.skipAnnotations((e=>this.state.nextbyte()!==t.Ieee754||8!==this.state.nextbyte()?e():St.fromBytes(this.state.nextbytes(8))))}nextEmbedded(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Embedded?this.embeddedDecode.decode(this.state):e()))}nextSignedInteger(){return this.skipAnnotations((e=>this.state.nextbyte()===t.SignedInteger?this.state.nextint(this.state.varint()):e()))}nextString(){return this.skipAnnotations((e=>this.state.nextbyte()===t.String?c.from(this.state.nextbytes(this.state.varint())).fromUtf8():e()))}nextByteString(){return this.skipAnnotations((e=>this.state.nextbyte()===t.ByteString?c.from(this.state.nextbytes(this.state.varint())):e()))}nextSymbol(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Symbol?Symbol.for(c.from(this.state.nextbytes(this.state.varint())).fromUtf8()):e()))}openRecord(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Record||(e(),!1)))}openSequence(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Sequence||(e(),!1)))}openSet(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Set||(e(),!1)))}openDictionary(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Dictionary||(e(),!1)))}closeCompound(){return this.state.peekend()}}function Jt(t,e={}){return new Kt(t,e).next()}function Xt(t,e={}){return Jt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const Zt=Object.assign({},Bt,Mt),Qt=Object.assign({},Gt,Vt),Yt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},te=Object.assign({},Yt,B);var ee;!function(t){t[t.Boolean=0]="Boolean",t[t.Double=1]="Double",t[t.SignedInteger=2]="SignedInteger",t[t.String=3]="String",t[t.ByteString=4]="ByteString",t[t.Symbol=5]="Symbol",t[t.Record=6]="Record",t[t.Sequence=7]="Sequence",t[t.Set=8]="Set",t[t.Dictionary=9]="Dictionary",t[t.Embedded=10]="Embedded",t[t.Annotated=11]="Annotated"}(ee||(ee={}));class ne{boolean(t){}double(t){}integer(t){}string(t){}bytes(t){}symbol(t){}record(t,e){e(t.label),t.forEach(e)}array(t,e){t.forEach(e)}set(t,e){t.forEach(e)}dictionary(t,e){t.forEach(((t,n)=>{e(n),e(t)}))}annotated(t,e){e(t.item),t.annotations.forEach(e)}embedded(t,e){}}class re extends ne{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class se{boolean(t){return t}double(t){return kt(t)}integer(t){return t}string(t){return t}bytes(t){return t}symbol(t){return t}record(t,e){return g(e(t.label),t.map(e))}array(t,e){return t.map(e)}set(t,e){return t.map(e)}dictionary(t,e){const n=new Q;return t.forEach(((t,r)=>n.set(e(r),e(t)))),n.simplifiedValue()}annotated(t,e){return pt(e(t.item),...t.annotations.map(e))}}class ie extends se{embedded(t,e){return t}}class oe extends se{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}function ae(t){switch(typeof t){case"boolean":return ee.Boolean;case"number":if(Number.isInteger(t))return ee.SignedInteger;throw new Error("Non-integer number in Preserves valueClass; missing Float wrapper?");case"bigint":return ee.SignedInteger;case"string":return ee.String;case"symbol":return ee.Symbol;case"object":return g.isRecord(t)?ee.Record:Array.isArray(t)?ee.Sequence:st.isSet(t)?ee.Set:Y.isDictionary(t)?ee.Dictionary:ft.isAnnotated(t)?ee.Annotated:c.isBytes(t)?ee.ByteString:vt.isDouble(t)?ee.Double:ee.Embedded;default:(t=>{throw new Error("Internal error")})()}}const ue=new ie;function ce(t,e){const n=t=>{switch(typeof t){case"boolean":return e.boolean(t);case"number":return Number.isInteger(t)?e.integer(t):e.double(t);case"bigint":return e.integer(t);case"string":return e.string(t);case"symbol":return e.symbol(t);case"object":if(g.isRecord(t))return e.record(t,n);if(Array.isArray(t))return e.array(t,n);if(st.isSet(t))return e.set(t,n);if(x(t))return e.embedded(t,n);if(ft.isAnnotated(t))return e.annotated(t,n);if(c.isBytes(t))return e.bytes(t);if(vt.isDouble(t))return e.double(t.value);if(Y.isDictionary(t))return e.dictionary(new Q(t),n);default:(t=>{throw new Error("Internal error")})()}};return n(t)}function he(t,e){return ce(t,new oe(e))}function le(t,e){return ce(t,new re(e))}function de(t,e,...n){function r(){throw new Error("Cannot merge items")}function s(e,n){return e===n?e:bt(e)||bt(n)||!ct(e,n)?ce(e,{boolean:r,double:t=>ct(e,n)?e:r(),integer:r,string:r,bytes:t=>ct(e,n)?e:r(),symbol:r,record:t=>(g.isRecord(n)||r(),g(s(t.label,n.label),i(t,n))),array:t=>(Array.isArray(n)&&!g.isRecord(n)||r(),i(t,n)),set(t){r()},dictionary(t){const e=Y.asMap(n);void 0===e&&r();const i=new Q;return t.forEach(((t,n)=>{const r=e.get(n);i.set(n,void 0===r?t:s(t,r))})),e.forEach(((e,n)=>{t.has(n)||i.set(n,e)})),i.simplifiedValue()},annotated:t=>s(t,$(n)),embedded(e){x(n)||r();const s=t(e,n);return void 0===s&&r(),s}}):e}function i(t,e){return t.length<=e.length?e.map(((e,n)=>n<t.length?s(t[n],e):e)):t.map(((t,n)=>n<e.length?s(t,e[n]):t))}return n.reduce(s,e)}function fe(t){switch(ut(t)&&(t=t.item),typeof t){case"boolean":return 0;case"number":case"bigint":return 3;case"string":return 4;case"symbol":return 6;case"object":if(vt.isFloat(t))return 2;if(c.isBytes(t))return 5;if(Array.isArray(t))return"label"in t?7:8;if(st.isSet(t))return 9;if(Y.isDictionary(t))return 10;if(x(t))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}function pe(t,e,n=((t,e)=>ct(t,e)?0:t<e?-1:1)){return function t(e,r){ut(e)&&(e=e.item),ut(r)&&(r=r.item);const s=fe(e),i=fe(r);if(s<i)return-1;if(s>i)return 1;switch(s){case 0:case 3:case 4:return e<r?-1:e>r?1:0;case 2:{const t=e.value,n=r.value;return t<n?-1:t>n?1:0}case 5:return c.compare(e,r);case 6:{const t=e.description,n=r.description;return t<n?-1:t>n?1:0}case 7:{const n=t(e.label,r.label);if(0!==n)return n}case 8:{const n=e,s=r,i=Math.min(n.length,s.length);for(let e=0;e<i;e++){const r=t(n[e],s[e]);if(0!==r)return r}return n.length<s.length?-1:n.length>s.length?1:0}case 9:return t(Array.from(e).sort(t),Array.from(r).sort(t));case 10:return t(Array.from(Y.asMap(e).entries()).sort(t),Array.from(Y.asMap(r).entries()).sort(t));case 11:return n(e,r);default:throw new Error("Invalid typeCode: "+s)}}(t,e)}class me{constructor(t){this.text=t}__as_preserve__(){return g(Symbol.for("p"),[Symbol.for(this.text)])}isComma(){return","===this.text}static isComma(t){return t instanceof me&&t.isComma()}isColon(t=1){return this.text===":".repeat(t)}static isColon(t,e=1){return t instanceof me&&t.isColon(e)}}class ye{constructor(t,e){this.expr=t,this.annotations=e}__as_preserve__(){var t,e;const n=Nt(this.expr);return new S(null!==(e=null===(t=this.annotations)||void 0===t?void 0:t.wrap(n))&&void 0!==e?e:n)}}class be{constructor(){this.positions=[],this.exprs=[],this.annotations=void 0}get(t){if(!(t>=this.exprs.length))return{position:this.positions[t],item:this.exprs[t],annotations:this.annotations&&this.annotations[t]}}push(t,e,n){if(void 0===e){const e=t;e.annotations&&(this._ensureAnnotations()[this.exprs.length]=e.annotations),this.positions.push(e.position),this.exprs.push(e.item)}else n&&(this._ensureAnnotations()[this.exprs.length]=n),this.positions.push(e),this.exprs.push(t);return!0}_ensureAnnotations(){return void 0===this.annotations&&(this.annotations=[]),this.annotations}_annotationsAt(t){var e,n;return null!==(e=(n=this._ensureAnnotations())[t])&&void 0!==e?e:n[t]=new ge}preservesValues(){return this.exprs.map(((t,e)=>{var n;const r=Nt(t);return void 0!==(null===(n=this.annotations)||void 0===n?void 0:n[e])?this.annotations[e].wrap(r):r}))}map(t,e=0){const n=[];for(let r=e;r<this.exprs.length;r++)n.push(t(this.get(r),r));return n}[Symbol.iterator](){let t=this,e=0;return{next:()=>e<t.exprs.length?{done:!1,value:t.get(e++)}:{done:!0,value:void 0},[Symbol.iterator]:()=>t[Symbol.iterator]()}}}class we extends be{__as_preserve__(){return this.preservesValues()}}class ge extends be{wrap(t){return pt(t,...this.preservesValues())}}class ve extends be{__as_preserve__(){const t=this.preservesValues();switch(this.variant){case"sequence":return t;case"record":return g(Symbol.for("r"),t);case"block":return g(Symbol.for("b"),t);case"group":return g(Symbol.for("g"),t);case"set":return g(Symbol.for("s"),t)}}}class xe extends ve{get variant(){return"sequence"}}class _e extends ve{get variant(){return"record"}}class Se extends ve{get variant(){return"block"}}class ke extends ve{get variant(){return"group"}}let Ee=class extends ve{get variant(){return"set"}};var Ae=Object.freeze({__proto__:null,Annotations:ge,BaseCompound:be,Block:Se,Compound:ve,Document:we,Embedded:ye,Group:ke,Punct:me,Reader:class extends It{nextDocument(t="all"){const e=new we;if(this.readExpr(e),"all"===t)for(;this.readExpr(e););return e}readCompound(t,e){for(;;){if(this.state.skipws(),this.state.peek()===e)return this.state.advance(),t;this.readExpr(t)||this.state.error(`Missing "${e}"`,this.state.copyPos())}}readSimpleExpr(t){return this._readInto(t,!1)}readExpr(t){return this._readInto(t,!0)}_readInto(t,e){for(;;){if(this.state.skipws(),this.state.atEnd())return!1;const n=this.state.copyPos(),r=this.state.nextchar();switch(r){case'"':return t.push(this.state.readString('"'),n);case"|":return t.push(Symbol.for(this.state.readString("|")),n);case";":if(e)return t.push(new me(";"),n);this.state.error("Semicolon is not permitted at this location",n);case"@":this.readSimpleExpr(t._annotationsAt(t.exprs.length))||this.state.error("Missing annotation",n);continue;case":":{let s=r;for(;!this.state.atEnd()&&":"===this.state.peek();)s+=":",this.state.advance();if(e)return t.push(new me(s),n);this.state.error("Colons are not permitted at this location",n)}case"#":{const e=this.state.nextchar();switch(e){case" ":case"\t":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push(this.state.readCommentLine(),e);continue}case"\n":case"\r":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push("",e);continue}case"!":{const e=this.state.copyPos(),n=new _e;n.push(Symbol.for("interpreter"),e),n.push(this.state.readCommentLine(),e),t._annotationsAt(t.exprs.length).push(n,e);continue}case"f":return this.state.requireDelimiter("#f"),t.push(!1,n);case"t":return this.state.requireDelimiter("#t"),t.push(!0,n);case"{":return t.push(this.readCompound(new Ee,"}"),n);case'"':return t.push(this.state.readLiteralBinary(),n);case"x":switch(this.state.nextchar()){case'"':return t.push(this.state.readHexBinary(),n);case"d":return t.push(this.state.readHexFloat(),n);default:this.state.error("Invalid #x syntax",n)}case"[":return t.push(this.state.readBase64Binary(),n);case":":{const e=new be;if(!this.readSimpleExpr(e))return!1;const r=new ye(e.exprs[0],e.annotations&&e.annotations[0]);return t.push(r,n)}default:this.state.error(`Invalid # syntax: ${e}`,n)}}case"(":return t.push(this.readCompound(new ke,")"),n);case"<":return t.push(this.readCompound(new _e,">"),n);case"[":return t.push(this.readCompound(new xe,"]"),n);case"{":return t.push(this.readCompound(new Se,"}"),n);case">":this.state.error("Unexpected >",n);case"]":this.state.error("Unexpected ]",n);case"}":this.state.error("Unexpected }",n);case",":if(e)return t.push(new me(","),n);this.state.error("Comma is not permitted at this location",n);default:return t.push(this.state.readRawSymbolOrNumber(r),n)}}}},Record:_e,Sequence:xe,Set:Ee,asPreserves:function(t,e={}){var n;const r=null!==(n=e.error)&&void 0!==n?n:(t,e)=>{throw new Error(dt(e)+": "+t)};function s(t){return Array.from(t).filter((t=>!me.isComma(t.item)))}return function t(n){if(n.item instanceof me)return r("invalid-punctuation",n.position);if(n.item instanceof ye)return e.onEmbedded?e.onEmbedded({position:n.position,item:n.item.expr},t):r("unexpected-embedded",n.position);if(!(n.item instanceof ve))return n.item;switch(n.item.variant){case"sequence":return s(n.item).map(t);case"record":{const e=s(n.item).map(t);if(e.length<1)return r("invalid-record",n.position);const i=e.slice(1);return i.label=e[0],i}case"block":{const e=new Q,i=s(n.item);if(i.length%3!=0)return r("invalid-dictionary",n.position);for(let n=0;n<i.length;n+=3){if(!me.isColon(i[n+1].item))return r("missing-colon",i[n+1].position);const s=t(i[n]),o=t(i[n+2]);e.set(s,o)}return e.simplifiedValue()}case"group":return e.onGroup?e.onGroup(n):r("unexpected-group",n.position);case"set":return new st(s(n.item).map(t))}}(t)}});Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const je=Array,Ce=Symbol;export{ft as Annotated,je as Array,c as Bytes,e as Constants,y as DecodeError,Kt as Decoder,$t as DecoderState,Y as Dictionary,Q as DictionaryMap,J as DictionaryType,kt as Double,St as DoubleFloat,_ as Embedded,X as EncodableDictionary,nt as EncodableSet,b as EncodeError,D as Encoder,I as EncoderState,p as ErrorType,H as FlexMap,L as FlexSet,vt as Float,gt as FloatType,re as ForEachEmbedded,S as GenericEmbedded,ue as IDENTITY_FOLD,ie as IdentityFold,N as IdentityMap,T as IdentitySet,v as IsEmbedded,F as IsMap,at as IsPreservesAnnotated,u as IsPreservesBytes,R as IsSet,W as JsDictionary,Z as KeyedDictionary,rt as KeyedSet,oe as MapFold,jt as NUMBER_RE,Ae as Pexpr,m as PreservesCodecError,Dt as Reader,It as ReaderBase,Ct as ReaderState,g as Record,st as Set,w as ShortPacket,Ce as Symbol,ee as ValueClass,se as ValueFold,ne as VoidFold,Pt as Writer,Ut as WriterState,z as _iterMap,pt as annotate,mt as annotations,Wt as asLiteral,V as canonicalEncode,U as canonicalString,pe as compare,f as dataview,Jt as decode,r as decodeBase64,Xt as decodeWithAnnotations,C as embeddedId,O as encode,i as encodeBase64,tt as encodeDictionaryOn,it as encodeSetOn,P as encodeWithAnnotations,xt as floatValue,_t as floatlikeString,ce as fold,le as forEachEmbedded,dt as formatPosition,Nt as fromJS,Tt as fromJS_options,Zt as genericEmbeddedType,Bt as genericEmbeddedTypeDecode,Mt as genericEmbeddedTypeEncode,h as hexDigit,te as identityEmbeddedType,Yt as identityEmbeddedTypeDecode,B as identityEmbeddedTypeEncode,ct as is,ut as isAnnotated,bt as isCompound,x as isEmbedded,k as isPreservable,qt as isPreserveWritable,wt as isSequence,he as mapEmbeddeds,de as merge,Qt as neverEmbeddedType,Gt as neverEmbeddedTypeDecode,Vt as neverEmbeddedTypeEncode,ht as newPosition,Ft as parse,Rt as parseAll,G as peel,yt as position,Lt as preserves,Ht as stringify,zt as stringifyEmbeddedWrite,K as strip,fe as typeCode,$ as unannotate,d as underlying,l as unhexDigit,lt as updatePosition,ae as valueClass,et as writeDictionaryOn,ot as writeSetOn};
var t;!function(t){t[t.False=128]="False",t[t.True=129]="True",t[t.End=132]="End",t[t.Annotation=133]="Annotation",t[t.Embedded=134]="Embedded",t[t.Ieee754=135]="Ieee754",t[t.SignedInteger=176]="SignedInteger",t[t.String=177]="String",t[t.ByteString=178]="ByteString",t[t.Symbol=179]="Symbol",t[t.Record=180]="Record",t[t.Sequence=181]="Sequence",t[t.Set=182]="Set",t[t.Dictionary=183]="Dictionary"}(t||(t={}));var e=Object.freeze({__proto__:null,get Tag(){return t}});const n={};function r(t){const e=new Uint8Array(Math.floor(3*t.length/4));let r=0,s=0;for(;r<t.length;){const i=n[t[r++]],o=n[t[r++]],a=n[t[r++]],u=n[t[r++]],c=i<<18|o<<12|a<<6|u;if(e[s++]=c>>16&255,void 0===a)break;if(e[s++]=c>>8&255,void 0===u)break;e[s++]=255&c}return e.subarray(0,s)}[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"].forEach(((t,e)=>n[t]=e)),n["+"]=n["-"]=62,n["/"]=n._=63;const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(t){let e="",n=0,r=0;for(let i of t)for(n=(63&n)<<8|i,r+=8;r>=6;){r-=6;e+=s[n>>r&63]}if(r>0){e+=s[n<<6-r&63]}return e}const o=new TextEncoder,a=new TextDecoder("utf-8",{fatal:!0}),u=Symbol.for("IsPreservesBytes");class c{constructor(t=new Uint8Array){if(c.isBytes(t))this._view=t._view;else if(ArrayBuffer.isView(t))this._view=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else if(t instanceof ArrayBuffer)this._view=new Uint8Array(t);else if("string"==typeof t)this._view=o.encode(t);else if("number"==typeof t)this._view=new Uint8Array(t);else{if("number"!=typeof t.length)throw new TypeError("Attempt to initialize Bytes from unsupported value: "+t);this._view=Uint8Array.from(t)}}dataview(){return new DataView(this._view.buffer,this._view.byteOffset,this._view.byteLength)}get length(){return this._view.length}static from(t){return new c(t)}static of(...t){return new c(Uint8Array.of(...t))}static fromLatin1(t){const e=new c(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>=256)throw new Error("Codepoint out of range for 'latin1' byte encoding");e._view[n]=r}return e}static fromBase64(t){return new c(r(t))}static fromHex(t){if(1&t.length)throw new Error("Cannot decode odd-length hexadecimal string");const e=new c(t.length>>1);return c._raw_fromHexInto(t,e._view),e}static _raw_fromHexInto(t,e){const n=t.length>>1;for(let r=0;r<n;r++)e[r]=l(t.charCodeAt(r<<1))<<4|l(t.charCodeAt(1+(r<<1)))}static fromIO(t){return"string"==typeof t||c.isBytes(t)?t:new c(t)}static toIO(t){return"string"==typeof t?t:c.isBytes(t)?t._view:t}get(t){return this._view[t]}equals(t){if(!c.isBytes(t))return!1;if(t.length!==this.length)return!1;const e=this._view,n=t._view;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}hashCode(){const t=this._view;let e=0;for(let n=0;n<t.length;n++)e=31*e+t[n]|0;return e}static compare(t,e){return t<e?-1:e<t?1:0}static decodeUtf8(t){return a.decode(d(t))}fromUtf8(){return a.decode(this._view)}__as_preserve__(){return this}static __from_preserve__(t){return c.isBytes(t)?t:void 0}toLatin1(){return String.fromCharCode.apply(null,this._view)}toBase64(){return i(this._view)}toHex(t=h){var e=[];for(let n=0;n<this.length;n++)e.push(t(this._view[n]>>4)),e.push(t(15&this._view[n]));return e.join("")}valueOf(){return this.toHex()}__preserve_on__(e){e.state.emitbyte(t.ByteString),e.state.varint(this.length),e.state.emitbytes(this._view)}__preserve_text_on__(t){t.state.writeBytes(this._view)}get[u](){return!0}static isBytes(t){return!!(null==t?void 0:t[u])}}function h(t){return"0123456789abcdef"[t]}function l(t,e=Error){if(t>=48&&t<=57)return t-48;if(t>=97&&t<=102)return t-97+10;if(t>=65&&t<=70)return t-65+10;throw new e("Invalid hex digit: "+String.fromCharCode(t))}function d(t){return t instanceof Uint8Array?t:t._view}function f(t){return t instanceof DataView?t:t.dataview()}c.concat=function(t){let e=0;for(let n=0;n<t.length;n++)e+=d(t[n]).length;const n=new c(e);let r=0;for(let e=0;e<t.length;e++){const s=d(t[e]);n._view.set(s,r),r+=s.length}return n},function(){for(const t of"entries every find findIndex forEach includes indexOf join\nkeys lastIndexOf reduce reduceRight some toLocaleString values".split(/\s+/))c.prototype[t]=function(...e){return this._view[t](...e)};for(const t of"filter map slice subarray".split(/\s+/))c.prototype[t]=function(...e){return new c(this._view[t](...e))};for(const t of"reverse sort".split(/\s+/))c.prototype[t]=function(...e){return new c(this._view.slice()[t](...e))};c.prototype[Symbol.iterator]=function(){return this._view[Symbol.iterator]()}}();const p=Symbol.for("ErrorType");class m{static isCodecError(t,e){return(null==t?void 0:t[p])===e}}class y extends Error{get[p](){return"DecodeError"}constructor(t,e){super(t),this.pos=e}static isDecodeError(t){return m.isCodecError(t,"DecodeError")}}class b extends Error{get[p](){return"EncodeError"}static isEncodeError(t){return m.isCodecError(t,"EncodeError")}constructor(t,e){super(t),this.irritant=e}}class w extends y{get[p](){return"ShortPacket"}static isShortPacket(t){return m.isCodecError(t,"ShortPacket")}}function g(t,e){return e.label=t,e}!function(t){t.isRecord=function(t){return Array.isArray(t)&&"label"in t},t.constructorInfo=function(t){return{label:t.label,arity:t.length}},t.isClassOf=function(e,n){return t.isRecord(n)&&ct(e.label,n.label)&&e.arity===n.length},t.makeConstructor=function(){return(e,n)=>{const r=(...n)=>t(e,n),s={label:e,arity:n.length};return r.constructorInfo=s,r.isClassOf=e=>t.isClassOf(s,e),r.fieldNumbers={},r._={},n.forEach(((t,e)=>{r._[t]=t=>t[e],r.fieldNumbers[t]=e})),r}}}(g||(g={}));const v=Symbol.for("IsEmbedded");function x(t){return!!(null==t?void 0:t[v])}let _=class{get[v](){return!0}constructor(t){this.value=t}equals(t){return"object"==typeof t&&"value"in t&&Object.is(this.value,t.value)}};class S{get[v](){return!0}constructor(t){this.generic=t}equals(t,e){return"object"==typeof t&&"generic"in t&&e(this.generic,t.generic)}toString(){return this.generic.toString()}}function k(t){return"object"==typeof t&&null!==t&&"__preserve_on__"in t&&"function"==typeof t.__preserve_on__}function E(t){return String.fromCharCode.apply(null,t)}let A=0;const j=new WeakMap;function C(t){let e=j.get(t);return void 0===e&&(e=A++,j.set(t,e)),e}const B={encode(t,e){new D(t,this).push(C(e))}};class I{constructor(t){this.chunks=[],this.view=new DataView(new ArrayBuffer(256)),this.index=0,this.options=t}get canonical(){var t;return null===(t=this.options.canonical)||void 0===t||t}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t?t:!this.canonical}contents(){if(0===this.chunks.length){const t=this.index;return this.index=0,new c(this.view.buffer.slice(0,t))}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],c.concat(t)}}contentsString(){if(0===this.chunks.length){const t=E(new Uint8Array(this.view.buffer,0,this.index));return this.index=0,t}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],t.map(E).join("")}}rotatebuffer(t){this.chunks.push(new Uint8Array(this.view.buffer,0,this.index)),this.view=new DataView(new ArrayBuffer(t)),this.index=0}makeroom(t){this.index+t>this.view.byteLength&&this.rotatebuffer(t+4096)}emitbyte(t){this.makeroom(1),this.view.setUint8(this.index++,t)}emitbytes(t){this.makeroom(t.length),new Uint8Array(this.view.buffer).set(t,this.index),this.index+=t.length}claimbytes(t){this.makeroom(t);const e=new Uint8Array(this.view.buffer,this.index,t);return this.index+=t,e}varint(t){for(;t>=128;)this.emitbyte(t%128+128),t=Math.floor(t/128);this.emitbyte(t)}encodeint(e){if("bigint"==typeof e)return this.encodebigint(e);if(this.emitbyte(t.SignedInteger),0===e)return void this.emitbyte(0);const n=(-1===e?0:Math.floor(Math.log2(e>0?e:-(1+e)))+1)+1+7>>3;this.varint(n);const r=(t,e)=>{t>0&&(r(t-1,Math.floor(e/256)),this.emitbyte(255&e))};r(n,e)}encodebigint(e){let n;if(this.emitbyte(t.SignedInteger),e>0)n=e.toString(16),1&n.length?n="0"+n:l(n.charCodeAt(0))>=8&&(n="00"+n);else{if(!(e<0))return void this.emitbyte(0);{const t=(~e).toString(16);n="";for(let e=0;e<t.length;e++)n+="fedcba9876543210"[l(t.charCodeAt(e))];1&n.length?n="f"+n:l(n.charCodeAt(0))<8&&(n="ff"+n)}}this.varint(n.length>>1),c._raw_fromHexInto(n,this.claimbytes(n.length>>1))}encodebytes(t,e){this.emitbyte(t),this.varint(e.length),this.emitbytes(e)}}class D{constructor(t={},e){var n;t instanceof I?(this.state=t,this.embeddedEncode=null!=e?e:B):(this.state=new I(t),this.embeddedEncode=null!==(n=t.embeddedEncode)&&void 0!==n?n:B)}withEmbeddedEncode(t,e){return e(new D(this.state,t)),this}get canonical(){return this.state.canonical}get includeAnnotations(){return this.state.includeAnnotations}contents(){return this.state.contents()}contentsString(){return this.state.contentsString()}grouped(e,n){this.state.emitbyte(e),n(),this.state.emitbyte(t.End)}push(e){if(k(e))e.__preserve_on__(this);else if(k(e))e.__preserve_on__(this);else if("boolean"==typeof e)this.state.emitbyte(e?t.True:t.False);else if("number"==typeof e||"bigint"==typeof e)this.state.encodeint(e);else if("string"==typeof e)this.state.encodebytes(t.String,new c(e)._view);else if("symbol"==typeof e){const n=Symbol.keyFor(e);if(void 0===n)throw new b("Cannot preserve non-global Symbol",e);this.state.encodebytes(t.Symbol,new c(n)._view)}else if(ArrayBuffer.isView(e))if(e instanceof Uint8Array)this.state.encodebytes(t.ByteString,e);else{const n=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);this.state.encodebytes(t.ByteString,n)}else if(g.isRecord(e)){this.state.emitbyte(t.Record),this.push(e.label);for(let t of e)this.push(t);this.state.emitbyte(t.End)}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(e)?x(e)?(this.state.emitbyte(t.Embedded),this.embeddedEncode.encode(this.state,e)):tt(new Q(e),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.grouped(t.Sequence,(()=>{for(let t of e)this.push(t)}));return this}}function O(t,e={}){return new D(e).push(t).contents()}const q=new D({canonical:!0});let M=!1;function V(t,e){if(void 0!==e||M)return O(t,Object.assign(Object.assign({},e),{canonical:!0}));{M=!0;const e=q.push(t).contents();return M=!1,e}}function U(t){if(M)return new D({canonical:!0}).push(t).contentsString();{M=!0;const e=q.push(t).contentsString();return M=!1,e}}function P(t,e={}){return O(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const N=Map,T=Set,F=Symbol.for("IsMap"),R=Symbol.for("IsSet");function z(t,e){const n=t=>t.done?{done:!0,value:null}:{done:!1,value:e(t.value)};return{next:e=>n(t.next(e)),return:e=>{var r,s;return n(null!==(s=null===(r=t.return)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},throw:e=>{var r,s;return n(null!==(s=null===(r=t.throw)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},[Symbol.iterator](){return this}}}F in Map.prototype||(Object.defineProperty(Map.prototype,F,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[F])),R in Set.prototype||(Object.defineProperty(Set.prototype,R,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[R]));class H{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(z(e[Symbol.iterator](),(([t,e])=>[this._key(t),[t,e]])))}_key(t){return this.canonicalizer(t)}get(t,e){const n=this.items.get(this._key(t));return void 0===n?e:n[1]}getOrSet(t,e){const n=this._key(t);let r=this.items.get(n);return void 0===r&&(r=[t,e()],this.items.set(n,r)),r[1]}set(t,e){return this.items.set(this._key(t),[t,e]),this}forEach(t,e){this.items.forEach((([n,r])=>t.call(e,r,n,this)))}entries(){return this.items.values()}keys(){return z(this.items.values(),(([t,e])=>t))}values(){return z(this.items.values(),(([t,e])=>e))}delete(t){return this.items.delete(this._key(t))}getAndDelete(t,e){const n=this._key(t),r=this.items.get(n);return void 0===r?e:(this.items.delete(n),r[1])}clear(){this.items.clear()}has(t){return this.items.has(this._key(t))}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexMap"}equals(t,e=((t,e)=>t===e)){if(!("size"in t&&"has"in t&&"get"in t))return!1;if(this.size!==t.size)return!1;for(let[n,r]of this.items.values()){if(!t.has(n))return!1;if(!e(r,t.get(n)))return!1}return!0}update(t,e,n,r=((t,e)=>t===e)){const s=this._key(t);if(this.items.has(s)){const n=this.items.get(s)[1],i=e(n);return void 0===i?(this.items.delete(s),-1):(r(i,n)||this.items.set(s,[t,i]),0)}{const r=e(n);return void 0===r?0:(this.items.set(s,[t,r]),1)}}canonicalKeys(){return this.items.keys()}get[F](){return!0}}class L{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(z(e[Symbol.iterator](),(t=>[this._key(t),t])))}_key(t){return this.canonicalizer(t)}has(t){return this.items.has(this._key(t))}get(t){const e=this._key(t);return this.items.has(e)?{item:this.items.get(e)}:null}add(t){return this.items.set(this._key(t),t),this}forEach(t,e){this.items.forEach((n=>t.call(e,n,n,this)))}entries(){return z(this.items.values(),(t=>[t,t]))}keys(){return this.items.values()}values(){return this.items.values()}delete(t){return this.items.delete(this._key(t))}clear(){this.items.clear()}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexSet"}equals(t){if(!("size"in t)||!("has"in t))return!1;if(this.size!==t.size)return!1;for(let e of this.items.values())if(!t.has(e))return!1;return!0}canonicalValues(){return this.items.keys()}union(t){const e=new L(this.canonicalizer,this);for(let n of t)e.add(n);return e}intersect(t){const e=new L(this.canonicalizer);for(let n of this)t.has(n)&&e.add(n);return e}subtract(t){const e=new L(this.canonicalizer);for(let n of this)t.has(n)||e.add(n);return e}get[R](){return!0}}var W;function $(t){return ft.isAnnotated(t)?t.item:t}function G(t){return K(t,1)}function K(t,e=1/0){return function t(e,n){if(0===n)return e;if(!ft.isAnnotated(e))return e;const r=n-1;function s(e){return t(e,r)}if(g.isRecord(e.item))return g(t(e.item.label,n),e.item.map(s));if(ft.isAnnotated(e.item))throw new Error("Improper annotation structure");if(0===r)return e.item;if(Array.isArray(e.item))return e.item.map(s);if(st.isSet(e.item))return e.item.map(s);if(Y.isDictionary(e.item)){const t=new Q;return new Q(e.item).forEach(((e,n)=>t.set(s(n),s(e)))),t.simplifiedValue()}return e.item}(t,e)}!function(t){function e(t,e){return t[e.description]}function n(t,e){return Object.hasOwnProperty.call(t,e.description)}function r(t){return Object.keys(t).length}function s(t){return z(Object.entries(t).values(),(([t,e])=>[Symbol.for(t),e]))}t.isJsDictionary=function(t){return"object"==typeof t&&null!==t&&null===Object.getPrototypeOf(Object.getPrototypeOf(t))&&"function"!=typeof t.__as_preserve__&&!x(t)},t.from=function(t){const e={};for(const[n,r]of t)e[n.description]=r;return e},t.clear=function(t){for(const e in t)delete t[e]},t.remove=function(t,e){const r=n(t,e);return delete t[e.description],r},t.forEach=function(t,e){Object.entries(t).forEach((([t,n])=>e(n,Symbol.for(t))))},t.get=e,t.has=n,t.set=function(t,e,n){return t[e.description]=n,t},t.size=r,t.entries=s,t.keys=function(t){return z(Object.keys(t).values(),(t=>Symbol.for(t)))},t.values=function(t){return Object.values(t).values()},t.clone=function(t){const e={};return Object.keys(t).forEach((n=>e[n]=t[n])),e},t.equals=function(t,i,o=((t,e)=>t===e)){if(r(t)!==r(i))return!1;for(let[r,a]of s(t)){if(!n(i,r))return!1;if(!o(a,e(i,r)))return!1}return!0}}(W||(W={}));const J=Symbol.for("DictionaryType");class X extends H{constructor(t,e,n){super((e=>U(t(e))),n),this.encodeK=t,this.encodeV=e}__preserve_on__(t){tt(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){et(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}}class Z extends X{get[J](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[J])}constructor(t){super((t=>t),(t=>t),t)}clone(){return new Z(this)}get[Symbol.toStringTag](){return"Dictionary"}equals(t,e=((t,e)=>t===e)){const n=Y.asMap(t);return!!n&&super.equals(n,e)}}class Q{get[F](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):J in t?(this.j=void 0,this.k=t):(this.j=t,this.k=void 0)}static from(t){const e=new Q;for(const[n,r]of t)e.set(n,r);return e}clear(){this.j?W.clear(this.j):this.k.clear()}delete(t){return this.j?"symbol"==typeof(t=$(t))&&W.remove(this.j,t):this.k.delete(t)}forEach(t,e){this.j?W.forEach(this.j,((n,r)=>t.call(e,n,r,this))):this.k.forEach(t,e)}get(t){if(this.j){if("symbol"!=typeof(t=$(t)))return;return W.get(this.j,t)}return this.k.get(t)}has(t){return this.j?"symbol"==typeof(t=$(t))&&W.has(this.j,t):this.k.has(t)}set(t,e){if(this.j){if("symbol"==typeof t)return W.set(this.j,t,e),this;this.k=new Z(W.entries(this.j)),this.j=void 0}return this.k.set(t,e),this}get size(){return this.j?W.size(this.j):this.k.size}entries(){return this.j?W.entries(this.j):this.k.entries()}keys(){return this.j?W.keys(this.j):this.k.keys()}values(){return this.j?W.values(this.j):this.k.values()}[Symbol.iterator](){return this.entries()}get[Symbol.toStringTag](){return"DictionaryMap"}clone(){return new Q(this.j?W.clone(this.j):this.k.clone())}get value(){var t;return null!==(t=this.j)&&void 0!==t?t:this.k}simplify(){if(!this.j){const t={};for(const[e,n]of this.k.entries()){if("symbol"!=typeof e)return;t[e.description]=n}this.j=t,this.k=void 0}}simplifiedValue(){return this.simplify(),this.value}asJsDictionary(){if(this.simplify(),!this.j)throw new Error("Cannot represent general dictionary as JsDictionary");return this.j}asKeyedDictionary(){var t;return null!==(t=this.k)&&void 0!==t?t:new Z(W.entries(this.j))}}var Y;function tt(e,n,r,s){if(n.canonical){const i=Array.from(e),o=new D({canonical:!0,embeddedEncode:n.embeddedEncode}),a=i.map((([t,e],n)=>(r(t,o),[o.contents(),n])));a.sort(((t,e)=>c.compare(t[0],e[0]))),n.grouped(t.Dictionary,(()=>a.forEach((([t,e])=>{const[o,a]=i[e];r(o,n),s(a,n)}))))}else n.grouped(t.Dictionary,(()=>e.forEach(((t,e)=>{r(e,n),s(t,n)}))))}function et(t,e,n,r){e.state.writeSeq("{","}",t.entries(),(([t,s])=>{n(t,e),ft.isAnnotated(s)&&mt(s).length>1&&e.state.isIndenting?(e.state.pieces.push(":"),e.state.indentCount++,e.state.writeIndent(),r(s,e),e.state.indentCount--):(e.state.pieces.push(": "),r(s,e))}))}!function(t){function e(t){if("object"!=typeof t||null===t)return!1;switch(t[J]){case"Dictionary":return!0;case void 0:return W.isJsDictionary(t);default:return!1}}t.isDictionary=e,t.asMap=function(t){return e(t)?new Q(t):void 0},t.from=function(t){return Q.from(t).simplifiedValue()},t.__from_preserve__=function(e){return t.isDictionary(e)?e:void 0}}(Y||(Y={}));class nt extends L{constructor(t,e){super((e=>U(t(e))),e),this.encodeV=t}__preserve_on__(t){it(this,t,((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){ot(this,t,((t,e)=>e.push(this.encodeV(t))))}}class rt extends nt{get[J](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[J])}constructor(t){super((t=>t),t)}map(t){return new rt(z(this[Symbol.iterator](),t))}filter(t){const e=new rt;for(let n of this)t(n)&&e.add(n);return e}clone(){return new rt(this)}get[Symbol.toStringTag](){return"Set"}}let st=class t extends rt{static isSet(t){return"Set"===(null==t?void 0:t[J])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function it(e,n,r){if(n.canonical){const s=new D({canonical:!0,embeddedEncode:n.embeddedEncode}),i=Array.from(e).map((t=>(r(t,s),[s.contents(),t])));i.sort(((t,e)=>c.compare(t[0],e[0]))),n.grouped(t.Set,(()=>i.forEach((([t,e])=>r(e,n)))))}else n.grouped(t.Set,(()=>e.forEach((t=>r(t,n)))))}function ot(t,e,n){e.state.writeSeq("#{","}",t,(t=>n(t,e)))}const at=Symbol.for("IsPreservesAnnotated");function ut(t){return!!(null==t?void 0:t[at])}function ct(t,e){if(ut(t)&&(t=t.item),ut(e)&&(e=e.item),Object.is(t,e))return!0;if(typeof t!=typeof e)return("number"==typeof t&&"bigint"==typeof e||"bigint"==typeof t&&"number"==typeof e)&&t==e;if("object"==typeof t){if(null===t||null===e)return!1;if("equals"in t&&"function"==typeof t.equals)return t.equals(e,ct);if(Array.isArray(t)&&Array.isArray(e)){const n="label"in t;if(n!=="label"in e)return!1;if(n&&!ct(t.label,e.label))return!1;if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!ct(t[n],e[n]))return!1;return!0}{const n=Y.asMap(t),r=Y.asMap(e);if(!n||!r)return!1;if(n.size!==r.size)return!1;for(const t of n.keys()){if(!r.has(t))return!1;if(!ct(n.get(t),r.get(t)))return!1}return!0}}return!1}function ht(t){return{line:1,column:0,pos:0,name:t}}function lt(t,e){if(t.pos++,void 0===t.line)return!1;{let n=!1;switch(e){case"\t":t.column=t.column+8&-8;break;case"\n":t.column=0,t.line++,n=!0;break;case"\r":t.column=0;break;default:t.column++}return n}}function dt(t){var e,n,r;return null===t?"<unknown>":"string"==typeof t?t:`${null!==(e=t.name)&&void 0!==e?e:""}:${null!==(n=t.line)&&void 0!==n?n:""}:${null!==(r=t.column)&&void 0!==r?r:""}:${t.pos}`}class ft{constructor(t,e){this.annotations=[],this.pos=null!=e?e:null,this.item=t}__as_preserve__(){return this}static __from_preserve__(t){return ut(t)?t:void 0}__preserve_on__(e){if(e.includeAnnotations)for(const n of this.annotations)e.state.emitbyte(t.Annotation),e.push(n);e.push(this.item)}__preserve_text_on__(t){if(t.includeAnnotations){const e=this.annotations.length<=1;for(const n of this.annotations)t.state.pieces.push("@"),t.push(n),e?t.state.pieces.push(" "):t.state.writeIndentSpace()}t.push(this.item)}equals(t){return ct(this.item,ft.isAnnotated(t)?t.item:t)}get[at](){return!0}static isAnnotated(t){return ut(t)}}function pt(t,...e){const n=ft.isAnnotated(t)?t:new ft(t);return e.forEach((t=>n.annotations.push(t))),n}function mt(t){return ft.isAnnotated(t)?t.annotations:[]}function yt(t){return ft.isAnnotated(t)?t.pos:null}function bt(t){return Array.isArray(t)||st.isSet(t)||Y.isDictionary(t)}function wt(t){return Array.isArray(t)&&!("label"in t)}const gt=Symbol.for("FloatType");class vt{constructor(t){this.value="number"==typeof t?t:t.value}__preserve_text_on__(t){t.state.pieces.push(this.toString())}equals(t){return!!Object.is(t.constructor,this.constructor)&&(Number.isNaN(this.value)&&Number.isNaN(t.value)?t.toBytes().equals(this.toBytes()):Object.is(t.value,this.value))}hashCode(){return 0|this.value}}function xt(t){return"number"==typeof t?t:vt.isFloat(t)?t.value:NaN}function _t(t){if(Object.is(t,-0))return"-0.0";const e=""+t;return e.includes(".")||e.includes("e")||e.includes("E")?e:e+".0"}vt.isFloat=t=>void 0!==(null==t?void 0:t[gt]),vt.isDouble=t=>"Double"===(null==t?void 0:t[gt]);class St extends vt{__as_preserve__(){return this}static fromBytes(t){return new St(f(t).getFloat64(0,!1))}static __from_preserve__(t){return vt.isDouble(t)?t:void 0}__preserve_on__(e){e.state.emitbyte(t.Ieee754),e.state.emitbyte(8),e.state.makeroom(8),e.state.view.setFloat64(e.state.index,this.value,!1),e.state.index+=8}toBytes(){const t=new c(8);return t.dataview().setFloat64(0,this.value,!1),t}toString(){return Number.isFinite(this.value)?_t(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[gt](){return"Double"}}function kt(t){return new St(t)}const Et=BigInt(Number.MAX_SAFE_INTEGER),At=BigInt(Number.MIN_SAFE_INTEGER),jt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class Ct{constructor(t,e){switch(this.discarded=0,this.buffer=t,typeof e.name){case"undefined":this.pos=ht();break;case"string":this.pos=ht(e.name);break;case"object":this.pos=Object.assign({},e.name)}this.index=0,this.options=e}error(t,e){throw new y(t,Object.assign({},e))}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}copyPos(){return Object.assign({},this.pos)}write(t){this.atEnd()?this.buffer=t:this.buffer=this.buffer.substring(this.index)+t,this.discarded+=this.index,this.index=0}atEnd(){return this.index>=this.buffer.length}peek(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.index]}advance(){const t=this.index++;return lt(this.pos,this.buffer[t]),t}nextchar(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.advance()]}nextcharcode(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer.charCodeAt(this.advance())}skipws(t=!1){for(;!this.atEnd();){const e=this.peek();if(!(Ot(e)||t&&","===e))break;this.advance()}}readHex2(){return l(this.nextcharcode(),y)<<4|l(this.nextcharcode(),y)}readHex4(){return l(this.nextcharcode(),y)<<12|l(this.nextcharcode(),y)<<8|l(this.nextcharcode(),y)<<4|l(this.nextcharcode(),y)}readHexBinary(){const t=[];for(;;){if(this.skipws(),'"'===this.peek())return this.advance(),c.from(t);t.push(this.readHex2())}}readHexFloat(){const t=this.copyPos();'"'!==this.nextchar()&&this.error("Missing open-double-quote in hex-encoded floating-point number",t);const e=this.readHexBinary();return 8!==e.length&&this.error("Incorrect number of bytes in hex-encoded Double",t),St.fromBytes(e)}readBase64Binary(){let t="";for(;;){this.skipws();const e=this.nextchar();if("]"===e)break;t+=e}return c.fromBase64(t)}requireDelimiter(t){this.delimiterFollows()||this.error(`Delimiter must follow ${t}`,this.pos)}delimiterFollows(){if(this.atEnd())return!0;const t=this.peek();return-1!=='(){}[]<>";,@#:|'.indexOf(t)||Ot(t)}readRawSymbolOrNumber(t){for(;!this.delimiterFollows();)t+=this.nextchar();const e=jt.exec(t);if(e){if(void 0===e[2]){let t=BigInt(e[1]);return t<=At||t>=Et?t:Number(t)}return kt(parseFloat(t))}return Symbol.for(t)}readStringlike(t,e,n,r,s){let i=[];for(;;){const o=this.nextchar();switch(o){case n:return e(i);case"\\":{const e=this.nextchar();switch(e){case r:i.push(s());break;case n:case"\\":case"/":i.push(t(e));break;case"b":i.push(t("\b"));break;case"f":i.push(t("\f"));break;case"n":i.push(t("\n"));break;case"r":i.push(t("\r"));break;case"t":i.push(t("\t"));break;default:this.error(`Invalid escape code \\${e}`,this.pos)}break}default:i.push(t(o))}}}readString(t){return this.readStringlike((t=>t),(t=>t.join("")),t,"u",(()=>{const t=this.readHex4();if(t>=55296&&t<=57343){if("\\"===this.nextchar()&&"u"===this.nextchar()){const e=this.readHex4();if(e>=56320&&e<=57343&&t<=56319)return String.fromCharCode(t,e)}this.error("Invalid surrogate pair",this.pos)}return String.fromCharCode(t)}))}readLiteralBinary(){return this.readStringlike((t=>{const e=t.charCodeAt(0);return e>=256&&this.error(`Invalid code point ${e} in literal binary`,this.pos),e}),c.from,'"',"x",(()=>this.readHex2()))}readCommentLine(){let t="";for(;;){const e=this.nextchar();if("\n"===e||"\r"===e)return t;t+=e}}}const Bt={decode(t){return new S(new Kt(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:K(t))};class It{constructor(t="",e){var n,r;if(t instanceof Ct)this.state=t,this.embeddedType=e;else{const s=null!==(n=e)&&void 0!==n?n:{};this.state=new Ct(t,s),this.embeddedType=null!==(r=s.embeddedDecode)&&void 0!==r?r:Gt}}write(t){this.state.write(t)}}let Dt=class t extends It{readCommentLine(){const t=this.state.copyPos();return this.wrap(this.state.readCommentLine(),t)}wrap(t,e){return this.state.includeAnnotations&&!ft.isAnnotated(t)&&(t=new ft(t,e)),t}annotateNextWith(t){if(this.state.skipws(),this.state.atEnd())throw new y("Trailing annotations and comments are not permitted",this.state.pos);const e=this.next();return this.state.includeAnnotations&&e.annotations.unshift(t),e}readToEnd(){const t=[];for(;;){if(this.state.skipws(),this.state.atEnd())return t;t.push(this.next())}}next(){this.state.skipws();const e=this.state.copyPos(),n=(()=>{const n=this.state.nextchar();switch(n){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",e);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",e);case"#":{const n=this.state.nextchar();switch(n){case" ":case"\t":return this.annotateNextWith(this.readCommentLine());case"\n":case"\r":return this.annotateNextWith("");case"!":return this.annotateNextWith(g(Symbol.for("interpreter"),[this.readCommentLine()]));case"f":return this.state.requireDelimiter("#f"),!1;case"t":return this.state.requireDelimiter("#t"),!0;case"{":return this.readSet();case'"':return this.state.readLiteralBinary();case"x":switch(this.state.nextchar()){case'"':return this.state.readHexBinary();case"d":return this.state.readHexFloat();default:this.state.error("Invalid #x syntax",e)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new t(this.state,Bt).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${n}`,e)}}case"<":return g(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",e);case"]":this.state.error("Unexpected ]",e);case"}":this.state.error("Unexpected }",e);case",":this.state.error("Unexpected ,",e);default:return this.state.readRawSymbolOrNumber(n)}})();return this.wrap(n,e)}seq(t,e,n,r){for(;;){if(this.state.skipws(t),this.state.peek()===r)return this.state.advance(),e;n(this.next(),e)}}readSequence(t,e){return this.seq(e,[],((t,e)=>e.push(t)),t)}readDictionary(){return this.seq(!0,new Q,((t,e)=>{if(this.state.skipws(),":"===this.state.peek())this.state.advance(),e.has(t)&&this.state.error(`Duplicate key: ${Ht(t)}`,this.state.pos),e.set(t,this.next());else this.state.error("Missing key/value separator",this.state.pos)}),"}").simplifiedValue()}readSet(){return this.seq(!0,new st,((t,e)=>{e.has(t)&&this.state.error(`Duplicate value in set: ${Ht(t)}`,this.state.pos),e.add(t)}),"}")}};function Ot(t){return-1!==" \t\n\r".indexOf(t)}function qt(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const Mt={encode(t,e){new D(t,this).push(e.generic)},toValue:t=>t.generic},Vt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class Ut{constructor(t){var e;this.pieces=[],this.indentCount=0,this.options=t,this.indentDelta=" ".repeat(null!==(e=t.indent)&&void 0!==e?e:0)}get isIndenting(){return this.indentDelta.length>0}get includeAnnotations(){var t;return null===(t=this.options.includeAnnotations)||void 0===t||t}writeIndent(){if(this.isIndenting){this.pieces.push("\n");for(let t=0;t<this.indentCount;t++)this.pieces.push(this.indentDelta)}}writeIndentSpace(){this.isIndenting?this.writeIndent():this.pieces.push(" ")}escapeStringlikeChar(t,e=(t=>t)){switch(t){case"\\":return"\\\\";case"\b":return"\\b";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";default:return e(t)}}escapeStringlike(t,e){let n=e;for(let r of t)n+=r===e?"\\"+e:this.escapeStringlikeChar(r);return n+e}writeSeq(t,e,n,r){let s=n[Symbol.iterator]();this.pieces.push(t);const i=s.next();if(!0!==i.done){const t=i.value,e=s.next();if(!0===e.done)r(t);else{let n;for(this.indentCount++,this.writeIndent(),r(t),this.writeIndentSpace(),r(e.value);!0!==(n=s.next()).done;)this.writeIndentSpace(),r(n.value);this.indentCount--,this.writeIndent()}}this.pieces.push(e)}writeBytes(t){var e,n;const r=null!==(e=this.options.maxBinaryAsciiLength)&&void 0!==e?e:1024,s=null!==(n=this.options.maxBinaryAsciiProportion)&&void 0!==n?n:.75;if(t.length>=r)this.writeBase64(t);else{let e=0,n=Math.min(t.length,r);for(let r=0;r<n;r++){const n=t[r];switch(n){case 9:case 10:case 13:e++;break;default:n>=32&&n<=126&&e++}}0===n||e/n>=s?this.writeBinaryStringlike(t):this.writeBase64(t)}}writeBase64(t){this.pieces.push("#[",i(t),"]")}writeBinaryStringlike(t){let e='#"';for(let n of t)e+=34===n?'\\"':this.escapeStringlikeChar(String.fromCharCode(n),(t=>n>=32&&n<=126&&92!==n?t:"\\x"+("0"+n.toString(16)).slice(-2)));this.pieces.push(e+'"')}couldBeFlat(t){let e=!1;for(let n of t){if(Array.isArray(n)||Set.isSet(n)||Map.isMap(n)){if(e)return!1;e=!0}if(this.includeAnnotations&&ut(n)&&n.annotations.length>1)return!1}return!0}}class Pt{constructor(t={},e){var n;t instanceof Ut?(this.state=t,this.embeddedWrite=e):(this.state=new Ut(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:Vt)}static stringify(t,e){const n=new Pt(e);return n.push(t),n.contents()}contents(){return this.state.pieces.join("")}get includeAnnotations(){return this.state.includeAnnotations}push(t){switch(typeof t){case"boolean":this.state.pieces.push(t?"#t":"#f");break;case"string":this.state.pieces.push(this.state.escapeStringlike(t,'"'));break;case"symbol":{const e=t.description;/^[-a-zA-Z0-9~!$%^&*?_=+/.]+$/.exec(e)&&!jt.exec(e)?this.state.pieces.push(e):this.state.pieces.push(this.state.escapeStringlike(e,"|"));break}case"bigint":case"number":this.state.pieces.push(""+t);break;case"object":if(null===t)throw new Error("Cannot encode null in Preserves Writer.push");if(qt(t))t.__preserve_text_on__(this);else if(qt(t))t.__preserve_text_on__(this);else if(ArrayBuffer.isView(t))if(t instanceof Uint8Array)this.state.writeBytes(t);else{const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.state.writeBytes(e)}else if(g.isRecord(t)){const e=this.state.couldBeFlat(t);this.state.pieces.push("<"),this.push(t.label),e||this.state.indentCount++;for(let n of t)e?this.state.pieces.push(" "):this.state.writeIndentSpace(),this.push(n);e||this.state.indentCount--,this.state.pieces.push(">")}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(t)?x(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new Pt(this.state,Mt).push(this.embeddedWrite.toValue(t))):et(new Q(t),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.state.writeSeq("[","]",t,(t=>this.push(t)));break;default:(e=>{throw new Error(`Internal error: unhandled in Preserves Writer.push for ${t}`)})()}return this}}function Nt(t){return Tt(t)}function Tt(t,e){return function t(n){var r,s;switch(typeof n){case"number":if(!Number.isInteger(n)){const t=null!==(s=null===(r=null==e?void 0:e.onNonInteger)||void 0===r?void 0:r.call(e,n))&&void 0!==s?s:void 0;if(void 0!==t)return t;throw new TypeError("Refusing to autoconvert non-integer number to Double")}case"bigint":case"string":case"symbol":case"boolean":return n;case"undefined":case"function":break;case"object":if(null===n)break;if("function"==typeof n.__as_preserve__)return n.__as_preserve__();if(g.isRecord(n))return n;if(Array.isArray(n))return n.map(t);if(ArrayBuffer.isView(n)||n instanceof ArrayBuffer)return c.from(n);if(Map.isMap(n)){const e=new Z;return n.forEach(((n,r)=>e.set(t(r),t(n)))),e}if(st.isSet(n)){const e=new st;return n.forEach((n=>e.add(t(n)))),e}if(x(n))return n;{const e={};return Object.entries(n).forEach((([n,r])=>e[n]=t(r))),e}}throw new TypeError("Cannot represent JavaScript value as Preserves: "+n)}(t)}function Ft(t,e){return new Dt(t,e).next()}function Rt(t,e){return new Dt(t,e).readToEnd()}Y.stringMap=function(t){const e=new Z;return Object.entries(t).forEach((([t,n])=>e.set(t,Nt(n)))),e};const zt={write(t,e){if(e instanceof S)new Pt(t,this).push(e.generic);else{try{const n=Nt(e);if(!x(n))return void new Pt(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Ht(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:zt,Pt.stringify(Nt(t),e)}function Lt(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Ht(e)),n.push(t[r+1])})),n.join("")}function Wt(t,e){return ct(t,e)?e:void 0}[ft,c,Z,rt].forEach((t=>{t.prototype.toString=function(){return Ht(this)}}));class $t{constructor(t,e){this.index=0,this.packet=d(t),this.options=e}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}write(t){this.index===this.packet.length?this.packet=d(t):this.packet=c.concat([this.packet.slice(this.index),t])._view,this.index=0}atEnd(){return this.index>=this.packet.length}mark(){return this.index}restoreMark(t){this.index=t}shortGuard(t,e){if(this.atEnd())return e();const n=this.mark();try{return t()}catch(t){if(w.isShortPacket(t))return this.restoreMark(n),e();throw t}}nextbyte(){if(this.atEnd())throw new w("Short packet");return this.packet[this.index++]}nextbytes(t){const e=this.index;if(this.index+=t,this.index>this.packet.length)throw new w("Short packet");return new DataView(this.packet.buffer,this.packet.byteOffset+e,t)}varint(){const t=this.nextbyte();return t<128?t:(this.varint()<<7)+(t-128)}peekend(){return this.nextbyte()===t.End||(this.index--,!1)}nextint(t){const e=this.index;if(0===t)return 0;if(t>7)return this.nextbigint(t);if(7===t){const e=this.packet[this.index];if(e>=32&&e<224)return this.nextbigint(t)}let n=this.nextbyte();128&n&&(n-=256);for(let e=1;e<t;e++)n=256*n+this.nextbyte();return Number.isSafeInteger(n)?n:(this.index=e,this.nextbigint(t))}nextbigint(t){if(0===t)return BigInt(0);const e=c.from(this.nextbytes(t));if(e.get(0)>=128){const t=e.toHex((t=>h(15-t)));return~BigInt("0x"+t)}{const t=e.toHex();return BigInt("0x"+t)}}wrap(t){return this.includeAnnotations?new ft(t):t}unshiftAnnotation(t,e){return this.includeAnnotations&&e.annotations.unshift(t),e}}const Gt={decode(t){throw new Error("Embeddeds not permitted at this point in Preserves document")},fromValue(t,e){throw new Error("Embeddeds not permitted at this point in Preserves document")}};class Kt{constructor(t=new Uint8Array(0),e){var n,r,s;if(t instanceof $t)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:Gt;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new $t(t,n),this.embeddedDecode=null!==(s=n.embeddedDecode)&&void 0!==s?s:Gt}}write(t){this.state.write(t)}nextvalues(){const t=[];for(;!this.state.peekend();)t.push(this.next());return t}static dictionaryFromArray(t){const e=new Q;if(t.length%2)throw new y("Missing dictionary value");for(let n=0;n<t.length;n+=2){if(e.has(t[n]))throw new y(`Duplicate key: ${Ht(t[n])}`);e.set(t[n],t[n+1])}return e.simplifiedValue()}next(){const e=this.state.nextbyte();switch(e){case t.False:return this.state.wrap(!1);case t.True:return this.state.wrap(!0);case t.End:throw new y("Unexpected Compound end marker");case t.Annotation:{const t=this.next(),e=this.next();return this.state.unshiftAnnotation(t,e)}case t.Embedded:return this.state.wrap(this.embeddedDecode.decode(this.state));case t.Ieee754:if(8===this.state.varint())return this.state.wrap(St.fromBytes(this.state.nextbytes(8)));throw new y("Invalid IEEE754 size");case t.SignedInteger:return this.state.wrap(this.state.nextint(this.state.varint()));case t.String:return this.state.wrap(c.from(this.state.nextbytes(this.state.varint())).fromUtf8());case t.ByteString:return this.state.wrap(c.from(this.state.nextbytes(this.state.varint())));case t.Symbol:return this.state.wrap(Symbol.for(c.from(this.state.nextbytes(this.state.varint())).fromUtf8()));case t.Record:{const t=this.nextvalues();if(0===t.length)throw new y("Too few elements in encoded record");return this.state.wrap(g(t[0],t.slice(1)))}case t.Sequence:return this.state.wrap(this.nextvalues());case t.Set:{const t=new st;for(const e of this.nextvalues()){if(t.has(e))throw new y(`Duplicate value: ${Ht(e)}`);t.add(e)}return this.state.wrap(t)}case t.Dictionary:return this.state.wrap(Kt.dictionaryFromArray(this.nextvalues()));default:throw new y("Unsupported Preserves tag: "+e)}}try_next(){return this.state.shortGuard((()=>this.next()),(()=>{}))}atEnd(){return this.state.atEnd()}mark(){return this.state.mark()}restoreMark(t){return this.state.restoreMark(t)}skip(){this.next()}withEmbeddedDecode(t,e){return e(new Kt(this.state,t))}skipAnnotations(e){const n=this.mark();for(;!this.state.atEnd()&&this.state.packet[this.state.index]===t.Annotation;)this.state.index++,this.skip();return e((()=>this.restoreMark(n)))}nextBoolean(){return this.skipAnnotations((e=>{switch(this.state.nextbyte()){case t.False:return!1;case t.True:return!0;default:return e()}}))}nextDouble(){return this.skipAnnotations((e=>this.state.nextbyte()!==t.Ieee754||8!==this.state.nextbyte()?e():St.fromBytes(this.state.nextbytes(8))))}nextEmbedded(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Embedded?this.embeddedDecode.decode(this.state):e()))}nextSignedInteger(){return this.skipAnnotations((e=>this.state.nextbyte()===t.SignedInteger?this.state.nextint(this.state.varint()):e()))}nextString(){return this.skipAnnotations((e=>this.state.nextbyte()===t.String?c.from(this.state.nextbytes(this.state.varint())).fromUtf8():e()))}nextByteString(){return this.skipAnnotations((e=>this.state.nextbyte()===t.ByteString?c.from(this.state.nextbytes(this.state.varint())):e()))}nextSymbol(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Symbol?Symbol.for(c.from(this.state.nextbytes(this.state.varint())).fromUtf8()):e()))}openRecord(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Record||(e(),!1)))}openSequence(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Sequence||(e(),!1)))}openSet(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Set||(e(),!1)))}openDictionary(){return this.skipAnnotations((e=>this.state.nextbyte()===t.Dictionary||(e(),!1)))}closeCompound(){return this.state.peekend()}}function Jt(t,e={}){return new Kt(t,e).next()}function Xt(t,e={}){return Jt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const Zt=Object.assign({},Bt,Mt),Qt=Object.assign({},Gt,Vt),Yt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},te=Object.assign({},Yt,B);var ee;!function(t){t[t.Boolean=0]="Boolean",t[t.Double=1]="Double",t[t.SignedInteger=2]="SignedInteger",t[t.String=3]="String",t[t.ByteString=4]="ByteString",t[t.Symbol=5]="Symbol",t[t.Record=6]="Record",t[t.Sequence=7]="Sequence",t[t.Set=8]="Set",t[t.Dictionary=9]="Dictionary",t[t.Embedded=10]="Embedded",t[t.Annotated=11]="Annotated"}(ee||(ee={}));class ne{boolean(t){}double(t){}integer(t){}string(t){}bytes(t){}symbol(t){}record(t,e){e(t.label),t.forEach(e)}array(t,e){t.forEach(e)}set(t,e){t.forEach(e)}dictionary(t,e){t.forEach(((t,n)=>{e(n),e(t)}))}annotated(t,e){e(t.item),t.annotations.forEach(e)}embedded(t,e){}}class re extends ne{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class se{boolean(t){return t}double(t){return kt(t)}integer(t){return t}string(t){return t}bytes(t){return t}symbol(t){return t}record(t,e){return g(e(t.label),t.map(e))}array(t,e){return t.map(e)}set(t,e){return t.map(e)}dictionary(t,e){const n=new Q;return t.forEach(((t,r)=>n.set(e(r),e(t)))),n.simplifiedValue()}annotated(t,e){return pt(e(t.item),...t.annotations.map(e))}}class ie extends se{embedded(t,e){return t}}class oe extends se{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}function ae(t){switch(typeof t){case"boolean":return ee.Boolean;case"number":if(Number.isInteger(t))return ee.SignedInteger;throw new Error("Non-integer number in Preserves valueClass; missing Float wrapper?");case"bigint":return ee.SignedInteger;case"string":return ee.String;case"symbol":return ee.Symbol;case"object":return g.isRecord(t)?ee.Record:Array.isArray(t)?ee.Sequence:st.isSet(t)?ee.Set:Y.isDictionary(t)?ee.Dictionary:ft.isAnnotated(t)?ee.Annotated:c.isBytes(t)?ee.ByteString:vt.isDouble(t)?ee.Double:ee.Embedded;default:(t=>{throw new Error("Internal error")})()}}const ue=new ie;function ce(t,e){const n=t=>{switch(typeof t){case"boolean":return e.boolean(t);case"number":return Number.isInteger(t)?e.integer(t):e.double(t);case"bigint":return e.integer(t);case"string":return e.string(t);case"symbol":return e.symbol(t);case"object":if(g.isRecord(t))return e.record(t,n);if(Array.isArray(t))return e.array(t,n);if(st.isSet(t))return e.set(t,n);if(x(t))return e.embedded(t,n);if(ft.isAnnotated(t))return e.annotated(t,n);if(c.isBytes(t))return e.bytes(t);if(vt.isDouble(t))return e.double(t.value);if(Y.isDictionary(t))return e.dictionary(new Q(t),n);default:(t=>{throw new Error("Internal error")})()}};return n(t)}function he(t,e){return ce(t,new oe(e))}function le(t,e){return ce(t,new re(e))}function de(t,e,...n){function r(){throw new Error("Cannot merge items")}function s(e,n){return e===n?e:bt(e)||bt(n)||!ct(e,n)?ce(e,{boolean:r,double:t=>ct(e,n)?e:r(),integer:r,string:r,bytes:t=>ct(e,n)?e:r(),symbol:r,record:t=>(g.isRecord(n)||r(),g(s(t.label,n.label),i(t,n))),array:t=>(Array.isArray(n)&&!g.isRecord(n)||r(),i(t,n)),set(t){r()},dictionary(t){const e=Y.asMap(n);void 0===e&&r();const i=new Q;return t.forEach(((t,n)=>{const r=e.get(n);i.set(n,void 0===r?t:s(t,r))})),e.forEach(((e,n)=>{t.has(n)||i.set(n,e)})),i.simplifiedValue()},annotated:t=>s(t,$(n)),embedded(e){x(n)||r();const s=t(e,n);return void 0===s&&r(),s}}):e}function i(t,e){return t.length<=e.length?e.map(((e,n)=>n<t.length?s(t[n],e):e)):t.map(((t,n)=>n<e.length?s(t,e[n]):t))}return n.reduce(s,e)}function fe(t){switch(ut(t)&&(t=t.item),typeof t){case"boolean":return 0;case"number":case"bigint":return 3;case"string":return 4;case"symbol":return 6;case"object":if(vt.isFloat(t))return 2;if(c.isBytes(t))return 5;if(Array.isArray(t))return"label"in t?7:8;if(st.isSet(t))return 9;if(Y.isDictionary(t))return 10;if(x(t))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}function pe(t,e,n=((t,e)=>ct(t,e)?0:t<e?-1:1)){return function t(e,r){ut(e)&&(e=e.item),ut(r)&&(r=r.item);const s=fe(e),i=fe(r);if(s<i)return-1;if(s>i)return 1;switch(s){case 0:case 3:case 4:return e<r?-1:e>r?1:0;case 2:{const t=e.value,n=r.value;return t<n?-1:t>n?1:0}case 5:return c.compare(e,r);case 6:{const t=e.description,n=r.description;return t<n?-1:t>n?1:0}case 7:{const n=t(e.label,r.label);if(0!==n)return n}case 8:{const n=e,s=r,i=Math.min(n.length,s.length);for(let e=0;e<i;e++){const r=t(n[e],s[e]);if(0!==r)return r}return n.length<s.length?-1:n.length>s.length?1:0}case 9:return t(Array.from(e).sort(t),Array.from(r).sort(t));case 10:return t(Array.from(Y.asMap(e).entries()).sort(t),Array.from(Y.asMap(r).entries()).sort(t));case 11:return n(e,r);default:throw new Error("Invalid typeCode: "+s)}}(t,e)}class me{constructor(t){this.text=t}__as_preserve__(){return g(Symbol.for("p"),[Symbol.for(this.text)])}isComma(){return","===this.text}static isComma(t){return t instanceof me&&t.isComma()}isColon(t=1){return this.text===":".repeat(t)}static isColon(t,e=1){return t instanceof me&&t.isColon(e)}}class ye{constructor(t,e){this.expr=t,this.annotations=e}__as_preserve__(){var t,e;const n=Nt(this.expr);return new S(null!==(e=null===(t=this.annotations)||void 0===t?void 0:t.wrap(n))&&void 0!==e?e:n)}}class be{constructor(){this.positions=[],this.exprs=[],this.annotations=void 0}get(t){if(!(t>=this.exprs.length))return{position:this.positions[t],item:this.exprs[t],annotations:this.annotations&&this.annotations[t]}}push(t,e,n){if(void 0===e){const e=t;e.annotations&&(this._ensureAnnotations()[this.exprs.length]=e.annotations),this.positions.push(e.position),this.exprs.push(e.item)}else n&&(this._ensureAnnotations()[this.exprs.length]=n),this.positions.push(e),this.exprs.push(t);return!0}_ensureAnnotations(){return void 0===this.annotations&&(this.annotations=[]),this.annotations}_annotationsAt(t){var e,n;return null!==(e=(n=this._ensureAnnotations())[t])&&void 0!==e?e:n[t]=new ge}preservesValues(){return this.exprs.map(((t,e)=>{var n;const r=Nt(t);return void 0!==(null===(n=this.annotations)||void 0===n?void 0:n[e])?this.annotations[e].wrap(r):r}))}map(t,e=0){const n=[];for(let r=e;r<this.exprs.length;r++)n.push(t(this.get(r),r));return n}[Symbol.iterator](){let t=this,e=0;return{next:()=>e<t.exprs.length?{done:!1,value:t.get(e++)}:{done:!0,value:void 0},[Symbol.iterator]:()=>t[Symbol.iterator]()}}}class we extends be{__as_preserve__(){return this.preservesValues()}}class ge extends be{wrap(t){return pt(t,...this.preservesValues())}}class ve extends be{__as_preserve__(){const t=this.preservesValues();switch(this.variant){case"sequence":return t;case"record":return g(Symbol.for("r"),t);case"block":return g(Symbol.for("b"),t);case"group":return g(Symbol.for("g"),t);case"set":return g(Symbol.for("s"),t)}}}class xe extends ve{get variant(){return"sequence"}}class _e extends ve{get variant(){return"record"}}class Se extends ve{get variant(){return"block"}}class ke extends ve{get variant(){return"group"}}let Ee=class extends ve{get variant(){return"set"}};var Ae=Object.freeze({__proto__:null,Annotations:ge,BaseCompound:be,Block:Se,Compound:ve,Document:we,Embedded:ye,Group:ke,Punct:me,Reader:class extends It{nextDocument(t="all"){const e=new we;if(this.readExpr(e),"all"===t)for(;this.readExpr(e););return e}readCompound(t,e){for(;;){if(this.state.skipws(),this.state.peek()===e)return this.state.advance(),t;this.readExpr(t)||this.state.error(`Missing "${e}"`,this.state.copyPos())}}readSimpleExpr(t){return this._readInto(t,!1)}readExpr(t){return this._readInto(t,!0)}_readInto(t,e){for(;;){if(this.state.skipws(),this.state.atEnd())return!1;const n=this.state.copyPos(),r=this.state.nextchar();switch(r){case'"':return t.push(this.state.readString('"'),n);case"|":return t.push(Symbol.for(this.state.readString("|")),n);case";":if(e)return t.push(new me(";"),n);this.state.error("Semicolon is not permitted at this location",n);case"@":this.readSimpleExpr(t._annotationsAt(t.exprs.length))||this.state.error("Missing annotation",n);continue;case":":{let s=r;for(;!this.state.atEnd()&&":"===this.state.peek();)s+=":",this.state.advance();if(e)return t.push(new me(s),n);this.state.error("Colons are not permitted at this location",n)}case"#":{const e=this.state.nextchar();switch(e){case" ":case"\t":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push(this.state.readCommentLine(),e);continue}case"\n":case"\r":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push("",e);continue}case"!":{const e=this.state.copyPos(),n=new _e;n.push(Symbol.for("interpreter"),e),n.push(this.state.readCommentLine(),e),t._annotationsAt(t.exprs.length).push(n,e);continue}case"f":return this.state.requireDelimiter("#f"),t.push(!1,n);case"t":return this.state.requireDelimiter("#t"),t.push(!0,n);case"{":return t.push(this.readCompound(new Ee,"}"),n);case'"':return t.push(this.state.readLiteralBinary(),n);case"x":switch(this.state.nextchar()){case'"':return t.push(this.state.readHexBinary(),n);case"d":return t.push(this.state.readHexFloat(),n);default:this.state.error("Invalid #x syntax",n)}case"[":return t.push(this.state.readBase64Binary(),n);case":":{const e=new be;if(!this.readSimpleExpr(e))return!1;const r=new ye(e.exprs[0],e.annotations&&e.annotations[0]);return t.push(r,n)}default:this.state.error(`Invalid # syntax: ${e}`,n)}}case"(":return t.push(this.readCompound(new ke,")"),n);case"<":return t.push(this.readCompound(new _e,">"),n);case"[":return t.push(this.readCompound(new xe,"]"),n);case"{":return t.push(this.readCompound(new Se,"}"),n);case">":this.state.error("Unexpected >",n);case"]":this.state.error("Unexpected ]",n);case"}":this.state.error("Unexpected }",n);case",":if(e)return t.push(new me(","),n);this.state.error("Comma is not permitted at this location",n);default:return t.push(this.state.readRawSymbolOrNumber(r),n)}}}},Record:_e,Sequence:xe,Set:Ee,asPreserves:function(t,e={}){var n;const r=null!==(n=e.error)&&void 0!==n?n:(t,e)=>{throw new Error(dt(e)+": "+t)};function s(t){return Array.from(t).filter((t=>!me.isComma(t.item)))}return function t(n){if(n.item instanceof me)return r("invalid-punctuation",n.position);if(n.item instanceof ye)return e.onEmbedded?e.onEmbedded({position:n.position,item:n.item.expr},t):r("unexpected-embedded",n.position);if(!(n.item instanceof ve))return n.item;switch(n.item.variant){case"sequence":return s(n.item).map(t);case"record":{const e=s(n.item).map(t);if(e.length<1)return r("invalid-record",n.position);const i=e.slice(1);return i.label=e[0],i}case"block":{const e=new Q,i=s(n.item);if(i.length%3!=0)return r("invalid-dictionary",n.position);for(let n=0;n<i.length;n+=3){if(!me.isColon(i[n+1].item))return r("missing-colon",i[n+1].position);const s=t(i[n]),o=t(i[n+2]);e.set(s,o)}return e.simplifiedValue()}case"group":return e.onGroup?e.onGroup(n):r("unexpected-group",n.position);case"set":return new st(s(n.item).map(t))}}(t)}});Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const je=Array,Ce=Symbol;export{ft as Annotated,je as Array,c as Bytes,e as Constants,y as DecodeError,Kt as Decoder,$t as DecoderState,Y as Dictionary,Q as DictionaryMap,J as DictionaryType,kt as Double,St as DoubleFloat,_ as Embedded,X as EncodableDictionary,nt as EncodableSet,b as EncodeError,D as Encoder,I as EncoderState,p as ErrorType,H as FlexMap,L as FlexSet,vt as Float,gt as FloatType,re as ForEachEmbedded,S as GenericEmbedded,ue as IDENTITY_FOLD,ie as IdentityFold,N as IdentityMap,T as IdentitySet,v as IsEmbedded,F as IsMap,at as IsPreservesAnnotated,u as IsPreservesBytes,R as IsSet,W as JsDictionary,Z as KeyedDictionary,rt as KeyedSet,oe as MapFold,jt as NUMBER_RE,Ae as Pexpr,m as PreservesCodecError,Dt as Reader,It as ReaderBase,Ct as ReaderState,g as Record,st as Set,w as ShortPacket,Ce as Symbol,ee as ValueClass,se as ValueFold,ne as VoidFold,Pt as Writer,Ut as WriterState,z as _iterMap,pt as annotate,mt as annotations,Wt as asLiteral,V as canonicalEncode,U as canonicalString,pe as compare,f as dataview,Jt as decode,r as decodeBase64,Xt as decodeWithAnnotations,C as embeddedId,O as encode,i as encodeBase64,tt as encodeDictionaryOn,it as encodeSetOn,P as encodeWithAnnotations,xt as floatValue,_t as floatlikeString,ce as fold,le as forEachEmbedded,dt as formatPosition,Nt as fromJS,Tt as fromJS_options,Zt as genericEmbeddedType,Bt as genericEmbeddedTypeDecode,Mt as genericEmbeddedTypeEncode,h as hexDigit,te as identityEmbeddedType,Yt as identityEmbeddedTypeDecode,B as identityEmbeddedTypeEncode,ct as is,ut as isAnnotated,bt as isCompound,x as isEmbedded,k as isPreservable,qt as isPreserveWritable,wt as isSequence,he as mapEmbeddeds,de as merge,Qt as neverEmbeddedType,Gt as neverEmbeddedTypeDecode,Vt as neverEmbeddedTypeEncode,ht as newPosition,Ft as parse,Rt as parseAll,G as peel,yt as position,Lt as preserves,Ht as stringify,zt as stringifyEmbeddedWrite,K as strip,fe as typeCode,$ as unannotate,d as underlying,l as unhexDigit,lt as updatePosition,ae as valueClass,et as writeDictionaryOn,ot as writeSetOn};

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Preserves={})}(this,(function(t){"use strict";var e;!function(t){t[t.False=128]="False",t[t.True=129]="True",t[t.End=132]="End",t[t.Annotation=133]="Annotation",t[t.Embedded=134]="Embedded",t[t.Ieee754=135]="Ieee754",t[t.SignedInteger=176]="SignedInteger",t[t.String=177]="String",t[t.ByteString=178]="ByteString",t[t.Symbol=179]="Symbol",t[t.Record=180]="Record",t[t.Sequence=181]="Sequence",t[t.Set=182]="Set",t[t.Dictionary=183]="Dictionary"}(e||(e={}));var n=Object.freeze({__proto__:null,get Tag(){return e}});const r={};function s(t){const e=new Uint8Array(Math.floor(3*t.length/4));let n=0,s=0;for(;n<t.length;){const i=r[t[n++]],o=r[t[n++]],a=r[t[n++]],c=r[t[n++]],u=i<<18|o<<12|a<<6|c;if(e[s++]=u>>16&255,void 0===a)break;if(e[s++]=u>>8&255,void 0===c)break;e[s++]=255&u}return e.subarray(0,s)}[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"].forEach(((t,e)=>r[t]=e)),r["+"]=r["-"]=62,r["/"]=r._=63;const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(t){let e="",n=0,r=0;for(let s of t)for(n=(63&n)<<8|s,r+=8;r>=6;){r-=6;e+=i[n>>r&63]}if(r>0){e+=i[n<<6-r&63]}return e}const a=new TextEncoder,c=new TextDecoder("utf-8",{fatal:!0}),u=Symbol.for("IsPreservesBytes");class h{constructor(t=new Uint8Array){if(h.isBytes(t))this._view=t._view;else if(ArrayBuffer.isView(t))this._view=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else if(t instanceof ArrayBuffer)this._view=new Uint8Array(t);else if("string"==typeof t)this._view=a.encode(t);else if("number"==typeof t)this._view=new Uint8Array(t);else{if("number"!=typeof t.length)throw new TypeError("Attempt to initialize Bytes from unsupported value: "+t);this._view=Uint8Array.from(t)}}dataview(){return new DataView(this._view.buffer,this._view.byteOffset,this._view.byteLength)}get length(){return this._view.length}static from(t){return new h(t)}static of(...t){return new h(Uint8Array.of(...t))}static fromLatin1(t){const e=new h(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>=256)throw new Error("Codepoint out of range for 'latin1' byte encoding");e._view[n]=r}return e}static fromBase64(t){return new h(s(t))}static fromHex(t){if(1&t.length)throw new Error("Cannot decode odd-length hexadecimal string");const e=new h(t.length>>1);return h._raw_fromHexInto(t,e._view),e}static _raw_fromHexInto(t,e){const n=t.length>>1;for(let r=0;r<n;r++)e[r]=l(t.charCodeAt(r<<1))<<4|l(t.charCodeAt(1+(r<<1)))}static fromIO(t){return"string"==typeof t||h.isBytes(t)?t:new h(t)}static toIO(t){return"string"==typeof t?t:h.isBytes(t)?t._view:t}get(t){return this._view[t]}equals(t){if(!h.isBytes(t))return!1;if(t.length!==this.length)return!1;const e=this._view,n=t._view;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}hashCode(){const t=this._view;let e=0;for(let n=0;n<t.length;n++)e=31*e+t[n]|0;return e}static compare(t,e){return t<e?-1:e<t?1:0}static decodeUtf8(t){return c.decode(f(t))}fromUtf8(){return c.decode(this._view)}__as_preserve__(){return this}static __from_preserve__(t){return h.isBytes(t)?t:void 0}toLatin1(){return String.fromCharCode.apply(null,this._view)}toBase64(){return o(this._view)}toHex(t=d){var e=[];for(let n=0;n<this.length;n++)e.push(t(this._view[n]>>4)),e.push(t(15&this._view[n]));return e.join("")}valueOf(){return this.toHex()}__preserve_on__(t){t.state.emitbyte(e.ByteString),t.state.varint(this.length),t.state.emitbytes(this._view)}__preserve_text_on__(t){t.state.writeBytes(this._view)}get[u](){return!0}static isBytes(t){return!!(null==t?void 0:t[u])}}function d(t){return"0123456789abcdef"[t]}function l(t,e=Error){if(t>=48&&t<=57)return t-48;if(t>=97&&t<=102)return t-97+10;if(t>=65&&t<=70)return t-65+10;throw new e("Invalid hex digit: "+String.fromCharCode(t))}function f(t){return t instanceof Uint8Array?t:t._view}function p(t){return t instanceof DataView?t:t.dataview()}h.concat=function(t){let e=0;for(let n=0;n<t.length;n++)e+=f(t[n]).length;const n=new h(e);let r=0;for(let e=0;e<t.length;e++){const s=f(t[e]);n._view.set(s,r),r+=s.length}return n},function(){for(const t of"entries every find findIndex forEach includes indexOf join\nkeys lastIndexOf reduce reduceRight some toLocaleString values".split(/\s+/))h.prototype[t]=function(...e){return this._view[t](...e)};for(const t of"filter map slice subarray".split(/\s+/))h.prototype[t]=function(...e){return new h(this._view[t](...e))};for(const t of"reverse sort".split(/\s+/))h.prototype[t]=function(...e){return new h(this._view.slice()[t](...e))};h.prototype[Symbol.iterator]=function(){return this._view[Symbol.iterator]()}}();const y=Symbol.for("ErrorType");class m{static isCodecError(t,e){return(null==t?void 0:t[y])===e}}class b extends Error{get[y](){return"DecodeError"}constructor(t,e){super(t),this.pos=e}static isDecodeError(t){return m.isCodecError(t,"DecodeError")}}class g extends Error{get[y](){return"EncodeError"}static isEncodeError(t){return m.isCodecError(t,"EncodeError")}constructor(t,e){super(t),this.irritant=e}}class w extends b{get[y](){return"ShortPacket"}static isShortPacket(t){return m.isCodecError(t,"ShortPacket")}}function v(t,e){return e.label=t,e}!function(t){t.isRecord=function(t){return Array.isArray(t)&&"label"in t},t.constructorInfo=function(t){return{label:t.label,arity:t.length}},t.isClassOf=function(e,n){return t.isRecord(n)&&st(e.label,n.label)&&e.arity===n.length},t.makeConstructor=function(){return(e,n)=>{const r=(...n)=>t(e,n),s={label:e,arity:n.length};return r.constructorInfo=s,r.isClassOf=e=>t.isClassOf(s,e),r.fieldNumbers={},r._={},n.forEach(((t,e)=>{r._[t]=t=>t[e],r.fieldNumbers[t]=e})),r}}}(v||(v={}));const x=Symbol.for("IsEmbedded");function _(t){return!!(null==t?void 0:t[x])}class S{get[x](){return!0}constructor(t){this.generic=t}equals(t,e){return"object"==typeof t&&"generic"in t&&e(this.generic,t.generic)}toString(){return this.generic.toString()}}function E(t){return"object"==typeof t&&null!==t&&"__preserve_on__"in t&&"function"==typeof t.__preserve_on__}function k(t){return String.fromCharCode.apply(null,t)}let A=0;const D=new WeakMap;function C(t){let e=D.get(t);return void 0===e&&(e=A++,D.set(t,e)),e}const I={encode(t,e){new B(t,this).push(C(e))}};class j{constructor(t){this.chunks=[],this.view=new DataView(new ArrayBuffer(256)),this.index=0,this.options=t}get canonical(){var t;return null===(t=this.options.canonical)||void 0===t||t}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t?t:!this.canonical}contents(){if(0===this.chunks.length){const t=this.index;return this.index=0,new h(this.view.buffer.slice(0,t))}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],h.concat(t)}}contentsString(){if(0===this.chunks.length){const t=k(new Uint8Array(this.view.buffer,0,this.index));return this.index=0,t}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],t.map(k).join("")}}rotatebuffer(t){this.chunks.push(new Uint8Array(this.view.buffer,0,this.index)),this.view=new DataView(new ArrayBuffer(t)),this.index=0}makeroom(t){this.index+t>this.view.byteLength&&this.rotatebuffer(t+4096)}emitbyte(t){this.makeroom(1),this.view.setUint8(this.index++,t)}emitbytes(t){this.makeroom(t.length),new Uint8Array(this.view.buffer).set(t,this.index),this.index+=t.length}claimbytes(t){this.makeroom(t);const e=new Uint8Array(this.view.buffer,this.index,t);return this.index+=t,e}varint(t){for(;t>=128;)this.emitbyte(t%128+128),t=Math.floor(t/128);this.emitbyte(t)}encodeint(t){if("bigint"==typeof t)return this.encodebigint(t);if(this.emitbyte(e.SignedInteger),0===t)return void this.emitbyte(0);const n=(-1===t?0:Math.floor(Math.log2(t>0?t:-(1+t)))+1)+1+7>>3;this.varint(n);const r=(t,e)=>{t>0&&(r(t-1,Math.floor(e/256)),this.emitbyte(255&e))};r(n,t)}encodebigint(t){let n;if(this.emitbyte(e.SignedInteger),t>0)n=t.toString(16),1&n.length?n="0"+n:l(n.charCodeAt(0))>=8&&(n="00"+n);else{if(!(t<0))return void this.emitbyte(0);{const e=(~t).toString(16);n="";for(let t=0;t<e.length;t++)n+="fedcba9876543210"[l(e.charCodeAt(t))];1&n.length?n="f"+n:l(n.charCodeAt(0))<8&&(n="ff"+n)}}this.varint(n.length>>1),h._raw_fromHexInto(n,this.claimbytes(n.length>>1))}encodebytes(t,e){this.emitbyte(t),this.varint(e.length),this.emitbytes(e)}}class B{constructor(t={},e){var n;t instanceof j?(this.state=t,this.embeddedEncode=null!=e?e:I):(this.state=new j(t),this.embeddedEncode=null!==(n=t.embeddedEncode)&&void 0!==n?n:I)}withEmbeddedEncode(t,e){return e(new B(this.state,t)),this}get canonical(){return this.state.canonical}get includeAnnotations(){return this.state.includeAnnotations}contents(){return this.state.contents()}contentsString(){return this.state.contentsString()}grouped(t,n){this.state.emitbyte(t),n(),this.state.emitbyte(e.End)}push(t){if(E(t))t.__preserve_on__(this);else if(E(t))t.__preserve_on__(this);else if("boolean"==typeof t)this.state.emitbyte(t?e.True:e.False);else if("number"==typeof t||"bigint"==typeof t)this.state.encodeint(t);else if("string"==typeof t)this.state.encodebytes(e.String,new h(t)._view);else if("symbol"==typeof t){const n=Symbol.keyFor(t);if(void 0===n)throw new g("Cannot preserve non-global Symbol",t);this.state.encodebytes(e.Symbol,new h(n)._view)}else if(ArrayBuffer.isView(t))if(t instanceof Uint8Array)this.state.encodebytes(e.ByteString,t);else{const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.state.encodebytes(e.ByteString,n)}else if(v.isRecord(t)){this.state.emitbyte(e.Record),this.push(t.label);for(let e of t)this.push(e);this.state.emitbyte(e.End)}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(t)?_(t)?(this.state.emitbyte(e.Embedded),this.embeddedEncode.encode(this.state,t)):G(new K(t),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.grouped(e.Sequence,(()=>{for(let e of t)this.push(e)}));return this}}function O(t,e={}){return new B(e).push(t).contents()}const V=new B({canonical:!0});let M=!1;function T(t){if(M)return new B({canonical:!0}).push(t).contentsString();{M=!0;const e=V.push(t).contentsString();return M=!1,e}}const q=Map,P=Set,F=Symbol.for("IsMap"),U=Symbol.for("IsSet");function N(t,e){const n=t=>t.done?{done:!0,value:null}:{done:!1,value:e(t.value)};return{next:e=>n(t.next(e)),return:e=>{var r,s;return n(null!==(s=null===(r=t.return)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},throw:e=>{var r,s;return n(null!==(s=null===(r=t.throw)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},[Symbol.iterator](){return this}}}F in Map.prototype||(Object.defineProperty(Map.prototype,F,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[F])),U in Set.prototype||(Object.defineProperty(Set.prototype,U,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[U]));class R{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(N(e[Symbol.iterator](),(([t,e])=>[this._key(t),[t,e]])))}_key(t){return this.canonicalizer(t)}get(t,e){const n=this.items.get(this._key(t));return void 0===n?e:n[1]}getOrSet(t,e){const n=this._key(t);let r=this.items.get(n);return void 0===r&&(r=[t,e()],this.items.set(n,r)),r[1]}set(t,e){return this.items.set(this._key(t),[t,e]),this}forEach(t,e){this.items.forEach((([n,r])=>t.call(e,r,n,this)))}entries(){return this.items.values()}keys(){return N(this.items.values(),(([t,e])=>t))}values(){return N(this.items.values(),(([t,e])=>e))}delete(t){return this.items.delete(this._key(t))}getAndDelete(t,e){const n=this._key(t),r=this.items.get(n);return void 0===r?e:(this.items.delete(n),r[1])}clear(){this.items.clear()}has(t){return this.items.has(this._key(t))}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexMap"}equals(t,e=((t,e)=>t===e)){if(!("size"in t&&"has"in t&&"get"in t))return!1;if(this.size!==t.size)return!1;for(let[n,r]of this.items.values()){if(!t.has(n))return!1;if(!e(r,t.get(n)))return!1}return!0}update(t,e,n,r=((t,e)=>t===e)){const s=this._key(t);if(this.items.has(s)){const n=this.items.get(s)[1],i=e(n);return void 0===i?(this.items.delete(s),-1):(r(i,n)||this.items.set(s,[t,i]),0)}{const r=e(n);return void 0===r?0:(this.items.set(s,[t,r]),1)}}canonicalKeys(){return this.items.keys()}get[F](){return!0}}class z{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(N(e[Symbol.iterator](),(t=>[this._key(t),t])))}_key(t){return this.canonicalizer(t)}has(t){return this.items.has(this._key(t))}get(t){const e=this._key(t);return this.items.has(e)?{item:this.items.get(e)}:null}add(t){return this.items.set(this._key(t),t),this}forEach(t,e){this.items.forEach((n=>t.call(e,n,n,this)))}entries(){return N(this.items.values(),(t=>[t,t]))}keys(){return this.items.values()}values(){return this.items.values()}delete(t){return this.items.delete(this._key(t))}clear(){this.items.clear()}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexSet"}equals(t){if(!("size"in t)||!("has"in t))return!1;if(this.size!==t.size)return!1;for(let e of this.items.values())if(!t.has(e))return!1;return!0}canonicalValues(){return this.items.keys()}union(t){const e=new z(this.canonicalizer,this);for(let n of t)e.add(n);return e}intersect(t){const e=new z(this.canonicalizer);for(let n of this)t.has(n)&&e.add(n);return e}subtract(t){const e=new z(this.canonicalizer);for(let n of this)t.has(n)||e.add(n);return e}get[U](){return!0}}function J(t){return ct.isAnnotated(t)?t.item:t}function H(e,n=1/0){return function e(n,r){if(0===r)return n;if(!ct.isAnnotated(n))return n;const s=r-1;function i(t){return e(t,s)}if(v.isRecord(n.item))return v(e(n.item.label,r),n.item.map(i));if(ct.isAnnotated(n.item))throw new Error("Improper annotation structure");if(0===s)return n.item;if(Array.isArray(n.item))return n.item.map(i);if(Q.isSet(n.item))return n.item.map(i);if(t.Dictionary.isDictionary(n.item)){const t=new K;return new K(n.item).forEach(((e,n)=>t.set(i(n),i(e)))),t.simplifiedValue()}return n.item}(e,n)}t.JsDictionary=void 0,function(t){function e(t,e){return t[e.description]}function n(t,e){return Object.hasOwnProperty.call(t,e.description)}function r(t){return Object.keys(t).length}function s(t){return N(Object.entries(t).values(),(([t,e])=>[Symbol.for(t),e]))}t.isJsDictionary=function(t){return"object"==typeof t&&null!==t&&null===Object.getPrototypeOf(Object.getPrototypeOf(t))&&"function"!=typeof t.__as_preserve__},t.from=function(t){const e={};for(const[n,r]of t)e[n.description]=r;return e},t.clear=function(t){for(const e in t)delete t[e]},t.remove=function(t,e){const r=n(t,e);return delete t[e.description],r},t.forEach=function(t,e){Object.entries(t).forEach((([t,n])=>e(n,Symbol.for(t))))},t.get=e,t.has=n,t.set=function(t,e,n){return t[e.description]=n,t},t.size=r,t.entries=s,t.keys=function(t){return N(Object.keys(t).values(),(t=>Symbol.for(t)))},t.values=function(t){return Object.values(t).values()},t.clone=function(t){const e={};return Object.keys(t).forEach((n=>e[n]=t[n])),e},t.equals=function(t,i,o=((t,e)=>t===e)){if(r(t)!==r(i))return!1;for(let[r,a]of s(t)){if(!n(i,r))return!1;if(!o(a,e(i,r)))return!1}return!0}}(t.JsDictionary||(t.JsDictionary={}));const W=Symbol.for("DictionaryType");class L extends R{constructor(t,e,n){super((e=>T(t(e))),n),this.encodeK=t,this.encodeV=e}__preserve_on__(t){G(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){X(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}}class $ extends L{get[W](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[W])}constructor(t){super((t=>t),(t=>t),t)}clone(){return new $(this)}get[Symbol.toStringTag](){return"Dictionary"}equals(e,n=((t,e)=>t===e)){const r=t.Dictionary.asMap(e);return!!r&&super.equals(r,n)}}class K{get[F](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):W in t?(this.j=void 0,this.k=t):(this.j=t,this.k=void 0)}static from(t){const e=new K;for(const[n,r]of t)e.set(n,r);return e}clear(){this.j?t.JsDictionary.clear(this.j):this.k.clear()}delete(e){return this.j?"symbol"==typeof(e=J(e))&&t.JsDictionary.remove(this.j,e):this.k.delete(e)}forEach(e,n){this.j?t.JsDictionary.forEach(this.j,((t,r)=>e.call(n,t,r,this))):this.k.forEach(e,n)}get(e){if(this.j){if("symbol"!=typeof(e=J(e)))return;return t.JsDictionary.get(this.j,e)}return this.k.get(e)}has(e){return this.j?"symbol"==typeof(e=J(e))&&t.JsDictionary.has(this.j,e):this.k.has(e)}set(e,n){if(this.j){if("symbol"==typeof e)return t.JsDictionary.set(this.j,e,n),this;this.k=new $(t.JsDictionary.entries(this.j)),this.j=void 0}return this.k.set(e,n),this}get size(){return this.j?t.JsDictionary.size(this.j):this.k.size}entries(){return this.j?t.JsDictionary.entries(this.j):this.k.entries()}keys(){return this.j?t.JsDictionary.keys(this.j):this.k.keys()}values(){return this.j?t.JsDictionary.values(this.j):this.k.values()}[Symbol.iterator](){return this.entries()}get[Symbol.toStringTag](){return"DictionaryMap"}clone(){return new K(this.j?t.JsDictionary.clone(this.j):this.k.clone())}get value(){var t;return null!==(t=this.j)&&void 0!==t?t:this.k}simplify(){if(!this.j){const t={};for(const[e,n]of this.k.entries()){if("symbol"!=typeof e)return;t[e.description]=n}this.j=t,this.k=void 0}}simplifiedValue(){return this.simplify(),this.value}asJsDictionary(){if(this.simplify(),!this.j)throw new Error("Cannot represent general dictionary as JsDictionary");return this.j}asKeyedDictionary(){var e;return null!==(e=this.k)&&void 0!==e?e:new $(t.JsDictionary.entries(this.j))}}function G(t,n,r,s){if(n.canonical){const i=Array.from(t),o=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),a=i.map((([t,e],n)=>(r(t,o),[o.contents(),n])));a.sort(((t,e)=>h.compare(t[0],e[0]))),n.grouped(e.Dictionary,(()=>a.forEach((([t,e])=>{const[o,a]=i[e];r(o,n),s(a,n)}))))}else n.grouped(e.Dictionary,(()=>t.forEach(((t,e)=>{r(e,n),s(t,n)}))))}function X(t,e,n,r){e.state.writeSeq("{","}",t.entries(),(([t,s])=>{n(t,e),ct.isAnnotated(s)&&ht(s).length>1&&e.state.isIndenting?(e.state.pieces.push(":"),e.state.indentCount++,e.state.writeIndent(),r(s,e),e.state.indentCount--):(e.state.pieces.push(": "),r(s,e))}))}t.Dictionary=void 0,function(e){function n(e){if("object"!=typeof e||null===e)return!1;switch(e[W]){case"Dictionary":return!0;case void 0:return t.JsDictionary.isJsDictionary(e);default:return!1}}e.isDictionary=n,e.asMap=function(t){return n(t)?new K(t):void 0},e.from=function(t){return K.from(t).simplifiedValue()},e.__from_preserve__=function(t){return e.isDictionary(t)?t:void 0}}(t.Dictionary||(t.Dictionary={}));class Y extends z{constructor(t,e){super((e=>T(t(e))),e),this.encodeV=t}__preserve_on__(t){tt(this,t,((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){et(this,t,((t,e)=>e.push(this.encodeV(t))))}}class Z extends Y{get[W](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[W])}constructor(t){super((t=>t),t)}map(t){return new Z(N(this[Symbol.iterator](),t))}filter(t){const e=new Z;for(let n of this)t(n)&&e.add(n);return e}clone(){return new Z(this)}get[Symbol.toStringTag](){return"Set"}}let Q=class t extends Z{static isSet(t){return"Set"===(null==t?void 0:t[W])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function tt(t,n,r){if(n.canonical){const s=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),i=Array.from(t).map((t=>(r(t,s),[s.contents(),t])));i.sort(((t,e)=>h.compare(t[0],e[0]))),n.grouped(e.Set,(()=>i.forEach((([t,e])=>r(e,n)))))}else n.grouped(e.Set,(()=>t.forEach((t=>r(t,n)))))}function et(t,e,n){e.state.writeSeq("#{","}",t,(t=>n(t,e)))}const nt=Symbol.for("IsPreservesAnnotated");function rt(t){return!!(null==t?void 0:t[nt])}function st(e,n){if(rt(e)&&(e=e.item),rt(n)&&(n=n.item),Object.is(e,n))return!0;if(typeof e!=typeof n)return("number"==typeof e&&"bigint"==typeof n||"bigint"==typeof e&&"number"==typeof n)&&e==n;if("object"==typeof e){if(null===e||null===n)return!1;if("equals"in e&&"function"==typeof e.equals)return e.equals(n,st);if(Array.isArray(e)&&Array.isArray(n)){const t="label"in e;if(t!=="label"in n)return!1;if(t&&!st(e.label,n.label))return!1;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!st(e[t],n[t]))return!1;return!0}{const r=t.Dictionary.asMap(e),s=t.Dictionary.asMap(n);if(!r||!s)return!1;if(r.size!==s.size)return!1;for(const t of r.keys()){if(!s.has(t))return!1;if(!st(r.get(t),s.get(t)))return!1}return!0}}return!1}function it(t){return{line:1,column:0,pos:0,name:t}}function ot(t,e){if(t.pos++,void 0===t.line)return!1;{let n=!1;switch(e){case"\t":t.column=t.column+8&-8;break;case"\n":t.column=0,t.line++,n=!0;break;case"\r":t.column=0;break;default:t.column++}return n}}function at(t){var e,n,r;return null===t?"<unknown>":"string"==typeof t?t:`${null!==(e=t.name)&&void 0!==e?e:""}:${null!==(n=t.line)&&void 0!==n?n:""}:${null!==(r=t.column)&&void 0!==r?r:""}:${t.pos}`}class ct{constructor(t,e){this.annotations=[],this.pos=null!=e?e:null,this.item=t}__as_preserve__(){return this}static __from_preserve__(t){return rt(t)?t:void 0}__preserve_on__(t){if(t.includeAnnotations)for(const n of this.annotations)t.state.emitbyte(e.Annotation),t.push(n);t.push(this.item)}__preserve_text_on__(t){if(t.includeAnnotations){const e=this.annotations.length<=1;for(const n of this.annotations)t.state.pieces.push("@"),t.push(n),e?t.state.pieces.push(" "):t.state.writeIndentSpace()}t.push(this.item)}equals(t){return st(this.item,ct.isAnnotated(t)?t.item:t)}get[nt](){return!0}static isAnnotated(t){return rt(t)}}function ut(t,...e){const n=ct.isAnnotated(t)?t:new ct(t);return e.forEach((t=>n.annotations.push(t))),n}function ht(t){return ct.isAnnotated(t)?t.annotations:[]}function dt(e){return Array.isArray(e)||Q.isSet(e)||t.Dictionary.isDictionary(e)}const lt=Symbol.for("FloatType");class ft{constructor(t){this.value="number"==typeof t?t:t.value}__preserve_text_on__(t){t.state.pieces.push(this.toString())}equals(t){return!!Object.is(t.constructor,this.constructor)&&(Number.isNaN(this.value)&&Number.isNaN(t.value)?t.toBytes().equals(this.toBytes()):Object.is(t.value,this.value))}hashCode(){return 0|this.value}}function pt(t){if(Object.is(t,-0))return"-0.0";const e=""+t;return e.includes(".")||e.includes("e")||e.includes("E")?e:e+".0"}ft.isFloat=t=>void 0!==(null==t?void 0:t[lt]),ft.isDouble=t=>"Double"===(null==t?void 0:t[lt]);class yt extends ft{__as_preserve__(){return this}static fromBytes(t){return new yt(p(t).getFloat64(0,!1))}static __from_preserve__(t){return ft.isDouble(t)?t:void 0}__preserve_on__(t){t.state.emitbyte(e.Ieee754),t.state.emitbyte(8),t.state.makeroom(8),t.state.view.setFloat64(t.state.index,this.value,!1),t.state.index+=8}toBytes(){const t=new h(8);return t.dataview().setFloat64(0,this.value,!1),t}toString(){return Number.isFinite(this.value)?pt(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[lt](){return"Double"}}function mt(t){return new yt(t)}const bt=BigInt(Number.MAX_SAFE_INTEGER),gt=BigInt(Number.MIN_SAFE_INTEGER),wt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class vt{constructor(t,e){switch(this.discarded=0,this.buffer=t,typeof e.name){case"undefined":this.pos=it();break;case"string":this.pos=it(e.name);break;case"object":this.pos=Object.assign({},e.name)}this.index=0,this.options=e}error(t,e){throw new b(t,Object.assign({},e))}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}copyPos(){return Object.assign({},this.pos)}write(t){this.atEnd()?this.buffer=t:this.buffer=this.buffer.substring(this.index)+t,this.discarded+=this.index,this.index=0}atEnd(){return this.index>=this.buffer.length}peek(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.index]}advance(){const t=this.index++;return ot(this.pos,this.buffer[t]),t}nextchar(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.advance()]}nextcharcode(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer.charCodeAt(this.advance())}skipws(t=!1){for(;!this.atEnd();){const e=this.peek();if(!(Et(e)||t&&","===e))break;this.advance()}}readHex2(){return l(this.nextcharcode(),b)<<4|l(this.nextcharcode(),b)}readHex4(){return l(this.nextcharcode(),b)<<12|l(this.nextcharcode(),b)<<8|l(this.nextcharcode(),b)<<4|l(this.nextcharcode(),b)}readHexBinary(){const t=[];for(;;){if(this.skipws(),'"'===this.peek())return this.advance(),h.from(t);t.push(this.readHex2())}}readHexFloat(){const t=this.copyPos();'"'!==this.nextchar()&&this.error("Missing open-double-quote in hex-encoded floating-point number",t);const e=this.readHexBinary();return 8!==e.length&&this.error("Incorrect number of bytes in hex-encoded Double",t),yt.fromBytes(e)}readBase64Binary(){let t="";for(;;){this.skipws();const e=this.nextchar();if("]"===e)break;t+=e}return h.fromBase64(t)}requireDelimiter(t){this.delimiterFollows()||this.error(`Delimiter must follow ${t}`,this.pos)}delimiterFollows(){if(this.atEnd())return!0;const t=this.peek();return-1!=='(){}[]<>";,@#:|'.indexOf(t)||Et(t)}readRawSymbolOrNumber(t){for(;!this.delimiterFollows();)t+=this.nextchar();const e=wt.exec(t);if(e){if(void 0===e[2]){let t=BigInt(e[1]);return t<=gt||t>=bt?t:Number(t)}return mt(parseFloat(t))}return Symbol.for(t)}readStringlike(t,e,n,r,s){let i=[];for(;;){const o=this.nextchar();switch(o){case n:return e(i);case"\\":{const e=this.nextchar();switch(e){case r:i.push(s());break;case n:case"\\":case"/":i.push(t(e));break;case"b":i.push(t("\b"));break;case"f":i.push(t("\f"));break;case"n":i.push(t("\n"));break;case"r":i.push(t("\r"));break;case"t":i.push(t("\t"));break;default:this.error(`Invalid escape code \\${e}`,this.pos)}break}default:i.push(t(o))}}}readString(t){return this.readStringlike((t=>t),(t=>t.join("")),t,"u",(()=>{const t=this.readHex4();if(t>=55296&&t<=57343){if("\\"===this.nextchar()&&"u"===this.nextchar()){const e=this.readHex4();if(e>=56320&&e<=57343&&t<=56319)return String.fromCharCode(t,e)}this.error("Invalid surrogate pair",this.pos)}return String.fromCharCode(t)}))}readLiteralBinary(){return this.readStringlike((t=>{const e=t.charCodeAt(0);return e>=256&&this.error(`Invalid code point ${e} in literal binary`,this.pos),e}),h.from,'"',"x",(()=>this.readHex2()))}readCommentLine(){let t="";for(;;){const e=this.nextchar();if("\n"===e||"\r"===e)return t;t+=e}}}const xt={decode(t){return new S(new qt(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:H(t))};class _t{constructor(t="",e){var n,r;if(t instanceof vt)this.state=t,this.embeddedType=e;else{const s=null!==(n=e)&&void 0!==n?n:{};this.state=new vt(t,s),this.embeddedType=null!==(r=s.embeddedDecode)&&void 0!==r?r:Tt}}write(t){this.state.write(t)}}let St=class t extends _t{readCommentLine(){const t=this.state.copyPos();return this.wrap(this.state.readCommentLine(),t)}wrap(t,e){return this.state.includeAnnotations&&!ct.isAnnotated(t)&&(t=new ct(t,e)),t}annotateNextWith(t){if(this.state.skipws(),this.state.atEnd())throw new b("Trailing annotations and comments are not permitted",this.state.pos);const e=this.next();return this.state.includeAnnotations&&e.annotations.unshift(t),e}readToEnd(){const t=[];for(;;){if(this.state.skipws(),this.state.atEnd())return t;t.push(this.next())}}next(){this.state.skipws();const e=this.state.copyPos(),n=(()=>{const n=this.state.nextchar();switch(n){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",e);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",e);case"#":{const n=this.state.nextchar();switch(n){case" ":case"\t":return this.annotateNextWith(this.readCommentLine());case"\n":case"\r":return this.annotateNextWith("");case"!":return this.annotateNextWith(v(Symbol.for("interpreter"),[this.readCommentLine()]));case"f":return this.state.requireDelimiter("#f"),!1;case"t":return this.state.requireDelimiter("#t"),!0;case"{":return this.readSet();case'"':return this.state.readLiteralBinary();case"x":switch(this.state.nextchar()){case'"':return this.state.readHexBinary();case"d":return this.state.readHexFloat();default:this.state.error("Invalid #x syntax",e)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new t(this.state,xt).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${n}`,e)}}case"<":return v(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",e);case"]":this.state.error("Unexpected ]",e);case"}":this.state.error("Unexpected }",e);case",":this.state.error("Unexpected ,",e);default:return this.state.readRawSymbolOrNumber(n)}})();return this.wrap(n,e)}seq(t,e,n,r){for(;;){if(this.state.skipws(t),this.state.peek()===r)return this.state.advance(),e;n(this.next(),e)}}readSequence(t,e){return this.seq(e,[],((t,e)=>e.push(t)),t)}readDictionary(){return this.seq(!0,new K,((t,e)=>{if(this.state.skipws(),":"===this.state.peek())this.state.advance(),e.has(t)&&this.state.error(`Duplicate key: ${Vt(t)}`,this.state.pos),e.set(t,this.next());else this.state.error("Missing key/value separator",this.state.pos)}),"}").simplifiedValue()}readSet(){return this.seq(!0,new Q,((t,e)=>{e.has(t)&&this.state.error(`Duplicate value in set: ${Vt(t)}`,this.state.pos),e.add(t)}),"}")}};function Et(t){return-1!==" \t\n\r".indexOf(t)}function kt(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const At={encode(t,e){new B(t,this).push(e.generic)},toValue:t=>t.generic},Dt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class Ct{constructor(t){var e;this.pieces=[],this.indentCount=0,this.options=t,this.indentDelta=" ".repeat(null!==(e=t.indent)&&void 0!==e?e:0)}get isIndenting(){return this.indentDelta.length>0}get includeAnnotations(){var t;return null===(t=this.options.includeAnnotations)||void 0===t||t}writeIndent(){if(this.isIndenting){this.pieces.push("\n");for(let t=0;t<this.indentCount;t++)this.pieces.push(this.indentDelta)}}writeIndentSpace(){this.isIndenting?this.writeIndent():this.pieces.push(" ")}escapeStringlikeChar(t,e=(t=>t)){switch(t){case"\\":return"\\\\";case"\b":return"\\b";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";default:return e(t)}}escapeStringlike(t,e){let n=e;for(let r of t)n+=r===e?"\\"+e:this.escapeStringlikeChar(r);return n+e}writeSeq(t,e,n,r){let s=n[Symbol.iterator]();this.pieces.push(t);const i=s.next();if(!0!==i.done){const t=i.value,e=s.next();if(!0===e.done)r(t);else{let n;for(this.indentCount++,this.writeIndent(),r(t),this.writeIndentSpace(),r(e.value);!0!==(n=s.next()).done;)this.writeIndentSpace(),r(n.value);this.indentCount--,this.writeIndent()}}this.pieces.push(e)}writeBytes(t){var e,n;const r=null!==(e=this.options.maxBinaryAsciiLength)&&void 0!==e?e:1024,s=null!==(n=this.options.maxBinaryAsciiProportion)&&void 0!==n?n:.75;if(t.length>=r)this.writeBase64(t);else{let e=0,n=Math.min(t.length,r);for(let r=0;r<n;r++){const n=t[r];switch(n){case 9:case 10:case 13:e++;break;default:n>=32&&n<=126&&e++}}0===n||e/n>=s?this.writeBinaryStringlike(t):this.writeBase64(t)}}writeBase64(t){this.pieces.push("#[",o(t),"]")}writeBinaryStringlike(t){let e='#"';for(let n of t)e+=34===n?'\\"':this.escapeStringlikeChar(String.fromCharCode(n),(t=>n>=32&&n<=126&&92!==n?t:"\\x"+("0"+n.toString(16)).slice(-2)));this.pieces.push(e+'"')}couldBeFlat(t){let e=!1;for(let n of t){if(Array.isArray(n)||Set.isSet(n)||Map.isMap(n)){if(e)return!1;e=!0}if(this.includeAnnotations&&rt(n)&&n.annotations.length>1)return!1}return!0}}class It{constructor(t={},e){var n;t instanceof Ct?(this.state=t,this.embeddedWrite=e):(this.state=new Ct(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:Dt)}static stringify(t,e){const n=new It(e);return n.push(t),n.contents()}contents(){return this.state.pieces.join("")}get includeAnnotations(){return this.state.includeAnnotations}push(t){switch(typeof t){case"boolean":this.state.pieces.push(t?"#t":"#f");break;case"string":this.state.pieces.push(this.state.escapeStringlike(t,'"'));break;case"symbol":{const e=t.description;/^[-a-zA-Z0-9~!$%^&*?_=+/.]+$/.exec(e)&&!wt.exec(e)?this.state.pieces.push(e):this.state.pieces.push(this.state.escapeStringlike(e,"|"));break}case"bigint":case"number":this.state.pieces.push(""+t);break;case"object":if(null===t)throw new Error("Cannot encode null in Preserves Writer.push");if(kt(t))t.__preserve_text_on__(this);else if(kt(t))t.__preserve_text_on__(this);else if(ArrayBuffer.isView(t))if(t instanceof Uint8Array)this.state.writeBytes(t);else{const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.state.writeBytes(e)}else if(v.isRecord(t)){const e=this.state.couldBeFlat(t);this.state.pieces.push("<"),this.push(t.label),e||this.state.indentCount++;for(let n of t)e?this.state.pieces.push(" "):this.state.writeIndentSpace(),this.push(n);e||this.state.indentCount--,this.state.pieces.push(">")}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(t)?_(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new It(this.state,At).push(this.embeddedWrite.toValue(t))):X(new K(t),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.state.writeSeq("[","]",t,(t=>this.push(t)));break;default:(e=>{throw new Error(`Internal error: unhandled in Preserves Writer.push for ${t}`)})()}return this}}function jt(t){return Bt(t)}function Bt(t,e){return function t(n){var r,s;switch(typeof n){case"number":if(!Number.isInteger(n)){const t=null!==(s=null===(r=null==e?void 0:e.onNonInteger)||void 0===r?void 0:r.call(e,n))&&void 0!==s?s:void 0;if(void 0!==t)return t;throw new TypeError("Refusing to autoconvert non-integer number to Double")}case"bigint":case"string":case"symbol":case"boolean":return n;case"undefined":case"function":break;case"object":if(null===n)break;if("function"==typeof n.__as_preserve__)return n.__as_preserve__();if(v.isRecord(n))return n;if(Array.isArray(n))return n.map(t);if(ArrayBuffer.isView(n)||n instanceof ArrayBuffer)return h.from(n);if(Map.isMap(n)){const e=new $;return n.forEach(((n,r)=>e.set(t(r),t(n)))),e}if(Q.isSet(n)){const e=new Q;return n.forEach((n=>e.add(t(n)))),e}if(_(n))return n;{const e={};return Object.entries(n).forEach((([n,r])=>e[n]=t(r))),e}}throw new TypeError("Cannot represent JavaScript value as Preserves: "+n)}(t)}t.Dictionary.stringMap=function(t){const e=new $;return Object.entries(t).forEach((([t,n])=>e.set(t,jt(n)))),e};const Ot={write(t,e){if(e instanceof S)new It(t,this).push(e.generic);else{try{const n=jt(e);if(!_(n))return void new It(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Vt(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:Ot,It.stringify(jt(t),e)}[ct,h,$,Z].forEach((t=>{t.prototype.toString=function(){return Vt(this)}}));class Mt{constructor(t,e){this.index=0,this.packet=f(t),this.options=e}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}write(t){this.index===this.packet.length?this.packet=f(t):this.packet=h.concat([this.packet.slice(this.index),t])._view,this.index=0}atEnd(){return this.index>=this.packet.length}mark(){return this.index}restoreMark(t){this.index=t}shortGuard(t,e){if(this.atEnd())return e();const n=this.mark();try{return t()}catch(t){if(w.isShortPacket(t))return this.restoreMark(n),e();throw t}}nextbyte(){if(this.atEnd())throw new w("Short packet");return this.packet[this.index++]}nextbytes(t){const e=this.index;if(this.index+=t,this.index>this.packet.length)throw new w("Short packet");return new DataView(this.packet.buffer,this.packet.byteOffset+e,t)}varint(){const t=this.nextbyte();return t<128?t:(this.varint()<<7)+(t-128)}peekend(){return this.nextbyte()===e.End||(this.index--,!1)}nextint(t){const e=this.index;if(0===t)return 0;if(t>7)return this.nextbigint(t);if(7===t){const e=this.packet[this.index];if(e>=32&&e<224)return this.nextbigint(t)}let n=this.nextbyte();128&n&&(n-=256);for(let e=1;e<t;e++)n=256*n+this.nextbyte();return Number.isSafeInteger(n)?n:(this.index=e,this.nextbigint(t))}nextbigint(t){if(0===t)return BigInt(0);const e=h.from(this.nextbytes(t));if(e.get(0)>=128){const t=e.toHex((t=>d(15-t)));return~BigInt("0x"+t)}{const t=e.toHex();return BigInt("0x"+t)}}wrap(t){return this.includeAnnotations?new ct(t):t}unshiftAnnotation(t,e){return this.includeAnnotations&&e.annotations.unshift(t),e}}const Tt={decode(t){throw new Error("Embeddeds not permitted at this point in Preserves document")},fromValue(t,e){throw new Error("Embeddeds not permitted at this point in Preserves document")}};class qt{constructor(t=new Uint8Array(0),e){var n,r,s;if(t instanceof Mt)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:Tt;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new Mt(t,n),this.embeddedDecode=null!==(s=n.embeddedDecode)&&void 0!==s?s:Tt}}write(t){this.state.write(t)}nextvalues(){const t=[];for(;!this.state.peekend();)t.push(this.next());return t}static dictionaryFromArray(t){const e=new K;if(t.length%2)throw new b("Missing dictionary value");for(let n=0;n<t.length;n+=2){if(e.has(t[n]))throw new b(`Duplicate key: ${Vt(t[n])}`);e.set(t[n],t[n+1])}return e.simplifiedValue()}next(){const t=this.state.nextbyte();switch(t){case e.False:return this.state.wrap(!1);case e.True:return this.state.wrap(!0);case e.End:throw new b("Unexpected Compound end marker");case e.Annotation:{const t=this.next(),e=this.next();return this.state.unshiftAnnotation(t,e)}case e.Embedded:return this.state.wrap(this.embeddedDecode.decode(this.state));case e.Ieee754:if(8===this.state.varint())return this.state.wrap(yt.fromBytes(this.state.nextbytes(8)));throw new b("Invalid IEEE754 size");case e.SignedInteger:return this.state.wrap(this.state.nextint(this.state.varint()));case e.String:return this.state.wrap(h.from(this.state.nextbytes(this.state.varint())).fromUtf8());case e.ByteString:return this.state.wrap(h.from(this.state.nextbytes(this.state.varint())));case e.Symbol:return this.state.wrap(Symbol.for(h.from(this.state.nextbytes(this.state.varint())).fromUtf8()));case e.Record:{const t=this.nextvalues();if(0===t.length)throw new b("Too few elements in encoded record");return this.state.wrap(v(t[0],t.slice(1)))}case e.Sequence:return this.state.wrap(this.nextvalues());case e.Set:{const t=new Q;for(const e of this.nextvalues()){if(t.has(e))throw new b(`Duplicate value: ${Vt(e)}`);t.add(e)}return this.state.wrap(t)}case e.Dictionary:return this.state.wrap(qt.dictionaryFromArray(this.nextvalues()));default:throw new b("Unsupported Preserves tag: "+t)}}try_next(){return this.state.shortGuard((()=>this.next()),(()=>{}))}atEnd(){return this.state.atEnd()}mark(){return this.state.mark()}restoreMark(t){return this.state.restoreMark(t)}skip(){this.next()}withEmbeddedDecode(t,e){return e(new qt(this.state,t))}skipAnnotations(t){const n=this.mark();for(;!this.state.atEnd()&&this.state.packet[this.state.index]===e.Annotation;)this.state.index++,this.skip();return t((()=>this.restoreMark(n)))}nextBoolean(){return this.skipAnnotations((t=>{switch(this.state.nextbyte()){case e.False:return!1;case e.True:return!0;default:return t()}}))}nextDouble(){return this.skipAnnotations((t=>this.state.nextbyte()!==e.Ieee754||8!==this.state.nextbyte()?t():yt.fromBytes(this.state.nextbytes(8))))}nextEmbedded(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Embedded?this.embeddedDecode.decode(this.state):t()))}nextSignedInteger(){return this.skipAnnotations((t=>this.state.nextbyte()===e.SignedInteger?this.state.nextint(this.state.varint()):t()))}nextString(){return this.skipAnnotations((t=>this.state.nextbyte()===e.String?h.from(this.state.nextbytes(this.state.varint())).fromUtf8():t()))}nextByteString(){return this.skipAnnotations((t=>this.state.nextbyte()===e.ByteString?h.from(this.state.nextbytes(this.state.varint())):t()))}nextSymbol(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Symbol?Symbol.for(h.from(this.state.nextbytes(this.state.varint())).fromUtf8()):t()))}openRecord(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Record||(t(),!1)))}openSequence(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Sequence||(t(),!1)))}openSet(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Set||(t(),!1)))}openDictionary(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Dictionary||(t(),!1)))}closeCompound(){return this.state.peekend()}}function Pt(t,e={}){return new qt(t,e).next()}const Ft=Object.assign({},xt,At),Ut=Object.assign({},Tt,Dt),Nt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},Rt=Object.assign({},Nt,I);var zt;t.ValueClass=void 0,(zt=t.ValueClass||(t.ValueClass={}))[zt.Boolean=0]="Boolean",zt[zt.Double=1]="Double",zt[zt.SignedInteger=2]="SignedInteger",zt[zt.String=3]="String",zt[zt.ByteString=4]="ByteString",zt[zt.Symbol=5]="Symbol",zt[zt.Record=6]="Record",zt[zt.Sequence=7]="Sequence",zt[zt.Set=8]="Set",zt[zt.Dictionary=9]="Dictionary",zt[zt.Embedded=10]="Embedded",zt[zt.Annotated=11]="Annotated";class Jt{boolean(t){}double(t){}integer(t){}string(t){}bytes(t){}symbol(t){}record(t,e){e(t.label),t.forEach(e)}array(t,e){t.forEach(e)}set(t,e){t.forEach(e)}dictionary(t,e){t.forEach(((t,n)=>{e(n),e(t)}))}annotated(t,e){e(t.item),t.annotations.forEach(e)}embedded(t,e){}}class Ht extends Jt{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class Wt{boolean(t){return t}double(t){return mt(t)}integer(t){return t}string(t){return t}bytes(t){return t}symbol(t){return t}record(t,e){return v(e(t.label),t.map(e))}array(t,e){return t.map(e)}set(t,e){return t.map(e)}dictionary(t,e){const n=new K;return t.forEach(((t,r)=>n.set(e(r),e(t)))),n.simplifiedValue()}annotated(t,e){return ut(e(t.item),...t.annotations.map(e))}}class Lt extends Wt{embedded(t,e){return t}}class $t extends Wt{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}const Kt=new Lt;function Gt(e,n){const r=e=>{switch(typeof e){case"boolean":return n.boolean(e);case"number":return Number.isInteger(e)?n.integer(e):n.double(e);case"bigint":return n.integer(e);case"string":return n.string(e);case"symbol":return n.symbol(e);case"object":if(v.isRecord(e))return n.record(e,r);if(Array.isArray(e))return n.array(e,r);if(Q.isSet(e))return n.set(e,r);if(_(e))return n.embedded(e,r);if(ct.isAnnotated(e))return n.annotated(e,r);if(h.isBytes(e))return n.bytes(e);if(ft.isDouble(e))return n.double(e.value);if(t.Dictionary.isDictionary(e))return n.dictionary(new K(e),r);default:(t=>{throw new Error("Internal error")})()}};return r(e)}function Xt(e){switch(rt(e)&&(e=e.item),typeof e){case"boolean":return 0;case"number":case"bigint":return 3;case"string":return 4;case"symbol":return 6;case"object":if(ft.isFloat(e))return 2;if(h.isBytes(e))return 5;if(Array.isArray(e))return"label"in e?7:8;if(Q.isSet(e))return 9;if(t.Dictionary.isDictionary(e))return 10;if(_(e))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}class Yt{constructor(t){this.text=t}__as_preserve__(){return v(Symbol.for("p"),[Symbol.for(this.text)])}isComma(){return","===this.text}static isComma(t){return t instanceof Yt&&t.isComma()}isColon(t=1){return this.text===":".repeat(t)}static isColon(t,e=1){return t instanceof Yt&&t.isColon(e)}}class Zt{constructor(t,e){this.expr=t,this.annotations=e}__as_preserve__(){var t,e;const n=jt(this.expr);return new S(null!==(e=null===(t=this.annotations)||void 0===t?void 0:t.wrap(n))&&void 0!==e?e:n)}}class Qt{constructor(){this.positions=[],this.exprs=[],this.annotations=void 0}get(t){if(!(t>=this.exprs.length))return{position:this.positions[t],item:this.exprs[t],annotations:this.annotations&&this.annotations[t]}}push(t,e,n){if(void 0===e){const e=t;e.annotations&&(this._ensureAnnotations()[this.exprs.length]=e.annotations),this.positions.push(e.position),this.exprs.push(e.item)}else n&&(this._ensureAnnotations()[this.exprs.length]=n),this.positions.push(e),this.exprs.push(t);return!0}_ensureAnnotations(){return void 0===this.annotations&&(this.annotations=[]),this.annotations}_annotationsAt(t){var e,n;return null!==(e=(n=this._ensureAnnotations())[t])&&void 0!==e?e:n[t]=new ee}preservesValues(){return this.exprs.map(((t,e)=>{var n;const r=jt(t);return void 0!==(null===(n=this.annotations)||void 0===n?void 0:n[e])?this.annotations[e].wrap(r):r}))}map(t,e=0){const n=[];for(let r=e;r<this.exprs.length;r++)n.push(t(this.get(r),r));return n}[Symbol.iterator](){let t=this,e=0;return{next:()=>e<t.exprs.length?{done:!1,value:t.get(e++)}:{done:!0,value:void 0},[Symbol.iterator]:()=>t[Symbol.iterator]()}}}class te extends Qt{__as_preserve__(){return this.preservesValues()}}class ee extends Qt{wrap(t){return ut(t,...this.preservesValues())}}class ne extends Qt{__as_preserve__(){const t=this.preservesValues();switch(this.variant){case"sequence":return t;case"record":return v(Symbol.for("r"),t);case"block":return v(Symbol.for("b"),t);case"group":return v(Symbol.for("g"),t);case"set":return v(Symbol.for("s"),t)}}}class re extends ne{get variant(){return"sequence"}}class se extends ne{get variant(){return"record"}}class ie extends ne{get variant(){return"block"}}class oe extends ne{get variant(){return"group"}}let ae=class extends ne{get variant(){return"set"}};var ce=Object.freeze({__proto__:null,Annotations:ee,BaseCompound:Qt,Block:ie,Compound:ne,Document:te,Embedded:Zt,Group:oe,Punct:Yt,Reader:class extends _t{nextDocument(t="all"){const e=new te;if(this.readExpr(e),"all"===t)for(;this.readExpr(e););return e}readCompound(t,e){for(;;){if(this.state.skipws(),this.state.peek()===e)return this.state.advance(),t;this.readExpr(t)||this.state.error(`Missing "${e}"`,this.state.copyPos())}}readSimpleExpr(t){return this._readInto(t,!1)}readExpr(t){return this._readInto(t,!0)}_readInto(t,e){for(;;){if(this.state.skipws(),this.state.atEnd())return!1;const n=this.state.copyPos(),r=this.state.nextchar();switch(r){case'"':return t.push(this.state.readString('"'),n);case"|":return t.push(Symbol.for(this.state.readString("|")),n);case";":if(e)return t.push(new Yt(";"),n);this.state.error("Semicolon is not permitted at this location",n);case"@":this.readSimpleExpr(t._annotationsAt(t.exprs.length))||this.state.error("Missing annotation",n);continue;case":":{let s=r;for(;!this.state.atEnd()&&":"===this.state.peek();)s+=":",this.state.advance();if(e)return t.push(new Yt(s),n);this.state.error("Colons are not permitted at this location",n)}case"#":{const e=this.state.nextchar();switch(e){case" ":case"\t":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push(this.state.readCommentLine(),e);continue}case"\n":case"\r":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push("",e);continue}case"!":{const e=this.state.copyPos(),n=new se;n.push(Symbol.for("interpreter"),e),n.push(this.state.readCommentLine(),e),t._annotationsAt(t.exprs.length).push(n,e);continue}case"f":return this.state.requireDelimiter("#f"),t.push(!1,n);case"t":return this.state.requireDelimiter("#t"),t.push(!0,n);case"{":return t.push(this.readCompound(new ae,"}"),n);case'"':return t.push(this.state.readLiteralBinary(),n);case"x":switch(this.state.nextchar()){case'"':return t.push(this.state.readHexBinary(),n);case"d":return t.push(this.state.readHexFloat(),n);default:this.state.error("Invalid #x syntax",n)}case"[":return t.push(this.state.readBase64Binary(),n);case":":{const e=new Qt;if(!this.readSimpleExpr(e))return!1;const r=new Zt(e.exprs[0],e.annotations&&e.annotations[0]);return t.push(r,n)}default:this.state.error(`Invalid # syntax: ${e}`,n)}}case"(":return t.push(this.readCompound(new oe,")"),n);case"<":return t.push(this.readCompound(new se,">"),n);case"[":return t.push(this.readCompound(new re,"]"),n);case"{":return t.push(this.readCompound(new ie,"}"),n);case">":this.state.error("Unexpected >",n);case"]":this.state.error("Unexpected ]",n);case"}":this.state.error("Unexpected }",n);case",":if(e)return t.push(new Yt(","),n);this.state.error("Comma is not permitted at this location",n);default:return t.push(this.state.readRawSymbolOrNumber(r),n)}}}},Record:se,Sequence:re,Set:ae,asPreserves:function(t,e={}){var n;const r=null!==(n=e.error)&&void 0!==n?n:(t,e)=>{throw new Error(at(e)+": "+t)};function s(t){return Array.from(t).filter((t=>!Yt.isComma(t.item)))}return function t(n){if(n.item instanceof Yt)return r("invalid-punctuation",n.position);if(n.item instanceof Zt)return e.onEmbedded?e.onEmbedded({position:n.position,item:n.item.expr},t):r("unexpected-embedded",n.position);if(!(n.item instanceof ne))return n.item;switch(n.item.variant){case"sequence":return s(n.item).map(t);case"record":{const e=s(n.item).map(t);if(e.length<1)return r("invalid-record",n.position);const i=e.slice(1);return i.label=e[0],i}case"block":{const e=new K,i=s(n.item);if(i.length%3!=0)return r("invalid-dictionary",n.position);for(let n=0;n<i.length;n+=3){if(!Yt.isColon(i[n+1].item))return r("missing-colon",i[n+1].position);const s=t(i[n]),o=t(i[n+2]);e.set(s,o)}return e.simplifiedValue()}case"group":return e.onGroup?e.onGroup(n):r("unexpected-group",n.position);case"set":return new Q(s(n.item).map(t))}}(t)}});Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const ue=Array,he=Symbol;t.Annotated=ct,t.Array=ue,t.Bytes=h,t.Constants=n,t.DecodeError=b,t.Decoder=qt,t.DecoderState=Mt,t.DictionaryMap=K,t.DictionaryType=W,t.Double=mt,t.DoubleFloat=yt,t.Embedded=class{get[x](){return!0}constructor(t){this.value=t}equals(t){return"object"==typeof t&&"value"in t&&Object.is(this.value,t.value)}},t.EncodableDictionary=L,t.EncodableSet=Y,t.EncodeError=g,t.Encoder=B,t.EncoderState=j,t.ErrorType=y,t.FlexMap=R,t.FlexSet=z,t.Float=ft,t.FloatType=lt,t.ForEachEmbedded=Ht,t.GenericEmbedded=S,t.IDENTITY_FOLD=Kt,t.IdentityFold=Lt,t.IdentityMap=q,t.IdentitySet=P,t.IsEmbedded=x,t.IsMap=F,t.IsPreservesAnnotated=nt,t.IsPreservesBytes=u,t.IsSet=U,t.KeyedDictionary=$,t.KeyedSet=Z,t.MapFold=$t,t.NUMBER_RE=wt,t.Pexpr=ce,t.PreservesCodecError=m,t.Reader=St,t.ReaderBase=_t,t.ReaderState=vt,t.Record=v,t.Set=Q,t.ShortPacket=w,t.Symbol=he,t.ValueFold=Wt,t.VoidFold=Jt,t.Writer=It,t.WriterState=Ct,t._iterMap=N,t.annotate=ut,t.annotations=ht,t.asLiteral=function(t,e){return st(t,e)?e:void 0},t.canonicalEncode=function(t,e){if(void 0!==e||M)return O(t,Object.assign(Object.assign({},e),{canonical:!0}));{M=!0;const e=V.push(t).contents();return M=!1,e}},t.canonicalString=T,t.compare=function(e,n,r=((t,e)=>st(t,e)?0:t<e?-1:1)){return function e(n,s){rt(n)&&(n=n.item),rt(s)&&(s=s.item);const i=Xt(n),o=Xt(s);if(i<o)return-1;if(i>o)return 1;switch(i){case 0:case 3:case 4:return n<s?-1:n>s?1:0;case 2:{const t=n.value,e=s.value;return t<e?-1:t>e?1:0}case 5:return h.compare(n,s);case 6:{const t=n.description,e=s.description;return t<e?-1:t>e?1:0}case 7:{const t=e(n.label,s.label);if(0!==t)return t}case 8:{const t=n,r=s,i=Math.min(t.length,r.length);for(let n=0;n<i;n++){const s=e(t[n],r[n]);if(0!==s)return s}return t.length<r.length?-1:t.length>r.length?1:0}case 9:return e(Array.from(n).sort(e),Array.from(s).sort(e));case 10:return e(Array.from(t.Dictionary.asMap(n).entries()).sort(e),Array.from(t.Dictionary.asMap(s).entries()).sort(e));case 11:return r(n,s);default:throw new Error("Invalid typeCode: "+i)}}(e,n)},t.dataview=p,t.decode=Pt,t.decodeBase64=s,t.decodeWithAnnotations=function(t,e={}){return Pt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))},t.embeddedId=C,t.encode=O,t.encodeBase64=o,t.encodeDictionaryOn=G,t.encodeSetOn=tt,t.encodeWithAnnotations=function(t,e={}){return O(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))},t.floatValue=function(t){return"number"==typeof t?t:ft.isFloat(t)?t.value:NaN},t.floatlikeString=pt,t.fold=Gt,t.forEachEmbedded=function(t,e){return Gt(t,new Ht(e))},t.formatPosition=at,t.fromJS=jt,t.fromJS_options=Bt,t.genericEmbeddedType=Ft,t.genericEmbeddedTypeDecode=xt,t.genericEmbeddedTypeEncode=At,t.hexDigit=d,t.identityEmbeddedType=Rt,t.identityEmbeddedTypeDecode=Nt,t.identityEmbeddedTypeEncode=I,t.is=st,t.isAnnotated=rt,t.isCompound=dt,t.isEmbedded=_,t.isPreservable=E,t.isPreserveWritable=kt,t.isSequence=function(t){return Array.isArray(t)&&!("label"in t)},t.mapEmbeddeds=function(t,e){return Gt(t,new $t(e))},t.merge=function(e,n,...r){function s(){throw new Error("Cannot merge items")}function i(n,r){return n===r?n:dt(n)||dt(r)||!st(n,r)?Gt(n,{boolean:s,double:t=>st(n,r)?n:s(),integer:s,string:s,bytes:t=>st(n,r)?n:s(),symbol:s,record:t=>(v.isRecord(r)||s(),v(i(t.label,r.label),o(t,r))),array:t=>(Array.isArray(r)&&!v.isRecord(r)||s(),o(t,r)),set(t){s()},dictionary(e){const n=t.Dictionary.asMap(r);void 0===n&&s();const o=new K;return e.forEach(((t,e)=>{const r=n.get(e);o.set(e,void 0===r?t:i(t,r))})),n.forEach(((t,n)=>{e.has(n)||o.set(n,t)})),o.simplifiedValue()},annotated:t=>i(t,J(r)),embedded(t){_(r)||s();const n=e(t,r);return void 0===n&&s(),n}}):n}function o(t,e){return t.length<=e.length?e.map(((e,n)=>n<t.length?i(t[n],e):e)):t.map(((t,n)=>n<e.length?i(t,e[n]):t))}return r.reduce(i,n)},t.neverEmbeddedType=Ut,t.neverEmbeddedTypeDecode=Tt,t.neverEmbeddedTypeEncode=Dt,t.newPosition=it,t.parse=function(t,e){return new St(t,e).next()},t.parseAll=function(t,e){return new St(t,e).readToEnd()},t.peel=function(t){return H(t,1)},t.position=function(t){return ct.isAnnotated(t)?t.pos:null},t.preserves=function(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Vt(e)),n.push(t[r+1])})),n.join("")},t.stringify=Vt,t.stringifyEmbeddedWrite=Ot,t.strip=H,t.typeCode=Xt,t.unannotate=J,t.underlying=f,t.unhexDigit=l,t.updatePosition=ot,t.valueClass=function(e){switch(typeof e){case"boolean":return t.ValueClass.Boolean;case"number":if(Number.isInteger(e))return t.ValueClass.SignedInteger;throw new Error("Non-integer number in Preserves valueClass; missing Float wrapper?");case"bigint":return t.ValueClass.SignedInteger;case"string":return t.ValueClass.String;case"symbol":return t.ValueClass.Symbol;case"object":return v.isRecord(e)?t.ValueClass.Record:Array.isArray(e)?t.ValueClass.Sequence:Q.isSet(e)?t.ValueClass.Set:t.Dictionary.isDictionary(e)?t.ValueClass.Dictionary:ct.isAnnotated(e)?t.ValueClass.Annotated:h.isBytes(e)?t.ValueClass.ByteString:ft.isDouble(e)?t.ValueClass.Double:t.ValueClass.Embedded;default:(t=>{throw new Error("Internal error")})()}},t.writeDictionaryOn=X,t.writeSetOn=et}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Preserves={})}(this,(function(t){"use strict";var e;!function(t){t[t.False=128]="False",t[t.True=129]="True",t[t.End=132]="End",t[t.Annotation=133]="Annotation",t[t.Embedded=134]="Embedded",t[t.Ieee754=135]="Ieee754",t[t.SignedInteger=176]="SignedInteger",t[t.String=177]="String",t[t.ByteString=178]="ByteString",t[t.Symbol=179]="Symbol",t[t.Record=180]="Record",t[t.Sequence=181]="Sequence",t[t.Set=182]="Set",t[t.Dictionary=183]="Dictionary"}(e||(e={}));var n=Object.freeze({__proto__:null,get Tag(){return e}});const r={};function s(t){const e=new Uint8Array(Math.floor(3*t.length/4));let n=0,s=0;for(;n<t.length;){const i=r[t[n++]],o=r[t[n++]],a=r[t[n++]],c=r[t[n++]],u=i<<18|o<<12|a<<6|c;if(e[s++]=u>>16&255,void 0===a)break;if(e[s++]=u>>8&255,void 0===c)break;e[s++]=255&u}return e.subarray(0,s)}[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"].forEach(((t,e)=>r[t]=e)),r["+"]=r["-"]=62,r["/"]=r._=63;const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(t){let e="",n=0,r=0;for(let s of t)for(n=(63&n)<<8|s,r+=8;r>=6;){r-=6;e+=i[n>>r&63]}if(r>0){e+=i[n<<6-r&63]}return e}const a=new TextEncoder,c=new TextDecoder("utf-8",{fatal:!0}),u=Symbol.for("IsPreservesBytes");class h{constructor(t=new Uint8Array){if(h.isBytes(t))this._view=t._view;else if(ArrayBuffer.isView(t))this._view=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);else if(t instanceof ArrayBuffer)this._view=new Uint8Array(t);else if("string"==typeof t)this._view=a.encode(t);else if("number"==typeof t)this._view=new Uint8Array(t);else{if("number"!=typeof t.length)throw new TypeError("Attempt to initialize Bytes from unsupported value: "+t);this._view=Uint8Array.from(t)}}dataview(){return new DataView(this._view.buffer,this._view.byteOffset,this._view.byteLength)}get length(){return this._view.length}static from(t){return new h(t)}static of(...t){return new h(Uint8Array.of(...t))}static fromLatin1(t){const e=new h(t.length);for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);if(r>=256)throw new Error("Codepoint out of range for 'latin1' byte encoding");e._view[n]=r}return e}static fromBase64(t){return new h(s(t))}static fromHex(t){if(1&t.length)throw new Error("Cannot decode odd-length hexadecimal string");const e=new h(t.length>>1);return h._raw_fromHexInto(t,e._view),e}static _raw_fromHexInto(t,e){const n=t.length>>1;for(let r=0;r<n;r++)e[r]=l(t.charCodeAt(r<<1))<<4|l(t.charCodeAt(1+(r<<1)))}static fromIO(t){return"string"==typeof t||h.isBytes(t)?t:new h(t)}static toIO(t){return"string"==typeof t?t:h.isBytes(t)?t._view:t}get(t){return this._view[t]}equals(t){if(!h.isBytes(t))return!1;if(t.length!==this.length)return!1;const e=this._view,n=t._view;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0}hashCode(){const t=this._view;let e=0;for(let n=0;n<t.length;n++)e=31*e+t[n]|0;return e}static compare(t,e){return t<e?-1:e<t?1:0}static decodeUtf8(t){return c.decode(f(t))}fromUtf8(){return c.decode(this._view)}__as_preserve__(){return this}static __from_preserve__(t){return h.isBytes(t)?t:void 0}toLatin1(){return String.fromCharCode.apply(null,this._view)}toBase64(){return o(this._view)}toHex(t=d){var e=[];for(let n=0;n<this.length;n++)e.push(t(this._view[n]>>4)),e.push(t(15&this._view[n]));return e.join("")}valueOf(){return this.toHex()}__preserve_on__(t){t.state.emitbyte(e.ByteString),t.state.varint(this.length),t.state.emitbytes(this._view)}__preserve_text_on__(t){t.state.writeBytes(this._view)}get[u](){return!0}static isBytes(t){return!!(null==t?void 0:t[u])}}function d(t){return"0123456789abcdef"[t]}function l(t,e=Error){if(t>=48&&t<=57)return t-48;if(t>=97&&t<=102)return t-97+10;if(t>=65&&t<=70)return t-65+10;throw new e("Invalid hex digit: "+String.fromCharCode(t))}function f(t){return t instanceof Uint8Array?t:t._view}function p(t){return t instanceof DataView?t:t.dataview()}h.concat=function(t){let e=0;for(let n=0;n<t.length;n++)e+=f(t[n]).length;const n=new h(e);let r=0;for(let e=0;e<t.length;e++){const s=f(t[e]);n._view.set(s,r),r+=s.length}return n},function(){for(const t of"entries every find findIndex forEach includes indexOf join\nkeys lastIndexOf reduce reduceRight some toLocaleString values".split(/\s+/))h.prototype[t]=function(...e){return this._view[t](...e)};for(const t of"filter map slice subarray".split(/\s+/))h.prototype[t]=function(...e){return new h(this._view[t](...e))};for(const t of"reverse sort".split(/\s+/))h.prototype[t]=function(...e){return new h(this._view.slice()[t](...e))};h.prototype[Symbol.iterator]=function(){return this._view[Symbol.iterator]()}}();const y=Symbol.for("ErrorType");class m{static isCodecError(t,e){return(null==t?void 0:t[y])===e}}class b extends Error{get[y](){return"DecodeError"}constructor(t,e){super(t),this.pos=e}static isDecodeError(t){return m.isCodecError(t,"DecodeError")}}class g extends Error{get[y](){return"EncodeError"}static isEncodeError(t){return m.isCodecError(t,"EncodeError")}constructor(t,e){super(t),this.irritant=e}}class w extends b{get[y](){return"ShortPacket"}static isShortPacket(t){return m.isCodecError(t,"ShortPacket")}}function v(t,e){return e.label=t,e}!function(t){t.isRecord=function(t){return Array.isArray(t)&&"label"in t},t.constructorInfo=function(t){return{label:t.label,arity:t.length}},t.isClassOf=function(e,n){return t.isRecord(n)&&st(e.label,n.label)&&e.arity===n.length},t.makeConstructor=function(){return(e,n)=>{const r=(...n)=>t(e,n),s={label:e,arity:n.length};return r.constructorInfo=s,r.isClassOf=e=>t.isClassOf(s,e),r.fieldNumbers={},r._={},n.forEach(((t,e)=>{r._[t]=t=>t[e],r.fieldNumbers[t]=e})),r}}}(v||(v={}));const x=Symbol.for("IsEmbedded");function _(t){return!!(null==t?void 0:t[x])}class S{get[x](){return!0}constructor(t){this.generic=t}equals(t,e){return"object"==typeof t&&"generic"in t&&e(this.generic,t.generic)}toString(){return this.generic.toString()}}function E(t){return"object"==typeof t&&null!==t&&"__preserve_on__"in t&&"function"==typeof t.__preserve_on__}function k(t){return String.fromCharCode.apply(null,t)}let A=0;const D=new WeakMap;function C(t){let e=D.get(t);return void 0===e&&(e=A++,D.set(t,e)),e}const I={encode(t,e){new B(t,this).push(C(e))}};class j{constructor(t){this.chunks=[],this.view=new DataView(new ArrayBuffer(256)),this.index=0,this.options=t}get canonical(){var t;return null===(t=this.options.canonical)||void 0===t||t}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t?t:!this.canonical}contents(){if(0===this.chunks.length){const t=this.index;return this.index=0,new h(this.view.buffer.slice(0,t))}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],h.concat(t)}}contentsString(){if(0===this.chunks.length){const t=k(new Uint8Array(this.view.buffer,0,this.index));return this.index=0,t}{this.rotatebuffer(4096);const t=this.chunks;return this.chunks=[],t.map(k).join("")}}rotatebuffer(t){this.chunks.push(new Uint8Array(this.view.buffer,0,this.index)),this.view=new DataView(new ArrayBuffer(t)),this.index=0}makeroom(t){this.index+t>this.view.byteLength&&this.rotatebuffer(t+4096)}emitbyte(t){this.makeroom(1),this.view.setUint8(this.index++,t)}emitbytes(t){this.makeroom(t.length),new Uint8Array(this.view.buffer).set(t,this.index),this.index+=t.length}claimbytes(t){this.makeroom(t);const e=new Uint8Array(this.view.buffer,this.index,t);return this.index+=t,e}varint(t){for(;t>=128;)this.emitbyte(t%128+128),t=Math.floor(t/128);this.emitbyte(t)}encodeint(t){if("bigint"==typeof t)return this.encodebigint(t);if(this.emitbyte(e.SignedInteger),0===t)return void this.emitbyte(0);const n=(-1===t?0:Math.floor(Math.log2(t>0?t:-(1+t)))+1)+1+7>>3;this.varint(n);const r=(t,e)=>{t>0&&(r(t-1,Math.floor(e/256)),this.emitbyte(255&e))};r(n,t)}encodebigint(t){let n;if(this.emitbyte(e.SignedInteger),t>0)n=t.toString(16),1&n.length?n="0"+n:l(n.charCodeAt(0))>=8&&(n="00"+n);else{if(!(t<0))return void this.emitbyte(0);{const e=(~t).toString(16);n="";for(let t=0;t<e.length;t++)n+="fedcba9876543210"[l(e.charCodeAt(t))];1&n.length?n="f"+n:l(n.charCodeAt(0))<8&&(n="ff"+n)}}this.varint(n.length>>1),h._raw_fromHexInto(n,this.claimbytes(n.length>>1))}encodebytes(t,e){this.emitbyte(t),this.varint(e.length),this.emitbytes(e)}}class B{constructor(t={},e){var n;t instanceof j?(this.state=t,this.embeddedEncode=null!=e?e:I):(this.state=new j(t),this.embeddedEncode=null!==(n=t.embeddedEncode)&&void 0!==n?n:I)}withEmbeddedEncode(t,e){return e(new B(this.state,t)),this}get canonical(){return this.state.canonical}get includeAnnotations(){return this.state.includeAnnotations}contents(){return this.state.contents()}contentsString(){return this.state.contentsString()}grouped(t,n){this.state.emitbyte(t),n(),this.state.emitbyte(e.End)}push(t){if(E(t))t.__preserve_on__(this);else if(E(t))t.__preserve_on__(this);else if("boolean"==typeof t)this.state.emitbyte(t?e.True:e.False);else if("number"==typeof t||"bigint"==typeof t)this.state.encodeint(t);else if("string"==typeof t)this.state.encodebytes(e.String,new h(t)._view);else if("symbol"==typeof t){const n=Symbol.keyFor(t);if(void 0===n)throw new g("Cannot preserve non-global Symbol",t);this.state.encodebytes(e.Symbol,new h(n)._view)}else if(ArrayBuffer.isView(t))if(t instanceof Uint8Array)this.state.encodebytes(e.ByteString,t);else{const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.state.encodebytes(e.ByteString,n)}else if(v.isRecord(t)){this.state.emitbyte(e.Record),this.push(t.label);for(let e of t)this.push(e);this.state.emitbyte(e.End)}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(t)?_(t)?(this.state.emitbyte(e.Embedded),this.embeddedEncode.encode(this.state,t)):G(new K(t),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.grouped(e.Sequence,(()=>{for(let e of t)this.push(e)}));return this}}function O(t,e={}){return new B(e).push(t).contents()}const V=new B({canonical:!0});let M=!1;function T(t){if(M)return new B({canonical:!0}).push(t).contentsString();{M=!0;const e=V.push(t).contentsString();return M=!1,e}}const q=Map,P=Set,F=Symbol.for("IsMap"),U=Symbol.for("IsSet");function N(t,e){const n=t=>t.done?{done:!0,value:null}:{done:!1,value:e(t.value)};return{next:e=>n(t.next(e)),return:e=>{var r,s;return n(null!==(s=null===(r=t.return)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},throw:e=>{var r,s;return n(null!==(s=null===(r=t.throw)||void 0===r?void 0:r.call(t,e))&&void 0!==s?s:{done:!0,value:null})},[Symbol.iterator](){return this}}}F in Map.prototype||(Object.defineProperty(Map.prototype,F,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[F])),U in Set.prototype||(Object.defineProperty(Set.prototype,U,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[U]));class R{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(N(e[Symbol.iterator](),(([t,e])=>[this._key(t),[t,e]])))}_key(t){return this.canonicalizer(t)}get(t,e){const n=this.items.get(this._key(t));return void 0===n?e:n[1]}getOrSet(t,e){const n=this._key(t);let r=this.items.get(n);return void 0===r&&(r=[t,e()],this.items.set(n,r)),r[1]}set(t,e){return this.items.set(this._key(t),[t,e]),this}forEach(t,e){this.items.forEach((([n,r])=>t.call(e,r,n,this)))}entries(){return this.items.values()}keys(){return N(this.items.values(),(([t,e])=>t))}values(){return N(this.items.values(),(([t,e])=>e))}delete(t){return this.items.delete(this._key(t))}getAndDelete(t,e){const n=this._key(t),r=this.items.get(n);return void 0===r?e:(this.items.delete(n),r[1])}clear(){this.items.clear()}has(t){return this.items.has(this._key(t))}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexMap"}equals(t,e=((t,e)=>t===e)){if(!("size"in t&&"has"in t&&"get"in t))return!1;if(this.size!==t.size)return!1;for(let[n,r]of this.items.values()){if(!t.has(n))return!1;if(!e(r,t.get(n)))return!1}return!0}update(t,e,n,r=((t,e)=>t===e)){const s=this._key(t);if(this.items.has(s)){const n=this.items.get(s)[1],i=e(n);return void 0===i?(this.items.delete(s),-1):(r(i,n)||this.items.set(s,[t,i]),0)}{const r=e(n);return void 0===r?0:(this.items.set(s,[t,r]),1)}}canonicalKeys(){return this.items.keys()}get[F](){return!0}}class z{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(N(e[Symbol.iterator](),(t=>[this._key(t),t])))}_key(t){return this.canonicalizer(t)}has(t){return this.items.has(this._key(t))}get(t){const e=this._key(t);return this.items.has(e)?{item:this.items.get(e)}:null}add(t){return this.items.set(this._key(t),t),this}forEach(t,e){this.items.forEach((n=>t.call(e,n,n,this)))}entries(){return N(this.items.values(),(t=>[t,t]))}keys(){return this.items.values()}values(){return this.items.values()}delete(t){return this.items.delete(this._key(t))}clear(){this.items.clear()}get size(){return this.items.size}[Symbol.iterator](){return this.items.values()}get[Symbol.toStringTag](){return"FlexSet"}equals(t){if(!("size"in t)||!("has"in t))return!1;if(this.size!==t.size)return!1;for(let e of this.items.values())if(!t.has(e))return!1;return!0}canonicalValues(){return this.items.keys()}union(t){const e=new z(this.canonicalizer,this);for(let n of t)e.add(n);return e}intersect(t){const e=new z(this.canonicalizer);for(let n of this)t.has(n)&&e.add(n);return e}subtract(t){const e=new z(this.canonicalizer);for(let n of this)t.has(n)||e.add(n);return e}get[U](){return!0}}function J(t){return ct.isAnnotated(t)?t.item:t}function H(e,n=1/0){return function e(n,r){if(0===r)return n;if(!ct.isAnnotated(n))return n;const s=r-1;function i(t){return e(t,s)}if(v.isRecord(n.item))return v(e(n.item.label,r),n.item.map(i));if(ct.isAnnotated(n.item))throw new Error("Improper annotation structure");if(0===s)return n.item;if(Array.isArray(n.item))return n.item.map(i);if(Q.isSet(n.item))return n.item.map(i);if(t.Dictionary.isDictionary(n.item)){const t=new K;return new K(n.item).forEach(((e,n)=>t.set(i(n),i(e)))),t.simplifiedValue()}return n.item}(e,n)}t.JsDictionary=void 0,function(t){function e(t,e){return t[e.description]}function n(t,e){return Object.hasOwnProperty.call(t,e.description)}function r(t){return Object.keys(t).length}function s(t){return N(Object.entries(t).values(),(([t,e])=>[Symbol.for(t),e]))}t.isJsDictionary=function(t){return"object"==typeof t&&null!==t&&null===Object.getPrototypeOf(Object.getPrototypeOf(t))&&"function"!=typeof t.__as_preserve__&&!_(t)},t.from=function(t){const e={};for(const[n,r]of t)e[n.description]=r;return e},t.clear=function(t){for(const e in t)delete t[e]},t.remove=function(t,e){const r=n(t,e);return delete t[e.description],r},t.forEach=function(t,e){Object.entries(t).forEach((([t,n])=>e(n,Symbol.for(t))))},t.get=e,t.has=n,t.set=function(t,e,n){return t[e.description]=n,t},t.size=r,t.entries=s,t.keys=function(t){return N(Object.keys(t).values(),(t=>Symbol.for(t)))},t.values=function(t){return Object.values(t).values()},t.clone=function(t){const e={};return Object.keys(t).forEach((n=>e[n]=t[n])),e},t.equals=function(t,i,o=((t,e)=>t===e)){if(r(t)!==r(i))return!1;for(let[r,a]of s(t)){if(!n(i,r))return!1;if(!o(a,e(i,r)))return!1}return!0}}(t.JsDictionary||(t.JsDictionary={}));const W=Symbol.for("DictionaryType");class L extends R{constructor(t,e,n){super((e=>T(t(e))),n),this.encodeK=t,this.encodeV=e}__preserve_on__(t){G(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){X(this,t,((t,e)=>e.push(this.encodeK(t))),((t,e)=>e.push(this.encodeV(t))))}}class $ extends L{get[W](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[W])}constructor(t){super((t=>t),(t=>t),t)}clone(){return new $(this)}get[Symbol.toStringTag](){return"Dictionary"}equals(e,n=((t,e)=>t===e)){const r=t.Dictionary.asMap(e);return!!r&&super.equals(r,n)}}class K{get[F](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):W in t?(this.j=void 0,this.k=t):(this.j=t,this.k=void 0)}static from(t){const e=new K;for(const[n,r]of t)e.set(n,r);return e}clear(){this.j?t.JsDictionary.clear(this.j):this.k.clear()}delete(e){return this.j?"symbol"==typeof(e=J(e))&&t.JsDictionary.remove(this.j,e):this.k.delete(e)}forEach(e,n){this.j?t.JsDictionary.forEach(this.j,((t,r)=>e.call(n,t,r,this))):this.k.forEach(e,n)}get(e){if(this.j){if("symbol"!=typeof(e=J(e)))return;return t.JsDictionary.get(this.j,e)}return this.k.get(e)}has(e){return this.j?"symbol"==typeof(e=J(e))&&t.JsDictionary.has(this.j,e):this.k.has(e)}set(e,n){if(this.j){if("symbol"==typeof e)return t.JsDictionary.set(this.j,e,n),this;this.k=new $(t.JsDictionary.entries(this.j)),this.j=void 0}return this.k.set(e,n),this}get size(){return this.j?t.JsDictionary.size(this.j):this.k.size}entries(){return this.j?t.JsDictionary.entries(this.j):this.k.entries()}keys(){return this.j?t.JsDictionary.keys(this.j):this.k.keys()}values(){return this.j?t.JsDictionary.values(this.j):this.k.values()}[Symbol.iterator](){return this.entries()}get[Symbol.toStringTag](){return"DictionaryMap"}clone(){return new K(this.j?t.JsDictionary.clone(this.j):this.k.clone())}get value(){var t;return null!==(t=this.j)&&void 0!==t?t:this.k}simplify(){if(!this.j){const t={};for(const[e,n]of this.k.entries()){if("symbol"!=typeof e)return;t[e.description]=n}this.j=t,this.k=void 0}}simplifiedValue(){return this.simplify(),this.value}asJsDictionary(){if(this.simplify(),!this.j)throw new Error("Cannot represent general dictionary as JsDictionary");return this.j}asKeyedDictionary(){var e;return null!==(e=this.k)&&void 0!==e?e:new $(t.JsDictionary.entries(this.j))}}function G(t,n,r,s){if(n.canonical){const i=Array.from(t),o=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),a=i.map((([t,e],n)=>(r(t,o),[o.contents(),n])));a.sort(((t,e)=>h.compare(t[0],e[0]))),n.grouped(e.Dictionary,(()=>a.forEach((([t,e])=>{const[o,a]=i[e];r(o,n),s(a,n)}))))}else n.grouped(e.Dictionary,(()=>t.forEach(((t,e)=>{r(e,n),s(t,n)}))))}function X(t,e,n,r){e.state.writeSeq("{","}",t.entries(),(([t,s])=>{n(t,e),ct.isAnnotated(s)&&ht(s).length>1&&e.state.isIndenting?(e.state.pieces.push(":"),e.state.indentCount++,e.state.writeIndent(),r(s,e),e.state.indentCount--):(e.state.pieces.push(": "),r(s,e))}))}t.Dictionary=void 0,function(e){function n(e){if("object"!=typeof e||null===e)return!1;switch(e[W]){case"Dictionary":return!0;case void 0:return t.JsDictionary.isJsDictionary(e);default:return!1}}e.isDictionary=n,e.asMap=function(t){return n(t)?new K(t):void 0},e.from=function(t){return K.from(t).simplifiedValue()},e.__from_preserve__=function(t){return e.isDictionary(t)?t:void 0}}(t.Dictionary||(t.Dictionary={}));class Y extends z{constructor(t,e){super((e=>T(t(e))),e),this.encodeV=t}__preserve_on__(t){tt(this,t,((t,e)=>e.push(this.encodeV(t))))}__preserve_text_on__(t){et(this,t,((t,e)=>e.push(this.encodeV(t))))}}class Z extends Y{get[W](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[W])}constructor(t){super((t=>t),t)}map(t){return new Z(N(this[Symbol.iterator](),t))}filter(t){const e=new Z;for(let n of this)t(n)&&e.add(n);return e}clone(){return new Z(this)}get[Symbol.toStringTag](){return"Set"}}let Q=class t extends Z{static isSet(t){return"Set"===(null==t?void 0:t[W])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function tt(t,n,r){if(n.canonical){const s=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),i=Array.from(t).map((t=>(r(t,s),[s.contents(),t])));i.sort(((t,e)=>h.compare(t[0],e[0]))),n.grouped(e.Set,(()=>i.forEach((([t,e])=>r(e,n)))))}else n.grouped(e.Set,(()=>t.forEach((t=>r(t,n)))))}function et(t,e,n){e.state.writeSeq("#{","}",t,(t=>n(t,e)))}const nt=Symbol.for("IsPreservesAnnotated");function rt(t){return!!(null==t?void 0:t[nt])}function st(e,n){if(rt(e)&&(e=e.item),rt(n)&&(n=n.item),Object.is(e,n))return!0;if(typeof e!=typeof n)return("number"==typeof e&&"bigint"==typeof n||"bigint"==typeof e&&"number"==typeof n)&&e==n;if("object"==typeof e){if(null===e||null===n)return!1;if("equals"in e&&"function"==typeof e.equals)return e.equals(n,st);if(Array.isArray(e)&&Array.isArray(n)){const t="label"in e;if(t!=="label"in n)return!1;if(t&&!st(e.label,n.label))return!1;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!st(e[t],n[t]))return!1;return!0}{const r=t.Dictionary.asMap(e),s=t.Dictionary.asMap(n);if(!r||!s)return!1;if(r.size!==s.size)return!1;for(const t of r.keys()){if(!s.has(t))return!1;if(!st(r.get(t),s.get(t)))return!1}return!0}}return!1}function it(t){return{line:1,column:0,pos:0,name:t}}function ot(t,e){if(t.pos++,void 0===t.line)return!1;{let n=!1;switch(e){case"\t":t.column=t.column+8&-8;break;case"\n":t.column=0,t.line++,n=!0;break;case"\r":t.column=0;break;default:t.column++}return n}}function at(t){var e,n,r;return null===t?"<unknown>":"string"==typeof t?t:`${null!==(e=t.name)&&void 0!==e?e:""}:${null!==(n=t.line)&&void 0!==n?n:""}:${null!==(r=t.column)&&void 0!==r?r:""}:${t.pos}`}class ct{constructor(t,e){this.annotations=[],this.pos=null!=e?e:null,this.item=t}__as_preserve__(){return this}static __from_preserve__(t){return rt(t)?t:void 0}__preserve_on__(t){if(t.includeAnnotations)for(const n of this.annotations)t.state.emitbyte(e.Annotation),t.push(n);t.push(this.item)}__preserve_text_on__(t){if(t.includeAnnotations){const e=this.annotations.length<=1;for(const n of this.annotations)t.state.pieces.push("@"),t.push(n),e?t.state.pieces.push(" "):t.state.writeIndentSpace()}t.push(this.item)}equals(t){return st(this.item,ct.isAnnotated(t)?t.item:t)}get[nt](){return!0}static isAnnotated(t){return rt(t)}}function ut(t,...e){const n=ct.isAnnotated(t)?t:new ct(t);return e.forEach((t=>n.annotations.push(t))),n}function ht(t){return ct.isAnnotated(t)?t.annotations:[]}function dt(e){return Array.isArray(e)||Q.isSet(e)||t.Dictionary.isDictionary(e)}const lt=Symbol.for("FloatType");class ft{constructor(t){this.value="number"==typeof t?t:t.value}__preserve_text_on__(t){t.state.pieces.push(this.toString())}equals(t){return!!Object.is(t.constructor,this.constructor)&&(Number.isNaN(this.value)&&Number.isNaN(t.value)?t.toBytes().equals(this.toBytes()):Object.is(t.value,this.value))}hashCode(){return 0|this.value}}function pt(t){if(Object.is(t,-0))return"-0.0";const e=""+t;return e.includes(".")||e.includes("e")||e.includes("E")?e:e+".0"}ft.isFloat=t=>void 0!==(null==t?void 0:t[lt]),ft.isDouble=t=>"Double"===(null==t?void 0:t[lt]);class yt extends ft{__as_preserve__(){return this}static fromBytes(t){return new yt(p(t).getFloat64(0,!1))}static __from_preserve__(t){return ft.isDouble(t)?t:void 0}__preserve_on__(t){t.state.emitbyte(e.Ieee754),t.state.emitbyte(8),t.state.makeroom(8),t.state.view.setFloat64(t.state.index,this.value,!1),t.state.index+=8}toBytes(){const t=new h(8);return t.dataview().setFloat64(0,this.value,!1),t}toString(){return Number.isFinite(this.value)?pt(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[lt](){return"Double"}}function mt(t){return new yt(t)}const bt=BigInt(Number.MAX_SAFE_INTEGER),gt=BigInt(Number.MIN_SAFE_INTEGER),wt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class vt{constructor(t,e){switch(this.discarded=0,this.buffer=t,typeof e.name){case"undefined":this.pos=it();break;case"string":this.pos=it(e.name);break;case"object":this.pos=Object.assign({},e.name)}this.index=0,this.options=e}error(t,e){throw new b(t,Object.assign({},e))}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}copyPos(){return Object.assign({},this.pos)}write(t){this.atEnd()?this.buffer=t:this.buffer=this.buffer.substring(this.index)+t,this.discarded+=this.index,this.index=0}atEnd(){return this.index>=this.buffer.length}peek(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.index]}advance(){const t=this.index++;return ot(this.pos,this.buffer[t]),t}nextchar(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer[this.advance()]}nextcharcode(){if(this.atEnd())throw new w("Short term",this.pos);return this.buffer.charCodeAt(this.advance())}skipws(t=!1){for(;!this.atEnd();){const e=this.peek();if(!(Et(e)||t&&","===e))break;this.advance()}}readHex2(){return l(this.nextcharcode(),b)<<4|l(this.nextcharcode(),b)}readHex4(){return l(this.nextcharcode(),b)<<12|l(this.nextcharcode(),b)<<8|l(this.nextcharcode(),b)<<4|l(this.nextcharcode(),b)}readHexBinary(){const t=[];for(;;){if(this.skipws(),'"'===this.peek())return this.advance(),h.from(t);t.push(this.readHex2())}}readHexFloat(){const t=this.copyPos();'"'!==this.nextchar()&&this.error("Missing open-double-quote in hex-encoded floating-point number",t);const e=this.readHexBinary();return 8!==e.length&&this.error("Incorrect number of bytes in hex-encoded Double",t),yt.fromBytes(e)}readBase64Binary(){let t="";for(;;){this.skipws();const e=this.nextchar();if("]"===e)break;t+=e}return h.fromBase64(t)}requireDelimiter(t){this.delimiterFollows()||this.error(`Delimiter must follow ${t}`,this.pos)}delimiterFollows(){if(this.atEnd())return!0;const t=this.peek();return-1!=='(){}[]<>";,@#:|'.indexOf(t)||Et(t)}readRawSymbolOrNumber(t){for(;!this.delimiterFollows();)t+=this.nextchar();const e=wt.exec(t);if(e){if(void 0===e[2]){let t=BigInt(e[1]);return t<=gt||t>=bt?t:Number(t)}return mt(parseFloat(t))}return Symbol.for(t)}readStringlike(t,e,n,r,s){let i=[];for(;;){const o=this.nextchar();switch(o){case n:return e(i);case"\\":{const e=this.nextchar();switch(e){case r:i.push(s());break;case n:case"\\":case"/":i.push(t(e));break;case"b":i.push(t("\b"));break;case"f":i.push(t("\f"));break;case"n":i.push(t("\n"));break;case"r":i.push(t("\r"));break;case"t":i.push(t("\t"));break;default:this.error(`Invalid escape code \\${e}`,this.pos)}break}default:i.push(t(o))}}}readString(t){return this.readStringlike((t=>t),(t=>t.join("")),t,"u",(()=>{const t=this.readHex4();if(t>=55296&&t<=57343){if("\\"===this.nextchar()&&"u"===this.nextchar()){const e=this.readHex4();if(e>=56320&&e<=57343&&t<=56319)return String.fromCharCode(t,e)}this.error("Invalid surrogate pair",this.pos)}return String.fromCharCode(t)}))}readLiteralBinary(){return this.readStringlike((t=>{const e=t.charCodeAt(0);return e>=256&&this.error(`Invalid code point ${e} in literal binary`,this.pos),e}),h.from,'"',"x",(()=>this.readHex2()))}readCommentLine(){let t="";for(;;){const e=this.nextchar();if("\n"===e||"\r"===e)return t;t+=e}}}const xt={decode(t){return new S(new qt(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:H(t))};class _t{constructor(t="",e){var n,r;if(t instanceof vt)this.state=t,this.embeddedType=e;else{const s=null!==(n=e)&&void 0!==n?n:{};this.state=new vt(t,s),this.embeddedType=null!==(r=s.embeddedDecode)&&void 0!==r?r:Tt}}write(t){this.state.write(t)}}let St=class t extends _t{readCommentLine(){const t=this.state.copyPos();return this.wrap(this.state.readCommentLine(),t)}wrap(t,e){return this.state.includeAnnotations&&!ct.isAnnotated(t)&&(t=new ct(t,e)),t}annotateNextWith(t){if(this.state.skipws(),this.state.atEnd())throw new b("Trailing annotations and comments are not permitted",this.state.pos);const e=this.next();return this.state.includeAnnotations&&e.annotations.unshift(t),e}readToEnd(){const t=[];for(;;){if(this.state.skipws(),this.state.atEnd())return t;t.push(this.next())}}next(){this.state.skipws();const e=this.state.copyPos(),n=(()=>{const n=this.state.nextchar();switch(n){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",e);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",e);case"#":{const n=this.state.nextchar();switch(n){case" ":case"\t":return this.annotateNextWith(this.readCommentLine());case"\n":case"\r":return this.annotateNextWith("");case"!":return this.annotateNextWith(v(Symbol.for("interpreter"),[this.readCommentLine()]));case"f":return this.state.requireDelimiter("#f"),!1;case"t":return this.state.requireDelimiter("#t"),!0;case"{":return this.readSet();case'"':return this.state.readLiteralBinary();case"x":switch(this.state.nextchar()){case'"':return this.state.readHexBinary();case"d":return this.state.readHexFloat();default:this.state.error("Invalid #x syntax",e)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new t(this.state,xt).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${n}`,e)}}case"<":return v(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",e);case"]":this.state.error("Unexpected ]",e);case"}":this.state.error("Unexpected }",e);case",":this.state.error("Unexpected ,",e);default:return this.state.readRawSymbolOrNumber(n)}})();return this.wrap(n,e)}seq(t,e,n,r){for(;;){if(this.state.skipws(t),this.state.peek()===r)return this.state.advance(),e;n(this.next(),e)}}readSequence(t,e){return this.seq(e,[],((t,e)=>e.push(t)),t)}readDictionary(){return this.seq(!0,new K,((t,e)=>{if(this.state.skipws(),":"===this.state.peek())this.state.advance(),e.has(t)&&this.state.error(`Duplicate key: ${Vt(t)}`,this.state.pos),e.set(t,this.next());else this.state.error("Missing key/value separator",this.state.pos)}),"}").simplifiedValue()}readSet(){return this.seq(!0,new Q,((t,e)=>{e.has(t)&&this.state.error(`Duplicate value in set: ${Vt(t)}`,this.state.pos),e.add(t)}),"}")}};function Et(t){return-1!==" \t\n\r".indexOf(t)}function kt(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const At={encode(t,e){new B(t,this).push(e.generic)},toValue:t=>t.generic},Dt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class Ct{constructor(t){var e;this.pieces=[],this.indentCount=0,this.options=t,this.indentDelta=" ".repeat(null!==(e=t.indent)&&void 0!==e?e:0)}get isIndenting(){return this.indentDelta.length>0}get includeAnnotations(){var t;return null===(t=this.options.includeAnnotations)||void 0===t||t}writeIndent(){if(this.isIndenting){this.pieces.push("\n");for(let t=0;t<this.indentCount;t++)this.pieces.push(this.indentDelta)}}writeIndentSpace(){this.isIndenting?this.writeIndent():this.pieces.push(" ")}escapeStringlikeChar(t,e=(t=>t)){switch(t){case"\\":return"\\\\";case"\b":return"\\b";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";default:return e(t)}}escapeStringlike(t,e){let n=e;for(let r of t)n+=r===e?"\\"+e:this.escapeStringlikeChar(r);return n+e}writeSeq(t,e,n,r){let s=n[Symbol.iterator]();this.pieces.push(t);const i=s.next();if(!0!==i.done){const t=i.value,e=s.next();if(!0===e.done)r(t);else{let n;for(this.indentCount++,this.writeIndent(),r(t),this.writeIndentSpace(),r(e.value);!0!==(n=s.next()).done;)this.writeIndentSpace(),r(n.value);this.indentCount--,this.writeIndent()}}this.pieces.push(e)}writeBytes(t){var e,n;const r=null!==(e=this.options.maxBinaryAsciiLength)&&void 0!==e?e:1024,s=null!==(n=this.options.maxBinaryAsciiProportion)&&void 0!==n?n:.75;if(t.length>=r)this.writeBase64(t);else{let e=0,n=Math.min(t.length,r);for(let r=0;r<n;r++){const n=t[r];switch(n){case 9:case 10:case 13:e++;break;default:n>=32&&n<=126&&e++}}0===n||e/n>=s?this.writeBinaryStringlike(t):this.writeBase64(t)}}writeBase64(t){this.pieces.push("#[",o(t),"]")}writeBinaryStringlike(t){let e='#"';for(let n of t)e+=34===n?'\\"':this.escapeStringlikeChar(String.fromCharCode(n),(t=>n>=32&&n<=126&&92!==n?t:"\\x"+("0"+n.toString(16)).slice(-2)));this.pieces.push(e+'"')}couldBeFlat(t){let e=!1;for(let n of t){if(Array.isArray(n)||Set.isSet(n)||Map.isMap(n)){if(e)return!1;e=!0}if(this.includeAnnotations&&rt(n)&&n.annotations.length>1)return!1}return!0}}class It{constructor(t={},e){var n;t instanceof Ct?(this.state=t,this.embeddedWrite=e):(this.state=new Ct(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:Dt)}static stringify(t,e){const n=new It(e);return n.push(t),n.contents()}contents(){return this.state.pieces.join("")}get includeAnnotations(){return this.state.includeAnnotations}push(t){switch(typeof t){case"boolean":this.state.pieces.push(t?"#t":"#f");break;case"string":this.state.pieces.push(this.state.escapeStringlike(t,'"'));break;case"symbol":{const e=t.description;/^[-a-zA-Z0-9~!$%^&*?_=+/.]+$/.exec(e)&&!wt.exec(e)?this.state.pieces.push(e):this.state.pieces.push(this.state.escapeStringlike(e,"|"));break}case"bigint":case"number":this.state.pieces.push(""+t);break;case"object":if(null===t)throw new Error("Cannot encode null in Preserves Writer.push");if(kt(t))t.__preserve_text_on__(this);else if(kt(t))t.__preserve_text_on__(this);else if(ArrayBuffer.isView(t))if(t instanceof Uint8Array)this.state.writeBytes(t);else{const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);this.state.writeBytes(e)}else if(v.isRecord(t)){const e=this.state.couldBeFlat(t);this.state.pieces.push("<"),this.push(t.label),e||this.state.indentCount++;for(let n of t)e?this.state.pieces.push(" "):this.state.writeIndentSpace(),this.push(n);e||this.state.indentCount--,this.state.pieces.push(">")}else!function(t){return"object"==typeof t&&null!==t&&"function"==typeof t[Symbol.iterator]}(t)?_(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new It(this.state,At).push(this.embeddedWrite.toValue(t))):X(new K(t),this,((t,e)=>e.push(t)),((t,e)=>e.push(t))):this.state.writeSeq("[","]",t,(t=>this.push(t)));break;default:(e=>{throw new Error(`Internal error: unhandled in Preserves Writer.push for ${t}`)})()}return this}}function jt(t){return Bt(t)}function Bt(t,e){return function t(n){var r,s;switch(typeof n){case"number":if(!Number.isInteger(n)){const t=null!==(s=null===(r=null==e?void 0:e.onNonInteger)||void 0===r?void 0:r.call(e,n))&&void 0!==s?s:void 0;if(void 0!==t)return t;throw new TypeError("Refusing to autoconvert non-integer number to Double")}case"bigint":case"string":case"symbol":case"boolean":return n;case"undefined":case"function":break;case"object":if(null===n)break;if("function"==typeof n.__as_preserve__)return n.__as_preserve__();if(v.isRecord(n))return n;if(Array.isArray(n))return n.map(t);if(ArrayBuffer.isView(n)||n instanceof ArrayBuffer)return h.from(n);if(Map.isMap(n)){const e=new $;return n.forEach(((n,r)=>e.set(t(r),t(n)))),e}if(Q.isSet(n)){const e=new Q;return n.forEach((n=>e.add(t(n)))),e}if(_(n))return n;{const e={};return Object.entries(n).forEach((([n,r])=>e[n]=t(r))),e}}throw new TypeError("Cannot represent JavaScript value as Preserves: "+n)}(t)}t.Dictionary.stringMap=function(t){const e=new $;return Object.entries(t).forEach((([t,n])=>e.set(t,jt(n)))),e};const Ot={write(t,e){if(e instanceof S)new It(t,this).push(e.generic);else{try{const n=jt(e);if(!_(n))return void new It(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Vt(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:Ot,It.stringify(jt(t),e)}[ct,h,$,Z].forEach((t=>{t.prototype.toString=function(){return Vt(this)}}));class Mt{constructor(t,e){this.index=0,this.packet=f(t),this.options=e}get includeAnnotations(){var t;return null!==(t=this.options.includeAnnotations)&&void 0!==t&&t}write(t){this.index===this.packet.length?this.packet=f(t):this.packet=h.concat([this.packet.slice(this.index),t])._view,this.index=0}atEnd(){return this.index>=this.packet.length}mark(){return this.index}restoreMark(t){this.index=t}shortGuard(t,e){if(this.atEnd())return e();const n=this.mark();try{return t()}catch(t){if(w.isShortPacket(t))return this.restoreMark(n),e();throw t}}nextbyte(){if(this.atEnd())throw new w("Short packet");return this.packet[this.index++]}nextbytes(t){const e=this.index;if(this.index+=t,this.index>this.packet.length)throw new w("Short packet");return new DataView(this.packet.buffer,this.packet.byteOffset+e,t)}varint(){const t=this.nextbyte();return t<128?t:(this.varint()<<7)+(t-128)}peekend(){return this.nextbyte()===e.End||(this.index--,!1)}nextint(t){const e=this.index;if(0===t)return 0;if(t>7)return this.nextbigint(t);if(7===t){const e=this.packet[this.index];if(e>=32&&e<224)return this.nextbigint(t)}let n=this.nextbyte();128&n&&(n-=256);for(let e=1;e<t;e++)n=256*n+this.nextbyte();return Number.isSafeInteger(n)?n:(this.index=e,this.nextbigint(t))}nextbigint(t){if(0===t)return BigInt(0);const e=h.from(this.nextbytes(t));if(e.get(0)>=128){const t=e.toHex((t=>d(15-t)));return~BigInt("0x"+t)}{const t=e.toHex();return BigInt("0x"+t)}}wrap(t){return this.includeAnnotations?new ct(t):t}unshiftAnnotation(t,e){return this.includeAnnotations&&e.annotations.unshift(t),e}}const Tt={decode(t){throw new Error("Embeddeds not permitted at this point in Preserves document")},fromValue(t,e){throw new Error("Embeddeds not permitted at this point in Preserves document")}};class qt{constructor(t=new Uint8Array(0),e){var n,r,s;if(t instanceof Mt)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:Tt;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new Mt(t,n),this.embeddedDecode=null!==(s=n.embeddedDecode)&&void 0!==s?s:Tt}}write(t){this.state.write(t)}nextvalues(){const t=[];for(;!this.state.peekend();)t.push(this.next());return t}static dictionaryFromArray(t){const e=new K;if(t.length%2)throw new b("Missing dictionary value");for(let n=0;n<t.length;n+=2){if(e.has(t[n]))throw new b(`Duplicate key: ${Vt(t[n])}`);e.set(t[n],t[n+1])}return e.simplifiedValue()}next(){const t=this.state.nextbyte();switch(t){case e.False:return this.state.wrap(!1);case e.True:return this.state.wrap(!0);case e.End:throw new b("Unexpected Compound end marker");case e.Annotation:{const t=this.next(),e=this.next();return this.state.unshiftAnnotation(t,e)}case e.Embedded:return this.state.wrap(this.embeddedDecode.decode(this.state));case e.Ieee754:if(8===this.state.varint())return this.state.wrap(yt.fromBytes(this.state.nextbytes(8)));throw new b("Invalid IEEE754 size");case e.SignedInteger:return this.state.wrap(this.state.nextint(this.state.varint()));case e.String:return this.state.wrap(h.from(this.state.nextbytes(this.state.varint())).fromUtf8());case e.ByteString:return this.state.wrap(h.from(this.state.nextbytes(this.state.varint())));case e.Symbol:return this.state.wrap(Symbol.for(h.from(this.state.nextbytes(this.state.varint())).fromUtf8()));case e.Record:{const t=this.nextvalues();if(0===t.length)throw new b("Too few elements in encoded record");return this.state.wrap(v(t[0],t.slice(1)))}case e.Sequence:return this.state.wrap(this.nextvalues());case e.Set:{const t=new Q;for(const e of this.nextvalues()){if(t.has(e))throw new b(`Duplicate value: ${Vt(e)}`);t.add(e)}return this.state.wrap(t)}case e.Dictionary:return this.state.wrap(qt.dictionaryFromArray(this.nextvalues()));default:throw new b("Unsupported Preserves tag: "+t)}}try_next(){return this.state.shortGuard((()=>this.next()),(()=>{}))}atEnd(){return this.state.atEnd()}mark(){return this.state.mark()}restoreMark(t){return this.state.restoreMark(t)}skip(){this.next()}withEmbeddedDecode(t,e){return e(new qt(this.state,t))}skipAnnotations(t){const n=this.mark();for(;!this.state.atEnd()&&this.state.packet[this.state.index]===e.Annotation;)this.state.index++,this.skip();return t((()=>this.restoreMark(n)))}nextBoolean(){return this.skipAnnotations((t=>{switch(this.state.nextbyte()){case e.False:return!1;case e.True:return!0;default:return t()}}))}nextDouble(){return this.skipAnnotations((t=>this.state.nextbyte()!==e.Ieee754||8!==this.state.nextbyte()?t():yt.fromBytes(this.state.nextbytes(8))))}nextEmbedded(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Embedded?this.embeddedDecode.decode(this.state):t()))}nextSignedInteger(){return this.skipAnnotations((t=>this.state.nextbyte()===e.SignedInteger?this.state.nextint(this.state.varint()):t()))}nextString(){return this.skipAnnotations((t=>this.state.nextbyte()===e.String?h.from(this.state.nextbytes(this.state.varint())).fromUtf8():t()))}nextByteString(){return this.skipAnnotations((t=>this.state.nextbyte()===e.ByteString?h.from(this.state.nextbytes(this.state.varint())):t()))}nextSymbol(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Symbol?Symbol.for(h.from(this.state.nextbytes(this.state.varint())).fromUtf8()):t()))}openRecord(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Record||(t(),!1)))}openSequence(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Sequence||(t(),!1)))}openSet(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Set||(t(),!1)))}openDictionary(){return this.skipAnnotations((t=>this.state.nextbyte()===e.Dictionary||(t(),!1)))}closeCompound(){return this.state.peekend()}}function Pt(t,e={}){return new qt(t,e).next()}const Ft=Object.assign({},xt,At),Ut=Object.assign({},Tt,Dt),Nt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},Rt=Object.assign({},Nt,I);var zt;t.ValueClass=void 0,(zt=t.ValueClass||(t.ValueClass={}))[zt.Boolean=0]="Boolean",zt[zt.Double=1]="Double",zt[zt.SignedInteger=2]="SignedInteger",zt[zt.String=3]="String",zt[zt.ByteString=4]="ByteString",zt[zt.Symbol=5]="Symbol",zt[zt.Record=6]="Record",zt[zt.Sequence=7]="Sequence",zt[zt.Set=8]="Set",zt[zt.Dictionary=9]="Dictionary",zt[zt.Embedded=10]="Embedded",zt[zt.Annotated=11]="Annotated";class Jt{boolean(t){}double(t){}integer(t){}string(t){}bytes(t){}symbol(t){}record(t,e){e(t.label),t.forEach(e)}array(t,e){t.forEach(e)}set(t,e){t.forEach(e)}dictionary(t,e){t.forEach(((t,n)=>{e(n),e(t)}))}annotated(t,e){e(t.item),t.annotations.forEach(e)}embedded(t,e){}}class Ht extends Jt{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class Wt{boolean(t){return t}double(t){return mt(t)}integer(t){return t}string(t){return t}bytes(t){return t}symbol(t){return t}record(t,e){return v(e(t.label),t.map(e))}array(t,e){return t.map(e)}set(t,e){return t.map(e)}dictionary(t,e){const n=new K;return t.forEach(((t,r)=>n.set(e(r),e(t)))),n.simplifiedValue()}annotated(t,e){return ut(e(t.item),...t.annotations.map(e))}}class Lt extends Wt{embedded(t,e){return t}}class $t extends Wt{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}const Kt=new Lt;function Gt(e,n){const r=e=>{switch(typeof e){case"boolean":return n.boolean(e);case"number":return Number.isInteger(e)?n.integer(e):n.double(e);case"bigint":return n.integer(e);case"string":return n.string(e);case"symbol":return n.symbol(e);case"object":if(v.isRecord(e))return n.record(e,r);if(Array.isArray(e))return n.array(e,r);if(Q.isSet(e))return n.set(e,r);if(_(e))return n.embedded(e,r);if(ct.isAnnotated(e))return n.annotated(e,r);if(h.isBytes(e))return n.bytes(e);if(ft.isDouble(e))return n.double(e.value);if(t.Dictionary.isDictionary(e))return n.dictionary(new K(e),r);default:(t=>{throw new Error("Internal error")})()}};return r(e)}function Xt(e){switch(rt(e)&&(e=e.item),typeof e){case"boolean":return 0;case"number":case"bigint":return 3;case"string":return 4;case"symbol":return 6;case"object":if(ft.isFloat(e))return 2;if(h.isBytes(e))return 5;if(Array.isArray(e))return"label"in e?7:8;if(Q.isSet(e))return 9;if(t.Dictionary.isDictionary(e))return 10;if(_(e))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}class Yt{constructor(t){this.text=t}__as_preserve__(){return v(Symbol.for("p"),[Symbol.for(this.text)])}isComma(){return","===this.text}static isComma(t){return t instanceof Yt&&t.isComma()}isColon(t=1){return this.text===":".repeat(t)}static isColon(t,e=1){return t instanceof Yt&&t.isColon(e)}}class Zt{constructor(t,e){this.expr=t,this.annotations=e}__as_preserve__(){var t,e;const n=jt(this.expr);return new S(null!==(e=null===(t=this.annotations)||void 0===t?void 0:t.wrap(n))&&void 0!==e?e:n)}}class Qt{constructor(){this.positions=[],this.exprs=[],this.annotations=void 0}get(t){if(!(t>=this.exprs.length))return{position:this.positions[t],item:this.exprs[t],annotations:this.annotations&&this.annotations[t]}}push(t,e,n){if(void 0===e){const e=t;e.annotations&&(this._ensureAnnotations()[this.exprs.length]=e.annotations),this.positions.push(e.position),this.exprs.push(e.item)}else n&&(this._ensureAnnotations()[this.exprs.length]=n),this.positions.push(e),this.exprs.push(t);return!0}_ensureAnnotations(){return void 0===this.annotations&&(this.annotations=[]),this.annotations}_annotationsAt(t){var e,n;return null!==(e=(n=this._ensureAnnotations())[t])&&void 0!==e?e:n[t]=new ee}preservesValues(){return this.exprs.map(((t,e)=>{var n;const r=jt(t);return void 0!==(null===(n=this.annotations)||void 0===n?void 0:n[e])?this.annotations[e].wrap(r):r}))}map(t,e=0){const n=[];for(let r=e;r<this.exprs.length;r++)n.push(t(this.get(r),r));return n}[Symbol.iterator](){let t=this,e=0;return{next:()=>e<t.exprs.length?{done:!1,value:t.get(e++)}:{done:!0,value:void 0},[Symbol.iterator]:()=>t[Symbol.iterator]()}}}class te extends Qt{__as_preserve__(){return this.preservesValues()}}class ee extends Qt{wrap(t){return ut(t,...this.preservesValues())}}class ne extends Qt{__as_preserve__(){const t=this.preservesValues();switch(this.variant){case"sequence":return t;case"record":return v(Symbol.for("r"),t);case"block":return v(Symbol.for("b"),t);case"group":return v(Symbol.for("g"),t);case"set":return v(Symbol.for("s"),t)}}}class re extends ne{get variant(){return"sequence"}}class se extends ne{get variant(){return"record"}}class ie extends ne{get variant(){return"block"}}class oe extends ne{get variant(){return"group"}}let ae=class extends ne{get variant(){return"set"}};var ce=Object.freeze({__proto__:null,Annotations:ee,BaseCompound:Qt,Block:ie,Compound:ne,Document:te,Embedded:Zt,Group:oe,Punct:Yt,Reader:class extends _t{nextDocument(t="all"){const e=new te;if(this.readExpr(e),"all"===t)for(;this.readExpr(e););return e}readCompound(t,e){for(;;){if(this.state.skipws(),this.state.peek()===e)return this.state.advance(),t;this.readExpr(t)||this.state.error(`Missing "${e}"`,this.state.copyPos())}}readSimpleExpr(t){return this._readInto(t,!1)}readExpr(t){return this._readInto(t,!0)}_readInto(t,e){for(;;){if(this.state.skipws(),this.state.atEnd())return!1;const n=this.state.copyPos(),r=this.state.nextchar();switch(r){case'"':return t.push(this.state.readString('"'),n);case"|":return t.push(Symbol.for(this.state.readString("|")),n);case";":if(e)return t.push(new Yt(";"),n);this.state.error("Semicolon is not permitted at this location",n);case"@":this.readSimpleExpr(t._annotationsAt(t.exprs.length))||this.state.error("Missing annotation",n);continue;case":":{let s=r;for(;!this.state.atEnd()&&":"===this.state.peek();)s+=":",this.state.advance();if(e)return t.push(new Yt(s),n);this.state.error("Colons are not permitted at this location",n)}case"#":{const e=this.state.nextchar();switch(e){case" ":case"\t":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push(this.state.readCommentLine(),e);continue}case"\n":case"\r":{const e=this.state.copyPos();t._annotationsAt(t.exprs.length).push("",e);continue}case"!":{const e=this.state.copyPos(),n=new se;n.push(Symbol.for("interpreter"),e),n.push(this.state.readCommentLine(),e),t._annotationsAt(t.exprs.length).push(n,e);continue}case"f":return this.state.requireDelimiter("#f"),t.push(!1,n);case"t":return this.state.requireDelimiter("#t"),t.push(!0,n);case"{":return t.push(this.readCompound(new ae,"}"),n);case'"':return t.push(this.state.readLiteralBinary(),n);case"x":switch(this.state.nextchar()){case'"':return t.push(this.state.readHexBinary(),n);case"d":return t.push(this.state.readHexFloat(),n);default:this.state.error("Invalid #x syntax",n)}case"[":return t.push(this.state.readBase64Binary(),n);case":":{const e=new Qt;if(!this.readSimpleExpr(e))return!1;const r=new Zt(e.exprs[0],e.annotations&&e.annotations[0]);return t.push(r,n)}default:this.state.error(`Invalid # syntax: ${e}`,n)}}case"(":return t.push(this.readCompound(new oe,")"),n);case"<":return t.push(this.readCompound(new se,">"),n);case"[":return t.push(this.readCompound(new re,"]"),n);case"{":return t.push(this.readCompound(new ie,"}"),n);case">":this.state.error("Unexpected >",n);case"]":this.state.error("Unexpected ]",n);case"}":this.state.error("Unexpected }",n);case",":if(e)return t.push(new Yt(","),n);this.state.error("Comma is not permitted at this location",n);default:return t.push(this.state.readRawSymbolOrNumber(r),n)}}}},Record:se,Sequence:re,Set:ae,asPreserves:function(t,e={}){var n;const r=null!==(n=e.error)&&void 0!==n?n:(t,e)=>{throw new Error(at(e)+": "+t)};function s(t){return Array.from(t).filter((t=>!Yt.isComma(t.item)))}return function t(n){if(n.item instanceof Yt)return r("invalid-punctuation",n.position);if(n.item instanceof Zt)return e.onEmbedded?e.onEmbedded({position:n.position,item:n.item.expr},t):r("unexpected-embedded",n.position);if(!(n.item instanceof ne))return n.item;switch(n.item.variant){case"sequence":return s(n.item).map(t);case"record":{const e=s(n.item).map(t);if(e.length<1)return r("invalid-record",n.position);const i=e.slice(1);return i.label=e[0],i}case"block":{const e=new K,i=s(n.item);if(i.length%3!=0)return r("invalid-dictionary",n.position);for(let n=0;n<i.length;n+=3){if(!Yt.isColon(i[n+1].item))return r("missing-colon",i[n+1].position);const s=t(i[n]),o=t(i[n+2]);e.set(s,o)}return e.simplifiedValue()}case"group":return e.onGroup?e.onGroup(n):r("unexpected-group",n.position);case"set":return new Q(s(n.item).map(t))}}(t)}});Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const ue=Array,he=Symbol;t.Annotated=ct,t.Array=ue,t.Bytes=h,t.Constants=n,t.DecodeError=b,t.Decoder=qt,t.DecoderState=Mt,t.DictionaryMap=K,t.DictionaryType=W,t.Double=mt,t.DoubleFloat=yt,t.Embedded=class{get[x](){return!0}constructor(t){this.value=t}equals(t){return"object"==typeof t&&"value"in t&&Object.is(this.value,t.value)}},t.EncodableDictionary=L,t.EncodableSet=Y,t.EncodeError=g,t.Encoder=B,t.EncoderState=j,t.ErrorType=y,t.FlexMap=R,t.FlexSet=z,t.Float=ft,t.FloatType=lt,t.ForEachEmbedded=Ht,t.GenericEmbedded=S,t.IDENTITY_FOLD=Kt,t.IdentityFold=Lt,t.IdentityMap=q,t.IdentitySet=P,t.IsEmbedded=x,t.IsMap=F,t.IsPreservesAnnotated=nt,t.IsPreservesBytes=u,t.IsSet=U,t.KeyedDictionary=$,t.KeyedSet=Z,t.MapFold=$t,t.NUMBER_RE=wt,t.Pexpr=ce,t.PreservesCodecError=m,t.Reader=St,t.ReaderBase=_t,t.ReaderState=vt,t.Record=v,t.Set=Q,t.ShortPacket=w,t.Symbol=he,t.ValueFold=Wt,t.VoidFold=Jt,t.Writer=It,t.WriterState=Ct,t._iterMap=N,t.annotate=ut,t.annotations=ht,t.asLiteral=function(t,e){return st(t,e)?e:void 0},t.canonicalEncode=function(t,e){if(void 0!==e||M)return O(t,Object.assign(Object.assign({},e),{canonical:!0}));{M=!0;const e=V.push(t).contents();return M=!1,e}},t.canonicalString=T,t.compare=function(e,n,r=((t,e)=>st(t,e)?0:t<e?-1:1)){return function e(n,s){rt(n)&&(n=n.item),rt(s)&&(s=s.item);const i=Xt(n),o=Xt(s);if(i<o)return-1;if(i>o)return 1;switch(i){case 0:case 3:case 4:return n<s?-1:n>s?1:0;case 2:{const t=n.value,e=s.value;return t<e?-1:t>e?1:0}case 5:return h.compare(n,s);case 6:{const t=n.description,e=s.description;return t<e?-1:t>e?1:0}case 7:{const t=e(n.label,s.label);if(0!==t)return t}case 8:{const t=n,r=s,i=Math.min(t.length,r.length);for(let n=0;n<i;n++){const s=e(t[n],r[n]);if(0!==s)return s}return t.length<r.length?-1:t.length>r.length?1:0}case 9:return e(Array.from(n).sort(e),Array.from(s).sort(e));case 10:return e(Array.from(t.Dictionary.asMap(n).entries()).sort(e),Array.from(t.Dictionary.asMap(s).entries()).sort(e));case 11:return r(n,s);default:throw new Error("Invalid typeCode: "+i)}}(e,n)},t.dataview=p,t.decode=Pt,t.decodeBase64=s,t.decodeWithAnnotations=function(t,e={}){return Pt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))},t.embeddedId=C,t.encode=O,t.encodeBase64=o,t.encodeDictionaryOn=G,t.encodeSetOn=tt,t.encodeWithAnnotations=function(t,e={}){return O(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))},t.floatValue=function(t){return"number"==typeof t?t:ft.isFloat(t)?t.value:NaN},t.floatlikeString=pt,t.fold=Gt,t.forEachEmbedded=function(t,e){return Gt(t,new Ht(e))},t.formatPosition=at,t.fromJS=jt,t.fromJS_options=Bt,t.genericEmbeddedType=Ft,t.genericEmbeddedTypeDecode=xt,t.genericEmbeddedTypeEncode=At,t.hexDigit=d,t.identityEmbeddedType=Rt,t.identityEmbeddedTypeDecode=Nt,t.identityEmbeddedTypeEncode=I,t.is=st,t.isAnnotated=rt,t.isCompound=dt,t.isEmbedded=_,t.isPreservable=E,t.isPreserveWritable=kt,t.isSequence=function(t){return Array.isArray(t)&&!("label"in t)},t.mapEmbeddeds=function(t,e){return Gt(t,new $t(e))},t.merge=function(e,n,...r){function s(){throw new Error("Cannot merge items")}function i(n,r){return n===r?n:dt(n)||dt(r)||!st(n,r)?Gt(n,{boolean:s,double:t=>st(n,r)?n:s(),integer:s,string:s,bytes:t=>st(n,r)?n:s(),symbol:s,record:t=>(v.isRecord(r)||s(),v(i(t.label,r.label),o(t,r))),array:t=>(Array.isArray(r)&&!v.isRecord(r)||s(),o(t,r)),set(t){s()},dictionary(e){const n=t.Dictionary.asMap(r);void 0===n&&s();const o=new K;return e.forEach(((t,e)=>{const r=n.get(e);o.set(e,void 0===r?t:i(t,r))})),n.forEach(((t,n)=>{e.has(n)||o.set(n,t)})),o.simplifiedValue()},annotated:t=>i(t,J(r)),embedded(t){_(r)||s();const n=e(t,r);return void 0===n&&s(),n}}):n}function o(t,e){return t.length<=e.length?e.map(((e,n)=>n<t.length?i(t[n],e):e)):t.map(((t,n)=>n<e.length?i(t,e[n]):t))}return r.reduce(i,n)},t.neverEmbeddedType=Ut,t.neverEmbeddedTypeDecode=Tt,t.neverEmbeddedTypeEncode=Dt,t.newPosition=it,t.parse=function(t,e){return new St(t,e).next()},t.parseAll=function(t,e){return new St(t,e).readToEnd()},t.peel=function(t){return H(t,1)},t.position=function(t){return ct.isAnnotated(t)?t.pos:null},t.preserves=function(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Vt(e)),n.push(t[r+1])})),n.join("")},t.stringify=Vt,t.stringifyEmbeddedWrite=Ot,t.strip=H,t.typeCode=Xt,t.unannotate=J,t.underlying=f,t.unhexDigit=l,t.updatePosition=ot,t.valueClass=function(e){switch(typeof e){case"boolean":return t.ValueClass.Boolean;case"number":if(Number.isInteger(e))return t.ValueClass.SignedInteger;throw new Error("Non-integer number in Preserves valueClass; missing Float wrapper?");case"bigint":return t.ValueClass.SignedInteger;case"string":return t.ValueClass.String;case"symbol":return t.ValueClass.Symbol;case"object":return v.isRecord(e)?t.ValueClass.Record:Array.isArray(e)?t.ValueClass.Sequence:Q.isSet(e)?t.ValueClass.Set:t.Dictionary.isDictionary(e)?t.ValueClass.Dictionary:ct.isAnnotated(e)?t.ValueClass.Annotated:h.isBytes(e)?t.ValueClass.ByteString:ft.isDouble(e)?t.ValueClass.Double:t.ValueClass.Embedded;default:(t=>{throw new Error("Internal error")})()}},t.writeDictionaryOn=X,t.writeSetOn=et}));

@@ -0,1 +1,2 @@

import { isEmbedded } from './embedded';
import { _iterMap } from './flex';

@@ -10,3 +11,4 @@ export var JsDictionary;

&& Object.getPrototypeOf(Object.getPrototypeOf(x)) === null
&& typeof x.__as_preserve__ !== 'function';
&& typeof x.__as_preserve__ !== 'function'
&& !isEmbedded(x);
}

@@ -13,0 +15,0 @@ JsDictionary.isJsDictionary = isJsDictionary;

{
"name": "@preserves/core",
"version": "0.995.202",
"version": "0.995.203",
"description": "Preserves data serialization format",

@@ -26,3 +26,3 @@ "homepage": "https://gitlab.com/preserves/preserves",

},
"gitHead": "9192bdea7edc948290644c68813f295a600bb11d"
"gitHead": "35e6ba2e82ceee131f9373540e35727ed772edd9"
}

@@ -0,1 +1,2 @@

import { isEmbedded } from './embedded';
import { Equivalence, _iterMap } from './flex';

@@ -14,3 +15,4 @@

&& Object.getPrototypeOf(Object.getPrototypeOf(x)) === null
&& typeof x.__as_preserve__ !== 'function';
&& typeof x.__as_preserve__ !== 'function'
&& !isEmbedded(x);
}

@@ -17,0 +19,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc