Skip to content

Commit

Permalink
fix: copy global styles
Browse files Browse the repository at this point in the history
  • Loading branch information
infodusha committed Jul 28, 2024
1 parent 0b7ee2d commit baf3d25
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 2 additions & 6 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<meta charset="UTF-8" />
<title>define-html</title>
<link rel="stylesheet" href="style.css" type="text/css" />

<link
rel="preload"
href="components/app-root.html"
Expand All @@ -21,11 +23,5 @@
</head>
<body>
<app-root></app-root>

<style>
body {
margin: 4%;
}
</style>
</body>
</html>
2 changes: 1 addition & 1 deletion example/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
body {
margin: auto;
margin: 4%;
}
6 changes: 5 additions & 1 deletion src/css-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { cloneNode } from "./helpers.js";

const hostRe = /:host(\((.+)\))?/g;

export function getEncapsulatedCss(
Expand Down Expand Up @@ -38,5 +40,7 @@ export function appendCssLink(cssText: string): void {
export type GlobalStyle = HTMLStyleElement | HTMLLinkElement;

export function getGlobalStyles(): GlobalStyle[] {
return Array.from(document.querySelectorAll("style, link[rel='stylesheet']"));
return Array.from(
document.querySelectorAll<GlobalStyle>("style, link[rel='stylesheet']")
).map((el) => cloneNode(el));
}
2 changes: 1 addition & 1 deletion src/execute-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { returnIfDefined } from "./helpers.js";
const importRe =
/(?<=(?:[\s\n;])|^)(?:import[\s\n]*((?:(?<=[\s\n])type)?)(?=[\n\s\*\{])[\s\n]*)((?:(?:[_\$\w][_\$\w0-9]*)(?:[\s\n]+(?:as[\s\n]+(?:[_\$\w][_\$\w0-9]*)))?(?=(?:[\n\s]*,[\n\s]*[\{\*])|(?:[\n\s]+from)))?)[\s\n,]*((?:\*[\n\s]*(?:as[\s\n]+(?:[_\$\w][_\$\w0-9]*))(?=[\n\s]+from))?)[\s\n,]*((?:\{[n\s]*(?:(?:[_\$\w][_\$\w0-9]*)(?:[\s\n]+(?:as[\s\n]+(?:[_\$\w][_\$\w0-9]*)))?[\s\n]*,?[\s\n]*)*\}(?=[\n\s]*from))?)(?:[\s\n]*((?:from)?))[\s\n]*(?:["']([^"']*)(["']))[\s\n]*?;?/gm;

const scriptContextSymbolKey = "scriptContextSymbol";
const scriptContextSymbolKey = "define-html-script-context";
const scriptContextSymbol: unique symbol = Symbol.for(scriptContextSymbolKey);

declare global {
Expand Down

0 comments on commit baf3d25

Please sign in to comment.