elementAXObjectMap.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _lite = require("dequal/lite");
  7. var _AXObjectsMap = _interopRequireDefault(require("./AXObjectsMap"));
  8. var _iterationDecorator = _interopRequireDefault(require("./util/iterationDecorator"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  11. function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  12. function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
  13. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  14. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
  15. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  16. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  17. var elementAXObjects = [];
  18. var _iterator = _createForOfIteratorHelper(_AXObjectsMap.default.entries()),
  19. _step;
  20. try {
  21. var _loop = function _loop() {
  22. var _step$value = _slicedToArray(_step.value, 2),
  23. name = _step$value[0],
  24. def = _step$value[1];
  25. var relatedConcepts = def.relatedConcepts;
  26. if (Array.isArray(relatedConcepts)) {
  27. relatedConcepts.forEach(function (relation) {
  28. if (relation.module === 'HTML') {
  29. var concept = relation.concept;
  30. if (concept != null) {
  31. var conceptStr = JSON.stringify(concept);
  32. var axObjects;
  33. var index = 0;
  34. for (; index < elementAXObjects.length; index++) {
  35. var key = elementAXObjects[index][0];
  36. if (JSON.stringify(key) === conceptStr) {
  37. axObjects = elementAXObjects[index][1];
  38. break;
  39. }
  40. }
  41. if (!Array.isArray(axObjects)) {
  42. axObjects = [];
  43. }
  44. var loc = axObjects.findIndex(function (item) {
  45. return item === name;
  46. });
  47. if (loc === -1) {
  48. axObjects.push(name);
  49. }
  50. if (index < elementAXObjects.length) {
  51. elementAXObjects.splice(index, 1, [concept, axObjects]);
  52. } else {
  53. elementAXObjects.push([concept, axObjects]);
  54. }
  55. }
  56. }
  57. });
  58. }
  59. };
  60. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  61. _loop();
  62. }
  63. } catch (err) {
  64. _iterator.e(err);
  65. } finally {
  66. _iterator.f();
  67. }
  68. var elementAXObjectMap = {
  69. entries: function entries() {
  70. return elementAXObjects;
  71. },
  72. forEach: function forEach(fn) {
  73. var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  74. var _iterator2 = _createForOfIteratorHelper(elementAXObjects),
  75. _step2;
  76. try {
  77. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  78. var _step2$value = _slicedToArray(_step2.value, 2),
  79. key = _step2$value[0],
  80. values = _step2$value[1];
  81. fn.call(thisArg, values, key, elementAXObjects);
  82. }
  83. } catch (err) {
  84. _iterator2.e(err);
  85. } finally {
  86. _iterator2.f();
  87. }
  88. },
  89. get: function get(key) {
  90. var item = elementAXObjects.find(function (tuple) {
  91. return key.name === tuple[0].name && (0, _lite.dequal)(key.attributes, tuple[0].attributes);
  92. });
  93. return item && item[1];
  94. },
  95. has: function has(key) {
  96. return !!elementAXObjectMap.get(key);
  97. },
  98. keys: function keys() {
  99. return elementAXObjects.map(function (_ref) {
  100. var _ref2 = _slicedToArray(_ref, 1),
  101. key = _ref2[0];
  102. return key;
  103. });
  104. },
  105. values: function values() {
  106. return elementAXObjects.map(function (_ref3) {
  107. var _ref4 = _slicedToArray(_ref3, 2),
  108. values = _ref4[1];
  109. return values;
  110. });
  111. }
  112. };
  113. var _default = (0, _iterationDecorator.default)(elementAXObjectMap, elementAXObjectMap.entries());
  114. exports.default = _default;