DOMAdaptor.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. var __values = (this && this.__values) || function(o) {
  3. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  4. if (m) return m.call(o);
  5. if (o && typeof o.length === "number") return {
  6. next: function () {
  7. if (o && i >= o.length) o = void 0;
  8. return { value: o && o[i++], done: !o };
  9. }
  10. };
  11. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  12. };
  13. Object.defineProperty(exports, "__esModule", { value: true });
  14. exports.AbstractDOMAdaptor = void 0;
  15. var AbstractDOMAdaptor = (function () {
  16. function AbstractDOMAdaptor(document) {
  17. if (document === void 0) { document = null; }
  18. this.document = document;
  19. }
  20. AbstractDOMAdaptor.prototype.node = function (kind, def, children, ns) {
  21. var e_1, _a;
  22. if (def === void 0) { def = {}; }
  23. if (children === void 0) { children = []; }
  24. var node = this.create(kind, ns);
  25. this.setAttributes(node, def);
  26. try {
  27. for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
  28. var child = children_1_1.value;
  29. this.append(node, child);
  30. }
  31. }
  32. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  33. finally {
  34. try {
  35. if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
  36. }
  37. finally { if (e_1) throw e_1.error; }
  38. }
  39. return node;
  40. };
  41. AbstractDOMAdaptor.prototype.setAttributes = function (node, def) {
  42. var e_2, _a, e_3, _b, e_4, _c;
  43. if (def.style && typeof (def.style) !== 'string') {
  44. try {
  45. for (var _d = __values(Object.keys(def.style)), _e = _d.next(); !_e.done; _e = _d.next()) {
  46. var key = _e.value;
  47. this.setStyle(node, key.replace(/-([a-z])/g, function (_m, c) { return c.toUpperCase(); }), def.style[key]);
  48. }
  49. }
  50. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  51. finally {
  52. try {
  53. if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
  54. }
  55. finally { if (e_2) throw e_2.error; }
  56. }
  57. }
  58. if (def.properties) {
  59. try {
  60. for (var _f = __values(Object.keys(def.properties)), _g = _f.next(); !_g.done; _g = _f.next()) {
  61. var key = _g.value;
  62. node[key] = def.properties[key];
  63. }
  64. }
  65. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  66. finally {
  67. try {
  68. if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
  69. }
  70. finally { if (e_3) throw e_3.error; }
  71. }
  72. }
  73. try {
  74. for (var _h = __values(Object.keys(def)), _j = _h.next(); !_j.done; _j = _h.next()) {
  75. var key = _j.value;
  76. if ((key !== 'style' || typeof (def.style) === 'string') && key !== 'properties') {
  77. this.setAttribute(node, key, def[key]);
  78. }
  79. }
  80. }
  81. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  82. finally {
  83. try {
  84. if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
  85. }
  86. finally { if (e_4) throw e_4.error; }
  87. }
  88. };
  89. AbstractDOMAdaptor.prototype.replace = function (nnode, onode) {
  90. this.insert(nnode, onode);
  91. this.remove(onode);
  92. return onode;
  93. };
  94. AbstractDOMAdaptor.prototype.childNode = function (node, i) {
  95. return this.childNodes(node)[i];
  96. };
  97. AbstractDOMAdaptor.prototype.allClasses = function (node) {
  98. var classes = this.getAttribute(node, 'class');
  99. return (!classes ? [] :
  100. classes.replace(/ +/g, ' ').replace(/^ /, '').replace(/ $/, '').split(/ /));
  101. };
  102. return AbstractDOMAdaptor;
  103. }());
  104. exports.AbstractDOMAdaptor = AbstractDOMAdaptor;
  105. //# sourceMappingURL=DOMAdaptor.js.map