vicowa-web-components
Version:
2 lines • 2.06 kB
JavaScript
import{WebComponentBaseClass as t}from"/third_party/web-component-base-class/dist/web-component-base-class.js";import e from"../utilities/observerFactory.js";let n=1;window.customElements.define("vicowa-resize-detector",class VicowaResizeDetector extends t{#t;#e;#n;constructor(){super(),this.#t=e(),this.#e=n,this.#n={},n++}static get properties(){return{}}attached(){const t=`<!DOCTYPE html>\n<html>\n\t<body>\n\t<script>\n\tfunction ready(fn){ if (document.readyState !== 'loading'){ fn(); } else { document.addEventListener('DOMContentLoaded', fn); } }\n\tconst handleResize = function(){ window.parent.postMessage({ message: 'resize', target: ${this.#e} },'*'); }\n\twindow.addEventListener('resize', handleResize);\n\tready(handleResize);\n\twindow.oncontextmenu = function() { return false; };\n\t<\/script>\n\t</body>\n</html>`,e=this.parentElement?getComputedStyle(this.parentElement,null):null;if(!e||!e.position||"static"===e.position)throw new Error("make sure this element is contained within a positioned element, e.g. position: absolute, position: relative");this.$.detector.src=`data:text/html;charset=utf-8,${escape(t)}`,this.addAutoEventListener(window,"message",(t=>{if(t.data&&t.data.message&&"resize"===t.data.message&&t.data.target===this.#e){const t=this.getBoundingClientRect();this.#t.notify("resize",{oldRect:this.#n,newRect:t}),this.#n=t}})),this.#n=this.getBoundingClientRect()}addObserver(t,e){this.#t.addObserver("resize",t,e)}removeObserver(t){this.#t.removeObserver("resize",t)}removeOwner(t){this.#t.removeOwner(t)}static get template(){return'\n\t\t\t<style>\n\t\t\t\t:host,\n\t\t\t\t\tiframe {\n\t\t\t\t\tdisplay: block;\n\t\t\t\t\tposition: absolute;\n\t\t\t\t\ttop: 0;\n\t\t\t\t\tright: 0;\n\t\t\t\t\tbottom: 0;\n\t\t\t\t\tleft: 0;\n\t\t\t\t\tpointer-events: none;\n\t\t\t\t\topacity: 0;\n\t\t\t\t\tborder: none;\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\theight: 100%;\n\t\t\t\t\tbackground: transparent;\n\t\t\t\t}\n\t\t\t</style>\n\t\t\t<iframe id="detector"></iframe>\n\t\t'}});
//# sourceMappingURL=vicowa-resize-detector.js.map