10d47604d8036e94be5fa4e1750f1bd910e4834b7b67a2c00fd78ab09de42eac8ce7c618cc97e28da8d12d759eabc5159da57f220dd676facc3178c2322e43 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  4. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5. var cloneNode = function cloneNode(obj, parent) {
  6. if ((typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) !== 'object') {
  7. return obj;
  8. }
  9. var cloned = new obj.constructor();
  10. for (var i in obj) {
  11. if (!obj.hasOwnProperty(i)) {
  12. continue;
  13. }
  14. var value = obj[i];
  15. var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
  16. if (i === 'parent' && type === 'object') {
  17. if (parent) {
  18. cloned[i] = parent;
  19. }
  20. } else if (value instanceof Array) {
  21. cloned[i] = value.map(function (j) {
  22. return cloneNode(j, cloned);
  23. });
  24. } else {
  25. cloned[i] = cloneNode(value, cloned);
  26. }
  27. }
  28. return cloned;
  29. };
  30. var _class = function () {
  31. function _class() {
  32. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  33. _classCallCheck(this, _class);
  34. Object.assign(this, opts);
  35. this.spaces = this.spaces || {};
  36. this.spaces.before = this.spaces.before || '';
  37. this.spaces.after = this.spaces.after || '';
  38. }
  39. _class.prototype.remove = function remove() {
  40. if (this.parent) {
  41. this.parent.removeChild(this);
  42. }
  43. this.parent = undefined;
  44. return this;
  45. };
  46. _class.prototype.replaceWith = function replaceWith() {
  47. if (this.parent) {
  48. for (var index in arguments) {
  49. this.parent.insertBefore(this, arguments[index]);
  50. }
  51. this.remove();
  52. }
  53. return this;
  54. };
  55. _class.prototype.next = function next() {
  56. return this.parent.at(this.parent.index(this) + 1);
  57. };
  58. _class.prototype.prev = function prev() {
  59. return this.parent.at(this.parent.index(this) - 1);
  60. };
  61. _class.prototype.clone = function clone() {
  62. var overrides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  63. var cloned = cloneNode(this);
  64. for (var name in overrides) {
  65. cloned[name] = overrides[name];
  66. }
  67. return cloned;
  68. };
  69. _class.prototype.toString = function toString() {
  70. return [this.spaces.before, String(this.value), this.spaces.after].join('');
  71. };
  72. return _class;
  73. }();
  74. exports.default = _class;
  75. module.exports = exports['default'];