blueprint-renderer-webcomponents
Version:
1 lines • 2.98 kB
Source Map (JSON)
{"mappings":";AAiBA,qCACsC,SAAQ,UAAU;IAEtD,GAAG,SAAM;IAGT,cAAc,UAAS;;IASjB,OAAO;IAyCb,MAAM,CAAC,MAAM,0BAWX;IAEF,MAAM;CASP","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"import { LitElement, html, css } from \"lit\";\nimport { customElement, property } from \"lit/decorators\";\nimport { Graph } from \"blueprint-renderer\";\n\nfunction notscroll(e: any) {\n e.preventDefault();\n}\n\nconst disable = () => {\n document.addEventListener(\"wheel\", notscroll, { passive: false });\n document.addEventListener(\"touchmove\", notscroll, { passive: false });\n};\nconst enable = () => {\n document.removeEventListener(\"wheel\", notscroll);\n document.removeEventListener(\"touchmove\", notscroll);\n};\n\n@customElement(\"blueprint-renderer\")\nexport class BlueprintRendererElement extends LitElement {\n @property({ attribute: true, reflect: true, type: String })\n src = \"\";\n\n @property({ attribute: \"scroll-disabled\", reflect: true, type: Boolean })\n scrollDisabled = false;\n\n private graph: Graph | undefined;\n\n constructor() {\n super();\n this.graph = undefined;\n }\n\n async updated() {\n const data = await BlueprintRendererElement.readGraphCode(this.src).catch(\n (err) => console.error(err)\n );\n console.debug(data);\n const g = this.shadowRoot!.getElementById(\"graph\") as HTMLDivElement;\n const wrapper = this.shadowRoot!.querySelector(\n \".wrapper\"\n ) as HTMLDivElement;\n this.graph = new Graph(g, {\n size: {\n width: wrapper.clientWidth,\n height: wrapper.clientHeight,\n },\n });\n window.addEventListener(\"resize\", () => {\n if (this.graph !== undefined) {\n this.graph.stage.width(wrapper.clientWidth);\n this.graph.stage.height(wrapper.clientHeight);\n }\n });\n console.log(this.scrollDisabled);\n }\n\n private static async readGraphCode(url: string) {\n const res = await fetch(url, {\n headers: { \"Content-Type\": \"text/plain\" },\n });\n try {\n if (!res.ok) {\n console.error(\"response.ok:\", res.ok);\n console.error(\"response.status:\", res.status);\n console.error(\"response.statusText:\", res.statusText);\n throw new Error(res.statusText);\n }\n } catch (error) {\n console.error(error);\n }\n return await res.text();\n }\n\n static styles = css`\n .wrapper {\n inline-size: 100%;\n block-size: 100%;\n }\n div {\n border-radius: inherit;\n }\n canvas {\n border-radius: inherit;\n }\n `;\n\n render() {\n return html` <div\n @mouseenter=\"${this.scrollDisabled ? disable : () => {}}\"\n @mouseleave=\"${enable}\"\n class=\"wrapper\"\n >\n <div id=\"graph\"></div>\n </div>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"blueprint-renderer\": BlueprintRendererElement;\n }\n}\n"],"names":[],"version":3,"file":"types.d.ts.map"}