accessibility.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var accessibility_exports = {};
  20. __export(accessibility_exports, {
  21. Accessibility: () => Accessibility
  22. });
  23. module.exports = __toCommonJS(accessibility_exports);
  24. class Accessibility {
  25. constructor(getAXTree) {
  26. this._getAXTree = getAXTree;
  27. }
  28. async snapshot(options = {}) {
  29. const {
  30. interestingOnly = true,
  31. root = null
  32. } = options;
  33. const { tree, needle } = await this._getAXTree(root || void 0);
  34. if (!interestingOnly) {
  35. if (root)
  36. return needle && serializeTree(needle)[0];
  37. return serializeTree(tree)[0];
  38. }
  39. const interestingNodes = /* @__PURE__ */ new Set();
  40. collectInterestingNodes(interestingNodes, tree, false);
  41. if (root && (!needle || !interestingNodes.has(needle)))
  42. return null;
  43. return serializeTree(needle || tree, interestingNodes)[0];
  44. }
  45. }
  46. function collectInterestingNodes(collection, node, insideControl) {
  47. if (node.isInteresting(insideControl))
  48. collection.add(node);
  49. if (node.isLeafNode())
  50. return;
  51. insideControl = insideControl || node.isControl();
  52. for (const child of node.children())
  53. collectInterestingNodes(collection, child, insideControl);
  54. }
  55. function serializeTree(node, whitelistedNodes) {
  56. const children = [];
  57. for (const child of node.children())
  58. children.push(...serializeTree(child, whitelistedNodes));
  59. if (whitelistedNodes && !whitelistedNodes.has(node))
  60. return children;
  61. const serializedNode = node.serialize();
  62. if (children.length)
  63. serializedNode.children = children;
  64. return [serializedNode];
  65. }
  66. // Annotate the CommonJS export names for ESM import in node:
  67. 0 && (module.exports = {
  68. Accessibility
  69. });