@cronn/element-snapshot 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +12 -6
- package/dist/index.global.js +34 -15
- package/dist/types.d.ts +12 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ interface ButtonAttributes extends DisableableAttributes {
|
|
|
18
18
|
}
|
|
19
19
|
type PressedValue = true | "mixed";
|
|
20
20
|
|
|
21
|
+
interface DiscribableAttributes {
|
|
22
|
+
description?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
interface InputSnapshot extends GenericElementSnapshot<CommonInputRole, InputAttributes> {
|
|
22
26
|
}
|
|
23
27
|
type InputRole = "button" | "combobox" | CommonInputRole;
|
|
@@ -26,8 +30,7 @@ interface InputAttributes extends CommonInputAttributes {
|
|
|
26
30
|
value?: string;
|
|
27
31
|
checked?: boolean;
|
|
28
32
|
}
|
|
29
|
-
interface CommonInputAttributes extends InputStateAttributes {
|
|
30
|
-
description?: string;
|
|
33
|
+
interface CommonInputAttributes extends InputStateAttributes, DiscribableAttributes {
|
|
31
34
|
placeholder?: string;
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -46,13 +49,16 @@ interface OptionAttributes {
|
|
|
46
49
|
interface DialogSnapshot extends GenericElementSnapshot<DialogRole, DialogAttributes> {
|
|
47
50
|
}
|
|
48
51
|
type DialogRole = "dialog" | "alertdialog";
|
|
49
|
-
interface DialogAttributes {
|
|
50
|
-
description?: string;
|
|
52
|
+
interface DialogAttributes extends DiscribableAttributes {
|
|
51
53
|
modal?: boolean;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
interface GroupSnapshot extends GenericElementSnapshot<"group"> {
|
|
55
57
|
}
|
|
58
|
+
interface RadiogroupSnapshot extends GenericElementSnapshot<"radiogroup", RadiogroupAttributes> {
|
|
59
|
+
}
|
|
60
|
+
interface RadiogroupAttributes extends DiscribableAttributes {
|
|
61
|
+
}
|
|
56
62
|
|
|
57
63
|
interface HeadingSnapshot extends GenericElementSnapshot<"heading", HeadingAttributes> {
|
|
58
64
|
}
|
|
@@ -97,9 +103,9 @@ interface TextSnapshot {
|
|
|
97
103
|
|
|
98
104
|
type SnapshotTargetElement = HTMLElement | SVGElement;
|
|
99
105
|
type NodeRole = ElementRole | "text";
|
|
100
|
-
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | "progressbar" | ContainerRole | InputRole | DialogRole;
|
|
106
|
+
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | "radiogroup" | "progressbar" | ContainerRole | InputRole | DialogRole;
|
|
101
107
|
type NodeSnapshot = ElementSnapshot | TextSnapshot;
|
|
102
|
-
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot | ProgressbarSnapshot;
|
|
108
|
+
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot | RadiogroupSnapshot | ProgressbarSnapshot;
|
|
103
109
|
interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
|
|
104
110
|
role: TRole;
|
|
105
111
|
name?: string;
|
package/dist/index.global.js
CHANGED
|
@@ -126,6 +126,11 @@
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
// src/snapshots/description.ts
|
|
129
|
+
function discribableAttributes(element) {
|
|
130
|
+
return {
|
|
131
|
+
description: resolveDescription(element)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
129
134
|
function resolveDescription(element) {
|
|
130
135
|
const describedByElement = resolveElementReference(
|
|
131
136
|
element,
|
|
@@ -428,13 +433,14 @@
|
|
|
428
433
|
}
|
|
429
434
|
function snapshotCommonInputAttributes(element, isEmpty) {
|
|
430
435
|
return {
|
|
431
|
-
|
|
436
|
+
...discribableAttributes(element),
|
|
432
437
|
placeholder: isEmpty ? resolvePlaceholder(element) : void 0,
|
|
433
438
|
...inputStateAttributes(element)
|
|
434
439
|
};
|
|
435
440
|
}
|
|
441
|
+
var CHECKED_INPUT_TYPES = /* @__PURE__ */ new Set(["checkbox", "radio"]);
|
|
436
442
|
function resolveInputValue(element) {
|
|
437
|
-
if (element instanceof HTMLInputElement && element.type
|
|
443
|
+
if (element instanceof HTMLInputElement && CHECKED_INPUT_TYPES.has(element.type)) {
|
|
438
444
|
return void 0;
|
|
439
445
|
}
|
|
440
446
|
return stringAttribute(element.value);
|
|
@@ -477,7 +483,7 @@
|
|
|
477
483
|
return null;
|
|
478
484
|
}
|
|
479
485
|
const options = snapshotOptions(element);
|
|
480
|
-
const value = resolveValue(element
|
|
486
|
+
const value = resolveValue(element);
|
|
481
487
|
return {
|
|
482
488
|
role: "combobox",
|
|
483
489
|
name: resolveInputLabel(element),
|
|
@@ -497,15 +503,23 @@
|
|
|
497
503
|
}
|
|
498
504
|
return false;
|
|
499
505
|
}
|
|
500
|
-
function resolveValue(element
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
506
|
+
function resolveValue(element) {
|
|
507
|
+
if (element instanceof HTMLButtonElement) {
|
|
508
|
+
return snapshotTextContent(element);
|
|
509
|
+
}
|
|
510
|
+
if (element instanceof HTMLInputElement) {
|
|
511
|
+
return resolveInputValue(element);
|
|
512
|
+
}
|
|
513
|
+
const selectedLabels = Array.from(element.selectedOptions).map(
|
|
514
|
+
(option) => option.label
|
|
515
|
+
);
|
|
516
|
+
if (selectedLabels.length === 0) {
|
|
517
|
+
return void 0;
|
|
504
518
|
}
|
|
505
|
-
if (
|
|
506
|
-
return
|
|
519
|
+
if (selectedLabels.length === 1) {
|
|
520
|
+
return selectedLabels.at(0);
|
|
507
521
|
}
|
|
508
|
-
return
|
|
522
|
+
return selectedLabels;
|
|
509
523
|
}
|
|
510
524
|
function snapshotOptions(element) {
|
|
511
525
|
return resolveOptions(element).map(snapshotOption).filter((childSnapshot) => childSnapshot !== null);
|
|
@@ -514,10 +528,6 @@
|
|
|
514
528
|
if (element instanceof HTMLSelectElement) {
|
|
515
529
|
return Array.from(element.options);
|
|
516
530
|
}
|
|
517
|
-
const ariaExpanded = element.ariaExpanded === "true";
|
|
518
|
-
if (!ariaExpanded) {
|
|
519
|
-
return [];
|
|
520
|
-
}
|
|
521
531
|
const controlledElement = resolveElementReference(element, "aria-controls");
|
|
522
532
|
if (controlledElement === null) {
|
|
523
533
|
return [];
|
|
@@ -545,7 +555,7 @@
|
|
|
545
555
|
role,
|
|
546
556
|
name: resolveAccessibleName(element, false),
|
|
547
557
|
attributes: {
|
|
548
|
-
|
|
558
|
+
...discribableAttributes(element),
|
|
549
559
|
modal: booleanAttribute(element.ariaModal)
|
|
550
560
|
},
|
|
551
561
|
children: snapshotChildren(element)
|
|
@@ -567,6 +577,14 @@
|
|
|
567
577
|
}
|
|
568
578
|
return resolveAccessibleName(element, false);
|
|
569
579
|
}
|
|
580
|
+
function snapshotRadiogroup(element) {
|
|
581
|
+
return {
|
|
582
|
+
role: "radiogroup",
|
|
583
|
+
name: resolveAccessibleName(element, false),
|
|
584
|
+
attributes: discribableAttributes(element),
|
|
585
|
+
children: snapshotChildren(element)
|
|
586
|
+
};
|
|
587
|
+
}
|
|
570
588
|
|
|
571
589
|
// src/snapshots/heading.ts
|
|
572
590
|
var LEVEL_REGEXP = /^H([1-6])$/;
|
|
@@ -677,6 +695,7 @@
|
|
|
677
695
|
menuitem: snapshotMenuitem,
|
|
678
696
|
columnheader: snapshotColumnheader,
|
|
679
697
|
group: snapshotGroup,
|
|
698
|
+
radiogroup: snapshotRadiogroup,
|
|
680
699
|
progressbar: snapshotProgressbar
|
|
681
700
|
};
|
|
682
701
|
function snapshotElement(element) {
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ interface ButtonAttributes extends DisableableAttributes {
|
|
|
18
18
|
}
|
|
19
19
|
type PressedValue = true | "mixed";
|
|
20
20
|
|
|
21
|
+
interface DiscribableAttributes {
|
|
22
|
+
description?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
interface InputSnapshot extends GenericElementSnapshot<CommonInputRole, InputAttributes> {
|
|
22
26
|
}
|
|
23
27
|
type InputRole = "button" | "combobox" | CommonInputRole;
|
|
@@ -26,8 +30,7 @@ interface InputAttributes extends CommonInputAttributes {
|
|
|
26
30
|
value?: string;
|
|
27
31
|
checked?: boolean;
|
|
28
32
|
}
|
|
29
|
-
interface CommonInputAttributes extends InputStateAttributes {
|
|
30
|
-
description?: string;
|
|
33
|
+
interface CommonInputAttributes extends InputStateAttributes, DiscribableAttributes {
|
|
31
34
|
placeholder?: string;
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -51,13 +54,16 @@ type ContainerRole = SetValues<typeof CONTAINER_ROLES>;
|
|
|
51
54
|
interface DialogSnapshot extends GenericElementSnapshot<DialogRole, DialogAttributes> {
|
|
52
55
|
}
|
|
53
56
|
type DialogRole = "dialog" | "alertdialog";
|
|
54
|
-
interface DialogAttributes {
|
|
55
|
-
description?: string;
|
|
57
|
+
interface DialogAttributes extends DiscribableAttributes {
|
|
56
58
|
modal?: boolean;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
interface GroupSnapshot extends GenericElementSnapshot<"group"> {
|
|
60
62
|
}
|
|
63
|
+
interface RadiogroupSnapshot extends GenericElementSnapshot<"radiogroup", RadiogroupAttributes> {
|
|
64
|
+
}
|
|
65
|
+
interface RadiogroupAttributes extends DiscribableAttributes {
|
|
66
|
+
}
|
|
61
67
|
|
|
62
68
|
interface HeadingSnapshot extends GenericElementSnapshot<"heading", HeadingAttributes> {
|
|
63
69
|
}
|
|
@@ -101,9 +107,9 @@ interface TextSnapshot {
|
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
type NodeRole = ElementRole | "text";
|
|
104
|
-
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | "progressbar" | ContainerRole | InputRole | DialogRole;
|
|
110
|
+
type ElementRole = "heading" | "link" | "button" | "option" | "tab" | "menuitem" | "columnheader" | "group" | "radiogroup" | "progressbar" | ContainerRole | InputRole | DialogRole;
|
|
105
111
|
type NodeSnapshot = ElementSnapshot | TextSnapshot;
|
|
106
|
-
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot | ProgressbarSnapshot;
|
|
112
|
+
type ElementSnapshot = ContainerSnapshot | HeadingSnapshot | LinkSnapshot | ButtonSnapshot | InputSnapshot | ComboboxSnapshot | OptionSnapshot | DialogSnapshot | TabSnapshot | MenuitemSnapshot | ColumnheaderSnapshot | GroupSnapshot | RadiogroupSnapshot | ProgressbarSnapshot;
|
|
107
113
|
interface GenericElementSnapshot<TRole extends NodeRole = NodeRole, TAttributes = unknown> {
|
|
108
114
|
role: TRole;
|
|
109
115
|
name?: string;
|