@ohhwells/bridge 0.1.143 → 0.1.144
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 +70 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1428,6 +1428,52 @@ function assignmentFor(el, content, tokens) {
|
|
|
1428
1428
|
function labelElement(el) {
|
|
1429
1429
|
return el.querySelector('[data-ohw-editable="text"], [data-ohw-editable="plain"]') ?? (el.matches('[data-ohw-editable="text"], [data-ohw-editable="plain"]') ? el : null);
|
|
1430
1430
|
}
|
|
1431
|
+
var BRAND_TRACK_PRECEDENCE = {
|
|
1432
|
+
background: ["primary", "accent", "background", "surface", "on-primary", "text", "border", "text-muted"],
|
|
1433
|
+
color: ["on-primary", "text", "primary", "accent", "text-muted", "background", "surface", "border"],
|
|
1434
|
+
borderColor: ["border", "primary", "accent", "text", "on-primary", "background", "surface", "text-muted"]
|
|
1435
|
+
};
|
|
1436
|
+
var FONT_TRACK_VARS = ["--font-body", "--font-heading", "--font-display", "--brand-font-body", "--brand-font-heading"];
|
|
1437
|
+
function readRootVar(doc, name) {
|
|
1438
|
+
const root = doc.documentElement;
|
|
1439
|
+
return root.style.getPropertyValue(name).trim() || getComputedStyle(root).getPropertyValue(name).trim();
|
|
1440
|
+
}
|
|
1441
|
+
function sameColor(a, b) {
|
|
1442
|
+
return Math.round(a.r) === Math.round(b.r) && Math.round(a.g) === Math.round(b.g) && Math.round(a.b) === Math.round(b.b) && Math.abs(a.a - b.a) < 0.02;
|
|
1443
|
+
}
|
|
1444
|
+
function brandTrackedColor(doc, color, roles) {
|
|
1445
|
+
if (!color || color.includes("var(")) return color;
|
|
1446
|
+
const parsed = parseColor(color);
|
|
1447
|
+
if (!parsed || isTransparent(parsed)) return color;
|
|
1448
|
+
for (const role of roles) {
|
|
1449
|
+
const name = `--brand-${role}`;
|
|
1450
|
+
const token = parseColor(readRootVar(doc, name));
|
|
1451
|
+
if (token && !isTransparent(token) && sameColor(parsed, token)) return `var(${name}, ${color})`;
|
|
1452
|
+
}
|
|
1453
|
+
return color;
|
|
1454
|
+
}
|
|
1455
|
+
function brandTrackedChrome(doc, chrome) {
|
|
1456
|
+
return {
|
|
1457
|
+
...chrome,
|
|
1458
|
+
background: brandTrackedColor(doc, chrome.background, BRAND_TRACK_PRECEDENCE.background),
|
|
1459
|
+
color: brandTrackedColor(doc, chrome.color, BRAND_TRACK_PRECEDENCE.color),
|
|
1460
|
+
borderColor: brandTrackedColor(doc, chrome.borderColor, BRAND_TRACK_PRECEDENCE.borderColor)
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
function firstFamily(stack) {
|
|
1464
|
+
const first = stack.split(",")[0]?.trim() ?? "";
|
|
1465
|
+
return first.replace(/^['"]|['"]$/g, "").toLowerCase();
|
|
1466
|
+
}
|
|
1467
|
+
function brandTrackedFontFamily(doc, stack) {
|
|
1468
|
+
if (!stack || stack.includes("var(")) return stack;
|
|
1469
|
+
const family = firstFamily(stack);
|
|
1470
|
+
if (!family) return stack;
|
|
1471
|
+
for (const name of FONT_TRACK_VARS) {
|
|
1472
|
+
const raw = readRootVar(doc, name);
|
|
1473
|
+
if (raw && firstFamily(raw) === family) return `var(${name}, ${stack})`;
|
|
1474
|
+
}
|
|
1475
|
+
return stack;
|
|
1476
|
+
}
|
|
1431
1477
|
var paintLockByEl = /* @__PURE__ */ new WeakMap();
|
|
1432
1478
|
var paintObserverByEl = /* @__PURE__ */ new WeakMap();
|
|
1433
1479
|
var paintingButton = false;
|
|
@@ -1454,7 +1500,7 @@ function paintButtonChrome(el, assignment, tokens) {
|
|
|
1454
1500
|
el.style.borderRadius = px(origin.size.borderRadius);
|
|
1455
1501
|
el.style.gap = geometry.gap;
|
|
1456
1502
|
el.style.height = px(geometry.height);
|
|
1457
|
-
el.style.fontFamily = typography.fontFamily;
|
|
1503
|
+
el.style.fontFamily = brandTrackedFontFamily(el.ownerDocument, typography.fontFamily);
|
|
1458
1504
|
el.style.fontWeight = typography.fontWeight;
|
|
1459
1505
|
el.style.letterSpacing = typography.letterSpacing;
|
|
1460
1506
|
el.style.textTransform = typography.textTransform;
|
|
@@ -1483,9 +1529,18 @@ function paintedTokensOf(el) {
|
|
|
1483
1529
|
return paintLockByEl.get(el)?.tokens ?? null;
|
|
1484
1530
|
}
|
|
1485
1531
|
function applyButtonStyle(el, assignment, tokens) {
|
|
1486
|
-
|
|
1532
|
+
const doc = el.ownerDocument;
|
|
1533
|
+
const tracked = {
|
|
1534
|
+
...tokens,
|
|
1535
|
+
variants: {
|
|
1536
|
+
primary: brandTrackedChrome(doc, tokens.variants.primary),
|
|
1537
|
+
secondary: brandTrackedChrome(doc, tokens.variants.secondary),
|
|
1538
|
+
ghost: brandTrackedChrome(doc, tokens.variants.ghost)
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
paintLockByEl.set(el, { assignment, tokens: tracked });
|
|
1487
1542
|
paintingButton = true;
|
|
1488
|
-
paintButtonChrome(el, assignment,
|
|
1543
|
+
paintButtonChrome(el, assignment, tracked);
|
|
1489
1544
|
paintingButton = false;
|
|
1490
1545
|
guardTemplateHover(el);
|
|
1491
1546
|
}
|
|
@@ -6966,8 +7021,8 @@ function applyBrandToDom(kit) {
|
|
|
6966
7021
|
if (kit.fonts) {
|
|
6967
7022
|
appliedFonts = applyFonts ? kit.fonts : null;
|
|
6968
7023
|
}
|
|
7024
|
+
for (const name of BUTTON_VAR_NAMES) root.style.removeProperty(name);
|
|
6969
7025
|
if (kit.buttons) {
|
|
6970
|
-
for (const name of BUTTON_VAR_NAMES) root.style.removeProperty(name);
|
|
6971
7026
|
for (const [name, value] of Object.entries(buttonStyleVars({ ...kit, buttons: kit.buttons }))) root.style.setProperty(name, value);
|
|
6972
7027
|
}
|
|
6973
7028
|
syncButtonRules(kit.buttons ? kit : null);
|
|
@@ -10368,7 +10423,7 @@ function isChromeSection2(el) {
|
|
|
10368
10423
|
if (CHROME_SECTION_IDS.has(el.getAttribute("data-ohw-section") ?? "")) return true;
|
|
10369
10424
|
return el.tagName === "HEADER" || el.tagName === "FOOTER";
|
|
10370
10425
|
}
|
|
10371
|
-
function
|
|
10426
|
+
function readRootVar2(name) {
|
|
10372
10427
|
if (typeof document === "undefined") return "";
|
|
10373
10428
|
return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
10374
10429
|
}
|
|
@@ -10408,14 +10463,14 @@ function humanizeFontFamily(name) {
|
|
|
10408
10463
|
return name.replace(/^__/, "").replace(/_[0-9a-f]{6}$/i, "").replace(/_/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").trim().replace(/\s+/g, " ").replace(/(^|\s)([a-z])/g, (_, sep, c) => sep + c.toUpperCase());
|
|
10409
10464
|
}
|
|
10410
10465
|
function readFontVar(name) {
|
|
10411
|
-
return humanizeFontFamily(primaryFontFamily(
|
|
10466
|
+
return humanizeFontFamily(primaryFontFamily(readRootVar2(name)));
|
|
10412
10467
|
}
|
|
10413
10468
|
function deriveBrandOverride() {
|
|
10414
|
-
const dark =
|
|
10415
|
-
const primary =
|
|
10416
|
-
const light =
|
|
10469
|
+
const dark = readRootVar2("--ohw-brand-dark");
|
|
10470
|
+
const primary = readRootVar2("--ohw-brand-primary");
|
|
10471
|
+
const light = readRootVar2("--ohw-brand-light");
|
|
10417
10472
|
if (!dark || !primary || !light) return null;
|
|
10418
|
-
const accent =
|
|
10473
|
+
const accent = readRootVar2("--ohw-brand-accent");
|
|
10419
10474
|
const heading = readFontVar("--font-heading") || readFontVar("--font-display");
|
|
10420
10475
|
const body = readFontVar("--font-body");
|
|
10421
10476
|
return {
|
|
@@ -10427,11 +10482,11 @@ function deriveBrandOverride() {
|
|
|
10427
10482
|
};
|
|
10428
10483
|
}
|
|
10429
10484
|
function deriveTemplateBrandLive() {
|
|
10430
|
-
const primary =
|
|
10431
|
-
const dark =
|
|
10432
|
-
const light =
|
|
10485
|
+
const primary = readRootVar2("--brand-primary") || readRootVar2("--color-primary");
|
|
10486
|
+
const dark = readRootVar2("--brand-text") || readRootVar2("--color-dark");
|
|
10487
|
+
const light = readRootVar2("--brand-background") || readRootVar2("--color-light");
|
|
10433
10488
|
if (!dark || !primary || !light) return null;
|
|
10434
|
-
const accent =
|
|
10489
|
+
const accent = readRootVar2("--brand-accent") || readRootVar2("--color-accent");
|
|
10435
10490
|
const heading = readFontVar("--brand-font-heading") || readFontVar("--font-heading") || readFontVar("--font-display");
|
|
10436
10491
|
const body = readFontVar("--brand-font-body") || readFontVar("--font-body");
|
|
10437
10492
|
return {
|
|
@@ -31255,7 +31310,7 @@ function OhhwellsBridge() {
|
|
|
31255
31310
|
postToParent2({
|
|
31256
31311
|
type: "ow:ready",
|
|
31257
31312
|
version: "1",
|
|
31258
|
-
bridgeVersion: "0.1.
|
|
31313
|
+
bridgeVersion: "0.1.143",
|
|
31259
31314
|
path: pathname,
|
|
31260
31315
|
nodes: collectEditableNodes(editContentRef.current),
|
|
31261
31316
|
sections
|