This commit is contained in:
Daniel Ledda
2024-11-01 21:29:13 +01:00
parent 64640300dd
commit 20479958bd
17 changed files with 224 additions and 96 deletions

View File

@@ -1,3 +1,6 @@
import { type InjectionKey, inject } from 'vue';
import useDJSSRContext from "@/useDJSSRContext.ts";
export function gid(id: string, doc: (Document | ShadowRoot) | undefined) {
return ((doc ?? document).getElementById(id));
}
@@ -37,9 +40,23 @@ export function css(strs: TemplateStringsArray, ...vals: string[]) {
for (let i = 1; i < strs.length; i++) {
result += vals[i] + strs[i];
}
const sheet = new CSSStyleSheet();
sheet.replaceSync(result);
return sheet;
return result;
}
export const cssRegistry = Symbol('css-registry') as InjectionKey<Set<string>>;
export function addCSS(key: string, css: string) {
const context = useDJSSRContext();
if (context && !context.styles[key]) {
context.styles[key] = css;
} else {
const registry = inject(cssRegistry);
if (!registry?.has(key)) {
const stylesheet = new CSSStyleSheet();
stylesheet.replace(css);
document.adoptedStyleSheets.push(stylesheet);
}
}
}
/*