@decimalturn/toml-patch 1.0.1 → 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,6 +7,25 @@ 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
+
24
+ ## [1.0.2] - 2026-02-14
25
+
26
+ ### Changed
27
+ - Improve stringification performance ([#106](https://github.com/DecimalTurn/toml-patch/pull/106))
28
+
10
29
  ## [1.0.1] - 2026-02-14
11
30
 
12
31
  ### Changed
@@ -1,4 +1,107 @@
1
- //! @decimalturn/toml-patch v1.0.1 - 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.1 - 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 i(t){return t.type===e.KeyValue}function a(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 i=r+1;return{line:i,column:t-(n[i-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=/[\w,\d,\",\',\+,\-,\_]/,T=10,I=13,k=127;function*C(e){const n=e.length;let r=0;const o=[],i=(e,t)=>({start:p(o,e),end:p(o,t)});for(;r<n;){const c=e.charCodeAt(r);if((c<=31||c===k)&&9!==c&&c!==I&&c!==T)throw new v(e,p(o,r),`Control character 0x${c.toString(16).toUpperCase().padStart(2,"0")} is not allowed in TOML`);if(c===I&&(r+1>=n||e.charCodeAt(r+1)!==T))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===I);else if(c===T)o.push(r);else if(91===c||93===c)yield{type:t.Bracket,raw:e[r],loc:i(r,r+1)};else if(123===c||125===c)yield{type:t.Curly,raw:e[r],loc:i(r,r+1)};else if(61===c)yield{type:t.Equal,raw:"=",loc:i(r,r+1)};else if(44===c)yield{type:t.Comma,raw:",",loc:i(r,r+1)};else if(46===c)yield{type:t.Dot,raw:".",loc:i(r,r+1)};else if(35===c)yield a();else{const t=E(e,r,$)||E(e,r,b);t?yield l(t):yield s()}r++}function a(){const a=r;for(;r+1<n;){const t=e.charCodeAt(r+1);if(t===T||t===I)break;r++;const n=e.charCodeAt(r);if((n<=31||n===k)&&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(a,r+1),loc:i(a,r+1)}}function l(a){const l=r,s=a+a+a;for(r+=3;r<n;){if(E(e,r,a)){let t=3;for(;e[r+t]===a;)t++;if(t>=6)throw new v(e,p(o,r),`Invalid multiline string: ${t} consecutive ${a} characters`);if(3===t){r+=2;break}r+=t-3,r+=2;break}const t=e.charCodeAt(r);if(t===I&&(r+1>=n||e.charCodeAt(r+1)!==T))throw new v(e,p(o,r),"Invalid standalone CR (\\r) in multiline string (must be part of CRLF sequence)");if((t<=31||t===k)&&9!==t&&t!==T&&t!==I){const n=a===b?"multiline basic strings":"multiline literal strings",i=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let l="";0===t?l="Null":t===k&&(l="DEL");const s=l?`${l} (control character ${i}) is not allowed in ${n}`:`Control character ${i} is not allowed in ${n}`;throw new v(e,p(o,r),s)}t===T&&o.push(r),r++}if(r>=n){if(a===b){let t=0,i=n-1;for(;i>=0&&"\\"===e[i];)t++,i--;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:i(l,r+1)}}function s(){const a=e[r];if(!S.test(a))throw new v(e,p(o,r),`Unsupported character "${a}". Expected ALPHANUMERIC, ", ', +, -, or _`);const l=r;let s=a===b,c=a===$;for(;r<n&&!(r+1>=n);){const t=e.charCodeAt(r+1);if(!(s||c||32!==t&&9!==t&&t!==T&&t!==I&&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===k)&&9!==t){const n=s?"basic strings":"literal strings",i=`0x${t.toString(16).toUpperCase().padStart(2,"0")}`;let a="";t===T?a="Newline":t===I?a="Carriage return":0===t?a="Null":t===k&&(a="DEL");const l=a?`${a} (control character ${i}) is not allowed in ${n}`:`Control character ${i} is not allowed in ${n}`;throw new v(e,p(o,r),l)}}const i=e[r];if(i===b&&(s=!s),i!==$||s||(c=!c),r+1>=n)break;if(s&&"\\"===i){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:i(l,r+1)}}}function E(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 A=new Int8Array(128);A.fill(-1);for(let e=0;e<10;e++)A[48+e]=e;for(let e=0;e<6;e++)A[65+e]=10+e,A[97+e]=10+e;function x(e){const t=e.charCodeAt(0);return t<128&&-1!==A[t]}function _(e,t){return A[e.charCodeAt(t)]<<12|A[e.charCodeAt(t+1)]<<8|A[e.charCodeAt(t+2)]<<4|A[e.charCodeAt(t+3)]}function U(e){return e.startsWith("'''")?D(e.slice(3,e.length-3)):e.startsWith($)?e.slice(1,e.length-1):e.startsWith('"""')?O(D(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 i=0;i<n;i++){if("\\"!==e[i])continue;if(i>o&&r.push(e.slice(o,i)),i++,i>=n)throw new Error("Invalid escape sequence: trailing backslash");const a=e[i];switch(a){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(i+4>n||!x(e[i+1])||!x(e[i+2])||!x(e[i+3])||!x(e[i+4]))throw new Error(`Invalid Unicode escape: \\u${e.slice(i+1,i+5)}`);const t=_(e,i+1);if(t>=55296&&t<=57343)throw new Error(`Invalid Unicode escape: \\u${e.slice(i+1,i+5)} (surrogate codepoints are not allowed)`);r.push(String.fromCharCode(t)),i+=4;break}case"U":{if(i+8>n)throw new Error(`Invalid Unicode escape: \\U${e.slice(i+1,i+9)}`);for(let t=1;t<=8;t++)if(!x(e[i+t]))throw new Error(`Invalid Unicode escape: \\U${e.slice(i+1,i+9)}`);const t=parseInt(e.slice(i+1,i+9),16);r.push(String.fromCodePoint(t)),i+=8;break}case"x":{if(i+2>n||!x(e[i+1])||!x(e[i+2]))throw new Error(`Invalid hex escape: \\x${e.slice(i+1,i+3)}`);const t=A[e.charCodeAt(i+1)]<<4|A[e.charCodeAt(i+2)];r.push(String.fromCharCode(t)),i+=2;break}default:if(t&&("\n"===a||"\r"===a||" "===a||"\t"===a)){let t="\n"===a||"\r"===a,r=i;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: \\${a}`);i=r-1;break}throw new Error(`Invalid escape sequence: \\${a}`)}o=i+1}return 0===o?e:(o<n&&r.push(e.slice(o)),r.join(""))}function D(e){return 10===e.charCodeAt(0)?e.slice(1):13===e.charCodeAt(0)&&10===e.charCodeAt(1)?e.slice(2):e}class F{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 L=Object.freeze({value:void 0,done:!0});function M(){return L}class K{static createDateWithOriginalFormat(e,t){if(K.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 W(t,!1)}const t=e.toISOString().split("T")[0];return new N(t)}if(K.IS_TIME_ONLY.test(t)){if(e instanceof j)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,i,a]=o.split(":"),[l]=a.split(".");o=`${r}:${i}:${l}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new j(o,t)}{const r=String(e.getUTCHours()).padStart(2,"0"),o=String(e.getUTCMinutes()).padStart(2,"0"),i=String(e.getUTCSeconds()).padStart(2,"0"),a=e.getUTCMilliseconds();let l;if(n){const e=n[1].length;l=`${r}:${o}:${i}.${String(a).padStart(3,"0").slice(0,e)}`}else if(a>0){l=`${r}:${o}:${i}.${String(a).padStart(3,"0").replace(/0+$/,"")}`}else l=`${r}:${o}:${i}`;return new j(l,t)}}}if(K.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,i]=r.split("T"),[a,l,s]=i.split(":"),[c]=s.split(".");r=`${o}T${a}:${l}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new W(r,!1,t)}if(K.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,i]=r.split(" "),[a,l,s]=i.split(":"),[c]=s.split(".");r=`${o} ${a}:${l}:${c}.${String(e.getUTCMilliseconds()).padStart(3,"0").slice(0,t)}`}return new W(r,!0,t)}if(K.IS_OFFSET_DATETIME_T.test(t)||K.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=K.IS_OFFSET_DATETIME_SPACE.test(t),i=t.match(/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/),a=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(a+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(i){const e=i[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}}K.IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,K.IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,K.IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,K.IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/,K.IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,K.IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/,K.IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/,K.IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;class N extends Date{constructor(e){super(e)}toISOString(){return`${this.getUTCFullYear()}-${String(this.getUTCMonth()+1).padStart(2,"0")}-${String(this.getUTCDate()).padStart(2,"0")}`}}class j 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*$/),i=o?o[1].length:3;return`${e}:${t}:${n}.${String(r).padStart(3,"0").slice(0,i)}`}if(r>0){return`${e}:${t}:${n}.${String(r).padStart(3,"0").replace(/0+$/,"")}`}return`${e}:${t}:${n}`}}class W 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"),i=String(this.getUTCSeconds()).padStart(2,"0"),a=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}:${i}.${String(a).padStart(3,"0").slice(0,t)}`}if(a>0){return`${l}${s}${r}:${o}:${i}.${String(a).padStart(3,"0").replace(/0+$/,"")}`}return`${l}${s}${r}:${o}:${i}`}}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"),i=String(n.getUTCDate()).padStart(2,"0"),a=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}-${i}`,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}${a}:${l}:${s}.${String(c).padStart(3,"0").slice(0,t)}${this.originalOffset}`}if(c>0){return`${u}${f}${a}:${l}:${s}.${String(c).padStart(3,"0").replace(/0+$/,"")}${this.originalOffset}`}return`${u}${f}${a}:${l}:${s}${this.originalOffset}`}const e=super.toISOString();return this.useSpaceSeparator?e.replace("T"," "):e}}const B=K,z="true",q=/e/i,V=/\_/g,R=/^[+\-]?inf$/,P=/^[+\-]?nan$/,H=/^[+\-]?0x/i;function Y(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||95===e||45===e}const J=/^[+\-]?0o/i,X=/^[+\-]?0b/i;function*G(e){const t=new F(C(e));for(;!t.next().done;){const n=ae(t,e);for(const e of n)yield e}}function Q(t){return{type:e.Comment,loc:t.value.loc,raw:t.value.raw}}function ee(n,r){const o=n.peek().done||n.peek().value.type!==t.Bracket?e.Table:e.TableArray,i=o===e.Table;if(i&&"["!==n.value.raw)throw new v(r,n.value.loc.start,`Expected table opening "[", found ${n.value.raw}`);if(!i){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 a=i?{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,a.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(!Y(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=[U(n.value.raw)]}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}for(a.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(!Y(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-a.item.loc.end.column),i=" ".repeat(n.value.loc.start.column-e.loc.end.column);a.item.loc.end=n.value.loc.end,a.item.raw+=`${o}.${i}${n.value.raw}`;try{a.item.value.push(U(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=a.loc.start.line;if(n.value.loc.start.line!==e)throw new v(r,n.value.loc.start,i?`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(i&&(n.done||"]"!==n.value.raw))throw new v(r,n.done?a.item.loc.end:n.value.loc.start,`Expected table closing "]", found ${n.done?"end of file":n.value.raw}`);if(!i&&(n.done||n.peek().done||"]"!==n.value.raw||"]"!==n.peek().value.raw))throw new v(r,n.done||n.peek().done?a.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(!i){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(i||n.next(),a.loc.end=n.value.loc.end,!n.peek().done){const e=n.peek().value;if(e.loc.start.line===a.loc.end.line&&e.type!==t.Comment)throw new v(r,e.loc.start,`Unexpected content after ${i?"table":"array of tables"} header`)}let c=[];for(;!n.peek().done&&n.peek().value.type!==t.Bracket;){n.next();const e=ae(n,r);for(let t=0;t<e.length;t++)c.push(e[t])}return{type:i?e.Table:e.TableArray,loc:{start:g(a.loc.start),end:c.length?g(c[c.length-1].loc.end):g(a.loc.end)},key:a,items:c}}function te(t,n){let r;try{r=U(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 ne(t){return{type:e.Boolean,loc:t.value.loc,value:t.value.raw===z}}function re(n,r){let o,i=n.value.loc,a=n.value.raw;if(!n.peek().done&&n.peek().value.type===t.Literal&&B.IS_FULL_DATE.test(a)&&B.IS_FULL_TIME.test(n.peek().value.raw)){const e=i.start;n.next(),i={start:e,end:n.value.loc.end},a+=` ${n.value.raw}`}if(!n.peek().done&&n.peek().value.type===t.Dot){const e=i.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(),i={start:e,end:n.value.loc.end},a+=`.${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],i=o[3],a=o[4];if(":"!==i)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(!a||0===a.length)throw new v(t,n,`Invalid timezone offset "${e}": minute component is required`);if(2!==a.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(a,10);if(s<0||s>59)throw new v(t,n,`Invalid timezone offset "${e}": minute must be between 00 and 59, found ${a}`)}const i=/^\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)&&!i.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 a=e.match(/^(\d+)-/);if(a&&4!==a[1].length)throw new v(t,n,`Invalid date "${e}": year must be exactly 4 digits, found ${a[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,i]=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(i&&2!==i.length)throw new v(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${i.length}`)}const f=/^(\d+):(\d+)(?::(\d+))?/,d=e.match(f);if(d&&!s){const[,r,o,i]=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(i&&2!==i.length)throw new v(t,n,`Invalid time "${e}": second must be exactly 2 digits, found ${i.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,i,a,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(i,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 ${i} is invalid for month ${o} in year ${r}`);if(void 0!==a){const r=parseInt(a,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,i]=h,a=parseInt(r,10);if(a<0||a>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!==i){const r=parseInt(i,10);if(r<0||r>60)throw new v(t,n,`Invalid time "${e}": second must be between 00 and 60`)}}}(a,r,i.start),B.IS_FULL_DATE.test(a))o=B.IS_DATE_ONLY.test(a)?new N(a):B.IS_LOCAL_DATETIME_T.test(a)?new W(a,!1):B.IS_LOCAL_DATETIME_SPACE.test(a)?new W(a,!0):B.IS_OFFSET_DATETIME_T.test(a)?new Z(a,!1):B.IS_OFFSET_DATETIME_SPACE.test(a)?new Z(a,!0):new Date(a.replace(" ","T"));else if(B.IS_TIME_ONLY.test(a))o=new j(a,a);else{const[e]=(new Date).toISOString().split("T");o=new Date(`${e}T${a}`)}return{type:e.DateTime,loc:i,raw:a,value:o}}function oe(n,r){let o,i=n.value.loc,a=n.value.raw;if(R.test(a))o=a.startsWith("-")?-1/0:1/0;else if(P.test(a))o=NaN;else if(n.peek().done||n.peek().value.type!==t.Dot){if(/_$/.test(a))throw new v(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(a))throw new v(r,i.start,"Leading underscore is not allowed");if(/__/.test(a))throw new v(r,i.start,"Consecutive underscores are not allowed");if(/[eE][+\-]?$/.test(a))throw new v(r,i.start,`Invalid float "${a}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(a))throw new v(r,i.start,`Invalid float "${a}": decimal point not allowed in exponent`);if(/_[eE]/.test(a))throw new v(r,i.start,"Underscore before exponent is not allowed");if(/[eE][+\-]?_/.test(a))throw new v(r,i.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 "${a}.": cannot have decimal point after exponent`);const e=a.replace(V,"");if(/^[+\-]?0\d/.test(e)&&!H.test(a)&&!J.test(a)&&!X.test(a))throw new v(r,i.start,"Leading zeros are not allowed in the integer part of a float");o=Number(a.replace(V,""))}else{const e=i.start;{if(q.test(a)&&!H.test(a))throw new v(r,i.start,`Invalid float "${a}": cannot have decimal point after exponent`);const e=a,t=e.replace(V,"");if(/^[+\-]?0\d/.test(t)&&!H.test(e)&&!J.test(e)&&!X.test(e))throw new v(r,i.start,"Leading zeros are not allowed in the integer part of a float");const n=e.replace(/^[+\-]/,"");if(""===n||"_"===n)throw new v(r,i.start,"Invalid float: decimal point must be preceded by at least one digit");if(/_$/.test(e))throw new v(r,i.start,"Underscore before decimal point is not allowed");if(/^[+\-]?_/.test(e))throw new v(r,i.start,"Leading underscore is not allowed");if(/__/.test(e))throw new v(r,i.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(),a+=`.${n.value.raw}`,i={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 "${a}": incomplete exponent`);if(/[eE][+\-]?.*\./.test(e))throw new v(r,n.value.loc.start,`Invalid float "${a}": decimal point not allowed in exponent`)}o=Number(a.replace(V,""))}if(Number.isNaN(o)&&!P.test(a))throw new v(r,i.start,`Invalid float "${a}"`);return{type:e.Float,loc:i,raw:a,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)&&!H.test(r)&&!J.test(r)&&!X.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 i,a=10;if(H.test(r)){if(a=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(i=r.replace(/^[+\-]?0x/i,""),!i||"_"===i||/^_/.test(i))throw new v(n,o.start,"Incomplete hexadecimal number");const e=i.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(J.test(r)){if(a=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(i=r.replace(/^[+\-]?0o/i,""),!i||"_"===i||/^_/.test(i))throw new v(n,o.start,"Incomplete octal number");const e=i.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(X.test(r)){if(a=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(i=r.replace(/^[+\-]?0b/i,""),!i||"_"===i||/^_/.test(i))throw new v(n,o.start,"Incomplete binary number");const e=i.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(V,"").replace(J,"").replace(X,""),a);if(Number.isNaN(l))throw new v(n,o.start,`Invalid integer "${r}"`);return{type:e.Integer,loc:o,raw:r,value:l}}function ae(n,r){if(n.value.type===t.Comment)return[Q(n)];if(n.value.type===t.Bracket)return[ee(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(!Y(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 i;try{i=[U(n.value.raw)]}catch(e){const t=e;throw new v(r,n.value.loc.start,t.message)}const a={type:e.Key,loc:n.value.loc,raw:n.value.raw,value:i};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(!Y(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 -`);a.loc.end=n.value.loc.end,a.raw+=`.${n.value.raw}`;try{a.value.push(U(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!==a.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?a.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,a.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,a.loc.start,"Expected value for key-value");const c=le(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:a,value:u,loc:{start:g(a.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 le(n,r){if(n.value.type===t.Literal){const e=n.value.raw;return e[0]===b||e[0]===$?[te(n,r)]:e===z||"false"===e?[ne(n)]:/^\d/.test(e)&&(/^\d{1,}-\d{1,}/.test(e)||/^\d{1,}:\d{1,}/.test(e))?[re(n,r)]:!n.peek().done&&n.peek().value.type===t.Dot||R.test(e)||P.test(e)||q.test(e)&&!H.test(e)?[oe(n,r)]:[ie(n,r)]}if(n.value.type===t.Curly){const[o,i]=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:[]},i=[];n.next();for(;!n.done&&(n.value.type!==t.Curly||"}"!==n.value.raw);){if(n.value.type===t.Comment){i.push(Q(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 a=o.items[o.items.length-1];if(a&&!a.comma)throw new v(r,n.value.loc.start,"Missing comma between inline table items");const l=ae(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++)i.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,i]}(n,r);return[o,...i]}if(n.value.type===t.Bracket){const[o,i]=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:[]},i=[];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)i.push(Q(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 a=le(n,r),l=a[0];o.items.push({type:e.InlineItem,loc:y(l.loc),item:l,comma:!1});for(let e=1;e<a.length;e++)i.push(a[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,i]}(n,r);return[o,...i]}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 se(e){return e[e.length-1]}function ce(){return Object.create(null)}function ue(e){return"number"==typeof e&&e%1==0&&isFinite(e)&&!Object.is(e,-0)}function fe(e){return"[object Date]"===Object.prototype.toString.call(e)}function de(e){return e&&"object"==typeof e&&!fe(e)&&!Array.isArray(e)}function me(e,t){return t in e}function he(e){if(de(e)){return`{${Object.keys(e).sort().map((t=>`${JSON.stringify(t)}:${he(e[t])}`)).join(",")}}`}return Array.isArray(e)?`[${e.map(he).join(",")}]`:JSON.stringify(e)}function pe(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 we(e){return e.startsWith('"""')||e.startsWith("'''")}function ge(t,n){var r;function o(e,t){for(const n of e)i(n,t)}function i(t,r){const a=n[t.type];switch(a&&"function"==typeof a&&a(t,r),a&&a.enter&&a.enter(t,r),t.type){case e.Document:o(t.items,t);break;case e.Table:i(t.key,t),o(t.items,t);break;case e.TableKey:i(t.item,t);break;case e.TableArray:i(t.key,t),o(t.items,t);break;case e.TableArrayKey:i(t.item,t);break;case e.KeyValue:i(t.key,t),i(t.value,t);break;case e.InlineArray:o(t.items,t);break;case e.InlineItem:i(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}"`)}a&&a.exit&&a.exit(t,r)}null!=(r=t)&&"function"==typeof r[Symbol.iterator]?o(t,null):i(t,null)}const ye=new WeakMap,ve=e=>(ye.has(e)||ye.set(e,new WeakMap),ye.get(e)),be=new WeakMap,$e=e=>(be.has(e)||be.set(e,new WeakMap),be.get(e));function Se(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(i(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(!i(t))throw new Error(`Unsupported parent type "${t.type}" for replace`);t.key===n?t.key=r:t.value=r}xe(r,{lines:n.loc.start.line-r.loc.start.line,columns:n.loc.start.column-r.loc.start.column});const o=h(n.loc),a=h(r.loc);_e({lines:a.lines-o.lines,columns:a.columns-o.columns},$e(e),r,n)}function Te(e,t,a,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]:se(e.items),o=null==n||n===e.items.length;e.items.splice(n,0,t);const i=!!r,a=!o;i&&(r.comma=!0);a&&(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 Ie(e,t,n,{useNewLine:l,hasCommaHandling:!0,isLastElement:o,hasSeparatingCommaBefore:i,hasSeparatingCommaAfter:a,hasTrailingComma:u})}(t,a,l)):m&&n(t)?({shift:p,offset:w}=function(e,t,n){const r=Ie(e,t,n,{useNewLine:!1,hasCommaHandling:!1});return e.items.splice(n,0,t),r}(t,a,l)):({shift:p,offset:w}=function(e,t,a){if(l=t,!(i(l)||r(l)||o(l)||f(l)))throw new Error(`Incompatible child type "${t.type}"`);var l;const s=e.items[a-1],c=n(e)&&!e.items.length;e.items.splice(a,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,a,l)),xe(a,p);const y=t.items[l-1],v=y&&$e(e).get(y);v&&(w.lines+=v.lines,w.columns+=v.columns,$e(e).delete(y));$e(e).set(a,w)}function Ie(e,t,n,r={}){const{useNewLine:o=!1,skipCommaSpace:i=2,skipBracketSpace:a=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+=i:(e||l&&!m)&&(p.column+=a)}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?i:0)+(d?1+b:0)}}}function ke(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 i=t.items[r+1];t.items.splice(r,1);let a=h(n.loc);i&&f(i)&&i.loc.start.line===n.loc.end.line&&(a=h({start:n.loc.start,end:i.loc.end}),i=t.items[r+1],t.items.splice(r,1));const l=o&&c(o)||i&&c(i),s=o&&o.loc.end.line===n.loc.start.line,u=i&&i.loc.start.line===n.loc.end.line,p=l&&(s||u),w={lines:-(a.lines-(p?1:0)),columns:-a.columns};if(void 0===o&&void 0===i&&(w.lines=0,w.columns=0),l&&s&&(w.columns-=2),l&&!o&&i&&(w.columns-=2),l&&o&&!i){const e=n.comma;o.comma=!!e}const g=o||t,y=o?$e(e):ve(e),v=$e(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)}function Ce(e,t,n=!0){if(!n)return;if(!t.items.length)return;_e({lines:0,columns:1},ve(e),t);const r=se(t.items);_e({lines:0,columns:1},$e(e),r)}function Ee(e,t,n=!1){if(!n)return;if(!t.items.length)return;const r=se(t.items);r.comma=!0,_e({lines:0,columns:1},$e(e),r)}function Ae(t){const n=ve(t),r=$e(t),o={lines:0,columns:{}};function i(e){const t=o.lines;e.loc.start.line+=t;const r=o.columns[e.loc.start.line]||0;e.loc.start.column+=r;const i=n.get(e);i&&(o.lines+=i.lines,o.columns[e.loc.start.line]=(o.columns[e.loc.start.line]||0)+i.columns)}function a(e){const t=o.lines;e.loc.end.line+=t;const n=o.columns[e.loc.end.line]||0;e.loc.end.column+=n;const i=r.get(e);i&&(o.lines+=i.lines,o.columns[e.loc.end.line]=(o.columns[e.loc.end.line]||0)+i.columns)}const l={enter:i,exit:a};ge(t,{[e.Document]:l,[e.Table]:l,[e.TableArray]:l,[e.InlineTable]:l,[e.InlineArray]:l,[e.InlineItem]:l,[e.TableKey]:l,[e.TableArrayKey]:l,[e.KeyValue]:{enter(e){const t=e.loc.start.line+o.lines,n=r.get(e.key);e.equals+=(o.columns[t]||0)+(n?n.columns:0),i(e)},exit:a},[e.Key]:l,[e.String]:l,[e.Integer]:l,[e.Float]:l,[e.Boolean]:l,[e.DateTime]:l,[e.Comment]:l}),ye.delete(t),be.delete(t)}function xe(t,n,r={}){const{first_line_only:o=!1}=r,i=t.loc.start.line,{lines:a,columns:l}=n,s=e=>{o&&e.loc.start.line!==i||(e.loc.start.column+=l,e.loc.end.column+=l),e.loc.start.line+=a,e.loc.end.line+=a};return ge(t,{[e.Table]:s,[e.TableKey]:s,[e.TableArray]:s,[e.TableArrayKey]:s,[e.KeyValue](e){s(e),e.equals+=l},[e.Key]:s,[e.String]:s,[e.Integer]:s,[e.Float]:s,[e.Boolean]:s,[e.DateTime]:s,[e.InlineArray]:s,[e.InlineItem]:s,[e.InlineTable]:s,[e.Comment]:s}),t}function _e(e,t,n,r){const o=t.get(r||n);o&&(e.lines+=o.lines,e.columns+=o.columns),t.set(n,e)}function Ue(){return{type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:[]}}function Oe(t){const n=function(t){const n=Me(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 De(t){const n=function(t){const n=Me(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 Fe(t,n){const r=function(t){const n=Me(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,i=o+1;return xe(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:i,value:n}}const Le=/^[\w-]+$/;function Me(e){return e.map((e=>Le.test(e)?e:JSON.stringify(e))).join(".")}function Ke(t,n){let r,o;if(n&&we(n)){let e=n.startsWith("'''");e&&t.includes("'''")&&(e=!1);const o=e?"'''":'"""',i=n.includes("\r\n")?"\r\n":"\n",a=n.startsWith(`${o}${i}`)||(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=a?`${o}${i}${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 Ne(t){return{type:e.InlineItem,loc:y(t.loc),item:t,comma:!1}}const je=!1,We=!0,Ze=!1,Be=!1;function ze(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,i=e.end.line-1,a=e.start.column,l=e.end.column;let s="";if(o===i)s=(null===(n=r[o])||void 0===n?void 0:n.substring(a,l+1))||"";else{r[o]&&(s+=r[o].substring(a));for(let e=o+1;e<i;e++)s+="\n"+(r[e]||"");r[i]&&(s+="\n"+r[i].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=ze(n,t);if(null!==e)return e;if(n.item){const e=ze(n.item,t);if(null!==e)return e}}for(const n of["value","key","item"])if(e[n]){const r=ze(e[n],t);if(null!==r)return r}return null}function qe(e){if(!e||"object"!=typeof e)return null;if("InlineArray"===e.type&&e.items&&Array.isArray(e.items))return Ve(e.items);if("InlineTable"===e.type&&e.items&&Array.isArray(e.items))return Ve(e.items);if("KeyValue"===e.type&&e.value)return qe(e.value);if(e.items&&Array.isArray(e.items))for(const t of e.items){const e=qe(t);if(null!==e)return e}return null}function Ve(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 Re(e){if(!s(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function Pe(e){if(!u(e))return!1;if(0===e.items.length)return!1;return!0===e.items[e.items.length-1].comma}function He(e){const t=e.indexOf("\n");return t>0&&"\r"===e.substring(t-1,t)?"\r\n":"\n"}function Ye(e,t){var n,r,o,i,a,l;if(e){if(e instanceof Je)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 i in e){const a=Object.prototype.hasOwnProperty.call(e,i);if(t.has(i)){const t=e[i];switch(i){case"newLine":"string"==typeof t?n.newLine=t:o.push(`${i} (expected string, got ${typeof t})`);break;case"trailingNewline":"boolean"==typeof t||"number"==typeof t?n.trailingNewline=t:o.push(`${i} (expected boolean or number, got ${typeof t})`);break;case"trailingComma":case"bracketSpacing":case"truncateZeroTimeInDates":case"useTabsForIndentation":"boolean"==typeof t?n[i]=t:o.push(`${i} (expected boolean, got ${typeof t})`);break;case"inlineTableStart":"number"==typeof t&&Number.isInteger(t)&&t>=0||null==t?n.inlineTableStart=t:o.push(`${i} (expected non-negative integer or undefined, got ${typeof t})`)}}else a&&r.push(i)}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 Je(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!==(i=s.bracketSpacing)&&void 0!==i?i:t.bracketSpacing,void 0!==s.inlineTableStart?s.inlineTableStart:t.inlineTableStart,null!==(a=s.truncateZeroTimeInDates)&&void 0!==a?a:t.truncateZeroTimeInDates,null!==(l=s.useTabsForIndentation)&&void 0!==l?l:t.useTabsForIndentation)}}return t}class Je{constructor(e,t,n,r,o,i,a){this.newLine=null!=e?e:"\n",this.trailingNewline=null!=t?t:1,this.trailingComma=null!=n?n:je,this.bracketSpacing=null!=r?r:We,this.inlineTableStart=null!=o?o:1,this.truncateZeroTimeInDates=null!=i?i:Ze,this.useTabsForIndentation=null!=a?a:Be}static default(){return new Je("\n",1,je,We,1,Ze,Be)}static autoDetectFormat(e){const t=Je.default();t.newLine=He(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=G(e),r=Array.from(n);t.trailingComma=function(e){const t=Array.from(e);for(const e of t){const t=qe(e);if(null!==t)return t}return je}(r),t.bracketSpacing=function(e,t){const n=Array.from(t);for(const t of n){const n=ze(t,e);if(null!==n)return n}return We}(e,r)}catch(e){t.trailingComma=je,t.bracketSpacing=We}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 Xe(e,t){if(0===t.inlineTableStart)return e;return e.items.filter((e=>{if(!i(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=et(e.key.value);return void 0===t.inlineTableStart||n<t.inlineTableStart}return!1})).forEach((t=>{ke(e,e,t),u(t.value)?Te(e,e,Ge(t)):function(e){const t=Ue();for(const n of e.value.items){const r=De(e.key.value);Te(t,t,r);for(const e of n.item.items)Te(t,r,e.item)}return Ae(t),t.items}(t).forEach((t=>{Te(e,e,t)}))})),Ae(e),e}function Ge(e){const t=Oe(e.key.value);for(const n of e.value.items)Te(t,t,n.item);return Ae(t),t}function Qe(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 et(e){return Math.max(0,e.length-1)}function tt(e,t,n){var r;for(let o=e.items.length-1;o>=0;o--){const a=e.items[o];if(i(a)&&u(a.value)){const o=[...e.key.item.value,...a.key.value];if(et(o)<(null!==(r=n.inlineTableStart)&&void 0!==r?r:1)){const r=Oe(o);for(const e of a.value.items)Te(r,r,e.item);ke(e,e,a),Qe(e),t.push(r),tt(r,t,n)}}}}function nt(e,t=Je.default()){e=function(e){const t=[],n=[];for(const r in e)de(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=it(e));const n=Ue();for(const r of rt(e,t))Te(n,n,r);Ae(n);const r=function(e,...t){return t.reduce(((e,t)=>t(e)),e)}(n,(e=>Xe(e,t)),(e=>function(e,t){if(void 0===t.inlineTableStart||0===t.inlineTableStart)return e;const n=[];for(const r of e.items)if(i(r)&&u(r.value)){if(et(r.key.value)<t.inlineTableStart){const o=Ge(r);ke(e,e,r),Te(e,e,o),tt(o,n,t)}}else"Table"===r.type&&tt(r,n,t);for(const t of n)Te(e,e,t);return Ae(e),e}(e,t)),(e=>function(e){return e}(e)));return 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)),xe(r,{lines:t,columns:0}),n=r.loc.end.line;return e}(r)}function*rt(e,t){for(const n of Object.keys(e))yield Fe([n],ot(e[n],t))}function ot(t,n){if(null==t)throw new Error('"null" and "undefined" values are not supported');return function(e){return"string"==typeof e}(t)?Ke(t):ue(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&&(!ue(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):fe(t)?function(t,n){n.truncateZeroTimeInDates&&0===t.getUTCHours()&&0===t.getUTCMinutes()&&0===t.getUTCSeconds()&&0===t.getUTCMilliseconds()&&(t=new N(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){Te(r,r,Ne(ot(e,n)))}return Ce(r,r,n.bracketSpacing),Ee(r,r,n.trailingComma),Ae(r),r}(t,n):function(t,n){if(t=it(t),!de(t))return ot(t,n);const r={type:e.InlineTable,loc:{start:{line:1,column:0},end:{line:1,column:2}},items:[]},o=[...rt(t,n)];for(const e of o){Te(r,r,Ne(e))}return Ce(r,r,n.bracketSpacing),Ee(r,r,n.trailingComma),Ae(r),r}(t,n)}function it(e){return e?fe(e)?e:"function"==typeof e.toJSON?e.toJSON():e:e}const at=/(\r\n|\n)/g;function lt(t,n){const r=[],o=n.useTabsForIndentation?"\t":" ";if(ge(t,{[e.TableKey](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),st(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[e.TableArrayKey](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+2}},"[[",o),st(r,{start:{line:n.line,column:n.column-2},end:n},"]]",o)},[e.KeyValue](e){const{start:{line:t}}=e.loc;st(r,{start:{line:t,column:e.equals},end:{line:t,column:e.equals+1}},"=",o)},[e.Key](e){st(r,e.loc,e.raw,o)},[e.String](e){st(r,e.loc,e.raw,o)},[e.Integer](e){st(r,e.loc,e.raw,o)},[e.Float](e){st(r,e.loc,e.raw,o)},[e.Boolean](e){st(r,e.loc,e.value.toString(),o)},[e.DateTime](e){st(r,e.loc,e.raw,o)},[e.InlineArray](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+1}},"[",o),st(r,{start:{line:n.line,column:n.column-1},end:n},"]",o)},[e.InlineTable](e){const{start:t,end:n}=e.loc;st(r,{start:t,end:{line:t.line,column:t.column+1}},"{",o),st(r,{start:{line:n.line,column:n.column-1},end:n},"}",o)},[e.InlineItem](e){if(!e.comma)return;const t=e.loc.end;st(r,{start:t,end:{line:t.line,column:t.column+1}},",",o)},[e.Comment](e){st(r,e.loc,e.raw,o)}}),n.useTabsForIndentation)for(let e=0;e<r.length;e++){const t=r[e],n=t.match(/^( +)/);if(n){const o=n[1],i="\t".repeat(o.length);r[e]=i+t.substring(o.length)}}return r.join(n.newLine)+n.newLine.repeat(n.trailingNewline)}function st(e,t,n,r=" "){const o=n.split(at).filter((e=>"\n"!==e&&"\r\n"!==e)),i=t.end.line-t.start.line+1;if(o.length!==i)throw new Error(`Mismatch between location and raw string, expected ${i} lines for "${n}"`);for(let r=t.start.line;r<=t.end.line;r++){const i=ct(e,r);if(void 0===i)throw new Error(`Line ${r} is uninitialized when writing "${n}" at ${t.start.line}:${t.start.column} to ${t.end.line}:${t.end.column}`);const a=r===t.start.line,l=r===t.end.line;let s="";if(a){const e=i.substring(0,t.start.column);s=e.length<t.start.column?e.padEnd(t.start.column," "):e}const c=l?i.substring(t.end.column):"";e[r-1]=s+o[r-t.start.line]+c}}function ct(e,t){if(!e[t-1])for(let n=0;n<t;n++)e[n]||(e[n]="");return e[t-1]}function ut(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(gt(e)),ut(t.value,e,r)}}}function ft(t,n=""){const r=ce(),o=new Set,i=new Set,a=new Set,l=new Set,s=new Set;let c=r,u=[];const f={tables:o,table_arrays:i,defined:a,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{mt(r,[],t,e.type,f)}catch(t){const r=t;throw new v(n,e.key.loc.start,r.message)}const i=gt(t);o.add(i),a.add(i),c=ht(r,t),u=t}function m(e){const t=e.key.item.value;try{mt(r,[],t,e.type,f)}catch(t){const r=t;throw new v(n,e.key.loc.start,r.message)}const o=gt(t);i.add(o),a.add(o),c=function(e,t){const n=pt(e,t.slice(0,-1)),r=se(t);n[r]||(n[r]=[]);const o=ce();return n[se(t)].push(o),o}(r,t),u=t}function h(t){const r=t.key.value;try{mt(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=gt(u.concat(r.slice(0,e)));l.add(t),a.add(t)}let o;try{o=dt(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(gt(e)),ut(t.value,e,s)}(r.length>1?ht(c,r.slice(0,-1)):c)[se(r)]=o,a.add(gt(u.concat(r)))}}function dt(t){switch(t.type){case e.InlineTable:const n=ce(),r=new Set,o=new Map;return t.items.forEach((({item:e})=>{const t=e.key.value,i=dt(e.value),a=gt(t);if(r.has(a))throw new Error(`Duplicate key "${a}" in inline table`);for(let e=1;e<t.length;e++){const n=gt(t.slice(0,e));if(r.has(n))throw new Error(`Key "${a}" conflicts with already defined key "${n}" in inline table`)}if(o.has(a)){const e=o.get(a);throw new Error(`Key "${a}" conflicts with already defined key "${e}" in inline table`)}r.add(a);for(let e=1;e<t.length;e++){const n=gt(t.slice(0,e));o.has(n)||o.set(n,a)}(t.length>1?ht(n,t.slice(0,-1)):n)[se(t)]=i})),n;case e.InlineArray:return t.items.map((e=>dt(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 mt(t,n,r,o,i){const a=n.length>0?gt(n):"",l=new Array(r.length);let s=a;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(i.inline_tables.has(t))throw new Error(`Invalid key, cannot extend an inline table at ${t}`)}if((o===e.Table||o===e.TableArray)&&i.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(i.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(i.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)&&i.implicit_tables.has(c))throw new Error(`Invalid key, a table has already been defined implicitly named ${c}`);if(o===e.KeyValue&&i.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(i.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(!me(t,e))return;if(wt(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])&&!i.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?se(t[e]):t[e]}const f=c;if(t&&o===e.Table&&i.defined.has(f))throw new Error(`Invalid key, a table has already been defined named ${f}`);if(t&&o===e.KeyValue&&1===r.length&&i.defined.has(f)&&!wt(t))throw new Error(`Invalid key, a table has already been defined named ${f}`);if(t&&o===e.TableArray&&!i.table_arrays.has(f))throw new Error(`Invalid key, cannot add an array of tables to a table at ${f}`)}function ht(e,t){const n=pt(e,t.slice(0,-1)),r=se(t);return n[r]||(n[r]=ce()),n[r]}function pt(e,t){return t.reduce(((e,t)=>(e[t]||(e[t]=ce()),Array.isArray(e[t])?se(e[t]):e[t])),e)}function wt(e){return"object"!=typeof e&&!fe(e)}function gt(e){return e.join(".")}var yt,vt,bt,$t;function St(e){return e.type===yt.Remove}function Tt(e,t,n=[]){return e===t||(o=t,fe(r=e)&&fe(o)&&r.toISOString()===o.toISOString())?[]:Array.isArray(e)&&Array.isArray(t)?function(e,t,n=[]){let r=[];const o=e.map(he),i=t.map(he);i.forEach(((a,l)=>{const s=l>=o.length;if(!s&&o[l]===a)return;const c=o.indexOf(a,l+1);if(!s&&c>-1){r.push({type:yt.Move,path:n,from:c,to:l});const e=o.splice(c,1);return void o.splice(l,0,...e)}const u=!i.includes(o[l]);if(!s&&u)return pe(r,Tt(e[l],t[l],n.concat(l))),void(o[l]=a);r.push({type:yt.Add,path:n.concat(l)}),o.splice(l,0,a)}));for(let e=i.length;e<o.length;e++)r.push({type:yt.Remove,path:n.concat(e)});return r}(e,t,n):de(e)&&de(t)?function(e,t,n=[]){let r=[];const o=Object.keys(e),i=o.map((t=>he(e[t]))),a=Object.keys(t),l=a.map((e=>he(t[e]))),s=(e,t)=>{if(t.indexOf(e)<0)return!1;const n=o[i.indexOf(e)];return!a.includes(n)};return o.forEach(((o,c)=>{const u=n.concat(o);if(a.includes(o))pe(r,Tt(e[o],t[o],u));else if(s(i[c],l)){const e=a[l.indexOf(i[c])];r.push({type:yt.Rename,path:n,from:o,to:e})}else r.push({type:yt.Remove,path:u})})),a.forEach(((e,t)=>{o.includes(e)||s(l[t],i)||r.push({type:yt.Add,path:n.concat(e)})})),r}(e,t,n):[{type:yt.Edit,path:n}];var r,o}function It(e,t){if(!t.length)return c(e)&&i(e.item)?e.item:e;if(i(e))return It(e.value,t);const n={};let a;if(d(e)&&e.items.some(((e,l)=>{try{let s=[];if(i(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=he(s);n[t]||(n[t]=0);const r=n[t]++;s=s.concat(r)}else c(e)&&i(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)))&&(a=c(e)&&i(e.item)?t.length===s.length?e:It(e.item.value,t.slice(s.length)):It(e,t.slice(s.length)),!0)}catch(e){return!1}})),!a)throw new Error(`Could not find node at path ${t.join(".")}`);return a}function kt(e,t){try{return It(e,t)}catch(e){}}function Ct(e,t){let n,r=t;for(;r.length&&!n;)r=r.slice(0,-1),n=kt(e,r);if(!n)throw new Error(`Count not find parent node for path ${t.join(".")}`);return n}function Et(e,t,n){return At(G(e),t,Ye(n,Je.autoDetectFormat(e))).tomlString}function At(t,a,l){const f=[...t],d=ft(f),h={type:e.Document,loc:{start:{line:1,column:0},end:{line:1,column:0}},items:f},p=nt(a,Ye(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(St(n)){let r=t+1;for(;r<e.length;){const o=e[r];if(St(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}(Tt(d,a));if(0===w.length)return{tomlString:lt(f,l),document:h};const g=function(e,t,a,l){return a.forEach((a=>{if(function(e){return e.type===yt.Add}(a)){const f=It(t,a.path),d=a.path.slice(0,-1);let m,h=se(a.path),p=o(f);if(ue(h)&&!d.some(ue)){const t=kt(e,d.concat(0));t&&o(t)&&(p=!0)}if(r(f))m=e;else if(p){m=e;const t=e,n=kt(t,d.concat(h-1)),r=kt(t,d.concat(h));h=r?t.items.indexOf(r):n?t.items.indexOf(n)+1:t.items.length}else m=Ct(e,a.path),i(m)&&(m=m.value);if(o(m)||s(m)||n(m)){if(s(m)){const e=Re(m);c(f)&&(f.comma=e)}if(void 0!==l.inlineTableStart&&l.inlineTableStart>0&&n(m)&&r(f)){const t=_t(f,e,l);Te(e,m,f,h);for(const n of t)Te(e,e,n,void 0)}else Te(e,m,f,h)}else if(u(m)){const t=Pe(m);if(i(f)){const n=Ne(f);n.comma=t,Te(e,m,n)}else Te(e,m,f)}else if(void 0!==l.inlineTableStart&&l.inlineTableStart>0&&i(f)&&u(f.value)&&r(m)){et([...m.key.item.value,...f.key.value])<l.inlineTableStart?function(e,t,n,r){const o=t.key.item.value,a=[...o,...e.key.value],l=Oe(a);if(u(e.value))for(const t of e.value.items)c(t)&&i(t.item)&&Te(n,l,t.item,void 0);Te(n,n,l,void 0),Qe(t);const s=_t(l,n,r);for(const e of s)Te(n,n,e,void 0)}(f,m,e,l):Te(e,m,f)}else if(0===l.inlineTableStart&&i(f)&&u(f.value)&&n(m))Te(e,m,f,void 0,!0);else{let t=f;c(f)&&(r(m)||n(m))&&(t=f.item),Te(e,m,t)}}else if(function(e){return e.type===yt.Edit}(a)){let n,r=It(e,a.path),o=It(t,a.path);if(i(r)&&i(o))xt(r.value,o.value),n=r,r=r.value,o=o.value;else if(i(r)&&c(o)&&i(o.item))n=r,r=r.value,o=o.item.value;else if(c(r)&&i(o))n=r,r=r.item;else if(c(r)&&c(o)&&i(r.item)&&i(o.item))xt(r.item.value,o.item.value),n=r.item,r=r.item.value,o=o.item.value;else if(n=Ct(e,a.path),i(n)){const t=a.path.slice(0,-1),r=It(e,t);i(r)&&s(r.value)&&(n=r.value)}Se(e,n,r,o)}else if(St(a)){let t=Ct(e,a.path);i(t)&&(t=t.value);const n=It(e,a.path);ke(e,t,n)}else if(function(e){return e.type===yt.Move}(a)){let t=It(e,a.path);m(t)&&(t=t.item),i(t)&&(t=t.value);const n=t.items[a.from];ke(e,t,n),Te(e,t,n,a.to)}else if(function(e){return e.type===yt.Rename}(a)){let n=It(e,a.path.concat(a.from)),r=It(t,a.path.concat(a.to));m(n)&&(n=n.item),m(r)&&(r=r.item),Se(e,n,n.key,r.key)}})),Ae(e),e}(h,p,w,l);return{tomlString:lt(g.items,l),document:g}}function xt(e,t){if(a(e)&&a(t)&&we(e.raw)){const n=Ke(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=K.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=Re(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}if(u(e)&&u(t)){const n=Pe(e);if(t.items.length>0){t.items[t.items.length-1].comma=n}}}function _t(e,t,n){const r=[],o=(e,r)=>{var a;for(let l=e.items.length-1;l>=0;l--){const s=e.items[l];if(i(s)&&u(s.value)){const u=[...e.key.item.value,...s.key.value];if(et(u)<(null!==(a=n.inlineTableStart)&&void 0!==a?a:1)&&0!==n.inlineTableStart){const n=Oe(u);for(const e of s.value.items)c(e)&&i(e.item)&&Te(t,n,e.item,void 0);e.items.splice(l,1),Qe(e),r.push(n),o(n,r)}}}};return o(e,r),r}function Ut(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 Ot(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 Dt(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"}(yt||(yt={})),"function"==typeof SuppressedError&&SuppressedError;class Ft{constructor(e){vt.set(this,void 0),bt.set(this,void 0),$t.set(this,void 0),Ot(this,bt,e,"f"),Ot(this,vt,Array.from(G(e)),"f"),Ot(this,$t,Je.autoDetectFormat(e),"f")}get toTomlString(){return Ut(this,bt,"f")}get toJsObject(){return Lt(ft(Ut(this,vt,"f")))}get ast(){return Ut(this,vt,"f")}patch(e,t){const n=Ye(t,Ut(this,$t,"f")),{tomlString:r,document:o}=At(Ut(this,vt,"f"),e,n);Ot(this,vt,o.items,"f"),Ot(this,bt,r,"f")}update(e){if(e===this.toTomlString)return;const t=this.toTomlString.split(Ut(this,$t,"f").newLine),n=He(e),r=e.split(n);let o=0;for(;o<t.length&&o<r.length&&t[o]===r[o];)o++;let i=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]){i=t;break}}let a=o+1;const{truncatedAst:l,lastEndPosition:s}=function(e,t,n){const r={line:t,column:n},o=[];let i=null;for(const t of e){const e=Dt(t.loc.end,r)<0,n=Dt(t.loc.start,r)<0;if(!e){if(n&&!e)break;break}o.push(t),i=t.loc.end}return{truncatedAst:o,lastEndPosition:i}}(Ut(this,vt,"f"),a,i),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(Ut(this,$t,"f").newLine);Ot(this,vt,Array.from(function*(e,t){for(const t of e)yield t;const n=new F(C(t));for(;!n.next().done;){const e=ae(n,t);for(const t of e)yield t}}(l,d)),"f"),Ot(this,bt,e,"f"),Ot(this,$t,Je.autoDetectFormat(e),"f")}overwrite(e){e!==this.toTomlString&&(Ot(this,vt,Array.from(G(e)),"f"),Ot(this,bt,e,"f"),Ot(this,$t,Je.autoDetectFormat(e),"f"))}}function Lt(e){if(e instanceof Date)return new Date(e.getTime());if(Array.isArray(e))return e.map(Lt);if(e&&"object"==typeof e){const t={};for(const[n,r]of Object.entries(e))t[n]=Lt(r);return t}return e}function Mt(e){return ft(G(e),e)}function Kt(e,t){const n=Ye(t,Je.default());return lt(nt(e,n).items,n)}vt=new WeakMap,bt=new WeakMap,$t=new WeakMap;export{Ft as TomlDocument,Je as TomlFormat,Mt as parse,Et as patch,Kt 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.1",
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:example": "npm-run-all2 \"bench:* -- --example\"",
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
+ }