@master/internal-site 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -11,19 +11,29 @@ export interface PropagatedModule<T> {
|
|
|
11
11
|
collectedStyles: (string | { id: string, content: string })[]
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
export interface PageStyle {
|
|
15
|
+
/** The dev-time Vite module id. Hydrated islands that import the same CSS update this element in place. */
|
|
16
|
+
id?: string
|
|
17
|
+
content: string
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
export interface PageAssets {
|
|
15
21
|
links: string[]
|
|
16
|
-
styles:
|
|
22
|
+
styles: PageStyle[]
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export const propagatedAssetsQuery = '?astroPropagatedAssets'
|
|
20
26
|
|
|
21
27
|
export function mergeAssets(...modules: PropagatedModule<unknown>[]): PageAssets {
|
|
22
28
|
const links = new Set<string>()
|
|
23
|
-
const styles = new
|
|
29
|
+
const styles = new Map<string, PageStyle>()
|
|
24
30
|
for (const module of modules) {
|
|
25
31
|
module.collectedLinks.forEach((link) => links.add(link))
|
|
26
|
-
|
|
32
|
+
for (const style of module.collectedStyles) {
|
|
33
|
+
const record: PageStyle = typeof style === 'string' ? { content: style } : style
|
|
34
|
+
const key = record.id ?? record.content
|
|
35
|
+
if (!styles.has(key)) styles.set(key, record)
|
|
36
|
+
}
|
|
27
37
|
}
|
|
28
|
-
return { links: [...links], styles: [...styles] }
|
|
38
|
+
return { links: [...links], styles: [...styles.values()] }
|
|
29
39
|
}
|
|
@@ -56,7 +56,8 @@ if (['dark', 'light'].includes(value)) document.documentElement.style.colorSchem
|
|
|
56
56
|
Their request-local context must already exist, even with cached CSS/JS. */}
|
|
57
57
|
<script is:inline type="application/json" id={siteContextElementId} set:html={siteContextJSON}></script>
|
|
58
58
|
{assets.links.map((href) => <link rel="stylesheet" href={href} />)}
|
|
59
|
-
{
|
|
59
|
+
{/* Without the dev id, Vite appends a second copy when an island imports the same CSS, reordering the cascade. */}
|
|
60
|
+
{assets.styles.map(({ id, content }) => <style is:inline data-vite-dev-id={id} set:html={content}></style>)}
|
|
60
61
|
<title>{head.title}</title>
|
|
61
62
|
{config.feeds?.map(feed => <link rel="alternate" type={feed.type} title={feed.title} href={new URL(feed.href, config.origin).href} />)}
|
|
62
63
|
{head.tags.map(({ tag: Tag, attributes }) => <Tag {...attributes} />)}
|