UNPKG

blueprint-renderer-webcomponents

Version:
125 lines (117 loc) 4.03 kB
import {initializerDefineProperty as $f3Ts0$initializerDefineProperty, applyDecoratedDescriptor as $f3Ts0$applyDecoratedDescriptor} from "@swc/helpers"; import {html as $f3Ts0$html, LitElement as $f3Ts0$LitElement, css as $f3Ts0$css} from "lit"; import {customElement as $f3Ts0$customElement, property as $f3Ts0$property} from "lit/decorators"; import {Graph as $f3Ts0$Graph} from "blueprint-renderer"; var _class; var _class1, _descriptor, _dec, _descriptor1, _dec1; function $a8e101027d325e52$var$notscroll(e) { e.preventDefault(); } const $a8e101027d325e52$var$disable = ()=>{ document.addEventListener("wheel", $a8e101027d325e52$var$notscroll, { passive: false }); document.addEventListener("touchmove", $a8e101027d325e52$var$notscroll, { passive: false }); }; const $a8e101027d325e52$var$enable = ()=>{ document.removeEventListener("wheel", $a8e101027d325e52$var$notscroll); document.removeEventListener("touchmove", $a8e101027d325e52$var$notscroll); }; var _dec2 = $f3Ts0$customElement("blueprint-renderer"); let $a8e101027d325e52$export$2dd7962ad25d4af2 = _class1 = _dec2((_class1 = (_class = class BlueprintRendererElement extends $f3Ts0$LitElement { constructor(){ super(); $f3Ts0$initializerDefineProperty(this, "src", _descriptor, this); $f3Ts0$initializerDefineProperty(this, "scrollDisabled", _descriptor1, this); this.graph = undefined; } async updated() { const data = await BlueprintRendererElement.readGraphCode(this.src).catch((err)=>console.error(err) ); console.debug(data); const g = this.shadowRoot.getElementById("graph"); const wrapper = this.shadowRoot.querySelector(".wrapper"); this.graph = new $f3Ts0$Graph(g, { size: { width: wrapper.clientWidth, height: wrapper.clientHeight } }); window.addEventListener("resize", ()=>{ if (this.graph !== undefined) { this.graph.stage.width(wrapper.clientWidth); this.graph.stage.height(wrapper.clientHeight); } }); console.log(this.scrollDisabled); } static async readGraphCode(url) { const res = await fetch(url, { headers: { "Content-Type": "text/plain" } }); try { if (!res.ok) { console.error("response.ok:", res.ok); console.error("response.status:", res.status); console.error("response.statusText:", res.statusText); throw new Error(res.statusText); } } catch (error) { console.error(error); } return await res.text(); } render() { return $f3Ts0$html` <div @mouseenter="${this.scrollDisabled ? $a8e101027d325e52$var$disable : ()=>{ }}" @mouseleave="${$a8e101027d325e52$var$enable}" class="wrapper" > <div id="graph"></div> </div>`; } }, _class.styles = $f3Ts0$css` .wrapper { inline-size: 100%; block-size: 100%; } div { border-radius: inherit; } canvas { border-radius: inherit; } `, _class), _dec = $f3Ts0$property({ attribute: true, reflect: true, type: String }), _dec1 = $f3Ts0$property({ attribute: "scroll-disabled", reflect: true, type: Boolean }), _descriptor = $f3Ts0$applyDecoratedDescriptor(_class1.prototype, "src", [ _dec ], { configurable: true, enumerable: true, writable: true, initializer: function() { return ""; } }), _descriptor1 = $f3Ts0$applyDecoratedDescriptor(_class1.prototype, "scrollDisabled", [ _dec1 ], { configurable: true, enumerable: true, writable: true, initializer: function() { return false; } }), _class1)) || _class1; export {$a8e101027d325e52$export$2dd7962ad25d4af2 as BlueprintRendererElement}; //# sourceMappingURL=module.js.map