diff --git a/src/Ljbc1994.Blazor.IntersectionObserver/src/index.ts b/src/Ljbc1994.Blazor.IntersectionObserver/src/index.ts index d763b2c..55ab40c 100644 --- a/src/Ljbc1994.Blazor.IntersectionObserver/src/index.ts +++ b/src/Ljbc1994.Blazor.IntersectionObserver/src/index.ts @@ -189,6 +189,7 @@ export function remove(callbackId: string): boolean { */ function toEntryObject(entry: IntersectionObserverEntry) { function toRectReadOnlyObject(obj) { + if (!obj) return null; return { X: obj.x, Y: obj.y, diff --git a/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.js b/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.js index 51fe0f2..e934762 100644 --- a/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.js +++ b/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.js @@ -68,6 +68,8 @@ function remove(callbackId) { } function toEntryObject(entry) { function toRectReadOnlyObject(obj) { + if (!obj) + return null; return { X: obj.x, Y: obj.y, diff --git a/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.min.js b/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.min.js index cf2c7b9..8d82f59 100644 --- a/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.min.js +++ b/src/Ljbc1994.Blazor.IntersectionObserver/wwwroot/blazor-intersection-observer.min.js @@ -1 +1 @@ -const e="blazor_plugin_observer__";let t=1;const n=new Map;function o(){t=0,n.clear()}function r(){return n}function s(e,t,o){const r=function(e){return t=>{if(!n.has(e))return;const{dotnetRef:o}=n.get(e),r=t.map((e=>function(e){function t(e){return{X:e.x,Y:e.y,Width:e.width,Height:e.height,Top:e.top,Left:e.left,Bottom:e.bottom,Right:e.right}}return{IsIntersecting:e.isIntersecting,IntersectionRatio:e.intersectionRatio,Time:e.time,BoundingClientRect:t(e.boundingClientRect),IntersectionRect:t(e.intersectionRect),RootBounds:t(e.rootBounds)}}(e)));o.invokeMethodAsync("OnCallback",e,r)}}(t),s=new IntersectionObserver(r,o);return n.set(t,{dotnetRef:e,observer:s,elements:[]}),n.get(t)}function i(e,o){const r=n.get(e);if(null==r)throw new Error(`Failed to observe element for key: ${e} as the observer does not exist`);if(r.elements.some((e=>e.element==o)))return console.warn(`BlazorIntersectionObserver: The element is already being observed by observer for key ${e}`),"";const s="blazor_plugin_observer__"+t++;return r.observer.observe(o),r.elements.push({elementId:s,element:o}),s}function l(e,t,n){return s(e,t,n)}function c(e,t,n,o){return s(e,t,o),i(t,n)}function u(e,t){var o;const r=n.get(e);if(null==r)throw new Error(`Failed to unobserve element for key: ${e} as the observer does not exist`);const s=null===(o=r.elements.find((e=>e.element==t)))||void 0===o?void 0:o.elementId;return null==s&&console.warn(`BlazorIntersectionObserver: The record does not exist for observer: ${e}`),r.observer.unobserve(t),r.elements=r.elements.filter((e=>e.element!=t)),s}function f(e){const t=n.get(e);if(null==t)throw new Error(`Failed to disconnect for key: ${e} as the observer does not exist`);return t.observer.disconnect(),t.elements=[],!0}function d(e){if(f(e))return n.delete(e)}export{e as OBSERVER_ID_PREFIX,l as create,f as disconnect,r as getObserverItems,c as observe,i as observeElement,d as remove,o as reset,u as unobserve}; +const e="blazor_plugin_observer__";let t=1;const n=new Map;function o(){t=0,n.clear()}function r(){return n}function s(e,t,o){const r=function(e){return t=>{if(!n.has(e))return;const{dotnetRef:o}=n.get(e),r=t.map((e=>{const t=function(e){function t(e){return e?{X:e.x,Y:e.y,Width:e.width,Height:e.height,Top:e.top,Left:e.left,Bottom:e.bottom,Right:e.right}:null}return{IsIntersecting:e.isIntersecting,IntersectionRatio:e.intersectionRatio,Time:e.time,BoundingClientRect:t(e.boundingClientRect),IntersectionRect:t(e.intersectionRect),RootBounds:t(e.rootBounds)}}(e);return t}));o.invokeMethodAsync("OnCallback",e,r)}}(t),s=new IntersectionObserver(r,o);return n.set(t,{dotnetRef:e,observer:s,elements:[]}),n.get(t)}function i(e,o){const r=n.get(e);if(null==r)throw new Error(`Failed to observe element for key: ${e} as the observer does not exist`);if(r.elements.some((e=>e.element==o)))return console.warn(`BlazorIntersectionObserver: The element is already being observed by observer for key ${e}`),"";const s="blazor_plugin_observer__"+t++;return r.observer.observe(o),r.elements.push({elementId:s,element:o}),s}function l(e,t,n){return s(e,t,n)}function c(e,t,n,o){return s(e,t,o),i(t,n)}function u(e,t){var o;const r=n.get(e);if(null==r)throw new Error(`Failed to unobserve element for key: ${e} as the observer does not exist`);const s=null===(o=r.elements.find((e=>e.element==t)))||void 0===o?void 0:o.elementId;return null==s&&console.warn(`BlazorIntersectionObserver: The record does not exist for observer: ${e}`),r.observer.unobserve(t),r.elements=r.elements.filter((e=>e.element!=t)),s}function f(e){const t=n.get(e);if(null==t)throw new Error(`Failed to disconnect for key: ${e} as the observer does not exist`);return t.observer.disconnect(),t.elements=[],!0}function d(e){if(f(e))return n.delete(e)}export{e as OBSERVER_ID_PREFIX,l as create,f as disconnect,r as getObserverItems,c as observe,i as observeElement,d as remove,o as reset,u as unobserve};