0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-08-06 11:07:37 +00:00
Files
homebrewery/client/components/anchorPositioningPolyfill.js
T
2026-04-25 23:32:48 -05:00

27 lines
693 B
JavaScript

let polyfillPromise;
const supportsAnchorPositioning = ()=>'anchorName' in document.documentElement.style;
const afterInitialRender = ()=>new Promise((resolve)=>{
requestAnimationFrame(()=>{
requestAnimationFrame(resolve);
});
});
export const bootstrapAnchorPositioningPolyfill = ()=>{
if(supportsAnchorPositioning()) return Promise.resolve(false);
if(polyfillPromise) return polyfillPromise;
polyfillPromise = afterInitialRender()
.then(async ()=>{
const { default: polyfill } = await import('@oddbird/css-anchor-positioning/fn');
await polyfill();
return true;
})
.catch((error)=>{
polyfillPromise = undefined;
throw error;
});
return polyfillPromise;
};