@ai-matrx/design-system 0.61.6 → 0.61.8
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 +29 -5
- 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 +31 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -350,12 +350,33 @@ function describe(el) {
|
|
|
350
350
|
const t = (el.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
351
351
|
return t.length > 60 ? `${t.slice(0, 57)}\u2026` : t;
|
|
352
352
|
}
|
|
353
|
+
var INTERACTIVE = 'a[href],button,[role="tab"],[role="button"],[role="radio"],[role="link"],[role="menuitem"],[role="option"]';
|
|
354
|
+
function ownTextNodes(el, view) {
|
|
355
|
+
const out = [];
|
|
356
|
+
const walker = el.ownerDocument.createTreeWalker(
|
|
357
|
+
el,
|
|
358
|
+
4
|
|
359
|
+
/* NodeFilter.SHOW_TEXT */
|
|
360
|
+
);
|
|
361
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
362
|
+
let offFlow = false;
|
|
363
|
+
for (let p = n.parentElement; p && p !== el; p = p.parentElement) {
|
|
364
|
+
const pcs = view.getComputedStyle(p);
|
|
365
|
+
if (pcs.position === "absolute" || pcs.position === "fixed" || pcs.display === "none" || p.matches(INTERACTIVE)) {
|
|
366
|
+
offFlow = true;
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (!offFlow) out.push(n);
|
|
371
|
+
}
|
|
372
|
+
return out;
|
|
373
|
+
}
|
|
353
374
|
function findPillViolation(el, maxWidth = PILL_MAX_WIDTH_PX) {
|
|
354
375
|
if (el.getAttribute("data-matrx-pill") === "off") return null;
|
|
355
|
-
const text = (el.textContent ?? "").trim();
|
|
356
|
-
if (!text) return null;
|
|
357
376
|
const view = el.ownerDocument.defaultView;
|
|
358
377
|
if (!view) return null;
|
|
378
|
+
const own = ownTextNodes(el, view);
|
|
379
|
+
if (!own.some((t) => (t.textContent ?? "").trim())) return null;
|
|
359
380
|
const rect = el.getBoundingClientRect();
|
|
360
381
|
if (rect.width === 0 || rect.height === 0) return null;
|
|
361
382
|
const cs = view.getComputedStyle(el);
|
|
@@ -363,17 +384,21 @@ function findPillViolation(el, maxWidth = PILL_MAX_WIDTH_PX) {
|
|
|
363
384
|
if (rect.width > maxWidth + 0.5) {
|
|
364
385
|
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.`;
|
|
365
386
|
}
|
|
366
|
-
const lines = lineCount(el, cs, rect.height);
|
|
387
|
+
const lines = lineCount(el, own, cs, rect.height);
|
|
367
388
|
if (lines > 1) {
|
|
368
389
|
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.`;
|
|
369
390
|
}
|
|
370
391
|
return null;
|
|
371
392
|
}
|
|
372
|
-
function lineCount(el, cs, height) {
|
|
393
|
+
function lineCount(el, own, cs, height) {
|
|
373
394
|
const range = el.ownerDocument.createRange?.();
|
|
374
395
|
if (range && typeof range.getClientRects === "function") {
|
|
375
|
-
|
|
376
|
-
const
|
|
396
|
+
const rects = [];
|
|
397
|
+
for (const node of own) {
|
|
398
|
+
if (!(node.textContent ?? "").trim()) continue;
|
|
399
|
+
range.selectNodeContents(node);
|
|
400
|
+
rects.push(...Array.from(range.getClientRects()).filter((r) => r.width > 0 && r.height > 0));
|
|
401
|
+
}
|
|
377
402
|
range.detach?.();
|
|
378
403
|
if (rects.length) {
|
|
379
404
|
const mids = [];
|