@ohhwells/bridge 0.1.158-next.423 → 0.1.158-next.424

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
@@ -220,6 +220,56 @@ function isRenderableTree(value) {
220
220
  return AI_TREE_SCHEMA_VERSIONS.includes(tree.schemaVersion) && tree.type === "section" && Array.isArray(tree.rows);
221
221
  }
222
222
 
223
+ // src/lib/headline-size.ts
224
+ var HEADLINE_SIZE_MULTIPLIERS = {
225
+ xs: 0.7,
226
+ sm: 0.85,
227
+ base: 1,
228
+ lg: 1.2,
229
+ xl: 1.45,
230
+ "2xl": 1.75
231
+ };
232
+ var HEADLINE_SIZE_ATTR = "data-ohw-style-headlinesize";
233
+ var PREV_ATTR = "data-ohw-style-prev-fsmul";
234
+ var NODE_FONT_SIZE_ATTR = "data-ohw-style-prev-font-size";
235
+ function headingsIn(section) {
236
+ return Array.from(section.querySelectorAll("h1, h2, h3"));
237
+ }
238
+ function clearHeadlineSizes(root = document) {
239
+ for (const el of Array.from(root.querySelectorAll(`[${PREV_ATTR}]`))) {
240
+ const prev = el.getAttribute(PREV_ATTR) ?? "";
241
+ if (prev) el.style.setProperty("font-size", prev);
242
+ else el.style.removeProperty("font-size");
243
+ el.removeAttribute(PREV_ATTR);
244
+ }
245
+ }
246
+ function applyHeadlineSizes(root = document) {
247
+ clearHeadlineSizes(root);
248
+ for (const section of Array.from(
249
+ root.querySelectorAll(`[${HEADLINE_SIZE_ATTR}]`)
250
+ )) {
251
+ const multiplier = HEADLINE_SIZE_MULTIPLIERS[section.getAttribute(HEADLINE_SIZE_ATTR) ?? ""];
252
+ if (!multiplier || multiplier === 1) continue;
253
+ for (const heading of headingsIn(section)) {
254
+ if (heading.hasAttribute(NODE_FONT_SIZE_ATTR)) continue;
255
+ const base = Number.parseFloat(window.getComputedStyle(heading).fontSize);
256
+ if (!Number.isFinite(base) || base <= 0) continue;
257
+ heading.setAttribute(PREV_ATTR, heading.style.getPropertyValue("font-size"));
258
+ heading.style.setProperty("font-size", `${Math.round(base * multiplier * 100) / 100}px`, "important");
259
+ }
260
+ }
261
+ }
262
+ var resizeInstalled = false;
263
+ function installHeadlineSizeResize() {
264
+ if (resizeInstalled || typeof window === "undefined") return;
265
+ resizeInstalled = true;
266
+ let timer;
267
+ window.addEventListener("resize", () => {
268
+ if (timer) clearTimeout(timer);
269
+ timer = setTimeout(() => applyHeadlineSizes(), 120);
270
+ });
271
+ }
272
+
223
273
  // src/lib/sections.ts
224
274
  var LINK_PICKER_EXCLUDED_IDS = /* @__PURE__ */ new Set(["navbar", "footer"]);
225
275
  function isChromeSection(el) {
@@ -6011,6 +6061,7 @@ var SECTION_ATTRS = {
6011
6061
  sectionBackground: "data-ohw-style-bg",
6012
6062
  textDistribution: "data-ohw-style-distribution",
6013
6063
  headlineScale: "data-ohw-style-headline",
6064
+ headlineSize: HEADLINE_SIZE_ATTR,
6014
6065
  imageAspect: "data-ohw-style-aspect",
6015
6066
  spacing: "data-ohw-style-spacing",
6016
6067
  verticalPadding: "data-ohw-style-vpadding",
@@ -6079,6 +6130,15 @@ function clearSectionAttrs(root) {
6079
6130
  }
6080
6131
  }
6081
6132
  var ITEM_WROTE_ATTR = "data-ohw-style-item";
6133
+ function paintIcon(slot, color) {
6134
+ for (const el of [slot, ...Array.from(slot.querySelectorAll("svg, svg *"))]) {
6135
+ const styled = el;
6136
+ if (!styled.style) continue;
6137
+ saveInline(styled, "color");
6138
+ styled.style.setProperty("color", color, "important");
6139
+ styled.setAttribute(NODE_WROTE_ATTR, "");
6140
+ }
6141
+ }
6082
6142
  function clearNodeProps(root) {
6083
6143
  for (const el of Array.from(root.querySelectorAll(`[${NODE_WROTE_ATTR}]`))) {
6084
6144
  const h = el;
@@ -6116,6 +6176,7 @@ function applyStylesToDom(store) {
6116
6176
  ensureStyleSheet();
6117
6177
  clearSectionAttrs(document);
6118
6178
  clearNodeProps(document);
6179
+ clearHeadlineSizes(document);
6119
6180
  loadStyleFonts(
6120
6181
  store ? [
6121
6182
  ...Object.values(store.nodes).flatMap((n) => n.fontFamily ? [n.fontFamily] : []),
@@ -6189,9 +6250,13 @@ function applyStylesToDom(store) {
6189
6250
  const nodes = document.querySelectorAll(`[data-ohw-key="${CSS.escape(key)}"]`);
6190
6251
  for (const el of Array.from(nodes)) {
6191
6252
  if (override.color !== void 0) {
6192
- saveInline(el, "color");
6193
- el.style.setProperty("color", override.color, "important");
6194
- el.setAttribute(NODE_WROTE_ATTR, "");
6253
+ if (el.dataset.ohwEditable === "icon") {
6254
+ paintIcon(el, override.color);
6255
+ } else {
6256
+ saveInline(el, "color");
6257
+ el.style.setProperty("color", override.color, "important");
6258
+ el.setAttribute(NODE_WROTE_ATTR, "");
6259
+ }
6195
6260
  }
6196
6261
  if (override.fontFamily !== void 0) {
6197
6262
  saveInline(el, "font-family");
@@ -6255,13 +6320,11 @@ function applyStylesToDom(store) {
6255
6320
  const sections = byInstance.length ? byInstance : document.querySelectorAll(`[data-ohw-section="${escaped}"]`);
6256
6321
  for (const marker of Array.from(sections)) {
6257
6322
  const icons = marker.querySelectorAll('[data-ohw-editable="icon"]');
6258
- for (const el of Array.from(icons)) {
6259
- saveInline(el, "color");
6260
- el.style.setProperty("color", override.iconColor, "important");
6261
- el.setAttribute(NODE_WROTE_ATTR, "");
6262
- }
6323
+ for (const el of Array.from(icons)) paintIcon(el, override.iconColor);
6263
6324
  }
6264
6325
  }
6326
+ applyHeadlineSizes(document);
6327
+ installHeadlineSizeResize();
6265
6328
  }
6266
6329
 
6267
6330
  // src/lib/ai-sections-store.ts
@@ -6301,17 +6364,21 @@ function resolveSectionTree(sectionId, aiSectionsRaw) {
6301
6364
  return parseAiSectionsState(aiSectionsRaw).sections.find((entry) => entry.id === sectionId)?.tree;
6302
6365
  }
6303
6366
  function resolveSectionSettingsContext(sectionId, aiSectionsRaw, stylesRaw) {
6367
+ const styleOverride = parseStyleStore(stylesRaw)?.sections[sectionId];
6368
+ const headlineSize = styleOverride?.headlineSize;
6304
6369
  const genSettings = parseAiSectionsState(aiSectionsRaw).sections.find(
6305
6370
  (entry) => entry.id === sectionId
6306
6371
  )?.tree.settings;
6307
- if (genSettings) return genSettings;
6308
- const styleOverride = parseStyleStore(stylesRaw)?.sections[sectionId];
6309
- if (!styleOverride?.verticalPadding && !styleOverride?.minHeight && !styleOverride?.spacing) {
6372
+ if (genSettings) {
6373
+ return { ...genSettings, ...headlineSize ? { headlineSize } : {} };
6374
+ }
6375
+ if (!styleOverride?.verticalPadding && !styleOverride?.minHeight && !styleOverride?.spacing && !headlineSize) {
6310
6376
  return void 0;
6311
6377
  }
6312
6378
  return {
6313
- verticalPadding: styleOverride.verticalPadding ?? legacyVerticalPaddingAlias(styleOverride.spacing),
6314
- minHeight: styleOverride.minHeight
6379
+ verticalPadding: styleOverride?.verticalPadding ?? legacyVerticalPaddingAlias(styleOverride?.spacing),
6380
+ minHeight: styleOverride?.minHeight,
6381
+ ...headlineSize ? { headlineSize } : {}
6315
6382
  };
6316
6383
  }
6317
6384
  function applyTreeToState(state, payload) {
@@ -17300,7 +17367,7 @@ function apiBase() {
17300
17367
  function bridgeVersion() {
17301
17368
  try {
17302
17369
  if (true) {
17303
- return "0.1.158-next.423";
17370
+ return "0.1.158-next.424";
17304
17371
  }
17305
17372
  } catch {
17306
17373
  }
@@ -17314,7 +17381,7 @@ function stampBridgeVersionOnDocument() {
17314
17381
  return;
17315
17382
  }
17316
17383
  try {
17317
- const v = true ? "0.1.158-next.423" : "";
17384
+ const v = true ? "0.1.158-next.424" : "";
17318
17385
  if (v) {
17319
17386
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
17320
17387
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -31650,9 +31717,11 @@ function OhhwellsBridge() {
31650
31717
  if (e.data?.type !== "ow:collect-section") return;
31651
31718
  const sectionId = e.data.sectionId;
31652
31719
  if (typeof sectionId !== "string" || !sectionId) return;
31653
- const foundEl = document.querySelector(
31654
- `[data-ohw-section="${CSS.escape(sectionId)}"]`
31720
+ const escapedSectionId = CSS.escape(sectionId);
31721
+ const instanceEl = document.querySelector(
31722
+ `[data-ohw-instance="${escapedSectionId}"]`
31655
31723
  );
31724
+ const foundEl = instanceEl ? sectionElementOf(instanceEl) : document.querySelector(`[data-ohw-section="${escapedSectionId}"]`);
31656
31725
  const sectionEl = foundEl && !foundEl.hasAttribute("data-ohw-ai-template-hidden") && !foundEl.hasAttribute("data-ohw-ai-removed") && !foundEl.hasAttribute("data-ohw-ai-replaced-by") ? foundEl : null;
31657
31726
  const nodes = sectionEl ? collectEditableNodes(void 0, sectionEl).filter(
31658
31727
  (n) => n.key && !n.key.startsWith("__ohw_") && !["meta", "sections", "video-setting"].includes(n.type)
@@ -31665,7 +31734,11 @@ function OhhwellsBridge() {
31665
31734
  width: box.width,
31666
31735
  height: box.height
31667
31736
  } : null;
31668
- const settings = resolveSectionSettingsContext(sectionId, aiSectionsRef.current, stylesRef.current);
31737
+ const settings = resolveSectionSettingsContext(
31738
+ sectionId,
31739
+ aiSectionsRef.current,
31740
+ stylesRef.current
31741
+ );
31669
31742
  const tree = resolveSectionTree(sectionId, aiSectionsRef.current);
31670
31743
  postToParentRef.current({
31671
31744
  type: "ow:section-nodes",
@@ -32396,7 +32469,7 @@ function OhhwellsBridge() {
32396
32469
  postToParent2({
32397
32470
  type: "ow:ready",
32398
32471
  version: "1",
32399
- bridgeVersion: "0.1.158-next.423",
32472
+ bridgeVersion: "0.1.158-next.424",
32400
32473
  path: pathname,
32401
32474
  nodes: collectEditableNodes(editContentRef.current),
32402
32475
  sections