@ohhwells/bridge 0.1.174-next.463 → 0.1.174-next.465

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
@@ -90,6 +90,7 @@ __export(index_exports, {
90
90
  applyLogoVersionsFromContent: () => applyLogoVersionsFromContent,
91
91
  applyStickySearchParams: () => applyStickySearchParams,
92
92
  blockPathFromEditKey: () => blockPathFromEditKey,
93
+ brandColorVars: () => brandColorVars,
93
94
  buildDefaultFooterTree: () => buildDefaultFooterTree,
94
95
  buildTarget: () => buildTarget,
95
96
  canRemoveAiBlock: () => canRemoveAiBlock,
@@ -125,6 +126,7 @@ __export(index_exports, {
125
126
  mountBackgroundTone: () => mountBackgroundTone,
126
127
  mountLogoTonePick: () => mountLogoTonePick,
127
128
  nextViableSlide: () => nextViableSlide,
129
+ onPrimaryInk: () => onPrimaryInk,
128
130
  parseAiFooterState: () => parseAiFooterState,
129
131
  parseAiSectionsState: () => parseAiSectionsState,
130
132
  parseCssColor: () => parseCssColor,
@@ -613,6 +615,7 @@ var CTA_BUTTON_SELECTOR = '[data-ohw-role="navbar-button"], [data-ohw-role="butt
613
615
  var TONE_THRESHOLD = 0.5;
614
616
  var TONE_ATTR = "data-ohw-tone";
615
617
  var TONE_FIX_ATTR = "data-ohw-tone-fix";
618
+ var TONE_INK_ATTR = "data-ohw-tone-ink";
616
619
  var TONE_CHANGE_EVENT = "ohw:tone-change";
617
620
  var IMAGE_COVER_RATIO = 0.8;
618
621
  var SURFACE_MIN_PX = 24;
@@ -629,7 +632,6 @@ var MEASURING_ATTR = "data-ohw-tone-measuring";
629
632
  var TONE_FIX_LINE_ATTR = "data-ohw-tone-fix-line";
630
633
  var INK_FIX_STYLE_ID = "ohw-tone-ink-fix";
631
634
  var INK_MIN_CONTRAST = 3;
632
- var IMAGE_TEXT_MIN_CONTRAST = 3;
633
635
  var NEVER_SURFACE = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "CANVAS", "IFRAME", "PICTURE", "PATH", "SCRIPT", "STYLE"]);
634
636
  var clamp01 = (n) => Math.min(1, Math.max(0, n));
635
637
  function num(raw, percentOf = 1) {
@@ -1169,28 +1171,6 @@ var TEXT_SPOTS = [
1169
1171
  [1 / 2, 3 / 4],
1170
1172
  [5 / 6, 3 / 4]
1171
1173
  ];
1172
- function fixInks(doc) {
1173
- const view = doc?.defaultView;
1174
- const root = doc?.documentElement;
1175
- const read = (names, fallback) => {
1176
- if (!view || !root) return fallback;
1177
- let style;
1178
- try {
1179
- style = view.getComputedStyle(root);
1180
- } catch {
1181
- return fallback;
1182
- }
1183
- for (const name of names) {
1184
- const parsed = parseCssColor(style.getPropertyValue(name).trim());
1185
- if (parsed) return parsed;
1186
- }
1187
- return fallback;
1188
- };
1189
- return {
1190
- dark: read(["--ohw-brand-dark", "--color-dark"], { r: 12, g: 10, b: 9, a: 1 }),
1191
- light: read(["--ohw-brand-light", "--color-light"], WHITE)
1192
- };
1193
- }
1194
1174
  function glyphBox(el) {
1195
1175
  try {
1196
1176
  const range = el.ownerDocument?.createRange?.();
@@ -1219,17 +1199,42 @@ function spotsOf(box, at) {
1219
1199
  }
1220
1200
  return spots;
1221
1201
  }
1222
- function fixTextOnImage(el, text, box, at, inks) {
1223
- if (!text) return;
1224
- const spots = spotsOf(box, at);
1225
- if (spots.length === 0 || worstContrast(text, spots) >= IMAGE_TEXT_MIN_CONTRAST) return;
1226
- const darkWorks = worstContrast(inks.dark, spots) >= IMAGE_TEXT_MIN_CONTRAST;
1227
- const lightWorks = worstContrast(inks.light, spots) >= IMAGE_TEXT_MIN_CONTRAST;
1228
- if (darkWorks && (!lightWorks || worstContrast(inks.dark, spots) >= worstContrast(inks.light, spots))) {
1229
- el.setAttribute(TONE_FIX_ATTR, "light");
1230
- } else if (lightWorks) {
1231
- el.setAttribute(TONE_FIX_ATTR, "dark");
1232
- }
1202
+ function fixInks(doc) {
1203
+ const view = doc?.defaultView;
1204
+ const root = doc?.documentElement;
1205
+ const read = (names, fallback) => {
1206
+ if (!view || !root) return fallback;
1207
+ let style;
1208
+ try {
1209
+ style = view.getComputedStyle(root);
1210
+ } catch {
1211
+ return fallback;
1212
+ }
1213
+ for (const name of names) {
1214
+ const parsed = parseCssColor(style.getPropertyValue(name).trim());
1215
+ if (parsed) return parsed;
1216
+ }
1217
+ return fallback;
1218
+ };
1219
+ return {
1220
+ dark: read(["--ohw-brand-dark", "--color-dark"], { r: 12, g: 10, b: 9, a: 1 }),
1221
+ light: read(["--ohw-brand-light", "--color-light"], WHITE)
1222
+ };
1223
+ }
1224
+ function betterInkSide(spots, inks) {
1225
+ return worstContrast(inks.dark, spots) >= worstContrast(inks.light, spots) ? "light" : "dark";
1226
+ }
1227
+ function isBetterOption(text, spots, inks, side) {
1228
+ const winner = side === "light" ? inks.dark : inks.light;
1229
+ const loser = side === "light" ? inks.light : inks.dark;
1230
+ const seen = compositeColor(text, spots[0]);
1231
+ const like = contrastRatioOf(seen, winner) <= contrastRatioOf(seen, loser);
1232
+ return like && worstContrast(text, spots) >= worstContrast(loser, spots);
1233
+ }
1234
+ function fixTextAgainst(el, text, spots, inks) {
1235
+ if (!text || spots.length === 0) return;
1236
+ const side = betterInkSide(spots, inks);
1237
+ if (!isBetterOption(text, spots, inks, side)) el.setAttribute(TONE_FIX_ATTR, side);
1233
1238
  }
1234
1239
  var KEYED_TEXT_SELECTOR = "[data-ohw-key]:not([data-ohw-editable])";
1235
1240
  function hasOwnText(el) {
@@ -1243,8 +1248,7 @@ function hiddenWithin(deps, el, stop) {
1243
1248
  }
1244
1249
  return false;
1245
1250
  }
1246
- function fixTextContrast(deps, section, resolved, imageContexts, pending) {
1247
- let inks = null;
1251
+ function fixTextContrast(deps, section, resolved, imageContexts, pending, inks) {
1248
1252
  const texts = new Set(Array.from(section.querySelectorAll(TEXT_SELECTOR)));
1249
1253
  const keyed = /* @__PURE__ */ new Set();
1250
1254
  for (const el of Array.from(section.querySelectorAll(KEYED_TEXT_SELECTOR))) {
@@ -1267,15 +1271,19 @@ function fixTextContrast(deps, section, resolved, imageContexts, pending) {
1267
1271
  if (had) el.removeAttribute(TONE_FIX_ATTR);
1268
1272
  if (imageAt && !isEditorBackground(context)) {
1269
1273
  if (!hasPickedColour(el, context)) {
1270
- inks ?? (inks = fixInks(section.ownerDocument));
1271
- fixTextOnImage(el, parseCssColor(deps.style(el).color), glyphBox(el) ?? deps.rect(el), imageAt, inks);
1274
+ fixTextAgainst(el, parseCssColor(deps.style(el).color), spotsOf(glyphBox(el) ?? deps.rect(el), imageAt), inks);
1272
1275
  }
1273
1276
  continue;
1274
1277
  }
1275
- const text = parseCssColor(deps.style(el).color);
1276
- const bgTone = toneOfColor(bg);
1277
- const needsFix = text !== null && toneOfColor(compositeColor(text, bg)) === bgTone;
1278
- if (needsFix) el.setAttribute(TONE_FIX_ATTR, bgTone);
1278
+ fixTextAgainst(el, parseCssColor(deps.style(el).color), [bg], inks);
1279
+ }
1280
+ }
1281
+ function writeEditorInks(section, resolved, inks) {
1282
+ for (const stale of [section, ...Array.from(section.querySelectorAll(`[${TONE_INK_ATTR}]`))]) {
1283
+ if (!isEditorBackground(stale) || !resolved.has(stale)) stale.removeAttribute(TONE_INK_ATTR);
1284
+ }
1285
+ for (const [el, color] of resolved) {
1286
+ if (isEditorBackground(el)) el.setAttribute(TONE_INK_ATTR, betterInkSide([color], inks));
1279
1287
  }
1280
1288
  }
1281
1289
  function pickedButtonInks(doc) {
@@ -1364,7 +1372,6 @@ function fixOverlayText(deps, doc) {
1364
1372
  if (roots.length === 0) return;
1365
1373
  const photoSections = topSections(doc).filter((s) => sectionPhotos.has(s));
1366
1374
  const boxes = new Map(photoSections.map((s) => [s, deps.rect(s)]));
1367
- let inks = null;
1368
1375
  for (const root of roots) {
1369
1376
  const items = [];
1370
1377
  for (const el of Array.from(root.querySelectorAll(TEXT_SELECTOR))) {
@@ -1386,8 +1393,7 @@ function fixOverlayText(deps, doc) {
1386
1393
  const spots = spotsOf(box, photo);
1387
1394
  if (text && spots.length > 0) items.push({ el, text, spots, line: underlineOf(deps, el, root) });
1388
1395
  }
1389
- inks ?? (inks = fixInks(doc));
1390
- fixBarInk(items, inks);
1396
+ fixBarInk(items, fixInks(doc));
1391
1397
  for (const item of items) {
1392
1398
  const fix = item.el.getAttribute(TONE_FIX_ATTR);
1393
1399
  if (fix) item.line?.setAttribute(TONE_FIX_LINE_ATTR, fix);
@@ -1445,25 +1451,11 @@ function underlineOf(deps, el, root) {
1445
1451
  return null;
1446
1452
  }
1447
1453
  function fixBarInk(items, inks) {
1448
- if (!items.some((item) => worstContrast(item.text, item.spots) < IMAGE_TEXT_MIN_CONTRAST)) return;
1449
- const score = (ink) => {
1450
- let readable = 0;
1451
- let worst = Infinity;
1452
- for (const item of items) {
1453
- const c = worstContrast(ink, item.spots);
1454
- if (c >= IMAGE_TEXT_MIN_CONTRAST) readable++;
1455
- worst = Math.min(worst, c);
1456
- }
1457
- return { readable, worst };
1458
- };
1459
- const dark = score(inks.dark);
1460
- const light = score(inks.light);
1461
- if (dark.readable === 0 && light.readable === 0) return;
1462
- const useDark = dark.readable > light.readable || dark.readable === light.readable && dark.worst >= light.worst;
1463
- const fix = useDark ? "light" : "dark";
1454
+ if (items.length === 0) return;
1455
+ const spots = items.flatMap((item) => item.spots);
1456
+ const side = betterInkSide(spots, inks);
1464
1457
  for (const item of items) {
1465
- if (toneOfColor(item.text) === (useDark ? "dark" : "light")) continue;
1466
- item.el.setAttribute(TONE_FIX_ATTR, fix);
1458
+ if (!isBetterOption(item.text, spots, inks, side)) item.el.setAttribute(TONE_FIX_ATTR, side);
1467
1459
  }
1468
1460
  }
1469
1461
  function computeSection(deps, section, onReady) {
@@ -1551,7 +1543,9 @@ function computeSection(deps, section, onReady) {
1551
1543
  for (const stale of Array.from(section.querySelectorAll(`[${TONE_ATTR}]`))) {
1552
1544
  if (!written.has(stale) && !stale.hasAttribute(OVERLAY_TONE_ATTR)) stale.removeAttribute(TONE_ATTR);
1553
1545
  }
1554
- fixTextContrast(deps, section, resolved, imageContexts, pending);
1546
+ const inks = fixInks(section.ownerDocument);
1547
+ writeEditorInks(section, resolved, inks);
1548
+ fixTextContrast(deps, section, resolved, imageContexts, pending, inks);
1555
1549
  fixButtonInk(deps, section, painted);
1556
1550
  }
1557
1551
  function topSections(root) {
@@ -7432,8 +7426,8 @@ function styleSheetCss() {
7432
7426
  const lightText = "var(--ohw-brand-light, var(--color-light, #FFFFFF))";
7433
7427
  const darkText = "var(--ohw-brand-dark, var(--color-dark, #0C0A09))";
7434
7428
  rules.push(
7435
- `:is([data-ohw-style-bg], [data-ohw-style-bgcolor])[data-ohw-tone="dark"], [data-ohw-tone-fix="dark"] { color: ${lightText} !important; }`,
7436
- `:is([data-ohw-style-bg], [data-ohw-style-bgcolor])[data-ohw-tone="light"], [data-ohw-tone-fix="light"] { color: ${darkText} !important; }`
7429
+ `:is([data-ohw-style-bg], [data-ohw-style-bgcolor])[data-ohw-tone-ink="dark"], [data-ohw-tone-fix="dark"] { color: ${lightText} !important; }`,
7430
+ `:is([data-ohw-style-bg], [data-ohw-style-bgcolor])[data-ohw-tone-ink="light"], [data-ohw-tone-fix="light"] { color: ${darkText} !important; }`
7437
7431
  );
7438
7432
  rules.push(
7439
7433
  `[data-ohw-style-distribution="space-between"] { display: flex !important; flex-direction: column; justify-content: space-between; }`,
@@ -8601,8 +8595,12 @@ var LEGACY_BRAND_VAR_NAMES = [
8601
8595
  "text-muted",
8602
8596
  "surface",
8603
8597
  "border",
8604
- "on-primary"
8605
- ].map((role) => `--brand-${role}`);
8598
+ "on-primary",
8599
+ "on-primary-muted",
8600
+ "on-primary-faint",
8601
+ "on-accent",
8602
+ "on-accent-muted"
8603
+ ].map((role) => `--brand-${role}`).concat(["--on-primary", "--on-accent"]);
8606
8604
  var FONT_VARS = {
8607
8605
  heading: ["--font-heading", "--font-display", "--brand-font-heading"],
8608
8606
  body: ["--font-body", "--brand-font-body"]
@@ -8728,6 +8726,8 @@ function brandColorVars(palette) {
8728
8726
  const surface = mix(light, 95, dark);
8729
8727
  const border = mix(light, 85, dark);
8730
8728
  const muted = mix(dark, 62, light);
8729
+ const onPrimary = onPrimaryInk(primary, light, dark);
8730
+ const onAccent = onPrimaryInk(accent, light, dark);
8731
8731
  return {
8732
8732
  [`${BRAND_VAR_PREFIX}primary`]: primary,
8733
8733
  [`${BRAND_VAR_PREFIX}accent`]: accent,
@@ -8744,11 +8744,27 @@ function brandColorVars(palette) {
8744
8744
  "--brand-text-muted": muted,
8745
8745
  "--brand-surface": surface,
8746
8746
  "--brand-border": border,
8747
- // Buttons/bands painted in the primary colour assume it's dark/saturated enough to need
8748
- // light text on top — the same assumption LOGO_IMAGE's light-on-dark navbar mark makes.
8749
- "--brand-on-primary": light
8747
+ // Text on anything painted Primary (buttons, bands, Meridien's service cards): whichever of
8748
+ // Light and Dark reads better on it. Hard-wiring Light put white on a pale pink Primary.
8749
+ // Muted and faint are template literals (cream at 75% / 55%) the kit has to follow too.
8750
+ "--brand-on-primary": onPrimary,
8751
+ "--brand-on-primary-muted": `color-mix(in srgb, ${onPrimary} 75%, transparent)`,
8752
+ "--brand-on-primary-faint": `color-mix(in srgb, ${onPrimary} 55%, transparent)`,
8753
+ // Same rule for anything painted Accent (drserene, salon, tutor surfaces). Templates bake
8754
+ // these in from their build-time palette, so an Accent changed in the editor kept the old ink.
8755
+ "--brand-on-accent": onAccent,
8756
+ "--brand-on-accent-muted": `color-mix(in srgb, ${onAccent} 75%, transparent)`,
8757
+ "--on-primary": onPrimary,
8758
+ "--on-accent": onAccent
8750
8759
  };
8751
8760
  }
8761
+ function onPrimaryInk(primary, light, dark) {
8762
+ const p = parseCssColor(primary);
8763
+ const l = parseCssColor(light);
8764
+ const d = parseCssColor(dark);
8765
+ if (!p || !l || !d) return light;
8766
+ return contrastRatioOf(d, p) >= contrastRatioOf(l, p) ? dark : light;
8767
+ }
8752
8768
  function isButtonStyle(value) {
8753
8769
  if (!value || typeof value !== "object") return false;
8754
8770
  const v = value;
@@ -19417,7 +19433,7 @@ function apiBase() {
19417
19433
  function bridgeVersion() {
19418
19434
  try {
19419
19435
  if (true) {
19420
- return "0.1.174-next.463";
19436
+ return "0.1.174-next.465";
19421
19437
  }
19422
19438
  } catch {
19423
19439
  }
@@ -19431,7 +19447,7 @@ function stampBridgeVersionOnDocument() {
19431
19447
  return;
19432
19448
  }
19433
19449
  try {
19434
- const v = true ? "0.1.174-next.463" : "";
19450
+ const v = true ? "0.1.174-next.465" : "";
19435
19451
  if (v) {
19436
19452
  document.documentElement.setAttribute("data-ohw-bridge-version", v);
19437
19453
  window.__OHW_BRIDGE_VERSION__ = v;
@@ -34816,7 +34832,7 @@ function OhhwellsBridge() {
34816
34832
  postToParent2({
34817
34833
  type: "ow:ready",
34818
34834
  version: "1",
34819
- bridgeVersion: "0.1.174-next.463",
34835
+ bridgeVersion: "0.1.174-next.465",
34820
34836
  path: pathname,
34821
34837
  nodes: collectEditableNodes(editContentRef.current),
34822
34838
  sections
@@ -36230,6 +36246,7 @@ function EmptySection({ title, homeHref = "/", eyebrowKey, titleKey, subtitleKey
36230
36246
  applyLogoVersionsFromContent,
36231
36247
  applyStickySearchParams,
36232
36248
  blockPathFromEditKey,
36249
+ brandColorVars,
36233
36250
  buildDefaultFooterTree,
36234
36251
  buildTarget,
36235
36252
  canRemoveAiBlock,
@@ -36265,6 +36282,7 @@ function EmptySection({ title, homeHref = "/", eyebrowKey, titleKey, subtitleKey
36265
36282
  mountBackgroundTone,
36266
36283
  mountLogoTonePick,
36267
36284
  nextViableSlide,
36285
+ onPrimaryInk,
36268
36286
  parseAiFooterState,
36269
36287
  parseAiSectionsState,
36270
36288
  parseCssColor,