@decimalturn/toml-patch 3.2.0-dev → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +200 -0
- package/dist/patch-lite.js +20 -0
- package/dist/toml-patch.js +84 -0
- package/package.json +104 -13
- package/dist/dev/comment-alignment.js +0 -372
- package/dist/dev/comment-alignment.js.map +0 -1
- package/dist/dev/comment-ownership.js +0 -660
- package/dist/dev/comment-ownership.js.map +0 -1
- package/dist/dev/cst-source.js +0 -118
- package/dist/dev/cst-source.js.map +0 -1
- package/dist/dev/cst.js +0 -68
- package/dist/dev/cst.js.map +0 -1
- package/dist/dev/cursor.js +0 -66
- package/dist/dev/cursor.js.map +0 -1
- package/dist/dev/date-format.js +0 -196
- package/dist/dev/date-format.js.map +0 -1
- package/dist/dev/decode-utf8.js +0 -27
- package/dist/dev/decode-utf8.js.map +0 -1
- package/dist/dev/diff-lite.js +0 -123
- package/dist/dev/diff-lite.js.map +0 -1
- package/dist/dev/diff.js +0 -265
- package/dist/dev/diff.js.map +0 -1
- package/dist/dev/encode-lite.js +0 -193
- package/dist/dev/encode-lite.js.map +0 -1
- package/dist/dev/escape-preference.js +0 -166
- package/dist/dev/escape-preference.js.map +0 -1
- package/dist/dev/find-by-path.js +0 -111
- package/dist/dev/find-by-path.js.map +0 -1
- package/dist/dev/formatter.js +0 -298
- package/dist/dev/formatter.js.map +0 -1
- package/dist/dev/generate.js +0 -465
- package/dist/dev/generate.js.map +0 -1
- package/dist/dev/inline-comma-space.js +0 -13
- package/dist/dev/inline-comma-space.js.map +0 -1
- package/dist/dev/inline-format.js +0 -106
- package/dist/dev/inline-format.js.map +0 -1
- package/dist/dev/inline-layout.js +0 -107
- package/dist/dev/inline-layout.js.map +0 -1
- package/dist/dev/line-ending-backslash.js +0 -320
- package/dist/dev/line-ending-backslash.js.map +0 -1
- package/dist/dev/literal-string.js +0 -46
- package/dist/dev/literal-string.js.map +0 -1
- package/dist/dev/location.js +0 -104
- package/dist/dev/location.js.map +0 -1
- package/dist/dev/parse-error.js +0 -27
- package/dist/dev/parse-error.js.map +0 -1
- package/dist/dev/parse-js.js +0 -150
- package/dist/dev/parse-js.js.map +0 -1
- package/dist/dev/parse-string.js +0 -122
- package/dist/dev/parse-string.js.map +0 -1
- package/dist/dev/parse-toml.js +0 -714
- package/dist/dev/parse-toml.js.map +0 -1
- package/dist/dev/patch-lite.js +0 -4
- package/dist/dev/patch-lite2.js +0 -96
- package/dist/dev/patch-lite2.js.map +0 -1
- package/dist/dev/patch.js +0 -2652
- package/dist/dev/patch.js.map +0 -1
- package/dist/dev/smol-toml-date.js +0 -61
- package/dist/dev/smol-toml-date.js.map +0 -1
- package/dist/dev/to-js.js +0 -303
- package/dist/dev/to-js.js.map +0 -1
- package/dist/dev/to-toml.js +0 -874
- package/dist/dev/to-toml.js.map +0 -1
- package/dist/dev/tokenizer.js +0 -225
- package/dist/dev/tokenizer.js.map +0 -1
- package/dist/dev/toml-document.js +0 -220
- package/dist/dev/toml-document.js.map +0 -1
- package/dist/dev/toml-format.js +0 -528
- package/dist/dev/toml-format.js.map +0 -1
- package/dist/dev/toml-patch.js +0 -94
- package/dist/dev/toml-patch.js.map +0 -1
- package/dist/dev/traverse.js +0 -61
- package/dist/dev/traverse.js.map +0 -1
- package/dist/dev/truncate.js +0 -64
- package/dist/dev/truncate.js.map +0 -1
- package/dist/dev/update-order.js +0 -235
- package/dist/dev/update-order.js.map +0 -1
- package/dist/dev/utils.js +0 -244
- package/dist/dev/utils.js.map +0 -1
- package/dist/dev/writer.js +0 -758
- package/dist/dev/writer.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019–2025 Tim Hall
|
|
4
|
+
Copyright (c) 2025 Martin Leduc
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
<img src="assets/toml-patch-logo.png" alt="toml-patch logo" width="120"/>
|
|
2
|
+
|
|
3
|
+
# toml-patch
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@decimalturn/toml-patch)
|
|
6
|
+
[](https://jsr.io/@decimalturn/toml-patch)
|
|
7
|
+
[](https://github.com/DecimalTurn/toml-patch/actions/workflows/test-and-build.yml)
|
|
8
|
+
|
|
9
|
+
Patch, parse, and stringify [TOML](https://toml.io/en/) (v1.1.0) while preserving comments, whitespace and formatting.
|
|
10
|
+
|
|
11
|
+
This project started as a fork of the [original toml-patch](https://github.com/timhall/toml-patch) but has since evolved into a standalone project with significant improvements in reliability and features. We've added TOML v1.1 support, introduced new APIs like `TomlDocument` and `TomlFormat` classes, fixed numerous bugs through increase in testing namely with [toml-test](https://github.com/toml-lang/toml-test).
|
|
12
|
+
|
|
13
|
+
We hope that these improvements can be incorporated upstream one day if the original author returns, but until then, this project is the actively maintained version.
|
|
14
|
+
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
- [Installation](#installation)
|
|
18
|
+
- [API](#api)
|
|
19
|
+
- [Patch-lite](#patch-lite)
|
|
20
|
+
- [Comment ownership](#comment-ownership)
|
|
21
|
+
- [Date/time handling and Temporal](#datetime-handling--temporal)
|
|
22
|
+
- [Formatting](#formatting)
|
|
23
|
+
- [Changelog](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/CHANGELOG.md)
|
|
24
|
+
- [Contributing](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/CONTRIBUTING.md)
|
|
25
|
+
- [MIT License](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/LICENSE)
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
toml-patch is dependency-free and can be installed via your favorite package manager.
|
|
30
|
+
|
|
31
|
+
*Example with NPM*
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
$ npm install --save @decimalturn/toml-patch
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For the standalone lite distribution, install the `lite` npm dist-tag:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
$ npm install --save @decimalturn/toml-patch@lite
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For browser usage, you can use unpkg:
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<script type="module">
|
|
47
|
+
import * as TOML from 'https://unpkg.com/@decimalturn/toml-patch@v3.2.0/dist/toml-patch.js';
|
|
48
|
+
</script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
overwrite(tomlString: string): void
|
|
54
|
+
toml-patch provides a functional API for one-time operations and a document-oriented API for workflows that need multiple operations on the same TOML document.
|
|
55
|
+
|
|
56
|
+
See the [API reference](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/API.md) for `patch`, `parse`, `stringify` and the `TomlDocument` class.
|
|
57
|
+
|
|
58
|
+
For a quick start, patch an existing TOML string like this:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import { patch } from '@decimalturn/toml-patch';
|
|
62
|
+
|
|
63
|
+
const existing = 'title = "TOML example"\nowner.name = "Bob"\n';
|
|
64
|
+
const updated = patch(existing, {
|
|
65
|
+
title: 'TOML example',
|
|
66
|
+
owner: { name: 'Tim' }
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Patch-lite
|
|
71
|
+
|
|
72
|
+
The `patch-lite` subpath is a smaller, edit-only distribution for applications that only need to update existing TOML values, such as bumping a package version. It exposes the same `patch` name with a two-argument `(existing, updated)` signature:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
import { patch } from '@decimalturn/toml-patch/patch-lite';
|
|
76
|
+
|
|
77
|
+
const existing = 'version = "1.0.0"\n';
|
|
78
|
+
const updated = patch(existing, { version: '1.0.1' });
|
|
79
|
+
// updated === 'version = "1.0.1"\n'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The lite function edits existing primitive values only and preserves all source text outside the edited value, including comments, whitespace, line endings and a leading BOM. Added or removed keys, array length changes, reordering, renames, primitive/container type changes and unsupported value types throw before any output is produced. Use the full `patch()` for additions, removals, moves, renames and advanced formatting.
|
|
83
|
+
|
|
84
|
+
Unlike the full `patch()`, the lite distribution performs no encoding validation on its output: it does not reject strings containing unpaired UTF-16 surrogates, which cannot be represented as valid TOML/UTF-8. Use the full `patch()` when this validation is required.
|
|
85
|
+
|
|
86
|
+
The [Patch-lite guide](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Patch-Lite.md) lists every supported and rejected operation with its error code, the value-encoding rules that differ from the full `patch()`, and the measured size and throughput, so you can check whether the lite distribution covers your use case.
|
|
87
|
+
|
|
88
|
+
The lite distribution is also published as a standalone package under the `lite` npm dist-tag:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
npm install @decimalturn/toml-patch@lite
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Comment Ownership
|
|
95
|
+
|
|
96
|
+
When `patch()` removes or reorders an entry, any comment describing it (a same-line trailing
|
|
97
|
+
comment, or a line-comment directly above with no blank line in between) travels along with
|
|
98
|
+
it, instead of being left behind to describe whatever ends up in that spot. This applies to root
|
|
99
|
+
keys, `[table]`/`[[array-of-tables]]` blocks, and elements inside multi-line arrays and inline
|
|
100
|
+
tables.
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import * as TOML from '@decimalturn/toml-patch';
|
|
104
|
+
import { strict as assert } from 'assert';
|
|
105
|
+
|
|
106
|
+
const existing = `
|
|
107
|
+
x = 1 # a note about x
|
|
108
|
+
y = 2
|
|
109
|
+
`;
|
|
110
|
+
|
|
111
|
+
const patched = TOML.patch(existing, { y: 2 });
|
|
112
|
+
|
|
113
|
+
assert.strictEqual(patched, `
|
|
114
|
+
y = 2
|
|
115
|
+
`);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
See the [comment ownership guide](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Comment-Ownership.md) for the full behavior, including how a blank line opts a comment out of ownership and current scope limitations.
|
|
119
|
+
|
|
120
|
+
Note that `patch()` does not reorder entries by default.
|
|
121
|
+
To have it match the key order of the object you pass in, enable `updateOrder` in the [formatting options](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Formatting.md#updateorder).
|
|
122
|
+
|
|
123
|
+
## Date/Time Handling & Temporal
|
|
124
|
+
|
|
125
|
+
TOML date/time values are parsed into custom `Date` subclasses (`LocalDate`, `LocalTime`, `LocalDateTime`, `OffsetDateTime`) by default. Set `temporal: true` to receive [Temporal](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Temporal) objects instead. `stringify()` and `patch()` auto-detect Temporal objects and serialize them correctly.
|
|
126
|
+
|
|
127
|
+
### Enabling Temporal
|
|
128
|
+
|
|
129
|
+
The `temporal: true` option requires `Temporal` to be available in the runtime:
|
|
130
|
+
|
|
131
|
+
| Runtime | How to enable |
|
|
132
|
+
|---|---|
|
|
133
|
+
| **Node.js 26+** | Built-in — enable with `temporal: true` |
|
|
134
|
+
| **Node.js 20–24** | `node --harmony-temporal` flag |
|
|
135
|
+
| **Node.js 14–26** | [@js-temporal/polyfill](https://www.npmjs.com/package/@js-temporal/polyfill) |
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
import * as TOML from '@decimalturn/toml-patch';
|
|
139
|
+
|
|
140
|
+
// Node 26+ (native) or Node 20–24 with --harmony-temporal:
|
|
141
|
+
const obj = TOML.parse('d = 2024-01-15\n', { temporal: true });
|
|
142
|
+
// obj.d → Temporal.PlainDate
|
|
143
|
+
|
|
144
|
+
// All Node versions with the polyfill:
|
|
145
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
146
|
+
globalThis.Temporal = Temporal;
|
|
147
|
+
const obj2 = TOML.parse('d = 2024-01-15\n', { temporal: true });
|
|
148
|
+
// obj2.d → PlainDate (polyfill)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
> **Note:** Only offset-based timezones (`+05:30`, `Z`) are supported in TOML. IANA timezone annotations (e.g., `[Asia/Kolkata]`) will throw an error.
|
|
152
|
+
|
|
153
|
+
See the [date/time guide](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Dates.md) for details and examples.
|
|
154
|
+
|
|
155
|
+
## Formatting
|
|
156
|
+
|
|
157
|
+
The `TomlFormat` class controls how TOML documents are formatted during stringification and patching operations.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
class TomlFormat {
|
|
161
|
+
newLine: string
|
|
162
|
+
trailingNewline: number
|
|
163
|
+
trailingComma: boolean
|
|
164
|
+
bracketSpacing: boolean
|
|
165
|
+
inlineTableStart?: number
|
|
166
|
+
truncateZeroTimeInDates: boolean
|
|
167
|
+
useTabsForIndentation?: boolean
|
|
168
|
+
indentWidth: number
|
|
169
|
+
minimumDecimals?: number
|
|
170
|
+
leadingBom: boolean
|
|
171
|
+
updateOrder?: boolean
|
|
172
|
+
multilineTable: boolean | number | 'auto' | 'parent'
|
|
173
|
+
multilineArray: boolean | number | 'auto' | 'parent'
|
|
174
|
+
|
|
175
|
+
static default(): TomlFormat
|
|
176
|
+
static autoDetectFormat(tomlString: string): TomlFormat
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Start with `TomlFormat.default()` and override the options you need. e.g.:
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import { stringify, TomlFormat } from '@decimalturn/toml-patch';
|
|
184
|
+
|
|
185
|
+
const format = TomlFormat.default();
|
|
186
|
+
format.newLine = '\r\n';
|
|
187
|
+
format.trailingNewline = 0;
|
|
188
|
+
format.trailingComma = true;
|
|
189
|
+
format.bracketSpacing = false;
|
|
190
|
+
format.indentWidth = 4;
|
|
191
|
+
format.multilineTable = 'parent';
|
|
192
|
+
|
|
193
|
+
const toml = stringify({
|
|
194
|
+
title: 'My App',
|
|
195
|
+
tags: ['dev', 'config'],
|
|
196
|
+
database: { host: 'localhost', port: 5432 }
|
|
197
|
+
}, format);
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
See the [formatting reference](https://github.com/DecimalTurn/toml-patch/blob/v3.2.0/docs/Formatting.md) for the complete list of options, auto-detection behavior, `updateOrder` and more examples.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//! @decimalturn/toml-patch v3.2.0 - https://github.com/DecimalTurn/toml-patch - @license: MIT
|
|
2
|
+
function e(e){return e.type===`Document`}function t(e){return e.type===`Table`}function n(e){return e.type===`TableArray`}function r(e){return e.type===`KeyValue`}function i(e){return e.type===`String`}function a(e){return e.type===`Integer`}function o(e){return e.type===`Float`}function s(e){return e.type===`Boolean`}function c(e){return e.type===`DateTime`}function l(e){return e.type===`InlineArray`}function u(e){return e.type===`InlineItem`}function d(e){return e.type===`InlineTable`}function f(r){return e(r)||t(r)||n(r)||d(r)||l(r)}function p(e){return i(e)||a(e)||o(e)||s(e)||c(e)||l(e)||d(e)}let m,h;function g(e){if(m===e&&h!==void 0)return h;let t=te(e);return m=e,h=t,t}function ee(){m=void 0,h=void 0}function _(e,t){let n=Array.isArray(e)?e:te(e);if(n.length===0)return{line:1,column:t};let r=0,i=n.length-1;for(;r<i;){let e=r+i>>>1;n[e]<t?r=e+1:i=e}n[r]<t&&r++;let a=r+1;return{line:a,column:t-(n[a-2]+1||0)}}function v(e,t){let n=g(e),r=n[t.line-2]===void 0?0:n[t.line-2]+1,i=n[t.line-1]||e.length;return e.substring(r,i)}function te(e){let t=[];for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===10?t.push(n):r===13&&(e.charCodeAt(n+1)===10?(t.push(n+1),n++):t.push(n))}return t.push(e.length),t}function y(e){return{line:e.line,column:e.column}}function ne(e){return{start:y(e.start),end:y(e.end)}}var b=class extends Error{line;column;constructor(e,t,n){let r=`Error parsing TOML (${t.line}, ${t.column+1}):\n`;if(e){let n=v(e,t),i=`${re(t.column)}^`;n&&(r+=`${n}\n${i}\n`)}r+=n,super(r),this.line=t.line,this.column=t.column}};function re(e,t=` `){return t.repeat(e)}const ie=/[\w,\d,",',+,\-,_]/;function ae(){return{reference:null,mixed:!1}}function*oe(e,t){let n=e.length,r=0,i=t??ae(),a=[],o=(e,t)=>({start:_(a,e),end:_(a,t)});for(;r<n;){let t=e.charCodeAt(r);if((t<=31||t===127)&&t!==9&&t!==13&&t!==10)throw new b(e,_(a,r),`Control char 0x${t.toString(16).toUpperCase().padStart(2,`0`)} not allowed`);if(t===13&&(r+1>=n||e.charCodeAt(r+1)!==10))throw new b(e,_(a,r),`Standalone CR; must be CRLF or LF`);if(t!==32&&t!==9&&t!==13){if(t===10)s(r);else if(t===91||t===93)yield{type:`Bracket`,raw:e[r],loc:o(r,r+1)};else if(t===123||t===125)yield{type:`Curly`,raw:e[r],loc:o(r,r+1)};else if(t===61)yield{type:`Equal`,raw:`=`,loc:o(r,r+1)};else if(t===44)yield{type:`Comma`,raw:`,`,loc:o(r,r+1)};else if(t===46)yield{type:`Dot`,raw:`.`,loc:o(r,r+1)};else if(t===35)yield c();else{let t=se(e,r,`'`)||se(e,r,`"`);t?yield l(t):yield u()}}r++}function s(t){a.push(t);let n=t>0&&e.charCodeAt(t-1)===13?`\r
|
|
3
|
+
`:`
|
|
4
|
+
`;i.reference===null?i.reference=n:i.reference!==n&&(i.mixed=!0)}function c(){let t=r;for(;r+1<n;){let t=e.charCodeAt(r+1);if(t===10||t===13)break;r++;let n=e.charCodeAt(r);if((n<=31||n===127)&&n!==9)throw new b(e,_(a,r),`Control char 0x${n.toString(16).toUpperCase().padStart(2,`0`)} not allowed`)}return{type:`Comment`,raw:e.slice(t,r+1),loc:o(t,r+1)}}function l(t){let i=r,c=t+t+t;for(r+=3;r<n;){if(se(e,r,t)){let n=3;for(;e[r+n]===t;)n++;if(n>=6)throw new b(e,_(a,r),`Invalid multiline string: ${n} consecutive ${t} characters`);if(n===3){r+=2;break}r+=n-3,r+=2;break}let i=e.charCodeAt(r);if(i===13&&(r+1>=n||e.charCodeAt(r+1)!==10))throw new b(e,_(a,r),`Standalone CR in multiline string; must be CRLF or LF`);if((i<=31||i===127)&&i!==9&&i!==10&&i!==13){let n=t===`"`?`multiline basic strings`:`multiline literal strings`,o=`0x${i.toString(16).toUpperCase().padStart(2,`0`)}`,s=``;i===0?s=`Null`:i===127&&(s=`DEL`);let c=s?`${s} (${o}) not allowed in ${n}`:`Control char ${o} not allowed in ${n}`;throw new b(e,_(a,r),c)}i===10&&s(r),r++}if(r>=n){if(t===`"`){let t=0,i=n-1;for(;i>=0&&e[i]===`\\`;)t++,i--;if(t>0&&t%2!=0)throw new b(e,_(a,r),`Unterminated multiline ${c} (possible escape issue)`)}throw new b(e,_(a,r),`Unterminated multiline ${c}`)}return{type:`Literal`,raw:e.slice(i,r+1),loc:o(i,r+1)}}function u(){let t=e[r];if(!ie.test(t))throw new b(e,_(a,r),`Unexpected char "${t}"`);let i=r,s=t===`"`,c=t===`'`;for(;r<n&&!(r+1>=n);){let t=e.charCodeAt(r+1);if(!(s||c)&&(t===32||t===9||t===10||t===13||t===44||t===46||t===93||t===125||t===61||t===35))break;if(r++,!(s||c)){let t=e.charCodeAt(r);if(t<=31||t===127)throw new b(e,_(a,r),`Control char 0x${t.toString(16).toUpperCase().padStart(2,`0`)} not allowed in unquoted value`)}if(s||c){let t=e.charCodeAt(r);if((t<=31||t===127)&&t!==9){let n=s?`basic strings`:`literal strings`,i=`0x${t.toString(16).toUpperCase().padStart(2,`0`)}`,o=``;t===10?o=`Newline`:t===13?o=`Carriage return`:t===0?o=`Null`:t===127&&(o=`DEL`);let c=o?`${o} (${i}) not allowed in ${n}`:`Control char ${i} not allowed in ${n}`;throw new b(e,_(a,r),c)}}let i=e[r];if(i===`"`&&!c&&(s=!s),i===`'`&&!s&&(c=!c),r+1>=n)break;if(s&&i===`\\`){let t=e[r+1];(t===`"`||t===`\\`)&&r++}}if(s||c)throw new b(e,_(a,i),`Expected close of string with ${s?`"`:`'`}`);return{type:`Literal`,raw:e.slice(i,r+1),loc:o(i,r+1)}}}function se(e,t,n){if(!n||e[t]!==n||e[t+1]!==n||e[t+2]!==n)return!1;if(n===`'`)return n;let r=0,i=t-1;for(;i>=0&&e[i]===`\\`;)r++,i--;return(r===0||r%2==0)&&n}const 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 S(e){let t=e.charCodeAt(0);return t<128&&x[t]!==-1}function ce(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 le(e){return e.startsWith(`'''`)?de(e.slice(3,e.length-3)):e.startsWith(`'`)?e.slice(1,e.length-1):e.startsWith(`"""`)?ue(de(e.slice(3,e.length-3)),!0):e.startsWith(`"`)?ue(e.slice(1,e.length-1),!1):e}function ue(e,t){let n=e.length;if(!t&&e.indexOf(`\\`)===-1)return e;let r=[],i=0;for(let a=0;a<n;a++){if(e[a]!==`\\`)continue;if(a>i&&r.push(e.slice(i,a)),a++,a>=n)throw Error(`Trailing backslash`);let o=e[a];switch(o){case`b`:r.push(`\b`);break;case`t`:r.push(` `);break;case`n`:r.push(`
|
|
5
|
+
`);break;case`f`:r.push(`\f`);break;case`r`:r.push(`\r`);break;case`"`:r.push(`"`);break;case`\\`:r.push(`\\`);break;case`e`:r.push(`\x1B`);break;case`u`:{if(a+4>n||!S(e[a+1])||!S(e[a+2])||!S(e[a+3])||!S(e[a+4]))throw Error(`Invalid Unicode escape: \\u${e.slice(a+1,a+5)}`);let t=ce(e,a+1);if(t>=55296&&t<=57343)throw Error(`Invalid \\u${e.slice(a+1,a+5)}: surrogates not allowed`);r.push(String.fromCharCode(t)),a+=4;break}case`U`:{if(a+8>n)throw Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);for(let t=1;t<=8;t++)if(!S(e[a+t]))throw Error(`Invalid Unicode escape: \\U${e.slice(a+1,a+9)}`);let t=parseInt(e.slice(a+1,a+9),16);if(t>=55296&&t<=57343)throw Error(`Invalid \\U${e.slice(a+1,a+9)}: surrogates not allowed`);r.push(String.fromCodePoint(t)),a+=8;break}case`x`:{if(a+2>n||!S(e[a+1])||!S(e[a+2]))throw Error(`Invalid hex escape: \\x${e.slice(a+1,a+3)}`);let t=x[e.charCodeAt(a+1)]<<4|x[e.charCodeAt(a+2)];r.push(String.fromCharCode(t)),a+=2;break}default:if(t&&(o===`
|
|
6
|
+
`||o===`\r`||o===` `||o===` `)){let t=o===`
|
|
7
|
+
`||o===`\r`,r=a;for(;r<n&&(e[r]===` `||e[r]===` `||e[r]===`
|
|
8
|
+
`||e[r]===`\r`);)(e[r]===`
|
|
9
|
+
`||e[r]===`\r`)&&(t=!0),r++;if(!t)throw Error(`Invalid escape sequence: \\${o}`);a=r-1;break}throw Error(`Invalid escape sequence: \\${o}`)}i=a+1}return i===0?e:(i<n&&r.push(e.slice(i)),r.join(``))}function de(e){return e.charCodeAt(0)===10?e.slice(1):e.charCodeAt(0)===13&&e.charCodeAt(1)===10?e.slice(2):e}var fe=class{iterator;index;value;done;peeked;constructor(e){this.iterator=e,this.index=-1,this.value=void 0,this.done=!1,this.peeked=null}next(){if(this.done)return me();let e=this.peeked||this.iterator.next();return this.index+=1,this.value=e.value,this.done=e.done??!1,this.peeked=null,e}peek(){return this.done?me():(this.peeked||=this.iterator.next(),this.peeked)}[Symbol.iterator](){return this}};const pe=Object.freeze({value:void 0,done:!0});function me(){return pe}const he=new WeakMap;function ge(e,t){he.set(e,t)}function C(e){return{year:String(e.getUTCFullYear()).padStart(4,`0`),month:String(e.getUTCMonth()+1).padStart(2,`0`),day:String(e.getUTCDate()).padStart(2,`0`),hours:String(e.getUTCHours()).padStart(2,`0`),minutes:String(e.getUTCMinutes()).padStart(2,`0`),seconds:String(e.getUTCSeconds()).padStart(2,`0`),ms:e.getUTCMilliseconds()}}function w(e,t,n=/\.(\d+)\s*$/){if(t&&t.includes(`.`)){let r=t.match(n),i=r?r[1].length:3;return`.`+String(e).padStart(3,`0`).slice(0,i)}return e>0?`.`+String(e).padStart(3,`0`).replace(/0+$/,``):``}function _e(e){if(e===`Z`)return 0;let t=e[0]===`+`?1:-1,[n,r]=e.slice(1).split(`:`);return t*(parseInt(n)*60+parseInt(r))}var ve=class e{static IS_DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/;static IS_TIME_ONLY=/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_LOCAL_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/;static IS_OFFSET_DATETIME_T=/^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_OFFSET_DATETIME_SPACE=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})$/;static IS_FULL_DATE=/(\d{4})-(\d+)-(\d+)/;static IS_FULL_TIME=/(\d+):(\d+)(?::(\d+))?/;static createDateWithOriginalFormat(t,n){if(e.IS_DATE_ONLY.test(n)){if(t.getUTCHours()!==0||t.getUTCMinutes()!==0||t.getUTCSeconds()!==0||t.getUTCMilliseconds()!==0){if(t instanceof O)return t;let e=t.toISOString().replace(`Z`,``);return e=e.replace(/\.000$/,``),new D(e,!1)}let e=t.toISOString().split(`T`)[0];return new T(e)}if(e.IS_TIME_ONLY.test(n)){if(t instanceof E)return t;{let e=C(t),r=w(e.ms,n);return new E(`${e.hours}:${e.minutes}:${e.seconds}${r}`,n)}}if(e.IS_LOCAL_DATETIME_T.test(n)){let e=C(t),r=w(e.ms,n);return new D(`${e.year}-${e.month}-${e.day}T${e.hours}:${e.minutes}:${e.seconds}${r}`,!1,n)}if(e.IS_LOCAL_DATETIME_SPACE.test(n)){let e=C(t),r=w(e.ms,n);return new D(`${e.year}-${e.month}-${e.day} ${e.hours}:${e.minutes}:${e.seconds}${r}`,!0,n)}if(e.IS_OFFSET_DATETIME_T.test(n)||e.IS_OFFSET_DATETIME_SPACE.test(n)){let r=n.match(/([+-]\d{2}:\d{2}|[Zz])$/),i=r?r[1]===`z`?`Z`:r[1]:`Z`,a=e.IS_OFFSET_DATETIME_SPACE.test(n),o=C(new Date(t.getTime()+_e(i)*6e4)),s=a?` `:`T`,c=w(o.ms,n,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return new O(`${o.year}-${o.month}-${o.day}${s}${o.hours}:${o.minutes}:${o.seconds}${c}${i}`,a)}return t}},T=class extends Date{constructor(e){super(e)}toISOString(){let e=C(this);return`${e.year}-${e.month}-${e.day}`}},E=class extends Date{originalFormat;constructor(e,t){let n=e;/:\d{2}:\d{2}/.test(e)||(n=e+`:00`),super(`0000-01-01T${n}Z`),this.originalFormat=t}toISOString(){let e=C(this);return`${e.hours}:${e.minutes}:${e.seconds}${w(e.ms,this.originalFormat)}`}},D=class extends Date{useSpaceSeparator=!1;originalFormat;constructor(e,t=!1,n){let r=e;/\d{2}:\d{2}:\d{2}/.test(e)||(r=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,`$1:00$2`)),super(r.replace(` `,`T`)+`Z`),this.useSpaceSeparator=t,this.originalFormat=n||e}toISOString(){let e=C(this),t=this.useSpaceSeparator?` `:`T`;return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${w(e.ms,this.originalFormat)}`}},O=class extends Date{useSpaceSeparator=!1;originalOffset;originalFormat;constructor(e,t=!1){let n=e;/\d{2}:\d{2}:\d{2}/.test(e)||(n=e.replace(/(\d{2}:\d{2})([\s\-+TZ]|$)/,`$1:00$2`)),super(n.replace(` `,`T`)),this.useSpaceSeparator=t,this.originalFormat=e;let r=e.match(/([+-]\d{2}:\d{2}|[Zz])$/);r&&(this.originalOffset=r[1]===`z`?`Z`:r[1])}toISOString(){if(this.originalOffset){let e=C(new Date(this.getTime()+_e(this.originalOffset)*6e4)),t=this.useSpaceSeparator?` `:`T`,n=w(e.ms,this.originalFormat,/\.(\d+)(?:[Zz]|[+-]\d{2}:\d{2})\s*$/);return`${e.year}-${e.month}-${e.day}${t}${e.hours}:${e.minutes}:${e.seconds}${n}${this.originalOffset}`}let e=super.toISOString();return this.useSpaceSeparator?e.replace(`T`,` `):e}};const k=ve,ye=`true`,be=/e/i,A=/_/g,xe=/^[+-]?inf$/,Se=/^[+-]?nan$/,j=/^[+-]?0x/i;function Ce(e){return e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===95||e===45}const M=/^[+-]?0o/i,N=/^[+-]?0b/i;function P(e,t,n){for(let r=0;r<e.length;r++)if(!Ce(e.charCodeAt(r)))throw new b(t,{line:n.line,column:n.column+r},`Invalid bare key char '${e[r]}'`)}function we(e,t,n){if(e.startsWith(`"""`)||e.startsWith(`'''`))throw new b(t,n,`Multiline strings cannot be keys`)}function F(e,t,n){try{return le(e)}catch(e){throw new b(t,n,e.message)}}function I(e,t,n,r=!0){if(e.endsWith(`_`)||(r?/^[+-]?_/.test(e):e.startsWith(`_`)))throw new b(t,n,`Underscore must be between digits`);if(/__/.test(e))throw new b(t,n,`Consecutive underscores not allowed`)}function L(e,t,n,r){let i=e.replace(A,``);if(/^[+-]?0\d/.test(i)&&!j.test(e)&&!M.test(e)&&!N.test(e))throw new b(t,n,`Leading zeros are not allowed in ${r}`)}function Te(e,t,n,r){if(/_[eE]/.test(e))throw new b(n,r,`Underscore before exponent is not allowed`);if(/[eE][+-]?_/.test(e))throw new b(n,r,`Underscore at start of exponent is not allowed`);if(/[eE][+-]?$/.test(e))throw new b(n,r,`Invalid float "${t}": incomplete exponent`);if(/[eE][+-]?.*\./.test(e))throw new b(n,r,`Invalid float "${t}": decimal point not allowed in exponent`)}function Ee(e,t,n,r,i,a){if(e.length!==2)throw new b(i,a,`"${r}": hour must be 2 digits`);if(t.length!==2)throw new b(i,a,`"${r}": minute must be 2 digits`);if(n&&n.length!==2)throw new b(i,a,`"${r}": second must be 2 digits`)}function De(e,t,n,r,i,a){if(e!==void 0){let t=parseInt(e,10);if(t<0||t>23)throw new b(i,a,`"${r}": hour must be 00-23`)}if(t!==void 0){let e=parseInt(t,10);if(e<0||e>59)throw new b(i,a,`"${r}": minute must be 00-59`)}if(n!==void 0){let e=parseInt(n,10);if(e<0||e>60)throw new b(i,a,`"${r}": second must be 00-60`)}}function Oe(e,t,n){if(j.test(e)||M.test(e)||N.test(e))return;let r=e.replace(/^[+-]/,``).replace(/_/g,``);if(!/^[0-9]+$/.test(r))throw new b(t,n,`Invalid integer "${e}"`)}function R(e,t,n,r,i,a,o){let s=r[0]+r[1].toUpperCase();if(RegExp(`^[+\\-]?`+s.replace(/([[\]])/g,`\\$1`)).test(e))throw new b(t,n,`${a} prefix must be lowercase "${r}"`);if(RegExp(`^[+\\-]?`+r+`_`,`i`).test(e))throw new b(t,n,`Underscore must be between digits`);let c=RegExp(`^[+\\-]?`+r,`i`),l=e.replace(c,``);if(!l||l===`_`||l.startsWith(`_`))throw new b(t,n,`Incomplete ${a.toLowerCase()} number`);let u=l.replace(/_/g,``);if(!i.test(u))throw new b(t,n,o??`Invalid ${a.toLowerCase()} digits`);if(/^[+-]/.test(e))throw new b(t,n,`${a} numbers cannot have a sign prefix`)}function*ke(e,t){let n=new fe(oe(e,t));try{for(;!n.next().done;){let t=B(n,e);for(let e of t)yield e}}finally{ee()}}function z(e){return{type:`Comment`,loc:e.value.loc,raw:e.value.raw}}function Ae(e,t){let n=!e.peek().done&&e.peek().value.type===`Bracket`?`TableArray`:`Table`,r=n===`Table`;if(r&&e.value.raw!==`[`)throw new b(t,e.value.loc.start,`Expected table opening "[", found ${e.value.raw}`);if(!r){let n=e.peek();if(n.done)throw new b(t,e.value.loc.start,`Expected "[[" for Array of Tables, found end of input`);if(e.value.raw!==`[`||n.value.raw!==`[`)throw new b(t,e.value.loc.start,`Expected "[[", found ${e.value.raw+n.value.raw}`);let r=e.value,i=n.value;if(r.loc.end.line!==i.loc.start.line||r.loc.end.column!==i.loc.start.column)throw new b(t,r.loc.start,`"[[" brackets must be adjacent (no whitespace)`)}let i=r?{type:`TableKey`,loc:e.value.loc}:{type:`TableArrayKey`,loc:e.value.loc};if(e.next(),n===`TableArray`&&e.next(),e.done)throw new b(t,i.loc.start,`Expected table key, reached end of file`);if(e.value.type===`Bracket`&&e.value.raw===`]`)throw new b(t,e.value.loc.start,n===`TableArray`?`Array of Tables header [[]] requires a table name`:`Table header [] requires a table name`);let a=e.value.raw;we(a,t,e.value.loc.start),a.startsWith(`"`)||a.startsWith(`'`)||P(a,t,e.value.loc.start);let o;for(o=[F(e.value.raw,t,e.value.loc.start)],i.item={type:`Key`,loc:e.value.loc,raw:e.value.raw,value:o};!e.peek().done&&e.peek().value.type===`Dot`;){e.next();let n=e.value;e.next();let r=e.value.raw;r.startsWith(`"`)||r.startsWith(`'`)||P(r,t,e.value.loc.start);let a=` `.repeat(n.loc.start.column-i.item.loc.end.column),o=` `.repeat(e.value.loc.start.column-n.loc.end.column);i.item.loc.end=e.value.loc.end,i.item.raw+=`${a}.${o}${e.value.raw}`;try{i.item.value.push(le(e.value.raw))}catch(n){let r=n;throw new b(t,e.value.loc.start,r.message)}}if(e.next(),!e.done){let n=i.loc.start.line;if(e.value.loc.start.line!==n)throw new b(t,e.value.loc.start,r?`Table header must be single-line`:`Array of Tables header must be single-line`)}if(r&&(e.done||e.value.raw!==`]`))throw new b(t,e.done?i.item.loc.end:e.value.loc.start,`Expected table closing "]", found ${e.done?`end of file`:e.value.raw}`);if(!r&&(e.done||e.peek().done||e.value.raw!==`]`||e.peek().value.raw!==`]`))throw new b(t,e.done||e.peek().done?i.item.loc.end:e.value.loc.start,`Expected "]]" closing, found ${e.done||e.peek().done?`end of file`:e.value.raw+e.peek().value.raw}`);if(!r){let n=e.value,r=e.peek().value;if(n.loc.end.line!==r.loc.start.line||n.loc.end.column!==r.loc.start.column)throw new b(t,n.loc.start,`"]]" brackets must be adjacent (no whitespace)`)}if(r||e.next(),i.loc.end=e.value.loc.end,!e.peek().done){let n=e.peek().value;if(n.loc.start.line===i.loc.end.line&&n.type!==`Comment`)throw new b(t,n.loc.start,`Extra content after ${r?`table`:`Array of Tables`} header`)}let s=[];for(;!e.peek().done&&e.peek().value.type!==`Bracket`;){e.next();let n=B(e,t);for(let e=0;e<n.length;e++)s.push(n[e])}return{type:r?`Table`:`TableArray`,loc:{start:y(i.loc.start),end:s.length?y(s[s.length-1].loc.end):y(i.loc.end)},key:i,items:s}}function je(e,t){let n=F(e.value.raw,t,e.value.loc.start);return{type:`String`,loc:e.value.loc,raw:e.value.raw,value:n}}function Me(e){return{type:`Boolean`,loc:e.value.loc,value:e.value.raw===ye}}function Ne(e,t){let n=e.value.loc,r=e.value.raw,i;if(!e.peek().done&&e.peek().value.type===`Literal`&&k.IS_FULL_DATE.test(r)&&/^\d/.test(e.peek().value.raw)&&k.IS_FULL_TIME.test(e.peek().value.raw)){let t=n.start;e.next(),n={start:t,end:e.value.loc.end},r+=` ${e.value.raw}`}if(!e.peek().done&&e.peek().value.type===`Dot`){let i=n.start;if(e.next(),e.peek().done||e.peek().value.type!==`Literal`)throw new b(t,e.value.loc.end,`Expected fractional value for DateTime`);e.next(),n={start:i,end:e.value.loc.end},r+=`.${e.value.raw}`}if(Fe(r,t,n.start),k.IS_FULL_DATE.test(r))i=k.IS_DATE_ONLY.test(r)?new T(r):k.IS_LOCAL_DATETIME_T.test(r)?new D(r,!1):k.IS_LOCAL_DATETIME_SPACE.test(r)?new D(r,!0):k.IS_OFFSET_DATETIME_T.test(r)?new O(r,!1):k.IS_OFFSET_DATETIME_SPACE.test(r)?new O(r,!0):new Date(r.replace(` `,`T`));else if(k.IS_TIME_ONLY.test(r))i=new E(r,r);else{let[e]=new Date().toISOString().split(`T`);i=new Date(`${e}T${r}`)}return{type:`DateTime`,loc:n,raw:r,value:i}}function Pe(e,t){return t===2?e%4==0&&e%100!=0||e%400==0?29:28:[31,28,31,30,31,30,31,31,30,31,30,31][t-1]}function Fe(e,t,n){if(/\.([Zz]|[+-])/.test(e))throw new b(t,n,`"${e}": fractional seconds needs digit after dot`);if(/[+-]$/.test(e))throw new b(t,n,`"${e}": offset needs HH:MM`);let r=/\d{2}:\d{2}/.test(e)?e.match(/([+-])(\d+)(:?)(\d*)$/):null;if(r){let e=r[0],i=r[2],a=r[3],o=r[4];if(a!==`:`)throw new b(t,n,`Offset "${e}": missing colon separator`);if(i.length!==2)throw new b(t,n,`Offset "${e}": hour must be 2 digits`);if(!o||o.length===0)throw new b(t,n,`Offset "${e}": minute required`);if(o.length!==2)throw new b(t,n,`Offset "${e}": minute must be 2 digits`);let s=parseInt(i,10);if(s<0||s>23)throw new b(t,n,`Offset "${e}": hour must be 00-23`);let c=parseInt(o,10);if(c<0||c>59)throw new b(t,n,`Offset "${e}": minute must be 00-59`)}if(!/^\d{4}-\d{2}-\d{2}(?:[Tt ]\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?(?:[Zz]|[+-]\d{2}:\d{2})?)?$/.test(e)&&!/^\d{2}:\d{2}(?::\d{2})?(?:\.\d+)?$/.test(e))throw/^\d{4}-\d{2}-\d{2}T$/.test(e)?new b(t,n,`"${e}": 'T' requires time component`):/^\d{4}-\d{2}-\d{2}[a-su-zA-SU-Z]/.test(e)?new b(t,n,`Invalid date "${e}": unexpected character after date`):/^\d{4}-\d{2}-\d{2}\d{2}:\d{2}/.test(e)?new b(t,n,`"${e}": missing 'T' or space separator`):new b(t,n,`Invalid datetime "${e}"`);let i=e.match(/^(\d+)-/);if(i&&i[1].length!==4)throw new b(t,n,`"${e}": year must be 4 digits`);let a=e.match(/^(\d+)-(\d+)-(\d+)/);if(a){let[,,r,i]=a;if(r.length!==2)throw new b(t,n,`"${e}": month must be 2 digits`);if(i.length!==2)throw new b(t,n,`"${e}": day must be 2 digits`)}let o=e.match(/[T ](\d+):(\d+)(?::(\d+))?/);if(o){let[,r,i,a]=o;Ee(r,i,a,e,t,n)}let s=e.match(/^(\d+):(\d+)(?::(\d+))?/);if(s&&!a){let[,r,i,a]=s;Ee(r,i,a,e,t,n)}let c=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?/),l=e.match(/^(\d{2}):(\d{2})(?::(\d{2}))?/);if(c){let[,r,i,a,o,s,l]=c,u=parseInt(i,10);if(u<1||u>12)throw new b(t,n,`"${e}": month must be 01-12`);let d=parseInt(a,10);if(d<1||d>31)throw new b(t,n,`"${e}": day must be 01-31`);if(d>Pe(parseInt(r,10),u))throw new b(t,n,`"${e}": day ${a} invalid for ${r}-${i}`);De(o,s,l,e,t,n)}else if(l){let[,r,i,a]=l;De(r,i,a,e,t,n)}}function Ie(e,t){let n=e.value.loc,r=e.value.raw,i;if(xe.test(r))i=r.startsWith(`-`)?-1/0:1/0;else if(Se.test(r)){let e=new Float64Array(1),t=new DataView(e.buffer);r.startsWith(`-`)?(t.setUint32(0,0,!0),t.setUint32(4,4294443008,!0)):(t.setUint32(0,0,!0),t.setUint32(4,2146959360,!0)),i=e[0];let a=r.startsWith(`+`)?`+`:r.startsWith(`-`)?`-`:void 0;return{type:`Float`,loc:n,raw:r,value:i,nanSign:a}}else if(!e.peek().done&&e.peek().value.type===`Dot`){let a=n.start;{if(be.test(r)&&!j.test(r))throw new b(t,n.start,`Float "${r}": dot after exponent`);let e=r;L(e,t,n.start,`the integer part of a float`);let i=e.replace(/^[+-]/,``);if(i===``||i===`_`)throw new b(t,n.start,`Float: digit required before dot`);I(e,t,n.start)}if(e.next(),e.peek().done||e.peek().value.type!==`Literal`)throw new b(t,e.value.loc.end,`Expected fraction value for Float`);e.next(),r+=`.${e.value.raw}`,n={start:a,end:e.value.loc.end};{let n=e.value.raw;if(!/^\d/.test(n))throw new b(t,e.value.loc.start,`Float: fraction must start with digit, found "${n}"`);I(n,t,e.value.loc.start,!1),Te(n,r,t,e.value.loc.start)}i=Number(r.replace(A,``))}else{if(I(r,t,n.start),Te(r,r,t,n.start),!e.peek().done&&e.peek().value.type===`Dot`)throw new b(t,e.peek().value.loc.start,`Float "${r}.": dot after exponent`);L(r,t,n.start,`the integer part of a float`),i=Number(r.replace(A,``))}if(Number.isNaN(i)&&!Se.test(r))throw new b(t,n.start,`Invalid float "${r}"`);return{type:`Float`,loc:n,raw:r,value:i}}function Le(e,t){let n=e.value.raw,r=e.value.loc;if(/^\d{1,}-\d{1,}/.test(n)||/^\d{1,}:\d{1,}/.test(n)||/^\d{6}-\d{2}$/.test(n))throw new b(t,r.start,`Invalid integer "${n}"`);if(n===`-0`||n===`+0`)return{type:`Integer`,loc:r,raw:n,value:0};if(/^[+-]{2,}/.test(n))throw new b(t,r.start,`Double sign is not allowed in integers`);L(n,t,r.start,`decimal integers`),I(n,t,r.start),Oe(n,t,r.start);let i=10;j.test(n)?(i=16,R(n,t,r.start,`0x`,/^[0-9a-fA-F]+$/,`Hexadecimal`)):M.test(n)?(i=8,R(n,t,r.start,`0o`,/^[0-7]+$/,`Octal`,`Invalid octal digits (must be 0-7)`)):N.test(n)&&(i=2,R(n,t,r.start,`0b`,/^[01]+$/,`Binary`,`Invalid binary digits (must be 0 or 1)`));let a=parseInt(n.replace(A,``).replace(M,``).replace(N,``),i);if(Number.isNaN(a))throw new b(t,r.start,`Invalid integer "${n}"`);return{type:`Integer`,loc:r,raw:n,value:a}}function B(e,t){if(e.value.type===`Comment`)return[z(e)];if(e.value.type===`Bracket`)return[Ae(e,t)];if(e.value.type===`Literal`)return Re(e,t);throw e.value.type===`Equal`?new b(t,e.value.loc.start,`Missing key before '='`):new b(t,e.value.loc.start,`Unexpected token "${e.value.type}"`)}function Re(e,t){let n=e.value.raw;if(n.endsWith(`:`))throw new b(t,{line:e.value.loc.start.line,column:e.value.loc.start.column+[...n].length-1},`Use '=' to separate keys and values, not ':'`);we(n,t,e.value.loc.start),n.startsWith(`"`)||n.startsWith(`'`)||P(n,t,e.value.loc.start);let r;r=[F(e.value.raw,t,e.value.loc.start)];let i={type:`Key`,loc:e.value.loc,raw:e.value.raw,value:r};for(;!e.peek().done&&e.peek().value.type===`Dot`;){e.next();let n=e.value;e.next();let r=e.value.raw;we(r,t,e.value.loc.start),r.startsWith(`"`)||r.startsWith(`'`)||P(r,t,e.value.loc.start);let a=v(t,i.loc.end),o=v(t,n.loc.end),s=a.slice(i.loc.end.column,n.loc.start.column),c=o.slice(n.loc.end.column,e.value.loc.start.column);i.loc.end=e.value.loc.end,i.raw+=`${s}.${c}${e.value.raw}`,i.value.push(F(e.value.raw,t,e.value.loc.start))}if(e.next(),!e.done&&e.value.loc.start.line!==i.loc.end.line)throw new b(t,e.value.loc.start,`"=" must be on same line as key`);if(e.done||e.value.type!==`Equal`)throw!e.done&&e.value.raw===`:`?new b(t,e.value.loc.start,`Use '=' to separate keys and values, not ':'`):new b(t,e.done?i.loc.end:e.value.loc.start,`Expected "=" for key-value`);let a=e.value.loc.start.column,o=e.value.loc.start.line;if(e.next(),e.done)throw new b(t,i.loc.start,`Expected value, reached EOF`);if(e.value.loc.start.line!==o)throw new b(t,e.value.loc.start,`Value must be on same line as '='`);if(e.done)throw new b(t,i.loc.start,`Expected value for key-value`);let s=ze(e,t),c=s[0];if(!e.peek().done){let n=e.peek().value;if(n.type===`Dot`&&n.loc.start.line===c.loc.end.line&&(c.type===`Float`||c.type===`Integer`))throw new b(t,n.loc.start,`Invalid number: multiple decimal points not allowed`);if((n.type===`Literal`||n.type===`Bracket`)&&n.loc.start.line===c.loc.end.line)throw new b(t,n.loc.start,`Key/value pairs must be separated by a newline`)}return s[0]={type:`KeyValue`,key:i,value:c,loc:{start:y(i.loc.start),end:y(c.loc.end)},equals:a},s}function ze(e,t){if(e.value.type===`Literal`){let n=e.value.raw;return n[0]===`"`||n[0]===`'`?[je(e,t)]:n===ye||n===`false`?[Me(e)]:/^\d/.test(n)&&(/^\d{1,}-\d{1,}/.test(n)||/^\d{1,}:\d{1,}/.test(n))?[Ne(e,t)]:!e.peek().done&&e.peek().value.type===`Dot`||xe.test(n)||Se.test(n)||be.test(n)&&!j.test(n)?[Ie(e,t)]:[Le(e,t)]}if(e.value.type===`Curly`){let[n,r]=Ve(e,t);return[n,...r]}if(e.value.type===`Bracket`){let[n,r]=He(e,t);return[n,...r]}throw e.value.type===`Dot`?new b(t,e.value.loc.start,`Number cannot start with a dot`):new b(t,e.value.loc.start,`Unrecognized token type`)}function Be(e){for(let t=1;t<e.length;t++){let n=e[t-1],r=e[t];if(n.loc.end.line===r.loc.start.line){let e=r.loc.start.column-n.loc.end.column;if(e>=1)return e}}}function Ve(e,t){if(e.value.raw!==`{`)throw new b(t,e.value.loc.start,`Expected "{" for inline table`);let n={type:`InlineTable`,loc:e.value.loc,items:[]},r=[];for(e.next();!e.done&&(e.value.type!==`Curly`||e.value.raw!==`}`);){if(e.value.type===`Comment`){r.push(z(e)),e.next();continue}if(e.value.type===`Comma`){let r=n.items[n.items.length-1];if(!r)throw new b(t,e.value.loc.start,`Leading comma in inline table`);if(r.comma)throw new b(t,e.value.loc.start,`Consecutive commas in inline table`);r.comma=!0,r.loc.end=e.value.loc.start,e.next();continue}let i=n.items[n.items.length-1];if(i&&!i.comma)throw new b(t,e.value.loc.start,`Missing comma between inline table items`);let a=B(e,t),o=a[0];if(o.type===`KeyValue`){n.items.push({type:`InlineItem`,loc:ne(o.loc),item:o,comma:!1});for(let e=1;e<a.length;e++)r.push(a[e])}e.next()}if(e.done||e.value.type!==`Curly`||e.value.raw!==`}`)throw new b(t,e.done?n.loc.start:e.value.loc.start,`Expected "}"`);n.loc.end=e.value.loc.end;{let e=Be(n.items);e!==void 0&&ge(n,e)}return[n,r]}function He(e,t){if(e.value.raw!==`[`)throw new b(t,e.value.loc.start,`Expected "[" for inline array`);let n={type:`InlineArray`,loc:e.value.loc,items:[]},r=[];for(e.next();!e.done&&(e.value.type!==`Bracket`||e.value.raw!==`]`);){if(e.value.type===`Comma`){let r=n.items[n.items.length-1];if(!r)throw new b(t,e.value.loc.start,`Leading comma in array`);if(r.comma)throw new b(t,e.value.loc.start,`Consecutive commas in array`);r.comma=!0,r.loc.end=e.value.loc.start}else if(e.value.type===`Comment`)r.push(z(e));else{let i=n.items[n.items.length-1];if(i&&!i.comma)throw new b(t,e.value.loc.start,`Missing comma between array elements`);let a=ze(e,t),o=a[0];n.items.push({type:`InlineItem`,loc:ne(o.loc),item:o,comma:!1});for(let e=1;e<a.length;e++)r.push(a[e])}e.next()}if(e.done||e.value.type!==`Bracket`||e.value.raw!==`]`)throw new b(t,e.done?n.loc.start:e.value.loc.start,`Expected "]"`);n.loc.end=e.value.loc.end;{let e=Be(n.items);e!==void 0&&ge(n,e)}return[n,r]}function V(e){return e[e.length-1]}function H(){return Object.create(null)}function Ue(e,t){return e===t&&(typeof e!=`number`||Object.is(e,t))}const We=new DataView(new ArrayBuffer(8));function U(e){return Number.isNaN(e)?(We.setFloat64(0,e,!0),!!(We.getUint32(4,!0)&2147483648)):!1}function W(e){return Object.prototype.toString.call(e)===`[object Date]`}const Ge=new Set([`Temporal.PlainDate`,`Temporal.PlainTime`,`Temporal.PlainDateTime`,`Temporal.ZonedDateTime`,`PlainDate`,`PlainTime`,`PlainDateTime`,`ZonedDateTime`]);function G(e){var t;return typeof e==`object`&&!!e&&Ge.has((t=e.constructor)==null?void 0:t.name)&&typeof e.equals==`function`}function Ke(e){return e&&typeof e==`object`&&!W(e)&&!G(e)&&!Array.isArray(e)}function qe(e,t){return t in e}function K(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Je(e,t){return G(e)&&G(t)?e.toString()===t.toString():W(e)&&W(t)?e.toISOString()===t.toISOString():!1}function q(e){let t=[],n=new WeakSet,r=[{value:e}];for(;r.length>0;){let e=r.pop();if(`text`in e){t.push(e.text),`leave`in e&&n.delete(e.leave);continue}let i=e.value;if(Ke(i)){if(n.has(i))throw TypeError(`Cannot stableStringify a circular structure`);n.add(i);let e=Object.keys(i).sort();t.push(`{`),r.push({leave:i,text:`}`});for(let t=e.length-1;t>=0;t--){let n=e[t];t<e.length-1&&r.push({text:`,`}),r.push({value:i[n]}),r.push({text:`:`}),r.push({text:JSON.stringify(n)})}}else if(Array.isArray(i)){if(n.has(i))throw TypeError(`Cannot stableStringify a circular structure`);n.add(i),t.push(`[`),r.push({leave:i,text:`]`});for(let e=i.length-1;e>=0;e--)e<i.length-1&&r.push({text:`,`}),r.push({value:i[e]})}else if(G(i))t.push(JSON.stringify(i.toString()));else if(W(i))t.push(JSON.stringify(i.toISOString()));else if(typeof i==`bigint`)t.push(i.toString()+`n`);else if(typeof i==`number`&&!Number.isFinite(i)){let e=Number.isNaN(i)?U(i)?`-`:`+`:i<0?`-`:`+`;t.push(`${e}${String(i)}`)}else typeof i==`number`&&Object.is(i,-0)?t.push(`-0`):t.push(JSON.stringify(i))}return t.join(``)}typeof String.prototype.isWellFormed==`function`&&String.prototype.isWellFormed;function Ye(e,t=`asNeeded`){let n=e.replace(/_/g,``),r=n;if(/^[+-]?0x/i.test(n)||/^[+-]?0o/i.test(n)||/^[+-]?0b/i.test(n)){let e=n[0]===`+`||n[0]===`-`?n[0]:``;r=e+n.slice(+!!e).toLowerCase()}let i;try{i=BigInt(r)}catch{return Number(n)}return t===!0?i:t===!1||i>=BigInt(-(2**53-1))&&i<=BigInt(2**53-1)?Number(i):i}function Xe(e,t,n){for(let r of e.items){let e=r.item;if(e.value.type===`InlineTable`){let r=t.concat(e.key.value);n.add(J(r)),Xe(e.value,r,n)}}}function Ze(e){var t,n,r,i,a,o;if((t=e.constructor)!=null&&(t=t.name)!=null&&(n=t.startsWith)!=null&&n.call(t,`Temporal.`)||((r=e.constructor)==null?void 0:r.name)===`PlainDate`||((i=e.constructor)==null?void 0:i.name)===`PlainTime`||((a=e.constructor)==null?void 0:a.name)===`PlainDateTime`||((o=e.constructor)==null?void 0:o.name)===`ZonedDateTime`)return e;let s=globalThis.Temporal;if(e instanceof T)return s.PlainDate.from(e.toISOString());if(e instanceof E)return s.PlainTime.from(e.toISOString());if(e instanceof D)return s.PlainDateTime.from(e.toISOString().replace(` `,`T`));if(e instanceof O){let t=e.toISOString().replace(` `,`T`),n=t.match(/([+-]\d{2}:\d{2}|Z)$/),r=n?n[1]:`Z`,i=t.replace(/([+-]\d{2}:\d{2}|Z)$/,``),a=r===`Z`?`+00:00`:r;return s.ZonedDateTime.from(`${i}${r}[${a}]`)}return s.PlainDateTime.from(e.toISOString().replace(`Z`,``))}function Qe(e,t=``,n={}){let{integersAsBigInt:r=`asNeeded`,temporal:i=!1}=n,a=H(),o=new Set,s=new Set,c=new Set,l=new Set,u=new Set,d=a,f=[],p={tables:o,table_arrays:s,defined:c,implicit_tables:l,inline_tables:u};for(let t of e)switch(t.type){case`Table`:m(t);for(let e of t.items)e.type===`KeyValue`&&g(e);break;case`TableArray`:h(t);for(let e of t.items)e.type===`KeyValue`&&g(e);break;case`KeyValue`:g(t)}return a;function m(e){let n=e.key.item.value;try{et(a,[],n,e.type,p)}catch(n){let r=n;throw new b(t,e.key.loc.start,r.message)}let r=J(n);o.add(r),c.add(r),d=tt(a,n),f=n}function h(e){let n=e.key.item.value;try{et(a,[],n,e.type,p)}catch(n){let r=n;throw new b(t,e.key.loc.start,r.message)}let r=J(n);s.add(r),c.add(r),d=nt(a,n),f=n}function g(e){let n=e.key.value;try{et(d,f,n,e.type,p)}catch(n){let r=n;throw new b(t,e.key.loc.start,r.message)}if(n.length>1)for(let e=1;e<n.length;e++){let t=J(f.concat(n.slice(0,e)));l.add(t),c.add(t)}let a;try{a=$e(e.value,{integersAsBigInt:r,temporal:i})}catch(n){let r=n;throw new b(t,e.value.loc.start,r.message)}if(e.value.type===`InlineTable`){let t=f.concat(n);u.add(J(t)),Xe(e.value,t,u)}let o=n.length>1?tt(d,n.slice(0,-1)):d;o[V(n)]=a,c.add(J(f.concat(n)))}}function $e(e,t={}){let{integersAsBigInt:n=`asNeeded`,temporal:r=!1}=t;switch(e.type){case`InlineTable`:let t=H(),i=new Set,a=new Map;return e.items.forEach(({item:e})=>{let o=e.key.value,s=$e(e.value,{integersAsBigInt:n,temporal:r}),c=at(o),l=J(o);if(i.has(l))throw Error(`Duplicate key "${c}" in inline table`);for(let e=1;e<o.length;e++){let t=at(o.slice(0,e));if(i.has(J(o.slice(0,e))))throw Error(`Key "${c}" conflicts with key: "${t}"`)}if(a.has(l)){let e=a.get(l);throw Error(`Key "${c}" conflicts with key: "${e}"`)}i.add(l);for(let e=1;e<o.length;e++){let t=J(o.slice(0,e));a.has(t)||a.set(t,c)}let u=o.length>1?tt(t,o.slice(0,-1)):t;u[V(o)]=s}),t;case`InlineArray`:return e.items.map(e=>$e(e.item,{integersAsBigInt:n,temporal:r}));case`DateTime`:if(r){if(globalThis.Temporal===void 0)throw Error(`Temporal API is not available in this runtime. Set temporal: false or use a runtime with Temporal support.`);return Ze(e.value)}return e.value;case`String`:return e.value;case`Integer`:return Ye(e.raw,n);case`Float`:case`Boolean`:return e.value;default:throw Error(`Unrecognized value type "${e.type}"`)}}function et(e,t,n,r,i){let a=t.length>0?[...t]:[],o=Array(n.length),s=Array(n.length);for(let e=0;e<n.length;e++)a.push(n[e]),o[e]=at(a),s[e]=J(a);let c=o[n.length-1],l=s[n.length-1];if(r===`KeyValue`&&n.length>1)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.inline_tables.has(s[e-1]))throw Error(`Cannot extend inline table at ${t}`)}if((r===`Table`||r===`TableArray`)&&i.inline_tables.has(l))throw Error(`Cannot extend inline table at ${c}`);if(r===`Table`||r===`TableArray`)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.inline_tables.has(s[e-1]))throw Error(`Cannot extend inline table at ${t}`)}if(r===`KeyValue`&&n.length>1)for(let e=1;e<n.length;e++){let t=o[e-1];if(i.table_arrays.has(s[e-1]))throw Error(`Cannot traverse Array of Tables at ${t}`)}if((r===`Table`||r===`TableArray`)&&i.implicit_tables.has(l))throw Error(`Implicit table already defined: ${c}`);if(r===`KeyValue`&&i.implicit_tables.has(l))throw Error(`Table already defined: ${c}`);if(r===`KeyValue`&&n.length>1)for(let e=1;e<=n.length;e++){let t=o[e-1];if(i.tables.has(s[e-1]))throw Error(`Cannot extend explicit table ${t} with dotted keys`)}let u=0;for(let t of n){if(!qe(e,t))return;if(it(e[t]))throw Error(`Value already defined for ${o[u]}`);let r=o[u];if(Array.isArray(e[t])&&!i.table_arrays.has(s[u]))throw Error(`Cannot add to static array at ${r}`);let a=u++<n.length-1;e=Array.isArray(e[t])&&a?V(e[t]):e[t]}let d=c;if(e&&r===`Table`&&i.defined.has(l)||e&&r===`KeyValue`&&n.length===1&&i.defined.has(l)&&!it(e))throw Error(`Table already defined: ${d}`);if(e&&r===`TableArray`&&!i.table_arrays.has(l))throw Error(`Cannot add Array of Tables to table at ${d}`)}function tt(e,t){let n=rt(e,t.slice(0,-1)),r=V(t);return n[r]||(n[r]=H()),n[r]}function nt(e,t){let n=rt(e,t.slice(0,-1)),r=V(t);n[r]||(n[r]=[]);let i=H();return n[V(t)].push(i),i}function rt(e,t){return t.reduce((e,t)=>(e[t]||(e[t]=H()),Array.isArray(e[t])?V(e[t]):e[t]),e)}function it(e){return typeof e!=`object`&&!W(e)}function at(e){return e.join(`.`)}function J(e){return JSON.stringify(e)}var Y=class extends Error{code;path;constructor(e,t,n){super(n),this.name=`PatchLiteError`,this.code=e,this.path=t}};function X(e){let t=``;for(let n of e)t+=typeof n==`number`?`[${n}]`:t?`.${n}`:n;return t||`(root)`}function ot(e){let t=typeof e;return t===`string`||t===`boolean`||t===`number`||t===`bigint`}function Z(e){if(e===null)return`null`;if(Array.isArray(e))return`array`;if(e instanceof Date)return`date`;let t=typeof e;return t===`object`?`table`:t}function st(e,t){return U(e)===U(t)}function ct(e){let t=e.toISOString();return/^\d{4}-\d{2}-\d{2}$/.test(t)?`date`:/^\d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(t)?`time`:/(?:[Zz]|[+-]\d{2}:\d{2})$/.test(t)?`offset`:`datetime`}function lt(e,t){return e.getTime()===t.getTime()&&ct(e)===ct(t)}function ut(e,t,n=[]){if(Je(e,t)||e instanceof Date&&t instanceof Date&<(e,t)||Ue(e,t)||typeof e==`number`&&typeof t==`number`&&Number.isNaN(e)&&Number.isNaN(t)&&st(e,t))return[];let r=Array.isArray(e),i=Array.isArray(t);if(r&&i)return ft(e,t,n);if(r||i)throw new Y(`TypeChange`,n,`Cannot change a ${r?`array`:Z(e)} to a ${i?`array`:Z(t)} at ${X(n)}`);let a=Ke(e),o=Ke(t);if(a&&o)return dt(e,t,n);if(a||o)throw new Y(`TypeChange`,n,`Cannot change a ${a?`table`:Z(e)} to a ${o?`table`:Z(t)} at ${X(n)}`);if(e instanceof Date&&t instanceof Date)return[{type:`Edit`,path:n}];if(e instanceof Date||t instanceof Date)throw new Y(`TypeChange`,n,`Cannot change a ${Z(e)} to a ${Z(t)} at ${X(n)}`);if(!ot(e)||!ot(t))throw new Y(`UnsupportedValue`,n,`Unsupported value type ${Z(t)} at ${X(n)}`);return[{type:`Edit`,path:n}]}function dt(e,t,n){let r=Object.keys(e),i=Object.keys(t),a=new Set(i);for(let e of r)if(!a.has(e))throw new Y(`RemovedKey`,n.concat(e),`Cannot remove key ${X(n.concat(e))}`);let o=new Set(r);for(let e of i)if(!o.has(e))throw new Y(`AddedKey`,n.concat(e),`Cannot add key ${X(n.concat(e))}`);let s=[];for(let i of r){let r=ut(e[i],t[i],n.concat(i));for(let e of r)s.push(e)}return s}function ft(e,t,n){if(e.length!==t.length)throw new Y(`ArrayLengthChange`,n,`Cannot change the length of array at ${X(n)} (${e.length} to ${t.length})`);let r=e.map(q),i=t.map(q);if(!r.every((e,t)=>e===i[t])){let e=r.slice().sort(),t=i.slice().sort();if(e.length===t.length&&e.every((e,n)=>e===t[n]))throw new Y(`ArrayReorder`,n,`Cannot reorder array elements at ${X(n)}`)}let a=[];for(let r=0;r<e.length;r++){let i=ut(e[r],t[r],n.concat(r));for(let e of i)a.push(e)}return a}function pt(e){if(e.includes(`'`))return!1;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32&&n!==9||n===127)return!1}return!0}function mt(e){if(e.includes(`'''`))return!1;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n===13){if(e.charCodeAt(t+1)!==10)return!1}else if(n<32&&n!==9&&n!==10||n===127)return!1}return!0}function ht(e,t,n){let r=typeof e;if(r===`string`)return Ct(e,t==null?void 0:t.raw);if(r===`boolean`)return e?`true`:`false`;if(r===`bigint`)return e.toString();if(r===`number`)return Number.isFinite(e)?Number.isSafeInteger(e)&&!Object.is(e,-0)&&!o(t)?yt(e,t==null?void 0:t.raw):bt(e,o(t)?t.raw:void 0):St(e);if(e instanceof Date)return gt(e,t);throw new Y(`UnsupportedValue`,n,`Unsupported value type ${Object.prototype.toString.call(e)} at ${X(n)}`)}function gt(e,t){let n=t==null?void 0:t.raw,r=_t(e);return typeof n==`string`?ve.createDateWithOriginalFormat(r,n).toISOString():r.toISOString()}function _t(e){let t=e;if(typeof t.isDate!=`function`||typeof t.isTime!=`function`)return e;let n=e.toISOString().replace(/\.000(?=([Zz]|[+-]\d{2}:\d{2})$|$)/,``);return t.isDate()?new T(n):t.isTime()?new E(n,n):t.isLocal()?new D(n,!1):new O(n,!1)}function vt(e){if(e.startsWith(`0x`))return{radix:16,prefix:`0x`};if(e.startsWith(`0o`))return{radix:8,prefix:`0o`};if(e.startsWith(`0b`))return{radix:2,prefix:`0b`}}function yt(e,t){if(t){let n=vt(t);if(n&&e>=0){let r=n.radix===16&&/[A-F]/.test(t),i=e.toString(n.radix);return r&&(i=i.toUpperCase()),n.prefix+i}}return String(e)}function bt(e,t){if(Object.is(e,-0))return`-0.0`;if(t&&/[eE]/.test(t))return xt(e,t);let n=String(e);return/[.eE]/.test(n)?n:`${n}.0`}function xt(e,t){let n=t.slice(0,t.search(/[eE]/)),r=n.indexOf(`.`),i=r===-1?``:n.slice(r+1),a=!/[1-9]/.test(i),o=Number.isInteger(e)&&!Object.is(e,-0)&&a?i.length:0,[s,c]=e.toExponential().split(/[eE]/),l=s.includes(`.`)?s.length-s.indexOf(`.`)-1:0,u=Math.max(o,l);return`${u>0?Number(s).toFixed(u):String(Number(s))}${t.includes(`E`)?`E`:`e`}${c.replace(/^\+/,``)}`}function St(e){return Number.isNaN(e)?U(e)?`-nan`:`nan`:e>0?`inf`:`-inf`}function Q(e,t,n){return e.startsWith(t+`\r
|
|
10
|
+
`)?`\r
|
|
11
|
+
`:e.startsWith(t+`
|
|
12
|
+
`)?`
|
|
13
|
+
`:n.startsWith(`\r
|
|
14
|
+
`)?`\r
|
|
15
|
+
`:n.startsWith(`
|
|
16
|
+
`)?`
|
|
17
|
+
`:``}function Ct(e,t){if(t){if(t.startsWith(`'''`))return mt(e)?`'''`+Q(t,`'''`,e)+e+`'''`:Et(e);if(t.startsWith(`"""`))return wt(e,t);if(t.startsWith(`'`)){if(pt(e))return`'`+e+`'`;if(mt(e))return`'''`+Q(t,`'''`,e)+e+`'''`}}return Et(e)}function wt(e,t){let n=Tt(e);return`"""`+Q(t,`"""`,n)+n+`"""`}function Tt(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n],i=e.charCodeAt(n);t+=r===`\\`?`\\\\`:r===`\b`?`\\b`:r===` `?`\\t`:r===`
|
|
18
|
+
`?`
|
|
19
|
+
`:r===`\f`?`\\f`:r===`\r`?e.charCodeAt(n+1)===10?`\r`:`\\r`:i>=0&&i<=7||i===11||i>=14&&i<=31||i===127?`\\u`+i.toString(16).padStart(4,`0`).toUpperCase():r}return t.replace(/"""/g,`""\\"`)}function Et(e){let t=`"`;for(let n of e){let e=n.codePointAt(0);t+=n===`"`?`\\"`:n===`\\`?`\\\\`:n===`\b`?`\\b`:n===` `?`\\t`:n===`
|
|
20
|
+
`?`\\n`:n===`\f`?`\\f`:n===`\r`?`\\r`:e<32||e===127?`\\u`+e.toString(16).padStart(4,`0`).toUpperCase():n}return t+=`"`,t}function $(i,a){if(!a.length)return u(i)&&r(i.item)?i.item:i;if(r(i))return $(i.value,a);let o={},s,c;if(f(i)&&i.items.some((l,d)=>{try{let f=[];if(r(l))f=l.key.value;else if(t(l))f=l.key.item.value;else if(n(l)){f=l.key.item.value;let e=q(f);o[e]||(o[e]=0);let t=o[e]++;f=f.concat(t)}else u(l)&&r(l.item)?f=l.item.key.value:u(l)&&(f=[d]);if(f.length&&K(f,a.slice(0,f.length))){let t=a.slice(f.length);if(e(i)&&n(l)&&t.length>0){let e=l.key.item.value,r=i,a=r.items.findIndex((t,r)=>r>d&&n(t)&&K(t.key.item.value,e)),o=a===-1?r.items.length:a;s=Dt(l,t,e,r.items.slice(d+1,o))}else s=u(l)&&r(l.item)?a.length===f.length?l:$(l.item.value,t):u(l)&&a.length>f.length?$(l.item,t):$(l,t);return!0}return(r(l)||u(l)&&r(l.item))&&f.length>a.length&&K(f.slice(0,a.length),a)&&(c||=l),!1}catch{return!1}}),!s&&c&&(s=c),!s)throw Error(`Node not found at ${a.join(`.`)}`);return s}function Dt(e,r,i,a){try{return $(e,r)}catch{}let o={};for(let e of a){let a=[];if(t(e)){let t=e.key.item.value;t.length>i.length&&K(t.slice(0,i.length),i)&&(a=t.slice(i.length))}else if(n(e)){let t=e.key.item.value;if(t.length>i.length&&K(t.slice(0,i.length),i)){let e=t.slice(i.length),n=q(e);o[n]||(o[n]=0);let r=o[n]++;a=e.concat(r)}}if(a.length&&K(a,r.slice(0,a.length)))try{return $(e,r.slice(a.length))}catch{}}throw Error(`Node not found at (aot scope) ${r.join(`.`)}`)}function Ot(e){return e.charCodeAt(0)===65279}const kt=new WeakMap,At=new WeakMap;function jt(e,t){return(e[t.line-1]??e[e.length-1])+t.column}function Mt(e,t){let n=Nt(t);for(let t of e)n(t)}function Nt(e){let i=[0];for(let t=0;t<e.length;t++)e.charCodeAt(t)===10&&i.push(t+1);return a=>{let o=[a];for(;o.length>0;){let a=o.pop(),s=[jt(i,a.loc.start),jt(i,a.loc.end)];if(Object.defineProperty(a,"range",{configurable:!0,enumerable:!1,value:s}),kt.set(a,e),At.set(a,Pt(a).slice()),r(a))o.push(a.value),o.push(a.key);else if(u(a))o.push(a.item);else if(t(a)||n(a)){o.push(a.key);let e=a.items;for(let t=e.length-1;t>=0;t--)o.push(e[t])}else if(f(a)){let e=a.items;for(let t=e.length-1;t>=0;t--)o.push(e[t])}}}}function Pt(e){return r(e)?[e.key,e.value]:u(e)?[e.item]:t(e)||n(e)?[e.key,...e.items]:f(e)?e.items:[]}function Ft(e){let t=1,n=0;for(let r of e){let e=r.loc.end;(e.line>t||e.line===t&&e.column>n)&&(t=e.line,n=e.column)}return{type:`Document`,loc:{start:{line:1,column:0},end:{line:t,column:n}},items:e}}function It(e){return r(e)?e.value:u(e)?r(e.item)?e.item.value:e.item:e}function Lt(e,t){let n=e;for(let e of t)n=n==null?void 0:n[e];return n}function Rt(e,t){if(arguments.length>2&&arguments[2]!==void 0&&arguments[2]!==null)throw new Y(`UnsupportedOption`,[],`patch-lite does not support formatting options; use patch() from the main package`);let n=Ot(e),r=n?e.slice(1):e,i=Array.from(ke(r));Mt(i,r);let a=ut(Qe(i,r,{integersAsBigInt:`asNeeded`,temporal:!1}),t);if(a.length===0)return e;let o=Ft(i),s=[];for(let e of a){let n=It($(o,e.path));if(!p(n))throw Error(`Cannot locate a value at ${X(e.path)}`);let r=n.range;if(!r)throw Error(`Missing source location for value at ${X(e.path)}`);s.push({start:r[0],end:r[1],text:ht(Lt(t,e.path),n,e.path)})}s.sort((e,t)=>t.start-e.start);let c=r;for(let e of s)c=c.slice(0,e.start)+e.text+c.slice(e.end);return n?``+c:c}export{Rt as patch};
|