@decimalturn/toml-patch 1.0.2 → 1.0.5

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.
package/CHANGELOG.md CHANGED
@@ -7,12 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.0.5] - 2026-03-17
11
+
12
+ ## [1.0.4] - 2026-03-17
13
+
14
+ ## [1.0.3] - 2026-03-17
15
+
16
+ ### Fixed
17
+ - Patching: Adding keys to nested inline tables (e.g. `config = { server = { host = "localhost" } }`) now works correctly
18
+
19
+ ### Changed
20
+ - Remove circular dependency between `toml-format` and `generate` modules ([#118](https://github.com/DecimalTurn/toml-patch/pull/118))
21
+ - Reduce bundle size by deduplicating internal parsing and date-formatting helpers, implementing schema-based validation and shortening error messages ([#122](https://github.com/DecimalTurn/toml-patch/pull/122))
22
+ - Improve internal representation handling for faster write performance (~3–4% speedup in benchmarks) by fixing inconsistencies in how positions are tracked internally ([#125](https://github.com/DecimalTurn/toml-patch/pull/125))
23
+
10
24
  ## [1.0.2] - 2026-02-14
11
25
 
26
+ ### Changed
27
+ - Improve stringification performance ([#106](https://github.com/DecimalTurn/toml-patch/pull/106))
28
+
12
29
  ## [1.0.1] - 2026-02-14
13
30
 
14
31
  ### Changed
15
- - Improve stringification performance ([#106](https://github.com/DecimalTurn/toml-patch/pull/106))
16
32
  - Improve parsing and conversion performance ([#105](https://github.com/DecimalTurn/toml-patch/pull/105))
17
33
  - Better benchmarking ([#104](https://github.com/DecimalTurn/toml-patch/pull/104))
18
34
  - Migrate benchmarks from CommonJS to ESM modules
@@ -1,4 +1,107 @@
1
- //! @decimalturn/toml-patch v1.0.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
1
+ //! @decimalturn/toml-patch v1.0.5 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
+ declare class TomlFormat {
3
+ /**
4
+ * The line ending character(s) to use in the output TOML.
5
+ * This option affects only the stringification process, not the internal representation (AST).
6
+ *
7
+ * @example
8
+ * - '\n' for Unix/Linux line endings
9
+ * - '\r\n' for Windows line endings
10
+ */
11
+ newLine: string;
12
+ /**
13
+ * The number of trailing newlines to add at the end of the TOML document.
14
+ * This option affects only the stringification process, not the internal representation (AST).
15
+ *
16
+ * @example
17
+ * - 0: No trailing newline
18
+ * - 1: One trailing newline (standard)
19
+ * - 2: Two trailing newlines (adds extra spacing)
20
+ */
21
+ trailingNewline: number;
22
+ /**
23
+ * Whether to add trailing commas after the last element in arrays and inline tables.
24
+ *
25
+ * @example
26
+ * - true: [1, 2, 3,] and { x = 1, y = 2, }
27
+ * - false: [1, 2, 3] and { x = 1, y = 2 }
28
+ */
29
+ trailingComma: boolean;
30
+ /**
31
+ * Whether to add spaces after opening brackets/braces and before closing brackets/braces
32
+ * in arrays and inline tables.
33
+ *
34
+ * @example
35
+ * - true: [ 1, 2, 3 ] and { x = 1, y = 2 }
36
+ * - false: [1, 2, 3] and {x = 1, y = 2}
37
+ */
38
+ bracketSpacing: boolean;
39
+ /**
40
+ * The nesting depth at which new tables should start being formatted as inline tables.
41
+ * When adding new tables during patching or stringifying objects:
42
+ * - Tables at depth >= inlineTableStart will be formatted as inline tables
43
+ * - Tables at depth < inlineTableStart will be formatted as separate table sections
44
+ *
45
+ * @example
46
+ * - 0: All tables are inline tables including top-level tables (root level)
47
+ * - 1: Top-level tables as sections, nested tables as inline (default)
48
+ * - 2: Two levels as sections, deeper nesting as inline
49
+ */
50
+ inlineTableStart?: number;
51
+ /**
52
+ * Whether to truncate time components in UTC date fields when they are zero.
53
+ * This setting affects only the stringification process.
54
+ *
55
+ * @example
56
+ * - true: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15
57
+ * - false: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15T00:00:00.000Z
58
+ *
59
+ */
60
+ truncateZeroTimeInDates?: boolean;
61
+ /**
62
+ * Whether to use tabs instead of spaces for indentation/padding.
63
+ * When enabled, lines that need to be indented will use tabs.
64
+ *
65
+ * @example
66
+ * - true: Uses tabs for indentation
67
+ * - false: Uses spaces for indentation (default)
68
+ *
69
+ */
70
+ useTabsForIndentation?: boolean;
71
+ constructor(newLine?: string, trailingNewline?: number, trailingComma?: boolean, bracketSpacing?: boolean, inlineTableStart?: number, truncateZeroTimeInDates?: boolean, useTabsForIndentation?: boolean);
72
+ /**
73
+ * Creates a new TomlFormat instance with default formatting preferences.
74
+ *
75
+ * @returns A new TomlFormat instance with default values:
76
+ * - newLine: '\n'
77
+ * - trailingNewline: 1
78
+ * - trailingComma: false
79
+ * - bracketSpacing: true
80
+ * - inlineTableStart: 1
81
+ * - truncateZeroTimeInDates: false
82
+ */
83
+ static default(): TomlFormat;
84
+ /**
85
+ * Auto-detects formatting preferences from an existing TOML string.
86
+ *
87
+ * This method analyzes the provided TOML string to determine formatting
88
+ * preferences such as line endings, trailing newlines, and comma usage.
89
+ *
90
+ * @param tomlString - The TOML string to analyze for formatting patterns
91
+ * @returns A new TomlFormat instance with detected formatting preferences
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const toml = 'array = ["a", "b", "c",]\ntable = { x = 1, y = 2, }';
96
+ * const format = TomlFormat.autoDetectFormat(toml);
97
+ * // format.trailingComma will be true
98
+ * // format.newLine will be '\n'
99
+ * // format.trailingNewline will be 0 (no trailing newline)
100
+ * ```
101
+ */
102
+ static autoDetectFormat(tomlString: string): TomlFormat;
103
+ }
104
+
2
105
  interface Location {
3
106
  start: Position;
4
107
  end: Position;
@@ -163,109 +266,6 @@ interface TreeNode {
163
266
  loc: Location;
164
267
  }
165
268
 
166
- declare class TomlFormat {
167
- /**
168
- * The line ending character(s) to use in the output TOML.
169
- * This option affects only the stringification process, not the internal representation (AST).
170
- *
171
- * @example
172
- * - '\n' for Unix/Linux line endings
173
- * - '\r\n' for Windows line endings
174
- */
175
- newLine: string;
176
- /**
177
- * The number of trailing newlines to add at the end of the TOML document.
178
- * This option affects only the stringification process, not the internal representation (AST).
179
- *
180
- * @example
181
- * - 0: No trailing newline
182
- * - 1: One trailing newline (standard)
183
- * - 2: Two trailing newlines (adds extra spacing)
184
- */
185
- trailingNewline: number;
186
- /**
187
- * Whether to add trailing commas after the last element in arrays and inline tables.
188
- *
189
- * @example
190
- * - true: [1, 2, 3,] and { x = 1, y = 2, }
191
- * - false: [1, 2, 3] and { x = 1, y = 2 }
192
- */
193
- trailingComma: boolean;
194
- /**
195
- * Whether to add spaces after opening brackets/braces and before closing brackets/braces
196
- * in arrays and inline tables.
197
- *
198
- * @example
199
- * - true: [ 1, 2, 3 ] and { x = 1, y = 2 }
200
- * - false: [1, 2, 3] and {x = 1, y = 2}
201
- */
202
- bracketSpacing: boolean;
203
- /**
204
- * The nesting depth at which new tables should start being formatted as inline tables.
205
- * When adding new tables during patching or stringifying objects:
206
- * - Tables at depth >= inlineTableStart will be formatted as inline tables
207
- * - Tables at depth < inlineTableStart will be formatted as separate table sections
208
- *
209
- * @example
210
- * - 0: All tables are inline tables including top-level tables (root level)
211
- * - 1: Top-level tables as sections, nested tables as inline (default)
212
- * - 2: Two levels as sections, deeper nesting as inline
213
- */
214
- inlineTableStart?: number;
215
- /**
216
- * Whether to truncate time components in UTC date fields when they are zero.
217
- * This setting affects only the stringification process.
218
- *
219
- * @example
220
- * - true: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15
221
- * - false: Date('2024-01-15T00:00:00.000Z') serializes as 2024-01-15T00:00:00.000Z
222
- *
223
- */
224
- truncateZeroTimeInDates?: boolean;
225
- /**
226
- * Whether to use tabs instead of spaces for indentation/padding.
227
- * When enabled, lines that need to be indented will use tabs.
228
- *
229
- * @example
230
- * - true: Uses tabs for indentation
231
- * - false: Uses spaces for indentation (default)
232
- *
233
- */
234
- useTabsForIndentation?: boolean;
235
- constructor(newLine?: string, trailingNewline?: number, trailingComma?: boolean, bracketSpacing?: boolean, inlineTableStart?: number, truncateZeroTimeInDates?: boolean, useTabsForIndentation?: boolean);
236
- /**
237
- * Creates a new TomlFormat instance with default formatting preferences.
238
- *
239
- * @returns A new TomlFormat instance with default values:
240
- * - newLine: '\n'
241
- * - trailingNewline: 1
242
- * - trailingComma: false
243
- * - bracketSpacing: true
244
- * - inlineTableStart: 1
245
- * - truncateZeroTimeInDates: false
246
- */
247
- static default(): TomlFormat;
248
- /**
249
- * Auto-detects formatting preferences from an existing TOML string.
250
- *
251
- * This method analyzes the provided TOML string to determine formatting
252
- * preferences such as line endings, trailing newlines, and comma usage.
253
- *
254
- * @param tomlString - The TOML string to analyze for formatting patterns
255
- * @returns A new TomlFormat instance with detected formatting preferences
256
- *
257
- * @example
258
- * ```typescript
259
- * const toml = 'array = ["a", "b", "c",]\ntable = { x = 1, y = 2, }';
260
- * const format = TomlFormat.autoDetectFormat(toml);
261
- * // format.trailingComma will be true
262
- * // format.newLine will be '\n'
263
- * // format.trailingNewline will be 0 (no trailing newline)
264
- * ```
265
- */
266
- static autoDetectFormat(tomlString: string): TomlFormat;
267
- }
268
-
269
269
  /**
270
270
  * Applies modifications to a TOML document by comparing an existing TOML string with updated JavaScript data.
271
271
  *
@@ -285,7 +285,9 @@ declare function patch(existing: string, updated: any, format?: Partial<TomlForm
285
285
  * TomlDocument encapsulates a TOML AST and provides methods to interact with it.
286
286
  */
287
287
  declare class TomlDocument {
288
- #private;
288
+ private _ast;
289
+ private _currentTomlString;
290
+ private _format;
289
291
  /**
290
292
  * Initializes the TomlDocument with a TOML string, parsing it into an AST.
291
293
  * @param tomlString - The TOML string to parse
@@ -1,2 +1,2 @@
1
- //! @decimalturn/toml-patch v1.0.2 - https://github.com/DecimalTurn/toml-patch - @license: MIT
2
- var e,t;function n(t){return t.type===e.Document}function r(t){return t.type===e.Table}function o(t){return t.type===e.TableArray}function a(t){return t.type===e.KeyValue}function i(t){return t.type===e.String}function l(t){return t.type===e.DateTime}function s(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 d(e){return n(e)||r(e)||o(e)||u(e)||s(e)}function m(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}function h(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:w(e);if(0===n.length)return{line:1,column:t};let r=0,o=n.length-1;for(;r<o;){const e=r+o>>>1;n[e]<t?r=e+1:o=e}n[r]<t&&r++;const a=r+1;return{line:a,column:t-(n[a-2]+1||0)}}function w(e){const t=[];for(let n=0;n<e.length;n++){const r=e.charCodeAt(n);10===r?t.push(n):13===r&&(10===e.charCodeAt(n+1)?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function g(e){return{line:e.line,column:e.column}}function y(e){return{start:g(e.start),end:g(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{constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=w(e),r=void 0!==n[t.line-2]?n[t.line-2]+1:0,o=n[t.line-1]||e.length;return e.substring(r,o)}(e,t),o=`${function(e,t=" "){return t.repeat(e)}(t.column)}^`;n&&(r+=`${n}\n${o}\n`)}r+=n,super(r),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='"',$="'",S=" ",T=/[\w,\d,\",\',\+,\-,\_]/,I=10,k=13,C=127;function*E(e){const n=e.length;let r=0;const o=[],a=(e,t)=>({start:p(o,e),end:p(o,t)});for(;r<n;){const c=e.charCodeAt(r);if((c<=31||c===C)&&9!==c&&c!==k&&c!==I)throw new v(e,p(o,r),`Control character 0x${c.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`);if(c===k&&(r+1>=n||e.charCodeAt(r+1)!==I))throw new v(e,p(o,r),"Invalid standalone CR (\\r); CR must be part of a CRLF sequence");if(32===c||9===c||c===k);else if(c===I)o.push(r);else if(91===c||93===c)yield{type:t.Bracket,raw:e[r],loc:a(r,r+1)};else if(123===c||125===c)yield{type:t.Curly,raw:e[r],loc:a(r,r+1)};else if(61===c)yield{type:t.Equal,raw:"=",loc:a(r,r+1)};else if(44===c)yield{type:t.Comma,raw:",",loc:a(r,r+1)};else if(46===c)yield{type:t.Dot,raw:".",loc:a(r,r+1)};else if(35===c)yield i();else{const t=A(e,r,$)||A(e,r,b);t?yield l(t):yield s()}r++}function i(){const i=r;for(;r+1<n;){const t=e.charCodeAt(r+1);if(t===I||t===k)break;r++;const n=e.charCodeAt(r);if((n<=31||n===C)&&9!==n)throw new v(e,p(o,r),`Control character 0x${n.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`)}return{type:t.Comment,raw:e.slice(i,r+1),loc:a(i,r+1)}}function l(i){const l=r,s=i+i+i;for(r+=3;r<n;){if(A(e,r,i)){let t=3;for(;e[r+t]===i;)t++;if(t>=6)throw new v(e,p(o,r),`Invalid multiline string: ${t} consecutive ${i} characters`);if(3===t){r+=2;break}r+=t-3,r+=2;break}const t=e.charCodeAt(r);if(t===k&&(r+1>=n||e.charCodeAt(r+1)!==I))throw new v(e,p(o,r),"Invalid standalone CR (\\r) in multiline string (must be part of CRLF sequence)");if((t<=31||t===C)&&9!==t&&t!==I&&t!==k){const n=i===b?"multiline basic strings":"multiline literal strings",a=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let l="";0===t?l="Null":t===C&&(l="DEL");const s=l?`${l} (control character ${a}) is not allowed in ${n}`:`Control character ${a} is not allowed in ${n}`;throw new v(e,p(o,r),s)}t===I&&o.push(r),r++}if(r>=n){if(i===b){let t=0,a=n-1;for(;a>=0&&"\\"===e[a];)t++,a--;if(t>0&&t%2!=0)throw new v(e,p(o,r),`Expected close of multiline string with ${s}, reached end of file. Check for escape sequences (\\) that may be preventing proper string closure`)}throw new v(e,p(o,r),`Expected close of multiline string with ${s}, reached end of file`)}return{type:t.Literal,raw:e.slice(l,r+1),loc:a(l,r+1)}}function s(){const i=e[r];if(!T.test(i))throw new v(e,p(o,r),`Unsupported character "${i}". Expected ALPHANUMERIC, ", ', +, -, or _`);const l=r;let s=i===b,c=i===$;for(;r<n&&!(r+1>=n);){const t=e.charCodeAt(r+1);if(!(s||c||32!==t&&9!==t&&t!==I&&t!==k&&44!==t&&46!==t&&93!==t&&125!==t&&61!==t&&35!==t))break;if(r++,s||c){const t=e.charCodeAt(r);if((t<=31||t===C)&&9!==t){const n=s?"basic strings":"literal strings",a=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let i="";t===I?i="Newline":t===k?i="Carriage return":0===t?i="Null":t===C&&(i="DEL");const l=i?`${i} (control character ${a}) is not allowed in ${n}`:`Control character ${a} is not allowed in ${n}`;throw new v(e,p(o,r),l)}}const a=e[r];if(a===b&&(s=!s),a!==$||s||(c=!c),r+1>=n)break;if(s&&"\\"===a){const t=e[r+1];t!==b&&"\\"!==t||r++}}if(s||c)throw new v(e,p(o,l),`Expected close of string with ${s?b:$}`);return{type:t.Literal,raw:e.slice(l,r+1),loc:a(l,r+1)}}}function A(e,t,n){if(!n)return!1;if(!(e[t]===n&&e[t+1]===n&&e[t+2]===n))return!1;if(n===$)return n;let r=0,o=t-1;for(;o>=0&&"\\"===e[o];)r++,o--;if(0===r)return n;return!(r%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 _(e){const t=e.charCodeAt(0);return t<128&&-1!==x[t]}function U(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 D(e){return e.startsWith("'''")?F(e.slice(3,e.length-3)):e.startsWith($)?e.slice(1,e.length-1):e.startsWith('"""')?O(F(e.slice(3,e.length-3)),!0):e.startsWith(b)?O(e.slice(1,e.length-1),!1):e}function O(e,t){const n=e.length;if(!t&&-1===e.indexOf("\\"))return e;const r=[];let o=0;for(let a=0;a<n;a++){if("\\"!==e[a])continue;if(a>o&&r.push(e.slice(o,a)),a++,a>=n)throw new Error("Invalid escape sequence: trailing backslash");const i=e[a];switch(i){case"b":r.push("\b");break;case"t":r.push("\t");break;case"n":r.push("\n");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("");break;case"u":{if(a+4>n||!_(e[a+1])||!_(e[a+2])||!_(e[a+3])||!_(e[a+4]))throw new Error(`Invalid Unicode escape: \\u${e.slice(a+1,a+5)}`);const t=U(e,a+1);if(t>=55296&&t<=57343)throw new Error(`Invalid Unicode escape: \\u${e.slice(a+1,a+5)} (surrogate codepoints are not allowed)`);r.push(String.fromCharCode(t)),a+=4;break}case"U":{if(a+8>n)throw new Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);for(let t=1;t<=8;t++)if(!_(e[a+t]))throw new Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);const t=parseInt(e.slice(a+1,a+9),16);r.push(String.fromCodePoint(t)),a+=8;break}case"x":{if(a+2>n||!_(e[a+1])||!_(e[a+2]))throw new Error(`Invalid hex escape: \\x${e.slice(a+1,a+3)}`);const t=x[e.charCodeAt(a+1)]<<4|x[e.charCodeAt(a+2)];r.push(String.fromCharCode(t)),a+=2;break}default:if(t&&("\n"===i||"\r"===i||" "===i||"\t"===i)){let t="\n"===i||"\r"===i,r=a;for(;r<n&&(" "===e[r]||"\t"===e[r]||"\n"===e[r]||"\r"===e[r]);)"\n"!==e[r]&&"\r"!==e[r]||(t=!0),r++;if(!t)throw new Error(`Invalid escape sequence: \\${i}`);a=r-1;break}throw new Error(`Invalid escape sequence: \\${i}`)}o=a+1}return 0===o?e:(o<n&&r.push(e.slice(o)),r.join(""))}function F(e){return 10===e.charCodeAt(0)?e.slice(1):13===e.charCodeAt(0)&&10===e.charCodeAt(1)?e.slice(2):e}class L{constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){var e;if(this.done)return K();const t=this.peeked||this.iterator.next();return this.index+=1,this.value=t.value,this.done=null!==(e=t.done)&&void 0!==e&&e,this.peeked=null,t}peek(){return this.done?K():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}const M=Object.freeze({value:void 0,done:!0});function K(){return M}class N{static createDateWithOriginalFormat(e,t){if(N.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof Z)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new B(t,!1)}const t=e.toISOString().split("T")[0];return new j(t)}if(N.IS_TIME_ONLY.test(t)){if(e instanceof W)return e;{const n=t.match(/\.(\d+)\s*$/),r=e.toISOString();if(r&&r.includes("T")){let o=r.split("T")[1].split("Z")[0];if(n){const t=n[1].length,[r,a,i]=o.split(":"),[l]=i.split(".");o=`${r}:${a}:${l}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new W(o,t)}{const r=String(e.getUTCHours()).padStart(2,"0"),o=String(e.getUTCMinutes()).padStart(2,"0"),a=String(e.getUTCSeconds()).padStart(2,"0"),i=e.getUTCMilliseconds();let l;if(n){const e=n[1].length;l=`${r}:${o}:${a}.${String(i).padStart(3,"0").slice(0,e)}`}else if(i>0){l=`${r}:${o}:${a}.${String(i).padStart(3,"0").replace(/0+$/,"")}`}else l=`${r}:${o}:${a}`;return new W(l,t)}}}if(N.IS_LOCAL_DATETIME_T.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","");if(n){const t=n[1].length,[o,a]=r.split("T"),[i,l,s]=a.split(":"),[c]=s.split(".");r=`${o}T${i}:${l}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new B(r,!1,t)}if(N.IS_LOCAL_DATETIME_SPACE.test(t)){const n=t.match(/\.(\d+)\s*$/);let r=e.toISOString().replace("Z","").replace("T"," ");if(n){const t=n[1].length,[o,a]=r.split(" "),[i,l,s]=a.split(":"),[c]=s.split(".");r=`${o} ${i}:${l}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new B(r,!0,t)}if(N.IS_OFFSET_DATETIME_T.test(t)||N.IS_OFFSET_DATETIME_SPACE.test(t)){const n=t.match(/([+-]\d{2}:\d{2}|[Zz])$/),r=n?"z"===n[1]?"Z":n[1]:"Z",o=N.IS_OFFSET_DATETIME_SPACE.test(t),a=t.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),i=e.getTime();let l=0;if("Z"!==r){const e="+"===r[0]?1:-1,[t,n]=r.slice(1).split(":");l=e*(60*parseInt(t)+parseInt(n))}const s=new Date(i+6e4*l),c=s.getUTCFullYear(),u=String(s.getUTCMonth()+1).padStart(2,"0"),f=String(s.getUTCDate()).padStart(2,"0"),d=String(s.getUTCHours()).padStart(2,"0"),m=String(s.getUTCMinutes()).padStart(2,"0"),h=String(s.getUTCSeconds()).padStart(2,"0"),p=s.getUTCMilliseconds(),w=o?" ":"T";let g=`${d}:${m}:${h}`;if(a){const e=a[1].length;g+=`.${String(p).padStart(3,"0").slice(0,e)}`}else if(p>0){g+=`.${String(p).padStart(3,"0").replace(/0+$/,"")}`}return new Z(`${c}-${u}-${f}${w}${g}${r}`,o)}return e}}N.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,N.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,N.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,N.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,N.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,N.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,N.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,N.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class j extends Date{constructor(e){super(e)}toISOString(){return`${this.getUTCFullYear()}-${String(this.getUTCMonth()+1).padStart(2,"0")}-${String(this.getUTCDate()).padStart(2,"0")}`}}class W extends Date{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=String(this.getUTCHours()).padStart(2,"0"),t=String(this.getUTCMinutes()).padStart(2,"0"),n=String(this.getUTCSeconds()).padStart(2,"0"),r=this.getUTCMilliseconds();if(this.originalFormat&&this.originalFormat.includes(".")){const o=this.originalFormat.match(/\.(\d+)\s*$/),a=o?o[1].length:3;return`${e}:${t}:${n}.${String(r).padStart(3,"0").slice(0,a)}`}if(r>0){return`${e}:${t}:${n}.${String(r).padStart(3,"0").replace(/0+$/,"")}`}return`${e}:${t}:${n}`}}class B extends Date{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=!1,this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){const e=this.getUTCFullYear(),t=String(this.getUTCMonth()+1).padStart(2,"0"),n=String(this.getUTCDate()).padStart(2,"0"),r=String(this.getUTCHours()).padStart(2,"0"),o=String(this.getUTCMinutes()).padStart(2,"0"),a=String(this.getUTCSeconds()).padStart(2,"0"),i=this.getUTCMilliseconds(),l=`${e}-${t}-${n}`,s=this.useSpaceSeparator?" ":"T";if(this.originalFormat&&this.originalFormat.includes(".")){const e=this.originalFormat.match(/\.(\d+)\s*$/),t=e?e[1].length:3;return`${l}${s}${r}:${o}:${a}.${String(i).padStart(3,"0").slice(0,t)}`}if(i>0){return`${l}${s}${r}:${o}:${a}.${String(i).padStart(3,"0").replace(/0+$/,"")}`}return`${l}${s}${r}:${o}:${a}`}}class Z extends Date{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=!1,this.useSpaceSeparator=t,this.originalFormat=e;const r=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);r&&(this.originalOffset="z"===r[1]?"Z":r[1])}toISOString(){if(this.originalOffset){const e=this.getTime();let t=0;if("Z"!==this.originalOffset){const e="+"===this.originalOffset[0]?1:-1,[n,r]=this.originalOffset.slice(1).split(":");t=e*(60*parseInt(n)+parseInt(r))}const n=new Date(e+6e4*t),r=n.getUTCFullYear(),o=String(n.getUTCMonth()+1).padStart(2,"0"),a=String(n.getUTCDate()).padStart(2,"0"),i=String(n.getUTCHours()).padStart(2,"0"),l=String(n.getUTCMinutes()).padStart(2,"0"),s=String(n.getUTCSeconds()).padStart(2,"0"),c=n.getUTCMilliseconds(),u=`${r}-${o}-${a}`,f=this.useSpaceSeparator?" ":"T";if(this.originalFormat&&this.originalFormat.includes(".")){const e=this.originalFormat.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),t=e?e[1].length:3;return`${u}${f}${i}:${l}:${s}.${String(c).padStart(3,"0").slice(0,t)}${this.originalOffset}`}if(c>0){return`${u}${f}${i}:${l}:${s}.${String(c).padStart(3,"0").replace(/0+$/,"")}${this.originalOffset}`}return`${u}${f}${i}:${l}:${s}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const z=N,q="true",V=/e/i,R=/\_/g,P=/^[+\-]?inf$/,H=/^[+\-]?nan$/,Y=/^[+\-]?0x/i;function J(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||95===e||45===e}const X=/^[+\-]?0o/i,G=/^[+\-]?0b/i;function*Q(e){const t=new L(E(e));for(;!t.next().done;){const n=le(t,e);for(const e of n)yield e}}function ee(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function te(n,r){const o=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,a=o===e.Table;if(a&&"["!==n.value.raw)throw new v(r,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!a){const e=n.peek();if(e.done)throw new v(r,n.value.loc.start,'Expected second "[" for array of tables opening, found end of input');if("["!==n.value.raw||"["!==e.value.raw)throw new v(r,n.value.loc.start,`Expected array of tables opening "[[", found ${n.value.raw+e.value.raw}`);const t=n.value,o=e.value;if(t.loc.end.line!==o.loc.start.line||t.loc.end.column!==o.loc.start.column)throw new v(r,t.loc.start,"Array of tables opening brackets must be immediately adjacent with no whitespace: [[table]]")}const i=a?{type:e.TableKey,loc:n.value.loc}:{type:e.TableArrayKey,loc:n.value.loc};if(n.next(),o===e.TableArray&&n.next(),n.done)throw new v(r,i.loc.start,"Expected table key, reached end of file");if(n.value.type===t.Bracket&&"]"===n.value.raw)throw new v(r,n.value.loc.start,o===e.TableArray?"Array of tables header [[]] requires a table name":"Table header [] requires a table name");const l=n.value.raw;if(l.startsWith('"""')||l.startsWith("'''"))throw new v(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(l.startsWith('"')||l.startsWith("'")))for(let e=0;e<l.length;e++)if(!J(l.charCodeAt(e)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${l[e]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);let s;try{s=[D(n.value.raw)]}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}for(i.item={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:s};!n.peek().done&&n.peek().value.type===t.Dot;){n.next();const e=n.value;n.next();const t=n.value.raw;if(!(t.startsWith('"')||t.startsWith("'")))for(let e=0;e<t.length;e++)if(!J(t.charCodeAt(e)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${t[e]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);const o=" ".repeat(e.loc.start.column-i.item.loc.end.column),a=" ".repeat(n.value.loc.start.column-e.loc.end.column);i.item.loc.end=n.value.loc.end,i.item.raw+=`${o}.${a}${n.value.raw}`;try{i.item.value.push(D(n.value.raw))}catch(e){const t=e;throw new v(r,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(r,n.value.loc.start,a?`Table header must not contain newlines. Expected closing ']' on line ${e}, found on line ${n.value.loc.start.line}`:`Unclosed array of tables header: expected closing ']]' on line ${e}, found newline`)}if(a&&(n.done||"]"!==n.value.raw))throw new v(r,n.done?i.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!a&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new v(r,n.done||n.peek().done?i.item.loc.end:n.value.loc.start,`Expected array of tables closing "]]", found ${n.done||n.peek().done?"end of file":n.value.raw+n.peek().value.raw}`);if(!a){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(r,e.loc.start,"Array of tables closing brackets must be immediately adjacent with no whitespace: ]]")}if(a||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(r,e.loc.start,`Unexpected content after ${a?"table":"array of tables"} header`)}let c=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;){n.next();const e=le(n,r);for(let t=0;t<e.length;t++)c.push(e[t])}return{type:a?e.Table:e.TableArray,loc:{start:g(i.loc.start),end:c.length?g(c[c.length-1].loc.end):g(i.loc.end)},key:i,items:c}}function ne(t,n){let r;try{r=D(t.value.raw)}catch(e){const r=e;throw new v(n,t.value.loc.start,r.message)}return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:r}}function re(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===q}}function oe(n,r){let o,a=n.value.loc,i=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&z.IS_FULL_DATE.test(i)&&z.IS_FULL_TIME.test(n.peek().value.raw)){const e=a.start;n.next(),a={start:e,end:n.value.loc.end},i+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=a.start;if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(r,n.value.loc.end,"Expected fractional value for DateTime");n.next(),a={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,`Invalid datetime "${e}": fractional seconds must have at least one digit after decimal point`);if(/[+-]$/.test(e))throw new v(t,n,`Invalid datetime "${e}": timezone offset requires hour and minute components`);const r=/\d{2}:\d{2}/.test(e),o=r?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(o){const e=o[0],r=o[2],a=o[3],i=o[4];if(":"!==a)throw new v(t,n,`Invalid timezone offset "${e}": must use colon separator (e.g., +09:09)`);if(2!==r.length)throw new v(t,n,`Invalid timezone offset "${e}": hour must be exactly 2 digits`);if(!i||0===i.length)throw new v(t,n,`Invalid timezone offset "${e}": minute component is required`);if(2!==i.length)throw new v(t,n,`Invalid timezone offset "${e}": minute must be exactly 2 digits`);const l=parseInt(r,10);if(l<0||l>23)throw new v(t,n,`Invalid timezone offset "${e}": hour must be between 00 and 23, found ${r}`);const s=parseInt(i,10);if(s<0||s>59)throw new v(t,n,`Invalid timezone offset "${e}": minute must be between 00 and 59, found ${i}`)}const a=/^\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)&&!a.test(e)){if(/^\d{4}-\d{2}-\d{2}T$/.test(e))throw new v(t,n,`Invalid date "${e}": date cannot end with 'T' without a 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,`Invalid datetime "${e}": missing separator 'T' or space between date and time`);throw new v(t,n,`Invalid datetime "${e}"`)}const i=e.match(/^(\d+)-/);if(i&&4!==i[1].length)throw new v(t,n,`Invalid date "${e}": year must be exactly 4 digits, found ${i[1].length}`);const l=/^(\d+)-(\d+)-(\d+)/,s=e.match(l);if(s){const[,,r,o]=s;if(2!==r.length)throw new v(t,n,`Invalid date "${e}": month must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new v(t,n,`Invalid date "${e}": day must be exactly 2 digits, found ${o.length}`)}const c=/[T ](\d+):(\d+)(?::(\d+))?/,u=e.match(c);if(u){const[,r,o,a]=u;if(2!==r.length)throw new v(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new v(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(a&&2!==a.length)throw new v(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${a.length}`)}const f=/^(\d+):(\d+)(?::(\d+))?/,d=e.match(f);if(d&&!s){const[,r,o,a]=d;if(2!==r.length)throw new v(t,n,`Invalid time "${e}": hour must be exactly 2 digits, found ${r.length}`);if(2!==o.length)throw new v(t,n,`Invalid time "${e}": minute must be exactly 2 digits, found ${o.length}`);if(a&&2!==a.length)throw new v(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${a.length}`)}const m=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),h=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(m){const[,r,o,a,i,l,s]=m,c=parseInt(o,10);if(c<1||c>12)throw new v(t,n,`Invalid date "${e}": month must be between 01 and 12`);const u=parseInt(a,10);if(u<1||u>31)throw new v(t,n,`Invalid date "${e}": day must be between 01 and 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(r,10),c);if(u>f)throw new v(t,n,`Invalid date "${e}": day ${a} is invalid for month ${o} in year ${r}`);if(void 0!==i){const r=parseInt(i,10);if(r<0||r>23)throw new v(t,n,`Invalid time "${e}": hour must be between 00 and 23`)}if(void 0!==l){const r=parseInt(l,10);if(r<0||r>59)throw new v(t,n,`Invalid time "${e}": minute must be between 00 and 59`)}if(void 0!==s){const r=parseInt(s,10);if(r<0||r>60)throw new v(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}else if(h){const[,r,o,a]=h,i=parseInt(r,10);if(i<0||i>23)throw new v(t,n,`Invalid time "${e}": hour must be between 00 and 23`);const l=parseInt(o,10);if(l<0||l>59)throw new v(t,n,`Invalid time "${e}": minute must be between 00 and 59`);if(void 0!==a){const r=parseInt(a,10);if(r<0||r>60)throw new v(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}}(i,r,a.start),z.IS_FULL_DATE.test(i))o=z.IS_DATE_ONLY.test(i)?new j(i):z.IS_LOCAL_DATETIME_T.test(i)?new B(i,!1):z.IS_LOCAL_DATETIME_SPACE.test(i)?new B(i,!0):z.IS_OFFSET_DATETIME_T.test(i)?new Z(i,!1):z.IS_OFFSET_DATETIME_SPACE.test(i)?new Z(i,!0):new Date(i.replace(" ","T"));else if(z.IS_TIME_ONLY.test(i))o=new W(i,i);else{const[e]=(new Date).toISOString().split("T");o=new Date(`${e}T${i}`)}return{type:e.DateTime,loc:a,raw:i,value:o}}function ae(n,r){let o,a=n.value.loc,i=n.value.raw;if(P.test(i))o=i.startsWith("-")?-1/0:1/0;else if(H.test(i))o=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(/_$/.test(i))throw new v(r,a.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(i))throw new v(r,a.start,"Leading underscore is not allowed");if(/__/.test(i))throw new v(r,a.start,"Consecutive underscores are not allowed");if(/[eE][+\-]?$/.test(i))throw new v(r,a.start,`Invalid float "${i}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(i))throw new v(r,a.start,`Invalid float "${i}": decimal point not allowed in exponent`);if(/_[eE]/.test(i))throw new v(r,a.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(i))throw new v(r,a.start,"Underscore at start of exponent is not allowed");if(!n.peek().done&&n.peek().value.type===t.Dot)throw new v(r,n.peek().value.loc.start,`Invalid float "${i}.": cannot have decimal point after exponent`);const e=i.replace(R,"");if(/^[+\-]?0\d/.test(e)&&!Y.test(i)&&!X.test(i)&&!G.test(i))throw new v(r,a.start,"Leading zeros are not allowed in the integer part of a float");o=Number(i.replace(R,""))}else{const e=a.start;{if(V.test(i)&&!Y.test(i))throw new v(r,a.start,`Invalid float "${i}": cannot have decimal point after exponent`);const e=i,t=e.replace(R,"");if(/^[+\-]?0\d/.test(t)&&!Y.test(e)&&!X.test(e)&&!G.test(e))throw new v(r,a.start,"Leading zeros are not allowed in the integer part of a float");const n=e.replace(/^[+\-]/,"");if(""===n||"_"===n)throw new v(r,a.start,"Invalid float: decimal point must be preceded by at least one digit");if(/_$/.test(e))throw new v(r,a.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(e))throw new v(r,a.start,"Leading underscore is not allowed");if(/__/.test(e))throw new v(r,a.start,"Consecutive underscores are not allowed")}if(n.next(),n.peek().done||n.peek().value.type!==t.Literal)throw new v(r,n.value.loc.end,"Expected fraction value for Float");n.next(),i+=`.${n.value.raw}`,a={start:e,end:n.value.loc.end};{const e=n.value.raw;if(!/^\d/.test(e))throw new v(r,n.value.loc.start,`Invalid float: fractional part must start with a digit, found "${e}"`);if(/^_/.test(e))throw new v(r,n.value.loc.start,"Underscore after decimal point is not allowed");if(/_$/.test(e))throw new v(r,n.value.loc.start,"Trailing underscore in fractional part is not allowed");if(/_[eE]/.test(e))throw new v(r,n.value.loc.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(e))throw new v(r,n.value.loc.start,"Underscore at start of exponent is not allowed");if(/[eE][+\-]?$/.test(e))throw new v(r,n.value.loc.start,`Invalid float "${i}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(e))throw new v(r,n.value.loc.start,`Invalid float "${i}": decimal point not allowed in exponent`)}o=Number(i.replace(R,""))}if(Number.isNaN(o)&&!H.test(i))throw new v(r,a.start,`Invalid float "${i}"`);return{type:e.Float,loc:a,raw:i,value:o}}function ie(t,n){const r=t.value.raw,o=t.value.loc;if(/^\d{1,}-\d{1,}/.test(r)||/^\d{1,}:\d{1,}/.test(r)||/^\d{6}-\d{2}$/.test(r))throw new v(n,o.start,`Invalid integer "${r}"`);{if("-0"===r||"+0"===r)return{type:e.Integer,loc:o,raw:r,value:0};if(/^[+\-]{2,}/.test(r))throw new v(n,o.start,"Double sign is not allowed in integers");const t=r.replace(/_/g,"");if(/^[+\-]?0\d/.test(t)&&!Y.test(r)&&!X.test(r)&&!G.test(r))throw new v(n,o.start,"Leading zeros are not allowed in decimal integers");if(/_$/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(/^[+\-]?_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(/__/.test(r))throw new v(n,o.start,"Consecutive underscores in numbers are not allowed")}let a,i=10;if(Y.test(r)){if(i=16,/^[+\-]?0X/.test(r))throw new v(n,o.start,'Hexadecimal prefix must be lowercase "0x"');if(/^[+\-]?0x_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(a=r.replace(/^[+\-]?0x/i,""),!a||"_"===a||/^_/.test(a))throw new v(n,o.start,"Incomplete hexadecimal number");const e=a.replace(/_/g,"");if(!/^[0-9a-fA-F]+$/.test(e))throw new v(n,o.start,"Invalid hexadecimal digits");if(/^[+\-]/.test(r))throw new v(n,o.start,"Hexadecimal numbers cannot have a sign prefix")}else if(X.test(r)){if(i=8,/^[+\-]?0O/.test(r))throw new v(n,o.start,'Octal prefix must be lowercase "0o"');if(/^[+\-]?0o_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(a=r.replace(/^[+\-]?0o/i,""),!a||"_"===a||/^_/.test(a))throw new v(n,o.start,"Incomplete octal number");const e=a.replace(/_/g,"");if(!/^[0-7]+$/.test(e))throw new v(n,o.start,"Invalid octal digits (must be 0-7)");if(/^[+\-]/.test(r))throw new v(n,o.start,"Octal numbers cannot have a sign prefix")}else if(G.test(r)){if(i=2,/^[+\-]?0B/.test(r))throw new v(n,o.start,'Binary prefix must be lowercase "0b"');if(/^[+\-]?0b_/.test(r))throw new v(n,o.start,"Underscores in numbers must be surrounded by digits");if(a=r.replace(/^[+\-]?0b/i,""),!a||"_"===a||/^_/.test(a))throw new v(n,o.start,"Incomplete binary number");const e=a.replace(/_/g,"");if(!/^[01]+$/.test(e))throw new v(n,o.start,"Invalid binary digits (must be 0 or 1)");if(/^[+\-]/.test(r))throw new v(n,o.start,"Binary numbers cannot have a sign prefix")}const l=parseInt(r.replace(R,"").replace(X,"").replace(G,""),i);if(Number.isNaN(l))throw new v(n,o.start,`Invalid integer "${r}"`);return{type:e.Integer,loc:o,raw:r,value:l}}function le(n,r){if(n.value.type===t.Comment)return[ee(n)];if(n.value.type===t.Bracket)return[te(n,r)];if(n.value.type===t.Literal)return function(n,r){const o=n.value.raw;if(o.endsWith(":"))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+[...o].length-1},"Use '=' to separate keys and values, not ':'");if(o.startsWith('"""')||o.startsWith("'''"))throw new v(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!o.startsWith('"')&&!o.startsWith("'"))for(let e=0;e<o.length;e++)if(!J(o.charCodeAt(e)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+e},`Invalid character '${o[e]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);let a;try{a=[D(n.value.raw)]}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}const i={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:a};for(;!n.peek().done&&n.peek().value.type===t.Dot;){n.next(),n.next();const e=n.value.raw;if(e.startsWith('"""')||e.startsWith("'''"))throw new v(r,n.value.loc.start,"Multiline strings (\"\"\" or ''') cannot be used as keys");if(!(e.startsWith('"')||e.startsWith("'")))for(let t=0;t<e.length;t++)if(!J(e.charCodeAt(t)))throw new v(r,{line:n.value.loc.start.line,column:n.value.loc.start.column+t},`Invalid character '${e[t]}' in bare key. Bare keys can only contain A-Z, a-z, 0-9, _, and -`);i.loc.end=n.value.loc.end,i.raw+=`.${n.value.raw}`;try{i.value.push(D(n.value.raw))}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}}if(n.next(),!n.done&&n.value.loc.start.line!==i.loc.end.line)throw new v(r,n.value.loc.start,'Expected "=" for key-value on the same line as the key');if(n.done||n.value.type!==t.Equal){if(!n.done&&":"===n.value.raw)throw new v(r,n.value.loc.start,"Use '=' to separate keys and values, not ':'");throw new v(r,n.done?i.loc.end:n.value.loc.start,'Expected "=" for key-value')}const l=n.value.loc.start.column,s=n.value.loc.start.line;if(n.next(),n.done)throw new v(r,i.loc.start,"Expected value for key-value, reached end of file");if(n.value.loc.start.line!==s)throw new v(r,n.value.loc.start,"Expected value on the same line as the '=' sign");if(n.done)throw new v(r,i.loc.start,"Expected value for key-value");const c=se(n,r),u=c[0];if(!n.peek().done){const o=n.peek().value;if(o.type===t.Dot&&o.loc.start.line===u.loc.end.line&&(u.type===e.Float||u.type===e.Integer))throw new v(r,o.loc.start,"Invalid number: multiple decimal points not allowed");if((o.type===t.Literal||o.type===t.Bracket)&&o.loc.start.line===u.loc.end.line)throw new v(r,o.loc.start,"Key/value pairs must be separated by a newline")}return c[0]={type:e.KeyValue,key:i,value:u,loc:{start:g(i.loc.start),end:g(u.loc.end)},equals:l},c}(n,r);throw n.value.type===t.Equal?new v(r,n.value.loc.start,"Missing key before '='"):new v(r,n.value.loc.start,`Unexpected token "${n.value.type}". Expected Comment, Bracket, or String`)}function se(n,r){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===b||e[0]===$?[ne(n,r)]:e===q||"false"===e?[re(n)]:/^\d/.test(e)&&(/^\d{1,}-\d{1,}/.test(e)||/^\d{1,}:\d{1,}/.test(e))?[oe(n,r)]:!n.peek().done&&n.peek().value.type===t.Dot||P.test(e)||H.test(e)||V.test(e)&&!Y.test(e)?[ae(n,r)]:[ie(n,r)]}if(n.value.type===t.Curly){const[o,a]=function(n,r){if("{"!==n.value.raw)throw new v(r,n.value.loc.start,'Expected "{" for inline table');const o={type:e.InlineTable,loc:n.value.loc,items:[]},a=[];n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comment){a.push(ee(n)),n.next();continue}if(n.value.type===t.Comma){const e=o.items[o.items.length-1];if(!e)throw new v(r,n.value.loc.start,'Found "," without previous value in inline table');if(e.comma)throw new v(r,n.value.loc.start,"Found consecutive commas in inline table (double comma is not allowed)");e.comma=!0,e.loc.end=n.value.loc.start,n.next();continue}const i=o.items[o.items.length-1];if(i&&!i.comma)throw new v(r,n.value.loc.start,"Missing comma between inline table items");const l=le(n,r),s=l[0];if(s.type===e.KeyValue){o.items.push({type:e.InlineItem,loc:y(s.loc),item:s,comma:!1});for(let e=1;e<l.length;e++)a.push(l[e])}n.next()}if(n.done||n.value.type!==t.Curly||"}"!==n.value.raw)throw new v(r,n.done?o.loc.start:n.value.loc.start,'Expected "}"');return o.loc.end=n.value.loc.end,[o,a]}(n,r);return[o,...a]}if(n.value.type===t.Bracket){const[o,a]=function(n,r){if("["!==n.value.raw)throw new v(r,n.value.loc.start,'Expected "[" for inline array');const o={type:e.InlineArray,loc:n.value.loc,items:[]},a=[];n.next();for(;!n.done&&(n.value.type!==t.Bracket||"]"!==n.value.raw);){if(n.value.type===t.Comma){const e=o.items[o.items.length-1];if(!e)throw new v(r,n.value.loc.start,'Found "," without previous value for inline array');if(e.comma)throw new v(r,n.value.loc.start,"Found consecutive commas in array (double comma is not allowed)");e.comma=!0,e.loc.end=n.value.loc.start}else if(n.value.type===t.Comment)a.push(ee(n));else{const t=o.items[o.items.length-1];if(t&&!t.comma)throw new v(r,n.value.loc.start,"Missing comma between array elements");const i=se(n,r),l=i[0];o.items.push({type:e.InlineItem,loc:y(l.loc),item:l,comma:!1});for(let e=1;e<i.length;e++)a.push(i[e])}n.next()}if(n.done||n.value.type!==t.Bracket||"]"!==n.value.raw)throw new v(r,n.done?o.loc.start:n.value.loc.start,'Expected "]"');return o.loc.end=n.value.loc.end,[o,a]}(n,r);return[o,...a]}throw n.value.type===t.Dot?new v(r,n.value.loc.start,"Invalid number: cannot start with a dot. Numbers must start with a digit"):new v(r,n.value.loc.start,"Unrecognized token type")}function ce(e){return e[e.length-1]}function ue(){return Object.create(null)}function fe(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function de(e){return"[object Date]"===Object.prototype.toString.call(e)}function me(e){return e&&"object"==typeof e&&!de(e)&&!Array.isArray(e)}function he(e){return null!=e&&"function"==typeof e[Symbol.iterator]}function pe(e,t){return t in e}function we(e){if(me(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${we(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(we).join(",")}]`:JSON.stringify(e)}function ge(e,t){const n=e.length,r=t.length;e.length=n+r;for(let o=0;o<r;o++)e[n+o]=t[o]}function ye(e){return e.startsWith('"""')||e.startsWith("'''")}const ve=new WeakSet,be=new WeakMap,$e=e=>(be.has(e)||be.set(e,new WeakMap),be.get(e)),Se=new WeakMap,Te=e=>(Se.has(e)||Se.set(e,new WeakMap),Se.get(e));function Ie(e,t,n,r){if(d(t)){const e=t.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.items.splice(e,1,r)}else if(a(t)&&u(t.value)&&!u(n)){const e=t.value.items.indexOf(n);if(e<0)throw new Error("Could not find existing item in parent node for replace");t.value.items.splice(e,1,r)}else if(m(t))t.item=r;else{if(!a(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=r:t.value=r}Ue(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});const o=h(n.loc),i=h(r.loc);De({lines:i.lines-o.lines,columns:i.columns-o.columns},Te(e),r,n),ve.add(e)}function ke(e,t,i,l,m){if(!d(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,w;l=null!=l&&"number"==typeof l?l:t.items.length,s(t)||u(t)?({shift:p,offset:w}=function(e,t,n){if(!c(t))throw new Error(`Incompatible child type "${t.type}"`);const r=null!=n?e.items[n-1]:ce(e.items),o=null==n||n===e.items.length;e.items.splice(n,0,t);const a=!!r,i=!o;a&&(r.comma=!0);i&&(t.comma=!0);const l=s(e)&&function(e){if(!e.items.length)return!1;return h(e.loc).lines>e.items.length}(e),u=o&&!0===t.comma;return Ce(e,t,n,{useNewLine:l,hasCommaHandling:!0,isLastElement:o,hasSeparatingCommaBefore:a,hasSeparatingCommaAfter:i,hasTrailingComma:u})}(t,i,l)):m&&n(t)?({shift:p,offset:w}=function(e,t,n){const r=Ce(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}(t,i,l)):({shift:p,offset:w}=function(e,t,i){if(l=t,!(a(l)||r(l)||o(l)||f(l)))throw new Error(`Incompatible child type "${t.type}"`);var l;const s=e.items[i-1],c=n(e)&&!e.items.length;e.items.splice(i,0,t);const u=s?{line:s.loc.end.line,column:f(s)?e.loc.start.column:s.loc.start.column}:g(e.loc.start),d=r(t)||o(t);let m=0;c||(m=d?2:1);u.line+=m;const p={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},w=h(t.loc),y={lines:w.lines+(m-1),columns:w.columns};return{shift:p,offset:y}}(t,i,l)),Ue(i,p);const y=t.items[l-1],v=y&&Te(e).get(y);v&&(w.lines+=v.lines,w.columns+=v.columns,Te(e).delete(y));Te(e).set(i,w),ve.add(e)}function Ce(e,t,n,r={}){const{useNewLine:o=!1,skipCommaSpace:a=2,skipBracketSpace:i=1,hasCommaHandling:l=!1,isLastElement:s=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:d=!1}=r,m=n>0?e.items[n-1]:void 0,p=m?{line:m.loc.end.line,column:o?f(m)?e.loc.start.column:m.loc.start.column:m.loc.end.column}:g(e.loc.start);let w=0;if(o)w=1;else{const e=c||!l&&!!m;e&&l?p.column+=a:(e||l&&!m)&&(p.column+=i)}p.line+=w;const y={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},v=h(t.loc);if(!l){return{shift:y,offset:{lines:v.lines+(w-1),columns:v.columns}}}let b=0;c&&d&&!u&&s&&(b=-1);return{shift:y,offset:{lines:v.lines+(w-1),columns:v.columns+(c||u?a:0)+(d?1+b:0)}}}function Ee(e,t,n){if(!d(t))throw new Error(`Unsupported parent type "${t.type}" for remove`);let r=t.items.indexOf(n);if(r<0){if(r=t.items.findIndex((e=>m(e)&&e.item===n)),r<0)throw new Error("Could not find node in parent for removal");n=t.items[r]}const o=t.items[r-1];let a=t.items[r+1];t.items.splice(r,1);let i=h(n.loc);a&&f(a)&&a.loc.start.line===n.loc.end.line&&(i=h({start:n.loc.start,end:a.loc.end}),a=t.items[r+1],t.items.splice(r,1));const l=o&&c(o)||a&&c(a),s=o&&o.loc.end.line===n.loc.start.line,u=a&&a.loc.start.line===n.loc.end.line,p=l&&(s||u),w={lines:-(i.lines-(p?1:0)),columns:-i.columns};if(void 0===o&&void 0===a&&(w.lines=0,w.columns=0),l&&s&&(w.columns-=2),l&&!o&&a&&(w.columns-=2),l&&o&&!a){const e=n.comma;o.comma=!!e}const g=o||t,y=o?Te(e):$e(e),v=Te(e),b=y.get(g);b&&(w.lines+=b.lines,w.columns+=b.columns);const $=v.get(n);$&&(w.lines+=$.lines,w.columns+=$.columns),y.set(g,w),ve.add(e)}function Ae(e,t,n=!0){if(!n)return;if(!t.items.length)return;De({lines:0,columns:1},$e(e),t);const r=ce(t.items);De({lines:0,columns:1},Te(e),r),ve.add(e)}function xe(e,t,n=!1){if(!n)return;if(!t.items.length)return;const r=ce(t.items);r.comma=!0,De({lines:0,columns:1},Te(e),r),ve.add(e)}function _e(t){if(!ve.has(t))return;const n=$e(t),r=Te(t);let o=0;const a={};function i(e){e.loc.start.line+=o;const t=a[e.loc.start.line]||0;e.loc.start.column+=t;const r=n.get(e);r&&(o+=r.lines,a[e.loc.start.line]=(a[e.loc.start.line]||0)+r.columns)}function l(e){e.loc.end.line+=o;const t=a[e.loc.end.line]||0;e.loc.end.column+=t;const n=r.get(e);n&&(o+=n.lines,a[e.loc.end.line]=(a[e.loc.end.line]||0)+n.columns)}!function t(n){switch(n.type){case e.Document:{const e=n;i(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);l(e);break}case e.Table:{const e=n;i(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);l(e);break}case e.TableArray:{const e=n;i(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);l(e);break}case e.TableKey:{const e=n;i(e),t(e.item),l(e);break}case e.TableArrayKey:{const e=n;i(e),t(e.item),l(e);break}case e.KeyValue:{const e=n,s=e.loc.start.line+o,c=r.get(e.key);e.equals+=(a[s]||0)+(c?c.columns:0),i(e),t(e.key),t(e.value),l(e);break}case e.InlineArray:{const e=n;i(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);l(e);break}case e.InlineTable:{const e=n;i(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);l(e);break}case e.InlineItem:{const e=n;i(e),t(e.item),l(e);break}case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:i(n),l(n);break;default:throw new Error(`Unrecognized node type "${n.type}"`)}}(t),ve.delete(t),be.delete(t),Se.delete(t)}function Ue(t,n,r={}){const{lines:o,columns:a}=n;if(0===o&&0===a)return t;const{first_line_only:i=!1}=r,l=t.loc.start.line,s=t.type;if(s===e.Key||s===e.String||s===e.Integer||s===e.Float||s===e.Boolean||s===e.DateTime||s===e.Comment)return i&&t.loc.start.line!==l||(t.loc.start.column+=a,t.loc.end.column+=a),t.loc.start.line+=o,t.loc.end.line+=o,t;if(s===e.KeyValue){const n=t,r=n.value.type;if(r===e.String||r===e.Integer||r===e.Float||r===e.Boolean||r===e.DateTime){i&&n.loc.start.line!==l||(n.loc.start.column+=a,n.loc.end.column+=a),n.loc.start.line+=o,n.loc.end.line+=o,n.equals+=a;const e=n.key;i&&e.loc.start.line!==l||(e.loc.start.column+=a,e.loc.end.column+=a),e.loc.start.line+=o,e.loc.end.line+=o;const r=n.value;return i&&r.loc.start.line!==l||(r.loc.start.column+=a,r.loc.end.column+=a),r.loc.start.line+=o,r.loc.end.line+=o,t}}const c=e=>{i&&e.loc.start.line!==l||(e.loc.start.column+=a,e.loc.end.column+=a),e.loc.start.line+=o,e.loc.end.line+=o};return function(t,n){function r(e,t){for(const n of e)o(n,t)}function o(t,a){const i=n[t.type];switch(i&&"function"==typeof i&&i(t,a),i&&i.enter&&i.enter(t,a),t.type){case e.Document:r(t.items,t);break;case e.Table:o(t.key,t),r(t.items,t);break;case e.TableKey:o(t.item,t);break;case e.TableArray:o(t.key,t),r(t.items,t);break;case e.TableArrayKey:o(t.item,t);break;case e.KeyValue:o(t.key,t),o(t.value,t);break;case e.InlineArray:r(t.items,t);break;case e.InlineItem:o(t.item,t);break;case e.InlineTable:r(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,a)}he(t)?r(t,null):o(t,null)}(t,{[e.Table]:c,[e.TableKey]:c,[e.TableArray]:c,[e.TableArrayKey]:c,[e.KeyValue](e){c(e),e.equals+=a},[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 De(e,t,n,r){const o=t.get(r||n);o&&(e.lines+=o.lines,e.columns+=o.columns),t.set(n,e)}function Oe(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Fe(t){const n=function(t){const n=Ne(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 Le(t){const n=function(t){const n=Ne(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 Me(t,n){const r=function(t){const n=Ne(t);return{type:e.Key,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t),{column:o}=r.loc.end,a=o+1;return Ue(n,{lines:0,columns:o+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:g(r.loc.start),end:g(n.loc.end)},key:r,equals:a,value:n}}const Ke=/^[\w-]+$/;function Ne(e){return e.map((e=>Ke.test(e)?e:JSON.stringify(e))).join(".")}function je(t,n){let r,o;if(n&&ye(n)){let e=n.startsWith("'''");e&&t.includes("'''")&&(e=!1);const o=e?"'''":'"""',a=n.includes("\r\n")?"\r\n":"\n",i=n.startsWith(`${o}${a}`)||(n.startsWith("'''\n")||n.startsWith("'''\r\n"))&&!e;let l;l=e?t:t.replace(/\\/g,"\\\\").replace(/\x08/g,"\\b").replace(/\f/g,"\\f").replace(/\t/g,"\\t").replace(/[\x00-\x07\x0B\x0E-\x1F\x7F]/g,(e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase())).replace(/"""/g,'""\\"'),r=i?`${o}${a}${l}${o}`:`${o}${l}${o}`}else r=JSON.stringify(t);if(r.includes("\r\n")||r.includes("\n")&&!r.includes("\r\n")){const e=r.includes("\r\n")?"\r\n":"\n",t=(r.match(new RegExp("\r\n"===e?"\\r\\n":"\\n","g"))||[]).length;o=t>0?{line:1+t,column:3}:{line:1,column:r.length}}else o={line:1,column:r.length};return{type:e.String,loc:{start:{line:1,column:0},end:o},raw:r,value:t}}function We(t){return{type:e.InlineItem,loc:y(t.loc),item:t,comma:!1}}const Be=!1,Ze=!0,ze=!1,qe=!1;function Ve(e,t){if(!e||"object"!=typeof e)return null;if(("InlineArray"===e.type||"InlineTable"===e.type)&&e.loc){const n=function(e,t){var n;if(!e||!e.start||!e.end)return null;const r=t.split(/\r?\n/),o=e.start.line-1,a=e.end.line-1,i=e.start.column,l=e.end.column;let s="";if(o===a)s=(null===(n=r[o])||void 0===n?void 0:n.substring(i,l+1))||"";else{r[o]&&(s+=r[o].substring(i));for(let e=o+1;e<a;e++)s+="\n"+(r[e]||"");r[a]&&(s+="\n"+r[a].substring(0,l+1))}const c=s.match(/^\[(\s*)/),u=s.match(/^\{(\s*)/);if(c)return c[1].length>0;if(u)return u[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=Ve(n,t);if(null!==e)return e;if(n.item){const e=Ve(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const r=Ve(e[n],t);if(null!==r)return r}return null}function Re(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return Pe(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return Pe(e.items);if("KeyValue"===e.type&&e.value)return Re(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=Re(t);if(null!==e)return e}return null}function Pe(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 He(e){if(!s(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Ye(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Je(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function Xe(e,t){var n,r,o,a,i,l;if(e){if(e instanceof Ge)return e;{const s=function(e){if(!e||"object"!=typeof e)return{};const t=new Set(["newLine","trailingNewline","trailingComma","bracketSpacing","inlineTableStart","truncateZeroTimeInDates","useTabsForIndentation"]),n={},r=[],o=[];for(const a in e){const i=Object.prototype.hasOwnProperty.call(e,a);if(t.has(a)){const t=e[a];switch(a){case"newLine":"string"==typeof t?n.newLine=t:o.push(`${a} (expected string, got ${typeof t})`);break;case"trailingNewline":"boolean"==typeof t||"number"==typeof t?n.trailingNewline=t:o.push(`${a} (expected boolean or number, got ${typeof t})`);break;case"trailingComma":case"bracketSpacing":case"truncateZeroTimeInDates":case"useTabsForIndentation":"boolean"==typeof t?n[a]=t:o.push(`${a} (expected boolean, got ${typeof t})`);break;case"inlineTableStart":"number"==typeof t&&Number.isInteger(t)&&t>=0||null==t?n.inlineTableStart=t:o.push(`${a} (expected non-negative integer or undefined, got ${typeof t})`)}}else i&&r.push(a)}if(r.length>0&&console.warn(`toml-patch: Ignoring unsupported format properties: ${r.join(", ")}. Supported properties are: ${Array.from(t).join(", ")}`),o.length>0)throw new TypeError(`Invalid types for format properties: ${o.join(", ")}`);return n}(e);return new Ge(null!==(n=s.newLine)&&void 0!==n?n:t.newLine,null!==(r=s.trailingNewline)&&void 0!==r?r:t.trailingNewline,null!==(o=s.trailingComma)&&void 0!==o?o:t.trailingComma,null!==(a=s.bracketSpacing)&&void 0!==a?a:t.bracketSpacing,void 0!==s.inlineTableStart?s.inlineTableStart:t.inlineTableStart,null!==(i=s.truncateZeroTimeInDates)&&void 0!==i?i:t.truncateZeroTimeInDates,null!==(l=s.useTabsForIndentation)&&void 0!==l?l:t.useTabsForIndentation)}}return t}class Ge{constructor(e,t,n,r,o,a,i){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:Be,this.bracketSpacing=null!=r?r:Ze,this.inlineTableStart=null!=o?o:1,this.truncateZeroTimeInDates=null!=a?a:ze,this.useTabsForIndentation=null!=i?i:qe}static default(){return new Ge("\n",1,Be,Ze,1,ze,qe)}static autoDetectFormat(e){const t=Ge.default();t.newLine=Je(e),t.trailingNewline=function(e,t){let n=0,r=e.length;for(;r>=t.length&&e.substring(r-t.length,r)===t;)n++,r-=t.length;return n}(e,t.newLine);try{const n=Q(e),r=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=Re(e);if(null!==t)return t}return Be}(r),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=Ve(t,e);if(null!==n)return n}return Ze}(e,r)}catch(e){t.trailingComma=Be,t.bracketSpacing=Ze}return t.useTabsForIndentation=function(e){const t=e.split(/\r?\n/);let n=0,r=0;for(const e of t)if(0!==e.length&&("\t"===e[0]?n++:" "===e[0]&&r++,n+r>=5))break;return n>r}(e),t.inlineTableStart=1,t.truncateZeroTimeInDates=ze,t}}function Qe(e,t){if(0===t.inlineTableStart)return e;return e.items.filter((e=>{if(!a(e))return!1;const n=u(e.value),r=s(e.value)&&e.value.items.length&&u(e.value.items[0].item);if(n||r){const n=nt(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1})).forEach((t=>{Ee(e,e,t),u(t.value)?ke(e,e,et(t)):function(e){const t=Oe();for(const n of e.value.items){const r=Le(e.key.value);ke(t,t,r);for(const e of n.item.items)ke(t,r,e.item)}return _e(t),t.items}(t).forEach((t=>{ke(e,e,t)}))})),_e(e),e}function et(e){const t=Fe(e.key.value);for(const n of e.value.items)ke(t,t,n.item);return _e(t),t}function tt(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 nt(e){return Math.max(0,e.length-1)}function rt(e,t,n){var r;for(let o=e.items.length-1;o>=0;o--){const i=e.items[o];if(a(i)&&u(i.value)){const o=[...e.key.item.value,...i.key.value];if(nt(o)<(null!==(r=n.inlineTableStart)&&void 0!==r?r:1)){const r=Fe(o);for(const e of i.value.items)ke(r,r,e.item);Ee(e,e,i),tt(e),t.push(r),rt(r,t,n)}}}}function ot(e,t=Ge.default()){e=function(e){const t=[],n=[];for(const r in e)me(e[r])||Array.isArray(e[r])?n.push(r):t.push(r);const r={};for(let n=0;n<t.length;n++){const o=t[n];r[o]=e[o]}for(let t=0;t<n.length;t++){const o=n[t];r[o]=e[o]}return r}(e=lt(e));const n=Oe();for(const r of at(e,t))ke(n,n,r);return _e(n),Qe(n,t),function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const r of e.items)if(a(r)&&u(r.value)){if(nt(r.key.value)<t.inlineTableStart){const o=et(r);Ee(e,e,r),ke(e,e,o),rt(o,n,t)}}else"Table"===r.type&&rt(r,n,t);for(const t of n)ke(e,e,t);_e(e)}(n,t),function(e){let t=0,n=0;for(const r of e.items)0===n&&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)),Ue(r,{lines:t,columns:0}),n=r.loc.end.line;return e}(n)}function*at(e,t){for(const n of Object.keys(e))yield Me([n],it(e[n],t))}function it(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?je(t):fe(t)?function(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}}(t):function(e){return"number"==typeof e&&(!fe(e)||!isFinite(e)||Object.is(e,-0))}(t)?function(t){let n;return n=t===1/0?"inf":t===-1/0?"-inf":Number.isNaN(t)?"nan":Object.is(t,-0)?"-0.0":t.toString(),{type:e.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):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):de(t)?function(t,n){n.truncateZeroTimeInDates&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new j(t.toISOString().split("T")[0]));const r=t.toISOString();return{type:e.DateTime,loc:{start:{line:1,column:0},end:{line:1,column:r.length}},raw:r,value:t}}(t,n):Array.isArray(t)?function(t,n){const r={type:e.InlineArray,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of t){ke(r,r,We(it(e,n)))}return Ae(r,r,n.bracketSpacing),xe(r,r,n.trailingComma),_e(r),r}(t,n):function(t,n){if(t=lt(t),!me(t))return it(t,n);const r={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of at(t,n)){ke(r,r,We(e))}return Ae(r,r,n.bracketSpacing),xe(r,r,n.trailingComma),_e(r),r}(t,n)}function lt(e){return e?de(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const st=/(\r\n|\n)/g;function ct(t,n){const r=[];function o(t){switch(t.type){case e.Document:for(let e=0;e<t.items.length;e++)o(t.items[e]);break;case e.Table:{const e=t;o(e.key);for(let t=0;t<e.items.length;t++)o(e.items[t]);break}case e.TableKey:{const e=t,{start:n,end:a}=e.loc;ft(r,n.line,n.column,"["),ft(r,a.line,a.column-1,"]"),o(e.item);break}case e.TableArray:{const e=t;o(e.key);for(let t=0;t<e.items.length;t++)o(e.items[t]);break}case e.TableArrayKey:{const e=t,{start:n,end:a}=e.loc;dt(r,n.line,n.column,n.column+2,"[["),dt(r,a.line,a.column-2,a.column,"]]"),o(e.item);break}case e.KeyValue:{const e=t,n=e.loc.start.line;ft(r,n,e.equals,"="),o(e.key),o(e.value);break}case e.Key:case e.String:case e.Integer:case e.Float:ut(r,t.loc,t.raw);break;case e.Boolean:ut(r,t.loc,t.value.toString());break;case e.DateTime:ut(r,t.loc,t.raw);break;case e.InlineArray:{const e=t,{start:n,end:a}=e.loc;ft(r,n.line,n.column,"["),ft(r,a.line,a.column-1,"]");for(let t=0;t<e.items.length;t++)o(e.items[t]);break}case e.InlineTable:{const e=t,{start:n,end:a}=e.loc;ft(r,n.line,n.column,"{"),ft(r,a.line,a.column-1,"}");for(let t=0;t<e.items.length;t++)o(e.items[t]);break}case e.InlineItem:{const e=t;if(o(e.item),e.comma){const t=e.loc.end;ft(r,t.line,t.column,",")}break}case e.Comment:ut(r,t.loc,t.raw);break;default:{const e=t.type;throw new Error(`toTOML: Unrecognized node type: ${String(e)}`)}}}if(he(t))for(const e of t)o(e);else o(t);if(n.useTabsForIndentation)for(let e=0;e<r.length;e++){const t=r[e],n=t.match(/^( +)/);if(n){const o=n[1],a="\t".repeat(o.length);r[e]=a+t.substring(o.length)}}return r.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function ut(e,t,n){if(t.start.line===t.end.line){const r=mt(e,t.start.line),o=r.substring(0,t.start.column),a=o.length<t.start.column?o.padEnd(t.start.column,S):o,i=r.substring(t.end.column);return void(e[t.start.line-1]=a+n+i)}const r=n.split(st).filter((e=>"\n"!==e&&"\r\n"!==e)),o=t.end.line-t.start.line+1;if(r.length!==o)throw new Error(`Mismatch between location and raw string, expected ${o} lines for "${n}"`);for(let n=t.start.line;n<=t.end.line;n++){const o=mt(e,n),a=n===t.start.line,i=n===t.end.line;let l="";if(a){const e=o.substring(0,t.start.column);l=e.length<t.start.column?e.padEnd(t.start.column,S):e}const s=i?o.substring(t.end.column):"";e[n-1]=l+r[n-t.start.line]+s}}function ft(e,t,n,r){const o=mt(e,t),a=o.length<n?o.padEnd(n,S):o.substring(0,n),i=o.substring(n+1);e[t-1]=a+r+i}function dt(e,t,n,r,o){const a=mt(e,t),i=a.length<n?a.padEnd(n,S):a.substring(0,n),l=a.substring(r);e[t-1]=i+o+l}function mt(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function ht(t,n,r){for(const o of t.items){const t=o.item;if(t.value.type===e.InlineTable){const e=n.concat(t.key.value);r.add($t(e)),ht(t.value,e,r)}}}function pt(t,n=""){const r=ue(),o=new Set,a=new Set,i=new Set,l=new Set,s=new Set;let c=r,u=[];const f={tables:o,table_arrays:a,defined:i,implicit_tables:l,inline_tables:s};for(const n of t)switch(n.type){case e.Table:d(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.TableArray:m(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.KeyValue:h(n)}return r;function d(e){const t=e.key.item.value;try{gt(r,[],t,e.type,f)}catch(t){const r=t;throw new v(n,e.key.loc.start,r.message)}const a=$t(t);o.add(a),i.add(a),c=yt(r,t),u=t}function m(e){const t=e.key.item.value;try{gt(r,[],t,e.type,f)}catch(t){const r=t;throw new v(n,e.key.loc.start,r.message)}const o=$t(t);a.add(o),i.add(o),c=function(e,t){const n=vt(e,t.slice(0,-1)),r=ce(t);n[r]||(n[r]=[]);const o=ue();return n[ce(t)].push(o),o}(r,t),u=t}function h(t){const r=t.key.value;try{gt(c,u,r,t.type,f)}catch(e){const r=e;throw new v(n,t.key.loc.start,r.message)}if(r.length>1)for(let e=1;e<r.length;e++){const t=$t(u.concat(r.slice(0,e)));l.add(t),i.add(t)}let o;try{o=wt(t.value)}catch(e){const r=e;throw new v(n,t.value.loc.start,r.message)}if(t.value.type===e.InlineTable){const e=u.concat(r);s.add($t(e)),ht(t.value,e,s)}(r.length>1?yt(c,r.slice(0,-1)):c)[ce(r)]=o,i.add($t(u.concat(r)))}}function wt(t){switch(t.type){case e.InlineTable:const n=ue(),r=new Set,o=new Map;return t.items.forEach((({item:e})=>{const t=e.key.value,a=wt(e.value),i=$t(t);if(r.has(i))throw new Error(`Duplicate key "${i}" in inline table`);for(let e=1;e<t.length;e++){const n=$t(t.slice(0,e));if(r.has(n))throw new Error(`Key "${i}" conflicts with already defined key "${n}" in inline table`)}if(o.has(i)){const e=o.get(i);throw new Error(`Key "${i}" conflicts with already defined key "${e}" in inline table`)}r.add(i);for(let e=1;e<t.length;e++){const n=$t(t.slice(0,e));o.has(n)||o.set(n,i)}(t.length>1?yt(n,t.slice(0,-1)):n)[ce(t)]=a})),n;case e.InlineArray:return t.items.map((e=>wt(e.item)));case e.DateTime:case e.String:case e.Integer:case e.Float:case e.Boolean:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function gt(t,n,r,o,a){const i=n.length>0?$t(n):"",l=new Array(r.length);let s=i;for(let e=0;e<r.length;e++)s=s?s+"."+r[e]:r[e],l[e]=s;const c=l[r.length-1];if(o===e.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=l[e-1];if(a.inline_tables.has(t))throw new Error(`Invalid key, cannot extend an inline table at ${t}`)}if((o===e.Table||o===e.TableArray)&&a.inline_tables.has(c))throw new Error(`Invalid key, cannot extend an inline table at ${c}`);if(o===e.Table||o===e.TableArray)for(let e=1;e<r.length;e++){const t=l[e-1];if(a.inline_tables.has(t))throw new Error(`Invalid key, cannot extend an inline table at ${t}`)}if(o===e.KeyValue&&r.length>1)for(let e=1;e<r.length;e++){const t=l[e-1];if(a.table_arrays.has(t))throw new Error(`Invalid key, cannot traverse into an array of tables at ${t}`)}if((o===e.Table||o===e.TableArray)&&a.implicit_tables.has(c))throw new Error(`Invalid key, a table has already been defined implicitly named ${c}`);if(o===e.KeyValue&&a.implicit_tables.has(c))throw new Error(`Invalid key, a table has already been defined named ${c}`);if(o===e.KeyValue&&r.length>1)for(let e=1;e<=r.length;e++){const t=l[e-1];if(a.tables.has(t))throw new Error(`Invalid key, cannot add to an explicitly defined table ${t} using dotted keys`)}let u=0;for(const e of r){if(!pe(t,e))return;if(bt(t[e]))throw new Error(`Invalid key, a value has already been defined for ${l[u]}`);const n=l[u];if(Array.isArray(t[e])&&!a.table_arrays.has(n))throw new Error(`Invalid key, cannot add to a static array at ${n}`);const o=u++<r.length-1;t=Array.isArray(t[e])&&o?ce(t[e]):t[e]}const f=c;if(t&&o===e.Table&&a.defined.has(f))throw new Error(`Invalid key, a table has already been defined named ${f}`);if(t&&o===e.KeyValue&&1===r.length&&a.defined.has(f)&&!bt(t))throw new Error(`Invalid key, a table has already been defined named ${f}`);if(t&&o===e.TableArray&&!a.table_arrays.has(f))throw new Error(`Invalid key, cannot add an array of tables to a table at ${f}`)}function yt(e,t){const n=vt(e,t.slice(0,-1)),r=ce(t);return n[r]||(n[r]=ue()),n[r]}function vt(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=ue()),Array.isArray(e[t])?ce(e[t]):e[t])),e)}function bt(e){return"object"!=typeof e&&!de(e)}function $t(e){return e.join(".")}var St,Tt,It,kt;function Ct(e){return e.type===St.Remove}function Et(e,t,n=[]){return e===t||(o=t,de(r=e)&&de(o)&&r.toISOString()===o.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let r=[];const o=e.map(we),a=t.map(we);a.forEach(((i,l)=>{const s=l>=o.length;if(!s&&o[l]===i)return;const c=o.indexOf(i,l+1);if(!s&&c>-1){r.push({type:St.Move,path:n,from:c,to:l});const e=o.splice(c,1);return void o.splice(l,0,...e)}const u=!a.includes(o[l]);if(!s&&u)return ge(r,Et(e[l],t[l],n.concat(l))),void(o[l]=i);r.push({type:St.Add,path:n.concat(l)}),o.splice(l,0,i)}));for(let e=a.length;e<o.length;e++)r.push({type:St.Remove,path:n.concat(e)});return r}(e,t,n):me(e)&&me(t)?function(e,t,n=[]){let r=[];const o=Object.keys(e),a=o.map((t=>we(e[t]))),i=Object.keys(t),l=i.map((e=>we(t[e]))),s=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=o[a.indexOf(e)];return!i.includes(n)};return o.forEach(((o,c)=>{const u=n.concat(o);if(i.includes(o))ge(r,Et(e[o],t[o],u));else if(s(a[c],l)){const e=i[l.indexOf(a[c])];r.push({type:St.Rename,path:n,from:o,to:e})}else r.push({type:St.Remove,path:u})})),i.forEach(((e,t)=>{o.includes(e)||s(l[t],a)||r.push({type:St.Add,path:n.concat(e)})})),r}(e,t,n):[{type:St.Edit,path:n}];var r,o}function At(e,t){if(!t.length)return c(e)&&a(e.item)?e.item:e;if(a(e))return At(e.value,t);const n={};let i;if(d(e)&&e.items.some(((e,l)=>{try{let s=[];if(a(e))s=e.key.value;else if(r(e))s=e.key.item.value;else if(o(e)){s=e.key.item.value;const t=we(s);n[t]||(n[t]=0);const r=n[t]++;s=s.concat(r)}else c(e)&&a(e.item)?s=e.item.key.value:c(e)&&(s=[l]);return!(!s.length||!function(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}(s,t.slice(0,s.length)))&&(i=c(e)&&a(e.item)?t.length===s.length?e:At(e.item.value,t.slice(s.length)):At(e,t.slice(s.length)),!0)}catch(e){return!1}})),!i)throw new Error(`Could not find node at path ${t.join(".")}`);return i}function xt(e,t){try{return At(e,t)}catch(e){}}function _t(e,t){let n,r=t;for(;r.length&&!n;)r=r.slice(0,-1),n=xt(e,r);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}function Ut(e,t,n){return Dt(Q(e),t,Xe(n,Ge.autoDetectFormat(e))).tomlString}function Dt(t,i,l){const f=[...t],d=pt(f),h={type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:f},p=ot(i,Xe(Object.assign(Object.assign({},l),{inlineTableStart:void 0}),l)),w=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(Ct(n)){let r=t+1;for(;r<e.length;){const o=e[r];if(Ct(o)&&o.path[0]===n.path[0]&&o.path[1]>n.path[1]){e.splice(r,1),e.splice(t,0,o),t=0;break}r++}}}return e}(Et(d,i));if(0===w.length)return{tomlString:ct(f,l),document:h};const g=function(e,t,i,l){return i.forEach((i=>{if(function(e){return e.type===St.Add}(i)){const f=At(t,i.path),d=i.path.slice(0,-1);let m,h=ce(i.path),p=o(f);if(fe(h)&&!d.some(fe)){const t=xt(e,d.concat(0));t&&o(t)&&(p=!0)}if(r(f))m=e;else if(p){m=e;const t=e,n=xt(t,d.concat(h-1)),r=xt(t,d.concat(h));h=r?t.items.indexOf(r):n?t.items.indexOf(n)+1:t.items.length}else m=_t(e,i.path),a(m)&&(m=m.value);if(o(m)||s(m)||n(m)){if(s(m)){const e=He(m);c(f)&&(f.comma=e)}if(void 0!==l.inlineTableStart&&l.inlineTableStart>0&&n(m)&&r(f)){const t=Ft(f,e,l);ke(e,m,f,h);for(const n of t)ke(e,e,n,void 0)}else ke(e,m,f,h)}else if(u(m)){const t=Ye(m);if(a(f)){const n=We(f);n.comma=t,ke(e,m,n)}else ke(e,m,f)}else if(void 0!==l.inlineTableStart&&l.inlineTableStart>0&&a(f)&&u(f.value)&&r(m)){nt([...m.key.item.value,...f.key.value])<l.inlineTableStart?function(e,t,n,r){const o=t.key.item.value,i=[...o,...e.key.value],l=Fe(i);if(u(e.value))for(const t of e.value.items)c(t)&&a(t.item)&&ke(n,l,t.item,void 0);ke(n,n,l,void 0),tt(t);const s=Ft(l,n,r);for(const e of s)ke(n,n,e,void 0)}(f,m,e,l):ke(e,m,f)}else if(0===l.inlineTableStart&&a(f)&&u(f.value)&&n(m))ke(e,m,f,void 0,!0);else{let t=f;c(f)&&(r(m)||n(m))&&(t=f.item),ke(e,m,t)}}else if(function(e){return e.type===St.Edit}(i)){let n,r=At(e,i.path),o=At(t,i.path);if(a(r)&&a(o))Ot(r.value,o.value),n=r,r=r.value,o=o.value;else if(a(r)&&c(o)&&a(o.item))n=r,r=r.value,o=o.item.value;else if(c(r)&&a(o))n=r,r=r.item;else if(c(r)&&c(o)&&a(r.item)&&a(o.item))Ot(r.item.value,o.item.value),n=r.item,r=r.item.value,o=o.item.value;else if(n=_t(e,i.path),a(n)){const t=i.path.slice(0,-1),r=At(e,t);a(r)&&s(r.value)&&(n=r.value)}Ie(e,n,r,o)}else if(Ct(i)){let t=_t(e,i.path);a(t)&&(t=t.value);const n=At(e,i.path);Ee(e,t,n)}else if(function(e){return e.type===St.Move}(i)){let t=At(e,i.path);m(t)&&(t=t.item),a(t)&&(t=t.value);const n=t.items[i.from];Ee(e,t,n),ke(e,t,n,i.to)}else if(function(e){return e.type===St.Rename}(i)){let n=At(e,i.path.concat(i.from)),r=At(t,i.path.concat(i.to));m(n)&&(n=n.item),m(r)&&(r=r.item),Ie(e,n,n.key,r.key)}})),_e(e),e}(h,p,w,l);return{tomlString:ct(g.items,l),document:g}}function Ot(e,t){if(i(e)&&i(t)&&ye(e.raw)){const n=je(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(l(e)&&l(t)){const n=e.raw,r=t.value,o=N.createDateWithOriginalFormat(r,n);t.value=o,t.raw=o.toISOString();0!==t.raw.length-n.length&&(t.loc.end.column=t.loc.start.column+t.raw.length)}if(s(e)&&s(t)){const n=He(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=Ye(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function Ft(e,t,n){const r=[],o=(e,r)=>{var i;for(let l=e.items.length-1;l>=0;l--){const s=e.items[l];if(a(s)&&u(s.value)){const u=[...e.key.item.value,...s.key.value];if(nt(u)<(null!==(i=n.inlineTableStart)&&void 0!==i?i:1)&&0!==n.inlineTableStart){const n=Fe(u);for(const e of s.value.items)c(e)&&a(e.item)&&ke(t,n,e.item,void 0);e.items.splice(l,1),tt(e),r.push(n),o(n,r)}}}};return o(e,r),r}function Lt(e,t,n,r){if("a"===n&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?r:"a"===n?r.call(e):r?r.value:t.get(e)}function Mt(e,t,n,r,o){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?o.call(e,n):o?o.value=n:t.set(e,n),n}function Kt(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(St||(St={})),"function"==typeof SuppressedError&&SuppressedError;class Nt{constructor(e){Tt.set(this,void 0),It.set(this,void 0),kt.set(this,void 0),Mt(this,It,e,"f"),Mt(this,Tt,Array.from(Q(e)),"f"),Mt(this,kt,Ge.autoDetectFormat(e),"f")}get toTomlString(){return Lt(this,It,"f")}get toJsObject(){return jt(pt(Lt(this,Tt,"f")))}get ast(){return Lt(this,Tt,"f")}patch(e,t){const n=Xe(t,Lt(this,kt,"f")),{tomlString:r,document:o}=Dt(Lt(this,Tt,"f"),e,n);Mt(this,Tt,o.items,"f"),Mt(this,It,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(Lt(this,kt,"f").newLine),n=Je(e),r=e.split(n);let o=0;for(;o<t.length&&o<r.length&&t[o]===r[o];)o++;let a=0;if(o<t.length&&o<r.length){const e=t[o],n=r[o];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){a=t;break}}let i=o+1;const{truncatedAst:l,lastEndPosition:s}=function(e,t,n){const r={line:t,column:n},o=[];let a=null;for(const t of e){const e=Kt(t.loc.end,r)<0,n=Kt(t.loc.start,r)<0;if(!e){if(n&&!e)break;break}o.push(t),a=t.loc.end}return{truncatedAst:o,lastEndPosition:a}}(Lt(this,Tt,"f"),i,a),c=s?s.line:1,u=s?s.column+1:0,f=r.slice(c-1);f.length>0&&u>0&&(f[0]=f[0].substring(u));const d=f.join(Lt(this,kt,"f").newLine);Mt(this,Tt,Array.from(function*(e,t){for(const t of e)yield t;const n=new L(E(t));for(;!n.next().done;){const e=le(n,t);for(const t of e)yield t}}(l,d)),"f"),Mt(this,It,e,"f"),Mt(this,kt,Ge.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(Mt(this,Tt,Array.from(Q(e)),"f"),Mt(this,It,e,"f"),Mt(this,kt,Ge.autoDetectFormat(e),"f"))}}function jt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(jt);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=jt(r);return t}return e}function Wt(e){return pt(Q(e),e)}function Bt(e,t){const n=Xe(t,Ge.default());return ct(ot(e,n).items,n)}Tt=new WeakMap,It=new WeakMap,kt=new WeakMap;export{Nt as TomlDocument,Ge as TomlFormat,Wt as parse,Ut as patch,Bt as stringify};
1
+ //! @decimalturn/toml-patch v1.0.5 - 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 a(t){return t.type===e.DateTime}function s(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)||s(e)}function d(t){return function(t){return t.type===e.TableKey}(t)||function(t){return t.type===e.TableArrayKey}(t)||c(t)}function h(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:w(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 w(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 y(e){return{line:e.line,column:e.column}}function g(e){return{start:y(e.start),end:y(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{constructor(e,t,n){let o=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){const n=function(e,t){const n=w(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='"',T="'",$=" ",k=/[\w,\d,",',+,\-,_]/,S=10,I=13,E=127;function*A(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!==I&&c!==S)throw new v(e,p(r,o),`Control char 0x${c.toString(16).toUpperCase().padStart(2,"0")} not allowed`);if(c===I&&(o+1>=n||e.charCodeAt(o+1)!==S))throw new v(e,p(r,o),"Standalone CR; must be CRLF or LF");if(32===c||9===c||c===I);else if(c===S)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=C(e,o,T)||C(e,o,b);t?yield a(t):yield s()}o++}function i(){const i=o;for(;o+1<n;){const t=e.charCodeAt(o+1);if(t===S||t===I)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 a(i){const a=o,s=i+i+i;for(o+=3;o<n;){if(C(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===I&&(o+1>=n||e.charCodeAt(o+1)!==S))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!==S&&t!==I){const n=i===b?"multiline basic strings":"multiline literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let a="";0===t?a="Null":t===E&&(a="DEL");const s=a?`${a} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),s)}t===S&&r.push(o),o++}if(o>=n){if(i===b){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 ${s} (possible escape issue)`)}throw new v(e,p(r,o),`Unterminated multiline ${s}`)}return{type:t.Literal,raw:e.slice(a,o+1),loc:l(a,o+1)}}function s(){const i=e[o];if(!k.test(i))throw new v(e,p(r,o),`Unexpected char "${i}"`);const a=o;let s=i===b,c=i===T;for(;o<n&&!(o+1>=n);){const t=e.charCodeAt(o+1);if(!(s||c||32!==t&&9!==t&&t!==S&&t!==I&&44!==t&&46!==t&&93!==t&&125!==t&&61!==t&&35!==t))break;if(o++,s||c){const t=e.charCodeAt(o);if((t<=31||t===E)&&9!==t){const n=s?"basic strings":"literal strings",l=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let i="";t===S?i="Newline":t===I?i="Carriage return":0===t?i="Null":t===E&&(i="DEL");const a=i?`${i} (${l}) not allowed in ${n}`:`Control char ${l} not allowed in ${n}`;throw new v(e,p(r,o),a)}}const l=e[o];if(l===b&&(s=!s),l!==T||s||(c=!c),o+1>=n)break;if(s&&"\\"===l){const t=e[o+1];t!==b&&"\\"!==t||o++}}if(s||c)throw new v(e,p(r,a),`Expected close of string with ${s?b:T}`);return{type:t.Literal,raw:e.slice(a,o+1),loc:l(a,o+1)}}}function C(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 _(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 D(e){return e.startsWith("'''")?L(e.slice(3,e.length-3)):e.startsWith(T)?e.slice(1,e.length-1):e.startsWith('"""')?F(L(e.slice(3,e.length-3)),!0):e.startsWith(b)?F(e.slice(1,e.length-1),!1):e}function F(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||!_(e[l+1])||!_(e[l+2])||!_(e[l+3])||!_(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(!_(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||!_(e[l+1])||!_(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 K{constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){var e;if(this.done)return M();const t=this.peeked||this.iterator.next();return this.index+=1,this.value=t.value,this.done=null!==(e=t.done)&&void 0!==e&&e,this.peeked=null,t}peek(){return this.done?M():(this.peeked||(this.peeked=this.iterator.next()),this.peeked)}[Symbol.iterator](){return this}}const U=Object.freeze({value:void 0,done:!0});function M(){return U}function N(e){return{year:String(e.getUTCFullYear()),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(".")){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 W(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 B{static createDateWithOriginalFormat(e,t){if(B.IS_DATE_ONLY.test(t)){if(0!==e.getUTCHours()||0!==e.getUTCMinutes()||0!==e.getUTCSeconds()||0!==e.getUTCMilliseconds()){if(e instanceof z)return e;let t=e.toISOString().replace("Z","");return t=t.replace(/\.000$/,""),new q(t,!1)}const t=e.toISOString().split("T")[0];return new Z(t)}if(B.IS_TIME_ONLY.test(t)){if(e instanceof V)return e;{const n=N(e),o=j(n.ms,t);return new V(`${n.hours}:${n.minutes}:${n.seconds}${o}`,t)}}if(B.IS_LOCAL_DATETIME_T.test(t)){const n=N(e),o=j(n.ms,t);return new q(`${n.year}-${n.month}-${n.day}T${n.hours}:${n.minutes}:${n.seconds}${o}`,!1,t)}if(B.IS_LOCAL_DATETIME_SPACE.test(t)){const n=N(e),o=j(n.ms,t);return new q(`${n.year}-${n.month}-${n.day} ${n.hours}:${n.minutes}:${n.seconds}${o}`,!0,t)}if(B.IS_OFFSET_DATETIME_T.test(t)||B.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=B.IS_OFFSET_DATETIME_SPACE.test(t),l=N(new Date(e.getTime()+6e4*W(o))),i=r?" ":"T",a=j(l.ms,t,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),s=`${l.year}-${l.month}-${l.day}${i}${l.hours}:${l.minutes}:${l.seconds}${a}${o}`;return new z(s,r)}return e}}B.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,B.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,B.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,B.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,B.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,B.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,B.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,B.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class Z extends Date{constructor(e){super(e)}toISOString(){const e=N(this);return`${e.year}-${e.month}-${e.day}`}}class V extends Date{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=N(this);return`${e.hours}:${e.minutes}:${e.seconds}${j(e.ms,this.originalFormat)}`}}class q extends Date{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=!1,this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){const e=N(this),t=this.useSpaceSeparator?" ":"T";return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${j(e.ms,this.originalFormat)}`}}class z extends Date{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=!1,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=N(new Date(this.getTime()+6e4*W(this.originalOffset))),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}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const R=B,P="true",H=/e/i,J=/_/g,Y=/^[+-]?inf$/,G=/^[+-]?nan$/,Q=/^[+-]?0x/i;function X(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||95===e||45===e}const ee=/^[+-]?0o/i,te=/^[+-]?0b/i;function ne(e,t,n){for(let o=0;o<e.length;o++)if(!X(e.charCodeAt(o)))throw new v(t,{line:n.line,column:n.column+o},`Invalid bare key char '${e[o]}'`)}function oe(e,t,n){if(e.startsWith('"""')||e.startsWith("'''"))throw new v(t,n,"Multiline strings cannot be keys")}function re(e,t,n){try{return D(e)}catch(e){throw new v(t,n,e.message)}}function le(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 ie(e,t,n,o){const r=e.replace(J,"");if(/^[+-]?0\d/.test(r)&&!Q.test(e)&&!ee.test(e)&&!te.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 se(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 ce(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 ue(e,t,n,o,r,l,i){const a=o[0]+o[1].toUpperCase();if(new RegExp("^[+\\-]?"+a.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 s=new RegExp("^[+\\-]?"+o,"i"),c=e.replace(s,"");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,null!=i?i:`Invalid ${l.toLowerCase()} digits`);if(/^[+-]/.test(e))throw new v(t,n,`${l} numbers cannot have a sign prefix`)}function*fe(e){const t=new K(A(e));for(;!t.next().done;){const n=ve(t,e);for(const e of n)yield e}}function me(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 a=n.value.raw;oe(a,o,n.value.loc.start);let s;for(a.startsWith('"')||a.startsWith("'")||ne(a,o,n.value.loc.start),s=[re(n.value.raw,o,n.value.loc.start)],i.item={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:s};!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("'")||ne(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(D(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=ve(n,o);for(let t=0;t<e.length;t++)c.push(e[t])}return{type:l?e.Table:e.TableArray,loc:{start:y(i.loc.start),end:c.length?y(c[c.length-1].loc.end):y(i.loc.end)},key:i,items:c}}function he(t,n){const o=re(t.value.raw,n,t.value.loc.start);return{type:e.String,loc:t.value.loc,raw:t.value.raw,value:o}}function pe(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===P}}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 a=parseInt(o,10);if(a<0||a>23)throw new v(t,n,`Offset "${e}": hour must be 00-23`);const s=parseInt(i,10);if(s<0||s>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 a=/^(\d+)-(\d+)-(\d+)/,s=e.match(a);if(s){const[,,o,r]=s;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;se(o,r,l,e,t,n)}const f=/^(\d+):(\d+)(?::(\d+))?/,m=e.match(f);if(m&&!s){const[,o,r,l]=m;se(o,r,l,e,t,n)}const d=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),h=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(d){const[,o,r,l,i,a,s]=d,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}`);ce(i,a,s,e,t,n)}else if(h){const[,o,r,l]=h;ce(o,r,l,e,t,n)}}(i,o,l.start),R.IS_FULL_DATE.test(i))r=R.IS_DATE_ONLY.test(i)?new Z(i):R.IS_LOCAL_DATETIME_T.test(i)?new q(i,!1):R.IS_LOCAL_DATETIME_SPACE.test(i)?new q(i,!0):R.IS_OFFSET_DATETIME_T.test(i)?new z(i,!1):R.IS_OFFSET_DATETIME_SPACE.test(i)?new z(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(Y.test(i))r=i.startsWith("-")?-1/0:1/0;else if(G.test(i))r=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(le(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`);ie(i,o,l.start,"the integer part of a float"),r=Number(i.replace(J,""))}else{const e=l.start;{if(H.test(i)&&!Q.test(i))throw new v(o,l.start,`Float "${i}": dot after exponent`);const e=i;ie(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");le(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}"`);le(e,o,n.value.loc.start,!1),ae(e,i,o,n.value.loc.start)}r=Number(i.replace(J,""))}if(Number.isNaN(r)&&!G.test(i))throw new v(o,l.start,`Invalid float "${i}"`);return{type:e.Float,loc:l,raw:i,value:r}}function ge(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");ie(o,n,r.start,"decimal integers"),le(o,n,r.start);let l=10;Q.test(o)?(l=16,ue(o,n,r.start,"0x",/^[0-9a-fA-F]+$/,"Hexadecimal")):ee.test(o)?(l=8,ue(o,n,r.start,"0o",/^[0-7]+$/,"Octal","Invalid octal digits (must be 0-7)")):te.test(o)&&(l=2,ue(o,n,r.start,"0b",/^[01]+$/,"Binary","Invalid binary digits (must be 0 or 1)"));const i=parseInt(o.replace(J,"").replace(ee,"").replace(te,""),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 ve(n,o){if(n.value.type===t.Comment)return[me(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 ':'");oe(r,o,n.value.loc.start);r.startsWith('"')||r.startsWith("'")||ne(r,o,n.value.loc.start);let l;l=[re(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;oe(e,o,n.value.loc.start);e.startsWith('"')||e.startsWith("'")||ne(e,o,n.value.loc.start),i.loc.end=n.value.loc.end,i.raw+=`.${n.value.raw}`,i.value.push(re(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 a=n.value.loc.start.column,s=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!==s)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=be(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:y(i.loc.start),end:y(u.loc.end)},equals:a},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 be(n,o){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===b||e[0]===T?[he(n,o)]:e===P||"false"===e?[pe(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||Y.test(e)||G.test(e)||H.test(e)&&!Q.test(e)?[ye(n,o)]:[ge(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(me(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 a=ve(n,o),s=a[0];if(s.type===e.KeyValue){r.items.push({type:e.InlineItem,loc:g(s.loc),item:s,comma:!1});for(let e=1;e<a.length;e++)l.push(a[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(me(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=be(n,o),a=i[0];r.items.push({type:e.InlineItem,loc:g(a.loc),item:a,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 $e(){return Object.create(null)}function ke(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function Se(e){return"[object Date]"===Object.prototype.toString.call(e)}function Ie(e){return e&&"object"==typeof e&&!Se(e)&&!Array.isArray(e)}function Ee(e){return null!=e&&"function"==typeof e[Symbol.iterator]}function Ae(e,t){return t in e}function Ce(e){if(Ie(e)){return`{${Object.keys(e).sort().map(t=>`${JSON.stringify(t)}:${Ce(e[t])}`).join(",")}}`}return Array.isArray(e)?`[${e.map(Ce).join(",")}]`:JSON.stringify(e)}function xe(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]}function _e(e){return e.startsWith('"""')||e.startsWith("'''")}const Oe=new WeakSet,De=new WeakMap,Fe=e=>(De.has(e)||De.set(e,new WeakMap),De.get(e)),Le=new WeakMap,Ke=e=>(Le.has(e)||Le.set(e,new WeakMap),Le.get(e));function Ue(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(d(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}Ve(o,{lines:n.loc.start.line-o.loc.start.line,columns:n.loc.start.column-o.loc.start.column});const r=h(n.loc),i=h(o.loc);qe({lines:i.lines-r.lines,columns:i.columns-r.columns},Ke(e),o,n),Oe.add(e)}function Me(e,t,i,a,d){if(!m(t))throw new Error(`Unsupported parent type "${t.type}" for insert`);let p,w;a=null!=a&&"number"==typeof a?a:t.items.length,s(t)||u(t)?({shift:p,offset:w}=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 a=s(e)&&function(e){if(!e.items.length)return!1;return h(e.loc).lines>e.items.length}(e),u=r&&!0===t.comma;return Ne(e,t,n,{useNewLine:a,hasCommaHandling:!0,isLastElement:r,hasSeparatingCommaBefore:l,hasSeparatingCommaAfter:i,hasTrailingComma:u})}(t,i,a)):d&&n(t)?({shift:p,offset:w}=function(e,t,n){const o=Ne(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),o}(t,i,a)):({shift:p,offset:w}=function(e,t,i){if(a=t,!(l(a)||o(a)||r(a)||f(a)))throw new Error(`Incompatible child type "${t.type}"`);var a;const s=e.items[i-1],c=n(e)&&!e.items.length;e.items.splice(i,0,t);const u=s?{line:s.loc.end.line,column:f(s)?e.loc.start.column:s.loc.start.column}:y(e.loc.start),m=o(t)||r(t);let d=0;c||(d=m?2:1);u.line+=d;const p={lines:u.line-t.loc.start.line,columns:u.column-t.loc.start.column},w=h(t.loc),g={lines:w.lines+(d-1),columns:w.columns};return{shift:p,offset:g}}(t,i,a)),Ve(i,p);const g=t.items[a-1],v=g&&Ke(e).get(g);v&&(w.lines+=v.lines,w.columns+=v.columns,Ke(e).delete(g));Ke(e).set(i,w),Oe.add(e)}function Ne(e,t,n,o={}){const{useNewLine:r=!1,skipCommaSpace:l=2,skipBracketSpace:i=1,hasCommaHandling:a=!1,isLastElement:s=!1,hasSeparatingCommaBefore:c=!1,hasSeparatingCommaAfter:u=!1,hasTrailingComma:m=!1}=o,d=n>0?e.items[n-1]:void 0,p=d?{line:d.loc.end.line,column:r?f(d)?e.loc.start.column:d.loc.start.column:d.loc.end.column}:y(e.loc.start);let w=0;if(r)w=1;else{const e=c||!a&&!!d;e&&a?p.column+=l:(e||a&&!d)&&(p.column+=i)}p.line+=w;const g={lines:p.line-t.loc.start.line,columns:p.column-t.loc.start.column},v=h(t.loc);if(!a){return{shift:g,offset:{lines:v.lines+(w-1),columns:v.columns}}}let b=0;c&&m&&!u&&s&&(b=-1);return{shift:g,offset:{lines:v.lines+(w-1),columns:v.columns+(c||u?l:0)+(m?1+b:0)}}}function je(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=>d(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 a=t.items[l+1];t.items.splice(l,1);let s=h(n.loc);a&&f(a)&&a.loc.start.line===n.loc.end.line&&(s=h({start:n.loc.start,end:a.loc.end}),a=t.items[l+1],t.items.splice(l,1));const u=i&&c(i)||a&&c(a),p=i&&i.loc.end.line===n.loc.start.line,w=a&&a.loc.start.line===n.loc.end.line,y=u&&(p||w),g={lines:-(s.lines-(y?1:0)),columns:y?-s.columns:0};if(void 0===i&&void 0===a&&(g.lines=0,g.columns=0),u&&p&&(g.columns-=2),u&&!i&&a&&(g.columns-=2),u&&i&&!a){const e=n.comma;i.comma=!!e}let v,b;i?(v=i,b=Ke(e)):(o(t)||r(t))&&"key"in t?(v=t.key,b=Ke(e)):(v=t,b=Fe(e));const T=Ke(e),$=b.get(v);$&&(g.lines+=$.lines,g.columns+=$.columns);const k=T.get(n);k&&(g.lines+=k.lines,g.columns+=k.columns),b.set(v,g),Oe.add(e)}function We(e,t,n=!0){if(!n)return;if(!t.items.length)return;qe({lines:0,columns:1},Fe(e),t);const o=Te(t.items);qe({lines:0,columns:1},Ke(e),o),Oe.add(e)}function Be(e,t,n=!1){if(!n)return;if(!t.items.length)return;const o=Te(t.items);o.comma=!0,qe({lines:0,columns:1},Ke(e),o),Oe.add(e)}function Ze(t){if(!Oe.has(t))return;const n=Fe(t),o=Ke(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 a(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 s(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;a(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e),i(e);break}case e.Table:{const e=n;a(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e),i(e);break}case e.TableArray:{const e=n;a(e),t(e.key);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e),i(e);break}case e.TableKey:{const e=n;a(e),t(e.item),s(e);break}case e.TableArrayKey:{const e=n;a(e),t(e.item),s(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),a(e),t(e.key),t(e.value),s(e);break}case e.InlineArray:{const e=n;a(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e);break}case e.InlineTable:{const e=n;a(e);for(let n=0;n<e.items.length;n++)t(e.items[n]);s(e);break}case e.InlineItem:{const e=n;a(e),t(e.item),s(e);break}case e.Key:case e.String:case e.Integer:case e.Float:case e.Boolean:case e.DateTime:case e.Comment:a(n),s(n);break;default:throw new Error(`Unrecognized node type "${n.type}"`)}}(t),Oe.delete(t),De.delete(t),Le.delete(t)}function Ve(t,n,o={}){const{lines:r,columns:l}=n;if(0===r&&0===l)return t;const{first_line_only:i=!1}=o,a=t.loc.start.line,s=t.type;if(s===e.Key||s===e.String||s===e.Integer||s===e.Float||s===e.Boolean||s===e.DateTime||s===e.Comment)return i&&t.loc.start.line!==a||(t.loc.start.column+=l,t.loc.end.column+=l),t.loc.start.line+=r,t.loc.end.line+=r,t;if(s===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!==a||(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!==a||(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!==a||(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!==a||(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)}Ee(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 qe(e,t,n,o){const r=t.get(o||n);r&&(e.lines+=r.lines,e.columns+=r.columns),t.set(n,e)}function ze(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Re(t){const n=function(t){const n=Ye(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:g(n.loc),key:n,items:[]}}function Pe(t){const n=function(t){const n=Ye(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:g(n.loc),key:n,items:[]}}function He(t,n){const o=function(t){const n=Ye(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 Ve(n,{lines:0,columns:r+3-n.loc.start.column},{first_line_only:!0}),{type:e.KeyValue,loc:{start:y(o.loc.start),end:y(n.loc.end)},key:o,equals:l,value:n}}const Je=/^[\w-]+$/;function Ye(e){return e.map(e=>Je.test(e)?e:JSON.stringify(e)).join(".")}function Ge(t,n){let o,r;if(n&&_e(n)){let e=n.startsWith("'''");e&&t.includes("'''")&&(e=!1);const r=e?"'''":'"""',l=n.includes("\r\n")?"\r\n":"\n",i=n.startsWith(`${r}${l}`)||(n.startsWith("'''\n")||n.startsWith("'''\r\n"))&&!e;let a;a=e?t:t.replace(/\\/g,"\\\\").replace(/\x08/g,"\\b").replace(/\f/g,"\\f").replace(/\t/g,"\\t").replace(/[\x00-\x07\x0B\x0E-\x1F\x7F]/g,e=>"\\u"+e.charCodeAt(0).toString(16).padStart(4,"0").toUpperCase()).replace(/"""/g,'""\\"'),o=i?`${r}${l}${a}${r}`:`${r}${a}${r}`}else o=JSON.stringify(t);if(o.includes("\r\n")||o.includes("\n")&&!o.includes("\r\n")){const e=o.includes("\r\n")?"\r\n":"\n",t=(o.match(new RegExp("\r\n"===e?"\\r\\n":"\\n","g"))||[]).length;r=t>0?{line:1+t,column:3}:{line:1,column:o.length}}else r={line:1,column:o.length};return{type:e.String,loc:{start:{line:1,column:0},end:r},raw:o,value:t}}function Qe(t){return{type:e.InlineItem,loc:g(t.loc),item:t,comma:!1}}const Xe=!1,et=!0,tt=!1,nt=!1;function ot(e,t){if(!e||"object"!=typeof e)return null;if(("InlineArray"===e.type||"InlineTable"===e.type)&&e.loc){const n=function(e,t){var n;if(!e||!e.start||!e.end)return null;const o=t.split(/\r?\n/),r=e.start.line-1,l=e.end.line-1,i=e.start.column,a=e.end.column;let s="";if(r===l)s=(null===(n=o[r])||void 0===n?void 0:n.substring(i,a+1))||"";else{o[r]&&(s+=o[r].substring(i));for(let e=r+1;e<l;e++)s+="\n"+(o[e]||"");o[l]&&(s+="\n"+o[l].substring(0,a+1))}const c=s.match(/^\[(\s*)/),u=s.match(/^\{(\s*)/);if(c)return c[1].length>0;if(u)return u[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=ot(n,t);if(null!==e)return e;if(n.item){const e=ot(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const o=ot(e[n],t);if(null!==o)return o}return null}function rt(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return lt(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return lt(e.items);if("KeyValue"===e.type&&e.value)return rt(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=rt(t);if(null!==e)return e}return null}function lt(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 it(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function at(e,t){var n,o,r,l,i,a;if(e){if(e instanceof st)return e;{const s=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,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},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 st(null!==(n=s.newLine)&&void 0!==n?n:t.newLine,null!==(o=s.trailingNewline)&&void 0!==o?o:t.trailingNewline,null!==(r=s.trailingComma)&&void 0!==r?r:t.trailingComma,null!==(l=s.bracketSpacing)&&void 0!==l?l:t.bracketSpacing,void 0!==s.inlineTableStart?s.inlineTableStart:t.inlineTableStart,null!==(i=s.truncateZeroTimeInDates)&&void 0!==i?i:t.truncateZeroTimeInDates,null!==(a=s.useTabsForIndentation)&&void 0!==a?a:t.useTabsForIndentation)}}return t}class st{constructor(e,t,n,o,r,l,i){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:Xe,this.bracketSpacing=null!=o?o:et,this.inlineTableStart=null!=r?r:1,this.truncateZeroTimeInDates=null!=l?l:tt,this.useTabsForIndentation=null!=i?i:nt}static default(){return new st("\n",1,Xe,et,1,tt,nt)}static autoDetectFormat(e){const t=st.default();t.newLine=it(e),t.trailingNewline=function(e,t){let n=0,o=e.length;for(;o>=t.length&&e.substring(o-t.length,o)===t;)n++,o-=t.length;return n}(e,t.newLine);try{const n=fe(e),o=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=rt(e);if(null!==t)return t}return Xe}(o),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=ot(t,e);if(null!==n)return n}return et}(e,o)}catch(e){t.trailingComma=Xe,t.bracketSpacing=et}return t.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}(e),t.inlineTableStart=1,t.truncateZeroTimeInDates=tt,t}}function ct(e){if(!s(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function ut(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function ft(e,t){if(0===t.inlineTableStart)return e;return e.items.filter(e=>{if(!l(e))return!1;const n=u(e.value),o=s(e.value)&&e.value.items.length&&u(e.value.items[0].item);if(n||o){const n=ht(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1}).forEach(t=>{je(e,e,t),u(t.value)?Me(e,e,mt(t)):function(e){const t=ze();for(const n of e.value.items){const o=Pe(e.key.value);Me(t,t,o);for(const e of n.item.items)Me(t,o,e.item)}return Ze(t),t.items}(t).forEach(t=>{Me(e,e,t)})}),Ze(e),e}function mt(e){const t=Re(e.key.value);for(const n of e.value.items)Me(t,t,n.item);return Ze(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 ht(e){return Math.max(0,e.length-1)}function pt(e,t,n){var o;for(let r=e.items.length-1;r>=0;r--){const i=e.items[r];if(l(i)&&u(i.value)){const r=[...e.key.item.value,...i.key.value];if(ht(r)<(null!==(o=n.inlineTableStart)&&void 0!==o?o:1)){const o=Re(r);for(const e of i.value.items)Me(o,o,e.item);je(e,e,i),dt(e),t.push(o),pt(o,t,n)}}}}function wt(e,t=st.default()){e=vt(e);const n=ze();for(const o of yt(e,t))Me(n,n,o);return Ze(n),ft(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(ht(o.key.value)<t.inlineTableStart){const r=mt(o);je(e,e,o),Me(e,e,r),pt(r,n,t)}}else"Table"===o.type&&pt(o,n,t);for(const t of n)Me(e,e,t);Ze(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)),Ve(o,{lines:t,columns:0}),n=o.loc.end.line;return e}(n)}function*yt(e,t){for(const n of Object.keys(e))yield He([n],gt(e[n],t))}function gt(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?Ge(t):ke(t)?function(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}}(t):function(e){return"number"==typeof e&&(!ke(e)||!isFinite(e)||Object.is(e,-0))}(t)?function(t){let n;return n=t===1/0?"inf":t===-1/0?"-inf":Number.isNaN(t)?"nan":Object.is(t,-0)?"-0.0":t.toString(),{type:e.Float,loc:{start:{line:1,column:0},end:{line:1,column:n.length}},raw:n,value:t}}(t):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):Se(t)?function(t,n=!1){n&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new Z(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){Me(o,o,Qe(gt(e,n)))}return We(o,o,n.bracketSpacing),Be(o,o,n.trailingComma),Ze(o),o}(t,n):function(t,n){if(t=vt(t),!Ie(t))return gt(t,n);const o={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]};for(const e of yt(t,n)){Me(o,o,Qe(e))}return We(o,o,n.bracketSpacing),Be(o,o,n.trailingComma),Ze(o),o}(t,n)}function vt(e){return e?Se(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const bt=/(\r\n|\n)/g;function Tt(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;kt(o,n.line,n.column,"["),kt(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;St(o,n.line,n.column,n.column+2,"[["),St(o,l.line,l.column-2,l.column,"]]"),r(e.item);break}case e.KeyValue:{const e=t,n=e.loc.start.line;kt(o,n,e.equals,"="),r(e.key),r(e.value);break}case e.Key:case e.String:case e.Integer:case e.Float:$t(o,t.loc,t.raw);break;case e.Boolean:$t(o,t.loc,t.value.toString());break;case e.DateTime:$t(o,t.loc,t.raw);break;case e.InlineArray:{const e=t,{start:n,end:l}=e.loc;kt(o,n.line,n.column,"["),kt(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;kt(o,n.line,n.column,"{"),kt(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;kt(o,t.line,t.column,",")}break}case e.Comment:$t(o,t.loc,t.raw);break;default:{const e=t.type;throw new Error(`toTOML: Unrecognized node type: ${String(e)}`)}}}if(Ee(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 $t(e,t,n){if(t.start.line===t.end.line){const o=It(e,t.start.line),r=o.substring(0,t.start.column),l=r.length<t.start.column?r.padEnd(t.start.column,$):r,i=o.substring(t.end.column);return void(e[t.start.line-1]=l+n+i)}const o=n.split(bt).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=It(e,n),l=n===t.start.line,i=n===t.end.line;let a="";if(l){const e=r.substring(0,t.start.column);a=e.length<t.start.column?e.padEnd(t.start.column,$):e}const s=i?r.substring(t.end.column):"";e[n-1]=a+o[n-t.start.line]+s}}function kt(e,t,n,o){const r=It(e,t),l=r.length<n?r.padEnd(n,$):r.substring(0,n),i=r.substring(n+1);e[t-1]=l+o+i}function St(e,t,n,o,r){const l=It(e,t),i=l.length<n?l.padEnd(n,$):l.substring(0,n),a=l.substring(o);e[t-1]=i+r+a}function It(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function Et(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(Ft(e)),Et(t.value,e,o)}}}function At(t,n=""){const o=$e(),r=new Set,l=new Set,i=new Set,a=new Set,s=new Set;let c=o,u=[];const f={tables:r,table_arrays:l,defined:i,implicit_tables:a,inline_tables:s};for(const n of t)switch(n.type){case e.Table:m(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.TableArray:d(n);for(const t of n.items)t.type===e.KeyValue&&h(t);break;case e.KeyValue:h(n)}return o;function m(e){const t=e.key.item.value;try{xt(o,[],t,e.type,f)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const l=Ft(t);r.add(l),i.add(l),c=_t(o,t),u=t}function d(e){const t=e.key.item.value;try{xt(o,[],t,e.type,f)}catch(t){const o=t;throw new v(n,e.key.loc.start,o.message)}const r=Ft(t);l.add(r),i.add(r),c=function(e,t){const n=Ot(e,t.slice(0,-1)),o=Te(t);n[o]||(n[o]=[]);const r=$e();return n[Te(t)].push(r),r}(o,t),u=t}function h(t){const o=t.key.value;try{xt(c,u,o,t.type,f)}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=Ft(u.concat(o.slice(0,e)));a.add(t),i.add(t)}let r;try{r=Ct(t.value)}catch(e){const o=e;throw new v(n,t.value.loc.start,o.message)}if(t.value.type===e.InlineTable){const e=u.concat(o);s.add(Ft(e)),Et(t.value,e,s)}(o.length>1?_t(c,o.slice(0,-1)):c)[Te(o)]=r,i.add(Ft(u.concat(o)))}}function Ct(t){switch(t.type){case e.InlineTable:const n=$e(),o=new Set,r=new Map;return t.items.forEach(({item:e})=>{const t=e.key.value,l=Ct(e.value),i=Ft(t);if(o.has(i))throw new Error(`Duplicate key "${i}" in inline table`);for(let e=1;e<t.length;e++){const n=Ft(t.slice(0,e));if(o.has(n))throw new Error(`Key "${i}" conflicts with key: "${n}"`)}if(r.has(i)){const e=r.get(i);throw new Error(`Key "${i}" conflicts with key: "${e}"`)}o.add(i);for(let e=1;e<t.length;e++){const n=Ft(t.slice(0,e));r.has(n)||r.set(n,i)}(t.length>1?_t(n,t.slice(0,-1)):n)[Te(t)]=l}),n;case e.InlineArray:return t.items.map(e=>Ct(e.item));case e.DateTime:case e.String:case e.Integer:case e.Float:case e.Boolean:return t.value;default:throw new Error(`Unrecognized value type "${t.type}"`)}}function xt(t,n,o,r,l){const i=n.length>0?Ft(n):"",a=new Array(o.length);let s=i;for(let e=0;e<o.length;e++)s=s?s+"."+o[e]:o[e],a[e]=s;const c=a[o.length-1];if(r===e.KeyValue&&o.length>1)for(let e=1;e<o.length;e++){const t=a[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=a[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=a[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=a[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(!Ae(t,e))return;if(Dt(t[e]))throw new Error(`Value already defined for ${a[u]}`);const n=a[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)&&!Dt(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 _t(e,t){const n=Ot(e,t.slice(0,-1)),o=Te(t);return n[o]||(n[o]=$e()),n[o]}function Ot(e,t){return t.reduce((e,t)=>(e[t]||(e[t]=$e()),Array.isArray(e[t])?Te(e[t]):e[t]),e)}function Dt(e){return"object"!=typeof e&&!Se(e)}function Ft(e){return e.join(".")}var Lt;function Kt(e){return e.type===Lt.Remove}function Ut(e,t,n=[]){return e===t||(r=t,Se(o=e)&&Se(r)&&o.toISOString()===r.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let o=[];const r=e.map(Ce),l=t.map(Ce);l.forEach((i,a)=>{const s=a>=r.length;if(!s&&r[a]===i)return;const c=r.indexOf(i,a+1);if(!s&&c>-1){o.push({type:Lt.Move,path:n,from:c,to:a});const e=r.splice(c,1);return void r.splice(a,0,...e)}const u=!l.includes(r[a]);if(!s&&u)return xe(o,Ut(e[a],t[a],n.concat(a))),void(r[a]=i);o.push({type:Lt.Add,path:n.concat(a)}),r.splice(a,0,i)});for(let e=l.length;e<r.length;e++)o.push({type:Lt.Remove,path:n.concat(e)});return o}(e,t,n):Ie(e)&&Ie(t)?function(e,t,n=[]){let o=[];const r=Object.keys(e),l=r.map(t=>Ce(e[t])),i=Object.keys(t),a=i.map(e=>Ce(t[e])),s=(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))xe(o,Ut(e[r],t[r],u));else if(s(l[c],a)){const e=i[a.indexOf(l[c])];o.push({type:Lt.Rename,path:n,from:r,to:e})}else o.push({type:Lt.Remove,path:u})}),i.forEach((e,t)=>{r.includes(e)||s(a[t],l)||o.push({type:Lt.Add,path:n.concat(e)})}),o}(e,t,n):[{type:Lt.Edit,path:n}];var o,r}function Mt(e,t){if(!t.length)return c(e)&&l(e.item)?e.item:e;if(l(e))return Mt(e.value,t);const n={};let i;if(m(e)&&e.items.some((e,a)=>{try{let s=[];if(l(e))s=e.key.value;else if(o(e))s=e.key.item.value;else if(r(e)){s=e.key.item.value;const t=Ce(s);n[t]||(n[t]=0);const o=n[t]++;s=s.concat(o)}else c(e)&&l(e.item)?s=e.item.key.value:c(e)&&(s=[a]);return!(!s.length||!function(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}(s,t.slice(0,s.length)))&&(i=c(e)&&l(e.item)?t.length===s.length?e:Mt(e.item.value,t.slice(s.length)):Mt(e,t.slice(s.length)),!0)}catch(e){return!1}}),!i)throw new Error(`Node not found at ${t.join(".")}`);return i}function Nt(e,t){try{return Mt(e,t)}catch(e){}}function jt(e,t){let n,o=t;for(;o.length&&!n;)o=o.slice(0,-1),n=Nt(e,o);if(!n)throw new Error(`Parent not found for ${t.join(".")}`);return n}function Wt(e,t,n){return Bt(fe(e),t,at(n,st.autoDetectFormat(e))).tomlString}function Bt(t,i,a){const f=[...t];let h=1,p=0;for(const e of f){const t=e.loc.end;(t.line>h||t.line===h&&t.column>p)&&(h=t.line,p=t.column)}const w=At(f),y={type:e.Document,loc:{start:{line:1,column:0},end:{line:h,column:p}},items:f},g=wt(i,at(Object.assign(Object.assign({},a),{inlineTableStart:void 0}),a)),v=function(e){for(let t=0;t<e.length;t++){const n=e[t];if(Kt(n)){let o=t+1;for(;o<e.length;){const r=e[o];if(Kt(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}(Ut(w,i));if(0===v.length)return{tomlString:Tt(f,a),document:y};const b=function(e,t,i,a){return i.forEach(i=>{if(function(e){return e.type===Lt.Add}(i)){const f=Mt(t,i.path),m=i.path.slice(0,-1);let d,h=Te(i.path),p=r(f);if(ke(h)&&!m.some(ke)){const t=Nt(e,m.concat(0));t&&r(t)&&(p=!0)}if(o(f))d=e;else if(p){d=e;const t=e,n=Nt(t,m.concat(h-1)),o=Nt(t,m.concat(h));h=o?t.items.indexOf(o):n?t.items.indexOf(n)+1:t.items.length}else d=jt(e,i.path),l(d)?d=d.value:c(d)&&l(d.item)&&(d=d.item.value);if(r(d)||s(d)||n(d)){if(s(d)){const e=ct(d);c(f)&&(f.comma=e)}if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&n(d)&&o(f)){const t=Vt(f,e,a);Me(e,d,f,h);for(const n of t)Me(e,e,n,void 0)}else Me(e,d,f,h)}else if(u(d)){const t=ut(d);if(l(f)){const n=Qe(f);n.comma=t,Me(e,d,n)}else Me(e,d,f)}else if(void 0!==a.inlineTableStart&&a.inlineTableStart>0&&l(f)&&u(f.value)&&o(d)){ht([...d.key.item.value,...f.key.value])<a.inlineTableStart?function(e,t,n,o){const r=t.key.item.value,i=[...r,...e.key.value],a=Re(i);if(u(e.value))for(const t of e.value.items)c(t)&&l(t.item)&&Me(n,a,t.item,void 0);Me(n,n,a,void 0),dt(t);const s=Vt(a,n,o);for(const e of s)Me(n,n,e,void 0)}(f,d,e,a):Me(e,d,f)}else if(0===a.inlineTableStart&&l(f)&&u(f.value)&&n(d))Me(e,d,f,void 0,!0);else{let t=f;c(f)&&(o(d)||n(d))&&(t=f.item),Me(e,d,t)}}else if(function(e){return e.type===Lt.Edit}(i)){let n,o=Mt(e,i.path),r=Mt(t,i.path);if(l(o)&&l(r))Zt(o.value,r.value),n=o,o=o.value,r=r.value;else if(l(o)&&c(r)&&l(r.item))n=o,o=o.value,r=r.item.value;else if(c(o)&&l(r))n=o,o=o.item;else if(c(o)&&c(r)&&l(o.item)&&l(r.item))Zt(o.item.value,r.item.value),n=o.item,o=o.item.value,r=r.item.value;else if(n=jt(e,i.path),l(n)){const t=i.path.slice(0,-1),o=Mt(e,t);l(o)&&s(o.value)&&(n=o.value)}Ue(e,n,o,r)}else if(Kt(i)){const t=Nt(e,i.path);if(t){let n=jt(e,i.path);l(n)&&(n=n.value),m(n)&&!n.items.includes(t)&&(n=e),je(e,n,t)}else{if(Nt(e,i.path.concat(0))){let t;for(;t=Nt(e,i.path.concat(0));)je(e,e,t)}else Mt(e,i.path)}}else if(function(e){return e.type===Lt.Move}(i)){let t=Nt(e,i.path);if(t){d(t)&&(t=t.item),l(t)&&(t=t.value);const n=t.items[i.from];je(e,t,n),Me(e,t,n,i.to)}else{const t=Mt(e,i.path.concat(i.from));je(e,e,t);const n=Nt(e,i.path.concat(i.to)),o=n?e.items.indexOf(n):e.items.length;Me(e,e,t,o)}}else if(function(e){return e.type===Lt.Rename}(i)){let n=Mt(e,i.path.concat(i.from)),o=Mt(t,i.path.concat(i.to));d(n)&&(n=n.item),d(o)&&(o=o.item),Ue(e,n,n.key,o.key)}}),Ze(e),e}(y,g,v,a);return{tomlString:Tt(b.items,a),document:b}}function Zt(e,t){if(i(e)&&i(t)&&_e(e.raw)){const n=Ge(t.value,e.raw);t.raw=n.raw,t.loc=n.loc}if(a(e)&&a(t)){const n=e.raw,o=t.value,r=B.createDateWithOriginalFormat(o,n);t.value=r,t.raw=r.toISOString();0!==t.raw.length-n.length&&(t.loc.end.column=t.loc.start.column+t.raw.length)}if(s(e)&&s(t)){const n=ct(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=ut(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function Vt(e,t,n){const o=[],r=(e,o)=>{var i;for(let a=e.items.length-1;a>=0;a--){const s=e.items[a];if(l(s)&&u(s.value)){const u=[...e.key.item.value,...s.key.value];if(ht(u)<(null!==(i=n.inlineTableStart)&&void 0!==i?i:1)&&0!==n.inlineTableStart){const n=Re(u);for(const e of s.value.items)c(e)&&l(e.item)&&Me(t,n,e.item,void 0);e.items.splice(a,1),dt(e),o.push(n),r(n,o)}}}};return r(e,o),o}function qt(e,t){return e.line!==t.line?e.line-t.line:e.column-t.column}!function(e){e.Add="Add",e.Edit="Edit",e.Remove="Remove",e.Move="Move",e.Rename="Rename"}(Lt||(Lt={}));class zt{constructor(e){this._currentTomlString=e,this._ast=Array.from(fe(e)),this._format=st.autoDetectFormat(e)}get toTomlString(){return this._currentTomlString}get toJsObject(){return Rt(At(this._ast))}get ast(){return this._ast}patch(e,t){const n=at(t,this._format),{tomlString:o,document:r}=Bt(this._ast,e,n);this._ast=r.items,this._currentTomlString=o}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(this._format.newLine),n=it(e),o=e.split(n);let r=0;for(;r<t.length&&r<o.length&&t[r]===o[r];)r++;let l=0;if(r<t.length&&r<o.length){const e=t[r],n=o[r];for(let t=0;t<Math.max(e.length,n.length);t++)if(e[t]!==n[t]){l=t;break}}let i=r+1;const{truncatedAst:a,lastEndPosition:s}=function(e,t,n){const o={line:t,column:n},r=[];let l=null;for(const t of e){const e=qt(t.loc.end,o)<0,n=qt(t.loc.start,o)<0;if(!e){if(n&&!e)break;break}r.push(t),l=t.loc.end}return{truncatedAst:r,lastEndPosition:l}}(this._ast,i,l),c=s?s.line:1,u=s?s.column+1:0,f=o.slice(c-1);f.length>0&&u>0&&(f[0]=f[0].substring(u));const m=f.join(this._format.newLine);this._ast=Array.from(function*(e,t){for(const t of e)yield t;const n=new K(A(t));for(;!n.next().done;){const e=ve(n,t);for(const t of e)yield t}}(a,m)),this._currentTomlString=e,this._format=st.autoDetectFormat(e)}overwrite(e){e!==this.toTomlString&&(this._ast=Array.from(fe(e)),this._currentTomlString=e,this._format=st.autoDetectFormat(e))}}function Rt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Rt);if(e&&"object"==typeof e){const t={};for(const[n,o]of Object.entries(e))t[n]=Rt(o);return t}return e}function Pt(e){return At(fe(e),e)}function Ht(e,t){const n=at(t,st.default());return Tt(wt(e,n).items,n)}export{zt as TomlDocument,st as TomlFormat,Pt as parse,Wt as patch,Ht as stringify};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decimalturn/toml-patch",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "contributors": [
5
5
  "Tim Hall <tim.hall.engr@gmail.com>",
6
6
  "Martin Leduc <31558169+DecimalTurn@users.noreply.github.com>"
@@ -33,37 +33,25 @@
33
33
  "default": "./dist/toml-patch.js"
34
34
  }
35
35
  },
36
- "scripts": {
37
- "dev": "npm run typecheck && npm run build && npm-run-all2 --parallel test:all specs",
38
- "test": "jest --config jest.config.json",
39
- "test:js": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.mjs",
40
- "test:all": "npm run test && npm run test:js",
41
- "typecheck": "tsc",
42
- "specs": "jest --config specs.config.cjs",
43
- "benchmark": "npm-run-all2 bench:*",
44
- "benchmark:ci": "npm-run-all2 \"bench:* -- --sample --versions latest\"",
45
- "bench:parse": "node benchmark/parse-benchmark.mjs",
46
- "bench:stringify": "node benchmark/stringify-benchmark.mjs",
47
- "profile": "node benchmark/profile.mjs",
48
- "build": "rimraf dist && rollup -c",
49
- "prepublishOnly": "npm run build"
50
- },
51
36
  "devDependencies": {
52
- "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@1.0.0",
53
- "@rollup/plugin-terser": "^0.4.4",
37
+ "@decimalturn/toml-patch": "npm:@decimalturn/toml-patch@1.0.2",
38
+ "@rollup/plugin-terser": "^1.0.0",
54
39
  "@rollup/plugin-typescript": "^12.1.2",
55
40
  "@types/dedent": "^0.7.2",
56
41
  "@types/jest": "^30.0.0",
57
42
  "@types/js-yaml": "^4.0.0",
43
+ "@types/node": "^22.0.0",
58
44
  "benchmark": "^2",
59
45
  "dedent": "^1.5.3",
60
46
  "glob": "^13.0.0",
61
47
  "jest": "^30.0.0",
62
48
  "js-yaml": "^4.0.0",
63
49
  "mri": "^1",
50
+ "nano-staged": "^0.9.0",
64
51
  "npm-run-all2": "^8.0.0",
52
+ "oxlint": "^1.55.0",
65
53
  "rimraf": "^6.0.0",
66
- "rollup": ">=4.0.0 <4.53.0 || >4.53.0",
54
+ "rollup": "^4.59.0",
67
55
  "rollup-plugin-dts": "^6.2.1",
68
56
  "rollup-plugin-filesize": "^10",
69
57
  "ts-jest": "^29",
@@ -74,8 +62,27 @@
74
62
  "singleQuote": true,
75
63
  "printWidth": 100
76
64
  },
65
+ "nano-staged": {
66
+ "*.{js,jsx,ts,tsx,mjs,cjs}": "pnpm run lint"
67
+ },
77
68
  "files": [
78
69
  "dist/",
79
70
  "CHANGELOG.md"
80
- ]
81
- }
71
+ ],
72
+ "scripts": {
73
+ "dev": "pnpm run typecheck && pnpm run build && npm-run-all2 --parallel test:all specs",
74
+ "test": "jest --config jest.config.json",
75
+ "test:js": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.mjs",
76
+ "test:all": "pnpm run test && pnpm run test:js",
77
+ "typecheck": "tsc",
78
+ "specs": "jest --config specs.config.cjs",
79
+ "benchmark": "npm-run-all2 bench:*",
80
+ "benchmark:ci": "npm-run-all2 \"bench:* -- --sample --versions latest\"",
81
+ "bench:parse": "node benchmark/parse-benchmark.mjs",
82
+ "bench:stringify": "node benchmark/stringify-benchmark.mjs",
83
+ "profile": "node benchmark/profile.mjs",
84
+ "build": "rimraf dist && rollup -c",
85
+ "lint": "oxlint",
86
+ "lint:fix": "oxlint --fix"
87
+ }
88
+ }