domma-cms 1.16.2 → 1.18.0

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/admin/js/lib/admin-theme.js +1 -1
  3. package/admin/js/lib/editor-type.js +1 -1
  4. package/admin/js/lib/effects-builder.js +1 -1
  5. package/admin/js/lib/menu-editor-arrange.js +2 -2
  6. package/admin/js/lib/scribe-composer.js +1 -1
  7. package/admin/js/lib/scribe-model.js +1 -1
  8. package/admin/js/lib/shortcode-preview.js +1 -1
  9. package/admin/js/lib/shortcode-registry.js +3 -3
  10. package/admin/js/lib/theme-settings-arrange.js +1 -1
  11. package/admin/js/templates/docs/usage-navigation.html +7 -0
  12. package/admin/js/templates/menu-editor.html +9 -0
  13. package/admin/js/templates/theme.html +64 -1
  14. package/admin/js/views/menu-editor.js +10 -10
  15. package/admin/js/views/page-editor.js +9 -9
  16. package/docs/DommaFeatures.md +2 -2
  17. package/docs/screenshots/editor-font-families-mobile.png +0 -0
  18. package/docs/screenshots/theme-font-families.png +0 -0
  19. package/docs/typography.md +44 -0
  20. package/package.json +1 -1
  21. package/plugins/_lib/admin/mail/fonts.js +5 -0
  22. package/public/css/menu-cards.css +1 -1
  23. package/public/js/effects.js +1 -1
  24. package/public/js/font-families.mjs +1 -0
  25. package/public/js/menu-cards.mjs +4 -4
  26. package/public/js/menu-look.mjs +1 -1
  27. package/public/js/scribe-style.mjs +1 -1
  28. package/public/js/site.js +1 -1
  29. package/public/js/text-style.mjs +1 -1
  30. package/server/routes/api/theme.js +2 -1
  31. package/server/services/menus.js +1 -1
  32. package/server/services/renderer.js +41 -54
  33. package/server/services/themeSettings.js +7 -0
  34. package/server/templates/page.html +3 -3
@@ -21,6 +21,8 @@ import {isToolEnabled} from './tools.js';
21
21
  import {consentSettingsFor, measurementIdOf} from './googleAnalytics.js';
22
22
  import {fmtDateTime} from './dates.js';
23
23
  import {cssClasses} from '../../public/js/css-classes.mjs';
24
+ import {fontFamilyValue, fontStylesheetHref, isFontStylesheet} from '../../public/js/font-families.mjs';
25
+ import {CMS_WEB_FONTS} from '../../public/js/text-style.mjs';
24
26
  import {parseMarkdown} from './markdown.js';
25
27
 
26
28
  const VALID_LAYOUT_WIDTHS = new Set(['narrow', 'normal', 'wide', 'full']);
@@ -477,9 +479,10 @@ export async function renderPage(page, opts = {}) {
477
479
  html: `${page.html || ''}${overlayMenus}${footerBlocksHtml}`,
478
480
  menus: [navItemsDecorated, footerPrimaryDecorated, footerLegalDecorated]
479
481
  });
480
- const {fontLink, fontStyleTag, autoTheme, activeTheme, dommaTheme, customThemeClass} = themeView;
482
+ const {fontStyleTag, autoTheme, activeTheme, dommaTheme, customThemeClass} = themeView;
483
+ const fontLink = contentFontLinks(`${page.html || ''}${overlayMenus}${footerBlocksHtml}`, themeView.fontLink);
481
484
 
482
- const {navbarFontLink, navbarStyleTag} = buildNavbarStyleTag(navigation);
485
+ const {navbarFontLink, navbarStyleTag} = buildNavbarStyleTag(navigation, themeView.cfg.font);
483
486
 
484
487
  const customCssTag = customCss.trim()
485
488
  ? `<style>${customCss.replace(/<\/style>/gi, '<\\/style>')}</style>`
@@ -1028,7 +1031,7 @@ function railBodyClass(navigation) {
1028
1031
  ].filter(Boolean).join(' ');
1029
1032
  }
1030
1033
 
1031
- function buildNavbarStyleTag(nav) {
1034
+ function buildNavbarStyleTag(nav, font = {}) {
1032
1035
  const s = nav?.style || {};
1033
1036
  // A docked rail's width is a token the rail and the body's gutter both read.
1034
1037
  const railWidth = nav?.orientation === 'vertical' && Number.isFinite(nav?.dock?.width)
@@ -1036,11 +1039,8 @@ function buildNavbarStyleTag(nav) {
1036
1039
  if (!s.fontFamily && !s.fontSize && !s.fontWeight && !s.letterSpacing && !s.iconSize) {
1037
1040
  return {navbarFontLink: '', navbarStyleTag: railWidth ? `<style>${railWidth}</style>` : ''};
1038
1041
  }
1039
- let navbarFontLink = '';
1040
- if (s.fontFamily && s.fontFamily !== 'system-ui' && s.fontFamily !== 'inherit') {
1041
- const encoded = s.fontFamily.replace(/ /g, '+');
1042
- navbarFontLink = `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=${encoded}:wght@300;400;500;600;700&display=swap">`;
1043
- }
1042
+ const navbarHref = fontStylesheetHref(s.fontFamily, {...font, navbar: true});
1043
+ const navbarFontLink = navbarHref ? `<link rel="stylesheet" href="${escapeHtml(navbarHref)}">` : '';
1044
1044
  const rules = [];
1045
1045
  const decls = [];
1046
1046
  if (s.fontFamily) decls.push(`font-family: ${fontFamilyValue(s.fontFamily)}`);
@@ -1060,33 +1060,6 @@ function buildNavbarStyleTag(nav) {
1060
1060
  return {navbarFontLink, navbarStyleTag};
1061
1061
  }
1062
1062
 
1063
- // Families whose CSS fallback should be `serif`/`monospace` rather than the default `sans-serif`.
1064
- const SERIF_FAMILIES = new Set([
1065
- 'Merriweather', 'Playfair Display', 'Lora', 'Roboto Slab',
1066
- 'Cormorant Garamond', 'DM Serif Display', 'IBM Plex Serif'
1067
- ]);
1068
- const MONO_FAMILIES = new Set(['Fira Code', 'JetBrains Mono', 'IBM Plex Mono']);
1069
-
1070
- /**
1071
- * Build a `font-family` value for a configured family name.
1072
- *
1073
- * Family names are quoted: `Source Sans 3` is not a valid unquoted CSS identifier
1074
- * (a digit cannot start one), so the whole declaration would be dropped. The name is
1075
- * also stripped to letters/digits/space/hyphen because the navbar family is a free-text
1076
- * admin field that lands inside a `<style>` tag.
1077
- *
1078
- * @param {string} family - Configured family name, or the `system-ui`/`inherit` keywords
1079
- * @returns {string} CSS font-family value including its generic fallback
1080
- */
1081
- function fontFamilyValue(family) {
1082
- if (family === 'inherit') return 'inherit';
1083
- if (family === 'system-ui') return 'system-ui, -apple-system, sans-serif';
1084
- const safe = String(family).replace(/[^\w\s-]/g, '').trim();
1085
- if (!safe) return 'inherit';
1086
- const generic = SERIF_FAMILIES.has(safe) ? 'serif' : MONO_FAMILIES.has(safe) ? 'monospace' : 'sans-serif';
1087
- return `'${safe}', ${generic}`;
1088
- }
1089
-
1090
1063
  /**
1091
1064
  * The theme facts one render needs.
1092
1065
  *
@@ -1125,7 +1098,7 @@ async function buildThemeView(page = {}) {
1125
1098
  };
1126
1099
  }
1127
1100
 
1128
- const {fontLink, fontOverride} = buildFontVars(cfg.font?.family, cfg.font?.size);
1101
+ const {fontLink, fontOverride} = buildFontVars(cfg.font?.family, cfg.font?.size, cfg.font?.stylesheet);
1129
1102
 
1130
1103
  return {
1131
1104
  cfg,
@@ -1141,26 +1114,39 @@ async function buildThemeView(page = {}) {
1141
1114
  };
1142
1115
  }
1143
1116
 
1144
- function buildFontVars(fontFamily, fontSize) {
1145
- const PRECONNECT = '<link rel="preconnect" href="https://fonts.googleapis.com">\n <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>';
1117
+ /** Inline text typography needs a webfont even when the page body uses another family. */
1118
+ function contentFontLinks(html, existing = '') {
1119
+ const links = [existing || ''];
1120
+ for (const family of CMS_WEB_FONTS) {
1121
+ // Only curated family names can add a request; authored markup cannot supply a URL.
1122
+ const pattern = new RegExp(`font-family\\s*:\\s*(?:['"]|&#39;|&quot;)?${family}(?![\\w -])`, 'i');
1123
+ if (!pattern.test(html)) continue;
1124
+ const href = ['Poppins', 'Montserrat', 'Urbanist'].includes(family)
1125
+ ? fontStylesheetHref(family)
1126
+ : `https://fonts.googleapis.com/css2?family=${encodeURIComponent(family).replace(/%20/g, '+')}&display=swap`;
1127
+ if (!String(existing || '').includes(escapeHtml(href))) links.push(`<link rel="stylesheet" href="${escapeHtml(href)}">`);
1128
+ }
1129
+ return links.filter(Boolean).join('\n ') || null;
1130
+ }
1131
+
1132
+ function buildFontVars(fontFamily, fontSize, stylesheet = '') {
1146
1133
  const family = fontFamily || 'Roboto';
1147
1134
  const rules = [];
1148
-
1149
1135
  if (fontSize && fontSize !== 16) rules.push(`html { font-size: ${fontSize}px; }`);
1150
-
1151
- let fontLink;
1152
- if (family === 'system-ui') {
1153
- fontLink = null;
1154
- rules.push(`body, button, input, select, textarea { font-family: ${fontFamilyValue(family)}; }`);
1155
- } else {
1156
- const encoded = family.replace(/ /g, '+');
1157
- const href = `https://fonts.googleapis.com/css2?family=${encoded}:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap`;
1158
- fontLink = `${PRECONNECT}\n <link rel="stylesheet" href="${href}">`;
1159
- if (family !== 'Roboto') {
1160
- rules.push(`body, button, input, select, textarea { font-family: ${fontFamilyValue(family)}; }`);
1161
- }
1136
+ const hrefs = new Set([fontStylesheetHref(family, {stylesheet})]);
1137
+ // A page can use a licensed family in a menu or authored content even when
1138
+ // its body uses a Google font. The optional site-owned stylesheet serves both.
1139
+ if (isFontStylesheet(stylesheet)) hrefs.add(stylesheet);
1140
+ const links = [...hrefs].filter(Boolean);
1141
+ const preconnect = links.some(href => href.startsWith('https://fonts.googleapis.com/'))
1142
+ ? '<link rel="preconnect" href="https://fonts.googleapis.com">\n <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>\n ' : '';
1143
+ const fontLink = links.length ? preconnect + links
1144
+ .map(href => `<link rel="stylesheet" href="${escapeHtml(href)}">`).join('\n ') : null;
1145
+ if (family !== 'Roboto') {
1146
+ const stack = fontFamilyValue(family);
1147
+ rules.push(`body { --dm-font-sans: ${stack}; }`);
1148
+ rules.push(`body, button, input, select, textarea { font-family: ${stack}; }`);
1162
1149
  }
1163
-
1164
1150
  return {fontLink, fontOverride: rules.length ? rules.join(' ') : null};
1165
1151
  }
1166
1152
 
@@ -1288,8 +1274,9 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1288
1274
  html: `${renderedFragment || ''}${overlayMenus}${footerBlocksHtml}`,
1289
1275
  menus: [navItemsDecorated, footerPrimaryDecorated, footerLegalDecorated]
1290
1276
  });
1291
- const {fontLink, fontStyleTag, activeTheme, dommaTheme, customThemeClass} = themeView;
1292
- const {navbarFontLink, navbarStyleTag} = buildNavbarStyleTag(navigation);
1277
+ const {fontStyleTag, activeTheme, dommaTheme, customThemeClass} = themeView;
1278
+ const fontLink = contentFontLinks(`${renderedFragment}${overlayMenus}${footerBlocksHtml}`, themeView.fontLink);
1279
+ const {navbarFontLink, navbarStyleTag} = buildNavbarStyleTag(navigation, themeView.cfg.font);
1293
1280
 
1294
1281
  const customCssTag = customCss.trim()
1295
1282
  ? `<style>${customCss.replace(/<\/style>/gi, '<\\/style>')}</style>`
@@ -43,6 +43,7 @@
43
43
  * rather than papered over with generated counter-rules.
44
44
  */
45
45
 
46
+ import {isFontStylesheet} from '../../public/js/font-families.mjs';
46
47
  import fs from 'fs/promises';
47
48
  import fsSync from 'fs';
48
49
  import path from 'path';
@@ -675,6 +676,12 @@ export function validateThemeConfig(input, {remembered = []} = {}) {
675
676
  }
676
677
  }
677
678
  if (input.font) {
679
+ if (input.font.stylesheet && !isFontStylesheet(input.font.stylesheet)) {
680
+ errors.push('Font stylesheet must be a CSS file under /public/fonts/, for example /public/fonts/brand.css');
681
+ }
682
+ if (input.font.adminFamily !== undefined && !/^[\w \-',]{0,80}$/.test(String(input.font.adminFamily))) {
683
+ errors.push('Admin font family contains unexpected characters');
684
+ }
678
685
  const size = input.font.size;
679
686
  if (size !== undefined && (!Number.isFinite(Number(size)) || Number(size) < 8 || Number(size) > 48)) {
680
687
  errors.push('Font size must be between 8 and 48');
@@ -30,7 +30,7 @@
30
30
  <!-- Menu item hover / current-page effects. Loaded after site.css so a
31
31
  menu's own highlight wins over the blanket link styling there. -->
32
32
  <link rel="stylesheet" href="/public/css/menu-highlight.css?v=20261024-menu-highlight-fix">
33
- <link rel="stylesheet" href="/public/css/menu-cards.css?v=20261029-bar-shapes">
33
+ <link rel="stylesheet" href="/public/css/menu-cards.css?v=20261029-bar-fit-name">
34
34
  <link rel="stylesheet" href="/public/css/footer-showcase.css?v=20261029-footer-showcase">
35
35
  <link rel="stylesheet" href="/public/css/page-motion.css?v=20261029-page-motion">
36
36
 
@@ -188,7 +188,7 @@
188
188
  <script src="/public/js/form-logic-engine.js?v=20261025-dropzone-disable" defer></script>
189
189
 
190
190
  <!-- Site initialisation -->
191
- <script src="/public/js/site.js?v=20261029-site-branding" type="module"></script>
191
+ <script src="/public/js/site.js?v=20261029-bar-fit-js" type="module"></script>
192
192
  <script src="/public/js/collection-context.js?v=20261010-utf8-payloads" type="module"></script>
193
193
  {{ctxMenusModule}}
194
194
 
@@ -201,7 +201,7 @@
201
201
  <script src="/public/js/forms.js?v=20261025-forms-files-total" type="module"></script>
202
202
 
203
203
  <!-- Core effects runtime -->
204
- <script src="/public/js/effects.js?v=20261015-occasions" defer></script>
204
+ <script src="/public/js/effects.js?v=20261029-all-cms-fonts" defer></script>
205
205
 
206
206
  <!-- Plugin body-end injection -->
207
207
  {{bodyEndInject}}