@cronn/element-snapshot 0.31.0 → 0.32.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/browser-lib.iife.js +7 -3
- package/dist/index.mjs +8 -5
- package/package.json +1 -1
package/dist/browser-lib.iife.js
CHANGED
|
@@ -451,7 +451,7 @@
|
|
|
451
451
|
function resolveLabelName(element) {
|
|
452
452
|
if (element.id !== null) {
|
|
453
453
|
const referencedElement = element.ownerDocument.querySelector(attributeSelector("for", element.id));
|
|
454
|
-
if (referencedElement !== null) return resolveAccessibleTextContent(referencedElement);
|
|
454
|
+
if (referencedElement !== null) return resolveAccessibleTextContent(referencedElement, [element]);
|
|
455
455
|
}
|
|
456
456
|
const closestLabel = element.closest("label");
|
|
457
457
|
if (closestLabel !== null) return resolveAccessibleTextContent(closestLabel, [element]);
|
|
@@ -515,6 +515,11 @@
|
|
|
515
515
|
};
|
|
516
516
|
}
|
|
517
517
|
//#endregion
|
|
518
|
+
//#region src/utils/array.ts
|
|
519
|
+
function unwrapSingleItem(items) {
|
|
520
|
+
return items.length === 1 ? items.at(0) : items;
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
518
523
|
//#region src/browser/description.ts
|
|
519
524
|
function discribableAttributes(element) {
|
|
520
525
|
return { description: resolveDescription(element) };
|
|
@@ -600,8 +605,7 @@
|
|
|
600
605
|
if (!(element instanceof HTMLSelectElement)) return resolveAccessibleTextContent(element);
|
|
601
606
|
const selectedLabels = Array.from(element.selectedOptions).map((option) => option.label);
|
|
602
607
|
if (selectedLabels.length === 0) return;
|
|
603
|
-
|
|
604
|
-
return selectedLabels;
|
|
608
|
+
return unwrapSingleItem(selectedLabels);
|
|
605
609
|
}
|
|
606
610
|
function snapshotOptions(element) {
|
|
607
611
|
const optionsContainer = resolveOptionsContainer(element);
|
package/dist/index.mjs
CHANGED
|
@@ -96,6 +96,11 @@ var ElementSnapshotProxy = class ElementSnapshotProxy {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
//#endregion
|
|
99
|
+
//#region src/utils/array.ts
|
|
100
|
+
function unwrapSingleItem(items) {
|
|
101
|
+
return items.length === 1 ? items.at(0) : items;
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
99
104
|
//#region src/transformers/semantic-snapshot-transformer.ts
|
|
100
105
|
function semanticSnapshotTransformer(snapshot, context) {
|
|
101
106
|
if (snapshot.role === "text") return snapshot.name;
|
|
@@ -113,12 +118,12 @@ function transformElementSnapshot(snapshot, transformRecursive) {
|
|
|
113
118
|
}
|
|
114
119
|
if (hasOnlyChildren(normalizedSnapshot)) {
|
|
115
120
|
const { role, children } = normalizedSnapshot;
|
|
116
|
-
return transformedSnapshot(role,
|
|
121
|
+
return transformedSnapshot(role, unwrapSingleItem(children));
|
|
117
122
|
}
|
|
118
123
|
const { role, name, attributes, children } = normalizedSnapshot;
|
|
119
124
|
return transformedSnapshot(role, name, {
|
|
120
125
|
...attributes,
|
|
121
|
-
children: children
|
|
126
|
+
children: isEmpty(children) ? void 0 : unwrapSingleItem(children)
|
|
122
127
|
});
|
|
123
128
|
}
|
|
124
129
|
function normalizeElementSnapshot(snapshot, transformRecursive) {
|
|
@@ -195,9 +200,7 @@ var SnapshotSerializer = class {
|
|
|
195
200
|
this.defaultTransformer = options.defaultTransformer ?? semanticSnapshotTransformer;
|
|
196
201
|
}
|
|
197
202
|
transform(snapshots) {
|
|
198
|
-
|
|
199
|
-
if (transformedSnapshots.length === 1) return transformedSnapshots.at(0);
|
|
200
|
-
return transformedSnapshots;
|
|
203
|
+
return unwrapSingleItem(this.filterSnapshots(snapshots).map(this.transformSnapshotRecursive));
|
|
201
204
|
}
|
|
202
205
|
filterSnapshots(snapshots) {
|
|
203
206
|
if (this.filter === void 0) return snapshots;
|