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.200 to 0.995.201

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 y{static isCodecError(t,e){return(null==t?void 0:t[p])===e}}class m extends Error{get[p](){return"DecodeError"}constructor(t,e){super(t),this.pos=e}static isDecodeError(t){return y.isCodecError(t,"DecodeError")}}class b extends Error{get[p](){return"EncodeError"}static isEncodeError(t){return y.isCodecError(t,"EncodeError")}constructor(t,e){super(t),this.irritant=e}}class w extends m{get[p](){return"ShortPacket"}static isShortPacket(t){return y.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 _(t){return!!(null==t?void 0:t[v])}class x{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 A(t){return String.fromCharCode.apply(null,t)}let E=0;const j=new WeakMap;function B(t){let e=j.get(t);return void 0===e&&(e=E++,j.set(t,e)),e}const I={encode(t,e){new C(t,this).push(B(e))}};class D{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=A(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(A).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 C{constructor(t={},e){var n;t instanceof D?(this.state=t,this.embeddedEncode=null!=e?e:I):(this.state=new D(t),this.embeddedEncode=null!==(n=t.embeddedEncode)&&void 0!==n?n:I)}withEmbeddedEncode(t,e){return e(new C(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)?_(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 C(e).push(t).contents()}const M=new C({canonical:!0});let q=!1;function T(t,e){if(void 0!==e||q)return O(t,Object.assign(Object.assign({},e),{canonical:!0}));{q=!0;const e=M.push(t).contents();return q=!1,e}}function U(t){if(q)return new C({canonical:!0}).push(t).contentsString();{q=!0;const e=M.push(t).contentsString();return q=!1,e}}function V(t,e={}){return O(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const N=Map,F=Set,z=Symbol.for("IsMap"),P=Symbol.for("IsSet");function R(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}}}z in Map.prototype||(Object.defineProperty(Map.prototype,z,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[z])),P in Set.prototype||(Object.defineProperty(Set.prototype,P,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[P]));class H{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(R(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 R(this.items.values(),(([t,e])=>t))}values(){return R(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[z](){return!0}}class W{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(R(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 R(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 W(this.canonicalizer,this);for(let n of t)e.add(n);return e}intersect(t){const e=new W(this.canonicalizer);for(let n of this)t.has(n)&&e.add(n);return e}subtract(t){const e=new W(this.canonicalizer);for(let n of this)t.has(n)||e.add(n);return e}get[P](){return!0}}var L;function $(t){return ft.isAnnotated(t)?t.item:t}function K(t){return J(t,1)}function J(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 R(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 R(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}}(L||(L={}));const G=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[G](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[G])}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[z](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):G 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?L.clear(this.j):this.k.clear()}delete(t){return this.j?"symbol"==typeof(t=$(t))&&L.remove(this.j,t):this.k.delete(t)}forEach(t,e){this.j?L.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 L.get(this.j,t)}return this.k.get(t)}has(t){return this.j?"symbol"==typeof(t=$(t))&&L.has(this.j,t):this.k.has(t)}set(t,e){if(this.j){if("symbol"==typeof t)return L.set(this.j,t,e),this;this.k=new Z(L.entries(this.j)),this.j=void 0}return this.k.set(t,e),this}get size(){return this.j?L.size(this.j):this.k.size}entries(){return this.j?L.entries(this.j):this.k.entries()}keys(){return this.j?L.keys(this.j):this.k.keys()}values(){return this.j?L.values(this.j):this.k.values()}[Symbol.iterator](){return this.entries()}get[Symbol.toStringTag](){return"DictionaryMap"}clone(){return new Q(this.j?L.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(L.entries(this.j))}}var Y;function tt(e,n,r,s){if(n.canonical){const i=Array.from(e),o=new C({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)&&yt(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[G]){case"Dictionary":return!0;case void 0:return L.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 W{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[G](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[G])}constructor(t){super((t=>t),t)}map(t){return new rt(R(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[G])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function it(e,n,r){if(n.canonical){const s=new C({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 yt(t){return ft.isAnnotated(t)?t.annotations:[]}function mt(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 _t(t){return"number"==typeof t?t:vt.isFloat(t)?t.value:NaN}function xt(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)?xt(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[gt](){return"Double"}}function kt(t){return new St(t)}const At=BigInt(Number.MAX_SAFE_INTEGER),Et=BigInt(Number.MIN_SAFE_INTEGER),jt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class Bt{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 m(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(!(Ct(e)||t&&","===e))break;this.advance()}}readHex2(){return l(this.nextcharcode(),m)<<4|l(this.nextcharcode(),m)}readHex4(){return l(this.nextcharcode(),m)<<12|l(this.nextcharcode(),m)<<8|l(this.nextcharcode(),m)<<4|l(this.nextcharcode(),m)}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)||Ct(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<=Et||t>=At?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()))}}const It={decode(t){return new S(new $t(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:J(t))};class Dt{constructor(t="",e){var n,r;if(t instanceof Bt)this.state=t,this.embeddedType=e;else{const s=null!==(n=e)&&void 0!==n?n:{};this.state=new Bt(t,s),this.embeddedType=null!==(r=s.embeddedDecode)&&void 0!==r?r:Lt}}write(t){this.state.write(t)}readCommentLine(){const t=this.state.copyPos();let e="";for(;;){const n=this.state.nextchar();if("\n"===n||"\r"===n)return this.wrap(e,t);e+=n}}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 m("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 t=this.state.copyPos(),e=(()=>{const e=this.state.nextchar();switch(e){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",t);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",t);case"#":{const e=this.state.nextchar();switch(e){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",t)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new Dt(this.state,It).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${e}`,t)}}case"<":return g(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",t);case"]":this.state.error("Unexpected ]",t);case"}":this.state.error("Unexpected }",t);case",":this.state.error("Unexpected ,",t);default:return this.state.readRawSymbolOrNumber(e)}})();return this.wrap(e,t)}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: ${Pt(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: ${Pt(t)}`,this.state.pos),e.add(t)}),"}")}}function Ct(t){return-1!==" \t\n\r".indexOf(t)}function Ot(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const Mt={encode(t,e){new C(t,this).push(e.generic)},toValue:t=>t.generic},qt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class Tt{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 Ut{constructor(t={},e){var n;t instanceof Tt?(this.state=t,this.embeddedWrite=e):(this.state=new Tt(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:qt)}static stringify(t,e){const n=new Ut(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(Ot(t))t.__preserve_text_on__(this);else if(Ot(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)?_(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new Ut(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 Vt(t){switch(typeof t){case"number":if(!Number.isInteger(t))throw new TypeError("Refusing to autoconvert non-integer number to Double");case"bigint":case"string":case"symbol":case"boolean":return t;case"undefined":case"function":break;case"object":if(null===t)break;if("function"==typeof t.__as_preserve__)return t.__as_preserve__();if(g.isRecord(t))return t;if(Array.isArray(t))return t.map(Vt);if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer)return c.from(t);if(Map.isMap(t)){const e=new Z;return t.forEach(((t,n)=>e.set(Vt(n),Vt(t)))),e}if(st.isSet(t)){const e=new st;return t.forEach((t=>e.add(Vt(t)))),e}if(_(t))return t;{const e={};return Object.entries(t).forEach((([t,n])=>e[t]=Vt(n))),e}}throw new TypeError("Cannot represent JavaScript value as Preserves: "+t)}function Nt(t,e){return new Dt(t,e).next()}function Ft(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,Vt(n)))),e};const zt={write(t,e){if(e instanceof S)new Ut(t,this).push(e.generic);else{try{const n=Vt(e);if(!_(n))return void new Ut(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Pt(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:zt,Ut.stringify(Vt(t),e)}function Rt(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Pt(e)),n.push(t[r+1])})),n.join("")}function Ht(t,e){return ct(t,e)?e:void 0}[ft,c,Z,rt].forEach((t=>{t.prototype.toString=function(){return Pt(this)}}));class Wt{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 Lt={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 $t{constructor(t=new Uint8Array(0),e){var n,r,s;if(t instanceof Wt)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:Lt;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new Wt(t,n),this.embeddedDecode=null!==(s=n.embeddedDecode)&&void 0!==s?s:Lt}}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 m("Missing dictionary value");for(let n=0;n<t.length;n+=2){if(e.has(t[n]))throw new m(`Duplicate key: ${Pt(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 m("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 m("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 m("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 m(`Duplicate value: ${Pt(e)}`);t.add(e)}return this.state.wrap(t)}case t.Dictionary:return this.state.wrap($t.dictionaryFromArray(this.nextvalues()));default:throw new m("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 $t(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 Kt(t,e={}){return new $t(t,e).next()}function Jt(t,e={}){return Kt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const Gt=Object.assign({},It,Mt),Xt=Object.assign({},Lt,qt),Zt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},Qt=Object.assign({},Zt,I);var Yt;!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"}(Yt||(Yt={}));class te{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 ee extends te{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class ne{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 re extends ne{embedded(t,e){return t}}class se extends ne{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}function ie(t){switch(typeof t){case"boolean":return Yt.Boolean;case"number":if(Number.isInteger(t))return Yt.SignedInteger;throw new Error("Non-integer number in Preserves valueClass; missing Float wrapper?");case"bigint":return Yt.SignedInteger;case"string":return Yt.String;case"symbol":return Yt.Symbol;case"object":return g.isRecord(t)?Yt.Record:Array.isArray(t)?Yt.Sequence:st.isSet(t)?Yt.Set:Y.isDictionary(t)?Yt.Dictionary:ft.isAnnotated(t)?Yt.Annotated:c.isBytes(t)?Yt.ByteString:vt.isDouble(t)?Yt.Double:Yt.Embedded;default:(t=>{throw new Error("Internal error")})()}}const oe=new re;function ae(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(_(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 ue(t,e){return ae(t,new se(e))}function ce(t,e){return ae(t,new ee(e))}function he(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)?ae(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){_(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 le(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(_(t))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}function de(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=le(e),i=le(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)}Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const fe=Array,pe=Symbol;export{ft as Annotated,fe as Array,c as Bytes,e as Constants,m as DecodeError,$t as Decoder,Wt as DecoderState,Y as Dictionary,Q as DictionaryMap,G as DictionaryType,kt as Double,St as DoubleFloat,x as Embedded,X as EncodableDictionary,nt as EncodableSet,b as EncodeError,C as Encoder,D as EncoderState,p as ErrorType,H as FlexMap,W as FlexSet,vt as Float,gt as FloatType,ee as ForEachEmbedded,S as GenericEmbedded,oe as IDENTITY_FOLD,re as IdentityFold,N as IdentityMap,F as IdentitySet,v as IsEmbedded,z as IsMap,at as IsPreservesAnnotated,u as IsPreservesBytes,P as IsSet,L as JsDictionary,Z as KeyedDictionary,rt as KeyedSet,se as MapFold,jt as NUMBER_RE,y as PreservesCodecError,Dt as Reader,Bt as ReaderState,g as Record,st as Set,w as ShortPacket,pe as Symbol,Yt as ValueClass,ne as ValueFold,te as VoidFold,Ut as Writer,Tt as WriterState,R as _iterMap,pt as annotate,yt as annotations,Ht as asLiteral,T as canonicalEncode,U as canonicalString,de as compare,f as dataview,Kt as decode,r as decodeBase64,Jt as decodeWithAnnotations,B as embeddedId,O as encode,i as encodeBase64,tt as encodeDictionaryOn,it as encodeSetOn,V as encodeWithAnnotations,_t as floatValue,xt as floatlikeString,ae as fold,ce as forEachEmbedded,dt as formatPosition,Vt as fromJS,Gt as genericEmbeddedType,It as genericEmbeddedTypeDecode,Mt as genericEmbeddedTypeEncode,h as hexDigit,Qt as identityEmbeddedType,Zt as identityEmbeddedTypeDecode,I as identityEmbeddedTypeEncode,ct as is,ut as isAnnotated,bt as isCompound,_ as isEmbedded,k as isPreservable,Ot as isPreserveWritable,wt as isSequence,ue as mapEmbeddeds,he as merge,Xt as neverEmbeddedType,Lt as neverEmbeddedTypeDecode,qt as neverEmbeddedTypeEncode,ht as newPosition,Nt as parse,Ft as parseAll,K as peel,mt as position,Rt as preserves,Pt as stringify,zt as stringifyEmbeddedWrite,J as strip,le as typeCode,$ as unannotate,d as underlying,l as unhexDigit,lt as updatePosition,ie 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 y{static isCodecError(t,e){return(null==t?void 0:t[p])===e}}class m extends Error{get[p](){return"DecodeError"}constructor(t,e){super(t),this.pos=e}static isDecodeError(t){return y.isCodecError(t,"DecodeError")}}class b extends Error{get[p](){return"EncodeError"}static isEncodeError(t){return y.isCodecError(t,"EncodeError")}constructor(t,e){super(t),this.irritant=e}}class w extends m{get[p](){return"ShortPacket"}static isShortPacket(t){return y.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 _(t){return!!(null==t?void 0:t[v])}class x{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 A(t){return String.fromCharCode.apply(null,t)}let E=0;const j=new WeakMap;function B(t){let e=j.get(t);return void 0===e&&(e=E++,j.set(t,e)),e}const I={encode(t,e){new C(t,this).push(B(e))}};class D{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=A(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(A).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 C{constructor(t={},e){var n;t instanceof D?(this.state=t,this.embeddedEncode=null!=e?e:I):(this.state=new D(t),this.embeddedEncode=null!==(n=t.embeddedEncode)&&void 0!==n?n:I)}withEmbeddedEncode(t,e){return e(new C(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)?_(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 C(e).push(t).contents()}const M=new C({canonical:!0});let q=!1;function N(t,e){if(void 0!==e||q)return O(t,Object.assign(Object.assign({},e),{canonical:!0}));{q=!0;const e=M.push(t).contents();return q=!1,e}}function T(t){if(q)return new C({canonical:!0}).push(t).contentsString();{q=!0;const e=M.push(t).contentsString();return q=!1,e}}function U(t,e={}){return O(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const V=Map,F=Set,z=Symbol.for("IsMap"),P=Symbol.for("IsSet");function R(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}}}z in Map.prototype||(Object.defineProperty(Map.prototype,z,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[z])),P in Set.prototype||(Object.defineProperty(Set.prototype,P,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[P]));class H{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(R(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 R(this.items.values(),(([t,e])=>t))}values(){return R(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[z](){return!0}}class W{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(R(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 R(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 W(this.canonicalizer,this);for(let n of t)e.add(n);return e}intersect(t){const e=new W(this.canonicalizer);for(let n of this)t.has(n)&&e.add(n);return e}subtract(t){const e=new W(this.canonicalizer);for(let n of this)t.has(n)||e.add(n);return e}get[P](){return!0}}var L;function $(t){return ft.isAnnotated(t)?t.item:t}function K(t){return J(t,1)}function J(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 R(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 R(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}}(L||(L={}));const G=Symbol.for("DictionaryType");class X extends H{constructor(t,e,n){super((e=>T(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[G](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[G])}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[z](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):G 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?L.clear(this.j):this.k.clear()}delete(t){return this.j?"symbol"==typeof(t=$(t))&&L.remove(this.j,t):this.k.delete(t)}forEach(t,e){this.j?L.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 L.get(this.j,t)}return this.k.get(t)}has(t){return this.j?"symbol"==typeof(t=$(t))&&L.has(this.j,t):this.k.has(t)}set(t,e){if(this.j){if("symbol"==typeof t)return L.set(this.j,t,e),this;this.k=new Z(L.entries(this.j)),this.j=void 0}return this.k.set(t,e),this}get size(){return this.j?L.size(this.j):this.k.size}entries(){return this.j?L.entries(this.j):this.k.entries()}keys(){return this.j?L.keys(this.j):this.k.keys()}values(){return this.j?L.values(this.j):this.k.values()}[Symbol.iterator](){return this.entries()}get[Symbol.toStringTag](){return"DictionaryMap"}clone(){return new Q(this.j?L.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(L.entries(this.j))}}var Y;function tt(e,n,r,s){if(n.canonical){const i=Array.from(e),o=new C({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)&&yt(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[G]){case"Dictionary":return!0;case void 0:return L.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 W{constructor(t,e){super((e=>T(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[G](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[G])}constructor(t){super((t=>t),t)}map(t){return new rt(R(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[G])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function it(e,n,r){if(n.canonical){const s=new C({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 yt(t){return ft.isAnnotated(t)?t.annotations:[]}function mt(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 _t(t){return"number"==typeof t?t:vt.isFloat(t)?t.value:NaN}function xt(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)?xt(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[gt](){return"Double"}}function kt(t){return new St(t)}const At=BigInt(Number.MAX_SAFE_INTEGER),Et=BigInt(Number.MIN_SAFE_INTEGER),jt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class Bt{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 m(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(!(Ct(e)||t&&","===e))break;this.advance()}}readHex2(){return l(this.nextcharcode(),m)<<4|l(this.nextcharcode(),m)}readHex4(){return l(this.nextcharcode(),m)<<12|l(this.nextcharcode(),m)<<8|l(this.nextcharcode(),m)<<4|l(this.nextcharcode(),m)}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)||Ct(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<=Et||t>=At?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()))}}const It={decode(t){return new S(new Kt(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:J(t))};class Dt{constructor(t="",e){var n,r;if(t instanceof Bt)this.state=t,this.embeddedType=e;else{const s=null!==(n=e)&&void 0!==n?n:{};this.state=new Bt(t,s),this.embeddedType=null!==(r=s.embeddedDecode)&&void 0!==r?r:$t}}write(t){this.state.write(t)}readCommentLine(){const t=this.state.copyPos();let e="";for(;;){const n=this.state.nextchar();if("\n"===n||"\r"===n)return this.wrap(e,t);e+=n}}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 m("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 t=this.state.copyPos(),e=(()=>{const e=this.state.nextchar();switch(e){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",t);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",t);case"#":{const e=this.state.nextchar();switch(e){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",t)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new Dt(this.state,It).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${e}`,t)}}case"<":return g(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",t);case"]":this.state.error("Unexpected ]",t);case"}":this.state.error("Unexpected }",t);case",":this.state.error("Unexpected ,",t);default:return this.state.readRawSymbolOrNumber(e)}})();return this.wrap(e,t)}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: ${Rt(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: ${Rt(t)}`,this.state.pos),e.add(t)}),"}")}}function Ct(t){return-1!==" \t\n\r".indexOf(t)}function Ot(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const Mt={encode(t,e){new C(t,this).push(e.generic)},toValue:t=>t.generic},qt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class Nt{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 Tt{constructor(t={},e){var n;t instanceof Nt?(this.state=t,this.embeddedWrite=e):(this.state=new Nt(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:qt)}static stringify(t,e){const n=new Tt(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(Ot(t))t.__preserve_text_on__(this);else if(Ot(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)?_(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new Tt(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 Ut(t){return Vt(t)}function Vt(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(_(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 zt(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,Ut(n)))),e};const Pt={write(t,e){if(e instanceof S)new Tt(t,this).push(e.generic);else{try{const n=Ut(e);if(!_(n))return void new Tt(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Rt(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:Pt,Tt.stringify(Ut(t),e)}function Ht(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Rt(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 Rt(this)}}));class Lt{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 $t={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 Lt)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:$t;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new Lt(t,n),this.embeddedDecode=null!==(s=n.embeddedDecode)&&void 0!==s?s:$t}}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 m("Missing dictionary value");for(let n=0;n<t.length;n+=2){if(e.has(t[n]))throw new m(`Duplicate key: ${Rt(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 m("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 m("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 m("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 m(`Duplicate value: ${Rt(e)}`);t.add(e)}return this.state.wrap(t)}case t.Dictionary:return this.state.wrap(Kt.dictionaryFromArray(this.nextvalues()));default:throw new m("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 Gt(t,e={}){return Jt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))}const Xt=Object.assign({},It,Mt),Zt=Object.assign({},$t,qt),Qt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},Yt=Object.assign({},Qt,I);var te;!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"}(te||(te={}));class ee{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 ne extends ee{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class re{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 se extends re{embedded(t,e){return t}}class ie extends re{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}function oe(t){switch(typeof t){case"boolean":return te.Boolean;case"number":if(Number.isInteger(t))return te.SignedInteger;throw new Error("Non-integer number in Preserves valueClass; missing Float wrapper?");case"bigint":return te.SignedInteger;case"string":return te.String;case"symbol":return te.Symbol;case"object":return g.isRecord(t)?te.Record:Array.isArray(t)?te.Sequence:st.isSet(t)?te.Set:Y.isDictionary(t)?te.Dictionary:ft.isAnnotated(t)?te.Annotated:c.isBytes(t)?te.ByteString:vt.isDouble(t)?te.Double:te.Embedded;default:(t=>{throw new Error("Internal error")})()}}const ae=new se;function ue(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(_(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 ce(t,e){return ue(t,new ie(e))}function he(t,e){return ue(t,new ne(e))}function le(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)?ue(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){_(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 de(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(_(t))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}function fe(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=de(e),i=de(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)}Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const pe=Array,ye=Symbol;export{ft as Annotated,pe as Array,c as Bytes,e as Constants,m as DecodeError,Kt as Decoder,Lt as DecoderState,Y as Dictionary,Q as DictionaryMap,G as DictionaryType,kt as Double,St as DoubleFloat,x as Embedded,X as EncodableDictionary,nt as EncodableSet,b as EncodeError,C as Encoder,D as EncoderState,p as ErrorType,H as FlexMap,W as FlexSet,vt as Float,gt as FloatType,ne as ForEachEmbedded,S as GenericEmbedded,ae as IDENTITY_FOLD,se as IdentityFold,V as IdentityMap,F as IdentitySet,v as IsEmbedded,z as IsMap,at as IsPreservesAnnotated,u as IsPreservesBytes,P as IsSet,L as JsDictionary,Z as KeyedDictionary,rt as KeyedSet,ie as MapFold,jt as NUMBER_RE,y as PreservesCodecError,Dt as Reader,Bt as ReaderState,g as Record,st as Set,w as ShortPacket,ye as Symbol,te as ValueClass,re as ValueFold,ee as VoidFold,Tt as Writer,Nt as WriterState,R as _iterMap,pt as annotate,yt as annotations,Wt as asLiteral,N as canonicalEncode,T as canonicalString,fe as compare,f as dataview,Jt as decode,r as decodeBase64,Gt as decodeWithAnnotations,B as embeddedId,O as encode,i as encodeBase64,tt as encodeDictionaryOn,it as encodeSetOn,U as encodeWithAnnotations,_t as floatValue,xt as floatlikeString,ue as fold,he as forEachEmbedded,dt as formatPosition,Ut as fromJS,Vt as fromJS_options,Xt as genericEmbeddedType,It as genericEmbeddedTypeDecode,Mt as genericEmbeddedTypeEncode,h as hexDigit,Yt as identityEmbeddedType,Qt as identityEmbeddedTypeDecode,I as identityEmbeddedTypeEncode,ct as is,ut as isAnnotated,bt as isCompound,_ as isEmbedded,k as isPreservable,Ot as isPreserveWritable,wt as isSequence,ce as mapEmbeddeds,le as merge,Zt as neverEmbeddedType,$t as neverEmbeddedTypeDecode,qt as neverEmbeddedTypeEncode,ht as newPosition,Ft as parse,zt as parseAll,K as peel,mt as position,Ht as preserves,Rt as stringify,Pt as stringifyEmbeddedWrite,J as strip,de as typeCode,$ as unannotate,d as underlying,l as unhexDigit,lt as updatePosition,oe 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 i(t){const e=new Uint8Array(Math.floor(3*t.length/4));let n=0,i=0;for(;n<t.length;){const s=r[t[n++]],o=r[t[n++]],a=r[t[n++]],c=r[t[n++]],u=s<<18|o<<12|a<<6|c;if(e[i++]=u>>16&255,void 0===a)break;if(e[i++]=u>>8&255,void 0===c)break;e[i++]=255&u}return e.subarray(0,i)}[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"].forEach(((t,e)=>r[t]=e)),r["+"]=r["-"]=62,r["/"]=r._=63;const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(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 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(i(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 i=f(t[e]);n._view.set(i,r),r+=i.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)&&it(e.label,n.label)&&e.arity===n.length},t.makeConstructor=function(){return(e,n)=>{const r=(...n)=>t(e,n),i={label:e,arity:n.length};return r.constructorInfo=i,r.isClassOf=e=>t.isClassOf(i,e),r.fieldNumbers={},r._={},n.forEach(((t,e)=>{r._[t]=t=>t[e],r.fieldNumbers[t]=e})),r}}}(v||(v={}));const _=Symbol.for("IsEmbedded");function x(t){return!!(null==t?void 0:t[_])}class S{get[_](){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 j(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(j(e))}};class C{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 C?(this.state=t,this.embeddedEncode=null!=e?e:I):(this.state=new C(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)?x(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 F=Map,q=Set,P=Symbol.for("IsMap"),N=Symbol.for("IsSet");function U(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,i;return n(null!==(i=null===(r=t.return)||void 0===r?void 0:r.call(t,e))&&void 0!==i?i:{done:!0,value:null})},throw:e=>{var r,i;return n(null!==(i=null===(r=t.throw)||void 0===r?void 0:r.call(t,e))&&void 0!==i?i:{done:!0,value:null})},[Symbol.iterator](){return this}}}P in Map.prototype||(Object.defineProperty(Map.prototype,P,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[P])),N in Set.prototype||(Object.defineProperty(Set.prototype,N,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[N]));class R{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(U(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 U(this.items.values(),(([t,e])=>t))}values(){return U(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 i=this._key(t);if(this.items.has(i)){const n=this.items.get(i)[1],s=e(n);return void 0===s?(this.items.delete(i),-1):(r(s,n)||this.items.set(i,[t,s]),0)}{const r=e(n);return void 0===r?0:(this.items.set(i,[t,r]),1)}}canonicalKeys(){return this.items.keys()}get[P](){return!0}}class z{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(U(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 U(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[N](){return!0}}function J(t){return at.isAnnotated(t)?t.item:t}function W(e,n=1/0){return function e(n,r){if(0===r)return n;if(!at.isAnnotated(n))return n;const i=r-1;function s(t){return e(t,i)}if(v.isRecord(n.item))return v(e(n.item.label,r),n.item.map(s));if(at.isAnnotated(n.item))throw new Error("Improper annotation structure");if(0===i)return n.item;if(Array.isArray(n.item))return n.item.map(s);if(Q.isSet(n.item))return n.item.map(s);if(t.Dictionary.isDictionary(n.item)){const t=new K;return new K(n.item).forEach(((e,n)=>t.set(s(n),s(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 i(t){return U(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=i,t.keys=function(t){return U(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,s,o=((t,e)=>t===e)){if(r(t)!==r(s))return!1;for(let[r,a]of i(t)){if(!n(s,r))return!1;if(!o(a,e(s,r)))return!1}return!0}}(t.JsDictionary||(t.JsDictionary={}));const H=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[H](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[H])}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[P](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):H 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,i){if(n.canonical){const s=Array.from(t),o=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),a=s.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]=s[e];r(o,n),i(a,n)}))))}else n.grouped(e.Dictionary,(()=>t.forEach(((t,e)=>{r(e,n),i(t,n)}))))}function X(t,e,n,r){e.state.writeSeq("{","}",t.entries(),(([t,i])=>{n(t,e),at.isAnnotated(i)&&ut(i).length>1&&e.state.isIndenting?(e.state.pieces.push(":"),e.state.indentCount++,e.state.writeIndent(),r(i,e),e.state.indentCount--):(e.state.pieces.push(": "),r(i,e))}))}t.Dictionary=void 0,function(e){function n(e){if("object"!=typeof e||null===e)return!1;switch(e[H]){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[H](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[H])}constructor(t){super((t=>t),t)}map(t){return new Z(U(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[H])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function tt(t,n,r){if(n.canonical){const i=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),s=Array.from(t).map((t=>(r(t,i),[i.contents(),t])));s.sort(((t,e)=>h.compare(t[0],e[0]))),n.grouped(e.Set,(()=>s.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 it(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,it);if(Array.isArray(e)&&Array.isArray(n)){const t="label"in e;if(t!=="label"in n)return!1;if(t&&!it(e.label,n.label))return!1;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!it(e[t],n[t]))return!1;return!0}{const r=t.Dictionary.asMap(e),i=t.Dictionary.asMap(n);if(!r||!i)return!1;if(r.size!==i.size)return!1;for(const t of r.keys()){if(!i.has(t))return!1;if(!it(r.get(t),i.get(t)))return!1}return!0}}return!1}function st(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}}class at{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 it(this.item,at.isAnnotated(t)?t.item:t)}get[nt](){return!0}static isAnnotated(t){return rt(t)}}function ct(t,...e){const n=at.isAnnotated(t)?t:new at(t);return e.forEach((t=>n.annotations.push(t))),n}function ut(t){return at.isAnnotated(t)?t.annotations:[]}function ht(e){return Array.isArray(e)||Q.isSet(e)||t.Dictionary.isDictionary(e)}const dt=Symbol.for("FloatType");class lt{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 ft(t){if(Object.is(t,-0))return"-0.0";const e=""+t;return e.includes(".")||e.includes("e")||e.includes("E")?e:e+".0"}lt.isFloat=t=>void 0!==(null==t?void 0:t[dt]),lt.isDouble=t=>"Double"===(null==t?void 0:t[dt]);class pt extends lt{__as_preserve__(){return this}static fromBytes(t){return new pt(p(t).getFloat64(0,!1))}static __from_preserve__(t){return lt.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)?ft(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[dt](){return"Double"}}function yt(t){return new pt(t)}const mt=BigInt(Number.MAX_SAFE_INTEGER),bt=BigInt(Number.MIN_SAFE_INTEGER),gt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class wt{constructor(t,e){switch(this.discarded=0,this.buffer=t,typeof e.name){case"undefined":this.pos=st();break;case"string":this.pos=st(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(!(xt(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),pt.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)||xt(t)}readRawSymbolOrNumber(t){for(;!this.delimiterFollows();)t+=this.nextchar();const e=gt.exec(t);if(e){if(void 0===e[2]){let t=BigInt(e[1]);return t<=bt||t>=mt?t:Number(t)}return yt(parseFloat(t))}return Symbol.for(t)}readStringlike(t,e,n,r,i){let s=[];for(;;){const o=this.nextchar();switch(o){case n:return e(s);case"\\":{const e=this.nextchar();switch(e){case r:s.push(i());break;case n:case"\\":case"/":s.push(t(e));break;case"b":s.push(t("\b"));break;case"f":s.push(t("\f"));break;case"n":s.push(t("\n"));break;case"r":s.push(t("\r"));break;case"t":s.push(t("\t"));break;default:this.error(`Invalid escape code \\${e}`,this.pos)}break}default:s.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()))}}const vt={decode(t){return new S(new Vt(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:W(t))};class _t{constructor(t="",e){var n,r;if(t instanceof wt)this.state=t,this.embeddedType=e;else{const i=null!==(n=e)&&void 0!==n?n:{};this.state=new wt(t,i),this.embeddedType=null!==(r=i.embeddedDecode)&&void 0!==r?r:Ot}}write(t){this.state.write(t)}readCommentLine(){const t=this.state.copyPos();let e="";for(;;){const n=this.state.nextchar();if("\n"===n||"\r"===n)return this.wrap(e,t);e+=n}}wrap(t,e){return this.state.includeAnnotations&&!at.isAnnotated(t)&&(t=new at(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 t=this.state.copyPos(),e=(()=>{const e=this.state.nextchar();switch(e){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",t);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",t);case"#":{const e=this.state.nextchar();switch(e){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",t)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new _t(this.state,vt).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${e}`,t)}}case"<":return v(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",t);case"]":this.state.error("Unexpected ]",t);case"}":this.state.error("Unexpected }",t);case",":this.state.error("Unexpected ,",t);default:return this.state.readRawSymbolOrNumber(e)}})();return this.wrap(e,t)}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: ${Ct(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: ${Ct(t)}`,this.state.pos),e.add(t)}),"}")}}function xt(t){return-1!==" \t\n\r".indexOf(t)}function St(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const Et={encode(t,e){new B(t,this).push(e.generic)},toValue:t=>t.generic},kt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class At{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 i=n[Symbol.iterator]();this.pieces.push(t);const s=i.next();if(!0!==s.done){const t=s.value,e=i.next();if(!0===e.done)r(t);else{let n;for(this.indentCount++,this.writeIndent(),r(t),this.writeIndentSpace(),r(e.value);!0!==(n=i.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,i=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>=i?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 Dt{constructor(t={},e){var n;t instanceof At?(this.state=t,this.embeddedWrite=e):(this.state=new At(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:kt)}static stringify(t,e){const n=new Dt(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)&&!gt.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(St(t))t.__preserve_text_on__(this);else if(St(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)?x(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new Dt(this.state,Et).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){switch(typeof t){case"number":if(!Number.isInteger(t))throw new TypeError("Refusing to autoconvert non-integer number to Double");case"bigint":case"string":case"symbol":case"boolean":return t;case"undefined":case"function":break;case"object":if(null===t)break;if("function"==typeof t.__as_preserve__)return t.__as_preserve__();if(v.isRecord(t))return t;if(Array.isArray(t))return t.map(jt);if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer)return h.from(t);if(Map.isMap(t)){const e=new $;return t.forEach(((t,n)=>e.set(jt(n),jt(t)))),e}if(Q.isSet(t)){const e=new Q;return t.forEach((t=>e.add(jt(t)))),e}if(x(t))return t;{const e={};return Object.entries(t).forEach((([t,n])=>e[t]=jt(n))),e}}throw new TypeError("Cannot represent JavaScript value as Preserves: "+t)}t.Dictionary.stringMap=function(t){const e=new $;return Object.entries(t).forEach((([t,n])=>e.set(t,jt(n)))),e};const It={write(t,e){if(e instanceof S)new Dt(t,this).push(e.generic);else{try{const n=jt(e);if(!x(n))return void new Dt(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Ct(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:It,Dt.stringify(jt(t),e)}[at,h,$,Z].forEach((t=>{t.prototype.toString=function(){return Ct(this)}}));class Bt{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 at(t):t}unshiftAnnotation(t,e){return this.includeAnnotations&&e.annotations.unshift(t),e}}const Ot={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 Vt{constructor(t=new Uint8Array(0),e){var n,r,i;if(t instanceof Bt)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:Ot;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new Bt(t,n),this.embeddedDecode=null!==(i=n.embeddedDecode)&&void 0!==i?i:Ot}}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: ${Ct(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(pt.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: ${Ct(e)}`);t.add(e)}return this.state.wrap(t)}case e.Dictionary:return this.state.wrap(Vt.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 Vt(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():pt.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 Mt(t,e={}){return new Vt(t,e).next()}const Tt=Object.assign({},vt,Et),Ft=Object.assign({},Ot,kt),qt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},Pt=Object.assign({},qt,I);var Nt;t.ValueClass=void 0,(Nt=t.ValueClass||(t.ValueClass={}))[Nt.Boolean=0]="Boolean",Nt[Nt.Double=1]="Double",Nt[Nt.SignedInteger=2]="SignedInteger",Nt[Nt.String=3]="String",Nt[Nt.ByteString=4]="ByteString",Nt[Nt.Symbol=5]="Symbol",Nt[Nt.Record=6]="Record",Nt[Nt.Sequence=7]="Sequence",Nt[Nt.Set=8]="Set",Nt[Nt.Dictionary=9]="Dictionary",Nt[Nt.Embedded=10]="Embedded",Nt[Nt.Annotated=11]="Annotated";class Ut{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 Rt extends Ut{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class zt{boolean(t){return t}double(t){return yt(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 ct(e(t.item),...t.annotations.map(e))}}class Jt extends zt{embedded(t,e){return t}}class Wt extends zt{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}const Ht=new Jt;function Lt(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(x(e))return n.embedded(e,r);if(at.isAnnotated(e))return n.annotated(e,r);if(h.isBytes(e))return n.bytes(e);if(lt.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 $t(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(lt.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(x(e))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const Kt=Array,Gt=Symbol;t.Annotated=at,t.Array=Kt,t.Bytes=h,t.Constants=n,t.DecodeError=b,t.Decoder=Vt,t.DecoderState=Bt,t.DictionaryMap=K,t.DictionaryType=H,t.Double=yt,t.DoubleFloat=pt,t.Embedded=class{get[_](){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=C,t.ErrorType=y,t.FlexMap=R,t.FlexSet=z,t.Float=lt,t.FloatType=dt,t.ForEachEmbedded=Rt,t.GenericEmbedded=S,t.IDENTITY_FOLD=Ht,t.IdentityFold=Jt,t.IdentityMap=F,t.IdentitySet=q,t.IsEmbedded=_,t.IsMap=P,t.IsPreservesAnnotated=nt,t.IsPreservesBytes=u,t.IsSet=N,t.KeyedDictionary=$,t.KeyedSet=Z,t.MapFold=Wt,t.NUMBER_RE=gt,t.PreservesCodecError=m,t.Reader=_t,t.ReaderState=wt,t.Record=v,t.Set=Q,t.ShortPacket=w,t.Symbol=Gt,t.ValueFold=zt,t.VoidFold=Ut,t.Writer=Dt,t.WriterState=At,t._iterMap=U,t.annotate=ct,t.annotations=ut,t.asLiteral=function(t,e){return it(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)=>it(t,e)?0:t<e?-1:1)){return function e(n,i){rt(n)&&(n=n.item),rt(i)&&(i=i.item);const s=$t(n),o=$t(i);if(s<o)return-1;if(s>o)return 1;switch(s){case 0:case 3:case 4:return n<i?-1:n>i?1:0;case 2:{const t=n.value,e=i.value;return t<e?-1:t>e?1:0}case 5:return h.compare(n,i);case 6:{const t=n.description,e=i.description;return t<e?-1:t>e?1:0}case 7:{const t=e(n.label,i.label);if(0!==t)return t}case 8:{const t=n,r=i,s=Math.min(t.length,r.length);for(let n=0;n<s;n++){const i=e(t[n],r[n]);if(0!==i)return i}return t.length<r.length?-1:t.length>r.length?1:0}case 9:return e(Array.from(n).sort(e),Array.from(i).sort(e));case 10:return e(Array.from(t.Dictionary.asMap(n).entries()).sort(e),Array.from(t.Dictionary.asMap(i).entries()).sort(e));case 11:return r(n,i);default:throw new Error("Invalid typeCode: "+s)}}(e,n)},t.dataview=p,t.decode=Mt,t.decodeBase64=i,t.decodeWithAnnotations=function(t,e={}){return Mt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))},t.embeddedId=j,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:lt.isFloat(t)?t.value:NaN},t.floatlikeString=ft,t.fold=Lt,t.forEachEmbedded=function(t,e){return Lt(t,new Rt(e))},t.formatPosition=function(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}`},t.fromJS=jt,t.genericEmbeddedType=Tt,t.genericEmbeddedTypeDecode=vt,t.genericEmbeddedTypeEncode=Et,t.hexDigit=d,t.identityEmbeddedType=Pt,t.identityEmbeddedTypeDecode=qt,t.identityEmbeddedTypeEncode=I,t.is=it,t.isAnnotated=rt,t.isCompound=ht,t.isEmbedded=x,t.isPreservable=E,t.isPreserveWritable=St,t.isSequence=function(t){return Array.isArray(t)&&!("label"in t)},t.mapEmbeddeds=function(t,e){return Lt(t,new Wt(e))},t.merge=function(e,n,...r){function i(){throw new Error("Cannot merge items")}function s(n,r){return n===r?n:ht(n)||ht(r)||!it(n,r)?Lt(n,{boolean:i,double:t=>it(n,r)?n:i(),integer:i,string:i,bytes:t=>it(n,r)?n:i(),symbol:i,record:t=>(v.isRecord(r)||i(),v(s(t.label,r.label),o(t,r))),array:t=>(Array.isArray(r)&&!v.isRecord(r)||i(),o(t,r)),set(t){i()},dictionary(e){const n=t.Dictionary.asMap(r);void 0===n&&i();const o=new K;return e.forEach(((t,e)=>{const r=n.get(e);o.set(e,void 0===r?t:s(t,r))})),n.forEach(((t,n)=>{e.has(n)||o.set(n,t)})),o.simplifiedValue()},annotated:t=>s(t,J(r)),embedded(t){x(r)||i();const n=e(t,r);return void 0===n&&i(),n}}):n}function o(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 r.reduce(s,n)},t.neverEmbeddedType=Ft,t.neverEmbeddedTypeDecode=Ot,t.neverEmbeddedTypeEncode=kt,t.newPosition=st,t.parse=function(t,e){return new _t(t,e).next()},t.parseAll=function(t,e){return new _t(t,e).readToEnd()},t.peel=function(t){return W(t,1)},t.position=function(t){return at.isAnnotated(t)?t.pos:null},t.preserves=function(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Ct(e)),n.push(t[r+1])})),n.join("")},t.stringify=Ct,t.stringifyEmbeddedWrite=It,t.strip=W,t.typeCode=$t,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:at.isAnnotated(e)?t.ValueClass.Annotated:h.isBytes(e)?t.ValueClass.ByteString:lt.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 i(t){const e=new Uint8Array(Math.floor(3*t.length/4));let n=0,i=0;for(;n<t.length;){const s=r[t[n++]],o=r[t[n++]],a=r[t[n++]],c=r[t[n++]],u=s<<18|o<<12|a<<6|c;if(e[i++]=u>>16&255,void 0===a)break;if(e[i++]=u>>8&255,void 0===c)break;e[i++]=255&u}return e.subarray(0,i)}[..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"].forEach(((t,e)=>r[t]=e)),r["+"]=r["-"]=62,r["/"]=r._=63;const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function o(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 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(i(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 i=f(t[e]);n._view.set(i,r),r+=i.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)&&it(e.label,n.label)&&e.arity===n.length},t.makeConstructor=function(){return(e,n)=>{const r=(...n)=>t(e,n),i={label:e,arity:n.length};return r.constructorInfo=i,r.isClassOf=e=>t.isClassOf(i,e),r.fieldNumbers={},r._={},n.forEach(((t,e)=>{r._[t]=t=>t[e],r.fieldNumbers[t]=e})),r}}}(v||(v={}));const _=Symbol.for("IsEmbedded");function x(t){return!!(null==t?void 0:t[_])}class S{get[_](){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 j(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(j(e))}};class C{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 C?(this.state=t,this.embeddedEncode=null!=e?e:I):(this.state=new C(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)?x(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 F=Map,q=Set,P=Symbol.for("IsMap"),N=Symbol.for("IsSet");function U(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,i;return n(null!==(i=null===(r=t.return)||void 0===r?void 0:r.call(t,e))&&void 0!==i?i:{done:!0,value:null})},throw:e=>{var r,i;return n(null!==(i=null===(r=t.throw)||void 0===r?void 0:r.call(t,e))&&void 0!==i?i:{done:!0,value:null})},[Symbol.iterator](){return this}}}P in Map.prototype||(Object.defineProperty(Map.prototype,P,{get:()=>!0}),Map.isMap=t=>!!(null==t?void 0:t[P])),N in Set.prototype||(Object.defineProperty(Set.prototype,N,{get:()=>!0}),Set.isSet=t=>!!(null==t?void 0:t[N]));class R{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(U(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 U(this.items.values(),(([t,e])=>t))}values(){return U(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 i=this._key(t);if(this.items.has(i)){const n=this.items.get(i)[1],s=e(n);return void 0===s?(this.items.delete(i),-1):(r(s,n)||this.items.set(i,[t,s]),0)}{const r=e(n);return void 0===r?0:(this.items.set(i,[t,r]),1)}}canonicalKeys(){return this.items.keys()}get[P](){return!0}}class z{constructor(t,e){this.canonicalizer=t,this.items=void 0===e?new Map:new Map(U(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 U(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[N](){return!0}}function J(t){return at.isAnnotated(t)?t.item:t}function W(e,n=1/0){return function e(n,r){if(0===r)return n;if(!at.isAnnotated(n))return n;const i=r-1;function s(t){return e(t,i)}if(v.isRecord(n.item))return v(e(n.item.label,r),n.item.map(s));if(at.isAnnotated(n.item))throw new Error("Improper annotation structure");if(0===i)return n.item;if(Array.isArray(n.item))return n.item.map(s);if(Q.isSet(n.item))return n.item.map(s);if(t.Dictionary.isDictionary(n.item)){const t=new K;return new K(n.item).forEach(((e,n)=>t.set(s(n),s(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 i(t){return U(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=i,t.keys=function(t){return U(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,s,o=((t,e)=>t===e)){if(r(t)!==r(s))return!1;for(let[r,a]of i(t)){if(!n(s,r))return!1;if(!o(a,e(s,r)))return!1}return!0}}(t.JsDictionary||(t.JsDictionary={}));const H=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[H](){return"Dictionary"}static isKeyedDictionary(t){return"Dictionary"===(null==t?void 0:t[H])}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[P](){return!0}constructor(t){void 0===t?(this.j={},this.k=void 0):H 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,i){if(n.canonical){const s=Array.from(t),o=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),a=s.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]=s[e];r(o,n),i(a,n)}))))}else n.grouped(e.Dictionary,(()=>t.forEach(((t,e)=>{r(e,n),i(t,n)}))))}function X(t,e,n,r){e.state.writeSeq("{","}",t.entries(),(([t,i])=>{n(t,e),at.isAnnotated(i)&&ut(i).length>1&&e.state.isIndenting?(e.state.pieces.push(":"),e.state.indentCount++,e.state.writeIndent(),r(i,e),e.state.indentCount--):(e.state.pieces.push(": "),r(i,e))}))}t.Dictionary=void 0,function(e){function n(e){if("object"!=typeof e||null===e)return!1;switch(e[H]){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[H](){return"Set"}static isKeyedSet(t){return"Set"===(null==t?void 0:t[H])}constructor(t){super((t=>t),t)}map(t){return new Z(U(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[H])}static __from_preserve__(e){return t.isSet(e)?e:void 0}};function tt(t,n,r){if(n.canonical){const i=new B({canonical:!0,embeddedEncode:n.embeddedEncode}),s=Array.from(t).map((t=>(r(t,i),[i.contents(),t])));s.sort(((t,e)=>h.compare(t[0],e[0]))),n.grouped(e.Set,(()=>s.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 it(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,it);if(Array.isArray(e)&&Array.isArray(n)){const t="label"in e;if(t!=="label"in n)return!1;if(t&&!it(e.label,n.label))return!1;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!it(e[t],n[t]))return!1;return!0}{const r=t.Dictionary.asMap(e),i=t.Dictionary.asMap(n);if(!r||!i)return!1;if(r.size!==i.size)return!1;for(const t of r.keys()){if(!i.has(t))return!1;if(!it(r.get(t),i.get(t)))return!1}return!0}}return!1}function st(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}}class at{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 it(this.item,at.isAnnotated(t)?t.item:t)}get[nt](){return!0}static isAnnotated(t){return rt(t)}}function ct(t,...e){const n=at.isAnnotated(t)?t:new at(t);return e.forEach((t=>n.annotations.push(t))),n}function ut(t){return at.isAnnotated(t)?t.annotations:[]}function ht(e){return Array.isArray(e)||Q.isSet(e)||t.Dictionary.isDictionary(e)}const dt=Symbol.for("FloatType");class lt{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 ft(t){if(Object.is(t,-0))return"-0.0";const e=""+t;return e.includes(".")||e.includes("e")||e.includes("E")?e:e+".0"}lt.isFloat=t=>void 0!==(null==t?void 0:t[dt]),lt.isDouble=t=>"Double"===(null==t?void 0:t[dt]);class pt extends lt{__as_preserve__(){return this}static fromBytes(t){return new pt(p(t).getFloat64(0,!1))}static __from_preserve__(t){return lt.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)?ft(this.value):'#xd"'+this.toBytes().toHex()+'"'}get[dt](){return"Double"}}function yt(t){return new pt(t)}const mt=BigInt(Number.MAX_SAFE_INTEGER),bt=BigInt(Number.MIN_SAFE_INTEGER),gt=/^([-+]?\d+)((\.\d+([eE][-+]?\d+)?)|([eE][-+]?\d+))?$/;class wt{constructor(t,e){switch(this.discarded=0,this.buffer=t,typeof e.name){case"undefined":this.pos=st();break;case"string":this.pos=st(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(!(xt(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),pt.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)||xt(t)}readRawSymbolOrNumber(t){for(;!this.delimiterFollows();)t+=this.nextchar();const e=gt.exec(t);if(e){if(void 0===e[2]){let t=BigInt(e[1]);return t<=bt||t>=mt?t:Number(t)}return yt(parseFloat(t))}return Symbol.for(t)}readStringlike(t,e,n,r,i){let s=[];for(;;){const o=this.nextchar();switch(o){case n:return e(s);case"\\":{const e=this.nextchar();switch(e){case r:s.push(i());break;case n:case"\\":case"/":s.push(t(e));break;case"b":s.push(t("\b"));break;case"f":s.push(t("\f"));break;case"n":s.push(t("\n"));break;case"r":s.push(t("\r"));break;case"t":s.push(t("\t"));break;default:this.error(`Invalid escape code \\${e}`,this.pos)}break}default:s.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()))}}const vt={decode(t){return new S(new Mt(t,this).next())},fromValue:(t,e)=>new S(e.includeAnnotations?t:W(t))};class _t{constructor(t="",e){var n,r;if(t instanceof wt)this.state=t,this.embeddedType=e;else{const i=null!==(n=e)&&void 0!==n?n:{};this.state=new wt(t,i),this.embeddedType=null!==(r=i.embeddedDecode)&&void 0!==r?r:Vt}}write(t){this.state.write(t)}readCommentLine(){const t=this.state.copyPos();let e="";for(;;){const n=this.state.nextchar();if("\n"===n||"\r"===n)return this.wrap(e,t);e+=n}}wrap(t,e){return this.state.includeAnnotations&&!at.isAnnotated(t)&&(t=new at(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 t=this.state.copyPos(),e=(()=>{const e=this.state.nextchar();switch(e){case'"':return this.state.readString('"');case"|":return Symbol.for(this.state.readString("|"));case";":this.state.error("Semicolon is reserved syntax",t);case"@":return this.annotateNextWith(this.next());case":":this.state.error("Unexpected key/value separator between items",t);case"#":{const e=this.state.nextchar();switch(e){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",t)}case"[":return this.state.readBase64Binary();case":":return this.embeddedType.fromValue(new _t(this.state,vt).next(),this.state.options);default:this.state.error(`Invalid # syntax: ${e}`,t)}}case"<":return v(this.next(),this.readSequence(">",!1));case"[":return this.readSequence("]",!0);case"{":return this.readDictionary();case">":this.state.error("Unexpected >",t);case"]":this.state.error("Unexpected ]",t);case"}":this.state.error("Unexpected }",t);case",":this.state.error("Unexpected ,",t);default:return this.state.readRawSymbolOrNumber(e)}})();return this.wrap(e,t)}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: ${Bt(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: ${Bt(t)}`,this.state.pos),e.add(t)}),"}")}}function xt(t){return-1!==" \t\n\r".indexOf(t)}function St(t){return"object"==typeof t&&null!==t&&"__preserve_text_on__"in t&&"function"==typeof t.__preserve_text_on__}const Et={encode(t,e){new B(t,this).push(e.generic)},toValue:t=>t.generic},kt={encode(t,e){throw new Error("Embeddeds not permitted encoding Preserves document")},toValue(t){throw new Error("Embeddeds not permitted writing Preserves document")}};class At{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 i=n[Symbol.iterator]();this.pieces.push(t);const s=i.next();if(!0!==s.done){const t=s.value,e=i.next();if(!0===e.done)r(t);else{let n;for(this.indentCount++,this.writeIndent(),r(t),this.writeIndentSpace(),r(e.value);!0!==(n=i.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,i=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>=i?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 Dt{constructor(t={},e){var n;t instanceof At?(this.state=t,this.embeddedWrite=e):(this.state=new At(t),this.embeddedWrite=null!==(n=t.embeddedWrite)&&void 0!==n?n:kt)}static stringify(t,e){const n=new Dt(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)&&!gt.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(St(t))t.__preserve_text_on__(this);else if(St(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)?x(t)?(this.state.pieces.push("#:"),"write"in this.embeddedWrite?this.embeddedWrite.write(this.state,t):new Dt(this.state,Et).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 It(t)}function It(t,e){return function t(n){var r,i;switch(typeof n){case"number":if(!Number.isInteger(n)){const t=null!==(i=null===(r=null==e?void 0:e.onNonInteger)||void 0===r?void 0:r.call(e,n))&&void 0!==i?i: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(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)}t.Dictionary.stringMap=function(t){const e=new $;return Object.entries(t).forEach((([t,n])=>e.set(t,jt(n)))),e};const Ct={write(t,e){if(e instanceof S)new Dt(t,this).push(e.generic);else{try{const n=jt(e);if(!x(n))return void new Dt(t,this).push(n)}catch(t){}try{return void t.pieces.push(JSON.stringify(e))}catch(t){}t.pieces.push("⌜"+e+"⌝")}}};function Bt(t,e){var n;return(e=Object.assign({},null!=e?e:{})).embeddedWrite=null!==(n=e.embeddedWrite)&&void 0!==n?n:Ct,Dt.stringify(jt(t),e)}[at,h,$,Z].forEach((t=>{t.prototype.toString=function(){return Bt(this)}}));class Ot{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 at(t):t}unshiftAnnotation(t,e){return this.includeAnnotations&&e.annotations.unshift(t),e}}const Vt={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 Mt{constructor(t=new Uint8Array(0),e){var n,r,i;if(t instanceof Ot)this.state=t,this.embeddedDecode=null!==(n=e)&&void 0!==n?n:Vt;else{const n=null!==(r=e)&&void 0!==r?r:{};this.state=new Ot(t,n),this.embeddedDecode=null!==(i=n.embeddedDecode)&&void 0!==i?i:Vt}}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: ${Bt(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(pt.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: ${Bt(e)}`);t.add(e)}return this.state.wrap(t)}case e.Dictionary:return this.state.wrap(Mt.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 Mt(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():pt.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 Tt(t,e={}){return new Mt(t,e).next()}const Ft=Object.assign({},vt,Et),qt=Object.assign({},Vt,kt),Pt={decode(t){throw new Error("Cannot decode identityEmbeddedType")},fromValue(t,e){throw new Error("Cannot decode identityEmbeddedType")}},Nt=Object.assign({},Pt,I);var Ut;t.ValueClass=void 0,(Ut=t.ValueClass||(t.ValueClass={}))[Ut.Boolean=0]="Boolean",Ut[Ut.Double=1]="Double",Ut[Ut.SignedInteger=2]="SignedInteger",Ut[Ut.String=3]="String",Ut[Ut.ByteString=4]="ByteString",Ut[Ut.Symbol=5]="Symbol",Ut[Ut.Record=6]="Record",Ut[Ut.Sequence=7]="Sequence",Ut[Ut.Set=8]="Set",Ut[Ut.Dictionary=9]="Dictionary",Ut[Ut.Embedded=10]="Embedded",Ut[Ut.Annotated=11]="Annotated";class Rt{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 zt extends Rt{constructor(t){super(),this.f=t}embedded(t,e){this.f(t,e)}}class Jt{boolean(t){return t}double(t){return yt(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 ct(e(t.item),...t.annotations.map(e))}}class Wt extends Jt{embedded(t,e){return t}}class Ht extends Jt{constructor(t){super(),this.f=t}embedded(t,e){return this.f(t)}}const Lt=new Wt;function $t(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(x(e))return n.embedded(e,r);if(at.isAnnotated(e))return n.annotated(e,r);if(h.isBytes(e))return n.bytes(e);if(lt.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 Kt(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(lt.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(x(e))return 11;default:throw new Error("Invalid Value<T> in typeCode")}}Array.__from_preserve__=t=>Array.isArray(t)?t:void 0;const Gt=Array,Xt=Symbol;t.Annotated=at,t.Array=Gt,t.Bytes=h,t.Constants=n,t.DecodeError=b,t.Decoder=Mt,t.DecoderState=Ot,t.DictionaryMap=K,t.DictionaryType=H,t.Double=yt,t.DoubleFloat=pt,t.Embedded=class{get[_](){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=C,t.ErrorType=y,t.FlexMap=R,t.FlexSet=z,t.Float=lt,t.FloatType=dt,t.ForEachEmbedded=zt,t.GenericEmbedded=S,t.IDENTITY_FOLD=Lt,t.IdentityFold=Wt,t.IdentityMap=F,t.IdentitySet=q,t.IsEmbedded=_,t.IsMap=P,t.IsPreservesAnnotated=nt,t.IsPreservesBytes=u,t.IsSet=N,t.KeyedDictionary=$,t.KeyedSet=Z,t.MapFold=Ht,t.NUMBER_RE=gt,t.PreservesCodecError=m,t.Reader=_t,t.ReaderState=wt,t.Record=v,t.Set=Q,t.ShortPacket=w,t.Symbol=Xt,t.ValueFold=Jt,t.VoidFold=Rt,t.Writer=Dt,t.WriterState=At,t._iterMap=U,t.annotate=ct,t.annotations=ut,t.asLiteral=function(t,e){return it(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)=>it(t,e)?0:t<e?-1:1)){return function e(n,i){rt(n)&&(n=n.item),rt(i)&&(i=i.item);const s=Kt(n),o=Kt(i);if(s<o)return-1;if(s>o)return 1;switch(s){case 0:case 3:case 4:return n<i?-1:n>i?1:0;case 2:{const t=n.value,e=i.value;return t<e?-1:t>e?1:0}case 5:return h.compare(n,i);case 6:{const t=n.description,e=i.description;return t<e?-1:t>e?1:0}case 7:{const t=e(n.label,i.label);if(0!==t)return t}case 8:{const t=n,r=i,s=Math.min(t.length,r.length);for(let n=0;n<s;n++){const i=e(t[n],r[n]);if(0!==i)return i}return t.length<r.length?-1:t.length>r.length?1:0}case 9:return e(Array.from(n).sort(e),Array.from(i).sort(e));case 10:return e(Array.from(t.Dictionary.asMap(n).entries()).sort(e),Array.from(t.Dictionary.asMap(i).entries()).sort(e));case 11:return r(n,i);default:throw new Error("Invalid typeCode: "+s)}}(e,n)},t.dataview=p,t.decode=Tt,t.decodeBase64=i,t.decodeWithAnnotations=function(t,e={}){return Tt(t,Object.assign(Object.assign({},e),{includeAnnotations:!0}))},t.embeddedId=j,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:lt.isFloat(t)?t.value:NaN},t.floatlikeString=ft,t.fold=$t,t.forEachEmbedded=function(t,e){return $t(t,new zt(e))},t.formatPosition=function(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}`},t.fromJS=jt,t.fromJS_options=It,t.genericEmbeddedType=Ft,t.genericEmbeddedTypeDecode=vt,t.genericEmbeddedTypeEncode=Et,t.hexDigit=d,t.identityEmbeddedType=Nt,t.identityEmbeddedTypeDecode=Pt,t.identityEmbeddedTypeEncode=I,t.is=it,t.isAnnotated=rt,t.isCompound=ht,t.isEmbedded=x,t.isPreservable=E,t.isPreserveWritable=St,t.isSequence=function(t){return Array.isArray(t)&&!("label"in t)},t.mapEmbeddeds=function(t,e){return $t(t,new Ht(e))},t.merge=function(e,n,...r){function i(){throw new Error("Cannot merge items")}function s(n,r){return n===r?n:ht(n)||ht(r)||!it(n,r)?$t(n,{boolean:i,double:t=>it(n,r)?n:i(),integer:i,string:i,bytes:t=>it(n,r)?n:i(),symbol:i,record:t=>(v.isRecord(r)||i(),v(s(t.label,r.label),o(t,r))),array:t=>(Array.isArray(r)&&!v.isRecord(r)||i(),o(t,r)),set(t){i()},dictionary(e){const n=t.Dictionary.asMap(r);void 0===n&&i();const o=new K;return e.forEach(((t,e)=>{const r=n.get(e);o.set(e,void 0===r?t:s(t,r))})),n.forEach(((t,n)=>{e.has(n)||o.set(n,t)})),o.simplifiedValue()},annotated:t=>s(t,J(r)),embedded(t){x(r)||i();const n=e(t,r);return void 0===n&&i(),n}}):n}function o(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 r.reduce(s,n)},t.neverEmbeddedType=qt,t.neverEmbeddedTypeDecode=Vt,t.neverEmbeddedTypeEncode=kt,t.newPosition=st,t.parse=function(t,e){return new _t(t,e).next()},t.parseAll=function(t,e){return new _t(t,e).readToEnd()},t.peel=function(t){return W(t,1)},t.position=function(t){return at.isAnnotated(t)?t.pos:null},t.preserves=function(t,...e){const n=[t[0]];return e.forEach(((e,r)=>{n.push(Bt(e)),n.push(t[r+1])})),n.join("")},t.stringify=Bt,t.stringifyEmbeddedWrite=Ct,t.strip=W,t.typeCode=Kt,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:at.isAnnotated(e)?t.ValueClass.Annotated:h.isBytes(e)?t.ValueClass.ByteString:lt.isDouble(e)?t.ValueClass.Double:t.ValueClass.Embedded;default:(t=>{throw new Error("Internal error")})()}},t.writeDictionaryOn=X,t.writeSetOn=et}));

@@ -32,3 +32,3 @@ import { Encoder } from "./encoder";

constructor(input?: Dictionary<T, V>);
static from<T extends Embeddable = GenericEmbedded, V = Value<T>>(entries: Iterable<[Value<T>, V]>): DictionaryMap<T, V>;
static from<T extends Embeddable = GenericEmbedded, V = Value<T>>(entries: [Value<T>, V][] | Iterable<[Value<T>, V]>): DictionaryMap<T, V>;
clear(): void;

@@ -57,3 +57,3 @@ delete(key: Value<T>): boolean;

function asMap<T extends Embeddable = GenericEmbedded, V = Value<T>>(x: any): DictionaryMap<T, V> | undefined;
function from<T extends Embeddable = GenericEmbedded, V = Value<T>>(entries: Iterable<[Value<T>, V]>): Dictionary<T, V>;
function from<T extends Embeddable = GenericEmbedded, V = Value<T>>(entries: [Value<T>, V][] | Iterable<[Value<T>, V]>): Dictionary<T, V>;
function __from_preserve__<T extends Embeddable>(v: Value<T>): undefined | Dictionary<T>;

@@ -60,0 +60,0 @@ }

import { Embeddable, GenericEmbedded } from "./embedded";
import { Value } from "./values";
export interface FromJSOptions<T extends Embeddable = GenericEmbedded> {
onNonInteger?(n: number): Value<T> | undefined;
}
export declare function fromJS<T extends Embeddable = GenericEmbedded>(x: any): Value<T>;
export declare function fromJS_options<T extends Embeddable = GenericEmbedded>(x: any, options?: FromJSOptions<T>): Value<T>;
declare module "./dictionary" {

@@ -5,0 +9,0 @@ namespace Dictionary {

@@ -6,56 +6,66 @@ import { isEmbedded } from "./embedded";

export function fromJS(x) {
switch (typeof x) {
case 'number':
if (!Number.isInteger(x)) {
// We require that clients be explicit about integer vs. non-integer types.
throw new TypeError("Refusing to autoconvert non-integer number to Double");
}
// FALL THROUGH
case 'bigint':
case 'string':
case 'symbol':
case 'boolean':
return x;
case 'undefined':
case 'function':
break;
case 'object':
if (x === null) {
return fromJS_options(x);
}
export function fromJS_options(x, options) {
function walk(x) {
var _a, _b;
switch (typeof x) {
case 'number':
if (!Number.isInteger(x)) {
// We require that clients be explicit about integer vs. non-integer types.
const converted = (_b = (_a = options === null || options === void 0 ? void 0 : options.onNonInteger) === null || _a === void 0 ? void 0 : _a.call(options, x)) !== null && _b !== void 0 ? _b : void 0;
if (converted !== void 0)
return converted;
throw new TypeError("Refusing to autoconvert non-integer number to Double");
}
// FALL THROUGH
case 'bigint':
case 'string':
case 'symbol':
case 'boolean':
return x;
case 'undefined':
case 'function':
break;
}
if (typeof x.__as_preserve__ === 'function') {
return x.__as_preserve__();
}
if (Record.isRecord(x)) {
return x;
}
if (Array.isArray(x)) {
return x.map(fromJS);
}
if (ArrayBuffer.isView(x) || x instanceof ArrayBuffer) {
return Bytes.from(x);
}
if (Map.isMap(x)) {
const d = new KeyedDictionary();
x.forEach((v, k) => d.set(fromJS(k), fromJS(v)));
return d;
}
if (Set.isSet(x)) {
const s = new Set();
x.forEach(v => s.add(fromJS(v)));
return s;
}
if (isEmbedded(x)) {
return x;
}
// Handle plain JS objects to build a JsDictionary
{
const r = {};
Object.entries(x).forEach(([k, v]) => r[k] = fromJS(v));
return r;
}
default:
break;
case 'object':
if (x === null) {
break;
}
if (typeof x.__as_preserve__ === 'function') {
return x.__as_preserve__();
}
if (Record.isRecord(x)) {
return x;
}
if (Array.isArray(x)) {
return x.map(walk);
}
if (ArrayBuffer.isView(x) || x instanceof ArrayBuffer) {
return Bytes.from(x);
}
if (Map.isMap(x)) {
const d = new KeyedDictionary();
x.forEach((v, k) => d.set(walk(k), walk(v)));
return d;
}
if (Set.isSet(x)) {
const s = new Set();
x.forEach(v => s.add(walk(v)));
return s;
}
if (isEmbedded(x)) {
return x;
}
// Handle plain JS objects to build a JsDictionary
{
const r = {};
Object.entries(x).forEach(([k, v]) => r[k] = walk(v));
return r;
}
default:
break;
}
throw new TypeError("Cannot represent JavaScript value as Preserves: " + x);
}
throw new TypeError("Cannot represent JavaScript value as Preserves: " + x);
return walk(x);
}

@@ -62,0 +72,0 @@ Dictionary.stringMap = function (x) {

{
"name": "@preserves/core",
"version": "0.995.200",
"version": "0.995.201",
"description": "Preserves data serialization format",

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

},
"gitHead": "3e67c754275431964a06b72176573e7741f385eb"
"gitHead": "7b8e0ff4b603841d9be9c15bff7ceb38aab70b9c"
}

@@ -100,3 +100,3 @@ import { Encoder, canonicalString } from "./encoder";

static from<T extends Embeddable = GenericEmbedded, V = Value<T>>(
entries: Iterable<[Value<T>, V]>,
entries: [Value<T>, V][] | Iterable<[Value<T>, V]>,
): DictionaryMap<T, V> {

@@ -252,3 +252,3 @@ const r = new DictionaryMap<T, V>();

export function from<T extends Embeddable = GenericEmbedded, V = Value<T>>(
entries: Iterable<[Value<T>, V]>,
entries: [Value<T>, V][] | Iterable<[Value<T>, V]>,
): Dictionary<T, V> {

@@ -255,0 +255,0 @@ return DictionaryMap.from(entries).simplifiedValue();

@@ -8,61 +8,75 @@ import { Embeddable, GenericEmbedded, isEmbedded } from "./embedded";

export interface FromJSOptions<T extends Embeddable = GenericEmbedded> {
onNonInteger?(n: number): Value<T> | undefined;
}
export function fromJS<T extends Embeddable = GenericEmbedded>(x: any): Value<T> {
switch (typeof x) {
case 'number':
if (!Number.isInteger(x)) {
// We require that clients be explicit about integer vs. non-integer types.
throw new TypeError("Refusing to autoconvert non-integer number to Double");
}
return fromJS_options(x);
}
export function fromJS_options<T extends Embeddable = GenericEmbedded>(x: any, options?: FromJSOptions<T>): Value<T> {
function walk(x: any): Value<T> {
switch (typeof x) {
case 'number':
if (!Number.isInteger(x)) {
// We require that clients be explicit about integer vs. non-integer types.
const converted = options?.onNonInteger?.(x) ?? void 0;
if (converted !== void 0) return converted;
throw new TypeError("Refusing to autoconvert non-integer number to Double");
}
// FALL THROUGH
case 'bigint':
case 'string':
case 'symbol':
case 'boolean':
return x;
case 'bigint':
case 'string':
case 'symbol':
case 'boolean':
return x;
case 'undefined':
case 'function':
break;
case 'undefined':
case 'function':
break;
case 'object':
if (x === null) {
case 'object':
if (x === null) {
break;
}
if (typeof x.__as_preserve__ === 'function') {
return x.__as_preserve__();
}
if (Record.isRecord<Value<T>, Tuple<Value<T>>, T>(x)) {
return x;
}
if (Array.isArray(x)) {
return x.map<Value<T>>(walk);
}
if (ArrayBuffer.isView(x) || x instanceof ArrayBuffer) {
return Bytes.from(x);
}
if (Map.isMap(x)) {
const d = new KeyedDictionary<T>();
x.forEach((v, k) => d.set(walk(k), walk(v)));
return d;
}
if (Set.isSet(x)) {
const s = new Set<T>();
x.forEach(v => s.add(walk(v)));
return s;
}
if (isEmbedded<T>(x)) {
return x;
}
// Handle plain JS objects to build a JsDictionary
{
const r: JsDictionary<Value<T>> = {};
Object.entries(x).forEach(([k, v]) => r[k] = walk(v));
return r;
}
default:
break;
}
if (typeof x.__as_preserve__ === 'function') {
return x.__as_preserve__();
}
if (Record.isRecord<Value<T>, Tuple<Value<T>>, T>(x)) {
return x;
}
if (Array.isArray(x)) {
return x.map<Value<T>>(fromJS);
}
if (ArrayBuffer.isView(x) || x instanceof ArrayBuffer) {
return Bytes.from(x);
}
if (Map.isMap(x)) {
const d = new KeyedDictionary<T>();
x.forEach((v, k) => d.set(fromJS(k), fromJS(v)));
return d;
}
if (Set.isSet(x)) {
const s = new Set<T>();
x.forEach(v => s.add(fromJS(v)));
return s;
}
if (isEmbedded<T>(x)) {
return x;
}
// Handle plain JS objects to build a JsDictionary
{
const r: JsDictionary<Value<T>> = {};
Object.entries(x).forEach(([k, v]) => r[k] = fromJS(v));
return r;
}
}
default:
break;
throw new TypeError("Cannot represent JavaScript value as Preserves: " + x);
}
throw new TypeError("Cannot represent JavaScript value as Preserves: " + x);
return walk(x);
}

@@ -69,0 +83,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

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