Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
{
"version": 3,
"sources": ["../../../src/delegate/ResizeHandler.ts"],
"sourcesContent": ["import { instanceOfUI5Element } from \"../UI5Element.js\";\n\ntype ResizeObserverCallback = () => Promise | void;\n\nlet resizeObserver: ResizeObserver;\nconst observedElements = new Map>();\n\nconst getResizeObserver = () => {\n\tif (!resizeObserver) {\n\t\tresizeObserver = new window.ResizeObserver(entries => {\n\t\t\twindow.requestAnimationFrame(() => {\n\t\t\t\tentries.forEach(entry => {\n\t\t\t\t\tconst callbacks = observedElements.get(entry.target as HTMLElement);\n\t\t\t\t\t// Callbacks could be async and we need to handle returned promises to comply with the eslint \"no-misused-promises\" rule.\n\t\t\t\t\t// Although Promise.all awaits all, we don't await the additional task after calling the callbacks and should not make any difference.\n\t\t\t\t\tcallbacks && Promise.all(callbacks.map((callback: ResizeObserverCallback) => callback()));\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\treturn resizeObserver;\n};\n\nconst observe = (element: HTMLElement, callback: ResizeObserverCallback) => {\n\tconst callbacks = observedElements.get(element) || [];\n\n\t// if no callbacks have been added for this element - start observing it\n\tif (!callbacks.length) {\n\t\tgetResizeObserver().observe(element);\n\t}\n\n\t// save the callbacks in an array\n\tobservedElements.set(element, [...callbacks, callback]);\n};\n\nconst unobserve = (element: HTMLElement, callback: ResizeObserverCallback) => {\n\tconst callbacks = observedElements.get(element) || [];\n\tif (callbacks.length === 0) {\n\t\treturn;\n\t}\n\n\tconst filteredCallbacks = callbacks.filter((fn: ResizeObserverCallback) => fn !== callback);\n\tif (filteredCallbacks.length === 0) {\n\t\tgetResizeObserver().unobserve(element);\n\t\tobservedElements.delete(element);\n\t} else {\n\t\tobservedElements.set(element, filteredCallbacks);\n\t}\n};\n\n/**\n * Allows to register/deregister resize observers for a DOM element\n *\n * @public\n * @class\n */\nclass ResizeHandler {\n\t/**\n\t * @public\n\t * @param element UI5 Web Component or DOM Element to be observed\n\t * @param callback Callback to be executed\n\t */\n\tstatic register(element: HTMLElement, callback: ResizeObserverCallback): void {\n\t\tlet effectiveElement: HTMLElement | undefined = element;\n\n\t\tif (instanceOfUI5Element(effectiveElement)) {\n\t\t\teffectiveElement = effectiveElement.getDomRef();\n\t\t}\n\n\t\tif (effectiveElement instanceof HTMLElement) {\n\t\t\tobserve(effectiveElement, callback);\n\t\t} else {\n\t\t\tconsole.warn(\"Cannot register ResizeHandler for element\", element); // eslint-disable-line\n\t\t}\n\t}\n\n\t/**\n\t * @public\n\t * @param element UI5 Web Component or DOM Element to be unobserved\n\t * @param callback Callback to be removed\n\t */\n\tstatic deregister(element: HTMLElement, callback: ResizeObserverCallback): void {\n\t\tlet effectiveElement: HTMLElement | undefined = element;\n\n\t\tif (instanceOfUI5Element(effectiveElement)) {\n\t\t\teffectiveElement = effectiveElement.getDomRef();\n\t\t}\n\n\t\tif (effectiveElement instanceof HTMLElement) {\n\t\t\tunobserve(effectiveElement, callback);\n\t\t} else {\n\t\t\tconsole.warn(\"Cannot deregister ResizeHandler for element\", element); // eslint-disable-line\n\t\t}\n\t}\n}\n\nexport default ResizeHandler;\nexport type {\n\tResizeObserverCallback,\n};\n"],
"mappings": "aAAA,OAAS,wBAAAA,MAA4B,mBAIrC,IAAIC,EACJ,MAAMC,EAAmB,IAAI,IAEvBC,EAAoB,KACpBF,IACJA,EAAiB,IAAI,OAAO,eAAeG,GAAW,CACrD,OAAO,sBAAsB,IAAM,CAClCA,EAAQ,QAAQC,GAAS,CACxB,MAAMC,EAAYJ,EAAiB,IAAIG,EAAM,MAAqB,EAGlEC,GAAa,QAAQ,IAAIA,EAAU,IAAKC,GAAqCA,EAAS,CAAC,CAAC,CACzF,CAAC,CACF,CAAC,CACF,CAAC,GAEKN,GAGFO,EAAU,CAACC,EAAsBF,IAAqC,CAC3E,MAAMD,EAAYJ,EAAiB,IAAIO,CAAO,GAAK,CAAC,EAG/CH,EAAU,QACdH,EAAkB,EAAE,QAAQM,CAAO,EAIpCP,EAAiB,IAAIO,EAAS,CAAC,GAAGH,EAAWC,CAAQ,CAAC,CACvD,EAEMG,EAAY,CAACD,EAAsBF,IAAqC,CAC7E,MAAMD,EAAYJ,EAAiB,IAAIO,CAAO,GAAK,CAAC,EACpD,GAAIH,EAAU,SAAW,EACxB,OAGD,MAAMK,EAAoBL,EAAU,OAAQM,GAA+BA,IAAOL,CAAQ,EACtFI,EAAkB,SAAW,GAChCR,EAAkB,EAAE,UAAUM,CAAO,EACrCP,EAAiB,OAAOO,CAAO,GAE/BP,EAAiB,IAAIO,EAASE,CAAiB,CAEjD,EAQA,MAAME,CAAc,CAMnB,OAAO,SAASJ,EAAsBF,EAAwC,CAC7E,IAAIO,EAA4CL,EAE5CT,EAAqBc,CAAgB,IACxCA,EAAmBA,EAAiB,UAAU,GAG3CA,aAA4B,YAC/BN,EAAQM,EAAkBP,CAAQ,EAElC,QAAQ,KAAK,4CAA6CE,CAAO,CAEnE,CAOA,OAAO,WAAWA,EAAsBF,EAAwC,CAC/E,IAAIO,EAA4CL,EAE5CT,EAAqBc,CAAgB,IACxCA,EAAmBA,EAAiB,UAAU,GAG3CA,aAA4B,YAC/BJ,EAAUI,EAAkBP,CAAQ,EAEpC,QAAQ,KAAK,8CAA+CE,CAAO,CAErE,CACD,CAEA,eAAeI",
"names": ["instanceOfUI5Element", "resizeObserver", "observedElements", "getResizeObserver", "entries", "entry", "callbacks", "callback", "observe", "element", "unobserve", "filteredCallbacks", "fn", "ResizeHandler", "effectiveElement"]
}