@bicharts/chart-host 0.6.84 → 0.6.85

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.
@@ -28,6 +28,11 @@ import {
28
28
  trackPress,
29
29
  validRowSet
30
30
  } from "./chunk-IURROJT7.mjs";
31
+ import {
32
+ clipWindowOf,
33
+ fitRenderedChart,
34
+ unpinScrolledAxis
35
+ } from "./chunk-BQFG5HWZ.mjs";
31
36
  import {
32
37
  NA_ISO3,
33
38
  NA_LAT_MAX,
@@ -69,7 +74,6 @@ import {
69
74
  ROW_IDX_ATTR,
70
75
  SEASONAL_MARKERS_DEFAULT,
71
76
  SELECTION_ACTIVE_CLASS,
72
- SNAPSHOT_SVG_ATTR,
73
77
  VALUE_AXIS_BASELINE_DEFAULT,
74
78
  XFILTER_REFRESH_EVENT,
75
79
  chartOwnsTimeline,
@@ -1318,556 +1322,6 @@ function valuePlacementFlag(c) {
1318
1322
  return "place:d3:off" + bucket;
1319
1323
  }
1320
1324
 
1321
- // src/fit.ts
1322
- var SCROLL_SLACK_PX = 8;
1323
- function needsScroll(contentPx, viewportPx, slackPx = SCROLL_SLACK_PX) {
1324
- if (!isFinite(contentPx) || !isFinite(viewportPx)) return false;
1325
- if (contentPx <= 0 || viewportPx <= 0) return false;
1326
- return contentPx - viewportPx > slackPx;
1327
- }
1328
- function contentExtentOf(boxes) {
1329
- if (!boxes || boxes.length === 0) return { w: 0, h: 0, source: "none" };
1330
- const usable = boxes.filter((b) => b && isFinite(b.right) && isFinite(b.bottom) && (b.right > 0 || b.bottom > 0));
1331
- if (usable.length === 0) return { w: 0, h: 0, source: "none" };
1332
- const inFlow = usable.filter((b) => !b.floating);
1333
- const counted = inFlow.length > 0 ? inFlow : usable;
1334
- let w = 0, h = 0;
1335
- for (const b of counted) {
1336
- if (b.right > w) w = b.right;
1337
- if (b.bottom > h) h = b.bottom;
1338
- }
1339
- return { w, h, source: inFlow.length > 0 ? "in-flow" : "all-floating" };
1340
- }
1341
- function scrollFitFor(contentW, contentH, viewportW, viewportH, slackPx = SCROLL_SLACK_PX) {
1342
- return {
1343
- overflowX: needsScroll(contentW, viewportW, slackPx) ? "auto" : "hidden",
1344
- overflowY: needsScroll(contentH, viewportH, slackPx) ? "auto" : "hidden"
1345
- };
1346
- }
1347
- var FIT_CONTENT_SELECTOR = "text, .d3-mark, .d3-legend-mark";
1348
- var PHANTOM_FRACTION = 0.95;
1349
- function isPhantomBox(w, h, refW, refH) {
1350
- return w > refW * PHANTOM_FRACTION || h > refH * PHANTOM_FRACTION;
1351
- }
1352
- var MAX_FRAME_GROW_FACTOR = 20;
1353
- function planFrameGrow(inkBottomPx, elHeightPx, viewBoxH, ctmScale, slackPx = SCROLL_SLACK_PX, maxFactor = MAX_FRAME_GROW_FACTOR) {
1354
- const none = (reason) => ({ grow: false, heightPx: elHeightPx, viewBoxH, reason });
1355
- if (!isFinite(inkBottomPx) || !isFinite(elHeightPx) || elHeightPx <= 0) return none("unmeasurable");
1356
- if (!needsScroll(inkBottomPx, elHeightPx, slackPx)) return none("fits");
1357
- if (inkBottomPx > elHeightPx * maxFactor) return none("beyond-ceiling");
1358
- const heightPx = Math.ceil(inkBottomPx);
1359
- const delta = heightPx - elHeightPx;
1360
- if (!(viewBoxH > 0)) return { grow: true, heightPx, viewBoxH, reason: "grow-no-viewbox" };
1361
- if (!(ctmScale > 0) || !isFinite(ctmScale)) return none("no-scale");
1362
- return { grow: true, heightPx, viewBoxH: viewBoxH + delta / ctmScale, reason: "grow" };
1363
- }
1364
- var AXIS_PIN_MIN_LABELS = 2;
1365
- var AXIS_PIN_BAND_PAD_PX = 2;
1366
- var AXIS_PIN_MAX_BAND_FRACTION = 0.4;
1367
- var AXIS_PIN_TRACK_REACH_PX = 12;
1368
- function isHorizontalLabelRow(boxes) {
1369
- if (!boxes || boxes.length < 2) return false;
1370
- let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
1371
- for (const b of boxes) {
1372
- const cx = (b.left + b.right) / 2, cy = (b.top + b.bottom) / 2;
1373
- if (!isFinite(cx) || !isFinite(cy)) return false;
1374
- if (cx < minX) minX = cx;
1375
- if (cx > maxX) maxX = cx;
1376
- if (cy < minY) minY = cy;
1377
- if (cy > maxY) maxY = cy;
1378
- }
1379
- return maxX - minX > maxY - minY;
1380
- }
1381
- function labelBand(boxes, tracks = [], pad = AXIS_PIN_BAND_PAD_PX, trackReach = AXIS_PIN_TRACK_REACH_PX) {
1382
- if (!boxes || boxes.length === 0) return null;
1383
- let top = Infinity, bottom = -Infinity;
1384
- for (const b of boxes) {
1385
- if (!isFinite(b.top) || !isFinite(b.bottom)) continue;
1386
- if (b.top < top) top = b.top;
1387
- if (b.bottom > bottom) bottom = b.bottom;
1388
- }
1389
- if (!isFinite(top) || !isFinite(bottom) || bottom <= top) return null;
1390
- for (const t of tracks || []) {
1391
- if (!isFinite(t.top) || !isFinite(t.bottom)) continue;
1392
- const gap = t.bottom < top ? top - t.bottom : t.top > bottom ? t.top - bottom : 0;
1393
- if (gap > trackReach) continue;
1394
- if (t.top < top) top = t.top;
1395
- if (t.bottom > bottom) bottom = t.bottom;
1396
- }
1397
- return { top: top - pad, bottom: bottom + pad };
1398
- }
1399
- function planAxisPin(candidates, viewportH, minLabels = AXIS_PIN_MIN_LABELS, maxFraction = AXIS_PIN_MAX_BAND_FRACTION) {
1400
- const none = (reason) => ({ pin: false, index: -1, band: null, reason });
1401
- if (!isFinite(viewportH) || viewportH <= 0) return none("unmeasurable");
1402
- let sawAxis = false, best = null;
1403
- for (const c of candidates || []) {
1404
- if (!c || !c.labels || c.labels.length < minLabels) continue;
1405
- sawAxis = true;
1406
- if (!isHorizontalLabelRow(c.labels)) continue;
1407
- if (!best || c.labels.length > best.labels.length) best = c;
1408
- }
1409
- if (!best) return none(sawAxis ? "vertical-only" : "no-axis");
1410
- const band = labelBand(best.labels, best.tracks || []);
1411
- if (!band) return none("unmeasurable");
1412
- if (band.bottom - band.top > viewportH * maxFraction) return none("band-too-tall");
1413
- return { pin: true, index: best.index, band, reason: "pinned" };
1414
- }
1415
- function axisPinPlacement(band, scrollTop, viewportH) {
1416
- if (!band || !isFinite(band.top) || !isFinite(band.bottom)) return null;
1417
- if (!isFinite(scrollTop) || !isFinite(viewportH) || viewportH <= 0) return null;
1418
- if (band.top < scrollTop) return "top";
1419
- if (band.bottom > scrollTop + viewportH) return "bottom";
1420
- return null;
1421
- }
1422
-
1423
- // src/fitDom.ts
1424
- var FIT_WALK_CAP = 8e3;
1425
- function ctmScaleOf(m) {
1426
- if (!m) return 0;
1427
- const s = Math.hypot(m.a, m.b);
1428
- return isFinite(s) && s > 0 ? s : 0;
1429
- }
1430
- function svgInkReach(svg) {
1431
- try {
1432
- const box2 = svg.getBoundingClientRect();
1433
- if (!(box2.width > 0) || !(box2.height > 0)) return null;
1434
- const els = svg.querySelectorAll(FIT_CONTENT_SELECTOR);
1435
- const clipOf = clipWindowReader(svg);
1436
- let right = -Infinity, bottom = -Infinity, seen = 0;
1437
- for (let i = 0; i < els.length && seen < FIT_WALK_CAP; i++) {
1438
- const r = els[i].getBoundingClientRect();
1439
- if (r.width <= 0 && r.height <= 0) continue;
1440
- if (isPhantomBox(r.width, r.height, box2.width, box2.height)) continue;
1441
- let rr = r.right, rb = r.bottom;
1442
- const clip = clipOf(els[i]);
1443
- if (clip) {
1444
- if (r.left >= clip.right || r.top >= clip.bottom) continue;
1445
- rr = Math.min(rr, clip.right);
1446
- rb = Math.min(rb, clip.bottom);
1447
- }
1448
- seen++;
1449
- if (rr > right) right = rr;
1450
- if (rb > bottom) bottom = rb;
1451
- }
1452
- if (seen === 0) return null;
1453
- return { right: right - box2.left, bottom: bottom - box2.top };
1454
- } catch {
1455
- return null;
1456
- }
1457
- }
1458
- function clipWindowOf(el) {
1459
- try {
1460
- const m = /url\(\s*['"]?#([^'")\s]+)['"]?\s*\)/.exec(el.getAttribute("clip-path") || "");
1461
- const cp = m ? (el.closest("svg") ?? el.ownerDocument).querySelector(`clipPath[id="${m[1].replace(/"/g, '\\"')}"]`) : null;
1462
- const ctm = cp ? el.getScreenCTM?.() : null;
1463
- if (!cp || !ctm || cp.getAttribute("clipPathUnits") === "objectBoundingBox") return null;
1464
- let l = Infinity, t = Infinity, r = -Infinity, b = -Infinity;
1465
- for (let i = 0; i < cp.children.length; i++) {
1466
- const bb = cp.children[i].getBBox?.();
1467
- if (!bb || !(bb.width > 0) || !(bb.height > 0)) continue;
1468
- for (const [x, y] of [[bb.x, bb.y], [bb.x + bb.width, bb.y], [bb.x, bb.y + bb.height], [bb.x + bb.width, bb.y + bb.height]]) {
1469
- const sx = ctm.a * x + ctm.c * y + ctm.e, sy = ctm.b * x + ctm.d * y + ctm.f;
1470
- l = Math.min(l, sx);
1471
- t = Math.min(t, sy);
1472
- r = Math.max(r, sx);
1473
- b = Math.max(b, sy);
1474
- }
1475
- }
1476
- return isFinite(r) && isFinite(b) ? { left: l, top: t, right: r, bottom: b } : null;
1477
- } catch {
1478
- return null;
1479
- }
1480
- }
1481
- function clipWindowReader(svg) {
1482
- const own = /* @__PURE__ */ new Map();
1483
- const windowOf = (el) => {
1484
- if (!own.has(el)) own.set(el, clipWindowOf(el));
1485
- return own.get(el);
1486
- };
1487
- return (el) => {
1488
- let acc = null;
1489
- for (let a = el; a && a !== svg; a = a.parentElement) {
1490
- const w = windowOf(a);
1491
- if (w) acc = acc ? { right: Math.min(acc.right, w.right), bottom: Math.min(acc.bottom, w.bottom) } : w;
1492
- }
1493
- return acc;
1494
- };
1495
- }
1496
- function measureContainerBoxes(c, inkOf) {
1497
- const boxes = [];
1498
- if (!c || !c.children) return boxes;
1499
- const view = c.ownerDocument && c.ownerDocument.defaultView || globalThis;
1500
- const cRect = c.getBoundingClientRect();
1501
- for (let i = 0; i < c.children.length; i++) {
1502
- const el = c.children[i];
1503
- let floating = false;
1504
- try {
1505
- const cs = view.getComputedStyle(el);
1506
- if (cs.display === "none") continue;
1507
- floating = cs.position === "absolute" || cs.position === "fixed";
1508
- } catch {
1509
- }
1510
- const r = el.getBoundingClientRect();
1511
- let right = r.right - cRect.left - c.clientLeft + c.scrollLeft;
1512
- let bottom = r.bottom - cRect.top - c.clientTop + c.scrollTop;
1513
- if (inkOf) {
1514
- try {
1515
- const ink = inkOf(el);
1516
- if (ink) {
1517
- const originX = r.left - cRect.left - c.clientLeft + c.scrollLeft;
1518
- const originY = r.top - cRect.top - c.clientTop + c.scrollTop;
1519
- if (isFinite(ink.right)) right = Math.max(right, originX + ink.right);
1520
- if (isFinite(ink.bottom)) bottom = Math.max(bottom, originY + ink.bottom);
1521
- }
1522
- } catch {
1523
- }
1524
- }
1525
- boxes.push({ right, bottom, floating });
1526
- }
1527
- return boxes;
1528
- }
1529
- function fitReadingFor(lane, c, slackPx = SCROLL_SLACK_PX, inkOf) {
1530
- if (!c) return null;
1531
- const viewW = c.clientWidth, viewH = c.clientHeight;
1532
- if (!(viewW > 0) || !(viewH > 0)) return null;
1533
- const boxes = measureContainerBoxes(c, inkOf);
1534
- const extent = contentExtentOf(boxes);
1535
- const contentW = extent.source === "none" ? c.scrollWidth : extent.w;
1536
- const contentH = extent.source === "none" ? c.scrollHeight : extent.h;
1537
- if (!isFinite(contentW) || !isFinite(contentH)) return null;
1538
- return {
1539
- lane,
1540
- contentW: Math.round(contentW),
1541
- contentH: Math.round(contentH),
1542
- viewW,
1543
- viewH,
1544
- overflowsX: needsScroll(contentW, viewW, slackPx),
1545
- overflowsY: needsScroll(contentH, viewH, slackPx),
1546
- extentSource: extent.source,
1547
- boxes: boxes.length,
1548
- floating: boxes.filter((b) => b.floating).length,
1549
- scrollW: c.scrollWidth,
1550
- scrollH: c.scrollHeight
1551
- };
1552
- }
1553
- var noPin = (reason) => ({ pinned: false, reason, bandPx: 0, axisAt: "", labels: 0, carried: 0, edge: null });
1554
- var CONTAINER_SLOT_AXIS_PIN = "__bicAxisPin";
1555
- var SVG_NS = "http://www.w3.org/2000/svg";
1556
- var AXIS_PIN_MAX_CARRIED = 12;
1557
- function unpinScrolledAxis(container) {
1558
- if (!container) return;
1559
- const st = container[CONTAINER_SLOT_AXIS_PIN];
1560
- if (!st) return;
1561
- try {
1562
- container.removeEventListener("scroll", st.onScroll);
1563
- } catch {
1564
- }
1565
- try {
1566
- if (st.overlay.parentNode) st.overlay.parentNode.removeChild(st.overlay);
1567
- } catch {
1568
- }
1569
- try {
1570
- delete container[CONTAINER_SLOT_AXIS_PIN];
1571
- } catch {
1572
- }
1573
- }
1574
- function textHidden(t, view) {
1575
- if (t.getAttribute("display") === "none" || t.getAttribute("visibility") === "hidden") return true;
1576
- try {
1577
- const cs = view.getComputedStyle(t);
1578
- if (cs && (cs.display === "none" || cs.visibility === "hidden")) return true;
1579
- } catch {
1580
- }
1581
- return false;
1582
- }
1583
- function backdropFill(svg, container, view, svgBox) {
1584
- try {
1585
- const rects = svg.querySelectorAll("rect");
1586
- for (let i = 0; i < rects.length && i < 6; i++) {
1587
- const r = rects[i];
1588
- if (r.closest(".d3-mark")) continue;
1589
- const b = r.getBoundingClientRect();
1590
- if (b.width >= svgBox.width * 0.9 && b.height >= svgBox.height * 0.9) {
1591
- let fill = "";
1592
- try {
1593
- fill = view.getComputedStyle(r).fill || "";
1594
- } catch {
1595
- }
1596
- if (!fill || fill === "none") fill = r.getAttribute("fill") || "";
1597
- if (fill && fill !== "none" && fill !== "transparent") return fill;
1598
- break;
1599
- }
1600
- }
1601
- } catch {
1602
- }
1603
- try {
1604
- let el = container;
1605
- for (let hops = 0; el && hops < 12; hops++, el = el.parentElement) {
1606
- const bg = view.getComputedStyle(el).backgroundColor;
1607
- if (bg && bg !== "transparent" && bg !== "rgba(0, 0, 0, 0)") return bg;
1608
- }
1609
- } catch {
1610
- }
1611
- return "#ffffff";
1612
- }
1613
- function cloneWithChain(el, svg, root) {
1614
- const chain = [];
1615
- let n = el.parentElement;
1616
- while (n && n !== svg) {
1617
- chain.unshift(n);
1618
- n = n.parentElement;
1619
- }
1620
- let parent = root;
1621
- for (const anc of chain) {
1622
- const c = anc.cloneNode(false);
1623
- parent.appendChild(c);
1624
- parent = c;
1625
- }
1626
- parent.appendChild(el.cloneNode(true));
1627
- const ids = root.querySelectorAll("[id]");
1628
- for (let i = 0; i < ids.length; i++) ids[i].removeAttribute("id");
1629
- }
1630
- function pinScrolledAxis(container, svg) {
1631
- unpinScrolledAxis(container);
1632
- if (!container) return noPin("no-container");
1633
- if (!svg) return noPin("no-svg");
1634
- try {
1635
- const doc = svg.ownerDocument;
1636
- const view = doc && doc.defaultView || globalThis;
1637
- const svgBox = svg.getBoundingClientRect();
1638
- if (!(svgBox.width > 0) || !(svgBox.height > 0)) return noPin("unmeasurable");
1639
- const m = typeof svg.getScreenCTM === "function" ? svg.getScreenCTM() : null;
1640
- if (!m || !(m.a > 0) || !(m.d > 0) || !isFinite(m.e) || !isFinite(m.f)) return noPin("no-ctm");
1641
- const viewportH = container.clientHeight;
1642
- if (!(viewportH > 0)) return noPin("unmeasurable");
1643
- const rel = (r) => ({ left: r.left - svgBox.left, top: r.top - svgBox.top, right: r.right - svgBox.left, bottom: r.bottom - svgBox.top });
1644
- const ticks = svg.querySelectorAll(".tick");
1645
- const byAxis = /* @__PURE__ */ new Map();
1646
- for (let i = 0; i < ticks.length; i++) {
1647
- const t = ticks[i];
1648
- if (t.closest("svg") !== svg) continue;
1649
- const p = t.parentElement;
1650
- if (!p) continue;
1651
- const list = byAxis.get(p);
1652
- if (list) list.push(t);
1653
- else byAxis.set(p, [t]);
1654
- }
1655
- const axes = [];
1656
- const cands = [];
1657
- byAxis.forEach((group, axis2) => {
1658
- const labels = [];
1659
- for (const tick of group) {
1660
- const txt = tick.querySelector("text");
1661
- if (!txt || textHidden(txt, view)) continue;
1662
- const r = txt.getBoundingClientRect();
1663
- if (!(r.width > 0) || !(r.height > 0)) continue;
1664
- labels.push(rel(r));
1665
- }
1666
- const tracks = [];
1667
- for (let i = 0; i < axis2.children.length; i++) {
1668
- const ch = axis2.children[i];
1669
- if (ch.tagName.toLowerCase() !== "path" || !(ch.getAttribute("class") || "").split(/\s+/).includes("domain")) continue;
1670
- const r = ch.getBoundingClientRect();
1671
- if (r.width > 0 && r.height <= 4) tracks.push(rel(r));
1672
- }
1673
- cands.push({ index: axes.length, labels, tracks });
1674
- axes.push(axis2);
1675
- });
1676
- const plan = planAxisPin(cands, viewportH);
1677
- if (!plan.pin || !plan.band) return noPin(plan.reason);
1678
- const axis = axes[plan.index];
1679
- const band = { top: Math.max(0, plan.band.top), bottom: Math.min(svgBox.height, plan.band.bottom) };
1680
- const bandPx = band.bottom - band.top;
1681
- if (!(bandPx > 0)) return noPin("unmeasurable");
1682
- const carried = [];
1683
- const texts = svg.querySelectorAll("text");
1684
- for (let i = 0; i < texts.length && carried.length < AXIS_PIN_MAX_CARRIED; i++) {
1685
- const t = texts[i];
1686
- if (t.closest("svg") !== svg) continue;
1687
- if (t.closest(".tick") || t.closest(".d3-mark") || t.closest(".d3-legend-mark")) continue;
1688
- if (axis.contains(t) || textHidden(t, view)) continue;
1689
- const r = rel(t.getBoundingClientRect());
1690
- if (!(r.right > r.left) || !(r.bottom > r.top)) continue;
1691
- if (r.top >= band.top && r.bottom <= band.bottom) carried.push(t);
1692
- }
1693
- const pinSvg = doc.createElementNS(SVG_NS, "svg");
1694
- for (const a of ["font-family", "font-size", "font-weight", "font", "fill", "color", "text-rendering"]) {
1695
- const v = svg.getAttribute(a);
1696
- if (v) pinSvg.setAttribute(a, v);
1697
- }
1698
- const styles = svg.querySelectorAll("style");
1699
- for (let i = 0; i < styles.length; i++) pinSvg.appendChild(styles[i].cloneNode(true));
1700
- const vbX = (svgBox.left - m.e) / m.a, vbY = (svgBox.top + band.top - m.f) / m.d;
1701
- const vbW = svgBox.width / m.a, vbH = bandPx / m.d;
1702
- pinSvg.setAttribute("viewBox", `${vbX} ${vbY} ${vbW} ${vbH}`);
1703
- pinSvg.setAttribute("preserveAspectRatio", "none");
1704
- pinSvg.setAttribute("width", String(svgBox.width));
1705
- pinSvg.setAttribute("height", String(bandPx));
1706
- pinSvg.setAttribute("aria-hidden", "true");
1707
- pinSvg.style.display = "block";
1708
- pinSvg.style.pointerEvents = "none";
1709
- const back = doc.createElementNS(SVG_NS, "rect");
1710
- back.setAttribute("x", String(vbX));
1711
- back.setAttribute("y", String(vbY));
1712
- back.setAttribute("width", String(vbW));
1713
- back.setAttribute("height", String(vbH));
1714
- back.setAttribute("fill", backdropFill(svg, container, view, svgBox));
1715
- pinSvg.appendChild(back);
1716
- cloneWithChain(axis, svg, pinSvg);
1717
- for (const t of carried) cloneWithChain(t, svg, pinSvg);
1718
- const overlay = doc.createElement("div");
1719
- overlay.setAttribute("data-bic-axis-pin", "1");
1720
- const o = overlay.style;
1721
- o.position = "absolute";
1722
- o.margin = "0";
1723
- o.padding = "0";
1724
- o.border = "0";
1725
- o.width = `${svgBox.width}px`;
1726
- o.height = `${bandPx}px`;
1727
- o.overflow = "hidden";
1728
- o.pointerEvents = "none";
1729
- o.zIndex = "3";
1730
- o.display = "none";
1731
- overlay.appendChild(pinSvg);
1732
- try {
1733
- const cs = view.getComputedStyle(container);
1734
- const pos = cs && cs.position || container.style.position;
1735
- if (!pos || pos === "static") container.style.position = "relative";
1736
- } catch {
1737
- container.style.position = container.style.position || "relative";
1738
- }
1739
- const cRect = container.getBoundingClientRect();
1740
- const svgLeft = svgBox.left - cRect.left - container.clientLeft + container.scrollLeft;
1741
- const svgTop = svgBox.top - cRect.top - container.clientTop + container.scrollTop;
1742
- const contentBand = { top: svgTop + band.top, bottom: svgTop + band.bottom };
1743
- const place = () => {
1744
- const st = container.scrollTop, vh = container.clientHeight;
1745
- const edge2 = axisPinPlacement(contentBand, st, vh);
1746
- if (!edge2) {
1747
- o.display = "none";
1748
- return null;
1749
- }
1750
- o.display = "block";
1751
- o.left = `${svgLeft}px`;
1752
- o.top = `${edge2 === "top" ? st : st + vh - bandPx}px`;
1753
- return edge2;
1754
- };
1755
- const onScroll = () => {
1756
- try {
1757
- if (!overlay.isConnected) {
1758
- unpinScrolledAxis(container);
1759
- return;
1760
- }
1761
- place();
1762
- } catch {
1763
- }
1764
- };
1765
- container.appendChild(overlay);
1766
- container.addEventListener("scroll", onScroll, { passive: true });
1767
- container[CONTAINER_SLOT_AXIS_PIN] = { overlay, onScroll };
1768
- const edge = place();
1769
- const mid = (band.top + band.bottom) / 2 / svgBox.height;
1770
- return {
1771
- pinned: true,
1772
- reason: "pinned",
1773
- bandPx: Math.round(bandPx),
1774
- axisAt: mid < 1 / 3 ? "top" : mid > 2 / 3 ? "bottom" : "middle",
1775
- labels: cands[plan.index].labels.length,
1776
- carried: carried.length,
1777
- edge
1778
- };
1779
- } catch {
1780
- unpinScrolledAxis(container);
1781
- return noPin("threw");
1782
- }
1783
- }
1784
- function fitRenderedChart(container, opts = {}) {
1785
- const slackPx = opts.slackPx ?? SCROLL_SLACK_PX;
1786
- const result = {
1787
- grew: false,
1788
- growFrom: 0,
1789
- growTo: 0,
1790
- growReason: "no-container",
1791
- overflowX: "hidden",
1792
- overflowY: "hidden",
1793
- reading: null,
1794
- axisPin: noPin("no-container")
1795
- };
1796
- if (!container) return result;
1797
- try {
1798
- let svg = container.querySelector(`svg[${SNAPSHOT_SVG_ATTR}]`);
1799
- for (let i = 0; i < container.children.length && !svg; i++) {
1800
- const el = container.children[i];
1801
- if (el.tagName && el.tagName.toLowerCase() === "svg") svg = el;
1802
- }
1803
- if (!svg) svg = container.querySelector("svg");
1804
- let inkCache;
1805
- const svgInk = (el) => {
1806
- if (inkCache === void 0) inkCache = svgInkReach(el);
1807
- return inkCache;
1808
- };
1809
- const inkOf = (el) => el && el.tagName && el.tagName.toLowerCase() === "svg" ? svgInk(el) : null;
1810
- if (svg && opts.grow !== false) {
1811
- try {
1812
- const ink = svgInk(svg);
1813
- const elH = svg.getBoundingClientRect().height;
1814
- const vb = svg.viewBox && svg.viewBox.baseVal ? svg.viewBox.baseVal.height : 0;
1815
- const ctm = typeof svg.getScreenCTM === "function" ? svg.getScreenCTM() : null;
1816
- const plan = planFrameGrow(
1817
- ink ? ink.bottom : NaN,
1818
- elH,
1819
- vb,
1820
- ctmScaleOf(ctm),
1821
- slackPx
1822
- );
1823
- result.growFrom = Math.round(elH);
1824
- result.growTo = plan.heightPx;
1825
- result.growReason = plan.reason;
1826
- if (plan.grow) {
1827
- svg.setAttribute("height", String(plan.heightPx));
1828
- if (vb > 0) {
1829
- const b = svg.viewBox.baseVal;
1830
- svg.setAttribute("viewBox", `${b.x} ${b.y} ${b.width} ${plan.viewBoxH}`);
1831
- }
1832
- result.grew = true;
1833
- }
1834
- } catch {
1835
- result.growReason = "grow-threw";
1836
- }
1837
- } else if (!svg) {
1838
- result.growReason = "no-svg";
1839
- } else {
1840
- result.growReason = "grow-disabled";
1841
- }
1842
- const reading = fitReadingFor(opts.lane ?? "chart", container, slackPx, inkOf);
1843
- result.reading = reading;
1844
- const boxes = measureContainerBoxes(container, inkOf);
1845
- const extent = contentExtentOf(boxes);
1846
- const svgBox = svg ? svg.getBoundingClientRect() : null;
1847
- const contentW = extent.source === "none" ? Math.max(container.scrollWidth, svgBox ? svgBox.width : 0) : extent.w;
1848
- const contentH = extent.source === "none" ? Math.max(container.scrollHeight, svgBox ? svgBox.height : 0) : extent.h;
1849
- const fit = scrollFitFor(contentW, contentH, container.clientWidth, container.clientHeight, slackPx);
1850
- result.overflowX = fit.overflowX;
1851
- result.overflowY = fit.overflowY;
1852
- if (opts.applyOverflow !== false) {
1853
- container.style.overflowX = fit.overflowX;
1854
- container.style.overflowY = fit.overflowY;
1855
- if (fit.overflowY !== "auto") {
1856
- unpinScrolledAxis(container);
1857
- result.axisPin = noPin("not-scrolling");
1858
- } else if (opts.pinAxis === false) {
1859
- unpinScrolledAxis(container);
1860
- result.axisPin = noPin("disabled");
1861
- } else result.axisPin = pinScrolledAxis(container, svg);
1862
- } else {
1863
- unpinScrolledAxis(container);
1864
- result.axisPin = noPin("overflow-not-applied");
1865
- }
1866
- } catch {
1867
- }
1868
- return result;
1869
- }
1870
-
1871
1325
  // src/labelContrastDom.ts
1872
1326
  var LABEL_CONTRAST_DONE_ATTR = "data-lch-contrast";
1873
1327
  var LABEL_CONTRAST_CAP = 2e3;
@@ -3290,30 +2744,6 @@ export {
3290
2744
  VALUE_AXIS_MIN_FIT,
3291
2745
  censusValuePlacement,
3292
2746
  valuePlacementFlag,
3293
- SCROLL_SLACK_PX,
3294
- needsScroll,
3295
- contentExtentOf,
3296
- scrollFitFor,
3297
- FIT_CONTENT_SELECTOR,
3298
- PHANTOM_FRACTION,
3299
- isPhantomBox,
3300
- MAX_FRAME_GROW_FACTOR,
3301
- planFrameGrow,
3302
- AXIS_PIN_MIN_LABELS,
3303
- AXIS_PIN_BAND_PAD_PX,
3304
- AXIS_PIN_MAX_BAND_FRACTION,
3305
- AXIS_PIN_TRACK_REACH_PX,
3306
- isHorizontalLabelRow,
3307
- labelBand,
3308
- planAxisPin,
3309
- axisPinPlacement,
3310
- ctmScaleOf,
3311
- svgInkReach,
3312
- measureContainerBoxes,
3313
- fitReadingFor,
3314
- unpinScrolledAxis,
3315
- pinScrolledAxis,
3316
- fitRenderedChart,
3317
2747
  LABEL_CONTRAST_DONE_ATTR,
3318
2748
  LABEL_CONTRAST_CAP,
3319
2749
  LABEL_PILL_CLASS,