HTMLHandler.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.HTMLHandler = void 0;
  19. var Handler_js_1 = require("../../core/Handler.js");
  20. var HTMLDocument_js_1 = require("./HTMLDocument.js");
  21. var HTMLHandler = (function (_super) {
  22. __extends(HTMLHandler, _super);
  23. function HTMLHandler() {
  24. var _this = _super !== null && _super.apply(this, arguments) || this;
  25. _this.documentClass = HTMLDocument_js_1.HTMLDocument;
  26. return _this;
  27. }
  28. HTMLHandler.prototype.handlesDocument = function (document) {
  29. var adaptor = this.adaptor;
  30. if (typeof (document) === 'string') {
  31. try {
  32. document = adaptor.parse(document, 'text/html');
  33. }
  34. catch (err) { }
  35. }
  36. if (document instanceof adaptor.window.Document ||
  37. document instanceof adaptor.window.HTMLElement ||
  38. document instanceof adaptor.window.DocumentFragment) {
  39. return true;
  40. }
  41. return false;
  42. };
  43. HTMLHandler.prototype.create = function (document, options) {
  44. var adaptor = this.adaptor;
  45. if (typeof (document) === 'string') {
  46. document = adaptor.parse(document, 'text/html');
  47. }
  48. else if (document instanceof adaptor.window.HTMLElement ||
  49. document instanceof adaptor.window.DocumentFragment) {
  50. var child = document;
  51. document = adaptor.parse('', 'text/html');
  52. adaptor.append(adaptor.body(document), child);
  53. }
  54. return _super.prototype.create.call(this, document, options);
  55. };
  56. return HTMLHandler;
  57. }(Handler_js_1.AbstractHandler));
  58. exports.HTMLHandler = HTMLHandler;
  59. //# sourceMappingURL=HTMLHandler.js.map