bookish-press 0.5.22 → 0.5.24
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.
|
@@ -29,6 +29,8 @@ $: {
|
|
|
29
29
|
// Set the theme, whatever it is, and change it when the edition changes
|
|
30
30
|
setTheme(edition.getTheme() ?? BookishTheme);
|
|
31
31
|
}
|
|
32
|
+
// The CSS to set on the edition.
|
|
33
|
+
let themeCSS;
|
|
32
34
|
// Set the theme on mount.
|
|
33
35
|
onMount(() => {
|
|
34
36
|
setTheme(edition.getTheme() ?? BookishTheme);
|
|
@@ -36,74 +38,25 @@ onMount(() => {
|
|
|
36
38
|
// Redirect old hash routes by simply replacing their hash before routing.
|
|
37
39
|
if (typeof window !== 'undefined' && window.location.hash.startsWith('#/'))
|
|
38
40
|
goto(location.hash.replace('#', ''));
|
|
39
|
-
/** Given a theme, sets the appropriate CSS rules in the browser to apply the theme
|
|
41
|
+
/** Given a theme, sets the appropriate CSS rules in the browser to apply the theme. */
|
|
40
42
|
function setTheme(theme) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// If the imports changed, update theme.
|
|
59
|
-
if (themeTagImportsValue !== newThemeTagImportsValue) {
|
|
60
|
-
// If it's being set, create a new style tag.
|
|
61
|
-
const newThemeImportsTag = document.createElement('style');
|
|
62
|
-
// Give it an ID so we can remove it later.
|
|
63
|
-
newThemeImportsTag.setAttribute('id', 'bookish-theme-imports');
|
|
64
|
-
newThemeImportsTag.dataset.imports = newThemeTagImportsValue;
|
|
65
|
-
// Insert any import statements, then any rules.
|
|
66
|
-
const css = `${(theme.imports ?? [])
|
|
67
|
-
.map((url) => `@import url(${url});`)
|
|
68
|
-
.join('\n')}`;
|
|
69
|
-
newThemeImportsTag.appendChild(document.createTextNode(css));
|
|
70
|
-
document.head.appendChild(newThemeImportsTag);
|
|
71
|
-
// Remove the old tag
|
|
72
|
-
themeTagImports?.remove();
|
|
73
|
-
}
|
|
74
|
-
// If the rules changed, update them.
|
|
75
|
-
if (themeTagCSSValue !== newThemeTagCSSValue) {
|
|
76
|
-
// If it's being set, create a new style tag.
|
|
77
|
-
const newThemeCSSTag = document.createElement('style');
|
|
78
|
-
// Give it an ID so we can remove it later.
|
|
79
|
-
newThemeCSSTag.setAttribute('id', 'bookish-theme');
|
|
80
|
-
newThemeCSSTag.dataset.css = newThemeTagCSSValue;
|
|
81
|
-
// Insert any import statements, then any rules.
|
|
82
|
-
const css = `
|
|
83
|
-
${(theme.imports ?? [])
|
|
84
|
-
.map((url) => `@import url(${url});`)
|
|
85
|
-
.join('\n')}
|
|
86
|
-
.bookish {
|
|
87
|
-
${theme.light ? toRules(theme.light) : ''}
|
|
88
|
-
${theme.fonts ? toRules(theme.fonts) : ''}
|
|
89
|
-
${theme.sizes ? toRules(theme.sizes) : ''}
|
|
90
|
-
${theme.weights ? toRules(theme.weights) : ''}
|
|
91
|
-
${theme.spacing ? toRules(theme.spacing) : ''}
|
|
92
|
-
}
|
|
93
|
-
.dark {
|
|
94
|
-
${theme.dark ? toRules(theme.dark) : ''}
|
|
95
|
-
}`;
|
|
96
|
-
newThemeCSSTag.appendChild(document.createTextNode(css));
|
|
97
|
-
document.head.appendChild(newThemeCSSTag);
|
|
98
|
-
// Remove the old tag
|
|
99
|
-
themeTagCSS?.remove();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
// Remove the old tags, unsetting the theme.
|
|
104
|
-
themeTagImports?.remove();
|
|
105
|
-
themeTagCSS?.remove();
|
|
106
|
-
}
|
|
43
|
+
if (theme === null)
|
|
44
|
+
theme = BookishTheme;
|
|
45
|
+
themeCSS = `
|
|
46
|
+
${(theme.imports ?? [])
|
|
47
|
+
.map((url) => `@import url(${url});`)
|
|
48
|
+
.join('\n')}
|
|
49
|
+
.bookish {
|
|
50
|
+
${theme.light ? toRules(theme.light) : ''}
|
|
51
|
+
${theme.fonts ? toRules(theme.fonts) : ''}
|
|
52
|
+
${theme.sizes ? toRules(theme.sizes) : ''}
|
|
53
|
+
${theme.weights ? toRules(theme.weights) : ''}
|
|
54
|
+
${theme.spacing ? toRules(theme.spacing) : ''}
|
|
55
|
+
}
|
|
56
|
+
.dark {
|
|
57
|
+
${theme.dark ? toRules(theme.dark) : ''}
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
107
60
|
}
|
|
108
61
|
function toRules(set) {
|
|
109
62
|
return Object.keys(set)
|
|
@@ -124,7 +77,12 @@ function toRules(set) {
|
|
|
124
77
|
}
|
|
125
78
|
</script>
|
|
126
79
|
|
|
127
|
-
|
|
80
|
+
<!-- Keep the imports up to date -->
|
|
81
|
+
<svelte:head>
|
|
82
|
+
{@html '<' + `style>${themeCSS}</style>`}
|
|
83
|
+
</svelte:head>
|
|
84
|
+
|
|
85
|
+
<main class="bookish {$darkMode ? ' dark' : ''}" style={themeCSS}>
|
|
128
86
|
<slot />
|
|
129
87
|
</main>
|
|
130
88
|
|