iframe-element-container.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var element_container_1 = require("../element-container");
  17. var node_parser_1 = require("../node-parser");
  18. var color_1 = require("../../css/types/color");
  19. var parser_1 = require("../../css/syntax/parser");
  20. var parseColor = function (value) { return color_1.color.parse(parser_1.Parser.create(value).parseComponentValue()); };
  21. var IFrameElementContainer = /** @class */ (function (_super) {
  22. __extends(IFrameElementContainer, _super);
  23. function IFrameElementContainer(iframe) {
  24. var _this = _super.call(this, iframe) || this;
  25. _this.src = iframe.src;
  26. _this.width = parseInt(iframe.width, 10) || 0;
  27. _this.height = parseInt(iframe.height, 10) || 0;
  28. _this.backgroundColor = _this.styles.backgroundColor;
  29. try {
  30. if (iframe.contentWindow &&
  31. iframe.contentWindow.document &&
  32. iframe.contentWindow.document.documentElement) {
  33. _this.tree = node_parser_1.parseTree(iframe.contentWindow.document.documentElement);
  34. // http://www.w3.org/TR/css3-background/#special-backgrounds
  35. var documentBackgroundColor = iframe.contentWindow.document.documentElement
  36. ? parseColor(getComputedStyle(iframe.contentWindow.document.documentElement)
  37. .backgroundColor)
  38. : color_1.COLORS.TRANSPARENT;
  39. var bodyBackgroundColor = iframe.contentWindow.document.body
  40. ? parseColor(getComputedStyle(iframe.contentWindow.document.body).backgroundColor)
  41. : color_1.COLORS.TRANSPARENT;
  42. _this.backgroundColor = color_1.isTransparent(documentBackgroundColor)
  43. ? color_1.isTransparent(bodyBackgroundColor)
  44. ? _this.styles.backgroundColor
  45. : bodyBackgroundColor
  46. : documentBackgroundColor;
  47. }
  48. }
  49. catch (e) { }
  50. return _this;
  51. }
  52. return IFrameElementContainer;
  53. }(element_container_1.ElementContainer));
  54. exports.IFrameElementContainer = IFrameElementContainer;
  55. //# sourceMappingURL=iframe-element-container.js.map