diy-template-components 4.0.7 → 5.1.1

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/build/index.es.js CHANGED
@@ -2452,6 +2452,25 @@ const fontWeight = {
2452
2452
  superBold: 900
2453
2453
  };
2454
2454
 
2455
+ /**
2456
+ * Central font name resolver.
2457
+ * Maps legacy/display names to canonical Google Fonts family names.
2458
+ */
2459
+ const FONT_NAME_ALIASES = {
2460
+ 'Ibm Plex Sans': 'IBM Plex Sans'
2461
+ };
2462
+
2463
+ /**
2464
+ * Resolves a font family name to its canonical form for loading/rendering.
2465
+ * @param {string} fontFamily - Raw font name (e.g. from metadata or user selection)
2466
+ * @returns {string} Resolved font name for CSS/Google Fonts URL
2467
+ */
2468
+ function resolveFont(fontFamily) {
2469
+ if (!fontFamily || typeof fontFamily !== 'string') return fontFamily;
2470
+ const normalized = fontFamily.trim();
2471
+ return FONT_NAME_ALIASES[normalized] || normalized;
2472
+ }
2473
+
2455
2474
  const getBorderRadius = roundness => {
2456
2475
  const mapping = {
2457
2476
  sharp: {
@@ -2488,8 +2507,9 @@ const getBorderRadius = roundness => {
2488
2507
  };
2489
2508
  function getTheme(colorTheme = 'blue', fontFamily = 'Arial', isMobile, roundness = 'rounded') {
2490
2509
  const palette = palettes[colorTheme] || palettes['blue'];
2510
+ const resolvedFont = resolveFont(fontFamily);
2491
2511
  const typography = {
2492
- fontFamily: `"${fontFamily}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
2512
+ fontFamily: `"${resolvedFont}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
2493
2513
  fontSize: isMobile ? fontSizeMob : fontSize,
2494
2514
  fontWeight
2495
2515
  };
@@ -2506,58 +2526,25 @@ function getTheme(colorTheme = 'blue', fontFamily = 'Arial', isMobile, roundness
2506
2526
  };
2507
2527
  }
2508
2528
 
2509
- const fontComponents = {
2510
- Rubik,
2511
- 'Ibm Plex Sans': IbmPlexSans,
2512
- 'Merriweather Sans': MerriweatherSans,
2513
- 'Arima Madurai': ArimaMadurai,
2514
- 'Nanum Square': NanumSquare
2515
- };
2516
- const getFontComponent = font => fontComponents[font] || (() => null);
2529
+ const NANUM_SQUARE_URL = 'https://cdn.jsdelivr.net/gh/moonspam/NanumSquare@2.0/nanumsquare.css';
2530
+ const FONT_LINK_ID_PREFIX = 'diy-font-seeder-';
2531
+ const getGoogleFontsUrl = fontFamily => `https://fonts.googleapis.com/css2?family=${fontFamily.replace(/ /g, '+')}:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap`;
2517
2532
  function FontSeeder({
2518
2533
  fontFamily
2519
2534
  }) {
2520
- const Comp = getFontComponent(fontFamily);
2521
- return /*#__PURE__*/React.createElement(Comp, null);
2522
- }
2523
- const useRubikFont = createUseStyles$1({
2524
- '@import': `url('https://fonts.googleapis.com/css2?family=Lato&family=Rubik:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap')`
2525
- });
2526
- function Rubik() {
2527
- // to import "Rubik" font css
2528
- useRubikFont();
2529
- return null;
2530
- }
2531
- const useIbmPlexSansFont = createUseStyles$1({
2532
- '@import': 'url(https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap)'
2533
- });
2534
- function IbmPlexSans() {
2535
- // to import "Ibm Plex Sans" font css
2536
- useIbmPlexSansFont();
2537
- return null;
2538
- }
2539
- const useMerriweatherSansFont = createUseStyles$1({
2540
- '@import': 'url(https://fonts.googleapis.com/css2?family=Merriweather+Sans:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap)'
2541
- });
2542
- function MerriweatherSans() {
2543
- // to import "Merriweather Sans" font css
2544
- useMerriweatherSansFont();
2545
- return null;
2546
- }
2547
- const useArimaMaduraiFont = createUseStyles$1({
2548
- '@import': 'url(https://fonts.googleapis.com/css2?family=Arima+Madurai:wght@400;500;700&display=swap)'
2549
- });
2550
- function ArimaMadurai() {
2551
- // to import "Arima Madurai" font css
2552
- useArimaMaduraiFont();
2553
- return null;
2554
- }
2555
- const useNanumSqaureFont = createUseStyles$1({
2556
- '@import': 'url(https://cdn.jsdelivr.net/gh/moonspam/NanumSquare@2.0/nanumsquare.css)'
2557
- });
2558
- function NanumSquare() {
2559
- // to import "Nanum Square" font css
2560
- useNanumSqaureFont();
2535
+ useEffect(() => {
2536
+ if (!fontFamily || typeof document === 'undefined') return;
2537
+ const normalizedName = String(fontFamily).trim();
2538
+ const fontForUrl = resolveFont(normalizedName);
2539
+ const url = normalizedName.toLowerCase() === 'nanum square' ? NANUM_SQUARE_URL : getGoogleFontsUrl(fontForUrl);
2540
+ const linkId = `${FONT_LINK_ID_PREFIX}${normalizedName.replace(/\s+/g, '-')}`;
2541
+ if (document.getElementById(linkId)) return;
2542
+ const link = document.createElement('link');
2543
+ link.id = linkId;
2544
+ link.rel = 'stylesheet';
2545
+ link.href = url;
2546
+ document.head.appendChild(link);
2547
+ }, [fontFamily]);
2561
2548
  return null;
2562
2549
  }
2563
2550
 
@@ -3026,8 +3013,9 @@ const generateTheme = (theme = 'blue', fontFamily = 'Arial', isMobile, roundness
3026
3013
  headerText: allColors[color],
3027
3014
  headerHover: allColors['tertiary' + color]
3028
3015
  };
3016
+ const resolvedFont = resolveFont(fontFamily);
3029
3017
  const typography = {
3030
- fontFamily: `"${fontFamily}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
3018
+ fontFamily: `"${resolvedFont}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
3031
3019
  fontSize: isMobile ? fontSizeMob : fontSize,
3032
3020
  fontWeight
3033
3021
  };