update
This commit is contained in:
23
app/util.ts
23
app/util.ts
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user