mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-08 21:15:18 +09:00
34 lines
1002 B
TypeScript
34 lines
1002 B
TypeScript
import {
|
|
insertCriticalCss as insert,
|
|
getCssText as getCanvasCssText,
|
|
} from "@webstudio-is/sdk";
|
|
import { getCssText as getDesignerCssText } from "~/shared/design-system";
|
|
import config from "./config";
|
|
|
|
const getCssTextFunctions = {
|
|
[config.previewPath]: getCanvasCssText,
|
|
[config.canvasPath]: getCanvasCssText,
|
|
[config.designerPath]: getDesignerCssText,
|
|
[config.dashboardPath]: getDesignerCssText,
|
|
};
|
|
|
|
const getCssTextFunction = (url: string) => {
|
|
const { pathname } = new URL(url);
|
|
let path: keyof typeof getCssTextFunctions;
|
|
for (path in getCssTextFunctions) {
|
|
if (pathname.indexOf(path) === 0) {
|
|
return getCssTextFunctions[path];
|
|
}
|
|
}
|
|
return getCanvasCssText;
|
|
};
|
|
|
|
/**
|
|
* This works around the problem with getCssTextfunction being a different one
|
|
* depending on createStitches() used in each outlet.
|
|
* @todo find a better way
|
|
*/
|
|
export const insertCriticalCss = (markup: string, url: string): string => {
|
|
return insert(markup, getCssTextFunction(url));
|
|
};
|