@es-joy/jsoe 0.5.1 → 0.6.1

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.
Files changed (80) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.cjs +2 -0
  3. package/.nyc_output/out.json +121296 -0
  4. package/CHANGES.md +10 -0
  5. package/README.md +47 -21
  6. package/cypress.config.ts +13 -0
  7. package/demo/index-instrumented.html +29 -0
  8. package/demo/index.html +10 -1
  9. package/demo/index.js +482 -126
  10. package/dist/formatAndTypeChoices.d.ts +2 -2
  11. package/dist/formatAndTypeChoices.d.ts.map +1 -1
  12. package/dist/formats/json.d.ts.map +1 -1
  13. package/dist/formats/structuredCloning.d.ts +2 -1
  14. package/dist/formats/structuredCloning.d.ts.map +1 -1
  15. package/dist/fundamentalTypes/arrayType.d.ts +6 -37
  16. package/dist/fundamentalTypes/arrayType.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/dateType.d.ts.map +1 -1
  18. package/dist/fundamentalTypes/errorType.d.ts +6 -0
  19. package/dist/fundamentalTypes/errorType.d.ts.map +1 -0
  20. package/dist/fundamentalTypes/mapType.d.ts +6 -0
  21. package/dist/fundamentalTypes/mapType.d.ts.map +1 -0
  22. package/dist/fundamentalTypes/nullType.d.ts.map +1 -1
  23. package/dist/fundamentalTypes/objectReferenceType.d.ts.map +1 -1
  24. package/dist/fundamentalTypes/setType.d.ts +6 -0
  25. package/dist/fundamentalTypes/setType.d.ts.map +1 -0
  26. package/dist/fundamentalTypes/sparseUndefinedType.d.ts.map +1 -1
  27. package/dist/fundamentalTypes/undefinedType.d.ts.map +1 -1
  28. package/dist/subTypes/blobHTMLType.d.ts +12 -6
  29. package/dist/subTypes/blobHTMLType.d.ts.map +1 -1
  30. package/dist/superTypes/SpecialNumberType.d.ts +14 -0
  31. package/dist/superTypes/SpecialNumberType.d.ts.map +1 -0
  32. package/dist/superTypes/SpecialRealNumberType.d.ts +6 -0
  33. package/dist/superTypes/SpecialRealNumberType.d.ts.map +1 -0
  34. package/dist/superTypes/errorsSpecialType.d.ts +8 -0
  35. package/dist/superTypes/errorsSpecialType.d.ts.map +1 -0
  36. package/dist/typeChoices.d.ts +4 -2
  37. package/dist/typeChoices.d.ts.map +1 -1
  38. package/dist/types.d.ts +83 -231
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/utils/dialogs.d.ts +22 -22
  41. package/dist/utils/dialogs.d.ts.map +1 -1
  42. package/dist/utils/templateUtils.d.ts +6 -6
  43. package/dist/utils/templateUtils.d.ts.map +1 -1
  44. package/dist/vendor-imports.d.ts +1 -1
  45. package/package.json +39 -34
  46. package/rollup.config.js +14 -2
  47. package/server.js +1 -1
  48. package/src/formatAndTypeChoices.js +9 -9
  49. package/src/formats/indexedDBKey.js +2 -2
  50. package/src/formats/json.js +1 -2
  51. package/src/formats/structuredCloning.js +101 -29
  52. package/src/formats.js +2 -2
  53. package/src/fundamentalTypes/arrayReferenceType.js +3 -3
  54. package/src/fundamentalTypes/arrayType.js +390 -87
  55. package/src/fundamentalTypes/dateType.js +4 -6
  56. package/src/fundamentalTypes/errorType.js +416 -0
  57. package/src/fundamentalTypes/mapType.js +34 -0
  58. package/src/fundamentalTypes/nullType.js +1 -2
  59. package/src/fundamentalTypes/objectReferenceType.js +2 -1
  60. package/src/fundamentalTypes/regexpType.js +2 -2
  61. package/src/fundamentalTypes/setType.js +34 -0
  62. package/src/fundamentalTypes/sparseUndefinedType.js +2 -3
  63. package/src/fundamentalTypes/undefinedType.js +2 -3
  64. package/src/jsoe.css +3 -0
  65. package/src/subTypes/blobHTMLType.js +37 -33
  66. package/src/subTypes/falseType.js +2 -2
  67. package/src/subTypes/trueType.js +2 -2
  68. package/src/superTypes/{SpecialNumberSuperType.js → SpecialNumberType.js} +1 -1
  69. package/src/superTypes/{SpecialRealNumberSuperType.js → SpecialRealNumberType.js} +3 -2
  70. package/src/superTypes/errorsSpecialType.js +768 -0
  71. package/src/typeChoices.js +27 -20
  72. package/src/types.js +71 -39
  73. package/src/utils/dialogs.js +11 -12
  74. package/src/utils/jsonPointer.js +3 -3
  75. package/src/utils/templateUtils.js +4 -4
  76. package/src/vendor-imports.js +2 -2
  77. package/tsconfig.json +1 -1
  78. package/typings/CypressPlugins.d.ts +10 -0
  79. package/vendor/jamilih/dist/jml-es.js +126 -106
  80. package/vendor/typeson-registry/dist/index.js +188 -44
@@ -43,7 +43,7 @@ Other Todos:
43
43
 
44
44
  /**
45
45
  * @typedef {{
46
- * element: Document|Element|DocumentFragment,
46
+ * element: Document|HTMLElement|DocumentFragment,
47
47
  * attribute: {name: string|null, value: JamilihAttValue},
48
48
  * opts: JamilihOptions
49
49
  * }} PluginSettings
@@ -52,7 +52,7 @@ Other Todos:
52
52
  /**
53
53
  * @typedef {object} JamilihPlugin
54
54
  * @property {string} name
55
- * @property {(opts: PluginSettings) => string} set
55
+ * @property {(opts: PluginSettings) => string|Promise<void>} set
56
56
  */
57
57
 
58
58
  /**
@@ -60,7 +60,7 @@ Other Todos:
60
60
  */
61
61
  let win;
62
62
 
63
- /* c8 ignore next */
63
+ /* c8 ignore next 3 */
64
64
  if (typeof window !== 'undefined' && window) {
65
65
  win = window;
66
66
  }
@@ -120,7 +120,7 @@ const NULLABLES = ['autocomplete', 'dir',
120
120
 
121
121
  /**
122
122
  * @param {string} sel
123
- * @returns {Element|null}
123
+ * @returns {HTMLElement|null}
124
124
  */
125
125
  const $ = sel => {
126
126
  if (!doc) {
@@ -131,13 +131,13 @@ const $ = sel => {
131
131
 
132
132
  /**
133
133
  * @param {string} sel
134
- * @returns {Element[]}
134
+ * @returns {HTMLElement[]}
135
135
  */
136
136
  const $$ = sel => {
137
137
  if (!doc) {
138
- return [];
138
+ throw new Error('No document object');
139
139
  }
140
- return [...doc.querySelectorAll(sel)];
140
+ return [... /** @type {NodeListOf<HTMLElement>} */doc.querySelectorAll(sel)];
141
141
  };
142
142
 
143
143
  /**
@@ -153,7 +153,7 @@ function _getHTMLNodeName(node) {
153
153
  /**
154
154
  * @private
155
155
  * @static
156
- * @param {Document|DocumentFragment|Element} parent The parent to which to append the element
156
+ * @param {Document|DocumentFragment|HTMLElement} parent The parent to which to append the element
157
157
  * @param {Node|string} child The element or other node to append to the parent
158
158
  * @throws {Error} Rethrow if problem with `append` and unhandled
159
159
  * @returns {void}
@@ -170,14 +170,15 @@ function _appendNode(parent, child) {
170
170
  /**
171
171
  * Attach event in a cross-browser fashion.
172
172
  * @static
173
- * @param {Element} el DOM element to which to attach the event
173
+ * @param {HTMLElement} el DOM element to which to attach the event
174
174
  * @param {string} type The DOM event (without 'on') to attach to the element
175
- * @param {EventListener} handler The event handler to attach to the element
175
+ * @param {(evt: Event & {target: HTMLElement}) => void} handler The event handler to attach to the element
176
176
  * @param {boolean} [capturing] Whether or not the event should be
177
177
  * capturing (W3C-browsers only); default is false; NOT IN USE
178
178
  * @returns {void}
179
179
  */
180
180
  function _addEvent(el, type, handler, capturing) {
181
+ // @ts-expect-error It's ok
181
182
  el.addEventListener(type, handler, Boolean(capturing));
182
183
  }
183
184
 
@@ -190,6 +191,7 @@ function _addEvent(el, type, handler, capturing) {
190
191
  * @returns {Text} The text node of the resolved reference
191
192
  */
192
193
  function _createSafeReference(type, prefix, arg) {
194
+ /* c8 ignore next 3 */
193
195
  if (!doc) {
194
196
  throw new Error('No document defined');
195
197
  }
@@ -229,7 +231,7 @@ function _isNullish(o) {
229
231
  * @static
230
232
  * @param {string|JamilihAttributes|JamilihArray|JamilihChildren|
231
233
  * JamilihDocumentFragment|JamilihAttributeNode|
232
- * JamilihOptions|Element|Document|DocumentFragment|null|undefined} item
234
+ * JamilihOptions|HTMLElement|Document|DocumentFragment|null|undefined} item
233
235
  * @returns {"string"|"null"|"array"|"element"|"fragment"|"object"|
234
236
  * "symbol"|"bigint"|"function"|"number"|"boolean"|"undefined"|
235
237
  * "document"|"non-container node"}
@@ -326,14 +328,14 @@ function _childrenToJML(node) {
326
328
  /**
327
329
  * Keep this in sync with `JamilihArray`'s first argument (minus `Document`).
328
330
  * @typedef {JamilihDoc|JamilihDoctype|JamilihTextNode|
329
- * JamilihAttributeNode|JamilihOptions|ElementName|Element|
331
+ * JamilihAttributeNode|JamilihOptions|ElementName|HTMLElement|
330
332
  * JamilihDocumentFragment
331
333
  * } JamilihFirstArg
332
334
  */
333
335
 
334
336
  /**
335
337
  * @callback JamilihAppender
336
- * @param {JamilihArray|JamilihFirstArg|Node} childJML
338
+ * @param {JamilihArray|JamilihFirstArg|Node|TextNodeString} childJML
337
339
  * @returns {void}
338
340
  */
339
341
 
@@ -345,6 +347,9 @@ function _childrenToJML(node) {
345
347
  */
346
348
  function _appendJML(node) {
347
349
  return function (childJML) {
350
+ if (typeof childJML === 'string' || typeof childJML === 'number') {
351
+ throw new TypeError('Unexpected text string/number in the head');
352
+ }
348
353
  if (Array.isArray(childJML)) {
349
354
  node.append(jml(...childJML));
350
355
  } else if (typeof childJML === 'object' && 'nodeType' in childJML) {
@@ -357,7 +362,7 @@ function _appendJML(node) {
357
362
 
358
363
  /**
359
364
  * @callback appender
360
- * @param {JamilihArray|JamilihFirstArg|Node} childJML
365
+ * @param {JamilihArray|JamilihFirstArg|Node|TextNodeString} childJML
361
366
  * @returns {void}
362
367
  */
363
368
 
@@ -369,8 +374,8 @@ function _appendJML(node) {
369
374
  */
370
375
  function _appendJMLOrText(node) {
371
376
  return function (childJML) {
372
- if (typeof childJML === 'string') {
373
- node.append(childJML);
377
+ if (typeof childJML === 'string' || typeof childJML === 'number') {
378
+ node.append(String(childJML));
374
379
  } else if (Array.isArray(childJML)) {
375
380
  node.append(jml(...childJML));
376
381
  } else if (typeof childJML === 'object' && 'nodeType' in childJML) {
@@ -395,7 +400,7 @@ function _DOMfromJMLOrString (childNodeJML) {
395
400
  */
396
401
 
397
402
  /**
398
- * @typedef {Element|DocumentFragment|Comment|Attr|
403
+ * @typedef {HTMLElement|DocumentFragment|Comment|Attr|
399
404
  * Text|Document|DocumentType|ProcessingInstruction|CDATASection} JamilihReturn
400
405
  */
401
406
  // 'string|JamilihOptions|JamilihDocumentFragment|JamilihAttributes|(string|JamilihArray)[]
@@ -405,11 +410,11 @@ function _DOMfromJMLOrString (childNodeJML) {
405
410
  * 1. JamilihAttributes followed by an array of JamilihArrays or Elements.
406
411
  * (Cannot be multiple single JamilihArrays despite TS type).
407
412
  * 2. Any number of JamilihArrays.
408
- * @typedef {[(JamilihAttributes|JamilihArray|JamilihArray[]|Element), ...(JamilihArray|JamilihArray[]|Element)[]]} TemplateJamilihArray
413
+ * @typedef {[(JamilihAttributes|JamilihArray|JamilihArray[]|HTMLElement), ...(JamilihArray|JamilihArray[]|HTMLElement)[]]} TemplateJamilihArray
409
414
  */
410
415
 
411
416
  /**
412
- * @typedef {(JamilihArray|Element)[]} ShadowRootJamilihArrayContainer
417
+ * @typedef {(JamilihArray|HTMLElement)[]} ShadowRootJamilihArrayContainer
413
418
  */
414
419
 
415
420
  /**
@@ -431,7 +436,7 @@ function _DOMfromJMLOrString (childNodeJML) {
431
436
 
432
437
  /**
433
438
  * @typedef {{
434
- * [key: string]: string|number|null|DatasetAttributeObject
439
+ * [key: string]: string|number|null|undefined|DatasetAttributeObject
435
440
  * }} DatasetAttributeObject
436
441
  */
437
442
 
@@ -440,7 +445,7 @@ function _DOMfromJMLOrString (childNodeJML) {
440
445
  */
441
446
 
442
447
  /**
443
- * @typedef {(this: Element, event?: Event) => void} EventHandler
448
+ * @typedef {(this: HTMLElement, event: Event & {target: HTMLElement}) => void} EventHandler
444
449
  */
445
450
 
446
451
  /**
@@ -460,7 +465,7 @@ function _DOMfromJMLOrString (childNodeJML) {
460
465
  */
461
466
 
462
467
  /**
463
- * @typedef {((this: Element, event?: Event) => void)} HandlerAttributeValue
468
+ * @typedef {((this: HTMLElement, event?: Event) => void)} HandlerAttributeValue
464
469
  */
465
470
 
466
471
  /* eslint-disable jsdoc/valid-types -- jsdoc-type-pratt-parser Bug */
@@ -511,29 +516,34 @@ function _DOMfromJMLOrString (childNodeJML) {
511
516
  */
512
517
 
513
518
  /**
514
- * @typedef {{elem?: Element, [key: string]: any}} SymbolObject
519
+ * @typedef {{elem?: HTMLElement, [key: string]: any}} SymbolObject
515
520
  */
516
521
 
517
522
  /**
518
- * @typedef {[symbol|string, ((this: Element, ...args: any[]) => any)|SymbolObject]} SymbolArray
523
+ * @typedef {[symbol|string, ((this: HTMLElement, ...args: any[]) => any)|SymbolObject]} SymbolArray
519
524
  */
520
525
 
521
526
  /**
522
527
  * @typedef {null|undefined} NullableAttributeValue
523
528
  */
524
529
 
530
+ /**
531
+ * @typedef {[string, object]|string|{[key: string]: any}} PluginValue
532
+ */
533
+
525
534
  /**
526
535
  * @typedef {(string|NullableAttributeValue|BooleanAttribute|
527
536
  * JamilihArray|JamilihShadowRootObject|StringifiableNumber|
528
537
  * JamilihDocumentType|JamilihDocument|XmlnsAttributeValue|
529
538
  * OnAttributeObject|
530
- * HandlerAttributeValue|DefineObject|SymbolArray|PluginReference
539
+ * HandlerAttributeValue|DefineObject|SymbolArray|PluginReference|
540
+ * PluginValue
531
541
  * )} JamilihAttValue
532
542
  */
533
543
 
534
544
  /**
535
545
  * @typedef {{
536
- * [key: string]: string|number|((this: Element, ...args: any[]) => any)
546
+ * [key: string]: string|number|((this: HTMLElement, ...args: any[]) => any)
537
547
  * }} DataAttributeObject
538
548
  */
539
549
 
@@ -622,7 +632,11 @@ function _DOMfromJMLOrString (childNodeJML) {
622
632
  */
623
633
 
624
634
  /**
625
- * @typedef {{'#': (JamilihArray|TextNodeString|Element)[]}} JamilihDocumentFragment
635
+ * @typedef {JamilihArray|TextNodeString|HTMLElement} JamilihDocumentFragmentContent
636
+ */
637
+
638
+ /**
639
+ * @typedef {{'#': JamilihDocumentFragmentContent[]}} JamilihDocumentFragment
626
640
  */
627
641
 
628
642
  /**
@@ -630,7 +644,7 @@ function _DOMfromJMLOrString (childNodeJML) {
630
644
  */
631
645
 
632
646
  /**
633
- * @typedef {string} TextNodeString
647
+ * @typedef {string|number} TextNodeString
634
648
  */
635
649
 
636
650
  /**
@@ -639,14 +653,16 @@ function _DOMfromJMLOrString (childNodeJML) {
639
653
 
640
654
  /**
641
655
  * @typedef {(
642
- * JamilihArray|TextNodeString|Element|Comment|ProcessingInstruction|
656
+ * JamilihArray|TextNodeString|HTMLElement|Comment|ProcessingInstruction|
643
657
  * Text|DocumentFragment|JamilihProcessingInstruction|JamilihDocumentFragment|
644
658
  * PluginReference
645
659
  * )[]} JamilihChildren
646
660
  */
647
661
 
662
+ // Todo: DocumentType, Comment, ProcessingInstruction, Text
663
+ // Todo: JamilihCDATANode, JamilihComment, JamilihProcessingInstruction
648
664
  /**
649
- * @typedef {Document|ElementName|Element|DocumentFragment|
665
+ * @typedef {Document|ElementName|HTMLElement|DocumentFragment|
650
666
  * JamilihDocumentFragment|JamilihDoc|JamilihDoctype|JamilihTextNode|
651
667
  * JamilihAttributeNode} JamilihFirstArgument
652
668
  */
@@ -675,29 +691,29 @@ function _DOMfromJMLOrString (childNodeJML) {
675
691
  * (JamilihFirstArgument|
676
692
  * JamilihAttributes|
677
693
  * JamilihChildren|
678
- * Element|ShadowRoot|
694
+ * HTMLElement|ShadowRoot|
679
695
  * null)?,
680
696
  * (JamilihAttributes|
681
697
  * JamilihChildren|
682
- * Element|ShadowRoot|
698
+ * HTMLElement|ShadowRoot|
683
699
  * ElementName|null)?,
684
700
  * ...(JamilihAttributes|
685
701
  * JamilihChildren|
686
- * Element|ShadowRoot|
702
+ * HTMLElement|ShadowRoot|
687
703
  * ElementName|null)[]
688
704
  * ]} JamilihArray
689
705
  */
690
706
 
691
707
  /**
692
708
  * @typedef {[
693
- * (string|Element|ShadowRoot), (JamilihArray[]|JamilihAttributes|Element|ShadowRoot|null)?, ...(JamilihArray[]|Element|JamilihAttributes|ShadowRoot|null)[]
709
+ * (string|HTMLElement|ShadowRoot), (JamilihArray[]|JamilihAttributes|HTMLElement|ShadowRoot|null)?, ...(JamilihArray[]|HTMLElement|JamilihAttributes|ShadowRoot|null)[]
694
710
  * ]} JamilihArrayPostOptions
695
711
  */
696
712
 
697
713
  /**
698
714
  * @typedef {{
699
- * root: [Map<Element,any>|WeakMap<Element,any>, any],
700
- * [key: string]: [Map<Element,any>|WeakMap<Element,any>, any]
715
+ * root: [Map<HTMLElement,any>|WeakMap<HTMLElement,any>, any],
716
+ * [key: string]: [Map<HTMLElement,any>|WeakMap<HTMLElement,any>, any]
701
717
  * }} MapWithRoot
702
718
  */
703
719
 
@@ -709,16 +725,16 @@ function _DOMfromJMLOrString (childNodeJML) {
709
725
  * @typedef {object} JamilihOptions
710
726
  * @property {TraversalState} [$state]
711
727
  * @property {JamilihPlugin[]} [$plugins]
712
- * @property {MapWithRoot|[Map<Element,any>|WeakMap<Element,any>, any]} [$map]
728
+ * @property {MapWithRoot|[Map<HTMLElement,any>|WeakMap<HTMLElement,any>, any]} [$map]
713
729
  */
714
730
 
715
731
  /**
716
- * @param {Document|Element|DocumentFragment} elem
732
+ * @param {Document|HTMLElement|DocumentFragment} elem
717
733
  * @param {string|null} att
718
734
  * @param {JamilihAttValue} attVal
719
735
  * @param {JamilihOptions} opts
720
736
  * @param {TraversalState} [state]
721
- * @returns {string|null}
737
+ * @returns {Promise<void>|string|null}
722
738
  */
723
739
  function checkPluginValue(elem, att, attVal, opts, state) {
724
740
  opts.$state = state !== null && state !== void 0 ? state : 'attributeValue';
@@ -766,7 +782,7 @@ const jml = function jml(...args) {
766
782
  throw new Error('No document object');
767
783
  }
768
784
 
769
- /** @type {(Document|DocumentFragment|Element) & {[key: string]: any}} */
785
+ /** @type {(Document|DocumentFragment|HTMLElement) & {[key: string]: any}} */
770
786
  let elem = doc.createDocumentFragment();
771
787
  /**
772
788
  *
@@ -775,6 +791,7 @@ const jml = function jml(...args) {
775
791
  * @returns {void}
776
792
  */
777
793
  function _checkAtts(atts) {
794
+ /* c8 ignore next 3 */
778
795
  if (!doc) {
779
796
  throw new Error('No document object');
780
797
  }
@@ -826,7 +843,7 @@ const jml = function jml(...args) {
826
843
  content,
827
844
  template
828
845
  } = /** @type {JamilihShadowRootObject} */attVal;
829
- const shadowRoot = /** @type {Element} */elem.attachShadow({
846
+ const shadowRoot = /** @type {HTMLElement} */elem.attachShadow({
830
847
  mode: closed || open === false ? 'closed' : 'open'
831
848
  });
832
849
  if (template) {
@@ -835,12 +852,12 @@ const jml = function jml(...args) {
835
852
  _getType(template[0]) === 'object' ? jml('template', ...
836
853
  /**
837
854
  * @type {[
838
- * JamilihAttributes, ...(JamilihArray[]|Element)[]
855
+ * JamilihAttributes, ...(JamilihArray[]|HTMLElement)[]
839
856
  * ]}
840
857
  */
841
858
  template, doc.body) : jml('template',
842
859
  /**
843
- * @type {JamilihArray[]|Element}
860
+ * @type {JamilihArray[]|HTMLElement}
844
861
  */
845
862
  template, doc.body);
846
863
  } else if (typeof template === 'string') {
@@ -900,7 +917,7 @@ const jml = function jml(...args) {
900
917
  if (!Object.hasOwn(atts, 'is')) {
901
918
  throw new TypeError(`Expected \`is\` with \`$define\` on built-in; args: ${JSON.stringify(args)}`);
902
919
  }
903
- atts.is = checkPluginValue(elem, 'is', atts.is, opts);
920
+ atts.is = /** @type {string} */checkPluginValue(elem, 'is', atts.is, opts);
904
921
  elem.setAttribute('is', atts.is);
905
922
  ({
906
923
  is
@@ -917,6 +934,7 @@ const jml = function jml(...args) {
917
934
  * @returns {DefineConstructor}
918
935
  */
919
936
  const getConstructor = cnstrct => {
937
+ /* c8 ignore next 3 */
920
938
  if (!doc) {
921
939
  throw new Error('No document object');
922
940
  }
@@ -998,7 +1016,7 @@ const jml = function jml(...args) {
998
1016
  {
999
1017
  const [symbol, func] = /** @type {SymbolArray} */attVal;
1000
1018
  if (typeof func === 'function') {
1001
- const funcBound = func.bind( /** @type {Element} */elem);
1019
+ const funcBound = func.bind( /** @type {HTMLElement} */elem);
1002
1020
  if (typeof symbol === 'string') {
1003
1021
  // @ts-expect-error
1004
1022
  elem[Symbol.for(symbol)] = funcBound;
@@ -1008,7 +1026,7 @@ const jml = function jml(...args) {
1008
1026
  }
1009
1027
  } else {
1010
1028
  const obj = func;
1011
- obj.elem = /** @type {Element} */elem;
1029
+ obj.elem = /** @type {HTMLElement} */elem;
1012
1030
  if (typeof symbol === 'string') {
1013
1031
  // @ts-expect-error
1014
1032
  elem[Symbol.for(symbol)] = obj;
@@ -1082,11 +1100,11 @@ const jml = function jml(...args) {
1082
1100
 
1083
1101
  if (jamlihDoc.head && head) {
1084
1102
  // each child of `head` is:
1085
- // (JamilihArray|TextNodeString|Element|Comment|ProcessingInstruction|
1103
+ // (JamilihArray|TextNodeString|HTMLElement|Comment|ProcessingInstruction|
1086
1104
  // Text|DocumentFragment|JamilihProcessingInstruction|JamilihDocumentFragment)
1087
1105
 
1088
1106
  // * @typedef {JamilihDoc|JamilihDoctype|JamilihTextNode|
1089
- // * JamilihAttributeNode|JamilihOptions|ElementName|Element|
1107
+ // * JamilihAttributeNode|JamilihOptions|ElementName|HTMLElement|
1090
1108
  // * JamilihDocumentFragment
1091
1109
  // * } JamilihFirstArg
1092
1110
  // appender childJML param is: JamilihArray|JamilihFirstArg
@@ -1119,7 +1137,7 @@ const jml = function jml(...args) {
1119
1137
  if (typeof val[0] !== 'function') {
1120
1138
  throw new TypeError(`Expect a function for \`$on\`; args: ${JSON.stringify(args)}`);
1121
1139
  }
1122
- _addEvent( /** @type {Element} */elem, p2, val[0], val[1]); // element, event name, handler, capturing
1140
+ _addEvent( /** @type {HTMLElement} */elem, p2, val[0], val[1]); // element, event name, handler, capturing
1123
1141
  }
1124
1142
 
1125
1143
  break;
@@ -1229,7 +1247,7 @@ const jml = function jml(...args) {
1229
1247
  if (matchingPlugin) {
1230
1248
  matchingPlugin.set({
1231
1249
  opts,
1232
- element: elem,
1250
+ element: /** @type {HTMLElement} */nodes[0],
1233
1251
  attribute: {
1234
1252
  name: pluginName,
1235
1253
  value: /** @type {PluginReference} */attVal
@@ -1299,7 +1317,7 @@ const jml = function jml(...args) {
1299
1317
  */
1300
1318
  const setMap = dataVal => {
1301
1319
  let map, obj;
1302
- const defMap = /** @type {[Map<Element, any> | WeakMap<Element, any>, any]} */defaultMap;
1320
+ const defMap = /** @type {[Map<HTMLElement, any> | WeakMap<HTMLElement, any>, any]} */defaultMap;
1303
1321
  // Boolean indicating use of default map and object
1304
1322
  if (dataVal === true) {
1305
1323
  [map, obj] = defMap;
@@ -1324,8 +1342,8 @@ const jml = function jml(...args) {
1324
1342
  map = defMap[0];
1325
1343
  obj = dataVal;
1326
1344
  }
1327
- /** @type {Map<Element, any> | WeakMap<Element, any>} */
1328
- map.set( /** @type {Element} */
1345
+ /** @type {Map<HTMLElement, any> | WeakMap<HTMLElement, any>} */
1346
+ map.set( /** @type {HTMLElement} */
1329
1347
  elem, obj);
1330
1348
  };
1331
1349
  for (let i = argStart; i < argc; i++) {
@@ -1415,16 +1433,19 @@ const jml = function jml(...args) {
1415
1433
  const {
1416
1434
  is
1417
1435
  } = /** @type {JamilihAttributes} */atts;
1418
- /* c8 ignore next */
1436
+ /* c8 ignore next 4 */
1419
1437
  elem = doc.createElementNS
1420
- /* eslint-disable object-shorthand -- Casting */ ? doc.createElementNS(NS_HTML, elStr, {
1438
+ // Should create separate file for this
1439
+ /* eslint-disable object-shorthand -- Casting */ ? /** @type {HTMLElement} */doc.createElementNS(NS_HTML, elStr, {
1421
1440
  is: /** @type {string} */is
1422
- }) : doc.createElement(elStr, {
1441
+ })
1442
+ /* c8 ignore next 1 */ : doc.createElement(elStr, {
1423
1443
  is: /** @type {string} */is
1424
1444
  });
1425
1445
  /* eslint-enable object-shorthand -- Casting */
1426
1446
  } else /* c8 ignore next */if (doc.createElementNS) {
1427
1447
  elem = doc.createElementNS(NS_HTML, elStr);
1448
+ /* c8 ignore next 3 */
1428
1449
  } else {
1429
1450
  elem = doc.createElement(elStr);
1430
1451
  }
@@ -1438,6 +1459,7 @@ const jml = function jml(...args) {
1438
1459
  case 'object':
1439
1460
  {
1440
1461
  // Non-DOM-element objects indicate attribute-value pairs
1462
+ /* c8 ignore next 3 */
1441
1463
  if (!arg || typeof arg !== 'object') {
1442
1464
  throw new Error('Null should not reach here');
1443
1465
  }
@@ -1476,7 +1498,7 @@ const jml = function jml(...args) {
1476
1498
  */
1477
1499
  if (i === 0) {
1478
1500
  // Allow wrapping of element, fragment, or document
1479
- elem = /** @type {Document|DocumentFragment|Element} */arg;
1501
+ elem = /** @type {Document|DocumentFragment|HTMLElement} */arg;
1480
1502
  // Todo: Report to plugins and change for document/fragment
1481
1503
  opts.$state = 'element';
1482
1504
  }
@@ -1484,10 +1506,10 @@ const jml = function jml(...args) {
1484
1506
  // parent
1485
1507
  const elsl = nodes.length;
1486
1508
  for (let k = 0; k < elsl; k++) {
1487
- _appendNode( /** @type {Document|DocumentFragment|Element} */arg, nodes[k]);
1509
+ _appendNode( /** @type {Document|DocumentFragment|HTMLElement} */arg, nodes[k]);
1488
1510
  }
1489
1511
  } else {
1490
- nodes[nodes.length] = /** @type {Document|DocumentFragment|Element} */arg;
1512
+ nodes[nodes.length] = /** @type {Document|DocumentFragment|HTMLElement} */arg;
1491
1513
  }
1492
1514
  break;
1493
1515
  case 'array':
@@ -1499,7 +1521,7 @@ const jml = function jml(...args) {
1499
1521
  // Go through children array container to handle elements
1500
1522
  const childContent = child[j];
1501
1523
  const childContentType = typeof childContent;
1502
- if (_isNullish(childContent)) {
1524
+ if (childContent === null || _isNullish(childContent)) {
1503
1525
  throw new TypeError(`Bad children (parent array: ${JSON.stringify(args)}; index ${j} of child: ${JSON.stringify(child)})`);
1504
1526
  }
1505
1527
  switch (childContentType) {
@@ -1510,13 +1532,13 @@ const jml = function jml(...args) {
1510
1532
  _appendNode(elem, doc.createTextNode(String(childContent)));
1511
1533
  break;
1512
1534
  default:
1513
- if (!childContent || typeof childContent !== 'object') {
1514
- throw new Error('Unexpected type');
1535
+ // bigint, symbol, function
1536
+ if (typeof childContent !== 'object') {
1537
+ throw new TypeError(`Bad children (parent array: ${JSON.stringify(args)}; index ${j} of child: ${JSON.stringify(child)})`);
1515
1538
  }
1516
1539
  if (Array.isArray(childContent)) {
1517
1540
  // Arrays representing child elements
1518
1541
  opts.$state = 'children';
1519
- // @ts-expect-error Should be ok
1520
1542
  _appendNode(elem, jml(opts, ...childContent));
1521
1543
  } else if ('#' in childContent) {
1522
1544
  // Fragment
@@ -1529,7 +1551,7 @@ const jml = function jml(...args) {
1529
1551
  newChildContent = /** @type {string} */
1530
1552
  checkPluginValue(elem, null, childContent, opts, 'children');
1531
1553
  }
1532
- _appendNode(elem, /** @type {string | Element | DocumentFragment | Comment} */
1554
+ _appendNode(elem, /** @type {string|HTMLElement|DocumentFragment|Comment} */
1533
1555
  newChildContent || childContent);
1534
1556
  }
1535
1557
  break;
@@ -1789,7 +1811,7 @@ jml.toJML = function (nde, {
1789
1811
  case 1:
1790
1812
  {
1791
1813
  // ELEMENT
1792
- const node = /** @type {Element} */nodeOrEntity;
1814
+ const node = /** @type {HTMLElement} */nodeOrEntity;
1793
1815
  setTemp();
1794
1816
  const nodeName = node.nodeName.toLowerCase(); // Todo: for XML, should not lower-case
1795
1817
 
@@ -1832,7 +1854,6 @@ jml.toJML = function (nde, {
1832
1854
  resetTemp();
1833
1855
  break;
1834
1856
  }
1835
- case undefined: // Treat as attribute node until this is fixed: https://github.com/jsdom/jsdom/issues/1641 / https://github.com/jsdom/jsdom/pull/1822
1836
1857
  case 2:
1837
1858
  {
1838
1859
  // ATTRIBUTE (should only get here if passing in an attribute node)
@@ -2026,7 +2047,7 @@ jml.toHTML = function (...args) {
2026
2047
  // Todo: deal with serialization of properties like 'selected',
2027
2048
  // 'checked', 'value', 'defaultValue', 'for', 'dataset', 'on*',
2028
2049
  // 'style'! (i.e., need to build a string ourselves)
2029
- return (/** @type {Element} */ret.outerHTML
2050
+ return (/** @type {HTMLElement} */ret.outerHTML
2030
2051
  );
2031
2052
  }
2032
2053
  case 2:
@@ -2037,42 +2058,40 @@ jml.toHTML = function (...args) {
2037
2058
  /** @type {Attr} */ret.value.replace(/"/gu, '&quot;')}"`;
2038
2059
  }
2039
2060
  case 3:
2040
- case 4:
2041
2061
  {
2042
- // CDATA
2062
+ // TEXT
2063
+ // Fallthrough
2064
+ // } case 4: { // CDATA
2065
+ /* c8 ignore next 3 */
2043
2066
  if (!ret.nodeValue) {
2044
2067
  throw new TypeError('Unexpected null Text node');
2045
2068
  }
2046
2069
  return (/** @type {Text|CDATASection} */ret.nodeValue
2047
2070
  );
2048
- // case 5: // Entity
2049
- }
2050
- case 7:
2051
- {
2052
- // PROCESSING INSTRUCTION
2053
- const node = /** @type {ProcessingInstruction} */ret;
2054
- return `<?${node.target} ${node.data}?>`;
2055
- }
2056
- case 8:
2057
- {
2058
- // Comment
2059
- return `<!--${ret.nodeValue}-->`;
2071
+ // case 5: // Entity Reference Node
2072
+ // No 6: Entity Node
2073
+ // No 12: Notation Node
2074
+ // } case 7: { // PROCESSING INSTRUCTION
2075
+ // const node = /** @type {ProcessingInstruction} */ (ret);
2076
+ // return `<?${node.target} ${node.data}?>`;
2077
+ // } case 8: { // Comment
2078
+ // return `<!--${ret.nodeValue}-->`;
2060
2079
  }
2061
2080
  case 9:
2081
+ case 11:
2062
2082
  {
2063
- // Document
2064
- throw new Error('Document serialization not yet implemented');
2083
+ // DOCUMENT FRAGMENT
2084
+ const node = /** @type {DocumentFragment} */ret;
2085
+ return [...node.childNodes].map(childNode => {
2086
+ return jml.toHTML( /** @type {JamilihFirstArgument} */childNode);
2087
+ }).join('');
2065
2088
  }
2066
2089
  case 10:
2067
2090
  {
2068
2091
  // DOCUMENT TYPE
2069
2092
  const node = /** @type {DocumentType} */ret;
2070
- return `<!DOCTYPE ${node.name}${node.publicId ? `PUBLIC "${node.publicId}" "${node.systemId}"` : node.systemId ? `SYSTEM "${node.systemId}"` : ``}>`;
2071
- }
2072
- case 11:
2073
- {
2074
- // DOCUMENT FRAGMENT
2075
- throw new Error('Document fragment serialization not yet implemented');
2093
+ return `<!DOCTYPE ${node.name}${node.publicId ? ` PUBLIC "${node.publicId}" "${node.systemId}"` : node.systemId ? ` SYSTEM "${node.systemId}"` : ``}>`;
2094
+ /* c8 ignore next 3 */
2076
2095
  }
2077
2096
  default:
2078
2097
  throw new Error('Unexpected node type');
@@ -2117,7 +2136,7 @@ jml.toXMLDOMString = function (...args) {
2117
2136
  */
2118
2137
  class JamilihMap extends Map {
2119
2138
  /**
2120
- * @param {?(string|Element)} element
2139
+ * @param {?(string|HTMLElement)} element
2121
2140
  * @returns {ArbitraryValue}
2122
2141
  */
2123
2142
  get(element) {
@@ -2125,7 +2144,7 @@ class JamilihMap extends Map {
2125
2144
  return super.get.call(this, elem);
2126
2145
  }
2127
2146
  /**
2128
- * @param {string|Element} element
2147
+ * @param {string|HTMLElement} element
2129
2148
  * @param {ArbitraryValue} value
2130
2149
  * @returns {ArbitraryValue}
2131
2150
  */
@@ -2134,7 +2153,7 @@ class JamilihMap extends Map {
2134
2153
  return super.set.call(this, elem, value);
2135
2154
  }
2136
2155
  /**
2137
- * @param {string|Element} element
2156
+ * @param {string|HTMLElement} element
2138
2157
  * @param {string} methodName
2139
2158
  * @param {...ArbitraryValue} args
2140
2159
  * @returns {ArbitraryValue}
@@ -2151,7 +2170,7 @@ class JamilihMap extends Map {
2151
2170
  */
2152
2171
  class JamilihWeakMap extends WeakMap {
2153
2172
  /**
2154
- * @param {Element} element
2173
+ * @param {HTMLElement} element
2155
2174
  * @returns {ArbitraryValue}
2156
2175
  */
2157
2176
  get(element) {
@@ -2162,7 +2181,7 @@ class JamilihWeakMap extends WeakMap {
2162
2181
  return super.get.call(this, elem);
2163
2182
  }
2164
2183
  /**
2165
- * @param {Element} element
2184
+ * @param {HTMLElement} element
2166
2185
  * @param {ArbitraryValue} value
2167
2186
  * @returns {ArbitraryValue}
2168
2187
  */
@@ -2174,7 +2193,7 @@ class JamilihWeakMap extends WeakMap {
2174
2193
  return super.set.call(this, elem, value);
2175
2194
  }
2176
2195
  /**
2177
- * @param {string|Element} element
2196
+ * @param {string|HTMLElement} element
2178
2197
  * @param {string} methodName
2179
2198
  * @param {...ArbitraryValue} args
2180
2199
  * @returns {ArbitraryValue}
@@ -2191,7 +2210,7 @@ jml.Map = JamilihMap;
2191
2210
  jml.WeakMap = JamilihWeakMap;
2192
2211
 
2193
2212
  /**
2194
- * @typedef {[JamilihWeakMap|JamilihMap, Element]} MapAndElementArray
2213
+ * @typedef {[JamilihWeakMap|JamilihMap, HTMLElement]} MapAndElementArray
2195
2214
  */
2196
2215
 
2197
2216
  /**
@@ -2204,7 +2223,7 @@ jml.weak = function (obj, ...args) {
2204
2223
  const elem = jml({
2205
2224
  $map: [map, obj]
2206
2225
  }, ...args);
2207
- return [map, /** @type {Element} */elem];
2226
+ return [map, /** @type {HTMLElement} */elem];
2208
2227
  };
2209
2228
 
2210
2229
  /**
@@ -2217,11 +2236,11 @@ jml.strong = function (obj, ...args) {
2217
2236
  const elem = jml({
2218
2237
  $map: [map, obj]
2219
2238
  }, ...args);
2220
- return [map, /** @type {Element} */elem];
2239
+ return [map, /** @type {HTMLElement} */elem];
2221
2240
  };
2222
2241
 
2223
2242
  /**
2224
- * @param {string|Element} element If a string, will be interpreted as a selector
2243
+ * @param {string|HTMLElement} element If a string, will be interpreted as a selector
2225
2244
  * @param {symbol|string} sym If a string, will be used with `Symbol.for`
2226
2245
  * @returns {ArbitraryValue} The value associated with the symbol
2227
2246
  */
@@ -2233,12 +2252,12 @@ jml.symbol = jml.sym = jml.for = function (element, sym) {
2233
2252
  };
2234
2253
 
2235
2254
  /**
2236
- * @typedef {((elem: Element, ...args: any[]) => void)|{[key: string]: (elem: Element, ...args: any[]) => void}} MapCommand
2255
+ * @typedef {((elem: HTMLElement, ...args: any[]) => void)|{[key: string]: (elem: HTMLElement, ...args: any[]) => void}} MapCommand
2237
2256
  */
2238
2257
 
2239
2258
  /**
2240
- * @param {?(string|Element)} elem If a string, will be interpreted as a selector
2241
- * @param {symbol|string|Map<Element, MapCommand>|WeakMap<Element, MapCommand>} symOrMap If a string, will be used with `Symbol.for`
2259
+ * @param {?(string|HTMLElement)} elem If a string, will be interpreted as a selector
2260
+ * @param {symbol|string|Map<HTMLElement, MapCommand>|WeakMap<HTMLElement, MapCommand>} symOrMap If a string, will be used with `Symbol.for`
2242
2261
  * @param {string|any} methodName Can be `any` if the symbol or map directly
2243
2262
  * points to a function (it is then used as the first argument).
2244
2263
  * @param {ArbitraryValue[]} args
@@ -2258,7 +2277,7 @@ jml.command = function (elem, symOrMap, methodName, ...args) {
2258
2277
 
2259
2278
  return func[methodName](...args);
2260
2279
  }
2261
- func = /** @type {Map<Element, MapCommand>|WeakMap<Element, MapCommand>} */symOrMap.get(elem);
2280
+ func = /** @type {Map<HTMLElement, MapCommand>|WeakMap<HTMLElement, MapCommand>} */symOrMap.get(elem);
2262
2281
  if (!func) {
2263
2282
  throw new Error('No map found');
2264
2283
  }
@@ -2272,12 +2291,13 @@ jml.command = function (elem, symOrMap, methodName, ...args) {
2272
2291
  /**
2273
2292
  * Expects properties `document`, `XMLSerializer`, and `DOMParser`.
2274
2293
  * Also updates `body` with `document.body`.
2275
- * @param {import('jsdom').DOMWindow|HTMLWindow} wind
2294
+ * @param {import('jsdom').DOMWindow|HTMLWindow|undefined} wind
2276
2295
  * @returns {void}
2277
2296
  */
2278
2297
  jml.setWindow = wind => {
2298
+ var _win2;
2279
2299
  win = wind;
2280
- doc = win.document;
2300
+ doc = (_win2 = win) === null || _win2 === void 0 ? void 0 : _win2.document;
2281
2301
  if (doc && doc.body) {
2282
2302
  // eslint-disable-next-line prefer-destructuring -- Needed for typing
2283
2303
  body = /** @type {HTMLBodyElement} */doc.body;
@@ -2312,7 +2332,7 @@ function glue(array, glu) {
2312
2332
  */
2313
2333
  let body; // eslint-disable-line import/no-mutable-exports
2314
2334
 
2315
- /* c8 ignore next 3 */
2335
+ /* c8 ignore next 4 */
2316
2336
  if (doc && doc.body) {
2317
2337
  // eslint-disable-next-line prefer-destructuring -- Needed for type
2318
2338
  body = /** @type {HTMLBodyElement} */doc.body;