mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-08-06 08:57:38 +00:00
34 lines
913 B
JavaScript
34 lines
913 B
JavaScript
/*
|
|
This file basically checks support for Anchor Positioning API in the browser,
|
|
and then loads the Oddbird polyfill if support is lacking.
|
|
*/
|
|
|
|
let polyfillPromise;
|
|
|
|
// look for `anchorName` in the computed styles
|
|
const supportsAnchorPositioning = ()=>'anchorName' in document.documentElement.style;
|
|
|
|
// wait for initial render
|
|
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;
|
|
}; |