@decimalturn/toml-patch 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,38 @@
1
- //! @decimalturn/toml-patch v2.1.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- var e,t;function n(t){return t.type===e.Document}function o(t){return t.type===e.Table}function r(t){return t.type===e.TableArray}function l(t){return t.type===e.KeyValue}function i(t){return t.type===e.String}function s(t){return t.type===e.DateTime}function a(t){return t.type===e.InlineArray}function c(t){return t.type===e.InlineItem}function u(t){return t.type===e.InlineTable}function f(t){return t.type===e.Comment}function m(e){return n(e)||o(e)||r(e)||u(e)||a(e)}function h(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}function d(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function p(e,t){const n=Array.isArray(e)?e:g(e);if(0===n.length)return{line:1,column:t};let o=0,r=n.length-1;for(;o<r;){const e=o+r>>>1;n[e]<t?o=e+1:r=e}n[o]<t&&o++;const l=o+1;return{line:l,column:t-(n[l-2]+1||0)}}function g(e){const t=[];for(let n=0;n<e.length;n++){const o=e.charCodeAt(n);10===o?t.push(n):13===o&&(10===e.charCodeAt(n+1)?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function w(e){return{line:e.line,column:e.column}}function y(e){return{start:w(e.start),end:w(e.end)}}!function(e){e.Document="Document",e.Table="Table",e.TableKey="TableKey",e.TableArray="TableArray",e.TableArrayKey="TableArrayKey",e.KeyValue="KeyValue",e.Key="Key",e.String="String",e.Integer="Integer",e.Float="Float",e.Boolean="Boolean",e.DateTime="DateTime",e.InlineArray="InlineArray",e.InlineItem="InlineItem",e.InlineTable="InlineTable",e.Comment="Comment"}(e||(e={}));class v extends Error{line;column;constructor(e,t,n){let o=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=g(e),o=void 0!==n[t.line-2]?n[t.line-2]+1:0,r=n[t.line-1]||e.length;return e.substring(o,r)}(e,t),r=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(o+=`${n}\n${r}\n`)}o+=n,super(o),this.line=t.line,this.column=t.column}}!function(e){e.Bracket="Bracket",e.Curly="Curly",e.Equal="Equal",e.Comma="Comma",e.Dot="Dot",e.Comment="Comment",e.Literal="Literal"}(t||(t={}));const b=/^[\w-]+$/,$='"',T="'",k=" ",S=/[\w,\d,",',+,\-,_]/,I=10,A=13,E=127;function*C(e){const n=e.length;let o=0;const r=[],l=(e,t)=>({start:p(r,e),end:p(r,t)});for(;o<n;){const c=e.charCodeAt(o);if((c<=31||c===E)&&9!==c&&c!==A&&c!==I)throw new v(e,p(r,o),`Control char 0x${c.toString(16).toUpperCase().padStart(2,"0")} not allowed`);if(c===A&&(o+1>=n||e.charCodeAt(o+1)!==I))throw new v(e,p(r,o),"Standalone CR; must be CRLF or LF");if(32===c||9===c||c===A);else if(c===I)r.push(o);else if(91===c||93===c)yield{type:t.Bracket,raw:e[o],loc:l(o,o+1)};else if(123===c||125===c)yield{type:t.Curly,raw:e[o],loc:l(o,o+1)};else if(61===c)yield{type:t.Equal,raw:"=",loc:l(o,o+1)};else if(44===c)yield{type:t.Comma,raw:",",loc:l(o,o+1)};else if(46===c)yield{type:t.Dot,raw:".",loc:l(o,o+1)};else if(35===c)yield i();else{const t=_(e,o,T)||_(e,o,$);t?yield s(t):yield a()}o++}function i(){const i=o;for(;o+1<n;){const t=e.charCodeAt(o+1);if(t===I||t===A)break;o++;const n=e.charCodeAt(o);if((n<=31||n===E)&&9!==n)throw new v(e,p(r,o),`Control char 0x${n.toString(16).toUpperCase().padStart(2,"0")} not allowed`)}return{type:t.Comment,raw:e.slice(i,o+1),loc:l(i,o+1)}}function s(i){const s=o,a=i+i+i;for(o+=3;o<n;){if(_(e,o,i)){let t=3;for(;e[o+t]===i;)t++;if(t>=6)throw new v(e,p(r,o),`Invalid multiline string: ${t} consecutive ${i} characters`);if(3===t){o+=2;break}o+=t-3,o+=2;break}const t=e.charCodeAt(o);if(t===A&&(o+1>=n||e.charCodeAt(o+1)!==I))throw new v(e,p(r,o),"Standalone CR in multiline string; must be CRLF or LF");if((t<=31||t===E)&&9!==t&&t!==I&&t!==A){const n=i===$?"multiline basic strings":"multiline literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let s="";0===t?s="Null":t===E&&(s="DEL");const a=s?`${s} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),a)}t===I&&r.push(o),o++}if(o>=n){if(i===$){let t=0,l=n-1;for(;l>=0&&"\\"===e[l];)t++,l--;if(t>0&&t%2!=0)throw new v(e,p(r,o),`Unterminated multiline ${a} (possible escape issue)`)}throw new v(e,p(r,o),`Unterminated multiline ${a}`)}return{type:t.Literal,raw:e.slice(s,o+1),loc:l(s,o+1)}}function a(){const i=e[o];if(!S.test(i))throw new v(e,p(r,o),`Unexpected char "${i}"`);const s=o;let a=i===$,c=i===T;for(;o<n&&!(o+1>=n);){const t=e.charCodeAt(o+1);if(!(a||c||32!==t&&9!==t&&t!==I&&t!==A&&44!==t&&46!==t&&93!==t&&125!==t&&61!==t&&35!==t))break;if(o++,!a&&!c){const t=e.charCodeAt(o);if(t<=31||t===E)throw new v(e,p(r,o),`Control char 0x${t.toString(16).toUpperCase().padStart(2,"0")} not allowed in unquoted value`)}if(a||c){const t=e.charCodeAt(o);if((t<=31||t===E)&&9!==t){const n=a?"basic strings":"literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let i="";t===I?i="Newline":t===A?i="Carriage return":0===t?i="Null":t===E&&(i="DEL");const s=i?`${i} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),s)}}const l=e[o];if(l===$&&(a=!a),l!==T||a||(c=!c),o+1>=n)break;if(a&&"\\"===l){const t=e[o+1];t!==$&&"\\"!==t||o++}}if(a||c)throw new v(e,p(r,s),`Expected close of string with ${a?$:T}`);return{type:t.Literal,raw:e.slice(s,o+1),loc:l(s,o+1)}}}function _(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;if(n===T)return n;let o=0,r=t-1;for(;r>=0&&"\\"===e[r];)o++,r--;if(0===o)return n;return!(o%2!=0)&&n}const x=new Int8Array(128);x.fill(-1);for(let e=0;e<10;e++)x[48+e]=e;for(let e=0;e<6;e++)x[65+e]=10+e,x[97+e]=10+e;function D(e){const t=e.charCodeAt(0);return t<128&&-1!==x[t]}function O(e,t){return x[e.charCodeAt(t)]<<12|x[e.charCodeAt(t+1)]<<8|x[e.charCodeAt(t+2)]<<4|x[e.charCodeAt(t+3)]}function F(e){return e.startsWith("'''")?L(e.slice(3,e.length-3)):e.startsWith(T)?e.slice(1,e.length-1):e.startsWith('"""')?M(L(e.slice(3,e.length-3)),!0):e.startsWith($)?M(e.slice(1,e.length-1),!1):e}function M(e,t){const n=e.length;if(!t&&-1===e.indexOf("\\"))return e;const o=[];let r=0;for(let l=0;l<n;l++){if("\\"!==e[l])continue;if(l>r&&o.push(e.slice(r,l)),l++,l>=n)throw new Error("Trailing backslash");const i=e[l];switch(i){case"b":o.push("\b");break;case"t":o.push("\t");break;case"n":o.push("\n");break;case"f":o.push("\f");break;case"r":o.push("\r");break;case'"':o.push('"');break;case"\\":o.push("\\");break;case"e":o.push("");break;case"u":{if(l+4>n||!D(e[l+1])||!D(e[l+2])||!D(e[l+3])||!D(e[l+4]))throw new Error(`Invalid Unicode escape: \\u${e.slice(l+1,l+5)}`);const t=O(e,l+1);if(t>=55296&&t<=57343)throw new Error(`Invalid \\u${e.slice(l+1,l+5)}: surrogates not allowed`);o.push(String.fromCharCode(t)),l+=4;break}case"U":{if(l+8>n)throw new Error(`Invalid Unicode escape: \\U${e.slice(l+1,l+9)}`);for(let t=1;t<=8;t++)if(!D(e[l+t]))throw new Error(`Invalid Unicode escape: \\U${e.slice(l+1,l+9)}`);const t=parseInt(e.slice(l+1,l+9),16);o.push(String.fromCodePoint(t)),l+=8;break}case"x":{if(l+2>n||!D(e[l+1])||!D(e[l+2]))throw new Error(`Invalid hex escape: \\x${e.slice(l+1,l+3)}`);const t=x[e.charCodeAt(l+1)]<<4|x[e.charCodeAt(l+2)];o.push(String.fromCharCode(t)),l+=2;break}default:if(t&&("\n"===i||"\r"===i||" "===i||"\t"===i)){let t="\n"===i||"\r"===i,o=l;for(;o<n&&(" "===e[o]||"\t"===e[o]||"\n"===e[o]||"\r"===e[o]);)"\n"!==e[o]&&"\r"!==e[o]||(t=!0),o++;if(!t)throw new Error(`Invalid escape sequence: \\${i}`);l=o-1;break}throw new Error(`Invalid escape sequence: \\${i}`)}r=l+1}return 0===r?e:(r<n&&o.push(e.slice(r)),o.join(""))}function L(e){return 10===e.charCodeAt(0)?e.slice(1):13===e.charCodeAt(0)&&10===e.charCodeAt(1)?e.slice(2):e}class B{iterator;index;value;done;peeked;constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){if(this.done)return N();const e=this.peeked||this.iterator.next();return this.index+=1,this.value=e.value,this.done=e.done??!1,this.peeked=null,e}peek(){return this.done?N():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}const W=Object.freeze({value:void 0,done:!0});function N(){return W}function U(e){return{year:String(e.getUTCFullYear()).padStart(4,"0"),month:String(e.getUTCMonth()+1).padStart(2,"0"),day:String(e.getUTCDate()).padStart(2,"0"),hours:String(e.getUTCHours()).padStart(2,"0"),minutes:String(e.getUTCMinutes()).padStart(2,"0"),seconds:String(e.getUTCSeconds()).padStart(2,"0"),ms:e.getUTCMilliseconds()}}function K(e,t,n=/\.(\d+)\s*$/){if(t&&t.includes(".")){const o=t.match(n),r=o?o[1].length:3;return"."+String(e).padStart(3,"0").slice(0,r)}return e>0?"."+String(e).padStart(3,"0").replace(/0+$/,""):""}function j(e){if("Z"===e)return 0;const t="+"===e[0]?1:-1,[n,o]=e.slice(1).split(":");return t*(60*parseInt(n)+parseInt(o))}class Z{static IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/;static IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/;static IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;static createDateWithOriginalFormat(e,t){if(Z.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof q)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new z(t,!1)}const t=e.toISOString().split("T")[0];return new P(t)}if(Z.IS_TIME_ONLY.test(t)){if(e instanceof V)return e;{const n=U(e),o=K(n.ms,t);return new V(`${n.hours}:${n.minutes}:${n.seconds}${o}`,t)}}if(Z.IS_LOCAL_DATETIME_T.test(t)){const n=U(e),o=K(n.ms,t);return new z(`${n.year}-${n.month}-${n.day}T${n.hours}:${n.minutes}:${n.seconds}${o}`,!1,t)}if(Z.IS_LOCAL_DATETIME_SPACE.test(t)){const n=U(e),o=K(n.ms,t);return new z(`${n.year}-${n.month}-${n.day} ${n.hours}:${n.minutes}:${n.seconds}${o}`,!0,t)}if(Z.IS_OFFSET_DATETIME_T.test(t)||Z.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),o=n?"z"===n[1]?"Z":n[1]:"Z",r=Z.IS_OFFSET_DATETIME_SPACE.test(t),l=U(new Date(e.getTime()+6e4*j(o))),i=r?" ":"T",s=K(l.ms,t,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),a=`${l.year}-${l.month}-${l.day}${i}${l.hours}:${l.minutes}:${l.seconds}${s}${o}`;return new q(a,r)}return e}}class P extends Date{constructor(e){super(e)}toISOString(){const e=U(this);return`${e.year}-${e.month}-${e.day}`}}class V extends Date{originalFormat;constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+":00"),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){const e=U(this);return`${e.hours}:${e.minutes}:${e.seconds}${K(e.ms,this.originalFormat)}`}}class z extends Date{useSpaceSeparator=!1;originalFormat;constructor(e,t=!1,n){let o=e;/\d{2}:\d{2}:\d{2}/.test(e)||(o=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(o.replace(" ","T")+"Z"),this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){const e=U(this),t=this.useSpaceSeparator?" ":"T";return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${K(e.ms,this.originalFormat)}`}}class q extends Date{useSpaceSeparator=!1;originalOffset;originalFormat;constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,"$1:00$2")),super(n.replace(" ","T")),this.useSpaceSeparator=t,this.originalFormat=e;const o=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);o&&(this.originalOffset="z"===o[1]?"Z":o[1])}toISOString(){if(this.originalOffset){const e=U(new Date(this.getTime()+6e4*j(this.originalOffset))),t=this.useSpaceSeparator?" ":"T",n=K(e.ms,this.originalFormat,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${n}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const R=Z,H="true",J=/e/i,Y=/_/g,G=/^[+-]?inf$/,X=/^[+-]?nan$/,Q=/^[+-]?0x/i;function ee(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||95===e||45===e}const te=/^[+-]?0o/i,ne=/^[+-]?0b/i;function oe(e,t,n){for(let o=0;o<e.length;o++)if(!ee(e.charCodeAt(o)))throw new v(t,{line:n.line,column:n.column+o},`Invalid bare key char '${e[o]}'`)}function re(e,t,n){if(e.startsWith('"""')||e.startsWith("'''"))throw new v(t,n,"Multiline strings cannot be keys")}function le(e,t,n){try{return F(e)}catch(e){throw new v(t,n,e.message)}}function ie(e,t,n,o=!0){if(e.endsWith("_"))throw new v(t,n,"Underscore must be between digits");if(o?/^[+-]?_/.test(e):e.startsWith("_"))throw new v(t,n,"Underscore must be between digits");if(/__/.test(e))throw new v(t,n,"Consecutive underscores not allowed")}function se(e,t,n,o){const r=e.replace(Y,"");if(/^[+-]?0\d/.test(r)&&!Q.test(e)&&!te.test(e)&&!ne.test(e))throw new v(t,n,`Leading zeros are not allowed in ${o}`)}function ae(e,t,n,o){if(/_[eE]/.test(e))throw new v(n,o,"Underscore before exponent is not allowed");if(/[eE][+-]?_/.test(e))throw new v(n,o,"Underscore at start of exponent is not allowed");if(/[eE][+-]?$/.test(e))throw new v(n,o,`Invalid float "${t}": incomplete exponent`);if(/[eE][+-]?.*\./.test(e))throw new v(n,o,`Invalid float "${t}": decimal point not allowed in exponent`)}function ce(e,t,n,o,r,l){if(2!==e.length)throw new v(r,l,`"${o}": hour must be 2 digits`);if(2!==t.length)throw new v(r,l,`"${o}": minute must be 2 digits`);if(n&&2!==n.length)throw new v(r,l,`"${o}": second must be 2 digits`)}function ue(e,t,n,o,r,l){if(void 0!==e){const t=parseInt(e,10);if(t<0||t>23)throw new v(r,l,`"${o}": hour must be 00-23`)}if(void 0!==t){const e=parseInt(t,10);if(e<0||e>59)throw new v(r,l,`"${o}": minute must be 00-59`)}if(void 0!==n){const e=parseInt(n,10);if(e<0||e>60)throw new v(r,l,`"${o}": second must be 00-60`)}}function fe(e,t,n,o,r,l,i){const s=o[0]+o[1].toUpperCase();if(new RegExp("^[+\\-]?"+s.replace(/([[\]])/g,"\\$1")).test(e))throw new v(t,n,`${l} prefix must be lowercase "${o}"`);if(new RegExp("^[+\\-]?"+o+"_","i").test(e))throw new v(t,n,"Underscore must be between digits");const a=new RegExp("^[+\\-]?"+o,"i"),c=e.replace(a,"");if(!c||"_"===c||c.startsWith("_"))throw new v(t,n,`Incomplete ${l.toLowerCase()} number`);const u=c.replace(/_/g,"");if(!r.test(u))throw new v(t,n,i??`Invalid ${l.toLowerCase()} digits`);if(/^[+-]/.test(e))throw new v(t,n,`${l} numbers cannot have a sign prefix`)}function*me(e){const t=new B(C(e));for(;!t.next().done;){const n=be(t,e);for(const e of n)yield e}}function he(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function de(n,o){const r=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,l=r===e.Table;if(l&&"["!==n.value.raw)throw new v(o,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!l){const e=n.peek();if(e.done)throw new v(o,n.value.loc.start,'Expected "[[" for Array of Tables, found end of input');if("["!==n.value.raw||"["!==e.value.raw)throw new v(o,n.value.loc.start,`Expected "[[", found ${n.value.raw+e.value.raw}`);const t=n.value,r=e.value;if(t.loc.end.line!==r.loc.start.line||t.loc.end.column!==r.loc.start.column)throw new v(o,t.loc.start,'"[[" brackets must be adjacent (no whitespace)')}const i=l?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};if(n.next(),r===e.TableArray&&n.next(),n.done)throw new v(o,i.loc.start,"Expected table key, reached end of file");if(n.value.type===t.Bracket&&"]"===n.value.raw)throw new v(o,n.value.loc.start,r===e.TableArray?"Array of Tables header [[]] requires a table name":"Table header [] requires a table name");const s=n.value.raw;re(s,o,n.value.loc.start);let a;for(s.startsWith('"')||s.startsWith("'")||oe(s,o,n.value.loc.start),a=[le(n.value.raw,o,n.value.loc.start)],i.item={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:a};!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=n.value.raw;t.startsWith('"')||t.startsWith("'")||oe(t,o,n.value.loc.start);const r=" ".repeat(e.loc.start.column-i.item.loc.end.column),l=" ".repeat(n.value.loc.start.column-e.loc.end.column);i.item.loc.end=n.value.loc.end,i.item.raw+=`${r}.${l}${n.value.raw}`;try{i.item.value.push(F(n.value.raw))}catch(e){const t=e;throw new v(o,n.value.loc.start,t.message)}}if(n.next(),!n.done){const e=i.loc.start.line;if(n.value.loc.start.line!==e)throw new v(o,n.value.loc.start,l?"Table header must be single-line":"Array of Tables header must be single-line")}if(l&&(n.done||"]"!==n.value.raw))throw new v(o,n.done?i.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!l&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new v(o,n.done||n.peek().done?i.item.loc.end:n.value.loc.start,`Expected "]]" closing, found ${n.done||n.peek().done?"end of file":n.value.raw+n.peek().value.raw}`);if(!l){const e=n.value,t=n.peek().value;if(e.loc.end.line!==t.loc.start.line||e.loc.end.column!==t.loc.start.column)throw new v(o,e.loc.start,'"]]" brackets must be adjacent (no whitespace)')}if(l||n.next(),i.loc.end=n.value.loc.end,!n.peek().done){const e=n.peek().value;if(e.loc.start.line===i.loc.end.line&&e.type!==t.Comment)throw new v(o,e.loc.start,`Extra content after ${l?"table":"Array of Tables"} header`)}let c=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;){n.next();const e=be(n,o);for(let t=0;t<e.length;t++)c.push(e[t])}return{type:l?e.Table:e.TableArray,loc:{start:w(i.loc.start),end:c.length?w(c[c.length-1].loc.end):w(i.loc.end)},key:i,items:c}}function pe(t,n){const o=le(t.value.raw,n,t.value.loc.start);return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:o}}function ge(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===H}}function we(n,o){let r,l=n.value.loc,i=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&R.IS_FULL_DATE.test(i)&&R.IS_FULL_TIME.test(n.peek().value.raw)){const e=l.start;n.next(),l={start:e,end:n.value.loc.end},i+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=l.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(o,n.value.loc.end,"Expected fractional value for DateTime");n.next(),l={start:e,end:n.value.loc.end},i+=`.${n.value.raw}`}if(function(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new v(t,n,`"${e}": fractional seconds needs digit after dot`);if(/[+-]$/.test(e))throw new v(t,n,`"${e}": offset needs HH:MM`);const o=/\d{2}:\d{2}/.test(e),r=o?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(r){const e=r[0],o=r[2],l=r[3],i=r[4];if(":"!==l)throw new v(t,n,`Offset "${e}": missing colon separator`);if(2!==o.length)throw new v(t,n,`Offset "${e}": hour must be 2 digits`);if(!i||0===i.length)throw new v(t,n,`Offset "${e}": minute required`);if(2!==i.length)throw new v(t,n,`Offset "${e}": minute must be 2 digits`);const s=parseInt(o,10);if(s<0||s>23)throw new v(t,n,`Offset "${e}": hour must be 00-23`);const a=parseInt(i,10);if(a<0||a>59)throw new v(t,n,`Offset "${e}": minute must be 00-59`)}const l=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!l.test(e)){if(/^\d{4}-\d{2}-\d{2}T$/.test(e))throw new v(t,n,`"${e}": 'T' requires time component`);if(/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e))throw new v(t,n,`Invalid date "${e}": unexpected character after date`);if(/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e))throw new v(t,n,`"${e}": missing 'T' or space separator`);throw new v(t,n,`Invalid datetime "${e}"`)}const i=e.match(/^(\d+)-/);if(i&&4!==i[1].length)throw new v(t,n,`"${e}": year must be 4 digits`);const s=/^(\d+)-(\d+)-(\d+)/,a=e.match(s);if(a){const[,,o,r]=a;if(2!==o.length)throw new v(t,n,`"${e}": month must be 2 digits`);if(2!==r.length)throw new v(t,n,`"${e}": day must be 2 digits`)}const c=/[T ](\d+):(\d+)(?::(\d+))?/,u=e.match(c);if(u){const[,o,r,l]=u;ce(o,r,l,e,t,n)}const f=/^(\d+):(\d+)(?::(\d+))?/,m=e.match(f);if(m&&!a){const[,o,r,l]=m;ce(o,r,l,e,t,n)}const h=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),d=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(h){const[,o,r,l,i,s,a]=h,c=parseInt(r,10);if(c<1||c>12)throw new v(t,n,`"${e}": month must be 01-12`);const u=parseInt(l,10);if(u<1||u>31)throw new v(t,n,`"${e}": day must be 01-31`);const f=function(e,t){const n=[31,28,31,30,31,30,31,31,30,31,30,31];if(2===t){return e%4==0&&e%100!=0||e%400==0?29:28}return n[t-1]}(parseInt(o,10),c);if(u>f)throw new v(t,n,`"${e}": day ${l} invalid for ${o}-${r}`);ue(i,s,a,e,t,n)}else if(d){const[,o,r,l]=d;ue(o,r,l,e,t,n)}}(i,o,l.start),R.IS_FULL_DATE.test(i))r=R.IS_DATE_ONLY.test(i)?new P(i):R.IS_LOCAL_DATETIME_T.test(i)?new z(i,!1):R.IS_LOCAL_DATETIME_SPACE.test(i)?new z(i,!0):R.IS_OFFSET_DATETIME_T.test(i)?new q(i,!1):R.IS_OFFSET_DATETIME_SPACE.test(i)?new q(i,!0):new Date(i.replace(" ","T"));else if(R.IS_TIME_ONLY.test(i))r=new V(i,i);else{const[e]=(new Date).toISOString().split("T");r=new Date(`${e}T${i}`)}return{type:e.DateTime,loc:l,raw:i,value:r}}function ye(n,o){let r,l=n.value.loc,i=n.value.raw;if(G.test(i))r=i.startsWith("-")?-1/0:1/0;else if(X.test(i))r=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(ie(i,o,l.start),ae(i,i,o,l.start),!n.peek().done&&n.peek().value.type===t.Dot)throw new v(o,n.peek().value.loc.start,`Float "${i}.": dot after exponent`);se(i,o,l.start,"the integer part of a float"),r=Number(i.replace(Y,""))}else{const e=l.start;{if(J.test(i)&&!Q.test(i))throw new v(o,l.start,`Float "${i}": dot after exponent`);const e=i;se(e,o,l.start,"the integer part of a float");const t=e.replace(/^[+-]/,"");if(""===t||"_"===t)throw new v(o,l.start,"Float: digit required before dot");ie(e,o,l.start)}if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(o,n.value.loc.end,"Expected fraction value for Float");n.next(),i+=`.${n.value.raw}`,l={start:e,end:n.value.loc.end};{const e=n.value.raw;if(!/^\d/.test(e))throw new v(o,n.value.loc.start,`Float: fraction must start with digit, found "${e}"`);ie(e,o,n.value.loc.start,!1),ae(e,i,o,n.value.loc.start)}r=Number(i.replace(Y,""))}if(Number.isNaN(r)&&!X.test(i))throw new v(o,l.start,`Invalid float "${i}"`);return{type:e.Float,loc:l,raw:i,value:r}}function ve(t,n){const o=t.value.raw,r=t.value.loc;if(/^\d{1,}-\d{1,}/.test(o)||/^\d{1,}:\d{1,}/.test(o)||/^\d{6}-\d{2}$/.test(o))throw new v(n,r.start,`Invalid integer "${o}"`);if("-0"===o||"+0"===o)return{type:e.Integer,loc:r,raw:o,value:0};if(/^[+-]{2,}/.test(o))throw new v(n,r.start,"Double sign is not allowed in integers");se(o,n,r.start,"decimal integers"),ie(o,n,r.start),function(e,t,n){if(Q.test(e)||te.test(e)||ne.test(e))return;const o=e.replace(/^[+-]/,"").replace(/_/g,"");if(!/^[0-9]+$/.test(o))throw new v(t,n,`Invalid integer "${e}"`)}(o,n,r.start);let l=10;Q.test(o)?(l=16,fe(o,n,r.start,"0x",/^[0-9a-fA-F]+$/,"Hexadecimal")):te.test(o)?(l=8,fe(o,n,r.start,"0o",/^[0-7]+$/,"Octal","Invalid octal digits (must be 0-7)")):ne.test(o)&&(l=2,fe(o,n,r.start,"0b",/^[01]+$/,"Binary","Invalid binary digits (must be 0 or 1)"));const i=parseInt(o.replace(Y,"").replace(te,"").replace(ne,""),l);if(Number.isNaN(i))throw new v(n,r.start,`Invalid integer "${o}"`);return{type:e.Integer,loc:r,raw:o,value:i}}function be(n,o){if(n.value.type===t.Comment)return[he(n)];if(n.value.type===t.Bracket)return[de(n,o)];if(n.value.type===t.Literal)return function(n,o){const r=n.value.raw;if(r.endsWith(":"))throw new v(o,{line:n.value.loc.start.line,column:n.value.loc.start.column+[...r].length-1},"Use '=' to separate keys and values, not ':'");re(r,o,n.value.loc.start);r.startsWith('"')||r.startsWith("'")||oe(r,o,n.value.loc.start);let l;l=[le(n.value.raw,o,n.value.loc.start)];const i={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:l};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next(),n.next();const e=n.value.raw;re(e,o,n.value.loc.start);e.startsWith('"')||e.startsWith("'")||oe(e,o,n.value.loc.start),i.loc.end=n.value.loc.end,i.raw+=`.${n.value.raw}`,i.value.push(le(n.value.raw,o,n.value.loc.start))}if(n.next(),!n.done&&n.value.loc.start.line!==i.loc.end.line)throw new v(o,n.value.loc.start,'"=" must be on same line as key');if(n.done||n.value.type!==t.Equal){if(!n.done&&":"===n.value.raw)throw new v(o,n.value.loc.start,"Use '=' to separate keys and values, not ':'");throw new v(o,n.done?i.loc.end:n.value.loc.start,'Expected "=" for key-value')}const s=n.value.loc.start.column,a=n.value.loc.start.line;if(n.next(),n.done)throw new v(o,i.loc.start,"Expected value, reached EOF");if(n.value.loc.start.line!==a)throw new v(o,n.value.loc.start,"Value must be on same line as '='");if(n.done)throw new v(o,i.loc.start,"Expected value for key-value");const c=$e(n,o),u=c[0];if(!n.peek().done){const r=n.peek().value;if(r.type===t.Dot&&r.loc.start.line===u.loc.end.line&&(u.type===e.Float||u.type===e.Integer))throw new v(o,r.loc.start,"Invalid number: multiple decimal points not allowed");if((r.type===t.Literal||r.type===t.Bracket)&&r.loc.start.line===u.loc.end.line)throw new v(o,r.loc.start,"Key/value pairs must be separated by a newline")}return c[0]={type:e.KeyValue,key:i,value:u,loc:{start:w(i.loc.start),end:w(u.loc.end)},equals:s},c}(n,o);throw n.value.type===t.Equal?new v(o,n.value.loc.start,"Missing key before '='"):new v(o,n.value.loc.start,`Unexpected token "${n.value.type}"`)}function $e(n,o){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===$||e[0]===T?[pe(n,o)]:e===H||"false"===e?[ge(n)]:/^\d/.test(e)&&(/^\d{1,}-\d{1,}/.test(e)||/^\d{1,}:\d{1,}/.test(e))?[we(n,o)]:!n.peek().done&&n.peek().value.type===t.Dot||G.test(e)||X.test(e)||J.test(e)&&!Q.test(e)?[ye(n,o)]:[ve(n,o)]}if(n.value.type===t.Curly){const[r,l]=function(n,o){if("{"!==n.value.raw)throw new v(o,n.value.loc.start,'Expected "{" for inline table');const r={type:e.InlineTable,loc:n.value.loc,items:[]},l=[];n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comment){l.push(he(n)),n.next();continue}if(n.value.type===t.Comma){const e=r.items[r.items.length-1];if(!e)throw new v(o,n.value.loc.start,"Leading comma in inline table");if(e.comma)throw new v(o,n.value.loc.start,"Consecutive commas in inline table");e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const i=r.items[r.items.length-1];if(i&&!i.comma)throw new v(o,n.value.loc.start,"Missing comma between inline table items");const s=be(n,o),a=s[0];if(a.type===e.KeyValue){r.items.push({type:e.InlineItem,loc:y(a.loc),item:a,comma:!1});for(let e=1;e<s.length;e++)l.push(s[e])}n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new v(o,n.done?r.loc.start:n.value.loc.start,'Expected "}"');return r.loc.end=n.value.loc.end,[r,l]}(n,o);return[r,...l]}if(n.value.type===t.Bracket){const[r,l]=function(n,o){if("["!==n.value.raw)throw new v(o,n.value.loc.start,'Expected "[" for inline array');const r={type:e.InlineArray,loc:n.value.loc,items:[]},l=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=r.items[r.items.length-1];if(!e)throw new v(o,n.value.loc.start,"Leading comma in array");if(e.comma)throw new v(o,n.value.loc.start,"Consecutive commas in array");e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)l.push(he(n));else{const t=r.items[r.items.length-1];if(t&&!t.comma)throw new v(o,n.value.loc.start,"Missing comma between array elements");const i=$e(n,o),s=i[0];r.items.push({type:e.InlineItem,loc:y(s.loc),item:s,comma:!1});for(let e=1;e<i.length;e++)l.push(i[e])}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new v(o,n.done?r.loc.start:n.value.loc.start,'Expected "]"');return r.loc.end=n.value.loc.end,[r,l]}(n,o);return[r,...l]}throw n.value.type===t.Dot?new v(o,n.value.loc.start,"Number cannot start with a dot"):new v(o,n.value.loc.start,"Unrecognized token type")}function Te(e){return e[e.length-1]}function ke(){return Object.create(null)}function Se(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function Ie(e){return"[object Date]"===Object.prototype.toString.call(e)}const Ae=new Set(["Temporal.PlainDate","Temporal.PlainTime","Temporal.PlainDateTime","Temporal.ZonedDateTime","PlainDate","PlainTime","PlainDateTime","ZonedDateTime"]);function Ee(e){return null!=e&&"object"==typeof e&&Ae.has(e.constructor?.name)&&"function"==typeof e.equals}function Ce(e){const t=e.constructor?.name??"";if("Temporal.ZonedDateTime"===t||"ZonedDateTime"===t){const t=e.toString(),n=t.match(/\[(.+)\]$/);if(n&&!/^[+-]\d{2}:\d{2}$/.test(n[1]))throw new Error(`ZonedDateTime with IANA timezone "${t}" cannot be represented in TOML. TOML only supports offset-based timezones (+05:30, Z).`);return t.replace(/\[.*\]$/,"").replace(/(\+00:00)$/,"Z")}const n=e.toString();if(/\[.*\]/.test(n))throw new Error(`Temporal value contains unsupported annotation: "${n}". TOML only supports ISO 8601 calendar.`);return n}function _e(e){return e&&"object"==typeof e&&!Ie(e)&&!Ee(e)&&!Array.isArray(e)}function xe(e){return null!=e&&"function"==typeof e[Symbol.iterator]}function De(e,t){return t in e}function Oe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Fe(e){if(_e(e)){return`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${Fe(e[t])}`).join(",")}}`}return Array.isArray(e)?`[${e.map(Fe).join(",")}]`:Ee(e)?JSON.stringify(e.toString()):Ie(e)?JSON.stringify(e.toISOString()):JSON.stringify(e)}function Me(e,t){const n=e.length,o=t.length;e.length=n+o;for(let r=0;r<o;r++)e[n+r]=t[r]}const Le=new WeakSet,Be=new WeakMap,We=e=>(Be.has(e)||Be.set(e,new WeakMap),Be.get(e)),Ne=new WeakMap,Ue=e=>(Ne.has(e)||Ne.set(e,new WeakMap),Ne.get(e));function Ke(e,t,n,o){if(m(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Item not found in parent for replace");t.items.splice(e,1,o)}else if(l(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Item not found in parent for replace");t.value.items.splice(e,1,o)}else if(h(t))t.item=o;else{if(!l(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=o:t.value=o}Re(o,{lines:n.loc.start.line-o.loc.start.line,columns:n.loc.start.column-o.loc.start.column});const r=d(n.loc),i=d(o.loc);Je({lines:i.lines-r.lines,columns:i.columns-r.columns},Ue(e),o,n),Le.add(e)}function je(e,t,i,s,h){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,g;s=null!=s&&"number"==typeof s?s:t.items.length,a(t)||u(t)?({shift:p,offset:g}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const o=null!=n?e.items[n-1]:Te(e.items),r=null==n||n===e.items.length;e.items.splice(n,0,t);const l=!!o,i=!r;l&&(o.comma=!0);i&&(t.comma=!0);const s=He(e),a=r&&!0===t.comma;return Ze(e,t,n,{useNewLine:s,hasCommaHandling:!0,isLastElement:r,hasSeparatingCommaBefore:l,hasSeparatingCommaAfter:i,hasTrailingComma:a})}(t,i,s)):h&&n(t)?({shift:p,offset:g}=function(e,t,n){const o=Ze(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),o}(t,i,s)):({shift:p,offset:g}=function(e,t,i){if(s=t,!(l(s)||o(s)||r(s)||f(s)))throw new Error(`Incompatible child type "${t.type}"`);var s;const a=e.items[i-1],c=n(e)&&!e.items.length,u=n(e)&&!c&&void 0===a;e.items.splice(i,0,t);const m=a?{line:a.loc.end.line,column:f(a)?e.loc.start.column:a.loc.start.column}:w(e.loc.start),h=o(t)||r(t);let p=0;c||u||(p=h?2:1);m.line+=p;const g={lines:m.line-t.loc.start.line,columns:m.column-t.loc.start.column},y=d(t.loc),v={lines:u?y.lines+1:y.lines+(p-1),columns:y.columns};return{shift:g,offset:v}}(t,i,s)),Re(i,p);const y=t.items[s-1],v=y&&Ue(e).get(y);if(v&&(g.lines+=v.lines,g.columns+=v.columns,Ue(e).delete(y)),u(t)&&0!==g.lines&&m(e)&&e!==t){const t=i.loc.start.line,n=e.items;for(let e=0;e<n.length;e++){const o=n[e];if(!f(o))continue;o.loc.start.line<t&&(o.loc.start.line-=g.lines,o.loc.end.line-=g.lines)}}Ue(e).set(i,g),Le.add(e)}function Ze(e,t,n,o={}){const{useNewLine:r=!1,skipCommaSpace:l=2,skipBracketSpace:i=1,hasCommaHandling:s=!1,isLastElement:a=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:m=!1}=o,h=n>0?e.items[n-1]:void 0,p=h?{line:h.loc.end.line,column:r?f(h)?e.loc.start.column:h.loc.start.column:h.loc.end.column}:w(e.loc.start);let g=0;if(r)g=1;else{const e=c||!s&&!!h;e&&s?p.column+=l:(e||s&&!h)&&(p.column+=i)}p.line+=g;const y={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},v=d(t.loc);if(!s){return{shift:y,offset:{lines:v.lines+(g-1),columns:v.columns}}}let b=0;c&&m&&!u&&a&&(b=-1);return{shift:y,offset:{lines:v.lines+(g-1),columns:v.columns+(c||u?l:0)+(m?1+b:0)}}}function Pe(e,t,n){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for remove`);let l=t.items.indexOf(n);if(l<0){if(l=t.items.findIndex(e=>h(e)&&e.item===n),l<0)throw new Error("Node not found in parent for removal");n=t.items[l]}const i=t.items[l-1];let s=t.items[l+1];t.items.splice(l,1);let p=d(n.loc);s&&f(s)&&s.loc.start.line===n.loc.end.line&&(p=d({start:n.loc.start,end:s.loc.end}),s=t.items[l+1],t.items.splice(l,1));const g=i&&c(i)||s&&c(s),w=i&&i.loc.end.line===n.loc.start.line,y=s&&s.loc.start.line===n.loc.end.line,v=g&&(w||y),b={lines:-(p.lines-(v?1:0)),columns:v?-p.columns:0},$=(u(t)||a(t))&&t.loc.end.line>t.loc.start.line;if(void 0!==i||void 0!==s||$||(b.lines=0,b.columns=0),g&&w&&(b.columns-=2),g&&!i&&s&&(He(t)||(b.columns-=2)),g&&i&&!s){const e=n.comma;i.comma=!!e}let T,k;i?(T=i,k=Ue(e)):(o(t)||r(t))&&"key"in t?(T=t.key,k=Ue(e)):(T=t,k=We(e));const S=Ue(e),I=k.get(T);I&&(b.lines+=I.lines,b.columns+=I.columns);const A=S.get(n);if(A&&(b.lines+=A.lines,b.columns+=A.columns),k.set(T,b),Le.add(e),$&&m(e)&&e!==t){const t=n.loc.start.line,o=e.items,r=[];for(let e=0;e<o.length;e++){const n=o[e];if(!f(n))continue;const l=n.loc.start.line;l===t?r.push(e):0!==b.lines&&l<t&&(n.loc.start.line-=b.lines,n.loc.end.line-=b.lines)}for(let e=r.length-1;e>=0;e--)o.splice(r[e],1)}}function Ve(e,t,n=!0){if(!n)return;if(!t.items.length)return;Je({lines:0,columns:1},We(e),t);const o=Te(t.items);Je({lines:0,columns:1},Ue(e),o),Le.add(e)}function ze(e,t,n=!1){if(!n)return;if(!t.items.length)return;const o=Te(t.items);o.comma=!0,Je({lines:0,columns:1},Ue(e),o),Le.add(e)}function qe(t){if(!Le.has(t))return;const n=We(t),o=Ue(t);let r=0;const l={};function i(e){let t=e.loc.start.line,n=e.loc.start.column;if("key"in e){const o=e.key.loc.end;(o.line>t||o.line===t&&o.column>n)&&(t=o.line,n=o.column)}for(let o=0;o<e.items.length;o++){const r=e.items[o].loc.end;(r.line>t||r.line===t&&r.column>n)&&(t=r.line,n=r.column)}e.loc.end={line:t,column:n}}function s(e){e.loc.start.line+=r;const t=l[e.loc.start.line]||0;e.loc.start.column+=t;const o=n.get(e);o&&(r+=o.lines,l[e.loc.start.line]=(l[e.loc.start.line]||0)+o.columns)}function a(e){e.loc.end.line+=r;const t=l[e.loc.end.line]||0;e.loc.end.column+=t;const n=o.get(e);n&&(r+=n.lines,l[e.loc.end.line]=(l[e.loc.end.line]||0)+n.columns)}!function t(n){switch(n.type){case e.Document:{const e=n;s(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e),i(e);break}case e.Table:{const e=n;s(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e),i(e);break}case e.TableArray:{const e=n;s(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e),i(e);break}case e.TableKey:{const e=n;s(e),t(e.item),a(e);break}case e.TableArrayKey:{const e=n;s(e),t(e.item),a(e);break}case e.KeyValue:{const e=n,i=e.loc.start.line+r,c=o.get(e.key);e.equals+=(l[i]||0)+(c?c.columns:0),s(e),t(e.key),t(e.value),a(e);break}case e.InlineArray:{const e=n;s(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e);break}case e.InlineTable:{const e=n;s(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);a(e);break}case e.InlineItem:{const e=n;s(e),t(e.item),a(e);break}case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:s(n),a(n);break;default:throw new Error(`Unrecognized node type "${n.type}"`)}}(t),Le.delete(t),Be.delete(t),Ne.delete(t)}function Re(t,n,o={}){const{lines:r,columns:l}=n;if(0===r&&0===l)return t;const{first_line_only:i=!1}=o,s=t.loc.start.line,a=t.type;if(a===e.Key||a===e.String||a===e.Integer||a===e.Float||a===e.Boolean||a===e.DateTime||a===e.Comment)return i&&t.loc.start.line!==s||(t.loc.start.column+=l,t.loc.end.line===t.loc.start.line&&(t.loc.end.column+=l)),t.loc.start.line+=r,t.loc.end.line+=r,t;if(a===e.KeyValue){const n=t,o=n.value.type;if(o===e.String||o===e.Integer||o===e.Float||o===e.Boolean||o===e.DateTime){i&&n.loc.start.line!==s||(n.loc.start.column+=l,n.loc.end.column+=l),n.loc.start.line+=r,n.loc.end.line+=r,n.equals+=l;const e=n.key;i&&e.loc.start.line!==s||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=r,e.loc.end.line+=r;const o=n.value;return i&&o.loc.start.line!==s||(o.loc.start.column+=l,o.loc.end.column+=l),o.loc.start.line+=r,o.loc.end.line+=r,t}}const c=e=>{i&&e.loc.start.line!==s||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=r,e.loc.end.line+=r};return function(t,n){function o(e,t){for(const n of e)r(n,t)}function r(t,l){const i=n[t.type];switch(i&&"function"==typeof i&&i(t,l),i&&i.enter&&i.enter(t,l),t.type){case e.Document:o(t.items,t);break;case e.Table:r(t.key,t),o(t.items,t);break;case e.TableKey:r(t.item,t);break;case e.TableArray:r(t.key,t),o(t.items,t);break;case e.TableArrayKey:r(t.item,t);break;case e.KeyValue:r(t.key,t),r(t.value,t);break;case e.InlineArray:o(t.items,t);break;case e.InlineItem:r(t.item,t);break;case e.InlineTable:o(t.items,t);break;case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:break;default:throw new Error(`Unrecognized node type "${t.type}"`)}i&&i.exit&&i.exit(t,l)}xe(t)?o(t,null):r(t,null)}(t,{[e.Table]:c,[e.TableKey]:c,[e.TableArray]:c,[e.TableArrayKey]:c,[e.KeyValue](e){c(e),e.equals+=l},[e.Key]:c,[e.String]:c,[e.Integer]:c,[e.Float]:c,[e.Boolean]:c,[e.DateTime]:c,[e.InlineArray]:c,[e.InlineItem]:c,[e.InlineTable]:c,[e.Comment]:c}),t}function He(e){if(!e.items.length)return!1;return d(e.loc).lines>e.items.length}function Je(e,t,n,o){const r=t.get(o||n);r&&(e.lines+=r.lines,e.columns+=r.columns),t.set(n,e)}function Ye(e){switch(e){case"b":return"\b";case"t":return"\t";case"n":return"\n";case"f":return"\f";case"r":return"\r";case'"':return'"';case"\\":return"\\";default:return null}}function Ge(e,t){switch(e){case"\\":return"\\\\";case"\b":return"\\b";case"\t":return"\\t";case"\f":return"\\f";case'"':return"singleline-basic"===t?'\\"':'"';case"\n":return"singleline-basic"===t?"\\n":"\n";case"\r":return"singleline-basic"===t?"\\r":"\r";default:{const n=e.charCodeAt(0);return function(e,t){return"singleline-basic"===t?e<=31||127===e:e>=0&&e<=7||11===e||e>=14&&e<=31||127===e}(n,t)?`\\u${n.toString(16).padStart(4,"0").toUpperCase()}`:e}}}function Xe(e,t,n){const o=function(e){const t=new Map;for(let n=0;n<e.length;n++){if("\\"!==e[n])continue;const o=e[n+1];if(!o)continue;const r=Ye(o);if(null===r){if("x"===o&&/^[0-9A-Fa-f]{2}$/.test(e.slice(n+2,n+4))){const o=e.slice(n,n+4),r=Number.parseInt(e.slice(n+2,n+4),16),l=String.fromCharCode(r);t.has(l)||t.set(l,o),n+=3;continue}if("u"===o&&/^[0-9A-Fa-f]{4}$/.test(e.slice(n+2,n+6))){const o=e.slice(n,n+6),r=Number.parseInt(e.slice(n+2,n+6),16),l=String.fromCodePoint(r);t.has(l)||t.set(l,o),n+=5;continue}if("U"===o&&/^[0-9A-Fa-f]{8}$/.test(e.slice(n+2,n+10))){const o=e.slice(n,n+10),r=Number.parseInt(e.slice(n+2,n+10),16),l=String.fromCodePoint(r);t.has(l)||t.set(l,o),n+=9;continue}}else"\n"===r||"\r"===r||t.has(r)||t.set(r,"\\"+o),n+=1}return t}(t);if(0===o.size&&"singleline-basic"===n){return JSON.stringify(e).slice(1,-1).replace(/\x7f/g,"\\u007F")}const r=function(e,t,n){let o="";for(const r of e){const e=t.get(r);o+=e||Ge(r,n)}return o}(e,o,n);return"multiline-basic"===n?r.replace(/"""/g,'""\\"'):r}function Qe(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function et(t){const n=function(t){const n=rt(t);return{type:e.TableKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+2}},item:{type:e.Key,loc:{start:{line:1,column:1},end:{line:1,column:n.length+1}},value:t,raw:n}}}(t);return{type:e.Table,loc:y(n.loc),key:n,items:[]}}function tt(t){const n=function(t){const n=rt(t);return{type:e.TableArrayKey,loc:{start:{line:1,column:0},end:{line:1,column:n.length+4}},item:{type:e.Key,loc:{start:{line:1,column:2},end:{line:1,column:n.length+2}},value:t,raw:n}}}(t);return{type:e.TableArray,loc:y(n.loc),key:n,items:[]}}function nt(t,n){const o=function(t){const n=rt(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:r}=o.loc.end,l=r+1;return Re(n,{lines:0,columns:r+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:w(o.loc.start),end:w(n.loc.end)},key:o,equals:l,value:n}}function ot(e){return JSON.stringify(e).replace(/\x7f/g,"\\u007f")}function rt(e){return e.map(e=>b.test(e)?e:ot(e)).join(".")}function lt(t,n){return n?function(t,n){if(o=n,o.startsWith('"')&&!o.startsWith('"""'))return it(t,n);var o;if(function(e){return e.startsWith("'")&&!e.startsWith("'''")}(n)){if(!t.includes("'"))return function(t){const n=`'${t}'`;let o;if(n.includes("\n")){const e=n.split(/\r\n|\n/),t=e[e.length-1];o={line:e.length,column:t.length}}else o={line:1,column:n.length};return{type:e.String,loc:{start:{line:1,column:0},end:o},raw:n,value:t}}(t);if(!t.includes("'''")){return at(t,`'''${n.slice(1,-1)}'''`)}return it(t)}if(function(e){return e.startsWith("'''")}(n)){if(!t.includes("'''"))return at(t,n);return st(t,`"""${n.slice(3,-3)}"""`)}if(function(e){return e.startsWith('"""')}(n))return st(t,n);throw new Error(`Existing raw string value is not valid: ${n}`)}(t,n):it(t)}function it(t,n){let o="";return o=n?`"${Xe(t,n,"singleline-basic")}"`:ot(t),{type:e.String,loc:{start:{line:1,column:0},end:{line:1,column:o.length}},raw:o,value:t}}function st(t,n){const o=Xe(t,n,"multiline-basic");let r='"""'+(n.startsWith('"""\r\n')?"\r\n":n.startsWith('"""\n')?"\n":"")+o+'"""';const l=n.slice(3,-3);if(/(^|[^\\])(\\\\)*\\$/m.test(l)){const e=function(e,t){const n=function(e){const t=e.match(/\r\n|\n/);return"\r\n"===t?.[0]?"\r\n":"\n"}(e),o='"""';let r,l;(e=e.replace(/\r\n/g,"\n").replace(/\n/g,n)).startsWith(`${o}\\${n}`)?(r=4+n.length,l=`${o}\\${n}`):e.startsWith(`${o}${n}`)?(r=3+n.length,l=`${o}${n}`):(r=3,l=o);const i=e.length-3,s=e.slice(r,i).split(n),a=s[s.length-1],c=s.length>1&&/^[\t ]*$/.test(a),u=c?a:"",f=(c?s.slice(0,-1):s).map(e=>{if(/^[\t ]*$/.test(e))return{indent:e,content:"",trailingWs:"",hasBackslash:!1,isBlank:!0};let t=e,n=0;for(let e=t.length-1;e>=0&&"\\"===t[e];e--)n++;const o=n%2==1;o&&(t=t.slice(0,-1));const r=t.match(/^[\t ]*/)?.[0]??"",l=t.slice(r.length),i=l.match(/([\t ]+)$/),s=i?i[1]:"";return{indent:r,content:l.slice(0,l.length-s.length),trailingWs:s,hasBackslash:o,isBlank:!1}}),m=f.filter(e=>!e.isBlank),h=Math.max(...m.map(e=>e.content.length+e.trailingWs.length),1),d=m.filter(e=>e.hasBackslash),p=d[d.length-1]??m[m.length-1]??{indent:"",trailingWs:"",hasBackslash:!1,content:""},g=m[m.length-1]??p,w=[];{let e=[],t=0;for(const n of f)n.isBlank?e.push(n.indent):(t>0&&w.push(e),e=[],t++)}const y=m.some((e,t)=>!e.hasBackslash&&t<m.length-1),v=l===`${o}${n}`,b=v&&m.length>0?t.match(/^[\t ]*/)?.[0]??"":"",$=e=>{const t=e.match(/\S+| +/g)??[],n=[];let o=0;for(;o<t.length;){let e=t[o++];for(;o<t.length&&" "===t[o][0];){const n=t[o],r=t[o+1];if(!r){o++;break}if(!(e.length+n.length+r.length<=h)){e+=n,o++;break}e+=n+r,o+=2}n.push(e)}return 0===n.length&&n.push(""),n},T=[],k=[],S=new Set,I=new Set,A=new Map;let E=!1;if(!y||!t.includes(n)||"\r\n"!==n&&t.includes("\r\n")){const e=t.replace(/\r\n/g,"\\r\\n").replace(/\n/g,"\\n").slice(b.length);if(e.length>0){if(" "===e[0])return null;if(e.length-e.trimEnd().length!==g.trailingWs.length)return null}if(!y){let t=0,r=0;for(let n=0;n<m.length-1;n++){const o=m[n];if(!o.hasBackslash)break;const l=o.content+o.trailingWs;if(e.slice(r,r+l.length)!==l)break;t++,r+=l.length}let i=0,s=0;for(let n=m.length-1;n>=t;n--){const t=m[n],o=t.content+t.trailingWs;if(0===o.length)break;const l=e.length-s-o.length;if(!(l>=r&&e.slice(l,l+o.length)===o))break;i++,s+=o.length}if(i>0){const a=e.slice(r,e.length-s);if(0===a.length||" "!==a[0]){for(let e=0;e<t;e++){const n=m[e];if(k.push(`${n.indent}${n.content}${n.trailingWs}\\`),e<t-1&&e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}if(a.length>0){const e=$(a),n=e.join(""),o=/(?<!\\)\\n/.test(n);if(t>0&&!o){const e=t-1;if(e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}for(let n=0;n<e.length;n++){const r=e[n],l=t+n,i=l<m.length?m[l]:null,s=i?v&&0===l?b:i.indent:p.indent,c=r.length>0&&/\s$/.test(r)?"":a.endsWith(" ")?" ":"";if(k.push(`${s}${r}${c}\\`),n<e.length-1&&!o){const e=t+n;if(e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}}const r=m.length-i-1;if(!o&&r>=0&&r<w.length&&w[r].length>0)for(const e of w[r])k.push(e)}else if(t>0){const e=t-1;if(e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}const e=m.length-i;for(let t=e;t<m.length;t++){const n=m[t],o=t===m.length-1;if(t>e){const e=t-1;if(e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}k.push(o?`${n.indent}${n.content}${n.trailingWs}${n.hasBackslash&&""!==n.content?"\\":""}`:`${n.indent}${n.content}${n.trailingWs}\\`)}return!c||g.hasBackslash&&""===g.content?`${l}${k.join(n)}${o}`:`${l}${k.join(n)}${n}${u}${o}`}}const a=e.slice(r);if(t>0&&(r===e.length||a.length>0&&" "!==a[0])){for(let e=0;e<t;e++){const n=m[e];if(k.push(`${n.indent}${n.content}${n.trailingWs}\\`),e<t-1&&e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}if(r===e.length){const e=m[t-1],n=g.hasBackslash&&""!==e.content?"\\":"";k[k.length-1]=`${e.indent}${e.content}${g.trailingWs}${n}`}else{const e=$(a),n=e.join(""),o=/(?<!\\)\\n/.test(n),r=t-1;if(!o&&r<w.length&&w[r].length>0)for(const e of w[r])k.push(e);for(let n=0;n<e.length;n++){const r=n===e.length-1,l=e[n],i=t+n,s=i<m.length?m[i]:null,a=s?v&&0===i?b:s.indent:r?g.indent:p.indent;let c,u;if(r?(c=g.trailingWs,u=g.hasBackslash&&""!==g.content?"\\":""):(c=l.length>0&&/\s$/.test(l)?"":" ",u="\\"),k.push(`${a}${l}${c}${u}`),!r){const e=t+n;if(!o&&e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}}}return!c||g.hasBackslash&&""===g.content?`${l}${k.join(n)}${o}`:`${l}${k.join(n)}${n}${u}${o}`}}const r=$(e);for(const e of r)T.push(e)}else{E=!0;const e=t.split(n),o=e[0].slice(b.length);if(o.length>0&&" "===o[0])return null;const r=e[e.length-1];if(r.length>0&&r.length-r.trimEnd().length!==g.trailingWs.length)return null;for(let t=0;t<e.length;t++){const n=e[t],o=0===t?n.slice(b.length):n,r=o.match(/^[\t ]*/)?.[0]??"",l=$(o.slice(r.length)),i=T.length;I.add(i),t>0&&A.set(i,r);for(const e of l)T.push(e);t<e.length-1&&S.add(i+l.length-1)}}for(let e=0;e<T.length;e++){const t=e===T.length-1,n=S.has(e),o=t||n,r=e<m.length?m[e]:null,l=E&&I.has(e)&&e>0?A.get(e)??"":r?v&&0===e?b:r.indent:o?g.indent:p.indent,i=T[e];let s,a;if(o&&t?(s=g.trailingWs,a=g.hasBackslash&&""!==g.content?"\\":""):o?(s=g.trailingWs,a=""):(s=i.length>0&&/\s$/.test(i)?"":" ",a="\\"),k.push(`${l}${i}${s}${a}`),!t&&!n&&!E){const t=T.join("");if(!/(?<!\\)\\n/.test(t)&&e<w.length&&w[e].length>0)for(const t of w[e])k.push(t)}}return!c||g.hasBackslash&&""===g.content?`${l}${k.join(n)}${o}`:`${l}${k.join(n)}${n}${u}${o}`}(n,o);null!==e&&(r=e)}const i=ct(r);return{type:e.String,loc:{start:{line:1,column:0},end:i},raw:r,value:t}}function at(t,n){const o="'''"+(n.startsWith("'''\r\n")?"\r\n":n.startsWith("'''\n")?"\n":"")+t+"'''",r=ct(o);return{type:e.String,loc:{start:{line:1,column:0},end:r},raw:o,value:t}}function ct(e){if(e.includes("\n")){const t=e.split(/\r\n|\n/),n=t[t.length-1];return{line:t.length,column:n.length}}return{line:1,column:e.length}}function ut(t){const n=t.toString();return{type:e.Integer,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}function ft(t,n=1){let o;if(t===1/0)o="inf";else if(t===-1/0)o="-inf";else if(Number.isNaN(t))o="nan";else if(Object.is(t,-0))o="-0."+"0".repeat(Math.max(n,1));else{o=t.toString();const e=o.search(/[eE]/);if(-1!==e){const t=o.slice(0,e),r=o.slice(e),l=t.indexOf(".");if(-1===l)o=`${t}.${"0".repeat(Math.max(n,1))}${r}`;else{const e=t.length-l-1;o=e<n?`${t}${"0".repeat(n-e)}${r}`:`${t}${r}`}}else{const e=o.indexOf(".");if(-1===e)o+="."+"0".repeat(Math.max(n,1));else{const t=o.length-e-1;t<n&&(o+="0".repeat(n-t))}}}return{type:e.Float,loc:{start:{line:1,column:0},end:{line:1,column:o.length}},raw:o,value:t}}function mt(t){return{type:e.InlineItem,loc:y(t.loc),item:t,comma:!1}}function ht(e){return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode(e)}function dt(e){return 65279===e.charCodeAt(0)}function pt(e){return dt(e)?e.slice(1):e}const gt=!1,wt=!0,yt=!1,vt=!1,bt=!1;function $t(e,t){if(!e||"object"!=typeof e)return null;if(("InlineArray"===e.type||"InlineTable"===e.type)&&e.loc){const n=function(e,t){if(!e||!e.start||!e.end)return null;const n=t.split(/\r?\n/),o=e.start.line-1,r=e.end.line-1,l=e.start.column,i=e.end.column;let s="";if(o===r)s=n[o]?.substring(l,i+1)||"";else{n[o]&&(s+=n[o].substring(l));for(let e=o+1;e<r;e++)s+="\n"+(n[e]||"");n[r]&&(s+="\n"+n[r].substring(0,i+1))}const a=s.match(/^\[(\s*)/),c=s.match(/^\{(\s*)/);if(a)return a[1].length>0;if(c)return c[1].length>0;return null}(e.loc,t);if(null!==n)return n}if(e.items&&Array.isArray(e.items))for(const n of e.items){const e=$t(n,t);if(null!==e)return e;if(n.item){const e=$t(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const o=$t(e[n],t);if(null!==o)return o}return null}function Tt(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return kt(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return kt(e.items);if("KeyValue"===e.type&&e.value)return Tt(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=Tt(t);if(null!==e)return e}return null}function kt(e){if(0===e.length)return null;const t=e[e.length-1];return!(!t||"object"!=typeof t||!("comma"in t))&&!0===t.comma}function St(e){const t=e.indexOf("\n");return t>0&&"\r"===e[t-1]?"\r\n":"\n"}function It(e,t){if(e){if(e instanceof At)return e;{const n=function(e){if(!e||"object"!=typeof e)return{};const t=e=>"boolean"==typeof e?null:"expected boolean, got "+typeof e,n={newLine:e=>"string"==typeof e?null:"expected string, got "+typeof e,trailingNewline:e=>"boolean"==typeof e||"number"==typeof e?null:"expected boolean or number, got "+typeof e,trailingComma:t,bracketSpacing:t,leadingBom:t,inlineTableStart:e=>null==e||"number"==typeof e&&Number.isInteger(e)&&e>=0?null:"expected non-negative integer or undefined, got "+typeof e,truncateZeroTimeInDates:t,useTabsForIndentation:t,minimumDecimals:e=>null==e||"number"==typeof e&&Number.isInteger(e)&&e>=0?null:"expected non-negative integer or undefined, got "+typeof e},o={},r=[],l=[];for(const t in e){const i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0;if(i){const n=e[t],r=i(n);r?l.push(`${t} (${r})`):o[t]=n}else Object.prototype.hasOwnProperty.call(e,t)&&r.push(t)}if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Object.keys(n).join(", ")}`),l.length>0)throw new TypeError(`Invalid types for format properties: ${l.join(", ")}`);return o}(e);return new At(n.newLine??t.newLine,n.trailingNewline??t.trailingNewline,n.trailingComma??t.trailingComma,n.bracketSpacing??t.bracketSpacing,void 0!==n.inlineTableStart?n.inlineTableStart:t.inlineTableStart,n.truncateZeroTimeInDates??t.truncateZeroTimeInDates,n.useTabsForIndentation??t.useTabsForIndentation,n.minimumDecimals??t.minimumDecimals,n.leadingBom??t.leadingBom)}}return t}class At{newLine;trailingNewline;trailingComma;bracketSpacing;leadingBom;inlineTableStart;truncateZeroTimeInDates;useTabsForIndentation;minimumDecimals;constructor(e,t,n,o,r,l,i,s,a){this.newLine=e??"\n",this.trailingNewline=t??1,this.trailingComma=n??gt,this.bracketSpacing=o??wt,this.inlineTableStart=r??1,this.truncateZeroTimeInDates=l??yt,this.useTabsForIndentation=i??vt,this.minimumDecimals=s??0,this.leadingBom=a??bt}static default(){return new At("\n",1,gt,wt,1,yt,vt,0,bt)}static autoDetectFormat(e){return At.autoDetectFormatWithCst(e)}static autoDetectFormatWithCst(e,t){const n=At.default();n.leadingBom=dt(e);const o=pt(e);n.newLine=St(o),n.trailingNewline=function(e){let t=0,n=e.length;for(;n>0&&"\n"===e[n-1];)t++,n--,n>0&&"\r"===e[n-1]&&n--;return t}(o);try{const e=Array.isArray(t)?t:Array.from(t??me(o));n.trailingComma=function(e){for(const t of e){const e=Tt(t);if(null!==e)return e}return gt}(e),n.bracketSpacing=function(e,t){for(const n of t){const t=$t(n,e);if(null!==t)return t}return wt}(o,e)}catch(e){n.trailingComma=gt,n.bracketSpacing=wt}return n.useTabsForIndentation=function(e){const t=e.split(/\r?\n/);let n=0,o=0;for(const e of t)if(0!==e.length&&("\t"===e[0]?n++:" "===e[0]&&o++,n+o>=5))break;return n>o}(o),n.inlineTableStart=1,n.truncateZeroTimeInDates=yt,n.minimumDecimals=0,n}static autoDetectFormatWithAst(e,t){return At.autoDetectFormatWithCst(e,t)}}function Et(e){if(!a(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Ct(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function _t(e,t){if(0===t.inlineTableStart)return e;return e.items.filter(e=>{if(!l(e))return!1;const n=u(e.value),o=a(e.value)&&e.value.items.length>0&&e.value.items.every(e=>u(e.item));if(n||o){const n=Ot(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1}).forEach(t=>{Pe(e,e,t),u(t.value)?je(e,e,xt(t)):function(e){const t=Qe();for(const n of e.value.items){const o=tt(e.key.value);je(t,t,o);for(const e of n.item.items)je(t,o,e.item)}return qe(t),t.items}(t).forEach(t=>{je(e,e,t)})}),qe(e),e}function xt(e){const t=et(e.key.value);for(const n of e.value.items)je(t,t,n.item);return qe(t),t}function Dt(e){if(e.items.length>0){const t=e.items[e.items.length-1];e.loc.end.line=t.loc.end.line,e.loc.end.column=t.loc.end.column}else e.loc.end.line=e.key.loc.end.line,e.loc.end.column=e.key.loc.end.column}function Ot(e){return Math.max(0,e.length-1)}function Ft(e,t,n){for(let o=e.items.length-1;o>=0;o--){const r=e.items[o];if(l(r)&&u(r.value)){const o=[...e.key.item.value,...r.key.value];if(Ot(o)<(n.inlineTableStart??1)){const l=et(o);for(const e of r.value.items)je(l,l,e.item);Pe(e,e,r),Dt(e),t.push(l),Ft(l,t,n)}}}}function Mt(e,t=At.default()){e=Wt(e);const n=Qe();for(const o of Lt(e,t))je(n,n,o);return qe(n),_t(n,t),function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const o of e.items)if(l(o)&&u(o.value)){if(Ot(o.key.value)<t.inlineTableStart){const r=xt(o);Pe(e,e,o),je(e,e,r),Ft(r,n,t)}}else("Table"===o.type||r(o))&&Ft(o,n,t);for(const t of n)je(e,e,t);qe(e)}(n,t),function(e){let t=0,n=0;for(const o of e.items)0===n&&o.loc.start.line>1?t=1-o.loc.start.line:o.loc.start.line+t>n+2&&(t+=n+2-(o.loc.start.line+t)),Re(o,{lines:t,columns:0}),n=o.loc.end.line;return e}(n)}function*Lt(e,t){for(const n of Object.keys(e)){const o=e[n];if(void 0===o)continue;const r=Wt(o);void 0!==r&&(yield nt([n],Bt(r,t)))}}function Bt(t,n){const o=n.minimumDecimals??0;if(null===t)throw new Error('"null" values are not supported');if(void 0===t)throw new Error('"undefined" values are not supported inside arrays');return function(e){return"string"==typeof e}(t)?lt(t):function(e){return"bigint"==typeof e}(t)?ut(t):Se(t)?o>0?ft(t,o):ut(t):function(e){return"number"==typeof e&&(!Se(e)||!isFinite(e)||Object.is(e,-0))}(t)?ft(t,Math.max(o,1)):function(e){return"boolean"==typeof e}(t)?function(t){return{type:e.Boolean,loc:{start:{line:1,column:0},end:{line:1,column:t?4:5}},value:t}}(t):Ee(t)?function(t,n=!1){const o=t.constructor?.name??"",r="Temporal.PlainTime"===o||"PlainTime"===o,l="Temporal.PlainDateTime"===o||"PlainDateTime"===o;let i;if("Temporal.PlainDate"===o||"PlainDate"===o)i=Ce(t);else if(r)i=Ce(t);else if(l){if(n){const n=globalThis.Temporal;if(!n)throw new Error("Temporal API is not available in this runtime. Set temporal: false or use a runtime with Temporal support.");const o=n.PlainDate.from(t.toString().split("T")[0]);if(o.toString()+"T00:00:00"===t.toString().slice(0,19))return i=Ce(o),{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:i.length}},raw:i,value:o}}i=Ce(t)}else i=Ce(t);return{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:i.length}},raw:i,value:t}}(t,n.truncateZeroTimeInDates):Ie(t)?function(t,n=!1){n&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new P(t.toISOString().split("T")[0]));const o=t.toISOString();return{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:o.length}},raw:o,value:t}}(t,n.truncateZeroTimeInDates):Array.isArray(t)?function(t,n){const o={type:e.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of t){je(o,o,mt(Bt(e,n)))}return Ve(o,o,n.bracketSpacing),ze(o,o,n.trailingComma),qe(o),o}(t,n):function(t,n){if(t=Wt(t),!_e(t))return Bt(t,n);const o={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of Lt(t,n)){je(o,o,mt(e))}return Ve(o,o,n.bracketSpacing),ze(o,o,n.trailingComma),qe(o),o}(t,n)}function Wt(e){return e?Ie(e)||Ee(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const Nt=/(\r\n|\n)/g;function Ut(t,n){const o=[];function r(t){switch(t.type){case e.Document:for(let e=0;e<t.items.length;e++)r(t.items[e]);break;case e.Table:{const e=t;r(e.key);for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.TableKey:{const e=t,{start:n,end:l}=e.loc;jt(o,n.line,n.column,"["),jt(o,l.line,l.column-1,"]"),r(e.item);break}case e.TableArray:{const e=t;r(e.key);for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.TableArrayKey:{const e=t,{start:n,end:l}=e.loc;Zt(o,n.line,n.column,n.column+2,"[["),Zt(o,l.line,l.column-2,l.column,"]]"),r(e.item);break}case e.KeyValue:{const e=t,n=e.loc.start.line;jt(o,n,e.equals,"="),r(e.key),r(e.value);break}case e.Key:case e.String:case e.Integer:case e.Float:Kt(o,t.loc,t.raw);break;case e.Boolean:Kt(o,t.loc,t.value.toString());break;case e.DateTime:Kt(o,t.loc,t.raw);break;case e.InlineArray:{const e=t,{start:n,end:l}=e.loc;jt(o,n.line,n.column,"["),jt(o,l.line,l.column-1,"]");for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.InlineTable:{const e=t,{start:n,end:l}=e.loc;jt(o,n.line,n.column,"{"),jt(o,l.line,l.column-1,"}");for(let t=0;t<e.items.length;t++)r(e.items[t]);break}case e.InlineItem:{const e=t;if(r(e.item),e.comma){const t=e.loc.end;jt(o,t.line,t.column,",")}break}case e.Comment:Kt(o,t.loc,t.raw);break;default:{const e=t.type;throw new Error(`toTOML: Unrecognized node type: ${String(e)}`)}}}if(xe(t))for(const e of t)r(e);else r(t);if(n.useTabsForIndentation)for(let e=0;e<o.length;e++){const t=o[e],n=t.match(/^( +)/);if(n){const r=n[1],l="\t".repeat(r.length);o[e]=l+t.substring(r.length)}}return o.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function Kt(e,t,n){if(t.start.line===t.end.line){const o=Pt(e,t.start.line),r=o.substring(0,t.start.column),l=r.length<t.start.column?r.padEnd(t.start.column,k):r,i=o.substring(t.end.column);return void(e[t.start.line-1]=l+n+i)}const o=n.split(Nt).filter(e=>"\n"!==e&&"\r\n"!==e),r=t.end.line-t.start.line+1;if(o.length!==r)throw new Error(`Mismatch between location and raw string, expected ${r} lines for "${n}"`);for(let n=t.start.line;n<=t.end.line;n++){const r=Pt(e,n),l=n===t.start.line,i=n===t.end.line;let s="";if(l){const e=r.substring(0,t.start.column);s=e.length<t.start.column?e.padEnd(t.start.column,k):e}const a=i?r.substring(t.end.column):"";e[n-1]=s+o[n-t.start.line]+a}}function jt(e,t,n,o){const r=Pt(e,t),l=r.length<n?r.padEnd(n,k):r.substring(0,n),i=r.substring(n+1);e[t-1]=l+o+i}function Zt(e,t,n,o,r){const l=Pt(e,t),i=l.length<n?l.padEnd(n,k):l.substring(0,n),s=l.substring(o);e[t-1]=i+r+s}function Pt(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function Vt(t,n,o){for(const r of t.items){const t=r.item;if(t.value.type===e.InlineTable){const e=n.concat(t.key.value);o.add(Gt(e)),Vt(t.value,e,o)}}}function zt(t,n="",o={}){const{integersAsBigInt:r="asNeeded",temporal:l=!1}=o,i=ke(),s=new Set,a=new Set,c=new Set,u=new Set,f=new Set;let m=i,h=[];const d={tables:s,table_arrays:a,defined:c,implicit_tables:u,inline_tables:f};for(const n of t)switch(n.type){case e.Table:p(n);for(const t of n.items)t.type===e.KeyValue&&w(t);break;case e.TableArray:g(n);for(const t of n.items)t.type===e.KeyValue&&w(t);break;case e.KeyValue:w(n)}return i;function p(e){const t=e.key.item.value;try{Rt(i,[],t,e.type,d)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const o=Gt(t);s.add(o),c.add(o),m=Ht(i,t),h=t}function g(e){const t=e.key.item.value;try{Rt(i,[],t,e.type,d)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const o=Gt(t);a.add(o),c.add(o),m=function(e,t){const n=Jt(e,t.slice(0,-1)),o=Te(t);n[o]||(n[o]=[]);const r=ke();return n[Te(t)].push(r),r}(i,t),h=t}function w(t){const o=t.key.value;try{Rt(m,h,o,t.type,d)}catch(e){const o=e;throw new v(n,t.key.loc.start,o.message)}if(o.length>1)for(let e=1;e<o.length;e++){const t=Gt(h.concat(o.slice(0,e)));u.add(t),c.add(t)}let i;try{i=qt(t.value,{integersAsBigInt:r,temporal:l})}catch(e){const o=e;throw new v(n,t.value.loc.start,o.message)}if(t.value.type===e.InlineTable){const e=h.concat(o);f.add(Gt(e)),Vt(t.value,e,f)}(o.length>1?Ht(m,o.slice(0,-1)):m)[Te(o)]=i,c.add(Gt(h.concat(o)))}}function qt(t,n={}){const{integersAsBigInt:o="asNeeded",temporal:r=!1}=n;switch(t.type){case e.InlineTable:const n=ke(),l=new Set,i=new Map;return t.items.forEach(({item:e})=>{const t=e.key.value,s=qt(e.value,{integersAsBigInt:o,temporal:r}),a=Gt(t);if(l.has(a))throw new Error(`Duplicate key "${a}" in inline table`);for(let e=1;e<t.length;e++){const n=Gt(t.slice(0,e));if(l.has(n))throw new Error(`Key "${a}" conflicts with key: "${n}"`)}if(i.has(a)){const e=i.get(a);throw new Error(`Key "${a}" conflicts with key: "${e}"`)}l.add(a);for(let e=1;e<t.length;e++){const n=Gt(t.slice(0,e));i.has(n)||i.set(n,a)}(t.length>1?Ht(n,t.slice(0,-1)):n)[Te(t)]=s}),n;case e.InlineArray:return t.items.map(e=>qt(e.item,{integersAsBigInt:o,temporal:r}));case e.DateTime:if(r){if(void 0===globalThis.Temporal)throw new Error("Temporal API is not available in this runtime. Set temporal: false or use a runtime with Temporal support.");return function(e){if(e.constructor?.name?.startsWith?.("Temporal.")||"PlainDate"===e.constructor?.name||"PlainTime"===e.constructor?.name||"PlainDateTime"===e.constructor?.name||"ZonedDateTime"===e.constructor?.name)return e;const t=globalThis.Temporal;if(e instanceof P)return t.PlainDate.from(e.toISOString());if(e instanceof V)return t.PlainTime.from(e.toISOString());if(e instanceof z)return t.PlainDateTime.from(e.toISOString().replace(" ","T"));if(e instanceof q){const n=e.toISOString().replace(" ","T"),o=n.match(/([+-]\d{2}:\d{2}|Z)$/),r=o?o[1]:"Z",l=n.replace(/([+-]\d{2}:\d{2}|Z)$/,""),i="Z"===r?"+00:00":r;return t.ZonedDateTime.from(`${l}${r}[${i}]`)}return t.PlainDateTime.from(e.toISOString().replace("Z",""))}(t.value)}return t.value;case e.String:return t.value;case e.Integer:return function(e,t="asNeeded"){const n=e.replace(/_/g,"");let o,r=n;if(/^[+-]?0x/i.test(n)||/^[+-]?0o/i.test(n)||/^[+-]?0b/i.test(n)){const e="+"===n[0]||"-"===n[0]?n[0]:"";r=e+n.slice(e?1:0).toLowerCase()}try{o=BigInt(r)}catch{return Number(n)}return!0===t?o:!1===t||o>=BigInt(Number.MIN_SAFE_INTEGER)&&o<=BigInt(Number.MAX_SAFE_INTEGER)?Number(o):o}(t.raw,o);case e.Float:case e.Boolean:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function Rt(t,n,o,r,l){const i=n.length>0?Gt(n):"",s=new Array(o.length);let a=i;for(let e=0;e<o.length;e++)a=a?a+"."+o[e]:o[e],s[e]=a;const c=s[o.length-1];if(r===e.KeyValue&&o.length>1)for(let e=1;e<o.length;e++){const t=s[e-1];if(l.inline_tables.has(t))throw new Error(`Cannot extend inline table at ${t}`)}if((r===e.Table||r===e.TableArray)&&l.inline_tables.has(c))throw new Error(`Cannot extend inline table at ${c}`);if(r===e.Table||r===e.TableArray)for(let e=1;e<o.length;e++){const t=s[e-1];if(l.inline_tables.has(t))throw new Error(`Cannot extend inline table at ${t}`)}if(r===e.KeyValue&&o.length>1)for(let e=1;e<o.length;e++){const t=s[e-1];if(l.table_arrays.has(t))throw new Error(`Cannot traverse Array of Tables at ${t}`)}if((r===e.Table||r===e.TableArray)&&l.implicit_tables.has(c))throw new Error(`Implicit table already defined: ${c}`);if(r===e.KeyValue&&l.implicit_tables.has(c))throw new Error(`Table already defined: ${c}`);if(r===e.KeyValue&&o.length>1)for(let e=1;e<=o.length;e++){const t=s[e-1];if(l.tables.has(t))throw new Error(`Cannot extend explicit table ${t} with dotted keys`)}let u=0;for(const e of o){if(!De(t,e))return;if(Yt(t[e]))throw new Error(`Value already defined for ${s[u]}`);const n=s[u];if(Array.isArray(t[e])&&!l.table_arrays.has(n))throw new Error(`Cannot add to static array at ${n}`);const r=u++<o.length-1;t=Array.isArray(t[e])&&r?Te(t[e]):t[e]}const f=c;if(t&&r===e.Table&&l.defined.has(f))throw new Error(`Table already defined: ${f}`);if(t&&r===e.KeyValue&&1===o.length&&l.defined.has(f)&&!Yt(t))throw new Error(`Table already defined: ${f}`);if(t&&r===e.TableArray&&!l.table_arrays.has(f))throw new Error(`Cannot add Array of Tables to table at ${f}`)}function Ht(e,t){const n=Jt(e,t.slice(0,-1)),o=Te(t);return n[o]||(n[o]=ke()),n[o]}function Jt(e,t){return t.reduce((e,t)=>(e[t]||(e[t]=ke()),Array.isArray(e[t])?Te(e[t]):e[t]),e)}function Yt(e){return"object"!=typeof e&&!Ie(e)}function Gt(e){return e.join(".")}var Xt;function Qt(e){return e.type===Xt.Remove}function en(e,t,n=[]){return e===t||(r=t,Ee(o=e)&&Ee(r)?o.toString()===r.toString():Ie(o)&&Ie(r)&&o.toISOString()===r.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let o=[];const r=e.map(Fe),l=t.map(Fe);l.forEach((i,s)=>{const a=s>=r.length;if(!a&&r[s]===i)return;const c=r.indexOf(i,s+1);if(!a&&c>-1){o.push({type:Xt.Move,path:n,from:c,to:s});const e=r.splice(c,1);return void r.splice(s,0,...e)}const u=!l.includes(r[s]);if(!a&&u)return Me(o,en(e[s],t[s],n.concat(s))),void(r[s]=i);o.push({type:Xt.Add,path:n.concat(s)}),r.splice(s,0,i)});for(let e=l.length;e<r.length;e++)o.push({type:Xt.Remove,path:n.concat(e)});return o}(e,t,n):_e(e)&&_e(t)?function(e,t,n=[]){let o=[];const r=Object.keys(e),l=r.map(t=>Fe(e[t])),i=Object.keys(t),s=i.map(e=>Fe(t[e])),a=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=r[l.indexOf(e)];return!i.includes(n)};return r.forEach((r,c)=>{const u=n.concat(r);if(i.includes(r))Me(o,en(e[r],t[r],u));else if(a(l[c],s)){const e=i[s.indexOf(l[c])];o.push({type:Xt.Rename,path:n,from:r,to:e})}else o.push({type:Xt.Remove,path:u})}),i.forEach((e,t)=>{r.includes(e)||a(s[t],l)||o.push({type:Xt.Add,path:n.concat(e)})}),o}(e,t,n):[{type:Xt.Edit,path:n}];var o,r}function tn(e,t){if(!t.length)return c(e)&&l(e.item)?e.item:e;if(l(e))return tn(e.value,t);const i={};let s;if(m(e)&&e.items.some((a,u)=>{try{let f=[];if(l(a))f=a.key.value;else if(o(a))f=a.key.item.value;else if(r(a)){f=a.key.item.value;const e=Fe(f);i[e]||(i[e]=0);const t=i[e]++;f=f.concat(t)}else c(a)&&l(a.item)?f=a.item.key.value:c(a)&&(f=[u]);if(f.length&&Oe(f,t.slice(0,f.length))){const i=t.slice(f.length);if(n(e)&&r(a)&&i.length>0){const t=a.key.item.value,n=e,l=n.items.findIndex((e,n)=>n>u&&r(e)&&Oe(e.key.item.value,t)),c=-1===l?n.items.length:l,f=n.items.slice(u+1,c);s=function(e,t,n,l){try{return tn(e,t)}catch{}const i={};for(const e of l){let l=[];if(o(e)){const t=e.key.item.value;t.length>n.length&&Oe(t.slice(0,n.length),n)&&(l=t.slice(n.length))}else if(r(e)){const t=e.key.item.value;if(t.length>n.length&&Oe(t.slice(0,n.length),n)){const e=t.slice(n.length),o=Fe(e);i[o]||(i[o]=0);const r=i[o]++;l=e.concat(r)}}if(l.length&&Oe(l,t.slice(0,l.length)))try{return tn(e,t.slice(l.length))}catch{}}throw new Error(`Node not found at (aot scope) ${t.join(".")}`)}(a,i,t,f)}else s=c(a)&&l(a.item)?t.length===f.length?a:tn(a.item.value,i):c(a)&&t.length>f.length?tn(a.item,i):tn(a,i);return!0}return!1}catch(e){return!1}}),!s)throw new Error(`Node not found at ${t.join(".")}`);return s}function nn(e,t){try{return tn(e,t)}catch(e){}}function on(e,t){let n,o=t;for(;o.length&&!n;)o=o.slice(0,-1),n=nn(e,o);if(!n)throw new Error(`Parent not found for ${t.join(".")}`);return n}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(Xt||(Xt={}));const rn=new WeakMap,ln=new WeakMap;function sn(e,t){const n=e[t].loc.end.line;for(let o=t+1;o<e.length;o++){const t=e[o];if(f(t)&&t.loc.start.line===n)return t;if(!f(t)&&t.loc.start.line>n)return}}function an(e,t,n){for(let o=t+n;o>=0&&o<e.length;o+=n)if(!f(e[o]))return o}function cn(e,t,n){ln.has(e)||ln.set(e,e.loc.start.column);const o=e.loc.start.column+n,r=Math.max(t,o)-o;0!==r&&(e.loc.start.column+=r,e.loc.end.column+=r)}function un(e,t,n){if(!m(e)||0===n)return;const o=e.items,r=o.indexOf(t);if(r<0)return;const l=sn(o,r);l&&function(e,t){ln.set(t,t.loc.start.column),rn.set(t,t.loc.start.column-e.loc.end.column)}(t,l)}function fn(e,t=[]){for(const n of e.items)f(n)?t.push(n):(o(n)||r(n))&&fn(n,t);return t}function mn(e,t=new Set){for(const n of e.items)l(n)&&u(n.value)&&n.loc.start.line===n.loc.end.line?t.add(n.loc.end.line):(o(n)||r(n))&&mn(n,t);return t}function hn(e){for(const t of e.items)(o(t)||r(t))&&hn(t);let t=e.loc.end.line,n=e.loc.end.column;const l=(e,o)=>{(e>t||e===t&&o>n)&&(t=e,n=o)};(o(e)||r(e))&&l(e.key.loc.end.line,e.key.loc.end.column);for(const t of e.items)l(t.loc.end.line,t.loc.end.column);e.loc.end.line=t,e.loc.end.column=n}function dn(e,t,n){const o=n.newLine,r=t.match(/(?:\r\n|\n)+$/u),l=r?r[0]:"",i=l?t.slice(0,-l.length):t,s=i.length?i.split(o):[],a=mn(e),c=(e,t)=>{const n=e.lastIndexOf(t.raw);return n>=0?n:t.loc.start.column},u=fn(e).filter(e=>{const t=s[e.loc.start.line-1]||"",n=c(t,e),o=t.slice(0,n);return o.trim().length>0&&/\s{2,}$/u.test(o)}).sort((e,t)=>e.loc.start.line-t.loc.start.line),f=[];let m=[];for(const e of u){const t=m[m.length-1];t&&e.loc.start.line!==t.loc.start.line+1?(m.length>0&&f.push(m),m=[e]):m.push(e)}m.length>0&&f.push(m);for(const e of f){if(e.length<2)continue;let t=ln.get(e[0])??e[0].loc.start.column;const n=new Map;for(const t of e){const e=ln.get(t)??t.loc.start.column;n.set(e,(n.get(e)||0)+1)}let o=1;for(const[e,r]of n)r>o&&(o=r,t=e);const r=Math.max(...e.map(e=>{const t=s[e.loc.start.line-1]||"",n=c(t,e);return t.slice(0,n).trimEnd().length})),l=Math.min(...e.map(e=>{const t=s[e.loc.start.line-1]||"",n=c(t,e),o=t.slice(0,n).trimEnd();return Math.max(1,n-o.length)}));let i=l;const u=e.filter(e=>rn.has(e)),f=e.some(e=>!a.has(e.loc.start.line));if(u.length>0&&f){const t=Math.min(...e.map(e=>{if(rn.has(e))return rn.get(e)||1;const t=s[e.loc.start.line-1]||"",n=c(t,e),o=t.slice(0,n).trimEnd();return Math.max(1,n-o.length)}));i=Math.min(i,t)}if(t<r+1){const e=r+i;t=Math.max(t,e)}for(const n of e){const e=n.loc.start.line-1,o=s[e]||"",r=c(o,n),l=o.slice(0,r).trimEnd(),i=Math.max(t,l.length+1);if(r!==i){const t=" ".repeat(i-l.length);s[e]=l+t+n.raw}n.loc.start.column!==i&&(n.loc.start.column=i,n.loc.end.column=i+n.raw.length)}}return hn(e),s.join(o)+l}function pn(e,t,n){const o=Array.from(me(pt(e))),r=It(n,At.autoDetectFormatWithCst(e,o)),l=wn(o,t,r).tomlString;return r.leadingBom?`\ufeff${l}`:l}function gn(e,t=new WeakSet){if(null==e||"object"!=typeof e)return!1;if(Ee(e))return!0;if(t.has(e))return!1;t.add(e);for(const n of Object.values(e))if(gn(n,t))return!0;return!1}function wn(t,i,s){const f=[...t],p=gn(i);let g=1,w=0;for(const e of f){const t=e.loc.end;(t.line>g||t.line===g&&t.column>w)&&(g=t.line,w=t.column)}const y=zt(f,"",{temporal:p}),v={type:e.Document,loc:{start:{line:1,column:0},end:{line:g,column:w}},items:f},$=Mt(i,It({...s,inlineTableStart:void 0},s)),T=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(Qt(n)){let o=t+1;for(;o<e.length;){const r=e[o];if(Qt(r)&&r.path[0]===n.path[0]&&r.path[1]>n.path[1]){e.splice(o,1),e.splice(t,0,r),t=-1;break}o++}}}return e}(en(y,zt($.items,"",{temporal:p})));if(0===T.length)return{tomlString:Ut(f,s),document:v};const k=function(e,t,i,s,f=!1){return i.forEach(i=>{if(function(e){return e.type===Xt.Add}(i)){let h=tn(t,i.path);const p=i.path.slice(0,-1);let g,w=Te(i.path),y=r(h);if(Se(w)&&!y&&!Se(Te(p))){const t=nn(e,p.concat(0));t&&r(t)&&(y=!0)}if(y&&!r(h)){const e=p.filter(e=>"string"==typeof e);let n=zt(t.items,"",{temporal:f});for(const e of i.path)n=n?.[e];if(void 0!==n){const t=tt(e),o=Mt(n,s);for(const e of o.items)je(t,t,e,void 0);qe(t),h=t}}if(o(h))g=e;else if(y){g=e;const t=e,n=nn(t,p.concat(w-1)),o=nn(t,p.concat(w));w=o?t.items.indexOf(o):n?t.items.indexOf(n)+1:t.items.length}else g=on(e,i.path),l(g)?g=g.value:c(g)&&l(g.item)?g=g.item.value:c(g)&&u(g.item)&&(g=g.item);if(a(g)){const t=nn(e,p),n=nn(e,p.slice(0,-1));if(t&&l(t)&&n){const e=function(e,t,n){if(!a(e)&&!u(e))return 0;const o=d(t.loc),r=n>0,l=n<e.items.length,i=n===e.items.length,s=!!c(t)&&t.comma,f=r&&s&&!l&&i;return o.columns+(r||l?2:0)+(s?1+(f?-1:0):0)}(g,h,w);0!==e&&function(e,t,n){if(!m(e))return;const o=e.items,r=o.indexOf(t);if(r<0)return;const l=sn(o,r);if(!l)return;const i=l.loc.start.column,s=l.loc.start.line,a=[an(o,r,-1),an(o,r,1)];for(const e of a){if(null==e)continue;const t=sn(o,e);if(t&&1===Math.abs(t.loc.start.line-s)&&t.loc.start.column===i)return void cn(l,t.loc.start.column,n)}}(n,t,e)}}if(r(g)||a(g)||n(g)){if(a(g)){const e=Et(g);c(h)&&(h.comma=e)}if(void 0!==s.inlineTableStart&&s.inlineTableStart>0&&n(g)&&o(h)){const t=vn(h,e,s);je(e,g,h,w);for(const n of t)je(e,e,n,void 0)}else{let t=w;if(n(g)&&l(h)){const e=g.items.findIndex(e=>o(e)||r(e));-1!==e&&(t=e)}je(e,g,h,t)}}else if(u(g)){const t=Ct(g);if(l(h)){const n=mt(h);n.comma=t,je(e,g,n)}else je(e,g,h)}else if(void 0!==s.inlineTableStart&&s.inlineTableStart>0&&l(h)&&u(h.value)&&o(g)){Ot([...g.key.item.value,...h.key.value])<s.inlineTableStart?function(e,t,n,o){const r=t.key.item.value,i=[...r,...e.key.value],s=et(i);if(u(e.value))for(const t of e.value.items)c(t)&&l(t.item)&&je(n,s,t.item,void 0);je(n,n,s,void 0),Dt(t);const a=vn(s,n,o);for(const e of a)je(n,n,e,void 0)}(h,g,e,s):je(e,g,h)}else if(0===s.inlineTableStart&&l(h)&&u(h.value)&&n(g))je(e,g,h,void 0,!0);else{let t=h;c(h)&&(o(g)||n(g))&&(t=h.item),je(e,g,t)}}else if(function(e){return e.type===Xt.Edit}(i)){let n,r=tn(e,i.path),h=tn(t,i.path);const p=nn(e,i.path.slice(0,-1)),g=function(e,t){for(let n=t.length-1;n>0;n--){const o=nn(e,t.slice(0,n));if(!o||!l(o)||!u(o.value))continue;const r=nn(e,t.slice(0,n-1));if(r&&m(r))return{container:r,row:o}}}(e,i.path);if(l(r)&&l(h))yn(r.value,h.value),p&&function(e,t,n,o){if(!m(e))return;const r=e.items,l=r.indexOf(t);if(l<0)return;const i=sn(r,l);if(!i)return;if(n.loc.start.line!==n.loc.end.line)return;if(o.loc.start.line!==o.loc.end.line)return;const s=i.loc.start.column,a=i.loc.start.line,c=[an(r,l,-1),an(r,l,1)];let u;for(const e of c){if(null==e)continue;const t=sn(r,e);if(t&&1===Math.abs(t.loc.start.line-a)&&t.loc.start.column===s){u=t.loc.start.column;break}}if(null==u)return;const f=d(n.loc);cn(i,u,d(o.loc).columns-f.columns)}(p,r,r.value,h.value),n=r,r=r.value,h=h.value;else if(l(r)&&c(h)&&l(h.item))n=r,r=r.value,h=h.item.value;else if(c(r)&&l(r.item)&&l(h)){const e=r.item;yn(e.value,h.value),n=e,r=e.value,h=h.value}else if(c(r)&&c(h)&&l(r.item)&&l(h.item))yn(r.item.value,h.item.value),n=r.item,r=r.item.value,h=h.item.value;else if(o(r)){let o=zt(t.items,"",{temporal:f});for(const e of i.path)o=o?.[e];if(void 0!==o){const t=r.key.item.value,n=t.slice(-1),l=t.slice(0,-1),a=on(e,i.path),c=Mt({[n[0]]:o},s).items[0];if(l.length>0){const t=et(l);je(e,t,c,0),Ke(e,a,r,t)}else Ke(e,a,r,c);return}n=on(e,i.path)}else if(n=on(e,i.path),l(n)){const t=i.path.slice(0,-1),o=tn(e,t);l(o)&&a(o.value)&&(n=o.value)}if(g){const e=d(r.loc),t=d(h.loc).columns-e.columns;0!==t&&un(g.container,g.row,t)}Ke(e,n,r,h)}else if(Qt(i)){const t=nn(e,i.path);if(t){let n=on(e,i.path);l(n)&&(n=n.value),c(n)&&l(n.item)&&(n=n.item.value),c(n)&&u(n.item)&&(n=n.item),m(n)&&!n.items.includes(t)&&(n=e),Pe(e,n,t)}else{if(nn(e,i.path.concat(0))){let t;for(;t=nn(e,i.path.concat(0));)Pe(e,e,t)}else{const t=function(e,t){const n=[];for(const i of e.items){let e;l(i)?e=i.key.value:(o(i)||r(i))&&(e=i.key.item.value),e&&Oe(e.slice(0,t.length),t)&&n.push(i)}return n}(e,i.path);if(t.length>0)for(const n of t)Pe(e,e,n);else tn(e,i.path)}}}else if(function(e){return e.type===Xt.Move}(i)){let t=nn(e,i.path);if(t){h(t)&&(t=t.item),l(t)&&(t=t.value);const n=t.items[i.from];Pe(e,t,n),je(e,t,n,i.to)}else{const t=tn(e,i.path.concat(i.from));Pe(e,e,t);const n=nn(e,i.path.concat(i.to)),o=n?e.items.indexOf(n):e.items.length;je(e,e,t,o)}}else if(function(e){return e.type===Xt.Rename}(i)){let n=tn(e,i.path.concat(i.from)),o=tn(t,i.path.concat(i.to));h(n)&&(n=n.item),h(o)&&(o=o.item),o.key.raw=(p=n.key.raw,o.key.value.map(e=>b.test(e)?e:`"${Xe(e,p,"singleline-basic")}"`).join(".")),o.key.loc.end.column=o.key.loc.start.column+o.key.raw.length,Ke(e,n,n.key,o.key)}var p}),qe(e),e}(v,$,T,s,p);return{tomlString:dn(k,Ut(k.items,s),s),document:k}}function yn(e,t){if(i(e)&&i(t)){const n=lt(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(s(e)&&s(t)){const n=e.raw,o=t.value;if(Ee(o)){let e=Ce(o);if(n.includes(" ")&&e.includes("T")&&(e=e.replace("T"," ")),/(?:\+00:00|-00:00)/.test(n)&&e.endsWith("Z")){const t=n.match(/([+-]00:00)/)[1];e=e.replace(/Z$/,t)}t.raw=e,t.loc.end.column=t.loc.start.column+t.raw.length}else{const e=Z.createDateWithOriginalFormat(o,n);t.value=e,t.raw=e.toISOString(),t.loc.end.column=t.loc.start.column+t.raw.length}}if(a(e)&&a(t)){const n=Et(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=Ct(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function vn(e,t,n){const o=[],r=(e,o)=>{for(let i=e.items.length-1;i>=0;i--){const s=e.items[i];if(l(s)&&u(s.value)){const a=[...e.key.item.value,...s.key.value];if(Ot(a)<(n.inlineTableStart??1)&&0!==n.inlineTableStart){const n=et(a);for(const e of s.value.items)c(e)&&l(e.item)&&je(t,n,e.item,void 0);e.items.splice(i,1),Dt(e),o.push(n),r(n,o)}}}};return r(e,o),o}function bn(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}class $n{_cst;_currentTomlString;_format;_integersAsBigInt;_temporal;constructor(e,t){const n="string"==typeof e?e:ht(e),o=pt(n);this._currentTomlString=o,this._cst=Array.from(me(o)),this._integersAsBigInt=t?.integersAsBigInt??"asNeeded",this._temporal=t?.temporal??!1,this._format=At.autoDetectFormatWithCst(n,this._cst)}get toTomlString(){return this._format.leadingBom?`\ufeff${this._currentTomlString}`:this._currentTomlString}get toJsObject(){const e=zt(this._cst,this._currentTomlString,{integersAsBigInt:this._integersAsBigInt,temporal:this._temporal});return this._temporal?e:Tn(e)}get cst(){return this._cst}patch(e,t){const n=It(t,this._format),{tomlString:o,document:r}=wn(this._cst,e,n);this._cst=r.items,this._format=n,this._currentTomlString=o}update(e){const t=pt(e);if(t===this._currentTomlString)return void(this._format.leadingBom=dt(e));const n=this._currentTomlString.split(this._format.newLine),o=St(t),r=t.split(o);let l=0;for(;l<n.length&&l<r.length&&n[l]===r[l];)l++;let i=0;if(l<n.length&&l<r.length){const e=n[l],t=r[l];for(let n=0;n<Math.max(e.length,t.length);n++)if(e[n]!==t[n]){i=n;break}}let s=l+1;const{truncatedCst:a,lastEndPosition:c}=function(e,t,n){const o={line:t,column:n},r=[];let l=null;for(const t of e){const e=bn(t.loc.end,o)<0,n=bn(t.loc.start,o)<0;if(!e){if(n&&!e)break;break}r.push(t),l=t.loc.end}return{truncatedCst:r,lastEndPosition:l}}(this._cst,s,i),u=c?c.line:1,f=c?c.column+1:0,m=r.slice(u-1);m.length>0&&f>0&&(m[0]=m[0].substring(f));const h=m.join(this._format.newLine);this._cst=Array.from(function*(e,t){for(const t of e)yield t;const n=new B(C(t));for(;!n.next().done;){const e=be(n,t);for(const t of e)yield t}}(a,h)),this._currentTomlString=t,this._format=At.autoDetectFormatWithCst(e,this._cst)}overwrite(e){const t=pt(e);t!==this._currentTomlString?(this._cst=Array.from(me(t)),this._currentTomlString=t,this._format=At.autoDetectFormatWithCst(e,this._cst)):this._format.leadingBom=dt(e)}}function Tn(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Tn);if(e&&"object"==typeof e){const t={};for(const[n,o]of Object.entries(e))t[n]=Tn(o);return t}return e}function kn(e,t){const n=pt("string"==typeof e?e:ht(e));return zt(me(n),n,{integersAsBigInt:t?.integersAsBigInt??"asNeeded",temporal:t?.temporal??!1})}function Sn(e,t){const n=It(t,At.default()),o=Ut(Mt(e,n).items,n);return n.leadingBom?`\ufeff${o}`:o}export{P as LocalDate,z as LocalDateTime,V as LocalTime,q as OffsetDateTime,$n as TomlDocument,At as TomlFormat,kn as parse,pn as patch,Sn as stringify};
1
+ //! @decimalturn/toml-patch v3.0.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ function e(e){return e.type===`Document`}function t(e){return e.type===`Table`}function n(e){return e.type===`TableKey`}function r(e){return e.type===`TableArray`}function i(e){return e.type===`TableArrayKey`}function a(e){return e.type===`KeyValue`}function o(e){return e.type===`String`}function s(e){return e.type===`Float`}function c(e){return e.type===`DateTime`}function l(e){return e.type===`InlineArray`}function u(e){return e.type===`InlineItem`}function d(e){return e.type===`InlineTable`}function f(e){return e.type===`Comment`}function p(n){return e(n)||t(n)||r(n)||d(n)||l(n)}function m(e){return n(e)||i(e)||u(e)}function h(e){return a(e)||t(e)||r(e)||f(e)}function g(e){return{lines:e.end.line-e.start.line+1,columns:e.end.column-e.start.column}}function _(e,t){let n=Array.isArray(e)?e:y(e);if(n.length===0)return{line:1,column:t};let r=0,i=n.length-1;for(;r<i;){let e=r+i>>>1;n[e]<t?r=e+1:i=e}n[r]<t&&r++;let a=r+1;return{line:a,column:t-(n[a-2]+1||0)}}function v(e,t){let n=y(e),r=n[t.line-2]===void 0?0:n[t.line-2]+1,i=n[t.line-1]||e.length;return e.substring(r,i)}function y(e){let t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===10?t.push(n):r===13&&(e.charCodeAt(n+1)===10?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function b(e){return{line:e.line,column:e.column}}function x(e){return{start:b(e.start),end:b(e.end)}}function S(){return{line:1,column:0}}var C=class extends Error{line;column;constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){let n=v(e,t),i=`${w(t.column)}^`;n&&(r+=`${n}\n${i}\n`)}r+=n,super(r),this.line=t.line,this.column=t.column}};function w(e,t=` `){return t.repeat(e)}const T=/^[\w-]+$/,ee=/[\w,\d,",',+,\-,_]/;function*E(e){let t=e.length,n=0,r=[],i=(e,t)=>({start:_(r,e),end:_(r,t)});for(;n<t;){let c=e.charCodeAt(n);if((c<=31||c===127)&&c!==9&&c!==13&&c!==10)throw new C(e,_(r,n),`Control char 0x${c.toString(16).toUpperCase().padStart(2,`0`)} not allowed`);if(c===13&&(n+1>=t||e.charCodeAt(n+1)!==10))throw new C(e,_(r,n),`Standalone CR; must be CRLF or LF`);if(c!==32&&c!==9&&c!==13)if(c===10)r.push(n);else if(c===91||c===93)yield{type:`Bracket`,raw:e[n],loc:i(n,n+1)};else if(c===123||c===125)yield{type:`Curly`,raw:e[n],loc:i(n,n+1)};else if(c===61)yield{type:`Equal`,raw:`=`,loc:i(n,n+1)};else if(c===44)yield{type:`Comma`,raw:`,`,loc:i(n,n+1)};else if(c===46)yield{type:`Dot`,raw:`.`,loc:i(n,n+1)};else if(c===35)yield a();else{let t=D(e,n,`'`)||D(e,n,`"`);t?yield o(t):yield s()}n++}function a(){let a=n;for(;n+1<t;){let t=e.charCodeAt(n+1);if(t===10||t===13)break;n++;let i=e.charCodeAt(n);if((i<=31||i===127)&&i!==9)throw new C(e,_(r,n),`Control char 0x${i.toString(16).toUpperCase().padStart(2,`0`)} not allowed`)}return{type:`Comment`,raw:e.slice(a,n+1),loc:i(a,n+1)}}function o(a){let o=n,s=a+a+a;for(n+=3;n<t;){if(D(e,n,a)){let t=3;for(;e[n+t]===a;)t++;if(t>=6)throw new C(e,_(r,n),`Invalid multiline string: ${t} consecutive ${a} characters`);if(t===3){n+=2;break}n+=t-3,n+=2;break}let i=e.charCodeAt(n);if(i===13&&(n+1>=t||e.charCodeAt(n+1)!==10))throw new C(e,_(r,n),`Standalone CR in multiline string; must be CRLF or LF`);if((i<=31||i===127)&&i!==9&&i!==10&&i!==13){let t=a===`"`?`multiline basic strings`:`multiline literal strings`,o=`0x${i.toString(16).toUpperCase().padStart(2,`0`)}`,s=``;i===0?s=`Null`:i===127&&(s=`DEL`);let c=s?`${s} (${o}) not allowed in ${t}`:`Control char ${o} not allowed in ${t}`;throw new C(e,_(r,n),c)}i===10&&r.push(n),n++}if(n>=t){if(a===`"`){let i=0,a=t-1;for(;a>=0&&e[a]===`\\`;)i++,a--;if(i>0&&i%2!=0)throw new C(e,_(r,n),`Unterminated multiline ${s} (possible escape issue)`)}throw new C(e,_(r,n),`Unterminated multiline ${s}`)}return{type:`Literal`,raw:e.slice(o,n+1),loc:i(o,n+1)}}function s(){let a=e[n];if(!ee.test(a))throw new C(e,_(r,n),`Unexpected char "${a}"`);let o=n,s=a===`"`,c=a===`'`;for(;n<t&&!(n+1>=t);){let i=e.charCodeAt(n+1);if(!(s||c)&&(i===32||i===9||i===10||i===13||i===44||i===46||i===93||i===125||i===61||i===35))break;if(n++,!(s||c)){let t=e.charCodeAt(n);if(t<=31||t===127)throw new C(e,_(r,n),`Control char 0x${t.toString(16).toUpperCase().padStart(2,`0`)} not allowed in unquoted value`)}if(s||c){let t=e.charCodeAt(n);if((t<=31||t===127)&&t!==9){let i=s?`basic strings`:`literal strings`,a=`0x${t.toString(16).toUpperCase().padStart(2,`0`)}`,o=``;t===10?o=`Newline`:t===13?o=`Carriage return`:t===0?o=`Null`:t===127&&(o=`DEL`);let c=o?`${o} (${a}) not allowed in ${i}`:`Control char ${a} not allowed in ${i}`;throw new C(e,_(r,n),c)}}let a=e[n];if(a===`"`&&(s=!s),a===`'`&&!s&&(c=!c),n+1>=t)break;if(s&&a===`\\`){let t=e[n+1];(t===`"`||t===`\\`)&&n++}}if(s||c)throw new C(e,_(r,o),`Expected close of string with ${s?`"`:`'`}`);return{type:`Literal`,raw:e.slice(o,n+1),loc:i(o,n+1)}}}function D(e,t,n){if(!n||e[t]!==n||e[t+1]!==n||e[t+2]!==n)return!1;if(n===`'`)return n;let r=0,i=t-1;for(;i>=0&&e[i]===`\\`;)r++,i--;return(r===0||r%2==0)&&n}const O=new Int8Array(128);O.fill(-1);for(let e=0;e<10;e++)O[48+e]=e;for(let e=0;e<6;e++)O[65+e]=10+e,O[97+e]=10+e;function k(e){let t=e.charCodeAt(0);return t<128&&O[t]!==-1}function te(e,t){return O[e.charCodeAt(t)]<<12|O[e.charCodeAt(t+1)]<<8|O[e.charCodeAt(t+2)]<<4|O[e.charCodeAt(t+3)]}function ne(e){return e.startsWith(`'''`)?ie(e.slice(3,e.length-3)):e.startsWith(`'`)?e.slice(1,e.length-1):e.startsWith(`"""`)?re(ie(e.slice(3,e.length-3)),!0):e.startsWith(`"`)?re(e.slice(1,e.length-1),!1):e}function re(e,t){let n=e.length;if(!t&&e.indexOf(`\\`)===-1)return e;let r=[],i=0;for(let a=0;a<n;a++){if(e[a]!==`\\`)continue;if(a>i&&r.push(e.slice(i,a)),a++,a>=n)throw Error(`Trailing backslash`);let o=e[a];switch(o){case`b`:r.push(`\b`);break;case`t`:r.push(` `);break;case`n`:r.push(`
3
+ `);break;case`f`:r.push(`\f`);break;case`r`:r.push(`\r`);break;case`"`:r.push(`"`);break;case`\\`:r.push(`\\`);break;case`e`:r.push(`\x1B`);break;case`u`:{if(a+4>n||!k(e[a+1])||!k(e[a+2])||!k(e[a+3])||!k(e[a+4]))throw Error(`Invalid Unicode escape: \\u${e.slice(a+1,a+5)}`);let t=te(e,a+1);if(t>=55296&&t<=57343)throw Error(`Invalid \\u${e.slice(a+1,a+5)}: surrogates not allowed`);r.push(String.fromCharCode(t)),a+=4;break}case`U`:{if(a+8>n)throw Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);for(let t=1;t<=8;t++)if(!k(e[a+t]))throw Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);let t=parseInt(e.slice(a+1,a+9),16);r.push(String.fromCodePoint(t)),a+=8;break}case`x`:{if(a+2>n||!k(e[a+1])||!k(e[a+2]))throw Error(`Invalid hex escape: \\x${e.slice(a+1,a+3)}`);let t=O[e.charCodeAt(a+1)]<<4|O[e.charCodeAt(a+2)];r.push(String.fromCharCode(t)),a+=2;break}default:if(t&&(o===`
4
+ `||o===`\r`||o===` `||o===` `)){let t=o===`
5
+ `||o===`\r`,r=a;for(;r<n&&(e[r]===` `||e[r]===` `||e[r]===`
6
+ `||e[r]===`\r`);)(e[r]===`
7
+ `||e[r]===`\r`)&&(t=!0),r++;if(!t)throw Error(`Invalid escape sequence: \\${o}`);a=r-1;break}throw Error(`Invalid escape sequence: \\${o}`)}i=a+1}return i===0?e:(i<n&&r.push(e.slice(i)),r.join(``))}function ie(e){return e.charCodeAt(0)===10?e.slice(1):e.charCodeAt(0)===13&&e.charCodeAt(1)===10?e.slice(2):e}var ae=class{iterator;index;value;done;peeked;constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){if(this.done)return se();let e=this.peeked||this.iterator.next();return this.index+=1,this.value=e.value,this.done=e.done??!1,this.peeked=null,e}peek(){return this.done?se():(this.peeked||=this.iterator.next(),this.peeked)}[Symbol.iterator](){return this}};const oe=Object.freeze({value:void 0,done:!0});function se(){return oe}function A(e){return{year:String(e.getUTCFullYear()).padStart(4,`0`),month:String(e.getUTCMonth()+1).padStart(2,`0`),day:String(e.getUTCDate()).padStart(2,`0`),hours:String(e.getUTCHours()).padStart(2,`0`),minutes:String(e.getUTCMinutes()).padStart(2,`0`),seconds:String(e.getUTCSeconds()).padStart(2,`0`),ms:e.getUTCMilliseconds()}}function j(e,t,n=/\.(\d+)\s*$/){if(t&&t.includes(`.`)){let r=t.match(n),i=r?r[1].length:3;return`.`+String(e).padStart(3,`0`).slice(0,i)}return e>0?`.`+String(e).padStart(3,`0`).replace(/0+$/,``):``}function ce(e){if(e===`Z`)return 0;let t=e[0]===`+`?1:-1,[n,r]=e.slice(1).split(`:`);return t*(parseInt(n)*60+parseInt(r))}var le=class e{static IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/;static IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/;static IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;static createDateWithOriginalFormat(t,n){if(e.IS_DATE_ONLY.test(n)){if(t.getUTCHours()!==0||t.getUTCMinutes()!==0||t.getUTCSeconds()!==0||t.getUTCMilliseconds()!==0){if(t instanceof fe)return t;let e=t.toISOString().replace(`Z`,``);return e=e.replace(/\.000$/,``),new M(e,!1)}let e=t.toISOString().split(`T`)[0];return new ue(e)}else if(e.IS_TIME_ONLY.test(n)){if(t instanceof de)return t;{let e=A(t),r=j(e.ms,n);return new de(`${e.hours}:${e.minutes}:${e.seconds}${r}`,n)}}else if(e.IS_LOCAL_DATETIME_T.test(n)){let e=A(t),r=j(e.ms,n);return new M(`${e.year}-${e.month}-${e.day}T${e.hours}:${e.minutes}:${e.seconds}${r}`,!1,n)}else if(e.IS_LOCAL_DATETIME_SPACE.test(n)){let e=A(t),r=j(e.ms,n);return new M(`${e.year}-${e.month}-${e.day} ${e.hours}:${e.minutes}:${e.seconds}${r}`,!0,n)}else if(e.IS_OFFSET_DATETIME_T.test(n)||e.IS_OFFSET_DATETIME_SPACE.test(n)){let r=n.match(/([+-]\d{2}:\d{2}|[Zz])$/),i=r?r[1]===`z`?`Z`:r[1]:`Z`,a=e.IS_OFFSET_DATETIME_SPACE.test(n),o=A(new Date(t.getTime()+ce(i)*6e4)),s=a?` `:`T`,c=j(o.ms,n,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return new fe(`${o.year}-${o.month}-${o.day}${s}${o.hours}:${o.minutes}:${o.seconds}${c}${i}`,a)}else return t}},ue=class extends Date{constructor(e){super(e)}toISOString(){let e=A(this);return`${e.year}-${e.month}-${e.day}`}},de=class extends Date{originalFormat;constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+`:00`),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){let e=A(this);return`${e.hours}:${e.minutes}:${e.seconds}${j(e.ms,this.originalFormat)}`}},M=class extends Date{useSpaceSeparator=!1;originalFormat;constructor(e,t=!1,n){let r=e;/\d{2}:\d{2}:\d{2}/.test(e)||(r=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,`$1:00$2`)),super(r.replace(` `,`T`)+`Z`),this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){let e=A(this),t=this.useSpaceSeparator?` `:`T`;return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${j(e.ms,this.originalFormat)}`}},fe=class extends Date{useSpaceSeparator=!1;originalOffset;originalFormat;constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,`$1:00$2`)),super(n.replace(` `,`T`)),this.useSpaceSeparator=t,this.originalFormat=e;let r=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);r&&(this.originalOffset=r[1]===`z`?`Z`:r[1])}toISOString(){if(this.originalOffset){let e=A(new Date(this.getTime()+ce(this.originalOffset)*6e4)),t=this.useSpaceSeparator?` `:`T`,n=j(e.ms,this.originalFormat,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${n}${this.originalOffset}`}let e=super.toISOString();return this.useSpaceSeparator?e.replace(`T`,` `):e}};const N=le,pe=`true`,me=/e/i,he=/_/g,ge=/^[+-]?inf$/,_e=/^[+-]?nan$/,ve=/^[+-]?0x/i;function ye(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===95||e===45}const be=/^[+-]?0o/i,xe=/^[+-]?0b/i;function Se(e,t,n){for(let r=0;r<e.length;r++)if(!ye(e.charCodeAt(r)))throw new C(t,{line:n.line,column:n.column+r},`Invalid bare key char '${e[r]}'`)}function Ce(e,t,n){if(e.startsWith(`"""`)||e.startsWith(`'''`))throw new C(t,n,`Multiline strings cannot be keys`)}function we(e,t,n){try{return ne(e)}catch(e){throw new C(t,n,e.message)}}function Te(e,t,n,r=!0){if(e.endsWith(`_`)||(r?/^[+-]?_/.test(e):e.startsWith(`_`)))throw new C(t,n,`Underscore must be between digits`);if(/__/.test(e))throw new C(t,n,`Consecutive underscores not allowed`)}function Ee(e,t,n,r){let i=e.replace(he,``);if(/^[+-]?0\d/.test(i)&&!ve.test(e)&&!be.test(e)&&!xe.test(e))throw new C(t,n,`Leading zeros are not allowed in ${r}`)}function De(e,t,n,r){if(/_[eE]/.test(e))throw new C(n,r,`Underscore before exponent is not allowed`);if(/[eE][+-]?_/.test(e))throw new C(n,r,`Underscore at start of exponent is not allowed`);if(/[eE][+-]?$/.test(e))throw new C(n,r,`Invalid float "${t}": incomplete exponent`);if(/[eE][+-]?.*\./.test(e))throw new C(n,r,`Invalid float "${t}": decimal point not allowed in exponent`)}function Oe(e,t,n,r,i,a){if(e.length!==2)throw new C(i,a,`"${r}": hour must be 2 digits`);if(t.length!==2)throw new C(i,a,`"${r}": minute must be 2 digits`);if(n&&n.length!==2)throw new C(i,a,`"${r}": second must be 2 digits`)}function ke(e,t,n,r,i,a){if(e!==void 0){let t=parseInt(e,10);if(t<0||t>23)throw new C(i,a,`"${r}": hour must be 00-23`)}if(t!==void 0){let e=parseInt(t,10);if(e<0||e>59)throw new C(i,a,`"${r}": minute must be 00-59`)}if(n!==void 0){let e=parseInt(n,10);if(e<0||e>60)throw new C(i,a,`"${r}": second must be 00-60`)}}function Ae(e,t,n){if(ve.test(e)||be.test(e)||xe.test(e))return;let r=e.replace(/^[+-]/,``).replace(/_/g,``);if(!/^[0-9]+$/.test(r))throw new C(t,n,`Invalid integer "${e}"`)}function je(e,t,n,r,i,a,o){let s=r[0]+r[1].toUpperCase();if(RegExp(`^[+\\-]?`+s.replace(/([[\]])/g,`\\$1`)).test(e))throw new C(t,n,`${a} prefix must be lowercase "${r}"`);if(RegExp(`^[+\\-]?`+r+`_`,`i`).test(e))throw new C(t,n,`Underscore must be between digits`);let c=RegExp(`^[+\\-]?`+r,`i`),l=e.replace(c,``);if(!l||l===`_`||l.startsWith(`_`))throw new C(t,n,`Incomplete ${a.toLowerCase()} number`);let u=l.replace(/_/g,``);if(!i.test(u))throw new C(t,n,o??`Invalid ${a.toLowerCase()} digits`);if(/^[+-]/.test(e))throw new C(t,n,`${a} numbers cannot have a sign prefix`)}function*P(e){let t=new ae(E(e));for(;!t.next().done;){let n=He(t,e);for(let e of n)yield e}}function*Me(e,t){for(let t of e)yield t;let n=new ae(E(t));for(;!n.next().done;){let e=He(n,t);for(let t of e)yield t}}function Ne(e){return{type:`Comment`,loc:e.value.loc,raw:e.value.raw}}function Pe(e,t){let n=!e.peek().done&&e.peek().value.type===`Bracket`?`TableArray`:`Table`,r=n===`Table`;if(r&&e.value.raw!==`[`)throw new C(t,e.value.loc.start,`Expected table opening "[", found ${e.value.raw}`);if(!r){let n=e.peek();if(n.done)throw new C(t,e.value.loc.start,`Expected "[[" for Array of Tables, found end of input`);if(e.value.raw!==`[`||n.value.raw!==`[`)throw new C(t,e.value.loc.start,`Expected "[[", found ${e.value.raw+n.value.raw}`);let r=e.value,i=n.value;if(r.loc.end.line!==i.loc.start.line||r.loc.end.column!==i.loc.start.column)throw new C(t,r.loc.start,`"[[" brackets must be adjacent (no whitespace)`)}let i=r?{type:`TableKey`,loc:e.value.loc}:{type:`TableArrayKey`,loc:e.value.loc};if(e.next(),n===`TableArray`&&e.next(),e.done)throw new C(t,i.loc.start,`Expected table key, reached end of file`);if(e.value.type===`Bracket`&&e.value.raw===`]`)throw new C(t,e.value.loc.start,n===`TableArray`?`Array of Tables header [[]] requires a table name`:`Table header [] requires a table name`);let a=e.value.raw;Ce(a,t,e.value.loc.start),a.startsWith(`"`)||a.startsWith(`'`)||Se(a,t,e.value.loc.start);let o;for(o=[we(e.value.raw,t,e.value.loc.start)],i.item={type:`Key`,loc:e.value.loc,raw:e.value.raw,value:o};!e.peek().done&&e.peek().value.type===`Dot`;){e.next();let n=e.value;e.next();let r=e.value.raw;r.startsWith(`"`)||r.startsWith(`'`)||Se(r,t,e.value.loc.start);let a=` `.repeat(n.loc.start.column-i.item.loc.end.column),o=` `.repeat(e.value.loc.start.column-n.loc.end.column);i.item.loc.end=e.value.loc.end,i.item.raw+=`${a}.${o}${e.value.raw}`;try{i.item.value.push(ne(e.value.raw))}catch(n){let r=n;throw new C(t,e.value.loc.start,r.message)}}if(e.next(),!e.done){let n=i.loc.start.line;if(e.value.loc.start.line!==n)throw new C(t,e.value.loc.start,r?`Table header must be single-line`:`Array of Tables header must be single-line`)}if(r&&(e.done||e.value.raw!==`]`))throw new C(t,e.done?i.item.loc.end:e.value.loc.start,`Expected table closing "]", found ${e.done?`end of file`:e.value.raw}`);if(!r&&(e.done||e.peek().done||e.value.raw!==`]`||e.peek().value.raw!==`]`))throw new C(t,e.done||e.peek().done?i.item.loc.end:e.value.loc.start,`Expected "]]" closing, found ${e.done||e.peek().done?`end of file`:e.value.raw+e.peek().value.raw}`);if(!r){let n=e.value,r=e.peek().value;if(n.loc.end.line!==r.loc.start.line||n.loc.end.column!==r.loc.start.column)throw new C(t,n.loc.start,`"]]" brackets must be adjacent (no whitespace)`)}if(r||e.next(),i.loc.end=e.value.loc.end,!e.peek().done){let n=e.peek().value;if(n.loc.start.line===i.loc.end.line&&n.type!==`Comment`)throw new C(t,n.loc.start,`Extra content after ${r?`table`:`Array of Tables`} header`)}let s=[];for(;!e.peek().done&&e.peek().value.type!==`Bracket`;){e.next();let n=He(e,t);for(let e=0;e<n.length;e++)s.push(n[e])}return{type:r?`Table`:`TableArray`,loc:{start:b(i.loc.start),end:s.length?b(s[s.length-1].loc.end):b(i.loc.end)},key:i,items:s}}function Fe(e,t){let n=we(e.value.raw,t,e.value.loc.start);return{type:`String`,loc:e.value.loc,raw:e.value.raw,value:n}}function Ie(e){return{type:`Boolean`,loc:e.value.loc,value:e.value.raw===pe}}function Le(e,t){let n=e.value.loc,r=e.value.raw,i;if(!e.peek().done&&e.peek().value.type===`Literal`&&N.IS_FULL_DATE.test(r)&&N.IS_FULL_TIME.test(e.peek().value.raw)){let t=n.start;e.next(),n={start:t,end:e.value.loc.end},r+=` ${e.value.raw}`}if(!e.peek().done&&e.peek().value.type===`Dot`){let i=n.start;if(e.next(),e.peek().done||e.peek().value.type!==`Literal`)throw new C(t,e.value.loc.end,`Expected fractional value for DateTime`);e.next(),n={start:i,end:e.value.loc.end},r+=`.${e.value.raw}`}if(ze(r,t,n.start),N.IS_FULL_DATE.test(r))i=N.IS_DATE_ONLY.test(r)?new ue(r):N.IS_LOCAL_DATETIME_T.test(r)?new M(r,!1):N.IS_LOCAL_DATETIME_SPACE.test(r)?new M(r,!0):N.IS_OFFSET_DATETIME_T.test(r)?new fe(r,!1):N.IS_OFFSET_DATETIME_SPACE.test(r)?new fe(r,!0):new Date(r.replace(` `,`T`));else if(N.IS_TIME_ONLY.test(r))i=new de(r,r);else{let[e]=new Date().toISOString().split(`T`);i=new Date(`${e}T${r}`)}return{type:`DateTime`,loc:n,raw:r,value:i}}function Re(e,t){return t===2?e%4==0&&e%100!=0||e%400==0?29:28:[31,28,31,30,31,30,31,31,30,31,30,31][t-1]}function ze(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new C(t,n,`"${e}": fractional seconds needs digit after dot`);if(/[+-]$/.test(e))throw new C(t,n,`"${e}": offset needs HH:MM`);let r=/\d{2}:\d{2}/.test(e)?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(r){let e=r[0],i=r[2],a=r[3],o=r[4];if(a!==`:`)throw new C(t,n,`Offset "${e}": missing colon separator`);if(i.length!==2)throw new C(t,n,`Offset "${e}": hour must be 2 digits`);if(!o||o.length===0)throw new C(t,n,`Offset "${e}": minute required`);if(o.length!==2)throw new C(t,n,`Offset "${e}": minute must be 2 digits`);let s=parseInt(i,10);if(s<0||s>23)throw new C(t,n,`Offset "${e}": hour must be 00-23`);let c=parseInt(o,10);if(c<0||c>59)throw new C(t,n,`Offset "${e}": minute must be 00-59`)}if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/.test(e))throw/^\d{4}-\d{2}-\d{2}T$/.test(e)?new C(t,n,`"${e}": 'T' requires time component`):/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e)?new C(t,n,`Invalid date "${e}": unexpected character after date`):/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e)?new C(t,n,`"${e}": missing 'T' or space separator`):new C(t,n,`Invalid datetime "${e}"`);let i=e.match(/^(\d+)-/);if(i&&i[1].length!==4)throw new C(t,n,`"${e}": year must be 4 digits`);let a=e.match(/^(\d+)-(\d+)-(\d+)/);if(a){let[,,r,i]=a;if(r.length!==2)throw new C(t,n,`"${e}": month must be 2 digits`);if(i.length!==2)throw new C(t,n,`"${e}": day must be 2 digits`)}let o=e.match(/[T ](\d+):(\d+)(?::(\d+))?/);if(o){let[,r,i,a]=o;Oe(r,i,a,e,t,n)}let s=e.match(/^(\d+):(\d+)(?::(\d+))?/);if(s&&!a){let[,r,i,a]=s;Oe(r,i,a,e,t,n)}let c=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),l=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(c){let[,r,i,a,o,s,l]=c,u=parseInt(i,10);if(u<1||u>12)throw new C(t,n,`"${e}": month must be 01-12`);let d=parseInt(a,10);if(d<1||d>31)throw new C(t,n,`"${e}": day must be 01-31`);if(d>Re(parseInt(r,10),u))throw new C(t,n,`"${e}": day ${a} invalid for ${r}-${i}`);ke(o,s,l,e,t,n)}else if(l){let[,r,i,a]=l;ke(r,i,a,e,t,n)}}function Be(e,t){let n=e.value.loc,r=e.value.raw,i;if(ge.test(r))i=r.startsWith(`-`)?-1/0:1/0;else if(_e.test(r)){let e=new Float64Array(1),t=new DataView(e.buffer);r.startsWith(`-`)?(t.setUint32(0,0,!0),t.setUint32(4,4294443008,!0)):(t.setUint32(0,0,!0),t.setUint32(4,2146959360,!0)),i=e[0];let a=r.startsWith(`+`)?`+`:r.startsWith(`-`)?`-`:void 0;return{type:`Float`,loc:n,raw:r,value:i,nanSign:a}}else if(!e.peek().done&&e.peek().value.type===`Dot`){let a=n.start;{if(me.test(r)&&!ve.test(r))throw new C(t,n.start,`Float "${r}": dot after exponent`);let e=r;Ee(e,t,n.start,`the integer part of a float`);let i=e.replace(/^[+-]/,``);if(i===``||i===`_`)throw new C(t,n.start,`Float: digit required before dot`);Te(e,t,n.start)}if(e.next(),e.peek().done||e.peek().value.type!==`Literal`)throw new C(t,e.value.loc.end,`Expected fraction value for Float`);e.next(),r+=`.${e.value.raw}`,n={start:a,end:e.value.loc.end};{let n=e.value.raw;if(!/^\d/.test(n))throw new C(t,e.value.loc.start,`Float: fraction must start with digit, found "${n}"`);Te(n,t,e.value.loc.start,!1),De(n,r,t,e.value.loc.start)}i=Number(r.replace(he,``))}else{if(Te(r,t,n.start),De(r,r,t,n.start),!e.peek().done&&e.peek().value.type===`Dot`)throw new C(t,e.peek().value.loc.start,`Float "${r}.": dot after exponent`);Ee(r,t,n.start,`the integer part of a float`),i=Number(r.replace(he,``))}if(Number.isNaN(i)&&!_e.test(r))throw new C(t,n.start,`Invalid float "${r}"`);return{type:`Float`,loc:n,raw:r,value:i}}function Ve(e,t){let n=e.value.raw,r=e.value.loc;if(/^\d{1,}-\d{1,}/.test(n)||/^\d{1,}:\d{1,}/.test(n)||/^\d{6}-\d{2}$/.test(n))throw new C(t,r.start,`Invalid integer "${n}"`);if(n===`-0`||n===`+0`)return{type:`Integer`,loc:r,raw:n,value:0};if(/^[+-]{2,}/.test(n))throw new C(t,r.start,`Double sign is not allowed in integers`);Ee(n,t,r.start,`decimal integers`),Te(n,t,r.start),Ae(n,t,r.start);let i=10;ve.test(n)?(i=16,je(n,t,r.start,`0x`,/^[0-9a-fA-F]+$/,`Hexadecimal`)):be.test(n)?(i=8,je(n,t,r.start,`0o`,/^[0-7]+$/,`Octal`,`Invalid octal digits (must be 0-7)`)):xe.test(n)&&(i=2,je(n,t,r.start,`0b`,/^[01]+$/,`Binary`,`Invalid binary digits (must be 0 or 1)`));let a=parseInt(n.replace(he,``).replace(be,``).replace(xe,``),i);if(Number.isNaN(a))throw new C(t,r.start,`Invalid integer "${n}"`);return{type:`Integer`,loc:r,raw:n,value:a}}function He(e,t){if(e.value.type===`Comment`)return[Ne(e)];if(e.value.type===`Bracket`)return[Pe(e,t)];if(e.value.type===`Literal`)return Ue(e,t);throw e.value.type===`Equal`?new C(t,e.value.loc.start,`Missing key before '='`):new C(t,e.value.loc.start,`Unexpected token "${e.value.type}"`)}function Ue(e,t){let n=e.value.raw;if(n.endsWith(`:`))throw new C(t,{line:e.value.loc.start.line,column:e.value.loc.start.column+[...n].length-1},`Use '=' to separate keys and values, not ':'`);Ce(n,t,e.value.loc.start),n.startsWith(`"`)||n.startsWith(`'`)||Se(n,t,e.value.loc.start);let r;r=[we(e.value.raw,t,e.value.loc.start)];let i={type:`Key`,loc:e.value.loc,raw:e.value.raw,value:r};for(;!e.peek().done&&e.peek().value.type===`Dot`;){e.next(),e.next();let n=e.value.raw;Ce(n,t,e.value.loc.start),n.startsWith(`"`)||n.startsWith(`'`)||Se(n,t,e.value.loc.start),i.loc.end=e.value.loc.end,i.raw+=`.${e.value.raw}`,i.value.push(we(e.value.raw,t,e.value.loc.start))}if(e.next(),!e.done&&e.value.loc.start.line!==i.loc.end.line)throw new C(t,e.value.loc.start,`"=" must be on same line as key`);if(e.done||e.value.type!==`Equal`)throw!e.done&&e.value.raw===`:`?new C(t,e.value.loc.start,`Use '=' to separate keys and values, not ':'`):new C(t,e.done?i.loc.end:e.value.loc.start,`Expected "=" for key-value`);let a=e.value.loc.start.column,o=e.value.loc.start.line;if(e.next(),e.done)throw new C(t,i.loc.start,`Expected value, reached EOF`);if(e.value.loc.start.line!==o)throw new C(t,e.value.loc.start,`Value must be on same line as '='`);if(e.done)throw new C(t,i.loc.start,`Expected value for key-value`);let s=We(e,t),c=s[0];if(!e.peek().done){let n=e.peek().value;if(n.type===`Dot`&&n.loc.start.line===c.loc.end.line&&(c.type===`Float`||c.type===`Integer`))throw new C(t,n.loc.start,`Invalid number: multiple decimal points not allowed`);if((n.type===`Literal`||n.type===`Bracket`)&&n.loc.start.line===c.loc.end.line)throw new C(t,n.loc.start,`Key/value pairs must be separated by a newline`)}return s[0]={type:`KeyValue`,key:i,value:c,loc:{start:b(i.loc.start),end:b(c.loc.end)},equals:a},s}function We(e,t){if(e.value.type===`Literal`){let n=e.value.raw;return n[0]===`"`||n[0]===`'`?[Fe(e,t)]:n===pe||n===`false`?[Ie(e)]:/^\d/.test(n)&&(/^\d{1,}-\d{1,}/.test(n)||/^\d{1,}:\d{1,}/.test(n))?[Le(e,t)]:!e.peek().done&&e.peek().value.type===`Dot`||ge.test(n)||_e.test(n)||me.test(n)&&!ve.test(n)?[Be(e,t)]:[Ve(e,t)]}else if(e.value.type===`Curly`){let[n,r]=Ge(e,t);return[n,...r]}else if(e.value.type===`Bracket`){let[n,r]=Ke(e,t);return[n,...r]}else if(e.value.type===`Dot`)throw new C(t,e.value.loc.start,`Number cannot start with a dot`);else throw new C(t,e.value.loc.start,`Unrecognized token type`)}function Ge(e,t){if(e.value.raw!==`{`)throw new C(t,e.value.loc.start,`Expected "{" for inline table`);let n={type:`InlineTable`,loc:e.value.loc,items:[]},r=[];for(e.next();!e.done&&(e.value.type!==`Curly`||e.value.raw!==`}`);){if(e.value.type===`Comment`){r.push(Ne(e)),e.next();continue}if(e.value.type===`Comma`){let r=n.items[n.items.length-1];if(!r)throw new C(t,e.value.loc.start,`Leading comma in inline table`);if(r.comma)throw new C(t,e.value.loc.start,`Consecutive commas in inline table`);r.comma=!0,r.loc.end=e.value.loc.start,e.next();continue}let i=n.items[n.items.length-1];if(i&&!i.comma)throw new C(t,e.value.loc.start,`Missing comma between inline table items`);let a=He(e,t),o=a[0];if(o.type===`KeyValue`){n.items.push({type:`InlineItem`,loc:x(o.loc),item:o,comma:!1});for(let e=1;e<a.length;e++)r.push(a[e])}e.next()}if(e.done||e.value.type!==`Curly`||e.value.raw!==`}`)throw new C(t,e.done?n.loc.start:e.value.loc.start,`Expected "}"`);return n.loc.end=e.value.loc.end,[n,r]}function Ke(e,t){if(e.value.raw!==`[`)throw new C(t,e.value.loc.start,`Expected "[" for inline array`);let n={type:`InlineArray`,loc:e.value.loc,items:[]},r=[];for(e.next();!e.done&&(e.value.type!==`Bracket`||e.value.raw!==`]`);){if(e.value.type===`Comma`){let r=n.items[n.items.length-1];if(!r)throw new C(t,e.value.loc.start,`Leading comma in array`);if(r.comma)throw new C(t,e.value.loc.start,`Consecutive commas in array`);r.comma=!0,r.loc.end=e.value.loc.start}else if(e.value.type===`Comment`)r.push(Ne(e));else{let i=n.items[n.items.length-1];if(i&&!i.comma)throw new C(t,e.value.loc.start,`Missing comma between array elements`);let a=We(e,t),o=a[0];n.items.push({type:`InlineItem`,loc:x(o.loc),item:o,comma:!1});for(let e=1;e<a.length;e++)r.push(a[e])}e.next()}if(e.done||e.value.type!==`Bracket`||e.value.raw!==`]`)throw new C(t,e.done?n.loc.start:e.value.loc.start,`Expected "]"`);return n.loc.end=e.value.loc.end,[n,r]}function F(e){return e[e.length-1]}function qe(){return Object.create(null)}function Je(e){return typeof e==`string`}function Ye(e){return typeof e==`number`&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function Xe(e){return typeof e==`bigint`}function Ze(e){return typeof e==`number`&&(!Ye(e)||!isFinite(e)||Object.is(e,-0))}function Qe(e){return typeof e==`boolean`}function I(e){return Object.prototype.toString.call(e)===`[object Date]`}const $e=new Set([`Temporal.PlainDate`,`Temporal.PlainTime`,`Temporal.PlainDateTime`,`Temporal.ZonedDateTime`,`PlainDate`,`PlainTime`,`PlainDateTime`,`ZonedDateTime`]);function L(e){var t;return typeof e==`object`&&!!e&&$e.has((t=e.constructor)==null?void 0:t.name)&&typeof e.equals==`function`}function et(e){var t;let n=((t=e.constructor)==null?void 0:t.name)??``;if(n===`Temporal.ZonedDateTime`||n===`ZonedDateTime`){let t=e.toString(),n=t.match(/\[(.+)\]$/);if(n&&!/^[+-]\d{2}:\d{2}$/.test(n[1]))throw Error(`ZonedDateTime with IANA timezone "${t}" cannot be represented in TOML. TOML only supports offset-based timezones (+05:30, Z).`);return t.replace(/\[.*\]$/,``).replace(/(\+00:00)$/,`Z`)}let r=e.toString();if(/\[.*\]/.test(r))throw Error(`Temporal value contains unsupported annotation: "${r}". TOML only supports ISO 8601 calendar.`);return r}function R(e){return e&&typeof e==`object`&&!I(e)&&!L(e)&&!Array.isArray(e)}function tt(e){return e!=null&&typeof e[Symbol.iterator]==`function`}function nt(e){return e.startsWith(`"`)&&!e.startsWith(`"""`)}function rt(e){return e.startsWith(`"""`)}function it(e){return e.startsWith(`'`)&&!e.startsWith(`'''`)}function at(e){return e.startsWith(`'''`)}function ot(e,t){return t in e}function z(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function st(e,t){return L(e)&&L(t)?e.toString()===t.toString():I(e)&&I(t)?e.toISOString()===t.toISOString():!1}function B(e){return R(e)?`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${B(e[t])}`).join(`,`)}}`:Array.isArray(e)?`[${e.map(B).join(`,`)}]`:L(e)?JSON.stringify(e.toString()):I(e)?JSON.stringify(e.toISOString()):typeof e==`bigint`?e.toString()+`n`:JSON.stringify(e)}function ct(e,t){let n=e.length,r=t.length;e.length=n+r;for(let i=0;i<r;i++)e[n+i]=t[i]}function lt(e,t){tt(e)?n(e,null):r(e,null);function n(e,t){for(let n of e)r(n,t)}function r(e,i){let a=t[e.type];switch(a&&typeof a==`function`&&a(e,i),a&&a.enter&&a.enter(e,i),e.type){case`Document`:n(e.items,e);break;case`Table`:r(e.key,e),n(e.items,e);break;case`TableKey`:r(e.item,e);break;case`TableArray`:r(e.key,e),n(e.items,e);break;case`TableArrayKey`:r(e.item,e);break;case`KeyValue`:r(e.key,e),r(e.value,e);break;case`InlineArray`:n(e.items,e);break;case`InlineItem`:r(e.item,e);break;case`InlineTable`:n(e.items,e);break;case`Key`:case`String`:case`Integer`:case`Float`:case`Boolean`:case`DateTime`:case`Comment`:break;default:throw Error(`Unrecognized node type "${e.type}"`)}a&&a.exit&&a.exit(e,i)}}const V=new WeakSet,ut=new WeakMap,dt=new WeakSet,ft=new Set;function pt(e){return ft.has(e)}function mt(e){ft.delete(e)}const ht=new WeakMap,gt=e=>(ht.has(e)||ht.set(e,new WeakMap),ht.get(e)),_t=new WeakMap,H=e=>(_t.has(e)||_t.set(e,new WeakMap),_t.get(e));function vt(e,t,n,r){if(p(t)){let e=t.items.indexOf(n);if(e<0)throw Error(`Item not found in parent for replace`);t.items.splice(e,1,r)}else if(a(t)&&d(t.value)&&!d(n)){let e=t.value.items.indexOf(n);if(e<0)throw Error(`Item not found in parent for replace`);t.value.items.splice(e,1,r)}else if(m(t))t.item=r;else if(a(t))t.key===n?t.key=r:t.value=r;else throw Error(`Unsupported parent type "${t.type}" for replace`);Et(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});let i=g(n.loc),o=g(r.loc);Ot({lines:o.lines-i.lines,columns:o.columns-i.columns},H(e),r,n),V.add(e)}function U(t,n,r,i,a,o){if(!p(n))throw Error(`Unsupported parent type "${n.type}" for insert`);i=i!=null&&typeof i==`number`?i:n.items.length;let s,c;l(n)||d(n)?{shift:s,offset:c}=xt(n,r,i):a&&e(n)?{shift:s,offset:c}=St(n,r,i):{shift:s,offset:c}=yt(t,n,r,i),Et(r,s);let u=n.items[i-1],m=u&&H(t).get(u);if(m&&(c.lines+=m.lines,c.columns+=m.columns,H(t).delete(u)),(d(n)||l(n))&&c.lines!==0&&(o||p(t))&&t!==n){let e=r.loc.start.line,i=o??t.items;for(let t=0;t<i.length;t++){let r=i[t];if(!f(r))continue;let a=r.loc.start.line;a<n.loc.start.line||a>n.loc.end.line||a<e&&(r.loc.start.line-=c.lines,r.loc.end.line-=c.lines)}}H(t).set(r,c),V.add(t)}function yt(n,i,a,o){if(!h(a))throw Error(`Incompatible child type "${a.type}"`);let s=i.items[o-1],c=e(i)&&!i.items.length,l=e(i)&&!c&&s===void 0;i.items.splice(o,0,a);let u;if(s!==void 0){let e=-1,t=-1;for(let n=0;n<o;n++){let r=i.items[n],a=r.loc.end;(a.line>e||a.line===e&&a.column>t)&&(e=a.line,t=a.column,u=r)}}let d=u?{line:u.loc.end.line,column:f(u)?i.loc.start.column:u.loc.start.column}:b(i.loc.start),p=t(a)||r(a),m=0;c||l||(m=p?2:1),d.line+=m;let _={lines:d.line-a.loc.start.line,columns:d.column-a.loc.start.column},v=g(a.loc),y=s===void 0&&(t(i)||r(i)||e(i))&&ut.has(i),x=y&&!dt.has(i);y&&(ut.delete(i),dt.delete(i));let S=y&&!x,C=0;if(S){let e=t(i)||r(i)?H(n).get(i.key):gt(n).get(i);C=e?-e.lines:1}let w=x||S?-v.lines:m-1,T={lines:l?v.lines+1:v.lines+w,columns:v.columns};return{shift:{lines:_.lines+C,columns:_.columns},offset:T}}function bt(e,t,n,r={}){let{useNewLine:i=!1,skipCommaSpace:a=2,skipBracketSpace:o=1,hasCommaHandling:s=!1,isLastElement:c=!1,hasSeparatingCommaBefore:l=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:d=!1}=r,p=n>0?e.items[n-1]:void 0,m=p?{line:p.loc.end.line,column:i?f(p)?e.loc.start.column:p.loc.start.column:p.loc.end.column}:b(e.loc.start),h=0;if(i)h=1;else{let e=l||!s&&!!p;e&&s?m.column+=a:(e||s&&!p)&&(m.column+=o)}m.line+=h;let _={lines:m.line-t.loc.start.line,columns:m.column-t.loc.start.column},v=g(t.loc);if(!s)return{shift:_,offset:{lines:v.lines+(h-1),columns:v.columns}};let y=l&&d&&!u&&c,x=0;return y&&(x=-1),{shift:_,offset:{lines:v.lines+(h-1),columns:v.columns+(l||u?a:0)+(d?1+x:0)}}}function xt(e,t,n){if(!u(t))throw Error(`Incompatible child type "${t.type}"`);let r=n==null?F(e.items):e.items[n-1],i=n==null||n===e.items.length;e.items.splice(n,0,t);let a=!!r,o=!i;return a&&(r.comma=!0),o&&(t.comma=!0),bt(e,t,n,{useNewLine:Dt(e),hasCommaHandling:!0,isLastElement:i,hasSeparatingCommaBefore:a,hasSeparatingCommaAfter:o,hasTrailingComma:i&&t.comma===!0})}function St(e,t,n){let r=bt(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}function W(n,i,a,o){if(!p(i))throw Error(`Unsupported parent type "${i.type}" for remove`);let s=i.items.indexOf(a);if(s<0){if(s=i.items.findIndex(e=>m(e)&&e.item===a),s<0)throw Error(`Node not found in parent for removal`);a=i.items[s]}let c=i.items[s-1],h=i.items[s+1];i.items.splice(s,1);let _=g(a.loc);h&&f(h)&&h.loc.start.line===a.loc.end.line&&(_=g({start:a.loc.start,end:h.loc.end}),h=i.items[s+1],i.items.splice(s,1));let v=c&&u(c)||h&&u(h),y=c&&c.loc.end.line===a.loc.start.line,b=h&&h.loc.start.line===a.loc.end.line,x=v&&(y||b),S={lines:-(_.lines-+!!x),columns:x?-_.columns:0},C=(d(i)||l(i))&&i.loc.end.line>i.loc.start.line;c===void 0&&h===void 0&&!C&&(S.lines=0,S.columns=0,d(i)&&i.loc.end.line===i.loc.start.line&&ft.add(i),(t(i)||r(i)||e(i))&&ut.set(i,!0)),(c!==void 0||h!==void 0)&&(t(i)||r(i)||e(i))&&dt.add(i),v&&y&&(S.columns-=2),v&&!c&&h&&(Dt(i)||(S.columns-=2)),v&&c&&!h&&(a.comma?c.comma=!0:c.comma=!1);let w,T;c?(w=c,T=H(n)):(t(i)||r(i))&&`key`in i?(w=i.key,T=H(n)):(w=i,T=gt(n));let ee=H(n),E=T.get(w);E&&(S.lines+=E.lines,S.columns+=E.columns);let D=ee.get(a);if(D&&(S.lines+=D.lines,S.columns+=D.columns),T.set(w,S),V.add(n),C&&(o||p(n))&&n!==i){let e=a.loc.start.line,t=o??n.items,r=[];for(let n=0;n<t.length;n++){let a=t[n];if(!f(a))continue;let o=a.loc.start.line;o<i.loc.start.line||o>i.loc.end.line||(o===e?r.push(n):S.lines!==0&&o<e&&(a.loc.start.line-=S.lines,a.loc.end.line-=S.lines))}for(let e=r.length-1;e>=0;e--)t.splice(r[e],1)}}function Ct(e){let t=e.loc.start.line,n=e.loc.start.column;if(`key`in e){let r=e.key.loc.end;(r.line>t||r.line===t&&r.column>n)&&(t=r.line,n=r.column)}for(let r=0;r<e.items.length;r++){let i=e.items[r].loc.end;(i.line>t||i.line===t&&i.column>n)&&(t=i.line,n=i.column)}e.loc.end={line:t,column:n}}function wt(e,t,n=!0){if(!n||!t.items.length)return;Ot({lines:0,columns:1},gt(e),t);let r=F(t.items);Ot({lines:0,columns:1},H(e),r),V.add(e)}function Tt(e,t,n=!1){if(!n||!t.items.length)return;let r=F(t.items);r.comma=!0,Ot({lines:0,columns:1},H(e),r),V.add(e)}function G(e){if(!V.has(e))return;let t=gt(e),n=H(e),r=0,i={};function a(e){switch(e.type){case`Document`:{let t=e;o(t);for(let e=0;e<t.items.length;e++)a(t.items[e]);s(t),Ct(t);break}case`Table`:{let t=e;o(t),a(t.key);for(let e=0;e<t.items.length;e++)a(t.items[e]);s(t),Ct(t);break}case`TableArray`:{let t=e;o(t),a(t.key);for(let e=0;e<t.items.length;e++)a(t.items[e]);s(t),Ct(t);break}case`TableKey`:{let t=e;o(t),a(t.item),s(t);break}case`TableArrayKey`:{let t=e;o(t),a(t.item),s(t);break}case`KeyValue`:{let t=e,c=t.loc.start.line+r,l=n.get(t.key);t.equals+=(i[c]||0)+(l?l.columns:0),o(t),a(t.key),a(t.value),s(t);break}case`InlineArray`:{let t=e;o(t);for(let e=0;e<t.items.length;e++)a(t.items[e]);s(t);break}case`InlineTable`:{let t=e;o(t);for(let e=0;e<t.items.length;e++)a(t.items[e]);s(t);break}case`InlineItem`:{let t=e;o(t),a(t.item),s(t);break}case`Key`:case`String`:case`Integer`:case`Float`:case`Boolean`:case`DateTime`:case`Comment`:o(e),s(e);break;default:throw Error(`Unrecognized node type "${e.type}"`)}}function o(e){e.loc.start.line+=r;let n=i[e.loc.start.line]||0;e.loc.start.column+=n;let a=t.get(e);a&&(r+=a.lines,i[e.loc.start.line]=(i[e.loc.start.line]||0)+a.columns)}function s(e){e.loc.end.line+=r;let t=i[e.loc.end.line]||0;e.loc.end.column+=t;let a=n.get(e);a&&(r+=a.lines,i[e.loc.end.line]=(i[e.loc.end.line]||0)+a.columns)}a(e),V.delete(e),ht.delete(e),_t.delete(e)}function Et(e,t,n={}){let{lines:r,columns:i}=t;if(r===0&&i===0)return e;let{first_line_only:a=!1}=n,o=e.loc.start.line,s=e.type;if(s===`Key`||s===`String`||s===`Integer`||s===`Float`||s===`Boolean`||s===`DateTime`||s===`Comment`)return(!a||e.loc.start.line===o)&&(e.loc.start.column+=i,e.loc.end.line===e.loc.start.line&&(e.loc.end.column+=i)),e.loc.start.line+=r,e.loc.end.line+=r,e;if(s===`KeyValue`){let t=e,n=t.value.type;if(n===`String`||n===`Integer`||n===`Float`||n===`Boolean`||n===`DateTime`){(!a||t.loc.start.line===o)&&(t.loc.start.column+=i,t.loc.end.column+=i),t.loc.start.line+=r,t.loc.end.line+=r,t.equals+=i;let n=t.key;(!a||n.loc.start.line===o)&&(n.loc.start.column+=i,n.loc.end.column+=i),n.loc.start.line+=r,n.loc.end.line+=r;let s=t.value;return(!a||s.loc.start.line===o)&&(s.loc.start.column+=i,s.loc.end.column+=i),s.loc.start.line+=r,s.loc.end.line+=r,e}}let c=e=>{(!a||e.loc.start.line===o)&&(e.loc.start.column+=i,e.loc.end.column+=i),e.loc.start.line+=r,e.loc.end.line+=r};return lt(e,{Table:c,TableKey:c,TableArray:c,TableArrayKey:c,KeyValue(e){c(e),e.equals+=i},Key:c,String:c,Integer:c,Float:c,Boolean:c,DateTime:c,InlineArray:c,InlineItem:c,InlineTable:c,Comment:c}),e}function Dt(e){return e.items.length?g(e.loc).lines>e.items.length:!1}function Ot(e,t,n,r){let i=t.get(r||n);i&&(e.lines+=i.lines,e.columns+=i.columns),t.set(n,e)}function kt(e){let t=e.match(/\r\n|\n/);return(t==null?void 0:t[0])===`\r
8
+ `?`\r
9
+ `:`
10
+ `}function At(e,t){var n;let r=kt(e);e=e.replace(/\r\n/g,`
11
+ `).replace(/\n/g,r);let i,a;e.startsWith(`"""\\${r}`)?(i=4+r.length,a=`"""\\${r}`):e.startsWith(`"""${r}`)?(i=3+r.length,a=`"""${r}`):(i=3,a=`"""`);let o=e.length-3,s=e.slice(i,o).split(r),c=s[s.length-1],l=s.length>1&&/^[\t ]*$/.test(c),u=l?c:``,d=(l?s.slice(0,-1):s).map(e=>{var t;if(/^[\t ]*$/.test(e))return{indent:e,content:``,trailingWs:``,hasBackslash:!1,isBlank:!0};let n=e,r=0;for(let e=n.length-1;e>=0&&n[e]===`\\`;e--)r++;let i=r%2==1;i&&(n=n.slice(0,-1));let a=((t=n.match(/^[\t ]*/))==null?void 0:t[0])??``,o=n.slice(a.length),s=o.match(/([\t ]+)$/),c=s?s[1]:``;return{indent:a,content:o.slice(0,o.length-c.length),trailingWs:c,hasBackslash:i,isBlank:!1}}),f=d.filter(e=>!e.isBlank),p=Math.max(...f.map(e=>e.content.length+e.trailingWs.length),1),m=f.filter(e=>e.hasBackslash),h=m[m.length-1]??f[f.length-1]??{indent:``,trailingWs:``,hasBackslash:!1,content:``,isBlank:!1},g=f[f.length-1]??h,_=[];{let e=[],t=0;for(let n of d)n.isBlank?e.push(n.indent):(t>0&&_.push(e),e=[],t++)}let v=f.some((e,t)=>!e.hasBackslash&&t<f.length-1),y=a===`"""${r}`,b=y&&f.length>0?((n=t.match(/^[\t ]*/))==null?void 0:n[0])??``:``,x=e=>{let t=e.match(/\S+| +/g)??[],n=[],r=0;for(;r<t.length;){let e=t[r++];for(;r<t.length&&t[r][0]===` `;){let n=t[r],i=t[r+1];if(!i){r++;break}if(e.length+n.length+i.length<=p)e+=n+i,r+=2;else{e+=n,r++;break}}n.push(e)}return n.length===0&&n.push(``),n},S=[],C=[],w=new Set,T=new Set,ee=new Map,E=!1;if(v&&t.includes(r)&&(r===`\r
12
+ `||!t.includes(`\r
13
+ `))){E=!0;let e=t.split(r),n=e[0].slice(b.length);if(n.length>0&&n[0]===` `)return null;let i=e[e.length-1];if(i.length>0&&i.length-i.trimEnd().length!==g.trailingWs.length)return null;for(let t=0;t<e.length;t++){var D;let n=e[t],r=t===0?n.slice(b.length):n,i=((D=r.match(/^[\t ]*/))==null?void 0:D[0])??``,a=x(r.slice(i.length)),o=S.length;T.add(o),t>0&&ee.set(o,i);for(let e of a)S.push(e);t<e.length-1&&w.add(o+a.length-1)}}else{let e=t.replace(/\r\n/g,`\\r\\n`).replace(/\n/g,`\\n`).slice(b.length);if(e.length>0&&(e[0]===` `||e.length-e.trimEnd().length!==g.trailingWs.length))return null;if(!v){let t=0,n=0;for(let r=0;r<f.length-1;r++){let i=f[r];if(!i.hasBackslash)break;let a=i.content+i.trailingWs;if(e.slice(n,n+a.length)===a)t++,n+=a.length;else break}let i=0,o=0;for(let r=f.length-1;r>=t;r--){let t=f[r],a=t.content+t.trailingWs;if(a.length===0)break;let s=e.length-o-a.length;if(s>=n&&e.slice(s,s+a.length)===a)i++,o+=a.length;else break}if(i>0){let s=e.slice(n,e.length-o);if(s.length===0||s[0]!==` `){for(let e=0;e<t;e++){let n=f[e];if(C.push(`${n.indent}${n.content}${n.trailingWs}\\`),e<t-1&&e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}if(s.length>0){let e=x(s),n=e.join(``),r=/(?<!\\)\\n/.test(n);if(t>0&&!r){let e=t-1;if(e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}for(let n=0;n<e.length;n++){let i=e[n],a=t+n,o=a<f.length?f[a]:null,c=o?y&&a===0?b:o.indent:h.indent,l=i.length>0&&/\s$/.test(i)?``:s.endsWith(` `)?` `:``;if(C.push(`${c}${i}${l}\\`),n<e.length-1&&!r){let e=t+n;if(e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}}let a=f.length-i-1;if(!r&&a>=0&&a<_.length&&_[a].length>0)for(let e of _[a])C.push(e)}else if(t>0){let e=t-1;if(e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}let e=f.length-i;for(let t=e;t<f.length;t++){let n=f[t],r=t===f.length-1;if(t>e){let e=t-1;if(e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}C.push(r?`${n.indent}${n.content}${n.trailingWs}${n.hasBackslash&&n.content!==``?`\\`:``}`:`${n.indent}${n.content}${n.trailingWs}\\`)}return l&&!(g.hasBackslash&&g.content===``)?`${a}${C.join(r)}${r}${u}"""`:`${a}${C.join(r)}"""`}}let s=e.slice(n);if(t>0&&(n===e.length||s.length>0&&s[0]!==` `)){for(let e=0;e<t;e++){let n=f[e];if(C.push(`${n.indent}${n.content}${n.trailingWs}\\`),e<t-1&&e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}if(n===e.length){let e=f[t-1],n=g.hasBackslash&&e.content!==``?`\\`:``;C[C.length-1]=`${e.indent}${e.content}${g.trailingWs}${n}`}else{let e=x(s),n=e.join(``),r=/(?<!\\)\\n/.test(n),i=t-1;if(!r&&i<_.length&&_[i].length>0)for(let e of _[i])C.push(e);for(let n=0;n<e.length;n++){let i=n===e.length-1,a=e[n],o=t+n,s=o<f.length?f[o]:null,c=s?y&&o===0?b:s.indent:i?g.indent:h.indent,l,u;if(i?(l=g.trailingWs,u=g.hasBackslash&&g.content!==``?`\\`:``):(l=a.length>0&&/\s$/.test(a)?``:` `,u=`\\`),C.push(`${c}${a}${l}${u}`),!i){let e=t+n;if(!r&&e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}}}return l&&!(g.hasBackslash&&g.content===``)?`${a}${C.join(r)}${r}${u}"""`:`${a}${C.join(r)}"""`}}let n=x(e);for(let e of n)S.push(e)}for(let e=0;e<S.length;e++){let t=e===S.length-1,n=w.has(e),r=t||n,i=e<f.length?f[e]:null,a=E&&T.has(e)&&e>0?ee.get(e)??``:i?y&&e===0?b:i.indent:r?g.indent:h.indent,o=S[e],s,c;if(r&&t?(s=g.trailingWs,c=g.hasBackslash&&g.content!==``?`\\`:``):r?(s=g.trailingWs,c=``):(s=o.length>0&&/\s$/.test(o)?``:` `,c=`\\`),C.push(`${a}${o}${s}${c}`),!t&&!n&&!E){let t=S.join(``);if(!/(?<!\\)\\n/.test(t)&&e<_.length&&_[e].length>0)for(let t of _[e])C.push(t)}}return l&&!(g.hasBackslash&&g.content===``)?`${a}${C.join(r)}${r}${u}"""`:`${a}${C.join(r)}"""`}function jt(e){switch(e){case`b`:return`\b`;case`t`:return` `;case`n`:return`
14
+ `;case`f`:return`\f`;case`r`:return`\r`;case`"`:return`"`;case`\\`:return`\\`;default:return null}}function Mt(e,t){return t===`singleline-basic`?e<=31||e===127:e>=0&&e<=7||e===11||e>=14&&e<=31||e===127}function Nt(e,t){switch(e){case`\\`:return`\\\\`;case`\b`:return`\\b`;case` `:return`\\t`;case`\f`:return`\\f`;case`"`:return t===`singleline-basic`?`\\"`:`"`;case`
15
+ `:return t===`singleline-basic`?`\\n`:`
16
+ `;case`\r`:return t===`singleline-basic`?`\\r`:`\r`;default:{let n=e.charCodeAt(0);return Mt(n,t)?`\\u${n.toString(16).padStart(4,`0`).toUpperCase()}`:e}}}function Pt(e){let t=new Map;for(let n=0;n<e.length;n++){if(e[n]!==`\\`)continue;let r=e[n+1];if(!r)continue;let i=jt(r);if(i!==null){i!==`
17
+ `&&i!==`\r`&&!t.has(i)&&t.set(i,`\\`+r),n+=1;continue}if(r===`x`&&/^[0-9A-Fa-f]{2}$/.test(e.slice(n+2,n+4))){let r=e.slice(n,n+4),i=Number.parseInt(e.slice(n+2,n+4),16),a=String.fromCharCode(i);t.has(a)||t.set(a,r),n+=3;continue}if(r===`u`&&/^[0-9A-Fa-f]{4}$/.test(e.slice(n+2,n+6))){let r=e.slice(n,n+6),i=Number.parseInt(e.slice(n+2,n+6),16),a=String.fromCodePoint(i);t.has(a)||t.set(a,r),n+=5;continue}if(r===`U`&&/^[0-9A-Fa-f]{8}$/.test(e.slice(n+2,n+10))){let r=e.slice(n,n+10),i=Number.parseInt(e.slice(n+2,n+10),16),a=String.fromCodePoint(i);t.has(a)||t.set(a,r),n+=9;continue}}return t}function Ft(e,t,n){let r=``;for(let i of e){let e=t.get(i);if(e){r+=e;continue}r+=Nt(i,n)}return r}function It(e,t,n){let r=Pt(t);if(r.size===0&&n===`singleline-basic`)return JSON.stringify(e).slice(1,-1).replace(/\x7f/g,`\\u007F`);let i=Ft(e,r,n);return n===`multiline-basic`?i.replace(/"""/g,`""\\"`):i}function Lt(){return{type:`Document`,loc:{start:S(),end:S()},items:[]}}function Rt(e){let t=zt(e);return{type:`Table`,loc:x(t.loc),key:t,items:[]}}function zt(e){let t=Wt(e);return{type:`TableKey`,loc:{start:S(),end:{line:1,column:t.length+2}},item:{type:`Key`,loc:{start:{line:1,column:1},end:{line:1,column:t.length+1}},value:e,raw:t}}}function Bt(e){let t=Vt(e);return{type:`TableArray`,loc:x(t.loc),key:t,items:[]}}function Vt(e){let t=Wt(e);return{type:`TableArrayKey`,loc:{start:S(),end:{line:1,column:t.length+4}},item:{type:`Key`,loc:{start:{line:1,column:2},end:{line:1,column:t.length+2}},value:e,raw:t}}}function Ht(e,t){let n=Gt(e),{column:r}=n.loc.end,i=r+1;return Et(t,{lines:0,columns:r+3-t.loc.start.column},{first_line_only:!0}),{type:`KeyValue`,loc:{start:b(n.loc.start),end:b(t.loc.end)},key:n,equals:i,value:t}}function Ut(e){return JSON.stringify(e).replace(/\x7f/g,`\\u007f`)}function Wt(e){return e.map(e=>T.test(e)?e:Ut(e)).join(`.`)}function Gt(e){let t=Wt(e);return{type:`Key`,loc:{start:S(),end:{line:1,column:t.length}},raw:t,value:e}}function Kt(e,t){return t?qt(e,t):Jt(e)}function qt(e,t){if(nt(t))return Jt(e,t);if(it(t))return e.includes(`'`)?e.includes(`'''`)?Jt(e):Zt(e,`'''${t.slice(1,-1)}'''`):Yt(e);if(at(t))return e.includes(`'''`)?Xt(e,`"""${t.slice(3,-3)}"""`):Zt(e,t);if(rt(t))return Xt(e,t);throw Error(`Existing raw string value is not valid: ${t}`)}function Jt(e,t){let n=``;return n=t?`"${It(e,t,`singleline-basic`)}"`:Ut(e),{type:`String`,loc:{start:S(),end:{line:1,column:n.length}},raw:n,value:e}}function Yt(e){let t=`'${e}'`,n;if(t.includes(`
18
+ `)){let e=t.split(/\r\n|\n/),r=e[e.length-1];n={line:e.length,column:r.length}}else n={line:1,column:t.length};return{type:`String`,loc:{start:S(),end:n},raw:t,value:e}}function Xt(e,t){let n=It(e,t,`multiline-basic`),r=`"""`+(t.startsWith(`"""\r
19
+ `)?`\r
20
+ `:t.startsWith(`"""
21
+ `)?`
22
+ `:``)+n+`"""`,i=t.slice(3,-3);if(/(^|[^\\])(\\\\)*\\$/m.test(i)){let e=At(t,n);e!==null&&(r=e)}let a=Qt(r);return{type:`String`,loc:{start:S(),end:a},raw:r,value:e}}function Zt(e,t){let n=`'''`+(t.startsWith(`'''\r
23
+ `)?`\r
24
+ `:t.startsWith(`'''
25
+ `)?`
26
+ `:``)+e+`'''`,r=Qt(n);return{type:`String`,loc:{start:S(),end:r},raw:n,value:e}}function Qt(e){if(e.includes(`
27
+ `)){let t=e.split(/\r\n|\n/),n=t[t.length-1];return{line:t.length,column:n.length}}else return{line:1,column:e.length}}function $t(e){let t=e.toString();return{type:`Integer`,loc:{start:S(),end:{line:1,column:t.length}},raw:t,value:e}}function en(e,t=1){let n,r;if(e===1/0)n=`inf`;else if(e===-1/0)n=`-inf`;else if(Number.isNaN(e)){let t=new Float64Array([e]),i=(new DataView(t.buffer).getUint32(4,!0)&2147483648)!=0;r=i?`-`:void 0,n=i?`-nan`:`nan`}else if(Object.is(e,-0))n=`-0.`+`0`.repeat(Math.max(t,1));else{n=e.toString();let r=n.search(/[eE]/);if(r!==-1){let e=n.slice(0,r),i=n.slice(r),a=e.indexOf(`.`);if(a===-1)n=`${e}.${`0`.repeat(Math.max(t,1))}${i}`;else{let r=e.length-a-1;n=r<t?`${e}${`0`.repeat(t-r)}${i}`:`${e}${i}`}}else{let e=n.indexOf(`.`);if(e===-1)n+=`.`+`0`.repeat(Math.max(t,1));else{let r=n.length-e-1;r<t&&(n+=`0`.repeat(t-r))}}}return{type:`Float`,loc:{start:S(),end:{line:1,column:n.length}},raw:n,value:e,...r===void 0?{}:{nanSign:r}}}function tn(e){return{type:`Boolean`,loc:{start:S(),end:{line:1,column:e?4:5}},value:e}}function nn(e,t=!1){t&&e.getUTCHours()===0&&e.getUTCMinutes()===0&&e.getUTCSeconds()===0&&e.getUTCMilliseconds()===0&&(e=new ue(e.toISOString().split(`T`)[0]));let n=e.toISOString();return{type:`DateTime`,loc:{start:S(),end:{line:1,column:n.length}},raw:n,value:e}}function rn(e,t=!1){var n;let r=((n=e.constructor)==null?void 0:n.name)??``,i=r===`Temporal.PlainDate`||r===`PlainDate`,a=r===`Temporal.PlainTime`||r===`PlainTime`,o=r===`Temporal.PlainDateTime`||r===`PlainDateTime`,s;if(i)s=et(e);else if(a)s=et(e);else if(o){if(t){let t=globalThis.Temporal;if(!t)throw Error(`Temporal API is not available in this runtime. Set temporal: false or use a runtime with Temporal support.`);let n=t.PlainDate.from(e.toString().split(`T`)[0]);if(n.toString()+`T00:00:00`===e.toString().slice(0,19))return s=et(n),{type:`DateTime`,loc:{start:S(),end:{line:1,column:s.length}},raw:s,value:n}}s=et(e)}else s=et(e);return{type:`DateTime`,loc:{start:S(),end:{line:1,column:s.length}},raw:s,value:e}}function an(){return{type:`InlineArray`,loc:{start:S(),end:{line:1,column:2}},items:[]}}function on(e){return{type:`InlineItem`,loc:x(e.loc),item:e,comma:!1}}function sn(){return{type:`InlineTable`,loc:{start:S(),end:{line:1,column:2}},items:[]}}function cn(e){return new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(e)}function ln(e){return e.charCodeAt(0)===65279}function un(e){return ln(e)?e.slice(1):e}function dn(e){for(let t of e){let e=hn(t);if(e!==null)return e}return!1}function fn(e,t){for(let n of t){let t=pn(n,e);if(t!==null)return t}return!0}function pn(e,t){if(!e||typeof e!=`object`)return null;if((e.type===`InlineArray`||e.type===`InlineTable`)&&e.loc){let n=mn(e.loc,t);if(n!==null)return n}if(e.items&&Array.isArray(e.items))for(let n of e.items){let e=pn(n,t);if(e!==null)return e;if(n.item){let e=pn(n.item,t);if(e!==null)return e}}for(let n of[`value`,`key`,`item`])if(e[n]){let r=pn(e[n],t);if(r!==null)return r}return null}function mn(e,t){if(!e||!e.start||!e.end)return null;let n=t.split(/\r?\n/),r=e.start.line-1,i=e.end.line-1,a=e.start.column,o=e.end.column,s=``;if(r===i){var c;s=((c=n[r])==null?void 0:c.substring(a,o+1))||``}else{n[r]&&(s+=n[r].substring(a));for(let e=r+1;e<i;e++)s+=`
28
+ `+(n[e]||``);n[i]&&(s+=`
29
+ `+n[i].substring(0,o+1))}let l=s.match(/^\[(\s*)/),u=s.match(/^\{(\s*)/);return l?l[1].length>0:u?u[1].length>0:null}function hn(e){if(!e||typeof e!=`object`)return null;if(e.type===`InlineArray`&&e.items&&Array.isArray(e.items)||e.type===`InlineTable`&&e.items&&Array.isArray(e.items))return gn(e.items);if(e.type===`KeyValue`&&e.value)return hn(e.value);if(e.items&&Array.isArray(e.items))for(let t of e.items){let e=hn(t);if(e!==null)return e}return null}function gn(e){if(e.length===0)return null;let t=e[e.length-1];return t&&typeof t==`object`&&`comma`in t?t.comma===!0:!1}function _n(e){let t=e.indexOf(`
30
+ `);return t>0&&e[t-1]===`\r`?`\r
31
+ `:`
32
+ `}function vn(e){let t=0,n=e.length;for(;n>0&&e[n-1]===`
33
+ `;)t++,n--,n>0&&e[n-1]===`\r`&&n--;return t}function yn(e){let t=e.split(/\r?\n/),n=0,r=0;for(let e of t)if(e.length!==0&&(e[0]===` `?n++:e[0]===` `&&r++,n+r>=5))break;return n>r}function bn(e){if(!e||typeof e!=`object`)return{};let t=e=>typeof e==`boolean`?null:`expected boolean, got ${typeof e}`,n={newLine:e=>typeof e==`string`?null:`expected string, got ${typeof e}`,trailingNewline:e=>typeof e==`boolean`||typeof e==`number`?null:`expected boolean or number, got ${typeof e}`,trailingComma:t,bracketSpacing:t,leadingBom:t,inlineTableStart:e=>e==null||typeof e==`number`&&Number.isInteger(e)&&e>=0?null:`expected non-negative integer or undefined, got ${typeof e}`,truncateZeroTimeInDates:t,useTabsForIndentation:t,minimumDecimals:e=>e==null||typeof e==`number`&&Number.isInteger(e)&&e>=0?null:`expected non-negative integer or undefined, got ${typeof e}`,updateOrder:t},r={},i=[],a=[];for(let t in e){let o=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0;if(o){let n=e[t],i=o(n);i?a.push(`${t} (${i})`):r[t]=n}else Object.prototype.hasOwnProperty.call(e,t)&&i.push(t)}if(i.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${i.join(`, `)}. Supported properties are: ${Object.keys(n).join(`, `)}`),a.length>0)throw TypeError(`Invalid types for format properties: ${a.join(`, `)}`);return r}function xn(e,t){if(e){if(e instanceof K)return e;{let n=bn(e);return new K(n.newLine??t.newLine,n.trailingNewline??t.trailingNewline,n.trailingComma??t.trailingComma,n.bracketSpacing??t.bracketSpacing,`inlineTableStart`in n?n.inlineTableStart:t.inlineTableStart,n.truncateZeroTimeInDates??t.truncateZeroTimeInDates,n.useTabsForIndentation??t.useTabsForIndentation,n.minimumDecimals??t.minimumDecimals,n.leadingBom??t.leadingBom,n.updateOrder??t.updateOrder)}}else return t}var K=class e{newLine;trailingNewline;trailingComma;bracketSpacing;leadingBom;inlineTableStart;truncateZeroTimeInDates;useTabsForIndentation;minimumDecimals;updateOrder;constructor(e,t,n,r,i,a,o,s,c,l){this.newLine=e??`
34
+ `,this.trailingNewline=t??1,this.trailingComma=n??!1,this.bracketSpacing=r??!0,this.inlineTableStart=i??1,this.truncateZeroTimeInDates=a??!1,this.useTabsForIndentation=o??!1,this.minimumDecimals=s??0,this.leadingBom=c??!1,this.updateOrder=l??!1}static default(){return new e(`
35
+ `,1,!1,!0,1,!1,!1,0,!1,!1)}static autoDetectFormat(t){return e.autoDetectFormatWithCst(t)}static autoDetectFormatWithCst(t,n){let r=e.default();r.leadingBom=ln(t);let i=un(t);r.newLine=_n(i),r.trailingNewline=vn(i);try{let e=Array.isArray(n)?n:Array.from(n??P(i));r.trailingComma=dn(e),r.bracketSpacing=fn(i,e)}catch{r.trailingComma=!1,r.bracketSpacing=!0}return r.useTabsForIndentation=yn(i),r.inlineTableStart=1,r.truncateZeroTimeInDates=!1,r.minimumDecimals=0,r.updateOrder=!1,r}static autoDetectFormatWithAst(t,n){return e.autoDetectFormatWithCst(t,n)}};function Sn(e){return!l(e)||e.items.length===0?!1:e.items[e.items.length-1].comma===!0}function Cn(e){return!d(e)||e.items.length===0?!1:e.items[e.items.length-1].comma===!0}function wn(e,t){return t.inlineTableStart===0?e:(e.items.filter(e=>{if(!a(e))return!1;let n=d(e.value),r=l(e.value)&&e.value.items.length>0&&e.value.items.every(e=>d(e.item));if(n||r){let n=On(e.key.value);return t.inlineTableStart===void 0||n<t.inlineTableStart}return!1}).forEach(t=>{W(e,e,t),d(t.value)?t.value.items.length===0?U(e,e,Rt(t.key.value)):U(e,e,Tn(t)):En(t).forEach(t=>{U(e,e,t)})}),G(e),e)}function Tn(e){let t=Rt(e.key.value);for(let n of e.value.items)U(t,t,n.item);return G(t),t}function En(e){let t=Lt();for(let n of e.value.items){let r=Bt(e.key.value);U(t,t,r);for(let e of n.item.items)U(t,r,e.item)}return G(t),t.items}function Dn(e){if(e.items.length>0){let t=e.items[e.items.length-1];e.loc.end.line=t.loc.end.line,e.loc.end.column=t.loc.end.column}else e.loc.end.line=e.key.loc.end.line,e.loc.end.column=e.key.loc.end.column}function On(e){return Math.max(0,e.length-1)}function kn(e,t){if(t.inlineTableStart===void 0||t.inlineTableStart===0)return e;let n=[];for(let i of e.items)if(a(i)&&d(i.value)){if(On(i.key.value)<t.inlineTableStart){let r=Tn(i);W(e,e,i),U(e,e,r),An(r,n,t)}}else(i.type===`Table`||r(i))&&An(i,n,t);for(let t of n)U(e,e,t);return G(e),e}function An(e,t,n){for(let r=e.items.length-1;r>=0;r--){let i=e.items[r];if(a(i)&&d(i.value)){let r=[...e.key.item.value,...i.key.value];if(On(r)<(n.inlineTableStart??1)){let a=Rt(r);for(let e of i.value.items)U(a,a,e.item);W(e,e,i),Dn(e),t.push(a),An(a,t,n)}}}}function jn(e){let t=0,n=0;for(let r of e.items)n===0&&r.loc.start.line>1?t=1-r.loc.start.line:r.loc.start.line+t>n+2&&(t+=n+2-(r.loc.start.line+t)),Et(r,{lines:t,columns:0}),n=r.loc.end.line;return e}function q(e,t=K.default()){e=In(e);let n=Lt();for(let r of Mn(e,t))U(n,n,r);return G(n),wn(n,t),kn(n,t),jn(n)}function*Mn(e,t){for(let n of Object.keys(e)){let r=e[n];if(r===void 0)continue;let i=In(r);i!==void 0&&(yield Ht([n],Nn(i,t)))}}function Nn(e,t){let n=t.minimumDecimals??0;if(e===null)throw Error(`"null" values are not supported`);if(e===void 0)throw Error(`"undefined" values are not supported inside arrays`);return Je(e)?Kt(e):Xe(e)?$t(e):Ye(e)?n>0?en(e,n):$t(e):Ze(e)?en(e,Math.max(n,1)):Qe(e)?tn(e):L(e)?rn(e,t.truncateZeroTimeInDates):I(e)?nn(e,t.truncateZeroTimeInDates):Array.isArray(e)?Pn(e,t):Fn(e,t)}function Pn(e,t){let n=an();for(let r of e)U(n,n,on(Nn(r,t)));return wt(n,n,t.bracketSpacing),Tt(n,n,t.trailingComma),G(n),n}function Fn(e,t){if(e=In(e),!R(e))return Nn(e,t);let n=sn();for(let r of Mn(e,t))U(n,n,on(r));return wt(n,n,t.bracketSpacing),Tt(n,n,t.trailingComma),G(n),n}function In(e){return!e||I(e)||L(e)?e:typeof e.toJSON==`function`?e.toJSON():e}const Ln=/(\r\n|\n)/g;function Rn(e,t){let n=[];function r(e){switch(e.type){case`Document`:for(let t=0;t<e.items.length;t++)r(e.items[t]);break;case`Table`:{let t=e;r(t.key);for(let e=0;e<t.items.length;e++)r(t.items[e]);break}case`TableKey`:{let t=e;J(n,t.loc,`[`+t.item.raw+`]`);break}case`TableArray`:{let t=e;r(t.key);for(let e=0;e<t.items.length;e++)r(t.items[e]);break}case`TableArrayKey`:{let t=e;J(n,t.loc,`[[`+t.item.raw+`]]`);break}case`KeyValue`:{let t=e,i=t.loc.start.line;zn(n,i,t.equals,`=`),r(t.key),r(t.value);break}case`Key`:J(n,e.loc,e.raw);break;case`String`:J(n,e.loc,e.raw);break;case`Integer`:J(n,e.loc,e.raw);break;case`Float`:J(n,e.loc,e.raw);break;case`Boolean`:J(n,e.loc,e.value.toString());break;case`DateTime`:J(n,e.loc,e.raw);break;case`InlineArray`:{let t=e,{start:i,end:a}=t.loc;zn(n,i.line,i.column,`[`),zn(n,a.line,a.column-1,`]`);for(let e=0;e<t.items.length;e++)r(t.items[e]);break}case`InlineTable`:{let t=e,{start:i,end:a}=t.loc;zn(n,i.line,i.column,`{`),zn(n,a.line,a.column-1,`}`);for(let e=0;e<t.items.length;e++)r(t.items[e]);break}case`InlineItem`:{let t=e;if(r(t.item),t.comma){let e=t.loc.end;zn(n,e.line,e.column,`,`)}break}case`Comment`:J(n,e.loc,e.raw);break;default:{let t=e.type;throw Error(`toTOML: Unrecognized node type: ${String(t)}`)}}}if(tt(e))for(let t of e)r(t);else r(e);if(t.useTabsForIndentation)for(let e=0;e<n.length;e++){let t=n[e],r=t.match(/^( +)/);if(r){let i=r[1];n[e]=` `.repeat(i.length)+t.substring(i.length)}}return n.join(t.newLine)+t.newLine.repeat(t.trailingNewline)}function J(e,t,n){if(t.start.line===t.end.line){let r=Bn(e,t.start.line),i=r.substring(0,t.start.column),a=i.length<t.start.column?i.padEnd(t.start.column,` `):i,o=r.substring(t.end.column);e[t.start.line-1]=a+n+o;return}let r=n.split(Ln).filter(e=>e!==`
36
+ `&&e!==`\r
37
+ `),i=t.end.line-t.start.line+1;if(r.length!==i)throw Error(`Mismatch between location and raw string, expected ${i} lines for "${n}"`);for(let n=t.start.line;n<=t.end.line;n++){let i=Bn(e,n),a=n===t.start.line,o=n===t.end.line,s=``;if(a){let e=i.substring(0,t.start.column);s=e.length<t.start.column?e.padEnd(t.start.column,` `):e}let c=o?i.substring(t.end.column):``;e[n-1]=s+r[n-t.start.line]+c}}function zn(e,t,n,r){let i=Bn(e,t),a=i.length<n?i.padEnd(n,` `):i.substring(0,n),o=i.substring(n+1);e[t-1]=a+r+o}function Bn(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]=``);return e[t-1]}function Vn(e,t=`asNeeded`){let n=e.replace(/_/g,``),r=n;if(/^[+-]?0x/i.test(n)||/^[+-]?0o/i.test(n)||/^[+-]?0b/i.test(n)){let e=n[0]===`+`||n[0]===`-`?n[0]:``;r=e+n.slice(+!!e).toLowerCase()}let i;try{i=BigInt(r)}catch{return Number(n)}return t===!0?i:t===!1||i>=BigInt(-(2**53-1))&&i<=BigInt(2**53-1)?Number(i):i}function Hn(e,t,n){for(let r of e.items){let e=r.item;if(e.value.type===`InlineTable`){let r=t.concat(e.key.value);n.add(X(r)),Hn(e.value,r,n)}}}function Un(e){var t,n,r,i,a,o;if((t=e.constructor)!=null&&(t=t.name)!=null&&(n=t.startsWith)!=null&&n.call(t,`Temporal.`)||((r=e.constructor)==null?void 0:r.name)===`PlainDate`||((i=e.constructor)==null?void 0:i.name)===`PlainTime`||((a=e.constructor)==null?void 0:a.name)===`PlainDateTime`||((o=e.constructor)==null?void 0:o.name)===`ZonedDateTime`)return e;let s=globalThis.Temporal;if(e instanceof ue)return s.PlainDate.from(e.toISOString());if(e instanceof de)return s.PlainTime.from(e.toISOString());if(e instanceof M)return s.PlainDateTime.from(e.toISOString().replace(` `,`T`));if(e instanceof fe){let t=e.toISOString().replace(` `,`T`),n=t.match(/([+-]\d{2}:\d{2}|Z)$/),r=n?n[1]:`Z`,i=t.replace(/([+-]\d{2}:\d{2}|Z)$/,``),a=r===`Z`?`+00:00`:r;return s.ZonedDateTime.from(`${i}${r}[${a}]`)}return s.PlainDateTime.from(e.toISOString().replace(`Z`,``))}function Y(e,t=``,n={}){let{integersAsBigInt:r=`asNeeded`,temporal:i=!1}=n,a=qe(),o=new Set,s=new Set,c=new Set,l=new Set,u=new Set,d=a,f=[],p={tables:o,table_arrays:s,defined:c,implicit_tables:l,inline_tables:u};for(let t of e)switch(t.type){case`Table`:m(t);for(let e of t.items)e.type===`KeyValue`&&g(e);break;case`TableArray`:h(t);for(let e of t.items)e.type===`KeyValue`&&g(e);break;case`KeyValue`:g(t);break}return a;function m(e){let n=e.key.item.value;try{Gn(a,[],n,e.type,p)}catch(n){let r=n;throw new C(t,e.key.loc.start,r.message)}let r=X(n);o.add(r),c.add(r),d=Kn(a,n),f=n}function h(e){let n=e.key.item.value;try{Gn(a,[],n,e.type,p)}catch(n){let r=n;throw new C(t,e.key.loc.start,r.message)}let r=X(n);s.add(r),c.add(r),d=qn(a,n),f=n}function g(e){let n=e.key.value;try{Gn(d,f,n,e.type,p)}catch(n){let r=n;throw new C(t,e.key.loc.start,r.message)}if(n.length>1)for(let e=1;e<n.length;e++){let t=X(f.concat(n.slice(0,e)));l.add(t),c.add(t)}let a;try{a=Wn(e.value,{integersAsBigInt:r,temporal:i})}catch(n){let r=n;throw new C(t,e.value.loc.start,r.message)}if(e.value.type===`InlineTable`){let t=f.concat(n);u.add(X(t)),Hn(e.value,t,u)}let o=n.length>1?Kn(d,n.slice(0,-1)):d;o[F(n)]=a,c.add(X(f.concat(n)))}}function Wn(e,t={}){let{integersAsBigInt:n=`asNeeded`,temporal:r=!1}=t;switch(e.type){case`InlineTable`:let t=qe(),i=new Set,a=new Map;return e.items.forEach(({item:e})=>{let o=e.key.value,s=Wn(e.value,{integersAsBigInt:n,temporal:r}),c=X(o);if(i.has(c))throw Error(`Duplicate key "${c}" in inline table`);for(let e=1;e<o.length;e++){let t=X(o.slice(0,e));if(i.has(t))throw Error(`Key "${c}" conflicts with key: "${t}"`)}if(a.has(c)){let e=a.get(c);throw Error(`Key "${c}" conflicts with key: "${e}"`)}i.add(c);for(let e=1;e<o.length;e++){let t=X(o.slice(0,e));a.has(t)||a.set(t,c)}let l=o.length>1?Kn(t,o.slice(0,-1)):t;l[F(o)]=s}),t;case`InlineArray`:return e.items.map(e=>Wn(e.item,{integersAsBigInt:n,temporal:r}));case`DateTime`:if(r){if(globalThis.Temporal===void 0)throw Error(`Temporal API is not available in this runtime. Set temporal: false or use a runtime with Temporal support.`);return Un(e.value)}return e.value;case`String`:return e.value;case`Integer`:return Vn(e.raw,n);case`Float`:case`Boolean`:return e.value;default:throw Error(`Unrecognized value type "${e.type}"`)}}function Gn(e,t,n,r,i){let a=t.length>0?X(t):``,o=Array(n.length),s=a;for(let e=0;e<n.length;e++)s=s?s+`.`+n[e]:n[e],o[e]=s;let c=o[n.length-1];if(r===`KeyValue`&&n.length>1)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.inline_tables.has(t))throw Error(`Cannot extend inline table at ${t}`)}if((r===`Table`||r===`TableArray`)&&i.inline_tables.has(c))throw Error(`Cannot extend inline table at ${c}`);if(r===`Table`||r===`TableArray`)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.inline_tables.has(t))throw Error(`Cannot extend inline table at ${t}`)}if(r===`KeyValue`&&n.length>1)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.table_arrays.has(t))throw Error(`Cannot traverse Array of Tables at ${t}`)}if((r===`Table`||r===`TableArray`)&&i.implicit_tables.has(c))throw Error(`Implicit table already defined: ${c}`);if(r===`KeyValue`&&i.implicit_tables.has(c))throw Error(`Table already defined: ${c}`);if(r===`KeyValue`&&n.length>1)for(let e=1;e<=n.length;e++){let t=o[e-1];if(i.tables.has(t))throw Error(`Cannot extend explicit table ${t} with dotted keys`)}let l=0;for(let t of n){if(!ot(e,t))return;if(Yn(e[t]))throw Error(`Value already defined for ${o[l]}`);let r=o[l];if(Array.isArray(e[t])&&!i.table_arrays.has(r))throw Error(`Cannot add to static array at ${r}`);let a=l++<n.length-1;e=Array.isArray(e[t])&&a?F(e[t]):e[t]}let u=c;if(e&&r===`Table`&&i.defined.has(u)||e&&r===`KeyValue`&&n.length===1&&i.defined.has(u)&&!Yn(e))throw Error(`Table already defined: ${u}`);if(e&&r===`TableArray`&&!i.table_arrays.has(u))throw Error(`Cannot add Array of Tables to table at ${u}`)}function Kn(e,t){let n=Jn(e,t.slice(0,-1)),r=F(t);return n[r]||(n[r]=qe()),n[r]}function qn(e,t){let n=Jn(e,t.slice(0,-1)),r=F(t);n[r]||(n[r]=[]);let i=qe();return n[F(t)].push(i),i}function Jn(e,t){return t.reduce((e,t)=>(e[t]||(e[t]=qe()),Array.isArray(e[t])?F(e[t]):e[t]),e)}function Yn(e){return typeof e!=`object`&&!I(e)}function X(e){return e.join(`.`)}function Xn(e){return e.type===`Add`}function Zn(e){return e.type===`Edit`}function Z(e){return e.type===`Remove`}function Qn(e){return e.type===`Move`}function $n(e){return e.type===`Rename`}function er(e,t,n=[],r={}){if(e===t||st(e,t))return[];if(typeof e==`number`&&typeof t==`number`&&Number.isNaN(e)&&Number.isNaN(t)){let n=new Float64Array([e]),r=new Float64Array([t]),i=new DataView(n.buffer),a=new DataView(r.buffer);if((i.getUint32(4,!0)&2147483648)==(a.getUint32(4,!0)&2147483648))return[]}return Array.isArray(e)&&Array.isArray(t)?nr(e,t,n,r):R(e)&&R(t)?tr(e,t,n,r):[{type:`Edit`,path:n}]}function tr(e,t,n=[],r={}){let i=[],a=Object.keys(e),o=a.map(t=>B(e[t])),s=Object.keys(t),c=s.map(e=>B(t[e])),l=(e,t)=>{if(t.indexOf(e)<0)return!1;let n=a[o.indexOf(e)];return!s.includes(n)},u=new Map;if(a.forEach((a,d)=>{let f=n.concat(a);if(s.includes(a))ct(i,er(e[a],t[a],f,r));else if(l(o[d],c)){let e=s[c.indexOf(o[d])];i.push({type:`Rename`,path:n,from:a,to:e}),u.set(a,e)}else i.push({type:`Remove`,path:f})}),s.forEach((e,t)=>{!a.includes(e)&&!l(c[t],o)&&i.push({type:`Add`,path:n.concat(e)})}),r.updateOrder){let e=[];for(let t of a)if(s.includes(t))e.includes(t)||e.push(t);else if(u.has(t)){let n=u.get(t);e.includes(n)||e.push(n)}for(let t of s)e.includes(t)||e.push(t);s.forEach((t,r)=>{if(e[r]===t)return;let a=e.indexOf(t);i.push({type:`Move`,path:n,from:a,to:r,key:t}),e.splice(a,1),e.splice(r,0,t)})}return i}function nr(e,t,n=[],r={}){let i=[],a=e.map(B),o=t.map(B);o.forEach((s,c)=>{let l=c>=a.length;if(!l&&a[c]===s)return;let u=a.indexOf(s,c+1);if(!l&&u>-1){i.push({type:`Move`,path:n,from:u,to:c});let e=a.splice(u,1);a.splice(c,0,...e);return}let d=!o.includes(a[c]);if(!l&&d){ct(i,er(e[c],t[c],n.concat(c),r)),a[c]=s;return}i.push({type:`Add`,path:n.concat(c)}),a.splice(c,0,s)});for(let e=o.length;e<a.length;e++)i.push({type:`Remove`,path:n.concat(e)});return i}function Q(n,i){if(!i.length)return u(n)&&a(n.item)?n.item:n;if(a(n))return Q(n.value,i);let o={},s;if(p(n)&&n.items.some((c,l)=>{try{let d=[];if(a(c))d=c.key.value;else if(t(c))d=c.key.item.value;else if(r(c)){d=c.key.item.value;let e=B(d);o[e]||(o[e]=0);let t=o[e]++;d=d.concat(t)}else u(c)&&a(c.item)?d=c.item.key.value:u(c)&&(d=[l]);if(d.length&&z(d,i.slice(0,d.length))){let t=i.slice(d.length);if(e(n)&&r(c)&&t.length>0){let e=c.key.item.value,i=n,a=i.items.findIndex((t,n)=>n>l&&r(t)&&z(t.key.item.value,e)),o=a===-1?i.items.length:a;s=rr(c,t,e,i.items.slice(l+1,o))}else s=u(c)&&a(c.item)?i.length===d.length?c:Q(c.item.value,t):u(c)&&i.length>d.length?Q(c.item,t):Q(c,t);return!0}else return!1}catch{return!1}}),!s)throw Error(`Node not found at ${i.join(`.`)}`);return s}function rr(e,n,i,a){try{return Q(e,n)}catch{}let o={};for(let e of a){let a=[];if(t(e)){let t=e.key.item.value;t.length>i.length&&z(t.slice(0,i.length),i)&&(a=t.slice(i.length))}else if(r(e)){let t=e.key.item.value;if(t.length>i.length&&z(t.slice(0,i.length),i)){let e=t.slice(i.length),n=B(e);o[n]||(o[n]=0);let r=o[n]++;a=e.concat(r)}}if(a.length&&z(a,n.slice(0,a.length)))try{return Q(e,n.slice(a.length))}catch{}}throw Error(`Node not found at (aot scope) ${n.join(`.`)}`)}function $(e,t){try{return Q(e,t)}catch{}}function ir(e,t){let n=t,r;for(;n.length&&!r;)n=n.slice(0,-1),r=$(e,n);if(!r)throw Error(`Parent not found for ${t.join(`.`)}`);return r}const ar=String.raw`(?:[\w-]+|"[^"]*"|'[^']*')`,or=new RegExp(String.raw`^#\s*${ar}(?:\s*\.\s*${ar})*\s*=`),sr=new RegExp(String.raw`^#\s*\[\[?\s*${ar}(?:\s*\.\s*${ar})*\s*\]\]?\s*$`);function cr(e){return or.test(e.raw)||sr.test(e.raw)}function lr(e){return(d(e)||l(e))&&e.loc.end.line>e.loc.start.line}function ur(e){if(a(e))return e.key.value[0];if(t(e)||r(e))return e.key.item.value[0];if(u(e)&&a(e.item))return e.item.key.value[0]}function dr(e,t,n){let r=[],i=t,a,o=[],s=()=>{o.length&&(r.push({kind:`pinned`,items:o,startLine:o[0].loc.start.line,endLine:F(o).loc.end.line}),o=[])};for(let t of e){if(f(t)){if(t.loc.start.line<=i){a?(a.items.push(t),a.endLine=Math.max(a.endLine,t.loc.end.line)):r.push({kind:`pinned`,items:[t],startLine:t.loc.start.line,endLine:t.loc.end.line});continue}let e=o.length?F(o).loc.end.line:void 0;o.length&&t.loc.start.line===e+1||s(),o.push(t);continue}let e=[];if(o.length){let r=F(o).loc.end.line+1===t.loc.start.line,i=o.every(cr);r&&n(t)&&!i?(e=o,o=[]):s()}let c=[...e,t],l={kind:`member`,member:t,key:ur(t),items:c,startLine:c[0].loc.start.line,endLine:t.loc.end.line};r.push(l),a=l,i=t.loc.end.line}return s(),r}function fr(t,n=()=>!0){let r=e(t)?0:t.key.loc.end.line;return dr(t.items,r,n)}function pr(e,t){let n=t.filter(t=>f(t)&&t.loc.start.line>=e.loc.start.line&&t.loc.start.line<=e.loc.end.line);return dr([...e.items,...n].sort((e,t)=>e.loc.start.line-t.loc.start.line||e.loc.start.column-t.loc.start.column),e.loc.start.line,()=>!0)}function mr(e,n){function i(e,t){if(e===n)return t;if(d(e)||l(e))for(let r of e.items){if(r===n)return t;let e=i(r.item,t);if(e)return e}}function o(e){for(let s of e.items){if(s===n)return e;if(a(s)){let t=i(s.value,e);if(t)return t}else if(t(s)||r(s)){let e=o(s);if(e)return e}}}return o(e)}function hr(e){for(let n=0;n<e.items.length;n++){let i=e.items[n];if(!t(i)&&!r(i))continue;let a=e.items[n+1];if(!a)continue;let o=gr(i,a);if(!o)continue;let s=i.items;s.splice(s.length-o.length,o.length),e.items.splice(n+1,0,...o),Ct(i),n+=o.length}}function gr(e,t){let n=F(fr(e));if(!n||n.kind!==`pinned`)return;let r=n.items,i=n.endLine+1===t.loc.start.line,a=r.every(cr);if(!(!i||a))return r}function _r(n,i,a){if(e(i)&&(t(a)||r(a))){let e=i.items.indexOf(a),o=e>0?i.items[e-1]:void 0;if(o&&(t(o)||r(o))){let e=gr(o,a);if(e)for(let t of e)W(n,o,t)}}if(e(i)||t(i)||r(i)){let e=fr(i).find(e=>e.member===a);if(e){let t=e.items.indexOf(a);for(let r=0;r<=t;r++){let t=e.items[r];i.items.includes(t)&&W(n,i,t)}for(let n=t+1;n<e.items.length;n++){let t=e.items[n],r=i.items.indexOf(t);r<0||i.items.splice(r,1)}return}}if(lr(i)&&e(n)){let e=mr(n,i);if(e){let t=pr(i,e.items).find(e=>e.member===a);if(t){let r=t.items.filter(e=>e!==a);for(let t of r){let n=e.items.indexOf(t);n<0||e.items.splice(n,1)}r.length&&(a.loc.start=t.items[0].loc.start,a.loc.end=F(t.items).loc.end),W(n,i,a,e.items),G(n);return}}}W(n,i,a)}function vr(t,n,r,i){if(lr(n)&&e(t)){let e=mr(t,n);if(e){let a=pr(n,e.items),o=[],s,c;for(let t of a){if(t.kind!==`member`||!t.member)continue;let n=t.items.filter(e=>e!==t.member);if(t.member===r&&(s=b(r.loc.start),c=b(r.loc.end),n.length&&(r.loc.start=b(t.items[0].loc.start),r.loc.end=b(F(t.items).loc.end))),n.length){o.push({owner:t.member,ownerOriginalStart:b(t.member.loc.start),comments:n});for(let t of n){let n=e.items.indexOf(t);n>=0&&e.items.splice(n,1)}}}W(t,n,r,e.items),U(t,n,r,i,void 0,e.items),G(t);for(let{owner:t,ownerOriginalStart:n,comments:i}of o){let a;t===r?(a={lines:r.loc.start.line-n.line,columns:r.loc.start.column-n.column},r.loc.start={line:s.line+a.lines,column:s.column+a.columns},r.loc.end={line:c.line+a.lines,column:c.column+a.columns}):a={lines:t.loc.start.line-n.line,columns:t.loc.start.column-n.column};for(let t of i){Et(t,a);let n=e.items.findIndex(e=>e.loc.start.line>t.loc.start.line);n===-1?e.items.push(t):e.items.splice(n,0,t)}}return}}W(t,n,r),U(t,n,r,i)}function yr(e){let n=[];for(let i of e){if(i.kind===`pinned`){n.push({kind:`pinned`,isSection:!1,movable:!1,slots:[i],startLine:i.startLine,endLine:i.endLine,items:i.items});continue}let e=t(i.member)||r(i.member),a=n[n.length-1];if(a&&a.kind===`member`&&a.key===i.key){a.slots.push(i),a.endLine=i.endLine,a.items=a.items.concat(i.items);continue}n.push({kind:`member`,key:i.key,isSection:e,movable:!0,slots:[i],startLine:i.startLine,endLine:i.endLine,items:[...i.items]})}let i=new Map;for(let e of n)e.kind===`member`&&e.key!==void 0&&i.set(e.key,(i.get(e.key)??0)+1);for(let e of n)e.kind===`member`&&e.key!==void 0&&i.get(e.key)>1&&(e.movable=!1);return n}function br(e,t){let n=[...e];for(let e of t){if(e.key===void 0)continue;let t=n.indexOf(e.key);if(t===-1)continue;let r=Math.max(0,Math.min(e.to,n.length-1));t!==r&&(n.splice(t,1),n.splice(r,0,e.key))}return n}function xr(e){return[...e.path,e.key].join(`.`)}function Sr(n,i){if(i.length===0)return n;let o;try{o=$(n,i)}catch{return}if(o&&(a(o)&&(o=o.value),o&&m(o)&&(o=o.item),o&&(e(o)||t(o)||r(o))))return o}function Cr(t,n,r,i){let a=yr(fr(t,e=>r.has(e))),o=new Map;for(let e of a)e.kind===`member`&&e.movable&&e.key!==void 0&&o.set(e.key,e);let s=new Set(a.filter(e=>e.kind===`member`&&e.key!==void 0).map(e=>e.key));for(let e of n)e.key!==void 0&&s.has(e.key)&&!o.has(e.key)&&i.push(`"${xr(e)}" -- its entries are not contiguous in the document (e.g. the TOML spec's own "valid but discouraged" out-of-order table pattern), so reordering was skipped for it`);if(o.size===0)return;let c=0,l=a.filter(e=>e.kind===`member`).map(e=>e.movable?e.key:`\u0000anchor:${c++}`),u=n.filter(e=>e.key!==void 0&&o.has(e.key));if(u.length===0)return;let d=br(l,u).filter(e=>o.has(e)),f=d.filter(e=>!o.get(e).isSection),p=d.filter(e=>o.get(e).isSection),m=!1;for(let e of d)if(o.get(e).isSection)m=!0;else if(m){i.push(`the requested order asked for a root key-value to be positioned after a section header, which TOML cannot represent -- each group (root key-values, section blocks) was reordered to match its own requested relative order instead`);break}let h=0,g=0,_=a.map(e=>{if(e.kind!==`member`||!e.movable)return e;let t=e.isSection?p[g++]:f[h++];return o.get(t)});if(_.every((e,t)=>e===a[t]))return;let v=e(t)?1:t.key.loc.end.line,y=a.map((e,t)=>t===0?e.startLine-v:e.startLine-a[t-1].endLine-1),b=v;for(let e=0;e<_.length;e++){let t=_[e],n=y[e],r=(e===0?b:b+1)+n-t.startLine;if(r!==0)for(let e of t.items)Et(e,{lines:r,columns:0});b=t.endLine+r}let x=_.flatMap(e=>e.items),S=t.items;S.splice(0,S.length,...x),Ct(t)}function wr(e,t,n){if(t.length===0)return;hr(e);let r=[],i=new Map;for(let n of t){if(n.key===void 0)continue;let t=Sr(e,n.path);if(!t){r.push(`"${xr(n)}" -- unsupported location for reordering (e.g. a dotted-key implicit table, or an interior of an inline table/array-of-tables entry)`);continue}let a=i.get(t);a?a.push(n):i.set(t,[n])}for(let[e,t]of i)Cr(e,t,n,r);if(r.length>0){let e=[...new Set(r)];console.warn(`toml-patch: updateOrder could not honor the requested position for ${e.length===1?`1 entry`:`${e.length} entries`}, left unchanged:\n`+e.map(e=>` - ${e}`).join(`
38
+ `))}Ct(e)}const Tr=new WeakMap,Er=new WeakMap;function Dr(e,t){let n=e[t].loc.end.line;for(let r=t+1;r<e.length;r++){let t=e[r];if(f(t)&&t.loc.start.line===n)return t;if(!f(t)&&t.loc.start.line>n)return}}function Or(e,t,n){for(let r=t+n;r>=0&&r<e.length;r+=n)if(!f(e[r]))return r}function kr(e,t,n){Er.has(e)||Er.set(e,e.loc.start.column);let r=e.loc.start.column+n,i=Math.max(t,r)-r;i!==0&&(e.loc.start.column+=i,e.loc.end.column+=i)}function Ar(e,t){Er.set(t,t.loc.start.column),Tr.set(t,t.loc.start.column-e.loc.end.column)}function jr(e,t,n,r){if(!p(e))return;let i=e.items,a=i.indexOf(t);if(a<0)return;let o=Dr(i,a);if(!o||n.loc.start.line!==n.loc.end.line||r.loc.start.line!==r.loc.end.line)return;let s=o.loc.start.column,c=o.loc.start.line,l=[Or(i,a,-1),Or(i,a,1)],u;for(let e of l){if(e==null)continue;let t=Dr(i,e);if(t&&Math.abs(t.loc.start.line-c)===1&&t.loc.start.column===s){u=t.loc.start.column;break}}if(u==null)return;let d=g(n.loc),f=g(r.loc).columns-d.columns;kr(o,u,f)}function Mr(e,t,n){if(!p(e))return;let r=e.items,i=r.indexOf(t);if(i<0)return;let a=Dr(r,i);if(!a)return;let o=a.loc.start.column,s=a.loc.start.line,c=[Or(r,i,-1),Or(r,i,1)];for(let e of c){if(e==null)continue;let t=Dr(r,e);if(t&&Math.abs(t.loc.start.line-s)===1&&t.loc.start.column===o){kr(a,t.loc.start.column,n);return}}}function Nr(e,t,n){if(!p(e)||n===0)return;let r=e.items,i=r.indexOf(t);if(i<0)return;let a=Dr(r,i);a&&Ar(t,a)}function Pr(e,t,n){if(!l(e)&&!d(e))return 0;let r=g(t.loc),i=n>0,a=n<e.items.length,o=n===e.items.length,s=u(t)?t.comma:!1,c=i&&s&&!a&&o;return r.columns+(i||a?2:0)+(s?1+(c?-1:0):0)}function Fr(e,n=[]){for(let i of e.items){if(f(i)){n.push(i);continue}(t(i)||r(i))&&Fr(i,n)}return n}function Ir(e,n=new Set){for(let i of e.items){if(a(i)&&d(i.value)&&i.loc.start.line===i.loc.end.line){n.add(i.loc.end.line);continue}(t(i)||r(i))&&Ir(i,n)}return n}function Lr(e){for(let n of e.items)(t(n)||r(n))&&Lr(n);let n=e.loc.end.line,i=e.loc.end.column,a=(e,t)=>{(e>n||e===n&&t>i)&&(n=e,i=t)};(t(e)||r(e))&&a(e.key.loc.end.line,e.key.loc.end.column);for(let t of e.items)a(t.loc.end.line,t.loc.end.column);e.loc.end.line=n,e.loc.end.column=i}function Rr(e,t,n){let r=n.newLine,i=t.match(/(?:\r\n|\n)+$/u),a=i?i[0]:``,o=a?t.slice(0,-a.length):t,s=o.length?o.split(r):[],c=Ir(e),l=(e,t)=>{let n=e.lastIndexOf(t.raw);return n>=0?n:t.loc.start.column},u=Fr(e).filter(e=>{let t=s[e.loc.start.line-1]||``,n=l(t,e),r=t.slice(0,n);return r.trim().length>0&&/\s{2,}$/u.test(r)}).sort((e,t)=>e.loc.start.line-t.loc.start.line),d=[],f=[];for(let e of u){let t=f[f.length-1];!t||e.loc.start.line===t.loc.start.line+1?f.push(e):(f.length>0&&d.push(f),f=[e])}f.length>0&&d.push(f);for(let e of d){if(e.length<2)continue;let t=Er.get(e[0])??e[0].loc.start.column,n=new Map;for(let t of e){let e=Er.get(t)??t.loc.start.column;n.set(e,(n.get(e)||0)+1)}let r=1;for(let[e,i]of n)i>r&&(r=i,t=e);let i=Math.max(...e.map(e=>{let t=s[e.loc.start.line-1]||``,n=l(t,e);return t.slice(0,n).trimEnd().length})),a=Math.min(...e.map(e=>{let t=s[e.loc.start.line-1]||``,n=l(t,e),r=t.slice(0,n).trimEnd();return Math.max(1,n-r.length)})),o=e.filter(e=>Tr.has(e)),u=e.some(e=>!c.has(e.loc.start.line));if(o.length>0&&u){let t=Math.min(...e.map(e=>{if(Tr.has(e))return Tr.get(e)||1;let t=s[e.loc.start.line-1]||``,n=l(t,e),r=t.slice(0,n).trimEnd();return Math.max(1,n-r.length)}));a=Math.min(a,t)}if(t<i+1){let e=i+a;t=Math.max(t,e)}for(let n of e){let e=n.loc.start.line-1,r=s[e]||``,i=l(r,n),a=r.slice(0,i).trimEnd(),o=Math.max(t,a.length+1);i!==o&&(s[e]=a+` `.repeat(o-a.length)+n.raw),n.loc.start.column!==o&&(n.loc.start.column=o,n.loc.end.column=o+n.raw.length)}}return Lr(e),s.join(r)+a}function zr(e,t,n){let r=Array.from(P(un(e))),i=xn(n,K.autoDetectFormatWithCst(e,r)),a=Ur(r,t,i).tomlString;return i.leadingBom?`${a}`:a}function Br(e,t=new WeakSet){if(typeof e!=`object`||!e)return!1;if(L(e))return!0;if(t.has(e))return!1;t.add(e);for(let n of Object.values(e))if(Br(n,t))return!0;return!1}function Vr(e){let t=new WeakSet,n=e=>{t.add(e)};return lt(e,{Document:n,Table:n,TableKey:n,TableArray:n,TableArrayKey:n,KeyValue:n,Key:n,String:n,Integer:n,Float:n,Boolean:n,DateTime:n,InlineArray:n,InlineItem:n,InlineTable:n,Comment:n}),t}function Hr(e,t,n,r){if(!R(t))return t;let i=Y(q(e,xn({...n,inlineTableStart:0},n)).items,``,{temporal:r});if(!R(i))return t;let a={};for(let e of Object.keys(i))Object.prototype.hasOwnProperty.call(t,e)&&(a[e]=t[e]);for(let e of Object.keys(t))Object.prototype.hasOwnProperty.call(a,e)||(a[e]=t[e]);return a}function Ur(e,t,n){let r=[...e],i=Br(t),a=1,o=0;for(let e of r){let t=e.loc.end;(t.line>a||t.line===a&&t.column>o)&&(a=t.line,o=t.column)}let s=Y(r,``,{temporal:i}),c={type:`Document`,loc:{start:{line:1,column:0},end:{line:a,column:o}},items:r},l=n.inlineTableStart!=null&&n.inlineTableStart>1?1:n.inlineTableStart,u=xn({...n,inlineTableStart:l},n),d=q(t,u),f=Y(d.items,``,{temporal:i}),p=n.updateOrder?Hr(t,f,u,i):f,m=Wr(Gr(c,p,er(s,p,[],{updateOrder:n.updateOrder})));if(m.length===0)return{tomlString:Rn(r,n),document:c};let h=Jr(c,d,m,n,i,Vr(c));return{tomlString:Rr(h,Rn(h.items,n),n),document:h}}function Wr(e){for(let t=0;t<e.length;t++){let n=e[t];if(Z(n)){let r=t+1;for(;r<e.length;){let i=e[r];if(!Z(i)){r++;continue}let a=F(n.path),o=F(i.path),s=n.path.slice(0,-1),c=i.path.slice(0,-1);if(typeof a==`number`&&typeof o==`number`&&z(s,c)&&o>a){e.splice(r,1),e.splice(t,0,i),t=-1;break}r++}}}return e}function Gr(e,t,n){let i=new Set,a=[],o=new Map;for(let e of n){if(!Z(e)&&!Xn(e))continue;let t=e.path.slice(0,-1);if(t.length===0)continue;let n=JSON.stringify(t),r=o.get(n);r||(r={path:t,removes:[],adds:[]},o.set(n,r)),(Z(e)?r.removes:r.adds).push(e)}for(let t of o.values())t.removes.length!==0&&t.adds.length!==0&&($(e,t.path)||(t.removes.forEach(e=>i.add(e)),t.adds.forEach(e=>i.add(e)),a.push({type:`Edit`,path:t.path})));let s=new Map;for(let t of n){if(i.has(t)||!Zn(t)&&!Xn(t)&&!Z(t)||typeof F(t.path)!=`number`)continue;let n=t.path.slice(0,-1);if(n.length===0)continue;let a=$(e,n.concat(0));!a||!r(a)||s.set(JSON.stringify(n),n)}for(let e of s.values()){let r=t;for(let t of e)r=r==null?void 0:r[t];if(Array.isArray(r)&&!r.every(e=>typeof e==`object`&&!!e&&!Array.isArray(e))){for(let t of n)i.has(t)||!Zn(t)&&!Xn(t)&&!Z(t)||t.path.length===e.length+1&&z(t.path.slice(0,-1),e)&&i.add(t);a.push({type:`Edit`,path:e})}}if(i.size===0)return n;let c=n.filter(e=>!i.has(e));return c.push(...a),c}function Kr(e,t){return t.map(t=>T.test(t)?t:`"${It(t,e,`singleline-basic`)}"`).join(`.`)}function qr(e,t){if(o(e)&&o(t)){let n=Kt(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(c(e)&&c(t)){let n=e.raw,r=t.value;if(L(r)){let e=et(r);if(n.includes(` `)&&e.includes(`T`)&&(e=e.replace(`T`,` `)),/(?:\+00:00|-00:00)/.test(n)&&e.endsWith(`Z`)){let t=n.match(/([+-]00:00)/)[1];e=e.replace(/Z$/,t)}t.raw=e,t.loc.end.column=t.loc.start.column+t.raw.length}else{let e=le.createDateWithOriginalFormat(r,n);t.value=e,t.raw=e.toISOString(),t.loc.end.column=t.loc.start.column+t.raw.length}}if(s(e)&&s(t)&&Number.isNaN(e.value)&&Number.isNaN(t.value)){let n=e,r=t;n.nanSign&&(r.nanSign=`+`,r.raw=`+nan`)}if(l(e)&&l(t)){let n=Sn(e);if(t.items.length>0){let e=t.items[t.items.length-1];e.comma=n}}if(d(e)&&d(t)){let n=Cn(e);if(t.items.length>0){let e=t.items[t.items.length-1];e.comma=n}}}function Jr(n,i,o,s,c=!1,f=new WeakSet){let h=new Set,_=[];o.forEach(o=>{if(Xn(o)){var v;let f=Q(i,o.path),p=o.path.slice(0,-1),m=F(o.path),h=r(f);if(Ye(m)&&!h&&!Ye(F(p))){let e=$(n,p.concat(0));e&&r(e)&&(h=!0)}if(h&&!r(f)){let e=p.filter(e=>typeof e==`string`),t=Y(i.items,``,{temporal:c});for(let e of o.path)t=t==null?void 0:t[e];if(t!==void 0){let n=Bt(e),r=q(t,s);for(let e of r.items)U(n,n,e,void 0);G(n),f=n}}let g;if(t(f))g=n;else if(h){g=n;let e=n,t=$(e,p.concat(m-1)),r=$(e,p.concat(m));m=r?e.items.indexOf(r):t?e.items.indexOf(t)+1:e.items.length}else g=ir(n,o.path),a(g)?g=g.value:u(g)&&a(g.item)?g=g.item.value:u(g)&&d(g.item)&&(g=g.item);if(l(g)){let e=$(n,p),t=$(n,p.slice(0,-1));if(e&&a(e)&&t){let n=Pr(g,f,m);n!==0&&Mr(t,e,n)}}let _=l(g)||d(g)?(v=mr(n,g))==null?void 0:v.items:void 0;if(r(g)||l(g)||e(g)){if(l(g)){let e=Sn(g);u(f)&&(f.comma=e)}if(s.inlineTableStart!==void 0&&s.inlineTableStart>0&&e(g)&&t(f)){let e=ti(f,n,s);U(n,g,f,m);for(let t of e)U(n,n,t,void 0)}else{let i=m;if(e(g)&&a(f)){let e=g.items.findIndex(e=>t(e)||r(e));e!==-1&&(i=e)}U(n,g,f,i,void 0,_)}}else if(d(g)){let e=Cn(g);if(a(f)){let t=on(f);t.comma=e,U(n,g,t,void 0,void 0,_)}else U(n,g,f,void 0,void 0,_)}else if(s.inlineTableStart!==void 0&&s.inlineTableStart>0&&a(f)&&d(f.value)&&t(g))On([...g.key.item.value,...f.key.value])<s.inlineTableStart?ni(f,g,n,s):U(n,g,f);else if(s.inlineTableStart===0&&a(f)&&d(f.value)&&e(g))U(n,g,f,void 0,!0);else{let r=f;u(f)&&(t(g)||e(g))&&(r=f.item),U(n,g,r)}}else if(Zn(o)){let e=$(n,o.path),r=Q(i,o.path);if(!e){Qr(n,i,o,s,c,f);return}let d,p=$(n,o.path.slice(0,-1)),m=ri(n,o.path);if(a(e)&&a(r))qr(e.value,r.value),p&&jr(p,e,e.value,r.value),d=e,e=e.value,r=r.value;else if(a(e)&&u(r)&&a(r.item))d=e,e=e.value,r=r.item.value;else if(u(e)&&a(e.item)&&a(r)){let t=e.item;qr(t.value,r.value),d=t,e=t.value,r=r.value}else if(u(e)&&u(r)&&a(e.item)&&a(r.item))qr(e.item.value,r.item.value),d=e.item,e=e.item.value,r=r.item.value;else if(t(e)){let t=Y(i.items,``,{temporal:c});for(let e of o.path)t=t==null?void 0:t[e];if(t!==void 0){let r=e.key.item.value,i=r.slice(-1),a=r.slice(0,-1),c=ir(n,o.path),l=q({[i[0]]:t},s).items[0];if(a.length>0){let t=Rt(a);U(n,t,l,0),vt(n,c,e,t),f.add(t)}else vt(n,c,e,l),f.add(l),Zr(n,l);return}d=ir(n,o.path)}else if(d=ir(n,o.path),a(d)){let e=Q(n,o.path.slice(0,-1));a(e)&&l(e.value)&&(d=e.value)}if(m){let t=g(e.loc),n=g(r.loc).columns-t.columns;n!==0&&Nr(m.container,m.row,n)}vt(n,d,e,r)}else if(Z(o)){let e=$(n,o.path);if(e){let t=ir(n,o.path);if(a(t)&&(t=t.value),u(t)&&a(t.item)&&(t=t.item.value),u(t)&&d(t.item)&&(t=t.item),p(t)&&!t.items.includes(e)&&(t=n),_r(n,t,e),r(e)){let t=e.key.item.value;$(n,o.path.slice(0,-1).concat(0))||h.add(t.join(`.`))}}else if($(n,o.path.concat(0))){let e;for(;e=$(n,o.path.concat(0));)_r(n,n,e);let t=o.path[o.path.length-1];h.add(t)}else{let e=ii(n,o.path);if(e.length>0)for(let t of e)_r(n,n,t);else Q(n,o.path)}}else if(Qn(o)){if(o.key!==void 0){_.push(o);return}let e=$(n,o.path);if(e){m(e)&&(e=e.item),a(e)&&(e=e.value);let t=e.items[o.from];vr(n,e,t,o.to)}else{let e=Q(n,o.path.concat(o.from));W(n,n,e);let t=$(n,o.path.concat(o.to));U(n,n,e,t?n.items.indexOf(t):n.items.length)}}else if($n(o)){let e=Q(n,o.path.concat(o.from)),t=Q(i,o.path.concat(o.to));m(e)&&(e=e.item),m(t)&&(t=t.item),t.key.raw=Kr(e.key.raw,t.key.value),t.key.loc.end.column=t.key.loc.start.column+t.key.raw.length,vt(n,e,e.key,t.key)}}),G(n);let v=!1;return lt(n,{InlineTable:e=>{if(pt(e)&&e.items.length>0){let t=e.items[e.items.length-1];e.loc.end.column=t.loc.end.column+1,mt(e),wt(n,e,s.bracketSpacing),v=!0}}}),v&&G(n),$r(n),ei(n,h,s),wr(n,_,f),n}function Yr(e){return e.items.findIndex(e=>t(e)||r(e))}function Xr(e){let t=Yr(e);return t===-1?void 0:t}function Zr(e,t){let n=e.items.indexOf(t);if(n<0)return;let r=Yr(e);r===-1||r>n||(W(e,e,t),U(e,e,t,r))}function Qr(e,t,n,r,i,a){let o=Y(t.items,``,{temporal:i});for(let e of n.path)o=o==null?void 0:o[e];if(o===void 0)return;let s=o;for(let e=n.path.length-1;e>=0;e--)s={[n.path[e]]:s};let c=ii(e,n.path);for(let t of c)W(e,e,t);let l=Rn(q(s,r).items,r),u=Array.from(P(l))[0],d=Xr(e);d!==void 0&&G(e),U(e,e,u,d),a.add(u)}function $r(e){lt(e,{KeyValue:t=>{let n=t.value;if(!l(n)||n.items.length>0)return;let r=ir(e,[t.key.value[0]]);if(!r||!p(r))return;let i=t.loc.start.line,a=t.loc.end.line,o=r.items;for(let e=o.length-1;e>=0;e--){let t=o[e];if(!f(t))continue;let n=t.loc.start.line;n>=i&&n<=a&&o.splice(e,1)}}})}function ei(e,t,n){if(t.size!==0){for(let r of t){let t=q({[r]:[]},n).items[0];U(e,e,t,Xr(e))}G(e)}}function ti(e,t,n){let r=[],i=(e,r)=>{for(let o=e.items.length-1;o>=0;o--){let s=e.items[o];if(a(s)&&d(s.value)){let c=[...e.key.item.value,...s.key.value];if(On(c)<(n.inlineTableStart??1)&&n.inlineTableStart!==0){let n=Rt(c);for(let e of s.value.items)u(e)&&a(e.item)&&U(t,n,e.item,void 0);e.items.splice(o,1),Dn(e),r.push(n),i(n,r)}}}};return i(e,r),r}function ni(e,t,n,r){let i=Rt([...t.key.item.value,...e.key.value]);if(d(e.value))for(let t of e.value.items)u(t)&&a(t.item)&&U(n,i,t.item,void 0);U(n,n,i,void 0),Dn(t);let o=ti(i,n,r);for(let e of o)U(n,n,e,void 0)}function ri(e,t){for(let n=t.length-1;n>0;n--){let r=$(e,t.slice(0,n));if(!r||!a(r)||!d(r.value))continue;let i=$(e,t.slice(0,n-1));if(i&&p(i))return{container:i,row:r}}}function ii(e,n){let i=[];for(let o of e.items){let e;a(o)?e=o.key.value:(t(o)||r(o))&&(e=o.key.item.value),e&&z(e.slice(0,n.length),n)&&i.push(o)}return i}function ai(e,t){return e.line===t.line?e.column-t.column:e.line-t.line}function oi(e,t,n){let r={line:t,column:n},i=[],a=null;for(let t of e){let e=ai(t.loc.end,r)<0,n=ai(t.loc.start,r)<0;if(e)i.push(t),a=t.loc.end;else if(n&&!e)break;else break}return{truncatedCst:i,lastEndPosition:a}}var si=class{_cst;_currentTomlString;_format;_integersAsBigInt;_temporal;constructor(e,t){let n=typeof e==`string`?e:cn(e),r=un(n);this._currentTomlString=r,this._cst=Array.from(P(r)),this._integersAsBigInt=(t==null?void 0:t.integersAsBigInt)??`asNeeded`,this._temporal=(t==null?void 0:t.temporal)??!1,this._format=K.autoDetectFormatWithCst(n,this._cst)}get toTomlString(){return this._format.leadingBom?`${this._currentTomlString}`:this._currentTomlString}get toJsObject(){let e=Y(this._cst,this._currentTomlString,{integersAsBigInt:this._integersAsBigInt,temporal:this._temporal});return this._temporal?e:ci(e)}get cst(){return this._cst}patch(e,t){let n=xn(t,this._format),{tomlString:r,document:i}=Ur(this._cst,e,n);this._cst=i.items,this._format=n,this._currentTomlString=r}update(e){let t=un(e);if(t===this._currentTomlString){this._format.leadingBom=ln(e);return}let n=this._currentTomlString.split(this._format.newLine),r=_n(t),i=t.split(r),a=0;for(;a<n.length&&a<i.length&&n[a]===i[a];)a++;let o=0;if(a<n.length&&a<i.length){let e=n[a],t=i[a];for(let n=0;n<Math.max(e.length,t.length);n++)if(e[n]!==t[n]){o=n;break}}let s=a+1,{truncatedCst:c,lastEndPosition:l}=oi(this._cst,s,o),u=l?l.line:1,d=l?l.column+1:0,f=i.slice(u-1);f.length>0&&d>0&&(f[0]=f[0].substring(d));let p=f.join(this._format.newLine);this._cst=Array.from(Me(c,p)),this._currentTomlString=t,this._format=K.autoDetectFormatWithCst(e,this._cst)}overwrite(e){let t=un(e);if(t===this._currentTomlString){this._format.leadingBom=ln(e);return}this._cst=Array.from(P(t)),this._currentTomlString=t,this._format=K.autoDetectFormatWithCst(e,this._cst)}};function ci(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(ci);if(e&&typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))t[n]=ci(r);return t}return e}function li(e,t){let n=un(typeof e==`string`?e:cn(e));return Y(P(n),n,{integersAsBigInt:(t==null?void 0:t.integersAsBigInt)??`asNeeded`,temporal:(t==null?void 0:t.temporal)??!1})}function ui(e,t){let n=xn(t,K.default()),r=Rn(q(e,n).items,n);return n.leadingBom?`${r}`:r}function di(e,t){return new si(e,t)}export{ue as LocalDate,M as LocalDateTime,de as LocalTime,fe as OffsetDateTime,si as TomlDocument,K as TomlFormat,li as parse,di as parseDocument,zr as patch,ui as stringify};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decimalturn/toml-patch",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "contributors": [
5
5
  "Tim Hall <tim.hall.engr@gmail.com>",
6
6
  "Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"
@@ -30,7 +30,7 @@
30
30
  "edit-in-place"
31
31
  ],
32
32
  "engines": {
33
- "node": ">=14"
33
+ "node": ">=16"
34
34
  },
35
35
  "type": "module",
36
36
  "types": "./dist/toml-patch.d.ts",
@@ -42,11 +42,9 @@
42
42
  }
43
43
  },
44
44
  "devDependencies": {
45
- "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@2.0.0",
45
+ "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@2.0.1",
46
46
  "@js-temporal/polyfill": "^0.5.1",
47
47
  "@playwright/test": "^1.59.1",
48
- "@rollup/plugin-terser": "^1.0.0",
49
- "@rollup/plugin-typescript": "^12.1.2",
50
48
  "@types/dedent": "^0.7.2",
51
49
  "@types/js-yaml": "^4.0.0",
52
50
  "@types/node": "^24.12.3",
@@ -59,12 +57,10 @@
59
57
  "npm-run-all2": "^9.0.0",
60
58
  "oxlint": "^1.55.0",
61
59
  "rimraf": "^6.0.0",
62
- "rollup": "^4.59.0",
63
- "rollup-plugin-dts": "^6.2.1",
64
- "rollup-plugin-filesize": "^10",
65
60
  "smol-toml": "^1.6.1",
61
+ "tsdown": "^0.22.13",
66
62
  "tslib": "^2.0.0",
67
- "typescript": "6.0.3",
63
+ "typescript": "7.0.2",
68
64
  "vitest": "^4.1.10"
69
65
  },
70
66
  "prettier": {
@@ -96,7 +92,7 @@
96
92
  "bench:parse": "node benchmark/parse-benchmark.mjs",
97
93
  "bench:stringify": "node benchmark/stringify-benchmark.mjs",
98
94
  "profile": "node benchmark/profile.mjs",
99
- "build": "rimraf dist && node scripts/build.mjs",
95
+ "build": "tsdown",
100
96
  "build:demo": "node scripts/build-demo.mjs",
101
97
  "lint": "oxlint",
102
98
  "lint:fix": "oxlint --fix",