@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.cjs
CHANGED
|
@@ -1522,6 +1522,52 @@ function assignmentFor(el, content, tokens) {
|
|
|
1522
1522
|
function labelElement(el) {
|
|
1523
1523
|
return el.querySelector('[data-ohw-editable="text"], [data-ohw-editable="plain"]') ?? (el.matches('[data-ohw-editable="text"], [data-ohw-editable="plain"]') ? el : null);
|
|
1524
1524
|
}
|
|
1525
|
+
var BRAND_TRACK_PRECEDENCE = {
|
|
1526
|
+
background: ["primary", "accent", "background", "surface", "on-primary", "text", "border", "text-muted"],
|
|
1527
|
+
color: ["on-primary", "text", "primary", "accent", "text-muted", "background", "surface", "border"],
|
|
1528
|
+
borderColor: ["border", "primary", "accent", "text", "on-primary", "background", "surface", "text-muted"]
|
|
1529
|
+
};
|
|
1530
|
+
var FONT_TRACK_VARS = ["--font-body", "--font-heading", "--font-display", "--brand-font-body", "--brand-font-heading"];
|
|
1531
|
+
function readRootVar(doc, name) {
|
|
1532
|
+
const root = doc.documentElement;
|
|
1533
|
+
return root.style.getPropertyValue(name).trim() || getComputedStyle(root).getPropertyValue(name).trim();
|
|
1534
|
+
}
|
|
1535
|
+
function sameColor(a, b) {
|
|
1536
|
+
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;
|
|
1537
|
+
}
|
|
1538
|
+
function brandTrackedColor(doc, color, roles) {
|
|
1539
|
+
if (!color || color.includes("var(")) return color;
|
|
1540
|
+
const parsed = parseColor(color);
|
|
1541
|
+
if (!parsed || isTransparent(parsed)) return color;
|
|
1542
|
+
for (const role of roles) {
|
|
1543
|
+
const name = `--brand-${role}`;
|
|
1544
|
+
const token = parseColor(readRootVar(doc, name));
|
|
1545
|
+
if (token && !isTransparent(token) && sameColor(parsed, token)) return `var(${name}, ${color})`;
|
|
1546
|
+
}
|
|
1547
|
+
return color;
|
|
1548
|
+
}
|
|
1549
|
+
function brandTrackedChrome(doc, chrome) {
|
|
1550
|
+
return {
|
|
1551
|
+
...chrome,
|
|
1552
|
+
background: brandTrackedColor(doc, chrome.background, BRAND_TRACK_PRECEDENCE.background),
|
|
1553
|
+
color: brandTrackedColor(doc, chrome.color, BRAND_TRACK_PRECEDENCE.color),
|
|
1554
|
+
borderColor: brandTrackedColor(doc, chrome.borderColor, BRAND_TRACK_PRECEDENCE.borderColor)
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
function firstFamily(stack) {
|
|
1558
|
+
const first = stack.split(",")[0]?.trim() ?? "";
|
|
1559
|
+
return first.replace(/^['"]|['"]$/g, "").toLowerCase();
|
|
1560
|
+
}
|
|
1561
|
+
function brandTrackedFontFamily(doc, stack) {
|
|
1562
|
+
if (!stack || stack.includes("var(")) return stack;
|
|
1563
|
+
const family = firstFamily(stack);
|
|
1564
|
+
if (!family) return stack;
|
|
1565
|
+
for (const name of FONT_TRACK_VARS) {
|
|
1566
|
+
const raw = readRootVar(doc, name);
|
|
1567
|
+
if (raw && firstFamily(raw) === family) return `var(${name}, ${stack})`;
|
|
1568
|
+
}
|
|
1569
|
+
return stack;
|
|
1570
|
+
}
|
|
1525
1571
|
var paintLockByEl = /* @__PURE__ */ new WeakMap();
|
|
1526
1572
|
var paintObserverByEl = /* @__PURE__ */ new WeakMap();
|
|
1527
1573
|
var paintingButton = false;
|
|
@@ -1548,7 +1594,7 @@ function paintButtonChrome(el, assignment, tokens) {
|
|
|
1548
1594
|
el.style.borderRadius = px(origin.size.borderRadius);
|
|
1549
1595
|
el.style.gap = geometry.gap;
|
|
1550
1596
|
el.style.height = px(geometry.height);
|
|
1551
|
-
el.style.fontFamily = typography.fontFamily;
|
|
1597
|
+
el.style.fontFamily = brandTrackedFontFamily(el.ownerDocument, typography.fontFamily);
|
|
1552
1598
|
el.style.fontWeight = typography.fontWeight;
|
|
1553
1599
|
el.style.letterSpacing = typography.letterSpacing;
|
|
1554
1600
|
el.style.textTransform = typography.textTransform;
|
|
@@ -1577,9 +1623,18 @@ function paintedTokensOf(el) {
|
|
|
1577
1623
|
return paintLockByEl.get(el)?.tokens ?? null;
|
|
1578
1624
|
}
|
|
1579
1625
|
function applyButtonStyle(el, assignment, tokens) {
|
|
1580
|
-
|
|
1626
|
+
const doc = el.ownerDocument;
|
|
1627
|
+
const tracked = {
|
|
1628
|
+
...tokens,
|
|
1629
|
+
variants: {
|
|
1630
|
+
primary: brandTrackedChrome(doc, tokens.variants.primary),
|
|
1631
|
+
secondary: brandTrackedChrome(doc, tokens.variants.secondary),
|
|
1632
|
+
ghost: brandTrackedChrome(doc, tokens.variants.ghost)
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
paintLockByEl.set(el, { assignment, tokens: tracked });
|
|
1581
1636
|
paintingButton = true;
|
|
1582
|
-
paintButtonChrome(el, assignment,
|
|
1637
|
+
paintButtonChrome(el, assignment, tracked);
|
|
1583
1638
|
paintingButton = false;
|
|
1584
1639
|
guardTemplateHover(el);
|
|
1585
1640
|
}
|
|
@@ -7060,8 +7115,8 @@ function applyBrandToDom(kit) {
|
|
|
7060
7115
|
if (kit.fonts) {
|
|
7061
7116
|
appliedFonts = applyFonts ? kit.fonts : null;
|
|
7062
7117
|
}
|
|
7118
|
+
for (const name of BUTTON_VAR_NAMES) root.style.removeProperty(name);
|
|
7063
7119
|
if (kit.buttons) {
|
|
7064
|
-
for (const name of BUTTON_VAR_NAMES) root.style.removeProperty(name);
|
|
7065
7120
|
for (const [name, value] of Object.entries(buttonStyleVars({ ...kit, buttons: kit.buttons }))) root.style.setProperty(name, value);
|
|
7066
7121
|
}
|
|
7067
7122
|
syncButtonRules(kit.buttons ? kit : null);
|
|
@@ -10462,7 +10517,7 @@ function isChromeSection2(el) {
|
|
|
10462
10517
|
if (CHROME_SECTION_IDS.has(el.getAttribute("data-ohw-section") ?? "")) return true;
|
|
10463
10518
|
return el.tagName === "HEADER" || el.tagName === "FOOTER";
|
|
10464
10519
|
}
|
|
10465
|
-
function
|
|
10520
|
+
function readRootVar2(name) {
|
|
10466
10521
|
if (typeof document === "undefined") return "";
|
|
10467
10522
|
return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
|
|
10468
10523
|
}
|
|
@@ -10502,14 +10557,14 @@ function humanizeFontFamily(name) {
|
|
|
10502
10557
|
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());
|
|
10503
10558
|
}
|
|
10504
10559
|
function readFontVar(name) {
|
|
10505
|
-
return humanizeFontFamily(primaryFontFamily(
|
|
10560
|
+
return humanizeFontFamily(primaryFontFamily(readRootVar2(name)));
|
|
10506
10561
|
}
|
|
10507
10562
|
function deriveBrandOverride() {
|
|
10508
|
-
const dark =
|
|
10509
|
-
const primary =
|
|
10510
|
-
const light =
|
|
10563
|
+
const dark = readRootVar2("--ohw-brand-dark");
|
|
10564
|
+
const primary = readRootVar2("--ohw-brand-primary");
|
|
10565
|
+
const light = readRootVar2("--ohw-brand-light");
|
|
10511
10566
|
if (!dark || !primary || !light) return null;
|
|
10512
|
-
const accent =
|
|
10567
|
+
const accent = readRootVar2("--ohw-brand-accent");
|
|
10513
10568
|
const heading = readFontVar("--font-heading") || readFontVar("--font-display");
|
|
10514
10569
|
const body = readFontVar("--font-body");
|
|
10515
10570
|
return {
|
|
@@ -10521,11 +10576,11 @@ function deriveBrandOverride() {
|
|
|
10521
10576
|
};
|
|
10522
10577
|
}
|
|
10523
10578
|
function deriveTemplateBrandLive() {
|
|
10524
|
-
const primary =
|
|
10525
|
-
const dark =
|
|
10526
|
-
const light =
|
|
10579
|
+
const primary = readRootVar2("--brand-primary") || readRootVar2("--color-primary");
|
|
10580
|
+
const dark = readRootVar2("--brand-text") || readRootVar2("--color-dark");
|
|
10581
|
+
const light = readRootVar2("--brand-background") || readRootVar2("--color-light");
|
|
10527
10582
|
if (!dark || !primary || !light) return null;
|
|
10528
|
-
const accent =
|
|
10583
|
+
const accent = readRootVar2("--brand-accent") || readRootVar2("--color-accent");
|
|
10529
10584
|
const heading = readFontVar("--brand-font-heading") || readFontVar("--font-heading") || readFontVar("--font-display");
|
|
10530
10585
|
const body = readFontVar("--brand-font-body") || readFontVar("--font-body");
|
|
10531
10586
|
return {
|
|
@@ -31343,7 +31398,7 @@ function OhhwellsBridge() {
|
|
|
31343
31398
|
postToParent2({
|
|
31344
31399
|
type: "ow:ready",
|
|
31345
31400
|
version: "1",
|
|
31346
|
-
bridgeVersion: "0.1.
|
|
31401
|
+
bridgeVersion: "0.1.143",
|
|
31347
31402
|
path: pathname,
|
|
31348
31403
|
nodes: collectEditableNodes(editContentRef.current),
|
|
31349
31404
|
sections
|