diff --git a/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs b/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs index b3a21929..4234a13a 100644 --- a/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs +++ b/src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs @@ -68,7 +68,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) if (firstRender) { - _module ??= await JSRuntime.InvokeAsync("import","./_content/Z.Blazor.Diagrams/script.js"); + _module ??= await JSRuntime.InvokeAsync("import","./_content/Z.Blazor.Diagrams/script.min.js"); BlazorDiagram.SetContainer(await _module.GetBoundingClientRect(elementReference)); await _module.ObserveResizes(elementReference, _reference!); diff --git a/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs b/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs index 4ba55a42..153f38d7 100644 --- a/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs +++ b/src/Blazor.Diagrams/Components/Renderers/NodeRenderer.cs @@ -139,7 +139,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { - _module ??= await JsRuntime.InvokeAsync("import", "./_content/Z.Blazor.Diagrams/script.js"); + _module ??= await JsRuntime.InvokeAsync("import", "./_content/Z.Blazor.Diagrams/script.min.js"); } if (firstRender || _becameVisible) diff --git a/src/Blazor.Diagrams/Components/Renderers/PortRenderer.cs b/src/Blazor.Diagrams/Components/Renderers/PortRenderer.cs index db510dd0..1687fca0 100644 --- a/src/Blazor.Diagrams/Components/Renderers/PortRenderer.cs +++ b/src/Blazor.Diagrams/Components/Renderers/PortRenderer.cs @@ -85,7 +85,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { - _module ??= await JSRuntime.InvokeAsync("import", "./_content/Z.Blazor.Diagrams/script.js"); + _module ??= await JSRuntime.InvokeAsync("import", "./_content/Z.Blazor.Diagrams/script.min.js"); } if (!Port.Initialized) { @@ -131,7 +131,7 @@ private async Task UpdateDimensions() var zoom = BlazorDiagram.Zoom; var pan = BlazorDiagram.Pan; - _module ??= await JSRuntime.InvokeAsync("import", "./_content/Z.Blazor.Diagrams/script.js"); + _module ??= await JSRuntime.InvokeAsync("import", "./_content/Z.Blazor.Diagrams/script.min.js"); var rect = await _module.GetBoundingClientRect(_element); Port.Size = new Size(rect.Width / zoom, rect.Height / zoom); diff --git a/src/Blazor.Diagrams/wwwroot/script.min.js b/src/Blazor.Diagrams/wwwroot/script.min.js new file mode 100644 index 00000000..86cd3dd4 --- /dev/null +++ b/src/Blazor.Diagrams/wwwroot/script.min.js @@ -0,0 +1 @@ +let boundListener={},isObservingResize=!1;const mo=new MutationObserver(()=>{for(const id in boundListener){const canvas=boundListener[id],lastBounds=canvas.lastBounds,bounds=canvas.elem.getBoundingClientRect();lastBounds.left!==bounds.left||lastBounds.top!==bounds.top||lastBounds.width!==bounds.width||lastBounds.height!==bounds.height&&updateBounds(canvas)}}}),ro=new ResizeObserver(entries=>{for(const entry of entries){let id=Array.from(entry.target.attributes).find(e=>"name"===e.name.substring(0,4)).name.substring(4),element=boundListener[id];element&&updateBounds(element)}});export function getBoundingClientRect(el){return el.getBoundingClientRect()}function updateBounds(canvas){canvas.lastBounds=canvas.elem.getBoundingClientRect(),canvas.ref.invokeMethodAsync("OnResize",canvas.lastBounds)}export function observe(element,ref,id){if(!1===isObservingResize&&(mo.observe(document.body,{childList:!0,subtree:!0}),window.addEventListener("scroll",()=>{for(id in boundListener){const canvas=boundListener[id];updateBounds(canvas)}}),isObservingResize=!0),element){ro.observe(element);const lastBounds=element.getBoundingClientRect();boundListener[id]={elem:element,ref:ref,lastBounds}}export function unobserve(element,id){element&&ro.unobserve(element),delete boundListener[id]}