@uniweb/runtime 1.2.9 → 1.2.10
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 +3 -3
- package/src/font-links.js +23 -0
- package/src/setup.js +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/runtime",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.10",
|
|
4
4
|
"description": "Minimal runtime for loading Uniweb foundations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"node": ">=22.12"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@uniweb/
|
|
40
|
-
"@uniweb/
|
|
39
|
+
"@uniweb/theming": "~1.2.1",
|
|
40
|
+
"@uniweb/core": "~1.4.11"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@vitejs/plugin-react": "^4.5.2",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FONT_LINKS_MARKER } from '@uniweb/theming'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Give a page the theme's font links when it arrived without them.
|
|
5
|
+
*
|
|
6
|
+
* A built page carries them in its `<head>` (`@uniweb/build`), and so does a prerendered
|
|
7
|
+
* one (`injectPageContent` in `ssr-renderer.js`). A host that serves the shell alone and
|
|
8
|
+
* leaves every page to the browser carries neither. `ensureThemeCss` computes the links
|
|
9
|
+
* onto the graph for such a lane, but nothing put them on the page: the browser added the
|
|
10
|
+
* theme's CSS (`ThemeProvider`) and never its fonts, so every family the theme imports
|
|
11
|
+
* fell back to a system face. This is the browser's half of the prerender's font block,
|
|
12
|
+
* deduped on the same marker, so a page that already has them is left alone.
|
|
13
|
+
*
|
|
14
|
+
* @param {object} themeData - `website.themeData`, with the `links` block `@uniweb/theming` generated
|
|
15
|
+
* @param {Document|null} [doc]
|
|
16
|
+
* @returns {boolean} whether it added them
|
|
17
|
+
*/
|
|
18
|
+
export function injectFontLinks(themeData, doc = typeof document === 'undefined' ? null : document) {
|
|
19
|
+
const head = doc?.head
|
|
20
|
+
if (!head || !themeData?.links || head.innerHTML.includes(FONT_LINKS_MARKER)) return false
|
|
21
|
+
head.insertAdjacentHTML('beforeend', `${FONT_LINKS_MARKER}\n${themeData.links}`)
|
|
22
|
+
return true
|
|
23
|
+
}
|
package/src/setup.js
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
import { ChildBlocks } from './components/PageRenderer.jsx'
|
|
32
32
|
import Background from './components/Background.jsx'
|
|
33
33
|
import { wireFoundationCapabilities, hydrateDataStore, ensureThemeCss } from './wire-foundation.js'
|
|
34
|
+
import { injectFontLinks } from './font-links.js'
|
|
34
35
|
import { navigateInApp } from './navigation.js'
|
|
35
36
|
|
|
36
37
|
// Re-export so existing consumers importing hydrateDataStore from
|
|
@@ -274,6 +275,9 @@ export function initUniweb({ content, foundation, extensions = [], routingCompon
|
|
|
274
275
|
if (typeof document === 'undefined' || !document.getElementById('uniweb-theme')) {
|
|
275
276
|
ensureThemeCss(uniweb, foundation)
|
|
276
277
|
}
|
|
278
|
+
// And the theme's font links, which the CSS alone does not bring: a page that came
|
|
279
|
+
// with neither would otherwise set every imported family in a system face.
|
|
280
|
+
injectFontLinks(uniweb.activeWebsite?.themeData)
|
|
277
281
|
|
|
278
282
|
uniweb.routingComponents = routingComponents
|
|
279
283
|
uniweb.localeSwitch = localeSwitch
|