@ohhwells/bridge 0.1.62-next.174 → 0.1.63-next.175

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/dist/index.cjs CHANGED
@@ -372,6 +372,25 @@ function styleSheetCss() {
372
372
  }
373
373
  return rules.join("\n");
374
374
  }
375
+ var STYLE_FONT_LINK_ID = "ohw-style-fonts";
376
+ function loadStyleFonts(families) {
377
+ const unique = [...new Set(families.map((f) => f.trim()).filter(Boolean))];
378
+ const existing = document.getElementById(STYLE_FONT_LINK_ID);
379
+ if (unique.length === 0) {
380
+ existing?.remove();
381
+ return;
382
+ }
383
+ const spec = unique.map((f) => `${f.replace(/ /g, "+")}:400,500,600,700`).join("|");
384
+ const href = `https://fonts.googleapis.com/css?family=${spec}&display=swap`;
385
+ let link = existing;
386
+ if (!link) {
387
+ link = document.createElement("link");
388
+ link.id = STYLE_FONT_LINK_ID;
389
+ link.rel = "stylesheet";
390
+ document.head.appendChild(link);
391
+ }
392
+ if (link.href !== href) link.href = href;
393
+ }
375
394
  var SECTION_ATTRS = {
376
395
  sectionBackground: "data-ohw-style-bg",
377
396
  textDistribution: "data-ohw-style-distribution",
@@ -380,7 +399,7 @@ var SECTION_ATTRS = {
380
399
  spacing: "data-ohw-style-spacing"
381
400
  };
382
401
  var NODE_WROTE_ATTR = "data-ohw-style-node";
383
- var NODE_PROPS = ["color", "font-size", "background"];
402
+ var NODE_PROPS = ["color", "font-family", "font-size", "background"];
384
403
  function saveInline(el, prop) {
385
404
  const attr = `data-ohw-style-prev-${prop}`;
386
405
  if (!el.hasAttribute(attr)) el.setAttribute(attr, el.style.getPropertyValue(prop));
@@ -426,6 +445,9 @@ function applyStylesToDom(store) {
426
445
  ensureStyleSheet();
427
446
  clearSectionAttrs(document);
428
447
  clearNodeProps(document);
448
+ loadStyleFonts(
449
+ store ? Object.values(store.nodes).flatMap((n) => n.fontFamily ? [n.fontFamily] : []) : []
450
+ );
429
451
  if (!store) return;
430
452
  for (const [sectionId, override] of Object.entries(store.sections)) {
431
453
  const sections = document.querySelectorAll(
@@ -453,6 +475,11 @@ function applyStylesToDom(store) {
453
475
  el.style.setProperty("color", override.color, "important");
454
476
  el.setAttribute(NODE_WROTE_ATTR, "");
455
477
  }
478
+ if (override.fontFamily !== void 0) {
479
+ saveInline(el, "font-family");
480
+ el.style.setProperty("font-family", `'${override.fontFamily}'`, "important");
481
+ el.setAttribute(NODE_WROTE_ATTR, "");
482
+ }
456
483
  if (override.fontSize !== void 0) {
457
484
  saveInline(el, "font-size");
458
485
  el.style.setProperty("font-size", `${override.fontSize}px`, "important");
@@ -18551,7 +18578,7 @@ function OhhwellsBridge() {
18551
18578
  postToParent2({
18552
18579
  type: "ow:ready",
18553
18580
  version: "1",
18554
- bridgeVersion: "0.1.62",
18581
+ bridgeVersion: "0.1.63",
18555
18582
  path: pathname,
18556
18583
  nodes: collectEditableNodes(editContentRef.current),
18557
18584
  sections