@node-zugferd/kosit-schematron-definition 0.0.0-stage → 1.0.0-beta.2

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.
@@ -0,0 +1,3586 @@
1
+ type LiteralString = "" | (string & Record<never, never>);
2
+ type Awaitable<T> = T | Promise<T>;
3
+ type MaybeReadonly<TValue> = TValue | Readonly<TValue>;
4
+ type DeepPartial<T> = T extends Function ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]>; } : T;
5
+ declare const logLevels: readonly ["info", "success", "warn", "error", "debug"];
6
+ type LogLevel = (typeof logLevels)[number];
7
+ type Logger = {
8
+ disabled?: boolean | undefined;
9
+ level?: Exclude<LogLevel, "success"> | undefined;
10
+ log?: ((level: Exclude<LogLevel, "success">, message: string, ...args: any[]) => void) | undefined;
11
+ };
12
+ type LogHandlerParams = Parameters<NonNullable<Logger["log"]>> extends [LogLevel, ...infer Rest] ? Rest : never;
13
+ declare function createLogger(options?: Logger): Record<LogLevel, (...params: LogHandlerParams) => void>;
14
+ type ErrorMessage<Issue extends BaseIssue<unknown>> = ((issue: Issue) => string) | string;
15
+ interface Config<Issue extends BaseIssue<unknown>> {
16
+ readonly message?: ErrorMessage<Issue> | undefined;
17
+ readonly abortEarly?: boolean | undefined;
18
+ readonly abortPipeEarly?: boolean | undefined;
19
+ }
20
+ interface BaseIssue<Input> extends Config<BaseIssue<Input>> {
21
+ readonly kind: "schema" | "validation" | "transformation";
22
+ readonly type: string;
23
+ readonly input: Input;
24
+ readonly expected: string | null;
25
+ readonly received: string;
26
+ readonly message: string;
27
+ readonly requirement?: unknown | undefined;
28
+ readonly path?: [IssuePathItem, ...IssuePathItem[]] | undefined;
29
+ readonly issues?: [BaseIssue<Input>, ...BaseIssue<Input>[]] | undefined;
30
+ }
31
+ type IssuePathItem = ArrayPathItem | ObjectPathItem | UnknownPathItem;
32
+ /**
33
+ * Array path item interface.
34
+ */
35
+ interface ArrayPathItem {
36
+ /**
37
+ * The path item type.
38
+ */
39
+ readonly type: "array";
40
+ /**
41
+ * The path item origin.
42
+ */
43
+ readonly origin: "value";
44
+ /**
45
+ * The path item input.
46
+ */
47
+ readonly input: MaybeReadonly<unknown[]>;
48
+ /**
49
+ * The path item key.
50
+ */
51
+ readonly key: number;
52
+ /**
53
+ * The path item value.
54
+ */
55
+ readonly value: unknown;
56
+ }
57
+ /**
58
+ * Object path item interface.
59
+ */
60
+ interface ObjectPathItem {
61
+ /**
62
+ * The path item type.
63
+ */
64
+ readonly type: "object";
65
+ /**
66
+ * The path item origin.
67
+ */
68
+ readonly origin: "key" | "value";
69
+ /**
70
+ * The path item input.
71
+ */
72
+ readonly input: Record<string, unknown>;
73
+ /**
74
+ * The path item key.
75
+ */
76
+ readonly key: string;
77
+ /**
78
+ * The path item value.
79
+ */
80
+ readonly value: unknown;
81
+ }
82
+ /**
83
+ * Unknown path item interface.
84
+ */
85
+ interface UnknownPathItem {
86
+ /**
87
+ * The path item type.
88
+ */
89
+ readonly type: "unknown";
90
+ /**
91
+ * The path item origin.
92
+ */
93
+ readonly origin: "key" | "value";
94
+ /**
95
+ * The path item input.
96
+ */
97
+ readonly input: unknown;
98
+ /**
99
+ * The path item key.
100
+ */
101
+ readonly key: unknown;
102
+ /**
103
+ * The path item value.
104
+ */
105
+ readonly value: unknown;
106
+ }
107
+ interface UnknownDataset {
108
+ /**
109
+ * Whether is's typed.
110
+ */
111
+ typed?: false;
112
+ /**
113
+ * The dataset value.
114
+ */
115
+ value: unknown;
116
+ /**
117
+ * The dataset issues.
118
+ */
119
+ issues?: undefined;
120
+ }
121
+ interface SuccessDataset<Value> {
122
+ /**
123
+ * Whether is's typed.
124
+ */
125
+ typed: true;
126
+ /**
127
+ * The dataset value.
128
+ */
129
+ value: Value;
130
+ /**
131
+ * The dataset issues.
132
+ */
133
+ issues?: undefined;
134
+ }
135
+ interface PartialDataset<Value, Issue extends BaseIssue<unknown>> {
136
+ /**
137
+ * Whether is's typed.
138
+ */
139
+ typed: true;
140
+ /**
141
+ * The dataset value.
142
+ */
143
+ value: Value;
144
+ /**
145
+ * The dataset issues.
146
+ */
147
+ issues: [Issue, ...Issue[]];
148
+ }
149
+ interface FailureDataset<Issue extends BaseIssue<unknown>> {
150
+ /**
151
+ * Whether is's typed.
152
+ */
153
+ typed: false;
154
+ /**
155
+ * The dataset value.
156
+ */
157
+ value: unknown;
158
+ /**
159
+ * The dataset issues.
160
+ */
161
+ issues: [Issue, ...Issue[]];
162
+ }
163
+ type OutputDataset<Value, Issue extends BaseIssue<unknown>> = SuccessDataset<Value> | PartialDataset<Value, Issue> | FailureDataset<Issue>;
164
+ /** The Standard Typed interface. This is a base type extended by other specs. */
165
+ interface StandardTypedV1<Input = unknown, Output = Input> {
166
+ /** The Standard properties. */
167
+ readonly "~standard": StandardTypedV1.Props<Input, Output>;
168
+ }
169
+ declare namespace StandardTypedV1 {
170
+ /** The Standard Typed properties interface. */
171
+ interface Props<Input = unknown, Output = Input> {
172
+ /** The version number of the standard. */
173
+ readonly version: 1;
174
+ /** The vendor name of the schema library. */
175
+ readonly vendor: string;
176
+ /** Inferred types associated with the schema. */
177
+ readonly types?: Types<Input, Output> | undefined;
178
+ }
179
+ /** The Standard Typed types interface. */
180
+ interface Types<Input = unknown, Output = Input> {
181
+ /** The input type of the schema. */
182
+ readonly input: Input;
183
+ /** The output type of the schema. */
184
+ readonly output: Output;
185
+ }
186
+ /** Infers the input type of a Standard Typed. */
187
+ type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
188
+ /** Infers the output type of a Standard Typed. */
189
+ type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
190
+ }
191
+ /** The Standard Schema interface. */
192
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
193
+ /** The Standard Schema properties. */
194
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
195
+ }
196
+ declare namespace StandardSchemaV1 {
197
+ /** The Standard Schema properties interface. */
198
+ interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
199
+ /** Validates unknown input values. */
200
+ readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
201
+ }
202
+ /** The result interface of the validate function. */
203
+ type Result<Output> = SuccessResult<Output> | FailureResult;
204
+ /** The result interface if validation succeeds. */
205
+ interface SuccessResult<Output> {
206
+ /** The typed output value. */
207
+ readonly value: Output;
208
+ /** A falsy value for `issues` indicates success. */
209
+ readonly issues?: undefined;
210
+ }
211
+ interface Options {
212
+ /** Explicit support for additional vendor-specific parameters, if needed. */
213
+ readonly libraryOptions?: Record<string, unknown> | undefined;
214
+ }
215
+ /** The result interface if validation fails. */
216
+ interface FailureResult {
217
+ /** The issues of failed validation. */
218
+ readonly issues: ReadonlyArray<Issue>;
219
+ }
220
+ /** The issue interface of the failure output. */
221
+ interface Issue {
222
+ /** The error message of the issue. */
223
+ readonly message: string;
224
+ /** The path of the issue, if any. */
225
+ readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
226
+ }
227
+ /** The path segment interface of the issue. */
228
+ interface PathSegment {
229
+ /** The key representing a path segment. */
230
+ readonly key: PropertyKey;
231
+ }
232
+ /** The Standard types interface. */
233
+ interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
234
+ /** Infers the input type of a Standard. */
235
+ type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
236
+ /** Infers the output type of a Standard. */
237
+ type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
238
+ }
239
+ interface BaseSchema<Input, Output, Issue extends BaseIssue<unknown>> extends Readonly<StandardSchemaV1<Input, Output>> {
240
+ readonly kind: "schema";
241
+ readonly type: string;
242
+ readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>>;
243
+ readonly expects: string;
244
+ readonly async: false;
245
+ readonly "~run": (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => OutputDataset<Output, Issue>;
246
+ readonly "~types"?: {
247
+ readonly input: Input;
248
+ readonly output: Output;
249
+ readonly issue: Issue;
250
+ } | undefined;
251
+ }
252
+ interface BaseSchemaAsync<Input, Output, Issue extends BaseIssue<unknown>> extends Omit<BaseSchema<Input, Output, Issue>, "reference" | "async" | "~run"> {
253
+ readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
254
+ readonly async: true;
255
+ readonly "~run": (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<Output, Issue>>;
256
+ }
257
+ declare function createBuildHelper(): {
258
+ setCachedNode: {
259
+ <Node extends XMLBuilder>(id: string | ((node: Node) => string | undefined), node: Node): Node;
260
+ <Node extends XMLBuilder>(id: string | ((node: Node) => string | undefined), node: Node | undefined): Node | undefined;
261
+ };
262
+ getCachedNode: (id: string) => XMLBuilder | undefined;
263
+ findNode: {
264
+ (id: string, builder: XMLBuilder, fn: Parameters<XMLBuilder["find"]>[0]): XMLBuilder | undefined;
265
+ (id: string, builder: XMLBuilder, fn: Parameters<XMLBuilder["find"]>[0], fallback: XMLBuilder | ((fragment: XMLBuilder) => XMLBuilder)): XMLBuilder;
266
+ (id: string, builder: XMLBuilder, fn: Parameters<XMLBuilder["find"]>[0], fallback: XMLBuilder | ((fragment: XMLBuilder) => Promise<XMLBuilder>)): Promise<XMLBuilder>;
267
+ };
268
+ findAllNodes: (builder: XMLBuilder, fn: Parameters<XMLBuilder["filter"]>[0]) => XMLBuilder[];
269
+ };
270
+ type BuildHelper = ReturnType<typeof createBuildHelper>;
271
+ /**
272
+ * Represents an URL record.
273
+ */
274
+ interface URLRecord {
275
+ /**
276
+ * The type of URL
277
+ */
278
+ scheme: string;
279
+ /**
280
+ * Username
281
+ */
282
+ username: string;
283
+ /**
284
+ * Password
285
+ */
286
+ password: string;
287
+ /**
288
+ * Host
289
+ */
290
+ host: Host | null;
291
+ /**
292
+ * Port
293
+ */
294
+ port: number | null;
295
+ /**
296
+ * Path
297
+ */
298
+ path: string[];
299
+ /**
300
+ * Query string
301
+ */
302
+ query: string | null;
303
+ /**
304
+ * Fragment
305
+ */
306
+ fragment: string | null;
307
+ _cannotBeABaseURLFlag: boolean;
308
+ _blobURLEntry: any | null;
309
+ }
310
+ /**
311
+ * Represents an URL's host as either of:
312
+ * - a domain as a string
313
+ * - an IPv4 address as a number
314
+ * - an IPv6 address as a list of eight numbers
315
+ * - an opaque host as a string
316
+ * - or an empty host the an empty string `""`
317
+ */
318
+ type Host = string | number | number[];
319
+ /**
320
+ * Represents a DOM event.
321
+ */
322
+ interface Event {
323
+ NONE: number;
324
+ CAPTURING_PHASE: number;
325
+ AT_TARGET: number;
326
+ BUBBLING_PHASE: number;
327
+ /**
328
+ * Returns the type of event.
329
+ */
330
+ readonly type: string;
331
+ /**
332
+ * Returns the object to which event is dispatched (its target).
333
+ */
334
+ readonly target: EventTarget | null;
335
+ /**
336
+ * Historical alias of target.
337
+ */
338
+ readonly srcElement: EventTarget | null;
339
+ /**
340
+ * Returns the object whose event listener's callback is currently
341
+ * being invoked.
342
+ */
343
+ readonly currentTarget: EventTarget | null;
344
+ /**
345
+ * Returns the event's path (objects on which listeners will be
346
+ * invoked). This does not include nodes in shadow trees if the
347
+ * shadow root was created with its `mode` `"closed"`.
348
+ */
349
+ composedPath(): EventTarget[];
350
+ /**
351
+ * Returns the event's phase.
352
+ */
353
+ readonly eventPhase: EventPhase;
354
+ /**
355
+ * Prevents event from reaching any objects other than the current
356
+ * object.
357
+ */
358
+ stopPropagation(): void;
359
+ /**
360
+ * Historical alias of `stopPropagation()`.
361
+ */
362
+ cancelBubble: boolean;
363
+ /**
364
+ * Prevents event from reaching any registered event listeners after
365
+ * the current one finishes running.
366
+ */
367
+ stopImmediatePropagation(): void;
368
+ /**
369
+ * Returns `true` if the event goes through its target's ancestors in
370
+ * reverse tree order, and `false` otherwise.
371
+ */
372
+ readonly bubbles: boolean;
373
+ /**
374
+ * A historical alias of `stopPropagation()`.
375
+ */
376
+ readonly cancelable: boolean;
377
+ /**
378
+ * Historical property.
379
+ */
380
+ returnValue: boolean;
381
+ /**
382
+ * Cancels the event (if it is cancelable).
383
+ */
384
+ preventDefault(): void;
385
+ /**
386
+ * Indicates whether the event was cancelled with `preventDefault()`.
387
+ */
388
+ readonly defaultPrevented: boolean;
389
+ /**
390
+ * Determines whether the event can bubble to the shadow DOM.
391
+ */
392
+ readonly composed: boolean;
393
+ /**
394
+ * Returns `true` if event was dispatched by the user agent, and
395
+ * `false` otherwise.
396
+ */
397
+ readonly isTrusted: boolean;
398
+ /**
399
+ * Returns the the number of milliseconds measured relative to the
400
+ * time origin.
401
+ */
402
+ readonly timeStamp: number;
403
+ /**
404
+ * Historical method to initializes the value of an event.
405
+ *
406
+ * @param type - the type of event.
407
+ * @param bubbles - whether the event propagates in reverse.
408
+ * @param cancelable - whether the event can be cancelled.
409
+ */
410
+ initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
411
+ _target: PotentialEventTarget;
412
+ _relatedTarget: PotentialEventTarget;
413
+ _touchTargetList: PotentialEventTarget[];
414
+ _path: EventPathItem[];
415
+ _stopPropagationFlag: boolean;
416
+ _stopImmediatePropagationFlag: boolean;
417
+ _canceledFlag: boolean;
418
+ _inPassiveListenerFlag: boolean;
419
+ _composedFlag: boolean;
420
+ _initializedFlag: boolean;
421
+ _dispatchFlag: boolean;
422
+ _isTrusted: boolean;
423
+ _currentTarget: PotentialEventTarget;
424
+ _eventPhase: EventPhase;
425
+ _type: string;
426
+ _bubbles: boolean;
427
+ _cancelable: boolean;
428
+ _timeStamp: number;
429
+ }
430
+ /**
431
+ * Represents an object that is used to observe mutations to the node tree.
432
+ */
433
+ interface MutationObserver {
434
+ /**
435
+ * Observes a given target and reports any mutations based on options.
436
+ *
437
+ * @param target - the node to observe
438
+ * @param options - mutation criteria to observe
439
+ */
440
+ observe(target: Node, options?: MutationObserverInit): void;
441
+ /**
442
+ * Stops observing mutations.
443
+ */
444
+ disconnect(): void;
445
+ /**
446
+ * Returns the list of mutations.
447
+ */
448
+ takeRecords(): MutationRecord[];
449
+ _callback: MutationCallback;
450
+ _nodeList: Node[];
451
+ _recordQueue: MutationRecord[];
452
+ }
453
+ /**
454
+ * Represents a mutation record.
455
+ */
456
+ interface MutationRecord {
457
+ /**
458
+ * Returns `"attributes"` if it was an attribute mutation,
459
+ * `"characterData"` if it was a mutation to a CharacterData node,
460
+ * and `"childList"` if it was a mutation to the tree of nodes.
461
+ */
462
+ readonly type: "attributes" | "characterData" | "childList";
463
+ /**
464
+ * Returns the node the mutation affected.
465
+ */
466
+ readonly target: Node;
467
+ /**
468
+ * Returns a list of added nodes.
469
+ */
470
+ readonly addedNodes: NodeList;
471
+ /**
472
+ * Returns a list of removed nodes.
473
+ */
474
+ readonly removedNodes: NodeList;
475
+ /**
476
+ * Returns the previous sibling of added or removed nodes.
477
+ */
478
+ readonly previousSibling: Node | null;
479
+ /**
480
+ * Returns the next sibling of added or removed nodes.
481
+ */
482
+ readonly nextSibling: Node | null;
483
+ /**
484
+ * Returns the local name of the changed attribute, and `null` otherwise.
485
+ */
486
+ readonly attributeName: string | null;
487
+ /**
488
+ * Returns the namespace of the changed attribute, and `null` otherwise.
489
+ */
490
+ readonly attributeNamespace: string | null;
491
+ /**
492
+ * Returns a value depending on `type`:
493
+ * * For `"attributes"` the attribute value before the change,
494
+ * * For `"characterData"` node `data` before the change,
495
+ * * For `"childList"` `null`.
496
+ */
497
+ readonly oldValue: string | null;
498
+ }
499
+ /**
500
+ * Represents an object that receive event notifications.
501
+ */
502
+ interface EventListener {
503
+ /**
504
+ * A callback function that is called when an event occurs.
505
+ *
506
+ * @param event - the event to handle.
507
+ */
508
+ handleEvent: (event: Event) => void;
509
+ }
510
+ /**
511
+ * Represents an object that can receive events.
512
+ */
513
+ interface EventTarget {
514
+ /**
515
+ * Registers an event handler.
516
+ *
517
+ * @param type - event type to listen for.
518
+ * @param callback - object to receive a notification when an event occurs.
519
+ * @param options - object that specifies event characteristics.
520
+ */
521
+ addEventListener(type: string, callback: EventListener | null | ((event: Event) => void), options?: {
522
+ passive: boolean;
523
+ once: boolean;
524
+ capture: boolean;
525
+ } | boolean): void;
526
+ /**
527
+ * Removes an event listener.
528
+ *
529
+ * @param type - event type to listen for.
530
+ * @param callback - object to receive a notification when an event occurs.
531
+ * @param options - object that specifies event characteristics.
532
+ */
533
+ removeEventListener(type: string, callback: EventListener | null | ((event: Event) => void), options?: {
534
+ capture: boolean;
535
+ } | boolean): void;
536
+ /**
537
+ * Dispatches an event to this event target.
538
+ *
539
+ * @param event - the event to dispatch.
540
+ */
541
+ dispatchEvent(event: Event): boolean;
542
+ _eventListenerList: EventListenerEntry[];
543
+ _eventHandlerMap: {
544
+ [key: string]: EventHandlerEntry;
545
+ };
546
+ /**
547
+ * Gets the parent event target for the given event.
548
+ *
549
+ * @param event - an event
550
+ */
551
+ _getTheParent(event: Event): EventTarget | null;
552
+ /**
553
+ * Defines optional activation behavior for the given event.
554
+ *
555
+ * _Note:_ This exists because user agents perform certain actions for certain
556
+ * EventTarget objects, e.g., the area element, in response to synthetic
557
+ * MouseEvent events whose type attribute is click. Web compatibility
558
+ * prevented it from being removed and it is now the enshrined way of
559
+ * defining an activation of something.
560
+ *
561
+ * @param event - an event
562
+ */
563
+ _activationBehavior?(event: Event): void;
564
+ /**
565
+ * Defines optional legacy pre-activation behavior for the given event.
566
+ *
567
+ * _Note:_ These algorithms only exist for checkbox and radio input elements
568
+ * and are not to be used for anything else.
569
+ *
570
+ * @param event - an event
571
+ */
572
+ _legacyPreActivationBehavior?(event: Event): void;
573
+ /**
574
+ * Defines optional legacy canceled activation behavior for the given event.
575
+ *
576
+ * _Note:_ These algorithms only exist for checkbox and radio input elements
577
+ * and are not to be used for anything else.
578
+ *
579
+ * @param event - an event
580
+ */
581
+ _legacyCanceledActivationBehavior?(event: Event): void;
582
+ }
583
+ /**
584
+ * Represents a generic XML node.
585
+ */
586
+ interface Node extends EventTarget {
587
+ ELEMENT_NODE: number;
588
+ ATTRIBUTE_NODE: number;
589
+ TEXT_NODE: number;
590
+ CDATA_SECTION_NODE: number;
591
+ ENTITY_REFERENCE_NODE: number;
592
+ ENTITY_NODE: number;
593
+ PROCESSING_INSTRUCTION_NODE: number;
594
+ COMMENT_NODE: number;
595
+ DOCUMENT_NODE: number;
596
+ DOCUMENT_TYPE_NODE: number;
597
+ DOCUMENT_FRAGMENT_NODE: number;
598
+ NOTATION_NODE: number;
599
+ DOCUMENT_POSITION_DISCONNECTED: number;
600
+ DOCUMENT_POSITION_PRECEDING: number;
601
+ DOCUMENT_POSITION_FOLLOWING: number;
602
+ DOCUMENT_POSITION_CONTAINS: number;
603
+ DOCUMENT_POSITION_CONTAINED_BY: number;
604
+ DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number;
605
+ /**
606
+ * Returns the type of node.
607
+ */
608
+ readonly nodeType: NodeType;
609
+ /**
610
+ * Returns a string appropriate for the type of node.
611
+ */
612
+ readonly nodeName: string;
613
+ /**
614
+ * Gets the absolute base URL of the node.
615
+ */
616
+ readonly baseURI: string;
617
+ /**
618
+ * Returns whether the node is rooted to a document node.
619
+ */
620
+ readonly isConnected: boolean;
621
+ /**
622
+ * Returns the parent document.
623
+ */
624
+ readonly ownerDocument: Document | null;
625
+ /**
626
+ * Returns the root node.
627
+ *
628
+ * @param options - if options has `composed = true` this function
629
+ * returns the node's shadow-including root, otherwise it returns
630
+ * the node's root node.
631
+ */
632
+ getRootNode(options?: GetRootNodeOptions): Node;
633
+ /**
634
+ * Returns the parent node.
635
+ */
636
+ readonly parentNode: Node | null;
637
+ /**
638
+ * Returns the parent element.
639
+ */
640
+ readonly parentElement: Element | null;
641
+ /**
642
+ * Determines whether a node has any children.
643
+ */
644
+ hasChildNodes(): boolean;
645
+ /**
646
+ * Returns a {@link NodeList} of child nodes.
647
+ */
648
+ readonly childNodes: NodeList;
649
+ /**
650
+ * Returns the first child node.
651
+ */
652
+ readonly firstChild: Node | null;
653
+ /**
654
+ * Returns the last child node.
655
+ */
656
+ readonly lastChild: Node | null;
657
+ /**
658
+ * Returns the previous sibling node.
659
+ */
660
+ readonly previousSibling: Node | null;
661
+ /**
662
+ * Returns the next sibling node.
663
+ */
664
+ readonly nextSibling: Node | null;
665
+ /**
666
+ * Gets or sets the data associated with a {@link CharacterData} node.
667
+ * For other node types returns `null`.
668
+ */
669
+ nodeValue: string | null;
670
+ /**
671
+ * Returns the concatenation of data of all the {@link CharacterData}
672
+ * node descendants in tree order. When set, replaces the text
673
+ * contents of the node with the given value.
674
+ */
675
+ textContent: string | null;
676
+ /**
677
+ * Puts all {@link Text} nodes in the full depth of the sub-tree
678
+ * underneath this node into a "normal" form where only markup
679
+ * (e.g., tags, comments, processing instructions, CDATA sections,
680
+ * and entity references) separates {@link Text} nodes, i.e., there
681
+ * are no adjacent text nodes.
682
+ */
683
+ normalize(): void;
684
+ /**
685
+ * Returns a duplicate of this node, i.e., serves as a generic copy
686
+ * constructor for nodes. The duplicate node has no parent
687
+ * ({@link parentNode} returns `null`).
688
+ *
689
+ * @param deep - if `true`, recursively clone the subtree under the
690
+ * specified node if `false`, clone only the node itself (and its
691
+ * attributes, if it is an {@link Element}).
692
+ */
693
+ cloneNode(deep?: boolean): Node;
694
+ /**
695
+ * Determines if the given node is equal to this one.
696
+ *
697
+ * @param node - the node to compare with
698
+ */
699
+ isEqualNode(node?: Node | null): boolean;
700
+ /**
701
+ * Determines if the given node is reference equal to this one.
702
+ *
703
+ * @param node - the node to compare with
704
+ */
705
+ isSameNode(node?: Node | null): boolean;
706
+ /**
707
+ * Returns a bitmask indicating the position of the given `node`
708
+ * relative to this node.
709
+ */
710
+ compareDocumentPosition(node: Node): Position;
711
+ /**
712
+ * Returns `true` if given node is an inclusive descendant of this
713
+ * node, and `false` otherwise (including when other node is `null`).
714
+ *
715
+ * @param node - the node to check
716
+ */
717
+ contains(node: Node | null): boolean;
718
+ /**
719
+ * Returns the prefix for a given namespace URI, if present, and
720
+ * `null` if not.
721
+ *
722
+ * @param namespace - the namespace to search
723
+ */
724
+ lookupPrefix(namespace: string | null): string | null;
725
+ /**
726
+ * Returns the namespace URI for a given prefix if present, and `null`
727
+ * if not.
728
+ *
729
+ * @param prefix - the prefix to search
730
+ */
731
+ lookupNamespaceURI(prefix: string | null): string | null;
732
+ /**
733
+ * Returns `true` if the namespace is the default namespace on this
734
+ * node or `false` if not.
735
+ *
736
+ * @param namespace - the namespace to check
737
+ */
738
+ isDefaultNamespace(namespace: string | null): boolean;
739
+ /**
740
+ * Inserts the node `newChild` before the existing child node
741
+ * `refChild`. If `refChild` is `null`, inserts `newChild` at the end
742
+ * of the list of children.
743
+ *
744
+ * If `newChild` is a {@link DocumentFragment} object, all of its
745
+ * children are inserted, in the same order, before `refChild`.
746
+ *
747
+ * If `newChild` is already in the tree, it is first removed.
748
+ *
749
+ * @param newChild - the node to insert
750
+ * @param refChild - the node before which the new node must be
751
+ * inserted
752
+ *
753
+ * @returns the newly inserted child node
754
+ */
755
+ insertBefore(newChild: Node, refChild: Node | null): Node;
756
+ /**
757
+ * Adds the node `newChild` to the end of the list of children of this
758
+ * node, and returns it. If `newChild` is already in the tree, it is
759
+ * first removed.
760
+ *
761
+ * If `newChild` is a {@link DocumentFragment} object, the entire
762
+ * contents of the document fragment are moved into the child list of
763
+ * this node.
764
+ *
765
+ * @param newChild - the node to add
766
+ *
767
+ * @returns the newly inserted child node
768
+ */
769
+ appendChild(newChild: Node): Node;
770
+ /**
771
+ * Replaces the child node `oldChild` with `newChild` in the list of
772
+ * children, and returns the `oldChild` node. If `newChild` is already
773
+ * in the tree, it is first removed.
774
+ *
775
+ * @param newChild - the new node to put in the child list
776
+ * @param oldChild - the node being replaced in the list
777
+ *
778
+ * @returns the removed child node
779
+ */
780
+ replaceChild(newChild: Node, oldChild: Node): Node;
781
+ /**
782
+ * Removes the child node indicated by `oldChild` from the list of
783
+ * children, and returns it.
784
+ *
785
+ * @param oldChild - the node being removed from the list
786
+ *
787
+ * @returns the removed child node
788
+ */
789
+ removeChild(oldChild: Node): Node;
790
+ _nodeDocument: Document;
791
+ _registeredObserverList: Array<RegisteredObserver | TransientRegisteredObserver>;
792
+ /**
793
+ * Used to keep track of parent-child relations in the tree. These are
794
+ * non-standard properties.
795
+ */
796
+ _nodeType: NodeType;
797
+ _parent: Node | null;
798
+ _children: any;
799
+ _firstChild: Node | null;
800
+ _lastChild: Node | null;
801
+ _previousSibling: Node | null;
802
+ _nextSibling: Node | null;
803
+ }
804
+ /**
805
+ * Represents a generic text node.
806
+ */
807
+ interface CharacterData extends Node, NonDocumentTypeChildNode, ChildNode {
808
+ /**
809
+ * Gets or sets the text data of the node.
810
+ */
811
+ data: string;
812
+ /**
813
+ * Returns the number of code units in {@link data}.
814
+ */
815
+ readonly length: number;
816
+ /**
817
+ * Returns `count` number of characters from node data starting at
818
+ * the given `offset`.
819
+ *
820
+ * @param offset - the offset at which retrieval starts
821
+ * @param count - the number of characters to return
822
+ */
823
+ substringData(offset: number, count: number): string;
824
+ /**
825
+ * Appends the given string to text data of the node.
826
+ *
827
+ * @param data - the string of text to add to node data
828
+ */
829
+ appendData(data: string): void;
830
+ /**
831
+ * Inserts the given string into the text data of the node starting at
832
+ * the given `offset`.
833
+ *
834
+ * @param offset - the offset at which insertion starts
835
+ * @param data - the string of text to add to node data
836
+ */
837
+ insertData(offset: number, data: string): void;
838
+ /**
839
+ * Deletes `count` number of characters from node data starting at
840
+ * the given `offset`.
841
+ *
842
+ * @param offset - the offset at which removal starts
843
+ * @param count - the number of characters to delete
844
+ */
845
+ deleteData(offset: number, count: number): void;
846
+ /**
847
+ * Deletes `count` number of characters from node data starting at
848
+ * the given `offset` and replaces it with the given `data`.
849
+ *
850
+ * @param offset - the offset at which removal starts
851
+ * @param count - the number of characters to delete
852
+ * @param data - the string of text to add to node data
853
+ */
854
+ replaceData(offset: number, count: number, data: string): void;
855
+ _data: string;
856
+ }
857
+ /**
858
+ * Represents a text node.
859
+ */
860
+ interface Text extends CharacterData, Slotable {
861
+ /**
862
+ * Splits data at the given offset and returns the remainder as a text
863
+ * node.
864
+ *
865
+ * @param offset - the offset at which to split nodes.
866
+ */
867
+ splitText(offset: number): Text;
868
+ /**
869
+ * Returns the combined data of all direct text node siblings.
870
+ */
871
+ readonly wholeText: string;
872
+ }
873
+ /**
874
+ * Represents a collection of elements.
875
+ */
876
+ interface HTMLCollection extends Collection, Iterable<Element> {
877
+ /**
878
+ * Returns the number of elements in the collection.
879
+ */
880
+ readonly length: number;
881
+ /**
882
+ * Returns the element with index `index` from the collection.
883
+ *
884
+ * @param index - the zero-based index of the element to return
885
+ */
886
+ item(index: number): Element | null;
887
+ /**
888
+ * Returns the first element with ID or name `name` from the
889
+ * collection.
890
+ *
891
+ * @param name - the name of the element to return
892
+ */
893
+ namedItem(name: string): Element | null;
894
+ /**
895
+ * Returns the element with index index from the collection. The
896
+ * elements are sorted in tree order.
897
+ */
898
+ [index: number]: Element | undefined;
899
+ [key: string]: any;
900
+ }
901
+ /**
902
+ * Represents a document node.
903
+ */
904
+ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, ParentNode {
905
+ /**
906
+ * Returns the {@link DOMImplementation} object that is associated
907
+ * with the document.
908
+ */
909
+ readonly implementation: DOMImplementation;
910
+ /**
911
+ * Returns the document's URL.
912
+ */
913
+ readonly URL: string;
914
+ /**
915
+ * Gets or sets the document's URL.
916
+ */
917
+ readonly documentURI: string;
918
+ /**
919
+ * Returns the document's origin.
920
+ */
921
+ readonly origin: string;
922
+ /**
923
+ * Returns whether the document is rendered in Quirks mode or
924
+ * Standards mode.
925
+ */
926
+ readonly compatMode: string;
927
+ /**
928
+ * Returns the character set.
929
+ */
930
+ readonly characterSet: string;
931
+ /**
932
+ * Gets or sets the character set.
933
+ */
934
+ readonly charset: string;
935
+ /**
936
+ * Returns the character set.
937
+ */
938
+ readonly inputEncoding: string;
939
+ /**
940
+ * Returns the MIME type of the document.
941
+ */
942
+ readonly contentType: string;
943
+ /**
944
+ * Returns the {@link DocType} or `null` if there is none.
945
+ */
946
+ readonly doctype: DocumentType | null;
947
+ /**
948
+ * Returns the document element or `null` if there is none.
949
+ */
950
+ readonly documentElement: Element | null;
951
+ /**
952
+ * Returns a {@link HTMLCollection} of all descendant elements
953
+ * whose qualified name is `qualifiedName`.
954
+ *
955
+ * @param qualifiedName - the qualified name to match or `*` to match all
956
+ * descendant elements.
957
+ *
958
+ * @returns an {@link HTMLCollection} of matching descendant
959
+ * elements
960
+ */
961
+ getElementsByTagName(qualifiedName: string): HTMLCollection;
962
+ /**
963
+ * Returns a {@link HTMLCollection} of all descendant elements
964
+ * whose namespace is `namespace` and local name is `localName`.
965
+ *
966
+ * @param namespace - the namespace to match or `*` to match any
967
+ * namespace.
968
+ * @param localName - the local name to match or `*` to match any
969
+ * local name.
970
+ *
971
+ * @returns an {@link HTMLCollection} of matching descendant
972
+ * elements
973
+ */
974
+ getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollection;
975
+ /**
976
+ * Returns a {@link HTMLCollection} of all descendant elements
977
+ * whose classes are contained in the list of classes given in
978
+ * `classNames`.
979
+ *
980
+ * @param classNames - a space-separated list of classes
981
+ *
982
+ * @returns an {@link HTMLCollection} of matching descendant
983
+ * elements
984
+ */
985
+ getElementsByClassName(classNames: string): HTMLCollection;
986
+ /**
987
+ * Returns a new {@link Element} with the given `localName`.
988
+ *
989
+ * @param localName - local name
990
+ * @param options - element options
991
+ *
992
+ * @returns the new {@link Element}
993
+ */
994
+ createElement(localName: string, options?: string | {
995
+ is: string;
996
+ }): Element;
997
+ /**
998
+ * Returns a new {@link Element} with the given `namespace` and
999
+ * `qualifiedName`.
1000
+ *
1001
+ * @param namespace - namespace URL
1002
+ * @param qualifiedName - qualified name
1003
+ * @param options - element options
1004
+ *
1005
+ * @returns the new {@link Element}
1006
+ */
1007
+ createElementNS(namespace: string | null, qualifiedName: string, options?: string | {
1008
+ is: string;
1009
+ }): Element;
1010
+ /**
1011
+ * Returns a new {@link DocumentFragment}.
1012
+ *
1013
+ * @returns the new {@link DocumentFragment}
1014
+ */
1015
+ createDocumentFragment(): DocumentFragment;
1016
+ /**
1017
+ * Returns a new {@link Text} with the given `data`.
1018
+ *
1019
+ * @param data - text content
1020
+ *
1021
+ * @returns the new {@link Text}
1022
+ */
1023
+ createTextNode(data: string): Text;
1024
+ /**
1025
+ * Returns a new {@link CDATASection} with the given `data`.
1026
+ *
1027
+ * @param data - text content
1028
+ *
1029
+ * @returns the new {@link CDATASection}
1030
+ */
1031
+ createCDATASection(data: string): CDATASection;
1032
+ /**
1033
+ * Returns a new {@link Comment} with the given `data`.
1034
+ *
1035
+ * @param data - text content
1036
+ *
1037
+ * @returns the new {@link Comment}
1038
+ */
1039
+ createComment(data: string): Comment;
1040
+ /**
1041
+ * Returns a new {@link ProcessingInstruction} with the given `target`
1042
+ * and `data`.
1043
+ *
1044
+ * @param target - instruction target
1045
+ * @param data - text content
1046
+ *
1047
+ * @returns the new {@link ProcessingInstruction}
1048
+ */
1049
+ createProcessingInstruction(target: string, data: string): ProcessingInstruction;
1050
+ /**
1051
+ * Returns a copy of `node`.
1052
+ *
1053
+ * @param deep - true to include descendant nodes.
1054
+ *
1055
+ * @returns clone of node
1056
+ */
1057
+ importNode(node: Node, deep?: boolean): Node;
1058
+ /**
1059
+ * Moves `node` from another document into this document and returns
1060
+ * it.
1061
+ *
1062
+ * @param node - node to move.
1063
+ *
1064
+ * @returns the adopted node
1065
+ */
1066
+ adoptNode(node: Node): Node;
1067
+ /**
1068
+ * Returns a new {@link Attr} with the given `localName`.
1069
+ *
1070
+ * @param localName - local name
1071
+ *
1072
+ * @returns the new {@link Attr}
1073
+ */
1074
+ createAttribute(localName: string): Attr;
1075
+ /**
1076
+ * Returns a new {@link Attr} with the given `namespace` and
1077
+ * `qualifiedName`.
1078
+ *
1079
+ * @param namespace - namespace URL
1080
+ * @param qualifiedName - qualified name
1081
+ *
1082
+ * @returns the new {@link Attr}
1083
+ */
1084
+ createAttributeNS(namespace: string | null, qualifiedName: string): Attr;
1085
+ /**
1086
+ * Creates an event of the type specified.
1087
+ *
1088
+ * @param eventInterface - a string representing the type of event
1089
+ * to be created
1090
+ */
1091
+ createEvent(eventInterface: string): Event;
1092
+ /**
1093
+ * Creates a new Range object.
1094
+ */
1095
+ createRange(): Range;
1096
+ /**
1097
+ * Creates a new `NodeIterator` object.
1098
+ * @param root - the node to which the iterator is attached.
1099
+ * @param whatToShow - a filter on node type.
1100
+ * @param filter - a user defined filter.
1101
+ */
1102
+ createNodeIterator(root: Node, whatToShow?: WhatToShow, filter?: NodeFilter | ((node: Node) => FilterResult) | null): NodeIterator;
1103
+ /**
1104
+ * Creates a new `TreeWalker` object.
1105
+ * @param root - the node to which the iterator is attached.
1106
+ * @param whatToShow - a filter on node type.
1107
+ * @param filter - a user defined filter.
1108
+ */
1109
+ createTreeWalker(root: Node, whatToShow?: WhatToShow, filter?: NodeFilter | ((node: Node) => FilterResult) | null): TreeWalker;
1110
+ _encoding: {
1111
+ name: string;
1112
+ labels: string[];
1113
+ };
1114
+ _contentType: string;
1115
+ _URL: URLRecord;
1116
+ _origin: Origin;
1117
+ _type: "xml" | "html";
1118
+ _mode: "no-quirks" | "quirks" | "limited-quirks";
1119
+ _documentElement: Element | null;
1120
+ _hasNamespaces: boolean;
1121
+ }
1122
+ /**
1123
+ * Represents an XML document.
1124
+ */
1125
+ interface XMLDocument extends Document {}
1126
+ /**
1127
+ * Represents a document fragment in the XML tree.
1128
+ */
1129
+ interface DocumentFragment extends Node, NonElementParentNode, ParentNode {
1130
+ _host: Element | null;
1131
+ }
1132
+ /**
1133
+ * Represents a shadow root.
1134
+ */
1135
+ interface ShadowRoot extends DocumentFragment, DocumentOrShadowRoot {
1136
+ /**
1137
+ * Gets the shadow root's mode.
1138
+ */
1139
+ readonly mode: ShadowRootMode;
1140
+ /**
1141
+ * Gets the shadow root's host.
1142
+ */
1143
+ readonly host: Element;
1144
+ _host: Element;
1145
+ _mode: ShadowRootMode;
1146
+ }
1147
+ /**
1148
+ * Represents an element node.
1149
+ */
1150
+ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode, Slotable {
1151
+ /**
1152
+ * Gets the namespace URI.
1153
+ */
1154
+ readonly namespaceURI: string | null;
1155
+ /**
1156
+ * Gets the namespace prefix.
1157
+ */
1158
+ readonly prefix: string | null;
1159
+ /**
1160
+ * Gets the local name.
1161
+ */
1162
+ readonly localName: string;
1163
+ /**
1164
+ * If namespace prefix is not `null`, returns the concatenation of
1165
+ * namespace prefix, `":"`, and local name. Otherwise it returns the
1166
+ * local name.
1167
+ */
1168
+ readonly tagName: string;
1169
+ /**
1170
+ * Gets or sets the identifier of this element.
1171
+ */
1172
+ id: string;
1173
+ /**
1174
+ * Gets or sets the class name of this element.
1175
+ */
1176
+ className: string;
1177
+ /**
1178
+ * Returns a {@link DOMTokenList} with tokens from the class
1179
+ * attribute.
1180
+ */
1181
+ readonly classList: DOMTokenList;
1182
+ /**
1183
+ * Gets or sets the slot attribute of this element.
1184
+ */
1185
+ slot: string;
1186
+ /**
1187
+ * Determines if the element node contains any attributes.
1188
+ */
1189
+ hasAttributes(): boolean;
1190
+ /**
1191
+ * Returns a {@link NamedNodeMap} of attributes.
1192
+ */
1193
+ readonly attributes: NamedNodeMap;
1194
+ /**
1195
+ * Returns the list of all attribute's qualified names.
1196
+ */
1197
+ getAttributeNames(): string[];
1198
+ /**
1199
+ * Returns the value of the attribute with the given `name`.
1200
+ *
1201
+ * @param qualifiedName - attribute name
1202
+ */
1203
+ getAttribute(qualifiedName: string): string | null;
1204
+ /**
1205
+ * Returns the value of the attribute with the given `namespace` and
1206
+ * `localName`.
1207
+ *
1208
+ * @param namespace - namespace to search for
1209
+ * @param localName - local name to search for
1210
+ */
1211
+ getAttributeNS(namespace: string | null, localName: string): string | null;
1212
+ /**
1213
+ * Sets the value of the attribute with the given `name`.
1214
+ *
1215
+ * @param qualifiedName - attribute name
1216
+ * @param value - attribute value to set
1217
+ */
1218
+ setAttribute(qualifiedName: string, value: string): void;
1219
+ /**
1220
+ * Sets the value of the attribute with the given `namespace` and
1221
+ * `qualifiedName`.
1222
+ *
1223
+ * @param namespace - namespace to search for
1224
+ * @param qualifiedName - qualified name to search for
1225
+ * @param value - attribute value to set
1226
+ */
1227
+ setAttributeNS(namespace: string | null, qualifiedName: string, value: string): void;
1228
+ /**
1229
+ * Removes the attribute with the given `name`.
1230
+ *
1231
+ * @param qualifiedName - attribute name
1232
+ */
1233
+ removeAttribute(qualifiedName: string): void;
1234
+ /**
1235
+ * Removes the attribute with the given `namespace` and `localName`.
1236
+ *
1237
+ * @param namespace - namespace to search for
1238
+ * @param localName - local name to search for
1239
+ */
1240
+ removeAttributeNS(namespace: string | null, localName: string): void;
1241
+ /**
1242
+ * Determines whether the attribute with the given `name` exists.
1243
+ *
1244
+ * @param qualifiedName - attribute name
1245
+ */
1246
+ hasAttribute(qualifiedName: string): boolean;
1247
+ /**
1248
+ * Toggles a boolean attribute (removing it if it is present and adding it
1249
+ * if it is not present).
1250
+ *
1251
+ * @param qualifiedName - attribute name
1252
+ * @param force - whether the attribute should be added or removed,
1253
+ * no matter whether the attribute is present or not
1254
+ */
1255
+ toggleAttribute(qualifiedName: string, force?: boolean): boolean;
1256
+ /**
1257
+ * Determines whether the attribute with the given `namespace` and
1258
+ * `localName` exists.
1259
+ *
1260
+ * @param namespace - namespace to search for
1261
+ * @param localName - local name to search for
1262
+ */
1263
+ hasAttributeNS(namespace: string | null, localName: string): boolean;
1264
+ /**
1265
+ * Returns the attribute with the given `name`.
1266
+ *
1267
+ * @param qualifiedName - attribute name
1268
+ */
1269
+ getAttributeNode(qualifiedName: string): Attr | null;
1270
+ /**
1271
+ * Returns the attribute with the given `namespace` and
1272
+ * `localName`.
1273
+ *
1274
+ * @param namespace - namespace to search for
1275
+ * @param localName - local name to search for
1276
+ */
1277
+ getAttributeNodeNS(namespace: string | null, localName: string): Attr | null;
1278
+ /**
1279
+ * Sets the attribute given with `attr`.
1280
+ *
1281
+ * @param attr - attribute to set
1282
+ */
1283
+ setAttributeNode(attr: Attr): Attr | null;
1284
+ /**
1285
+ * Sets the attribute given with `attr`.
1286
+ *
1287
+ * @param attr - attribute to set
1288
+ */
1289
+ setAttributeNodeNS(attr: Attr): Attr | null;
1290
+ /**
1291
+ * Removes the given attribute.
1292
+ *
1293
+ * @param attr - attribute to remove
1294
+ */
1295
+ removeAttributeNode(attr: Attr): Attr;
1296
+ /**
1297
+ * Creates a shadow root for element and returns it.
1298
+ *
1299
+ * @param init - A ShadowRootInit dictionary.
1300
+ */
1301
+ attachShadow(init: {
1302
+ mode: ShadowRootMode;
1303
+ }): ShadowRoot;
1304
+ /**
1305
+ * Returns element's shadow root, if any, and if shadow root's mode
1306
+ * is `"open"`, and null otherwise.
1307
+ */
1308
+ readonly shadowRoot: ShadowRoot | null;
1309
+ /**
1310
+ * Returns the first (starting at element) inclusive ancestor that
1311
+ * matches selectors, and `null` otherwise.
1312
+ *
1313
+ * @param selectors
1314
+ */
1315
+ closest(selectors: string): Element | null;
1316
+ /**
1317
+ * Returns `true` if matching selectors against element's root yields
1318
+ * element, and `false` otherwise.
1319
+ *
1320
+ * @param selectors
1321
+ */
1322
+ matches(selectors: string): boolean;
1323
+ /**
1324
+ * Historical alias of `matches`.
1325
+ */
1326
+ webkitMatchesSelector(selectors: string): boolean;
1327
+ /**
1328
+ * Returns a {@link HTMLCollection} of all descendant elements
1329
+ * whose qualified name is `qualifiedName`.
1330
+ *
1331
+ * @param qualifiedName - the qualified name to match or `*` to match
1332
+ * all descendant elements.
1333
+ *
1334
+ * @returns an {@link HTMLCollection} of matching descendant
1335
+ * elements
1336
+ */
1337
+ getElementsByTagName(qualifiedName: string): HTMLCollection;
1338
+ /**
1339
+ * Returns a {@link HTMLCollection} of all descendant elements
1340
+ * whose namespace is `namespace` and local name is `localName`.
1341
+ *
1342
+ * @param namespace - the namespace to match or `*` to match any
1343
+ * namespace.
1344
+ * @param localName - the local name to match or `*` to match any
1345
+ * local name.
1346
+ *
1347
+ * @returns an {@link HTMLCollection} of matching descendant
1348
+ * elements
1349
+ */
1350
+ getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollection;
1351
+ /**
1352
+ * Returns a {@link HTMLCollection} of all descendant elements
1353
+ * whose classes are contained in the list of classes given in
1354
+ * `classNames`.
1355
+ *
1356
+ * @param classNames - a space-separated list of classes
1357
+ *
1358
+ * @returns an {@link HTMLCollection} of matching descendant
1359
+ * elements
1360
+ */
1361
+ getElementsByClassName(classNames: string): HTMLCollection;
1362
+ /**
1363
+ * Inserts a given element node at a given position relative to this
1364
+ * node.
1365
+ *
1366
+ * @param where - a string defining where to insert the element node.
1367
+ * - `beforebegin` before this element itself.
1368
+ * - `afterbegin` before the first child.
1369
+ * - `beforeend` after the last child.
1370
+ * - `afterend` after this element itself.
1371
+ * @param element - the element to insert
1372
+ *
1373
+ * @returns the inserted element
1374
+ */
1375
+ insertAdjacentElement(where: "beforebegin" | "afterbegin" | "beforeend" | "afterend", element: Element): Element | null;
1376
+ /**
1377
+ * Inserts a given text node at a given position relative to this
1378
+ * node.
1379
+ *
1380
+ * @param where - a string defining where to insert the element node.
1381
+ * - `beforebegin` before this element itself.
1382
+ * - `afterbegin` before the first child.
1383
+ * - `beforeend` after the last child.
1384
+ * - `afterend` after this element itself.
1385
+ * @param data - text node data
1386
+ *
1387
+ * @returns the inserted element
1388
+ */
1389
+ insertAdjacentText(where: "beforebegin" | "afterbegin" | "beforeend" | "afterend", data: string): void;
1390
+ _namespace: string | null;
1391
+ _namespacePrefix: string | null;
1392
+ _localName: string;
1393
+ _customElementState: "undefined" | "failed" | "uncustomized" | "custom";
1394
+ _customElementDefinition: CustomElementDefinition | null;
1395
+ _is: string | null;
1396
+ _shadowRoot: ShadowRoot | null;
1397
+ readonly _qualifiedName: string;
1398
+ readonly _htmlUppercasedQualifiedName: string;
1399
+ _attributeList: NamedNodeMap;
1400
+ _attributeChangeSteps: AttributeChangeStep[];
1401
+ _uniqueIdentifier?: string;
1402
+ }
1403
+ /**
1404
+ * Represents an object providing methods which are not dependent on
1405
+ * any particular document
1406
+ */
1407
+ interface DocumentType extends Node, ChildNode {
1408
+ /**
1409
+ * Returns the name of the node.
1410
+ */
1411
+ readonly name: string;
1412
+ /**
1413
+ * Returns the `PUBLIC` identifier of the node.
1414
+ */
1415
+ readonly publicId: string;
1416
+ /**
1417
+ * Returns the `SYSTEM` identifier of the node.
1418
+ */
1419
+ readonly systemId: string;
1420
+ _name: string;
1421
+ _publicId: string;
1422
+ _systemId: string;
1423
+ }
1424
+ /**
1425
+ * Represents a mixin that extends non-element parent nodes. This mixin
1426
+ * is implemented by {@link Document} and {@link DocumentFragment}.
1427
+ */
1428
+ interface NonElementParentNode {
1429
+ /**
1430
+ * Returns an {@link Element} who has an id attribute `elementId`.
1431
+ *
1432
+ * @param id - the value of the `id` attribute to match
1433
+ */
1434
+ getElementById(id: string): Element | null;
1435
+ }
1436
+ /**
1437
+ * Represents a mixin for an interface to be used to share APIs between
1438
+ * documents and shadow roots. This mixin is implemented by
1439
+ * {@link Document} and {@link ShadowRoot}.
1440
+ */
1441
+ interface DocumentOrShadowRoot {}
1442
+ /**
1443
+ * Represents a mixin that extends parent nodes that can have children.
1444
+ * This mixin is implemented by {@link Element}, {@link Document} and
1445
+ * {@link DocumentFragment}.
1446
+ */
1447
+ interface ParentNode {
1448
+ /**
1449
+ * Returns the child elements.
1450
+ */
1451
+ readonly children: HTMLCollection;
1452
+ /**
1453
+ * Returns the first child that is an element, and `null` otherwise.
1454
+ */
1455
+ readonly firstElementChild: Element | null;
1456
+ /**
1457
+ * Returns the last child that is an element, and `null` otherwise.
1458
+ */
1459
+ readonly lastElementChild: Element | null;
1460
+ /**
1461
+ * Returns the number of children that are elements.
1462
+ */
1463
+ readonly childElementCount: number;
1464
+ /**
1465
+ * Prepends the list of nodes or strings before the first child node.
1466
+ * Strings are converted into {@link Text} nodes.
1467
+ *
1468
+ * @param nodes - the array of nodes or strings
1469
+ */
1470
+ prepend(...nodes: (Node | string)[]): void;
1471
+ /**
1472
+ * Appends the list of nodes or strings after the last child node.
1473
+ * Strings are converted into {@link Text} nodes.
1474
+ *
1475
+ * @param nodes - the array of nodes or strings
1476
+ */
1477
+ append(...nodes: (Node | string)[]): void;
1478
+ /**
1479
+ * Returns the first element that is a descendant of node that
1480
+ * matches selectors.
1481
+ *
1482
+ * @param selectors - a selectors string
1483
+ */
1484
+ querySelector(selectors: string): Element | null;
1485
+ /**
1486
+ * Returns all element descendants of node that match selectors.
1487
+ *
1488
+ * @param selectors - a selectors string
1489
+ */
1490
+ querySelectorAll(selectors: string): NodeList;
1491
+ }
1492
+ /**
1493
+ * Represents a mixin that extends child nodes that can have siblings
1494
+ * including doctypes. This mixin is implemented by {@link Element},
1495
+ * {@link CharacterData} and {@link DocumentType}.
1496
+ */
1497
+ interface ChildNode {
1498
+ /**
1499
+ * Inserts nodes just before this node, while replacing strings in
1500
+ * nodes with equivalent text nodes.
1501
+ */
1502
+ before(...nodes: (Node | string)[]): void;
1503
+ /**
1504
+ * Inserts nodes just after this node, while replacing strings in
1505
+ * nodes with equivalent text nodes.
1506
+ */
1507
+ after(...nodes: (Node | string)[]): void;
1508
+ /**
1509
+ * Replaces nodes with this node, while replacing strings in
1510
+ * nodes with equivalent text nodes.
1511
+ */
1512
+ replaceWith(...nodes: (Node | string)[]): void;
1513
+ /**
1514
+ * Removes this node form its tree.
1515
+ */
1516
+ remove(): void;
1517
+ }
1518
+ /**
1519
+ * Represents a slot element of a shadow tree.
1520
+ */
1521
+ interface Slot extends Element {
1522
+ _name: string;
1523
+ _assignedNodes: Slotable[];
1524
+ }
1525
+ /**
1526
+ * Represents a mixin that allows nodes to become the contents of
1527
+ * a <slot> element. This mixin is implemented by {@link Element} and
1528
+ * {@link Text}.
1529
+ */
1530
+ interface Slotable {
1531
+ /**
1532
+ * Returns the <slot> element which this node is inserted in.
1533
+ */
1534
+ readonly assignedSlot: HTMLSlotElement | null;
1535
+ _name: string;
1536
+ _assignedSlot: Slot | null;
1537
+ }
1538
+ /**
1539
+ * Represents an attribute of an element node.
1540
+ */
1541
+ interface Attr extends Node {
1542
+ /**
1543
+ * Gets the namespace URI.
1544
+ */
1545
+ readonly namespaceURI: string | null;
1546
+ /**
1547
+ * Gets the namespace prefix.
1548
+ */
1549
+ readonly prefix: string | null;
1550
+ /**
1551
+ * Gets the local name.
1552
+ */
1553
+ readonly localName: string;
1554
+ /**
1555
+ * If namespace prefix is not `null`, returns the concatenation of
1556
+ * namespace prefix, `":"`, and local name. Otherwise it returns the
1557
+ * local name.
1558
+ */
1559
+ readonly name: string;
1560
+ /**
1561
+ * Gets or sets the attribute value.
1562
+ */
1563
+ value: string;
1564
+ /**
1565
+ * Gets the owner element node.
1566
+ */
1567
+ readonly ownerElement: Element | null;
1568
+ /**
1569
+ * Useless always returns true
1570
+ */
1571
+ readonly specified: boolean;
1572
+ _namespace: string | null;
1573
+ _namespacePrefix: string | null;
1574
+ _localName: string;
1575
+ _value: string;
1576
+ _element: Element | null;
1577
+ readonly _qualifiedName: string;
1578
+ }
1579
+ /**
1580
+ * Represents a CDATA node.
1581
+ */
1582
+ interface CDATASection extends Text {}
1583
+ /**
1584
+ * Represents a comment node.
1585
+ */
1586
+ interface Comment extends CharacterData {}
1587
+ /**
1588
+ * Represents an object providing methods which are not dependent on
1589
+ * any particular document
1590
+ */
1591
+ interface DOMImplementation {
1592
+ createDocumentType(qualifiedName: string, publicId: string, systemId: string): DocumentType;
1593
+ /**
1594
+ * Creates and returns an {@link XMLDocument}.
1595
+ *
1596
+ * @param namespace - the namespace of the document element
1597
+ * @param qualifiedName - the qualified name of the document element
1598
+ * @param doctype - a {@link DocType} to assign to this document
1599
+ */
1600
+ createDocument(namespace: string | null, qualifiedName: string, doctype?: DocumentType | null): XMLDocument;
1601
+ /**
1602
+ * Creates and returns a HTML document.
1603
+ *
1604
+ * @param title - document title
1605
+ */
1606
+ createHTMLDocument(title?: string): Document;
1607
+ /**
1608
+ * Obsolete, always returns true.
1609
+ */
1610
+ hasFeature(): boolean;
1611
+ _ID: string;
1612
+ _associatedDocument: Document;
1613
+ }
1614
+ /**
1615
+ * Represents a token set.
1616
+ */
1617
+ interface DOMTokenList extends Iterable<string> {
1618
+ /**
1619
+ * Returns the number of tokens.
1620
+ */
1621
+ readonly length: number;
1622
+ /**
1623
+ * Returns the token at the given index.
1624
+ *
1625
+ * @param index - the index to of the token
1626
+ */
1627
+ item(index: number): string | null;
1628
+ /**
1629
+ * Returns true if the set contains the given token.
1630
+ *
1631
+ * @param tokens - the token to check
1632
+ */
1633
+ contains(token: string): boolean;
1634
+ /**
1635
+ * Adds the given tokens to the set.
1636
+ *
1637
+ * @param tokens - the list of tokens to add
1638
+ */
1639
+ add(...tokens: string[]): void;
1640
+ /**
1641
+ * Removes the given tokens from the set.
1642
+ *
1643
+ * @param tokens - the list of tokens to remove
1644
+ */
1645
+ remove(...tokens: string[]): void;
1646
+ /**
1647
+ * Removes a given token from the set and returns `false` if it exists,
1648
+ * otherwise adds the token and returns `true`.
1649
+ *
1650
+ * @param token - the token to toggle
1651
+ * @param force - if `false` the token will only be removed but not
1652
+ * added again otherwise if `true` the token will only be added but
1653
+ * not removed again.
1654
+ *
1655
+ * @returns `false` if the token is not in the list after the call,
1656
+ * or `true` if the token is in the list after the call.
1657
+ */
1658
+ toggle(token: string, force?: boolean | undefined): boolean;
1659
+ /**
1660
+ * Replaces the given token with a new token.
1661
+ *
1662
+ * @param token - the token to replace
1663
+ * @param newToken - the new token
1664
+ *
1665
+ * @returns `true` if `token` was replaced with `newToken`,
1666
+ * and `false` otherwise.
1667
+ */
1668
+ replace(token: string, newToken: string): boolean;
1669
+ /**
1670
+ * Determines if a given token is in the associated attribute's
1671
+ * supported tokens
1672
+ *
1673
+ * @param token - the token to check
1674
+ */
1675
+ supports(token: string): boolean;
1676
+ /**
1677
+ * Gets the value of the token list as a string, or sets the token
1678
+ * list to the given value.
1679
+ */
1680
+ value: string;
1681
+ _tokenSet: Set<string>;
1682
+ _element: Element;
1683
+ _attribute: Attr;
1684
+ }
1685
+ /**
1686
+ * Represents a collection of attributes.
1687
+ */
1688
+ interface NamedNodeMap {
1689
+ /**
1690
+ * Returns the number of attribute in the collection.
1691
+ */
1692
+ readonly length: number;
1693
+ /**
1694
+ * Returns the attribute with index `index` from the collection.
1695
+ *
1696
+ * @param index - the zero-based index of the attribute to return
1697
+ */
1698
+ item(index: number): Attr | null;
1699
+ /**
1700
+ * Returns the attribute with the given `qualifiedName`.
1701
+ *
1702
+ * @param qualifiedName - qualified name to search for
1703
+ */
1704
+ getNamedItem(qualifiedName: string): Attr | null;
1705
+ /**
1706
+ * Returns the attribute with the given `namespace` and
1707
+ * `qualifiedName`.
1708
+ *
1709
+ * @param namespace - namespace to search for
1710
+ * @param localName - local name to search for
1711
+ */
1712
+ getNamedItemNS(namespace: string | null, localName: string): Attr | null;
1713
+ /**
1714
+ * Sets the attribute given with `attr`.
1715
+ *
1716
+ * @param attr - attribute to set
1717
+ */
1718
+ setNamedItem(attr: Attr): Attr | null;
1719
+ /**
1720
+ * Sets the attribute given with `attr`.
1721
+ *
1722
+ * @param attr - attribute to set
1723
+ */
1724
+ setNamedItemNS(attr: Attr): Attr | null;
1725
+ /**
1726
+ * Removes the attribute with the given `qualifiedName`.
1727
+ *
1728
+ * @param qualifiedName - qualified name to search for
1729
+ */
1730
+ removeNamedItem(qualifiedName: string): Attr;
1731
+ /**
1732
+ * Removes the attribute with the given `namespace` and
1733
+ * `qualifiedName`.
1734
+ *
1735
+ * @param namespace - namespace to search for
1736
+ * @param localName - local name to search for
1737
+ */
1738
+ removeNamedItemNS(namespace: string | null, localName: string): Attr;
1739
+ /**
1740
+ * Returns the attribute with index `index` from the collection. Returns
1741
+ * `undefined` is index is out of bounds.
1742
+ */
1743
+ [index: number]: Attr;
1744
+ /**
1745
+ * Iterates over all attribute in the collection.
1746
+ */
1747
+ [Symbol.iterator](): IterableIterator<Attr>;
1748
+ _element: Element;
1749
+ _asArray(): Array<Attr>;
1750
+ }
1751
+ /**
1752
+ * Represents a node filter.
1753
+ */
1754
+ interface NodeFilter {
1755
+ FILTER_ACCEPT: number;
1756
+ FILTER_REJECT: number;
1757
+ FILTER_SKIP: number;
1758
+ SHOW_ALL: number;
1759
+ SHOW_ELEMENT: number;
1760
+ SHOW_ATTRIBUTE: number;
1761
+ SHOW_TEXT: number;
1762
+ SHOW_CDATA_SECTION: number;
1763
+ SHOW_ENTITY_REFERENCE: number;
1764
+ SHOW_ENTITY: number;
1765
+ SHOW_PROCESSING_INSTRUCTION: number;
1766
+ SHOW_COMMENT: number;
1767
+ SHOW_DOCUMENT: number;
1768
+ SHOW_DOCUMENT_TYPE: number;
1769
+ SHOW_DOCUMENT_FRAGMENT: number;
1770
+ SHOW_NOTATION: number;
1771
+ /**
1772
+ * Callback function.
1773
+ */
1774
+ acceptNode(node: Node): FilterResult;
1775
+ }
1776
+ /**
1777
+ * Represents a collection of nodes.
1778
+ */
1779
+ interface Collection {
1780
+ _live: boolean;
1781
+ _root: Node;
1782
+ _filter: ((element: Element) => any) | null;
1783
+ }
1784
+ /**
1785
+ * Represents an ordered list of nodes.
1786
+ */
1787
+ interface NodeList extends Collection, Iterable<Node> {
1788
+ /**
1789
+ * Returns the number of nodes in the list.
1790
+ */
1791
+ readonly length: number;
1792
+ /**
1793
+ * Returns an iterator for node indices.
1794
+ */
1795
+ keys(): Iterable<number>;
1796
+ /**
1797
+ * Returns an iterator for nodes.
1798
+ */
1799
+ values(): Iterable<Node>;
1800
+ /**
1801
+ * Returns an iterator for indices and nodes.
1802
+ */
1803
+ entries(): Iterable<[number, Node]>;
1804
+ /**
1805
+ * Returns the node with index `index` from the collection.
1806
+ *
1807
+ * @param index - the zero-based index of the node to return
1808
+ */
1809
+ item(index: number): Node | null;
1810
+ /**
1811
+ * Returns the node at the given index from the collection. Returns `undefined`
1812
+ * if the index is out-of-bounds.
1813
+ */
1814
+ [index: number]: Node | undefined;
1815
+ /**
1816
+ * Returns an iterator for the node list.
1817
+ */
1818
+ [Symbol.iterator](): Iterator<Node>;
1819
+ /**
1820
+ * Calls the callback function for each node in the list. The callback
1821
+ * receives arguments as follows:
1822
+ * - the current node
1823
+ * - index of the current node
1824
+ * - the node list object
1825
+ *
1826
+ * @param callback - function to execute for each node
1827
+ * @param thisArg - value to use as `this` when executing callback
1828
+ */
1829
+ forEach(callback: (node: Node, index: number, list: NodeList) => any, thisArg?: any): void;
1830
+ /**
1831
+ * Used to keep track of child node count. This is a non-standard property.
1832
+ */
1833
+ _length: number;
1834
+ }
1835
+ /**
1836
+ * Represents a mixin that extends child nodes that can have siblings
1837
+ * other than doctypes. This mixin is implemented by {@link Element} and
1838
+ * {@link CharacterData}.
1839
+ */
1840
+ interface NonDocumentTypeChildNode {
1841
+ /**
1842
+ * Returns the previous sibling that is an element node.
1843
+ */
1844
+ readonly previousElementSibling: Element | null;
1845
+ /**
1846
+ * Returns the next sibling that is an element node.
1847
+ */
1848
+ readonly nextElementSibling: Element | null;
1849
+ }
1850
+ /**
1851
+ * Represents a processing instruction node.
1852
+ */
1853
+ interface ProcessingInstruction extends CharacterData {
1854
+ /**
1855
+ * Gets the target of the node.
1856
+ */
1857
+ readonly target: string;
1858
+ _target: string;
1859
+ }
1860
+ /**
1861
+ * Represents an object which can be used to traverse through the nodes
1862
+ * of a subtree.
1863
+ */
1864
+ interface Traverser {
1865
+ /**
1866
+ * Gets the root node of the subtree.
1867
+ */
1868
+ readonly root: Node;
1869
+ /**
1870
+ * Gets the node types to match.
1871
+ */
1872
+ readonly whatToShow: WhatToShow;
1873
+ /**
1874
+ * Gets the filter used to selected the nodes.
1875
+ */
1876
+ readonly filter: NodeFilter | null;
1877
+ _activeFlag: boolean;
1878
+ _root: Node;
1879
+ _whatToShow: WhatToShow;
1880
+ _filter: NodeFilter | null;
1881
+ }
1882
+ /**
1883
+ * Represents an object which can be used to iterate through the nodes
1884
+ * of a subtree.
1885
+ */
1886
+ interface NodeIterator extends Traverser {
1887
+ /**
1888
+ * Gets the node current node of the.
1889
+ */
1890
+ readonly referenceNode: Node;
1891
+ /**
1892
+ * Gets a flag that indicates whether the iterator is anchored before
1893
+ * or after the reference node. If is `true`, the iterator is anchored
1894
+ * before the node, otherwise it is anchored after the node.
1895
+ */
1896
+ readonly pointerBeforeReferenceNode: boolean;
1897
+ /**
1898
+ * Returns the next node in the subtree, or `null` if there are none.
1899
+ */
1900
+ nextNode(): Node | null;
1901
+ /**
1902
+ * Returns the previous node in the subtree, or `null` if there
1903
+ * are none.
1904
+ */
1905
+ previousNode(): Node | null;
1906
+ /**
1907
+ * Removes a range object from its owner document.
1908
+ *
1909
+ * _Note:_ According to the specification, this method is a no-op.
1910
+ * However, since JavaScript lacks weak references, there is no reliable
1911
+ * method of detecting out-of-scope variables. So, it is recommended to
1912
+ * manually `detach` range objects after using them.
1913
+ */
1914
+ detach(): void;
1915
+ _iteratorCollection: Collection;
1916
+ _reference: Node;
1917
+ _pointerBeforeReference: boolean;
1918
+ }
1919
+ /**
1920
+ * Represents the nodes of a subtree and a position within them.
1921
+ */
1922
+ interface TreeWalker extends Traverser {
1923
+ /**
1924
+ * Gets or sets the node to which the iterator is pointing at.
1925
+ */
1926
+ currentNode: Node;
1927
+ /**
1928
+ * Moves the iterator to the first parent node of current node, and
1929
+ * returns it. Returns `null` if no such node exists.
1930
+ */
1931
+ parentNode(): Node | null;
1932
+ /**
1933
+ * Moves the iterator to the first child node of current node, and
1934
+ * returns it. Returns `null` if no such node exists.
1935
+ */
1936
+ firstChild(): Node | null;
1937
+ /**
1938
+ * Moves the iterator to the last child node of current node, and
1939
+ * returns it. Returns `null` if no such node exists.
1940
+ */
1941
+ lastChild(): Node | null;
1942
+ /**
1943
+ * Moves the iterator to the next sibling of current node, and
1944
+ * returns it. Returns `null` if no such node exists.
1945
+ */
1946
+ nextSibling(): Node | null;
1947
+ /**
1948
+ * Moves the iterator to the previous sibling of current node, and
1949
+ * returns it. Returns `null` if no such node exists.
1950
+ */
1951
+ previousSibling(): Node | null;
1952
+ /**
1953
+ * Returns the next node in the subtree, or `null` if there are none.
1954
+ */
1955
+ nextNode(): Node | null;
1956
+ /**
1957
+ * Returns the previous node in the subtree, or `null` if there
1958
+ * are none.
1959
+ */
1960
+ previousNode(): Node | null;
1961
+ _current: Node;
1962
+ }
1963
+ /**
1964
+ * Represents an abstract range with a start and end boundary point.
1965
+ */
1966
+ interface AbstractRange {
1967
+ /**
1968
+ * Returns the start node of the range.
1969
+ */
1970
+ readonly startContainer: Node;
1971
+ /**
1972
+ * Returns the start offset of the range.
1973
+ */
1974
+ readonly startOffset: number;
1975
+ /**
1976
+ * Returns the end node of the range.
1977
+ */
1978
+ readonly endContainer: Node;
1979
+ /**
1980
+ * Returns the end offest of the range.
1981
+ */
1982
+ readonly endOffset: number;
1983
+ /**
1984
+ * Returns `true` if the range starts and ends at the same point.
1985
+ */
1986
+ readonly collapsed: boolean;
1987
+ _start: BoundaryPoint;
1988
+ _end: BoundaryPoint;
1989
+ readonly _startNode: Node;
1990
+ readonly _startOffset: number;
1991
+ readonly _endNode: Node;
1992
+ readonly _endOffset: number;
1993
+ readonly _collapsed: boolean;
1994
+ }
1995
+ /**
1996
+ * Represents a live range.
1997
+ */
1998
+ interface Range extends AbstractRange {
1999
+ START_TO_START: number;
2000
+ START_TO_END: number;
2001
+ END_TO_END: number;
2002
+ END_TO_START: number;
2003
+ /**
2004
+ * Returns the node, furthest away from the document, that is an
2005
+ * ancestor of both range's start node and end node.
2006
+ */
2007
+ readonly commonAncestorContainer: Node;
2008
+ /**
2009
+ * Sets the start of the range to the given boundary point.
2010
+ *
2011
+ * @param node - node of the boundary point
2012
+ * @param offset - offset of the boundary point along node's content
2013
+ */
2014
+ setStart(node: Node, offset: number): void;
2015
+ /**
2016
+ * Sets the end of the range to the given boundary point.
2017
+ *
2018
+ * @param node - node of the boundary point
2019
+ * @param offset - offset of the boundary point along node's content
2020
+ */
2021
+ setEnd(node: Node, offset: number): void;
2022
+ /**
2023
+ * Sets the start of the range to just before the given node.
2024
+ *
2025
+ * @param node - node of the boundary point
2026
+ */
2027
+ setStartBefore(node: Node): void;
2028
+ /**
2029
+ * Sets the start of the range to just after the given node.
2030
+ *
2031
+ * @param node - node of the boundary point
2032
+ */
2033
+ setStartAfter(node: Node): void;
2034
+ /**
2035
+ * Sets the end of the range to just before the given node.
2036
+ *
2037
+ * @param node - node of the boundary point
2038
+ */
2039
+ setEndBefore(node: Node): void;
2040
+ /**
2041
+ * Sets the end of the range to just after the given node.
2042
+ *
2043
+ * @param node - node of the boundary point
2044
+ */
2045
+ setEndAfter(node: Node): void;
2046
+ /**
2047
+ * Collapses the range.
2048
+ *
2049
+ * @param toStart - `true` to collapse to start node, otherwise
2050
+ * `false` to collapse to the end node.
2051
+ */
2052
+ collapse(toStart?: boolean): void;
2053
+ /**
2054
+ * Sets the range to contain the given node.
2055
+ *
2056
+ * @param node - the range to select
2057
+ */
2058
+ selectNode(node: Node): void;
2059
+ /**
2060
+ * Sets the range to contain the given node's contens.
2061
+ *
2062
+ * @param node - the range to select
2063
+ */
2064
+ selectNodeContents(node: Node): void;
2065
+ /**
2066
+ * Compares the boundary points of this range with another one.
2067
+ *
2068
+ * @param how - comparison method:
2069
+ * * `EndToEnd` - compares the end boundary-point of `sourceRange` to the end
2070
+ * boundary-point of this range.
2071
+ * * `EndToStart` - compares the end boundary-point of `sourceRange` to the
2072
+ * start boundary-point of this range.
2073
+ * * `StartToEnd` - compares the start boundary-point of `sourceRange` to the
2074
+ * end boundary-point of this range.
2075
+ * * `StartToStart` - compares the start boundary-point of `sourceRange` to
2076
+ * the start boundary-point of this range.
2077
+ * @param sourceRange - the range to compare to
2078
+ *
2079
+ * @returns a number depending on boundaries of ranges relative to each other:
2080
+ * * `-1` if the corresponding boundary point of this is range comes before
2081
+ * that of `sourceRange`
2082
+ * * `1` if the corresponding boundary point of this is range comes after
2083
+ * that of `sourceRange`
2084
+ * * `0` if corresponding boundary points of both ranges are equal
2085
+ */
2086
+ compareBoundaryPoints(how: HowToCompare, sourceRange: Range): number;
2087
+ /**
2088
+ * Removes the contents of the range from the tree.
2089
+ */
2090
+ deleteContents(): void;
2091
+ /**
2092
+ * Moves the contents of the range to a document fragment.
2093
+ */
2094
+ extractContents(): DocumentFragment;
2095
+ /**
2096
+ * Copies the contents of the range to a document fragment.
2097
+ */
2098
+ cloneContents(): DocumentFragment;
2099
+ /**
2100
+ * Inserts a node at the start boundary point.
2101
+ *
2102
+ * @param node - the node to insert
2103
+ */
2104
+ insertNode(node: Node): void;
2105
+ /**
2106
+ * Moves content of the Range into a new node, placing the new node
2107
+ * at the start of the range.
2108
+ *
2109
+ * @param newParent - a node to receive range's content
2110
+ */
2111
+ surroundContents(newParent: Node): void;
2112
+ /**
2113
+ * Creates a new range with identical boundary points.
2114
+ */
2115
+ cloneRange(): Range;
2116
+ /**
2117
+ * Unused method. Kept for compatibility.
2118
+ */
2119
+ detach(): void;
2120
+ /**
2121
+ * Determines whether the range contains the given boundary point.
2122
+ *
2123
+ * @param node - the node of the boundary point
2124
+ * @param offset - the offset of the boundary point
2125
+ */
2126
+ isPointInRange(node: Node, offset: number): boolean;
2127
+ /**
2128
+ * Returns `-1`, `0`, or `1` depending on whether `node` is
2129
+ * before, the same as, or after the range.
2130
+ *
2131
+ * @param node - the node to compare
2132
+ * @param offset - an offset within node
2133
+ */
2134
+ comparePoint(node: Node, offset: number): number;
2135
+ /**
2136
+ * Determines whether the given node intersects the range.
2137
+ *
2138
+ * @param node - the node to check
2139
+ */
2140
+ intersectsNode(node: Node): boolean;
2141
+ }
2142
+ /**
2143
+ * Represents a html element node.
2144
+ */
2145
+ interface HTMLElement extends Element {}
2146
+ /**
2147
+ * Represents a `<slot>` element.
2148
+ */
2149
+ interface HTMLSlotElement extends HTMLElement {}
2150
+ /**
2151
+ * Defines the event phase.
2152
+ */
2153
+ declare enum EventPhase {
2154
+ None = 0,
2155
+ Capturing = 1,
2156
+ AtTarget = 2,
2157
+ Bubbling = 3
2158
+ }
2159
+ /**
2160
+ * Defines the type of a node object.
2161
+ */
2162
+ declare enum NodeType {
2163
+ Element = 1,
2164
+ Attribute = 2,
2165
+ Text = 3,
2166
+ CData = 4,
2167
+ EntityReference = 5, // historical
2168
+ Entity = 6, // historical
2169
+ ProcessingInstruction = 7,
2170
+ Comment = 8,
2171
+ Document = 9,
2172
+ DocumentType = 10,
2173
+ DocumentFragment = 11,
2174
+ Notation = 12
2175
+ }
2176
+ /**
2177
+ * Defines the position of a node in the document relative to another
2178
+ * node.
2179
+ */
2180
+ declare enum Position {
2181
+ SameNode = 0,
2182
+ Disconnected = 1,
2183
+ Preceding = 2,
2184
+ Following = 4,
2185
+ Contains = 8,
2186
+ ContainedBy = 16,
2187
+ ImplementationSpecific = 32
2188
+ }
2189
+ /**
2190
+ * Defines the return value of a filter callback.
2191
+ */
2192
+ declare enum FilterResult {
2193
+ Accept = 1,
2194
+ Reject = 2,
2195
+ Skip = 3
2196
+ }
2197
+ /**
2198
+ * Defines what to show in node filter.
2199
+ */
2200
+ declare enum WhatToShow {
2201
+ All = 4294967295,
2202
+ Element = 1,
2203
+ Attribute = 2,
2204
+ Text = 4,
2205
+ CDataSection = 8,
2206
+ EntityReference = 16,
2207
+ Entity = 32,
2208
+ ProcessingInstruction = 64,
2209
+ Comment = 128,
2210
+ Document = 256,
2211
+ DocumentType = 512,
2212
+ DocumentFragment = 1024,
2213
+ Notation = 2048
2214
+ }
2215
+ /**
2216
+ * Defines how boundary points are compared.
2217
+ */
2218
+ declare enum HowToCompare {
2219
+ StartToStart = 0,
2220
+ StartToEnd = 1,
2221
+ EndToEnd = 2,
2222
+ EndToStart = 3
2223
+ }
2224
+ /**
2225
+ * Represents settings for the getRootNode() function.
2226
+ */
2227
+ interface GetRootNodeOptions {
2228
+ composed?: boolean;
2229
+ }
2230
+ /**
2231
+ * Defines the criteria for the mutations to observe.
2232
+ */
2233
+ interface MutationObserverInit {
2234
+ childList?: boolean;
2235
+ attributes?: boolean;
2236
+ characterData?: boolean;
2237
+ subtree?: boolean;
2238
+ attributeOldValue?: boolean;
2239
+ characterDataOldValue?: boolean;
2240
+ attributeFilter?: string[];
2241
+ }
2242
+ /**
2243
+ * Defines an entry in the event listeners list.
2244
+ */
2245
+ type EventListenerEntry = {
2246
+ type: string;
2247
+ callback: EventListener;
2248
+ capture: boolean;
2249
+ passive: boolean;
2250
+ once: boolean;
2251
+ removed: boolean;
2252
+ };
2253
+ /**
2254
+ * Defines a non-null event handler.
2255
+ */
2256
+ type EventHandlerNonNull = ((event: Event) => any);
2257
+ /**
2258
+ * Defines an event handler.
2259
+ */
2260
+ type EventHandler = EventHandlerNonNull | null;
2261
+ /**
2262
+ * Defines a struct containing an event handler.
2263
+ */
2264
+ type EventHandlerEntry = {
2265
+ value: EventHandler;
2266
+ listener: EventListenerEntry | null;
2267
+ };
2268
+ /**
2269
+ * Defines a boundary point which is a tuple consisting of a node and an offset
2270
+ * into the node's contents.
2271
+ */
2272
+ type BoundaryPoint = [Node, number];
2273
+ /**
2274
+ * Defines a callback function which is invoked after nodes registered with the
2275
+ * observe() method, are mutated.
2276
+ *
2277
+ * @param mutations - a list of `MutationRecord` objects
2278
+ * @param observer - the constructed `MutationObserver` object
2279
+ */
2280
+ type MutationCallback = (mutations: MutationRecord[], observer: MutationObserver) => void;
2281
+ /**
2282
+ * Represents a registered observer associated with a node.
2283
+ */
2284
+ type RegisteredObserver = {
2285
+ observer: MutationObserver;
2286
+ options: MutationObserverInit;
2287
+ };
2288
+ /**
2289
+ * Represents a transient registered observer associated with a node.
2290
+ * Transient registered observers are used to track mutations within a given
2291
+ * node's descendants after node has been removed so they do not get lost when
2292
+ * subtree is set to true on node's parent.
2293
+ */
2294
+ type TransientRegisteredObserver = RegisteredObserver & {
2295
+ source: RegisteredObserver;
2296
+ };
2297
+ /**
2298
+ * Defines the mode of a shadow root.
2299
+ */
2300
+ type ShadowRootMode = 'open' | 'closed';
2301
+ /**
2302
+ * Represents a potential event target.
2303
+ */
2304
+ type PotentialEventTarget = EventTarget | null;
2305
+ /**
2306
+ * Represents an object on the event path.
2307
+ */
2308
+ type EventPathItem = {
2309
+ invocationTarget: EventTarget;
2310
+ invocationTargetInShadowTree: boolean;
2311
+ shadowAdjustedTarget: PotentialEventTarget;
2312
+ relatedTarget: PotentialEventTarget;
2313
+ touchTargetList: PotentialEventTarget[];
2314
+ rootOfClosedTree: boolean;
2315
+ slotInClosedTree: boolean;
2316
+ };
2317
+ /**
2318
+ * Represents a document origin.
2319
+ * `null` represents an opaque origin.
2320
+ */
2321
+ type Origin = null | [string,
2322
+ // scheme
2323
+ string | number | number[],
2324
+ // host
2325
+ null | number,
2326
+ // port
2327
+ null | string];
2328
+ /**
2329
+ * Represents a `<slot>` element.
2330
+ */
2331
+ interface HTMLSlotElement {
2332
+ name: string;
2333
+ assignedNodes(options?: any): Node[];
2334
+ assignedElements(options?: any): Element[];
2335
+ }
2336
+ /**
2337
+ * Represents a custom element definition.
2338
+ */
2339
+ type CustomElementDefinition = {
2340
+ name: string;
2341
+ localName: string;
2342
+ constructor: (new (...args: any[]) => Element);
2343
+ observedAttributes: string[];
2344
+ lifecycleCallbacks: {
2345
+ "connectedCallback": ((args: any[]) => any) | null;
2346
+ "disconnectedCallback": ((args: any[]) => any) | null;
2347
+ "adoptedCallback": ((args: any) => any[]) | null;
2348
+ "attributeChangedCallback": ((args: any[]) => any) | null;
2349
+ "formAssociatedCallback": ((args: any[]) => any) | null;
2350
+ "formDisabledCallback": ((args: any[]) => any) | null;
2351
+ "formResetCallback": ((args: any[]) => any) | null;
2352
+ "formStateRestoreCallback": ((args: any[]) => any) | null;
2353
+ };
2354
+ constructionStack: (Element | boolean)[];
2355
+ formAssociated: boolean;
2356
+ disableInternals: boolean;
2357
+ disableShadow: boolean;
2358
+ };
2359
+ /**
2360
+ * Defines an attribute change step.
2361
+ */
2362
+ type AttributeChangeStep = ((element: Element, localName: string, oldValue: string | null, value: string | null, namespace: string | null) => any);
2363
+ /**
2364
+ * Defines the options used while creating an XML document.
2365
+ */
2366
+ interface XMLBuilderOptions {
2367
+ [key: string]: unknown;
2368
+ /**
2369
+ * A version number string, e.g. `"1.0"`
2370
+ */
2371
+ version: "1.0";
2372
+ /**
2373
+ * Encoding declaration, e.g. `"UTF-8"`
2374
+ */
2375
+ encoding: string | undefined;
2376
+ /**
2377
+ * Standalone document declaration: `true` or `false`
2378
+ */
2379
+ standalone: boolean | undefined;
2380
+ /**
2381
+ * Whether nodes with `null` values will be kept or ignored
2382
+ */
2383
+ keepNullNodes: boolean;
2384
+ /**
2385
+ * Whether attributes with `null` values will be kept or ignored
2386
+ */
2387
+ keepNullAttributes: boolean;
2388
+ /**
2389
+ * Whether converter strings will be ignored when converting JS
2390
+ * objects to nodes
2391
+ */
2392
+ ignoreConverters: boolean;
2393
+ /**
2394
+ * Whether whitespace-only text nodes are skipped or not.
2395
+ */
2396
+ skipWhitespaceOnlyText: boolean;
2397
+ /**
2398
+ * Defines string keys used while converting JS objects to nodes.
2399
+ */
2400
+ convert: ConvertOptions;
2401
+ /**
2402
+ * Defines default namespaces to apply to all elements and attributes.
2403
+ */
2404
+ defaultNamespace: {
2405
+ ele: undefined | null | string;
2406
+ att: undefined | null | string;
2407
+ };
2408
+ /**
2409
+ * Defines namespace aliases.
2410
+ */
2411
+ namespaceAlias: {
2412
+ /**
2413
+ * HTML namespace
2414
+ */
2415
+ html: "http://www.w3.org/1999/xhtml";
2416
+ /**
2417
+ * XML namespace
2418
+ */
2419
+ xml: "http://www.w3.org/XML/1998/namespace";
2420
+ /**
2421
+ * XMLNS namespace
2422
+ */
2423
+ xmlns: "http://www.w3.org/2000/xmlns/";
2424
+ /**
2425
+ * MathML namespace
2426
+ */
2427
+ mathml: "http://www.w3.org/1998/Math/MathML";
2428
+ /**
2429
+ * SVG namespace
2430
+ */
2431
+ svg: "http://www.w3.org/2000/svg";
2432
+ /**
2433
+ * XLink namespace
2434
+ */
2435
+ xlink: "http://www.w3.org/1999/xlink";
2436
+ /**
2437
+ * User supplied namespace alias
2438
+ */
2439
+ [key: string]: string | null;
2440
+ };
2441
+ /**
2442
+ * Defines a replacement for invalid characters in input strings.
2443
+ *
2444
+ * If `invalidCharReplacement` is a string, each invalid character in an input
2445
+ * string will be replaced with it; otherwise if `invalidCharReplacement`
2446
+ * is a function it will be passed each invalid character and should return
2447
+ * a replacement character.
2448
+ *
2449
+ * The arguments to the replacement function are:
2450
+ * - char - the invalid character to be replaced
2451
+ * - offset - the offset of the invalid character
2452
+ * - str - the input string
2453
+ */
2454
+ invalidCharReplacement: string | ((char: string, offset: number, str: string) => string) | undefined;
2455
+ /**
2456
+ * Defines custom parser functions.
2457
+ */
2458
+ parser: ParserOptions | undefined;
2459
+ }
2460
+ /**
2461
+ * Defines the identifier strings of the DocType node.
2462
+ */
2463
+ interface DTDOptions {
2464
+ /**
2465
+ * Name of the DTD. If name is omitted, it will be taken from the document
2466
+ * element node.
2467
+ */
2468
+ name?: string;
2469
+ /**
2470
+ * Public identifier of the DTD
2471
+ */
2472
+ pubID?: string;
2473
+ /**
2474
+ * System identifier of the DTD
2475
+ */
2476
+ sysID?: string;
2477
+ }
2478
+ /**
2479
+ * Defines string keys used while converting JS objects to nodes.
2480
+ */
2481
+ interface ConvertOptions {
2482
+ /**
2483
+ * When prepended to a JS object key, converts its key-value pair
2484
+ * to an attribute. Defaults to `"@"`. Multiple attributes can also be grouped
2485
+ * under the attribute key. For example:
2486
+ * ```js
2487
+ * obj1 = { pilot: { '@callsign': 'Maverick', '@rank': 'Lieutenant' } }
2488
+ * obj2 = { pilot: { '@': { 'callsign': 'Maverick', 'rank': 'Lieutenant' } } }
2489
+ * ```
2490
+ * both become:
2491
+ * ```xml
2492
+ * <pilot callsign="Maverick" rank="Lieutenant"/>
2493
+ * ````
2494
+ */
2495
+ att: string;
2496
+ /**
2497
+ * When prepended to a JS object key, converts its value to a processing
2498
+ * instruction node. Defaults to `"?"`. Instruction target and value should
2499
+ * be separated with a single space character. For example:
2500
+ * ```js
2501
+ * obj = {
2502
+ * '?': 'background classified ref="NAM#123456"',
2503
+ * pilot: 'Pete Mitchell'
2504
+ * }
2505
+ * ```
2506
+ * becomes:
2507
+ * ```xml
2508
+ * <?background classified ref="NAM#123456"?>
2509
+ * <pilot>Pete Mitchell</pilot>
2510
+ * ````
2511
+ */
2512
+ ins: string;
2513
+ /**
2514
+ * When prepended to a JS object key, converts its value to a text node.
2515
+ * Defaults to `"#"`. For example:
2516
+ * ```js
2517
+ * obj = { monologue: {
2518
+ * '#': 'Talk to me Goose!',
2519
+ * } }
2520
+ * ```
2521
+ * becomes:
2522
+ * ```xml
2523
+ * <monologue>Talk to me Goose!</monologue>
2524
+ * ````
2525
+ *
2526
+ * _Note:_ Since JS objects cannot contain duplicate keys, multiple text
2527
+ * nodes can be created by adding some unique text after each object
2528
+ * key. For example:
2529
+ * ```js
2530
+ * obj = { monologue: {
2531
+ * '#1': 'Talk to me Goose!',
2532
+ * '#2': 'Talk to me...'
2533
+ * } }
2534
+ * ```
2535
+ * becomes:
2536
+ * ```xml
2537
+ * <monologue>Talk to me Goose!Talk to me...</monologue>
2538
+ * ````
2539
+ *
2540
+ * _Note:_ `"#"` also allows mixed content. Example:
2541
+ * ```js
2542
+ * obj = { monologue: {
2543
+ * '#1': 'Talk to me Goose!',
2544
+ * 'cut': 'dog tag shot',
2545
+ * '#2': 'Talk to me...'
2546
+ * } }
2547
+ * ```
2548
+ * becomes:
2549
+ * ```xml
2550
+ * <monologue>
2551
+ * Talk to me Goose!
2552
+ * <cut>dog tag shot</cut>
2553
+ * Talk to me...
2554
+ * </monologue>
2555
+ * ````
2556
+ */
2557
+ text: string;
2558
+ /**
2559
+ * When prepended to a JS object key, converts its value to a CDATA
2560
+ * node. Defaults to `"$"`. For example:
2561
+ * ```js
2562
+ * obj = {
2563
+ * '$': '<a href="https://topgun.fandom.com/wiki/MiG-28"/>',
2564
+ * aircraft: 'MiG-28'
2565
+ * }
2566
+ * ```
2567
+ * becomes:
2568
+ * ```xml
2569
+ * <![CDATA[<a href="https://topgun.fandom.com/wiki/MiG-28"/>]]>
2570
+ * <aircraft>MiG-28</aircraft>
2571
+ * ````
2572
+ */
2573
+ cdata: string;
2574
+ /**
2575
+ * When prepended to a JS object key, converts its value to a
2576
+ * comment node. Defaults to `"!"`. For example:
2577
+ * ```js
2578
+ * obj = {
2579
+ * '!': 'Fictional; MiGs use odd numbers for fighters.',
2580
+ * aircraft: 'MiG-28'
2581
+ * }
2582
+ * ```
2583
+ * becomes:
2584
+ * ```xml
2585
+ * <!--Fictional; MiGs use odd numbers for fighters.-->
2586
+ * <aircraft>MiG-28</aircraft>
2587
+ * ````
2588
+ */
2589
+ comment: string;
2590
+ }
2591
+ /**
2592
+ * Defines custom parser functions.
2593
+ */
2594
+ type ParserOptions = {
2595
+ /**
2596
+ * Main parser function which parses the given object and returns an `XMLBuilder`.
2597
+ *
2598
+ * @param node - node to recieve parsed content
2599
+ * @param obj - object to parse
2600
+ *
2601
+ * @returns the last top level element node created
2602
+ */
2603
+ parse?: (parent: XMLBuilder, obj: string | ExpandObject) => XMLBuilder;
2604
+ /**
2605
+ * Creates a DocType node.
2606
+ * The node will be skipped if the function returns `undefined`.
2607
+ *
2608
+ * @param parent - parent node
2609
+ * @param name - node name
2610
+ * @param publicId - public identifier
2611
+ * @param systemId - system identifier
2612
+ *
2613
+ * @returns the parent document node
2614
+ */
2615
+ docType?: (parent: XMLBuilder, name: string, publicId: string, systemId: string) => XMLBuilder | undefined;
2616
+ /**
2617
+ * Creates a comment node.
2618
+ * The node will be skipped if the function returns `undefined`.
2619
+ *
2620
+ * @param parent - parent node
2621
+ * @param data - node data
2622
+ *
2623
+ * @returns the parent element node
2624
+ */
2625
+ comment?: (parent: XMLBuilder, data: string) => XMLBuilder | undefined;
2626
+ /**
2627
+ * Creates a text node.
2628
+ * The node will be skipped if the function returns `undefined`.
2629
+ *
2630
+ * @param parent - parent node
2631
+ * @param data - node data
2632
+ *
2633
+ * @returns the parent element node
2634
+ */
2635
+ text?: (parent: XMLBuilder, data: string) => XMLBuilder | undefined;
2636
+ /**
2637
+ * Creates a processing instruction node.
2638
+ * The node will be skipped if the function returns `undefined`.
2639
+ *
2640
+ * @param parent - parent node
2641
+ * @param target - instruction target
2642
+ * @param data - node data
2643
+ *
2644
+ * @returns the parent element node
2645
+ */
2646
+ instruction?: (parent: XMLBuilder, target: string, data: string) => XMLBuilder | undefined;
2647
+ /**
2648
+ * Creates a CData section node.
2649
+ * The node will be skipped if the function returns `undefined`.
2650
+ *
2651
+ * @param parent - parent node
2652
+ * @param data - node data
2653
+ *
2654
+ * @returns the parent element node
2655
+ */
2656
+ cdata?: (parent: XMLBuilder, data: string) => XMLBuilder | undefined;
2657
+ /**
2658
+ * Creates an element node.
2659
+ * The node will be skipped if the function returns `undefined`.
2660
+ *
2661
+ * @param parent - parent node
2662
+ * @param namespace - element namespace
2663
+ * @param name - node name
2664
+ *
2665
+ * @returns the new element node
2666
+ */
2667
+ element?: (parent: XMLBuilder, namespace: string | null | undefined, name: string) => XMLBuilder | undefined;
2668
+ /**
2669
+ * Creates an attribute or namespace declaration.
2670
+ * The node will be skipped if the function returns `undefined`.
2671
+ *
2672
+ * @param parent - parent node
2673
+ * @param namespace - attribute namespace
2674
+ * @param name - attribute name
2675
+ * @param value - attribute value
2676
+ *
2677
+ * @returns the parent element node
2678
+ */
2679
+ attribute?: (parent: XMLBuilder, namespace: string | null | undefined, name: string, value: string) => XMLBuilder | undefined;
2680
+ /**
2681
+ * Sanitizes input strings.
2682
+ *
2683
+ * @param str - input string
2684
+ */
2685
+ sanitize?(str: string): string;
2686
+ };
2687
+ /**
2688
+ * Defines the options passed to the writer.
2689
+ */
2690
+ type BaseWriterOptions = {
2691
+ /**
2692
+ * Output format. Defaults to `"xml"`.
2693
+ * - `"xml"` - Serializes the document as a string in XML format.
2694
+ * - `"map"` - Serializes the document as an object using `Map`s and
2695
+ * `Array`s.
2696
+ * - `"object"` - Serializes the document as an object using `Object`s and
2697
+ * `Array`s.
2698
+ * - `"json"` - Serializes the document as a JSON string.
2699
+ * - `"yaml"` - Serilizes the document as a YAML string
2700
+ */
2701
+ format?: "xml" | "map" | "object" | "json" | "yaml";
2702
+ /**
2703
+ * Ensures that the document adheres to the syntax rules specified by the
2704
+ * XML specification. If this flag is set and the document is not well-formed
2705
+ * errors will be thrown. Defaults to `false`.
2706
+ */
2707
+ wellFormed?: boolean;
2708
+ };
2709
+ /**
2710
+ * Defines the options passed to the map writer.
2711
+ */
2712
+ type MapWriterOptions = BaseWriterOptions & {
2713
+ /** @inheritdoc */
2714
+ format?: "map";
2715
+ /**
2716
+ * Groups consecutive nodes of same type under a single object. Defaults to
2717
+ * `false`.
2718
+ */
2719
+ group?: boolean;
2720
+ /**
2721
+ * Outputs child nodes as an array, even if the parent node has zero or one
2722
+ * child nodes.
2723
+ */
2724
+ verbose?: boolean;
2725
+ };
2726
+ /**
2727
+ * Defines the options passed to the object writer.
2728
+ */
2729
+ type ObjectWriterOptions = BaseWriterOptions & {
2730
+ /** @inheritdoc */
2731
+ format?: "object";
2732
+ /**
2733
+ * Groups consecutive nodes of same type under a single object. Defaults to
2734
+ * `false`.
2735
+ */
2736
+ group?: boolean;
2737
+ /**
2738
+ * Outputs child nodes as an array, even if the parent node has zero or one
2739
+ * child nodes.
2740
+ */
2741
+ verbose?: boolean;
2742
+ };
2743
+ /**
2744
+ * Defines the options passed to the XML writer.
2745
+ */
2746
+ type XMLWriterOptions = BaseWriterOptions & {
2747
+ /** @inheritdoc */
2748
+ format?: "xml";
2749
+ /**
2750
+ * Suppresses the XML declaration from the output. Defaults to `false`.
2751
+ */
2752
+ headless?: boolean;
2753
+ /**
2754
+ * Pretty-prints the XML tree. Defaults to `false`.
2755
+ */
2756
+ prettyPrint?: boolean;
2757
+ /**
2758
+ * Determines the indentation string for pretty printing. Defaults to two
2759
+ * space characters.
2760
+ */
2761
+ indent?: string;
2762
+ /**
2763
+ * Determines the newline string for pretty printing. Defaults to `"\n"`.
2764
+ */
2765
+ newline?: string;
2766
+ /**
2767
+ * Defines a fixed number of indentations to add to every line. Defaults to
2768
+ * `0`.
2769
+ */
2770
+ offset?: number;
2771
+ /**
2772
+ * Wraps attributes to the next line if the column width exceeds the given
2773
+ * value. Defaults to `0` which disables attribute wrapping.
2774
+ */
2775
+ width?: number;
2776
+ /**
2777
+ * Produces closing tags for empty element nodes. Defaults to `false`. With
2778
+ * this option set to `true`, closing tags will be produced for element nodes
2779
+ * without child nodes, e.g.
2780
+ * ```xml
2781
+ * <node></node>
2782
+ * ```
2783
+ * Otherwise, empty element nodes will be self-closed, e.g.
2784
+ * ```xml
2785
+ * <node/>
2786
+ * ```
2787
+ */
2788
+ allowEmptyTags?: boolean;
2789
+ /**
2790
+ * Indents contents of text-only element nodes. Defaults to `false` which
2791
+ * keeps a text node on the same line with its containing element node, e.g.
2792
+ * ```xml
2793
+ * <node>some text</node>
2794
+ * ```
2795
+ * Otherwise, it will be printed on a new line. e.g.
2796
+ * ```xml
2797
+ * <node>
2798
+ * some text
2799
+ * </node>
2800
+ * ```
2801
+ * _Note:_ Element nodes with mixed content are always indented regardless
2802
+ * of this setting.
2803
+ */
2804
+ indentTextOnlyNodes?: boolean;
2805
+ /**
2806
+ * Inserts a space character before the slash character of self-closing tags.
2807
+ * Defaults to `false`. With this options set to `true`, a space character
2808
+ * will be inserted before the slash character of self-closing tags, e.g.
2809
+ * ```xml
2810
+ * <node />
2811
+ * ```
2812
+ */
2813
+ spaceBeforeSlash?: boolean;
2814
+ };
2815
+ /**
2816
+ * Defines the options passed to the JSON writer.
2817
+ */
2818
+ type JSONWriterOptions = BaseWriterOptions & {
2819
+ /** @inheritdoc */
2820
+ format?: "json";
2821
+ /**
2822
+ * Pretty-prints the XML tree. Defaults to `false`.
2823
+ */
2824
+ prettyPrint?: boolean;
2825
+ /**
2826
+ * Determines the indentation string for pretty printing. Defaults to two
2827
+ * space characters.
2828
+ */
2829
+ indent?: string;
2830
+ /**
2831
+ * Determines the newline string for pretty printing. Defaults to `"\n"`.
2832
+ */
2833
+ newline?: string;
2834
+ /**
2835
+ * Defines a fixed number of indentations to add to every line. Defaults to
2836
+ * `0`.
2837
+ */
2838
+ offset?: number;
2839
+ /**
2840
+ * Groups consecutive nodes of same type under a single object. Defaults to
2841
+ * `false`.
2842
+ */
2843
+ group?: boolean;
2844
+ /**
2845
+ * Outputs child nodes as an array, even if the parent node has zero or one
2846
+ * child nodes.
2847
+ */
2848
+ verbose?: boolean;
2849
+ };
2850
+ /**
2851
+ * Defines the options passed to the YAML writer.
2852
+ */
2853
+ type YAMLWriterOptions = BaseWriterOptions & {
2854
+ /** @inheritdoc */
2855
+ format?: "yaml";
2856
+ /**
2857
+ * Determines the indentation string. Defaults to two space characters.
2858
+ */
2859
+ indent?: string;
2860
+ /**
2861
+ * Determines the newline string. Defaults to `"\n"`.
2862
+ */
2863
+ newline?: string;
2864
+ /**
2865
+ * Defines a fixed number of indentations to add to every line. Defaults to
2866
+ * `0`.
2867
+ */
2868
+ offset?: number;
2869
+ /**
2870
+ * Groups consecutive nodes of same type under a single object. Defaults to
2871
+ * `false`.
2872
+ */
2873
+ group?: boolean;
2874
+ /**
2875
+ * Outputs child nodes as an array, even if the parent node has only one
2876
+ * child node.
2877
+ */
2878
+ verbose?: boolean;
2879
+ };
2880
+ type XMLSerializedAsObject = {
2881
+ [key: string]: string | XMLSerializedAsObject | XMLSerializedAsObjectArray;
2882
+ };
2883
+ type XMLSerializedAsObjectArray = Array<string | XMLSerializedAsObject>;
2884
+ type XMLSerializedAsMap = Map<string, string | XMLSerializedAsMap | XMLSerializedAsMapArray>;
2885
+ type XMLSerializedAsMapArray = Array<string | XMLSerializedAsMap>;
2886
+ /**
2887
+ * Represents the type of a variable that can be expanded by the `ele` function
2888
+ * into nodes.
2889
+ */
2890
+ type ExpandObject = {
2891
+ [key: string]: any;
2892
+ } | Map<string, any> | any[] | Set<any> | ((...args: any) => any);
2893
+ /**
2894
+ * Represents the type of a variable that is a JS object defining
2895
+ * attributes.
2896
+ */
2897
+ type AttributesObject = Map<string, any> | {
2898
+ /**
2899
+ * Attribute key/value pairs
2900
+ */
2901
+ [key: string]: any;
2902
+ };
2903
+ /**
2904
+ * Represents the type of a variable that is a JS object defining
2905
+ * processing instructions.
2906
+ */
2907
+ type PIObject = Map<string, string> | string[] | {
2908
+ /**
2909
+ * Processing instruction target/data pairs
2910
+ */
2911
+ [key: string]: string;
2912
+ };
2913
+ /**
2914
+ * Represents a wrapper around XML nodes to implement easy to use and
2915
+ * chainable document builder methods.
2916
+ */
2917
+ interface XMLBuilder {
2918
+ /**
2919
+ * Returns the underlying DOM node.
2920
+ */
2921
+ readonly node: Node;
2922
+ /**
2923
+ * Gets the options used while creating an XML document.
2924
+ */
2925
+ readonly options: XMLBuilderOptions;
2926
+ /**
2927
+ * Sets builder options.
2928
+ *
2929
+ * @param - builder options
2930
+ *
2931
+ * @returns current element node
2932
+ */
2933
+ set(builderOptions: Partial<XMLBuilderOptions>): XMLBuilder;
2934
+ /**
2935
+ * Creates a new element node and appends it to the list of child nodes.
2936
+ *
2937
+ * @param namespace - element namespace
2938
+ * @param name - element name
2939
+ * @param attributes - a JS object with element attributes
2940
+ *
2941
+ * @returns the new element node
2942
+ */
2943
+ ele(namespace: string | null, name: string, attributes?: AttributesObject): XMLBuilder;
2944
+ /**
2945
+ * Creates a new element node and appends it to the list of child nodes.
2946
+ *
2947
+ * @param name - element name
2948
+ * @param attributes - a JS object with element attributes
2949
+ *
2950
+ * @returns the new element node
2951
+ */
2952
+ ele(name: string, attributes?: AttributesObject): XMLBuilder;
2953
+ /**
2954
+ * Creates new element nodes from the given JS object and appends it to the
2955
+ * list of child nodes.
2956
+ *
2957
+ * @param obj - a JS object representing nodes to insert
2958
+ *
2959
+ * @returns the last top level element node created
2960
+ */
2961
+ ele(obj: ExpandObject): XMLBuilder;
2962
+ /**
2963
+ * Creates new element nodes from the given XML document string appends it to the
2964
+ * list of child nodes.
2965
+ *
2966
+ * @param content - an XML document string representing nodes to insert
2967
+ *
2968
+ * @returns the last top level element node created
2969
+ */
2970
+ ele(content: string): XMLBuilder;
2971
+ /**
2972
+ * Removes this node from the XML document.
2973
+ *
2974
+ * @returns parent element node
2975
+ */
2976
+ remove(): XMLBuilder;
2977
+ /**
2978
+ * Creates or updates an element attribute.
2979
+ *
2980
+ * @param namespace - namespace of the attribute
2981
+ * @param name - attribute name
2982
+ * @param value - attribute value
2983
+ *
2984
+ * @returns current element node
2985
+ */
2986
+ att(namespace: string | null, name: string, value: string): XMLBuilder;
2987
+ /**
2988
+ * Creates or updates an element attribute.
2989
+ *
2990
+ * @param name - attribute name
2991
+ * @param value - attribute value
2992
+ *
2993
+ * @returns current element node
2994
+ */
2995
+ att(name: string, value: string): XMLBuilder;
2996
+ /**
2997
+ * Creates or updates an element attribute.
2998
+ *
2999
+ * @param obj - a JS object containing element attributes and values
3000
+ *
3001
+ * @returns current element node
3002
+ */
3003
+ att(obj: AttributesObject): XMLBuilder;
3004
+ /**
3005
+ * Removes an attribute.
3006
+ *
3007
+ * @param name - attribute name
3008
+ *
3009
+ * @returns current element node
3010
+ */
3011
+ removeAtt(name: string): XMLBuilder;
3012
+ /**
3013
+ * Removes a list of attributes.
3014
+ *
3015
+ * @param names - an array with attribute names
3016
+ *
3017
+ * @returns current element node
3018
+ */
3019
+ removeAtt(names: string[]): XMLBuilder;
3020
+ /**
3021
+ * Removes an attribute.
3022
+ *
3023
+ * @param namespace - namespace of the attribute to remove
3024
+ * @param name - attribute name
3025
+ *
3026
+ * @returns current element node
3027
+ */
3028
+ removeAtt(namespace: string | null, name: string): XMLBuilder;
3029
+ /**
3030
+ * Removes a list of attributes.
3031
+ *
3032
+ * @param namespace - namespace of the attributes to remove
3033
+ * @param names - an array with attribute names
3034
+ *
3035
+ * @returns current element node
3036
+ */
3037
+ removeAtt(namespace: string | null, names: string[]): XMLBuilder;
3038
+ /**
3039
+ * Creates a new text node and appends it to the list of child nodes.
3040
+ *
3041
+ * @param content - node content
3042
+ *
3043
+ * @returns current element node
3044
+ */
3045
+ txt(content: string): XMLBuilder;
3046
+ /**
3047
+ * Creates a new comment node and appends it to the list of child nodes.
3048
+ *
3049
+ * @param content - node content
3050
+ *
3051
+ * @returns current element node
3052
+ */
3053
+ com(content: string): XMLBuilder;
3054
+ /**
3055
+ * Creates a new CDATA node and appends it to the list of child nodes.
3056
+ *
3057
+ * @param content - node content
3058
+ *
3059
+ * @returns current element node
3060
+ */
3061
+ dat(content: string): XMLBuilder;
3062
+ /**
3063
+ * Creates a new processing instruction node and appends it to the list of
3064
+ * child nodes.
3065
+ *
3066
+ * @param target - instruction target
3067
+ * @param content - node content
3068
+ *
3069
+ * @returns current element node
3070
+ */
3071
+ ins(target: string, content?: string): XMLBuilder;
3072
+ /**
3073
+ * Creates new processing instruction nodes by expanding the given object and
3074
+ * appends them to the list of child nodes.
3075
+ *
3076
+ * @param contents - a JS object containing processing instruction targets
3077
+ * and values or an array of strings
3078
+ *
3079
+ * @returns current element node
3080
+ */
3081
+ ins(target: PIObject): XMLBuilder;
3082
+ /**
3083
+ * Updates XML declaration.
3084
+ *
3085
+ * @param options - declaration options
3086
+ *
3087
+ * @returns current element node
3088
+ */
3089
+ dec(options: {
3090
+ version?: "1.0";
3091
+ encoding?: string;
3092
+ standalone?: boolean;
3093
+ }): XMLBuilder;
3094
+ /**
3095
+ * Creates a new DocType node and inserts it into the document. If the
3096
+ * document already contains a DocType node it will be replaced by the new
3097
+ * node. Otherwise it will be inserted before the document element node.
3098
+ *
3099
+ * @param options - DocType identifiers
3100
+ *
3101
+ * @returns current element node
3102
+ */
3103
+ dtd(options?: DTDOptions): XMLBuilder;
3104
+ /**
3105
+ * Imports a node as a child node of this node. The nodes' descendants and
3106
+ * attributes will also be imported.
3107
+ *
3108
+ * @param node - the node to import
3109
+ *
3110
+ * _Note:_ The node will be cloned before being imported and this clone will
3111
+ * be inserted into the document; not the original node.
3112
+ *
3113
+ * _Note:_ If the imported node is a document, its document element node will
3114
+ * be imported. If the imported node is a document fragment its child nodes
3115
+ * will be imported.
3116
+ *
3117
+ * @returns current element node
3118
+ */
3119
+ import(node: XMLBuilder): XMLBuilder;
3120
+ /**
3121
+ * Returns the document node.
3122
+ */
3123
+ doc(): XMLBuilder;
3124
+ /**
3125
+ * Returns the root element node.
3126
+ */
3127
+ root(): XMLBuilder;
3128
+ /**
3129
+ * Returns the parent node.
3130
+ */
3131
+ up(): XMLBuilder;
3132
+ /**
3133
+ * Returns the previous sibling node.
3134
+ */
3135
+ prev(): XMLBuilder;
3136
+ /**
3137
+ * Returns the next sibling node.
3138
+ */
3139
+ next(): XMLBuilder;
3140
+ /**
3141
+ * Returns the first child node.
3142
+ */
3143
+ first(): XMLBuilder;
3144
+ /**
3145
+ * Returns the last child node.
3146
+ */
3147
+ last(): XMLBuilder;
3148
+ /**
3149
+ * Traverses through the child nodes of a node. `callback` is called with three
3150
+ * arguments: `(node, index, level)`.
3151
+ *
3152
+ * @param callback - a callback function to apply to each child node
3153
+ * @param self - whether to visit the current node along with child nodes
3154
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3155
+ * only the immediate child nodes
3156
+ * @param thisArg - value to use as this when executing callback
3157
+ */
3158
+ each(callback: ((node: XMLBuilder, index: number, level: number) => void), self?: boolean, recursive?: boolean, thisArg?: any): XMLBuilder;
3159
+ /**
3160
+ * Produces an array of values by transforming each child node with the given
3161
+ * callback function. `callback` is called with three arguments:
3162
+ * `(node, index, level)`.
3163
+ *
3164
+ * @param callback - a callback function to apply to each child node
3165
+ * @param self - whether to visit the current node along with child nodes
3166
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3167
+ * only the immediate child nodes
3168
+ * @param thisArg - value to use as this when executing callback
3169
+ */
3170
+ map<T>(callback: ((node: XMLBuilder, index: number, level: number) => T), self?: boolean, recursive?: boolean, thisArg?: any): T[];
3171
+ /**
3172
+ * Reduces child nodes into a single value by applying the given callback
3173
+ * function. `callback` is called with four arguments:
3174
+ * `(value, node, index, level)`.
3175
+ *
3176
+ * @param callback - a callback function to apply to each child node
3177
+ * @param initialValue - initial value of the iteration
3178
+ * @param self - whether to visit the current node along with child nodes
3179
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3180
+ * only the immediate child nodes
3181
+ * @param thisArg - value to use as this when executing callback
3182
+ */
3183
+ reduce<T>(callback: ((value: T, node: XMLBuilder, index: number, level: number) => T), initialValue: T, self?: boolean, recursive?: boolean, thisArg?: any): T;
3184
+ /**
3185
+ * Returns the first child node satisfying the given predicate. `predicate` is
3186
+ * called with three arguments: `(node, index, level)`.
3187
+ *
3188
+ * @param predicate - a callback function to apply to each child node
3189
+ * @param self - whether to visit the current node along with child nodes
3190
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3191
+ * only the immediate child nodes
3192
+ * @param thisArg - value to use as this when executing predicate
3193
+ */
3194
+ find(predicate: ((node: XMLBuilder, index: number, level: number) => boolean), self?: boolean, recursive?: boolean, thisArg?: any): XMLBuilder | undefined;
3195
+ /**
3196
+ * Produces an array of child nodes which pass the given predicate test.
3197
+ * `predicate` is called with three arguments: `(node, index, level)`.
3198
+ *
3199
+ * @param predicate - a callback function to apply to each child node
3200
+ * @param self - whether to visit the current node along with child nodes
3201
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3202
+ * only the immediate child nodes
3203
+ * @param thisArg - value to use as this when executing predicate
3204
+ */
3205
+ filter(predicate: ((node: XMLBuilder, index: number, level: number) => boolean), self?: boolean, recursive?: boolean, thisArg?: any): XMLBuilder[];
3206
+ /**
3207
+ * Returns `true` if all child nodes pass the given predicate test.
3208
+ * `predicate` is called with three arguments: `(node, index, level)`.
3209
+ *
3210
+ * @param predicate - a callback function to apply to each child node
3211
+ * @param self - whether to visit the current node along with child nodes
3212
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3213
+ * only the immediate child nodes
3214
+ * @param thisArg - value to use as this when executing predicate
3215
+ */
3216
+ every(predicate: ((node: XMLBuilder, index: number, level: number) => boolean), self?: boolean, recursive?: boolean, thisArg?: any): boolean;
3217
+ /**
3218
+ * Returns `true` if any of the child nodes pass the given predicate test.
3219
+ * `predicate` is called with three arguments: `(node, index, level)`.
3220
+ *
3221
+ * @param predicate - a callback function to apply to each child node
3222
+ * @param self - whether to visit the current node along with child nodes
3223
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3224
+ * only the immediate child nodes
3225
+ * @param thisArg - value to use as this when executing predicate
3226
+ */
3227
+ some(predicate: ((node: XMLBuilder, index: number, level: number) => boolean), self?: boolean, recursive?: boolean, thisArg?: any): boolean;
3228
+ /**
3229
+ * Produces an array of child nodes.
3230
+ *
3231
+ * @param self - whether to visit the current node along with child nodes
3232
+ * @param recursive - whether to visit all descendant nodes in tree-order or
3233
+ * only the immediate child nodes
3234
+ */
3235
+ toArray(self?: boolean, recursive?: boolean): XMLBuilder[];
3236
+ /**
3237
+ * Converts the node into an XML string.
3238
+ *
3239
+ * @param options - serialization options
3240
+ */
3241
+ toString(writerOptions?: XMLWriterOptions): string;
3242
+ /**
3243
+ * Converts the node into a JSON string.
3244
+ *
3245
+ * @param options - serialization options
3246
+ */
3247
+ toString(writerOptions: JSONWriterOptions): string;
3248
+ /**
3249
+ * Converts the node into a YAML string.
3250
+ *
3251
+ * @param options - serialization options
3252
+ */
3253
+ toString(writerOptions: YAMLWriterOptions): string;
3254
+ /**
3255
+ * Converts the node into its object representation.
3256
+ *
3257
+ * @param options - serialization options
3258
+ */
3259
+ toObject(writerOptions?: ObjectWriterOptions): XMLSerializedAsObject | XMLSerializedAsObjectArray;
3260
+ /**
3261
+ * Converts the node into its object representation using ES6 maps.
3262
+ *
3263
+ * @param options - serialization options
3264
+ */
3265
+ toObject(writerOptions: MapWriterOptions): XMLSerializedAsMap | XMLSerializedAsMapArray;
3266
+ /**
3267
+ * Converts the entire XML document into an XML document string with the
3268
+ * default writer options.
3269
+ */
3270
+ end(): string;
3271
+ /**
3272
+ * Converts the entire XML document into an XML document string.
3273
+ *
3274
+ * @param options - serialization options
3275
+ */
3276
+ end(writerOptions: XMLWriterOptions): string;
3277
+ /**
3278
+ * Converts the entire XML document into a JSON string.
3279
+ *
3280
+ * @param options - serialization options
3281
+ */
3282
+ end(writerOptions: JSONWriterOptions): string;
3283
+ /**
3284
+ * Converts the entire XML document into a YAML string.
3285
+ *
3286
+ * @param options - serialization options
3287
+ */
3288
+ end(writerOptions: YAMLWriterOptions): string;
3289
+ /**
3290
+ * Converts the entire XML document into its object representation.
3291
+ *
3292
+ * @param options - serialization options
3293
+ */
3294
+ end(writerOptions: ObjectWriterOptions): XMLSerializedAsObject | XMLSerializedAsObjectArray;
3295
+ /**
3296
+ * Converts the entire XML document into its object representation using ES6 maps.
3297
+ *
3298
+ * @param options - serialization options
3299
+ */
3300
+ end(writerOptions: MapWriterOptions): XMLSerializedAsMap | XMLSerializedAsMapArray;
3301
+ }
3302
+ type SchemaOutput<S extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>> = S extends BaseSchema<unknown, infer Output, BaseIssue<unknown>> | BaseSchemaAsync<unknown, infer Output, BaseIssue<unknown>> ? Output : NonNullable<S["~types"]>["output"];
3303
+ type ExtensionSchemaType = "INVOICE" | "ORDER" | "ORDER_RESPONSE" | "ORDER_CHANGE";
3304
+ type ExtensionSchema = {
3305
+ type: ExtensionSchemaType | ExtensionSchemaType[];
3306
+ conformanceLevel: "MINIMUM" | "BASIC WL" | "BASIC" | "EN 16931" | "COMFORT" | "EXTENDED" | "XRECHNUNG";
3307
+ fileName: "factur-x.xml" | "xrechnung.xml" | "order-x.xml";
3308
+ version: "1.0" | "1p0" | "2p0" | "2p1" | "2p2";
3309
+ };
3310
+ type DataRelationship = "Alternative" | "Source" | "Data" | "Supplement" | "Unspecified";
3311
+ type ZugferdRuleId = `BR-${string}` | `CII-SR-${string}`;
3312
+ type ZugferdProfileRulesContext = {
3313
+ profile: Omit<ZugferdProfile, "schema" | "rules">;
3314
+ error: (id: ZugferdRuleId, message: string) => {
3315
+ id: ZugferdRuleId;
3316
+ message: string;
3317
+ };
3318
+ };
3319
+ type ZugferdProfileBuildContext = {
3320
+ root: XMLBuilder;
3321
+ profile: Omit<ZugferdProfile, "schema" | "rules">;
3322
+ } & BuildHelper;
3323
+ type InferProfileIds<Opts> = Opts extends ZugferdOptions<infer Profiles> ? Profiles[number]["id"] : never;
3324
+ interface ZugferdProfile<Schema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> = any> {
3325
+ id: string;
3326
+ version?: string | undefined;
3327
+ schema: Schema | (<Ctx extends {
3328
+ profile: Omit<ZugferdProfile, "schema" | "rules">;
3329
+ }>(ctx: Ctx) => Schema);
3330
+ dataRelationship: Exclude<DataRelationship, "Supplement" | "Unspecified"> | [Exclude<DataRelationship, "Supplement" | "Unspecified">, ...Exclude<DataRelationship, "Supplement" | "Unspecified">[]];
3331
+ extensionSchema: {
3332
+ uri?: string | undefined;
3333
+ namespace?: string | undefined;
3334
+ fieldNameMap?: Record<keyof ExtensionSchema, string> | undefined;
3335
+ } & ExtensionSchema;
3336
+ build: (data: SchemaOutput<Schema> & Record<string, any>, ctx: ZugferdProfileBuildContext) => void | Promise<void>;
3337
+ rules?: ((data: SchemaOutput<Schema> & Record<string, any>, ctx: ZugferdProfileRulesContext) => void | Promise<void>) | undefined;
3338
+ readonly $Infer?: {
3339
+ readonly Input: unknown;
3340
+ readonly Output: unknown;
3341
+ } | undefined;
3342
+ }
3343
+ type ZugferdErrorReporter = (error: ZugferdError<any, any>) => Awaitable<void>;
3344
+ type ConsoleReporterOptions = {
3345
+ logger?: ((message: string, ...args: any[]) => void) | undefined;
3346
+ formatter?: (error: ZugferdError<any, any>) => string;
3347
+ };
3348
+ interface ZugferdOptions<P extends readonly ZugferdProfile[] = readonly ZugferdProfile[]> {
3349
+ profiles: P;
3350
+ plugins?: ZugferdPlugin[] | undefined;
3351
+ prettyPrint?: boolean | undefined;
3352
+ logger?: Logger | undefined;
3353
+ diagnostics?: {
3354
+ reporters?: ZugferdErrorReporter[] | undefined;
3355
+ defaultReporter?: ({
3356
+ /**
3357
+ * @default true
3358
+ */
3359
+ enabled?: boolean | undefined;
3360
+ } & Partial<ConsoleReporterOptions>) | undefined;
3361
+ } | undefined;
3362
+ hooks?: {
3363
+ afterXMLBuild?: ((ctx: {
3364
+ xml: string;
3365
+ profile: ZugferdProfile;
3366
+ context: ZugferdContext;
3367
+ }) => Promise<void> | void) | undefined;
3368
+ };
3369
+ advanced?: {
3370
+ instrumentation?: {
3371
+ span?<T>(name: string, attr: Record<string, string | number | boolean>, fn: () => T): T;
3372
+ span?<T>(name: string, attr: Record<string, string | number | boolean>, fn: () => Promise<T>): Promise<T>;
3373
+ } | undefined;
3374
+ handleBinaryObject?: ((ctx: {
3375
+ data: {
3376
+ content: Uint8Array;
3377
+ mimeType: string;
3378
+ filename: string;
3379
+ };
3380
+ context: ZugferdContext;
3381
+ profile: ZugferdProfile;
3382
+ }) => Awaitable<void>) | undefined;
3383
+ } | undefined;
3384
+ }
3385
+ interface ZugferdPluginRegistry<ZugferdOpts, Options> {}
3386
+ type ZugferdPluginRegistryId = keyof ZugferdPluginRegistry<unknown, unknown>;
3387
+ type InferPluginID<O extends ZugferdOptions> = O["plugins"] extends Array<infer P> ? P extends ZugferdPlugin ? P["id"] : never : never;
3388
+ type InferPluginOptions<O extends ZugferdOptions, ID extends ZugferdPluginRegistryId | LiteralString> = O["plugins"] extends Array<infer P> ? P extends ZugferdPlugin ? P["id"] extends ID ? P extends {
3389
+ options: infer O;
3390
+ } ? O : never : never : never : never;
3391
+ type PluginContext<Options extends ZugferdOptions> = {
3392
+ getPlugin: <ID extends ZugferdPluginRegistryId | LiteralString, PluginOptions extends InferPluginOptions<Options, ID>, Cfg extends {
3393
+ throw?: boolean | undefined;
3394
+ } | undefined = undefined>(pluginId: ID, cfg?: Cfg | undefined) => (ID extends ZugferdPluginRegistryId ? ZugferdPluginRegistry<Options, PluginOptions>[ID] extends {
3395
+ creator: infer C;
3396
+ } ? C extends ((...args: any[]) => infer R) ? R : never : never : ZugferdPlugin) | (Cfg extends {
3397
+ throw: true;
3398
+ } ? never : null);
3399
+ hasPlugin: <ID extends ZugferdPluginRegistryId | LiteralString>(pluginId: ID) => ID extends InferPluginID<Options> ? true : boolean;
3400
+ };
3401
+ type ProfileContext<Options extends ZugferdOptions> = {
3402
+ getProfile: <ID extends ZugferdOptions["profiles"][number]["id"] | LiteralString, Cfg extends {
3403
+ throw?: boolean | undefined;
3404
+ } | undefined = undefined>(profileId: ID, cfg?: Cfg | undefined) => (ID extends ZugferdOptions["profiles"][number]["id"] ? Extract<Options["profiles"][number], {
3405
+ id: ID;
3406
+ }> : never) | (Cfg extends {
3407
+ throw: true;
3408
+ } ? never : null);
3409
+ hasProfile: <ID extends ZugferdOptions["profiles"][number]["id"] | LiteralString>(profileId: ID) => ID extends Options["profiles"][number]["id"] ? true : boolean;
3410
+ };
3411
+ type ZugferdContext<Options extends ZugferdOptions = ZugferdOptions> = PluginContext<Options> & ProfileContext<Options> & {
3412
+ options: Options;
3413
+ logger: ReturnType<typeof createLogger>;
3414
+ withSpan<T>(name: string, attr: Record<string, string | number | boolean>, fn: () => T): T;
3415
+ withSpan<T>(name: string, attr: Record<string, string | number | boolean>, fn: () => Promise<T>): Promise<T>;
3416
+ };
3417
+ type ZugferdErrorCallParams = {
3418
+ cause?: unknown;
3419
+ sources?: string[];
3420
+ };
3421
+ declare class ZugferdError<Code extends string = string, Data = undefined> extends Error {
3422
+ name: "ZugferdError";
3423
+ readonly code: Code;
3424
+ readonly reason: string;
3425
+ readonly fix: string | undefined;
3426
+ readonly docs: string | undefined;
3427
+ readonly data: Data;
3428
+ readonly sources: string[] | undefined;
3429
+ get message(): string;
3430
+ constructor(init: {
3431
+ code: Code;
3432
+ reason: string;
3433
+ fix?: string;
3434
+ docs?: string;
3435
+ data?: Data;
3436
+ } & ZugferdErrorCallParams, captureStackTrace?: Function);
3437
+ static from<E extends ZugferdError<any, any>>(ctx: ZugferdContext, error: E): E;
3438
+ toJSON(): {
3439
+ name: "ZugferdError";
3440
+ code: Code;
3441
+ reason: string;
3442
+ fix: string | undefined;
3443
+ docs: string | undefined;
3444
+ data: Data;
3445
+ sources: string[] | undefined;
3446
+ cause: unknown;
3447
+ stack: string | undefined;
3448
+ };
3449
+ }
3450
+ type ErrorCodeDefinition<Data = any> = {
3451
+ reason: string | ((data: Data) => string);
3452
+ fix?: string | ((data: Data) => string);
3453
+ docs?: string | undefined;
3454
+ $InferData?: Data;
3455
+ };
3456
+ type InferData<Def> = Def extends {
3457
+ $InferData?: infer Data;
3458
+ } ? [unknown] extends [Data] ? undefined : Exclude<Data, undefined> : undefined;
3459
+ type HasRequiredFields<T> = Partial<T> extends T ? false : true;
3460
+ type HandleArgs<Data> = keyof Data extends never ? [props?: {
3461
+ data?: never;
3462
+ } & ZugferdErrorCallParams] : HasRequiredFields<Data> extends false ? [props?: {
3463
+ data: Data;
3464
+ } & ZugferdErrorCallParams] : [props: {
3465
+ data: Data;
3466
+ } & ZugferdErrorCallParams];
3467
+ type ErrorCodeHandle<Code extends string, Def extends ErrorCodeDefinition> = {
3468
+ (...args: HandleArgs<InferData<Def>>): ZugferdError<Code, InferData<Def>>;
3469
+ readonly code: Code;
3470
+ readonly definition: Def;
3471
+ is(error: unknown): error is ZugferdError<Code, InferData<Def>>;
3472
+ };
3473
+ type ErrorCatalog<Codes extends Record<string, ErrorCodeDefinition>> = {
3474
+ is(error: unknown): error is ZugferdError<Extract<keyof Codes, string>, any>;
3475
+ } & { [Code in Extract<keyof Codes, string>]: ErrorCodeHandle<Code, Codes[Code]>; };
3476
+ type AnyErrorCatalog = {
3477
+ is(error: unknown): error is ZugferdError<string, any>;
3478
+ };
3479
+ interface ZugferdPlugin {
3480
+ id: LiteralString;
3481
+ version?: string | undefined;
3482
+ init?: ((ctx: ZugferdContext) => {
3483
+ options?: (DeepPartial<ZugferdOptions> & Record<string, any>) | undefined;
3484
+ } | void) | undefined;
3485
+ actions?: ((ctx: ZugferdContext) => Record<string, unknown>) | undefined;
3486
+ options?: Record<string, any> | undefined;
3487
+ $ERROR_CODES?: AnyErrorCatalog | undefined;
3488
+ $Infer?: Record<string, any> | undefined;
3489
+ }
3490
+ /**
3491
+ * A compiled Schematron stylesheet stored inline as SEF JSON.
3492
+ *
3493
+ * SaxonJS HE executes compiled SEF stylesheets, so `content` must be the JSON
3494
+ * representation of a compiled stylesheet. Resources referenced with `doc()`
3495
+ * can be supplied through `imports`.
3496
+ */
3497
+ type InlineSchema = {
3498
+ /** Contents of the compiled stylesheet. */
3499
+ content: string;
3500
+ /** XML resources referenced by the stylesheet, keyed by URI or file name. */
3501
+ imports?: Record<string, string> | undefined;
3502
+ };
3503
+ /**
3504
+ * A compiled Schematron stylesheet read from the filesystem at validation time.
3505
+ */
3506
+ type FileSchema = {
3507
+ /** Path to the compiled SEF JSON file. */
3508
+ path: string;
3509
+ /** Directory used to resolve XML resources referenced by the stylesheet. */
3510
+ dir?: string | undefined;
3511
+ };
3512
+ type SchemaMapEntry = InlineSchema | FileSchema;
3513
+ type SchemaMap = Record<string, SchemaMapEntry | SchemaMapEntry[]>;
3514
+ type SCHOptions = {
3515
+ /**
3516
+ * Whether to automatically run validation after processing the document.
3517
+ *
3518
+ * @default true
3519
+ */
3520
+ autoRun?: boolean | undefined;
3521
+ schemaMap?: SchemaMap | undefined;
3522
+ };
3523
+ type ResolvedSCHOptions<Opts extends SCHOptions = SCHOptions, BundledSchemas extends SchemaMap = SchemaMap> = Omit<Opts, "autoRun" | "schemaMap"> & {
3524
+ autoRun: boolean;
3525
+ schemaMap: BundledSchemas & (Opts["schemaMap"] extends SchemaMap ? Opts["schemaMap"] : {});
3526
+ };
3527
+ declare module "@node-zugferd/core" {
3528
+ interface ZugferdPluginRegistry<ZugferdOpts, Options> {
3529
+ sch: {
3530
+ creator: typeof sch<ZugferdOpts extends (infer R extends ZugferdOptions) ? R : ZugferdOptions, Options extends SCHOptions ? Options : SCHOptions>;
3531
+ };
3532
+ }
3533
+ }
3534
+ declare const sch: <ZugferdOptions$1 extends ZugferdOptions, Opts extends SCHOptions>(options?: Opts | undefined) => {
3535
+ id: "sch";
3536
+ version: string;
3537
+ init(ctx: ZugferdContext): {
3538
+ options: {
3539
+ hooks: {
3540
+ afterXMLBuild({ profile, xml, context }: {
3541
+ xml: string;
3542
+ profile: ZugferdProfile;
3543
+ context: ZugferdContext;
3544
+ }): Promise<void>;
3545
+ };
3546
+ };
3547
+ } | undefined;
3548
+ actions(ctx: ZugferdContext): {
3549
+ sch: {
3550
+ validate<const ProfileID extends (InferProfileIds<ZugferdOptions$1> extends (infer R) ? R extends keyof ResolvedSCHOptions<Opts, {
3551
+ readonly minimum: SchemaMapEntry;
3552
+ readonly "basic-wl": SchemaMapEntry;
3553
+ readonly basic: SchemaMapEntry;
3554
+ readonly "en-16931": SchemaMapEntry;
3555
+ readonly extended: SchemaMapEntry;
3556
+ }>["schemaMap"] ? R extends string ? R : never : never : never) | {
3557
+ id: InferProfileIds<ZugferdOptions$1> extends (infer R) ? R extends keyof ResolvedSCHOptions<Opts, {
3558
+ readonly minimum: SchemaMapEntry;
3559
+ readonly "basic-wl": SchemaMapEntry;
3560
+ readonly basic: SchemaMapEntry;
3561
+ readonly "en-16931": SchemaMapEntry;
3562
+ readonly extended: SchemaMapEntry;
3563
+ }>["schemaMap"] ? R extends string ? R : never : never : never;
3564
+ }>(profileId: ProfileID, input: string | Uint8Array | ArrayBuffer): Promise<void>;
3565
+ };
3566
+ };
3567
+ options: ResolvedSCHOptions<Opts, {
3568
+ readonly minimum: SchemaMapEntry;
3569
+ readonly "basic-wl": SchemaMapEntry;
3570
+ readonly basic: SchemaMapEntry;
3571
+ readonly "en-16931": SchemaMapEntry;
3572
+ readonly extended: SchemaMapEntry;
3573
+ }>;
3574
+ $ERROR_CODES: ErrorCatalog<{
3575
+ readonly MISSING_SCH_SCHEMA: ErrorCodeDefinition<{
3576
+ profileId: string;
3577
+ }>;
3578
+ readonly MISSING_SCH_RESOURCE: ErrorCodeDefinition<{
3579
+ resource: string;
3580
+ }>;
3581
+ }>;
3582
+ };
3583
+ export declare const kositSchDefinitions: {
3584
+ readonly xrechnung: [SchemaMapEntry, SchemaMapEntry];
3585
+ };
3586
+ export { kositSchDefinitions as default };