@frak-labs/components
Version:
Frak Wallet components, helping any person to interact with the Frak wallet.
49 lines (48 loc) • 1.4 kB
JavaScript
import { r as lightDomBaseCss } from "./usePlacement-5kbU3BKj.js";
import { useEffect } from "preact/hooks";
//#region src/styles/styleManager.ts
function ensureStyle(id, css) {
const existing = document.getElementById(id);
if (existing) {
if (existing.textContent !== css) existing.textContent = css;
return;
}
const style = document.createElement("style");
style.id = id;
style.textContent = css;
document.head.appendChild(style);
}
function injectBase(tag, css) {
const id = `frak-base-${tag}`;
if (document.getElementById(id)) return;
if (!css) return;
const style = document.createElement("style");
style.id = id;
style.textContent = css;
document.head.appendChild(style);
}
function injectPlacement(tag, placementId, scopedCss) {
ensureStyle(`frak-placement-${tag}-${placementId}`, scopedCss);
}
const styleManager = {
injectBase,
injectPlacement
};
//#endregion
//#region src/hooks/useLightDomStyles.ts
function useLightDomStyles(tag, placementId, placementCss, baseCss, sharedBaseCss) {
useEffect(() => {
if (sharedBaseCss) styleManager.injectBase("shared", sharedBaseCss);
styleManager.injectBase(tag, baseCss ?? lightDomBaseCss);
}, [tag]);
useEffect(() => {
if (!placementId || !placementCss) return;
styleManager.injectPlacement(tag, placementId, placementCss);
}, [
tag,
placementId,
placementCss
]);
}
//#endregion
export { useLightDomStyles as t };