AXObjectElementMap.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _iterationDecorator = _interopRequireDefault(require("./util/iterationDecorator"));
  7. var _AXObjectsMap = _interopRequireDefault(require("./AXObjectsMap"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
  10. 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."); }
  11. 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; }
  12. function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
  13. 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; } } }; }
  14. 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); }
  15. 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; }
  16. var AXObjectElements = [];
  17. var _iterator = _createForOfIteratorHelper(_AXObjectsMap.default.entries()),
  18. _step;
  19. try {
  20. var _loop = function _loop() {
  21. var _step$value = _slicedToArray(_step.value, 2),
  22. name = _step$value[0],
  23. def = _step$value[1];
  24. var relatedConcepts = def.relatedConcepts;
  25. if (Array.isArray(relatedConcepts)) {
  26. relatedConcepts.forEach(function (relation) {
  27. if (relation.module === 'HTML') {
  28. var concept = relation.concept;
  29. if (concept) {
  30. var index = AXObjectElements.findIndex(function (_ref5) {
  31. var _ref6 = _slicedToArray(_ref5, 1),
  32. key = _ref6[0];
  33. return key === name;
  34. });
  35. if (index === -1) {
  36. AXObjectElements.push([name, []]);
  37. index = AXObjectElements.length - 1;
  38. }
  39. AXObjectElements[index][1].push(concept);
  40. }
  41. }
  42. });
  43. }
  44. };
  45. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  46. _loop();
  47. }
  48. } catch (err) {
  49. _iterator.e(err);
  50. } finally {
  51. _iterator.f();
  52. }
  53. var AXObjectElementMap = {
  54. entries: function entries() {
  55. return AXObjectElements;
  56. },
  57. forEach: function forEach(fn) {
  58. var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  59. var _iterator2 = _createForOfIteratorHelper(AXObjectElements),
  60. _step2;
  61. try {
  62. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  63. var _step2$value = _slicedToArray(_step2.value, 2),
  64. key = _step2$value[0],
  65. values = _step2$value[1];
  66. fn.call(thisArg, values, key, AXObjectElements);
  67. }
  68. } catch (err) {
  69. _iterator2.e(err);
  70. } finally {
  71. _iterator2.f();
  72. }
  73. },
  74. get: function get(key) {
  75. var item = AXObjectElements.find(function (tuple) {
  76. return tuple[0] === key ? true : false;
  77. });
  78. return item && item[1];
  79. },
  80. has: function has(key) {
  81. return !!AXObjectElementMap.get(key);
  82. },
  83. keys: function keys() {
  84. return AXObjectElements.map(function (_ref) {
  85. var _ref2 = _slicedToArray(_ref, 1),
  86. key = _ref2[0];
  87. return key;
  88. });
  89. },
  90. values: function values() {
  91. return AXObjectElements.map(function (_ref3) {
  92. var _ref4 = _slicedToArray(_ref3, 2),
  93. values = _ref4[1];
  94. return values;
  95. });
  96. }
  97. };
  98. var _default = (0, _iterationDecorator.default)(AXObjectElementMap, AXObjectElementMap.entries());
  99. exports.default = _default;