@ai-matrx/design-system 0.61.6 → 0.61.7
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/CHANGELOG.md +19 -0
- package/dist/controls.cjs +2 -1
- package/dist/controls.cjs.map +1 -1
- package/dist/controls.css +22 -7
- package/dist/controls.d.cts +3 -0
- package/dist/controls.d.ts +3 -0
- package/dist/controls.js +2 -1
- package/dist/controls.js.map +1 -1
- package/dist/index.cjs +30 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -681,12 +681,32 @@ function describe(el) {
|
|
|
681
681
|
const t = (el.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
682
682
|
return t.length > 60 ? `${t.slice(0, 57)}\u2026` : t;
|
|
683
683
|
}
|
|
684
|
+
function ownTextNodes(el, view) {
|
|
685
|
+
const out = [];
|
|
686
|
+
const walker = el.ownerDocument.createTreeWalker(
|
|
687
|
+
el,
|
|
688
|
+
4
|
|
689
|
+
/* NodeFilter.SHOW_TEXT */
|
|
690
|
+
);
|
|
691
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
692
|
+
let offFlow = false;
|
|
693
|
+
for (let p = n.parentElement; p && p !== el; p = p.parentElement) {
|
|
694
|
+
const pcs = view.getComputedStyle(p);
|
|
695
|
+
if (pcs.position === "absolute" || pcs.position === "fixed" || pcs.display === "none") {
|
|
696
|
+
offFlow = true;
|
|
697
|
+
break;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (!offFlow) out.push(n);
|
|
701
|
+
}
|
|
702
|
+
return out;
|
|
703
|
+
}
|
|
684
704
|
function findPillViolation(el, maxWidth = PILL_MAX_WIDTH_PX) {
|
|
685
705
|
if (el.getAttribute("data-matrx-pill") === "off") return null;
|
|
686
|
-
const text = (el.textContent ?? "").trim();
|
|
687
|
-
if (!text) return null;
|
|
688
706
|
const view = el.ownerDocument.defaultView;
|
|
689
707
|
if (!view) return null;
|
|
708
|
+
const own = ownTextNodes(el, view);
|
|
709
|
+
if (!own.some((t) => (t.textContent ?? "").trim())) return null;
|
|
690
710
|
const rect = el.getBoundingClientRect();
|
|
691
711
|
if (rect.width === 0 || rect.height === 0) return null;
|
|
692
712
|
const cs = view.getComputedStyle(el);
|
|
@@ -694,17 +714,21 @@ function findPillViolation(el, maxWidth = PILL_MAX_WIDTH_PX) {
|
|
|
694
714
|
if (rect.width > maxWidth + 0.5) {
|
|
695
715
|
return `pill is ${Math.round(rect.width)}px wide (budget ${maxWidth}px) holding "${describe(el)}" \u2014 a pill holds a short label: clamp it (Badge, or truncate + max-w + title) or render a list row.`;
|
|
696
716
|
}
|
|
697
|
-
const lines = lineCount(el, cs, rect.height);
|
|
717
|
+
const lines = lineCount(el, own, cs, rect.height);
|
|
698
718
|
if (lines > 1) {
|
|
699
719
|
return `pill wraps to ${lines} lines holding "${describe(el)}" \u2014 a pill is one line: clamp it (Badge, or truncate + max-w + title) or render a list row.`;
|
|
700
720
|
}
|
|
701
721
|
return null;
|
|
702
722
|
}
|
|
703
|
-
function lineCount(el, cs, height) {
|
|
723
|
+
function lineCount(el, own, cs, height) {
|
|
704
724
|
const range = el.ownerDocument.createRange?.();
|
|
705
725
|
if (range && typeof range.getClientRects === "function") {
|
|
706
|
-
|
|
707
|
-
const
|
|
726
|
+
const rects = [];
|
|
727
|
+
for (const node of own) {
|
|
728
|
+
if (!(node.textContent ?? "").trim()) continue;
|
|
729
|
+
range.selectNodeContents(node);
|
|
730
|
+
rects.push(...Array.from(range.getClientRects()).filter((r) => r.width > 0 && r.height > 0));
|
|
731
|
+
}
|
|
708
732
|
range.detach?.();
|
|
709
733
|
if (rects.length) {
|
|
710
734
|
const mids = [];
|