@ohhwells/bridge 0.1.174-next.463 → 0.1.174-next.464
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 +80 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +79 -73
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -125,6 +125,7 @@ __export(index_exports, {
|
|
|
125
125
|
mountBackgroundTone: () => mountBackgroundTone,
|
|
126
126
|
mountLogoTonePick: () => mountLogoTonePick,
|
|
127
127
|
nextViableSlide: () => nextViableSlide,
|
|
128
|
+
onPrimaryInk: () => onPrimaryInk,
|
|
128
129
|
parseAiFooterState: () => parseAiFooterState,
|
|
129
130
|
parseAiSectionsState: () => parseAiSectionsState,
|
|
130
131
|
parseCssColor: () => parseCssColor,
|
|
@@ -613,6 +614,7 @@ var CTA_BUTTON_SELECTOR = '[data-ohw-role="navbar-button"], [data-ohw-role="butt
|
|
|
613
614
|
var TONE_THRESHOLD = 0.5;
|
|
614
615
|
var TONE_ATTR = "data-ohw-tone";
|
|
615
616
|
var TONE_FIX_ATTR = "data-ohw-tone-fix";
|
|
617
|
+
var TONE_INK_ATTR = "data-ohw-tone-ink";
|
|
616
618
|
var TONE_CHANGE_EVENT = "ohw:tone-change";
|
|
617
619
|
var IMAGE_COVER_RATIO = 0.8;
|
|
618
620
|
var SURFACE_MIN_PX = 24;
|
|
@@ -629,7 +631,6 @@ var MEASURING_ATTR = "data-ohw-tone-measuring";
|
|
|
629
631
|
var TONE_FIX_LINE_ATTR = "data-ohw-tone-fix-line";
|
|
630
632
|
var INK_FIX_STYLE_ID = "ohw-tone-ink-fix";
|
|
631
633
|
var INK_MIN_CONTRAST = 3;
|
|
632
|
-
var IMAGE_TEXT_MIN_CONTRAST = 3;
|
|
633
634
|
var NEVER_SURFACE = /* @__PURE__ */ new Set(["IMG", "SVG", "VIDEO", "CANVAS", "IFRAME", "PICTURE", "PATH", "SCRIPT", "STYLE"]);
|
|
634
635
|
var clamp01 = (n) => Math.min(1, Math.max(0, n));
|
|
635
636
|
function num(raw, percentOf = 1) {
|
|
@@ -1169,28 +1170,6 @@ var TEXT_SPOTS = [
|
|
|
1169
1170
|
[1 / 2, 3 / 4],
|
|
1170
1171
|
[5 / 6, 3 / 4]
|
|
1171
1172
|
];
|
|
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
1173
|
function glyphBox(el) {
|
|
1195
1174
|
try {
|
|
1196
1175
|
const range = el.ownerDocument?.createRange?.();
|
|
@@ -1219,17 +1198,42 @@ function spotsOf(box, at) {
|
|
|
1219
1198
|
}
|
|
1220
1199
|
return spots;
|
|
1221
1200
|
}
|
|
1222
|
-
function
|
|
1223
|
-
|
|
1224
|
-
const
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1201
|
+
function fixInks(doc) {
|
|
1202
|
+
const view = doc?.defaultView;
|
|
1203
|
+
const root = doc?.documentElement;
|
|
1204
|
+
const read = (names, fallback) => {
|
|
1205
|
+
if (!view || !root) return fallback;
|
|
1206
|
+
let style;
|
|
1207
|
+
try {
|
|
1208
|
+
style = view.getComputedStyle(root);
|
|
1209
|
+
} catch {
|
|
1210
|
+
return fallback;
|
|
1211
|
+
}
|
|
1212
|
+
for (const name of names) {
|
|
1213
|
+
const parsed = parseCssColor(style.getPropertyValue(name).trim());
|
|
1214
|
+
if (parsed) return parsed;
|
|
1215
|
+
}
|
|
1216
|
+
return fallback;
|
|
1217
|
+
};
|
|
1218
|
+
return {
|
|
1219
|
+
dark: read(["--ohw-brand-dark", "--color-dark"], { r: 12, g: 10, b: 9, a: 1 }),
|
|
1220
|
+
light: read(["--ohw-brand-light", "--color-light"], WHITE)
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
function betterInkSide(spots, inks) {
|
|
1224
|
+
return worstContrast(inks.dark, spots) >= worstContrast(inks.light, spots) ? "light" : "dark";
|
|
1225
|
+
}
|
|
1226
|
+
function isBetterOption(text, spots, inks, side) {
|
|
1227
|
+
const winner = side === "light" ? inks.dark : inks.light;
|
|
1228
|
+
const loser = side === "light" ? inks.light : inks.dark;
|
|
1229
|
+
const seen = compositeColor(text, spots[0]);
|
|
1230
|
+
const like = contrastRatioOf(seen, winner) <= contrastRatioOf(seen, loser);
|
|
1231
|
+
return like && worstContrast(text, spots) >= worstContrast(loser, spots);
|
|
1232
|
+
}
|
|
1233
|
+
function fixTextAgainst(el, text, spots, inks) {
|
|
1234
|
+
if (!text || spots.length === 0) return;
|
|
1235
|
+
const side = betterInkSide(spots, inks);
|
|
1236
|
+
if (!isBetterOption(text, spots, inks, side)) el.setAttribute(TONE_FIX_ATTR, side);
|
|
1233
1237
|
}
|
|
1234
1238
|
var KEYED_TEXT_SELECTOR = "[data-ohw-key]:not([data-ohw-editable])";
|
|
1235
1239
|
function hasOwnText(el) {
|
|
@@ -1243,8 +1247,7 @@ function hiddenWithin(deps, el, stop) {
|
|
|
1243
1247
|
}
|
|
1244
1248
|
return false;
|
|
1245
1249
|
}
|
|
1246
|
-
function fixTextContrast(deps, section, resolved, imageContexts, pending) {
|
|
1247
|
-
let inks = null;
|
|
1250
|
+
function fixTextContrast(deps, section, resolved, imageContexts, pending, inks) {
|
|
1248
1251
|
const texts = new Set(Array.from(section.querySelectorAll(TEXT_SELECTOR)));
|
|
1249
1252
|
const keyed = /* @__PURE__ */ new Set();
|
|
1250
1253
|
for (const el of Array.from(section.querySelectorAll(KEYED_TEXT_SELECTOR))) {
|
|
@@ -1267,15 +1270,19 @@ function fixTextContrast(deps, section, resolved, imageContexts, pending) {
|
|
|
1267
1270
|
if (had) el.removeAttribute(TONE_FIX_ATTR);
|
|
1268
1271
|
if (imageAt && !isEditorBackground(context)) {
|
|
1269
1272
|
if (!hasPickedColour(el, context)) {
|
|
1270
|
-
|
|
1271
|
-
fixTextOnImage(el, parseCssColor(deps.style(el).color), glyphBox(el) ?? deps.rect(el), imageAt, inks);
|
|
1273
|
+
fixTextAgainst(el, parseCssColor(deps.style(el).color), spotsOf(glyphBox(el) ?? deps.rect(el), imageAt), inks);
|
|
1272
1274
|
}
|
|
1273
1275
|
continue;
|
|
1274
1276
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1277
|
+
fixTextAgainst(el, parseCssColor(deps.style(el).color), [bg], inks);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
function writeEditorInks(section, resolved, inks) {
|
|
1281
|
+
for (const stale of [section, ...Array.from(section.querySelectorAll(`[${TONE_INK_ATTR}]`))]) {
|
|
1282
|
+
if (!isEditorBackground(stale) || !resolved.has(stale)) stale.removeAttribute(TONE_INK_ATTR);
|
|
1283
|
+
}
|
|
1284
|
+
for (const [el, color] of resolved) {
|
|
1285
|
+
if (isEditorBackground(el)) el.setAttribute(TONE_INK_ATTR, betterInkSide([color], inks));
|
|
1279
1286
|
}
|
|
1280
1287
|
}
|
|
1281
1288
|
function pickedButtonInks(doc) {
|
|
@@ -1364,7 +1371,6 @@ function fixOverlayText(deps, doc) {
|
|
|
1364
1371
|
if (roots.length === 0) return;
|
|
1365
1372
|
const photoSections = topSections(doc).filter((s) => sectionPhotos.has(s));
|
|
1366
1373
|
const boxes = new Map(photoSections.map((s) => [s, deps.rect(s)]));
|
|
1367
|
-
let inks = null;
|
|
1368
1374
|
for (const root of roots) {
|
|
1369
1375
|
const items = [];
|
|
1370
1376
|
for (const el of Array.from(root.querySelectorAll(TEXT_SELECTOR))) {
|
|
@@ -1386,8 +1392,7 @@ function fixOverlayText(deps, doc) {
|
|
|
1386
1392
|
const spots = spotsOf(box, photo);
|
|
1387
1393
|
if (text && spots.length > 0) items.push({ el, text, spots, line: underlineOf(deps, el, root) });
|
|
1388
1394
|
}
|
|
1389
|
-
|
|
1390
|
-
fixBarInk(items, inks);
|
|
1395
|
+
fixBarInk(items, fixInks(doc));
|
|
1391
1396
|
for (const item of items) {
|
|
1392
1397
|
const fix = item.el.getAttribute(TONE_FIX_ATTR);
|
|
1393
1398
|
if (fix) item.line?.setAttribute(TONE_FIX_LINE_ATTR, fix);
|
|
@@ -1445,25 +1450,11 @@ function underlineOf(deps, el, root) {
|
|
|
1445
1450
|
return null;
|
|
1446
1451
|
}
|
|
1447
1452
|
function fixBarInk(items, inks) {
|
|
1448
|
-
if (
|
|
1449
|
-
const
|
|
1450
|
-
|
|
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";
|
|
1453
|
+
if (items.length === 0) return;
|
|
1454
|
+
const spots = items.flatMap((item) => item.spots);
|
|
1455
|
+
const side = betterInkSide(spots, inks);
|
|
1464
1456
|
for (const item of items) {
|
|
1465
|
-
if (
|
|
1466
|
-
item.el.setAttribute(TONE_FIX_ATTR, fix);
|
|
1457
|
+
if (!isBetterOption(item.text, spots, inks, side)) item.el.setAttribute(TONE_FIX_ATTR, side);
|
|
1467
1458
|
}
|
|
1468
1459
|
}
|
|
1469
1460
|
function computeSection(deps, section, onReady) {
|
|
@@ -1551,7 +1542,9 @@ function computeSection(deps, section, onReady) {
|
|
|
1551
1542
|
for (const stale of Array.from(section.querySelectorAll(`[${TONE_ATTR}]`))) {
|
|
1552
1543
|
if (!written.has(stale) && !stale.hasAttribute(OVERLAY_TONE_ATTR)) stale.removeAttribute(TONE_ATTR);
|
|
1553
1544
|
}
|
|
1554
|
-
|
|
1545
|
+
const inks = fixInks(section.ownerDocument);
|
|
1546
|
+
writeEditorInks(section, resolved, inks);
|
|
1547
|
+
fixTextContrast(deps, section, resolved, imageContexts, pending, inks);
|
|
1555
1548
|
fixButtonInk(deps, section, painted);
|
|
1556
1549
|
}
|
|
1557
1550
|
function topSections(root) {
|
|
@@ -7432,8 +7425,8 @@ function styleSheetCss() {
|
|
|
7432
7425
|
const lightText = "var(--ohw-brand-light, var(--color-light, #FFFFFF))";
|
|
7433
7426
|
const darkText = "var(--ohw-brand-dark, var(--color-dark, #0C0A09))";
|
|
7434
7427
|
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; }`
|
|
7428
|
+
`:is([data-ohw-style-bg], [data-ohw-style-bgcolor])[data-ohw-tone-ink="dark"], [data-ohw-tone-fix="dark"] { color: ${lightText} !important; }`,
|
|
7429
|
+
`:is([data-ohw-style-bg], [data-ohw-style-bgcolor])[data-ohw-tone-ink="light"], [data-ohw-tone-fix="light"] { color: ${darkText} !important; }`
|
|
7437
7430
|
);
|
|
7438
7431
|
rules.push(
|
|
7439
7432
|
`[data-ohw-style-distribution="space-between"] { display: flex !important; flex-direction: column; justify-content: space-between; }`,
|
|
@@ -8601,7 +8594,9 @@ var LEGACY_BRAND_VAR_NAMES = [
|
|
|
8601
8594
|
"text-muted",
|
|
8602
8595
|
"surface",
|
|
8603
8596
|
"border",
|
|
8604
|
-
"on-primary"
|
|
8597
|
+
"on-primary",
|
|
8598
|
+
"on-primary-muted",
|
|
8599
|
+
"on-primary-faint"
|
|
8605
8600
|
].map((role) => `--brand-${role}`);
|
|
8606
8601
|
var FONT_VARS = {
|
|
8607
8602
|
heading: ["--font-heading", "--font-display", "--brand-font-heading"],
|
|
@@ -8728,6 +8723,7 @@ function brandColorVars(palette) {
|
|
|
8728
8723
|
const surface = mix(light, 95, dark);
|
|
8729
8724
|
const border = mix(light, 85, dark);
|
|
8730
8725
|
const muted = mix(dark, 62, light);
|
|
8726
|
+
const onPrimary = onPrimaryInk(primary, light, dark);
|
|
8731
8727
|
return {
|
|
8732
8728
|
[`${BRAND_VAR_PREFIX}primary`]: primary,
|
|
8733
8729
|
[`${BRAND_VAR_PREFIX}accent`]: accent,
|
|
@@ -8744,11 +8740,21 @@ function brandColorVars(palette) {
|
|
|
8744
8740
|
"--brand-text-muted": muted,
|
|
8745
8741
|
"--brand-surface": surface,
|
|
8746
8742
|
"--brand-border": border,
|
|
8747
|
-
//
|
|
8748
|
-
//
|
|
8749
|
-
|
|
8743
|
+
// Text on anything painted Primary (buttons, bands, Meridien's service cards): whichever of
|
|
8744
|
+
// Light and Dark reads better on it. Hard-wiring Light put white on a pale pink Primary.
|
|
8745
|
+
// Muted and faint are template literals (cream at 75% / 55%) the kit has to follow too.
|
|
8746
|
+
"--brand-on-primary": onPrimary,
|
|
8747
|
+
"--brand-on-primary-muted": `color-mix(in srgb, ${onPrimary} 75%, transparent)`,
|
|
8748
|
+
"--brand-on-primary-faint": `color-mix(in srgb, ${onPrimary} 55%, transparent)`
|
|
8750
8749
|
};
|
|
8751
8750
|
}
|
|
8751
|
+
function onPrimaryInk(primary, light, dark) {
|
|
8752
|
+
const p = parseCssColor(primary);
|
|
8753
|
+
const l = parseCssColor(light);
|
|
8754
|
+
const d = parseCssColor(dark);
|
|
8755
|
+
if (!p || !l || !d) return light;
|
|
8756
|
+
return contrastRatioOf(d, p) >= contrastRatioOf(l, p) ? dark : light;
|
|
8757
|
+
}
|
|
8752
8758
|
function isButtonStyle(value) {
|
|
8753
8759
|
if (!value || typeof value !== "object") return false;
|
|
8754
8760
|
const v = value;
|
|
@@ -19417,7 +19423,7 @@ function apiBase() {
|
|
|
19417
19423
|
function bridgeVersion() {
|
|
19418
19424
|
try {
|
|
19419
19425
|
if (true) {
|
|
19420
|
-
return "0.1.174-next.
|
|
19426
|
+
return "0.1.174-next.464";
|
|
19421
19427
|
}
|
|
19422
19428
|
} catch {
|
|
19423
19429
|
}
|
|
@@ -19431,7 +19437,7 @@ function stampBridgeVersionOnDocument() {
|
|
|
19431
19437
|
return;
|
|
19432
19438
|
}
|
|
19433
19439
|
try {
|
|
19434
|
-
const v = true ? "0.1.174-next.
|
|
19440
|
+
const v = true ? "0.1.174-next.464" : "";
|
|
19435
19441
|
if (v) {
|
|
19436
19442
|
document.documentElement.setAttribute("data-ohw-bridge-version", v);
|
|
19437
19443
|
window.__OHW_BRIDGE_VERSION__ = v;
|
|
@@ -34816,7 +34822,7 @@ function OhhwellsBridge() {
|
|
|
34816
34822
|
postToParent2({
|
|
34817
34823
|
type: "ow:ready",
|
|
34818
34824
|
version: "1",
|
|
34819
|
-
bridgeVersion: "0.1.174-next.
|
|
34825
|
+
bridgeVersion: "0.1.174-next.464",
|
|
34820
34826
|
path: pathname,
|
|
34821
34827
|
nodes: collectEditableNodes(editContentRef.current),
|
|
34822
34828
|
sections
|
|
@@ -36265,6 +36271,7 @@ function EmptySection({ title, homeHref = "/", eyebrowKey, titleKey, subtitleKey
|
|
|
36265
36271
|
mountBackgroundTone,
|
|
36266
36272
|
mountLogoTonePick,
|
|
36267
36273
|
nextViableSlide,
|
|
36274
|
+
onPrimaryInk,
|
|
36268
36275
|
parseAiFooterState,
|
|
36269
36276
|
parseAiSectionsState,
|
|
36270
36277
|
parseCssColor,
|