diy-template-components 5.0.0 → 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.js CHANGED
@@ -2466,6 +2466,25 @@ const fontWeight = {
2466
2466
  superBold: 900
2467
2467
  };
2468
2468
 
2469
+ /**
2470
+ * Central font name resolver.
2471
+ * Maps legacy/display names to canonical Google Fonts family names.
2472
+ */
2473
+ const FONT_NAME_ALIASES = {
2474
+ 'Ibm Plex Sans': 'IBM Plex Sans'
2475
+ };
2476
+
2477
+ /**
2478
+ * Resolves a font family name to its canonical form for loading/rendering.
2479
+ * @param {string} fontFamily - Raw font name (e.g. from metadata or user selection)
2480
+ * @returns {string} Resolved font name for CSS/Google Fonts URL
2481
+ */
2482
+ function resolveFont(fontFamily) {
2483
+ if (!fontFamily || typeof fontFamily !== 'string') return fontFamily;
2484
+ const normalized = fontFamily.trim();
2485
+ return FONT_NAME_ALIASES[normalized] || normalized;
2486
+ }
2487
+
2469
2488
  const getBorderRadius = roundness => {
2470
2489
  const mapping = {
2471
2490
  sharp: {
@@ -2502,8 +2521,9 @@ const getBorderRadius = roundness => {
2502
2521
  };
2503
2522
  function getTheme(colorTheme = 'blue', fontFamily = 'Arial', isMobile, roundness = 'rounded') {
2504
2523
  const palette = palettes[colorTheme] || palettes['blue'];
2524
+ const resolvedFont = resolveFont(fontFamily);
2505
2525
  const typography = {
2506
- fontFamily: `"${fontFamily}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
2526
+ fontFamily: `"${resolvedFont}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
2507
2527
  fontSize: isMobile ? fontSizeMob : fontSize,
2508
2528
  fontWeight
2509
2529
  };
@@ -2520,58 +2540,25 @@ function getTheme(colorTheme = 'blue', fontFamily = 'Arial', isMobile, roundness
2520
2540
  };
2521
2541
  }
2522
2542
 
2523
- const fontComponents = {
2524
- Rubik,
2525
- 'Ibm Plex Sans': IbmPlexSans,
2526
- 'Merriweather Sans': MerriweatherSans,
2527
- 'Arima Madurai': ArimaMadurai,
2528
- 'Nanum Square': NanumSquare
2529
- };
2530
- const getFontComponent = font => fontComponents[font] || (() => null);
2543
+ const NANUM_SQUARE_URL = 'https://cdn.jsdelivr.net/gh/moonspam/NanumSquare@2.0/nanumsquare.css';
2544
+ const FONT_LINK_ID_PREFIX = 'diy-font-seeder-';
2545
+ 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`;
2531
2546
  function FontSeeder({
2532
2547
  fontFamily
2533
2548
  }) {
2534
- const Comp = getFontComponent(fontFamily);
2535
- return /*#__PURE__*/React__default["default"].createElement(Comp, null);
2536
- }
2537
- const useRubikFont = reactJss.createUseStyles({
2538
- '@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')`
2539
- });
2540
- function Rubik() {
2541
- // to import "Rubik" font css
2542
- useRubikFont();
2543
- return null;
2544
- }
2545
- const useIbmPlexSansFont = reactJss.createUseStyles({
2546
- '@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)'
2547
- });
2548
- function IbmPlexSans() {
2549
- // to import "Ibm Plex Sans" font css
2550
- useIbmPlexSansFont();
2551
- return null;
2552
- }
2553
- const useMerriweatherSansFont = reactJss.createUseStyles({
2554
- '@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)'
2555
- });
2556
- function MerriweatherSans() {
2557
- // to import "Merriweather Sans" font css
2558
- useMerriweatherSansFont();
2559
- return null;
2560
- }
2561
- const useArimaMaduraiFont = reactJss.createUseStyles({
2562
- '@import': 'url(https://fonts.googleapis.com/css2?family=Arima+Madurai:wght@400;500;700&display=swap)'
2563
- });
2564
- function ArimaMadurai() {
2565
- // to import "Arima Madurai" font css
2566
- useArimaMaduraiFont();
2567
- return null;
2568
- }
2569
- const useNanumSqaureFont = reactJss.createUseStyles({
2570
- '@import': 'url(https://cdn.jsdelivr.net/gh/moonspam/NanumSquare@2.0/nanumsquare.css)'
2571
- });
2572
- function NanumSquare() {
2573
- // to import "Nanum Square" font css
2574
- useNanumSqaureFont();
2549
+ React.useEffect(() => {
2550
+ if (!fontFamily || typeof document === 'undefined') return;
2551
+ const normalizedName = String(fontFamily).trim();
2552
+ const fontForUrl = resolveFont(normalizedName);
2553
+ const url = normalizedName.toLowerCase() === 'nanum square' ? NANUM_SQUARE_URL : getGoogleFontsUrl(fontForUrl);
2554
+ const linkId = `${FONT_LINK_ID_PREFIX}${normalizedName.replace(/\s+/g, '-')}`;
2555
+ if (document.getElementById(linkId)) return;
2556
+ const link = document.createElement('link');
2557
+ link.id = linkId;
2558
+ link.rel = 'stylesheet';
2559
+ link.href = url;
2560
+ document.head.appendChild(link);
2561
+ }, [fontFamily]);
2575
2562
  return null;
2576
2563
  }
2577
2564
 
@@ -3040,8 +3027,9 @@ const generateTheme = (theme = 'blue', fontFamily = 'Arial', isMobile, roundness
3040
3027
  headerText: allColors[color],
3041
3028
  headerHover: allColors['tertiary' + color]
3042
3029
  };
3030
+ const resolvedFont = resolveFont(fontFamily);
3043
3031
  const typography = {
3044
- fontFamily: `"${fontFamily}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
3032
+ fontFamily: `"${resolvedFont}", "Roboto", "Helvetica", "Arial", "sans-serif"`,
3045
3033
  fontSize: isMobile ? fontSizeMob : fontSize,
3046
3034
  fontWeight
3047
3035
  };