UNPKG

6.28 kBJavaScriptView Raw
1function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
3import "core-js/modules/es.array.concat.js";
4import "core-js/modules/es.object.assign.js";
5import "core-js/modules/es.object.get-prototype-of.js";
6
7function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
8
9function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
10
11function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
12
13function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
15function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
16
17function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
18
19function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
20
21function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
23function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
24
25function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
26
27function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
29function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
30
31function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
32
33import React, { Component } from 'react';
34import window from 'global';
35export var IFrame = /*#__PURE__*/function (_Component) {
36 _inherits(IFrame, _Component);
37
38 var _super = _createSuper(IFrame);
39
40 function IFrame() {
41 var _this;
42
43 _classCallCheck(this, IFrame);
44
45 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
46 args[_key] = arguments[_key];
47 }
48
49 _this = _super.call.apply(_super, [this].concat(args));
50 _this.iframe = null;
51 return _this;
52 }
53
54 _createClass(IFrame, [{
55 key: "componentDidMount",
56 value: function componentDidMount() {
57 var id = this.props.id;
58 this.iframe = window.document.getElementById(id);
59 }
60 }, {
61 key: "shouldComponentUpdate",
62 value: function shouldComponentUpdate(nextProps) {
63 var scale = nextProps.scale; // eslint-disable-next-line react/destructuring-assignment
64
65 if (scale !== this.props.scale) {
66 this.setIframeBodyStyle({
67 width: "".concat(scale * 100, "%"),
68 height: "".concat(scale * 100, "%"),
69 transform: "scale(".concat(1 / scale, ")"),
70 transformOrigin: 'top left'
71 });
72 }
73
74 return false;
75 }
76 }, {
77 key: "setIframeBodyStyle",
78 value: function setIframeBodyStyle(style) {
79 return Object.assign(this.iframe.contentDocument.body.style, style);
80 }
81 }, {
82 key: "render",
83 value: function render() {
84 var _this$props = this.props,
85 id = _this$props.id,
86 title = _this$props.title,
87 src = _this$props.src,
88 allowFullScreen = _this$props.allowFullScreen,
89 scale = _this$props.scale,
90 rest = _objectWithoutProperties(_this$props, ["id", "title", "src", "allowFullScreen", "scale"]);
91
92 return /*#__PURE__*/React.createElement("iframe", _extends({
93 id: id,
94 title: title,
95 src: src,
96 allowFullScreen: allowFullScreen // @ts-ignore
97 ,
98 loading: "lazy"
99 }, rest));
100 }
101 }]);
102
103 return IFrame;
104}(Component);
105IFrame.displayName = "IFrame";
\No newline at end of file