text: "use strict";
  var __extends = (this && this.__extends) || (function () {
      var extendStatics = function (d, b) {
          extendStatics = Object.setPrototypeOf ||
              ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
              function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
          return extendStatics(d, b);
      };
      return function (d, b) {
          extendStatics(d, b);
          function __() { this.constructor = d; }
          d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
      };
  })();
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.Element = exports.NodeWithChildren = exports.ProcessingInstruction = exports.Comment = exports.Text = exports.DataNode = exports.Node = void 0;
  var nodeTypes = new Map([
      ["tag" /* Tag */, 1],
      ["script" /* Script */, 1],
      ["style" /* Style */, 1],
      ["directive" /* Directive */, 1],
      ["text" /* Text */, 3],
      ["cdata" /* CDATA */, 4],
      ["comment" /* Comment */, 8],
  ]);
  /**
   * This object will be used as the prototype for Nodes when creating a
   * DOM-Level-1-compliant structure.
   */
  var Node = /** @class */ (function () {
      /**
       *
       * @param type The type of the node.
       */
      function Node(type) {
          this.type = type;
          /** Parent of the node */
          this.parent = null;
          /** Previous sibling */
          this.prev = null;
          /** Next sibling */
          this.next = null;
          /** The start index of the node. Requires `withStartIndices` on the handler to be `true. */
          this.startIndex = null;
          /** The end index of the node. Requires `withEndIndices` on the handler to be `true. */
          this.endIndex = null;
      }
      Object.defineProperty(Node.prototype, "nodeType", {
          // Read-only aliases
          get: function () {
              var _a;
              return (_a = nodeTypes.get(this.type)) !== null && _a !== void 0 ? _a : 1;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Node.prototype, "parentNode", {
          // Read-write aliases for properties
          get: function () {
              return this.parent;
          },
          set: function (parent) {
              this.parent = parent;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Node.prototype, "previousSibling", {
          get: function () {
              return this.prev;
          },
          set: function (prev) {
              this.prev = prev;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Node.prototype, "nextSibling", {
          get: function () {
              return this.next;
          },
          set: function (next) {
              this.next = next;
          },
          enumerable: false,
          configurable: true
      });
      return Node;
  }());
  exports.Node = Node;
  var DataNode = /** @class */ (function (_super) {
      __extends(DataNode, _super);
      /**
       *
       * @param type The type of the node
       * @param data The content of the data node
       */
      function DataNode(type, data) {
          var _this = _super.call(this, type) || this;
          _this.data = data;
          return _this;
      }
      Object.defineProperty(DataNode.prototype, "nodeValue", {
          get: function () {
              return this.data;
          },
          set: function (data) {
              this.data = data;
          },
          enumerable: false,
          configurable: true
      });
      return DataNode;
  }(Node));
  exports.DataNode = DataNode;
  var Text = /** @class */ (function (_super) {
      __extends(Text, _super);
      function Text(data) {
          return _super.call(this, "text" /* Text */, data) || this;
      }
      return Text;
  }(DataNode));
  exports.Text = Text;
  var Comment = /** @class */ (function (_super) {
      __extends(Comment, _super);
      function Comment(data) {
          return _super.call(this, "comment" /* Comment */, data) || this;
      }
      return Comment;
  }(DataNode));
  exports.Comment = Comment;
  var ProcessingInstruction = /** @class */ (function (_super) {
      __extends(ProcessingInstruction, _super);
      function ProcessingInstruction(name, data) {
          var _this = _super.call(this, "directive" /* Directive */, data) || this;
          _this.name = name;
          return _this;
      }
      return ProcessingInstruction;
  }(DataNode));
  exports.ProcessingInstruction = ProcessingInstruction;
  var NodeWithChildren = /** @class */ (function (_super) {
      __extends(NodeWithChildren, _super);
      /**
       *
       * @param type Type of the node.
       * @param children Children of the node. Only certain node types can have children.
       */
      function NodeWithChildren(type, children) {
          var _this = _super.call(this, type) || this;
          _this.children = children;
          return _this;
      }
      Object.defineProperty(NodeWithChildren.prototype, "firstChild", {
          // Aliases
          get: function () {
              var _a;
              return (_a = this.children[0]) !== null && _a !== void 0 ? _a : null;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(NodeWithChildren.prototype, "lastChild", {
          get: function () {
              return this.children.length > 0
                  ? this.children[this.children.length - 1]
                  : null;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(NodeWithChildren.prototype, "childNodes", {
          get: function () {
              return this.children;
          },
          set: function (children) {
              this.children = children;
          },
          enumerable: false,
          configurable: true
      });
      return NodeWithChildren;
  }(Node));
  exports.NodeWithChildren = NodeWithChildren;
  var Element = /** @class */ (function (_super) {
      __extends(Element, _super);
      /**
       *
       * @param name Name of the tag, eg. `div`, `span`
       * @param attribs Object mapping attribute names to attribute values
       */
      function Element(name, attribs) {
          var _this = _super.call(this, name === "script"
              ? "script" /* Script */
              : name === "style"
                  ? "style" /* Style */
                  : "tag" /* Tag */, []) || this;
          _this.name = name;
          _this.attribs = attribs;
          _this.attribs = attribs;
          return _this;
      }
      Object.defineProperty(Element.prototype, "tagName", {
          // DOM Level 1 aliases
          get: function () {
              return this.name;
          },
          set: function (name) {
              this.name = name;
          },
          enumerable: false,
          configurable: true
      });
      Object.defineProperty(Element.prototype, "attributes", {
          get: function () {
              var _this = this;
              return Object.keys(this.attribs).map(function (name) { return ({
                  name: name,
                  value: _this.attribs[name],
              }); });
          },
          enumerable: false,
          configurable: true
      });
      return Element;
  }(NodeWithChildren));
  exports.Element = Element;
  